I’m using libcurl to download a json file and then I want to get the hwids of the json by using nlohmann json and there is where the exception happens and I can’t figure it out on my own.
I’m pretty new to c++ so please don’t bomb me away thanks.
My application gets detected as Virus, I think it’s because of fopen, would be nice if someone could fix this.
Also I would really appreciate, if you could optimize my code thanks!
My Utils.cpp
#include <fcntl.h>
#include <io.h>
#include <filesystem>
#include "HWID.h"
#define PathAppendW
#define CURL_STATICLIB
#define SHGetFolderPathW
#include "curl/curl.h";
namespace fs = std::filesystem;
static size_t write_data(void* ptr, size_t size, size_t nmemb, void* stream)
{
size_t written = fwrite(ptr, size, nmemb, (FILE*)stream);
return written;
}
void savefile(std::string path) {
char c[MAX_PATH];
strcpy(c, path.c_str());
CURL* curl_handle;
static const char* pagefilename = c;
curl_global_init(CURL_GLOBAL_ALL);
/* init the curl session */
curl_handle = curl_easy_init();
/* set URL to get here */
curl_easy_setopt(curl_handle, CURLOPT_URL, "http://anix.bplaced.net/hwids.json");
/* Switch on full protocol/debug output while testing */
curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1L);
/* disable progress meter, set to 0L to enable it */
curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L);
/* send all data to this function */
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);
/* open the file */
FILE* pagefile = fopen(pagefilename, "w");
if (pagefile) {
/* write the page body to this file handle */
curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, pagefile);
/* get it! */
curl_easy_perform(curl_handle);
/* close the header file */
}
/* cleanup curl stuff */
curl_easy_cleanup(curl_handle);
curl_global_cleanup();
}
int main()
{
std::string appdata = getenv("APPDATA");
const std::string dir = appdata + "AnixCSGO";
fs::create_directories(dir);
std::string file = dir + "hwids.json";
savefile(file);
HWID hwid;
if (hwid.isinList(file)) hwid.printHWID();
}
My HWID.cpp
#include "HWID.h"
void HWID::hwidList(std::string file) {
std::ifstream reader(file);
json j;
reader >> j;
reader.close();
for (int i = 0; i < j["csgo"].size(); i++) {
hwids.push_back(j.at("csgo")[i].at("HWID"));
}
}
void HWID::getHWID() {
TCHAR volumeName[MAX_PATH + 1] = {}; // catch info of harddrive
TCHAR systemName[MAX_PATH + 1] = { 0 };
DWORD maxlen = 0; // max length of hwid
DWORD systemflags = 0; // user infos
if (GetVolumeInformation(_T("C:"), volumeName, ARRAYSIZE(volumeName), &hwidnum, &maxlen, &systemflags, systemName, ARRAYSIZE(systemName)));
}
boolean HWID::isinList(std::string file) {
hwidList(file);
getHWID();
if (find(hwids.begin(), hwids.end(), std::to_string(hwidnum)) != hwids.end()) { // check if hwid is on the list
return true;
}
return false;
}
void HWID::printHWID() {
getHWID();
std::cout << "Your HWID: " << hwidnum << "n";
}
Source: Windows Questions C++