2001: unsafe method exception

Issues related to VMProtect
Post Reply
weloveayaka
Posts: 58
Joined: Wed Jul 05, 2023 6:21 am

2001: unsafe method exception

Post by weloveayaka »

Code: Select all

[Obfuscation(Feature = "ultra", Exclude = false)]
public unsafe class UnsafeClass
{
    
    public void UnsafeMethod()
    {
        int* ptr = stackalloc int[1];
        *ptr = 42;
        Console.WriteLine("Unsafe method: " + *ptr);
    }
}
 
Type “System.IntPtr” cannot cast to “System.Int32&”

Below works fine.

Code: Select all

public static unsafe void unsafe2()
        {
            Console.WriteLine("Unsafe2");
            int* pointer = stackalloc int[10];
            for (int i = 0; i < 10; i++)
            {
                pointer[i] = i;
            }
            Console.WriteLine($"Stackalloc result: {pointer[5]}");
        }
Last edited by weloveayaka on Thu Mar 07, 2024 4:11 pm, edited 1 time in total.
weloveayaka
Posts: 58
Joined: Wed Jul 05, 2023 6:21 am

Re: 2001: unsafe method exception

Post by weloveayaka »

Code: Select all

 private static unsafe int PerformUnsafeOperation(int[] numbers)
        {
            fixed (int* pointer = numbers)
            {
                int sum = 0;
                for (int i = 0; i < numbers.Length; i++)
                {
                    sum += pointer[i];
                }
                return sum;
            }
        }
 
This one gets NullPointerException

P.S.
This Exception can't decode Stack trace using map file.
Only the "main" function's name decoded
Admin
Site Admin
Posts: 2586
Joined: Mon Aug 21, 2006 8:19 pm
Location: Russia, E-burg
Contact:

Re: 2001: unsafe method exception

Post by Admin »

Fixed in the 2023 build except this:

Code: Select all

public unsafe class UnsafeClass
{
    
    public void UnsafeMethod()
    {
        int* ptr = stackalloc int[1];
        *ptr = 42;
        Console.WriteLine("Unsafe method: " + *ptr);
    }
}
Post Reply