icedland / iced

Blazing fast and correct x86/x64 disassembler, assembler, decoder, encoder for Rust, .NET, Java, Python, Lua
MIT License
2.79k stars 230 forks source link

Disassembler: Add option to get register offsets #576

Open Symbai opened 2 weeks ago

Symbai commented 2 weeks ago

For displacement and immediate we can get the offsets. For used registers we currently cannot. I'd like to request the possibility to retrieve the offsets for registers too (C#).

In my scenario I have an array of bytes where some registers are wildcarded. I need to know which register(s) was wildcarded from this array to deal with it later on.

namespace Iced.Intel {

    public readonly struct UsedRegister {

        public Register Register;
        public OpAccess Access;
++      public byte Offset;

    }
}
wtfsck commented 2 weeks ago

Register bits can be in multiple bytes, eg. one bit could be in the REX prefix and 3 other bits in the modrm byte, or the bits could be in different bytes in the VEX/EVEX/etc prefix. So there's no single byte offset that could be returned.

Symbai commented 2 weeks ago

And when the instruction has no prefix? I can change the proposed property to nullable byte so that it only returns the offset if its possible and null when its not, like in the cases you mentioned.

Edit: Here is an example of an instruction where a register is wildcarded: 48 8B ?? 30 => mov rsi,[r??+30]