public override int ioWrite(sbyte[] inputBuffer, int inputOffset, int inputLength) { try { if (TruncateAtNextWrite) { // The file was open with PSP_O_TRUNC: truncate the file at the first write long position = Position; if (position < file.Length()) { file.Length = Position; } TruncateAtNextWrite = false; } file.write(inputBuffer, inputOffset, inputLength); } catch (IOException e) { Console.WriteLine("ioWrite", e); return(IO_ERROR); } return(inputLength); }
public virtual int sceNpDrmRenameCheck(PspString fileName) { CryptoEngine crypto = new CryptoEngine(); int result = 0; if (!NpDrmKeyStatus) { result = SceKernelErrors.ERROR_NPDRM_NO_K_LICENSEE_SET; } else { try { string pcfilename = Modules.IoFileMgrForUserModule.getDeviceFilePath(fileName.String); SeekableRandomFile file = new SeekableRandomFile(pcfilename, "r"); string[] name = pcfilename.Split("/", true); string fName = name[name.Length - 1]; for (int i = 0; i < name.Length; i++) { if (name[i].ToUpper().Contains("EDAT")) { fName = name[i]; } } // The file must contain a valid PSPEDAT header. if (file.Length() < 0x80) { // Test if we're using already decrypted DLC. // Discard the error in this situatuion. if (!DisableDLCStatus) { Console.WriteLine("sceNpDrmRenameCheck: invalid file size"); result = SceKernelErrors.ERROR_NPDRM_INVALID_FILE; } file.Dispose(); } else { // Setup the buffers. sbyte[] inBuf = new sbyte[0x80]; sbyte[] srcData = new sbyte[0x30]; sbyte[] srcHash = new sbyte[0x10]; // Read the header. file.readFully(inBuf); file.Dispose(); // The data seed is stored at offset 0x10 of the PSPEDAT header. Array.Copy(inBuf, 0x10, srcData, 0, 0x30); // The hash to compare is stored at offset 0x40 of the PSPEDAT header. Array.Copy(inBuf, 0x40, srcHash, 0, 0x10); // If the CryptoEngine fails to find a match, then the file has been renamed. if (!crypto.PGDEngine.CheckEDATRenameKey(fName.GetBytes(), srcHash, srcData)) { if (!DisableDLCStatus) { result = SceKernelErrors.ERROR_NPDRM_NO_FILENAME_MATCH; Console.WriteLine("sceNpDrmRenameCheck: the file has been renamed"); } } } } catch (FileNotFoundException e) { result = SceKernelErrors.ERROR_NPDRM_INVALID_FILE; //if (log.DebugEnabled) { Console.WriteLine(string.Format("sceNpDrmRenameCheck: file '{0}' not found: {1}", fileName.String, e.ToString())); } } catch (Exception e) { Console.WriteLine("sceNpDrmRenameCheck", e); } } return(result); }