Friday, January 19, 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 info
  1. Pentest Tools Nmap
  2. Hack Tools Github
  3. Pentest Tools Online
  4. Usb Pentest Tools
  5. Tools Used For Hacking
  6. Hacking Tools For Pc
  7. Hack Tools Pc
  8. What Are Hacking Tools
  9. Hack App
  10. Hack App
  11. Hacker
  12. Hacker Tools Apk
  13. Hacker Tools Hardware
  14. Hacking Tools For Mac
  15. Hack Rom Tools
  16. Pentest Tools Android
  17. Pentest Tools Find Subdomains
  18. New Hacker Tools
  19. Easy Hack Tools
  20. Pentest Tools Website
  21. Hacking Tools For Pc
  22. Pentest Tools Website
  23. Hacker Tools Apk Download
  24. Nsa Hack Tools Download
  25. Pentest Tools Port Scanner
  26. Hacking Tools For Mac
  27. Pentest Tools Review
  28. Hacker Tools For Mac
  29. Pentest Tools For Android
  30. Hackrf Tools
  31. Hack App
  32. How To Install Pentest Tools In Ubuntu
  33. Tools 4 Hack
  34. Android Hack Tools Github
  35. Hackers Toolbox
  36. Pentest Tools Download
  37. Hacker Tools For Pc
  38. Hacker Search Tools
  39. Blackhat Hacker Tools
  40. Pentest Tools Windows
  41. Pentest Automation Tools
  42. Underground Hacker Sites
  43. Pentest Tools For Ubuntu
  44. Hack Tools For Mac
  45. Computer Hacker
  46. Hacker Tools Linux
  47. Hacker Tools Software
  48. Pentest Tools Bluekeep
  49. Pentest Tools Download
  50. Growth Hacker Tools
  51. Best Hacking Tools 2019
  52. Hacker Tools For Mac
  53. Hackers Toolbox
  54. Hacking Tools For Games
  55. Hacking Tools And Software
  56. Pentest Tools Kali Linux
  57. Hacker Tools
  58. Hacker Tools Mac
  59. Hacking Tools Download
  60. What Is Hacking Tools
  61. Pentest Tools Free
  62. Pentest Tools Bluekeep
  63. Hackers Toolbox
  64. Hacking Tools Usb
  65. Hacking Tools Pc
  66. Pentest Tools Github
  67. Hack Tools For Mac
  68. Nsa Hacker Tools
  69. What Is Hacking Tools
  70. Hacker Tools Linux
  71. Hacking Tools Software
  72. Pentest Tools
  73. Pentest Tools Windows
  74. Hacker Hardware Tools
  75. Pentest Tools Url Fuzzer
  76. Pentest Tools Kali Linux
  77. Hacker Tools 2020
  78. Best Hacking Tools 2019
  79. Hack Tools Online
  80. Hack Tool Apk
  81. Pentest Tools Port Scanner
  82. Hacking Tools 2020
  83. Hacker
  84. Hacking Tools Windows 10
  85. Hacking Tools Download
  86. Pentest Tools Github
  87. Hack And Tools
  88. Hacker Tools For Pc
  89. Beginner Hacker Tools
  90. Hacking Tools Name
  91. Usb Pentest Tools
  92. Hack App
  93. Pentest Tools Windows
  94. Pentest Tools Windows
  95. Pentest Tools Alternative
  96. Hack Tools Github
  97. Pentest Automation Tools
  98. How To Hack
  99. Pentest Tools For Mac
  100. Game Hacking
  101. Computer Hacker
  102. Pentest Tools Download
  103. Pentest Tools
  104. Hack Tools Pc
  105. Computer Hacker
  106. Hacker Tools Hardware
  107. Pentest Tools Android
  108. Pentest Tools Tcp Port Scanner
  109. Install Pentest Tools Ubuntu
  110. Top Pentest Tools
  111. What Is Hacking Tools
  112. Top Pentest Tools
  113. Pentest Tools Website Vulnerability
  114. Hacking Apps
  115. Usb Pentest Tools
  116. What Is Hacking Tools
  117. Hacker Tools List
  118. Tools Used For Hacking
  119. Hacking Tools For Windows
  120. Hacker Tools List
  121. Computer Hacker
  122. Pentest Tools Bluekeep
  123. Hacking Tools For Kali Linux
  124. New Hacker Tools
  125. Free Pentest Tools For Windows
  126. Hacker Tools
  127. Free Pentest Tools For Windows
  128. Hack Tools Mac
  129. Pentest Tools
  130. How To Make Hacking Tools
  131. Pentest Tools Nmap
  132. Hacker Tools Mac
  133. Pentest Tools For Mac
  134. Hacking Tools For Windows Free Download
  135. Hack Tools
  136. Hackers Toolbox
  137. Ethical Hacker Tools
  138. Hack Tools For Games
  139. Best Pentesting Tools 2018
  140. Nsa Hack Tools
  141. Hack App
  142. Nsa Hack Tools Download
  143. Pentest Tools Apk

No comments:

Post a Comment