Sunday, August 23, 2020

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 links


  1. Pentest Reporting Tools
  2. Hacker Tool Kit
  3. Hack And Tools
  4. Pentest Tools Port Scanner
  5. Wifi Hacker Tools For Windows
  6. Hacking Tools Download
  7. Pentest Tools Bluekeep
  8. Hacker Tools Software
  9. Pentest Tools Free
  10. Hacker Tools For Pc
  11. Pentest Tools Android
  12. Hack Tools For Ubuntu
  13. Pentest Tools Framework
  14. Ethical Hacker Tools
  15. Hack Tools
  16. Hacker Tools List
  17. Hacking Tools For Games
  18. Hacking Tools Windows
  19. Kik Hack Tools
  20. Tools 4 Hack
  21. Hacker Hardware Tools
  22. Hack Tools Pc
  23. Hacker Tools Mac
  24. Hacking Tools For Beginners
  25. Hacking Tools For Mac
  26. Pentest Recon Tools
  27. Hacking Tools For Kali Linux
  28. Hack Tools For Games
  29. Hacking Tools For Games
  30. Computer Hacker
  31. Hacking Tools For Kali Linux
  32. Hacker Security Tools
  33. Android Hack Tools Github
  34. Pentest Tools Subdomain
  35. Hacking Tools Pc
  36. Hacking Tools Windows
  37. Hacker Search Tools
  38. Tools 4 Hack
  39. Hacker Tools Mac
  40. Hack Apps
  41. Hacker Tools For Pc
  42. Pentest Tools Windows
  43. Pentest Tools
  44. Pentest Recon Tools
  45. Pentest Tools Url Fuzzer
  46. New Hacker Tools
  47. Hacking Tools Free Download
  48. Hacker
  49. Pentest Tools Kali Linux
  50. Termux Hacking Tools 2019
  51. Hacking Apps
  52. Tools Used For Hacking
  53. Hak5 Tools
  54. Hack Tools For Mac
  55. Computer Hacker
  56. Hack Tools For Games
  57. Black Hat Hacker Tools
  58. Nsa Hack Tools Download
  59. Pentest Tools Open Source
  60. Hacking Tools Name
  61. Hacking Tools Mac
  62. Hackrf Tools
  63. Beginner Hacker Tools
  64. Hacking Tools
  65. Hacking Tools For Windows
  66. Hacking Tools For Kali Linux
  67. Hacking Tools Download
  68. Top Pentest Tools
  69. Pentest Tools For Mac
  70. Hack Tools Online
  71. Hacking Tools Download
  72. Tools Used For Hacking
  73. Bluetooth Hacking Tools Kali
  74. Hacker Tools Free Download
  75. Wifi Hacker Tools For Windows
  76. Pentest Tools Bluekeep
  77. Hacking Tools 2019

No comments:

Post a Comment