Skip to content

Commit ec7df9b

Browse files
fix: bad immediates analysis
the commit 361fd0a generates some bad code, especially in the test switch.bin. The information "(rax*8)" in the jumptable was lost.
1 parent 38c7f5f commit ec7df9b

File tree

4 files changed

+27
-27
lines changed

4 files changed

+27
-27
lines changed

plasma/lib/analyzer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def add_stack_variable(self, func_obj, inst, offset, op_size):
281281
# -> inst op, imm
282282
def analyze_imm(self, i, op, imm, is_written_op, is_deref_pointer):
283283
ret = self.__analyze_imm(i, op, imm, is_written_op, is_deref_pointer)
284-
if ret and op.type != self.ARCH_UTILS.OP_IMM:
284+
if is_written_op and ret and op.type != self.ARCH_UTILS.OP_IMM:
285285
self.db.immediates[i.address] = imm
286286

287287

tests/analyzer/arrays.rev

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,17 +183,17 @@ int var_c = -0xc
183183
0x40053a: rsp -= 48
184184
0x40053e: var_2c = edi
185185
0x400541: var_38 = rsi
186-
0x400545: !eax = &global_array[0]
186+
0x400545: eax = *(&global_array[0])
187187
0x40054b: var_c = eax
188-
0x40054e: !eax = &global_array[5]
188+
0x40054e: eax = *(&global_array[5])
189189
0x400554: var_10 = eax
190-
0x400557: !eax = &global_array[9]
190+
0x400557: eax = *(&global_array[9])
191191
0x40055d: var_14 = eax
192-
0x400560: !eax = &global_string[7] " a string.\n"
192+
0x400560: eax = (zero ext) *(&global_string[7] " a string.\n")
193193
0x400567: var_15 = al
194-
0x40056a: !rax = &global_ptr[0]
194+
0x40056a: rax = *(&global_ptr[0])
195195
0x400571: var_20 = rax
196-
0x400575: !eax = &global_array[8]
196+
0x400575: eax = *(&global_array[8])
197197
0x40057b: esi = eax
198198
0x40057d: edi = asc_400634 "%d\n"
199199
0x400582: eax = 0
@@ -226,9 +226,9 @@ frame_size = 56
226226
0x4005b4: r15d = edi
227227
0x4005b7: push r13
228228
0x4005b9: push r12
229-
0x4005bb: !r12 = __init_array_start
229+
0x4005bb: r12 = __init_array_start
230230
0x4005c2: push rbp
231-
0x4005c3: !rbp = __init_array_end
231+
0x4005c3: rbp = __init_array_end
232232
0x4005ca: push rbx
233233
0x4005cb: r14 = rsi
234234
0x4005ce: r13 = rdx

tests/analyzer/invert_cond.rev

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@ function main (.text) {
1717
# 0x6fa: cmp dword ptr [rbp - 4], 2
1818
# 0x6fe: je 0x70e
1919
if (var_c != 2) {
20-
0x700: !rdi = qword_7e4
20+
0x700: rdi = qword_7e4
2121
0x707: call puts
2222
0x70c: jmp ret_0x736
2323
} else {
24-
0x70e: !rdi = unk_7e6 "2"
24+
0x70e: rdi = unk_7e6 "2"
2525
0x715: call puts
2626
0x71a: jmp ret_0x736
2727
}
2828
} else {
29-
0x71c: !rdi = qword_7e8
29+
0x71c: rdi = qword_7e8
3030
0x723: call puts
3131
0x728: jmp ret_0x736
3232
}
3333
} else {
34-
0x72a: !rdi = unk_7ea "4"
34+
0x72a: rdi = unk_7ea "4"
3535
0x731: call puts
3636
}
3737
ret_0x736:
@@ -54,14 +54,14 @@ function func1 (.text) {
5454
# 0x692: cmp dword ptr [rbp - 4], 4
5555
# 0x696: jg 0x6ae
5656
if (var_c <= 4) {
57-
0x698: !rdi = qword_7e4
57+
0x698: rdi = qword_7e4
5858
0x69f: call puts
5959
0x6a4: edi = 0
6060
0x6a9: call exit
6161
}
6262

6363
ret_0x6ae:
64-
0x6ae: !rdi = unk_7e6 "2"
64+
0x6ae: rdi = unk_7e6 "2"
6565
0x6b5: call puts
6666
0x6ba: nop
6767
0x6bb: leave
@@ -78,11 +78,11 @@ function func2 (.text) {
7878
# 0x6c5: cmp dword ptr [rbp - 4], 4
7979
# 0x6c9: jg 0x6d7
8080
if (var_c <= 4) {
81-
0x6cb: !rdi = qword_7e4
81+
0x6cb: rdi = qword_7e4
8282
0x6d2: call puts
8383
}
8484
ret_0x6d7:
85-
0x6d7: !rdi = unk_7e6 "2"
85+
0x6d7: rdi = unk_7e6 "2"
8686
0x6de: call puts
8787
0x6e3: nop
8888
0x6e4: leave
@@ -101,24 +101,24 @@ function main (.text) {
101101
# 0x6ee: cmp dword ptr [rbp - 0xc], 0
102102
# 0x6f2: je 0x72a ; manually inverted
103103
if (var_14 == 0) {
104-
0x72a: !rdi = unk_7ea "4"
104+
0x72a: rdi = unk_7ea "4"
105105
0x731: call puts
106106
}
107107
# 0x6f4: cmp dword ptr [rbp - 8], 1
108108
# 0x6f8: je 0x71c ; manually inverted
109109
else if (var_10 == 1) {
110-
0x71c: !rdi = qword_7e8
110+
0x71c: rdi = qword_7e8
111111
0x723: call puts
112112
0x728: jmp ret_0x736
113113
}
114114
# 0x6fa: cmp dword ptr [rbp - 4], 2
115115
# 0x6fe: je 0x70e ; manually inverted
116116
else if (var_c == 2) {
117-
0x70e: !rdi = unk_7e6 "2"
117+
0x70e: rdi = unk_7e6 "2"
118118
0x715: call puts
119119
0x71a: jmp ret_0x736
120120
} else {
121-
0x700: !rdi = qword_7e4
121+
0x700: rdi = qword_7e4
122122
0x707: call puts
123123
0x70c: jmp ret_0x736
124124
}
@@ -143,13 +143,13 @@ function func1 (.text) {
143143
# 0x696: jg 0x6ae ; manually inverted
144144
if (var_c > 4) {
145145
ret_0x6ae:
146-
0x6ae: !rdi = unk_7e6 "2"
146+
0x6ae: rdi = unk_7e6 "2"
147147
0x6b5: call puts
148148
0x6ba: nop
149149
0x6bb: leave
150150
0x6bc: ret
151151
}
152-
0x698: !rdi = qword_7e4
152+
0x698: rdi = qword_7e4
153153
0x69f: call puts
154154
0x6a4: edi = 0
155155
0x6a9: call exit
@@ -165,11 +165,11 @@ function func2 (.text) {
165165
# 0x6c5: cmp dword ptr [rbp - 4], 4
166166
# 0x6c9: jg 0x6d7 ; manually inverted
167167
if (var_c <= 4) {
168-
0x6cb: !rdi = qword_7e4
168+
0x6cb: rdi = qword_7e4
169169
0x6d2: call puts
170170
}
171171
ret_0x6d7:
172-
0x6d7: !rdi = unk_7e6 "2"
172+
0x6d7: rdi = unk_7e6 "2"
173173
0x6de: call puts
174174
0x6e3: nop
175175
0x6e4: leave

tests/analyzer/switch.rev

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,9 @@ frame_size = 56
242242
0x400584: r15d = edi
243243
0x400587: push r13
244244
0x400589: push r12
245-
0x40058b: !r12 = __init_array_start
245+
0x40058b: r12 = __init_array_start
246246
0x400592: push rbp
247-
0x400593: !rbp = __init_array_end
247+
0x400593: rbp = __init_array_end
248248
0x40059a: push rbx
249249
0x40059b: r14 = rsi
250250
0x40059e: r13 = rdx

0 commit comments

Comments
 (0)