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
d19aae0b
Commit
d19aae0b
authored
Oct 27, 2014
by
devttys0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated zlib plugins to use Python's zlib module instead of libtinfl
parent
679c9485
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
42 deletions
+22
-42
gzipvalid.py
src/binwalk/plugins/gzipvalid.py
+10
-14
zlibvalid.py
src/binwalk/plugins/zlibvalid.py
+12
-18
compressed
src/magic/compressed
+0
-10
No files found.
src/binwalk/plugins/gzipvalid.py
View file @
d19aae0b
import
binwalk.core.C
import
zlib
import
binwalk.core.compat
import
binwalk.core.plugin
import
binwalk.core.plugin
from
binwalk.core.common
import
BlockFile
from
binwalk.core.common
import
BlockFile
...
@@ -8,18 +9,8 @@ class GzipValidPlugin(binwalk.core.plugin.Plugin):
...
@@ -8,18 +9,8 @@ class GzipValidPlugin(binwalk.core.plugin.Plugin):
'''
'''
MODULES
=
[
'Signature'
]
MODULES
=
[
'Signature'
]
MIN_DECOMP_SIZE
=
16
*
1024
MAX_DATA_SIZE
=
33
*
1024
MAX_DATA_SIZE
=
33
*
1024
TINFL
=
"tinfl"
TINFL_FUNCTIONS
=
[
binwalk
.
core
.
C
.
Function
(
name
=
"is_deflated"
,
type
=
int
),
]
def
init
(
self
):
# Load libtinfl.so
self
.
tinfl
=
binwalk
.
core
.
C
.
Library
(
self
.
TINFL
,
self
.
TINFL_FUNCTIONS
)
def
scan
(
self
,
result
):
def
scan
(
self
,
result
):
# If this result is a gzip signature match, try to decompress the data
# If this result is a gzip signature match, try to decompress the data
if
result
.
file
and
result
.
description
.
lower
()
.
startswith
(
'gzip'
):
if
result
.
file
and
result
.
description
.
lower
()
.
startswith
(
'gzip'
):
...
@@ -40,8 +31,13 @@ class GzipValidPlugin(binwalk.core.plugin.Plugin):
...
@@ -40,8 +31,13 @@ class GzipValidPlugin(binwalk.core.plugin.Plugin):
offset
+=
1
offset
+=
1
offset
+=
1
offset
+=
1
# Append basic zlib header to the beginning of the compressed data
data
=
"
\x78\x9C
"
+
data
[
offset
:]
# Check if this is valid deflate data (no zlib header)
# Check if this is valid deflate data (no zlib header)
decomp_size
=
self
.
tinfl
.
is_deflated
(
data
[
offset
:],
len
(
data
[
offset
:]),
0
)
try
:
if
decomp_size
<=
0
:
zlib
.
decompress
(
binwalk
.
core
.
compat
.
str2bytes
(
data
))
result
.
valid
=
False
except
zlib
.
error
as
e
:
if
not
str
(
e
)
.
startswith
(
"Error -5"
):
result
.
valid
=
False
src/binwalk/plugins/zlibvalid.py
View file @
d19aae0b
import
binwalk.core.C
import
zlib
import
binwalk.core.compat
import
binwalk.core.plugin
import
binwalk.core.plugin
from
binwalk.core.common
import
BlockFile
from
binwalk.core.common
import
BlockFile
...
@@ -8,18 +9,8 @@ class ZlibValidPlugin(binwalk.core.plugin.Plugin):
...
@@ -8,18 +9,8 @@ class ZlibValidPlugin(binwalk.core.plugin.Plugin):
'''
'''
MODULES
=
[
'Signature'
]
MODULES
=
[
'Signature'
]
MIN_DECOMP_SIZE
=
16
*
1024
MAX_DATA_SIZE
=
33
*
1024
MAX_DATA_SIZE
=
33
*
1024
TINFL
=
"tinfl"
TINFL_FUNCTIONS
=
[
binwalk
.
core
.
C
.
Function
(
name
=
"is_deflated"
,
type
=
int
),
]
def
init
(
self
):
# Load libtinfl.so
self
.
tinfl
=
binwalk
.
core
.
C
.
Library
(
self
.
TINFL
,
self
.
TINFL_FUNCTIONS
)
def
scan
(
self
,
result
):
def
scan
(
self
,
result
):
# If this result is a zlib signature match, try to decompress the data
# If this result is a zlib signature match, try to decompress the data
if
result
.
file
and
result
.
description
.
lower
()
.
startswith
(
'zlib'
):
if
result
.
file
and
result
.
description
.
lower
()
.
startswith
(
'zlib'
):
...
@@ -28,10 +19,13 @@ class ZlibValidPlugin(binwalk.core.plugin.Plugin):
...
@@ -28,10 +19,13 @@ class ZlibValidPlugin(binwalk.core.plugin.Plugin):
data
=
fd
.
read
(
self
.
MAX_DATA_SIZE
)
data
=
fd
.
read
(
self
.
MAX_DATA_SIZE
)
fd
.
close
()
fd
.
close
()
# Check if this is valid zlib data
# Check if this is valid zlib data. It is valid if:
decomp_size
=
self
.
tinfl
.
is_deflated
(
data
,
len
(
data
),
1
)
#
if
decomp_size
>
0
:
# 1. It decompresses without error
result
.
description
+=
", uncompressed size >=
%
d"
%
decomp_size
# 2. Decompression fails only because of truncated input
else
:
try
:
result
.
valid
=
False
zlib
.
decompress
(
binwalk
.
core
.
compat
.
str2bytes
(
data
))
except
zlib
.
error
as
e
:
# Error -5, incomplete or truncated data input
if
not
str
(
e
)
.
startswith
(
"Error -5"
):
result
.
valid
=
False
src/magic/compressed
View file @
d19aae0b
...
@@ -136,16 +136,6 @@
...
@@ -136,16 +136,6 @@
>4 ledate x %s
>4 ledate x %s
>4 lelong x \b{file-epoch:%d}
>4 lelong x \b{file-epoch:%d}
# Zlib signatures
# Too short to be useful on their own; see:
#
# o src/binwalk/magic/zlib
# o src/binwalk/plugins/zlib.py
#
#0 beshort 0x789C zlib compressed data
#0 beshort 0x78DA zlib compressed data
#0 beshort 0x7801 zlib compressed data
# Supplementary magic data for the file(1) command to support
# Supplementary magic data for the file(1) command to support
# rzip(1). The format is described in magic(5).
# rzip(1). The format is described in magic(5).
#
#
...
...
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