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
3ead886f
Commit
3ead886f
authored
Dec 21, 2013
by
devttys0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Consolidated BlockFile code.
parent
ef653b30
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
34 deletions
+36
-34
common.py
src/binwalk/core/common.py
+36
-34
No files found.
src/binwalk/core/common.py
View file @
3ead886f
...
@@ -336,7 +336,8 @@ class BlockFile(BLOCK_FILE_PARENT_CLASS):
...
@@ -336,7 +336,8 @@ class BlockFile(BLOCK_FILE_PARENT_CLASS):
def
read
(
self
,
n
=-
1
):
def
read
(
self
,
n
=-
1
):
''''
''''
Reads up to n bytes of data (or to EOF if n is not specified).
Reads up to n bytes of data (or to EOF if n is not specified).
Will not read more than self.length bytes.
io.FileIO.read does not guaruntee that all requested data will be read;
io.FileIO.read does not guaruntee that all requested data will be read;
this method overrides io.FileIO.read and does guaruntee that all data will be read.
this method overrides io.FileIO.read and does guaruntee that all data will be read.
...
@@ -345,15 +346,21 @@ class BlockFile(BLOCK_FILE_PARENT_CLASS):
...
@@ -345,15 +346,21 @@ class BlockFile(BLOCK_FILE_PARENT_CLASS):
l
=
0
l
=
0
data
=
b
''
data
=
b
''
while
n
<
0
or
l
<
n
:
if
self
.
total_read
<
self
.
length
:
tmp
=
super
(
self
.
__class__
,
self
)
.
read
(
n
-
l
)
# Don't read more than self.length bytes from the file
if
tmp
:
if
(
self
.
total_read
+
n
)
>
self
.
length
:
data
+=
tmp
n
=
self
.
length
-
self
.
total_read
l
+=
len
(
tmp
)
else
:
while
n
<
0
or
l
<
n
:
break
tmp
=
super
(
self
.
__class__
,
self
)
.
read
(
n
-
l
)
if
tmp
:
data
+=
tmp
l
+=
len
(
tmp
)
else
:
break
self
.
total_read
+=
len
(
data
)
self
.
total_read
+=
len
(
data
)
return
self
.
_swap_data_block
(
bytes2str
(
data
))
return
self
.
_swap_data_block
(
bytes2str
(
data
))
def
_internal_read
(
self
,
n
=-
1
):
def
_internal_read
(
self
,
n
=-
1
):
...
@@ -383,35 +390,30 @@ class BlockFile(BLOCK_FILE_PARENT_CLASS):
...
@@ -383,35 +390,30 @@ class BlockFile(BLOCK_FILE_PARENT_CLASS):
'''
'''
dlen
=
0
dlen
=
0
data
=
None
data
=
None
rsize
=
self
.
READ_BLOCK_SIZE
+
self
.
MAX_TRAILING_SIZE
if
self
.
total_read
<
self
.
length
:
# Do the read. Must use self._internal_read so that the total_read value is untouched (we update this ourselves later)
# Read in self.READ_BLOCK_SIZE + self.MAX_TRAILING_SIZE, unless this exceeds self.length
data
=
self
.
_internal_read
(
rsize
)
rsize
=
self
.
READ_BLOCK_SIZE
+
self
.
MAX_TRAILING_SIZE
if
(
self
.
total_read
+
rsize
)
>
self
.
length
:
rsize
=
self
.
length
-
self
.
total_read
# Do the read. Must use self._internal_read so that the total_read value is untouched (we update this ourselves later)
data
=
self
.
_internal_read
(
rsize
)
if
data
and
data
is
not
None
:
if
data
:
# Get the actual length of the read in data
# Get the actual length of the read in data
dlen
=
len
(
data
)
dlen
=
len
(
data
)
# Calculate how far back we need to seek to pick up at the self.READ_BLOCK_SIZE offset
# Calculate how far back we need to seek to pick up at the self.READ_BLOCK_SIZE offset
seek_offset
=
dlen
-
self
.
READ_BLOCK_SIZE
seek_offset
=
dlen
-
self
.
READ_BLOCK_SIZE
# If r
size was less than self.READ_BLOCK_SIZE seek backwards zero bytes
# If the actual read
size was less than self.READ_BLOCK_SIZE seek backwards zero bytes
if
seek_offset
<
0
:
if
seek_offset
<
0
:
seek_offset
=
0
seek_offset
=
0
# Read in READ_BLOCK_SIZE plus MAX_TRAILING_SIZE bytes, but return a max dlen value
# Read in READ_BLOCK_SIZE plus MAX_TRAILING_SIZE bytes, but return a max dlen value
# Return a max dlen value of READ_BLOCK_SIZE. This ensures that there is a MAX_TRAILING_SIZE
# Return a max dlen value of READ_BLOCK_SIZE. This ensures that there is a MAX_TRAILING_SIZE
# buffer at the end of the returned data in case a signature is found at or near data[READ_BLOCK_SIZE].
# buffer at the end of the returned data in case a signature is found at or near data[READ_BLOCK_SIZE].
if
dlen
==
(
self
.
READ_BLOCK_SIZE
+
self
.
MAX_TRAILING_SIZE
)
:
if
dlen
==
rsize
:
dlen
=
self
.
READ_BLOCK_SIZE
dlen
=
self
.
READ_BLOCK_SIZE
# Seek to the self.total_read offset so the next read can pick up where this one left off.
# Seek to the self.total_read offset so the next read can pick up where this one left off.
self
.
seek
(
self
.
tell
()
-
seek_offset
)
self
.
seek
(
self
.
tell
()
-
seek_offset
)
return
(
data
,
dlen
)
return
(
data
,
dlen
)
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