Skip to content

Commit

Permalink
根据设备名的哈希值生成 Guid
Browse files Browse the repository at this point in the history
  • Loading branch information
lanthora committed Dec 18, 2023
1 parent 2e842a7 commit e524bab
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/tun/windows.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
#include "utility/address.h"
#include <codecvt>
#include <memory>
#include <openssl/sha.h>
#include <spdlog/fmt/bin_to_hex.h>
#include <spdlog/spdlog.h>
#include <string>
// clang-format off
#include <combaseapi.h>
#include <winsock2.h>
#include <windows.h>
#include <ws2ipdef.h>
Expand Down Expand Up @@ -96,10 +96,10 @@ class WindowsTun {
}

GUID Guid;
if (CoCreateGuid(&Guid) != S_OK) {
spdlog::critical("create guid failed");
return -1;
}
std::string data = "CandyGuid" + this->name;
unsigned char hash[SHA256_DIGEST_LENGTH];
SHA256((unsigned char *)data.c_str(), data.size(), hash);
memcpy(&Guid, hash, sizeof(Guid));
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
this->adapter = WintunCreateAdapter(converter.from_bytes(this->name).c_str(), L"Candy", &Guid);
if (!this->adapter) {
Expand Down

0 comments on commit e524bab

Please sign in to comment.