Skip to content

Commit

Permalink
Merge pull request #313 from Ana06/fix-pep8
Browse files Browse the repository at this point in the history
Fix pep8 in Travis and fix offenses
  • Loading branch information
williballenthin committed Oct 8, 2019
2 parents 56fc202 + 02ae394 commit 5edb188
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ matrix:

install:
- pip install https://github.com/williballenthin/vivisect/zipball/master
- pip install pyinstaller pep8
- pip install pyinstaller pycodestyle
- echo "__version__ = '$(git describe --tags --always)'" > floss/version.py
- cat floss/version.py
- pip install -e .
Expand All @@ -28,7 +28,7 @@ install:
- pyinstaller floss.spec

script:
- find . -name \*.py -exec pep8 --ignore=E501 {} \;
- pycodestyle --ignore=E501 .
# haven't figured how to build wclang on osx yet, so no tests
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then py.test tests/src/ -v; fi

Expand Down
1 change: 1 addition & 0 deletions floss/api_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,7 @@ class CriticalSectionHooks(viv_utils.emulator_drivers.Hook):
Hook calls to:
- InitializeCriticalSection
'''

def hook(self, callname, emu, callconv, api, argv):
if callname == "kernel32.InitializeCriticalSection":
hsection, = argv
Expand Down
1 change: 1 addition & 0 deletions floss/decoding_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class DebugMonitor(viv_utils.emulator_drivers.Monitor):
"""
Emulator monitor that is useful during debugging.
"""

def __init__(self, *args, **kwargs):
super(DebugMonitor, self).__init__(*args, **kwargs)

Expand Down
1 change: 1 addition & 0 deletions floss/function_argument_getter.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

class CallMonitor(viv_utils.emulator_drivers.Monitor):
""" collect call arguments to a target function during emulation """

def __init__(self, vivisect_workspace, target_fva):
""" :param target_fva: address of function whose arguments to monitor """
viv_utils.emulator_drivers.Monitor.__init__(self, vivisect_workspace)
Expand Down
1 change: 1 addition & 0 deletions floss/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class DecodingRoutineIdentifier(Interface):
Return mapping from function virtual addresses to score of likelihood to be
a decoding function.
"""

def identify(self, vivisect_workspace, function_vas):
"""
Expand Down
30 changes: 17 additions & 13 deletions floss/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,11 @@ def make_parser():

return parser


def set_logging_levels(should_debug=False, should_verbose=False):
"""
Sets the logging levels of each of Floss's loggers individually.
Recomended to use if Floss is being used as a library, and your
Sets the logging levels of each of Floss's loggers individually.
Recomended to use if Floss is being used as a library, and your
project has its own logging set up. If both parameters 'should_debug'
and 'should_verbose' are false, the logging level will be set to ERROR.
:param should_debug: set logging level to DEBUG
Expand Down Expand Up @@ -311,12 +312,12 @@ def set_logging_levels(should_debug=False, should_verbose=False):
# ignore messages like:
# DEBUG: identify: suspicious MOV instruction at 0x00401017 in function 0x00401000: mov byte [edx],al
logging.getLogger("floss.plugins.mov_plugin.MovPlugin").setLevel(log_level)


def set_log_config(should_debug=False, should_verbose=False):
"""
Removes root logging handlers, and sets Floss's logging level.
Recomended to use if Floss is being used in a standalone script, or
Recomended to use if Floss is being used in a standalone script, or
your project doesn't have any loggers. If both parameters 'should_debug'
and 'should_verbose' are false, the logging level will be set to ERROR.
:param should_debug: set logging level to DEBUG
Expand Down Expand Up @@ -559,13 +560,13 @@ def create_x64dbg_database_content(sample_file_path, imagebase, decoded_strings)
rva = hex(ds.va - imagebase)
try:
processed[rva] += "\t" + sanitized_string
except:
except BaseException:
processed[rva] = "FLOSS: " + sanitized_string
else:
rva = hex(ds.decoded_at_va - imagebase)
try:
processed[rva] += "\t" + sanitized_string
except:
except BaseException:
processed[rva] = "FLOSS: " + sanitized_string

for i in processed.keys():
Expand Down Expand Up @@ -713,15 +714,15 @@ def AppendComment(ea, s):
fn.set_comment_at(addr.address, string)
def AppendLvarComment(fva, pc, s):
# stack var comments are not a thing in Binary Ninja so just add at top of function
# and at location where it's used as an arg
s = s.encode('ascii')
fn = bv.get_function_at(fva)
for addr in [fva, pc]:
string = fn.get_comment_at(addr)
if not string:
string = s
else:
Expand All @@ -737,6 +738,7 @@ def AppendLvarComment(fva, pc, s):
""" % (len(decoded_strings) + ss_len, sample_file_path, "\n".join(main_commands))
return script_content


def create_r2_script_content(sample_file_path, decoded_strings, stack_strings):
"""
Create r2script contents for r2 session annotations.
Expand Down Expand Up @@ -807,6 +809,7 @@ def create_ida_script(sample_file_path, ida_python_file, decoded_strings, stack_
raise e
# TODO return, catch exception in main()


def create_binja_script(sample_file_path, binja_script_file, decoded_strings, stack_strings):
"""
Create a Binary Ninja script to annotate a BNDB file with decoded strings.
Expand All @@ -825,6 +828,7 @@ def create_binja_script(sample_file_path, binja_script_file, decoded_strings, st
raise e
# TODO return, catch exception in main()


def create_r2_script(sample_file_path, r2_script_file, decoded_strings, stack_strings):
"""
Create an r2script to annotate r2 session with decoded strings.
Expand Down Expand Up @@ -871,7 +875,7 @@ def print_static_strings(path, min_length, quiet=False):
if not quiet:
print("")

if os.path.getsize(path) > sys.maxint:
if os.path.getsize(path) > sys.maxsize:
floss_logger.warning("File too large, strings listings may be truncated.")
floss_logger.warning("FLOSS cannot handle files larger than 4GB on 32bit systems.")

Expand Down Expand Up @@ -918,7 +922,7 @@ def print_file_meta_info(vw, selected_functions):
try:
for k, v in get_vivisect_meta_info(vw, selected_functions).iteritems():
print("%s: %s" % (k, v or "N/A")) # display N/A if value is None
except Exception, e:
except Exception as e:
floss_logger.error("Failed to print vivisect analysis information: {0}".format(e.message))


Expand Down Expand Up @@ -964,10 +968,10 @@ def load_vw(sample_file_path, save_workspace, verbose, is_shellcode, shellcode_e
return load_workspace(sample_file_path, save_workspace)
else:
return load_shellcode_workspace(sample_file_path, save_workspace, shellcode_entry_point, shellcode_base)
except LoadNotSupportedError, e:
except LoadNotSupportedError as e:
floss_logger.error(str(e))
raise WorkspaceLoadError
except Exception, e:
except Exception as e:
floss_logger.error("Vivisect failed to load the input file: {0}".format(e.message), exc_info=verbose)
raise WorkspaceLoadError

Expand Down
2 changes: 1 addition & 1 deletion floss/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from collections import namedtuple


ASCII_BYTE = " !\"#\$%&\'\(\)\*\+,-\./0123456789:;<=>\?@ABCDEFGHIJKLMNOPQRSTUVWXYZ\[\]\^_`abcdefghijklmnopqrstuvwxyz\{\|\}\\\~\t"
ASCII_BYTE = r" !\"#\$%&\'\(\)\*\+,-\./0123456789:;<=>\?@ABCDEFGHIJKLMNOPQRSTUVWXYZ\[\]\^_`abcdefghijklmnopqrstuvwxyz\{\|\}\\\~\t"
ASCII_RE_4 = re.compile("([%s]{%d,})" % (ASCII_BYTE, 4))
UNICODE_RE_4 = re.compile(b"((?:[%s]\x00){%d,})" % (ASCII_BYTE, 4))
REPEATS = ["A", "\x00", "\xfe", "\xff"]
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,6 @@ def repr_failure(self, excinfo):
"FLOSS extraction failed:",
" expected: %s" % str(expected),
" got: %s" % str(got),
" expected-got: %s" % str(set(expected)-set(got)),
" expected-got: %s" % str(set(expected) - set(got)),
" got-expected: %s" % str(set(got) - set(expected)),
])
3 changes: 1 addition & 2 deletions tests/test_buf_filled_with.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
tests = [
("A", True),
("AB", False),
("A" * 10000, True),
("A" * 10000, True),
(("A" * 10000) + "B", False),
("B" + ("A" * 5000), False),
(("A" * 5000) + "B" + ("A" * 2000), False),
Expand All @@ -32,4 +32,3 @@ def test_mmap():
f.flush()
test_mmap = mmap.mmap(f.fileno(), 0, access=mmap.ACCESS_READ)
assert buf_filled_with(test_mmap, test_mmap[0]) == expectation

0 comments on commit 5edb188

Please sign in to comment.