copapy/tools/clean_asm.py

39 lines
925 B
Python
Raw Normal View History

2025-10-15 20:59:22 +00:00
import argparse
import re
2025-10-18 21:21:31 +00:00
2025-10-15 21:15:47 +00:00
def main() -> None:
2025-10-15 20:59:22 +00:00
parser = argparse.ArgumentParser()
parser.add_argument("path", type=str, help="Input file path")
args = parser.parse_args()
regex = r"(\:\n)(.*?)(^[^\n]+\n[^\n]+result_.*?\n\n)"
2025-10-15 21:15:43 +00:00
subst = "\\g<1><b>\\g<2></b><i>\\g<3></i>"
2025-10-15 20:59:22 +00:00
with open(args.path, 'rt') as f:
text = f.read()
outp_flag = "Disassembly of section .text" not in text
2025-10-15 21:15:47 +00:00
text = text.replace('\t', ' ' * 4)
2025-10-15 20:59:22 +00:00
text = text.replace('>', '&gt;')
text = text.replace('<', '&lt;')
text = re.sub(regex, subst, text, 0, re.MULTILINE | re.DOTALL)
2025-10-15 21:15:43 +00:00
text = re.sub(r"(?<= ) ", "&nbsp;", text, 0, re.MULTILINE | re.DOTALL)
2025-10-15 21:15:47 +00:00
2025-10-15 20:59:22 +00:00
print('<code>')
for line in text.splitlines():
if outp_flag:
2025-10-15 21:15:47 +00:00
print(line + '<br>')
2025-10-15 20:59:22 +00:00
if "Disassembly of section .text:" in line:
outp_flag = True
2025-10-18 21:21:31 +00:00
2025-10-15 20:59:22 +00:00
print('</code>')
2025-10-18 21:21:31 +00:00
2025-10-15 20:59:22 +00:00
if __name__ == "__main__":
2025-10-15 21:15:47 +00:00
main()