Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've been having some frustrating hours of woes with the
sym_resolver
- mainly it forcing a radix change and symbol offsets to be calculated correctly.This is mostly based on suggestions from other issues and a cherry-picked commit from another PR. I've added a few more examples to
bindings/python/sample.py
to illustrate it seemingly behaving correctly now. I've also added regression tests for anything mentioned below. All the examples in that file now also run for me again - on master they appear broken. Details below.1. Invalid symbol offsets
Issues: #244 #271 #351
Given a symbol table:
On current master with base
0x1000
:Assembles to
eb ff 90
. That offset is incorrect and looks like it's calculated from the start of the instruction rather than the end of it, missing the offset for it.The suggestion from #351 fixes that and symbol offsets now appear to be calculated correctly. With the suggested change the instructions correctly assemble to
eb fe 90
.I've fixed the Python sym_resolver examples. The
x64_sym_resolver.py
regression test, too, which also passes.2. Radix set from default (10) to 16 when setting sym_resolver
Issues: #481 #436 #538
Cherry-picked 5c7ed87 from #528
Another issue is present in the setting of
ks_option
:This currently forces a radix of 16 every time any
ks_option
call is made. So when a symbol resolver is set without explicitly setting a radix of 16, one still ends up with a radix of 16.This change for this was made for #382 to address https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=10437 but unless ks_option is called at least once, the issue still remains.
This is now also now covered by a new regression test.
In #382 was also a short discussion if the default should be
16
or10
and it was set to16
. This also appears to be incorrect because the actual default in keystone unless explicitly changed is a radix of 10, which is also NASM's default.Notes
I hope we can get this (or a similar fix) merged a new version released. I'm happy to write additional regression tests or make any necessary needed. My current project has some code for incremental multi-pass assembling on top of keystone where I handle the symbol table myself and this is currently blocking my work :(