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
e929bb00
Commit
e929bb00
authored
Dec 13, 2013
by
devttys0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed --term and logging bugs.
parent
5475c714
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
76 additions
and
42 deletions
+76
-42
display.py
src/binwalk/display.py
+22
-15
module.py
src/binwalk/module.py
+42
-5
__init__.py
src/binwalk/modules/__init__.py
+3
-3
binvis.py
src/binwalk/modules/binvis.py
+1
-4
configuration.py
src/binwalk/modules/configuration.py
+2
-2
hashmatch.py
src/binwalk/modules/hashmatch.py
+2
-4
hexdiff.py
src/binwalk/modules/hexdiff.py
+1
-3
signature.py
src/binwalk/modules/signature.py
+3
-6
No files found.
src/binwalk/display.py
View file @
e929bb00
import
sys
import
csv
as
pycsv
import
binwalk.common
class
Display
(
object
):
BUFFER_WIDTH
=
0
HEADER_WIDTH
=
115
MAX_LINE_LEN
=
0
SCREEN_WIDTH
=
0
HEADER_WIDTH
=
150
DEFAULT_FORMAT
=
"
%
s
\n
"
def
__init__
(
self
,
quiet
=
False
,
verbose
=
0
,
log
=
None
,
csv
=
False
,
fit_to_screen
=
False
):
...
...
@@ -15,18 +13,22 @@ class Display(object):
self
.
fit_to_screen
=
fit_to_screen
self
.
fp
=
None
self
.
csv
=
None
self
.
num_columns
=
0
self
.
_configure_formatting
()
if
log
:
self
.
fp
=
binwalk
.
common
.
BlockFile
(
log
,
mode
=
"w"
)
if
self
.
csv
:
self
.
fp
=
open
(
log
,
"w"
)
if
csv
:
self
.
csv
=
pycsv
.
writer
(
self
.
fp
)
def
format_strings
(
self
,
header
,
result
):
self
.
result_format
=
result
self
.
header_format
=
header
if
self
.
num_columns
==
0
:
self
.
num_columns
=
len
(
header
.
split
())
def
log
(
self
,
fmt
,
columns
):
if
self
.
fp
:
if
self
.
csv
:
...
...
@@ -35,6 +37,8 @@ class Display(object):
self
.
fp
.
write
(
fmt
%
tuple
(
columns
))
def
header
(
self
,
*
args
):
self
.
num_columns
=
len
(
args
)
self
.
_fprint
(
"
%
s"
,
"
\n
"
,
csv
=
False
)
self
.
_fprint
(
self
.
header_format
,
args
)
self
.
_fprint
(
"
%
s"
,
[
"-"
*
self
.
HEADER_WIDTH
+
"
\n
"
],
csv
=
False
)
...
...
@@ -49,7 +53,7 @@ class Display(object):
line
=
fmt
%
tuple
(
columns
)
sys
.
stdout
.
write
(
self
.
_format_line
(
line
.
strip
())
+
"
\n
"
)
if
not
(
self
.
csv
and
not
csv
):
if
self
.
fp
and
not
(
self
.
csv
and
not
csv
):
self
.
log
(
fmt
,
columns
)
def
_append_to_data_parts
(
self
,
data
,
start
,
end
):
...
...
@@ -81,13 +85,18 @@ class Display(object):
offset
=
0
space_offset
=
0
self
.
string_parts
=
[]
delim
=
'
\n
'
+
' '
*
self
.
BUFFER_WIDTH
delim
=
'
\n
'
if
self
.
fit_to_screen
:
while
len
(
line
[
offset
:])
>
self
.
MAX_LINE_LEN
:
space_offset
=
line
[
offset
:
offset
+
self
.
MAX_LINE_LEN
]
.
rfind
(
' '
)
if
self
.
fit_to_screen
and
len
(
line
)
>
self
.
SCREEN_WIDTH
:
line_columns
=
line
.
split
(
None
,
self
.
num_columns
-
1
)
if
line_columns
:
delim
=
'
\n
'
+
' '
*
line
.
rfind
(
line_columns
[
-
1
])
while
len
(
line
[
offset
:])
>
self
.
SCREEN_WIDTH
:
space_offset
=
line
[
offset
:
offset
+
self
.
HEADER_WIDTH
]
.
rfind
(
' '
)
if
space_offset
==
-
1
or
space_offset
==
0
:
space_offset
=
self
.
MAX_LINE_LEN
space_offset
=
self
.
SCREEN_WIDTH
self
.
_append_to_data_parts
(
line
,
offset
,
offset
+
space_offset
)
...
...
@@ -113,9 +122,7 @@ class Display(object):
# Get the terminal window width
hw
=
struct
.
unpack
(
'hh'
,
fcntl
.
ioctl
(
1
,
termios
.
TIOCGWINSZ
,
'1234'
))
self
.
HEADER_WIDTH
=
hw
[
1
]
self
.
SCREEN_WIDTH
=
self
.
HEADER_WIDTH
=
hw
[
1
]
except
Exception
as
e
:
pass
self
.
MAX_LINE_LEN
=
self
.
HEADER_WIDTH
-
self
.
BUFFER_WIDTH
src/binwalk/module.py
View file @
e929bb00
import
io
import
os
import
sys
import
inspect
import
argparse
...
...
@@ -103,9 +104,12 @@ class Module(object):
'''
All module classes must be subclassed from this.
'''
# The module name, a
s displayed in help output
# The module name, a
utomatically populated.
NAME
=
""
# The module title, as displayed in help output
TITLE
=
""
# A list of binwalk.module.ModuleOption command line options
CLI
=
[]
...
...
@@ -113,7 +117,7 @@ class Module(object):
KWARGS
=
[]
# A dictionary of module dependencies; all modules depend on binwalk.modules.configuration.Configuration
DEPENDS
=
{}
DEPENDS
=
{
'config'
:
'Configuration'
}
# Format string for printing the header during a scan
HEADER_FORMAT
=
"
%
s
\n
"
...
...
@@ -136,6 +140,7 @@ class Module(object):
# self.plugins = x
self
.
errors
=
[]
self
.
results
=
[]
self
.
NAME
=
self
.
__class__
.
__name__
process_kwargs
(
self
,
kwargs
)
...
...
@@ -302,17 +307,41 @@ class Modules(object):
Main class used for running and managing modules.
'''
def
__init__
(
self
,
argv
=
sys
.
argv
[
1
:]
):
def
__init__
(
self
,
*
argv
,
**
kargv
):
'''
Class constructor.
@argv - List of command line options. Must not include the program name (sys.argv[0]).
@argv - List of command line options. Must not include the program name (e.g., sys.argv[1:]).
@kargv - Keyword dictionary of command line options.
Returns None.
'''
argv
=
list
(
argv
)
for
(
k
,
v
)
in
iterator
(
kargv
):
k
=
self
.
_parse_api_opt
(
k
)
if
v
not
in
[
True
,
False
,
None
]:
argv
.
append
(
"
%
s
%
s"
%
(
k
,
v
))
else
:
argv
.
append
(
k
)
if
not
argv
:
argv
=
sys
.
argv
[
1
:]
self
.
arguments
=
argv
self
.
loaded_modules
=
{}
def
_parse_api_opt
(
self
,
opt
):
# If the argument already starts with a hyphen, don't add hyphens in front of it
if
opt
.
startswith
(
'-'
):
return
opt
# Short options are only 1 character
elif
len
(
opt
)
==
1
:
return
'-'
+
opt
else
:
return
'--'
+
opt
def
list
(
self
,
attribute
=
"run"
):
'''
Finds all modules with the specified attribute.
...
...
@@ -334,7 +363,7 @@ class Modules(object):
for
obj
in
self
.
list
(
attribute
=
"CLI"
):
if
obj
.
CLI
:
help_string
+=
"
\n
%
s Options:
\n
"
%
obj
.
NAM
E
help_string
+=
"
\n
%
s Options:
\n
"
%
obj
.
TITL
E
for
module_option
in
obj
.
CLI
:
if
module_option
.
long
:
...
...
@@ -384,6 +413,14 @@ class Modules(object):
if
hasattr
(
module
,
"DEPENDS"
):
for
(
kwarg
,
dependency
)
in
iterator
(
module
.
DEPENDS
):
# The dependency module must be imported by binwalk.modules.__init__.py
if
hasattr
(
binwalk
.
modules
,
dependency
):
dependency
=
getattr
(
binwalk
.
modules
,
dependency
)
else
:
sys
.
stderr
.
write
(
"WARNING:
%
s depends on
%
s which was not found in binwalk.modules.__init__.py
\n
"
%
(
str
(
module
),
dependency
))
continue
# No recursive dependencies, thanks
if
dependency
==
module
:
continue
...
...
src/binwalk/modules/__init__.py
View file @
e929bb00
from
configuration
import
Configuration
from
hashmatch
import
HashMatch
from
signature
import
Signature
from
binvis
import
Plotter
from
hexdiff
import
HexDiff
from
signature
import
Signature
from
hashmatch
import
HashMatch
from
configuration
import
Configuration
src/binwalk/modules/binvis.py
View file @
e929bb00
...
...
@@ -2,7 +2,6 @@ import os
import
binwalk.module
from
binwalk.compat
import
*
from
binwalk.common
import
BlockFile
from
binwalk.modules.configuration
import
Configuration
class
Plotter
(
binwalk
.
module
.
Module
):
'''
...
...
@@ -13,9 +12,7 @@ class Plotter(binwalk.module.Module):
MAX_2D_PLOT_POINTS
=
12500
MAX_3D_PLOT_POINTS
=
25000
NAME
=
"Binary Visualization"
DEPENDS
=
{
'config'
:
Configuration
}
TITLE
=
"Binary Visualization"
CLI
=
[
binwalk
.
module
.
ModuleOption
(
short
=
'3'
,
...
...
src/binwalk/modules/configuration.py
View file @
e929bb00
...
...
@@ -8,8 +8,8 @@ from binwalk.compat import *
class
Configuration
(
binwalk
.
module
.
Module
):
RUN
=
False
NAME
=
"General"
TITLE
=
"General"
CLI
=
[
binwalk
.
module
.
ModuleOption
(
long
=
'length'
,
short
=
'l'
,
...
...
src/binwalk/modules/hashmatch.py
View file @
e929bb00
...
...
@@ -8,7 +8,6 @@ import binwalk.common
import
binwalk.module
import
binwalk.smartstrings
from
binwalk.compat
import
*
from
binwalk.modules.configuration
import
Configuration
class
HashResult
(
object
):
'''
...
...
@@ -28,15 +27,14 @@ class HashMatch(binwalk.module.Module):
DEFAULT_CUTOFF
=
0
CONSERVATIVE_CUTOFF
=
90
DEPENDS
=
{
'config'
:
Configuration
}
TITLE
=
"Fuzzy Hash"
NAME
=
"Fuzzy Hash"
CLI
=
[
binwalk
.
module
.
ModuleOption
(
short
=
'F'
,
long
=
'fuzzy'
,
kwargs
=
{
'enabled'
:
True
},
description
=
'Perform fuzzy hash matching on files/directories'
),
binwalk
.
module
.
ModuleOption
(
short
=
'
c
'
,
binwalk
.
module
.
ModuleOption
(
short
=
'
t
'
,
long
=
'cutoff'
,
nargs
=
1
,
priority
=
100
,
...
...
src/binwalk/modules/hexdiff.py
View file @
e929bb00
...
...
@@ -5,7 +5,6 @@ import platform
import
binwalk.module
import
binwalk.common
as
common
from
binwalk.compat
import
*
from
binwalk.modules.configuration
import
Configuration
# TODO: This code is an effing mess.
class
HexDiff
(
binwalk
.
module
.
Module
):
...
...
@@ -23,9 +22,8 @@ class HexDiff(binwalk.module.Module):
'blue'
:
'34'
,
}
DEPENDS
=
{
'config'
:
Configuration
}
TITLE
=
"Binary Diffing"
NAME
=
"Binary Diffing"
CLI
=
[
binwalk
.
module
.
ModuleOption
(
short
=
'W'
,
long
=
'hexdump'
,
...
...
src/binwalk/modules/signature.py
View file @
e929bb00
...
...
@@ -5,13 +5,10 @@ import binwalk.parser
import
binwalk.filter
import
binwalk.smartsignature
from
binwalk.compat
import
*
from
binwalk.modules.configuration
import
Configuration
class
Signature
(
binwalk
.
module
.
Module
):
DEPENDS
=
{
'config'
:
Configuration
}
NAME
=
"Signature Scan"
TITLE
=
"Signature Scan"
CLI
=
[
binwalk
.
module
.
ModuleOption
(
short
=
'B'
,
...
...
@@ -32,8 +29,8 @@ class Signature(binwalk.module.Module):
binwalk
.
module
.
ModuleKwarg
(
name
=
'magic_files'
,
default
=
[]),
]
HEADER
=
"BINWALK"
HEADER_FORMAT
=
"
%
s
\n
"
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
"
...
...
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