コード例 #1
0
ファイル: OSIFile.cs プロジェクト: Vraiment/SAGESharp
            /// <summary>
            /// Reades a FunctionInfo from the given <see cref="BinaryReader"/>.
            /// </summary>
            /// <param name="reader">The BinaryReader to read the function from.</param>
            public FunctionInfo(BinaryReader reader)
            {
                byte nameLength = reader.ReadByte();

                this.Name           = Encoding.ASCII.GetString(reader.ReadBytes(nameLength));
                this.BytecodeOffset = reader.ReadUInt32();
                this.ParameterCount = reader.ReadUInt16();
                this.Instructions   = OSIFile.ReadBytecode(reader, BytecodeOffset);
            }
コード例 #2
0
        private static int DoDecompile(CLIOptions options)
        {
            OSIFile osi = null;

            string osiFilename     = options.Inputs.ElementAt(0);
            string outputDirectory = options.Output == "" ? System.IO.Path.ChangeExtension(osiFilename, "") : options.Output;

            using (System.IO.FileStream stream = new System.IO.FileStream(osiFilename, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read))
                using (System.IO.BinaryReader reader = new System.IO.BinaryReader(stream))
                {
                    osi = new OSIFile(reader);
                }

            if (!System.IO.Directory.Exists(outputDirectory))
            {
                System.IO.Directory.CreateDirectory(outputDirectory);
            }

            Decompiler.DecompileOSIProject(osi, outputDirectory);
            return(EXIT_SUCCESS);
        }
コード例 #3
0
        public JumpStaticInstruction(OSIFile osi, BCLInstruction addressInstruction, BCLInstruction jumpInstruction)
        {
            if (addressInstruction.Opcode != BCLOpcode.PushConstanti32 || jumpInstruction.Opcode != BCLOpcode.JumpRelative)
            {
                throw new ArgumentException("Must take a pair of PushConstanti32 and JumpRelative instructions.");
            }

            _size = addressInstruction.Size + jumpInstruction.Size;
            int targetAddress = addressInstruction.Arguments[0].GetValue <int>();

            ArgumentCount = jumpInstruction.Arguments[0].GetValue <sbyte>();
            foreach (OSIFile.FunctionInfo func in osi.Functions)
            {
                if (func.BytecodeOffset == targetAddress)
                {
                    FunctionName = func.Name;
                    break;
                }
            }
            if (FunctionName == null)
            {
                throw new ArgumentException("Could not find function for address 0x" + targetAddress.ToString("X8"));
            }
        }