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-depend
binwalk
Commits
44e33c03
Commit
44e33c03
authored
Dec 20, 2013
by
devttys0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed bugs, renamed config.py to settings.py
parent
578eeff2
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
64 additions
and
56 deletions
+64
-56
common.py
src/binwalk/core/common.py
+3
-0
display.py
src/binwalk/core/display.py
+11
-1
module.py
src/binwalk/core/module.py
+16
-3
plugin.py
src/binwalk/core/plugin.py
+3
-3
settings.py
src/binwalk/core/settings.py
+2
-32
configuration.py
src/binwalk/modules/configuration.py
+8
-7
signature.py
src/binwalk/modules/signature.py
+21
-10
No files found.
src/binwalk/core/common.py
View file @
44e33c03
...
...
@@ -312,6 +312,9 @@ class BlockFile(BLOCK_FILE_PARENT_CLASS):
return
data
def
reset
(
self
):
self
.
seek
(
self
.
offset
)
def
write
(
self
,
data
):
'''
Writes data to the opened file.
...
...
src/binwalk/core/display.py
View file @
44e33c03
...
...
@@ -43,7 +43,17 @@ class Display(object):
self
.
_fprint
(
"
%
s"
,
[
"-"
*
self
.
HEADER_WIDTH
+
"
\n
"
],
csv
=
False
)
def
result
(
self
,
*
args
):
self
.
_fprint
(
self
.
result_format
,
args
)
# Convert to list for item assignment
args
=
list
(
args
)
# Replace multiple spaces with single spaces. This is to prevent accidentally putting
# four spaces in the description string, which would break auto-formatting.
for
i
in
range
(
len
(
args
)):
if
isinstance
(
args
[
i
],
str
):
while
" "
in
args
[
i
]:
args
[
i
]
=
args
[
i
]
.
replace
(
" "
,
" "
)
self
.
_fprint
(
self
.
result_format
,
tuple
(
args
))
def
footer
(
self
):
self
.
_fprint
(
"
%
s"
,
"
\n
"
,
csv
=
False
)
...
...
src/binwalk/core/module.py
View file @
44e33c03
...
...
@@ -5,7 +5,7 @@ import inspect
import
argparse
import
traceback
import
binwalk.core.common
import
binwalk.core.
config
import
binwalk.core.
settings
import
binwalk.core.plugin
from
binwalk.core.compat
import
*
...
...
@@ -144,6 +144,10 @@ class Module(object):
#RESULT = ['offset', 'description']
RESULT
=
[
"offset"
,
"offset"
,
"description"
]
# If set to True, the progress status will be automatically updated for each result
# containing a valid file attribute.
AUTO_UPDATE_STATUS
=
True
def
__init__
(
self
,
dependency
=
False
,
**
kwargs
):
self
.
errors
=
[]
self
.
results
=
[]
...
...
@@ -167,6 +171,15 @@ class Module(object):
self
.
plugins
.
load_plugins
()
def
__del__
(
self
):
return
None
def
__enter__
(
self
):
return
self
def
__exit__
(
self
,
x
,
z
,
y
):
return
None
def
load
(
self
):
'''
Invoked at module load time.
...
...
@@ -282,7 +295,7 @@ class Module(object):
self
.
results
.
append
(
r
)
# Update the progress status automatically if it is not being done manually by the module
if
r
.
file
and
not
self
.
status
.
total
:
if
r
.
file
and
self
.
AUTO_UPDATE_STATUS
:
self
.
status
.
total
=
r
.
file
.
length
self
.
status
.
completed
=
r
.
file
.
tell
()
-
r
.
file
.
offset
...
...
@@ -446,7 +459,7 @@ class Modules(object):
return
modules
def
help
(
self
):
help_string
=
"
\n
Binwalk v
%
s
\n
Craig Heffner, http://www.binwalk.
core.org
\n
"
%
binwalk
.
core
.
config
.
Config
.
VERSION
help_string
=
"
\n
Binwalk v
%
s
\n
Craig Heffner, http://www.binwalk.
org
\n
"
%
binwalk
.
core
.
settings
.
Settings
.
VERSION
for
obj
in
self
.
list
(
attribute
=
"CLI"
):
if
obj
.
CLI
:
...
...
src/binwalk/core/plugin.py
View file @
44e33c03
import
os
import
sys
import
imp
import
binwalk.core.
config
import
binwalk.core.
settings
from
binwalk.core.compat
import
*
class
Plugins
:
...
...
@@ -54,7 +54,7 @@ class Plugins:
self
.
pre_scan
=
[]
self
.
post_scan
=
[]
self
.
parent
=
parent
self
.
config
=
binwalk
.
core
.
config
.
Config
()
self
.
settings
=
binwalk
.
core
.
settings
.
Settings
()
def
__del__
(
self
):
pass
...
...
@@ -112,7 +112,7 @@ class Plugins:
}
for
key
in
plugins
.
keys
():
plugins
[
key
][
'path'
]
=
self
.
config
.
paths
[
key
][
self
.
config
.
PLUGINS
]
plugins
[
key
][
'path'
]
=
self
.
settings
.
paths
[
key
][
self
.
settings
.
PLUGINS
]
for
file_name
in
os
.
listdir
(
plugins
[
key
][
'path'
]):
if
file_name
.
endswith
(
self
.
MODULE_EXTENSION
):
...
...
src/binwalk/core/
config
.py
→
src/binwalk/core/
settings
.py
View file @
44e33c03
...
...
@@ -2,36 +2,16 @@ import os
import
binwalk.core.common
as
common
from
binwalk.core.compat
import
*
class
Config
:
class
Settings
:
'''
Binwalk
configuration class, used for accessing user and system file path
s.
Binwalk
settings class, used for accessing user and system file paths and general configuration setting
s.
After instatiating the class, file paths can be accessed via the self.paths dictionary.
System file paths are listed under the 'system' key, user file paths under the 'user' key.
For example, to get the path to both the user and system binwalk magic files:
from binwalk import Config
conf = Config()
user_binwalk_file = conf.paths['user'][conf.BINWALK_MAGIC_FILE]
system_binwalk_file = conf.paths['system'][conf.BINWALK_MAGIC_FILE]
There is also an instance of this class available via the Binwalk.config object:
import binwalk
bw = binwalk.Binwalk()
user_binwalk_file = bw.config.paths['user'][conf.BINWALK_MAGIC_FILE]
system_binwalk_file = bw.config.paths['system'][conf.BINWALK_MAGIC_FILE]
Valid file names under both the 'user' and 'system' keys are as follows:
o BINWALK_MAGIC_FILE - Path to the default binwalk magic file.
o BINCAST_MAGIC_FILE - Path to the bincast magic file (used when -C is specified with the command line binwalk script).
o BINARCH_MAGIC_FILE - Path to the binarch magic file (used when -A is specified with the command line binwalk script).
o EXTRACT_FILE - Path to the extract configuration file (used when -e is specified with the command line binwalk script).
o PLUGINS - Path to the plugins directory.
'''
# Release version
...
...
@@ -47,10 +27,6 @@ class Config:
PLUGINS
=
"plugins"
EXTRACT_FILE
=
"extract.conf"
BINWALK_MAGIC_FILE
=
"binwalk"
BINCAST_MAGIC_FILE
=
"bincast"
BINARCH_MAGIC_FILE
=
"binarch"
ZLIB_MAGIC_FILE
=
"zlib"
COMPRESSD_MAGIC_FILE
=
"compressd"
def
__init__
(
self
):
'''
...
...
@@ -69,17 +45,11 @@ class Config:
# 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
.
BINCAST_MAGIC_FILE
]
=
self
.
_user_path
(
self
.
BINWALK_MAGIC_DIR
,
self
.
BINCAST_MAGIC_FILE
)
self
.
paths
[
'user'
][
self
.
BINARCH_MAGIC_FILE
]
=
self
.
_user_path
(
self
.
BINWALK_MAGIC_DIR
,
self
.
BINARCH_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
.
BINCAST_MAGIC_FILE
]
=
self
.
_system_path
(
self
.
BINWALK_MAGIC_DIR
,
self
.
BINCAST_MAGIC_FILE
)
self
.
paths
[
'system'
][
self
.
BINARCH_MAGIC_FILE
]
=
self
.
_system_path
(
self
.
BINWALK_MAGIC_DIR
,
self
.
BINARCH_MAGIC_FILE
)
self
.
paths
[
'system'
][
self
.
ZLIB_MAGIC_FILE
]
=
self
.
_system_path
(
self
.
BINWALK_MAGIC_DIR
,
self
.
ZLIB_MAGIC_FILE
)
self
.
paths
[
'system'
][
self
.
COMPRESSD_MAGIC_FILE
]
=
self
.
_system_path
(
self
.
BINWALK_MAGIC_DIR
,
self
.
COMPRESSD_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/configuration.py
View file @
44e33c03
...
...
@@ -2,9 +2,8 @@ import os
import
sys
import
argparse
import
binwalk.core.common
import
binwalk.core.config
import
binwalk.core.display
from
binwalk.core.config
import
*
import
binwalk.core.settings
from
binwalk.core.compat
import
*
from
binwalk.core.module
import
Module
,
Option
,
Kwarg
,
show_help
...
...
@@ -82,11 +81,12 @@ class Configuration(Module):
def
load
(
self
):
self
.
target_files
=
[]
# Order is important with these two methods
self
.
_open_target_files
()
self
.
_set_verbosity
()
self
.
settings
=
binwalk
.
core
.
config
.
Config
()
self
.
settings
=
binwalk
.
core
.
settings
.
Settings
()
self
.
display
=
binwalk
.
core
.
display
.
Display
(
log
=
self
.
log_file
,
csv
=
self
.
csv
,
quiet
=
self
.
quiet
,
...
...
@@ -97,15 +97,16 @@ class Configuration(Module):
show_help
()
sys
.
exit
(
0
)
def
reset
(
self
):
for
fp
in
self
.
target_files
:
fp
.
reset
()
def
__del__
(
self
):
self
.
_cleanup
()
def
__exit__
(
self
,
a
,
b
,
c
):
self
.
_cleanup
()
def
__enter__
(
self
):
return
self
def
_cleanup
(
self
):
if
hasattr
(
self
,
'target_files'
):
for
fp
in
self
.
target_files
:
...
...
src/binwalk/modules/signature.py
View file @
44e33c03
...
...
@@ -58,11 +58,6 @@ class Signature(Module):
Kwarg
(
name
=
'include_filters'
,
default
=
[]),
]
HEADER
=
[
"DECIMAL"
,
"HEX"
,
"DESCRIPTION"
]
HEADER_FORMAT
=
"
%-12
s
%-12
s
%
s
\n
"
RESULT
=
[
"offset"
,
"offset"
,
"description"
]
RESULT_FORMAT
=
"
%-12
d 0x
%-12
X
%
s
\n
"
MAGIC_FLAGS
=
magic
.
MAGIC_NO_CHECK_TEXT
|
magic
.
MAGIC_NO_CHECK_ENCODING
|
magic
.
MAGIC_NO_CHECK_APPTYPE
|
magic
.
MAGIC_NO_CHECK_TOKENS
def
init
(
self
):
...
...
@@ -124,6 +119,11 @@ class Signature(Module):
self
.
status
.
completed
=
block_start
-
fp
.
offset
for
candidate_offset
in
self
.
parser
.
find_signature_candidates
(
data
,
dlen
):
# current_block_offset is set when a jump-to-offset keyword is encountered while
# processing signatures. This points to an offset inside the current data block
# that scanning should jump to, so ignore any subsequent candidate signatures that
# occurr before this offset inside the current data block.
if
candidate_offset
<
current_block_offset
:
continue
...
...
@@ -134,16 +134,27 @@ class Signature(Module):
magic_result
=
self
.
magic
.
buffer
(
candidate_data
)
if
self
.
filter
.
valid_magic_result
(
magic_result
):
# The smart filter parser returns a
dictionary of keyword values and the signature description.
# The smart filter parser returns a
binwalk.core.module.Result object
r
=
self
.
smart
.
parse
(
magic_result
)
# Set the absolute offset inside the target file
r
.
offset
=
block_start
+
candidate_offset
+
r
.
adjust
# Provide an instance of the current file object
r
.
file
=
fp
# Register the result for futher processing/display
self
.
result
(
r
=
r
)
# Is this a valid result and did it specify a jump-to-offset keyword?
if
r
.
valid
and
r
.
jump
>
0
:
fp
.
seek
(
r
.
offset
+
r
.
jump
)
current_block_offset
=
r
.
jump
absolute_jump_offset
=
r
.
offset
+
r
.
jump
current_block_offset
=
candidate_offset
+
r
.
jump
# If the jump-to-offset is beyond the confines of the current block, seek the file to
# that offset and quit processing this block of data.
if
absolute_jump_offset
>=
fp
.
tell
():
fp
.
seek
(
r
.
offset
+
r
.
jump
)
break
def
run
(
self
):
target_files
=
self
.
config
.
target_files
...
...
@@ -153,7 +164,7 @@ class Signature(Module):
self
.
header
()
self
.
status
.
clear
()
self
.
status
.
total
=
fp
.
size
self
.
status
.
total
=
fp
.
length
self
.
status
.
completed
=
0
self
.
scan_file
(
fp
)
...
...
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