unsigned int getMethodEntry(unsigned int, unsigned int);
unsigned int getStaticFieldAddr(unsigned int, void*);
+#ifdef DEBUG
+#define dprintf(args...) do { printf (args); } while (0);
+#else
+#define dprintf(args...)
+#endif
+
#define NEW_MAP(prefix) \
void* prefix ## _map = NULL; \
void set_ ## prefix ## map(void *map) \
{ \
- printf("set_%s: 0x%08x\n", #prefix , (unsigned int) map); \
+ dprintf("set_%s: 0x%08x\n", #prefix , (unsigned int) map); \
prefix ## _map = map; \
} \
void *get_ ## prefix ## map() \
{ \
- printf("get_%s: 0x%08x\n", #prefix , (unsigned int) prefix ## _map); \
+ dprintf("get_%s: 0x%08x\n", #prefix , (unsigned int) prefix ## _map); \
return prefix ## _map; \
}
void mainresult(unsigned int a)
{
- printf("mainresult: 0x%08x\n", a);
+ dprintf("mainresult: 0x%08x\n", a);
}
void callertrap(int nSignal, siginfo_t *info, void *ctx)
mcontext_t *mctx = &((ucontext_t *) ctx)->uc_mcontext;
unsigned int from = (unsigned int) mctx->gregs[REG_EIP] - 2;
unsigned int *to_patch = (unsigned int *) (from + 1);
- printf("callertrap(mctx) by 0x%08x\n", from);
+ dprintf("callertrap(mctx) by 0x%08x\n", from);
if (*to_patch != 0x90ffff90) {
- printf("callertrap: something is wrong here. abort\n");
+ dprintf("callertrap: something is wrong here. abort\n");
exit(0);
}
unsigned int patchme = getMethodEntry(from, 0);
unsigned char *insn = (unsigned char *) from;
*insn = 0xe8; // call opcode
- printf(" to_patch: 0x%08x\n", (unsigned int) to_patch);
- printf("*to_patch: 0x%08x\n", *to_patch);
+ dprintf(" to_patch: 0x%08x\n", (unsigned int) to_patch);
+ dprintf("*to_patch: 0x%08x\n", *to_patch);
*to_patch = patchme - (from + 5);
- printf("*to_patch: 0x%08x\n", *to_patch);
+ dprintf("*to_patch: 0x%08x\n", *to_patch);
mctx->gregs[REG_EIP] = (unsigned long) insn;
}
unsigned int from = (unsigned int) mctx->gregs[REG_EIP];
if (from < 0x10000) { // invokevirtual
if (from > 0) {
- printf("from: 0x%08x but should be 0 :-(\n", from);
+ dprintf("from: 0x%08x but should be 0 :-(\n", from);
}
unsigned int method_table_ptr = (unsigned int) mctx->gregs[REG_EAX];
unsigned int *esp = (unsigned int *) mctx->gregs[REG_ESP];
unsigned char offset = *((unsigned char *) (*esp) - 1);
/* method entry to patch */
unsigned int *to_patch = (unsigned int*) (method_table_ptr + offset);
- printf("invokevirtual by 0x%08x with offset 0x%08x\n", from, offset);
- printf(" to_patch: 0x%08x\n", (unsigned int) to_patch);
- printf("*to_patch: 0x%08x\n", *to_patch);
+ dprintf("invokevirtual by 0x%08x with offset 0x%08x\n", from, offset);
+ dprintf(" to_patch: 0x%08x\n", (unsigned int) to_patch);
+ dprintf("*to_patch: 0x%08x\n", *to_patch);
*to_patch = getMethodEntry(from, method_table_ptr);
mctx->gregs[REG_EIP] = *to_patch;
- printf("*to_patch: 0x%08x\n", *to_patch);
+ dprintf("*to_patch: 0x%08x\n", *to_patch);
} else {
unsigned int *to_patch = (unsigned int *) (from + 2);
- printf("staticfieldtrap by 0x%08x\n", from);
+ dprintf("staticfieldtrap by 0x%08x\n", from);
if (*to_patch != 0x00000000) {
- printf("staticfieldtrap: something is wrong here. abort\n");
+ dprintf("staticfieldtrap: something is wrong here. abort\n");
exit(0);
}
unsigned int patchme = getStaticFieldAddr(from, trap_map);
- printf(" to_patch: 0x%08x\n", (unsigned int) to_patch);
- printf("*to_patch: 0x%08x\n", *to_patch);
+ dprintf(" to_patch: 0x%08x\n", (unsigned int) to_patch);
+ dprintf("*to_patch: 0x%08x\n", *to_patch);
*to_patch = patchme;
- printf("*to_patch: 0x%08x\n", *to_patch);
+ dprintf("*to_patch: 0x%08x\n", *to_patch);
}
}