-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdissectSvg.py
69 lines (52 loc) · 2.12 KB
/
dissectSvg.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
68
69
import argparse
import sys
import svgwrite
from RegionRetriever import RegionRetriever
from MetadataRetriever import MetadataRetriever
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-p", "--prefix", help="prefix for nm tool (e.g. arm-none-eabi-, default: \"\")", default='', metavar='PREFIX')
parser.add_argument("elffile", help="input elf file")
parser.add_argument("mapfile", help="input map file")
parser.add_argument("region", help="memory region to dissect")
parser.add_argument("output", help="output file")
args = parser.parse_args()
try:
memMapRetriever = RegionRetriever(mapFile=args.mapfile)
except:
print("Error occurred! Does %s file exist?" % args.mapfile)
sys.exit()
Regions = memMapRetriever.GetRegions()
metadataRetriever = MetadataRetriever(args.elffile, args.mapfile, Regions, args.prefix)
symbolList = metadataRetriever.retreiveSymbols()
if args.region in Regions.keys():
symbolList = [d for d in symbolList if args.region == d["region"]]
else:
print("Region %s does not exist in %s" % (args.region, args.elffile))
sys.exit()
regionOffset = Regions[args.region]["Origin"]
div = 160
heigth = Regions[args.region]["Length"]/div
width = (heigth)/8
bgColor = svgwrite.rgb(75, 75, 85, '%')
fgColor = [ svgwrite.rgb(70, 60, 50, '%'),
svgwrite.rgb(60, 70, 50, '%')]
dwg = svgwrite.Drawing(args.output, profile='full', size=(str(width), str(heigth)))
dwg.add(dwg.rect((0, 0), (width, heigth), fill=bgColor))
fgColorVectorDim = len(fgColor)
fgColorIndex = 0
lastaddr = -1
for symbol in symbolList:
if lastaddr == symbol["addr"]:
continue
if symbol["fill"]:
continue
symbolY = (symbol["addr"] - regionOffset) / div
dwg.add(dwg.rect((0, symbolY), (width, symbol["dim"]/div), fill=fgColor[fgColorIndex]))
lastaddr = symbol["addr"]
fgColorIndex += 1
if fgColorIndex >= fgColorVectorDim:
fgColorIndex = 0
dwg.save()
if __name__ == '__main__':
main()