Skip to content

Commit cfd721b

Browse files
committed
Fixed SIB.base handling when ASIZE == 32 (Fixes #592)
1 parent ae12a09 commit cfd721b

File tree

6 files changed

+97
-3
lines changed

6 files changed

+97
-3
lines changed

src/Decoder.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1432,7 +1432,9 @@ static ZyanStatus ZydisDecodeOperandMemory(const ZydisDecoderContext* context,
14321432
operand->mem.index = ZYDIS_REGISTER_NONE;
14331433
operand->mem.scale = 0;
14341434
}
1435-
if (operand->mem.base == ZYDIS_REGISTER_EBP)
1435+
if ((operand->mem.base == ZYDIS_REGISTER_EBP) ||
1436+
(operand->mem.base == ZYDIS_REGISTER_R13D) ||
1437+
(operand->mem.base == ZYDIS_REGISTER_R29D))
14361438
{
14371439
if (instruction->raw.modrm.mod == 0)
14381440
{

tests/cases/default_049.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-64 67418A0C25D8E98800

tests/cases/default_049.out

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
== [ BASIC ] ============================================================================================
2+
MNEMONIC: mov [ENC: DEFAULT, MAP: DEFAULT, OPC: 0x8A]
3+
LENGTH: 9
4+
SSZ: 64
5+
EOSZ: 8
6+
EASZ: 32
7+
CATEGORY: DATAXFER
8+
ISA-SET: I86
9+
ISA-EXT: BASE
10+
EXCEPTIONS: NONE
11+
ATTRIBUTES: HAS_MODRM HAS_SIB HAS_REX ACCEPTS_SEGMENT HAS_ADDRESSSIZE
12+
OPTIMIZED: 8A 0C 25 D8 E9 88 00
13+
14+
== [ OPERANDS ] ============================================================================================
15+
## TYPE VISIBILITY ACTION ENCODING SIZE NELEM ELEMSZ ELEMTYPE VALUE
16+
-- --------- ---------- ------ ------------ ---- ----- ------ -------- ---------------------------
17+
0 REGISTER EXPLICIT W MODRM_REG 8 1 8 INT cl
18+
1 MEMORY EXPLICIT R MODRM_RM 8 1 8 INT TYPE = MEM
19+
SEG = ds
20+
BASE = none
21+
INDEX = none
22+
SCALE = 0
23+
DISP = 0x000000000088E9D8
24+
-- --------- ---------- ------ ------------ ---- ----- ------ -------- ---------------------------
25+
26+
== [ ATT ] ============================================================================================
27+
ABSOLUTE: mov 0x0088E9D8, %cl
28+
RELATIVE: mov 0x0088E9D8, %cl
29+
30+
== [ INTEL ] ============================================================================================
31+
ABSOLUTE: mov cl, byte ptr ds:[0x0088E9D8]
32+
RELATIVE: mov cl, byte ptr ds:[0x0088E9D8]
33+
34+
== [ SEGMENTS ] ============================================================================================
35+
67 41 8A 0C 25 D8 E9 88 00
36+
: : : : : :..DISP
37+
: : : : :..SIB
38+
: : : :..MODRM
39+
: : :..OPCODE
40+
: :..REX
41+
:..PREFIXES

tests/cases/default_050.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-64 67450FAC3CC50000E94110

tests/cases/default_050.out

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
== [ BASIC ] ============================================================================================
2+
MNEMONIC: shrd [ENC: DEFAULT, MAP: 0F, OPC: 0xAC]
3+
LENGTH: 11
4+
SSZ: 64
5+
EOSZ: 32
6+
EASZ: 32
7+
CATEGORY: SHIFT
8+
ISA-SET: I386
9+
ISA-EXT: BASE
10+
EXCEPTIONS: NONE
11+
ATTRIBUTES: HAS_MODRM HAS_SIB HAS_REX CPUFLAG_ACCESS ACCEPTS_SEGMENT HAS_ADDRESSSIZE
12+
OPTIMIZED: 67 44 0F AC 3C C5 00 00 E9 41 10
13+
14+
== [ OPERANDS ] ============================================================================================
15+
## TYPE VISIBILITY ACTION ENCODING SIZE NELEM ELEMSZ ELEMTYPE VALUE
16+
-- --------- ---------- ------ ------------ ---- ----- ------ -------- ---------------------------
17+
0 MEMORY EXPLICIT RCW MODRM_RM 32 1 32 UINT TYPE = MEM
18+
SEG = ds
19+
BASE = none
20+
INDEX = eax
21+
SCALE = 8
22+
DISP = 0x0000000041E90000
23+
1 REGISTER EXPLICIT R MODRM_REG 32 1 32 UINT r15d
24+
2 IMMEDIATE EXPLICIT R UIMM8 8 1 8 UINT [U A 8] 0x0000000000000010
25+
3 REGISTER HIDDEN W NONE 64 64 1 INT rflags
26+
-- --------- ---------- ------ ------------ ---- ----- ------ -------- ---------------------------
27+
28+
== [ FLAGS ] ============================================================================================
29+
ACTIONS: [CF : M ] [PF : M ] [AF : U ] [ZF : M ] [SF : M ] [OF : U ]
30+
READ: 0x00000000
31+
WRITTEN: 0x000008D5
32+
33+
== [ ATT ] ============================================================================================
34+
ABSOLUTE: shrd $0x10, %r15d, 0x41E90000(,%eax,8)
35+
RELATIVE: shrd $0x10, %r15d, 0x41E90000(,%eax,8)
36+
37+
== [ INTEL ] ============================================================================================
38+
ABSOLUTE: shrd dword ptr ds:[eax*8+0x41E90000], r15d, 0x10
39+
RELATIVE: shrd dword ptr ds:[eax*8+0x41E90000], r15d, 0x10
40+
41+
== [ SEGMENTS ] ============================================================================================
42+
67 45 0F AC 3C C5 00 00 E9 41 10
43+
: : : : : : :..IMM
44+
: : : : : :..DISP
45+
: : : : :..SIB
46+
: : : :..MODRM
47+
: : :..OPCODE
48+
: :..REX
49+
:..PREFIXES

tests/regression.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@ def get_exitcode_stdout_stderr(path, cmd):
4343

4444
pre, ext = os.path.splitext(case)
4545
path = os.path.join(TEST_CASE_DIRECTORY, pre + ".out")
46+
out = out.decode().replace('\r\n', '\n')
4647

4748
if args.operation == "rebase":
4849
with open(path, mode="wb") as f:
49-
f.write(out)
50+
f.write(out.encode())
5051
continue
5152

5253
try:
5354
with open(path, mode="rb") as f:
5455
expected = f.read().decode().replace('\r\n', '\n')
5556

56-
out = out.decode().replace('\r\n', '\n')
5757
if expected != out:
5858
print(f"FAILED: '{case}' [{payload}]")
5959
print('\n'.join(difflib.unified_diff(

0 commit comments

Comments
 (0)