示例#1
0
        public static QualityTypeName ReadTypeName(this BinaryReader bin, VeinModule module)
        {
            var typeIndex = bin.ReadInt32();

            return(module.types_table.GetValueOrDefault(typeIndex) ??
                   throw new Exception($"TypeName by index '{typeIndex}' not found in '{module.Name}' module."));
        }
示例#2
0
        protected IshtarTestBase()
        {
            if (VM.watcher is DefaultWatchDog)
            {
                VM.watcher = new TestWatchDog();
            }
            AppVault.CurrentVault ??= new AppVault("<test-app>");
            lock (guarder)
            {
                if (!isInited)
                {
                    VeinCore.Init();

                    IshtarGC.INIT();
                    FFI.INIT();
                    _corlib = LoadCorLib();
                    IshtarCore.INIT_ADDITIONAL_MAPPING();
                    foreach (var @class in VeinCore.All.OfType <RuntimeIshtarClass>())
                    {
                        @class.init_vtable();
                    }
                    // ReSharper disable once VirtualMemberCallInConstructor
                    StartUp();
                    isInited = true;
                }
            }
        }
示例#3
0
        public static QualityTypeName[] ReadTypesArray(this BinaryReader bin, VeinModule module)
        {
            Debug.Assert(bin.ReadInt32() == 0x19, "[magic number] bin.ReadInt32() == 0x19");
            var sign   = bin.ReadIshtarString();
            var size   = bin.ReadInt32();
            var result = new List <QualityTypeName>();

            foreach (int i in..size)
            {
                result.Add(bin.ReadTypeName(module));
            }
            Debug.Assert(bin.ReadInt32() == 0x61, "[magic number] bin.ReadInt32() == 0x61");
            return(result.ToArray());
        }
示例#4
0
        public static RuntimeIshtarClass GetClass(uint index, VeinModule module, CallFrame frame)
        {
            var name = module.types_table.GetValueOrDefault((int)index);

            Assert(name is not null, WNE.TYPE_LOAD, $"Cant find '{index}' in class_table.", frame);
            var type = module.FindType(name, true, false);

            if (type is UnresolvedVeinClass)
            {
                FastFail(WNE.MISSING_TYPE, $"Cant load '{name.NameWithNS}' in '{name.AssemblyName}'", frame);
                ValidateLastError();
                return(null);
            }
            Assert(type is RuntimeIshtarClass, WNE.TYPE_LOAD, $"metadata is corrupted.");
            return(type as RuntimeIshtarClass);
        }
示例#5
0
        public static List <ProtectedZone> DeconstructExceptions(byte[] arr, int offset, VeinModule module)
        {
            if (arr.Length == 0)
            {
                return(new());
            }

            using var mem = new MemoryStream(arr);
            using var bin = new BinaryReader(mem);

            mem.Seek(offset, SeekOrigin.Begin);

            if (arr.Length == offset)
            {
                return(new());
            }

            var magic = bin.ReadInt16();

            if (magic != -0xFF1)
            {
                return(new());
            }

            var size = bin.ReadInt32();

            if (size == 0)
            {
                return(new());
            }
            var result = new List <ProtectedZone>();

            foreach (var i in..size)
            {
                var startAddr   = bin.ReadInt32();
                var tryEndLabel = bin.ReadInt32();
                var endAddr     = bin.ReadInt32();
                var filterAddr  = bin.ReadIntArray();
                var catchAddr   = bin.ReadIntArray();
                var catchClass  = bin.ReadTypesArray(module);
                var types       = bin.ReadSpecialByteArray <ExceptionMarkKind>();
                var item        = new ProtectedZone(
                    (uint)startAddr,
                    (uint)endAddr,
                    tryEndLabel,
                    filterAddr,
                    catchAddr,
                    catchClass,
                    types);

                result.Add(item);
            }

            return(result);
        }
示例#6
0
        public static RuntimeIshtarField GetField(uint index, RuntimeIshtarClass owner, VeinModule module, CallFrame frame)
        {
            var name  = module.GetFieldNameByIndex((int)index);
            var field = owner.FindField(name.Name);

            if (field is null)
            {
                FastFail(WNE.MISSING_FIELD, $"Field '{name}' not found in '{owner.FullName.NameWithNS}'", frame);
                ValidateLastError();
                return(null);
            }
            return(field);
        }
示例#7
0
        public static RuntimeIshtarMethod GetMethod(uint index, QualityTypeName owner, VeinModule module, CallFrame frame)
        {
            var clazz = module.FindType(owner);
            var name  = module.GetConstStringByIndex((int)index);

            var method = clazz.FindMethod(name, m => m.Name.Equals(name));

            if (method is null)
            {
                FastFail(WNE.MISSING_METHOD, $"Method '{name}' not found in '{clazz.FullName.NameWithNS}'", frame);
                ValidateLastError();
                return(null);
            }
            Assert(method is RuntimeIshtarMethod, WNE.MISSING_METHOD, $"metadata is corrupted.");
            return((RuntimeIshtarMethod)method);
        }
示例#8
0
 public static QualityTypeName readTypeName(uint index, VeinModule module)
 => module.types_table.GetValueOrDefault((int)index);
示例#9
0
 public static unsafe void LinkFFIMethods(VeinModule module) =>
 module.class_table
 .Select(x => x.Methods.OfExactType <RuntimeIshtarMethod>())
 .Pipe(LinkFFIMethods)
 .Consume();