Monday, August 24, 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.




More info
  1. Android Hack Tools Github
  2. Hacking Tools For Beginners
  3. Hacker Tools List
  4. Pentest Tools Apk
  5. Hackrf Tools
  6. Pentest Tools Port Scanner
  7. Hacker Tools Mac
  8. Hacker Hardware Tools
  9. Pentest Tools Linux
  10. Pentest Recon Tools
  11. Hacking Tools Download
  12. Hacker Tools Hardware
  13. Hacking Tools Windows
  14. Pentest Tools Review
  15. Hacker Tools List
  16. Hack Tools For Mac
  17. Hack Tool Apk
  18. Wifi Hacker Tools For Windows
  19. Pentest Tools Framework
  20. Pentest Tools List
  21. Hacking Tools For Games
  22. Hacker Tools Online
  23. Hacking Tools Mac
  24. Hack Tool Apk No Root
  25. Usb Pentest Tools
  26. Pentest Tools For Android
  27. Pentest Tools Find Subdomains
  28. Hacker Tools Free
  29. Hack Tools For Pc
  30. Growth Hacker Tools
  31. Hack Tools Mac
  32. Hacking Tools Mac
  33. Beginner Hacker Tools
  34. Hack And Tools
  35. Hack And Tools
  36. Pentest Tools Open Source
  37. Bluetooth Hacking Tools Kali
  38. Pentest Tools For Windows
  39. Pentest Tools Online
  40. Easy Hack Tools
  41. Pentest Recon Tools
  42. Hacking Tools Name
  43. Hacker Tools Linux
  44. Hacker Tools List
  45. Hacker Tools 2019
  46. Hacking Tools Windows 10
  47. Physical Pentest Tools
  48. Pentest Tools For Android
  49. How To Install Pentest Tools In Ubuntu
  50. Hacker Tools Github
  51. Hacker Tools For Windows
  52. World No 1 Hacker Software
  53. Pentest Tools For Mac
  54. Hack Tools For Windows
  55. Hacking Tools
  56. Pentest Tools Linux
  57. Hacking Tools For Kali Linux
  58. Pentest Tools Port Scanner
  59. What Are Hacking Tools
  60. Ethical Hacker Tools
  61. Pentest Tools Bluekeep
  62. Hacking Tools Online
  63. Pentest Tools For Android
  64. Pentest Tools Nmap
  65. Tools 4 Hack
  66. Hack Tools Github
  67. Hacker Tools List
  68. What Is Hacking Tools
  69. Pentest Tools Bluekeep
  70. Hack Website Online Tool
  71. Pentest Tools Linux
  72. Hacking Tools Free Download
  73. Hacker Tools Online
  74. Hacking Tools Hardware
  75. Hacking Tools For Mac
  76. Pentest Tools Kali Linux
  77. Game Hacking
  78. Pentest Tools Windows
  79. Hacking Tools
  80. Hack Tools Mac
  81. World No 1 Hacker Software
  82. Pentest Tools Url Fuzzer
  83. Pentest Tools Website Vulnerability
  84. Hack Tool Apk No Root
  85. Hack Tools For Ubuntu
  86. Hacking Tools For Pc
  87. Hacker Tools For Pc
  88. Hack Tools For Pc
  89. Computer Hacker
  90. Hacker Tools Software
  91. Best Hacking Tools 2020
  92. Pentest Tools Linux
  93. Hacker Search Tools
  94. Pentest Tools For Windows
  95. Hacker Tools Free
  96. Ethical Hacker Tools
  97. Hack Tools For Ubuntu
  98. How To Hack

No comments: