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
84e83d0f
Commit
84e83d0f
authored
Jan 12, 2014
by
devttys0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added --cast option
parent
5c4291ec
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
4 deletions
+25
-4
magic.py
src/binwalk/core/magic.py
+5
-2
settings.py
src/binwalk/core/settings.py
+3
-0
signature.py
src/binwalk/modules/signature.py
+17
-2
No files found.
src/binwalk/core/magic.py
View file @
84e83d0f
...
...
@@ -12,6 +12,7 @@ class Magic(object):
binwalk
.
core
.
C
.
Function
(
name
=
"magic_buffer"
,
type
=
str
),
]
MAGIC_CONTINUE
=
0x000020
MAGIC_NO_CHECK_TEXT
=
0x020000
MAGIC_NO_CHECK_APPTYPE
=
0x008000
MAGIC_NO_CHECK_TOKENS
=
0x100000
...
...
@@ -19,13 +20,15 @@ class Magic(object):
MAGIC_FLAGS
=
MAGIC_NO_CHECK_TEXT
|
MAGIC_NO_CHECK_ENCODING
|
MAGIC_NO_CHECK_APPTYPE
|
MAGIC_NO_CHECK_TOKENS
def
__init__
(
self
,
magic_file
=
None
):
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
(
"magic"
,
self
.
LIBMAGIC_FUNCTIONS
)
self
.
magic_cookie
=
self
.
libmagic
.
magic_open
(
self
.
MAGIC_FLAGS
)
self
.
magic_cookie
=
self
.
libmagic
.
magic_open
(
self
.
MAGIC_FLAGS
|
flags
)
self
.
libmagic
.
magic_load
(
self
.
magic_cookie
,
self
.
magic_file
)
def
buffer
(
self
,
data
):
...
...
src/binwalk/core/settings.py
View file @
84e83d0f
...
...
@@ -28,6 +28,7 @@ class Settings:
EXTRACT_FILE
=
"extract.conf"
BINWALK_MAGIC_FILE
=
"binwalk"
BINARCH_MAGIC_FILE
=
"binarch"
BINCAST_MAGIC_FILE
=
"bincast"
def
__init__
(
self
):
'''
...
...
@@ -47,12 +48,14 @@ class Settings:
# Build the paths to all user-specific files
self
.
paths
[
'user'
][
self
.
BINWALK_MAGIC_FILE
]
=
self
.
_user_path
(
self
.
BINWALK_MAGIC_DIR
,
self
.
BINWALK_MAGIC_FILE
)
self
.
paths
[
'user'
][
self
.
BINARCH_MAGIC_FILE
]
=
self
.
_user_path
(
self
.
BINWALK_MAGIC_DIR
,
self
.
BINARCH_MAGIC_FILE
)
self
.
paths
[
'user'
][
self
.
BINCAST_MAGIC_FILE
]
=
self
.
_user_path
(
self
.
BINWALK_MAGIC_DIR
,
self
.
BINCAST_MAGIC_FILE
)
self
.
paths
[
'user'
][
self
.
EXTRACT_FILE
]
=
self
.
_user_path
(
self
.
BINWALK_CONFIG_DIR
,
self
.
EXTRACT_FILE
)
self
.
paths
[
'user'
][
self
.
PLUGINS
]
=
self
.
_user_path
(
self
.
BINWALK_PLUGINS_DIR
)
# Build the paths to all system-wide files
self
.
paths
[
'system'
][
self
.
BINWALK_MAGIC_FILE
]
=
self
.
_system_path
(
self
.
BINWALK_MAGIC_DIR
,
self
.
BINWALK_MAGIC_FILE
)
self
.
paths
[
'system'
][
self
.
BINARCH_MAGIC_FILE
]
=
self
.
_system_path
(
self
.
BINWALK_MAGIC_DIR
,
self
.
BINARCH_MAGIC_FILE
)
self
.
paths
[
'system'
][
self
.
BINCAST_MAGIC_FILE
]
=
self
.
_system_path
(
self
.
BINWALK_MAGIC_DIR
,
self
.
BINCAST_MAGIC_FILE
)
self
.
paths
[
'system'
][
self
.
EXTRACT_FILE
]
=
self
.
_system_path
(
self
.
BINWALK_CONFIG_DIR
,
self
.
EXTRACT_FILE
)
self
.
paths
[
'system'
][
self
.
PLUGINS
]
=
self
.
_system_path
(
self
.
BINWALK_PLUGINS_DIR
)
...
...
src/binwalk/modules/signature.py
View file @
84e83d0f
...
...
@@ -22,6 +22,10 @@ class Signature(Module):
long
=
'opcodes'
,
kwargs
=
{
'enabled'
:
True
,
'search_for_opcodes'
:
True
},
description
=
'Scan target file(s) for common executable opcodes'
),
Option
(
short
=
'C'
,
long
=
'cast'
,
kwargs
=
{
'enabled'
:
True
,
'cast_data_types'
:
True
},
description
=
'Cast offsets as various data types'
),
Option
(
short
=
'm'
,
long
=
'magic'
,
kwargs
=
{
'magic_files'
:
[]},
...
...
@@ -38,6 +42,7 @@ class Signature(Module):
Kwarg
(
name
=
'enabled'
,
default
=
False
),
Kwarg
(
name
=
'raw_bytes'
,
default
=
None
),
Kwarg
(
name
=
'search_for_opcodes'
,
default
=
False
),
Kwarg
(
name
=
'cast_data_types'
,
default
=
False
),
Kwarg
(
name
=
'dumb_scan'
,
default
=
False
),
Kwarg
(
name
=
'magic_files'
,
default
=
[]),
]
...
...
@@ -45,6 +50,8 @@ class Signature(Module):
VERBOSE_FORMAT
=
"
%
s
%
d"
def
init
(
self
):
flags
=
0
# Create Signature and MagicParser class instances. These are mostly for internal use.
self
.
smart
=
binwalk
.
core
.
smart
.
Signature
(
self
.
config
.
filter
,
ignore_smart_signatures
=
self
.
dumb_scan
)
self
.
parser
=
binwalk
.
core
.
parser
.
MagicParser
(
self
.
config
.
filter
,
self
.
smart
)
...
...
@@ -54,14 +61,21 @@ class Signature(Module):
self
.
magic_files
=
[
self
.
parser
.
file_from_string
(
self
.
raw_bytes
)]
# Use the system default magic file if no other was specified
# Append the user's magic file first so that those signatures take precedence
if
not
self
.
magic_files
:
if
self
.
search_for_opcodes
:
flags
|=
binwalk
.
core
.
magic
.
Magic
.
MAGIC_CONTINUE
self
.
magic_files
=
[
self
.
config
.
settings
.
paths
[
'user'
][
self
.
config
.
settings
.
BINARCH_MAGIC_FILE
],
self
.
config
.
settings
.
paths
[
'system'
][
self
.
config
.
settings
.
BINARCH_MAGIC_FILE
],
]
elif
self
.
cast_data_types
:
self
.
magic_files
=
[
self
.
config
.
settings
.
paths
[
'user'
][
self
.
config
.
settings
.
BINCAST_MAGIC_FILE
],
self
.
config
.
settings
.
paths
[
'system'
][
self
.
config
.
settings
.
BINCAST_MAGIC_FILE
],
]
else
:
# Append the user's magic file first so that those signatures take precedence
self
.
magic_files
=
[
self
.
config
.
settings
.
paths
[
'user'
][
self
.
config
.
settings
.
BINWALK_MAGIC_FILE
],
self
.
config
.
settings
.
paths
[
'system'
][
self
.
config
.
settings
.
BINWALK_MAGIC_FILE
],
...
...
@@ -69,7 +83,7 @@ class Signature(Module):
# Parse the magic file(s) and initialize libmagic
self
.
mfile
=
self
.
parser
.
parse
(
self
.
magic_files
)
self
.
magic
=
binwalk
.
core
.
magic
.
Magic
(
self
.
mfile
)
self
.
magic
=
binwalk
.
core
.
magic
.
Magic
(
self
.
mfile
,
flags
)
# Once the temporary magic files are loaded into libmagic, we don't need them anymore; delete the temp files
self
.
parser
.
rm_magic_files
()
...
...
@@ -145,3 +159,4 @@ class Signature(Module):
self
.
header
()
self
.
scan_file
(
fp
)
self
.
footer
()
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