9 /* This code is only for x86_64 */
13 void handle_segv(int segv, siginfo_t* siginfo, void* ucontext) {
14 ucontext_t* uc = (ucontext_t*) ucontext;
16 /* do disassembly at from IP */
19 ud_set_mode(&ud_obj, 64);
20 ud_set_syntax(&ud_obj, UD_SYN_ATT);
21 ud_set_input_buffer(&ud_obj, (unsigned char*) uc->uc_mcontext.gregs[REG_RIP],
24 /* was disassembly successful? */
25 if (!ud_disassemble(&ud_obj)) {
26 printf("Disassembly fail!\n");
30 /* is disassembly a memory-operation? */
31 struct ud_operand op0 = ud_obj.operand[0];
32 struct ud_operand op1 = ud_obj.operand[1];
35 if (op0.type == UD_OP_MEM) {
37 } else if (op1.type == UD_OP_MEM) {
40 printf("Instruction unknown\n");
44 /* find out the register - this part is clumsy as we have two sets
114 printf("Register not supported!\n");
118 /* set the register - as before */
119 uc->uc_mcontext.gregs[setreg] = (greg_t) &k;
122 void cause_segv (int* ptr) {
130 bzero(&q, sizeof(q));
131 q.sa_sigaction = handle_segv;
132 q.sa_flags = SA_SIGINFO;
133 sigaction(11, &q, NULL);