Page 1 of 1

Can we use VMProtect offline in dotnet C#?

Posted: Mon Apr 08, 2024 11:11 am
by kkwong95
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.

Code: Select all

[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#?

Re: Can we use VMProtect offline in dotnet C#?

Posted: Mon Apr 08, 2024 12:19 pm
by Admin
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.

Re: Can we use VMProtect offline in dotnet C#?

Posted: Tue Apr 09, 2024 3:21 am
by kkwong95
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).

Re: Can we use VMProtect offline in dotnet C#?

Posted: Tue Apr 09, 2024 4:21 am
by Admin
It seems you work in the test mode:
https://vmpsoft.com/vmprotect/user-manu ... pplication

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

Re: Can we use VMProtect offline in dotnet C#?

Posted: Fri Apr 12, 2024 2:05 am
by kkwong95
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:

Re: Can we use VMProtect offline in dotnet C#?

Posted: Fri Apr 12, 2024 3:39 am
by weloveayaka
did you try .NET vmprotect sdk?
Located at Lib\windows\Net\VMProtect.SDK.dll

Re: Can we use VMProtect offline in dotnet C#?

Posted: Fri Apr 12, 2024 7:44 am
by Admin
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.