public virtual void sceIoOpen(int result, int filename_addr, string filename, int flags, int permissions, string mode) { // File handle list if (result >= 0) { FileHandleInfo info = new FileHandleInfo(result, filename); fileHandleIdMap[result] = info; sortRequired = true; } string filelog = string.Format("path=0x{0:X8}('{1}')", filename_addr, filename); if (filename.StartsWith("disc0:/sce_lbn", StringComparison.Ordinal)) { // try to resolve LBA addressing if possible UmdIsoReader iso = Modules.IoFileMgrForUserModule.IsoReader; if (iso != null) { string filePath = filename; filePath = filePath.Substring(14); // Length of "disc0:/sce_lba" int sep = filePath.IndexOf("_size", StringComparison.Ordinal); int fileStart = Integer.decode(filePath.Substring(0, sep)); string resolved = iso.getFileName(fileStart); if (!string.ReferenceEquals(resolved, null)) { filelog = string.Format("path=0x{0:X8}('{1}', '{2}')", filename_addr, filename, resolved); } } } filelog += string.Format(" flags=0x{0:X4}, permissions=0x{1:X4}({2})", flags, permissions, mode); // File Command list logFileCommand(new FileCommandInfo(this, "open", result, filelog)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public pspsharp.HLE.VFS.IVirtualFile ioReadForLoadExec() throws java.io.FileNotFoundException, java.io.IOException public virtual IVirtualFile ioReadForLoadExec() { UmdIsoReader iso = IsoReader; IVirtualFileSystem vfs = new UmdIsoVirtualFileSystem(iso); return(vfs.ioOpen("PSP_GAME/SYSDIR/EBOOT.BIN", IoFileMgrForUser.PSP_O_RDONLY, 0)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public Iso9660Directory(pspsharp.filesystems.umdiso.UmdIsoReader r, int directorySector, long directorySize) throws java.io.IOException public Iso9660Directory(UmdIsoReader r, int directorySector, long directorySize) { // parse directory sector UmdIsoFile dataStream = new UmdIsoFile(r, directorySector, directorySize, null, null); files = new List <Iso9660File>(); sbyte[] b = new sbyte[256]; while (directorySize >= 1) { int entryLength = dataStream.read(); // This is assuming that the padding bytes are always filled with 0's. if (entryLength == 0) { directorySize--; continue; } directorySize -= entryLength; int readLength = dataStream.read(b, 0, entryLength - 1); Iso9660File file = new Iso9660File(b, readLength, r.hasJolietExtension()); files.Add(file); } dataStream.Dispose(); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public Iso9660Handler(pspsharp.filesystems.umdiso.UmdIsoReader r) throws java.io.IOException public Iso9660Handler(UmdIsoReader r) : base(r, 0, 0) { sbyte[] sector; if (r.hasJolietExtension()) { sector = r.readSector(UmdIsoReader.startSectorJoliet); } else { sector = r.readSector(UmdIsoReader.startSector); } System.IO.MemoryStream byteStream = new System.IO.MemoryStream(sector); byteStream.skip(157); // reach rootDirTocHeader sbyte[] b = new sbyte[38]; byteStream.Read(b, 0, b.Length); Iso9660File rootDirEntry = new Iso9660File(b, b.Length, r.hasJolietExtension()); int rootLBA = rootDirEntry.LBA; long rootSize = rootDirEntry.Size; internalDir = new Iso9660Directory(r, rootLBA, rootSize); }
public UmdBrowserPmf(UmdIsoReader iso, string fileName, JLabel display) { this.iso = iso; this.fileName = fileName; this.display = display; init(); initVideo(); }
protected internal virtual void hleDelayedUmdSwitch(UmdIsoReader iso) { Modules.IoFileMgrForUserModule.IsoReader = iso; IsoReader = iso; int notifyArg = NotificationArg | PSP_UMD_CHANGED; Modules.ThreadManForUserModule.hleKernelNotifyCallback(SceKernelThreadInfo.THREAD_CALLBACK_UMD, notifyArg); }
public virtual void hleUmdSwitch(UmdIsoReader newIso) { Scheduler scheduler = Scheduler.Instance; long delayedUmdSwitchSchedule = Scheduler.Now; if (iso != null) { // First notify that the UMD has been removed scheduler.addAction(new DelayedUmdRemoved()); // After 100ms delay, notify that a new UMD has been inserted delayedUmdSwitchSchedule += 100 * 1000; } scheduler.addAction(delayedUmdSwitchSchedule, new DelayedUmdSwitch(newIso)); }
public virtual int hleKernelLoadExec(ByteBuffer moduleBuffer, int argSize, int argAddr, string moduleFileName, UmdIsoReader iso) { sbyte[] arguments = null; if (argSize > 0) { // Save the memory content for the arguments because // the memory would be overwritten by the loading of the new module. arguments = new sbyte[argSize]; IMemoryReader memoryReader = MemoryReader.getMemoryReader(argAddr, argSize, 1); for (int i = 0; i < argSize; i++) { arguments[i] = (sbyte)memoryReader.readNext(); } } // Flush system memory to mimic a real PSP reset. Modules.SysMemUserForUserModule.reset(); try { if (moduleBuffer != null) { SceModule module = Emulator.Instance.load(moduleFileName, moduleBuffer, true); Emulator.Clock.resume(); // After a sceKernelLoadExec, host0: is relative to the directory where // the loaded file (prx) was located. // E.g.: // after // sceKernelLoadExec("disc0:/PSP_GAME/USRDIR/A.PRX") // the following file access // sceIoOpen("host0:B") // is actually referencing the file // disc0:/PSP_GAME/USRDIR/B if (!string.ReferenceEquals(moduleFileName, null)) { int pathIndex = moduleFileName.LastIndexOf("/", StringComparison.Ordinal); if (pathIndex >= 0) { Modules.IoFileMgrForUserModule.Host0Path = moduleFileName.Substring(0, pathIndex + 1); } } if ((module.fileFormat & Loader.FORMAT_ELF) != Loader.FORMAT_ELF) { Console.WriteLine("sceKernelLoadExec - failed, target is not an ELF"); throw new SceKernelErrorException(ERROR_KERNEL_ILLEGAL_LOADEXEC_FILENAME); } // Set the given arguments to the root thread. // Do not pass the file name as first parameter (tested on PSP). SceKernelThreadInfo rootThread = Modules.ThreadManForUserModule.getRootThread(module); Modules.ThreadManForUserModule.hleKernelSetThreadArguments(rootThread, arguments, argSize); // The memory model (32MB / 64MB) could have been changed, update the RuntimeContext RuntimeContext.updateMemory(); if (iso != null) { Modules.IoFileMgrForUserModule.IsoReader = iso; Modules.sceUmdUserModule.IsoReader = iso; } } } catch (GeneralJpcspException e) { Console.WriteLine("General Error", e); Emulator.PauseEmu(); } catch (IOException e) { Console.WriteLine(string.Format("sceKernelLoadExec - Error while loading module '{0}'", moduleFileName), e); return(ERROR_KERNEL_PROHIBIT_LOADEXEC_DEVICE); } return(0); }
public virtual int hleKernelLoadExec(PspString filename, int argSize, int argAddr) { string name = filename.String; // The PSP is replacing a loadexec of disc0:/PSP_GAME/SYSDIR/BOOT.BIN with EBOOT.BIN if (name.Equals(unencryptedBootPath)) { Console.WriteLine(string.Format("sceKernelLoadExec '{0}' replaced by '{1}'", name, encryptedBootPath)); name = encryptedBootPath; } ByteBuffer moduleBuffer = null; IVirtualFile vFile = Modules.IoFileMgrForUserModule.getVirtualFile(name, IoFileMgrForUser.PSP_O_RDONLY, 0); UmdIsoReader iso = null; if (vFile is XmbIsoVirtualFile) { try { IVirtualFile vFileLoadExec = ((XmbIsoVirtualFile)vFile).ioReadForLoadExec(); if (vFileLoadExec != null) { iso = ((XmbIsoVirtualFile)vFile).IsoReader; vFile.ioClose(); vFile = vFileLoadExec; } } catch (IOException e) { Console.WriteLine("hleKernelLoadExec", e); } } if (vFile != null) { sbyte[] moduleBytes = Utilities.readCompleteFile(vFile); vFile.ioClose(); if (moduleBytes != null) { moduleBuffer = ByteBuffer.wrap(moduleBytes); } } else { SeekableDataInput moduleInput = Modules.IoFileMgrForUserModule.getFile(name, IoFileMgrForUser.PSP_O_RDONLY); if (moduleInput != null) { try { sbyte[] moduleBytes = new sbyte[(int)moduleInput.Length()]; moduleInput.readFully(moduleBytes); moduleInput.Dispose(); moduleBuffer = ByteBuffer.wrap(moduleBytes); } catch (IOException e) { Console.WriteLine(string.Format("sceKernelLoadExec - Error while loading module '{0}'", name), e); return(ERROR_KERNEL_PROHIBIT_LOADEXEC_DEVICE); } } } return(hleKernelLoadExec(moduleBuffer, argSize, argAddr, name, iso)); }
public DelayedUmdSwitch(UmdIsoReader iso) { this.iso = iso; }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public UmdIsoReaderVirtualFile(String fileName) throws java.io.IOException public UmdIsoReaderVirtualFile(string fileName) : base(null) { iso = new UmdIsoReader(fileName); }
public XmbIsoVirtualFile(string umdFilename) : base(null) { this.umdFilename = umdFilename; umdName = System.IO.Path.GetFileName(umdFilename); File cacheDirectory = new File(CacheDirectory); bool createCacheFiles = !cacheDirectory.Directory; if (createCacheFiles) { cacheDirectory.mkdirs(); } try { UmdIsoReader iso = new UmdIsoReader(umdFilename); IVirtualFileSystem vfs = new UmdIsoVirtualFileSystem(iso); sections = new PbpSection[umdFilenames.Length + 1]; sections[0] = new PbpSection(); sections[0].index = 0; sections[0].offset = 0; sections[0].size = 0x28; sections[0].availableInContents = true; int offset = 0x28; SceIoStat stat = new SceIoStat(); for (int i = 0; i < umdFilenames.Length; i++) { PbpSection section = new PbpSection(); section.index = i + 1; section.offset = offset; section.umdFilename = umdFilenames[i]; if (vfs.ioGetstat(section.umdFilename, stat) >= 0) { section.size = (int)stat.size; if (log.TraceEnabled) { log.trace(string.Format("{0}: mapping {1} at offset 0x{2:X}, size 0x{3:X}", umdFilename, umdFilenames[i], section.offset, section.size)); } } string cacheFileName = getCacheFileName(section); File cacheFile = new File(cacheFileName); // Create only cache files for PARAM.SFO and ICON0.PNG if (createCacheFiles && i < 2) { IVirtualFile vFile = vfs.ioOpen(section.umdFilename, IoFileMgrForUser.PSP_O_RDONLY, 0); if (vFile != null) { section.size = (int)vFile.Length(); sbyte[] buffer = new sbyte[section.size]; int Length = vFile.ioRead(buffer, 0, buffer.Length); vFile.ioClose(); System.IO.Stream os = new System.IO.FileStream(cacheFile, System.IO.FileMode.Create, System.IO.FileAccess.Write); os.Write(buffer, 0, Length); os.Close(); } } if (cacheFile.canRead()) { section.cacheFile = cacheFile; } sections[section.index] = section; offset += section.size; } totalLength = offset; contents = new sbyte[offset]; ByteBuffer buffer = ByteBuffer.wrap(contents).order(ByteOrder.LITTLE_ENDIAN); buffer.putInt(PBP.PBP_MAGIC); buffer.putInt(0x10000); // version for (int i = 1; i < sections.Length; i++) { buffer.putInt(sections[i].offset); } int endSectionOffset = sections[sections.Length - 1].offset + sections[sections.Length - 1].size; for (int i = sections.Length; i <= 8; i++) { buffer.putInt(endSectionOffset); } if (log.TraceEnabled) { log.trace(string.Format("{0}: PBP header :{1}", umdFilename, Utilities.getMemoryDump(contents, sections[0].offset, sections[0].size))); } vfs.ioExit(); } catch (FileNotFoundException e) { Console.WriteLine("XmbIsoVirtualFile", e); } catch (IOException e) { Console.WriteLine("XmbIsoVirtualFile", e); } }
protected internal virtual void readSection(PbpSection section) { if (section.size > 0) { try { if (section.cacheFile != null) { //if (log.DebugEnabled) { Console.WriteLine(string.Format("XmbIsoVirtualFile.readSection from Cache {0}", section.cacheFile)); } System.IO.Stream @is = new System.IO.FileStream(section.cacheFile, System.IO.FileMode.Open, System.IO.FileAccess.Read); @is.Read(contents, section.offset, section.size); @is.Close(); } else { //if (log.DebugEnabled) { Console.WriteLine(string.Format("XmbIsoVirtualFile.readSection from UMD {0}", section.umdFilename)); } UmdIsoReader iso = new UmdIsoReader(umdFilename); IVirtualFileSystem vfs = new UmdIsoVirtualFileSystem(iso); IVirtualFile vFile = vfs.ioOpen(section.umdFilename, IoFileMgrForUser.PSP_O_RDONLY, 0); if (vFile != null) { vFile.ioRead(contents, section.offset, section.size); vFile.ioClose(); } vfs.ioExit(); } } catch (IOException e) { Console.WriteLine("readSection", e); } // PARAM.SFO? if (section.index == 1) { // Patch the CATEGORY in the PARAM.SFO: // the VSH is checking that the CATEGORY value is starting // with 'M' (meaning MemoryStick) and not 'U' (UMD). // Change the first letter 'U' into 'M'. int offset = section.offset; int keyTableOffset = readUnaligned32(contents, offset + 8) + offset; int valueTableOffset = readUnaligned32(contents, offset + 12) + offset; int numberKeys = readUnaligned32(contents, offset + 16); for (int i = 0; i < numberKeys; i++) { int keyOffset = readUnaligned16(contents, offset + 20 + i * 16); string key = Utilities.readStringZ(contents, keyTableOffset + keyOffset); if ("CATEGORY".Equals(key)) { int valueOffset = readUnaligned32(contents, offset + 20 + i * 16 + 12); char valueFirstChar = (char)contents[valueTableOffset + valueOffset]; // Change the first letter 'U' into 'M'. if (valueFirstChar == 'U') { contents[valueTableOffset + valueOffset] = (sbyte)'M'; } break; } } } } section.availableInContents = true; }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: protected void runFile(String fileName) throws Throwable protected internal virtual void runFile(string fileName) { File file = new File(fileName); reset(); try { RandomAccessFile raf = new RandomAccessFile(file, "r"); try { FileChannel roChannel = raf.Channel; try { ByteBuffer readbuffer = roChannel.map(FileChannel.MapMode.READ_ONLY, 0, (int)roChannel.size()); { //module = emulator.load(file.Path, readbuffer); } } finally { roChannel.close(); } } finally { raf.close(); } } catch (FileNotFoundException) { } RuntimeContext.IsHomebrew = true; UmdIsoReader umdIsoReader = new UmdIsoReader(rootDirectory + "/input/cube.cso"); Modules.IoFileMgrForUserModule.IsoReader = umdIsoReader; Modules.sceUmdUserModule.IsoReader = umdIsoReader; Modules.IoFileMgrForUserModule.setfilepath(file.Parent); debug(string.Format("Running: {0}...", fileName)); { RuntimeContext.IsHomebrew = false; HLEModuleManager.Instance.startModules(false); Modules.sceDisplayModule.UseSoftwareRenderer = true; { emulator.RunEmu(); long startTime = DateTimeHelper.CurrentUnixTimeMillis(); while (!Emulator.pause) { Modules.sceDisplayModule.step(); if (DateTimeHelper.CurrentUnixTimeMillis() - startTime > FAIL_TIMEOUT * 1000) { throw (new TimeoutException()); } Thread.Sleep(1); } } HLEModuleManager.Instance.stopModules(); } }