Commit 1ed3752f by devttys0

Removed useless str2int function.

parent 65ea6d1d
...@@ -48,22 +48,6 @@ def file_size(filename): ...@@ -48,22 +48,6 @@ def file_size(filename):
finally: finally:
os.close(fd) 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): def strip_quoted_strings(string):
''' '''
Strips out data in between double quotes. Strips out data in between double quotes.
......
...@@ -3,7 +3,6 @@ import re ...@@ -3,7 +3,6 @@ import re
import os.path import os.path
import tempfile import tempfile
from binwalk.core.compat import * from binwalk.core.compat import *
from binwalk.core.common import str2int
class MagicParser: class MagicParser:
''' '''
...@@ -223,7 +222,7 @@ 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* # 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... # throw an exception, but let's catch it just in case...
try: try:
entry['offset'] = str2int(entry['offset']) entry['offset'] = int(entry['offset'], 0)
except KeyboardInterrupt as e: except KeyboardInterrupt as e:
raise e raise e
except Exception as e: except Exception as e:
...@@ -245,7 +244,7 @@ class MagicParser: ...@@ -245,7 +244,7 @@ class MagicParser:
# for more advanced conditions for the first line of a signature, # for more advanced conditions for the first line of a signature,
# but needing that is rare. # but needing that is rare.
try: try:
intval = str2int(entry['condition'].strip('L')) intval = int(entry['condition'].strip('L'), 0)
except KeyboardInterrupt as e: except KeyboardInterrupt as e:
raise e raise e
except Exception as e: except Exception as e:
......
import re import re
import binwalk.core.module import binwalk.core.module
from binwalk.core.compat import * 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: class SmartSignature:
''' '''
...@@ -93,21 +93,21 @@ class SmartSignature: ...@@ -93,21 +93,21 @@ class SmartSignature:
# when extraction is enabled. If not specified, everything to the end of the file will be # when extraction is enabled. If not specified, everything to the end of the file will be
# extracted (see Binwalk.scan). # extracted (see Binwalk.scan).
try: try:
results['size'] = str2int(self._get_math_arg(data, 'filesize')) results['size'] = int(self._get_math_arg(data, 'filesize'), 0)
except KeyboardInterrupt as e: except KeyboardInterrupt as e:
raise e raise e
except Exception: except Exception:
pass pass
try: try:
results['year'] = str2int(self._get_keyword_arg(data, 'year')) results['year'] = int(self._get_keyword_arg(data, 'year'), 0)
except KeyboardInterrupt as e: except KeyboardInterrupt as e:
raise e raise e
except Exception: except Exception:
pass pass
try: try:
results['epoch'] = str2int(self._get_keyword_arg(data, 'epoch')) results['epoch'] = int(self._get_keyword_arg(data, 'epoch'), 0)
except KeyboardInterrupt as e: except KeyboardInterrupt as e:
raise e raise e
except Exception: except Exception:
...@@ -233,7 +233,7 @@ class SmartSignature: ...@@ -233,7 +233,7 @@ class SmartSignature:
offset_str = self._get_keyword_arg(data, 'jump') offset_str = self._get_keyword_arg(data, 'jump')
if offset_str: if offset_str:
try: try:
offset = str2int(offset_str) offset = int(offset_str, 0)
except KeyboardInterrupt as e: except KeyboardInterrupt as e:
raise e raise e
except Exception: except Exception:
...@@ -281,7 +281,7 @@ class SmartSignature: ...@@ -281,7 +281,7 @@ class SmartSignature:
# Also strip out everything after the raw-string keyword, including the keyword itself. # 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 # Failure to do so may (will) result in non-printable characters and this string will be
# marked as invalid when it shouldn't 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 return data
def _parse_string_len(self, data): def _parse_string_len(self, data):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment