aboutsummaryrefslogtreecommitdiff
path: root/runtime/VMProtect.Runtime/Tests/UnitTestProject/LoaderTests.cs
blob: 5ad8afa93b95370a5cef984070c47cbf70dc95ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System.Runtime.InteropServices;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using VMProtect;

namespace UnitTestProject
{
    [TestClass]
    public class LoaderTests
    {
        [TestMethod]
        public void LzmaDecode()
        {
            byte[] properties =
            {
                0x5d, 0, 0, 0, 1 // 5 bytes props
            };
            byte[] src =
            {
                0x00, 0x4e, 0x3a, 0x46, 0xeb, 0xe0, 0x06, 0x71, 0xc9, 0xe1, 
                0xe6, 0x37, 0xfd, 0x9b, 0xb6, 0xd0, 0x76, 0x3f, 0xc8, 0x73, 
                0xee, 0x11, 0xb6, 0x41, 0xaa, 0xb1, 0x7b, 0x7b, 0xef, 0xc6, 
                0x9f, 0xff, 0xf6, 0x1d, 0x28, 0x00 //36 bytes packed
            };
            byte [] dstExpected = { 0x9c, 0xe9, 0x57, 0xbe, 0x00, 0x00, 0xc3, 0xe9, 0x24, 0x2c, 0x01, 0x00, 0xe9, 0xef, 0x65, 0x00, 0x00, 0xe9, 0xc0, 0x41, 0x06, 0x00, 0xc3, 0x56, 0x57 }; 
            var pinnedSrc = GCHandle.Alloc(src, GCHandleType.Pinned);
            uint dstSize = 65536;
            var dstPtr = Marshal.AllocHGlobal((int)dstSize);
            try
            {
                dstSize = int.MaxValue;
                uint srcSize /*= (uint)src.Length*/;
                var res = Loader.LzmaDecode(dstPtr, pinnedSrc.AddrOfPinnedObject(), properties, ref dstSize, out srcSize);
                Assert.AreEqual(true, res);
                Assert.AreEqual(dstExpected.Length, (int)dstSize);
                var dst = new byte[dstSize];
                Marshal.Copy(dstPtr, dst, 0, (int)dstSize);
                CollectionAssert.AreEqual(dstExpected, dst);
                Assert.AreEqual(src.Length, (int)srcSize);
            }
            finally
            {
                pinnedSrc.Free();
                Marshal.FreeHGlobal(dstPtr);
            }
        }
    }
}