Saturday, January 20, 2024

Reversing Some C++ Io Operations

In general decompilers are not friendly with c++ let's analyse a simple program to get familiar with it.
Let's implement a simple code that loads a file into a vector and then save the vector with following functions:

  • err
  • load
  • save
  • main


Lets identify the typical way in C++ to print to stdout with the operator "<<"


The basic_ostream is initialized writing the word "error" to the cout, and then the operator<< again to add the endl.




The Main function simply calls  "vec = load(filename)"  but the compiler modified it and passed the vector pointer as a parĂ¡meter. Then it bulds and prints "loaded  " << size << " users".
And finally saves the vector to /tmp/pwd and print "saved".
Most of the mess is basically the operator "<<" to concat and print values.
Also note that the vectors and strings are automatically deallocated when exit the function.


And here is the code:


Let's take a look to the load function, which iterates the ifs.getline() and push to the vector.
First of all there is a mess on the function definition, __return_storage_ptr is the vector.
the ifstream object ifs is initialized as a basic_ifstream and then operator! checks if it wasn't possible to open the file and in that case calls err()
We see the memset and a loop, getline read a cstr like line from the file, and then is converted to a string before pushing it to the vector. lVar1 is the stack canary value.

In this situations dont obfuscate with the vector pointer vec initialization at the begining, in this case the logic is quite clear.



The function save is a bit more tricky, but it's no more than a vector iteration and ofs writing.
Looping a simple "for (auto s : *vec)" in the decompiler is quite dense, but we can see clearly two write, the second write DAT_0010400b is a "\n"



As we see, save implememtation is quite straightforward.




More information


  1. Hacking Tools
  2. How To Make Hacking Tools
  3. Termux Hacking Tools 2019
  4. Growth Hacker Tools
  5. Hacking Tools Hardware
  6. Install Pentest Tools Ubuntu
  7. Hacks And Tools
  8. Pentest Recon Tools
  9. Pentest Tools Kali Linux
  10. New Hack Tools
  11. Hacker Tools Mac
  12. New Hack Tools
  13. Pentest Tools Bluekeep
  14. Hacker Tools Apk
  15. Hack Tools
  16. Hack Rom Tools
  17. Pentest Tools Url Fuzzer
  18. Hackrf Tools
  19. Pentest Tools Find Subdomains
  20. Kik Hack Tools
  21. Pentest Tools Find Subdomains
  22. Hackers Toolbox
  23. Best Pentesting Tools 2018
  24. Hacker Search Tools
  25. Hacking Tools Windows
  26. Hacking Tools Free Download
  27. Pentest Tools For Mac
  28. New Hacker Tools
  29. Hacking Tools Software
  30. Nsa Hack Tools
  31. Best Pentesting Tools 2018
  32. Hacking Tools Github
  33. Hacking App
  34. Hacking Tools For Windows Free Download
  35. Pentest Tools Bluekeep
  36. Hacker Tools
  37. Pentest Tools For Windows
  38. New Hacker Tools
  39. Hack Tools 2019
  40. Black Hat Hacker Tools
  41. Growth Hacker Tools
  42. Hack Tools For Windows
  43. Hack Tools For Mac
  44. Hacking Tools For Games
  45. Hacking Tools Name
  46. Hacking Tools Windows 10
  47. Pentest Tools List
  48. Hacking Tools Download
  49. Pentest Reporting Tools
  50. Hacker Tools Software
  51. Hacker Tools
  52. Top Pentest Tools
  53. How To Make Hacking Tools
  54. Hacking Tools For Games
  55. Pentest Reporting Tools
  56. Best Hacking Tools 2019
  57. Hack Tools Github
  58. Hacks And Tools
  59. Best Hacking Tools 2020
  60. Pentest Tools Tcp Port Scanner
  61. Hack Tools
  62. Pentest Tools Apk
  63. Tools For Hacker
  64. Hacking Tools For Pc
  65. Install Pentest Tools Ubuntu
  66. Hacker Tools For Mac
  67. Hack Apps
  68. Nsa Hack Tools Download
  69. Pentest Tools Port Scanner
  70. Hack Tools Pc
  71. Easy Hack Tools
  72. Hack Tools Pc
  73. Bluetooth Hacking Tools Kali
  74. Hacking Tools 2019
  75. Pentest Tools Port Scanner
  76. Hacking Tools For Pc
  77. Hacking Tools 2020
  78. Hacker Tools Software
  79. Hack Tools For Pc
  80. Pentest Tools Bluekeep
  81. Hack Tools Github
  82. Pentest Tools List
  83. Hacking Tools Mac
  84. Hacker Tools Apk Download
  85. Best Hacking Tools 2020
  86. Hacks And Tools
  87. Hacker Search Tools
  88. Hacking Tools Windows
  89. Hacker Tools Apk Download
  90. Hacker
  91. Hacker Tools 2019
  92. Pentest Box Tools Download
  93. Hack Tools Online
  94. Hacking Tools Windows 10
  95. Free Pentest Tools For Windows
  96. Hacking Tools For Kali Linux
  97. Install Pentest Tools Ubuntu
  98. Tools Used For Hacking
  99. Hacker Tools For Ios
  100. Pentest Tools For Android
  101. Hack Tools For Mac
  102. Hacking Tools Windows
  103. Pentest Tools For Windows
  104. Pentest Tools Tcp Port Scanner
  105. Hacking Tools For Windows 7
  106. Hacker Hardware Tools
  107. Pentest Tools List
  108. Hacker Tools 2019
  109. Hack Tools Github
  110. Hacker Tools For Pc
  111. Pentest Tools Website
  112. Pentest Tools Find Subdomains
  113. Hacker Hardware Tools
  114. Hacking Tools For Mac
  115. Hacking Tools Usb
  116. Nsa Hack Tools
  117. Hack Tools Pc
  118. Hack Website Online Tool
  119. Hacking Tools For Pc
  120. Pentest Tools Alternative
  121. Pentest Tools Alternative
  122. Hacking Tools
  123. Hacker Tools For Windows
  124. Hacking Tools For Beginners
  125. Hack App
  126. Hack And Tools
  127. Hack Tools 2019
  128. Hack Tool Apk
  129. Hak5 Tools
  130. Hack App
  131. Hacker Tools For Ios
  132. Hacker Tools Mac
  133. Hack Tool Apk
  134. Hack Website Online Tool
  135. Hack Website Online Tool
  136. New Hack Tools
  137. Pentest Recon Tools
  138. Hack Tools Pc
  139. Hack Tools Download
  140. Pentest Tools Alternative
  141. Hacker
  142. Hacker Hardware Tools
  143. Hacking Tools For Pc
  144. Best Hacking Tools 2019
  145. Hacking Tools Mac
  146. Pentest Recon Tools
  147. Hack Tools Download
  148. Hack App
  149. Hacking Tools 2020
  150. Hacker Tools Online
  151. Hacker Tools List
  152. Hacker Tools Apk Download
  153. Hacking Tools For Windows
  154. Best Pentesting Tools 2018
  155. How To Hack
  156. Hacking Tools Github
  157. Hacker Tools 2020
  158. Pentest Tools Download
  159. Hacking Tools For Windows
  160. Hack Tools Github

No comments: