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;
}
相关推荐
OneQ6661 小时前
C++讲解---创建日期类
开发语言·c++·算法
Coding小公仔4 小时前
C++ bitset 模板类
开发语言·c++
菜鸟看点4 小时前
自定义Cereal XML输出容器节点
c++·qt
悲伤小伞5 小时前
linux_git的使用
linux·c语言·c++·git
ysa0510305 小时前
数论基础知识和模板
数据结构·c++·笔记·算法
小小小小王王王8 小时前
求猪肉价格最大值
数据结构·c++·算法
岁忧9 小时前
(LeetCode 面试经典 150 题 ) 58. 最后一个单词的长度 (字符串)
java·c++·算法·leetcode·面试·go
码农编程录10 小时前
【c/c++3】类和对象,vector容器,类继承和多态,systemd,std&boost
c++
??tobenewyorker11 小时前
力扣打卡第二十一天 中后遍历+中前遍历 构造二叉树
数据结构·c++·算法·leetcode
oioihoii12 小时前
C++11 forward_list 从基础到精通:原理、实践与性能优化
c++·性能优化·list