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
2c439f43
Commit
2c439f43
authored
Nov 19, 2013
by
heffnercj
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed compat.py python2.6 bug
parent
f930db15
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
17 deletions
+26
-17
tinfl.c
src/C/miniz/tinfl.c
+18
-11
compat.py
src/binwalk/compat.py
+8
-6
No files found.
src/C/miniz/tinfl.c
View file @
2c439f43
...
...
@@ -517,6 +517,7 @@ void *tinfl_decompress_mem_to_heap(const void *pSrc_buf, size_t src_buf_len, siz
size_t
src_buf_size
=
src_buf_len
-
src_buf_ofs
,
dst_buf_size
=
out_buf_capacity
-
*
pOut_len
,
new_out_buf_capacity
;
tinfl_status
status
=
tinfl_decompress
(
&
decomp
,
(
const
mz_uint8
*
)
pSrc_buf
+
src_buf_ofs
,
&
src_buf_size
,
(
mz_uint8
*
)
pBuf
,
pBuf
?
(
mz_uint8
*
)
pBuf
+
*
pOut_len
:
NULL
,
&
dst_buf_size
,
(
flags
&
~
TINFL_FLAG_HAS_MORE_INPUT
)
|
TINFL_FLAG_USING_NON_WRAPPING_OUTPUT_BUF
);
printf
(
"STATUS: %d
\n
"
,
status
);
if
((
status
<
0
)
||
(
status
==
TINFL_STATUS_NEEDS_MORE_INPUT
))
{
MZ_FREE
(
pBuf
);
*
pOut_len
=
0
;
return
NULL
;
...
...
@@ -606,10 +607,11 @@ int is_deflated(char *buf, size_t buf_size, int includes_zlib_header)
return
0
;
}
#define MAX_READ_SIZE 1*1024*1024
int
inflate_raw_file
(
char
*
in_file
,
char
*
out_file
)
{
int
retval
=
0
;
size_t
out_size
=
0
,
in_size
=
0
;
int
retval
=
0
,
i
=
0
;
size_t
out_size
=
0
,
in_size
=
0
,
nbytes
=
0
;
FILE
*
fp_in
=
NULL
,
*
fp_out
=
NULL
;
char
*
compressed_data
=
NULL
,
*
decompressed_data
=
NULL
;
...
...
@@ -624,20 +626,25 @@ int inflate_raw_file(char *in_file, char *out_file)
in_size
=
ftell
(
fp_in
);
fseek
(
fp_in
,
0L
,
SEEK_SET
);
compressed_data
=
malloc
(
in_size
);
compressed_data
=
malloc
(
MAX_READ_SIZE
);
if
(
compressed_data
)
{
memset
(
compressed_data
,
0
,
in_size
);
if
(
fread
(
compressed_data
,
1
,
in_size
,
fp_in
)
==
in_size
)
for
(
i
=
0
;
i
<
in_size
;
i
+=
MAX_READ_SIZE
)
{
decompressed_data
=
(
char
*
)
tinfl_decompress_mem_to_heap
(
compressed_data
,
in_size
,
&
out_size
,
0
);
if
(
decompressed_data
&&
out_size
>
0
)
memset
(
compressed_data
,
0
,
MAX_READ_SIZE
);
nbytes
=
fread
(
compressed_data
,
1
,
MAX_READ_SIZE
,
fp_in
);
if
(
nbytes
>
0
)
{
fwrite
(
decompressed_data
,
1
,
out_size
,
fp_out
);
free
(
decompressed_data
);
retval
=
out_size
;
decompressed_data
=
(
char
*
)
tinfl_decompress_mem_to_heap
(
compressed_data
,
nbytes
,
&
out_size
,
0
);
if
(
decompressed_data
&&
out_size
>
0
)
{
fwrite
(
decompressed_data
,
1
,
out_size
,
fp_out
);
free
(
decompressed_data
);
retval
+=
out_size
;
}
}
}
...
...
src/binwalk/compat.py
View file @
2c439f43
...
...
@@ -4,7 +4,9 @@ from __future__ import print_function
import
sys
import
string
if
sys
.
version_info
.
major
>
2
:
PY_MAJOR_VERSION
=
sys
.
version_info
[
0
]
if
PY_MAJOR_VERSION
>
2
:
import
urllib.request
as
urllib2
string
.
letters
=
string
.
ascii_letters
else
:
...
...
@@ -14,7 +16,7 @@ def iterator(dictionary):
'''
For cross compatibility between Python 2 and Python 3 dictionaries.
'''
if
sys
.
version_info
.
major
>
2
:
if
PY_MAJOR_VERSION
>
2
:
return
dictionary
.
items
()
else
:
return
dictionary
.
iteritems
()
...
...
@@ -23,7 +25,7 @@ def has_key(dictionary, key):
'''
For cross compatibility between Python 2 and Python 3 dictionaries.
'''
if
sys
.
version_info
.
major
>
2
:
if
PY_MAJOR_VERSION
>
2
:
return
key
in
dictionary
else
:
return
dictionary
.
has_key
(
key
)
...
...
@@ -32,7 +34,7 @@ def str2bytes(string):
'''
For cross compatibility between Python 2 and Python 3 strings.
'''
if
isinstance
(
string
,
type
(
''
))
and
sys
.
version_info
.
major
>
2
:
if
isinstance
(
string
,
type
(
''
))
and
PY_MAJOR_VERSION
>
2
:
return
bytes
(
string
,
'latin1'
)
else
:
return
string
...
...
@@ -41,7 +43,7 @@ def bytes2str(bs):
'''
For cross compatibility between Python 2 and Python 3 strings.
'''
if
isinstance
(
bs
,
type
(
b
''
))
and
sys
.
version_info
.
major
>
2
:
if
isinstance
(
bs
,
type
(
b
''
))
and
PY_MAJOR_VERSION
>
2
:
return
bs
.
decode
(
'latin1'
)
else
:
return
bs
...
...
@@ -50,7 +52,7 @@ def string_decode(string):
'''
For cross compatibility between Python 2 and Python 3 strings.
'''
if
sys
.
version_info
.
major
>
2
:
if
PY_MAJOR_VERSION
>
2
:
return
bytes
(
string
,
'utf-8'
)
.
decode
(
'unicode_escape'
)
else
:
return
string
.
decode
(
'string_escape'
)
...
...
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