How to read registry binary data using QT?
-
I want to read the registry binary and convert to string. In this first i need how to read binary data from registry
-
-
Checked already I am not getting info for reading the binary data, all other i am able to read
-
@Narasimman
Something like this?QSettings reg("HKEY_CURRENT_USER\\Environment", QSettings::NativeFormat); QString stringg = reg.value("TEST").toString(); QByteArray data = QByteArray((const char*)stringg.utf16()); qDebug() << "value : " << data;
-
@Narasimman @Ratzz I would say (since QString isn't binary):
QSettings reg("HKEY_CURRENT_USER\\Environment", QSettings::NativeFormat); QByteArray data = reg.value("TEST").toByteArray(); qDebug() << "value : " << data;
-
@jsulm said in How to read registry binary data using QT?:
qDebug() << "value : " << data;
QSettings Drives("HKEY_LOCAL_MACHINE\SYSTEM\MountedDevices",QSettings::NativeFormat);
QStringList keys = Drives.allKeys(); qDebug()<<"jeys list :"<<keys.count(); for(int i=0;i<keys.count();i++) { QString strkey = keys.at(i); qDebug()<<"Key: "<<strkey; QVariant strvalue=Drives.value(strkey); QByteArray data = Drives.value(strkey).toByteArray(); qDebug() << "valuebyte : " << data; qDebug()<<"Value Type : "<<strvalue.type()<<" name : "<<strvalue.typeName()<<" value :"<<strvalue.toByteArray().toStdString().c_str(); }
This is my code.
Below are the output of the above code
[Key: "#{f6d859dc-538d-11e7-81fe-f85971670abf}"]
[valuebyte : "\xE4\xB5\x84\xE4\xBD\x89\xE4\xA4\xBA\xE3\xA9\x84\xE6\xBB\x99\xEE\xBC\xB9\xE1\xA3\x9F\xE4\xA4\x8A\xE8\xBA\xA9\xEB\xBF\x8B\xE5\xBC\xB0\xE3\x88\x88"]
[Value Type : QVariant::QString name : QString value : ????????????]
[Key: "/??/Volume{0040c5a3-3c8c-11e8-8216-54e1ad32fe3b}"]
[valuebyte : ""]
[Value Type : QVariant::Invalid name : value : ]
[Key: "/??/Volume{1eb29a46-1878-11e8-8211-54e1ad32fe3b}"]
[valuebyte : ""]But still not getting the value. Let me know what is the issue ?
-
@Narasimman
Here you got binary:
[Key: "#{f6d859dc-538d-11e7-81fe-f85971670abf}"]
[valuebyte : "\xE4\xB5\x84\xE4\xBD\x89\xE4\xA4\xBA\xE3\xA9\x84\xE6\xBB\x99\xEE\xBC\xB9\xE1\xA3\x9F\xE4\xA4\x8A\xE8\xBA\xA9\xEB\xBF\x8B\xE5\xBC\xB0\xE3\x88\x88"]Here the content is a string and you should treat it as string:
[Value Type : QVariant::QString name : QString value : ????????????]
[Key: "/??/Volume{0040c5a3-3c8c-11e8-8216-54e1ad32fe3b}"]
[valuebyte : ""]Here you got something invalid:
[Value Type : QVariant::Invalid name : value : ]
[Key: "/??/Volume{1eb29a46-1878-11e8-8211-54e1ad32fe3b}"]
[valuebyte : ""] -
@jsulm said in How to read registry binary data using QT?:
@Narasimman
Here you got binary:
[Key: "#{f6d859dc-538d-11e7-81fe-f85971670abf}"]
[valuebyte : "\xE4\xB5\x84\xE4\xBD\x89\xE4\xA4\xBA\xE3\xA9\x84\xE6\xBB\x99\xEE\xBC\xB9\xE1\xA3\x9F\xE4\xA4\x8A\xE8\xBA\xA9\xEB\xBF\x8B\xE5\xBC\xB0\xE3\x88\x88"]Below all the registry keys are of same type as binary , why i got 1 as string another a binary, no clue on this.
Here the content is a string and you should treat it as string:
[Value Type : QVariant::QString name : QString value : ????????????]
[Key: "/??/Volume{0040c5a3-3c8c-11e8-8216-54e1ad32fe3b}"]
[valuebyte : ""]Here you got something invalid:
[Value Type : QVariant::Invalid name : value : ]
[Key: "/??/Volume{1eb29a46-1878-11e8-8211-54e1ad32fe3b}"]
[valuebyte : ""] -
@Narasimman How do these binary keys look in regedit.exe?
-
Above is the screeshot of the registry key.
-
Any update on this ?
-
@Narasimman @jsulm
I just noticedQSettings reg("HKEY_LOCAL_MACHINE\\SYSTEM\\DriverDatabase", QSettings::NativeFormat); QString stringg = reg.value("OemInfMap").toString(); QByteArray data = QByteArray((const char*)stringg.utf16()); qDebug() << "value using QString : " << data; QByteArray byteArray = reg.value("OemInfMap").toByteArray(); qDebug() << "value using QByteArray : " << byteArray;
Gives me
value using QString : "\xFF\xFF\xFF\xF0" value using QByteArray : "\xEF\xBF\xBF\xEF\x83\xBF"
-
@Ratzz said in How to read registry binary data using QT?:
QByteArray data = QByteArray((const char*)stringg.utf16());
This is simply wrong. If it is binary already then do
QByteArray data = reg.value("OemInfMap").toByteArray();
Do NOT convert binary data to string, then to Unicode string and then to binary again!
-
You ar right. The REG_BINARY type is converted to QString. But there is a bug. If the length of the binary data is odd, the last data is truncated.
in qsettings_win.cpp, line 547, Qt 5.10.0
s = QString::fromWCharArray((const wchar_t *)data.constData(), data.size() / 2); -
@Devopia53 said in How to read registry binary data using QT?:
You ar right. The REG_BINARY type is converted to QString. But there is a bug. If the length of the binary data is odd, the last data is truncated.
in qsettings_win.cpp, line 547, Qt 5.10.0
s = QString::fromWCharArray((const wchar_t *)data.constData(), data.size() / 2);This in itself is not a bug. A "wide char array" is an array of bytes in which each pair represents one character. Therefore the length must be even, and the code is as correct as it can be.
If the data is arbitrary bytes, as it seems to be, it should never be treated as a wide char array/
QString
.I don't know, but does (unfixed) https://bugreports.qt.io/browse/QTBUG-98 imply this is simply still not doable in Qt5?
It could be an enhancement to QSettings to support more registry types which are correctly mapped in the QVariant. Qt should map REG_BINARY to QByteArray
We can't fix this until Qt 5, because REG_BINARY is currently read by QSettings as a utf-16 encoded QString. Changing this would break existing applications.
Naughty, naughty!