NationalSecurityAgency / ghidra

Ghidra is a software reverse engineering (SRE) framework
https://www.nsa.gov/ghidra
Apache License 2.0
49.09k stars 5.65k forks source link

x86: PUSH FS/GS long mode improvements. #6602

Open Sleigh-InSPECtor opened 1 month ago

Sleigh-InSPECtor commented 1 month ago

In long-mode, PUSH instructions default to a 64-bit operand size, and the manual states: "If the source operand is a segment register (16 bits) and the operand size is 64-bits, a zero-extended value is pushed on the stack". Currently the SLEIGH spec adjusts RSP correctly but performs a 16-bit store leaving the upper bits unmodified.

Additionally, for segment register pushes the address size prefix should be ignored, but the operand override prefix needs to be accounted for.

This PR changes the pushseg88 macro to zero extend the input operand (the same macro is used in the CALLF which should also the upper 48-bits), and also fixes prefix handling.

(Note: The 32-bit variants use addrsize to choose whether to use the segment pcodeop, which is technically incorrect, see: #6601, but not included in this PR.)