SectionHeaderFileStream() public method

public SectionHeaderFileStream ( Elf SectionHeader ) : Stream
SectionHeader Elf
return Stream
Beispiel #1
0
        public void Load(Stream FileStream, Stream MemoryStream, MemoryPartition MemoryPartition, HleModuleManager ModuleManager)
        {
            this.ElfLoader = new ElfLoader();
            this.ModuleManager = ModuleManager;

            this.ElfLoader.Load(FileStream);

            PspEmulatorContext.PspConfig.InfoExeHasRelocation = this.ElfLoader.NeedsRelocation;

            BaseAddress = (uint)(this.ElfLoader.NeedsRelocation ? 0x08900000 : 0);

            this.ElfLoader.AllocateAndWrite(MemoryStream, MemoryPartition, BaseAddress);

            if (this.ElfLoader.NeedsRelocation)
            {
                RelocateFromHeaders();
            }

            this.ModuleInfo = ElfLoader.SectionHeaderFileStream(ElfLoader.SectionHeadersByName[".rodata.sceModuleInfo"]).ReadStruct<ElfPsp.ModuleInfo>(); ;

            //Console.WriteLine(this.ModuleInfo.ToStringDefault());

            this.InitInfo.PC = ElfLoader.Header.EntryPoint + BaseAddress;
            this.InitInfo.GP = this.ModuleInfo.GP + BaseAddress;

            UpdateModuleImports();
        }
Beispiel #2
0
        public void Load(Stream FileStream, Stream MemoryStream, MemoryPartition MemoryPartition, HleModuleManager ModuleManager)
        {
            this.ElfLoader     = new ElfLoader();
            this.ModuleManager = ModuleManager;

            this.ElfLoader.Load(FileStream);

            PspEmulatorContext.PspConfig.InfoExeHasRelocation = this.ElfLoader.NeedsRelocation;

            BaseAddress = (uint)(this.ElfLoader.NeedsRelocation ? 0x08900000 : 0);

            this.ElfLoader.AllocateAndWrite(MemoryStream, MemoryPartition, BaseAddress);

            if (this.ElfLoader.NeedsRelocation)
            {
                RelocateFromHeaders();
            }

            this.ModuleInfo = ElfLoader.SectionHeaderFileStream(ElfLoader.SectionHeadersByName[".rodata.sceModuleInfo"]).ReadStruct <ElfPsp.ModuleInfo>();;

            //Console.WriteLine(this.ModuleInfo.ToStringDefault());

            this.InitInfo.PC = ElfLoader.Header.EntryPoint + BaseAddress;
            this.InitInfo.GP = this.ModuleInfo.GP + BaseAddress;

            UpdateModuleImports();
        }
Beispiel #3
0
        protected void RelocateFromHeaders()
        {
            if ((BaseAddress & 0xFFFF) != 0)
            {
                throw(new NotImplementedException("Can't relocate with the BaseAddress.LO16 != 0"));
            }

            // Relocate from program headers
            foreach (var ProgramHeader in ElfLoader.ProgramHeaders)
            {
                switch (ProgramHeader.Type)
                {
                case Elf.ProgramHeader.TypeEnum.Reloc1:
                    Console.Error.WriteLine("NOT IMPLEMENTED Elf.ProgramHeader.TypeEnum.Reloc1!");
                    //RelocateRelocs(ElfLoader.ProgramHeaderFileStream(ProgramHeader).ReadStructVectorUntilTheEndOfStream<Elf.Reloc>());
                    //throw (new NotImplementedException());

                    /*
                     * int RelCount = (int)phdr.getP_filesz() / Elf32Relocate.sizeof();
                     * f.position((int)(elfOffset + phdr.getP_offset()));
                     * relocateFromBuffer(f, module, baseAddress, elf, RelCount);
                     */
                    break;

                case Elf.ProgramHeader.TypeEnum.Reloc2:
                    throw(new NotImplementedException());
                }
            }

            foreach (var SectionHeader in ElfLoader.SectionHeaders)
            {
                switch (SectionHeader.Type)
                {
                case Elf.SectionHeader.TypeEnum.Relocation:
                    Console.Error.WriteLine("Not implemented Elf.SectionHeader.TypeEnum.Relocation");
                    //throw (new NotImplementedException("Not implemented Elf.SectionHeader.TypeEnum.Relocation"));
                    break;

                case Elf.SectionHeader.TypeEnum.PrxRelocation:
                    RelocateRelocs(
                        ElfLoader.SectionHeaderFileStream(SectionHeader).ReadStructVectorUntilTheEndOfStream <Elf.Reloc>()
                        );
                    break;

                case Elf.SectionHeader.TypeEnum.PrxRelocation_FW5:
                    throw (new Exception("Not implemented ElfSectionHeader.Type.PrxRelocation_FW5"));
                }
            }
        }
Beispiel #4
0
        public HleModuleGuest LoadModule(Stream FileStream, Stream MemoryStream, MemoryPartition MemoryPartition, HleModuleManager ModuleManager, String GameTitle, string ModuleName, bool IsMainModule)
        {
            this.HleModuleGuest = new HleModuleGuest(PspEmulatorContext);

            this.ElfLoader = new ElfLoader();
            this.ModuleManager = ModuleManager;

            var Magic = FileStream.SliceWithLength(0, 4).ReadString(4);
            Logger.Info("Magic: '{0}'", Magic);
            if (Magic == "~PSP")
            {
                try
                {
                    var DecryptedData = new EncryptedPrx().Decrypt(FileStream.ReadAll(), true);
                    File.WriteAllBytes("last_decoded_prx.bin", DecryptedData);
                    FileStream = new MemoryStream(DecryptedData);
                }
                catch (Exception Exception)
                {
                    Logger.Error(Exception);
                    throw (Exception);
                }
            }

            this.ElfLoader.Load(FileStream, ModuleName);

            PspEmulatorContext.PspConfig.InfoExeHasRelocation = this.ElfLoader.NeedsRelocation;

            if (this.ElfLoader.NeedsRelocation)
            {
                var DummyPartition = MemoryPartition.Allocate(
                    0x4000,
                    Name: "Dummy"
                );
                BaseAddress = MemoryPartition.ChildPartitions.OrderByDescending(Partition => Partition.Size).First().Low;
                Logger.Info("BASE ADDRESS (Try    ): 0x{0:X}", BaseAddress);
                BaseAddress = MathUtils.NextAligned(BaseAddress, 0x1000);
                Logger.Info("BASE ADDRESS (Aligned): 0x{0:X}", BaseAddress);
            }
            else
            {
                BaseAddress = 0;
            }

            PspEmulatorContext.PspConfig.RelocatedBaseAddress = BaseAddress;
            PspEmulatorContext.PspConfig.GameTitle = GameTitle;

            this.ElfLoader.AllocateAndWrite(MemoryStream, MemoryPartition, BaseAddress);

            if (this.ElfLoader.NeedsRelocation)
            {
                RelocateFromHeaders();
            }

            if (!ElfLoader.SectionHeadersByName.ContainsKey(".rodata.sceModuleInfo"))
            {
                throw(new Exception("Can't find segment '.rodata.sceModuleInfo'"));
            }

            HleModuleGuest.ModuleInfo = ElfLoader.SectionHeaderFileStream(ElfLoader.SectionHeadersByName[".rodata.sceModuleInfo"]).ReadStruct<ElfPsp.ModuleInfo>(); ;

            //Console.WriteLine(this.ModuleInfo.ToStringDefault());

            HleModuleGuest.InitInfo = new InitInfoStruct()
            {
                PC = ElfLoader.Header.EntryPoint + BaseAddress,
                GP = HleModuleGuest.ModuleInfo.GP + BaseAddress,
            };

            UpdateModuleImports();
            UpdateModuleExports();

            ModuleManager.LoadedGuestModules.Add(HleModuleGuest);

            return HleModuleGuest;
        }
Beispiel #5
0
        protected void RelocateFromHeaders()
        {
            if ((BaseAddress & 0xFFFF) != 0)
            {
                //throw(new NotImplementedException("Can't relocate with the BaseAddress.LO16 != 0"));
            }

            // Relocate from program headers
            var relocProgramIndex = 0;

            foreach (var programHeader in ElfLoader.ProgramHeaders)
            {
                RelocOutput?.WriteLine("Program Header: %d".Sprintf(relocProgramIndex++));
                switch (programHeader.Type)
                {
                case Elf.ProgramHeader.TypeEnum.Reloc1:
                    _logger.Warning("SKIPPING Elf.ProgramHeader.TypeEnum.Reloc1!");
                    break;

                case Elf.ProgramHeader.TypeEnum.Reloc2:
                    throw new NotImplementedException();
                }
            }

            var relocSectionIndex = 0;

            foreach (var sectionHeader in ElfLoader.SectionHeaders)
            {
                //RelocOutput.WriteLine("Section Header: %d : %s".Sprintf(RelocSectionIndex++, SectionHeader.ToString()));
                RelocOutput?.WriteLine("Section Header: %d".Sprintf(relocSectionIndex++));

                switch (sectionHeader.Type)
                {
                case Elf.SectionHeader.TypeEnum.Relocation:
                    Console.Error.WriteLine("Not implemented Elf.SectionHeader.TypeEnum.Relocation");
                    //throw (new NotImplementedException("Not implemented Elf.SectionHeader.TypeEnum.Relocation"));
                    //break;

                    /*
                     * RelocateRelocs(
                     *  ElfLoader.SectionHeaderFileStream(SectionHeader).ReadStructVectorUntilTheEndOfStream<Elf.Reloc>()
                     * );
                     */
                    break;

                case Elf.SectionHeader.TypeEnum.PrxRelocation:
                    Logger.Info("PrxRelocation : {0}", sectionHeader);
                    RelocateRelocs(
                        ElfLoader.SectionHeaderFileStream(sectionHeader)
                        .ReadStructVectorUntilTheEndOfStream <Elf.Reloc>()
                        );
                    break;

                case Elf.SectionHeader.TypeEnum.PrxRelocationFw5:
                    throw new Exception("Not implemented ElfSectionHeader.Type.PrxRelocation_FW5");
                }
            }

            if (RelocOutput != null)
            {
                RelocOutput.Flush();
                _relocOutputStream.Flush();
                RelocOutput.Close();
                _relocOutputStream.Close();

                _relocOutput       = null;
                _relocOutputStream = null;
            }
        }