Created
December 4, 2024 14:10
-
-
Save deepak1556/b0e95a2a9ab71ffaa39c4feeda9d5fe9 to your computer and use it in GitHub Desktop.
Convert GNU_BUILD_ID to debug_id for minidump
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <sstream> | |
#include <cstdint> | |
#include <cstring> | |
typedef struct { | |
uint32_t data1; | |
uint16_t data2; | |
uint16_t data3; | |
uint8_t data4[8]; | |
} MDGUID; /* GUID */ | |
bool hexStringToUint8Array(const std::string& hexString, uint8_t* outputArray, size_t outputSize) { | |
if (hexString.length() % 2 != 0 || outputSize < hexString.length() / 2) { | |
return false; | |
} | |
for (size_t i = 0; i < hexString.length(); i += 2) { | |
std::string byteString = hexString.substr(i, 2); | |
uint8_t byte = static_cast<uint8_t>(std::stoi(byteString, nullptr, 16)); | |
outputArray[i / 2] = byte; | |
} | |
return true; | |
} | |
std::string guid_to_debug_id(const MDGUID& guid) { | |
char identifier_string[41]; | |
snprintf(identifier_string, sizeof(identifier_string), | |
"%08X%04X%04X%02X%02X%02X%02X%02X%02X%02X%02X%x", | |
guid.data1, | |
guid.data2, | |
guid.data3, | |
guid.data4[0], | |
guid.data4[1], | |
guid.data4[2], | |
guid.data4[3], | |
guid.data4[4], | |
guid.data4[5], | |
guid.data4[6], | |
guid.data4[7], | |
0); | |
return identifier_string; | |
} | |
int main() { | |
std::string hexString = ""; | |
size_t outputSize = hexString.length() / 2; | |
uint8_t* outputArray = new uint8_t[outputSize]; | |
if (hexStringToUint8Array(hexString, outputArray, outputSize)) { | |
MDGUID guid = {0}; | |
memcpy(&guid, outputArray, std::min(20ul, sizeof(MDGUID))); | |
std::cout << guid_to_debug_id(guid); | |
std::cout << std::endl; | |
} else { | |
std::cout << "Conversion failed." << std::endl; | |
} | |
delete[] outputArray; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment