VMProtect HWID 解析(C++)

0、VMProtect HWID是什么

  • VMProtect:一款商业软件加壳工具,保护软件不被破解
  • HWID:硬件码,设备的唯一标识,常常用于软件绑定白名单或黑名单

VMProtectSDK提供了生成HWID的API,但是没提供HWID分别对应每个设备的ID,所以得自己解析HWID

1、分析HWID组成字段

首先看看VMP Ultimate软件显示的样子

硬件ID(实际上就是Base64):eENCrBVf28czwzPH3pgmMMInHQVGM3aPguQjAGIAkpc=

解码之后:

通过观察可以发现:

  1. 4个字节为1组,即uint32_t
  2. 数据是小端存储
  3. 字段存在偏移

再做一个表简单分析一下

item 解码 实际 offset
CPU AC424378 AC424378 0
Host C7DB5F15 C7DB5F14 -1
HDD C733C333 C733C330 -3
以太网 302698DE 302698DC -2
以太网 ... ... -2
以太网 ... ... -2
以太网 ... ... -2

通过上表一眼盯真,CPU、Host、HDD、以太网(即网卡)的偏移各有不同,但都很简单

2、源码

根据以上结论,编写了用于解析HWID的C++代码

可以去godbolt进行C++代码线上编译测试

GCC 14.2+,参数是:-std=c++23 -g -O0

cpp 复制代码
#include <iostream>
#include <format>
#include <vector>
#include <string>
#include <span>
#include <ranges>

using namespace std;

struct HWID
{
    static constexpr size_t STRIDE = 4;
    using ItemType = std::array<uint8_t, STRIDE>;

    template <typename T>
    HWID(std::span<T> data)
    {
        auto bytes = std::span<uint8_t>(reinterpret_cast<uint8_t*>(data.data()), data.size_bytes());
        auto begin = bytes.begin();
        std::copy(begin, begin + STRIDE, cpu.begin());
        std::copy(begin + STRIDE, begin + STRIDE * 2, host.begin());
        std::copy(begin + STRIDE * 2, begin + STRIDE * 3, hdd.begin());
        const auto num_network_adapters = bytes.size_bytes() / STRIDE - 3;
        network_adapters.reserve(num_network_adapters);
        for (ItemType tmp_item; size_t i : std::views::iota(12llu, bytes.size_bytes()) | std::views::stride(STRIDE))
        {
            std::copy(begin + i, begin + i + STRIDE, tmp_item.begin());
            tmp_item[0] -= 2;
            network_adapters.push_back(tmp_item);
        }
        cpu[0] -= 0;
        host[0] -= 1;
        hdd[0] -= 3;
    }

    auto ToString() noexcept -> std::string
    {
        std::string str = std::format("{:08X}\n{:08X}\n{:08X}",
                                      *reinterpret_cast<uint32_t*>(cpu.data()),
                                      *reinterpret_cast<uint32_t*>(host.data()),
                                      *reinterpret_cast<uint32_t*>(hdd.data()));
        for (const auto& network_adapter : network_adapters)
        {
            str += std::format("\n{:08X}", *reinterpret_cast<const uint32_t*>(network_adapter.data()));
        }
        return str;
    }

    ItemType cpu, host, hdd;
    std::vector<ItemType> network_adapters;
};

unsigned char hwid_bytes[32] = {
	// Offset 0x00000000 to 0x0000001E
	0x78, 0x43, 0x42, 0xAC, 0x15, 0x5F, 0xDB, 0xC7, 0x33, 0xC3, 0x33, 0xC7,
	0xDE, 0x98, 0x26, 0x30, 0xC2, 0x27, 0x1D, 0x05, 0x46, 0x33, 0x76, 0x8F,
	0x82, 0xE4, 0x23, 0x00, 0x62, 0x00, 0x92, 0x97
};

int main() {
  std::span<uint8_t> data{hwid_bytes, 32};
  HWID hwid{data};
  std::cout << hwid.ToString() <<std::endl;

  return 0;
}
相关推荐
-dzk-17 小时前
【代码随想录】LC 59.螺旋矩阵 II
c++·线性代数·算法·矩阵·模拟
m0_7066532318 小时前
C++编译期数组操作
开发语言·c++·算法
qq_4232339018 小时前
C++与Python混合编程实战
开发语言·c++·算法
m0_7155753419 小时前
分布式任务调度系统
开发语言·c++·算法
CSDN_RTKLIB19 小时前
简化版unique_ptr说明其本质
c++
naruto_lnq19 小时前
泛型编程与STL设计思想
开发语言·c++·算法
m0_7487080520 小时前
C++中的观察者模式实战
开发语言·c++·算法
时光找茬20 小时前
【瑞萨AI挑战赛-FPB-RA6E2】+ 从零开始:FPB-RA6E2 开箱测评与 e2 studio 环境配置
c++·单片机·边缘计算
qq_5375626720 小时前
跨语言调用C++接口
开发语言·c++·算法
猷咪21 小时前
C++基础
开发语言·c++