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
659126cb
Commit
659126cb
authored
Dec 20, 2013
by
devttys0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added ability to override BlockFile parent class.
parent
8e52d4b1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
5 deletions
+11
-5
common.py
src/binwalk/common.py
+11
-5
No files found.
src/binwalk/common.py
View file @
659126cb
...
...
@@ -7,6 +7,12 @@ import hashlib
import
operator
as
op
from
binwalk.compat
import
*
# This allows other modules/scripts to subclass BlockFile from a custom class. Defaults to io.FileIO.
if
has_key
(
__builtins__
,
'BLOCK_FILE_PARENT_CLASS'
):
BLOCK_FILE_PARENT_CLASS
=
__builtins__
[
'BLOCK_FILE_PARENT_CLASS'
]
else
:
BLOCK_FILE_PARENT_CLASS
=
io
.
FileIO
def
file_md5
(
file_name
):
'''
Generate an MD5 hash of the specified file.
...
...
@@ -184,7 +190,7 @@ class MathExpression(object):
raise
TypeError
(
node
)
class
BlockFile
(
io
.
FileIO
):
class
BlockFile
(
BLOCK_FILE_PARENT_CLASS
):
'''
Abstraction class for accessing binary files.
...
...
@@ -275,7 +281,7 @@ class BlockFile(io.FileIO):
if
trail
>
0
:
self
.
MAX_TRAILING_SIZE
=
trail
io
.
FileIO
.
__init__
(
self
,
fname
,
mode
)
super
(
self
.
__class__
,
self
)
.
__init__
(
fname
,
mode
)
# Work around for python 2.6 where FileIO._name is not defined
try
:
...
...
@@ -320,7 +326,7 @@ class BlockFile(io.FileIO):
data
=
str2bytes
(
data
)
while
n
<
l
:
n
+=
io
.
FileIO
.
write
(
self
,
data
[
n
:])
n
+=
super
(
self
.
__class__
,
self
)
.
write
(
data
[
n
:])
return
n
...
...
@@ -337,7 +343,7 @@ class BlockFile(io.FileIO):
data
=
b
''
while
n
<
0
or
l
<
n
:
tmp
=
io
.
FileIO
.
read
(
self
,
n
-
l
)
tmp
=
super
(
self
.
__class__
,
self
)
.
read
(
n
-
l
)
if
tmp
:
data
+=
tmp
l
+=
len
(
tmp
)
...
...
@@ -364,7 +370,7 @@ class BlockFile(io.FileIO):
elif
whence
==
os
.
SEEK_END
:
self
.
total_read
=
self
.
size
+
n
io
.
FileIO
.
seek
(
self
,
n
,
whence
)
super
(
self
.
__class__
,
self
)
.
seek
(
n
,
whence
)
def
read_block
(
self
):
'''
...
...
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