Commit c6f7398e authored by swift_gan's avatar swift_gan

Merge remote-tracking branch 'origin/master'

parents aefda1dd 417f1802
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.4.1)
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library.
sandhook
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/cpp/sandhook.cpp
src/main/cpp/trampoline/trampoline.cpp
src/main/cpp/trampoline/trampoline_manager.cpp
src/main/cpp/utils/dlfcn_nougat.cpp
src/main/cpp/utils/hide_api.cpp
src/main/cpp/utils/utils.cpp
src/main/cpp/utils/offset.cpp
src/main/cpp/utils/elf_util.cpp
src/main/cpp/casts/cast_art_method.cpp
src/main/cpp/casts/cast_compiler_options.cpp
src/main/cpp/art/art_method.cpp
src/main/cpp/art/art_compiler_options.cpp
src/main/cpp/trampoline/arch/arm32.S
src/main/cpp/trampoline/arch/arm64.S
src/main/cpp/inst/insts_arm32.cpp
src/main/cpp/inst/insts_arm64.cpp
src/main/cpp/nativehook/native_hook.cpp
)
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log )
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
sandhook
# Links the target library to the log library
# included in the NDK.
${log-lib} )
add_definitions(-std=c++11)
ENABLE_LANGUAGE(ASM)
\ No newline at end of file
......@@ -13,7 +13,7 @@ android {
externalNativeBuild {
cmake {
arguments '-DBUILD_TESTING=OFF', '-DANDROID_TOOLCHAIN=gcc'
arguments '-DBUILD_TESTING=OFF'
cppFlags "-frtti -fexceptions"
abiFilters 'armeabi-v7a', 'arm64-v8a'
}
......@@ -22,7 +22,7 @@ android {
externalNativeBuild {
cmake {
path "CMakeLists.txt"
path "src/main/cpp/CMakeLists.txt"
}
}
......
cmake_minimum_required(VERSION 3.4.1)
project(sandhook)
ENABLE_LANGUAGE(ASM)
set(${PROJECT_NAME}_SOURCES
sandhook.cpp
trampoline/trampoline.cpp
trampoline/trampoline_manager.cpp
utils/dlfcn_nougat.cpp
utils/hide_api.cpp
utils/utils.cpp
utils/offset.cpp
utils/elf_util.cpp
casts/cast_art_method.cpp
casts/cast_compiler_options.cpp
art/art_method.cpp
art/art_compiler_options.cpp
trampoline/arch/arm32.S
trampoline/arch/arm64.S
inst/insts_arm32.cpp
inst/insts_arm64.cpp
nativehook/native_hook.cpp
)
add_definitions(-std=c++11)
add_library(${PROJECT_NAME}
SHARED
${${PROJECT_NAME}_SOURCES})
target_link_libraries(${PROJECT_NAME} log)
\ No newline at end of file
......@@ -215,7 +215,7 @@ namespace SandHook {
bool beAot = entryPointQuickCompiled->get(neverCall) != entryPointQuickCompiled->get(neverCall2);
if (beAot) {
quickToInterpreterBridge = getInterpreterBridge(false);
if (quickToInterpreterBridge == nullptr || quickToInterpreterBridge <= 0) {
if (quickToInterpreterBridge == nullptr) {
quickToInterpreterBridge = entryPointQuickCompiled->get(neverCall);
canGetInterpreterBridge = false;
}
......@@ -232,7 +232,7 @@ namespace SandHook {
beAot = entryPointQuickCompiled->get(neverCallNative) != entryPointQuickCompiled->get(neverCallNative2);
if (beAot) {
genericJniStub = getInterpreterBridge(true);
if (genericJniStub == nullptr || genericJniStub <= 0) {
if (genericJniStub == nullptr) {
genericJniStub = entryPointQuickCompiled->get(neverCallNative);
canGetJniBridge = false;
}
......
......@@ -15,6 +15,7 @@ x: \
.syntax unified; \
.text; \
.align 4; \
.thumb; \
.thumb_func; \
.global x; \
x: \
......
......@@ -45,7 +45,7 @@ namespace SandHook {
private:
const char* elf = nullptr;
void* base = nullptr;
uint8_t * base = nullptr;
char* buffer = nullptr;
off_t size = 0;
off_t bias = -4396;
......
......@@ -90,6 +90,7 @@ extern "C" void REPLACEMENT_HOOK_TRAMPOLINE();
extern "C" void CALL_ORIGIN_TRAMPOLINE();
#if defined(__arm__)
#include <unistd.h>
extern "C" void DIRECT_JUMP_TRAMPOLINE_T();
extern "C" void INLINE_HOOK_TRAMPOLINE_T();
extern "C" void CALL_ORIGIN_TRAMPOLINE_T();
......
......@@ -14,7 +14,7 @@ namespace SandHook {
uint32_t TrampolineManager::sizeOfEntryCode(mirror::ArtMethod *method) {
Code codeEntry = getEntryCode(method);
if (codeEntry == nullptr || codeEntry <= 0)
if (codeEntry == nullptr)
return 0;
#if defined(__arm__)
if (isThumbCode(reinterpret_cast<Size>(codeEntry))) {
......
......@@ -260,6 +260,7 @@ void *getSymCompat(const char *filename, const char *name) {
return dlsym(handle, name);
}
}
return nullptr;
}
}
\ No newline at end of file
......@@ -31,10 +31,10 @@ ElfImg::ElfImg(const char *elf) {
Elf_Off symtab_entsize = 0;
section_header = reinterpret_cast<Elf_Shdr *>(((void *) header) + header->e_shoff);
section_header = reinterpret_cast<Elf_Shdr *>(((uint8_t *) header) + header->e_shoff);
void* shoff = section_header;
char* section_str = reinterpret_cast<char *>(section_header[header->e_shstrndx].sh_offset + ((void *) header));
uint8_t* shoff = reinterpret_cast<uint8_t *>(section_header);
char* section_str = reinterpret_cast<char *>(section_header[header->e_shstrndx].sh_offset + ((uint8_t *) header));
bool has_strtab = false;
bool has_dynsym = false;
......@@ -75,10 +75,10 @@ ElfImg::ElfImg(const char *elf) {
LOGW("can't find symtab from sections\n");
}
sym_start = reinterpret_cast<Elf_Sym *>(((void *) header) + symtab_offset);
sym_start = reinterpret_cast<Elf_Sym *>(((uint8_t *) header) + symtab_offset);
//load module base
base = getModuleBase(elf);
base = reinterpret_cast<uint8_t *>(getModuleBase(elf));
}
ElfImg::~ElfImg() {
......@@ -97,7 +97,7 @@ Elf_Addr ElfImg::getSymbOffset(const char *name) {
Elf_Addr _offset = 0;
for(int i = 0 ; i < symtab_count; i++) {
unsigned int st_type = ELF_ST_TYPE(sym_start[i].st_info);
char* st_name = static_cast<char *>(((void *) header) + symstr_offset + sym_start[i].st_name);
char* st_name = reinterpret_cast<char *>(((uint8_t *) header) + symstr_offset + sym_start[i].st_name);
if (st_type == STT_FUNC && sym_start[i].st_size) {
if(strcmp(st_name, name) == 0) {
_offset = sym_start[i].st_value;
......@@ -111,7 +111,7 @@ Elf_Addr ElfImg::getSymbOffset(const char *name) {
Elf_Addr ElfImg::getSymbAddress(const char *name) {
Elf_Addr offset = getSymbOffset(name);
if (offset > 0 && base > 0) {
if (offset > 0 && base != nullptr) {
return reinterpret_cast<Elf_Addr>(base + offset - bias);
} else {
return 0;
......
......@@ -60,7 +60,7 @@ extern "C" {
bool generate_debug_info = false;
jitCompilerHandle = (jitLoad)(&generate_debug_info);
if (jitCompilerHandle != nullptr && jitCompilerHandle > 0) {
if (jitCompilerHandle != nullptr) {
art::CompilerOptions* compilerOptions = getCompilerOptions(
reinterpret_cast<art::jit::JitCompiler *>(jitCompilerHandle));
disableJitInline(compilerOptions);
......@@ -106,7 +106,7 @@ extern "C" {
}
bool canCompile() {
if (getGlobalJitCompiler() == nullptr || getGlobalJitCompiler() <= 0) {
if (getGlobalJitCompiler() == nullptr) {
LOGE("JIT not init!");
return false;
}
......@@ -165,7 +165,7 @@ extern "C" {
art::jit::JitCompiler* getGlobalJitCompiler() {
if (SDK_INT < ANDROID_N)
return nullptr;
if (globalJitCompileHandlerAddr == nullptr || globalJitCompileHandlerAddr <= 0)
if (globalJitCompileHandlerAddr == nullptr)
return nullptr;
return *globalJitCompileHandlerAddr;
}
......@@ -181,7 +181,7 @@ extern "C" {
}
bool disableJitInline(art::CompilerOptions* compilerOptions) {
if (compilerOptions == nullptr || compilerOptions <= 0)
if (compilerOptions == nullptr)
return false;
size_t originOptions = compilerOptions->getInlineMaxCodeUnits();
//maybe a real inlineMaxCodeUnits
......@@ -213,17 +213,17 @@ extern "C" {
if (SDK_INT < ANDROID_Q)
return false;
if (origin_jit_update_options == nullptr
|| origin_jit_update_options <= 0
|| *origin_jit_update_options == nullptr
|| *origin_jit_update_options <= 0)
|| *origin_jit_update_options == nullptr)
return false;
*origin_jit_update_options = fake_jit_update_options;
return true;
}
bool forceProcessProfiles() {
if (profileSaver_ForceProcessProfiles == nullptr)
return false;
profileSaver_ForceProcessProfiles();
return true;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment