Commit 14eda44c by devttys0

Added binwalk.common.core.debug function

parent 9a5a7237
...@@ -47,8 +47,9 @@ class FunctionHandler(object): ...@@ -47,8 +47,9 @@ class FunctionHandler(object):
Returns None. Returns None.
''' '''
self.name = function.name
self.retype = function.type self.retype = function.type
self.function = getattr(library, function.name) self.function = getattr(library, self.name)
if has_key(self.PY2CTYPES, self.retype): if has_key(self.PY2CTYPES, self.retype):
self.function.restype = self.PY2CTYPES[self.retype] self.function.restype = self.PY2CTYPES[self.retype]
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
import io import io
import os import os
import re import re
import sys
import ast import ast
import hashlib import hashlib
import operator as op import operator as op
...@@ -14,6 +15,16 @@ if has_key(__builtins__, 'BLOCK_FILE_PARENT_CLASS'): ...@@ -14,6 +15,16 @@ if has_key(__builtins__, 'BLOCK_FILE_PARENT_CLASS'):
else: else:
BLOCK_FILE_PARENT_CLASS = io.FileIO BLOCK_FILE_PARENT_CLASS = io.FileIO
def debug(msg):
'''
Displays debug messages to stderr only if the Python interpreter was invoked with the -O flag.
'''
# The __debug__ value is a bit backwards; by default it is set to True, but
# then set to False if the Python interpreter is run with the -O option.
if not __debug__:
sys.stderr.write("DEBUG: " + msg + "\n")
sys.stderr.flush()
def file_md5(file_name): def file_md5(file_name):
''' '''
Generate an MD5 hash of the specified file. Generate an MD5 hash of the specified file.
......
import binwalk.core.C import binwalk.core.C
import binwalk.core.common
from binwalk.core.compat import * from binwalk.core.compat import *
class Magic(object): class Magic(object):
...@@ -29,8 +30,12 @@ class Magic(object): ...@@ -29,8 +30,12 @@ class Magic(object):
self.libmagic = binwalk.core.C.Library("magic", self.LIBMAGIC_FUNCTIONS) self.libmagic = binwalk.core.C.Library("magic", self.LIBMAGIC_FUNCTIONS)
binwalk.core.common.debug("libmagic.magic_open(0x%X)" % (self.MAGIC_FLAGS | flags))
self.magic_cookie = self.libmagic.magic_open(self.MAGIC_FLAGS | flags) self.magic_cookie = self.libmagic.magic_open(self.MAGIC_FLAGS | flags)
binwalk.core.common.debug("libmagic.magic_load(0x%X, %s)" % (self.magic_cookie, self.magic_file))
self.libmagic.magic_load(self.magic_cookie, self.magic_file) self.libmagic.magic_load(self.magic_cookie, self.magic_file)
binwalk.core.common.debug("libmagic loaded OK!")
def close(self): def close(self):
if self.magic_cookie: if self.magic_cookie:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment