Commit 14eda44c by devttys0

Added binwalk.common.core.debug function

parent 9a5a7237
......@@ -22,8 +22,8 @@ class FunctionHandler(object):
'''
PY2CTYPES = {
bytes : ctypes.c_char_p,
str : ctypes.c_char_p,
int : ctypes.c_int,
str : ctypes.c_char_p,
int : ctypes.c_int,
float : ctypes.c_float,
bool : ctypes.c_int,
None : ctypes.c_int,
......@@ -47,8 +47,9 @@ class FunctionHandler(object):
Returns None.
'''
self.name = function.name
self.retype = function.type
self.function = getattr(library, function.name)
self.function = getattr(library, self.name)
if has_key(self.PY2CTYPES, self.retype):
self.function.restype = self.PY2CTYPES[self.retype]
......
......@@ -3,6 +3,7 @@
import io
import os
import re
import sys
import ast
import hashlib
import operator as op
......@@ -14,6 +15,16 @@ if has_key(__builtins__, 'BLOCK_FILE_PARENT_CLASS'):
else:
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):
'''
Generate an MD5 hash of the specified file.
......
import binwalk.core.C
import binwalk.core.common
from binwalk.core.compat import *
class Magic(object):
......@@ -26,11 +27,15 @@ class Magic(object):
self.magic_file = str2bytes(magic_file)
else:
self.magic_file = None
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)
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)
binwalk.core.common.debug("libmagic loaded OK!")
def close(self):
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