diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 1ec4153c..80dffc5b 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -3,6 +3,8 @@ project(Lightswitch VERSION 1 LANGUAGES CXX) set_property(GLOBAL PROPERTY CMAKE_CXX_STANDARD 17 PROPERTY CMAKE_CXX_STANDARD_REQUIRED TRUE) set(source_DIR ${CMAKE_SOURCE_DIR}/src/main/cpp) + include_directories(${source_DIR}/include) + add_library(lightswitch SHARED ${source_DIR}/lightswitch.cpp) target_link_libraries(lightswitch ${source_DIR}/lib/${ANDROID_ABI}/libunicorn.a) \ No newline at end of file diff --git a/app/src/main/cpp/core/arm/cpu.cpp b/app/src/main/cpp/core/arm/cpu.cpp new file mode 100644 index 00000000..231b20f5 --- /dev/null +++ b/app/src/main/cpp/core/arm/cpu.cpp @@ -0,0 +1,5 @@ +#include "cpu.h" + +namespace Core { + +} \ No newline at end of file diff --git a/app/src/main/cpp/core/arm/cpu.h b/app/src/main/cpp/core/arm/cpu.h new file mode 100644 index 00000000..8ce5f0ee --- /dev/null +++ b/app/src/main/cpp/core/arm/cpu.h @@ -0,0 +1,10 @@ +#pragma once + +#include + +namespace Core { + class Cpu { + private: + uc_engine *uc; + }; +} \ No newline at end of file diff --git a/app/src/main/cpp/lightswitch.cpp b/app/src/main/cpp/lightswitch.cpp index 0537ff84..5fb80a22 100644 --- a/app/src/main/cpp/lightswitch.cpp +++ b/app/src/main/cpp/lightswitch.cpp @@ -20,13 +20,20 @@ static void hook_code(uc_engine *uc, uint64_t address, uint32_t size, void *user syslog(LOG_DEBUG, ">>> Tracing instruction at 0x%" PRIx64 ", instruction size = 0x%x\n", size); } +static void hook_intr(uc_engine *uc, uint32_t intno, void *user_data) +{ + if (intno == 2) { + + } +} + extern "C" JNIEXPORT jstring JNICALL Java_gq_cyuubi_lightswitch_MainActivity_stringFromJNI( JNIEnv *env, jobject /* this */) { uc_engine *uc; uc_err err; - uc_hook trace1, trace2; + uc_hook trace1, trace2, intr; int64_t x11 = 0x12345678; // X11 register int64_t x13 = 0x10000 + 0x8; // X13 register @@ -58,6 +65,8 @@ Java_gq_cyuubi_lightswitch_MainActivity_stringFromJNI( // tracing one instruction at ADDRESS with customized callback uc_hook_add(uc, &trace2, UC_HOOK_CODE, (void*)hook_code, NULL, ADDRESS, ADDRESS); + uc_hook_add(uc, &intr, UC_HOOK_INTR, (void*)hook_intr, NULL, 1, 0); + // emulate machine code in infinite time (last param = 0), or when // finishing all the code. err = uc_emu_start(uc, ADDRESS, ADDRESS + sizeof(ARM_CODE) -1, 0, 0);