Пример #1
0
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;
}
Пример #2
0
/*
 * @describe get the value of the reg
 * @param {string} reg
 * @return {uint32_t}
 */
uint32_t getreg(char* reg) {
    uint32_t res;
    if(!strcmp(reg, "$eax")) res = cpu.eax;
    else if(!strcmp(reg, "$ecx")) res = cpu.ecx;
    else if(!strcmp(reg, "$edx")) res = cpu.edx;
    else if(!strcmp(reg, "$ebx")) res = cpu.ebx;
    else if(!strcmp(reg, "$esp")) res = cpu.esp;
    else if(!strcmp(reg, "$ebp")) res = cpu.ebp;
    else if(!strcmp(reg, "$esi")) res = cpu.esi;
    else if(!strcmp(reg, "$edi")) res = cpu.edi;

    else if(!strcmp(reg, "$eip")) res = cpu.eip;

    else if(!strcmp(reg, "$ax")) res = reg_w(0);
    else if(!strcmp(reg, "$cx")) res = reg_w(1);
    else if(!strcmp(reg, "$dx")) res = reg_w(2);
    else if(!strcmp(reg, "$bx")) res = reg_w(3);
    else if(!strcmp(reg, "$sp")) res = reg_w(4);
    else if(!strcmp(reg, "$bp")) res = reg_w(5);
    else if(!strcmp(reg, "$si")) res = reg_w(6);
    else if(!strcmp(reg, "$di")) res = reg_w(7);

    else if(!strcmp(reg, "$al")) res = reg_b(0);
    else if(!strcmp(reg, "$cl")) res = reg_b(1);
    else if(!strcmp(reg, "$dl")) res = reg_b(2);
    else if(!strcmp(reg, "$bl")) res = reg_b(3);
    else if(!strcmp(reg, "$ah")) res = reg_b(4);
    else if(!strcmp(reg, "$ch")) res = reg_b(5);
    else if(!strcmp(reg, "$dh")) res = reg_b(6);
    else if(!strcmp(reg, "$bh")) res = reg_b(7);

    else assert(0);
    return res;
}
Пример #3
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;
}
Пример #4
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;
	}
}
Пример #5
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;
}