Update Java samples to match C samples.

Also add all of the samples as Java tests, referencing the output of the C
samples.
This commit is contained in:
Robert Xiao
2023-05-14 16:23:49 -07:00
parent 3739c7e3e0
commit 4f563490e2
25 changed files with 3884 additions and 906 deletions

View File

@@ -122,8 +122,6 @@ public class FunctionalityTests {
u.emu_stop();
}).start();
u.emu_start(ADDRESS, ADDRESS + X86_CODE.length, 0, 0);
u.close();
}
@Test
@@ -157,8 +155,6 @@ public class FunctionalityTests {
uc.context_restore(ctx);
assertEquals(0xfee1deadL, uc.reg_read(Unicorn.UC_ARM64_REG_X0));
assertEquals(0xfee1deadL, ctx.reg_read(Unicorn.UC_ARM64_REG_X0));
uc.close();
}
@Test
@@ -188,6 +184,5 @@ public class FunctionalityTests {
assertEquals(0xfee1deadL, uc.reg_read(Unicorn.UC_ARM64_REG_X0));
uc.free(ctx);
uc.close();
}
}

View File

@@ -59,7 +59,6 @@ public class HookTests {
// TODO(nneonneo): I don't totally understand this output! Why 8 bytes at address 5?
assertTranslationBlock(new TranslationBlock(ADDRESS + 5, 3, 8),
u.ctl_request_cache(ADDRESS + 5));
u.close();
}
@Test
@@ -84,8 +83,6 @@ public class HookTests {
u.ctl_tlb_mode(Unicorn.UC_TLB_VIRTUAL);
u.emu_start(ADDRESS, ADDRESS + X86_CODE32_MEM_READ.length, 0, 0);
assertEquals("ecx", u.reg_read(Unicorn.UC_X86_REG_ECX), 0x04030201);
u.close();
}
@Test
@@ -124,7 +121,5 @@ public class HookTests {
assertThrows(UnicornException.class, () -> u.hook_del(h1));
assertThrows(UnicornException.class, () -> u.hook_del(h3));
assertThrows(UnicornException.class, () -> u.hook_del(h4));
u.close();
}
}

View File

@@ -29,7 +29,6 @@ public class MemTests {
assertEquals("two memory regions", 2, arr.length);
assertMemRegion(ADDR1, 2 * 1024 * 1024, Unicorn.UC_PROT_ALL, arr[0]);
assertMemRegion(ADDR2, 4096, Unicorn.UC_PROT_READ, arr[1]);
uc.close();
}
@Test
@@ -71,8 +70,6 @@ public class MemTests {
assertMemRegion(0x230000, 0x10000, Unicorn.UC_PROT_READ, mrs[7]);
assertMemRegion(0x250000, 0x10000, Unicorn.UC_PROT_WRITE, mrs[8]);
assertMemRegion(0x270000, 0x10000, Unicorn.UC_PROT_NONE, mrs[9]);
u.close();
}
@Test
@@ -111,8 +108,6 @@ public class MemTests {
assertEquals("ecx", 0x44556679, u.reg_read(Unicorn.UC_X86_REG_ECX));
assertEquals("edx", 0x22334453, u.reg_read(Unicorn.UC_X86_REG_EDX));
u.close();
}
@Test
@@ -132,7 +127,5 @@ public class MemTests {
u.emu_start(ADDRESS, ADDRESS + X86_CODE32_MEM_WRITE.length, 0, 0);
assertEquals("buffer contents", 0x12345678, buffer.getInt(0xaaa));
u.close();
}
}

View File

@@ -33,7 +33,6 @@ public class RegTests {
assertEquals(Math.sin(Math.log(Math.E) / Math.log(2)), reg1.toDouble(),
1e-12);
assertEquals(reg1.toDouble(), reg2.toDouble(), 1e-12);
u.close();
}
@Test
@@ -51,7 +50,6 @@ public class RegTests {
u.emu_start(ADDRESS, ADDRESS + X86_CODE.length, 0, 0);
reg = (X86_Float80) u.reg_read(Unicorn.UC_X86_REG_ST0, null);
assertEquals(Math.sin(-1.1), reg.toDouble(), 1e-12);
u.close();
}
@Test
@@ -104,8 +102,6 @@ public class RegTests {
b[0x70] = -0x80;
uc.reg_write(reg, new BigInteger(b));
assertEquals("write untrimmed value", b127, uc.reg_read(reg, null));
uc.close();
}
@Test
@@ -144,8 +140,6 @@ public class RegTests {
assertEquals("v0.8h = v1.8h + v2.8h",
new BigInteger("4860570d497678b4a5728c3e34a5f85c", 16),
uc.reg_read(Unicorn.UC_ARM64_REG_V0, null));
uc.close();
}
@Test
@@ -200,7 +194,5 @@ public class RegTests {
uc.reg_read(Unicorn.UC_ARM64_REG_X1));
assertEquals("X1 low bits should be unchanged", 0x0000bbbbccccddddL,
uc.reg_read(Unicorn.UC_ARM64_REG_X1) & 0xffffffffffffL);
uc.close();
}
}

View File

@@ -24,7 +24,6 @@ public class RegressionTests {
uc.reg_read(Unicorn.UC_ARM64_REG_B0));
assertEquals("V0 low halfword", 0x1234,
uc.reg_read(Unicorn.UC_ARM64_REG_H0));
uc.close();
}
/** Test for GH #1164: Java binding use CodeHook on Windows, will invoke callback before every instruction */

File diff suppressed because it is too large Load Diff