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
0d9524ba
Commit
0d9524ba
authored
Nov 07, 2014
by
devttys0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code cleanup, minor bug fixes
parent
43ddf9b9
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
30 deletions
+22
-30
magic.py
src/binwalk/core/magic.py
+3
-3
settings.py
src/binwalk/core/settings.py
+10
-7
images
src/binwalk/magic/images
+4
-0
signature.py
src/binwalk/modules/signature.py
+5
-20
No files found.
src/binwalk/core/magic.py
View file @
0d9524ba
...
...
@@ -352,9 +352,9 @@ class Magic(object):
tags
[
'description'
]
=
self
.
bspace
.
sub
(
''
,
" "
.
join
(
description
))
if
not
tags
[
'description'
]:
tags
[
'display'
]
=
False
tags
[
'invalid'
]
=
True
#
if not tags['description']:
#
tags['display'] = False
#
tags['invalid'] = True
if
self
.
printable
.
match
(
tags
[
'description'
])
.
group
()
!=
tags
[
'description'
]:
tags
[
'invalid'
]
=
True
...
...
src/binwalk/core/settings.py
View file @
0d9524ba
...
...
@@ -27,7 +27,6 @@ class Settings:
# File names
PLUGINS
=
"plugins"
PREFIX_FILE
=
"prefix.conf"
EXTRACT_FILE
=
"extract.conf"
BINWALK_MAGIC_FILE
=
"binwalk"
BINARCH_MAGIC_FILE
=
"binarch"
...
...
@@ -45,7 +44,7 @@ class Settings:
# Build the paths to all user-specific files
self
.
user
=
common
.
GenericContainer
(
binwalk
=
self
.
_user_path
(
self
.
BINWALK_MAGIC_DIR
,
self
.
BINWALK_MAGIC_FILE
),
binarch
=
self
.
_user_path
(
self
.
BINWALK_MAGIC_DIR
,
self
.
BINARCH_MAGIC_FILE
),
bincast
=
self
.
_user_path
(
self
.
BINWALK_MAGIC_DIR
,
self
.
BINCAST_MAGIC_FILE
),
magic
=
self
.
_magic_signature_files
(
user_only
=
True
),
extract
=
self
.
_user_path
(
self
.
BINWALK_CONFIG_DIR
,
self
.
EXTRACT_FILE
),
plugins
=
self
.
_user_path
(
self
.
BINWALK_PLUGINS_DIR
))
...
...
@@ -53,13 +52,14 @@ class Settings:
# Build the paths to all system-wide files
self
.
system
=
common
.
GenericContainer
(
binwalk
=
self
.
_system_path
(
self
.
BINWALK_MAGIC_DIR
,
self
.
BINWALK_MAGIC_FILE
),
binarch
=
self
.
_system_path
(
self
.
BINWALK_MAGIC_DIR
,
self
.
BINARCH_MAGIC_FILE
),
bincast
=
self
.
_system_path
(
self
.
BINWALK_MAGIC_DIR
,
self
.
BINCAST_MAGIC_FILE
),
magic
=
self
.
_magic_signature_files
(
system_only
=
True
),
extract
=
self
.
_system_path
(
self
.
BINWALK_CONFIG_DIR
,
self
.
EXTRACT_FILE
),
prefix
=
self
.
_system_path
(
self
.
BINWALK_CONFIG_DIR
,
self
.
PREFIX_FILE
),
plugins
=
self
.
_system_path
(
self
.
BINWALK_PLUGINS_DIR
))
def
magic_signature_files
(
self
,
system_only
=
False
,
user_only
=
False
):
def
_
magic_signature_files
(
self
,
system_only
=
False
,
user_only
=
False
):
files
=
[]
user_binarch
=
self
.
_user_path
(
self
.
BINWALK_MAGIC_DIR
,
self
.
BINARCH_MAGIC_FILE
)
system_binarch
=
self
.
_system_path
(
self
.
BINWALK_MAGIC_DIR
,
self
.
BINARCH_MAGIC_FILE
)
if
not
system_only
:
user_dir
=
os
.
path
.
join
(
self
.
user_dir
,
self
.
BINWALK_USER_DIR
,
self
.
BINWALK_MAGIC_DIR
)
...
...
@@ -67,8 +67,11 @@ class Settings:
if
not
user_only
:
system_dir
=
os
.
path
.
join
(
self
.
system_dir
,
self
.
BINWALK_MAGIC_DIR
)
files
+=
[
os
.
path
.
join
(
system_dir
,
x
)
for
x
in
os
.
listdir
(
system_dir
)]
if
self
.
system
.
binarch
in
files
:
files
.
remove
(
self
.
system
.
binarch
)
if
user_binarch
in
files
:
files
.
remove
(
user_binarch
)
if
system_binarch
in
files
:
files
.
remove
(
system_binarch
)
return
files
...
...
src/binwalk/magic/images
View file @
0d9524ba
...
...
@@ -56,6 +56,10 @@
# PC bitmaps (OS/2, Windows BMP files) (Greg Roelofs, newt@uchicago.edu)
0 string BM PC bitmap,
>14 leshort !12
>>14 leshort !64
>>>14 leshort !40
>>>>14 leshort !128 {invalid}
>14 leshort 12 OS/2 1.x format,
>>18 lelong <1 {invalid}
>>18 lelong >1000000 {invalid}
...
...
src/binwalk/modules/signature.py
View file @
0d9524ba
...
...
@@ -25,10 +25,6 @@ class Signature(Module):
long
=
'opcodes'
,
kwargs
=
{
'enabled'
:
True
,
'search_for_opcodes'
:
True
},
description
=
'Scan target file(s) for common executable opcode signatures'
),
#Option(short='C',
# long='cast',
# kwargs={'enabled' : True, 'cast_data_types' : True},
# description='Cast offsets as a given data type (use -y to specify the data type / endianness)'),
Option
(
short
=
'm'
,
long
=
'magic'
,
kwargs
=
{
'enabled'
:
True
,
'magic_files'
:
[]},
...
...
@@ -65,7 +61,6 @@ class Signature(Module):
Kwarg
(
name
=
'raw_bytes'
,
default
=
None
),
Kwarg
(
name
=
'search_for_opcodes'
,
default
=
False
),
Kwarg
(
name
=
'explicit_signature_scan'
,
default
=
False
),
Kwarg
(
name
=
'cast_data_types'
,
default
=
False
),
Kwarg
(
name
=
'dumb_scan'
,
default
=
False
),
Kwarg
(
name
=
'magic_files'
,
default
=
[]),
]
...
...
@@ -85,16 +80,9 @@ class Signature(Module):
self
.
config
.
settings
.
system
.
binarch
,
]
elif
self
.
cast_data_types
:
self
.
keep_going
=
True
self
.
magic_files
=
[
self
.
config
.
settings
.
user
.
bincast
,
self
.
config
.
settings
.
system
.
bincast
,
]
# Use the system default magic file if no other was specified, or if -B was explicitly specified
if
(
not
self
.
magic_files
)
or
(
self
.
explicit_signature_scan
and
not
self
.
cast_data_types
)
:
self
.
magic_files
+=
self
.
config
.
settings
.
magic_signature_files
()
if
(
not
self
.
magic_files
)
or
self
.
explicit_signature_scan
:
self
.
magic_files
+=
self
.
config
.
settings
.
user
.
magic
+
self
.
config
.
settings
.
system
.
magic
# Initialize libmagic
self
.
magic
=
binwalk
.
core
.
magic
.
Magic
(
include
=
self
.
include_filters
,
...
...
@@ -136,7 +124,7 @@ class Signature(Module):
block_start
=
fp
.
tell
()
-
dlen
self
.
status
.
completed
=
block_start
-
fp
.
offset
#
TODO: Make magic scan return a results object.
#
Scan this data block for magic signatures
for
r
in
self
.
magic
.
scan
(
data
,
dlen
):
# current_block_offset is set when a jump-to-offset keyword is encountered while
...
...
@@ -146,18 +134,15 @@ class Signature(Module):
if
r
.
offset
<
current_block_offset
:
continue
# Keep a record of the relative offset of this signature inside the current data block
relative_offset
=
r
.
offset
# Set the absolute offset inside the target file
# TODO: Don't need the offset adjust stuff anymore, get rid of it
r
.
offset
=
block_start
+
r
.
offset
+
r
.
adjust
r
.
offset
=
block_start
+
r
.
offset
# Provide an instance of the current file object
r
.
file
=
fp
# Check if this was marked as invalid
r
.
valid
=
(
not
r
.
invalid
)
# Register the result for futher processing/display
# self.result automatically calls self.validate for result validation
self
.
result
(
r
=
r
)
...
...
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