Fix ARM64 sign extension helper#380
Open
RatinCN wants to merge 1 commit into
Open
Conversation
detour_sign_extend should build the sign-extension mask from the source bit width, not from the amount used to shift the sign bit into position. Using 64 - bits places the mask at the wrong bit position and produces incorrect results for signed values whose sign bit is set. One affected path is ARM64 import thunk decoding, where negative ADRP page offsets can be decoded incorrectly.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #296. I fixed this in my SlimDetours commit fc42391, and now create this PR to Detours.
detour_sign_extendshould build the sign-extension mask from the source bit width, not from the amount used to shift the sign bit into position.Using 64 - bits places the mask at the wrong bit position and produces incorrect results for signed values whose sign bit is set. One affected path is ARM64 import thunk decoding, where negative
ADRPpage offsets can be decoded incorrectly.Using the example from #296, with
value = 0x0ffea2e4andbits = 28, the sign bit is set, so the value should be sign-extended.The current code uses
m1 << left, whereleft = 64 - bits = 36:This is incorrect because the mask starts at bit 36. It should start at the source width, bit 28:
Therefore the sign mask should use
m1 << bits.