Exemple #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public SeekableRandomFile duplicate() throws java.io.IOException
        public virtual SeekableRandomFile duplicate()
        {
            SeekableRandomFile duplicate = new SeekableRandomFile(fileName, mode);

            duplicate.seek(FilePointer);

            return(duplicate);
        }
Exemple #2
0
        public override IVirtualFile ioOpen(string fileName, int flags, int mode)
        {
            File file = getFile(fileName);

            if (file.exists() && hasFlag(flags, PSP_O_CREAT) && hasFlag(flags, PSP_O_EXCL))
            {
                //if (log.DebugEnabled)
                {
                    Console.WriteLine("hleIoOpen - file already exists (PSP_O_CREAT + PSP_O_EXCL)");
                }
                throw new SceKernelErrorException(SceKernelErrors.ERROR_ERRNO_FILE_ALREADY_EXISTS);
            }

            // When PSP_O_CREAT is specified, create the parent directories
            // if they do not yet exist.
            if (!file.exists() && hasFlag(flags, PSP_O_CREAT))
            {
                string parentDir = file.Parent;
                System.IO.Directory.CreateDirectory(parentDir);
            }

            SeekableRandomFile raf;

            try
            {
                raf = new SeekableRandomFile(file, getMode(flags));
            }
            catch (FileNotFoundException)
            {
                return(null);
            }

            LocalVirtualFile localVirtualFile = new LocalVirtualFile(raf);

            if (hasFlag(flags, PSP_O_WRONLY) && hasFlag(flags, PSP_O_TRUNC))
            {
                // When writing, PSP_O_TRUNC truncates the file at the position of the first write.
                // E.g.:
                //    open(PSP_O_TRUNC)
                //    seek(0x1000)
                //    write()  -> truncates the file at the position 0x1000 before writing
                localVirtualFile.TruncateAtNextWrite = true;
            }

            return(localVirtualFile);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
 public LocalVirtualFile(SeekableRandomFile file) : base(file)
 {
     this.file = file;
 }