Good To Know

Preprocessing tricks:

// Leak file
#include "/etc/passwd"
// variable without type (only work in global)
a;
s="hello";
int main(void) {
printf("%d:%s", a, s);
return 0;
}

Create char & strings

#include "stdio.h"
// Macros for creating strings
#define STR(x) #x
#define CAT(a, b) a##b
#define HELLO_CAT "he" "llo"
int main(void) {
// 1. Concatenation of string literals
char s[] = "h""e""l""l""o";
Every string assignation can be used by a char table like : {..., ..., ..., ..., ...}
puts(s);
// 2. Character table
char p[] = {'h', 'e', 'l', 'l', 'o'};
puts(p);
// 3. Octal escape sequences
char octal[] = "\150\145\154\154\157";
puts(octal);
// 4. Hexadecimal escape sequences
char hex[] = "\x68\x65\x6C\x6C\x6F";
puts(hex);
-
! Depends of the compilor !
+
// 5. Universal character names
+
char unicode[] = "\u0068\u0065\u006C\u006C\u006F";
+
puts(unicode);
// 9. Using macros with stringify
char macro_str[] = STR(hello);
puts(macro_str);
// 10. Using macros with concatenation
char macro_cat[] = HELLO_CAT;
puts(macro_cat);
return 0;
}

Create int

#include <stdio.h>
int main() {
const int h = (((__STDC__)*(__STDC__+__STDC__)+(__STDC__+__STDC__)+(__STDC__+__STDC__)*(__STDC__+__STDC__)+(__STDC__+__STDC__)+(__STDC__+__STDC__)) + (__STDC__)) * ((__STDC__+__STDC__)+(__STDC__+__STDC__)) * (__STDC__+__STDC__);
const int e = (__CHAR_BIT__ +__LITTLE_ENDIAN__+ __LITTLE_ENDIAN__)*(__SIZEOF_POINTER__+__STDC_HOSTED__+__STDC_HOSTED__) + __STDC_HOSTED__;
const int l = (__SCHAR_MAX__)-(((__BOOL_WIDTH__+__FLT16_MAX_10_EXP__))-(__STDC_UTF_16__-__SIZEOF_PTRDIFF_T__));
const int o = (__INT_FAST64_WIDTH__*__GCC_ATOMIC_WCHAR_T_LOCK_FREE)-(__SHRT_WIDTH__+__FLT16_HAS_INFINITY__);
printf("%s\n", (char []){h, e, l, l, o, 0});
}