From a6a454a3a58df737c6a670ddd515086a8b2c2316 Mon Sep 17 00:00:00 2001 From: Nobody6825 <117302867+Nobooooody@users.noreply.github.com> Date: Wed, 12 Apr 2023 02:48:53 +0800 Subject: [PATCH] Add Auto_Build Scripts and Initial commit for ArmAsmHelper_Linux.h and .gitignore for patch_kernel_root --- .github/workflows/PermissionManager.yml | 30 ++++++ .../workflows/SKRootKernelRoot_Windows.yml | 37 ++++++++ .gitignore | 1 + CMakeLists.txt | 35 +++++++ patch_kernel_root/ArmAsmHelper_Linux.h | 94 +++++++++++++++++++ ...{ArmAsmHelper.h => ArmAsmHelper_Windows.h} | 0 patch_kernel_root/patch_kernel_root.cpp | 9 +- 7 files changed, 204 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/PermissionManager.yml create mode 100644 .github/workflows/SKRootKernelRoot_Windows.yml create mode 100644 .gitignore create mode 100644 CMakeLists.txt create mode 100644 patch_kernel_root/ArmAsmHelper_Linux.h rename patch_kernel_root/{ArmAsmHelper.h => ArmAsmHelper_Windows.h} (100%) diff --git a/.github/workflows/PermissionManager.yml b/.github/workflows/PermissionManager.yml new file mode 100644 index 00000000..8911f264 --- /dev/null +++ b/.github/workflows/PermissionManager.yml @@ -0,0 +1,30 @@ +name: PermissionManager_CIBuild + +on: + push: + branches: [master] + pull_request: + branches: [master] + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Setup JDK + uses: actions/setup-java@v2 + with: + distribution: "adopt" + java-version: 11 + - name: Build with Gradle + run: | + cd PermissionManager + chmod +x ./gradlew + ./gradlew assembleRelease + - name: Upload Artifacts + uses: actions/upload-artifact@v2 + if: ${{ !github.event.pull_request }} + with: + path: "PermissionManager/app/build/outputs/apk/release/app-release-unsigned.apk" + name: app-release-unsigned.apk diff --git a/.github/workflows/SKRootKernelRoot_Windows.yml b/.github/workflows/SKRootKernelRoot_Windows.yml new file mode 100644 index 00000000..6d6e3dd7 --- /dev/null +++ b/.github/workflows/SKRootKernelRoot_Windows.yml @@ -0,0 +1,37 @@ +name: SKRootKernelRoot_Windows_CIBuild +on: + push: + branches: [master] + pull_request: + branches: [master] + workflow_dispatch: + +jobs: + build: + name: Compile SKRoot Kernel Root on Windows + runs-on: windows-latest + env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: true + steps: + - uses: actions/checkout@v2 + - name: Add MSBuild to PATH + uses: microsoft/setup-msbuild@v1.1 + - name: List files in current directory + run: | + Get-ChildItem -Path "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\" -Filter vcvarsall.bat -File -Recurse + Get-ChildItem -Path "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\" -Filter vcvars64.bat -File -Recurse + - name: Compile patch_kernel_root + shell: cmd + run: | + call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvars64.bat" + cl patch_kernel_root\patch_kernel_root.cpp /EHsc /Fe:patch_kernel_root /Ipatch_kernel_root /I "C:\Program Files (x86)\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.35.32215\include" + - name: List files in current directory + run: | + ls patch_kernel_root + Get-ChildItem -Path . -Filter 'patch_kernel_root.*' -File -Recurse + Get-ChildItem -Path . -Filter '*.exe' -File -Recurse + - name: Upload artifacts + uses: Actions/upload-artifact@main + with: + name: patch_kernel_root + path: patch_kernel_root.exe diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..d1638636 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..96edc715 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,35 @@ +# 要求最低的 CMake 版本 +cmake_minimum_required(VERSION 3.0) + +# 启用 CMP0048 策略 +cmake_policy(SET CMP0048 NEW) + +# 设置项目名称和版本号 +project(patch_kernel_root VERSION 1.0) + + +# 要求 C++17 标准 +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED True) + +# 添加头文件目录 +include_directories(include) + +# 添加所有源文件(排除测试文件) +file(GLOB SRC_FILES "${CMAKE_CURRENT_SOURCE_DIR}/patch_kernel_root/*.cpp") +list(FILTER SRC_FILES EXCLUDE REGEX "^Byte2HexTest.cpp$") + +# 添加可执行文件 +add_executable(patch_kernel_root ${SRC_FILES}) + +# 添加测试文件 +option(BUILD_TESTING "Build the tests" ON) +if(BUILD_TESTING) + enable_testing() + file(GLOB TEST_SOURCES "tests/*.cpp") + foreach(TEST_SOURCE ${TEST_SOURCES}) + get_filename_component(TEST_NAME ${TEST_SOURCE} NAME_WE) + add_executable(${TEST_NAME} ${TEST_SOURCE}) + target_link_libraries(${TEST_NAME} patch_kernel_root) + endforeach() +endif() diff --git a/patch_kernel_root/ArmAsmHelper_Linux.h b/patch_kernel_root/ArmAsmHelper_Linux.h new file mode 100644 index 00000000..cf899784 --- /dev/null +++ b/patch_kernel_root/ArmAsmHelper_Linux.h @@ -0,0 +1,94 @@ +#ifndef ARM_ASM_HELPER_H_ +#define ARM_ASM_HELPER_H_ +#include +#include +#include +#include +#include +#include +#include +#include + + +std::string AsmToBytes(const std::string& strArm64Asm) { +// 获取汇编文本 + +// 获取自身运行目录 +char szFileName[1024] = { 0 }; +readlink("/proc/self/exe", szFileName, sizeof(szFileName)-1); +std::string strMyPath = szFileName; +strMyPath = strMyPath.substr(0, strMyPath.find_last_of('/') + 1); + +// 写出 input.s 文件 +std::ofstream inputFile; +inputFile.open(strMyPath + "input.s", std::ios_base::out | std::ios_base::trunc); +inputFile << ".arch armv8-a\n"; +inputFile << ".text\n"; +inputFile << ".global _start\n"; +inputFile << "_start:\n"; +inputFile << strArm64Asm; +inputFile.close(); + +// ARM64 +std::system(std::string("rm -f " + strMyPath + "output.txt").c_str()); + +std::string cmd = "aarch64-linux-gnu-as -o " + strMyPath + "output.o " + strMyPath + "input.s"; +std::system(cmd.c_str()); + +cmd = "aarch64-linux-gnu-objcopy -O binary " + strMyPath + "output.o " + strMyPath + "output.bin"; +std::system(cmd.c_str()); + +// 读取 output.bin 文件 +std::ifstream in(strMyPath + "output.bin", std::ios::binary); +std::stringstream ssOutput; +if (in) // 有该文件 +{ + char buffer[1024] = {0}; + while (in.read(buffer, sizeof(buffer))) + { + ssOutput << std::hex; + for(int i = 0; i < sizeof(buffer); i++) { + ssOutput << ((buffer[i] >> 4) & 0xf) << (buffer[i] & 0xf); + } + } + + if (in.gcount() > 0) { + ssOutput << std::hex; + for(int i = 0; i < in.gcount(); i++) { + ssOutput << ((buffer[i] >> 4) & 0xf) << (buffer[i] & 0xf); + } + } + in.close(); +} +std::system(std::string("rm -f " + strMyPath + "input.s").c_str()); +std::system(std::string("rm -f " + strMyPath + "output.o").c_str()); +std::system(std::string("rm -f " + strMyPath + "output.bin").c_str()); + +return ssOutput.str(); +} + + + +const char HEX[16] = { +'0', '1', '2', '3', +'4', '5', '6', '7', +'8', '9', 'a', 'b', +'c', 'd', 'e', 'f' +}; + +/* Convert byte array to hex string. */ +std::string bytesToHexString(const std::byte* input, size_t length) { + + std::string str; + str.reserve(length << 1); + for (size_t i = 0; i < length; ++i) { + int t = static_cast(input[i]); + int a = t / 16; + int b = t % 16; + str.append(1, HEX[a]); + str.append(1, HEX[b]); + } + return str; +} + +#endif /* ARM_ASM_HELPER_H_ */ diff --git a/patch_kernel_root/ArmAsmHelper.h b/patch_kernel_root/ArmAsmHelper_Windows.h similarity index 100% rename from patch_kernel_root/ArmAsmHelper.h rename to patch_kernel_root/ArmAsmHelper_Windows.h diff --git a/patch_kernel_root/patch_kernel_root.cpp b/patch_kernel_root/patch_kernel_root.cpp index 0c395103..39032526 100644 --- a/patch_kernel_root/patch_kernel_root.cpp +++ b/patch_kernel_root/patch_kernel_root.cpp @@ -6,8 +6,13 @@ #include #include #include -#include "ArmAsmHelper.h" - +#if defined(_WIN16) || defined(_WIN32) || defined(_WIN64) +#include "ArmAsmHelper_Windows.h" +#elif defined(__linux__) || defined(__gnu_linux__) +#include "ArmAsmHelper_Linux.h" +#elif defined(__APPLE__) +#include "ArmAsmHelper_Linux.h" +#endif using namespace std;