Ejemplo n.º 1
0
        public void Process(File file, TextWriter writer)
        {
            var decoder  = new Decoder(file);
            var program  = new ScriptProgram(decoder);
            var analyzer = new ControlFlowAnalyzer(program);

            analyzer.Analyze();

            // Dump the code paths
            foreach (Function function in program.Functions)
            {
                writer.WriteLine("function " + function.Name);
                foreach (CodePath path in function.CodePaths)
                {
                    writer.WriteLine("    " + path.Name + ":");
                    writer.WriteLine(string.Format("        0x{0:x} --> 0x{1:x}", path.StartOffset, path.EndOffset));
                    if (path.ParentCodePath != null)
                    {
                        writer.WriteLine("        parent: {0}, exit: 0x{1:x}, reentry: 0x{2:x}",
                                         path.ParentCodePath.Name, path.ParentExitInstruction.Instruction.Offset,
                                         path.ParentEntryTargetInstruction.Instruction.Offset);
                    }
                }
                writer.WriteLine();
            }
        }
Ejemplo n.º 2
0
        public void Process(File file, TextWriter writer)
        {
            var decoder = new Decoder(file);
            var program = new ScriptProgram(decoder);
            var analyzer = new ControlFlowAnalyzer(program);
            analyzer.Analyze();

            // Dump the code paths
            foreach (Function function in program.Functions)
            {
                writer.WriteLine("function " + function.Name);
                foreach (CodePath path in function.CodePaths)
                {
                    writer.WriteLine("    " + path.Name + ":");
                    writer.WriteLine(string.Format("        0x{0:x} --> 0x{1:x}", path.StartOffset, path.EndOffset));
                    if (path.ParentCodePath != null)
                    {
                        writer.WriteLine("        parent: {0}, exit: 0x{1:x}, reentry: 0x{2:x}",
                                         path.ParentCodePath.Name, path.ParentExitInstruction.Instruction.Offset,
                                         path.ParentEntryTargetInstruction.Instruction.Offset);
                    }
                }
                writer.WriteLine();
            }
        }
Ejemplo n.º 3
0
        public void Process(File file, TextWriter writer)
        {
            var decoder = new Decoder(file);
            var program = new ScriptProgram(decoder);
            var analyzer = new ControlFlowAnalyzer(program);
            analyzer.Analyze();

            foreach (Function function in program.Functions)
            {
                writer.WriteLine(string.Format(".function {0} (params={1}, vars={2}, return={3})",
                                               function.Name, function.ParameterCount, function.VariableCount, function.ReturnCount));

                ProcessCodePath(writer, function.MainCodePath, "   ");

                writer.WriteLine(".endfunction");
                writer.WriteLine();
            }
        }
Ejemplo n.º 4
0
        public void Process(File file, TextWriter writer)
        {
            var decoder  = new Decoder(file);
            var program  = new ScriptProgram(decoder);
            var analyzer = new ControlFlowAnalyzer(program);

            analyzer.Analyze();

            foreach (Function function in program.Functions)
            {
                writer.WriteLine(string.Format(".function {0} (params={1}, vars={2}, return={3})",
                                               function.Name, function.ParameterCount, function.VariableCount, function.ReturnCount));

                ProcessCodePath(writer, function.MainCodePath, "   ");

                writer.WriteLine(".endfunction");
                writer.WriteLine();
            }
        }
Ejemplo n.º 5
0
        public void Process(File file, TextWriter writer)
        {
            var decoder = new Decoder(file);

            int length = file.Code.Length;
            int offset = 0;
            while (offset < length)
            {
                Instruction instruction = decoder.Decode(offset);
                writer.WriteLine(instruction.ToString());
                //instruction.ToString();

                offset += instruction.InstructionLength;
            }

            /*
            foreach (uint item in Scruff.Script.Natives.UnknownNatives)
            {
                writer.WriteLine(string.Format("0x{0:x}", item));
            }
             * */
        }
Ejemplo n.º 6
0
        public void Process(File file, TextWriter writer)
        {
            var decoder = new Decoder(file);

            int length = file.Code.Length;
            int offset = 0;

            while (offset < length)
            {
                Instruction instruction = decoder.Decode(offset);
                writer.WriteLine(instruction.ToString());
                //instruction.ToString();

                offset += instruction.InstructionLength;
            }

            /*
             * foreach (uint item in Scruff.Script.Natives.UnknownNatives)
             * {
             *  writer.WriteLine(string.Format("0x{0:x}", item));
             * }
             * */
        }
Ejemplo n.º 7
0
 public Decoder(File file)
 {
     File = file;
 }
Ejemplo n.º 8
0
        public void Process(File file, TextWriter writer)
        {
            var decoder  = new Decoder(file);
            var program  = new ScriptProgram(decoder);
            var analyzer = new ControlFlowAnalyzer(program);

            analyzer.Analyze();

            var stackAnalyzer = new StackUseAnalyzer(program);

            stackAnalyzer.Analyze();

            foreach (Function function in program.Functions)
            {
                var sb = new StringBuilder();
                for (int i = 0; i < function.ParameterCount; i++)
                {
                    if (i != 0)
                    {
                        sb.Append(", ");
                    }
                    sb.Append("var");
                    sb.Append(i);
                }

                writer.WriteLine(string.Format("{0} {1}({2})", function.ReturnCount > 0 ? "function" : "void",
                                               function.Name, sb));
                writer.WriteLine("{");

                if (function.VariableCount > 2)
                {
                    writer.Write("   auto ");
                    for (int i = 2; i < function.VariableCount; i++)
                    {
                        if (i != 2)
                        {
                            writer.Write(", ");
                        }
                        writer.Write("var" + (i + function.ParameterCount));
                    }
                    writer.WriteLine(";");
                }

                if (function.TemporaryCount > 0)
                {
                    writer.Write("   auto ");
                    for (int i = 0; i < function.TemporaryCount; i++)
                    {
                        if (i != 0)
                        {
                            writer.Write(", ");
                        }
                        writer.Write("temp" + i);
                    }
                    writer.WriteLine(";");
                }

                if (function.TemporaryCount > 0 || function.VariableCount > 2)
                {
                    writer.WriteLine();
                }

                ProcessCodePath(writer, function.MainCodePath, "   ");

                writer.WriteLine("}");
                writer.WriteLine();
            }
        }
Ejemplo n.º 9
0
        public void Process(File file, TextWriter writer)
        {
            var decoder = new Decoder(file);
            var program = new ScriptProgram(decoder);
            var analyzer = new ControlFlowAnalyzer(program);
            analyzer.Analyze();

            var stackAnalyzer = new StackUseAnalyzer(program);
            stackAnalyzer.Analyze();

            foreach (Function function in program.Functions)
            {
                var sb = new StringBuilder();
                for (int i = 0; i < function.ParameterCount; i++)
                {
                    if (i != 0)
                    {
                        sb.Append(", ");
                    }
                    sb.Append("var");
                    sb.Append(i);
                }

                writer.WriteLine(string.Format("{0} {1}({2})", function.ReturnCount > 0 ? "function" : "void",
                                               function.Name, sb));
                writer.WriteLine("{");

                if (function.VariableCount > 2)
                {
                    writer.Write("   auto ");
                    for (int i = 2; i < function.VariableCount; i++)
                    {
                        if (i != 2)
                        {
                            writer.Write(", ");
                        }
                        writer.Write("var" + (i + function.ParameterCount));
                    }
                    writer.WriteLine(";");
                }

                if (function.TemporaryCount > 0)
                {
                    writer.Write("   auto ");
                    for (int i = 0; i < function.TemporaryCount; i++)
                    {
                        if (i != 0)
                        {
                            writer.Write(", ");
                        }
                        writer.Write("temp" + i);
                    }
                    writer.WriteLine(";");
                }

                if (function.TemporaryCount > 0 || function.VariableCount > 2)
                {
                    writer.WriteLine();
                }

                ProcessCodePath(writer, function.MainCodePath, "   ");

                writer.WriteLine("}");
                writer.WriteLine();
            }
        }