public virtual ByteBuffer decrypt(ByteBuffer f) { if (f.capacity() == 0) { return(null); } CryptoEngine crypto = new CryptoEngine(); sbyte[] inBuf; if (f.hasArray() && f.position() <= PSP_HEADER_SIZE) { inBuf = f.array(); } else { int currentPosition = f.position(); f.position(currentPosition - PSP_HEADER_SIZE); inBuf = new sbyte[f.remaining()]; f.get(inBuf); f.position(currentPosition); } int inSize = inBuf.Length; sbyte[] elfBuffer = crypto.PRXEngine.DecryptAndUncompressPRX(inBuf, inSize); if (elfBuffer == null) { return(null); } if (CryptoEngine.ExtractEbootStatus) { try { string ebootPath = Settings.Instance.DiscTmpDirectory; System.IO.Directory.CreateDirectory(ebootPath); RandomAccessFile raf = new RandomAccessFile(ebootPath + "EBOOT.BIN", "rw"); raf.write(elfBuffer); raf.close(); } catch (IOException) { // Ignore. } } return(ByteBuffer.wrap(elfBuffer)); }
//public static Logger log = Modules.getLogger("semaphore"); public virtual int hleUtilsBufferCopyWithRange(sbyte[] @out, int outOffset, int outSize, sbyte[] @in, int inOffset, int inSize, int cmd) { int result = 0; if (preDecrypt(@out, outOffset, outSize, @in, inOffset, inSize, cmd)) { //if (log.DebugEnabled) { Console.WriteLine(string.Format("hleUtilsBufferCopyWithRange using pre-decrypted data")); } } else { // Call the KIRK engine to perform the given command ByteBuffer outBuffer = null; if (@out != null) { outBuffer = ByteBuffer.wrap(@out).order(ByteOrder.LITTLE_ENDIAN); outBuffer.position(outOffset); } ByteBuffer inBuffer = null; if (@in != null) { inBuffer = ByteBuffer.wrap(@in).order(ByteOrder.LITTLE_ENDIAN); inBuffer.position(inOffset); } int inSizeAligned = Utilities.alignUp(inSize, 15); CryptoEngine crypto = new CryptoEngine(); result = crypto.KIRKEngine.hleUtilsBufferCopyWithRange(outBuffer, outSize, inBuffer, inSizeAligned, inSize, cmd); if (result != 0) { Console.WriteLine(string.Format("hleUtilsBufferCopyWithRange cmd=0x{0:X} returned 0x{1:X}", cmd, result)); } } return(result); }
public virtual int scePauth_F7AA47F6(TPointer inputAddr, int inputLength, TPointer32 resultLengthAddr, TPointer keyAddr) { CryptoEngine crypto = new CryptoEngine(); sbyte[] @in = inputAddr.getArray8(inputLength); sbyte[] key = keyAddr.getArray8(0x10); sbyte[] xor = new sbyte[0x10]; for (int i = 0; i < 0x10; i++) { xor[i] = unchecked ((sbyte)(KeyVault.pauthXorKey[i] & 0xFF)); } // Try to read/write PAUTH data for external decryption. try { // Calculate CRC32 for PAUTH data. CRC32 crc = new CRC32(); crc.update(@in, 0, inputLength); int tag = (int)crc.Value; // Set PAUTH file name and PAUTH dir name. string pauthDirName = string.Format("{0}PAUTH{1}", Settings.Instance.DiscTmpDirectory, System.IO.Path.DirectorySeparatorChar); string pauthFileName = pauthDirName + string.Format("pauth-{0}.bin", tag.ToString("x")); string pauthDecFileName = pauthDirName + string.Format("pauth-{0}.bin.decrypt", tag.ToString("x")); string pauthKeyFileName = pauthDirName + string.Format("pauth-{0}.key", tag.ToString("x")); // Check for an already decrypted file. File dec = new File(pauthDecFileName); if (dec.exists()) { Console.WriteLine("Reading PAUTH data file from " + pauthDecFileName); // Read the externally decrypted file. SeekableRandomFile pauthPRXDec = new SeekableRandomFile(pauthDecFileName, "rw"); int pauthSize = (int)pauthPRXDec.Length(); sbyte[] pauthDec = new sbyte[pauthSize]; pauthPRXDec.read(pauthDec); pauthPRXDec.Dispose(); inputAddr.setArray(pauthDec, pauthSize); resultLengthAddr.setValue(pauthSize); } else { // Create PAUTH dir under tmp. File f = new File(pauthDirName); f.mkdirs(); Console.WriteLine("Writting PAUTH data file to " + pauthFileName); Console.WriteLine("Writting PAUTH key file to " + pauthKeyFileName); // Write the PAUTH file and key for external decryption. SeekableRandomFile pauthPRX = new SeekableRandomFile(pauthFileName, "rw"); SeekableRandomFile pauthKey = new SeekableRandomFile(pauthKeyFileName, "rw"); pauthPRX.write(@in); pauthKey.write(key); pauthPRX.Dispose(); pauthKey.Dispose(); // Decryption is not working properly due to a missing KIRK key. int reslength = crypto.PRXEngine.DecryptPRX(@in, inputLength, 5, key, xor); // Fake the result. inputAddr.clear(reslength); resultLengthAddr.setValue(reslength); } } catch (IOException ioe) { Console.WriteLine(ioe); } return(0); }