daily pastebin goal
41%
SHARE
TWEET

Untitled

dorin98 Jan 11th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* This file has been generated by the Hex-Rays decompiler.
  2.    Copyright (c) 2007-2017 Hex-Rays <info@hex-rays.com>
  3.  
  4.    Detected compiler: GNU C++
  5. */
  6.  
  7. #include <stdio.h>
  8.  
  9.  
  10. //-------------------------------------------------------------------------
  11. // Function declarations
  12.  
  13. int  syscall_wrapper(int a1);
  14. int do_exit();
  15. int do_write();
  16. int do_read();
  17. int do_open();
  18. int do_close();
  19. int read_from_file();
  20. int  print_string(int a1);
  21. int  print_line(int a1);
  22. signed int  parse_opt(int a1);
  23. int parse_args();
  24. int do_simple_echo();
  25. int do_run();
  26. int  mystery1(char *a1);
  27. signed int  mystery2(char *a1, char a2);
  28. signed int  streq(char *a1, char *a2, int a3);
  29. char * mystery4(char *a1, char *a2, int a3);
  30. _Bool mystery5(char a1);
  31. char * mystery6(char *a1);
  32. int  mystery7(char *a1);
  33. signed int  mystery8(int a1, int a2, unsigned int a3);
  34. unsigned int  mystery9(int a1, int a2, unsigned int a3, char *a4);
  35.  
  36. //-------------------------------------------------------------------------
  37. // Data declarations
  38.  
  39. char unk_80488D8; // weak
  40. char unk_80488DB; // weak
  41. char unk_80488DE; // weak
  42. char unk_80488E1; // weak
  43. int edata; // weak
  44. int wat2; // weak
  45. char g_wat3; // weak
  46. char g_wat4; // weak
  47. char g_wat5; // weak
  48. int g_wat6; // weak
  49. int g_wat7; // weak
  50. int g_wat8; // weak
  51.  
  52.  
  53. //----- (08048100) --------------------------------------------------------
  54. int  syscall_wrapper(int a1)
  55. {
  56.   int result; // eax
  57.  
  58.   result = a1;
  59.   __asm ("int $0x80");
  60.   return result;
  61. }
  62.  
  63. //----- (0804812C) --------------------------------------------------------
  64. int do_exit()
  65. {
  66.   return syscall_wrapper(1);
  67. }
  68.  
  69. //----- (08048144) --------------------------------------------------------
  70. int do_write()
  71. {
  72.   return syscall_wrapper(4);
  73. }
  74.  
  75. //----- (0804815E) --------------------------------------------------------
  76. int do_read()
  77. {
  78.   return syscall_wrapper(3);
  79. }
  80.  
  81. //----- (08048178) --------------------------------------------------------
  82. int do_open()
  83. {
  84.   return syscall_wrapper(5);
  85. }
  86.  
  87. //----- (08048192) --------------------------------------------------------
  88. int do_close()
  89. {
  90.   return syscall_wrapper(6);
  91. }
  92.  
  93. //----- (080481AA) --------------------------------------------------------
  94. int read_from_file()
  95. {
  96.   int v0; // ST18_4
  97.  
  98.   if ( do_open() < 0 )
  99.     do_exit();
  100.   v0 = do_read();
  101.   do_close();
  102.   return v0;
  103. }
  104.  
  105. //----- (080481FE) --------------------------------------------------------
  106. int  print_string(int a1)
  107. {
  108.   mystery1((char *)a1);
  109.   return do_write();
  110. }
  111.  
  112. //----- (0804822C) --------------------------------------------------------
  113. int  print_line(int a1)
  114. {
  115.   int result; // eax
  116.  
  117.   if ( mystery2((char *)a1, 10) == -2 )
  118.     result = print_string(a1);
  119.   else
  120.     result = do_write();
  121.   return result;
  122. }
  123.  
  124. //----- (0804827C) --------------------------------------------------------
  125. signed int  parse_opt(int a1)
  126. {
  127.   if ( mystery1((char *)a1) != 2 )
  128.     do_exit();
  129.   if ( !streq((char *)a1, &unk_80488D8, 2) ) // -f
  130.     return 8;
  131.   if ( !streq((char *)a1, &unk_80488DB, 2) ) // -s
  132.     return 2;
  133.   if ( !streq((char *)a1, &unk_80488DE, 2) ) // -e
  134.     return 4;
  135.   if ( streq((char *)a1, &unk_80488E1, 2) )  // -i
  136.     return -2;
  137.   return 1;
  138. }
  139.  
  140. //----- (08048329) --------------------------------------------------------
  141. int parse_args()
  142. {
  143.   int result; // eax
  144.   signed int v1; // [esp+0h] [ebp-18h]
  145.   signed int v2; // [esp+0h] [ebp-18h]
  146.   int v3; // [esp+0h] [ebp-18h]
  147.   int v4; // [esp+0h] [ebp-18h]
  148.   signed int v5; // [esp+4h] [ebp-14h]
  149.   int v6; // [esp+8h] [ebp-10h]
  150.   unsigned int i; // [esp+Ch] [ebp-Ch]
  151.  
  152.   v6 = 0;
  153.   for ( i = 1; i < edata; ++i )
  154.   {
  155.     if ( **(char **)(4 * i + wat2) == 45 )
  156.     {
  157.       v5 = parse_opt(*(int *)(4 * i + wat2));
  158.       if ( v5 == -2 ) // -i
  159.         do_exit();
  160.       if ( v6 & v5 )
  161.         do_exit();
  162.       v6 |= v5;
  163.       if ( v5 == 2 ) // -s
  164.       {
  165.         v3 = mystery7(*(char **)(4 * (i + 1) + wat2));
  166.         if ( v3 == -1 )
  167.           do_exit();
  168.         g_wat7 = v3;
  169.       }
  170.       else if ( v5 > 2 )
  171.       {
  172.         if ( v5 == 4 ) // -e
  173.         {
  174.           v4 = mystery7(*(char **)(4 * (i + 1) + wat2));
  175.           if ( v4 == -1 )
  176.             do_exit();
  177.           g_wat8 = v4;
  178.         }
  179.         else if ( v5 == 8 ) // -f
  180.         {
  181.           v2 = mystery1(*(char **)(4 * (i + 1) + wat2));
  182.           if ( v2 > 31 )
  183.             do_exit();
  184.           mystery4(&g_wat4, *(char **)(4 * (i + 1) + wat2), v2);
  185.         }
  186.       }
  187.       else if ( v5 == 1 )
  188.       {
  189.         v1 = mystery1(*(char **)(4 * (i + 1) + wat2));
  190.         if ( v1 > 31 )
  191.           do_exit();
  192.         mystery4(&g_wat3, *(char **)(4 * (i + 1) + wat2), v1);
  193.       }
  194.       ++i;
  195.     }
  196.   }
  197.   result = v6;
  198.   g_wat6 = v6;
  199.   return result;
  200. }
  201. // 804A000: using guessed type int edata;
  202. // 804A004: using guessed type int wat2;
  203. // EDBA060: using guessed type int g_wat6;
  204. // EDBA064: using guessed type int g_wat7;
  205. // EDBA068: using guessed type int g_wat8;
  206.  
  207. //----- (08048546) --------------------------------------------------------
  208. int do_simple_echo()
  209. {
  210.   unsigned int v0; // eax
  211.   int v2[8]; // [esp+Ch] [ebp-24h]
  212.   int v3; // [esp+2Ch] [ebp-4h]
  213.  
  214.   v0 = 0;
  215.   do
  216.   {
  217.     v2[v0] = 0;
  218.     ++v0;
  219.   }
  220.   while ( v0 < 8 );
  221.   v3 = 0;
  222.   v3 = do_read();
  223.   return do_write();
  224. }
  225. // 8048546: using guessed type int var_24[8];
  226.  
  227. //----- (08048598) --------------------------------------------------------
  228. int do_run()
  229. {
  230.   int result; // eax
  231.   int v1; // [esp+Ch] [ebp-Ch]
  232.  
  233.   if ( g_wat6 & 1 )
  234.     v1 = read_from_file();
  235.   else
  236.     v1 = do_read();
  237.   *(char *)(v1 + 134520928) = 0;
  238.   if ( !(g_wat6 & 2) )
  239.     g_wat7 = 0;
  240.   if ( !(g_wat6 & 4) )
  241.     g_wat8 = v1;
  242.   result = g_wat6 & 8;
  243.   if ( g_wat6 & 8 )
  244.     result = mystery9((int)&g_wat5, g_wat7, g_wat8, &g_wat4);
  245.   return result;
  246. }
  247. // EDBA060: using guessed type int g_wat6;
  248. // EDBA064: using guessed type int g_wat7;
  249. // EDBA068: using guessed type int g_wat8;
  250.  
  251. //----- (08048652) --------------------------------------------------------
  252. int main(int a1)
  253. {
  254.   void *retaddr; // [esp+Ch] [ebp+4h]
  255.  
  256.   edata = (int)retaddr;
  257.   wat2 = (int)&a1;
  258.   if ( retaddr == (void *)1 )
  259.   {
  260.     do_simple_echo();
  261.   }
  262.   else
  263.   {
  264.     parse_args();
  265.     do_run();
  266.   }
  267.   return do_exit();
  268. }
  269. // 804A000: using guessed type int edata;
  270. // 804A004: using guessed type int wat2;
  271.  
  272. //----- (080486A0) --------------------------------------------------------
  273. int  mystery1(char *a1)
  274. {
  275.   char *v1; // edi
  276.   int result; // eax
  277.   int v3; // ebx
  278.  
  279.   v1 = a1;
  280.   result = 0;
  281.   v3 = 0;
  282.   while ( 1 )
  283.   {
  284.     v3 = *v1;
  285.     if ( !v3 )
  286.       break;
  287.     ++result;
  288.     ++v1;
  289.   }
  290.   return result;
  291. }
  292.  
  293. //----- (080486B8) --------------------------------------------------------
  294. signed int  mystery2(char *a1, char a2)
  295. {
  296.   int v2; // ecx
  297.   signed int result; // eax
  298.   char *i; // edi
  299.  
  300.   v2 = mystery1(a1);
  301.   result = 0;
  302.   for ( i = a1; *i != a2; ++i )
  303.     ++result;
  304.   if ( !v2 )
  305.     result = -1;
  306.   return result;
  307. }
  308.  
  309. //----- (080486E7) --------------------------------------------------------
  310. signed int  streq(char *a1, char *a2, int a3)
  311. {
  312.   char *v3; // ebx
  313.   char *v4; // edx
  314.   int v5; // ecx
  315.  
  316.   v3 = a1;
  317.   v4 = a2;
  318.   v5 = a3;
  319.   while ( *v3 == *v4 )
  320.   {
  321.     ++v3;
  322.     ++v4;
  323.     if ( !--v5 )
  324.       return 0;
  325.   }
  326.   return 1;
  327. }
  328.  
  329. //----- (0804870A) --------------------------------------------------------
  330. char * mystery4(char *a1, char *a2, int a3)
  331. {
  332.   char *result; // eax
  333.   char *v4; // ebx
  334.   int v5; // ecx
  335.  
  336.   result = a1;
  337.   v4 = a2;
  338.   v5 = a3;
  339.   do
  340.   {
  341.     *result++ = *v4++;
  342.     --v5;
  343.   }
  344.   while ( v5 );
  345.   return result;
  346. }
  347.  
  348. //----- (08048722) --------------------------------------------------------
  349. _Bool mystery5(char a1)
  350. {
  351.   return a1 >= 48 && a1 <= 57;
  352. }
  353.  
  354. //----- (0804873E) --------------------------------------------------------
  355. char * mystery6(char *a1)
  356. {
  357.   int v1; // eax
  358.   int v2; // ecx
  359.   void *v3; // esp
  360.   char *v4; // ebx
  361.   int savedregs; // [esp+0h] [ebp+0h]
  362.  
  363.   v1 = mystery1(a1);
  364.   v2 = v1;
  365.   v3 = alloca(v1);
  366.   v4 = (char *)&savedregs - v1;
  367.   do
  368.     *v4++ = a1[v2-- - 1];
  369.   while ( v2 );
  370.   return mystery4(a1, (char *)&savedregs - v1, v1);
  371. }
  372.  
  373. //----- (08048772) --------------------------------------------------------
  374. int  mystery7(char *a1)
  375. {
  376.   int v1; // ST0C_4
  377.   int v2; // ecx
  378.   int v3; // ebx
  379.   int v4; // ecx
  380.   int result; // eax
  381.   int v6; // [esp+0h] [ebp-4h]
  382.  
  383.   v6 = 0;
  384.   v1 = mystery1(a1);
  385.   mystery6(a1);
  386.   v2 = v1;
  387.   v3 = 0;
  388.   while ( 1 )
  389.   {
  390.     v3 = a1[v2 - 1];
  391.     if ( !mystery5(v3) )
  392.       break;
  393.     v3 = v3 - 48;
  394.     result = v3 + 10 * v6;
  395.     v6 = v3 + 10 * v6;
  396.     v2 = v4 - 1;
  397.     if ( !v2 )
  398.       return result;
  399.   }
  400.   return -1;
  401. }
  402.  
  403. //----- (080487DD) --------------------------------------------------------
  404. signed int  mystery8(int a1, int a2, unsigned int a3)
  405. {
  406.   unsigned int v4; // [esp+8h] [ebp-8h]
  407.   int v5; // [esp+Ch] [ebp-4h]
  408.  
  409.   v5 = 0;
  410.   v4 = 0;
  411.   while ( v4 < a3 && *(char *)(a1 + v5) != 10 && *(char *)(a1 + v5) )
  412.   {
  413.     if ( *(char *)(a1 + v5) == *(char *)(a2 + v4) )
  414.       ++v4;
  415.     else
  416.       v4 = 0;
  417.     if ( v4 == a3 )
  418.       return 1;
  419.     ++v5;
  420.   }
  421.   return 0;
  422. }
  423.  
  424. //----- (08048856) --------------------------------------------------------
  425. unsigned int  mystery9(int a1, int a2, unsigned int a3, char *a4)
  426. {
  427.   unsigned int result; // eax
  428.   int length; // [esp+4h] [ebp-14h]
  429.   int v6; // [esp+8h] [ebp-10h]
  430.   unsigned int i; // [esp+Ch] [ebp-Ch]
  431.  
  432.   v6 = a2;
  433.   length = mystery1(a4);
  434.   for ( i = a2; ; ++i )
  435.   {
  436.     result = i;
  437.     if ( i >= a3 )
  438.       break;
  439.     if ( *(char *)(a1 + i) == 10 )
  440.     {
  441.       if ( mystery8(a1 + v6, (int)a4, length) != 0 )
  442.         print_line(a1 + v6);
  443.       v6 = i + 1;
  444.     }
  445.   }
  446.   return result;
  447. }
  448.  
  449. // ALL OK, 23 function(s) have been successfully decompiled
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top