Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
binwalk
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fact-gitdep
binwalk
Commits
1646ef51
Commit
1646ef51
authored
Jul 12, 2014
by
devttys0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fall back to system libmagic/libfuzzy libraries if custom ones are not found.
parent
57bdf346
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
25 additions
and
11 deletions
+25
-11
Makefile
src/C/Makefile
+2
-2
C.py
src/binwalk/core/C.py
+16
-5
magic.py
src/binwalk/core/magic.py
+4
-1
hashmatch.py
src/binwalk/modules/hashmatch.py
+3
-3
No files found.
src/C/Makefile
View file @
1646ef51
...
...
@@ -36,9 +36,9 @@ uninstall:
file_make_prep
:
if
[
"
$(BUILD_MAGIC)
"
-eq
"1"
]
;
then
sed
-e
s/libmagic/libinmagic/g < ./file-
$(FILE_VERSION)
/src/Makefile
>
./file-
$(FILE_VERSION)
/src/mktmp
;
fi
if
[
"
$(BUILD_MAGIC)
"
-eq
"1"
]
;
then
mv ./file-
$(FILE_VERSION)
/src/mktmp ./file-
$(FILE_VERSION)
/src/Makefile
;
fi
if
[
"
$(BUILD_MAGIC)
"
-eq
"1"
]
;
then
mv
-f
./file-
$(FILE_VERSION)
/src/mktmp ./file-
$(FILE_VERSION)
/src/Makefile
;
fi
ssdeep_make_prep
:
if
[
"
$(BUILD_FUZZY)
"
-eq
"1"
]
;
then
sed
-e
s/libfuzzy/libinfuzzy/g < ./ssdeep-
$(SSDEEP_VERSION)
/Makefile
>
./ssdeep-
$(SSDEEP_VERSION)
/mktmp
;
fi
if
[
"
$(BUILD_FUZZY)
"
-eq
"1"
]
;
then
mv ./ssdeep-
$(SSDEEP_VERSION)
/mktmp ./ssdeep-
$(SSDEEP_VERSION)
/Makefile
;
fi
if
[
"
$(BUILD_FUZZY)
"
-eq
"1"
]
;
then
mv
-f
./ssdeep-
$(SSDEEP_VERSION)
/mktmp ./ssdeep-
$(SSDEEP_VERSION)
/Makefile
;
fi
src/binwalk/core/C.py
View file @
1646ef51
...
...
@@ -91,7 +91,7 @@ class Library(object):
'''
Class constructor.
@library - Library name (e.g., 'magic' for libmagic).
@library - Library name (e.g., 'magic' for libmagic)
, or a list of names
.
@functions - A dictionary of function names and their return types (e.g., {'magic_buffer' : str})
Returns None.
...
...
@@ -104,15 +104,20 @@ class Library(object):
f
=
FunctionHandler
(
self
.
library
,
function
)
setattr
(
self
,
function
.
name
,
f
.
run
)
def
find_library
(
self
,
librar
y
):
def
find_library
(
self
,
librar
ies
):
'''
Locates the specified library.
@librar
y - Library name (e.g., 'magic' for libmagic)
.
@librar
ies - Library name (e.g., 'magic' for libmagic), or a list of names
.
Returns a string to be passed to ctypes.cdll.LoadLibrary.
'''
lib_path
=
None
if
isinstance
(
libraries
,
str
):
libraries
=
[
libraries
]
for
library
in
libraries
:
system_paths
=
{
'linux'
:
[
'/usr/local/lib/lib
%
s.so'
%
library
],
'linux2'
:
[
'/usr/local/lib/lib
%
s.so'
%
library
],
...
...
@@ -137,10 +142,16 @@ class Library(object):
if
not
lib_path
:
lib_path
=
ctypes
.
util
.
find_library
(
library
)
# Use the first library that we can find
if
lib_path
:
binwalk
.
core
.
common
.
debug
(
"Found library '
%
s' at:
%
s"
%
(
library
,
lib_path
))
break
else
:
binwalk
.
core
.
common
.
debug
(
"Could not find library '
%
s'"
%
library
)
# If we still couldn't find the library, error out
if
not
lib_path
:
raise
Exception
(
"Failed to locate librar
y '
%
s'"
%
library
)
raise
Exception
(
"Failed to locate librar
ies '
%
s'"
%
str
(
libraries
)
)
binwalk
.
core
.
common
.
debug
(
"Found library: "
+
lib_path
)
return
lib_path
src/binwalk/core/magic.py
View file @
1646ef51
...
...
@@ -32,13 +32,16 @@ class Magic(object):
MAGIC_FLAGS
=
MAGIC_NO_CHECK_TEXT
|
MAGIC_NO_CHECK_ENCODING
|
MAGIC_NO_CHECK_APPTYPE
|
MAGIC_NO_CHECK_TOKENS
# Look for libinmagic first, fall back on libmagic
LIBRARIES
=
[
"inmagic"
,
"magic"
]
def
__init__
(
self
,
magic_file
=
None
,
flags
=
0
):
if
magic_file
:
self
.
magic_file
=
str2bytes
(
magic_file
)
else
:
self
.
magic_file
=
None
self
.
libmagic
=
binwalk
.
core
.
C
.
Library
(
"inmagic"
,
self
.
LIBMAGIC_FUNCTIONS
)
self
.
libmagic
=
binwalk
.
core
.
C
.
Library
(
self
.
LIBRARIES
,
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
)
...
...
src/binwalk/modules/hashmatch.py
View file @
1646ef51
...
...
@@ -78,8 +78,8 @@ class HashMatch(Module):
Kwarg
(
name
=
'enabled'
,
default
=
False
),
]
#
Requires libfuzzybinwalk.so
LIBRARY_NAME
=
"infuzzy"
#
Look for libinfuzzy first, fall back on libfuzzy
LIBRARY_NAME
S
=
[
"infuzzy"
,
"fuzzy"
]
LIBRARY_FUNCTIONS
=
[
binwalk
.
core
.
C
.
Function
(
name
=
"fuzzy_hash_buf"
,
type
=
int
),
binwalk
.
core
.
C
.
Function
(
name
=
"fuzzy_hash_filename"
,
type
=
int
),
...
...
@@ -101,7 +101,7 @@ class HashMatch(Module):
self
.
last_file1
=
HashResult
(
None
)
self
.
last_file2
=
HashResult
(
None
)
self
.
lib
=
binwalk
.
core
.
C
.
Library
(
self
.
LIBRARY_NAME
,
self
.
LIBRARY_FUNCTIONS
)
self
.
lib
=
binwalk
.
core
.
C
.
Library
(
self
.
LIBRARY_NAME
S
,
self
.
LIBRARY_FUNCTIONS
)
def
_get_strings
(
self
,
fname
):
return
''
.
join
(
list
(
binwalk
.
core
.
common
.
strings
(
fname
,
minimum
=
10
)))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment