I'm using the Java bindings of the Capstone
disassembler. When I run the code example
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);
}
}
}
I'm getting an 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)
My maven
dependency is:
<dependency>
<groupId>com.github.transcurity</groupId>
<artifactId>capstone</artifactId>
<version>LATEST</version> <!-- 3.0.5-rc2 -->
</dependency>
Note that I supplied the capstone.dll
in the root of my project and it is found. Otherwise one would receive an UnsatisfiedLinkError
. I made sure it's the latest DLL
available but it still doesn't work. Strange enough, it worked before and they didn't make an update since July 2018.
Nevermind, it seems to be an issue with a newer JDK. I recently switched to JDK 11
. The fix is to wait till Capstone
supports Java 9
and higher or to use Java 8
so indeed it's a Capstone
bug.
EDIT:
This issue is now fixed.