Skip to content

Commit f80e4f3

Browse files
committed
update to v2.9.3
* add codeblock view * fix PE32+ DataDirectories * update win64 OS class * update documentation
1 parent 0a6ba6a commit f80e4f3

33 files changed

+607
-143
lines changed

README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ Changelog
9191
* add MIPS architecture (R3000 only)
9292
* improve support for changes in config
9393
* rework ext/stub interface
94+
* fixing sparc formatter
95+
* fixing PE32+ DataDirectories parsing
9496

9597
- `v2.9.2`_
9698

amoco/arch/x64/formats.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,13 @@ def opers(i):
3939
s = []
4040
for op in i.operands:
4141
if op._is_mem:
42-
if i.misc["rip_rel"] is not None:
43-
s.append((Token.Memory, "[%s]" % i.misc["rip_rel"]))
44-
else:
45-
s.append((Token.Memory, deref(op)))
42+
if i.misc['rip_rel']:
43+
op = i.misc['rip_rel']
44+
elif op.a.base._is_reg and op.a.base.etype & regtype.PC:
45+
if i.address is not None:
46+
op = op.__class__(i.address+i.length+op.a.disp,op.size,seg=op.a.seg)
47+
i.misc['rip_rel'] = op
48+
s.append((Token.Memory, deref(op)))
4649
elif op._is_cst:
4750
if i.misc["imm_ref"] is not None:
4851
s.append((Token.Address, str(i.misc["imm_ref"])))
@@ -61,11 +64,11 @@ def opers(i):
6164
def oprel(i):
6265
to = i.misc["to"]
6366
if to is not None:
64-
return [(Token.Address, "*" + str(to))]
67+
return [(Token.Address, str(to))]
6568
if (i.address is not None) and i.operands[0]._is_cst:
6669
v = i.address + i.operands[0].signextend(64) + i.length
6770
i.misc["to"] = v
68-
return [(Token.Address, "*" + str(v))]
71+
return [(Token.Address, str(v))]
6972
return [(Token.Constant, ".%+d" % i.operands[0].value)]
7073

7174

@@ -150,11 +153,11 @@ def opers_att(i):
150153
def oprel_att(i):
151154
to = i.misc["to"]
152155
if to is not None:
153-
return [(Token.Address, "*" + str(to))]
156+
return [(Token.Address, str(to))]
154157
if (i.address is not None) and i.operands[0]._is_cst:
155158
v = i.address + i.operands[0].signextend(64) + i.length
156159
i.misc["to"] = v
157-
return [(Token.Address, "*" + str(v))]
160+
return [(Token.Address, str(v))]
158161
return [(Token.Constant, "$.%+d" % i.operands[0].value)]
159162

160163

amoco/arch/x86/formats.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ def opers(i):
3939
s = []
4040
for op in i.operands:
4141
if op._is_mem:
42+
if op.a.base._is_reg and op.a.base.etype & regtype.PC:
43+
if i.address is not None:
44+
op = op.__class__(i.address+i.length+op.a.disp,op.size,seg=op.a.seg)
4245
s.append((Token.Memory, deref(op)))
4346
elif op._is_cst:
4447
if i.misc["imm_ref"] is not None:
@@ -58,11 +61,11 @@ def opers(i):
5861
def oprel(i):
5962
to = i.misc["to"]
6063
if to is not None:
61-
return [(Token.Address, "*" + str(to))]
64+
return [(Token.Address, str(to))]
6265
if (i.address is not None) and i.operands[0]._is_cst:
6366
v = i.address + i.operands[0].signextend(32) + i.length
6467
i.misc["to"] = v
65-
return [(Token.Address, "*" + str(v))]
68+
return [(Token.Address, str(v))]
6669
return [(Token.Constant, ".%+d" % i.operands[0].value)]
6770

6871

@@ -147,11 +150,11 @@ def opers_att(i):
147150
def oprel_att(i):
148151
to = i.misc["to"]
149152
if to is not None:
150-
return [(Token.Address, "*" + str(to))]
153+
return [(Token.Address, str(to))]
151154
if (i.address is not None) and i.operands[0]._is_cst:
152155
v = i.address + i.operands[0].signextend(32) + i.length
153156
i.misc["to"] = v
154-
return [(Token.Address, "*" + str(v))]
157+
return [(Token.Address, str(v))]
155158
return [(Token.Constant, "$.%+d" % i.operands[0].value)]
156159

157160

@@ -849,7 +852,7 @@ def att_opers(i, operands=None):
849852
def att_oprel(i):
850853
to = i.misc["to"]
851854
if to is not None:
852-
return [(Token.Address, "*" + str(to))]
855+
return [(Token.Address, str(to))]
853856
op = i.operands[0]
854857
if op._is_lab:
855858
return [(Token.Address, str(op.ref))]

amoco/cas/expressions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1505,7 +1505,7 @@ def __init__(self, x, pos, size, ref=None):
15051505

15061506
def setref(self, ref):
15071507
if self.x._is_reg:
1508-
self.etype |= et_reg
1508+
self.etype |= self.x.etype
15091509
if ref is None:
15101510
ref = self.x._subrefs.get((self.pos, self.size), None)
15111511
else:

amoco/cas/mapper.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,11 @@ def inputs(self):
7474
"list antecedent locations (used in the mapping)"
7575
r = []
7676
for l, v in iter(self.__map.items()):
77+
if (l==v):
78+
continue
7779
for lv in locations_of(v):
7880
if lv._is_reg and l._is_reg:
79-
if (lv == l) or (lv.etype & l.etype & regtype.FLAGS):
81+
if (lv.etype & l.etype & regtype.FLAGS):
8082
continue
8183
r.append(lv)
8284
return r

amoco/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
- 'helper' will use codeblock helper functions to pretty print code if True (default)
1818
- 'header' will show a dashed header line including the address of the block if True (default)
1919
- 'footer' will show a dashed footer line if True
20+
- 'segment' will show memory section/segment name in codeblock view if True (default)
2021
- 'bytecode' will show the hex encoded bytecode string of every instruction if True (default)
2122
- 'padding' will add the specified amount of blank chars to between address/bytecode/instruction (default 4).
23+
- 'hist' number of instruction's history shown in emulator view (default 3).
2224
2325
- 'Cas' which deals with parameters of the algebra system:
2426
@@ -89,6 +91,7 @@ class Code(Configurable):
8991
helper (Bool): use block helpers if True.
9092
header (Bool): display block header dash-line with its name if True.
9193
footer (Bool): display block footer dash-line if True.
94+
segment (Bool): display memory section/segment name if True.
9295
bytecode (Bool): display instructions' bytes.
9396
padding (int): add space-padding bytes to bytecode (default=4).
9497
hist (int): number of history instructions to show in
@@ -98,6 +101,7 @@ class Code(Configurable):
98101
header = Bool(True, config=True)
99102
footer = Bool(True, config=True)
100103
bytecode = Bool(True, config=True)
104+
segment = Bool(True, config=True)
101105
padding = Integer(4, config=True)
102106
hist = Integer(3, config=True)
103107

amoco/logger.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
3131
Setting all modules loggers to ``'ERROR'`` level::
3232
33-
In [2]: amoco.set_quiet()
33+
In [2]: amoco.logger.set_quiet()
3434
3535
Note:
3636
All loggers can be configured to log both to *stderr* with selected level

amoco/system/baremetal/psx.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def __init__(self, conf=None):
7979
conf = System()
8080
self.tasks = []
8181
self.abi = None
82+
self.symbols = {}
8283

8384
@classmethod
8485
def loader(cls, bprm, conf=None):

amoco/system/core.py

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,27 @@ def read_instruction(self, vaddr, **kargs):
135135
i.xdata(i, xdata)
136136
return i
137137

138+
def symbol_for(self,address):
139+
info = None
140+
if address in self.bin.variables:
141+
info = self.bin.variables[address]
142+
if isinstance(info,tuple):
143+
info = info[0]
144+
info = "$%s"%info
145+
elif address in self.bin.functions:
146+
info = self.bin.functions[address]
147+
if isinstance(info,tuple):
148+
info = info[0]
149+
info = "<%s>"%info
150+
elif self.OS and (address in self.OS.symbols):
151+
info = self.OS.symbols[address]
152+
info = "#%s"%info
153+
return info or ""
154+
155+
def segment_for(self,address,stype=None):
156+
s = self.bin.getinfo(address)[0]
157+
return s.name if hasattr(s,'name') else ""
158+
138159
def getx(self, loc, size=8, sign=False):
139160
"""
140161
high level method to get the expressions value associated
@@ -261,8 +282,8 @@ class BinFormat(object):
261282
symtab = None
262283
strtab = None
263284
reltab = None
264-
functions = None
265-
variables = None
285+
functions = {}
286+
variables = {}
266287

267288
@property
268289
def entrypoints(self):
@@ -275,6 +296,9 @@ def filename(self):
275296
def loadsegment(self, S, pagesize=None, raw=None):
276297
raise NotImplementedError
277298

299+
def getinfo(self, target):
300+
return (None, 0, 0)
301+
278302

279303
class DataIO(BinFormat):
280304
"""

amoco/system/elf.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,13 @@ def getinfo(self, target):
160160
# but this may lead to errors because what really matters are segments
161161
# loaded by the kernel binfmt_elf.c loader.
162162
if self.Shdr:
163-
for s in self.Shdr[::-1]:
164-
if s.sh_type == SHT_NULL:
163+
for s in reversed(self.Shdr):
164+
if s.sh_type != SHT_PROGBITS:
165165
continue
166166
if s.sh_addr <= addr < s.sh_addr + s.sh_size:
167167
return s, addr - s.sh_addr, s.sh_addr
168-
##
169168
elif self.Phdr:
170-
for s in self.Phdr[::-1]:
169+
for s in reversed(self.Phdr):
171170
if s.p_type != PT_LOAD:
172171
continue
173172
if s.p_vaddr <= addr < s.p_vaddr + s.p_filesz:
@@ -423,7 +422,8 @@ def checksec(self):
423422
R["PIE"] = 1
424423
R["Full RelRO"] = 0
425424
for d in self.readsection(".dynamic") or []:
426-
if d.d_tag == DT_BIND_NOW:
425+
if d.d_tag == DT_BIND_NOW or\
426+
(d.d_tag == DT_FLAGS and d.d_un==DF_BIND_NOW):
427427
R["Full RelRO"] = 1
428428
break
429429
return R
@@ -1156,6 +1156,12 @@ def DT_ADDRTAGIDX(self, tag):
11561156
DT_ADDRRNGHI = 0x6FFFFEFF
11571157
DT_ADDRNUM = 10
11581158

1159+
DF_ORIGIN = 0x1
1160+
DF_SYMBOLIC = 0x2
1161+
DF_TEXTREL = 0x4
1162+
DF_BIND_NOW = 0x8
1163+
DF_STATIC_TLS = 0x10
1164+
11591165

11601166
@StructDefine(
11611167
"""

0 commit comments

Comments
 (0)