Java bindings (#709)
* Remove glib from samples makefile * support new APIs * reimplement register batch mode interface * stop using deprecated java API
This commit is contained in:

committed by
Nguyen Anh Quynh

parent
d00f773e8e
commit
21ffaf7d10
@ -58,8 +58,8 @@ public class Shellcode {
|
||||
|
||||
System.out.print(String.format("Tracing instruction at 0x%x, instruction size = 0x%x\n", address, size));
|
||||
|
||||
byte[] r_eip = u.reg_read(Unicorn.UC_X86_REG_EIP, 4);
|
||||
System.out.print(String.format("*** EIP = %x ***: ", toInt(r_eip)));
|
||||
Long r_eip = (Long)u.reg_read(Unicorn.UC_X86_REG_EIP);
|
||||
System.out.print(String.format("*** EIP = %x ***: ", r_eip.intValue()));
|
||||
|
||||
size = Math.min(16, size);
|
||||
|
||||
@ -73,8 +73,8 @@ public class Shellcode {
|
||||
|
||||
public static class MyInterruptHook implements InterruptHook {
|
||||
public void hook(Unicorn u, int intno, Object user) {
|
||||
long r_ecx;
|
||||
long r_edx;
|
||||
Long r_ecx;
|
||||
Long r_edx;
|
||||
int size;
|
||||
|
||||
// only handle Linux syscall
|
||||
@ -82,30 +82,30 @@ public class Shellcode {
|
||||
return;
|
||||
}
|
||||
|
||||
long r_eax = toInt(u.reg_read(Unicorn.UC_X86_REG_EAX, 4));
|
||||
long r_eip = toInt(u.reg_read(Unicorn.UC_X86_REG_EIP, 4));
|
||||
Long r_eax = (Long)u.reg_read(Unicorn.UC_X86_REG_EAX);
|
||||
Long r_eip = (Long)u.reg_read(Unicorn.UC_X86_REG_EIP);
|
||||
|
||||
switch ((int)r_eax) {
|
||||
switch (r_eax.intValue()) {
|
||||
default:
|
||||
System.out.print(String.format(">>> 0x%x: interrupt 0x%x, EAX = 0x%x\n", r_eip, intno, r_eax));
|
||||
System.out.print(String.format(">>> 0x%x: interrupt 0x%x, EAX = 0x%x\n", r_eip.intValue(), intno, r_eax.intValue()));
|
||||
break;
|
||||
case 1: // sys_exit
|
||||
System.out.print(String.format(">>> 0x%x: interrupt 0x%x, SYS_EXIT. quit!\n\n", r_eip, intno));
|
||||
System.out.print(String.format(">>> 0x%x: interrupt 0x%x, SYS_EXIT. quit!\n\n", r_eip.intValue(), intno));
|
||||
u.emu_stop();
|
||||
break;
|
||||
case 4: // sys_write
|
||||
// ECX = buffer address
|
||||
r_ecx = toInt(u.reg_read(Unicorn.UC_X86_REG_ECX, 4));
|
||||
r_ecx = (Long)u.reg_read(Unicorn.UC_X86_REG_ECX);
|
||||
|
||||
// EDX = buffer size
|
||||
r_edx = toInt(u.reg_read(Unicorn.UC_X86_REG_EDX, 4));
|
||||
r_edx = (Long)u.reg_read(Unicorn.UC_X86_REG_EDX);
|
||||
|
||||
// read the buffer in
|
||||
size = (int)Math.min(256, r_edx);
|
||||
|
||||
byte[] buffer = u.mem_read(r_ecx, size);
|
||||
System.out.print(String.format(">>> 0x%x: interrupt 0x%x, SYS_WRITE. buffer = 0x%x, size = %u, content = '%s'\n",
|
||||
r_eip, intno, r_ecx, r_edx, new String(buffer)));
|
||||
r_eip.intValue(), intno, r_ecx.intValue(), r_edx.intValue(), new String(buffer)));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -113,7 +113,7 @@ public class Shellcode {
|
||||
|
||||
static void test_i386()
|
||||
{
|
||||
long r_esp = ADDRESS + 0x200000; // ESP register
|
||||
Long r_esp = new Long(ADDRESS + 0x200000); // ESP register
|
||||
|
||||
System.out.print("Emulate i386 code\n");
|
||||
|
||||
@ -127,7 +127,7 @@ public class Shellcode {
|
||||
u.mem_write(ADDRESS, X86_CODE32_SELF);
|
||||
|
||||
// initialize machine registers
|
||||
u.reg_write(Unicorn.UC_X86_REG_ESP, toBytes(r_esp));
|
||||
u.reg_write(Unicorn.UC_X86_REG_ESP, r_esp);
|
||||
|
||||
// tracing all instructions by having @begin > @end
|
||||
u.hook_add(new MyCodeHook(), 1, 0, null);
|
||||
|
Reference in New Issue
Block a user