kohlrak

main.cpp (GTx0 32bit x86 sample)

Oct 12th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.98 KB | None | 0 0
  1. //NOTE: This code is meant to be compiled on a 32bit x86 machine. I don't have a 64bit machine available to do this for that arch at the moment.
  2.  
  3. #include <stdio.h>
  4.  
  5. extern "C" int asm_data;
  6. extern "C" int asm_func(int x); //_Z7cppfunci, _Z is a prefix to tell us how it's mangled, 7 is the length of the function name, i means 1 int param
  7. extern "C" int asm_caller(int x, int y); //_Z7cppfuncii, which translates to how you predict it to.
  8.  
  9. int cppfunc(int x){ return x << 2; } //Same as asm_func(), so we won't use it.
  10. int cppfunc(int x, int y){ return x << y; } //We're not actually going to use this one.
  11.  
  12. int main(int argc, char** argv){
  13.         int input1 = 6, input2 = 1;
  14.         printf("asm_func(%i) returns %i\n", input1, asm_func(input1));
  15.         printf("asm_caller(%i, %i) return %i\n", input1, input2, asm_caller(input1, input2));
  16.         printf("asm_data = 0x%x\n", asm_data); //No mangling for global data, so it's just as easy the other direction.
  17.         return 0;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment