-
Notifications
You must be signed in to change notification settings - Fork 21
/
thumb2FlaRecover.py
67 lines (52 loc) · 2.76 KB
/
thumb2FlaRecover.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import struct
from flaRecover import FlaRecover
from thumb2Util import Thumb2Util
class Thumb2FlaRecover(FlaRecover):
def __init__(self, data, offset):
FlaRecover.__init__(self, data, offset)
self.instUtil = Thumb2Util()
# self.thumb2Util = self.instUtil
def fill_thumb_b_inst_by_offset(self, start, offset):
jmp_offset = self.instUtil.fill_thumb_b_inst_by_offset(start, offset)
for i in range(2):
self.origin_data[start + i - self.base_offset] = jmp_offset[i]
def fill_thumb_b_inst_by_addr(self, start, currentEA, destEA):
offset = self.instUtil.get_thumb_jmp_offset(currentEA, destEA)
self.fill_thumb_b_inst_by_offset(start, offset)
def fill_thumb2_b_inst_by_offset(self, start, offset):
jmp_offset1, jmp_offset2 = self.instUtil.fill_thumb2_b_inst_by_offset(start, offset)
#high
for i in range(2):
self.origin_data[start + i - self.base_offset] = jmp_offset1[i]
#low
for i in range(2):
self.origin_data[start + 2 + i - self.base_offset] = jmp_offset2[i]
def fill_thumb2_b_inst_by_addr(self, start, currentEA, destEA):
offset = self.instUtil.get_thumb_jmp_offset(currentEA, destEA)
self.fill_thumb2_b_inst_by_offset(start, offset)
def mov_inst(self, dest, src, len):
if dest == src:
return
for i in range(len):
if dest < src:
self.origin_data[dest + i - self.base_offset] = self.origin_data[src + i - self.base_offset]
else:
self.origin_data[dest + (len - 1 - i) - self.base_offset] = self.origin_data[src + (len - 1 - i) - self.base_offset]
def fill_thumb_bcc_inst_by_offset(self, bcc_type, start, offset):
jmp_offset = self.instUtil.fill_thumb_bcc_inst_by_offset(bcc_type, start, offset)
for i in range(2):
self.origin_data[start + i - self.base_offset] = jmp_offset[i]
def fill_thumb_bcc_inst_by_addr(self, bcc_type, start, currentEA, destEA):
offset = self.instUtil.get_thumb_jmp_offset(currentEA, destEA)
self.fill_thumb_bcc_inst_by_offset(bcc_type, start, offset)
def fill_thumb2_bcc_inst_by_offset(self, bcc_type, start, offset):
jmp_offset1, jmp_offset2 = self.instUtil.fill_thumb2_bcc_inst_by_offset(bcc_type, start, offset)
#high
for i in range(2):
self.origin_data[start + i - self.base_offset] = jmp_offset1[i]
#low
for i in range(2):
self.origin_data[start + 2 + i - self.base_offset] = jmp_offset2[i]
def fill_thumb2_bcc_inst_by_addr(self, bcc_type, start, currentEA, destEA):
offset = self.instUtil.get_thumb_jmp_offset(currentEA, destEA)
self.fill_thumb2_bcc_inst_by_offset(bcc_type, start, offset)