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(); }
protected Action<CpuThreadState> CreateDelegate(HleModuleManager ModuleManager, HleModuleHost Module, uint NID, string ModuleImportName, string NIDName) { Action<CpuThreadState> Callback = null; if (Module != null) { Callback = Module.DelegatesByNID.GetOrDefault(NID, null); } return (CpuThreadState) => { if (Callback == null) { if (CpuThreadState.CpuProcessor.PspConfig.DebugSyscalls) { Console.WriteLine( "Thread({0}:'{1}'):{2}:{3}", PspEmulatorContext.GetInstance<HleThreadManager>().Current.Id, PspEmulatorContext.GetInstance<HleThreadManager>().Current.Name, ModuleImportName, NIDName ); } throw (new NotImplementedException("Not Implemented '" + String.Format("{0}:{1}", ModuleImportName, NIDName) + "'")); } else { Callback(CpuThreadState); } }; }
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(); }
protected Action <CpuThreadState> CreateDelegate(HleModuleManager ModuleManager, HleModuleHost Module, uint NID, string ModuleImportName, string NIDName) { Action <CpuThreadState> Callback = null; if (Module != null) { Callback = Module.DelegatesByNID.GetOrDefault(NID, null); } return((CpuThreadState) => { if (Callback == null) { if (CpuThreadState.CpuProcessor.PspConfig.DebugSyscalls) { Console.WriteLine( "Thread({0}:'{1}'):{2}:{3}", PspEmulatorContext.GetInstance <HleThreadManager>().Current.Id, PspEmulatorContext.GetInstance <HleThreadManager>().Current.Name, ModuleImportName, NIDName ); } throw (new NotImplementedException("Not Implemented '" + String.Format("{0}:{1}", ModuleImportName, NIDName) + "'")); } else { Callback(CpuThreadState); } }); }
public override void InitializeComponent() { this.IsRunning = true; this.CpuProcessor = PspEmulatorContext.GetInstance <CpuProcessor>(); this.GpuProcessor = PspEmulatorContext.GetInstance <GpuProcessor>(); this.PspAudio = PspEmulatorContext.GetInstance <PspAudio>(); this.PspConfig = PspEmulatorContext.PspConfig; this.PspRtc = PspEmulatorContext.GetInstance <PspRtc>(); this.PspDisplay = PspEmulatorContext.GetInstance <PspDisplay>(); this.PspController = PspEmulatorContext.GetInstance <PspController>(); this.MipsEmiter = new MipsEmiter(); this.Kirk = new Kirk(); this.Kirk.kirk_init(); this.HleOutputHandler = PspEmulatorContext.GetInstance <HleOutputHandler>(); // @TODO FIX! New Instances!? this.ThreadManager = PspEmulatorContext.GetInstance <HleThreadManager>(); this.SemaphoreManager = PspEmulatorContext.GetInstance <HleSemaphoreManager>(); this.EventFlagManager = PspEmulatorContext.GetInstance <HleEventFlagManager>(); this.MemoryManager = new HleMemoryManager(this.CpuProcessor.Memory); this.ModuleManager = PspEmulatorContext.GetInstance <HleModuleManager>(); this.CallbackManager = PspEmulatorContext.GetInstance <HleCallbackManager>(); this.HleIoManager = PspEmulatorContext.GetInstance <HleIoManager>(); this.HleRegistryManager = PspEmulatorContext.GetInstance <HleRegistryManager>(); this.HleInterruptManager = PspEmulatorContext.GetInstance <HleInterruptManager>(); }
protected Action <CpuThreadState> CreateDelegate(HleModuleManager ModuleManager, HleModuleHost Module, uint NID, string ModuleImportName, string NIDName) { Action <CpuThreadState> Callback = null; if (Module != null) { if (Module.EntriesByNID.ContainsKey(NID)) { Callback = Module.EntriesByNID[NID].Delegate; } else { Callback = null; } } return((CpuThreadState) => { if (Callback == null) { if (CpuThreadState.CpuProcessor.CpuConfig.DebugSyscalls) { Console.WriteLine( "Thread({0}:'{1}'):{2}:{3}", HleThreadManager.Current.Id, HleThreadManager.Current.Name, ModuleImportName, NIDName ); } throw (new NotImplementedException("Not Implemented '" + $"{ModuleImportName}:{NIDName}" + "'")); } else { Callback(CpuThreadState); } }); }
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; }
protected Action<CpuThreadState> CreateDelegate(HleModuleManager ModuleManager, HleModuleHost Module, uint NID, string ModuleImportName, string NIDName) { Action<CpuThreadState> Callback = null; if (Module != null) { if (Module.EntriesByNID.ContainsKey(NID)) { Callback = Module.EntriesByNID[NID].Delegate; } else { Callback = null; } } return (CpuThreadState) => { if (Callback == null) { if (CpuThreadState.CpuProcessor.CpuConfig.DebugSyscalls) { Console.WriteLine( "Thread({0}:'{1}'):{2}:{3}", HleThreadManager.Current.Id, HleThreadManager.Current.Name, ModuleImportName, NIDName ); } throw (new NotImplementedException("Not Implemented '" + String.Format("{0}:{1}", ModuleImportName, NIDName) + "'")); } else { Callback(CpuThreadState); } }; }
public HleModuleGuest LoadModule(Stream fileStream, Stream memoryStream, MemoryPartition memoryPartition, HleModuleManager moduleManager, string gameTitle, string moduleName, bool isMainModule) { HleModuleGuest = InjectContext.NewInstance <HleModuleGuest>(); ElfLoader = new ElfLoader(); 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; } } ElfLoader.Load(fileStream, moduleName); ElfConfig.InfoExeHasRelocation = ElfLoader.NeedsRelocation; if (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; } ElfConfig.RelocatedBaseAddress = BaseAddress; ElfConfig.GameTitle = gameTitle; ElfLoader.AllocateAndWrite(memoryStream, memoryPartition, BaseAddress); LoadModuleInfo(); if (ElfLoader.NeedsRelocation) { RelocateFromHeaders(); } LoadModuleInfo(); //Console.WriteLine(this.ModuleInfo.ToStringDefault()); HleModuleGuest.InitInfo = new InitInfoStruct() { Pc = ElfLoader.Header.EntryPoint + BaseAddress, Gp = HleModuleGuest.ModuleInfo.Gp, }; UpdateModuleImports(); UpdateModuleExports(); moduleManager.LoadedGuestModules.Add(HleModuleGuest); return(HleModuleGuest); }