Exemple #1
0
        public virtual int ioClose()
        {
            try
            {
                file.Dispose();
            }
            catch (IOException e)
            {
                Console.WriteLine("ioClose", e);
                return(IO_ERROR);
            }

            return(0);
        }
Exemple #2
0
        public virtual int sceKernelLoadExecNpDrm(PspString fileName, TPointer optionAddr)
        {
            // Flush system memory to mimic a real PSP reset.
            Modules.SysMemUserForUserModule.reset();

            if (optionAddr.NotNull)
            {
                int optSize = optionAddr.getValue32(0);                 // Size of the option struct.
                int argSize = optionAddr.getValue32(4);                 // Number of args (strings).
                int argAddr = optionAddr.getValue32(8);                 // Pointer to a list of strings.
                int keyAddr = optionAddr.getValue32(12);                // Pointer to an encryption key (may not be used).

                //if (log.DebugEnabled)
                {
                    Console.WriteLine(string.Format("sceKernelLoadExecNpDrm (params: optSize={0:D}, argSize={1:D}, argAddr=0x{2:X8}, keyAddr=0x{3:X8})", optSize, argSize, argAddr, keyAddr));
                }
            }

            // SPRX modules can't be decrypted yet.
            if (!DisableDLCStatus)
            {
                Console.WriteLine(string.Format("sceKernelLoadModuleNpDrm detected encrypted DLC module: {0}", fileName.String));
                return(SceKernelErrors.ERROR_NPDRM_INVALID_PERM);
            }

            int result;

            try
            {
                SeekableDataInput moduleInput = Modules.IoFileMgrForUserModule.getFile(fileName.String, IoFileMgrForUser.PSP_O_RDONLY);
                if (moduleInput != null)
                {
                    sbyte[] moduleBytes = new sbyte[(int)moduleInput.Length()];
                    moduleInput.readFully(moduleBytes);
                    moduleInput.Dispose();
                    ByteBuffer moduleBuffer = ByteBuffer.wrap(moduleBytes);

                    SceModule module = Emulator.Instance.load(fileName.String, moduleBuffer, true);
                    Emulator.Clock.resume();

                    if ((module.fileFormat & Loader.FORMAT_ELF) == Loader.FORMAT_ELF)
                    {
                        result = 0;
                    }
                    else
                    {
                        Console.WriteLine("sceKernelLoadExecNpDrm - failed, target is not an ELF");
                        result = SceKernelErrors.ERROR_KERNEL_ILLEGAL_LOADEXEC_FILENAME;
                    }
                }
                else
                {
                    result = SceKernelErrors.ERROR_KERNEL_PROHIBIT_LOADEXEC_DEVICE;
                }
            }
            catch (GeneralJpcspException e)
            {
                Console.WriteLine("sceKernelLoadExecNpDrm", e);
                result = SceKernelErrors.ERROR_KERNEL_PROHIBIT_LOADEXEC_DEVICE;
            }
            catch (IOException e)
            {
                Console.WriteLine(string.Format("sceKernelLoadExecNpDrm - Error while loading module '{0}'", fileName), e);
                result = SceKernelErrors.ERROR_KERNEL_PROHIBIT_LOADEXEC_DEVICE;
            }

            return(result);
        }
Exemple #3
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));
        }