Skip to content

Commit 9e69ca3

Browse files
kpenney-lblldoolitt
authored andcommitted
Fixed a bug interpreting register names as a literal address in hexadecimal when they happen to contain all hex characters.
1 parent 1e39b9e commit 9e69ca3

File tree

3 files changed

+37
-5
lines changed

3 files changed

+37
-5
lines changed

projects/common/leep/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,15 @@ PYTHON=python3
66

77
LEEP_CORE=base.py raw.py ca.py file.py logic.py
88

9-
all: test_cli
9+
all: test_cli test_raw
1010

1111
test_cli: $(LEEP_CORE) cli.py
1212
PYTHONPATH="$(THIS_DIR)/..:$(BUILD_DIR)" $(PYTHON) -m leep.test.test_cli test
1313

14+
.PHONY: test_raw
15+
test_raw: raw.py
16+
@PYTHONPATH="$(THIS_DIR)/.." $(PYTHON) -m leep.test.test_raw
17+
1418
# This is a test target currently only used for manual testing. Development is in progress
1519
# for including this in automated regression tests.
1620
server: $(LEEP_CORE) cli.py

projects/common/leep/raw.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,13 @@ def _int(s):
111111
return int(s)
112112
except ValueError:
113113
pass
114-
bases = (2, 16, 10)
115-
for base in bases:
114+
if hasattr(s, 'startswith'):
116115
try:
117-
return int(s, base)
118-
except (TypeError, ValueError):
116+
if s.startswith('0x'):
117+
return int(s, 16)
118+
elif s.startswith('0b'):
119+
return int(s, 2)
120+
except ValueError:
119121
pass
120122
return None
121123

projects/common/leep/test/test_raw.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,29 @@ def test_array(self):
189189
self.assertEqual(self.serv.data[101], 0xdeadbeef)
190190
self.assertEqual(self.serv.data[102], 0x12345679)
191191
self.assertEqual(self.serv.data[103], 0xdeadbeef)
192+
193+
194+
def test_raw_int():
195+
from leep.raw import _int
196+
tests = {
197+
"foo": None,
198+
"123": 123,
199+
"0x100": 0x100,
200+
"0b1000": 0b1000,
201+
"0xreg": None,
202+
"0bentry": None,
203+
}
204+
for key, val in tests.items():
205+
if val != _int(key):
206+
raise Exception("Test failed _int({}) = {} != {}".format(key, _int(key), val))
207+
return True
208+
209+
210+
def doTests():
211+
test_raw_int()
212+
print("PASS")
213+
return
214+
215+
216+
if __name__ == "__main__":
217+
doTests()

0 commit comments

Comments
 (0)