Tuesday 30 May 2023

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. Hacker Tools Software
  2. Hacker Tools Github
  3. Hack And Tools
  4. Pentest Tools Alternative
  5. Hackers Toolbox
  6. Hacker Tools For Ios
  7. Hacking Apps
  8. Hacker Search Tools
  9. Hacking Tools 2020
  10. Hacking Tools Download
  11. What Are Hacking Tools
  12. Pentest Tools Kali Linux
  13. Blackhat Hacker Tools
  14. Hack Tools Github
  15. Hacker Tool Kit
  16. Hacking Tools Kit
  17. Hacker
  18. Hacking Tools For Mac
  19. Hack Website Online Tool
  20. Hack Tools For Windows
  21. Hacking Tools For Beginners
  22. Pentest Tools Windows
  23. Ethical Hacker Tools
  24. Hacker Tools Software
  25. Blackhat Hacker Tools
  26. Hack Tools For Mac
  27. Hack Website Online Tool
  28. Hack Tools Online
  29. Pentest Automation Tools
  30. Hacker Search Tools
  31. Hacker Tools Hardware
  32. Hacker Tools Free Download
  33. Hacker Tools Free Download
  34. Pentest Tools For Android
  35. What Are Hacking Tools
  36. How To Hack
  37. Pentest Tools Tcp Port Scanner
  38. Hacking Tools And Software
  39. Best Pentesting Tools 2018
  40. Pentest Tools Find Subdomains
  41. Hacker Tools Free
  42. Hacking Tools For Beginners
  43. Hacking Tools
  44. Hak5 Tools
  45. Hack Tools Online
  46. Hacking Tools For Pc
  47. Hacker Tools Online
  48. Pentest Tools Nmap
  49. Hacking Tools Windows
  50. Hacker Techniques Tools And Incident Handling
  51. Physical Pentest Tools
  52. Hacker Search Tools
  53. World No 1 Hacker Software
  54. Hacking Tools Kit
  55. Hacker Tools 2020
  56. Hack Tools
  57. Hack Website Online Tool
  58. Hacking Tools Name
  59. Pentest Tools Windows
  60. Hack Apps
  61. Pentest Tools For Android
  62. Hack Tools 2019
  63. Best Hacking Tools 2020
  64. Hacker Techniques Tools And Incident Handling
  65. Hacking Tools Kit
  66. Pentest Tools Online
  67. Pentest Tools For Android
  68. Hack Tools For Mac
  69. Hacker Tools Mac
  70. Hacking Tools For Windows Free Download
  71. Pentest Tools Linux
  72. Hacking Tools Windows
  73. Hacker Security Tools
  74. Hacking Tools For Mac
  75. Tools Used For Hacking
  76. Hackrf Tools
  77. Hack Tools Mac
  78. Termux Hacking Tools 2019
  79. Wifi Hacker Tools For Windows
  80. Computer Hacker
  81. Tools For Hacker
  82. Hacker Tools Software
  83. Hacking Tools And Software
  84. Hacker Tools 2019
  85. Pentest Tools Nmap
  86. Pentest Tools Apk
  87. Hacker Search Tools
  88. Underground Hacker Sites
  89. Nsa Hacker Tools
  90. World No 1 Hacker Software
  91. Hacking Tools For Games
  92. Hacking Tools
  93. Hacker Tools Online
  94. Physical Pentest Tools
  95. Hacking Tools For Windows
  96. Tools Used For Hacking
  97. Pentest Tools Windows
  98. Hacking Tools For Games
  99. Hackrf Tools
  100. Hacker Techniques Tools And Incident Handling
  101. Hack Tools For Windows
  102. Termux Hacking Tools 2019
  103. Growth Hacker Tools
  104. Hacker Tools 2019
  105. Hack App
  106. Hacks And Tools
  107. Hacking Tools Free Download
  108. Pentest Automation Tools
  109. Pentest Tools Android
  110. Pentest Reporting Tools
  111. Hacking Tools Software
  112. Hackers Toolbox
  113. Pentest Tools Download
  114. Pentest Tools Port Scanner
  115. Hacking Tools Download
  116. Easy Hack Tools
  117. Pentest Tools Nmap
  118. Hack Tools
  119. Nsa Hacker Tools
  120. Pentest Tools Bluekeep
  121. Hacker Search Tools
  122. Pentest Tools For Mac
  123. Hackrf Tools
  124. Hack Tools For Windows
  125. Tools Used For Hacking

No comments: