static int cmd_info_r() { int i; for (i = 0; i < 8; i++) { printf("%s\t%#10x\t%10d\t", regsl[i], reg_l(i), reg_l(i)); printf("%s\t%#6x\t%5d", regsw[i], reg_w(i), reg_w(i)); if (i < 4) { printf("\t%s\t%#4x\t%3d\t", regsb[i|4], reg_b(i|4), reg_b(i|4)); printf("%s\t%#4x\t%3d\n", regsb[i], reg_b(i), reg_b(i)); } else printf("\n"); } for (i = 0; i < 6; i++) { printf("%s\t%#6x: base = %#10x, limit = %#10x\n", regss[i], cpu.sr[i].sel, cpu.sr[i].base, cpu.sr[i].limit); } printf("eflags\t%#10x [%s%s%s%s%s%s%s ]\n", cpu.eflags, cpu.cf ? "CF" : "", cpu.pf ? "PF" : "", cpu.zf ? "ZF" : "", cpu.sf ? "SF" : "", cpu.ief? "IF" : "", cpu.df ? "DF" : "", cpu.of ? "OF" : "" ); printf("eip\t%#10x\n", cpu.eip); printf("cr0\t%#10x\tcr3\t%#10x\n", cpu.cr0.value, cpu.cr3); printf("gdtr:\tbase = %#10x, limit = %#10x\nidtr:\tbase = %#10x, limit = %#10x\n", cpu.gdtr.base, cpu.gdtr.limit, cpu.idtr.base, cpu.idtr.limit); return 0; }
static int cmd_info(char *args) { int i; if(strcmp(args, "r") == 0) { for(i=0;i<8;i++){ printf("%s-%08x\n", regsl[i], reg_l(i)); } for(i=0;i<8;i++){ printf("%s-%04x\n", regsw[i], reg_w(i)); } for(i=0;i<8;i++){ printf("%s-%02x\n", regsb[i], reg_b(i)); } printf("eip-%x\n", cpu.eip); } else if( strcmp(args, "w") == 0 ){ WP* temp = head; while(temp != NULL){ printf("%d, %s, %d\n", temp->NO, temp->addr, temp->old_value); temp = temp->next; } } else printf("Something's wrong:-(\n"); return 0; }
int read_ModR_M(swaddr_t eip, Operand *rm, Operand *reg) { ModR_M m; m.val = instr_fetch(eip, 1); // Log("m.val = %02x", m.val); reg->type = OP_TYPE_REG; reg->reg = m.reg; if(m.mod == 3) { rm->type = OP_TYPE_REG; rm->reg = m.R_M; switch(rm->size) { case 1: rm->val = reg_b(m.R_M); break; case 2: rm->val = reg_w(m.R_M); break; case 4: rm->val = reg_l(m.R_M); break; default: assert(0); } #ifdef DEBUG switch(rm->size) { case 1: sprintf(rm->str, "%%%s", regsb[m.R_M]); break; case 2: sprintf(rm->str, "%%%s", regsw[m.R_M]); break; case 4: sprintf(rm->str, "%%%s", regsl[m.R_M]); break; } #endif return 1; } else { int instr_len = load_addr(eip, &m, rm); rm->val = swaddr_read(rm->addr, rm->size, R_DS); //TODO DS or SS return instr_len; } }
static int cmd_info(char *args) { int i; if(args == NULL) { printf("no input!"); return 0; } if(args[0] == 'r') { for(i = R_EAX; i <= R_EDI; i ++) { printf("%s = 0x%08x\n", regsl[i], reg_l(i)); } /* for(i = R_AX; i <= R_DI; i ++) { printf("%s = 0x%04x\n", regsw[i], reg_w(i)); } for(i = R_AL; i <= R_BH; i ++) { printf("%s = 0x%02x\n", regsb[i], reg_b(i)); }*/ printf("PF = %d\n", cpu.PF); printf("OF = %d\n", cpu.OF); printf("CF = %d\n", cpu.CF); printf("SF = %d\n", cpu.SF); printf("ZF = %d\n", cpu.ZF); } else if(args[0] == 'w') { print_wp_info(); } return 0; }
static int cmd_info(char *args) { char command; if(args == NULL){ printf("please input arguments\n"); return 0; } if(sscanf(args,"%c",&command) != 1){ printf("wrong argument\n"); return 0; } if(command == 'r'){ //print the rigisters int i = 0; for(i = 0;i < 8; ++i){ printf("%s\t0x%x\t\t%u\n",regsl[i],reg_l(i),reg_l(i)); } for(i = 0;i < 8; ++i){ printf("%s\t0x%x\t\t%u\n",regsw[i],reg_w(i),reg_w(i)); } for(i = 0;i < 8; ++i){ printf("%s\t0x%x\t\t%u\n",regsb[i],reg_b(i),reg_b(i)); } printf("eip\t0x%x\t%d\n",cpu.eip,cpu.eip); printf("eflags\t0x%8x\t%d\n",cpu.eflags, cpu.eflags); printf("CF\t%x\n",cpu.CF); printf("PF\t%x\n",cpu.PF); printf("ZF\t%x\n",cpu.ZF); printf("SF\t%x\n",cpu.SF); printf("IF\t%x\n",cpu.IF); printf("DF\t%x\n",cpu.DF); printf("OF\t%x\n",cpu.OF); }else if(command == 'w'){ //打印监视点信息 print_wp(); }else{ printf("Unknown command: info %c\n",command); } return 0; }
static int cmd_info(char*args){ unsigned char*res=NULL; char *arg=strtok(NULL," "); if(arg==NULL){ printf("No Argument!\n"); } if(strcmp(arg,"r")==0) { int i; /*output eip*/ res = (unsigned char*)(&cpu.eip); printf("eip:%02x %02x %02x %02x\n",*(res+3),*(res+2),*(res+1),*res); for(i=R_EAX;i<=R_EDI;i++) { res =(unsigned char*)(®_l(i)); printf("%s:%02x %02x %02x %02x\n",regsl[i],*(res+3),*(res+2),*(res+1),*res); } res = (unsigned char*)(&cpu.GDTR.base); printf("%s:%02x %02x %02x %02x","GDTR",*(res+3),*(res+2),*(res+1),*res); res = (unsigned char*)(&cpu.GDTR.limit); printf(" %02x %02x\n",*(res+1),*res); res = (unsigned char*)(&cpu.cr0.val); printf("%s:%02x %02x %02x %02x\n","CR0",*(res+3),*(res+2),*(res+1),*res); for(i = R_ES; i <= R_DS; i ++){ res = (unsigned char*)(&sreg(i)); printf("%s:%02x %02x\n",sregs[i],*(res + 1),*res); } printf("%s %s %s %s %s %s\n","OF","SF","ZF","AF","PF","CF"); printf("%2d %2d %2d %2d %2d %2d\n",cpu.OF,cpu.SF,cpu.ZF,cpu.AF,cpu.PF,cpu.CF); } else if(strcmp(arg,"w")==0) print_wp(); else printf("No Such Command!\n"); return 0; }
int load_addr(swaddr_t eip, ModR_M *m, Operand *rm) { assert(m->mod != 3); int32_t disp; int instr_len, disp_offset, disp_size = 4; int base_reg = -1, index_reg = -1, scale = 0; swaddr_t addr = 0; if(m->R_M == R_ESP) { SIB s; s.val = instr_fetch(eip + 1, 1); base_reg = s.base; disp_offset = 2; scale = s.ss; if(s.index != R_ESP) { index_reg = s.index; } /* if (s.ss==0&&s.index==R_EBP){ rm->sreg=R_SS; } */ } else { /* no SIB */ base_reg = m->R_M; disp_offset = 1; } if (base_reg==R_ESP||base_reg==R_EBP){ rm->sreg=R_SS; }else{ rm->sreg=R_DS; } if(m->mod == 0) { if(base_reg == R_EBP) { base_reg = -1; } else { disp_size = 0; } } else if(m->mod == 1) { disp_size = 1; } instr_len = disp_offset; if(disp_size != 0) { /* has disp */ disp = instr_fetch(eip + disp_offset, disp_size); if(disp_size == 1) { disp = (int8_t)disp; } instr_len += disp_size; addr += disp; } if(base_reg != -1) { addr += reg_l(base_reg); } if(index_reg != -1) { addr += reg_l(index_reg) << scale; } #ifdef DEBUG char disp_buf[16]; char base_buf[8]; char index_buf[8]; if(disp_size != 0) { /* has disp */ sprintf(disp_buf, "%s%#x", (disp < 0 ? "-" : ""), (disp < 0 ? -disp : disp)); } else { disp_buf[0] = '\0'; } if(base_reg == -1) { base_buf[0] = '\0'; } else { sprintf(base_buf, "%%%s", regsl[base_reg]); } if(index_reg == -1) { index_buf[0] = '\0'; } else { sprintf(index_buf, ",%%%s,%d", regsl[index_reg], 1 << scale); } if(base_reg == -1 && index_reg == -1) { sprintf(rm->str, "%s", disp_buf); } else { sprintf(rm->str, "%s(%s%s)", disp_buf, base_buf, index_buf); } #endif rm->type = OP_TYPE_MEM; rm->addr = addr; return instr_len; }
/* For more details about instruction format, please refer to i386 manual. */ int read_ModR_M(swaddr_t eip, swaddr_t *addr) { ModR_M m; m.val = instr_fetch(eip, 1); int32_t disp; int instr_len, disp_offset, disp_size; int base_reg = -1, index_reg = -1, scale = 0; /* When m.mod == 3, the instruction is not going to access memory. * This situation should be handle before calling read_ModR_M(). * Therefore, m.mod should not be 3 here. */ assert(m.mod != 3); disp_size = 4; if(m.R_M == R_ESP) { SIB s; s.val = instr_fetch(eip + 1, 1); base_reg = s.base; disp_offset = 2; scale = s.ss; if(s.index != R_ESP) { index_reg = s.index; } } else { /* no SIB */ base_reg = m.R_M; disp_offset = 1; } if(m.mod == 0) { if(base_reg == R_EBP) { base_reg = -1; } else { disp_size = 0; } } else if(m.mod == 1) { disp_size = 1; } char disp_buf[16]; char base_buf[8]; char index_buf[8]; instr_len = disp_offset; *addr = 0; if(disp_size != 0) { /* has disp */ disp = instr_fetch(eip + disp_offset, disp_size); if(disp_size == 1) { disp = (int8_t)disp; } sprintf(disp_buf, "%s%#x", (disp < 0 ? "-" : ""), (disp < 0 ? -disp : disp)); instr_len += disp_size; *addr += disp; } else { disp_buf[0] = '\0'; } if(base_reg == -1) { base_buf[0] = '\0'; } else { sprintf(base_buf, "%%%s", regsl[base_reg]); *addr += reg_l(base_reg); } if(index_reg == -1) { index_buf[0] = '\0'; } else { sprintf(index_buf, ",%%%s,%d", regsl[index_reg], 1 << scale); *addr += reg_l(index_reg) << scale; } if(base_reg == -1 && index_reg == -1) { print_ModR_M_asm("%s", disp_buf); } else { print_ModR_M_asm("%s(%s%s)", disp_buf, base_buf, index_buf); } return instr_len; }
static void cmd_i(char* arg) { if(!arg) { puts("\"info\" must be followed by the name of an info command."); puts("List of info subcommands:\n"); puts("info registers -- List of integer registers and their contents"); puts("info breakpoints -- List of the information of breakpoints"); } else if(strcmp(arg, "r") == 0) { printf("eax\t0x%08x\t%d\n", reg_l(R_EAX), reg_l(R_EAX)); printf("ecx\t0x%08x\t%d\n", reg_l(R_ECX), reg_l(R_ECX)); printf("edx\t0x%08x\t%d\n", reg_l(R_EDX), reg_l(R_EDX)); printf("ebx\t0x%08x\t%d\n", reg_l(R_EBX), reg_l(R_EBX)); printf("esp\t0x%08x\t0x%08x\n", reg_l(R_ESP), reg_l(R_ESP)); printf("ebp\t0x%08x\t0x%08x\n", reg_l(R_EBP), reg_l(R_EBP)); printf("esi\t0x%08x\t%d\n", reg_l(R_ESI), reg_l(R_ESI)); printf("edi\t0x%08x\t%d\n", reg_l(R_EDI), reg_l(R_EDI)); printf("eip\t0x%08x\t0x%08x\n", cpu.eip, cpu.eip); printf("eflags\t0x%x\t\t[", cpu.eflags.value); int i = B_CF; for( ; i <= B_VM; ++i) { if((i != 1) && ((cpu.eflags.value >> i) & 1)) { printf(" %s", regf[i]); } } puts(" ]"); } else if(strcmp(arg, "b") == 0) {