学习示例
VMProtect SDK 演示 - 房有亮
https://bbs.pediy.com/thread-201173.htm
这个例子完整的示例了VMP-SDK的应用,
但在实际应用中, 常常使用的并不是SDK自带的验证, 此验证仅适合于单机验证.
VMProtect 下载
https://down.52pojie.cn/?query=vmp
下载地址: https://down.52pojie.cn/Tools/Packers/VMProtect_Ultimate_v3.2.0_x32_x64_Build_976_Retail_Licensed.7z
QT测试VMP-SDK
在QT测试用例中, 仅测试了
CRC校验
虚拟保护
变异保护
虚拟加变异保护
保护字符串
获取硬件ID
监测硬件ID
VMP测试
汇编对比
暂不探究字符串加密算法
源码
加密前
加密后
示例代码展示
完整工程
widget.cpp
#ifdef WIN32
#pragma execution_character_set("utf-8")
#endif
#include "widget.h"
#include "ui_widget.h"
#include <string>
#include <Windows.h>
#include "VMP_SDK/VMProtectSDK.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
}
Widget::~Widget()
{
delete ui;
}
#include <QDebug>
#include <QMessageBox>
//##############################################################################
//功能:内存CRC
//##############################################################################
void Widget::on_pushButton_clicked()
{
qDebug() << "on_pushButton_clicked";
if (VMProtectIsValidImageCRC())
{
QMessageBox::warning(this, "TestSDK", "内存 CRC 效验成功");
}
else
{
QMessageBox::warning(this, "TestSDK", "内存 CRC 效验失败");
}
}
//##############################################################################
//功能:普通保护
//##############################################################################
void Widget::on_pushButton_2_clicked()
{
qDebug() << "on_pushButton_2_clicked";
VMProtectBegin("OnBnClickedButton4");
QMessageBox::warning(this, "TestSDK", "VMProtectBegin");
VMProtectEnd();
}
//##############################################################################
//功能:虚拟保护
//##############################################################################
void Widget::on_pushButton_3_clicked()
{
qDebug() << "on_pushButton_3_clicked";
VMProtectBeginVirtualization("OnBnClickedButton5");
QMessageBox::warning(this, "TestSDK", "VMProtectBeginVirtualization");
VMProtectEnd();
}
//##############################################################################
//功能:变异保护
//##############################################################################
void Widget::on_pushButton_4_clicked()
{
qDebug() << "on_pushButton_4_clicked";
VMProtectBeginMutation("OnBnClickedButton6");
QMessageBox::warning(this, "TestSDK", "VMProtectBeginMutation");
VMProtectEnd();
}
//##############################################################################
//功能:虚拟加变异
//##############################################################################
void Widget::on_pushButton_5_clicked()
{
qDebug() << "on_pushButton_5_clicked";
VMProtectBeginUltra("OnBnClickedButton7");
QMessageBox::warning(this, "TestSDK", "VMProtectBeginUltra");
VMProtectEnd();
}
//##############################################################################
//功能:保护字符串
//##############################################################################
void Widget::on_pushButton_6_clicked()
{
qDebug() << "on_pushButton_6_clicked";
//__asm int 3;
QMessageBox::warning(this, "TestSDK", QString::fromStdWString(std::wstring(VMProtectDecryptStringW(L"保护字符串"))));
}
//##############################################################################
//功能:获取硬件ID
//##############################################################################
void Widget::on_pushButton_7_clicked()
{
qDebug() << "on_pushButton_7_clicked";
char *pHardWareString = NULL;
UINT Size = VMProtectGetCurrentHWID(NULL, 0);
pHardWareString = new char[Size];
VMProtectGetCurrentHWID(pHardWareString, Size);
QString str(pHardWareString);
ui->lineEdit->setText(str);
}
//########################################################################################################################################
//功能:检测硬件ID
//########################################################################################################################################
void Widget::on_pushButton_8_clicked()
{
qDebug() << "on_pushButton_8_clicked";
VMProtectBeginUltra("OnBnClickedButton10");
QString str;
str = ui->lineEdit->text();
char *pHardWareString = NULL;
UINT Size = VMProtectGetCurrentHWID(NULL, 0);
pHardWareString = new char[Size];
VMProtectGetCurrentHWID(pHardWareString, Size);
QString strHardWare(pHardWareString);
if (strHardWare == str)
{
QMessageBox::warning(this, "TestSDK", QString::fromStdWString(std::wstring(VMProtectDecryptStringW(L"您的机器已被授权"))));
}
else
{
QMessageBox::warning(this, "TestSDK",QString::fromStdWString(std::wstring( VMProtectDecryptStringW(L"您的机器未被授权"))));
}
VMProtectEnd();
}
稍作修改的VMProtectSDK.h
把lib放置于 .h
头文件同一目录, 然后包含头文件使用即可
#pragma once
// 用于自动查找到CURL目录下的lib文件
#define LIBPATH(p,f) p##f
#if defined(__APPLE__) || defined(__unix__)
#define VMP_IMPORT
#define VMP_API
#define VMP_WCHAR unsigned short
#else
#define VMP_IMPORT __declspec(dllimport)
#define VMP_API __stdcall
#define VMP_WCHAR wchar_t
#ifdef _WIN64
#pragma comment(lib, LIBPATH(__FILE__, ".dir/../VMProtectSDK64.lib"))
#else
#pragma comment(lib, LIBPATH(__FILE__, ".dir/../VMProtectSDK32.lib"))
#endif // _WIN64
#endif // __APPLE__ || __unix__
#ifdef __cplusplus
extern "C" {
#endif
// protection
VMP_IMPORT void VMP_API VMProtectBegin(const char *);
VMP_IMPORT void VMP_API VMProtectBeginVirtualization(const char *);
VMP_IMPORT void VMP_API VMProtectBeginMutation(const char *);
VMP_IMPORT void VMP_API VMProtectBeginUltra(const char *);
VMP_IMPORT void VMP_API VMProtectBeginVirtualizationLockByKey(const char *);
VMP_IMPORT void VMP_API VMProtectBeginUltraLockByKey(const char *);
VMP_IMPORT void VMP_API VMProtectEnd(void);
// utils
VMP_IMPORT bool VMP_API VMProtectIsProtected();
VMP_IMPORT bool VMP_API VMProtectIsDebuggerPresent(bool);
VMP_IMPORT bool VMP_API VMProtectIsVirtualMachinePresent(void);
VMP_IMPORT bool VMP_API VMProtectIsValidImageCRC(void);
VMP_IMPORT const char * VMP_API VMProtectDecryptStringA(const char *value);
VMP_IMPORT const VMP_WCHAR * VMP_API VMProtectDecryptStringW(const VMP_WCHAR *value);
VMP_IMPORT bool VMP_API VMProtectFreeString(const void *value);
// licensing
enum VMProtectSerialStateFlags
{
SERIAL_STATE_SUCCESS = 0,
SERIAL_STATE_FLAG_CORRUPTED = 0x00000001,
SERIAL_STATE_FLAG_INVALID = 0x00000002,
SERIAL_STATE_FLAG_BLACKLISTED = 0x00000004,
SERIAL_STATE_FLAG_DATE_EXPIRED = 0x00000008,
SERIAL_STATE_FLAG_RUNNING_TIME_OVER = 0x00000010,
SERIAL_STATE_FLAG_BAD_HWID = 0x00000020,
SERIAL_STATE_FLAG_MAX_BUILD_EXPIRED = 0x00000040,
};
#pragma pack(push, 1)
typedef struct
{
unsigned short wYear;
unsigned char bMonth;
unsigned char bDay;
} VMProtectDate;
typedef struct
{
int nState; // VMProtectSerialStateFlags
VMP_WCHAR wUserName[256]; // user name
VMP_WCHAR wEMail[256]; // email
VMProtectDate dtExpire; // date of serial number expiration
VMProtectDate dtMaxBuild; // max date of build, that will accept this key
int bRunningTime; // running time in minutes
unsigned char nUserDataLength; // length of user data in bUserData
unsigned char bUserData[255]; // up to 255 bytes of user data
} VMProtectSerialNumberData;
#pragma pack(pop)
VMP_IMPORT int VMP_API VMProtectSetSerialNumber(const char *serial);
VMP_IMPORT int VMP_API VMProtectGetSerialNumberState();
VMP_IMPORT bool VMP_API VMProtectGetSerialNumberData(VMProtectSerialNumberData *data, int size);
VMP_IMPORT int VMP_API VMProtectGetCurrentHWID(char *hwid, int size);
// activation
enum VMProtectActivationFlags
{
ACTIVATION_OK = 0,
ACTIVATION_SMALL_BUFFER,
ACTIVATION_NO_CONNECTION,
ACTIVATION_BAD_REPLY,
ACTIVATION_BANNED,
ACTIVATION_CORRUPTED,
ACTIVATION_BAD_CODE,
ACTIVATION_ALREADY_USED,
ACTIVATION_SERIAL_UNKNOWN,
ACTIVATION_EXPIRED,
ACTIVATION_NOT_AVAILABLE
};
VMP_IMPORT int VMP_API VMProtectActivateLicense(const char *code, char *serial, int size);
VMP_IMPORT int VMP_API VMProtectDeactivateLicense(const char *serial);
VMP_IMPORT int VMP_API VMProtectGetOfflineActivationString(const char *code, char *buf, int size);
VMP_IMPORT int VMP_API VMProtectGetOfflineDeactivationString(const char *serial, char *buf, int size);
#ifdef __cplusplus
}
#endif