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
f6eea731
Commit
f6eea731
authored
Nov 16, 2013
by
heffnercj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
deflate.py plugin now supports raw deflate stream extraction/decompression
parent
4989aba0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
65 additions
and
24 deletions
+65
-24
test.py
src/C/miniz/test.py
+4
-3
tinfl.c
src/C/miniz/tinfl.c
+52
-0
deflate.py
src/binwalk/plugins/deflate.py
+9
-21
No files found.
src/C/miniz/test.py
View file @
f6eea731
...
...
@@ -14,7 +14,8 @@ except:
tinfl
=
ctypes
.
cdll
.
LoadLibrary
(
ctypes
.
util
.
find_library
(
"tinfl"
))
if
tinfl
.
is_deflated
(
data
,
len
(
data
),
1
):
print
"
%
s is zlib compressed."
%
(
sys
.
argv
[
1
])
if
tinfl
.
is_deflated
(
data
,
len
(
data
),
0
):
print
"
%
s is deflated."
%
(
sys
.
argv
[
1
])
print
"Inflated to
%
d bytes!"
%
tinfl
.
inflate_raw_file
(
sys
.
argv
[
1
],
sys
.
argv
[
1
]
+
'.inflated'
)
else
:
print
"
%
s is not
zlib compress
ed."
%
sys
.
argv
[
1
]
print
"
%
s is not
deflat
ed."
%
sys
.
argv
[
1
]
src/C/miniz/tinfl.c
View file @
f6eea731
...
...
@@ -603,6 +603,50 @@ int is_deflated(char *buf, size_t buf_size, int includes_zlib_header)
return
0
;
}
int
inflate_raw_file
(
char
*
in_file
,
char
*
out_file
)
{
int
retval
=
0
;
size_t
out_size
=
0
,
in_size
=
0
;
FILE
*
fp_in
=
NULL
,
*
fp_out
=
NULL
;
char
*
compressed_data
=
NULL
,
*
decompressed_data
=
NULL
;
fp_in
=
fopen
(
in_file
,
"rb"
);
if
(
fp_in
)
{
fp_out
=
fopen
(
out_file
,
"wb"
);
if
(
fp_out
)
{
fseek
(
fp_in
,
0L
,
SEEK_END
);
in_size
=
ftell
(
fp_in
);
fseek
(
fp_in
,
0L
,
SEEK_SET
);
compressed_data
=
malloc
(
in_size
);
if
(
compressed_data
)
{
memset
(
compressed_data
,
0
,
in_size
);
fread
(
compressed_data
,
1
,
in_size
,
fp_in
);
decompressed_data
=
(
char
*
)
tinfl_decompress_mem_to_heap
(
compressed_data
,
in_size
,
&
out_size
,
0
);
if
(
decompressed_data
)
{
fwrite
(
decompressed_data
,
1
,
out_size
,
fp_out
);
free
(
decompressed_data
);
retval
=
out_size
;
}
free
(
compressed_data
);
}
}
}
if
(
fp_in
)
fclose
(
fp_in
);
if
(
fp_out
)
fclose
(
fp_out
);
return
retval
;
}
#endif // #ifndef TINFL_HEADER_FILE_ONLY
/*
...
...
@@ -631,3 +675,11 @@ int is_deflated(char *buf, size_t buf_size, int includes_zlib_header)
For more information, please refer to <http://unlicense.org/>
*/
#ifdef MAIN
int
main
(
int
argc
,
char
*
argv
[])
{
printf
(
"Inflated to %d bytes.
\n
"
,
inflate_raw_file
(
argv
[
1
],
argv
[
2
]));
return
0
;
}
#endif
src/binwalk/plugins/deflate.py
View file @
f6eea731
...
...
@@ -20,34 +20,18 @@ class Plugin:
# The tinfl library is built and installed with binwalk
self
.
tinfl
=
ctypes
.
cdll
.
LoadLibrary
(
ctypes
.
util
.
find_library
(
"tinfl"
))
# Add an extraction rule
if
self
.
binwalk
.
extractor
.
enabled
:
# TODO: Add python extractor rule
pass
self
.
binwalk
.
extractor
.
add_rule
(
regex
=
self
.
DESCRIPTION
.
lower
(),
extension
=
"deflate"
,
cmd
=
self
.
_extractor
)
def
pre_scan
(
self
,
fp
):
self
.
_deflate_scan
(
fp
)
return
PLUGIN_TERMINATE
def
_extractor
(
self
,
file_name
):
processed
=
0
inflated_data
=
''
fd
=
BlockFile
(
file_name
,
'rb'
)
fd
.
READ_BLOCK_SIZE
=
self
.
SIZE
while
processed
<
fd
.
length
:
(
data
,
dlen
)
=
fd
.
read_block
()
inflated_block
=
self
.
tinfl
.
inflate_block
(
data
,
dlen
)
if
inflated_block
:
inflated_data
+=
inflated_block
else
:
break
processed
+=
dlen
fd
.
close
()
print
"
%
s inflated to
%
d bytes"
%
(
file_name
,
len
(
inflated_data
))
if
self
.
tinfl
:
out_file
=
os
.
path
.
splitext
(
file_name
)[
0
]
self
.
tinfl
.
inflate_raw_file
(
file_name
,
out_file
)
def
_deflate_scan
(
self
,
fp
):
fp
.
MAX_TRAILING_SIZE
=
self
.
SIZE
...
...
@@ -70,6 +54,10 @@ class Plugin:
self
.
binwalk
.
total_scanned
=
current_total
+
i
self
.
binwalk
.
display
.
easy_results
(
loc
,
self
.
DESCRIPTION
)
# Extract the file
if
self
.
binwalk
.
extractor
.
enabled
:
self
.
binwalk
.
extractor
.
extract
(
loc
,
self
.
DESCRIPTION
,
fp
.
name
,
(
fp
.
length
-
loc
))
if
(
current_total
+
i
)
>
self
.
binwalk
.
scan_length
:
break
...
...
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