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
4e6c3063
Commit
4e6c3063
authored
Mar 25, 2017
by
Craig Heffner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed plugin extractor ordering.
parent
8d0afa75
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
32 deletions
+47
-32
extractor.py
src/binwalk/modules/extractor.py
+31
-11
lzmaextract.py
src/binwalk/plugins/lzmaextract.py
+5
-3
lzmamod.py
src/binwalk/plugins/lzmamod.py
+11
-18
No files found.
src/binwalk/modules/extractor.py
View file @
4e6c3063
...
@@ -275,7 +275,18 @@ class Extractor(Module):
...
@@ -275,7 +275,18 @@ class Extractor(Module):
def
append_rule
(
self
,
r
):
def
append_rule
(
self
,
r
):
self
.
extract_rules
.
append
(
r
.
copy
())
self
.
extract_rules
.
append
(
r
.
copy
())
def
add_rule
(
self
,
txtrule
=
None
,
regex
=
None
,
extension
=
None
,
cmd
=
None
,
codes
=
[
0
,
None
],
recurse
=
True
):
def
prepend_rule
(
self
,
r
):
self
.
extract_rules
=
[
r
]
+
self
.
extract_rules
def
add_rule
(
self
,
txtrule
=
None
,
regex
=
None
,
extension
=
None
,
cmd
=
None
,
codes
=
[
0
,
None
],
recurse
=
True
,
prepend
=
False
):
rules
=
self
.
create_rule
(
txtrule
,
regex
,
extension
,
cmd
,
codes
,
recurse
)
for
r
in
rules
:
if
prepend
:
self
.
prepend_rule
(
r
)
else
:
self
.
append_rule
(
r
)
def
create_rule
(
self
,
txtrule
=
None
,
regex
=
None
,
extension
=
None
,
cmd
=
None
,
codes
=
[
0
,
None
],
recurse
=
True
):
'''
'''
Adds a set of rules to the extraction rule list.
Adds a set of rules to the extraction rule list.
...
@@ -290,6 +301,7 @@ class Extractor(Module):
...
@@ -290,6 +301,7 @@ class Extractor(Module):
Returns None.
Returns None.
'''
'''
rules
=
[]
rules
=
[]
created_rules
=
[]
match
=
False
match
=
False
r
=
{
r
=
{
'extension'
:
''
,
'extension'
:
''
,
...
@@ -306,8 +318,7 @@ class Extractor(Module):
...
@@ -306,8 +318,7 @@ class Extractor(Module):
if
cmd
:
if
cmd
:
r
[
'cmd'
]
=
cmd
r
[
'cmd'
]
=
cmd
self
.
append_rule
(
r
)
return
[
r
]
return
# Process rule string, or list of rule strings
# Process rule string, or list of rule strings
if
not
isinstance
(
txtrule
,
type
([])):
if
not
isinstance
(
txtrule
,
type
([])):
...
@@ -334,7 +345,9 @@ class Extractor(Module):
...
@@ -334,7 +345,9 @@ class Extractor(Module):
# Verify that the match string was retrieved.
# Verify that the match string was retrieved.
if
match
:
if
match
:
self
.
append_rule
(
r
)
created_rules
.
append
(
r
)
return
created_rules
def
remove_rules
(
self
,
description
):
def
remove_rules
(
self
,
description
):
'''
'''
...
@@ -553,8 +566,7 @@ class Extractor(Module):
...
@@ -553,8 +566,7 @@ class Extractor(Module):
if
not
rules
:
if
not
rules
:
return
(
None
,
None
,
False
)
return
(
None
,
None
,
False
)
else
:
else
:
binwalk
.
core
.
common
.
debug
(
binwalk
.
core
.
common
.
debug
(
"Found
%
d matching extraction rules"
%
len
(
rules
))
"Found
%
d matching extraction rules"
%
len
(
rules
))
# Generate the output directory name where extracted files will be
# Generate the output directory name where extracted files will be
# stored
# stored
...
@@ -579,8 +591,7 @@ class Extractor(Module):
...
@@ -579,8 +591,7 @@ class Extractor(Module):
recurse
=
True
recurse
=
True
# Copy out the data to disk, if we haven't already
# Copy out the data to disk, if we haven't already
fname
=
self
.
_dd
(
fname
=
self
.
_dd
(
file_path
,
offset
,
size
,
rule
[
'extension'
],
output_file_name
=
name
)
file_path
,
offset
,
size
,
rule
[
'extension'
],
output_file_name
=
name
)
# If there was a command specified for this rule, try to execute it.
# If there was a command specified for this rule, try to execute it.
# If execution fails, the next rule will be attempted.
# If execution fails, the next rule will be attempted.
...
@@ -595,8 +606,7 @@ class Extractor(Module):
...
@@ -595,8 +606,7 @@ class Extractor(Module):
# Execute the specified command against the extracted file
# Execute the specified command against the extracted file
if
self
.
run_extractors
:
if
self
.
run_extractors
:
extract_ok
=
self
.
execute
(
extract_ok
=
self
.
execute
(
rule
[
'cmd'
],
fname
,
rule
[
'codes'
])
rule
[
'cmd'
],
fname
,
rule
[
'codes'
])
else
:
else
:
extract_ok
=
True
extract_ok
=
True
...
@@ -665,12 +675,22 @@ class Extractor(Module):
...
@@ -665,12 +675,22 @@ class Extractor(Module):
Returns None if no match is found.
Returns None if no match is found.
'''
'''
rules
=
[]
rules
=
[]
ordered_rules
=
[]
description
=
description
.
lower
()
description
=
description
.
lower
()
for
rule
in
self
.
extract_rules
:
for
rule
in
self
.
extract_rules
:
if
rule
[
'regex'
]
.
search
(
description
):
if
rule
[
'regex'
]
.
search
(
description
):
rules
.
append
(
rule
)
rules
.
append
(
rule
)
return
rules
# Plugin rules should take precedence over external extraction commands.
for
rule
in
rules
:
if
callable
(
rule
[
'cmd'
]):
ordered_rules
.
append
(
rule
)
for
rule
in
rules
:
if
not
callable
(
rule
[
'cmd'
]):
ordered_rules
.
append
(
rule
)
return
ordered_rules
def
_parse_rule
(
self
,
rule
):
def
_parse_rule
(
self
,
rule
):
'''
'''
...
...
src/binwalk/plugins/lzmaextract.py
View file @
4e6c3063
...
@@ -23,16 +23,18 @@ class LZMAExtractPlugin(binwalk.core.plugin.Plugin):
...
@@ -23,16 +23,18 @@ class LZMAExtractPlugin(binwalk.core.plugin.Plugin):
self
.
decompressor
=
lzma
.
decompress
self
.
decompressor
=
lzma
.
decompress
# If the extractor is enabled for the module we're currently loaded
# If the extractor is enabled for the module we're currently loaded
# into, then register self.extractor as a
zlib
extraction rule.
# into, then register self.extractor as a
n lzma
extraction rule.
if
self
.
module
.
extractor
.
enabled
:
if
self
.
module
.
extractor
.
enabled
:
self
.
module
.
extractor
.
add_rule
(
txtrule
=
None
,
self
.
module
.
extractor
.
add_rule
(
txtrule
=
None
,
regex
=
"^lzma compressed data"
,
regex
=
"^lzma compressed data"
,
extension
=
"7z"
,
extension
=
"7z"
,
cmd
=
self
.
extractor
)
cmd
=
self
.
extractor
,
prepend
=
True
)
self
.
module
.
extractor
.
add_rule
(
txtrule
=
None
,
self
.
module
.
extractor
.
add_rule
(
txtrule
=
None
,
regex
=
"^xz compressed data"
,
regex
=
"^xz compressed data"
,
extension
=
"xz"
,
extension
=
"xz"
,
cmd
=
self
.
extractor
)
cmd
=
self
.
extractor
,
prepend
=
True
)
except
ImportError
as
e
:
except
ImportError
as
e
:
pass
pass
...
...
src/binwalk/plugins/lzmamod.py
View file @
4e6c3063
import
os
import
os
import
shutil
import
binwalk.core.plugin
import
binwalk.core.plugin
from
binwalk.core.compat
import
*
from
binwalk.core.compat
import
*
from
binwalk.core.common
import
BlockFile
from
binwalk.core.common
import
BlockFile
...
@@ -19,21 +18,13 @@ class LZMAModPlugin(binwalk.core.plugin.Plugin):
...
@@ -19,21 +18,13 @@ class LZMAModPlugin(binwalk.core.plugin.Plugin):
def
init
(
self
):
def
init
(
self
):
self
.
original_cmd
=
''
self
.
original_cmd
=
''
# Replace the first existing LZMA extraction command with our own
self
.
module
.
extractor
.
add_rule
(
txtrule
=
None
,
for
rule
in
self
.
module
.
extractor
.
match
(
self
.
SIGNATURE
):
regex
=
"^
%
s"
%
self
.
SIGNATURE
,
self
.
original_cmd
=
rule
[
'cmd'
]
extension
=
"7z"
,
rule
[
'cmd'
]
=
self
.
lzma_cable_extractor
cmd
=
self
.
lzma_cable_extractor
,
prepend
=
True
)
break
def
lzma_cable_extractor
(
self
,
fname
):
def
lzma_cable_extractor
(
self
,
fname
):
# Try extracting the LZMA file without modification first
out_name
=
os
.
path
.
splitext
(
fname
)[
0
]
+
'-patched'
+
os
.
path
.
splitext
(
fname
)[
1
]
result
=
self
.
module
.
extractor
.
execute
(
self
.
original_cmd
,
fname
)
# If the external extractor was successul (True) or didn't exist
# (None), don't do anything.
if
result
not
in
[
True
,
None
]:
out_name
=
os
.
path
.
splitext
(
fname
)[
0
]
+
'-patched'
+
os
.
path
.
splitext
(
fname
)[
1
]
fp_out
=
BlockFile
(
out_name
,
'w'
)
fp_out
=
BlockFile
(
out_name
,
'w'
)
# Use self.module.config.open_file here to ensure that other config
# Use self.module.config.open_file here to ensure that other config
# settings (such as byte-swapping) are honored
# settings (such as byte-swapping) are honored
...
@@ -56,11 +47,13 @@ class LZMAModPlugin(binwalk.core.plugin.Plugin):
...
@@ -56,11 +47,13 @@ class LZMAModPlugin(binwalk.core.plugin.Plugin):
fp_in
.
close
()
fp_in
.
close
()
fp_out
.
close
()
fp_out
.
close
()
# Overwrite the original file so that it can be cleaned up if -r
for
rule
in
self
.
module
.
extractor
.
get_rules
(
self
.
SIGNATURE
):
# was specified
if
rule
[
'cmd'
]
!=
self
.
lzma_cable_extractor
:
shutil
.
move
(
out_name
,
fname
)
result
=
self
.
module
.
extractor
.
execute
(
rule
[
'cmd'
],
out_name
)
result
=
self
.
module
.
extractor
.
execute
(
self
.
original_cmd
,
fname
)
if
result
==
True
:
break
os
.
remove
(
out_name
)
return
result
return
result
def
scan
(
self
,
result
):
def
scan
(
self
,
result
):
...
...
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