-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Ignore ES/CS/SS/DS segment overrides in x64 mode #2819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jxors
wants to merge
10
commits into
capstone-engine:next
Choose a base branch
from
jxors:fix-x64-ecsd-segment-override
base: next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+345
−12
Open
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b22f4ea
Ignore ES/CS/SS/DS segment overrides in x64 mode
0cf6d87
Add tests for x86 segment override prefixes
187d104
Only update prefix1 if needed
e84be54
Also check prefix details in tests
1e8c11b
Fix formatting
251208d
Update release notes
2eec5a8
Refactor segment override handling into separate function
2451c4b
Make sure function name matches documentation
e658f7a
Rename function so it passes clang-format and doesn't need to be spli…
36fe2f1
Run clang-format again
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,293 @@ | ||
| test_cases: | ||
| # Test segment override priority | ||
| - | ||
| input: | ||
| name: "x86-16: rightmost segment override should take priority" | ||
| bytes: [ 0x26, 0x65, 0x64, 0x3E, 0x65, 0x2E, 0x00, 0x00 ] | ||
| arch: "CS_ARCH_X86" | ||
| options: [ CS_OPT_DETAIL, CS_MODE_16 ] | ||
| expected: | ||
| insns: | ||
| - | ||
| asm_text: "add byte ptr cs:[bx + si], al" | ||
| details: | ||
| x86: | ||
| prefix: [ X86_PREFIX_0, X86_PREFIX_CS, X86_PREFIX_0, X86_PREFIX_0 ] | ||
| - | ||
| input: | ||
| name: "x86-32: rightmost segment override should take priority" | ||
| bytes: [ 0x26, 0x65, 0x64, 0x3E, 0x65, 0x2E, 0x00, 0x00 ] | ||
| arch: "CS_ARCH_X86" | ||
| options: [ CS_OPT_DETAIL, CS_MODE_32 ] | ||
| expected: | ||
| insns: | ||
| - | ||
| asm_text: "add byte ptr cs:[eax], al" | ||
| details: | ||
| x86: | ||
| prefix: [ X86_PREFIX_0, X86_PREFIX_CS, X86_PREFIX_0, X86_PREFIX_0 ] | ||
| - | ||
| input: | ||
| name: "x86-64: rightmost segment override should take priority" | ||
| bytes: [ 0x26, 0x65, 0x64, 0x3E, 0x65, 0x2E, 0x00, 0x00 ] | ||
| arch: "CS_ARCH_X86" | ||
| options: [ CS_OPT_DETAIL, CS_MODE_64 ] | ||
| expected: | ||
| insns: | ||
| - | ||
| asm_text: "add byte ptr gs:[rax], al" | ||
| details: | ||
| x86: | ||
| prefix: [ X86_PREFIX_0, X86_PREFIX_GS, X86_PREFIX_0, X86_PREFIX_0 ] | ||
| - | ||
| input: | ||
| name: "x86-16: rightmost segment override should take priority" | ||
| bytes: [ 0x3E, 0x3E, 0x26, 0x36, 0x64, 0x36, 0x00, 0x00 ] | ||
| arch: "CS_ARCH_X86" | ||
| options: [ CS_OPT_DETAIL, CS_MODE_16 ] | ||
| expected: | ||
| insns: | ||
| - | ||
| asm_text: "add byte ptr ss:[bx + si], al" | ||
| details: | ||
| x86: | ||
| prefix: [ X86_PREFIX_0, X86_PREFIX_SS, X86_PREFIX_0, X86_PREFIX_0 ] | ||
| - | ||
| input: | ||
| name: "x86-32: rightmost segment override should take priority" | ||
| bytes: [ 0x3E, 0x3E, 0x26, 0x36, 0x64, 0x36, 0x00, 0x00 ] | ||
| arch: "CS_ARCH_X86" | ||
| options: [ CS_OPT_DETAIL, CS_MODE_32 ] | ||
| expected: | ||
| insns: | ||
| - | ||
| asm_text: "add byte ptr ss:[eax], al" | ||
| details: | ||
| x86: | ||
| prefix: [ X86_PREFIX_0, X86_PREFIX_SS, X86_PREFIX_0, X86_PREFIX_0 ] | ||
| - | ||
| input: | ||
| name: "x86-64: rightmost segment override should take priority" | ||
| bytes: [ 0x3E, 0x3E, 0x26, 0x36, 0x64, 0x36, 0x00, 0x00 ] | ||
| arch: "CS_ARCH_X86" | ||
| options: [ CS_OPT_DETAIL, CS_MODE_64 ] | ||
| expected: | ||
| insns: | ||
| - | ||
| asm_text: "add byte ptr fs:[rax], al" | ||
| details: | ||
| x86: | ||
| prefix: [ X86_PREFIX_0, X86_PREFIX_FS, X86_PREFIX_0, X86_PREFIX_0 ] | ||
| # Test segment override differences between 16/32 and 64-bit mode with ECDS and FS/GS | ||
| - | ||
| input: | ||
| name: "x86-16: ECSD segment overrides should override FS/GS segment overrides" | ||
| bytes: [ 0x64, 0x3E, 0x00, 0x00 ] | ||
| arch: "CS_ARCH_X86" | ||
| options: [ CS_OPT_DETAIL, CS_MODE_16 ] | ||
| expected: | ||
| insns: | ||
| - | ||
| asm_text: "add byte ptr ds:[bx + si], al" | ||
| details: | ||
| x86: | ||
| prefix: [ X86_PREFIX_0, X86_PREFIX_DS, X86_PREFIX_0, X86_PREFIX_0 ] | ||
| - | ||
| input: | ||
| name: "x86-32: ECSD segment overrides should override FS/GS segment overrides" | ||
| bytes: [ 0x64, 0x3E, 0x00, 0x00 ] | ||
| arch: "CS_ARCH_X86" | ||
| options: [ CS_OPT_DETAIL, CS_MODE_32 ] | ||
| expected: | ||
| insns: | ||
| - | ||
| asm_text: "add byte ptr ds:[eax], al" | ||
| details: | ||
| x86: | ||
| prefix: [ X86_PREFIX_0, X86_PREFIX_DS, X86_PREFIX_0, X86_PREFIX_0 ] | ||
| - | ||
| input: | ||
| name: "x86-64: ECSD segment overrides should be ignored and leave FS override intact" | ||
| bytes: [ 0x64, 0x3E, 0x00, 0x00 ] | ||
| arch: "CS_ARCH_X86" | ||
| options: [ CS_OPT_DETAIL, CS_MODE_64 ] | ||
| expected: | ||
| insns: | ||
| - | ||
| asm_text: "add byte ptr fs:[rax], al" | ||
| details: | ||
| x86: | ||
| prefix: [ X86_PREFIX_0, X86_PREFIX_FS, X86_PREFIX_0, X86_PREFIX_0 ] | ||
| - | ||
| input: | ||
| name: "x86-64: ECSD segment overrides should be ignored" | ||
| bytes: [ 0x3E, 0x00, 0x00 ] | ||
| arch: "CS_ARCH_X86" | ||
| options: [ CS_OPT_DETAIL, CS_MODE_64 ] | ||
| expected: | ||
| insns: | ||
| - | ||
| asm_text: "add byte ptr [rax], al" | ||
| details: | ||
| x86: | ||
| prefix: [ X86_PREFIX_0, X86_PREFIX_DS, X86_PREFIX_0, X86_PREFIX_0 ] | ||
| # Test duplicate segment override prefixes | ||
| - | ||
| input: | ||
| name: "x86-16: Duplicate ES override prefixes should decode successfully" | ||
| bytes: [ 0x26, 0x26, 0x00, 0x00 ] | ||
| arch: "CS_ARCH_X86" | ||
| options: [ CS_OPT_DETAIL, CS_MODE_16 ] | ||
| expected: | ||
| insns: | ||
| - | ||
| asm_text: "add byte ptr es:[bx + si], al" | ||
| details: | ||
| x86: | ||
| prefix: [ X86_PREFIX_0, X86_PREFIX_ES, X86_PREFIX_0, X86_PREFIX_0 ] | ||
| - | ||
| input: | ||
| name: "x86-32: Duplicate ES override prefixes should decode successfully" | ||
| bytes: [ 0x26, 0x26, 0x00, 0x00 ] | ||
| arch: "CS_ARCH_X86" | ||
| options: [ CS_OPT_DETAIL, CS_MODE_32 ] | ||
| expected: | ||
| insns: | ||
| - | ||
| asm_text: "add byte ptr es:[eax], al" | ||
| details: | ||
| x86: | ||
| prefix: [ X86_PREFIX_0, X86_PREFIX_ES, X86_PREFIX_0, X86_PREFIX_0 ] | ||
| - | ||
| input: | ||
| name: "x86-64: Duplicate FS override prefixes should decode successfully" | ||
| bytes: [ 0x64, 0x64, 0x00, 0x00 ] | ||
| arch: "CS_ARCH_X86" | ||
| options: [ CS_OPT_DETAIL, CS_MODE_64 ] | ||
| expected: | ||
| insns: | ||
| - | ||
| asm_text: "add byte ptr fs:[rax], al" | ||
| details: | ||
| x86: | ||
| prefix: [ X86_PREFIX_0, X86_PREFIX_FS, X86_PREFIX_0, X86_PREFIX_0 ] | ||
| # Test invalid REX prefix | ||
| - | ||
| input: | ||
| name: "x86-64: Invalid REX prefix should preserve previous segment override" | ||
| bytes: [ 0x64, 0x40, 0x2E, 0x00, 0x00 ] | ||
| arch: "CS_ARCH_X86" | ||
| options: [ CS_OPT_DETAIL, CS_MODE_64 ] | ||
| expected: | ||
| insns: | ||
| - | ||
| asm_text: "add byte ptr fs:[rax], al" | ||
| details: | ||
| x86: | ||
| prefix: [ X86_PREFIX_0, X86_PREFIX_FS, X86_PREFIX_0, X86_PREFIX_0 ] | ||
| - | ||
| input: | ||
| name: "x86-64: Invalid REX prefix should not add ECDS segment override" | ||
| bytes: [ 0x2E, 0x40, 0x2E, 0x00, 0x00 ] | ||
| arch: "CS_ARCH_X86" | ||
| options: [ CS_OPT_DETAIL, CS_MODE_64 ] | ||
| expected: | ||
| insns: | ||
| - | ||
| asm_text: "add byte ptr [rax], al" | ||
| details: | ||
| x86: | ||
| prefix: [ X86_PREFIX_0, X86_PREFIX_CS, X86_PREFIX_0, X86_PREFIX_0 ] | ||
| # Test whether `notrack` is correctly decoded | ||
| - | ||
| input: | ||
| name: "x86-16: notrack should decode correctly" | ||
| bytes: [ 0x3E, 0xE8, 0x00, 0x00 ] | ||
| arch: "CS_ARCH_X86" | ||
| options: [ CS_OPT_DETAIL, CS_MODE_16 ] | ||
| expected: | ||
| insns: | ||
| - | ||
| asm_text: "notrack call 4" | ||
| details: | ||
| x86: | ||
| prefix: [ X86_PREFIX_0, X86_PREFIX_DS, X86_PREFIX_0, X86_PREFIX_0 ] | ||
| - | ||
| input: | ||
| name: "x86-32: notrack should decode correctly" | ||
| bytes: [ 0x3E, 0xE8, 0x00, 0x00, 0x00, 0x00 ] | ||
| arch: "CS_ARCH_X86" | ||
| options: [ CS_OPT_DETAIL, CS_MODE_32 ] | ||
| expected: | ||
| insns: | ||
| - | ||
| asm_text: "notrack call 6" | ||
| details: | ||
| x86: | ||
| prefix: [ X86_PREFIX_0, X86_PREFIX_DS, X86_PREFIX_0, X86_PREFIX_0 ] | ||
| - | ||
| input: | ||
| name: "x86-64: notrack should decode correctly" | ||
| bytes: [ 0x3E, 0xE8, 0x00, 0x00, 0x00, 0x00 ] | ||
| arch: "CS_ARCH_X86" | ||
| options: [ CS_OPT_DETAIL, CS_MODE_64 ] | ||
| expected: | ||
| insns: | ||
| - | ||
| asm_text: "notrack call 6" | ||
| details: | ||
| x86: | ||
| prefix: [ X86_PREFIX_0, X86_PREFIX_DS, X86_PREFIX_0, X86_PREFIX_0 ] | ||
|
|
||
| - | ||
| input: | ||
| name: "x86-16: notrack should be applied when 0x3E is last segment override prefix" | ||
| bytes: [ 0x26, 0x64, 0x3E, 0xE8, 0x00, 0x00 ] | ||
| arch: "CS_ARCH_X86" | ||
| options: [ CS_OPT_DETAIL, CS_MODE_16 ] | ||
| expected: | ||
| insns: | ||
| - | ||
| asm_text: "notrack call 6" | ||
| details: | ||
| x86: | ||
| prefix: [ X86_PREFIX_0, X86_PREFIX_DS, X86_PREFIX_0, X86_PREFIX_0 ] | ||
| - | ||
| input: | ||
| name: "x86-32: notrack should be applied when 0x3E is last segment override prefix" | ||
| bytes: [ 0x26, 0x64, 0x3E, 0xE8, 0x00, 0x00, 0x00, 0x00 ] | ||
| arch: "CS_ARCH_X86" | ||
| options: [ CS_OPT_DETAIL, CS_MODE_32 ] | ||
| expected: | ||
| insns: | ||
| - | ||
| asm_text: "notrack call 8" | ||
| details: | ||
| x86: | ||
| prefix: [ X86_PREFIX_0, X86_PREFIX_DS, X86_PREFIX_0, X86_PREFIX_0 ] | ||
| - | ||
| input: | ||
| name: "x86-64: workaround: notrack should only be applied when 0x3E is last segment override prefix and no FS/GS segment override prefix is active" | ||
| bytes: [ 0x26, 0x64, 0x3E, 0xE8, 0x00, 0x00, 0x00, 0x00 ] | ||
| arch: "CS_ARCH_X86" | ||
| options: [ CS_OPT_DETAIL, CS_MODE_64 ] | ||
| expected: | ||
| insns: | ||
| - | ||
| asm_text: "call 8" | ||
| details: | ||
| x86: | ||
| prefix: [ X86_PREFIX_0, X86_PREFIX_FS, X86_PREFIX_0, X86_PREFIX_0 ] | ||
| - | ||
| input: | ||
| name: "x86-64: workaround: notrack should only be applied when 0x3E is last segment override prefix and no FS/GS segment override prefix is active" | ||
| bytes: [ 0x26, 0x2E, 0x3E, 0xE8, 0x00, 0x00, 0x00, 0x00 ] | ||
| arch: "CS_ARCH_X86" | ||
| options: [ CS_OPT_DETAIL, CS_MODE_64 ] | ||
| expected: | ||
| insns: | ||
| - | ||
| asm_text: "notrack call 8" | ||
| details: | ||
| x86: | ||
| prefix: [ X86_PREFIX_0, X86_PREFIX_DS, X86_PREFIX_0, X86_PREFIX_0 ] |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.