Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/PermissionManager.yml
Original file line number Diff line number Diff line change
@@ -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
37 changes: 37 additions & 0 deletions .github/workflows/SKRootKernelRoot_Windows.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
- 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
35 changes: 35 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()
94 changes: 94 additions & 0 deletions patch_kernel_root/ArmAsmHelper_Linux.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#ifndef ARM_ASM_HELPER_H_
#define ARM_ASM_HELPER_H_
#include <string>
#include <filesystem>
#include <fstream>
#include <sstream>
#include <cstddef>
#include <cstdlib>
#include <cstdio>
#include <unistd.h>


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<int>(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_ */
9 changes: 7 additions & 2 deletions patch_kernel_root/patch_kernel_root.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
#include <sstream>
#include <vector>
#include <algorithm>
#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;

Expand Down