-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add top level script to process all files
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env python3 | ||
import argparse, csv, os, subprocess, glob | ||
from subprocess import PIPE | ||
|
||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser( | ||
description='Process all the files in the directory, whose mappings is described by a csv file, where name, exe, sim_files are required') | ||
parser.add_argument('dir', help='directory of the inputs') | ||
parser.add_argument('--csv', required=True, help='csv file to describe the mappings') | ||
parser.add_argument('--items', help='Extra interesting items in sim_files') | ||
parser.add_argument('--objdump', default='objdump', help='path to objdump (this is needed if instruction in binary is not supported by system objdump)') | ||
parser.add_argument('--addr2line', default='addr2line', help='path of addr2line (this is needed if dwarf format of binary is not supported by system addr2line)') | ||
args = parser.parse_args() | ||
|
||
with open(args.csv, 'r') as csv_file: | ||
reader = csv.DictReader(csv_file) | ||
dir_path = args.dir | ||
items = args.items if args.items else '' | ||
for row in reader: | ||
name = row['name'] | ||
exe = row['exe'] | ||
sim_files = row['sim_files'].split(',') | ||
sub_dir = os.path.join(dir_path, name) | ||
exe_path = os.path.join(sub_dir, exe) | ||
|
||
disasm = exe_path + '.disasm' | ||
dump = subprocess.run([f'{args.objdump}', '-d', exe_path], stdout=PIPE, check=True) | ||
dump = dump.stdout.decode('utf-8') | ||
with open(disasm, 'w') as disasm_file: | ||
disasm_file.write(dump) | ||
|
||
for sim_file in sim_files: | ||
sim_file_path = os.path.join(sub_dir, sim_file) | ||
subprocess.run(['./sde2csv.py', sim_file_path, exe_path, f'--items={items}'], check=True) | ||
subprocess.run(['./csv2json.py'] + glob.glob(f'{sim_file_path}.*.csv'), check=True) | ||
subprocess.run(['./bb2fline.py', f'{sim_file_path}.bb.csv', exe_path, '--addr2line', args.addr2line], check=True) | ||
subprocess.run(['./annotater.py', disasm, f'{sim_file_path}.json'], check=True) |