Skip to content

Latest commit

 

History

History
59 lines (44 loc) · 1.47 KB

C.md

File metadata and controls

59 lines (44 loc) · 1.47 KB

C

Werror overwrite make CFLAGS=-Wno-error

Include path (print) gcc -xc -E -v - gcc -xc++ -E -v -

Macro

  • #define dbgprint(X,...) printf(X, ##__VA_ARGS__) : variadic argument macro

  • # operator is called the stringifier

  • __declspec(dllexport) # windows : export function in dll

  • __debugbreak() # Set breakpoint

  • offsetof(struct_t, elt_t) # Get elemenet offset

  • extern int const iPi = 3.1415926535

    • extern so importing this.h get iPi defined
    • const for the precompiler (to avoid errors)
  • #pragma pack(1) # to let the structure without aligning each field

  • __FILE__ # Name of the file.c

  • __LINE__ # Current line

  • __FUNCTION__ # Name of current function

  • Jump to arbitrary addr void (*foo)(void) = 0xcacacaca; foo();

Notes

  • Le tableau aloue de la mémoire et le pointeur non => préféré le tableau

Random

#include <time.h>
srand(time(NULL)); 	# Set seed
rand();				# Get Random

Calling conventions, function prototype

  • typedef int(__cdecl callback_t)(HANDLE h_process);

Usercall

int __usercall fct1@<eax>(int p1@<ecx>, int p2@<edx>, int p3) {return p1 + p2 + p3;}

Stdcall

The called function is cleaning the stack

Cdecl

The caller is correcting the stack (because HE knows : printf)

Fastcall (x64)

Rcx contains first var. The callee is cleaning the pile