Accéder au contenu principal

Reversing C++ String And QString

After the rust string overview of its internal substructures, let's see if c++ QString storage is more light, but first we'r going to take a look to the c++ standard string object:



At first sight we can see the allocation and deallocation created by the clang++ compiler, and the DAT_00400d34 is the string.

If we use same algorithm than the rust code but in c++:



We have a different decompilation layout. Note that the Ghidra scans very fast the c++ binaries, and with rust binaries gets crazy for a while.
Locating main is also very simple in a c++ compiled binary, indeed is more  low-level than rust.


The byte array is initialized with a simply move instruction:
        00400c4b 48 b8 68        MOV        RAX,0x6f77206f6c6c6568

And basic_string generates the string, in the case of rust this was carazy endless set of calls, detected by ghidra as a runtime, but nevertheless the basic_string is an external imported function not included on the binary.

(gdb) x/x 0x7fffffffe1d0
0x7fffffffe1d0: 0xffffe1e0            low str ptr
0x7fffffffe1d4: 0x00007fff           hight str ptr
0x7fffffffe1d8: 0x0000000b        sz
0x7fffffffe1dc: 0x00000000
0x7fffffffe1e0: 0x6c6c6568         "hello world"
0x7fffffffe1e4: 0x6f77206f
0x7fffffffe1e8: 0x00646c72
0x7fffffffe1ec: 0x00000000        null terminated
(gdb) x/s 0x7fffffffe1e0
0x7fffffffe1e0: "hello world"

The string is on the stack, and it's very curious to see what happens if there are two followed strings like these:

  auto s = string(cstr);
  string s2 = "test";

Clang puts toguether both stack strings:
[ptr1][sz1][string1][null][string2][null][ptr2][sz2]

C++ QString datatype

Let's see the great and featured QString object defined on qstring.cpp and qstring.h

Some QString methods use the QCharRef class whose definition is below:

class Q_EXPORT QCharRef {
friend class QString;
QString& s;
uint p;
Searching for the properties on the QString class I've realized that one improvement that  rust and golang does is the separation from properties and methods, so in the large QString class the methods are  hidden among the hundreds of methods, but basically the storage is a QStringData *;

After removing the methods of QStringData class definition we have this:

struct Q_EXPORT QStringData : public QShared {
    QChar *unicode;
    char *ascii;
#ifdef Q_OS_MAC9
    uint len;
#else
    uint len : 30;

Commentaires

Posts les plus consultés de ce blog

HTML5 Games On Android

On my last hollidays, I made two HTML5 games, and published on android market. Nowadays javascript has powerful libraries for doing almost everything, and also there are several compilers from java or c code to javascript, converting opengl c code to html5 canvas, but definitely, javascript execution is slower than dalvik applications, and of course much slower than arm c libs. For improving the speed of sounds and images loader, I have used javascript asynchronous execution and scheduling priority has been controlled with setTimeout/setInterval which deprioritize or priorize a code block. This games are published on the android market here: Android Planets and here: Far Planet Related news Hacker Hardware Tools Pentest Tools Port Scanner Hacker Tools For Mac Tools Used For Hacking Hacker Techniques Tools And Incident Handling Easy Hack Tools Hacking Tools Kit Hacking Tools Usb Hacker Hardware Tools Hacker Tools Hardware Hack Tools For Windows Hacking Tools For G...

BeEF: Browser Exploitation Framework

"BeEF is the browser exploitation framework. A professional tool to demonstrate the real-time impact of XSS browser vulnerabilities. Development has focused on creating a modular structure making new module development a trivial process with the intelligence residing within BeEF. Current modules include the first public Inter-protocol Exploit, a traditional browser overflow exploit, port scanning, keylogging, clipboard theft and more." read more... Website: http://www.bindshell.net/tools/beef Related links Pentest Automation Tools Ethical Hacker Tools Hacking Tools For Windows Free Download Pentest Reporting Tools Hack Tool Apk No Root Nsa Hack Tools Download Beginner Hacker Tools Hacking Tools For Windows Free Download Hack Tools For Mac Hack Tool Apk No Root Kik Hack Tools Hacking App Pentest Tools List Nsa Hacker Tools Hack Tools Mac Hacking Tools Kit Pentest Tools For Android Hack Tools For Windows Hackrf Tools Tools 4 Hack Hacking Tools Mac Hacking ...

Abdominal pain after a motor vehicle accident

CASE A 22-year-old man was brought to the ED complaining of abdominal pain after a rollover motor vehicle accident. He was the front seat passenger and was wearing a seat belt. Although he was trapped in the vehicle and it caught on fire, he did not suffer any cutaneous burns. History  The patient's past medical history was significant for attention-deficit hyperactivity disorder. He admitted to using tobacco and alcohol socially, but denied illicit drug use. He denied any medication use or drug allergies. A review of systems was positive for complaints of abdominal pain and anxiety. Physical examination  The patient's vital signs were: BP, 112/51 mm Hg; heart rate, 110 beats/minute; respirations, 23; SpO 2 , 95% on room air; and temperature, 37.4° C (99.3° F). On ED arrival, he was awake, alert, and oriented but appeared anxious and agitated. His pupils were equal, round, and reactive to light. His head was normocephalic with a 2-cm laceration on the left ear. The pati...