forked from Skewjo/SysLat_Software
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHardwareID.cpp
More file actions
96 lines (81 loc) · 3.33 KB
/
HardwareID.cpp
File metadata and controls
96 lines (81 loc) · 3.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "stdafx.h"
#include "HardwareID.h"
void HardwareID::GetUserAndComputerName() {
userNameSize = UNLEN + 1;
GetUserName(userName, &userNameSize);
DEBUG_PRINT(userName)
computerNameSize = UNLEN + 1;
GetComputerName(computerName, &computerNameSize);
DEBUG_PRINT(computerName)
}
char* HardwareID::GetMAC() {
PIP_ADAPTER_INFO AdapterInfo;
DWORD dwBufLen = sizeof(IP_ADAPTER_INFO);
char* mac_addr = (char*)malloc(18);
AdapterInfo = (IP_ADAPTER_INFO*)malloc(sizeof(IP_ADAPTER_INFO));
if (AdapterInfo == NULL) {
printf("Error allocating memory needed to call GetAdaptersinfo\n");
free(mac_addr);
return NULL; // it is safe to call free(NULL)
}
// Make an initial call to GetAdaptersInfo to get the necessary size into the dwBufLen variable
if (GetAdaptersInfo(AdapterInfo, &dwBufLen) == ERROR_BUFFER_OVERFLOW) {
free(AdapterInfo);
AdapterInfo = (IP_ADAPTER_INFO*)malloc(dwBufLen);
if (AdapterInfo == NULL) {
printf("Error allocating memory needed to call GetAdaptersinfo\n");
free(mac_addr);
return NULL;
}
}
if (GetAdaptersInfo(AdapterInfo, &dwBufLen) == NO_ERROR) {
// Contains pointer to current adapter info
PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;
do {
// technically should look at pAdapterInfo->AddressLength
// and not assume it is 6.
//replaced sprintf() here with just printf... not sure if correct and I haven't tested it.
printf(mac_addr, "%02X:%02X:%02X:%02X:%02X:%02X",
pAdapterInfo->Address[0], pAdapterInfo->Address[1],
pAdapterInfo->Address[2], pAdapterInfo->Address[3],
pAdapterInfo->Address[4], pAdapterInfo->Address[5]);
printf("Address: %s, mac: %s\n", pAdapterInfo->IpAddressList.IpAddress.String, mac_addr);
// print them all, return the last one.
// return mac_addr;
printf("\n");
pAdapterInfo = pAdapterInfo->Next;
} while (pAdapterInfo);
}
free(AdapterInfo);
return mac_addr; // caller must free.
}
//incomplete
void HardwareID::GetMachineSID() {
//m_pSID
//LookupAccountName(computerName, m_pSID, computerName, computerNameSize, );
LookupAccountSid(computerName, m_pSID, userName, &dwSize, lpDomain, &dwSize, &m_SIDType);
//ConvertSidToStringSid();
}
void HardwareID::CreateJSON() {
//BenchmarkDatasets: [BenchmarkDataset!] @relation(name: "dataSetOwnerHWID")
//UserMachineInfo: UserMachineInfo @relation(name: "MI_HWID")
HardwareIDJSON["UserMachineID"]["ComputerName"] = computerName;
HardwareIDJSON["UserMachineID"]["ComputerUserName"] = userName;
HardwareIDJSON["UserMachineID"]["HardwareID"] = hwProfileInfo.szHwProfileGuid;
HardwareIDJSON["UserMachineID"]["MACAddress"] = m_pMac;
//IPAddress : String // THIS WILL NEED TO BE ADDED BY THE WEBSITE, I THINK?? IDK
//MachineSID : String
//UserProfileName : String
}
void HardwareID::ExportData(string path) {
std::ofstream exportData;
exportData.open(path + "\\HardwareID.json");
if (exportData.is_open()) {
exportData << HardwareIDJSON;
m_bDataExported = true;
}
else {
DEBUG_PRINT("\nError exporting hardwareID file.\n")
}
exportData.close();
}