Capstone Disassembler Java绑定:“无效的内存访问”

时间:2018-11-28 15:40:35

标签: java windows dll capstone

我正在使用Capstone反汇编程序的Java bindings。当我运行代码示例

import capstone.Capstone;
import org.junit.Test;

public class DisassemblerTest
{
    private static byte[] CODE = {0x55, 0x48, (byte) 0x8b, 0x05, (byte) 0xb8,
            0x13, 0x00, 0x00};

    @Test
    public void testDisassembler()
    {
        Capstone cs = new Capstone(Capstone.CS_ARCH_X86, Capstone.CS_MODE_64);
        Capstone.CsInsn[] allInsn = cs.disasm(CODE, 0x1000);
        for (Capstone.CsInsn anAllInsn : allInsn)
        {
            System.out.printf("0x%x:\t%s\t%s\n", anAllInsn.address,
                    anAllInsn.mnemonic, anAllInsn.opStr);
        }
    }
}

我得到一个Error

java.lang.Error: Invalid memory access

    at com.sun.jna.Native.invokeInt(Native Method)
    at com.sun.jna.Function.invoke(Function.java:425)
    at com.sun.jna.Function.invoke(Function.java:360)
    at com.sun.jna.Library$Handler.invoke(Library.java:244)
    at capstone.$Proxy7.cs_disasm(Unknown Source)
    at capstone.Capstone.disasm(Capstone.java:457)
    at capstone.Capstone.disasm(Capstone.java:442)
    at DisassemblerTest.testDisassembler(DisassemblerTest.java:13)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:349)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:314)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:312)
    at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:292)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:396)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
    at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)

我的maven依赖项是:

<dependency>
    <groupId>com.github.transcurity</groupId>
    <artifactId>capstone</artifactId>
    <version>LATEST</version> <!-- 3.0.5-rc2 -->
</dependency>

请注意,我在项目的根目录中提供了capstone.dll,并已找到它。否则,将收到UnsatisfiedLinkError。我确保它是最新的DLL,但仍然无法使用。奇怪的是,它在they didn't make an update since July 2018和{{3}}之前都有效。

1 个答案:

答案 0 :(得分:0)

没关系,it seems to be an issue with a newer JDK。我最近切换到MessagingCenter.Subscribe<App>(this, "OnSleep", (sender) => { startSound.stop(); }); 。解决方法是等到JDK 11支持Capstone及更高版本或使用Java 9来解决,这确实是一个Java 8错误。