Can we use VMProtect offline in dotnet C#?

We are trying to write our code protection in dotnet C# but we can’t seems to get it to work. We have tried using VMProtect.SDK but the functions in the SDK always fails. So far we have attempted the following:

  • import VMProtectSDK64.dll into the c# project (example below)
  • writing a wrapper dll to call VMProtect functions in C++

Here’s a simple use case in our project.

[DllImport("VMProtectSDK64.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int VMProtectGetOfflineActivationString(
    string code,
    [Out, MarshalAs(UnmanagedType.LPStr)] StringBuilder buffer,
    ref int bufferSize);
    
public static void Main(string[] args)
{
    int bufferSize = 1024;
    StringBuilder stringBuilder = new StringBuilder(bufferSize);
    
    int res = VMProtectGetOfflineActivationString(code, stringBuilder, ref bufferSize);
    if (res == 0)
    {
        Console.WriteLine(stringBuilder.ToString());
    }
}

The result is that stringBuilder either contains garbage value or just being empty. This is similiar to ActivateLicense function where it would always return BadCode status. Is VMProtect usable in C#?

We have tried using VMProtect.SDK but the functions in the SDK always fails.

Could you provide more detailed information about this problem?

So far we have attempted the following:

  • import VMProtectSDK64.dll into the c# project (example below)
  • writing a wrapper dll to call VMProtect functions in C++

This scheme will never work.

Could you provide more detailed information about this problem?

VMProtect.SDK.ActivateLicense returns BadCode status.

VMProtect.SDK.GetOfflineActivationString returns Ok status but the buffer is always “Sdk OfflineActivationString”.

VMProtect.SDK.SetSerialNumber returns Invalid (serial number from activated license).

It seems you work in the test mode:

For real mode you have to protect your application with vmprotect.

Hi, the user manual is written for C++ apps, but we are writing our app in C#. Is there any specific steps we need to follow in order to enable real mode?

Particularly this step, it’s not an option available in C# dotnet projects.

Compile the program without the debug information, but in the linker settings we enable creating of the MAP-file – we will need it to work with VMProtect. After we run the program, we should see the following text:

did you try .NET vmprotect sdk?
Located at Lib\windows\Net\VMProtect.SDK.dll

Compile the program without the debug information, but in the linker settings we enable creating of the MAP-file

MAP/PDB aren’t required for .NET files because .NET files already contain all symbols inside.