Ejemplo n.º 1
0
        public Program VisitInputFile(string projectFilePath, DecompilerInput_v4 sInput)
        {
            var     bytes   = loader.LoadImageBytes(ConvertToAbsolutePath(projectFilePath, sInput.Filename), 0);
            var     sUser   = sInput.User;
            var     address = LoadAddress(sUser, this.arch);
            Program program;

            if (address != null &&
                sUser.Processor != null &&
                (sUser.PlatformOptions == null ||
                 sUser.PlatformOptions.Name != null))
            {
                var arch     = sUser.Processor.Name;
                var platform = sUser.PlatformOptions != null
                    ? sUser.PlatformOptions.Name
                    : null;
                program = loader.LoadRawImage(sInput.Filename, bytes, arch, platform, address);
            }
            else
            {
                program = loader.LoadExecutable(sInput.Filename, bytes, address);
            }
            program.Filename             = ConvertToAbsolutePath(projectFilePath, sInput.Filename);
            program.DisassemblyFilename  = ConvertToAbsolutePath(projectFilePath, sInput.DisassemblyFilename);
            program.IntermediateFilename = ConvertToAbsolutePath(projectFilePath, sInput.IntermediateFilename);
            program.OutputFilename       = ConvertToAbsolutePath(projectFilePath, sInput.OutputFilename);
            program.TypesFilename        = ConvertToAbsolutePath(projectFilePath, sInput.TypesFilename);
            program.GlobalsFilename      = ConvertToAbsolutePath(projectFilePath, sInput.GlobalsFilename);
            program.EnsureFilenames(program.Filename);
            LoadUserData(sUser, program, program.User);
            ProgramLoaded.Fire(this, new ProgramEventArgs(program));
            return(program);
        }
Ejemplo n.º 2
0
        public Program VisitInputFile(string projectFilePath, DecompilerInput_v4 sInput)
        {
            var binAbsPath = ConvertToAbsolutePath(projectFilePath, sInput.Filename) !;
            var bytes      = loader.LoadImageBytes(binAbsPath, 0);
            var sUser      = sInput.User ?? new UserData_v4
            {
                ExtractResources = true,
            };
            var     address     = LoadAddress(sUser, this.arch);
            var     archOptions = XmlOptions.LoadIntoDictionary(sUser.Processor?.Options, StringComparer.OrdinalIgnoreCase);
            Program program;

            if (!string.IsNullOrEmpty(sUser.Loader))
            {
                // The presence of an explicit loader name prompts us to
                // use the LoadRawImage path.
                var archName = sUser.Processor?.Name;
                var platform = sUser.PlatformOptions?.Name;
                program = loader.LoadRawImage(binAbsPath, bytes, address, new LoadDetails
                {
                    LoaderName          = sUser.Loader,
                    ArchitectureName    = archName,
                    ArchitectureOptions = archOptions,
                    PlatformName        = platform,
                    LoadAddress         = sUser.LoadAddress,
                });
            }
            else
            {
                program = loader.LoadExecutable(binAbsPath, bytes, sUser.Loader, address)
                          ?? new Program(); // A previous save of the project was able to read the file,
                                            // but now we can't...
            }
            LoadUserData(sUser, program, program.User, projectFilePath);
            program.Filename             = binAbsPath;
            program.DisassemblyDirectory = ConvertToAbsolutePath(projectFilePath, Path.GetDirectoryName(sInput.DisassemblyFilename));
            program.SourceDirectory      = ConvertToAbsolutePath(projectFilePath, Path.GetDirectoryName(sInput.OutputFilename));
            program.IncludeDirectory     = ConvertToAbsolutePath(projectFilePath, Path.GetDirectoryName(sInput.TypesFilename));
            program.ResourcesDirectory   = ConvertToAbsolutePath(projectFilePath, sInput.ResourcesDirectory);
            program.EnsureDirectoryNames(binAbsPath);
            program.User.LoadAddress = address;
            // We are fettered by backwards compatibility here, don't suddenly change behavior
            // but keep all code in one file. After loading users can change to other policies.
            program.User.OutputFilePolicy = program.User.OutputFilePolicy ?? Program.SingleFilePolicy;
            ProgramLoaded?.Invoke(this, new ProgramEventArgs(program));
            return(program);
        }
Ejemplo n.º 3
0
        public Program VisitInputFile(string projectFilePath, DecompilerInput_v4 sInput)
        {
            var binAbsPath = ConvertToAbsolutePath(projectFilePath, sInput.Filename);
            var bytes      = loader.LoadImageBytes(ConvertToAbsolutePath(projectFilePath, sInput.Filename), 0);
            var sUser      = sInput.User ?? new UserData_v4
            {
                ExtractResources = true,
            };
            var     address     = LoadAddress(sUser, this.arch);
            var     archOptions = XmlOptions.LoadIntoDictionary(sUser.Processor?.Options, StringComparer.OrdinalIgnoreCase);
            Program program;

            if (!string.IsNullOrEmpty(sUser.Loader))
            {
                // The presence of an explicit loader name prompts us to
                // use the LoadRawImage path.
                var arch     = sUser.Processor.Name;
                var platform = sUser.PlatformOptions?.Name;
                program = loader.LoadRawImage(binAbsPath, bytes, address, new LoadDetails
                {
                    LoaderName          = sUser.Loader,
                    ArchitectureName    = arch,
                    ArchitectureOptions = archOptions,
                    PlatformName        = platform,
                    LoadAddress         = sUser.LoadAddress,
                });
            }
            else
            {
                program = loader.LoadExecutable(binAbsPath, bytes, sUser.Loader, address)
                          ?? new Program(); // A previous save of the project was able to read the file,
                                            // but now we can't...
            }
            LoadUserData(sUser, program, program.User);
            program.Filename             = binAbsPath;
            program.DisassemblyFilename  = ConvertToAbsolutePath(projectFilePath, sInput.DisassemblyFilename);
            program.IntermediateFilename = ConvertToAbsolutePath(projectFilePath, sInput.IntermediateFilename);
            program.OutputFilename       = ConvertToAbsolutePath(projectFilePath, sInput.OutputFilename);
            program.TypesFilename        = ConvertToAbsolutePath(projectFilePath, sInput.TypesFilename);
            program.GlobalsFilename      = ConvertToAbsolutePath(projectFilePath, sInput.GlobalsFilename);
            program.ResourcesDirectory   = ConvertToAbsolutePath(projectFilePath, sInput.ResourcesDirectory);
            program.EnsureFilenames(program.Filename);
            program.User.LoadAddress = address;
            ProgramLoaded.Fire(this, new ProgramEventArgs(program));
            return(program);
        }
Ejemplo n.º 4
0
        public Program VisitInputFile(string projectFilePath, DecompilerInput_v4 sInput)
        {
            var     binAbsPath = ConvertToAbsolutePath(projectFilePath, sInput.Filename);
            var     bytes      = loader.LoadImageBytes(ConvertToAbsolutePath(projectFilePath, sInput.Filename), 0);
            var     sUser      = sInput.User;
            var     address    = LoadAddress(sUser, this.arch);
            Program program;

            if (!string.IsNullOrEmpty(sUser.Loader))
            {
                // The presence of an explicit loader name prompts us to
                // use the LoadRawImage path.
                var arch     = sUser.Processor.Name;
                var platform = sUser.PlatformOptions?.Name;
                program = loader.LoadRawImage(binAbsPath, bytes, address, new LoadDetails
                {
                    LoaderName       = sUser.Loader,
                    ArchitectureName = arch,
                    PlatformName     = platform,
                    LoadAddress      = sUser.LoadAddress,
                });
            }
            else
            {
                program = loader.LoadExecutable(binAbsPath, bytes, sUser.Loader, address);
            }
            program.Filename             = binAbsPath;
            program.DisassemblyFilename  = ConvertToAbsolutePath(projectFilePath, sInput.DisassemblyFilename);
            program.IntermediateFilename = ConvertToAbsolutePath(projectFilePath, sInput.IntermediateFilename);
            program.OutputFilename       = ConvertToAbsolutePath(projectFilePath, sInput.OutputFilename);
            program.TypesFilename        = ConvertToAbsolutePath(projectFilePath, sInput.TypesFilename);
            program.GlobalsFilename      = ConvertToAbsolutePath(projectFilePath, sInput.GlobalsFilename);
            program.EnsureFilenames(program.Filename);
            LoadUserData(sUser, program, program.User);
            program.User.LoadAddress = address;
            ProgramLoaded.Fire(this, new ProgramEventArgs(program));
            return(program);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Migrate DecompilerInput_v4 to DecompilerInput_v5.
        /// </summary>
        /// <remarks>
        /// Ignored fields (They existed in v4 but are unused in current code):
        ///     IntermediateFilename
        ///     GlobalsFilename
        /// </remarks>
        public static DecompilerInput_v5 MigrateDecompilerInput(DecompilerInput_v4 v4)
        {
            var v5 = new DecompilerInput_v5()
            {
                Filename             = v4.Filename,
                Comment              = v4.Comment,
                DisassemblyDirectory = v4.DisassemblyFilename != null?Path.GetDirectoryName(v4.DisassemblyFilename) : null,
                                           SourceDirectory = v4.OutputFilename != null?Path.GetDirectoryName(v4.OutputFilename) : null,
                                                                 IncludeDirectory = v4.TypesFilename != null?Path.GetDirectoryName(v4.TypesFilename) : null,
                                                                                        ResourcesDirectory = v4.ResourcesDirectory,
                                                                                        User = v4.User ?? new UserData_v4
                {
                    ExtractResources = true,
                }
            };

            if (string.IsNullOrWhiteSpace(v5.User.OutputFilePolicy))
            {
                v5.User.OutputFilePolicy = Program.SingleFilePolicy;
            }

            return(v5);
        }