?? decode.c
字號:
case 6: DECODE_PRINTF("ESI]"); return M.x86.R_ESI * index; case 7: DECODE_PRINTF("EDI]"); return M.x86.R_EDI * index; } HALT_SYS(); return 0; /* NOT REACHED OR REACHED ON ERROR */}/****************************************************************************PARAMETERS:mod - MOD value of preceding ModR/M byteRETURNS:Offset in memory for the address decodingREMARKS:Decodes SIB addressing byte and returns calculated effective address.****************************************************************************/unsigned decode_sib_address( int mod){ int sib = fetch_byte_imm(); int ss = (sib >> 6) & 0x03; int index = (sib >> 3) & 0x07; int base = sib & 0x07; int offset = 0; int displacement; switch (base) { case 0: DECODE_PRINTF("[EAX]"); offset = M.x86.R_EAX; break; case 1: DECODE_PRINTF("[ECX]"); offset = M.x86.R_ECX; break; case 2: DECODE_PRINTF("[EDX]"); offset = M.x86.R_EDX; break; case 3: DECODE_PRINTF("[EBX]"); offset = M.x86.R_EBX; break; case 4: DECODE_PRINTF("[ESP]"); offset = M.x86.R_ESP; break; case 5: switch (mod) { case 0: displacement = (s32)fetch_long_imm(); DECODE_PRINTF2("[%d]", displacement); offset = displacement; break; case 1: displacement = (s8)fetch_byte_imm(); DECODE_PRINTF2("[%d][EBP]", displacement); offset = M.x86.R_EBP + displacement; break; case 2: displacement = (s32)fetch_long_imm(); DECODE_PRINTF2("[%d][EBP]", displacement); offset = M.x86.R_EBP + displacement; break; default: HALT_SYS(); } DECODE_PRINTF("[EAX]"); offset = M.x86.R_EAX; break; case 6: DECODE_PRINTF("[ESI]"); offset = M.x86.R_ESI; break; case 7: DECODE_PRINTF("[EDI]"); offset = M.x86.R_EDI; break; default: HALT_SYS(); } offset += decode_sib_si(ss, index); return offset;}/****************************************************************************PARAMETERS:rm - RM value to decodeRETURNS:Offset in memory for the address decodingREMARKS:Return the offset given by mod=00 addressing. Also enables thedecoding of instructions.NOTE: The code which specifies the corresponding segment (ds vs ss) below in the case of [BP+..]. The assumption here is that at the point that this subroutine is called, the bit corresponding to SYSMODE_SEG_DS_SS will be zero. After every instruction except the segment override instructions, this bit (as well as any bits indicating segment overrides) will be clear. So if a SS access is needed, set this bit. Otherwise, DS access occurs (unless any of the segment override bits are set).****************************************************************************/unsigned decode_rm00_address( int rm){ unsigned offset; if (M.x86.mode & SYSMODE_PREFIX_ADDR) { /* 32-bit addressing */ switch (rm) { case 0: DECODE_PRINTF("[EAX]"); return M.x86.R_EAX; case 1: DECODE_PRINTF("[ECX]"); return M.x86.R_ECX; case 2: DECODE_PRINTF("[EDX]"); return M.x86.R_EDX; case 3: DECODE_PRINTF("[EBX]"); return M.x86.R_EBX; case 4: return decode_sib_address(0); case 5: offset = fetch_long_imm(); DECODE_PRINTF2("[%08x]", offset); return offset; case 6: DECODE_PRINTF("[ESI]"); return M.x86.R_ESI; case 7: DECODE_PRINTF("[EDI]"); return M.x86.R_EDI; } } else { /* 16-bit addressing */ switch (rm) { case 0: DECODE_PRINTF("[BX+SI]"); return (M.x86.R_BX + M.x86.R_SI) & 0xffff; case 1: DECODE_PRINTF("[BX+DI]"); return (M.x86.R_BX + M.x86.R_DI) & 0xffff; case 2: DECODE_PRINTF("[BP+SI]"); M.x86.mode |= SYSMODE_SEG_DS_SS; return (M.x86.R_BP + M.x86.R_SI) & 0xffff; case 3: DECODE_PRINTF("[BP+DI]"); M.x86.mode |= SYSMODE_SEG_DS_SS; return (M.x86.R_BP + M.x86.R_DI) & 0xffff; case 4: DECODE_PRINTF("[SI]"); return M.x86.R_SI; case 5: DECODE_PRINTF("[DI]"); return M.x86.R_DI; case 6: offset = fetch_word_imm(); DECODE_PRINTF2("[%04x]", offset); return offset; case 7: DECODE_PRINTF("[BX]"); return M.x86.R_BX; } } HALT_SYS(); return 0;}/****************************************************************************PARAMETERS:rm - RM value to decodeRETURNS:Offset in memory for the address decodingREMARKS:Return the offset given by mod=01 addressing. Also enables thedecoding of instructions.****************************************************************************/unsigned decode_rm01_address( int rm){ int displacement; if (M.x86.mode & SYSMODE_PREFIX_ADDR) { /* 32-bit addressing */ if (rm != 4) displacement = (s8)fetch_byte_imm(); else displacement = 0; switch (rm) { case 0: DECODE_PRINTF2("%d[EAX]", displacement); return M.x86.R_EAX + displacement; case 1: DECODE_PRINTF2("%d[ECX]", displacement); return M.x86.R_ECX + displacement; case 2: DECODE_PRINTF2("%d[EDX]", displacement); return M.x86.R_EDX + displacement; case 3: DECODE_PRINTF2("%d[EBX]", displacement); return M.x86.R_EBX + displacement; case 4: { int offset = decode_sib_address(1); displacement = (s8)fetch_byte_imm(); DECODE_PRINTF2("[%d]", displacement); return offset + displacement; } case 5: DECODE_PRINTF2("%d[EBP]", displacement); return M.x86.R_EBP + displacement; case 6: DECODE_PRINTF2("%d[ESI]", displacement); return M.x86.R_ESI + displacement; case 7: DECODE_PRINTF2("%d[EDI]", displacement); return M.x86.R_EDI + displacement; } } else { /* 16-bit addressing */ displacement = (s8)fetch_byte_imm(); switch (rm) { case 0: DECODE_PRINTF2("%d[BX+SI]", displacement); return (M.x86.R_BX + M.x86.R_SI + displacement) & 0xffff; case 1: DECODE_PRINTF2("%d[BX+DI]", displacement); return (M.x86.R_BX + M.x86.R_DI + displacement) & 0xffff; case 2: DECODE_PRINTF2("%d[BP+SI]", displacement); M.x86.mode |= SYSMODE_SEG_DS_SS; return (M.x86.R_BP + M.x86.R_SI + displacement) & 0xffff; case 3: DECODE_PRINTF2("%d[BP+DI]", displacement); M.x86.mode |= SYSMODE_SEG_DS_SS; return (M.x86.R_BP + M.x86.R_DI + displacement) & 0xffff; case 4: DECODE_PRINTF2("%d[SI]", displacement); return (M.x86.R_SI + displacement) & 0xffff; case 5: DECODE_PRINTF2("%d[DI]", displacement); return (M.x86.R_DI + displacement) & 0xffff; case 6: DECODE_PRINTF2("%d[BP]", displacement); M.x86.mode |= SYSMODE_SEG_DS_SS; return (M.x86.R_BP + displacement) & 0xffff; case 7: DECODE_PRINTF2("%d[BX]", displacement); return (M.x86.R_BX + displacement) & 0xffff; } } HALT_SYS(); return 0; /* SHOULD NOT HAPPEN */}/****************************************************************************PARAMETERS:rm - RM value to decodeRETURNS:Offset in memory for the address decodingREMARKS:Return the offset given by mod=10 addressing. Also enables thedecoding of instructions.****************************************************************************/unsigned decode_rm10_address( int rm){ if (M.x86.mode & SYSMODE_PREFIX_ADDR) { int displacement; /* 32-bit addressing */ if (rm != 4) displacement = (s32)fetch_long_imm(); else displacement = 0; switch (rm) { case 0: DECODE_PRINTF2("%d[EAX]", displacement); return M.x86.R_EAX + displacement; case 1: DECODE_PRINTF2("%d[ECX]", displacement); return M.x86.R_ECX + displacement; case 2: DECODE_PRINTF2("%d[EDX]", displacement); return M.x86.R_EDX + displacement; case 3: DECODE_PRINTF2("%d[EBX]", displacement); return M.x86.R_EBX + displacement; case 4: { int offset = decode_sib_address(2); displacement = (s32)fetch_long_imm(); DECODE_PRINTF2("[%d]", displacement); return offset + displacement; } case 5: DECODE_PRINTF2("%d[EBP]", displacement); return M.x86.R_EBP + displacement; case 6: DECODE_PRINTF2("%d[ESI]", displacement); return M.x86.R_ESI + displacement; case 7: DECODE_PRINTF2("%d[EDI]", displacement); return M.x86.R_EDI + displacement; } } else { int displacement = (s16)fetch_word_imm(); /* 16-bit addressing */ switch (rm) { case 0: DECODE_PRINTF2("%d[BX+SI]", displacement); return (M.x86.R_BX + M.x86.R_SI + displacement) & 0xffff; case 1: DECODE_PRINTF2("%d[BX+DI]", displacement); return (M.x86.R_BX + M.x86.R_DI + displacement) & 0xffff; case 2: DECODE_PRINTF2("%d[BP+SI]", displacement); M.x86.mode |= SYSMODE_SEG_DS_SS; return (M.x86.R_BP + M.x86.R_SI + displacement) & 0xffff; case 3: DECODE_PRINTF2("%d[BP+DI]", displacement); M.x86.mode |= SYSMODE_SEG_DS_SS; return (M.x86.R_BP + M.x86.R_DI + displacement) & 0xffff; case 4: DECODE_PRINTF2("%d[SI]", displacement); return (M.x86.R_SI + displacement) & 0xffff; case 5: DECODE_PRINTF2("%d[DI]", displacement); return (M.x86.R_DI + displacement) & 0xffff; case 6: DECODE_PRINTF2("%d[BP]", displacement); M.x86.mode |= SYSMODE_SEG_DS_SS; return (M.x86.R_BP + displacement) & 0xffff; case 7: DECODE_PRINTF2("%d[BX]", displacement); return (M.x86.R_BX + displacement) & 0xffff; } } HALT_SYS(); return 0; /* SHOULD NOT HAPPEN */}/****************************************************************************PARAMETERS:mod - modifierrm - RM value to decodeRETURNS:Offset in memory for the address decoding, multiplexing calls tothe decode_rmXX_address functionsREMARKS:Return the offset given by "mod" addressing.****************************************************************************/unsigned decode_rmXX_address(int mod, int rm){ if(mod == 0) return decode_rm00_address(rm); if(mod == 1) return decode_rm01_address(rm); return decode_rm10_address(rm);}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -