mirror of
https://github.com/mandiant/capa.git
synced 2025-12-23 07:28:34 -08:00
Merge branch 'master' of github.com:fireeye/capa
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import codecs
|
import codecs
|
||||||
import logging
|
import logging
|
||||||
|
import sys
|
||||||
|
|
||||||
import capa.engine
|
import capa.engine
|
||||||
|
|
||||||
@@ -8,6 +9,13 @@ logger = logging.getLogger(__name__)
|
|||||||
MAX_BYTES_FEATURE_SIZE = 0x100
|
MAX_BYTES_FEATURE_SIZE = 0x100
|
||||||
|
|
||||||
|
|
||||||
|
def bytes_to_str(b):
|
||||||
|
if sys.version_info[0] >= 3:
|
||||||
|
return str(codecs.encode(b, 'hex').decode('utf-8'))
|
||||||
|
else:
|
||||||
|
return codecs.encode(b, 'hex')
|
||||||
|
|
||||||
|
|
||||||
class Feature(object):
|
class Feature(object):
|
||||||
def __init__(self, args):
|
def __init__(self, args):
|
||||||
super(Feature, self).__init__()
|
super(Feature, self).__init__()
|
||||||
@@ -100,14 +108,14 @@ class Bytes(Feature):
|
|||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if self.symbol:
|
if self.symbol:
|
||||||
return 'bytes(0x%s = %s)' % (codecs.encode(self.value, 'hex').upper(), self.symbol)
|
return 'bytes(0x%s = %s)' % (bytes_to_str(self.value).upper(), self.symbol)
|
||||||
else:
|
else:
|
||||||
return 'bytes(0x%s)' % (codecs.encode(self.value, 'hex').upper())
|
return 'bytes(0x%s)' % (bytes_to_str(self.value).upper())
|
||||||
|
|
||||||
def freeze_serialize(self):
|
def freeze_serialize(self):
|
||||||
return (self.__class__.__name__,
|
return (self.__class__.__name__,
|
||||||
map(lambda x: codecs.encode(x, 'hex').upper(), self.args))
|
[bytes_to_str(x).upper() for x in self.args])
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def freeze_deserialize(cls, args):
|
def freeze_deserialize(cls, args):
|
||||||
return cls(*map(lambda x: codecs.decode(x, 'hex'), args))
|
return cls(*[codecs.decode(x, 'hex') for x in args])
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
import six
|
||||||
|
|
||||||
import capa.engine
|
import capa.engine
|
||||||
|
|
||||||
@@ -261,7 +262,7 @@ def render_default(rules, capabilities):
|
|||||||
|
|
||||||
class CapaJsonObjectEncoder(json.JSONEncoder):
|
class CapaJsonObjectEncoder(json.JSONEncoder):
|
||||||
def default(self, obj):
|
def default(self, obj):
|
||||||
if isinstance(obj, (list, dict, str, unicode, int, float, bool, type(None))):
|
if isinstance(obj, (list, dict, int, float, bool, type(None))) or isinstance(obj, six.string_types):
|
||||||
return json.JSONEncoder.default(self, obj)
|
return json.JSONEncoder.default(self, obj)
|
||||||
elif isinstance(obj, set):
|
elif isinstance(obj, set):
|
||||||
return list(sorted(obj))
|
return list(sorted(obj))
|
||||||
|
|||||||
Reference in New Issue
Block a user