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
cf10f5b2
Commit
cf10f5b2
authored
Feb 04, 2014
by
devttys0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added sanity checks to user and system file paths in case they don't exist.
parent
7c705dd9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
22 deletions
+47
-22
parser.py
src/binwalk/core/parser.py
+5
-4
settings.py
src/binwalk/core/settings.py
+26
-3
extractor.py
src/binwalk/modules/extractor.py
+10
-9
signature.py
src/binwalk/modules/signature.py
+6
-6
No files found.
src/binwalk/core/parser.py
View file @
cf10f5b2
...
@@ -145,10 +145,11 @@ class MagicParser(object):
...
@@ -145,10 +145,11 @@ class MagicParser(object):
files
=
[
file_name
]
files
=
[
file_name
]
for
fname
in
files
:
for
fname
in
files
:
if
os
.
path
.
exists
(
fname
):
if
fname
:
self
.
parse_file
(
fname
)
if
os
.
path
.
exists
(
fname
):
else
:
self
.
parse_file
(
fname
)
sys
.
stdout
.
write
(
"WARNING: Magic file '
%
s' does not exist!
\n
"
%
fname
)
else
:
sys
.
stdout
.
write
(
"WARNING: Magic file '
%
s' does not exist!
\n
"
%
fname
)
self
.
fd
.
seek
(
0
)
self
.
fd
.
seek
(
0
)
return
self
.
fd
.
name
return
self
.
fd
.
name
...
...
src/binwalk/core/settings.py
View file @
cf10f5b2
...
@@ -41,7 +41,7 @@ class Settings:
...
@@ -41,7 +41,7 @@ class Settings:
# Dictionary of all absolute user/system file paths
# Dictionary of all absolute user/system file paths
self
.
paths
=
{
self
.
paths
=
{
'user'
:
{},
'user'
:
{},
'system'
:
{},
'system'
:
{},
}
}
...
@@ -59,6 +59,19 @@ class Settings:
...
@@ -59,6 +59,19 @@ class Settings:
self
.
paths
[
'system'
][
self
.
EXTRACT_FILE
]
=
self
.
_system_path
(
self
.
BINWALK_CONFIG_DIR
,
self
.
EXTRACT_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
)
self
.
paths
[
'system'
][
self
.
PLUGINS
]
=
self
.
_system_path
(
self
.
BINWALK_PLUGINS_DIR
)
def
get_file_path
(
self
,
usersys
,
fname
):
'''
Retrieves the specified file path from self.paths.
@usersys - One of: 'user', 'system'.
@fname - The file name (e.g., self.BINWALK_MAGIC_FILE, self.PLUGINS, etc)
Returns the path, if it exists; returns None otherwise.
'''
if
self
.
paths
.
has_key
(
usersys
)
and
has_key
(
self
.
paths
[
usersys
],
fname
)
and
self
.
paths
[
usersys
][
fname
]:
return
self
.
paths
[
usersys
][
fname
]
return
None
def
find_magic_file
(
self
,
fname
,
system_only
=
False
,
user_only
=
False
):
def
find_magic_file
(
self
,
fname
,
system_only
=
False
,
user_only
=
False
):
'''
'''
Finds the specified magic file name in the system / user magic file directories.
Finds the specified magic file name in the system / user magic file directories.
...
@@ -149,7 +162,12 @@ class Settings:
...
@@ -149,7 +162,12 @@ class Settings:
Returns the full path to the 'subdir/basename' file.
Returns the full path to the 'subdir/basename' file.
'''
'''
return
self
.
_file_path
(
os
.
path
.
join
(
self
.
user_dir
,
self
.
BINWALK_USER_DIR
,
subdir
),
basename
)
try
:
return
self
.
_file_path
(
os
.
path
.
join
(
self
.
user_dir
,
self
.
BINWALK_USER_DIR
,
subdir
),
basename
)
except
KeyboardInterrupt
as
e
:
raise
e
except
Exception
:
return
None
def
_system_path
(
self
,
subdir
,
basename
=
''
):
def
_system_path
(
self
,
subdir
,
basename
=
''
):
'''
'''
...
@@ -160,5 +178,10 @@ class Settings:
...
@@ -160,5 +178,10 @@ class Settings:
Returns the full path to the 'subdir/basename' file.
Returns the full path to the 'subdir/basename' file.
'''
'''
return
self
.
_file_path
(
os
.
path
.
join
(
self
.
system_dir
,
subdir
),
basename
)
try
:
return
self
.
_file_path
(
os
.
path
.
join
(
self
.
system_dir
,
subdir
),
basename
)
except
KeyboardInterrupt
as
e
:
raise
e
except
Exception
:
return
None
src/binwalk/modules/extractor.py
View file @
cf10f5b2
...
@@ -258,18 +258,19 @@ class Extractor(Module):
...
@@ -258,18 +258,19 @@ class Extractor(Module):
'''
'''
# Load the user extract file first to ensure its rules take precedence.
# Load the user extract file first to ensure its rules take precedence.
extract_files
=
[
extract_files
=
[
self
.
config
.
settings
.
paths
[
'user'
][
self
.
config
.
settings
.
EXTRACT_FILE
]
,
self
.
config
.
settings
.
get_file_path
(
'user'
,
self
.
config
.
settings
.
EXTRACT_FILE
)
,
self
.
config
.
settings
.
paths
[
'system'
][
self
.
config
.
settings
.
EXTRACT_FILE
]
,
self
.
config
.
settings
.
get_file_path
(
'system'
,
self
.
config
.
settings
.
EXTRACT_FILE
)
,
]
]
for
extract_file
in
extract_files
:
for
extract_file
in
extract_files
:
try
:
if
extract_file
:
self
.
load_from_file
(
extract_file
)
try
:
except
KeyboardInterrupt
as
e
:
self
.
load_from_file
(
extract_file
)
raise
e
except
KeyboardInterrupt
as
e
:
except
Exception
as
e
:
raise
e
if
self
.
config
.
verbose
:
except
Exception
as
e
:
raise
Exception
(
"Extractor.load_defaults failed to load file '
%
s':
%
s"
%
(
extract_file
,
str
(
e
)))
if
self
.
config
.
verbose
:
raise
Exception
(
"Extractor.load_defaults failed to load file '
%
s':
%
s"
%
(
extract_file
,
str
(
e
)))
def
build_output_directory
(
self
,
path
):
def
build_output_directory
(
self
,
path
):
'''
'''
...
...
src/binwalk/modules/signature.py
View file @
cf10f5b2
...
@@ -62,21 +62,21 @@ class Signature(Module):
...
@@ -62,21 +62,21 @@ class Signature(Module):
# Append the user's magic file first so that those signatures take precedence
# Append the user's magic file first so that those signatures take precedence
if
self
.
search_for_opcodes
:
if
self
.
search_for_opcodes
:
self
.
magic_files
+=
[
self
.
magic_files
+=
[
self
.
config
.
settings
.
paths
[
'user'
][
self
.
config
.
settings
.
BINARCH_MAGIC_FILE
]
,
self
.
config
.
settings
.
get_file_path
(
'user'
,
self
.
config
.
settings
.
BINARCH_MAGIC_FILE
)
,
self
.
config
.
settings
.
paths
[
'system'
][
self
.
config
.
settings
.
BINARCH_MAGIC_FILE
]
,
self
.
config
.
settings
.
get_file_path
(
'system'
,
self
.
config
.
settings
.
BINARCH_MAGIC_FILE
)
,
]
]
if
self
.
cast_data_types
:
if
self
.
cast_data_types
:
self
.
magic_files
+=
[
self
.
magic_files
+=
[
self
.
config
.
settings
.
paths
[
'user'
][
self
.
config
.
settings
.
BINCAST_MAGIC_FILE
]
,
self
.
config
.
settings
.
get_file_path
(
'user'
,
self
.
config
.
settings
.
BINCAST_MAGIC_FILE
)
,
self
.
config
.
settings
.
paths
[
'system'
][
self
.
config
.
settings
.
BINCAST_MAGIC_FILE
]
,
self
.
config
.
settings
.
get_file_path
(
'system'
,
self
.
config
.
settings
.
BINCAST_MAGIC_FILE
)
,
]
]
# Use the system default magic file if no other was specified, or if -B was explicitly specified
# Use the system default magic file if no other was specified, or if -B was explicitly specified
if
not
self
.
magic_files
or
self
.
force_default_scan
:
if
not
self
.
magic_files
or
self
.
force_default_scan
:
self
.
magic_files
+=
[
self
.
magic_files
+=
[
self
.
config
.
settings
.
paths
[
'user'
][
self
.
config
.
settings
.
BINWALK_MAGIC_FILE
]
,
self
.
config
.
settings
.
get_file_path
(
'user'
,
self
.
config
.
settings
.
BINWALK_MAGIC_FILE
)
,
self
.
config
.
settings
.
paths
[
'system'
][
self
.
config
.
settings
.
BINWALK_MAGIC_FILE
]
,
self
.
config
.
settings
.
get_file_path
(
'system'
,
self
.
config
.
settings
.
BINWALK_MAGIC_FILE
)
,
]
]
# Parse the magic file(s) and initialize libmagic
# Parse the magic file(s) and initialize libmagic
...
...
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