iximeow / yaxpeax-x86

x86 decoders for the yaxpeax project
BSD Zero Clause License
129 stars 23 forks source link

Why register r12 and r13 has num 8 and 9 (long mode x64) #31

Closed tokatoka closed 9 months ago

tokatoka commented 9 months ago

Sorry if this is on purpose.

My question is why register r12 and r13 have the register number of 8 and 9 here? https://github.com/iximeow/yaxpeax-x86/blob/no-gods-no-/src/long_mode/mod.rs#L293

Shouldn't this part be

    register!(D,
        eax => 0, ecx => 1, edx => 2, ebx => 3,
        esp => 4, ebp => 5, esi => 6, edi => 7,
        r8d => 8, r9d => 9, r10d => 10, r11d => 11,
        r12d => 12, r13d => 13, r14d => 14, r15d => 15
    );

?

iximeow commented 9 months ago

oh that's a good catch. this is a bug. in all of those expansions (for Q, D, W, and rB), r12 and r13 should have register numbers 12 and 13. those macros expand out to const constructors like RegSpec::r12d(), so the consequence of this typo is that RegSpec::r12d will actually produce a RegSpec that prints as r8d.

the display impl, for example, uses that number directly: https://github.com/iximeow/yaxpeax-x86/blob/no-gods-no-/src/long_mode/display.rs#L110-L113

if you'd like to post a patch i'll merge it and do a release, or i can get to it later today

iximeow commented 9 months ago

oh i see https://github.com/tokatoka/yaxpeax-x86/commit/6016dc5e9d051771eea242e51412f874294cf491, i'll pull that, add some tests, and off we go

tokatoka commented 9 months ago

ok 👍

iximeow commented 9 months ago

ok! this and some other small issues i'd noticed along the way are now published as 1.2.2.