23.03.2013 Views

Quick introduction to reverse engineering for beginners

Quick introduction to reverse engineering for beginners

Quick introduction to reverse engineering for beginners

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

1.20 x86-64<br />

It’s a 64-bit extension <strong>to</strong> x86-architecture.<br />

From the <strong>reverse</strong> engineer’s perspective, most important differences are:<br />

∙ Almost all registers (except FPU and SIMD) are extended <strong>to</strong> 64 bits and got r- prefix. 8 additional<br />

registers added. Now general purpose registers are: rax, rbx, rcx, rdx, rbp, rsp, rsi, rdi, r8, r9,<br />

r10, r11, r12, r13, r14, r15.<br />

It’s still possible <strong>to</strong> access <strong>to</strong> older register parts as usual. For example, it’s possible <strong>to</strong> access lower<br />

32-bit part of RAX using EAX.<br />

New r8-r15 registers also has its lower parts: r8d-r15d (lower 32-bit parts), r8w-r15w (lower 16-bit<br />

parts), r8b-r15b (lower 8-bit parts).<br />

SIMD-registers number are doubled: from 8 <strong>to</strong> 16: XMM0-XMM15.<br />

∙ In Win64, function calling convention is slightly different, somewhat resembling fastcall 2.5.3. First 4<br />

arguments s<strong>to</strong>red in RCX, RDX, R8, R9 registers, others — in stack. Caller function should also allocate<br />

32 bytes so the callee may save there 4 first arguments and use these registers <strong>for</strong> own needs. Short<br />

functions may use arguments just from registers, but larger may save their values in<strong>to</strong> stack.<br />

See also section about calling conventions 2.5.<br />

∙ C int type is still 32-bit <strong>for</strong> compatibility.<br />

∙ All pointers are 64-bit now.<br />

Since now registers number are doubled, compilers has more space now <strong>for</strong> maneuvering calling register<br />

allocation 79 . What it meanings <strong>for</strong> us, emitted code will contain less local variables.<br />

For example, function calculating first S-box of DES encryption algorithm, it processing 32/64/128/256<br />

values at once (depending on DES_type type (uint32, uint64, SSE2 or AVX)) using bitslice DES method<br />

(read more about this method here 1.19):<br />

/*<br />

* Generated S-box files.<br />

*<br />

* This software may be modified, redistributed, and used <strong>for</strong> any purpose,<br />

* so long as its origin is acknowledged.<br />

*<br />

* Produced by Matthew Kwan - March 1998<br />

*/<br />

#ifdef _WIN64<br />

#define DES_type unsigned __int64<br />

#else<br />

#define DES_type unsigned int<br />

#endif<br />

void<br />

s1 (<br />

DES_type a1,<br />

DES_type a2,<br />

DES_type a3,<br />

DES_type a4,<br />

DES_type a5,<br />

DES_type a6,<br />

79 assigning variables <strong>to</strong> registers<br />

103

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!