Skip to content

Commit

Permalink
fix: bad immediates analysis
Browse files Browse the repository at this point in the history
the commit 361fd0a generates some bad code, especially in the test
switch.bin. The information "(rax*8)" in the jumptable was lost.
  • Loading branch information
plasma-disassembler committed Mar 4, 2019
1 parent 38c7f5f commit ec7df9b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion plasma/lib/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ def add_stack_variable(self, func_obj, inst, offset, op_size):
# -> inst op, imm
def analyze_imm(self, i, op, imm, is_written_op, is_deref_pointer):
ret = self.__analyze_imm(i, op, imm, is_written_op, is_deref_pointer)
if ret and op.type != self.ARCH_UTILS.OP_IMM:
if is_written_op and ret and op.type != self.ARCH_UTILS.OP_IMM:
self.db.immediates[i.address] = imm


Expand Down
16 changes: 8 additions & 8 deletions tests/analyzer/arrays.rev
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,17 @@ int var_c = -0xc
0x40053a: rsp -= 48
0x40053e: var_2c = edi
0x400541: var_38 = rsi
0x400545: !eax = &global_array[0]
0x400545: eax = *(&global_array[0])
0x40054b: var_c = eax
0x40054e: !eax = &global_array[5]
0x40054e: eax = *(&global_array[5])
0x400554: var_10 = eax
0x400557: !eax = &global_array[9]
0x400557: eax = *(&global_array[9])
0x40055d: var_14 = eax
0x400560: !eax = &global_string[7] " a string.\n"
0x400560: eax = (zero ext) *(&global_string[7] " a string.\n")
0x400567: var_15 = al
0x40056a: !rax = &global_ptr[0]
0x40056a: rax = *(&global_ptr[0])
0x400571: var_20 = rax
0x400575: !eax = &global_array[8]
0x400575: eax = *(&global_array[8])
0x40057b: esi = eax
0x40057d: edi = asc_400634 "%d\n"
0x400582: eax = 0
Expand Down Expand Up @@ -226,9 +226,9 @@ frame_size = 56
0x4005b4: r15d = edi
0x4005b7: push r13
0x4005b9: push r12
0x4005bb: !r12 = __init_array_start
0x4005bb: r12 = __init_array_start
0x4005c2: push rbp
0x4005c3: !rbp = __init_array_end
0x4005c3: rbp = __init_array_end
0x4005ca: push rbx
0x4005cb: r14 = rsi
0x4005ce: r13 = rdx
Expand Down
32 changes: 16 additions & 16 deletions tests/analyzer/invert_cond.rev
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ function main (.text) {
# 0x6fa: cmp dword ptr [rbp - 4], 2
# 0x6fe: je 0x70e
if (var_c != 2) {
0x700: !rdi = qword_7e4
0x700: rdi = qword_7e4
0x707: call puts
0x70c: jmp ret_0x736
} else {
0x70e: !rdi = unk_7e6 "2"
0x70e: rdi = unk_7e6 "2"
0x715: call puts
0x71a: jmp ret_0x736
}
} else {
0x71c: !rdi = qword_7e8
0x71c: rdi = qword_7e8
0x723: call puts
0x728: jmp ret_0x736
}
} else {
0x72a: !rdi = unk_7ea "4"
0x72a: rdi = unk_7ea "4"
0x731: call puts
}
ret_0x736:
Expand All @@ -54,14 +54,14 @@ function func1 (.text) {
# 0x692: cmp dword ptr [rbp - 4], 4
# 0x696: jg 0x6ae
if (var_c <= 4) {
0x698: !rdi = qword_7e4
0x698: rdi = qword_7e4
0x69f: call puts
0x6a4: edi = 0
0x6a9: call exit
}

ret_0x6ae:
0x6ae: !rdi = unk_7e6 "2"
0x6ae: rdi = unk_7e6 "2"
0x6b5: call puts
0x6ba: nop
0x6bb: leave
Expand All @@ -78,11 +78,11 @@ function func2 (.text) {
# 0x6c5: cmp dword ptr [rbp - 4], 4
# 0x6c9: jg 0x6d7
if (var_c <= 4) {
0x6cb: !rdi = qword_7e4
0x6cb: rdi = qword_7e4
0x6d2: call puts
}
ret_0x6d7:
0x6d7: !rdi = unk_7e6 "2"
0x6d7: rdi = unk_7e6 "2"
0x6de: call puts
0x6e3: nop
0x6e4: leave
Expand All @@ -101,24 +101,24 @@ function main (.text) {
# 0x6ee: cmp dword ptr [rbp - 0xc], 0
# 0x6f2: je 0x72a ; manually inverted
if (var_14 == 0) {
0x72a: !rdi = unk_7ea "4"
0x72a: rdi = unk_7ea "4"
0x731: call puts
}
# 0x6f4: cmp dword ptr [rbp - 8], 1
# 0x6f8: je 0x71c ; manually inverted
else if (var_10 == 1) {
0x71c: !rdi = qword_7e8
0x71c: rdi = qword_7e8
0x723: call puts
0x728: jmp ret_0x736
}
# 0x6fa: cmp dword ptr [rbp - 4], 2
# 0x6fe: je 0x70e ; manually inverted
else if (var_c == 2) {
0x70e: !rdi = unk_7e6 "2"
0x70e: rdi = unk_7e6 "2"
0x715: call puts
0x71a: jmp ret_0x736
} else {
0x700: !rdi = qword_7e4
0x700: rdi = qword_7e4
0x707: call puts
0x70c: jmp ret_0x736
}
Expand All @@ -143,13 +143,13 @@ function func1 (.text) {
# 0x696: jg 0x6ae ; manually inverted
if (var_c > 4) {
ret_0x6ae:
0x6ae: !rdi = unk_7e6 "2"
0x6ae: rdi = unk_7e6 "2"
0x6b5: call puts
0x6ba: nop
0x6bb: leave
0x6bc: ret
}
0x698: !rdi = qword_7e4
0x698: rdi = qword_7e4
0x69f: call puts
0x6a4: edi = 0
0x6a9: call exit
Expand All @@ -165,11 +165,11 @@ function func2 (.text) {
# 0x6c5: cmp dword ptr [rbp - 4], 4
# 0x6c9: jg 0x6d7 ; manually inverted
if (var_c <= 4) {
0x6cb: !rdi = qword_7e4
0x6cb: rdi = qword_7e4
0x6d2: call puts
}
ret_0x6d7:
0x6d7: !rdi = unk_7e6 "2"
0x6d7: rdi = unk_7e6 "2"
0x6de: call puts
0x6e3: nop
0x6e4: leave
Expand Down
4 changes: 2 additions & 2 deletions tests/analyzer/switch.rev
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,9 @@ frame_size = 56
0x400584: r15d = edi
0x400587: push r13
0x400589: push r12
0x40058b: !r12 = __init_array_start
0x40058b: r12 = __init_array_start
0x400592: push rbp
0x400593: !rbp = __init_array_end
0x400593: rbp = __init_array_end
0x40059a: push rbx
0x40059b: r14 = rsi
0x40059e: r13 = rdx
Expand Down

0 comments on commit ec7df9b

Please sign in to comment.