+ *to_patch = patchme - (from + 5);
+ printf("*to_patch: 0x%08x\n", *to_patch);
+ mctx->gregs[REG_EIP] = (unsigned long) insn;
+}
+
+void staticfieldtrap(int nSignal, siginfo_t *info, void *ctx)
+{
+ /* TODO(bernhard): more generic and cleaner please... */
+ mcontext_t *mctx = &((ucontext_t *) ctx)->uc_mcontext;
+ 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);
+ }
+ unsigned int method_table_ptr = (unsigned int) mctx->gregs[REG_EAX];
+ unsigned int *esp = (unsigned int *) mctx->gregs[REG_ESP];
+ /* get actual eip from stack storage */
+ unsigned int from = (*esp) - 3;
+ 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);
+ *to_patch = getMethodEntry(from, method_table_ptr);
+ mctx->gregs[REG_EIP] = *to_patch;
+ printf("*to_patch: 0x%08x\n", *to_patch);
+ } else {
+ unsigned int *to_patch = (unsigned int *) (from + 2);
+ printf("staticfieldtrap by 0x%08x\n", from);
+ if (*to_patch != 0x00000000) {
+ printf("staticfieldtrap: something is wrong here. abort\n");