mirror of
https://github.com/mandiant/capa.git
synced 2025-12-22 15:16:22 -08:00
py3: remove six
As we are not supporting Python 2 any longer, we can stop using six and use the equivalent Python 3 method instead.
This commit is contained in:
@@ -10,7 +10,6 @@ import logging
|
|||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
import idc
|
import idc
|
||||||
import six
|
|
||||||
import idaapi
|
import idaapi
|
||||||
import idautils
|
import idautils
|
||||||
|
|
||||||
@@ -85,7 +84,7 @@ def get_func_start_ea(ea):
|
|||||||
def get_file_md5():
|
def get_file_md5():
|
||||||
""" """
|
""" """
|
||||||
md5 = idautils.GetInputFileMD5()
|
md5 = idautils.GetInputFileMD5()
|
||||||
if not isinstance(md5, six.string_types):
|
if not isinstance(md5, str):
|
||||||
md5 = capa.features.bytes_to_str(md5)
|
md5 = capa.features.bytes_to_str(md5)
|
||||||
return md5
|
return md5
|
||||||
|
|
||||||
@@ -93,7 +92,7 @@ def get_file_md5():
|
|||||||
def get_file_sha256():
|
def get_file_sha256():
|
||||||
""" """
|
""" """
|
||||||
sha256 = idaapi.retrieve_input_file_sha256()
|
sha256 = idaapi.retrieve_input_file_sha256()
|
||||||
if not isinstance(sha256, six.string_types):
|
if not isinstance(sha256, str):
|
||||||
sha256 = capa.features.bytes_to_str(sha256)
|
sha256 = capa.features.bytes_to_str(sha256)
|
||||||
return sha256
|
return sha256
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
# Unless required by applicable law or agreed to in writing, software distributed under the License
|
# Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||||
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and limitations under the License.
|
# See the License for the specific language governing permissions and limitations under the License.
|
||||||
import six
|
|
||||||
from PyQt5 import QtCore
|
from PyQt5 import QtCore
|
||||||
from PyQt5.QtCore import Qt
|
from PyQt5.QtCore import Qt
|
||||||
|
|
||||||
@@ -208,7 +207,7 @@ class CapaExplorerSearchProxyModel(QtCore.QSortFilterProxyModel):
|
|||||||
if not data:
|
if not data:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not isinstance(data, six.string_types):
|
if not isinstance(data, str):
|
||||||
# sanity check: should already be a string, but double check
|
# sanity check: should already be a string, but double check
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,6 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
import capa.rules
|
import capa.rules
|
||||||
import capa.engine
|
import capa.engine
|
||||||
|
|
||||||
@@ -249,7 +247,7 @@ class CapaJsonObjectEncoder(json.JSONEncoder):
|
|||||||
"""JSON encoder that emits Python sets as sorted lists"""
|
"""JSON encoder that emits Python sets as sorted lists"""
|
||||||
|
|
||||||
def default(self, obj):
|
def default(self, obj):
|
||||||
if isinstance(obj, (list, dict, int, float, bool, type(None))) or isinstance(obj, six.string_types):
|
if isinstance(obj, (list, dict, int, float, bool, type(None))) or isinstance(obj, str):
|
||||||
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))
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
|
|
||||||
import collections
|
import collections
|
||||||
|
|
||||||
import six
|
|
||||||
import tabulate
|
import tabulate
|
||||||
|
|
||||||
import capa.render.utils as rutils
|
import capa.render.utils as rutils
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
# See the License for the specific language governing permissions and limitations under the License.
|
# See the License for the specific language governing permissions and limitations under the License.
|
||||||
|
|
||||||
import six
|
import io
|
||||||
|
|
||||||
import termcolor
|
import termcolor
|
||||||
|
|
||||||
|
|
||||||
@@ -49,7 +50,7 @@ def capability_rules(doc):
|
|||||||
yield rule
|
yield rule
|
||||||
|
|
||||||
|
|
||||||
class StringIO(six.StringIO):
|
class StringIO(io.StringIO):
|
||||||
def writeln(self, s):
|
def writeln(self, s):
|
||||||
self.write(s)
|
self.write(s)
|
||||||
self.write("\n")
|
self.write("\n")
|
||||||
|
|||||||
@@ -18,7 +18,8 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
from backports.functools_lru_cache import lru_cache
|
from backports.functools_lru_cache import lru_cache
|
||||||
|
|
||||||
import six
|
import io
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
import ruamel.yaml
|
import ruamel.yaml
|
||||||
|
|
||||||
@@ -244,7 +245,7 @@ def parse_description(s, value_type, description=None):
|
|||||||
"""
|
"""
|
||||||
s can be an int or a string
|
s can be an int or a string
|
||||||
"""
|
"""
|
||||||
if value_type != "string" and isinstance(s, six.string_types) and DESCRIPTION_SEPARATOR in s:
|
if value_type != "string" and isinstance(s, str) and DESCRIPTION_SEPARATOR in s:
|
||||||
if description:
|
if description:
|
||||||
raise InvalidRule(
|
raise InvalidRule(
|
||||||
'unexpected value: "%s", only one description allowed (inline description with `%s`)'
|
'unexpected value: "%s", only one description allowed (inline description with `%s`)'
|
||||||
@@ -256,7 +257,7 @@ def parse_description(s, value_type, description=None):
|
|||||||
else:
|
else:
|
||||||
value = s
|
value = s
|
||||||
|
|
||||||
if isinstance(value, six.string_types):
|
if isinstance(value, str):
|
||||||
if value_type == "bytes":
|
if value_type == "bytes":
|
||||||
try:
|
try:
|
||||||
value = codecs.decode(value.replace(" ", ""), "hex")
|
value = codecs.decode(value.replace(" ", ""), "hex")
|
||||||
@@ -406,7 +407,7 @@ def build_statements(d, scope):
|
|||||||
return Range(feature, min=min, max=max, description=description)
|
return Range(feature, min=min, max=max, description=description)
|
||||||
else:
|
else:
|
||||||
raise InvalidRule("unexpected range: %s" % (count))
|
raise InvalidRule("unexpected range: %s" % (count))
|
||||||
elif key == "string" and not isinstance(d[key], six.string_types):
|
elif key == "string" and not isinstance(d[key], str):
|
||||||
raise InvalidRule("ambiguous string value %s, must be defined as explicit string" % d[key])
|
raise InvalidRule("ambiguous string value %s, must be defined as explicit string" % d[key])
|
||||||
else:
|
else:
|
||||||
Feature = parse_feature(key)
|
Feature = parse_feature(key)
|
||||||
@@ -699,7 +700,7 @@ class Rule(object):
|
|||||||
for key in hidden_meta.keys():
|
for key in hidden_meta.keys():
|
||||||
del meta[key]
|
del meta[key]
|
||||||
|
|
||||||
ostream = six.BytesIO()
|
ostream = io.BytesIO()
|
||||||
self._get_ruamel_yaml_parser().dump(definition, ostream)
|
self._get_ruamel_yaml_parser().dump(definition, ostream)
|
||||||
|
|
||||||
for key, value in hidden_meta.items():
|
for key, value in hidden_meta.items():
|
||||||
@@ -938,7 +939,7 @@ class RuleSet(object):
|
|||||||
rules_filtered = set([])
|
rules_filtered = set([])
|
||||||
for rule in rules:
|
for rule in rules:
|
||||||
for k, v in rule.meta.items():
|
for k, v in rule.meta.items():
|
||||||
if isinstance(v, six.string_types) and tag in v:
|
if isinstance(v, str) and tag in v:
|
||||||
logger.debug('using rule "%s" and dependencies, found tag in meta.%s: %s', rule.name, k, v)
|
logger.debug('using rule "%s" and dependencies, found tag in meta.%s: %s', rule.name, k, v)
|
||||||
rules_filtered.update(set(capa.rules.get_rules_and_dependencies(rules, rule.name)))
|
rules_filtered.update(set(capa.rules.get_rules_and_dependencies(rules, rule.name)))
|
||||||
break
|
break
|
||||||
|
|||||||
Reference in New Issue
Block a user