Esempio n. 1
0
        public virtual int sceKernelLoadModuleNpDrm(PspString path, int flags, TPointer optionAddr)
        {
            SceKernelLMOption lmOption = null;

            if (optionAddr.NotNull)
            {
                lmOption = new SceKernelLMOption();
                lmOption.read(optionAddr);
                if (log.InfoEnabled)
                {
                    Console.WriteLine(string.Format("sceKernelLoadModuleNpDrm options: {0}", lmOption));
                }
            }

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

            LoadModuleContext loadModuleContext = new LoadModuleContext();

            loadModuleContext.fileName       = path.String;
            loadModuleContext.flags          = flags;
            loadModuleContext.lmOption       = lmOption;
            loadModuleContext.needModuleInfo = true;
            loadModuleContext.allocMem       = true;

            return(Modules.ModuleMgrForUserModule.hleKernelLoadModule(loadModuleContext));
        }
Esempio n. 2
0
        public virtual int sceKernelLoadModuleBuffer(TPointer buffer, int bufSize, int flags, TPointer optionAddr)
        {
            SceKernelLMOption lmOption = null;

            if (optionAddr.NotNull)
            {
                lmOption = new SceKernelLMOption();
                lmOption.read(optionAddr);
                if (log.InfoEnabled)
                {
                    Console.WriteLine(string.Format("sceKernelLoadModuleBuffer options: {0}", lmOption));
                }
            }

            LoadModuleContext loadModuleContext = new LoadModuleContext();

            loadModuleContext.fileName       = buffer.ToString();
            loadModuleContext.flags          = flags;
            loadModuleContext.buffer         = buffer.Address;
            loadModuleContext.bufferSize     = bufSize;
            loadModuleContext.lmOption       = lmOption;
            loadModuleContext.needModuleInfo = true;
            loadModuleContext.allocMem       = true;

            return(Modules.ModuleMgrForUserModule.hleKernelLoadModule(loadModuleContext));
        }
Esempio n. 3
0
        public virtual int sceKernelLoadModuleVSH(PspString path, int flags, TPointer optionAddr)
        {
            SceKernelLMOption lmOption = null;

            if (optionAddr.NotNull)
            {
                lmOption = new SceKernelLMOption();
                lmOption.read(optionAddr);
                if (log.InfoEnabled)
                {
                    Console.WriteLine(string.Format("sceKernelLoadModuleVSH options: {0}", lmOption));
                }
            }

            LoadModuleContext loadModuleContext = new LoadModuleContext();

            loadModuleContext.fileName       = path.String;
            loadModuleContext.flags          = flags;
            loadModuleContext.lmOption       = lmOption;
            loadModuleContext.needModuleInfo = true;
            loadModuleContext.allocMem       = true;

            return(Modules.ModuleMgrForUserModule.hleKernelLoadModule(loadModuleContext));
        }
Esempio n. 4
0
 public int sceKernelLoadModule(string Path, uint Flags, SceKernelLMOption* SceKernelLMOption)
 {
     return sceKernelLoadModuleWithStream(() =>
     {
         return HleIoManager.HleIoWrapper.Open(Path, Vfs.HleIoFlags.Read, Vfs.SceMode.All);
     }, Path, Flags, SceKernelLMOption);
 }
Esempio n. 5
0
        public int sceKernelLoadModuleWithStream(Func<Stream> GetStreamAction, string Path, uint Flags, SceKernelLMOption* SceKernelLMOption)
        {
            var Module = new HleModuleGuest(PspEmulatorContext);

            try
            {
                Path = Path.ToLowerInvariant();

                if (Path.StartsWith(@"disc0:/PSP_GAME/USRDIR/kmodule"))
                {
                    throw (new Exception("Ignore kmodule!"));
                }

                if (
                    Path.EndsWith(@"/libatrac3plus.prx") ||
                    Path.EndsWith(@"/videocodec.prx") ||
                    Path.EndsWith(@"/audiocodec.prx") ||
                    Path.EndsWith(@"/mpeg.prx") ||
                    Path.EndsWith(@"/mpegbase.prx") ||
                    Path.EndsWith(@"/libfont.prx") ||
                false)
                {
                    Logger.Warning("Ignore {0}!", Path);
                    throw (new Exception("Ignore " + Path + "!"));

                    //var ModuleId = Modules.Create(new HleModule());
                    //Module.ID = ModuleId;
                    //return ModuleId;

                }

                var ModuleStream = GetStreamAction();

                var HleModuleGuest = Loader.LoadModule(
                    ModuleStream,
                    new PspMemoryStream(PspMemory),
                    MemoryManager.GetPartition(HleMemoryManager.Partitions.User),
                    ModuleManager,
                    "",
                    ModuleName: Path,
                    IsMainModule: false
                );

                var SceModulePartition = MemoryManager.GetPartition(HleMemoryManager.Partitions.Kernel0).Allocate(sizeof(SceModule));

                var SceModulePtr = (SceModule*)PspMemory.PspAddressToPointerSafe(SceModulePartition.Low, Marshal.SizeOf(typeof(SceModule)));

                SceModulePtr->Attributes = HleModuleGuest.ModuleInfo.ModuleAtributes;
                SceModulePtr->Version = HleModuleGuest.ModuleInfo.ModuleVersion;
                SceModulePtr->ModuleName = HleModuleGuest.ModuleInfo.Name;
                SceModulePtr->GP = HleModuleGuest.ModuleInfo.GP;
                SceModulePtr->ent_top = HleModuleGuest.ModuleInfo.ExportsStart;
                SceModulePtr->ent_size = HleModuleGuest.ModuleInfo.ExportsEnd - HleModuleGuest.ModuleInfo.ExportsStart;
                SceModulePtr->stub_top = HleModuleGuest.ModuleInfo.ImportsStart;
                SceModulePtr->stub_size = HleModuleGuest.ModuleInfo.ImportsEnd - HleModuleGuest.ModuleInfo.ImportsStart;

                Module.ModuleInfo = HleModuleGuest.ModuleInfo;
                Module.InitInfo = HleModuleGuest.InitInfo;
                Module.Loaded = true;
                Module.SceModuleStructPartition = SceModulePartition;

                //Loader.InitInfo.GP
            }
            catch (Exception Exception)
            {
                Console.WriteLine(Exception);
                Module.Loaded = false;
            }

            var ModuleId = Modules.Create(Module);
            Module.ID = ModuleId;
            return ModuleId;
        }
Esempio n. 6
0
 public int sceKernelLoadModuleByID(SceUID FileId, uint Flags, SceKernelLMOption* SceKernelLMOption)
 {
     var Args = IoFileMgrForUser.GetFileArgFromHandle(FileId);
     return sceKernelLoadModuleWithStream(() =>
     {
         return new FileHandle(Args);
     }, Args.FullFileName, Flags, SceKernelLMOption);
 }
Esempio n. 7
0
        public virtual int sceKernelLoadModuleToBlock(PspString path, int blockId, TPointer32 separatedBlockId, int unknown2, TPointer optionAddr)
        {
            SceKernelLMOption lmOption = null;

            if (optionAddr.NotNull)
            {
                lmOption = new SceKernelLMOption();
                lmOption.read(optionAddr);
                if (log.InfoEnabled)
                {
                    Console.WriteLine(string.Format("sceKernelLoadModuleToBlock options: {0}", lmOption));
                }
            }

            SysMemInfo sysMemInfo = Modules.SysMemUserForUserModule.getSysMemInfo(blockId);

            if (sysMemInfo == null)
            {
                return(-1);
            }

            //if (log.DebugEnabled)
            {
                Console.WriteLine(string.Format("sceKernelLoadModuleToBlock sysMemInfo={0}", sysMemInfo));
            }

            modulesWithMemoryAllocated.Add(path.String);

            // If we cannot load the module file, return the same blockId
            separatedBlockId.setValue(blockId);

            StringBuilder      localFileName = new StringBuilder();
            IVirtualFileSystem vfs           = Modules.IoFileMgrForUserModule.getVirtualFileSystem(path.String, localFileName);

            if (vfs != null)
            {
                IVirtualFile vFile = vfs.ioOpen(localFileName.ToString(), IoFileMgrForUser.PSP_O_RDONLY, 0);
                if (vFile != null)
                {
                    sbyte[]    bytes        = new sbyte[(int)vFile.Length()];
                    int        Length       = vFile.ioRead(bytes, 0, bytes.Length);
                    ByteBuffer moduleBuffer = ByteBuffer.wrap(bytes, 0, Length);

                    SceModule module = Modules.ModuleMgrForUserModule.getModuleInfo(path.String, moduleBuffer, sysMemInfo.partitionid, sysMemInfo.partitionid);
                    if (module != null)
                    {
                        int size = Modules.ModuleMgrForUserModule.getModuleRequiredMemorySize(module);

                        //if (log.DebugEnabled)
                        {
                            Console.WriteLine(string.Format("sceKernelLoadModuleToBlock module requiring 0x{0:X} bytes", size));
                        }

                        // Aligned on 256 bytes boundary
                        size = Utilities.alignUp(size, 0xFF);
                        SysMemInfo separatedSysMemInfo = Modules.SysMemUserForUserModule.separateMemoryBlock(sysMemInfo, size);
                        // This is the new blockId after calling sceKernelSeparateMemoryBlock
                        separatedBlockId.setValue(separatedSysMemInfo.uid);

                        //if (log.DebugEnabled)
                        {
                            Console.WriteLine(string.Format("sceKernelLoadModuleToBlock separatedSysMemInfo={0}", separatedSysMemInfo));
                        }
                    }
                }
            }

            LoadModuleContext loadModuleContext = new LoadModuleContext();

            loadModuleContext.fileName       = path.String;
            loadModuleContext.lmOption       = lmOption;
            loadModuleContext.needModuleInfo = true;
            loadModuleContext.allocMem       = false;
            loadModuleContext.baseAddr       = sysMemInfo.addr;
            loadModuleContext.basePartition  = sysMemInfo.partitionid;

            return(Modules.ModuleMgrForUserModule.hleKernelLoadModule(loadModuleContext));
        }