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
75bc2e85
Commit
75bc2e85
authored
Dec 01, 2013
by
Dmitry Moiseev
Committed by
devttys0
Dec 01, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Addes {string-len} macros to calculate string length
parent
519e7d37
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
0 deletions
+24
-0
__init__.py
src/binwalk/__init__.py
+2
-0
smartsignature.py
src/binwalk/smartsignature.py
+22
-0
No files found.
src/binwalk/__init__.py
View file @
75bc2e85
...
...
@@ -550,6 +550,8 @@ class Binwalk(object):
i_set_results_offset
=
False
magic_result
=
self
.
smart
.
_parse_string_len
(
magic_result
)
# Some file names are not NULL byte terminated, but rather their length is
# specified in a size field. To ensure these are not marked as invalid due to
# non-printable characters existing in the file name, parse the filename(s) and
...
...
src/binwalk/smartsignature.py
View file @
75bc2e85
...
...
@@ -22,6 +22,7 @@ class SmartSignature:
'filename'
:
'
%
sfile-name:'
%
KEYWORD_DELIM_START
,
'filesize'
:
'
%
sfile-size:'
%
KEYWORD_DELIM_START
,
'raw-string'
:
'
%
sraw-string:'
%
KEYWORD_DELIM_START
,
# This one is special and must come last in a signature block
'string-len'
:
'
%
sstring-len:'
%
KEYWORD_DELIM_START
,
'raw-size'
:
'
%
sraw-string-length:'
%
KEYWORD_DELIM_START
,
'adjust'
:
'
%
soffset-adjust:'
%
KEYWORD_DELIM_START
,
'delay'
:
'
%
sextract-delay:'
%
KEYWORD_DELIM_START
,
...
...
@@ -240,6 +241,27 @@ class SmartSignature:
# marked as invalid when it shouldn't be.
data
=
data
[:
data
.
find
(
self
.
KEYWORDS
[
'raw-string'
])]
.
replace
(
self
.
KEYWORDS
[
'raw-replace'
],
'"'
+
raw_string
[:
str2int
(
raw_size
)]
+
'"'
)
return
data
def
_parse_string_len
(
self
,
data
):
'''
Process {string-len} macros.
@data - String to parse.
Returns strings length.
'''
if
not
self
.
ignore_smart_signatures
and
self
.
_is_valid
(
data
):
# Get the raw string keyword arg
raw_string
=
self
.
_get_keyword_arg
(
data
,
'string-len'
)
# Was a string-len keyword specified?
if
raw_string
:
# Is the raw string length arg is a numeric value?
# Replace all instances of string-len in data with supplied string lenth
# Also strip out everything after the string-len keyword, including the keyword itself.
data
=
re
.
sub
(
self
.
KEYWORDS
[
'string-len'
]
+
".+?
%
s"
%
self
.
KEYWORD_DELIM_END
,
str
(
len
(
raw_string
)),
data
)
return
data
def
_strip_tags
(
self
,
data
):
'''
...
...
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