backengineering / bintests

A large collection of 32bit and 64bit PE files useful for verifying the correctness of bin2bin transformations
38 stars 2 forks source link

jump table binaries #9

Closed CR3Swapper closed 4 months ago

CR3Swapper commented 4 months ago

64bit msvc jump table https://godbolt.org/z/neMa17bPe

CR3Swapper commented 4 months ago

32bit msvc jump table https://godbolt.org/z/cz8EPsdvG

CR3Swapper commented 4 months ago

big indirect jmp table https://godbolt.org/z/5axrWcKdG (msvc 64bit)

CR3Swapper commented 4 months ago

big indirect jmp table https://godbolt.org/z/5MTzoE4h4 (msvc 32bit)

CR3Swapper commented 4 months ago

unbounded jump table https://godbolt.org/z/bdsor4YnG clang

CR3Swapper commented 4 months ago

unbounded jump table https://godbolt.org/z/aY5zaaPEf msvc using __assume(0);

CR3Swapper commented 4 months ago

Notes

Im going to dump some information about jump tables that ive observed from research.

There are 3 types of jump tables

llvm vs msvc

seems like llvm puts its jump tables outside of the text section by default. MSVC keep them inside of the text section and close to the function. I think msvc does this for performance reasons (cache locality?). Theres an option for msvc to put jump tables into the rdata section though (https://learn.microsoft.com/en-us/cpp/build/reference/jump-table-rdata?view=msvc-170).

LLVM generated jump tables seem to compute the destination address by taking the address of the jump table itself and then adding it to the entries inside of the table. This is different than msvc which uses image base LEA. Also i have yet to get LLVM code to generate multi level jump tables.

image

Rust compiler and its magic

The rust compiler does a lot of compile time analysis of the source code. When you write a match case in rust that satisfices all possible cases the compiler will attempt to create an unbounded jump table. Very cool but also creates an issue with determining the length of the table in a "safe" manner.

CR3Swapper commented 4 months ago

done, parsed all jtable varients that we care for.