Skip to content

Commit

Permalink
Test changes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
tushar3q34 committed Feb 1, 2025
1 parent 187ebe4 commit 478ea91
Show file tree
Hide file tree
Showing 29 changed files with 610 additions and 548 deletions.
10 changes: 8 additions & 2 deletions librz/arch/isa/x86/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const char *x86_registers[ZYDIS_REGISTER_MAX_VALUE] = {
[ZYDIS_REGISTER_ES] = "es",
[ZYDIS_REGISTER_ESI] = "esi",
[ZYDIS_REGISTER_ESP] = "esp",
//[ZYDIS_REGISTER_X87STATUS] = "swd",
[ZYDIS_REGISTER_X87STATUS] = "swd",
[ZYDIS_REGISTER_FS] = "fs",
[ZYDIS_REGISTER_GS] = "gs",
[ZYDIS_REGISTER_IP] = "ip",
Expand Down Expand Up @@ -700,7 +700,7 @@ RZ_IPI RzILOpPure *x86_il_get_memaddr_segment_bits(X86Mem mem, X86Reg segment, i
}

/* Segmentation not present in x86-64 */
if (bits != 64 && segment != ZYDIS_REGISTER_NONE) {
if (bits == 16 && segment != ZYDIS_REGISTER_NONE) {
// TODO: Implement segmentation
/* Currently the segmentation is only implemented for real mode
Address = Segment * 0x10 + Offset */
Expand Down Expand Up @@ -745,7 +745,13 @@ RZ_IPI RzILOpPure *x86_il_get_operand_bits(X86Op op, int analysis_bits, ut64 pc,
return SN((op.size != 0 ? op.size : implicit_size) * BITS_PER_BYTE, imm_value(op, pc));
case ZYDIS_OPERAND_TYPE_MEMORY:
return LOADW((op.size != 0 ? op.size : implicit_size) * BITS_PER_BYTE, x86_il_get_memaddr_bits(op.mem, analysis_bits, pc));
case ZYDIS_OPERAND_TYPE_POINTER:
RzILOpPure *offset = UN(analysis_bits, op.ptr.offset);
RzILOpPure *segment = UN(analysis_bits, op.ptr.segment);
offset = ADD(offset, SHIFTL0(UNSIGNED(analysis_bits, segment), U8(4)));
return LOADW((op.size != 0 ? op.size : implicit_size) * BITS_PER_BYTE, offset);
default:
printf("SHOULD NOT REACH\n");
return NULL;
}
}
Expand Down
118 changes: 61 additions & 57 deletions librz/arch/isa/x86/il_ops.inc
Original file line number Diff line number Diff line change
Expand Up @@ -373,45 +373,45 @@ RzILOpEffect *x86_il_cmp_helper(const X86ILIns *ins, ut64 pc, RzAnalysis *analys

RzILOpPure *get_cmov_cond(X86InsMnem ins) {
switch (ins) {
// case ZYDIS_MNEMONIC_CMOVA:
// /* Same as CMOVNBE */
// /* CF = 0 and ZF = 0 */
// return AND(INV(VARG(EFLAGS(CF))), INV(VARG(EFLAGS(ZF))));
// case ZYDIS_MNEMONIC_CMOVAE:
// /* Same as CMOVNB, CMOVNC */
// /* CF = 0 */
// return INV(VARG(EFLAGS(CF)));
case ZYDIS_MNEMONIC_CMOVNBE:
/* Same as CMOVNBE */
/* CF = 0 and ZF = 0 */
return AND(INV(VARG(EFLAGS(CF))), INV(VARG(EFLAGS(ZF))));
case ZYDIS_MNEMONIC_CMOVNB:
/* Same as CMOVNB, CMOVNC */
/* CF = 0 */
return INV(VARG(EFLAGS(CF)));
case ZYDIS_MNEMONIC_CMOVB:
/* Same as CMOVC, CMOVNAE */
/* CF = 1 */
return VARG(EFLAGS(CF));
// case ZYDIS_MNEMONIC_CMOVBE:
// /* Same as CMOVNA */
// /* CF = 1 or ZF = 1*/
// return OR(VARG(EFLAGS(CF)), VARG(EFLAGS(ZF)));
// case ZYDIS_MNEMONIC_CMOVE:
// /* Same as CMOVZ */
// /* ZF = 1 */
// return VARG(EFLAGS(ZF));
// case ZYDIS_MNEMONIC_CMOVG:
// /* Same as CMOVNLE */
// /* ZF = 0 and SF = OF */
// return AND(INV(VARG(EFLAGS(ZF))), INV(XOR(VARG(EFLAGS(SF)), VARG(EFLAGS(OF)))));
// case ZYDIS_MNEMONIC_CMOVGE:
// /* Same CMOVNL */
// /* SF = OF */
// return INV(XOR(VARG(EFLAGS(SF)), VARG(EFLAGS(OF))));
case ZYDIS_MNEMONIC_CMOVBE:
/* Same as CMOVNA */
/* CF = 1 or ZF = 1*/
return OR(VARG(EFLAGS(CF)), VARG(EFLAGS(ZF)));
case ZYDIS_MNEMONIC_CMOVZ:
/* Same as CMOVZ */
/* ZF = 1 */
return VARG(EFLAGS(ZF));
case ZYDIS_MNEMONIC_CMOVNLE:
/* Same as CMOVNLE */
/* ZF = 0 and SF = OF */
return AND(INV(VARG(EFLAGS(ZF))), INV(XOR(VARG(EFLAGS(SF)), VARG(EFLAGS(OF)))));
case ZYDIS_MNEMONIC_CMOVNL:
/* Same CMOVNL */
/* SF = OF */
return INV(XOR(VARG(EFLAGS(SF)), VARG(EFLAGS(OF))));
case ZYDIS_MNEMONIC_CMOVL:
/* SF != OF */
return XOR(VARG(EFLAGS(SF)), VARG(EFLAGS(OF)));
case ZYDIS_MNEMONIC_CMOVLE:
/* Same as CMOVNG */
/* ZF = 1 or SF != OF */
return OR(VARG(EFLAGS(ZF)), XOR(VARG(EFLAGS(SF)), VARG(EFLAGS(OF))));
// case ZYDIS_MNEMONIC_CMOVNE:
// /* Same as CMOVNZ */
// /* ZF = 0 */
// return INV(VARG(EFLAGS(ZF)));
case ZYDIS_MNEMONIC_CMOVNZ:
/* Same as CMOVNZ */
/* ZF = 0 */
return INV(VARG(EFLAGS(ZF)));
case ZYDIS_MNEMONIC_CMOVNO:
/* OF = 0 */
return INV(VARG(EFLAGS(OF)));
Expand Down Expand Up @@ -2324,46 +2324,46 @@ IL_LIFTER(test) {
* Wait until not busy
* ZO
*/
// IL_LIFTER(wait) {
// /* NOP seems to be a reasonable implementation */
// return NOP();
// }
IL_LIFTER(fwait) {
/* NOP seems to be a reasonable implementation */
return NOP();
}

/**
* XCHG
* Exchange data
* Encoding: O, MR, RM
*/
// IL_LIFTER(xchg) {
// RzILOpEffect *temp = SETL("_temp", x86_il_get_op(0));
// RzILOpEffect *xchg = x86_il_set_op(0, x86_il_get_op(1));
// RzILOpEffect *set_src = x86_il_set_op(1, VARL("_temp"));
//
// return SEQ3(temp, xchg, set_src);
// }
IL_LIFTER(xchg) {
RzILOpEffect *temp = SETL("_temp", x86_il_get_op(0));
RzILOpEffect *xchg = x86_il_set_op(0, x86_il_get_op(1));
RzILOpEffect *set_src = x86_il_set_op(1, VARL("_temp"));

return SEQ3(temp, xchg, set_src);
}

/**
* XLATB
* Table look-up translation
* Encoding: ZO
*/
// IL_LIFTER(xlatb) {
// X86Mem mem;
// mem.disp.value = 0;
// mem.index = ZYDIS_REGISTER_NONE;
// mem.scale = 1;
// mem.segment = ZYDIS_REGISTER_DS;
// mem.base = ZYDIS_REGISTER_EBX;
//
// if (analysis->bits == 64) {
// mem.segment = ZYDIS_REGISTER_NONE;
// mem.base = ZYDIS_REGISTER_RBX;
// } else if (analysis->bits == 16) {
// mem.base = ZYDIS_REGISTER_BX;
// }
//
// return x86_il_set_reg(ZYDIS_REGISTER_AL, LOADW(8, ADD(x86_il_get_memaddr(mem), UNSIGNED(analysis->bits, x86_il_get_reg(ZYDIS_REGISTER_AL)))));
// }
IL_LIFTER(xlat) {
X86Mem mem;
mem.disp.value = 0;
mem.index = ZYDIS_REGISTER_NONE;
mem.scale = 1;
mem.segment = ZYDIS_REGISTER_DS;
mem.base = ZYDIS_REGISTER_EBX;

if (analysis->bits == 64) {
mem.segment = ZYDIS_REGISTER_NONE;
mem.base = ZYDIS_REGISTER_RBX;
} else if (analysis->bits == 16) {
mem.base = ZYDIS_REGISTER_BX;
}

return x86_il_set_reg(ZYDIS_REGISTER_AL, LOADW(8, ADD(x86_il_get_memaddr(mem), UNSIGNED(analysis->bits, x86_il_get_reg(ZYDIS_REGISTER_AL)))));
}

/**
* XOR
Expand Down Expand Up @@ -2394,7 +2394,11 @@ IL_LIFTER(bound) {

X86Mem mem = ins->operands[1].mem;
RzILOpEffect *lower = SETL("_lower", LOADW(ins->operands[0].size * BITS_PER_BYTE, x86_il_get_memaddr(mem)));
mem.disp.value += ins->operands[1].size / mem.scale;
if (mem.scale != 0) {
mem.disp.value += ins->operands[1].size / mem.scale;
} else {
mem.disp.value += ins->operands[1].size;
}
RzILOpEffect *upper = SETL("_upper", LOADW(ins->operands[0].size * BITS_PER_BYTE, x86_il_get_memaddr(mem)));

RzILOpBool *cond = OR(ULT(VARL("_index"), VARL("_lower")), UGT(VARL("_index"), VARL("_upper")));
Expand Down
7 changes: 4 additions & 3 deletions librz/arch/isa/x86/x86_il.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ x86_il_ins x86_ins[ZYDIS_MNEMONIC_MAX_VALUE] = {
[ZYDIS_MNEMONIC_STOSW] = x86_il_stosw,
[ZYDIS_MNEMONIC_SUB] = x86_il_sub,
[ZYDIS_MNEMONIC_TEST] = x86_il_test,
//[ZYDIS_MNEMONIC_WAIT] = x86_il_wait,
//[ZYDIS_MNEMONIC_XCHG] = x86_il_xchg,
//[ZYDIS_MNEMONIC_XLATB] = x86_il_xlatb,
[ZYDIS_MNEMONIC_FWAIT] = x86_il_fwait,
[ZYDIS_MNEMONIC_XCHG] = x86_il_xchg,
[ZYDIS_MNEMONIC_XLAT] = x86_il_xlat,
[ZYDIS_MNEMONIC_XOR] = x86_il_xor,
[ZYDIS_MNEMONIC_BOUND] = x86_il_bound,
[ZYDIS_MNEMONIC_ENTER] = x86_il_enter,
Expand Down Expand Up @@ -363,6 +363,7 @@ RZ_IPI bool rz_x86_il_opcode(RZ_NONNULL RzAnalysis *analysis, RZ_NONNULL RzAnaly
}

aop->il_op = lifted;
// printf("\n");
return true;
}

Expand Down
Loading

0 comments on commit 478ea91

Please sign in to comment.