1 "Module to deal with (binary) data of analyzed code."
5 from collections
import namedtuple
8 AreaTuple
= namedtuple("AreaTuple", ["start", "end", "data", "props"])
13 class InvalidAddrException(Exception):
14 "Thrown when dereferencing address which doesn't exist in address space."
15 def __init__(self
, addr
):
16 self
.args
= (addr
, hex(addr
))
20 "Initialize and load binary data structures."
21 for fname
in glob
.glob(dir + "/*.bin"):
22 m
= re
.search(r
".+/([0-9A-Fa-f]+)-([0-9A-Fa-f]+)(-([A-Za-z]+))?", fname
)
25 with
open(fname
, "rb") as f
:
27 start
= int(m
.group(1), 16)
28 end
= int(m
.group(2), 16)
29 access
= m
.group(4).upper()
30 AREAS
.append(AreaTuple(start
, end
, data
, {"access": access
}))
36 if a
.start
<= addr
< a
.end
:
37 return (addr
- a
.start
, a
)
41 def get_bytes(addr
, sz
):
42 off
, area
= addr2area(addr
)
44 raise InvalidAddrException(addr
)
45 return area
.data
[off
:off
+ sz
]
48 def deref(addr
, bits
):
49 # TODO: hardcodes little-endian
52 for b
in get_bytes(addr
, bits
// 8):
58 if __name__
== "__main__":
60 print(hex(deref(0x40000054, 32)))