Exemple #1
0
        public KoiEmulator(RhydonContext ctx, MethodExport export)
        {
            _emuCtx = new EmuContext(ctx, export);

            ctx.Reader.BaseStream.Position = export.Offset;

            foreach (var h in typeof(KoiEmulator).Assembly.DefinedTypes
                     .Where(t => !t.IsAbstract && typeof(KoiHandler).IsAssignableFrom(t))
                     .Select(ha => Activator.CreateInstance(ha, _emuCtx)).Cast <KoiHandler>().ToArray())
            {
                _emuCtx.Handlers[h.Handles] = h;
            }

            foreach (var v in typeof(KoiEmulator).Assembly.DefinedTypes
                     .Where(t => !t.IsAbstract && typeof(VCallHandler).IsAssignableFrom(t))
                     .Select(ha => Activator.CreateInstance(ha, _emuCtx)).Cast <VCallHandler>().ToArray())
            {
                _emuCtx.VCallHandlers[v.VCall] = v;
            }

            ctx.Logger.Info($"Emulating virtualized method at offset: 0x{export.Offset:X8}");

            _emuCtx.Registers[ctx.Constants.REG_K1] = new VMSlot {
                U4 = export.Key
            };
            _emuCtx.Registers[ctx.Constants.REG_BP] = new VMSlot {
                U4 = 0
            };
            _emuCtx.Registers[ctx.Constants.REG_SP] = new VMSlot {
                U4 = (uint)(export.ArgumentTypes.Length + 1)
            };
            _emuCtx.Registers[ctx.Constants.REG_IP] = new VMSlot {
                U8 = (ulong)ctx.Reader.BaseStream.Position
            };
        }
Exemple #2
0
        public static byte ReadKoiByte(this BinaryReader reader, MethodExport sig)
        {
            var b = (byte)(reader.ReadInt64() ^ sig.Key);

            reader.BaseStream.Position -= 7;
            sig.Key = sig.Key * 7 + b;
            return(b);
        }
Exemple #3
0
        internal EmuContext(RhydonContext ctx, MethodExport exp)
        {
            Export        = exp;
            MethodBody    = new List <KoiInstruction>();
            Stack         = new Stack <VMSlot>();
            Registers     = new VMSlot[16];
            Handlers      = new Dictionary <byte, KoiHandler>();
            VCallHandlers = new Dictionary <byte, VCallHandler>();

            Module      = ctx.Module;
            Reader      = ctx.Reader;
            Header      = ctx.Header;
            StartOffset = ctx.StartOffset;
            Constants   = ctx.Constants;
            Decompiled  = ctx.Decompiled;
            Logger      = ctx.Logger;
            Parameters  = ctx.Parameters;
        }