dev-python/egghatch: 0.2.3 port to py3

Thanks for https://github.com/hatching/egghatch/pull/2

Package-Manager: Portage-2.3.89, Repoman-2.3.20
Signed-off-by: Yury Martynov <email@linxon.ru>
This commit is contained in:
Yury Martynov 2020-03-02 08:44:15 +03:00
parent 7c13e994cf
commit 21aaaa156a
No known key found for this signature in database
GPG key ID: EBE62DD0CCEAE19E
3 changed files with 130 additions and 8 deletions

View file

@ -1,10 +1,10 @@
# Copyright 1999-2019 Gentoo Authors
# Copyright 1999-2020 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
EAPI=7
PYTHON_COMPAT=( python2_7 )
#python3_{5,6} )
PYTHON_COMPAT=( python3_{6,7} )
inherit distutils-r1
DESCRIPTION="Cuckoo Sandbox Shellcode Identification & Formatting"
@ -14,9 +14,10 @@ SRC_URI="mirror://pypi/${PN:0:1}/${PN}/${P}.tar.gz"
LICENSE="GPL-3"
SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE="test"
RDEPEND="dev-libs/capstone[python,${PYTHON_USEDEP}]
!!dev-libs/capstone-bindings"
DEPEND="${RDEPEND}
dev-python/setuptools[${PYTHON_USEDEP}]"
RDEPEND="${PYTHON_DEPS}
dev-libs/capstone[python,${PYTHON_USEDEP}]
dev-python/future[${PYTHON_USEDEP}]"
DEPEND="${RDEPEND}"
PATCHES=( "${FILESDIR}/${P}_add_Python3.6_support.patch" )

View file

@ -0,0 +1,113 @@
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 <sc.bin>" % sys.argv[0]
+ print("Usage: python %s <sc.bin>" % 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'": [

View file

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE pkgmetadata SYSTEM "http://www.gentoo.org/dtd/metadata.dtd">
<pkgmetadata>
<maintainer type="project">
<email>proxy-maint@gentoo.org</email>
<name>Proxy Maintainers</name>
</maintainer>
</pkgmetadata>