mirror of
https://github.com/isledecomp/isle.git
synced 2024-11-29 02:55:48 -05:00
recomp.py: use argparse to parse arguments (#30)
* recomp.py: use argparse to parse arguments * Address code revew comments * reccomp.py: -h/--help for help -H/--htmp for html * update CI to use new arg * slight string updates --------- Co-authored-by: itsmattkc <34096995+itsmattkc@users.noreply.github.com>
This commit is contained in:
parent
2644be3ca6
commit
da3ad91b20
2 changed files with 27 additions and 46 deletions
4
.github/workflows/build.yml
vendored
4
.github/workflows/build.yml
vendored
|
@ -60,8 +60,8 @@ jobs:
|
||||||
C:\msys64\usr\bin\wget.exe https://legoisland.org/download/ISLE.EXE
|
C:\msys64\usr\bin\wget.exe https://legoisland.org/download/ISLE.EXE
|
||||||
C:\msys64\usr\bin\wget.exe https://legoisland.org/download/LEGO1.DLL
|
C:\msys64\usr\bin\wget.exe https://legoisland.org/download/LEGO1.DLL
|
||||||
pip install capstone
|
pip install capstone
|
||||||
python3 tools/reccomp/reccomp.py -h ISLEPROGRESS.HTML ISLE.EXE Release/ISLE.EXE Release/ISLE.PDB ISLE
|
python3 tools/reccomp/reccomp.py -H ISLEPROGRESS.HTML ISLE.EXE Release/ISLE.EXE Release/ISLE.PDB ISLE
|
||||||
python3 tools/reccomp/reccomp.py -h LEGO1PROGRESS.HTML LEGO1.DLL Release/LEGO1.DLL Release/LEGO1.PDB LEGO1
|
python3 tools/reccomp/reccomp.py -H LEGO1PROGRESS.HTML LEGO1.DLL Release/LEGO1.DLL Release/LEGO1.PDB LEGO1
|
||||||
|
|
||||||
- name: Upload Artifact
|
- name: Upload Artifact
|
||||||
uses: actions/upload-artifact@master
|
uses: actions/upload-artifact@master
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
import argparse
|
||||||
from capstone import *
|
from capstone import *
|
||||||
import difflib
|
import difflib
|
||||||
import struct
|
import struct
|
||||||
|
@ -7,60 +8,40 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
def print_usage():
|
parser = argparse.ArgumentParser(allow_abbrev=False,
|
||||||
print('Usage: %s [options] <original-binary> <recompiled-binary> <recompiled-pdb> <decomp-dir>\n' % sys.argv[0])
|
description='Recomp Compare: compare an original EXE with a recompiled EXE + PDB.')
|
||||||
print('\t-v, --verbose <offset>\t\t\tPrint assembly diff for specific function (original file\'s offset)')
|
parser.add_argument('original', metavar='original-binary', help='The original binary')
|
||||||
print('\t-h, --html <output-file>\t\t\tGenerate searchable HTML summary of status and diffs')
|
parser.add_argument('recompiled', metavar='recompiled-binary', help='The recompiled binary')
|
||||||
sys.exit(1)
|
parser.add_argument('pdb', metavar='recompiled-pdb', help='The PDB of the recompiled binary')
|
||||||
|
parser.add_argument('decomp_dir', metavar='decomp-dir', help='The decompiled source tree')
|
||||||
|
parser.add_argument('--verbose', '-v', metavar='offset', help='Print assembly diff for specific function (original file\'s offset)')
|
||||||
|
parser.add_argument('--html', '-H', metavar='output-file', help='Generate searchable HTML summary of status and diffs')
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
positional_args = []
|
|
||||||
verbose = None
|
verbose = None
|
||||||
skip = False
|
if args.verbose:
|
||||||
html = None
|
try:
|
||||||
|
verbose = int(args.verbose, 16)
|
||||||
|
except ValueError:
|
||||||
|
parser.error('invalid verbose argument')
|
||||||
|
html = args.html
|
||||||
|
|
||||||
for i, arg in enumerate(sys.argv):
|
original = args.original
|
||||||
if skip:
|
|
||||||
skip = False
|
|
||||||
continue
|
|
||||||
|
|
||||||
if arg.startswith('-'):
|
|
||||||
# A flag rather than a positional arg
|
|
||||||
flag = arg[1:]
|
|
||||||
|
|
||||||
if flag == 'v' or flag == '-verbose':
|
|
||||||
verbose = int(sys.argv[i + 1], 16)
|
|
||||||
skip = True
|
|
||||||
elif flag == 'h' or flag == '-html':
|
|
||||||
html = sys.argv[i + 1]
|
|
||||||
skip = True
|
|
||||||
else:
|
|
||||||
print('Unknown flag: %s' % arg)
|
|
||||||
print_usage()
|
|
||||||
else:
|
|
||||||
positional_args.append(arg)
|
|
||||||
|
|
||||||
if len(positional_args) != 5:
|
|
||||||
print_usage()
|
|
||||||
|
|
||||||
original = positional_args[1]
|
|
||||||
if not os.path.isfile(original):
|
if not os.path.isfile(original):
|
||||||
print('Invalid input: Original binary does not exist')
|
parser.error('Original binary does not exist')
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
recomp = positional_args[2]
|
recomp = args.recompiled
|
||||||
if not os.path.isfile(recomp):
|
if not os.path.isfile(recomp):
|
||||||
print('Invalid input: Recompiled binary does not exist')
|
parser.error('Recompiled binary does not exist')
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
syms = positional_args[3]
|
syms = args.pdb
|
||||||
if not os.path.isfile(syms):
|
if not os.path.isfile(syms):
|
||||||
print('Invalid input: Symbols PDB does not exist')
|
parser.error('Symbols PDB does not exist')
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
source = positional_args[4]
|
source = args.decomp_dir
|
||||||
if not os.path.isdir(source):
|
if not os.path.isdir(source):
|
||||||
print('Invalid input: Source directory does not exist')
|
parser.error('Source directory does not exist')
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
# Declare a class that can automatically convert virtual executable addresses
|
# Declare a class that can automatically convert virtual executable addresses
|
||||||
# to file addresses
|
# to file addresses
|
||||||
|
|
Loading…
Reference in a new issue