Saturday, August 29, 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.




Read more
  1. Hacking Tools Download
  2. Hacking Tools Pc
  3. New Hacker Tools
  4. Pentest Tools Github
  5. Hack App
  6. Hacker Tools Online
  7. Pentest Tools Review
  8. Pentest Reporting Tools
  9. Pentest Tools Linux
  10. Pentest Tools Framework
  11. Pentest Tools Website
  12. Hack Tools Github
  13. Blackhat Hacker Tools
  14. Hacking Tools Windows 10
  15. Hacking Tools
  16. Pentest Tools Website
  17. Pentest Tools
  18. Pentest Tools Linux
  19. Pentest Tools Open Source
  20. Hacking Tools Free Download
  21. Pentest Tools Linux
  22. Hacking Tools Online
  23. Pentest Tools Bluekeep
  24. Pentest Tools Review
  25. Pentest Tools Find Subdomains
  26. Hacker Tools Github
  27. Hacker Tools For Ios
  28. Hack Tools For Pc
  29. Pentest Tools Open Source
  30. Hacker Tools 2020
  31. Hack App
  32. Pentest Tools For Android
  33. Tools 4 Hack
  34. Hacking Apps
  35. Hacking App
  36. Nsa Hack Tools
  37. How To Install Pentest Tools In Ubuntu
  38. Ethical Hacker Tools
  39. Hacking Tools For Beginners
  40. Pentest Tools Free
  41. Hacking Tools For Games
  42. Pentest Tools Framework
  43. Best Hacking Tools 2019
  44. Hack Tools Mac
  45. Pentest Tools For Android
  46. Wifi Hacker Tools For Windows
  47. Pentest Tools Apk
  48. Hack Tool Apk
  49. Hack Tools
  50. Hacking Tools For Windows Free Download
  51. Hacking Tools For Beginners
  52. Hacking Tools Github
  53. Pentest Tools Apk
  54. Pentest Tools Alternative
  55. How To Make Hacking Tools
  56. Easy Hack Tools
  57. Hacker Tools Github
  58. Hacker Tools Free Download
  59. Pentest Tools Online
  60. Hackrf Tools
  61. Hacker Tools List
  62. Hacking Tools And Software
  63. Free Pentest Tools For Windows
  64. Github Hacking Tools
  65. Pentest Tools Github
  66. Blackhat Hacker Tools
  67. Pentest Tools Tcp Port Scanner
  68. Pentest Tools Online
  69. Hacking Tools And Software
  70. Hacker Tools Hardware
  71. Install Pentest Tools Ubuntu
  72. Hacker Tools Software
  73. Black Hat Hacker Tools
  74. Hacker Tools For Windows
  75. Pentest Tools
  76. Kik Hack Tools
  77. Hacker Tools Free
  78. How To Install Pentest Tools In Ubuntu
  79. Hak5 Tools
  80. Hack Tools Pc

No comments:

Post a Comment