diff options
| author | Aetias <aetias@outlook.com> | 2024-03-19 00:56:32 +0100 |
|---|---|---|
| committer | Aetias <aetias@outlook.com> | 2024-03-19 00:56:32 +0100 |
| commit | 16660f579501eb0566cba86d59002fec7d4fb99f (patch) | |
| tree | 777c9c286bb59d880b827b11edcdb499831690af | |
| parent | 6f5558cf657e4413628107391fda1feda959bcc0 (diff) | |
Add name mangling tool
| -rw-r--r-- | tools/mangle.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tools/mangle.py b/tools/mangle.py new file mode 100644 index 00000000..cc7e0660 --- /dev/null +++ b/tools/mangle.py @@ -0,0 +1,36 @@ +import argparse +import os +from pathlib import Path +import platform +import re +import subprocess + +parser = argparse.ArgumentParser(description='Mangles function declarations') +parser.add_argument('file', help='C/C++ source file with defined function to mangle') + +tools_dir = Path(os.path.dirname(os.path.realpath(__file__))) +cc_path = tools_dir / 'mwccarm' / '2.0' / 'sp1p5' / 'mwccarm.exe' +root_dir = tools_dir.parent +include_dir = root_dir / 'include' + +if platform.system() == 'Windows': cc = [str(cc_path)] +else: cc = ['wine', str(cc_path)] + +args = parser.parse_args() + +cc.extend([ + '-nolink', + '-dis', + f'-I{include_dir}', + '-DSTUBS', + args.file +]) + +output = subprocess.check_output(cc) +output = output.decode() + +# print(output) + +mangled_names: list[str] = re.findall(r'.text +(_Z\S+)', output) +for name in mangled_names: + print(name) |
