From fb1cc2302d5c5b4c7a2763d5f5d00c7f2dfab84a Mon Sep 17 00:00:00 2001 From: android Date: Sat, 10 Oct 2020 18:18:40 +0800 Subject: [PATCH] Add unidbg-dynarmic module --- .gitignore | 2 ++ pom.xml | 1 + .../unidbg/arm/backend/dynarmic/Dynarmic.java | 9 -------- unidbg-dynarmic/pom.xml | 21 ++++++++++++++++++ .../arm/backend/dynarmic/DynarmicLoader.java | 16 +++++++++++++ .../src/main/native/dynarmic/build.sh | 2 +- ...hub_unidbg_arm_backend_dynarmic_Dynarmic.h | 0 .../src/main/native/dynarmic/dynarmic.cpp | 0 .../src/main/native/dynarmic/dynarmic.h | 0 .../src/main/native/dynarmic/khash.h | 0 .../natives/osx_64/libdynarmic.dylib | Bin .../arm/backend/DynarmicBackendTest.java | 5 +++++ .../arm/backend/dynarmic/DynarmicTest.java | 4 ++++ .../src/test/native/dynarmic/build.sh | 0 .../src/test/native/dynarmic/main.cpp | 0 .../src/test/resources/log4j.properties | 0 16 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 unidbg-dynarmic/pom.xml create mode 100644 unidbg-dynarmic/src/main/java/com/github/unidbg/arm/backend/dynarmic/DynarmicLoader.java rename {unidbg-api => unidbg-dynarmic}/src/main/native/dynarmic/build.sh (74%) rename {unidbg-api => unidbg-dynarmic}/src/main/native/dynarmic/com_github_unidbg_arm_backend_dynarmic_Dynarmic.h (100%) rename {unidbg-api => unidbg-dynarmic}/src/main/native/dynarmic/dynarmic.cpp (100%) rename {unidbg-api => unidbg-dynarmic}/src/main/native/dynarmic/dynarmic.h (100%) rename {unidbg-api => unidbg-dynarmic}/src/main/native/dynarmic/khash.h (100%) rename {unidbg-api => unidbg-dynarmic}/src/main/resources/natives/osx_64/libdynarmic.dylib (100%) rename {unidbg-api => unidbg-dynarmic}/src/test/java/com/github/unidbg/arm/backend/DynarmicBackendTest.java (85%) rename {unidbg-api => unidbg-dynarmic}/src/test/java/com/github/unidbg/arm/backend/dynarmic/DynarmicTest.java (92%) rename {unidbg-api => unidbg-dynarmic}/src/test/native/dynarmic/build.sh (100%) rename {unidbg-api => unidbg-dynarmic}/src/test/native/dynarmic/main.cpp (100%) rename {unidbg-api => unidbg-dynarmic}/src/test/resources/log4j.properties (100%) diff --git a/.gitignore b/.gitignore index 0a46a9bc6..ee65d4d5a 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ /unidbg-ios/unidbg-ios.iml /unidbg-ios/target/ /unidbg-android/target/ +/unidbg-dynarmic/target/ +/unidbg-dynarmic/unidbg-dynarmic.iml diff --git a/pom.xml b/pom.xml index bae83677d..5606fa1b3 100644 --- a/pom.xml +++ b/pom.xml @@ -9,6 +9,7 @@ unidbg-api unidbg-android unidbg-ios + unidbg-dynarmic UTF-8 diff --git a/unidbg-api/src/main/java/com/github/unidbg/arm/backend/dynarmic/Dynarmic.java b/unidbg-api/src/main/java/com/github/unidbg/arm/backend/dynarmic/Dynarmic.java index 8f159f1cb..293c18195 100644 --- a/unidbg-api/src/main/java/com/github/unidbg/arm/backend/dynarmic/Dynarmic.java +++ b/unidbg-api/src/main/java/com/github/unidbg/arm/backend/dynarmic/Dynarmic.java @@ -4,18 +4,9 @@ import org.apache.commons.logging.LogFactory; import java.io.Closeable; -import java.io.IOException; public class Dynarmic implements Closeable { - static { - try { - org.scijava.nativelib.NativeLoader.loadLibrary("dynarmic"); - } catch (IOException e) { - throw new IllegalStateException(e); - } - } - private static final Log log = LogFactory.getLog(Dynarmic.class); private static native long nativeInitialize(boolean is64Bit); diff --git a/unidbg-dynarmic/pom.xml b/unidbg-dynarmic/pom.xml new file mode 100644 index 000000000..535e6fb96 --- /dev/null +++ b/unidbg-dynarmic/pom.xml @@ -0,0 +1,21 @@ + + + + com.github.zhkl0228 + unidbg-parent + 0.7.0 + + 4.0.0 + + unidbg-dynarmic + 0.8.0-SNAPSHOT + + + com.github.zhkl0228 + unidbg-api + 0.8.0-SNAPSHOT + + + diff --git a/unidbg-dynarmic/src/main/java/com/github/unidbg/arm/backend/dynarmic/DynarmicLoader.java b/unidbg-dynarmic/src/main/java/com/github/unidbg/arm/backend/dynarmic/DynarmicLoader.java new file mode 100644 index 000000000..c0314fe9d --- /dev/null +++ b/unidbg-dynarmic/src/main/java/com/github/unidbg/arm/backend/dynarmic/DynarmicLoader.java @@ -0,0 +1,16 @@ +package com.github.unidbg.arm.backend.dynarmic; + +import java.io.IOException; + +public class DynarmicLoader { + + public static void useDynarmic() { + try { + org.scijava.nativelib.NativeLoader.loadLibrary("dynarmic"); + } catch (IOException e) { + throw new IllegalStateException(e); + } + System.setProperty("use.dynarmic.backend", "true"); + } + +} diff --git a/unidbg-api/src/main/native/dynarmic/build.sh b/unidbg-dynarmic/src/main/native/dynarmic/build.sh similarity index 74% rename from unidbg-api/src/main/native/dynarmic/build.sh rename to unidbg-dynarmic/src/main/native/dynarmic/build.sh index b83d348ec..12410afdc 100755 --- a/unidbg-api/src/main/native/dynarmic/build.sh +++ b/unidbg-dynarmic/src/main/native/dynarmic/build.sh @@ -1,7 +1,7 @@ JAVA_INC="$(realpath "$JAVA_HOME"/include)" JAVA_PLATFORM_INC="$(dirname "$(find "$JAVA_INC" -name jni_md.h)")" -"$(/usr/libexec/java_home -v 1.8)"/bin/javah -cp ../../../../target/classes com.github.unidbg.arm.backend.dynarmic.Dynarmic && \ +"$(/usr/libexec/java_home -v 1.8)"/bin/javah -cp ../../../../../unidbg-api/target/classes com.github.unidbg.arm.backend.dynarmic.Dynarmic && \ xcrun -sdk macosx clang++ -m64 -o libdynarmic.dylib -shared -std=c++11 \ -I ~/git/dynarmic/include dynarmic.cpp \ -I "$JAVA_INC" -I "$JAVA_PLATFORM_INC" \ diff --git a/unidbg-api/src/main/native/dynarmic/com_github_unidbg_arm_backend_dynarmic_Dynarmic.h b/unidbg-dynarmic/src/main/native/dynarmic/com_github_unidbg_arm_backend_dynarmic_Dynarmic.h similarity index 100% rename from unidbg-api/src/main/native/dynarmic/com_github_unidbg_arm_backend_dynarmic_Dynarmic.h rename to unidbg-dynarmic/src/main/native/dynarmic/com_github_unidbg_arm_backend_dynarmic_Dynarmic.h diff --git a/unidbg-api/src/main/native/dynarmic/dynarmic.cpp b/unidbg-dynarmic/src/main/native/dynarmic/dynarmic.cpp similarity index 100% rename from unidbg-api/src/main/native/dynarmic/dynarmic.cpp rename to unidbg-dynarmic/src/main/native/dynarmic/dynarmic.cpp diff --git a/unidbg-api/src/main/native/dynarmic/dynarmic.h b/unidbg-dynarmic/src/main/native/dynarmic/dynarmic.h similarity index 100% rename from unidbg-api/src/main/native/dynarmic/dynarmic.h rename to unidbg-dynarmic/src/main/native/dynarmic/dynarmic.h diff --git a/unidbg-api/src/main/native/dynarmic/khash.h b/unidbg-dynarmic/src/main/native/dynarmic/khash.h similarity index 100% rename from unidbg-api/src/main/native/dynarmic/khash.h rename to unidbg-dynarmic/src/main/native/dynarmic/khash.h diff --git a/unidbg-api/src/main/resources/natives/osx_64/libdynarmic.dylib b/unidbg-dynarmic/src/main/resources/natives/osx_64/libdynarmic.dylib similarity index 100% rename from unidbg-api/src/main/resources/natives/osx_64/libdynarmic.dylib rename to unidbg-dynarmic/src/main/resources/natives/osx_64/libdynarmic.dylib diff --git a/unidbg-api/src/test/java/com/github/unidbg/arm/backend/DynarmicBackendTest.java b/unidbg-dynarmic/src/test/java/com/github/unidbg/arm/backend/DynarmicBackendTest.java similarity index 85% rename from unidbg-api/src/test/java/com/github/unidbg/arm/backend/DynarmicBackendTest.java rename to unidbg-dynarmic/src/test/java/com/github/unidbg/arm/backend/DynarmicBackendTest.java index 7adb5f87e..a75497a75 100644 --- a/unidbg-api/src/test/java/com/github/unidbg/arm/backend/DynarmicBackendTest.java +++ b/unidbg-dynarmic/src/test/java/com/github/unidbg/arm/backend/DynarmicBackendTest.java @@ -1,10 +1,15 @@ package com.github.unidbg.arm.backend; +import com.github.unidbg.arm.backend.dynarmic.DynarmicLoader; import junit.framework.TestCase; import unicorn.Arm64Const; public class DynarmicBackendTest extends TestCase { + static { + DynarmicLoader.useDynarmic(); + } + public void testInitialize() { Backend backend = DynarmicBackend.tryInitialize(true); assertNotNull(backend); diff --git a/unidbg-api/src/test/java/com/github/unidbg/arm/backend/dynarmic/DynarmicTest.java b/unidbg-dynarmic/src/test/java/com/github/unidbg/arm/backend/dynarmic/DynarmicTest.java similarity index 92% rename from unidbg-api/src/test/java/com/github/unidbg/arm/backend/dynarmic/DynarmicTest.java rename to unidbg-dynarmic/src/test/java/com/github/unidbg/arm/backend/dynarmic/DynarmicTest.java index 16320fbd7..4b5aef6b9 100644 --- a/unidbg-api/src/test/java/com/github/unidbg/arm/backend/dynarmic/DynarmicTest.java +++ b/unidbg-dynarmic/src/test/java/com/github/unidbg/arm/backend/dynarmic/DynarmicTest.java @@ -5,6 +5,10 @@ public class DynarmicTest extends TestCase { + static { + DynarmicLoader.useDynarmic(); + } + public void testInitialize() { try (Dynarmic dynarmic = new Dynarmic(true)) { dynarmic.mem_map(0x0, 0x1000, UnicornConst.UC_PROT_WRITE); diff --git a/unidbg-api/src/test/native/dynarmic/build.sh b/unidbg-dynarmic/src/test/native/dynarmic/build.sh similarity index 100% rename from unidbg-api/src/test/native/dynarmic/build.sh rename to unidbg-dynarmic/src/test/native/dynarmic/build.sh diff --git a/unidbg-api/src/test/native/dynarmic/main.cpp b/unidbg-dynarmic/src/test/native/dynarmic/main.cpp similarity index 100% rename from unidbg-api/src/test/native/dynarmic/main.cpp rename to unidbg-dynarmic/src/test/native/dynarmic/main.cpp diff --git a/unidbg-api/src/test/resources/log4j.properties b/unidbg-dynarmic/src/test/resources/log4j.properties similarity index 100% rename from unidbg-api/src/test/resources/log4j.properties rename to unidbg-dynarmic/src/test/resources/log4j.properties