-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
3 changed files
with
81 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/python | ||
|
||
# Test BL <symbol> instruction with KS_OPT_SYM_RESOLVER for ARM32 | ||
|
||
# Github issue: #355 | ||
# Author: jan2642 | ||
|
||
from keystone import * | ||
|
||
import regress | ||
|
||
class TestARM(regress.RegressTest): | ||
def runTest(self): | ||
def sym_resolver(symbol, value): | ||
if symbol == "symBackward": | ||
value[0] = 0x0 | ||
return True | ||
|
||
if symbol == "symForward": | ||
value[0] = 0x20 | ||
return True | ||
|
||
return False | ||
|
||
# Initialize Keystone engine | ||
ks = Ks(KS_ARCH_ARM, KS_MODE_ARM) | ||
ks.sym_resolver = sym_resolver | ||
|
||
encoding, _ = ks.asm(b""" | ||
sub r0, r0, r0 | ||
sub r1, r1, r1 | ||
bl symBackward | ||
""") | ||
self.assertEqual(encoding[-4:], [ 0xfc, 0xff, 0xff, 0xeb ]) | ||
|
||
encoding, _ = ks.asm(b"bl symForward") | ||
self.assertEqual(encoding, [ 0x06, 0x00, 0x00, 0xeb ]) | ||
|
||
if __name__ == '__main__': | ||
regress.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/python | ||
|
||
# Test BL <symbol> instruction with KS_OPT_SYM_RESOLVER for THUMB | ||
|
||
# Github issue: #355 | ||
# Author: jan2642 | ||
|
||
from keystone import * | ||
|
||
import regress | ||
|
||
class TestARM(regress.RegressTest): | ||
def runTest(self): | ||
def sym_resolver(symbol, value): | ||
if symbol == "symBackward": | ||
value[0] = 0x0 | ||
return True | ||
|
||
if symbol == "symForward": | ||
value[0] = 0x20 | ||
return True | ||
|
||
return False | ||
|
||
# Initialize Keystone engine | ||
ks = Ks(KS_ARCH_ARM, KS_MODE_THUMB) | ||
ks.sym_resolver = sym_resolver | ||
|
||
encoding, _ = ks.asm(b""" | ||
sub r0, r0, r0 | ||
sub r0, r0, r0 | ||
bl symBackward | ||
""") | ||
self.assertEqual(encoding[-4:], [ 0xff, 0xf7, 0xfa, 0xff ]) | ||
|
||
encoding, _ = ks.asm(b"bl symForward") | ||
self.assertEqual(encoding, [ 0x00, 0xf0, 0x0e, 0xf8 ]) | ||
|
||
if __name__ == '__main__': | ||
regress.main() |