Example #1
0
        internal static bool IsEnabledFunction <T>(T Function)
        {
            for (int i = 0; InfoCollection.Functions.Count > i; i++)
            {
                PluginFunction pf       = InfoCollection.Functions[i];
                string         type_str = Function.GetType().ToString();

                if (pf.TypeName == type_str)
                {
                    if (pf.LastWriteDate != File.GetLastWriteTime(pf.Path))
                    {
                        pf.LastWriteDate         = File.GetLastWriteTime(pf.Path);
                        pf.TypeName              = Function.GetType().ToString();
                        pf.AssemblyQualifiedName = Function.GetType().AssemblyQualifiedName;
                        pf.Title = Function.ToString();
                    }

                    return(pf.Enabled);
                }
            }

            Assembly       asm = Function.GetType().Assembly;
            PluginFunction npf = new PluginFunction();

            npf.LastWriteDate         = File.GetLastWriteTime(asm.Location);
            npf.Enabled               = Config.Current.bValue[Enums.bValue.UseNewPlugin];
            npf.TypeName              = Function.GetType().ToString();
            npf.AssemblyQualifiedName = Function.GetType().AssemblyQualifiedName;
            npf.Path  = asm.Location;
            npf.Title = Function.ToString();
            InfoCollection.Functions.Add(npf);

            return(npf.Enabled);
        }
        private static File3DLoaderModule GetFileExporterModuleFromP(PluginFunction p)
        {
            var dic = new Dictionary <string, string>();

            p.Invoke(dic);
            var convMethod = p.Plugin.GetFunctions("loadermoduleexport").FirstOrDefault(n => Operators.ConditionalCompareObjectEqual(n.Params[0], p.Params[0], false));

            return(new File3DLoaderModule(Conversions.ToString(p.Params[0]), (File3DLoaderModule.ExporterAction)Delegate.CreateDelegate(typeof(File3DLoaderModule.ExporterAction), convMethod.Method), dic));
        }
Example #3
0
        private void ReadFuncImports(DataBuffer data)
        {
            data.Position = FuncImportsOffset;
            int offset = data.ReadInt32();
            int count  = data.ReadInt32();
            int length = StaticVarsOffset - FuncImportsOffset;

            data.Position = FuncImportsOffset + offset;

            Sections.Add(new Section("Function Imports", FuncImportsOffset, count, length));

            ImportFuncs = new PluginFunction[count];
            for (int i = 0; i < ImportFuncs.Length; i++)
            {
                ImportFuncs[i] = new PluginFunction();
                ushort pluginId   = data.ReadUInt16();
                ushort functionId = data.ReadUInt16();
                ImportFuncs[i].Plugin   = GetId(pluginId, $"Import Script Name #{i}");
                ImportFuncs[i].Function = GetId(functionId, $"Import Function Name #{i}");
            }
        }
Example #4
0
        private void ReadPluginImports(DataBuffer data)
        {
            data.Position = PluginsOffset;
            int offset = data.ReadInt32();
            int count  = data.ReadInt32();
            int length = OcImportsOffset - PluginsOffset;

            data.Position = PluginsOffset + offset;

            var section = new Section("Plugin Imports", PluginsOffset, count, length);

            Sections.Add(section);

            Plugins = new PluginFunction[count];
            for (int i = 0; i < Plugins.Length; i++)
            {
                Plugins[i] = new PluginFunction();
                ushort pluginId   = data.ReadUInt16();
                ushort functionId = data.ReadUInt16();
                Plugins[i].Plugin   = GetId(pluginId, $"Plugin Name #{i}");
                Plugins[i].Function = GetId(functionId, $"Plugin Function Name #{i}");
            }
        }
Example #5
0
        public void ReadInstruction(Script script, DataBuffer data, int funcIndex)
        {
            Address = data.Position;
            var opcode = (Opcode)data.ReadUInt8();

            Opcode = opcode;
            OpcodeInfo opcodeInfo = Opcode.GetInfo();
            int        operand    = ReadOperand(data, opcodeInfo.Size);

            switch (opcode)
            {
            case Opcode.NOP:
                break;

            case Opcode.CONST_0:
                break;

            case Opcode.CONST_1:
                break;

            case Opcode.CONST_2:
                break;

            case Opcode.CONST_3:
                break;

            case Opcode.CONST_4:
                break;

            case Opcode.CONST_I:
                break;

            case Opcode.CONST_I_W:
                break;

            case Opcode.POOL_INT:
            case Opcode.POOL_INT_W:
                Comment = script.IntPool[operand].ToString();
                break;

            case Opcode.POOL_FIXED:
            case Opcode.POOL_FIXED_W:
                Comment = script.FixedPool[operand].ToString(CultureInfo.InvariantCulture);
                break;

            case Opcode.POOL_STR:
            case Opcode.POOL_STR_W:
                Comment = script.StringPool[operand];
                break;

            case Opcode.LD:
            case Opcode.ST:
                Comment = script.LocalPool[script.FunctionPool[funcIndex].LocalPoolIndex][operand].Name;
                break;

            case Opcode.LD_ARG:
            case Opcode.ST_ARG:
                Comment = script.ArgsSymbols?[funcIndex][operand].Name ?? string.Empty;
                break;

            case Opcode.ST_ARG_OMIT:
                Comment = script.ArgsSymbols?[funcIndex][operand].Name ?? string.Empty;
                break;

            case Opcode.LD_0:
            case Opcode.LD_1:
            case Opcode.LD_2:
            case Opcode.LD_3:
                Comment = script.LocalPool[script.FunctionPool[funcIndex].LocalPoolIndex][opcode - Opcode.LD_0].Name;
                break;

            case Opcode.ST_0:
            case Opcode.ST_1:
            case Opcode.ST_2:
            case Opcode.ST_3:
                Comment = script.LocalPool[script.FunctionPool[funcIndex].LocalPoolIndex][opcode - Opcode.ST_0].Name;
                break;

            case Opcode.LD_ARG_0:
            case Opcode.LD_ARG_1:
            case Opcode.LD_ARG_2:
            case Opcode.LD_ARG_3:
                Comment = script.ArgsSymbols?[funcIndex][opcode - Opcode.LD_ARG_0].Name ?? string.Empty;
                break;

            case Opcode.ST_ARG_0:
            case Opcode.ST_ARG_1:
            case Opcode.ST_ARG_2:
            case Opcode.ST_ARG_3:
                Comment = script.ArgsSymbols?[funcIndex][opcode - Opcode.ST_ARG_0].Name ?? string.Empty;
                break;

            case Opcode.LD_STATIC:
            case Opcode.LD_STATIC_W:
                Comment = script.StaticVars[operand].Name;
                break;

            case Opcode.ST_STATIC:
            case Opcode.ST_STATIC_W:
                Comment = script.StaticVars[operand].Name;
                break;

            case Opcode.LD_AR:
            case Opcode.ST_AR:
                break;

            case Opcode.LD_NIL:
                break;

            case Opcode.LD_TRUE:
                break;

            case Opcode.LD_FALSE:
                break;

            case Opcode.LD_FUNC:
            case Opcode.LD_FUNC_W:
                break;

            case Opcode.LD_PLUGIN:
            case Opcode.LD_PLUGIN_W:
                break;

            case Opcode.LD_FUNC_FAR:
            case Opcode.LD_FUNC_FAR_W:
                break;

            case Opcode.MINUS:
                break;

            case Opcode.NOT:
                break;

            case Opcode.L_NOT:
                break;

            case Opcode.ADD:
                break;

            case Opcode.SUB:
                break;

            case Opcode.MUL:
                break;

            case Opcode.DIV:
                break;

            case Opcode.MOD:
                break;

            case Opcode.OR:
                break;

            case Opcode.AND:
                break;

            case Opcode.R_SHIFT:
                break;

            case Opcode.L_SHIFT:
                break;

            case Opcode.EQ:
                break;

            case Opcode.NE:
                break;

            case Opcode.GT:
                break;

            case Opcode.LT:
                break;

            case Opcode.GE:
                break;

            case Opcode.LE:
                break;

            case Opcode.L_OR:
                break;

            case Opcode.L_AND:
                break;

            case Opcode.JMP:
            case Opcode.JPF:
                operand = (short)operand;
                Comment = (Address + operand).ToString("x");
                Operand = ((ushort)operand).ToString("x");
                break;

            case Opcode.CALL:
            case Opcode.CALL_W:
                Comment = script.FunctionPool[operand].Name;
                break;

            case Opcode.CALL_IND:
                break;

            case Opcode.RET:
                break;

            case Opcode.NEXT:
                break;

            case Opcode.PLUGIN:
            case Opcode.PLUGIN_W:
                PluginFunction plugin = script.Plugins[operand];
                Comment = $"{plugin.Plugin}::{plugin.Function}";
                break;

            case Opcode.CALL_FAR:
                break;

            case Opcode.CALL_FAR_W:
                break;

            case Opcode.GET_OC:
            case Opcode.GET_OC_W:
                Comment = script.OcImports[operand];
                break;

            case Opcode.GETTER:
                break;

            case Opcode.GETTER_W:
                break;

            case Opcode.SETTER:
                break;

            case Opcode.SETTER_W:
                break;

            case Opcode.SEND:
            case Opcode.SEND_W:
                Comment = script.IdPool[operand];
                break;

            case Opcode.TYPEOF:
                break;

            case Opcode.SIZEOF:
                break;

            case Opcode.SWITCH:
                var values    = new int[operand];
                var addresses = new int[operand];
                if (operand > 0)
                {
                    data.Position += 4;
                }
                for (int i = 0; i < operand; i++)
                {
                    values[i]    = ReadOperand(data, 4);
                    addresses[i] = ReadOperand(data, 4);
                    Comment     += $"case {values[i]}: {addresses[i] + Address:x}\n";
                }

                break;

            case Opcode.INC:
                break;

            case Opcode.DEC:
                break;

            case Opcode.EXIT:
                break;

            case Opcode.BP:
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(opcode), opcode, null);
            }

            if (Operand == null)
            {
                Operand = opcodeInfo.Size > 0 ? operand.ToString() : string.Empty;
            }
        }