Sunday, May 28, 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.




Related news


  1. Hacker Tools For Ios
  2. World No 1 Hacker Software
  3. Hacker Tools For Mac
  4. Hack Tool Apk
  5. Pentest Tools Bluekeep
  6. Pentest Tools Find Subdomains
  7. Pentest Tools Tcp Port Scanner
  8. Hacker Tools For Mac
  9. Hacker Tools Software
  10. Hack Tools For Games
  11. Hacker Tools 2019
  12. Hacking Tools Github
  13. Pentest Recon Tools
  14. Pentest Tools Kali Linux
  15. Hacking Tools Kit
  16. Github Hacking Tools
  17. Hacker Security Tools
  18. Pentest Tools Github
  19. Hacking Tools Github
  20. Hack App
  21. Hack Tools
  22. Pentest Tools Url Fuzzer
  23. Hack Rom Tools
  24. Hacker Tools Free
  25. World No 1 Hacker Software
  26. Hacking Tools Usb
  27. Nsa Hack Tools
  28. Pentest Tools For Android
  29. Hacker Tools For Windows
  30. Pentest Tools Subdomain
  31. Pentest Tools Linux
  32. Hacking Tools
  33. Hacker Tool Kit
  34. New Hacker Tools
  35. Hack Tool Apk No Root
  36. Pentest Tools List
  37. Hacker Tools Apk
  38. Hack Tools
  39. How To Hack
  40. Hacking Tools Usb
  41. Hacking Tools Hardware
  42. Physical Pentest Tools
  43. Easy Hack Tools
  44. Hack Tool Apk
  45. Hacker Tools For Mac
  46. Pentest Tools Nmap
  47. Hackers Toolbox
  48. How To Make Hacking Tools
  49. Hacker Tools Apk
  50. Hacker Tools Windows
  51. Pentest Tools Free
  52. Pentest Tools Website
  53. Hacking Tools Free Download
  54. Computer Hacker
  55. Hacking Tools
  56. Pentest Tools For Ubuntu
  57. Hacker Tools Software
  58. What Is Hacking Tools
  59. Pentest Tools For Android
  60. Hack Tool Apk No Root
  61. Nsa Hack Tools
  62. Nsa Hacker Tools
  63. Hacker Tools Online
  64. Hack Tools 2019
  65. Hacking Tools Pc
  66. Pentest Tools List
  67. Pentest Tools Find Subdomains
  68. Hack Tools Download
  69. Hacker Tools Hardware
  70. Hacker Tools Mac
  71. Hacker Tool Kit
  72. Hacking Tools Online
  73. Black Hat Hacker Tools
  74. Tools For Hacker
  75. Pentest Tools For Ubuntu
  76. Hacks And Tools
  77. Hack Tool Apk No Root
  78. Hacking Tools 2020
  79. Hacking Tools Usb
  80. Hacker Tools
  81. New Hack Tools
  82. Hack Tools Pc
  83. Easy Hack Tools
  84. Pentest Tools Bluekeep
  85. Pentest Reporting Tools
  86. Physical Pentest Tools
  87. Hack And Tools
  88. Pentest Reporting Tools
  89. Hack Tools For Games
  90. Pentest Tools Review
  91. Hackrf Tools
  92. Hacker Tools 2019
  93. Pentest Reporting Tools
  94. Pentest Tools Port Scanner
  95. Hacker Tools 2019
  96. Pentest Tools List
  97. Hack Tool Apk
  98. Hacking Tools For Windows
  99. Pentest Tools Kali Linux
  100. Blackhat Hacker Tools
  101. Beginner Hacker Tools
  102. Usb Pentest Tools
  103. Hack Tools For Windows
  104. Hacking Tools Name
  105. Physical Pentest Tools
  106. Tools For Hacker
  107. Hacker Tools Windows

No comments:

Post a Comment