Initial commit

This commit is contained in:
Alukym
2023-05-12 20:16:10 +08:00
commit a8433f06ee
1167 changed files with 1036549 additions and 0 deletions

View File

@ -0,0 +1,35 @@
using System.Reflection;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("VMProtect.SDK")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("VMProtect.SDK")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("544f194e-b3a9-40a8-8f75-bd12b10868be")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

459
sdk/VMProtect.SDK/Sdk.cs Normal file
View File

@ -0,0 +1,459 @@
using System;
using System.Globalization;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedParameter.Global
// ReSharper disable UnusedMember.Global
// ReSharper disable once CheckNamespace
namespace VMProtect
{
/// <summary>
/// Serial number status flags
/// </summary>
[Flags]
public enum SerialState
{
/// <summary>
/// No problems.
/// </summary>
Success = 0x00000000,
/// <summary>
/// Licensing module is corrupted. This may be caused by cracking attempts. Usually you will never get this flag.
/// </summary>
Corrupted = 0x00000001,
/// <summary>
/// Serial number is invalid. You will get this flag if licensing module will be unable to decrypt serial number or
/// if the serial number is not yet set or it is empty.
/// </summary>
Invalid = 0x00000002,
/// <summary>
/// Serial number is correct, but it was blacklisted in VMProtect.
/// </summary>
Blacklisted = 0x00000004,
/// <summary>
/// Serial number is expired. You will get this flag if serial number has expiration date chunk and this date is in the past.
/// You may read the expiration date by calling GetSerialNumberData() function.
/// </summary>
DateExpired = 0x00000008,
/// <summary>
/// Running time limit for this session is over. You may read limit value by calling GetSerialNumberData() function.
/// </summary>
RunningTimeOver = 0x00000010,
/// <summary>
/// Serial number is locked to another hardware identifier.
/// </summary>
BadHwid = 0x00000020,
/// <summary>
/// Serial number will not work with this version of application, because it has "Max Build Date" block and the application was
/// build after those date. You may read maximal build date by calling GetSerialNumberData() function.
/// </summary>
MaxBuildExpired = 0x00000040,
};
/// <summary>
/// Serial number contents
/// </summary>
public class SerialNumberData
{
/// <summary>
/// Serial number status
/// </summary>
public SerialState State;
/// <summary>
/// End user name
/// </summary>
public string UserName;
/// <summary>
/// End user E-Mail
/// </summary>
public string EMail;
/// <summary>
/// Serial number expiration date.
/// </summary>
public DateTime Expires;
/// <summary>
/// Max date of build, that will accept this key
/// </summary>
public DateTime MaxBuild;
/// <summary>
/// Running time in minutes
/// </summary>
public int RunningTime;
/// <summary>
/// Up to 255 bytes of user data
/// </summary>
public byte[] UserData;
public SerialNumberData()
{
State = SerialState.Invalid;
Expires = DateTime.MaxValue;
MaxBuild = DateTime.MaxValue;
RunningTime = 0;
UserData = new byte[0];
UserName = "";
EMail = "";
}
};
/// <summary>
/// Activation API status codes
/// </summary>
public enum ActivationStatus
{
/// <summary>
/// Activation successful, the serial field contains a serial number.
/// </summary>
Ok,
/// <summary>
/// The activation module was unable to connect the Web License Manager.
/// </summary>
NoConnection,
/// <summary>
/// The server returned unexpected reply. This means configuration problems or probably a cracking attempt.
/// </summary>
BadReply,
/// <summary>
/// The activation code is blocked on the server. This doesn't mean that the number of possible activations is exceeded,
/// this means that this exactly code is banned by the vendor, so the user is trying to cheat you.
/// </summary>
Banned,
/// <summary>
/// Something goes really wrong here. The error means that the internal activation stuff is not working,
/// it is not safe to continue with the activation, registration and so on.
/// </summary>
Corrupted,
/// <summary>
/// The code has been successfully passed to the server and it was unable to find it in the database.
/// Probably the user made a mistake, so it is worth asking the user to check the entered code for mistakes.
/// </summary>
BadCode,
/// <summary>
/// The code has been used too many times and cannot be used more. This doesn't mean the code is bad or banned, it is OK.
/// The user may contact vendor to ask/purchase more activations, or the user may deactivate some installations to increase
/// the number of activations available for that code.
/// </summary>
AlreadyUsed,
/// <summary>
/// This is the deactivation error code that means that the server can't find the serial number that the user tries to deactivate.
/// </summary>
SerialUnknown,
/// <summary>
/// The code is expired.
/// </summary>
Expired,
/// <summary>
/// Activation/deactivation features are not available.
/// </summary>
NotAvailable
};
public static class SDK
{
private static bool _gSerialIsCorrect;
private static bool _gSerialIsBlacklisted;
private static readonly Int32 GTimeOfStart = Environment.TickCount;
private static string GetIniValue(string valueName, string defaultValue = null)
{
var ini = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "VMProtectLicense.ini");
if (!File.Exists(ini))
return defaultValue;
var contents = File.ReadAllText(ini);
var pattern = new Regex(@"
^ # Beginning of the line
((?:\[) # Section Start
(?<Section>[^\]]*) # Actual Section text into Section Group
(?:\]) # Section End then EOL/EOB
(?:[\r\n]{0,}|\Z)) # Match but don't capture the CRLF or EOB
( # Begin capture groups (Key Value Pairs)
(?!\[) # Stop capture groups if a [ is found; new section
(?<Key>[^=]*?) # Any text before the =, matched few as possible
(?:=) # Get the = now
(?<Value>[^\r\n]*) # Get everything that is not an Line Changes
(?:[\r\n]{0,4}) # MBDC \r\n
)+ # End Capture groups", RegexOptions.IgnorePatternWhitespace | RegexOptions.Multiline);
var ret = defaultValue;
foreach (Match m in pattern.Matches(contents))
{
var section = m.Groups["Section"].Value;
if(section != "TestLicense")
continue;
var i = 0;
foreach (Capture c in m.Groups["Key"].Captures)
{
if (c.Value == valueName)
{
ret = m.Groups["Value"].Captures[i].ToString();
break;
}
i++;
}
break;
}
return ret;
}
private static bool GetIniDateTime(string valueName, out DateTime dt)
{
return DateTime.TryParseExact(GetIniValue(valueName), "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt);
}
private static bool GetIniTimeLimit(out int nTimeLimit)
{
var sTimeLimit = GetIniValue("TimeLimit");
nTimeLimit = 0;
if (string.IsNullOrEmpty(sTimeLimit))
return false;
int.TryParse(sTimeLimit, out nTimeLimit);
if (nTimeLimit < 0)
nTimeLimit = 0;
else if (nTimeLimit > 255)
nTimeLimit = 255;
return true;
}
/// <summary>
/// !!! документировать здесь и в справке
/// </summary>
/// <returns></returns>
public static bool IsProtected() { return false; }
/// <summary>
/// Detect if the application is running in the debugger.
/// The result of its work (True/False) can be processed by the protection mechanisms built into the application.
/// If CheckKernelMode=False, the function checks for the user-mode debugger (OllyDBG, WinDBG, etc.).
/// If CheckKernelMode=True, both user-mode and kernel-mode debuggers will be detected (SoftICE, Syser, etc.).
/// </summary>
/// <returns></returns>
public static bool IsDebuggerPresent(bool checkKernelMode) { return System.Diagnostics.Debugger.IsAttached; }
/// <summary>
/// Detect if the application is running in a virtual environment: VMware, Virtual PC, VirtualBox, Sandboxie, Hyper-V.
/// The result of its work (True/False) can be processed by the protection mechanisms built into the application.
/// </summary>
public static bool IsVirtualMachinePresent() { return false; }
/// <summary>
/// Detect changes made in the application memory. The result of its work (True/False)
/// can be processed by the protection mechanisms built into the application.
/// </summary>
public static bool IsValidImageCRC() { return true; }
/// <summary>
/// Decrypt string constant. You have to add this constant to a list of protected objects.
/// </summary>
/// <param name="value">constant (not variable!) for decryption</param>
/// <returns>decrypted string</returns>
public static string DecryptString(string value) { return value; }
/// Pass serial number to the licensing module
/// </summary>
/// <param name="serial">serial number</param>
/// <returns>serial number state</returns>
public static SerialState SetSerialNumber(string serial)
{
_gSerialIsCorrect = false;
_gSerialIsBlacklisted = false;
if (string.IsNullOrEmpty(serial))
return SerialState.Invalid;
var bufSerial = new StringBuilder(2048);
foreach (var c in serial.ToCharArray())
{
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '+' || c == '/' || c == '=')
bufSerial.Append(c);
}
var iniSerial = GetIniValue("AcceptedSerialNumber", "serialnumber");
_gSerialIsCorrect = bufSerial.ToString() == iniSerial;
var iniBlackSerial = GetIniValue("BlackListedSerialNumber");
_gSerialIsBlacklisted = bufSerial.ToString() == iniBlackSerial;
return GetSerialNumberState();
}
/// <summary>
/// Get current serial number state
/// </summary>
/// <returns>serial number state</returns>
public static SerialState GetSerialNumberState()
{
if (!_gSerialIsCorrect)
return SerialState.Invalid;
if (_gSerialIsBlacklisted)
return SerialState.Blacklisted;
var res = SerialState.Success;
int runningTime;
if(GetIniTimeLimit(out runningTime))
{
int d = (Environment.TickCount - GTimeOfStart) / 1000 / 60; // minutes
if (runningTime <= d)
res |= SerialState.RunningTimeOver;
}
DateTime dt;
if (GetIniDateTime("ExpDate", out dt)) {
if (DateTime.Now > dt)
res |= SerialState.DateExpired;
}
if (GetIniDateTime("MaxBuildDate", out dt)) {
if (DateTime.Now > dt)
res |= SerialState.MaxBuildExpired;
}
if (GetIniValue("KeyHWID") != GetIniValue("MyHWID"))
res |= SerialState.BadHwid;
return res;
}
/// <summary>
/// Convert content of serial number to the structure
/// </summary>
/// <param name="data">struct to fill out</param>
/// <returns>true (always) or exception</returns>
public static bool GetSerialNumberData(out SerialNumberData data)
{
data = new SerialNumberData();
data.State = GetSerialNumberState();
if ((data.State & (SerialState.Invalid | SerialState.Blacklisted)) != 0)
return true; // do not need to read the rest
data.UserName = GetIniValue("UserName");
data.EMail = GetIniValue("EMail");
GetIniTimeLimit(out data.RunningTime);
DateTime dt;
if (GetIniDateTime("ExpDate", out dt)) {
data.Expires = dt;
}
if (GetIniDateTime("MaxBuildDate", out dt)) {
data.MaxBuild = dt;
}
var sUserData = GetIniValue("UserData");
if (!string.IsNullOrEmpty(sUserData)) {
var len = sUserData.Length;
if (len > 0 && len % 2 == 0 && len <= 0x200) // otherwise UserData is empty or has bad length
{
data.UserData = new byte[len / 2];
for (var index = 0; index < data.UserData.Length; index++)
{
var byteValue = sUserData.Substring(index * 2, 2);
data.UserData[index] = byte.Parse(byteValue, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
}
}
}
return true;
}
/// <summary>
/// Get hardware identifier (hwid) of the current computer
/// </summary>
/// <returns>hwid as string</returns>
public static string GetCurrentHWID() { return GetIniValue("MyHWID", "myhwid"); }
/// <summary>
/// Passes the activation code to the server for online activation and returns the serial number for that exactly installation.
/// </summary>
/// <param name="code">activation code, in</param>
/// <param name="serial">serial number, out</param>
/// <returns>activation status</returns>
public static ActivationStatus ActivateLicense(string code, out string serial)
{
serial = "";
if (code != GetIniValue("AcceptedActivationCode", "activationcode"))
return ActivationStatus.BadCode;
serial = GetIniValue("AcceptedSerialNumber", "serialnumber");
return ActivationStatus.Ok;
}
/// <summary>
/// Passes the serial number to the server for online deactivation.
/// </summary>
/// <param name="serial">contains the serial number (not the code) obtained from the server during the activation process</param>
/// <returns>deactivation status</returns>
public static ActivationStatus DeactivateLicense(string serial) { return ActivationStatus.Ok; }
/// <summary>
/// Same as ActivateLicense, but don't trying to connect the server. Instead, it returns a "magic" string that needs to be copy-pasted
/// to the web browser, showing the Web License Manager offline activation page.
/// </summary>
/// <param name="code">activation code, in</param>
/// <param name="buf">magic offline activation string, out</param>
/// <returns>operation status</returns>
public static ActivationStatus GetOfflineActivationString(string code, out string buf)
{
buf = "Sdk OfflineActivationString";
return ActivationStatus.Ok;
}
/// <summary>
/// Same as DeactivateLicense, but don't trying to connect the server. Instead, it returns a "magic" string that needs to be copy-pasted
/// to the web browser, showing the Web License Manager offline deactivation page.
/// </summary>
/// <param name="serial">contains the serial number (not the code) obtained from the server during the activation process, in</param>
/// <param name="buf">magic offline deactivation string, out</param>
/// <returns>operation status</returns>
public static ActivationStatus GetOfflineDeactivationString(string serial, out string buf)
{
buf = "Sdk GetOfflineDeactivationString";
return ActivationStatus.Ok;
}
}
/// <summary>
/// The marker that starts the protected section of the code, must be called before the first instruction
/// (calling a procedure or function) in the protected block of the code.
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public sealed class Begin : Attribute { }
/// <summary>
/// The marker that starts the protected section of the code with the predefined "virtualization" compilation type.
/// It is impossible to change the compilation type specified by the marker later in VMPotect.
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public sealed class BeginVirtualization : Attribute { }
/// <summary>
/// The marker that starts the protected section of the code with the predefined "mutation" compilation type.
/// It is impossible to change the compilation type specified by the marker later in VMPotect.
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public sealed class BeginMutation : Attribute { }
/// <summary>
/// The marker that starts the protected section of the code with the predefined "ultra" (mutation + virtualization) compilation type.
/// It is impossible to change the compilation type specified by the marker later in VMPotect.
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public sealed class BeginUltra : Attribute { }
/// <summary>
/// The marker that starts the protected section of the code with the predefined "virtualization" compilation type
/// and the option "Lock to key". It is impossible to change the compilation type specified by the marker later in VMPotect.
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public sealed class BeginVirtualizationLockByKey : Attribute { }
/// <summary>
/// The marker that starts the protected section of the code with the predefined "ultra" (mutation + virtualization) compilation type
/// and the option "Lock to key". It is impossible to change the compilation type specified by the marker later in VMPotect.
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public sealed class BeginUltraLockByKey : Attribute { }
}

View File

@ -0,0 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{946D07D4-1AE4-4FC3-9A8C-563B5F64B0B5}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>VMProtect.SDK</RootNamespace>
<AssemblyName>VMProtect.SDK</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<PlatformTarget>AnyCPU</PlatformTarget>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\bin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Sdk.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

96
sdk/VMProtectDDK.h Normal file
View File

@ -0,0 +1,96 @@
#pragma once
#define VMP_IMPORT __declspec(dllimport)
#define VMP_API __stdcall
#define VMP_WCHAR wchar_t
#ifdef _WIN64
#pragma comment(lib, "VMProtectDDK64.lib")
#else
#pragma comment(lib, "VMProtectDDK32.lib")
#endif // _WIN64
#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 BOOLEAN VMP_API VMProtectIsProtected();
VMP_IMPORT BOOLEAN VMP_API VMProtectIsDebuggerPresent(BOOLEAN); // IRQL = PASSIVE_LEVEL
VMP_IMPORT BOOLEAN VMP_API VMProtectIsVirtualMachinePresent(void); // IRQL = PASSIVE_LEVEL
VMP_IMPORT BOOLEAN 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 BOOLEAN 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 BOOLEAN 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

77
sdk/VMProtectSDK.bas Normal file
View File

@ -0,0 +1,77 @@
' protection
Public Declare Sub VMProtectBegin Lib "VMProtectSDK32.dll" (ByVal Ptr As Long)
Public Declare Sub VMProtectBeginVirtualization Lib "VMProtectSDK32.dll" (ByVal Ptr As Long)
Public Declare Sub VMProtectBeginMutation Lib "VMProtectSDK32.dll" (ByVal Ptr As Long)
Public Declare Sub VMProtectBeginUltra Lib "VMProtectSDK32.dll" (ByVal Ptr As Long)
Public Declare Sub VMProtectBeginVirtualizationLockByKey Lib "VMProtectSDK32.dll" (ByVal Ptr As Long)
Public Declare Sub VMProtectBeginUltraLockByKey Lib "VMProtectSDK32.dll" (ByVal Ptr As Long)
Public Declare Sub VMProtectEnd Lib "VMProtectSDK32.dll" ()
' utils
Public Declare Function VMProtectIsProtected Lib "VMProtectSDK32.dll" () As Boolean
Public Declare Function VMProtectIsDebuggerPresent Lib "VMProtectSDK32.dll" (ByVal Value As Boolean) As Boolean
Public Declare Function VMProtectIsVirtualMachinePresent Lib "VMProtectSDK32.dll" () As Boolean
Public Declare Function VMProtectIsValidImageCRC Lib "VMProtectSDK32.dll" () As Boolean
Public Declare Function VMProtectDecryptString Lib "VMProtectSDK32.dll" Alias "VMProtectDecryptStringW" (ByVal Ptr As Long) As Long
Public Declare Function VMProtectFreeString Lib "VMProtectSDK32.dll" (ByVal Ptr As Long) As Boolean
' licensing
Public Const SERIAL_STATE_FLAG_CORRUPTED = 1
Public Const SERIAL_STATE_FLAG_INVALID = 2
Public Const SERIAL_STATE_FLAG_BLACKLISTED = 4
Public Const SERIAL_STATE_FLAG_DATE_EXPIRED = 8
Public Const SERIAL_STATE_FLAG_RUNNING_TIME_OVER = 16
Public Const SERIAL_STATE_FLAG_BAD_HWID = 32
Public Const SERIAL_STATE_FLAG_MAX_BUILD_EXPIRED = 64
Public Type VMProtectDate
wYear As Integer
bMonth As Byte
bDay As Byte
End Type
Public Type VMProtectSerialNumberData
nState As Long
wUserName(1 To 256) As Integer
wEMail(1 To 256) As Integer
dtExpire As VMProtectDate
dtMaxBuild As VMProtectDate
bRunningTime As Long
nUserDataLength As Byte
bUserData(1 To 255) As Byte
End Type
Public Declare Function VMProtectSetSerialNumber Lib "VMProtectSDK32.dll" (ByVal Serial As String) As Long
Public Declare Function VMProtectGetSerialNumberState Lib "VMProtectSDK32.dll" () As Long
Public Declare Function VMProtectGetSerialNumberData Lib "VMProtectSDK32.dll" (ByRef Data As VMProtectSerialNumberData, ByVal Size As Long) As Boolean
Public Declare Function VMProtectGetCurrentHWID Lib "VMProtectSDK32.dll" (ByVal HWID As String, ByVal Size As Long) As Long
' activation
Public Const ACTIVATION_OK = 0
Public Const ACTIVATION_SMALL_BUFFER = 1
Public Const ACTIVATION_NO_CONNECTION = 2
Public Const ACTIVATION_BAD_REPLY = 3
Public Const ACTIVATION_BANNED = 4
Public Const ACTIVATION_CORRUPTED = 5
Public Const ACTIVATION_BAD_CODE = 6
Public Const ACTIVATION_ALREADY_USED = 7
Public Const ACTIVATION_SERIAL_UNKNOWN = 8
Public Const ACTIVATION_EXPIRED = 9
Public Const ACTIVATION_NOT_AVAILABLE = 10
Public Declare Function VMProtectActivateLicense Lib "VMProtectSDK32.dll" (ByVal Code As String, ByVal Serial As String, ByVal Size As Long) As Long
Public Declare Function VMProtectDeactivateLicense Lib "VMProtectSDK32.dll" (ByVal Serial As String) As Long
Public Declare Function VMProtectGetOfflineActivationString Lib "VMProtectSDK32.dll" (ByVal Code As String, ByVal Buf As String, ByVal Size As Long) As Long
Public Declare Function VMProtectGetOfflineDeactivationString Lib "VMProtectSDK32.dll" (ByVal Serial As String, ByVal Buf As String, ByVal Size As Long) As Long
' StrFromPtr
Private Declare Function StrLen Lib "kernel32.dll" Alias "lstrlenW" (ByVal Str As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (ByVal Dest As Long, ByVal Source As Long, ByVal Length As Long)
Public Function StrFromPtr(ByVal Ptr As Long) As String
Dim res As String
Dim chars As Long
chars = StrLen(Ptr)
res = String$(chars, 0)
CopyMemory StrPtr(res), Ptr, chars * 2
StrFromPtr = res
End Function

102
sdk/VMProtectSDK.h Normal file
View File

@ -0,0 +1,102 @@
#pragma once
#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, "VMProtectSDK64.lib")
#else
#pragma comment(lib, "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

69
sdk/VMProtectSDK.inc Normal file
View File

@ -0,0 +1,69 @@
; protection
VMProtectBegin PROTO :DWORD
VMProtectBeginVirtualization PROTO :DWORD
VMProtectBeginMutation PROTO :DWORD
VMProtectBeginUltra PROTO :DWORD
VMProtectBeginVirtualizationLockByKey PROTO :DWORD
VMProtectBeginUltraLockByKey PROTO :DWORD
VMProtectEnd PROTO
; utils
VMProtectIsProtected PROTO
VMProtectIsDebuggerPresent PROTO :DWORD
VMProtectIsVirtualMachinePresent PROTO
VMProtectIsDebuggerPresent PROTO :DWORD
VMProtectDecryptStringA PROTO :DWORD
VMProtectDecryptStringW PROTO :DWORD
VMProtectFreeString PROTO :DWORD
; licensing
SERIAL_STATE_SUCCESS equ 0
SERIAL_STATE_FLAG_CORRUPTED equ 0x00000001
SERIAL_STATE_FLAG_INVALID equ 0x00000002
SERIAL_STATE_FLAG_BLACKLISTED equ 0x00000004
SERIAL_STATE_FLAG_DATE_EXPIRED equ 0x00000008
SERIAL_STATE_FLAG_RUNNING_TIME_OVER equ 0x00000010
SERIAL_STATE_FLAG_BAD_HWID equ 0x00000020
SERIAL_STATE_FLAG_MAX_BUILD_EXPIRED equ 0x00000040
VMProtectDate STRUCT
wYear WORD ?
bMonth BYTE ?
bDay BYTE ?
VMProtectDate ENDS
VMProtectSerialNumberData STRUCT
nState DWORD ? ; VMProtectSerialStateFlags
wUserName WCHAR[256] ; user name
wEMail WCHAR[256] ; email
dtExpire VMProtectDate <> ; date of serial number expiration
dtMaxBuild VMProtectDate <> ; max date of build, that will accept this key
bRunningTime DWORD ? ; running time in minutes
nUserDataLength BYTE ? ; length of user data in bUserData
bUserData BYTE[255] ? ; up to 255 bytes of user data
VMProtectSerialNumberData ENDS
VMProtectSetSerialNumber PROTO :DWORD
VMProtectGetSerialNumberState PROTO
VMProtectGetSerialNumberData PROTO :DWORD,:DWORD
VMProtectGetCurrentHWID PROTO :DWORD,:DWORD
; activation
ACTIVATION_OK equ 0
ACTIVATION_SMALL_BUFFER equ 1
ACTIVATION_NO_CONNECTION equ 2
ACTIVATION_BAD_REPLY equ 3
ACTIVATION_BANNED equ 4
ACTIVATION_CORRUPTED equ 5
ACTIVATION_BAD_CODE equ 6
ACTIVATION_ALREADY_USED equ 7
ACTIVATION_SERIAL_UNKNOWN equ 8
ACTIVATION_NOT_AVAILABLE equ 9
VMProtectActivateLicense PROTO :DWORD,:DWORD,:DWORD
VMProtectDeactivateLicense PROTO :DWORD
VMProtectGetOfflineActivationString PROTO :DWORD,:DWORD,:DWORD
VMProtectGetOfflineDeactivationString PROTO :DWORD,:DWORD,:DWORD
; libs
includelib VMProtectSDK32.lib

136
sdk/VMProtectSDK.pas Normal file
View File

@ -0,0 +1,136 @@
unit VMProtectSDK;
interface
{$IF NOT DECLARED(PAnsiChar)}
type
PAnsiChar = PUTF8Char;
{$IFEND}
// protection
procedure VMProtectBegin(MarkerName: PAnsiChar); {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF};
procedure VMProtectBeginVirtualization(MarkerName: PAnsiChar); {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF};
procedure VMProtectBeginMutation(MarkerName: PAnsiChar); {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF};
procedure VMProtectBeginUltra(MarkerName: PAnsiChar); {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF};
procedure VMProtectBeginVirtualizationLockByKey(MarkerName: PAnsiChar); {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF};
procedure VMProtectBeginUltraLockByKey(MarkerName: PAnsiChar); {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF};
procedure VMProtectEnd; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF};
// utils
function VMProtectIsProtected: Boolean; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF};
function VMProtectIsDebuggerPresent(CheckKernelMode: Boolean): Boolean; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF};
function VMProtectIsVirtualMachinePresent: Boolean; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF};
function VMProtectIsValidImageCRC: Boolean; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF};
function VMProtectDecryptStringA(Value: PAnsiChar): PAnsiChar; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF};
function VMProtectDecryptStringW(Value: PWideChar): PWideChar; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF};
function VMProtectFreeString(Value: Pointer): Boolean; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF};
// licensing
type
TVMProtectDate = packed record
wYear: Word;
bMonth: Byte;
bDay: Byte;
end;
PVMProtectSerialNumberData = ^TVMProtectSerialNumberData;
TVMProtectSerialNumberData = packed record
nState: Longword;
wUserName: array [0..255] of WideChar;
wEMail: array [0..255] of WideChar;
dtExpire: TVMProtectDate;
dtMaxBuild: TVMProtectDate;
bRunningTime: Longword;
nUserDataLength: Byte;
bUserData: array [0..254] of Byte;
end;
const
SERIAL_STATE_SUCCESS = 0;
SERIAL_STATE_FLAG_CORRUPTED = $00000001;
SERIAL_STATE_FLAG_INVALID = $00000002;
SERIAL_STATE_FLAG_BLACKLISTED = $00000004;
SERIAL_STATE_FLAG_DATE_EXPIRED = $00000008;
SERIAL_STATE_FLAG_RUNNING_TIME_OVER = $00000010;
SERIAL_STATE_FLAG_BAD_HWID = $00000020;
SERIAL_STATE_FLAG_MAX_BUILD_EXPIRED = $00000040;
function VMProtectSetSerialNumber(SerialNumber: PAnsiChar): Longword; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF};
function VMProtectGetSerialNumberState: Longword; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF};
function VMProtectGetSerialNumberData(Data: PVMProtectSerialNumberData; DataSize: Integer): Boolean; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF};
function VMProtectGetCurrentHWID(Buffer: PAnsiChar; BufferLen: Integer): Integer; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF};
// activation
const
ACTIVATION_OK = 0;
ACTIVATION_SMALL_BUFFER = 1;
ACTIVATION_NO_CONNECTION = 2;
ACTIVATION_BAD_REPLY = 3;
ACTIVATION_BANNED = 4;
ACTIVATION_CORRUPTED = 5;
ACTIVATION_BAD_CODE = 6;
ACTIVATION_ALREADY_USED = 7;
ACTIVATION_SERIAL_UNKNOWN = 8;
ACTIVATION_EXPIRED = 9;
ACTIVATION_NOT_AVAILABLE = 10;
function VMProtectActivateLicense(ActivationCode: PAnsiChar; Buffer: PAnsiChar; BufferLen: Integer): Integer; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF};
function VMProtectDeactivateLicense(SerialNumber: PAnsiChar): Integer; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF};
function VMProtectGetOfflineActivationString(ActivationCode: PAnsiChar; Buffer: PAnsiChar; BufferLen: Integer): Integer; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF};
function VMProtectGetOfflineDeactivationString(SerialNumber: PAnsiChar; Buffer: PAnsiChar; BufferLen: Integer): Integer; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF};
implementation
{$IFDEF WIN64}
const VMProtectDLLName = 'VMProtectSDK64.dll';
{$ELSE}
{$IFDEF WIN32}
const VMProtectDLLName = 'VMProtectSDK32.dll';
{$ELSE}
{$IFDEF DARWIN}
{$LINKLIB libVMProtectSDK.dylib}
{$ELSE}
{$IFDEF MACOS}
const VMProtectDLLName = 'libVMProtectSDK.dylib';
{$IFNDEF MACOS64}
{$DEFINE MACOS32}
{$ENDIF}
{$ELSE}
{$IFDEF LINUX32}
const VMProtectDLLName = 'libVMProtectSDK32.so';
{$ELSE}
{$IFDEF LINUX64}
const VMProtectDLLName = 'libVMProtectSDK64.so';
{$ELSE}
{$FATAL Unsupported OS!!!}
{$ENDIF}
{$ENDIF}
{$ENDIF}
{$ENDIF}
{$ENDIF}
{$ENDIF}
procedure VMProtectBegin(MarkerName: PAnsiChar); {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF}; external {$IFNDEF DARWIN}VMProtectDLLName{$ENDIF} {$IFDEF MACOS32} name '_VMProtectBegin'{$ENDIF};
procedure VMProtectBeginVirtualization(MarkerName: PAnsiChar); {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF}; external {$IFNDEF DARWIN}VMProtectDLLName{$ENDIF} {$IFDEF MACOS32} name '_VMProtectBeginVirtualization'{$ENDIF};
procedure VMProtectBeginMutation(MarkerName: PAnsiChar); {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF}; external {$IFNDEF DARWIN}VMProtectDLLName{$ENDIF} {$IFDEF MACOS32} name '_VMProtectBeginMutation'{$ENDIF};
procedure VMProtectBeginUltra(MarkerName: PAnsiChar); {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF}; external {$IFNDEF DARWIN}VMProtectDLLName{$ENDIF} {$IFDEF MACOS32} name '_VMProtectBeginUltra'{$ENDIF};
procedure VMProtectBeginVirtualizationLockByKey(MarkerName: PAnsiChar); {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF}; external {$IFNDEF DARWIN}VMProtectDLLName{$ENDIF} {$IFDEF MACOS32} name '_VMProtectBeginVirtualizationLockByKey'{$ENDIF};
procedure VMProtectBeginUltraLockByKey(MarkerName: PAnsiChar); {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF}; external {$IFNDEF DARWIN}VMProtectDLLName{$ENDIF} {$IFDEF MACOS32} name '_VMProtectBeginUltraLockByKey'{$ENDIF};
procedure VMProtectEnd; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF}; external {$IFNDEF DARWIN}VMProtectDLLName{$ENDIF} {$IFDEF MACOS32} name '_VMProtectEnd'{$ENDIF};
function VMProtectIsProtected: Boolean; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF}; external {$IFNDEF DARWIN}VMProtectDLLName{$ENDIF} {$IFDEF MACOS32} name '_VMProtectIsProtected'{$ENDIF};
function VMProtectIsDebuggerPresent(CheckKernelMode: Boolean): Boolean; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF}; external {$IFNDEF DARWIN}VMProtectDLLName{$ENDIF} {$IFDEF MACOS32} name '_VMProtectIsDebuggerPresent'{$ENDIF};
function VMProtectIsVirtualMachinePresent: Boolean; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF}; external {$IFNDEF DARWIN}VMProtectDLLName{$ENDIF} {$IFDEF MACOS32} name '_VMProtectIsVirtualMachinePresent'{$ENDIF};
function VMProtectIsValidImageCRC: Boolean; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF}; external {$IFNDEF DARWIN}VMProtectDLLName{$ENDIF} {$IFDEF MACOS32} name '_VMProtectIsValidImageCRC'{$ENDIF};
function VMProtectDecryptStringA(Value: PAnsiChar): PAnsiChar; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF}; external {$IFNDEF DARWIN}VMProtectDLLName{$ENDIF} {$IFDEF MACOS32} name '_VMProtectDecryptStringA'{$ENDIF};
function VMProtectDecryptStringW(Value: PWideChar): PWideChar; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF}; external {$IFNDEF DARWIN}VMProtectDLLName{$ENDIF} {$IFDEF MACOS32} name '_VMProtectDecryptStringW'{$ENDIF};
function VMProtectFreeString(Value: Pointer): Boolean; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF}; external {$IFNDEF DARWIN}VMProtectDLLName{$ENDIF} {$IFDEF MACOS32} name '_VMProtectFreeString'{$ENDIF};
function VMProtectSetSerialNumber(SerialNumber: PAnsiChar): Longword; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF}; external {$IFNDEF DARWIN}VMProtectDLLName{$ENDIF} {$IFDEF MACOS32} name '_VMProtectSetSerialNumber'{$ENDIF};
function VMProtectGetSerialNumberState: Longword; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF}; external {$IFNDEF DARWIN}VMProtectDLLName{$ENDIF} {$IFDEF MACOS32} name '_VMProtectGetSerialNumberState'{$ENDIF};
function VMProtectGetSerialNumberData(Data: PVMProtectSerialNumberData; DataSize: Integer): Boolean; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF}; external {$IFNDEF DARWIN}VMProtectDLLName{$ENDIF} {$IFDEF MACOS32} name '_VMProtectGetSerialNumberData'{$ENDIF};
function VMProtectGetCurrentHWID(Buffer: PAnsiChar; BufferLen: Integer): Integer; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF}; external {$IFNDEF DARWIN}VMProtectDLLName{$ENDIF} {$IFDEF MACOS32} name '_VMProtectGetCurrentHWID'{$ENDIF};
function VMProtectActivateLicense(ActivationCode: PAnsiChar; Buffer: PAnsiChar; BufferLen: Integer): Integer; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF}; external {$IFNDEF DARWIN}VMProtectDLLName{$ENDIF} {$IFDEF MACOS32} name '_VMProtectActivateLicense'{$ENDIF};
function VMProtectDeactivateLicense(SerialNumber: PAnsiChar): Integer; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF}; external {$IFNDEF DARWIN}VMProtectDLLName{$ENDIF} {$IFDEF MACOS32} name '_VMProtectDeactivateLicense'{$ENDIF};
function VMProtectGetOfflineActivationString(ActivationCode: PAnsiChar; Buffer: PAnsiChar; BufferLen: Integer): Integer; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF}; external {$IFNDEF DARWIN}VMProtectDLLName{$ENDIF} {$IFDEF MACOS32} name '_VMProtectGetOfflineActivationString'{$ENDIF};
function VMProtectGetOfflineDeactivationString(SerialNumber: PAnsiChar; Buffer: PAnsiChar; BufferLen: Integer): Integer; {$IFDEF MSWINDOWS} stdcall {$ELSE} cdecl {$ENDIF}; external {$IFNDEF DARWIN}VMProtectDLLName{$ENDIF} {$IFDEF MACOS32} name '_VMProtectGetOfflineDeactivationString'{$ENDIF};
end.

13
sdk/lin_sdk.mak Normal file
View File

@ -0,0 +1,13 @@
SOURCES := sdk.cc
TARGET := libVMProtectSDK$(ARCH_DIR).so
BIN_DIR := ../bin
TMP_DIR := ../tmp/lin/sdk/$(ARCH_DIR)/SDK
PCH_DIR := $(TMP_DIR)/sdk.gch
DEFINES :=
LFLAGS := -shared -fPIC
LIBS :=
OBJCOMP :=
include ../lin_common.mak
include ../gnu_simple.mak

3
sdk/lin_sdk32.mak Normal file
View File

@ -0,0 +1,3 @@
ARCH := i386-linux-gnu
ARCH_DIR := 32
include lin_sdk.mak

3
sdk/lin_sdk64.mak Normal file
View File

@ -0,0 +1,3 @@
ARCH := x86_64-linux-gnu
ARCH_DIR := 64
include lin_sdk.mak

13
sdk/mac_sdk.mak Normal file
View File

@ -0,0 +1,13 @@
SOURCES := sdk.cc
TARGET := libVMProtectSDK$(ARCH_DIR).dylib
BIN_DIR := ../bin
TMP_DIR := ../tmp/mac/sdk/$(ARCH_DIR)/SDK
PCH_DIR := $(TMP_DIR)/sdk.gch
DEFINES :=
LFLAGS := -install_name @executable_path/libVMProtectSDK.dylib -dynamiclib
LIBS := -F/Library/Frameworks -L/Library/Frameworks
OBJCOMP :=
include ../mac_common.mak
include ../gnu_simple.mak

3
sdk/mac_sdk32.mak Normal file
View File

@ -0,0 +1,3 @@
ARCH := i386
ARCH_DIR := 32
include mac_sdk.mak

3
sdk/mac_sdk64.mak Normal file
View File

@ -0,0 +1,3 @@
ARCH := x86_64
ARCH_DIR := 64
include mac_sdk.mak

1
sdk/precompiled.cc Normal file
View File

@ -0,0 +1 @@
#include "precompiled.h"

31
sdk/precompiled.h Normal file
View File

@ -0,0 +1,31 @@
#pragma once
#ifndef SDK_PCH
#define SDK_PCH
#ifdef __unix__
#ifdef __i386__
__asm__(".symver memcpy,memcpy@GLIBC_2.0");
#else
__asm__(".symver memcpy,memcpy@GLIBC_2.2.5");
#endif
#endif
#include "../runtime/precommon.h"
#ifdef VMP_GNU
#include <stdint.h>
#include <stdlib.h>
#include <stddef.h>
#include <ctype.h>
#include <time.h>
#elif !defined(WIN_DRIVER)
#include <windows.h>
#endif
#ifdef __APPLE__
#include <sys/syslimits.h>
#include <mach/mach_time.h>
#include <mach-o/dyld.h>
#endif
#endif //SDK_PCH

624
sdk/sdk.cc Normal file
View File

@ -0,0 +1,624 @@
#include "sdk.h"
#if defined(__unix__)
#include <sys/time.h>
#include <unistd.h>
#endif
#ifdef VMP_GNU
#elif defined(WIN_DRIVER)
void DriverUnload(PDRIVER_OBJECT driver_object)
{
}
NTSTATUS DriverEntry(PDRIVER_OBJECT pDriverObject, PUNICODE_STRING pRegistryPath)
{
pRegistryPath;
pDriverObject->DriverUnload = DriverUnload;
return STATUS_SUCCESS;
}
#else
BOOL APIENTRY DllMain(HANDLE hModule, DWORD dwReason, LPVOID lpReserved)
{
hModule;
dwReason;
lpReserved;
return TRUE;
}
#endif
bool VMP_API VMProtectIsProtected()
{
return false;
}
void VMP_API VMProtectBegin(const char *)
{
}
void VMP_API VMProtectBeginMutation(const char *)
{
}
void VMP_API VMProtectBeginVirtualization(const char *)
{
}
void VMP_API VMProtectBeginUltra(const char *)
{
}
void VMP_API VMProtectBeginVirtualizationLockByKey(const char *)
{
}
void VMP_API VMProtectBeginUltraLockByKey(const char *)
{
}
void VMP_API VMProtectEnd()
{
}
bool VMP_API VMProtectIsDebuggerPresent(bool)
{
#ifdef VMP_GNU
return false;
#elif defined(WIN_DRIVER)
return false;
#else
return IsDebuggerPresent() != FALSE;
#endif
}
bool VMP_API VMProtectIsVirtualMachinePresent()
{
return false;
}
bool VMP_API VMProtectIsValidImageCRC()
{
return true;
}
const char * VMP_API VMProtectDecryptStringA(const char *value)
{
return value;
}
const VMP_WCHAR * VMP_API VMProtectDecryptStringW(const VMP_WCHAR *value)
{
return value;
}
bool VMP_API VMProtectFreeString(void *)
{
return true;
}
int VMP_API VMProtectGetOfflineActivationString(const char *, char *, int)
{
return ACTIVATION_OK;
}
int VMP_API VMProtectGetOfflineDeactivationString(const char *, char *, int)
{
return ACTIVATION_OK;
}
#ifdef __APPLE__
unsigned long GetTickCount()
{
const int64_t one_million = 1000 * 1000;
mach_timebase_info_data_t timebase_info;
mach_timebase_info(&timebase_info);
// mach_absolute_time() returns billionth of seconds,
// so divide by one million to get milliseconds
return static_cast<uint32_t>((mach_absolute_time() * timebase_info.numer) / (one_million * timebase_info.denom));
}
#endif
#ifdef __unix__
unsigned long GetTickCount()
{
struct timeval tv;
gettimeofday(&tv, NULL);
return tv.tv_sec * 1000 + tv.tv_usec / 1000;
}
#endif
#ifndef WIN_DRIVER
bool g_serial_is_correct = false;
bool g_serial_is_blacklisted = false;
uint32_t g_time_of_start = GetTickCount();
#endif
#ifdef VMP_GNU
#define strcmpi strcasecmp
#define INI_MAX_LINE 1024
size_t strnlen(char *text, size_t maxlen)
{
const char *last = (const char *)memchr(text, '\0', maxlen);
return last ? (size_t) (last - text) : maxlen;
}
/* Strip whitespace chars off end of given string, in place. Return s. */
static char* rstrip(char* s)
{
char* p = s + strlen(s);
while (p > s && isspace((unsigned char)(*--p)))
*p = '\0';
return s;
}
/* Return pointer to first non-whitespace char in given string. */
static char* lskip(const char* s)
{
while (*s && isspace((unsigned char)(*s)))
s++;
return (char*)s;
}
/* Return pointer to first char c or ';' comment in given string, or pointer to
null at end of string if neither found. ';' must be prefixed by a whitespace
character to register as a comment. */
static char* find_char_or_comment(const char* s, char c)
{
int was_whitespace = 0;
while (*s && *s != c && !(was_whitespace && *s == ';')) {
was_whitespace = isspace((unsigned char)(*s));
s++;
}
return (char*)s;
}
/* See documentation in header file. */
static int GetPrivateProfileString(const char *section_name, const char *key_name, char *buffer, size_t size, const char *file_name)
{
if (!buffer || !size)
return 0;
FILE* file = fopen(file_name, "r");
if (!file)
return 0;
char line[INI_MAX_LINE];
char* start;
char* end;
char* name;
char* value;
int lineno = 0;
int res = 0;
bool section_found = false;
/* Scan through file line by line */
while (fgets(line, INI_MAX_LINE, file) != NULL) {
lineno++;
start = line;
if (lineno == 1 && (unsigned char)start[0] == 0xEF &&
(unsigned char)start[1] == 0xBB &&
(unsigned char)start[2] == 0xBF) {
start += 3;
}
start = lskip(rstrip(start));
if (*start == ';' || *start == '#') {
/* Per Python ConfigParser, allow '#' comments at start of line */
} else if (*start == '[') {
/* A "[section]" line */
end = find_char_or_comment(start + 1, ']');
if (*end == ']') {
*end = '\0';
if (section_found)
break;
section_found = strcmpi(start + 1, section_name) == 0;
}
} else if (section_found && *start && *start != ';') {
/* Not a comment, must be a name[=:]value pair */
end = find_char_or_comment(start, '=');
if (*end != '=') {
end = find_char_or_comment(start, ':');
}
if (*end == '=' || *end == ':') {
*end = '\0';
name = rstrip(start);
value = lskip(end + 1);
end = find_char_or_comment(value, '\0');
if (*end == ';')
*end = '\0';
rstrip(value);
if (strcmpi(name, key_name) == 0) {
strncpy(buffer, value, size);
res = strnlen(buffer, size);
break;
}
}
}
}
fclose(file);
return res;
}
static bool GetIniValue(const char *value_name, char *buffer, size_t size)
{
char file_name[PATH_MAX];
file_name[0] = 0;
uint32_t name_size = sizeof(file_name);
#if defined(__APPLE__)
_NSGetExecutablePath(file_name, &name_size);
#else
int sz = readlink("/proc/self/exe", file_name, name_size);
if (sz > 0)
file_name[sz] = 0;
#endif
char *p = strrchr(file_name, '/');
if (p)
*(p + 1) = 0;
strncat(file_name, "VMProtectLicense.ini", sizeof(file_name) - (p - file_name));
return GetPrivateProfileString("TestLicense", value_name, buffer, size, file_name) != 0;
}
static const uint8_t utf8_limits[5] = {0xC0, 0xE0, 0xF0, 0xF8, 0xFC};
static void ConvertUTF8ToUnicode(const uint8_t *src, size_t len, VMP_WCHAR *dest, size_t dest_size)
{
if (!dest || dest_size == 0) return; // nothing to do
size_t pos = 0;
size_t dest_pos = 0;
while (pos < len && dest_pos < dest_size) {
uint8_t b = src[pos++];
if (b < 0x80) {
dest[dest_pos++] = b;
continue;
}
size_t val_len;
for (val_len = 0; val_len <= _countof(utf8_limits); val_len++) {
if (b < utf8_limits[val_len])
break;
}
if (val_len == 0)
continue;
uint32_t value = b - utf8_limits[val_len - 1];
for (size_t i = 0; i < val_len; i++) {
if (pos == len)
break;
b = src[pos++];
if (b < 0x80 || b >= 0xC0)
break;
value <<= 6;
value |= (b - 0x80);
}
if (value < 0x10000) {
dest[dest_pos++] = static_cast<uint16_t>(value);
} else if (value <= 0x10FFFF) {
value -= 0x10000;
dest[dest_pos++] = static_cast<uint16_t>(0xD800 + (value >> 10));
dest[dest_pos++] = static_cast<uint16_t>(0xDC00 + (value & 0x3FF));
}
}
if (dest_pos < dest_size - 1)
dest[dest_pos] = 0;
else
dest[dest_pos - 1] = 0;
}
static bool GetIniValue(const char *value_name, VMP_WCHAR *buffer, size_t size)
{
char value[INI_MAX_LINE];
if (GetIniValue(value_name, value, sizeof(value))) {
ConvertUTF8ToUnicode(reinterpret_cast<uint8_t *>(value), strlen(value), buffer, size);
return true;
}
if (buffer && size)
buffer[0] = 0;
return false;
}
#elif defined(WIN_DRIVER)
#else
static bool GetIniValue(const char *value_name, wchar_t *buffer, size_t size)
{
wchar_t file_name[MAX_PATH];
file_name[0] = 0;
GetModuleFileNameW(NULL, file_name, _countof(file_name));
wchar_t *p = wcsrchr(file_name, L'\\');
if (p)
*(p + 1) = 0;
wcsncat_s(file_name, L"VMProtectLicense.ini", _countof(file_name));
wchar_t key_name[1024] = {0};
MultiByteToWideChar(CP_ACP, 0, value_name, -1, key_name, _countof(key_name));
return GetPrivateProfileStringW(L"TestLicense", key_name, L"", buffer, static_cast<DWORD>(size), file_name) != 0;
}
static bool GetIniValue(const char *value_name, char *buffer, size_t size)
{
wchar_t value[2048];
if (GetIniValue(value_name, value, sizeof(value))) {
WideCharToMultiByte(CP_ACP, 0, value, -1, buffer, static_cast<int>(size), NULL, NULL);
return true;
}
if (buffer && size)
buffer[0] = 0;
return false;
}
#endif
#define MAKEDATE(y, m, d) (DWORD)((y << 16) + (m << 8) + d)
int VMP_API VMProtectGetSerialNumberState()
{
#ifdef WIN_DRIVER
return SERIAL_STATE_FLAG_INVALID;
#else
if (!g_serial_is_correct)
return SERIAL_STATE_FLAG_INVALID;
if (g_serial_is_blacklisted)
return SERIAL_STATE_FLAG_BLACKLISTED;
int res = 0;
char buf[256];
if (GetIniValue("TimeLimit", buf, sizeof(buf))) {
int running_time = atoi(buf);
if (running_time >= 0 && running_time <= 255) {
uint32_t dw = GetTickCount();
int d = (dw - g_time_of_start) / 1000 / 60; // minutes
if (running_time <= d)
res |= SERIAL_STATE_FLAG_RUNNING_TIME_OVER;
}
}
if (GetIniValue("ExpDate", buf, sizeof(buf))) {
int y, m, d;
if (sscanf_s(buf, "%04d%02d%02d", &y, &m, &d) == 3) {
uint32_t ini_date = (y << 16) + (static_cast<uint8_t>(m) << 8) + static_cast<uint8_t>(d);
uint32_t cur_date;
#ifdef VMP_GNU
time_t rawtime;
time(&rawtime);
struct tm local_tm;
tm *timeinfo = localtime_r(&rawtime, &local_tm);
cur_date = ((timeinfo->tm_year + 1900) << 16) + (static_cast<uint8_t>(timeinfo->tm_mon + 1) << 8) + static_cast<uint8_t>(timeinfo->tm_mday);
#else
SYSTEMTIME st;
GetLocalTime(&st);
cur_date = (st.wYear << 16) + (static_cast<uint8_t>(st.wMonth) << 8) + static_cast<uint8_t>(st.wDay);
#endif
if (cur_date > ini_date)
res |= SERIAL_STATE_FLAG_DATE_EXPIRED;
}
}
if (GetIniValue("MaxBuildDate", buf, sizeof(buf))) {
int y, m, d;
if (sscanf_s(buf, "%04d%02d%02d", &y, &m, &d) == 3) {
uint32_t ini_date = (y << 16) + (static_cast<uint8_t>(m) << 8) + static_cast<uint8_t>(d);
uint32_t cur_date;
#ifdef VMP_GNU
time_t rawtime;
time(&rawtime);
struct tm local_tm;
tm *timeinfo = localtime_r(&rawtime, &local_tm);
cur_date = ((timeinfo->tm_year + 1900) << 16) + (static_cast<uint8_t>(timeinfo->tm_mon + 1) << 8) + static_cast<uint8_t>(timeinfo->tm_mday);
#else
SYSTEMTIME st;
GetLocalTime(&st);
cur_date = (st.wYear << 16) + (static_cast<uint8_t>(st.wMonth) << 8) + static_cast<uint8_t>(st.wDay);
#endif
if (cur_date > ini_date)
res |= SERIAL_STATE_FLAG_MAX_BUILD_EXPIRED;
}
}
if (GetIniValue("KeyHWID", buf, sizeof(buf))) {
char buf2[256];
GetIniValue("MyHWID", buf2, sizeof(buf2));
if (strcmp(buf, buf2) != 0)
res |= SERIAL_STATE_FLAG_BAD_HWID;
}
return res;
#endif
}
int VMP_API VMProtectSetSerialNumber(const char *serial)
{
#ifdef WIN_DRIVER
serial;
return SERIAL_STATE_FLAG_INVALID;
#else
g_serial_is_correct = false;
g_serial_is_blacklisted = false;
if (!serial || !serial[0])
return SERIAL_STATE_FLAG_INVALID;
char buf_serial[2048];
const char *src = serial;
char *dst = buf_serial;
while (*src) {
char c = *src;
// check agains base64 alphabet
if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '+' || c == '/' || c == '=')
*dst++ = c;
src++;
}
*dst = 0;
char ini_serial[2048];
if (!GetIniValue("AcceptedSerialNumber", ini_serial, sizeof(ini_serial)))
strcpy_s(ini_serial, "serialnumber");
g_serial_is_correct = strcmp(buf_serial, ini_serial) == 0;
if (GetIniValue("BlackListedSerialNumber", ini_serial, sizeof(ini_serial)))
g_serial_is_blacklisted = strcmp(buf_serial, ini_serial) == 0;
return VMProtectGetSerialNumberState();
#endif
}
bool VMP_API VMProtectGetSerialNumberData(VMProtectSerialNumberData *data, int size)
{
#ifdef WIN_DRIVER
data;
size;
return false;
#else
if (size != sizeof(VMProtectSerialNumberData))
return false;
memset(data, 0, sizeof(VMProtectSerialNumberData));
data->nState = VMProtectGetSerialNumberState();
if (data->nState & (SERIAL_STATE_FLAG_INVALID | SERIAL_STATE_FLAG_BLACKLISTED))
return true; // do not need to read the rest
GetIniValue("UserName", data->wUserName, _countof(data->wUserName));
GetIniValue("EMail", data->wEMail, _countof(data->wEMail));
char buf[2048];
if (GetIniValue("TimeLimit", buf, sizeof(buf))) {
int running_time = atoi(buf);
if (running_time < 0)
running_time = 0;
else
if (running_time > 255)
running_time = 255;
data->bRunningTime = static_cast<unsigned char>(running_time);
}
if (GetIniValue("ExpDate", buf, sizeof(buf))) {
int y, m, d;
if (sscanf_s(buf, "%04d%02d%02d", &y, &m, &d) == 3) {
data->dtExpire.wYear = static_cast<unsigned short>(y);
data->dtExpire.bMonth = static_cast<unsigned char>(m);
data->dtExpire.bDay = static_cast<unsigned char>(d);
}
}
if (GetIniValue("MaxBuildDate", buf, sizeof(buf))) {
int y, m, d;
if (sscanf_s(buf, "%04d%02d%02d", &y, &m, &d) == 3) {
data->dtMaxBuild.wYear = static_cast<unsigned short>(y);
data->dtMaxBuild.bMonth = static_cast<unsigned char>(m);
data->dtMaxBuild.bDay = static_cast<unsigned char>(d);
}
}
if (GetIniValue("UserData", buf, sizeof(buf))) {
size_t len = strlen(buf);
if (len > 0 && len % 2 == 0 && len <= 255 * 2) // otherwise UserData is empty or has bad length
{
for (size_t src = 0, dst = 0; src < len; src++) {
int v = 0;
char c = buf[src];
if (c >= '0' && c <= '9') v = c - '0';
else if (c >= 'a' && c <= 'f') v = c - 'a' + 10;
else if (c >= 'A' && c <= 'F') v = c - 'A' + 10;
else {
data->nUserDataLength = 0;
memset(data->bUserData, 0, sizeof(data->bUserData));
break;
}
if (src % 2 == 0) {
data->bUserData[dst] = static_cast<unsigned char>(v << 4);
} else {
data->bUserData[dst] |= v;
dst++;
data->nUserDataLength = static_cast<unsigned char>(dst);
}
}
}
}
return true;
#endif
}
int VMP_API VMProtectGetCurrentHWID(char *hwid, int size)
{
#ifdef WIN_DRIVER
hwid;
size;
return 0;
#else
if (hwid && size == 0)
return 0;
char buf[1024];
if (!GetIniValue("MyHWID", buf, sizeof(buf)))
strcpy_s(buf, "myhwid");
int res = static_cast<int>(strlen(buf));
if (hwid) {
if (size - 1 < res)
res = size - 1;
memcpy(hwid, buf, res);
hwid[res] = 0;
}
return res + 1;
#endif
}
int VMP_API VMProtectActivateLicense(const char *code, char *serial, int size)
{
#ifdef WIN_DRIVER
code;
serial;
size;
return ACTIVATION_NOT_AVAILABLE;
#else
if (!code)
return ACTIVATION_BAD_CODE;
char buf[2048];
if (!GetIniValue("AcceptedActivationCode", buf, sizeof(buf)))
strcpy_s(buf, "activationcode");
if (strcmp(code, buf) != 0)
return ACTIVATION_BAD_CODE;
if (!GetIniValue("AcceptedSerialNumber", buf, sizeof(buf)))
strcpy_s(buf, "serialnumber");
int need = static_cast<int>(strlen(buf));
if (need > size - 1)
return ACTIVATION_SMALL_BUFFER;
strncpy_s(serial, size, buf, _TRUNCATE);
return ACTIVATION_OK;
#endif
}
int VMP_API VMProtectDeactivateLicense(const char *)
{
#ifdef WIN_DRIVER
return ACTIVATION_NOT_AVAILABLE;
#else
return ACTIVATION_OK;
#endif
}

23
sdk/sdk.def Normal file
View File

@ -0,0 +1,23 @@
EXPORTS
VMProtectIsProtected
VMProtectBegin
VMProtectBeginVirtualization
VMProtectBeginMutation
VMProtectBeginUltra
VMProtectBeginVirtualizationLockByKey
VMProtectBeginUltraLockByKey
VMProtectEnd
VMProtectIsDebuggerPresent
VMProtectIsVirtualMachinePresent
VMProtectIsValidImageCRC
VMProtectDecryptStringA
VMProtectDecryptStringW
VMProtectFreeString
VMProtectSetSerialNumber
VMProtectGetSerialNumberState
VMProtectGetSerialNumberData
VMProtectGetCurrentHWID
VMProtectActivateLicense
VMProtectDeactivateLicense
VMProtectGetOfflineActivationString
VMProtectGetOfflineDeactivationString

100
sdk/sdk.h Normal file
View File

@ -0,0 +1,100 @@
#ifndef SDK_H
#define SDK_H
#if defined(VMP_IMPORT)
// internal usage
#else
#ifdef VMP_GNU
#define VMP_IMPORT extern "C" __attribute__ ((visibility ("default")))
#else
#define VMP_IMPORT
#endif // VMP_GNU
#endif // VMP_IMPORT
#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(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
#endif