Minor update to draw map. Now annotates multiple overlaps. But doesn't draw them yet..

This commit is contained in:
Jonathan Herrewijnen 2024-09-13 22:39:23 +02:00
parent dd28bd80d4
commit 13f080e111
6 changed files with 80 additions and 23 deletions

12
.vscode/launch.json vendored
View File

@ -20,6 +20,18 @@
"console": "integratedTerminal",
"justMyCode": false
},
{
"name": "FF_MemoryDrawer",
"type": "debugpy",
"request": "launch",
"program": "herrewebpy/firmware_forensics/memory_drawer.py",
"args": [
"--input",
"sample_data/csv/stack_and_functions.csv",
],
"console": "integratedTerminal",
"justMyCode": false
},
{
"name": "C-ReadPlanGenerator",
"type": "debugpy",

View File

@ -4,5 +4,8 @@
#from herrewebpy.firmware_forensics import function_extractor
#function_extractor.FunctionExtractor('', 'ARM_AARCH64')
from herrewebpy.christianity import readplan_generator
readplan_generator.generate_readplan()
#from herrewebpy.christianity import readplan_generator
#readplan_generator.generate_readplan()
from herrewebpy.firmware_forensics import memory_drawer
memory_drawer.MemoryDrawer('sample_data/csv/stack_and_functions.csv')

View File

@ -4,8 +4,8 @@ import random, argparse
import numpy as np
import pandas as pd
def read_data(df):
data = pd.read_csv('stack_and_functions.csv')
def read_data(input_file):
data = pd.read_csv(input_file)
def convert_to_int(value):
try:
@ -27,24 +27,24 @@ def read_data(df):
data.reset_index(drop=True, inplace=True)
data['overlap'] = False
data['index'] = data.index
for i, row in data.iterrows():
for j, row2 in data.iterrows():
if i == j:
continue
if row['start'] <= row2['end'] and row['end'] > row2['start']:
if row['end'] - row['start'] >= row2['end'] - row2['start']:
continue
data.at[i, 'overlap'] = True
data.at[j, 'overlap'] = True
data.at[i, 'overlap_with'] = j
data['overlap_with'] = data['overlap_with'].fillna(data.index.to_series())
data['overlap_with'] = data['overlap_with'].astype(float)
# Annotate rows that overlap with each other
temp = data.loc[(data['start'] <= row['start']) & (data['end'] >= row['end'])]
data.at[i, 'overlap'] = False
if temp.shape[0] > 1:
data.at[i, 'overlap'] = True
# Increment the overlap_with column, with the value of of the column 'index' of the row, and allow multiple overlaps
data.at[i, 'overlap_with'] = ','.join(temp['index'].astype(str).to_list())
data.at[i, 'overlap_with'] = True
# Send warnings if sizes are negative
if (data['size'] < 0).any():
print(f'Warning: Negative sizes detected at indices {data[data["size"] < 0].index}')
return data
def draw_diagram(data):
@ -193,15 +193,20 @@ def draw_diagram(data):
legend_title_text="Function/Locations",
)
def write_output(fig):
fig.write_html("../_static/stack_and_functions.html")
return fig
def write_output(fig, output_file):
fig.write_html(f'{output_file}.html')
if __name__ == '__main__':
argparser = argparse.ArgumentParser()
argparser.add_argument('input', help='Input CSV file path', required=True)
argparser.add_argument('output', help='Output HTML filename', required=False)
argparser.add_argument('--input', help='Input CSV file path', required=True, type=str)
argparser.add_argument('--output', help='Output HTML filename', required=False, type=str)
args = argparser.parse_args()
data = read_data('stack_and_functions.csv')
if not args.output:
args.output = 'memory_drawer'
data = read_data(args.input)
fig = draw_diagram(data)
write_output(fig)
write_output(fig, args.output)

14
memory_drawer.html Normal file

File diff suppressed because one or more lines are too long

View File

@ -8,4 +8,5 @@ capstone
keystone
plotly
BioPython
pythonbible
pythonbible
tqdm

View File

@ -0,0 +1,22 @@
start,end,name,order,comment,X0,LR
0x00000000,0x00020000,BootROM,,,,
0x02020f60,0x02020f68,_boot_usb_ra,,,,
0x00012848,0x000128e8,auth_bl1,,,,
0x000064e0,0x0000658c,_boot_usb,,,,
0x020c0000,0x020c0004,_frederic_dest_ptr,,,,
0x000002c0,0x000002c4,_jump_bl1,,,,
0x02022000,0x02024000,BL1,,,,
0x02024000,0x02048000,BL31,,,,
0x02048000,0x0206ed10,BL2,,,,
0x02069000,0x0206f000,Debugger,,,,
0x020c0000,0x020c7000,Debugger relocated,,,,
0x02048000,0x0204daf0,BL2 empty space?,,,,
0x0204eb00,0x0204eb00,BL2 copy start/source,,,,
0x020c2000,0x020e8d10,BL2 load address?,,,,
0x0206ed10,0x02070000,End/Start peripheral space?,,,,
0x02019e5c,0x02020e5c,Tried debugger space,,,,
0x020C7800,0x020C8000,modem_interface,,,,
0x14AC0000,0x14ac5000,mali@14AC0000,,,,
0x02035600,0x02035608,TTBR0_EL3 address ptr,,,,
0x11207010,0x11207010,memread/write space,,,,
0xa0000000,0xa0013fff,Parts of BL2,,,,
1 start end name order comment X0 LR
2 0x00000000 0x00020000 BootROM
3 0x02020f60 0x02020f68 _boot_usb_ra
4 0x00012848 0x000128e8 auth_bl1
5 0x000064e0 0x0000658c _boot_usb
6 0x020c0000 0x020c0004 _frederic_dest_ptr
7 0x000002c0 0x000002c4 _jump_bl1
8 0x02022000 0x02024000 BL1
9 0x02024000 0x02048000 BL31
10 0x02048000 0x0206ed10 BL2
11 0x02069000 0x0206f000 Debugger
12 0x020c0000 0x020c7000 Debugger relocated
13 0x02048000 0x0204daf0 BL2 empty space?
14 0x0204eb00 0x0204eb00 BL2 copy start/source
15 0x020c2000 0x020e8d10 BL2 load address?
16 0x0206ed10 0x02070000 End/Start peripheral space?
17 0x02019e5c 0x02020e5c Tried debugger space
18 0x020C7800 0x020C8000 modem_interface
19 0x14AC0000 0x14ac5000 mali@14AC0000
20 0x02035600 0x02035608 TTBR0_EL3 address ptr
21 0x11207010 0x11207010 memread/write space
22 0xa0000000 0xa0013fff Parts of BL2