mirror of
https://github.com/mandiant/capa.git
synced 2025-12-23 07:28:34 -08:00
Python3 support for vivisect
Vivisect has moved to Python3. Allow to run vivisect with Python3 in capa. I am using the following version of vivisect (which includes fixes for some bugs I have found and some open PRs in vivisect): https://github.com/Ana06/vivisect/tree/py-3
This commit is contained in:
@@ -8,11 +8,7 @@
|
|||||||
|
|
||||||
import types
|
import types
|
||||||
|
|
||||||
import file
|
|
||||||
import insn
|
|
||||||
import function
|
|
||||||
import viv_utils
|
import viv_utils
|
||||||
import basicblock
|
|
||||||
|
|
||||||
import capa.features.extractors
|
import capa.features.extractors
|
||||||
import capa.features.extractors.viv.file
|
import capa.features.extractors.viv.file
|
||||||
@@ -42,7 +38,7 @@ def add_va_int_cast(o):
|
|||||||
this bit of skullduggery lets use cast viv-utils objects as ints.
|
this bit of skullduggery lets use cast viv-utils objects as ints.
|
||||||
the correct way of doing this is to update viv-utils (or subclass the objects here).
|
the correct way of doing this is to update viv-utils (or subclass the objects here).
|
||||||
"""
|
"""
|
||||||
setattr(o, "__int__", types.MethodType(get_va, o, type(o)))
|
setattr(o, "__int__", types.MethodType(get_va, o))
|
||||||
return o
|
return o
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -125,11 +125,16 @@ def get_printable_len(oper):
|
|||||||
|
|
||||||
|
|
||||||
def is_printable_ascii(chars):
|
def is_printable_ascii(chars):
|
||||||
return all(ord(c) < 127 and c in string.printable for c in chars)
|
try:
|
||||||
|
chars_str = chars.decode("ascii")
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return all(c in string.printable for c in chars_str)
|
||||||
|
|
||||||
|
|
||||||
def is_printable_utf16le(chars):
|
def is_printable_utf16le(chars):
|
||||||
if all(c == "\x00" for c in chars[1::2]):
|
if all(c == b"\x00" for c in chars[1::2]):
|
||||||
return is_printable_ascii(chars[::2])
|
return is_printable_ascii(chars[::2])
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
16
capa/main.py
16
capa/main.py
@@ -32,7 +32,7 @@ import capa.features.extractors
|
|||||||
from capa.helpers import oint, get_file_taste
|
from capa.helpers import oint, get_file_taste
|
||||||
|
|
||||||
RULES_PATH_DEFAULT_STRING = "(embedded rules)"
|
RULES_PATH_DEFAULT_STRING = "(embedded rules)"
|
||||||
SUPPORTED_FILE_MAGIC = set(["MZ"])
|
SUPPORTED_FILE_MAGIC = set([b"MZ"])
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger("capa")
|
logger = logging.getLogger("capa")
|
||||||
@@ -304,6 +304,7 @@ class UnsupportedRuntimeError(RuntimeError):
|
|||||||
|
|
||||||
|
|
||||||
def get_extractor_py3(path, format, disable_progress=False):
|
def get_extractor_py3(path, format, disable_progress=False):
|
||||||
|
if False:
|
||||||
from smda.SmdaConfig import SmdaConfig
|
from smda.SmdaConfig import SmdaConfig
|
||||||
from smda.Disassembler import Disassembler
|
from smda.Disassembler import Disassembler
|
||||||
|
|
||||||
@@ -317,6 +318,19 @@ def get_extractor_py3(path, format, disable_progress=False):
|
|||||||
smda_report = smda_disasm.disassembleFile(path)
|
smda_report = smda_disasm.disassembleFile(path)
|
||||||
|
|
||||||
return capa.features.extractors.smda.SmdaFeatureExtractor(smda_report, path)
|
return capa.features.extractors.smda.SmdaFeatureExtractor(smda_report, path)
|
||||||
|
else:
|
||||||
|
import capa.features.extractors.viv
|
||||||
|
|
||||||
|
with halo.Halo(text="analyzing program", spinner="simpleDots", stream=sys.stderr, enabled=not disable_progress):
|
||||||
|
vw = get_workspace(path, format, should_save=False)
|
||||||
|
|
||||||
|
try:
|
||||||
|
vw.saveWorkspace()
|
||||||
|
except IOError:
|
||||||
|
# see #168 for discussion around how to handle non-writable directories
|
||||||
|
logger.info("source directory is not writable, won't save intermediate workspace")
|
||||||
|
|
||||||
|
return capa.features.extractors.viv.VivisectFeatureExtractor(vw, path)
|
||||||
|
|
||||||
|
|
||||||
def get_extractor(path, format, disable_progress=False):
|
def get_extractor(path, format, disable_progress=False):
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -27,6 +27,8 @@ if sys.version_info >= (3, 0):
|
|||||||
# py3
|
# py3
|
||||||
requirements.append("halo")
|
requirements.append("halo")
|
||||||
requirements.append("networkx")
|
requirements.append("networkx")
|
||||||
|
requirements.append("vivisect @ git+https://github.com/Ana06/vivisect@py-3#egg=vivisect")
|
||||||
|
requirements.append("viv-utils==0.3.19")
|
||||||
requirements.append("smda==1.5.13")
|
requirements.append("smda==1.5.13")
|
||||||
else:
|
else:
|
||||||
# py2
|
# py2
|
||||||
|
|||||||
Reference in New Issue
Block a user