aboutsummaryrefslogtreecommitdiff
path: root/src/hardware_functions.cpp
diff options
context:
space:
mode:
authorstonedDiscord <Tukz@gmx.de>2022-03-27 15:02:08 +0200
committerGitHub <noreply@github.com>2022-03-27 15:02:08 +0200
commit7e9ad9946b7ccb43f10da5584297af4d8da6000b (patch)
tree5c8b8967007e956f0f01f0cf08b82e078b080f94 /src/hardware_functions.cpp
parent69f49f7fee33a8b24de8c38eb594e1116cdf356f (diff)
add new hdid algo (#694)
* add new hdid algo * forgot the w for unicode * add advapi32 to windows * get rid of visual studio 2022 shit * Update src/hardware_functions.cpp Co-authored-by: oldmud0 <oldmud0@users.noreply.github.com> * close handle when it fails Co-authored-by: oldmud0 <oldmud0@users.noreply.github.com>
Diffstat (limited to 'src/hardware_functions.cpp')
-rw-r--r--src/hardware_functions.cpp51
1 files changed, 33 insertions, 18 deletions
diff --git a/src/hardware_functions.cpp b/src/hardware_functions.cpp
index 2f3c44d3..4bd23997 100644
--- a/src/hardware_functions.cpp
+++ b/src/hardware_functions.cpp
@@ -3,28 +3,43 @@
#include <QDebug>
#include <QtGlobal>
-#if QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
-
#if (defined(_WIN32) || defined(_WIN64))
#include <windows.h>
-
-static DWORD dwVolSerial;
-static BOOL bIsRetrieved;
+#include <sddl.h>
QString get_hdid()
{
- bIsRetrieved = GetVolumeInformation(TEXT("C:\\"), nullptr, 0, &dwVolSerial,
- nullptr, nullptr, nullptr, 0);
-
- if (bIsRetrieved)
- return QString::number(dwVolSerial, 16);
- else
- // a totally random string
- // what could possibly go wrong
- return "gxsps32sa9fnwic92mfbs0";
-}
+ HANDLE hToken;
+ HANDLE pHandle;
+ PTOKEN_USER pToken;
+ DWORD uSize = 0;
+ LPWSTR HDIDParam;
+
+ pHandle = GetCurrentProcess();
+ OpenProcessToken(pHandle, TOKEN_QUERY, &hToken);
+ if (!GetTokenInformation(hToken, (TOKEN_INFORMATION_CLASS)1, NULL, 0, &uSize))
+ {
+ if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
+ CloseHandle(hToken);
+ return "gxsps32sa9fnwic92mfbs1";
+ }
+ }
-#elif (defined(LINUX) || defined(__linux__))
+ pToken = (PTOKEN_USER)GlobalAlloc(GPTR, uSize);
+
+ if (!GetTokenInformation(hToken, (TOKEN_INFORMATION_CLASS)1, pToken, uSize, &uSize))
+ {
+ CloseHandle(hToken);
+ return "gxsps32sa9fnwic92mfbs2";
+ }
+
+ ConvertSidToStringSidW(pToken->User.Sid, &HDIDParam);
+ QString returnHDID = QString::fromWCharArray(HDIDParam);
+ CloseHandle(hToken);
+ return returnHDID;
+}
+#elif QT_VERSION < QT_VERSION_CHECK(5, 11, 0)
+#if (defined(LINUX) || defined(__linux__))
#include <QFile>
#include <QTextStream>
@@ -33,7 +48,7 @@ QString get_hdid()
{
QFile fstab_file("/etc/fstab");
if (!fstab_file.open(QIODevice::ReadOnly))
- return "gxcps32sa9fnwic92mfbs0";
+ return "uxcps32sa9fnwic92mfbs0";
QTextStream in(&fstab_file);
@@ -48,7 +63,7 @@ QString get_hdid()
}
}
- return "gxcpz32sa9fnwic92mfbs0";
+ return "uxcpz32sa9fnwic92mfbs1";
}
#elif defined __APPLE__