Commit cc7e4a64 by devttys0

Made magic_t data type for libmagic wrapper

parent b2ac05ba
...@@ -56,7 +56,9 @@ class FunctionHandler(object): ...@@ -56,7 +56,9 @@ class FunctionHandler(object):
self.function.restype = self.PY2CTYPES[self.retype] self.function.restype = self.PY2CTYPES[self.retype]
self.retval_converter = self.RETVAL_CONVERTERS[self.retype] self.retval_converter = self.RETVAL_CONVERTERS[self.retype]
else: else:
raise Exception("Unknown return type: '%s'" % self.retype) self.function.restype = self.retype
self.retval_converter = None
#raise Exception("Unknown return type: '%s'" % self.retype)
def run(self, *args): def run(self, *args):
''' '''
...@@ -74,7 +76,11 @@ class FunctionHandler(object): ...@@ -74,7 +76,11 @@ class FunctionHandler(object):
if isinstance(args[i], str): if isinstance(args[i], str):
args[i] = str2bytes(args[i]) args[i] = str2bytes(args[i])
return self.retval_converter(self.function(*args)) retval = self.function(*args)
if self.retval_converter is not None:
retval = self.retval_converter(retval)
return retval
class Library(object): class Library(object):
''' '''
......
...@@ -5,6 +5,12 @@ ...@@ -5,6 +5,12 @@
import binwalk.core.C import binwalk.core.C
import binwalk.core.common import binwalk.core.common
from binwalk.core.compat import * from binwalk.core.compat import *
from ctypes import *
class magic_set(Structure):
pass
magic_set._fields_ = []
magic_t = POINTER(magic_set)
class Magic(object): class Magic(object):
''' '''
...@@ -12,8 +18,8 @@ class Magic(object): ...@@ -12,8 +18,8 @@ class Magic(object):
''' '''
LIBMAGIC_FUNCTIONS = [ LIBMAGIC_FUNCTIONS = [
binwalk.core.C.Function(name="magic_open", type=int), binwalk.core.C.Function(name="magic_open", type=magic_t),
binwalk.core.C.Function(name="magic_close", type=None), binwalk.core.C.Function(name="magic_close", type=int),
binwalk.core.C.Function(name="magic_load", type=int), binwalk.core.C.Function(name="magic_load", type=int),
binwalk.core.C.Function(name="magic_buffer", type=str), binwalk.core.C.Function(name="magic_buffer", type=str),
] ]
...@@ -37,7 +43,7 @@ class Magic(object): ...@@ -37,7 +43,7 @@ class Magic(object):
binwalk.core.common.debug("libmagic.magic_open(0x%X)" % (self.MAGIC_FLAGS | flags)) 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)) binwalk.core.common.debug("libmagic.magic_load(%s, %s)" % (type(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!") binwalk.core.common.debug("libmagic loaded OK!")
......
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