jueves, 18 de enero de 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 articles

  1. Pentest Tools For Windows
  2. Hacker Search Tools
  3. Hacker Techniques Tools And Incident Handling
  4. Hacking Tools Usb
  5. Pentest Tools
  6. Pentest Tools
  7. Hack Tool Apk
  8. Hacker Tools Free Download
  9. Hacking Tools Free Download
  10. Hack And Tools
  11. Github Hacking Tools
  12. Black Hat Hacker Tools
  13. Pentest Tools For Windows
  14. How To Install Pentest Tools In Ubuntu
  15. Free Pentest Tools For Windows
  16. Pentest Tools Find Subdomains
  17. Usb Pentest Tools
  18. Hacking Tools Windows
  19. Hacker Tools Linux
  20. Hacking Tools 2019
  21. Hacker Tools Free
  22. Nsa Hacker Tools
  23. Hacker Tools
  24. Hacks And Tools
  25. Hack App
  26. Pentest Reporting Tools
  27. What Is Hacking Tools
  28. Pentest Tools Apk
  29. Hackers Toolbox
  30. Best Pentesting Tools 2018
  31. Tools For Hacker
  32. Hacking Tools Free Download
  33. Easy Hack Tools
  34. Hacking Tools For Pc
  35. Hacker Tools Github
  36. Hacking Tools Windows 10
  37. Hack Tools Mac
  38. Hacker
  39. Hacker
  40. Pentest Tools Tcp Port Scanner
  41. Hacker Tools 2019
  42. Hacker Search Tools
  43. Hack Tools Pc
  44. Pentest Tools Bluekeep
  45. Hacker Techniques Tools And Incident Handling
  46. Nsa Hacker Tools
  47. Free Pentest Tools For Windows
  48. Hacking Tools Download
  49. Hacker Tools Apk Download
  50. Hacker Techniques Tools And Incident Handling
  51. Hack Tools Pc
  52. Hacking Apps
  53. Hacking Tools For Games
  54. Hacks And Tools
  55. Hacker Tools Hardware
  56. Hacking Tools Hardware
  57. Pentest Tools Open Source
  58. Hackrf Tools
  59. Hacker Tools For Pc
  60. Pentest Tools
  61. Wifi Hacker Tools For Windows
  62. How To Install Pentest Tools In Ubuntu
  63. Hacker Tools 2020
  64. Hacking Tools 2020
  65. Usb Pentest Tools
  66. Hacking Tools 2019
  67. Hack Tools
  68. Hack Tools Download
  69. Android Hack Tools Github
  70. Pentest Tools List
  71. Hacker Tools For Mac
  72. Kik Hack Tools
  73. Hacker
  74. Pentest Reporting Tools
  75. Hacker Tools For Ios
  76. Pentest Tools Github
  77. Pentest Tools Free
  78. Hacking Tools Windows 10
  79. Hacker Tools Free Download
  80. Hack Tool Apk No Root
  81. Hacker Tools For Mac
  82. Hack Tools For Pc
  83. Hack Apps
  84. Hacker Tools Free
  85. Pentest Tools Linux
  86. Hacker Tools For Pc
  87. Growth Hacker Tools
  88. Pentest Tools Find Subdomains
  89. Hacking Tools Hardware
  90. Pentest Tools Url Fuzzer
  91. Hack Rom Tools
  92. Free Pentest Tools For Windows
  93. Hack Tool Apk
  94. Tools Used For Hacking
  95. Pentest Box Tools Download
  96. Pentest Tools For Ubuntu
  97. Nsa Hacker Tools
  98. Hacker Tools Hardware
  99. Pentest Tools Bluekeep

No hay comentarios.: