From 75b6511f972a7b71b4fb5ddff126062a3a8c6a91 Mon Sep 17 00:00:00 2001 From: tisf Date: Wed, 14 Jun 2023 10:28:25 +0700 Subject: [PATCH] py3 support and requirements --- assembler.py | 5 ++++- disassembler.py | 5 ++++- main.py | 17 ++++++++++++++--- requirements.txt | 4 ++++ verifier.py | 2 +- 5 files changed, 27 insertions(+), 6 deletions(-) create mode 100644 requirements.txt diff --git a/assembler.py b/assembler.py index 5e7125f..240bccb 100644 --- a/assembler.py +++ b/assembler.py @@ -1,6 +1,9 @@ import logging -import cStringIO +try: + import cStringIO +except: + from io import StringIO as cStringIO import networkx as nx import dis diff --git a/disassembler.py b/disassembler.py index ec8a8a0..4ac5145 100644 --- a/disassembler.py +++ b/disassembler.py @@ -1,4 +1,7 @@ -import Queue +try: + import Queue +except: + import queue as Queue import logging import collections import dis diff --git a/main.py b/main.py index d638d0f..de1dd56 100644 --- a/main.py +++ b/main.py @@ -49,11 +49,22 @@ def process(ifile, ofile): logger.info('Opening file ' + ifile) ifPtr = open(ifile, 'rb') header = ifPtr.read(8) - if not header.startswith('\x03\xF3\x0D\x0A'): - raise SystemExit('[!] Header mismatch. The input file is not a valid pyc file.') + if not header.startswith(b'\x03\xF3\x0D\x0A'): + print("Header mismatch. The input file is not a valid pyc file.") + while True: + user_input = input("Do you want to continue? (y/n): ") + if user_input.lower() == 'n': + raise SystemExit('[!] Header mismatch. The input file is not a valid pyc file.') + elif user_input.lower() == 'y': + break + else: + print("Invalid input. Please enter 'y' or 'n'.") logger.info('Input pyc file header matched') logger.debug('Unmarshalling file') - rootCodeObject = marshal.load(ifPtr) + try: + rootCodeObject = marshal.load(ifPtr) + except ValueError: + raise SystemExit('[!] Failed to unmarshal file. The input file is not a valid pyc file.') ifPtr.close() deob = parse_code_object(rootCodeObject) logger.info('Writing deobfuscated code object to disk') diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..1bf6e84 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +pefile +uncompyle6 +networkx +pydotplus \ No newline at end of file diff --git a/verifier.py b/verifier.py index 1913181..965a43f 100644 --- a/verifier.py +++ b/verifier.py @@ -66,6 +66,6 @@ def verify_graph(bb_graph): logger.error('Orphaned block {} has no edges'.format(hex(id(bb)))) except Exception as ex: - print ex + print(ex) return False return True