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;
}
相关推荐
小欣加油6 小时前
leetcode 面试题01.02判定是否互为字符重排
数据结构·c++·算法·leetcode·职场和发展
王璐WL6 小时前
【c++】c++第一课:命名空间
数据结构·c++·算法
aramae6 小时前
C++ -- 模板
开发语言·c++·笔记·其他
MChine慕青8 小时前
顺序表与单链表:核心原理与实战应用
linux·c语言·开发语言·数据结构·c++·算法·链表
骄傲的心别枯萎10 小时前
RV1126 NO.16:通过多线程同时获取H264和H265码流
linux·c++·音视频·rv1126
落羽的落羽10 小时前
【C++】特别的程序错误处理方式——异常机制
开发语言·c++
空山新雨(大队长)10 小时前
C 语言第一课:hello word c
c++·c·exe
春蕾夏荷_72829772510 小时前
c++ 第三方库与个人封装库
c++·三方库
牵牛老人11 小时前
Qt C++ 复杂界面处理:巧用覆盖层突破复杂界面处理难题之一
数据库·c++·qt
离越词11 小时前
C++day8作业
开发语言·c++·windows