Friday, January 26, 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.




Continue reading


  1. Hack Tools Mac
  2. Hacker Tools For Pc
  3. Hacker Tools Free Download
  4. What Is Hacking Tools
  5. Pentest Tools Windows
  6. Black Hat Hacker Tools
  7. Hacking Tools 2019
  8. Computer Hacker
  9. Hacking Tools Software
  10. Physical Pentest Tools
  11. Hacker Tools Online
  12. Hack Tools Github
  13. Hacker Tools Free Download
  14. Hack Website Online Tool
  15. Hack Tools For Pc
  16. Hackrf Tools
  17. Pentest Tools Free
  18. Pentest Tools Android
  19. Tools Used For Hacking
  20. Pentest Tools Framework
  21. Pentest Tools Github
  22. Hacking Tools Name
  23. Hacking Tools For Pc
  24. Hacking Tools Kit
  25. Pentest Tools List
  26. What Is Hacking Tools
  27. Pentest Tools Review
  28. Hack Tool Apk No Root
  29. Pentest Tools Free
  30. Hack Website Online Tool
  31. Hack Tools 2019
  32. Hacker Tools Hardware
  33. Pentest Tools Free
  34. Hacking Tools Download
  35. Hacking Tools For Kali Linux
  36. Hackers Toolbox
  37. Nsa Hack Tools Download
  38. Hacker Tools Apk
  39. Pentest Tools Github
  40. Growth Hacker Tools
  41. Hack Rom Tools
  42. Pentest Box Tools Download
  43. Hacking Tools Free Download
  44. Tools 4 Hack
  45. Hacking Tools For Windows Free Download
  46. Hacking App
  47. What Are Hacking Tools
  48. Android Hack Tools Github
  49. Nsa Hack Tools Download
  50. Hacking Tools For Kali Linux
  51. How To Hack
  52. Hack Tools
  53. Pentest Tools Bluekeep
  54. Hack Tools Online
  55. Hack Tools Pc
  56. Tools For Hacker
  57. Hacking Tools Kit
  58. Hack Tools Mac
  59. Hacker Tools Free Download
  60. Hacking Tools Name
  61. Hacker Tools For Ios
  62. Hack Tool Apk
  63. Hacker Tools For Pc
  64. Hack Tools Github
  65. Hacker Tools For Pc
  66. Hacker Tools Windows
  67. Hacking Tools 2020
  68. Pentest Tools For Mac
  69. Hacker Tools For Pc
  70. Hacking Tools For Beginners
  71. Hack Tools For Ubuntu
  72. Hack Tools For Windows
  73. Hacker Tools Apk Download
  74. Black Hat Hacker Tools
  75. Hacking Tools For Pc
  76. Top Pentest Tools
  77. Pentest Tools For Android
  78. Pentest Tools Website Vulnerability
  79. Hack Rom Tools
  80. Hacker Tools 2019
  81. Easy Hack Tools
  82. Hack Tools For Ubuntu

0 comments