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
1ed3752f
Commit
1ed3752f
authored
Dec 21, 2013
by
devttys0
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed useless str2int function.
parent
65ea6d1d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
25 deletions
+8
-25
common.py
src/binwalk/core/common.py
+0
-16
parser.py
src/binwalk/core/parser.py
+2
-3
smart.py
src/binwalk/core/smart.py
+6
-6
No files found.
src/binwalk/core/common.py
View file @
1ed3752f
...
...
@@ -48,22 +48,6 @@ def file_size(filename):
finally
:
os
.
close
(
fd
)
def
str2int
(
string
):
'''
Attempts to convert string to a base 10 integer; if that fails, then base 16.
@string - String to convert to an integer.
Returns the integer value on success.
Throws an exception if the string cannot be converted into either a base 10 or base 16 integer value.
'''
try
:
return
int
(
string
)
except
KeyboardInterrupt
as
e
:
raise
e
except
Exception
:
return
int
(
string
,
16
)
def
strip_quoted_strings
(
string
):
'''
Strips out data in between double quotes.
...
...
src/binwalk/core/parser.py
View file @
1ed3752f
...
...
@@ -3,7 +3,6 @@ import re
import
os.path
import
tempfile
from
binwalk.core.compat
import
*
from
binwalk.core.common
import
str2int
class
MagicParser
:
'''
...
...
@@ -223,7 +222,7 @@ class MagicParser:
# We've already verified that the first character in this line is a number, so this *shouldn't*
# throw an exception, but let's catch it just in case...
try
:
entry
[
'offset'
]
=
str2int
(
entry
[
'offset'
]
)
entry
[
'offset'
]
=
int
(
entry
[
'offset'
],
0
)
except
KeyboardInterrupt
as
e
:
raise
e
except
Exception
as
e
:
...
...
@@ -245,7 +244,7 @@ class MagicParser:
# for more advanced conditions for the first line of a signature,
# but needing that is rare.
try
:
intval
=
str2int
(
entry
[
'condition'
]
.
strip
(
'L'
)
)
intval
=
int
(
entry
[
'condition'
]
.
strip
(
'L'
),
0
)
except
KeyboardInterrupt
as
e
:
raise
e
except
Exception
as
e
:
...
...
src/binwalk/core/smart.py
View file @
1ed3752f
import
re
import
binwalk.core.module
from
binwalk.core.compat
import
*
from
binwalk.core.common
import
str2int
,
get_quoted_strings
,
MathExpression
from
binwalk.core.common
import
get_quoted_strings
,
MathExpression
class
SmartSignature
:
'''
...
...
@@ -93,21 +93,21 @@ class SmartSignature:
# when extraction is enabled. If not specified, everything to the end of the file will be
# extracted (see Binwalk.scan).
try
:
results
[
'size'
]
=
str2int
(
self
.
_get_math_arg
(
data
,
'filesize'
)
)
results
[
'size'
]
=
int
(
self
.
_get_math_arg
(
data
,
'filesize'
),
0
)
except
KeyboardInterrupt
as
e
:
raise
e
except
Exception
:
pass
try
:
results
[
'year'
]
=
str2int
(
self
.
_get_keyword_arg
(
data
,
'year'
)
)
results
[
'year'
]
=
int
(
self
.
_get_keyword_arg
(
data
,
'year'
),
0
)
except
KeyboardInterrupt
as
e
:
raise
e
except
Exception
:
pass
try
:
results
[
'epoch'
]
=
str2int
(
self
.
_get_keyword_arg
(
data
,
'epoch'
)
)
results
[
'epoch'
]
=
int
(
self
.
_get_keyword_arg
(
data
,
'epoch'
),
0
)
except
KeyboardInterrupt
as
e
:
raise
e
except
Exception
:
...
...
@@ -233,7 +233,7 @@ class SmartSignature:
offset_str
=
self
.
_get_keyword_arg
(
data
,
'jump'
)
if
offset_str
:
try
:
offset
=
str2int
(
offset_str
)
offset
=
int
(
offset_str
,
0
)
except
KeyboardInterrupt
as
e
:
raise
e
except
Exception
:
...
...
@@ -281,7 +281,7 @@ class SmartSignature:
# Also strip out everything after the raw-string keyword, including the keyword itself.
# Failure to do so may (will) result in non-printable characters and this string will be
# 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
)]
+
'"'
)
data
=
data
[:
data
.
find
(
self
.
KEYWORDS
[
'raw-string'
])]
.
replace
(
self
.
KEYWORDS
[
'raw-replace'
],
'"'
+
raw_string
[:
int
(
raw_size
,
0
)]
+
'"'
)
return
data
def
_parse_string_len
(
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