fork(16) download
  1. #include <stdio.h>
  2. #include <stdint.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5.  
  6. #if defined(__GNUC__)
  7. typedef long long ll;
  8. typedef unsigned long long ull;
  9. #define __int64 long long
  10. #define __int32 int
  11. #define __int16 short
  12. #define __int8 char
  13. #define MAKELL(num) num ## LL
  14. #define FMT_64 "ll"
  15. #elif defined(_MSC_VER)
  16. typedef __int64 ll;
  17. typedef unsigned __int64 ull;
  18. #define MAKELL(num) num ## i64
  19. #define FMT_64 "I64"
  20. #elif defined (__BORLANDC__)
  21. typedef __int64 ll;
  22. typedef unsigned __int64 ull;
  23. #define MAKELL(num) num ## i64
  24. #define FMT_64 "L"
  25. #else
  26. #error "unknown compiler"
  27. #endif
  28. typedef unsigned int uint;
  29. typedef unsigned char uchar;
  30. typedef unsigned short ushort;
  31. typedef unsigned long ulong;
  32.  
  33. typedef char int8;
  34. typedef signed char sint8;
  35. typedef unsigned char uint8;
  36. typedef short int16;
  37. typedef signed short sint16;
  38. typedef unsigned short uint16;
  39. typedef int int32;
  40. typedef signed int sint32;
  41. typedef unsigned int uint32;
  42. typedef ll int64;
  43. typedef ll sint64;
  44. typedef ull uint64;
  45.  
  46. // Partially defined types. They are used when the decompiler does not know
  47. // anything about the type except its size.
  48. #define _BYTE uint8
  49. #define _WORD uint16
  50. #define _DWORD uint32
  51. #define _QWORD uint64
  52. #if !defined(_MSC_VER)
  53. #define _LONGLONG __int128
  54. #endif
  55.  
  56. // Non-standard boolean types. They are used when the decompiler can not use
  57. // the standard "bool" type because of the size mistmatch but the possible
  58. // values are only 0 and 1. See also 'BOOL' type below.
  59. typedef int8 _BOOL1;
  60. typedef int16 _BOOL2;
  61. typedef int32 _BOOL4;
  62.  
  63. #ifndef _WINDOWS_
  64. typedef int8 BYTE;
  65. typedef int16 WORD;
  66. typedef int32 DWORD;
  67. typedef int32 LONG;
  68. typedef int BOOL; // uppercase BOOL is usually 4 bytes
  69. #endif
  70. typedef int64 QWORD;
  71. #ifndef __cplusplus
  72. typedef int bool; // we want to use bool in our C programs
  73. #endif
  74.  
  75. #define __pure // pure function: always returns the same value, has no
  76. // side effects
  77.  
  78. // Non-returning function
  79. #if defined(__GNUC__)
  80. #define __noreturn __attribute__((noreturn))
  81. #else
  82. #define __noreturn __declspec(noreturn)
  83. #endif
  84.  
  85.  
  86. #ifndef NULL
  87. #define NULL 0
  88. #endif
  89.  
  90. // Some convenience macros to make partial accesses nicer
  91. // first unsigned macros:
  92. #define LOBYTE(x) (*((_BYTE*)&(x))) // low byte
  93. #define LOWORD(x) (*((_WORD*)&(x))) // low word
  94. #define LODWORD(x) (*((_DWORD*)&(x))) // low dword
  95. #define HIBYTE(x) (*((_BYTE*)&(x)+1))
  96. #define HIWORD(x) (*((_WORD*)&(x)+1))
  97. #define HIDWORD(x) (*((_DWORD*)&(x)+1))
  98. #define BYTEn(x, n) (*((_BYTE*)&(x)+n))
  99. #define WORDn(x, n) (*((_WORD*)&(x)+n))
  100. #define BYTE1(x) BYTEn(x, 1) // byte 1 (counting from 0)
  101. #define BYTE2(x) BYTEn(x, 2)
  102. #define BYTE3(x) BYTEn(x, 3)
  103. #define BYTE4(x) BYTEn(x, 4)
  104. #define BYTE5(x) BYTEn(x, 5)
  105. #define BYTE6(x) BYTEn(x, 6)
  106. #define BYTE7(x) BYTEn(x, 7)
  107. #define BYTE8(x) BYTEn(x, 8)
  108. #define BYTE9(x) BYTEn(x, 9)
  109. #define BYTE10(x) BYTEn(x, 10)
  110. #define BYTE11(x) BYTEn(x, 11)
  111. #define BYTE12(x) BYTEn(x, 12)
  112. #define BYTE13(x) BYTEn(x, 13)
  113. #define BYTE14(x) BYTEn(x, 14)
  114. #define BYTE15(x) BYTEn(x, 15)
  115. #define WORD1(x) WORDn(x, 1)
  116. #define WORD2(x) WORDn(x, 2) // third word of the object, unsigned
  117. #define WORD3(x) WORDn(x, 3)
  118. #define WORD4(x) WORDn(x, 4)
  119. #define WORD5(x) WORDn(x, 5)
  120. #define WORD6(x) WORDn(x, 6)
  121. #define WORD7(x) WORDn(x, 7)
  122.  
  123. // now signed macros (the same but with sign extension)
  124. #define SLOBYTE(x) (*((int8*)&(x)))
  125. #define SLOWORD(x) (*((int16*)&(x)))
  126. #define SLODWORD(x) (*((int32*)&(x)))
  127. #define SHIBYTE(x) (*((int8*)&(x)+1))
  128. #define SHIWORD(x) (*((int16*)&(x)+1))
  129. #define SHIDWORD(x) (*((int32*)&(x)+1))
  130. #define SBYTEn(x, n) (*((int8*)&(x)+n))
  131. #define SWORDn(x, n) (*((int16*)&(x)+n))
  132. #define SBYTE1(x) SBYTEn(x, 1)
  133. #define SBYTE2(x) SBYTEn(x, 2)
  134. #define SBYTE3(x) SBYTEn(x, 3)
  135. #define SBYTE4(x) SBYTEn(x, 4)
  136. #define SBYTE5(x) SBYTEn(x, 5)
  137. #define SBYTE6(x) SBYTEn(x, 6)
  138. #define SBYTE7(x) SBYTEn(x, 7)
  139. #define SBYTE8(x) SBYTEn(x, 8)
  140. #define SBYTE9(x) SBYTEn(x, 9)
  141. #define SBYTE10(x) SBYTEn(x, 10)
  142. #define SBYTE11(x) SBYTEn(x, 11)
  143. #define SBYTE12(x) SBYTEn(x, 12)
  144. #define SBYTE13(x) SBYTEn(x, 13)
  145. #define SBYTE14(x) SBYTEn(x, 14)
  146. #define SBYTE15(x) SBYTEn(x, 15)
  147. #define SWORD1(x) SWORDn(x, 1)
  148. #define SWORD2(x) SWORDn(x, 2)
  149. #define SWORD3(x) SWORDn(x, 3)
  150. #define SWORD4(x) SWORDn(x, 4)
  151. #define SWORD5(x) SWORDn(x, 5)
  152. #define SWORD6(x) SWORDn(x, 6)
  153. #define SWORD7(x) SWORDn(x, 7)
  154.  
  155.  
  156. // Helper functions to represent some assembly instructions.
  157.  
  158. #ifdef __cplusplus
  159.  
  160. // compile time assertion
  161. #define __CASSERT_N0__(l) COMPILE_TIME_ASSERT_ ## l
  162. #define __CASSERT_N1__(l) __CASSERT_N0__(l)
  163. #define CASSERT(cnd) typedef char __CASSERT_N1__(__LINE__) [(cnd) ? 1 : -1]
  164.  
  165. // check that unsigned multiplication does not overflow
  166. template<class T> bool is_mul_ok(T count, T elsize)
  167. {
  168. CASSERT((T)(-1) > 0); // make sure T is unsigned
  169. if ( elsize == 0 || count == 0 )
  170. return true;
  171. return count <= ((T)(-1)) / elsize;
  172. }
  173.  
  174. // multiplication that saturates (yields the biggest value) instead of overflowing
  175. // such a construct is useful in "operator new[]"
  176. template<class T> bool saturated_mul(T count, T elsize)
  177. {
  178. return is_mul_ok(count, elsize) ? count * elsize : T(-1);
  179. }
  180.  
  181. #include <stddef.h> // for size_t
  182.  
  183. // memcpy() with determined behavoir: it always copies
  184. // from the start to the end of the buffer
  185. // note: it copies byte by byte, so it is not equivalent to, for example, rep movsd
  186. inline void *qmemcpy(void *dst, const void *src, size_t cnt)
  187. {
  188. char *out = (char *)dst;
  189. const char *in = (const char *)src;
  190. while ( cnt > 0 )
  191. {
  192. *out++ = *in++;
  193. --cnt;
  194. }
  195. return dst;
  196. }
  197.  
  198. // Generate a reference to pair of operands
  199. template<class T> int16 __PAIR__( int8 high, T low) { return ((( int16)high) << sizeof(high)*8) | uint8(low); }
  200. template<class T> int32 __PAIR__( int16 high, T low) { return ((( int32)high) << sizeof(high)*8) | uint16(low); }
  201. template<class T> int64 __PAIR__( int32 high, T low) { return ((( int64)high) << sizeof(high)*8) | uint32(low); }
  202. template<class T> uint16 __PAIR__(uint8 high, T low) { return (((uint16)high) << sizeof(high)*8) | uint8(low); }
  203. template<class T> uint32 __PAIR__(uint16 high, T low) { return (((uint32)high) << sizeof(high)*8) | uint16(low); }
  204. template<class T> uint64 __PAIR__(uint32 high, T low) { return (((uint64)high) << sizeof(high)*8) | uint32(low); }
  205.  
  206. // rotate left
  207. template<class T> T __ROL__(T value, int count)
  208. {
  209. const uint nbits = sizeof(T) * 8;
  210.  
  211. if ( count > 0 )
  212. {
  213. count %= nbits;
  214. T high = value >> (nbits - count);
  215. if ( T(-1) < 0 ) // signed value
  216. high &= ~((T(-1) << count));
  217. value <<= count;
  218. value |= high;
  219. }
  220. else
  221. {
  222. count = -count % nbits;
  223. T low = value << (nbits - count);
  224. value >>= count;
  225. value |= low;
  226. }
  227. return value;
  228. }
  229.  
  230. inline uint8 __ROL1__(uint8 value, int count) { return __ROL__((uint8)value, count); }
  231. inline uint16 __ROL2__(uint16 value, int count) { return __ROL__((uint16)value, count); }
  232. inline uint32 __ROL4__(uint32 value, int count) { return __ROL__((uint32)value, count); }
  233. inline uint64 __ROL8__(uint64 value, int count) { return __ROL__((uint64)value, count); }
  234. inline uint8 __ROR1__(uint8 value, int count) { return __ROL__((uint8)value, -count); }
  235. inline uint16 __ROR2__(uint16 value, int count) { return __ROL__((uint16)value, -count); }
  236. inline uint32 __ROR4__(uint32 value, int count) { return __ROL__((uint32)value, -count); }
  237. inline uint64 __ROR8__(uint64 value, int count) { return __ROL__((uint64)value, -count); }
  238.  
  239. // carry flag of left shift
  240. template<class T> int8 __MKCSHL__(T value, uint count)
  241. {
  242. const uint nbits = sizeof(T) * 8;
  243. count %= nbits;
  244.  
  245. return (value >> (nbits-count)) & 1;
  246. }
  247.  
  248. // carry flag of right shift
  249. template<class T> int8 __MKCSHR__(T value, uint count)
  250. {
  251. return (value >> (count-1)) & 1;
  252. }
  253.  
  254. // sign flag
  255. template<class T> int8 __SETS__(T x)
  256. {
  257. if ( sizeof(T) == 1 )
  258. return int8(x) < 0;
  259. if ( sizeof(T) == 2 )
  260. return int16(x) < 0;
  261. if ( sizeof(T) == 4 )
  262. return int32(x) < 0;
  263. return int64(x) < 0;
  264. }
  265.  
  266. // overflow flag of subtraction (x-y)
  267. template<class T, class U> int8 __OFSUB__(T x, U y)
  268. {
  269. if ( sizeof(T) < sizeof(U) )
  270. {
  271. U x2 = x;
  272. int8 sx = __SETS__(x2);
  273. return (sx ^ __SETS__(y)) & (sx ^ __SETS__(x2-y));
  274. }
  275. else
  276. {
  277. T y2 = y;
  278. int8 sx = __SETS__(x);
  279. return (sx ^ __SETS__(y2)) & (sx ^ __SETS__(x-y2));
  280. }
  281. }
  282.  
  283. // overflow flag of addition (x+y)
  284. template<class T, class U> int8 __OFADD__(T x, U y)
  285. {
  286. if ( sizeof(T) < sizeof(U) )
  287. {
  288. U x2 = x;
  289. int8 sx = __SETS__(x2);
  290. return ((1 ^ sx) ^ __SETS__(y)) & (sx ^ __SETS__(x2+y));
  291. }
  292. else
  293. {
  294. T y2 = y;
  295. int8 sx = __SETS__(x);
  296. return ((1 ^ sx) ^ __SETS__(y2)) & (sx ^ __SETS__(x+y2));
  297. }
  298. }
  299.  
  300. // carry flag of subtraction (x-y)
  301. template<class T, class U> int8 __CFSUB__(T x, U y)
  302. {
  303. int size = sizeof(T) > sizeof(U) ? sizeof(T) : sizeof(U);
  304. if ( size == 1 )
  305. return uint8(x) < uint8(y);
  306. if ( size == 2 )
  307. return uint16(x) < uint16(y);
  308. if ( size == 4 )
  309. return uint32(x) < uint32(y);
  310. return uint64(x) < uint64(y);
  311. }
  312.  
  313. // carry flag of addition (x+y)
  314. template<class T, class U> int8 __CFADD__(T x, U y)
  315. {
  316. int size = sizeof(T) > sizeof(U) ? sizeof(T) : sizeof(U);
  317. if ( size == 1 )
  318. return uint8(x) > uint8(x+y);
  319. if ( size == 2 )
  320. return uint16(x) > uint16(x+y);
  321. if ( size == 4 )
  322. return uint32(x) > uint32(x+y);
  323. return uint64(x) > uint64(x+y);
  324. }
  325.  
  326. #else
  327. // The following definition is not quite correct because it always returns
  328. // uint64. The above C++ functions are good, though.
  329. #define __PAIR__(high, low) (((uint64)(high)<<sizeof(high)*8) | low)
  330. // For C, we just provide macros, they are not quite correct.
  331. #define __ROL__(x, y) __rotl__(x, y) // Rotate left
  332. #define __ROR__(x, y) __rotr__(x, y) // Rotate right
  333. #define __CFSHL__(x, y) invalid_operation // Generate carry flag for (x<<y)
  334. #define __CFSHR__(x, y) invalid_operation // Generate carry flag for (x>>y)
  335. #define __CFADD__(x, y) invalid_operation // Generate carry flag for (x+y)
  336. #define __CFSUB__(x, y) invalid_operation // Generate carry flag for (x-y)
  337. #define __OFADD__(x, y) invalid_operation // Generate overflow flag for (x+y)
  338. #define __OFSUB__(x, y) invalid_operation // Generate overflow flag for (x-y)
  339. #endif
  340.  
  341. // No definition for rcl/rcr because the carry flag is unknown
  342. #define __RCL__(x, y) invalid_operation // Rotate left thru carry
  343. #define __RCR__(x, y) invalid_operation // Rotate right thru carry
  344. #define __MKCRCL__(x, y) invalid_operation // Generate carry flag for a RCL
  345. #define __MKCRCR__(x, y) invalid_operation // Generate carry flag for a RCR
  346. #define __SETP__(x, y) invalid_operation // Generate parity flag for (x-y)
  347.  
  348. // In the decompilation listing there are some objects declarared as _UNKNOWN
  349. // because we could not determine their types. Since the C compiler does not
  350. // accept void item declarations, we replace them by anything of our choice,
  351. // for example a char:
  352.  
  353. #define _UNKNOWN char
  354.  
  355. #ifdef _MSC_VER
  356. #define snprintf _snprintf
  357. #define vsnprintf _vsnprintf
  358. #endif
  359.  
  360. int v1; // eax@2
  361. int v2; // eax@5
  362. char *v3; // rax@8
  363. uint64_t v4; // kr08_8@8
  364. int64_t v5; // rax@8
  365. char *v6; // rax@8
  366. size_t v7; // rax@8
  367. char v9; // [sp+10h] [bp-4E0h]@1
  368. int16_t v10; // [sp+40h] [bp-4B0h]@1
  369. char v11; // [sp+42h] [bp-4AEh]@1
  370. char dest; // [sp+50h] [bp-4A0h]@1
  371. int v13; // [sp+B0h] [bp-440h]@1
  372. char haystack[256]; // [sp+C0h] [bp-430h]@1
  373. char s[256]; // [sp+1C0h] [bp-330h]@8
  374. int64_t v16; // [sp+1C8h] [bp-328h]@8
  375. int64_t v17; // [sp+1D0h] [bp-320h]@8
  376. int64_t v18; // [sp+1D8h] [bp-318h]@8
  377. int64_t v19; // [sp+1E0h] [bp-310h]@8
  378. signed int v20; // [sp+1E8h] [bp-308h]@8
  379. char v21[520]; // [sp+2C0h] [bp-230h]@8
  380. int64_t v22; // [sp+4C8h] [bp-28h]@8
  381. int64_t v23; // [sp+4D0h] [bp-20h]@1
  382. char *src; // [sp+4D8h] [bp-18h]@8
  383. int64_t v25; // [sp+4E0h] [bp-10h]@8
  384. int fd; // [sp+4E8h] [bp-8h]@1
  385. int v27; // [sp+4ECh] [bp-4h]@1
  386.  
  387. int main(void)
  388. {
  389. memset(v21, 0, 0x200uLL);
  390. memset(s, 0, sizeof(s));
  391. *(_QWORD *)s = 8241904481816087053LL;
  392. v16 = 7233174018652708965LL;
  393. v17 = 7234302070389219449LL;
  394. v18 = 8462080219387160864LL;
  395. v19 = 7575168241365295218LL;
  396. v20 = 2112115;
  397. sub_400D46(v21, 512LL, s);
  398. v4 = strlen(v21) + 1;
  399. v3 = &v21[v4 - 1];
  400. *(_QWORD *)v3 = 7597125269444455526LL;
  401. v3[8] = 0;
  402. LODWORD(v5) = g_key_file_new(&v21[v4]);
  403. v25 = v5;
  404. v22 = 0LL;
  405. g_key_file_load_from_file(v5, v21, 0LL, 0LL);
  406. LODWORD(v6) = g_key_file_get_string(v25, "Sharif", "Flag", &v22);
  407. src = v6;
  408. strcat(s, v6);
  409. *(_WORD *)&s[strlen(s)] = 10;
  410. v7 = strlen(s);
  411. return 0;
  412. }
  413.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c: In function 'main':
prog.c:391:5: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     *(_QWORD *)s = 8241904481816087053LL;
     ^
prog.c:397:5: warning: implicit declaration of function 'sub_400D46' [-Wimplicit-function-declaration]
     sub_400D46(v21, 512LL, s);
     ^
prog.c:402:5: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     LODWORD(v5) = g_key_file_new(&v21[v4]);
     ^
prog.c:402:19: warning: implicit declaration of function 'g_key_file_new' [-Wimplicit-function-declaration]
     LODWORD(v5) = g_key_file_new(&v21[v4]);
                   ^
prog.c:405:5: warning: implicit declaration of function 'g_key_file_load_from_file' [-Wimplicit-function-declaration]
     g_key_file_load_from_file(v5, v21, 0LL, 0LL);
     ^
prog.c:406:5: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     LODWORD(v6) = g_key_file_get_string(v25, "Sharif", "Flag", &v22);
     ^
prog.c:406:19: warning: implicit declaration of function 'g_key_file_get_string' [-Wimplicit-function-declaration]
     LODWORD(v6) = g_key_file_get_string(v25, "Sharif", "Flag", &v22);
                   ^
prog.c:409:5: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     *(_WORD *)&s[strlen(s)] = 10;
     ^
/home/je8kjp/cc8wxVFh.o: In function `main':
prog.c:(.text.startup+0xdd): undefined reference to `sub_400D46'
prog.c:(.text.startup+0x123): undefined reference to `g_key_file_new'
prog.c:(.text.startup+0x169): undefined reference to `g_key_file_load_from_file'
prog.c:(.text.startup+0x18c): undefined reference to `g_key_file_get_string'
collect2: error: ld returned 1 exit status
stdout
Standard output is empty