diff -ur a/egghatch/main.py b/egghatch/main.py --- a/egghatch/main.py 2018-03-29 20:44:29.000000000 +0300 +++ b/egghatch/main.py 2020-03-02 08:32:22.766426957 +0300 @@ -9,10 +9,10 @@ def main(): if len(sys.argv) != 2: - print "Usage: python %s " % sys.argv[0] + print("Usage: python %s " % sys.argv[0]) exit(1) - print Shellcode(open(sys.argv[1], "rb").read()).to_json() + print(Shellcode(open(sys.argv[1], "rb").read()).to_json()) def parse(payload): return Shellcode(payload).to_dict() diff -ur a/egghatch/misc.py b/egghatch/misc.py --- a/egghatch/misc.py 2018-03-29 20:44:29.000000000 +0300 +++ b/egghatch/misc.py 2020-03-02 08:32:54.685192618 +0300 @@ -2,6 +2,9 @@ # This file is part of Cuckoo Sandbox - https://cuckoosandbox.org/. # See the file 'docs/LICENSE' for copying permission. +from builtins import int +from past.builtins import basestring + def str_as_db(s): r1 = [] for ch in s: @@ -14,7 +17,8 @@ r2, idx = [], 0 while idx < len(r1): - if isinstance(r1[idx], (int, long)): + print(type(r1[idx]),isinstance(r1[idx], str)) + if isinstance(r1[idx], int): r2.append("%s" % r1[idx]) idx += 1 continue diff -ur a/egghatch/shellcode.py b/egghatch/shellcode.py --- a/egghatch/shellcode.py 2018-04-01 16:05:45.000000000 +0300 +++ b/egghatch/shellcode.py 2020-03-02 08:34:49.022168624 +0300 @@ -5,6 +5,8 @@ import json from egghatch.block import Block +from builtins import range +import base64 class Shellcode(object): def __init__(self, payload): @@ -36,7 +38,15 @@ ret["bbl"] = sorted(self.bbl.items()) ret["text"] = sorted(self.insns) for idx, data in sorted(self.data.items()): - ret["data"].append((idx, data.decode("latin1"))) + if isinstance(data, str): + # Python2 + ret["data"].append((idx, "".join(data.decode("utf-8")))) + elif isinstance(data, bytes): + # Python3 + ret["data"].append((idx, "".join([chr(x) for x in data]))) + else: + print("Warning, wrong type received in data : %s" % type(data)) + ret = "" return ret def to_json(self): @@ -135,7 +145,7 @@ continue op = insn2.operands - for _ in xrange(64): + for _ in range(64): if insn2.addr + insn2.size not in insns: break @@ -156,7 +166,7 @@ parsed[len(self.payload)] = len(self.payload) chunks = sorted(parsed.items()) - for idx in xrange(1, len(chunks)): + for idx in range(1, len(chunks)): _, start = chunks[idx-1] end, _ = chunks[idx] if start != end and start < end: diff -ur a/setup.py b/setup.py --- a/setup.py 2018-06-21 21:46:46.000000000 +0300 +++ b/setup.py 2020-03-02 08:35:44.661253884 +0300 @@ -22,13 +22,13 @@ "Natural Language :: English", "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", "Operating System :: POSIX :: Linux", - "Programming Language :: Python :: 2.7", + "Programming Language :: Python :: 2.7, 3.6", "Topic :: Security", ], url="https://cuckoosandbox.org/", license="GPLv3", description="Cuckoo Sandbox Shellcode Identification & Formatting", - long_description=open("README.rst", "rb").read(), + long_description=open("README.rst", "r").read(), include_package_data=True, entry_points={ "console_scripts": [ @@ -36,6 +36,7 @@ ], }, install_requires=[ + "future", ], extras_require={ ":sys_platform == 'win32'": [