Ejemplo n.º 1
0
        public virtual int SysMemUserForUser_FE707FDF(PspString name, int type, int size, TPointer paramsAddr)
        {
            if (paramsAddr.NotNull)
            {
                int Length = paramsAddr.getValue32();
                if (Length != 4)
                {
                    Console.WriteLine(string.Format("SysMemUserForUser_FE707FDF: unknown parameters with Length={0:D}", Length));
                }
            }

            if (type < PSP_SMEM_Low || type > PSP_SMEM_High)
            {
                return(SceKernelErrors.ERROR_KERNEL_ILLEGAL_MEMBLOCK_ALLOC_TYPE);
            }

            // Always allocate memory in user area (partitionid == 2).
            SysMemInfo info = malloc(SysMemUserForUser.USER_PARTITION_ID, name.String, type, size, 0);

            if (info == null)
            {
                return(SceKernelErrors.ERROR_KERNEL_FAILED_ALLOC_MEMBLOCK);
            }

            return(info.uid);
        }
Ejemplo n.º 2
0
        public virtual int sceUmdActivate(int mode, PspString drive)
        {
            umdActivated = true;
            Modules.IoFileMgrForUserModule.registerUmdIso();

            // Notify the callback.
            // The callback will be executed at the next sceXXXXCB() syscall.
            int notifyArg = NotificationArg;

            Modules.ThreadManForUserModule.hleKernelNotifyCallback(SceKernelThreadInfo.THREAD_CALLBACK_UMD, notifyArg);

            checkWaitingThreads();

            // int arg[] = { 1 };
            // sceIoAssign(drive, "umd0:", "isofs0:", 1, &arg, 4);
            int sceIoAssign = NIDMapper.Instance.getAddressByName("sceIoAssign");

            if (sceIoAssign != 0)
            {
                SysMemInfo memInfo   = Modules.SysMemUserForUserModule.malloc(SysMemUserForUser.KERNEL_PARTITION_ID, "sceUmdActivate", SysMemUserForUser.PSP_SMEM_Low, 32, 0);
                int        argAddr   = memInfo.addr;
                int        umdAddr   = memInfo.addr + 4;
                int        isofsAddr = memInfo.addr + 10;

                Memory mem = Memory.Instance;
                Utilities.writeStringZ(mem, umdAddr, "umd0:");
                Utilities.writeStringZ(mem, isofsAddr, "isofs0:");
                mem.write32(argAddr, 1);

                SceKernelThreadInfo thread = Modules.ThreadManForUserModule.CurrentThread;
                Modules.ThreadManForUserModule.executeCallback(thread, sceIoAssign, null, false, drive.Address, umdAddr, isofsAddr, 1, argAddr, 4);
            }

            return(0);
        }
Ejemplo n.º 3
0
        public virtual int sceUmdDeactivate(int mode, PspString drive)
        {
            // Trigger the callback only if the UMD was already activated.
            // The callback will be executed at the next sceXXXXCB() syscall.
            bool triggerCallback = umdActivated;

            umdActivated = false;
            Modules.IoFileMgrForUserModule.registerUmdIso();
            umdDeactivateCalled = true;
            if (triggerCallback)
            {
                int notifyArg;
                if (iso != null)
                {
                    notifyArg = PSP_UMD_PRESENT | PSP_UMD_READY;
                }
                else
                {
                    notifyArg = PSP_UMD_NOT_PRESENT | PSP_UMD_NOT_READY;
                }
                Modules.ThreadManForUserModule.hleKernelNotifyCallback(SceKernelThreadInfo.THREAD_CALLBACK_UMD, notifyArg);
            }
            checkWaitingThreads();

            return(0);
        }
Ejemplo n.º 4
0
        public virtual int hleMSstorStorageIoDevctl(pspIoDrvFileArg drvFileArg, PspString devicename, int cmd, TPointer indata, int inlen, TPointer outdata, int outlen)
        {
            switch (cmd)
            {
            case 0x02125802:
                outdata.setValue32(0);                         // ???
                break;

            case 0x0211D814:
                // inlen == 4, outlen == 0
                break;

            case 0x0210D816:                     // Format Memory Stick
                // inlen == 0, outlen == 0
                Console.WriteLine(string.Format("A FORMAT of the Memory Stick was requested, ignoring the request"));
                break;

            case 0x02025806:                     // Check if the device is inserted
                // 0 = Not inserted.
                // 1 = Inserted.
                outdata.setValue32(1);
                break;

            default:
                Console.WriteLine(string.Format("hleMSstorStorageIoDevctl 0x{0:X8} unknown command on device '{1}'", cmd, devicename));
                break;
            }
            return(0);
        }
Ejemplo n.º 5
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));
        }
Ejemplo n.º 6
0
 public virtual int sceNetConfigSetIfEventFlag(PspString interfaceName, int eventFlagUid, int bitsToSet)
 {
     if (eventFlagUid == 0)
     {
         return(0);
     }
     return(Modules.ThreadManForUserModule.sceKernelSetEventFlag(eventFlagUid, bitsToSet));
 }
Ejemplo n.º 7
0
        public virtual int strstr(PspString s1, PspString s2)
        {
            int index = s1.String.IndexOf(s2.String, StringComparison.Ordinal);

            if (index < 0)
            {
                return(0);
            }
            return(s1.Address + index);
        }
Ejemplo n.º 8
0
        public virtual int sceNetConfigGetIfEvent(PspString interfaceName, TPointer32 eventAddr, TPointer32 unknown)
        {
            // Possible return values in eventAddr:
            // - 4 (WLAN switch off / 0x80410B03)
            // - 5 (WLAN beacon lost / 0x80410B0E)
            // - 7 (???)

            // Returns 0x80410184 if no event is available?
            return(SceKernelErrors.ERROR_NET_NO_EVENT);
        }
Ejemplo n.º 9
0
        public virtual int strrchr(PspString @string, int c)
        {
            int index = @string.String.LastIndexOf(c);

            if (index < 0)
            {
                return(0);
            }

            return(@string.Address + index);
        }
Ejemplo n.º 10
0
        public virtual int sceNpDrmOpen(PspString name, int flags, int permissions)
        {
            if (!NpDrmKeyStatus)
            {
                return(SceKernelErrors.ERROR_NPDRM_NO_K_LICENSEE_SET);
            }
            // Open the file with flags ORed with PSP_O_FGAMEDATA and send it to the IoFileMgr.
            int fd = Modules.IoFileMgrForUserModule.hleIoOpen(name, flags | 0x40000000, permissions, true);

            return(sceNpDrmEdataSetupKey(fd));
        }
Ejemplo n.º 11
0
        public virtual int sceKernelSearchModuleByName(PspString name)
        {
            SceModule module = Managers.modules.getModuleByName(name.String);

            if (module == null)
            {
                return(SceKernelErrors.ERROR_KERNEL_UNKNOWN_MODULE);
            }

            return(module.modid);
        }
Ejemplo n.º 12
0
        public virtual int hleKernelPrintf(CpuState cpu, PspString formatString, Logger logger)
        {
            // Format and print the message to the logger
            if (logger.InfoEnabled)
            {
                string formattedMsg = hleKernelSprintf(cpu, formatString.String, _a1);
                logger.info(formattedMsg);
            }

            return(0);
        }
Ejemplo n.º 13
0
        public virtual int scePopsManLoadModule(PspString ebootPbp, int unknown)
        {
            this.ebootPbp = ebootPbp.String;
            ebootPbpUid   = -1;
            vFileEbootPbp = null;

            string popsFileName = string.Format("flash0:/kd/pops_{0:D2}g.prx", Model.Model + 1);

            //      Modules.ModuleMgrForUserModule.hleKernelLoadAndStartModule("flash0:/vsh/module/paf.prx", 0x19);
            return(Modules.ModuleMgrForUserModule.hleKernelLoadAndStartModule(popsFileName, 0x20));
        }
Ejemplo n.º 14
0
        public virtual int strtol(PspString @string, TPointer32 endString, int @base)
        {
            // base == 0 seems to be handled as base == 10.
            if (@base == 0)
            {
                @base = 10;
            }

            IMemoryReader memoryReader = MemoryReader.getMemoryReader(@string.Address, 1);
            string        s            = @string.String;

            // Skip any leading "0x" in case of base 16
            if (@base == 16 && (s.StartsWith("0x", StringComparison.Ordinal) || s.StartsWith("0X", StringComparison.Ordinal)))
            {
                memoryReader.skip(2);
                s = s.Substring(2);
            }

            for (int i = 0; true; i++)
            {
                int c = memoryReader.readNext();
                if (c == 0 || !isNumberValidCharacter(c, @base))
                {
                    endString.setValue(@string.Address + i);
                    s = s.Substring(0, i);
                    break;
                }
            }

            int result;

            if (s.Length == 0)
            {
                result = 0;
            }
            else
            {
                result = Integer.parseInt(s, @base);
            }

            //if (log.DebugEnabled)
            {
                if (@base == 10)
                {
                    Console.WriteLine(string.Format("strtol on '{0}' returning {1:D}", s, result));
                }
                else
                {
                    Console.WriteLine(string.Format("strtol on '{0}' returning 0x{1:X}", s, result));
                }
            }

            return(result);
        }
Ejemplo n.º 15
0
        public virtual int sceHttpsInitWithPath(PspString rootCertFileList, PspString clientCertFile, PspString keyFile)
        {
            if (isHttpsInit)
            {
                return(ERROR_HTTP_ALREADY_INIT);
            }

            isHttpsInit = true;

            return(0);
        }
Ejemplo n.º 16
0
 public virtual void sceNetEtherStrton(PspString str, TPointer etherAddr)
 {
     // This syscall is only doing something when both parameters are not 0.
     if (str.NotNull && etherAddr.NotNull)
     {
         // Convert string Mac address string representation (XX:XX:XX:XX:XX:XX)
         // into 6-byte representation.
         pspNetMacAddress macAddress = new pspNetMacAddress();
         macAddress.MacAddress = convertStringToMacAddress(str.String);
         macAddress.write(etherAddr);
     }
 }
Ejemplo n.º 17
0
        public virtual int sceKernelCreateMutex(PspString name, int attr, int count, int option_addr)
        {
            if (count < 0 || (count > 1 && (attr & PSP_MUTEX_ATTR_ALLOW_RECURSIVE) == 0))
            {
                return(SceKernelErrors.ERROR_KERNEL_ILLEGAL_COUNT);
            }

            SceKernelMutexInfo info = new SceKernelMutexInfo(name.String, count, attr);

            mutexMap[info.uid] = info;

            return(info.uid);
        }
Ejemplo n.º 18
0
        public virtual int hleMSstorPartitionIoDevctl(pspIoDrvFileArg drvFileArg, PspString devicename, int cmd, TPointer indata, int inlen, TPointer outdata, int outlen)
        {
            switch (cmd)
            {
            case 0x02125802:
                outdata.setValue32(0);                         // ???
                break;

            default:
                Console.WriteLine(string.Format("hleMSstorPartitionIoDevctl 0x{0:X8} unknown command on device '{1}'", cmd, devicename));
                break;
            }
            return(0);
        }
Ejemplo n.º 19
0
        public virtual int sceKernelCreateVpl(PspString name, int partitionid, int attr, int size, TPointer option)
        {
            if (name.Null)
            {
                // PSP is returning this error is case of a NULL name
                return(SceKernelErrors.ERROR_KERNEL_ERROR);
            }

            if (option.NotNull)
            {
                int optionSize = option.getValue32();
                Console.WriteLine(string.Format("sceKernelCreateVpl option at {0}, size={1:D}", option, optionSize));
            }

            int memType = PSP_SMEM_Low;

            if ((attr & PSP_VPL_ATTR_ADDR_HIGH) == PSP_VPL_ATTR_ADDR_HIGH)
            {
                memType = PSP_SMEM_High;
            }

            if ((attr & ~PSP_VPL_ATTR_MASK) != 0)
            {
                Console.WriteLine("sceKernelCreateVpl bad attr value 0x" + attr.ToString("x"));
                return(ERROR_KERNEL_ILLEGAL_ATTR);
            }
            if (size == 0)
            {
                return(ERROR_KERNEL_ILLEGAL_MEMSIZE);
            }
            if (size < 0)
            {
                return(ERROR_KERNEL_NO_MEMORY);
            }

            SceKernelVplInfo info = SceKernelVplInfo.tryCreateVpl(name.String, partitionid, attr, size, memType);

            if (info == null)
            {
                return(ERROR_KERNEL_NO_MEMORY);
            }

            //if (log.DebugEnabled)
            {
                Console.WriteLine(string.Format("sceKernelCreateVpl returning {0}", info));
            }
            vplMap[info.uid] = info;

            return(info.uid);
        }
Ejemplo n.º 20
0
        public virtual int sceUsbStop(PspString driverName, int size, TPointer args)
        {
            usbStarted = false;

            SceModule module = loadedModules.Remove(driverName.String);

            if (module != null)
            {
                HLEModuleManager moduleManager = HLEModuleManager.Instance;
                moduleManager.UnloadFlash0Module(module);
            }

            notifyCallback();

            return(0);
        }
Ejemplo n.º 21
0
        public virtual int sceNetStrcasecmp(PspString src1Addr, PspString src2Addr)
        {
            if (src1Addr.Null || src2Addr.Null)
            {
                if (src1Addr.Address == src2Addr.Address)
                {
                    return(0);
                }
                if (src1Addr.NotNull)
                {
                    return(1);
                }
                return(-1);
            }

            return(string.Compare(src1Addr.String, src2Addr.String, StringComparison.OrdinalIgnoreCase));
        }
Ejemplo n.º 22
0
        public virtual int sceNetIfhandle_driver_9CBA24D4(PspString interfaceName)
        {
            int handleAddr = 0;

            for (int i = 0; i < handles.Length; i++)
            {
                if (handles[i].NotNull)
                {
                    SceNetIfHandle handle = new SceNetIfHandle();
                    handle.read(handles[i]);
                    if (interfaceName.Equals(handle.handleInternal.interfaceName))
                    {
                        handleAddr = handles[i].Address;
                        break;
                    }
                }
            }

            return(handleAddr);
        }
Ejemplo n.º 23
0
        public virtual int hleMSstorControllerIoDevctl(pspIoDrvFileArg drvFileArg, PspString devicename, int cmd, TPointer indata, int inlen, TPointer outdata, int outlen)
        {
            switch (cmd)
            {
            case 0x0203D802:                     // Set EventFlag named SceFatfsDetectMedium
                int eventFlag = indata.getValue32();
                // Event 0x1: memory stick inserted?
                // Event 0x2: memory stick ejected?
                Managers.eventFlags.sceKernelSetEventFlag(eventFlag, 0x1);
                outdata.setValue32(0);
                break;

            case 0x02025801:                     // Check the MemoryStick's driver status
                outdata.setValue32(4);
                break;

            case 0x2015807:
                outdata.setValue32(1);                         // Unknown value: seems to be 0 or 1?
                break;

            case 0x0202580A:
                outdata.clear(outlen);
                break;

            case 0x201580B:
                // inlen == 20, outlen == 0
                break;

            case 0x02025806:                     // Check if the device is inserted
                // 0 = Not inserted.
                // 1 = Inserted.
                outdata.setValue32(1);
                break;

            default:
                Console.WriteLine(string.Format("hleMSstorControllerIoDevctl 0x{0:X8} unknown command on device '{1}'", cmd, devicename));
                break;
            }
            return(0);
        }
Ejemplo n.º 24
0
        public virtual int sceHeapCreateHeap(PspString name, int heapSize, int attr, TPointer paramAddr)
        {
            if (paramAddr.NotNull)
            {
                Console.WriteLine(string.Format("sceHeapCreateHeap unknown option at {0}", paramAddr));
            }

            int memType = PSP_SMEM_Low;

            if ((attr & PSP_HEAP_ATTR_ADDR_HIGH) == PSP_HEAP_ATTR_ADDR_HIGH)
            {
                memType = PSP_SMEM_High;
            }

            // Allocate a virtual heap memory space and return it's address.
            SysMemInfo info          = null;
            int        alignment     = 4;
            int        totalHeapSize = (heapSize + (alignment - 1)) & (~(alignment - 1));
            int        partitionId   = SysMemUserForUser.USER_PARTITION_ID;
            int        maxFreeSize   = Modules.SysMemUserForUserModule.maxFreeMemSize(partitionId);

            if (totalHeapSize <= maxFreeSize)
            {
                info = Modules.SysMemUserForUserModule.malloc(partitionId, name.String, memType, totalHeapSize, 0);
            }
            else
            {
                Console.WriteLine(string.Format("sceHeapCreateHeap not enough free mem (want={0:D}, free={1:D}, diff={2:D})", totalHeapSize, maxFreeSize, totalHeapSize - maxFreeSize));
            }
            if (info == null)
            {
                return(0);                // Returns NULL on error.
            }

            HeapInfo heapInfo = new HeapInfo(info);

            heapMap[info.addr] = heapInfo;

            return(info.addr);
        }
Ejemplo n.º 25
0
        public virtual int sceKernelLoadExecVSHMs2(PspString filename, TPointer param)
        {
            SceKernelLoadExecVSHParam loadExecVSHParam = new SceKernelLoadExecVSHParam();

            loadExecVSHParam.read(param);

            //if (log.DebugEnabled)
            {
                Console.WriteLine(string.Format("sceKernelLoadExecVSHMs2 param: {0}", loadExecVSHParam));
                if (loadExecVSHParam.args > 0)
                {
                    Console.WriteLine(string.Format("sceKernelLoadExecVSHMs2 argp: {0}", Utilities.getMemoryDump(loadExecVSHParam.argp, loadExecVSHParam.args)));
                }
                if (loadExecVSHParam.vshmainArgsSize > 0)
                {
                    Console.WriteLine(string.Format("sceKernelLoadExecVSHMs2 vshmainArgs: {0}", Utilities.getMemoryDump(loadExecVSHParam.vshmainArgs, loadExecVSHParam.vshmainArgsSize)));
                }
            }

            if (loadExecVSHParam.args > 0 && loadExecVSHParam.argp != 0)
            {
                string arg = Utilities.readStringNZ(loadExecVSHParam.argp, loadExecVSHParam.args);
                if (arg.StartsWith("disc0:", StringComparison.Ordinal))
                {
                    Modules.IoFileMgrForUserModule.setfilepath("disc0/");
                }
                else if (arg.StartsWith("ms0:", StringComparison.Ordinal))
                {
                    int dirIndex = arg.LastIndexOf('/');
                    if (dirIndex >= 0)
                    {
                        Modules.IoFileMgrForUserModule.setfilepath(Settings.Instance.getDirectoryMapping("ms0") + arg.Substring(4, dirIndex - 4));
                    }
                }
            }

            return(Modules.LoadExecForUserModule.hleKernelLoadExec(filename, loadExecVSHParam.args, loadExecVSHParam.argp));
        }
Ejemplo n.º 26
0
        public virtual int sceKernelLoadExec(PspString filename, TPointer32 optionAddr)
        {
            int argSize = 0;
            int argAddr = 0;

            if (optionAddr.NotNull)
            {
                int optSize = optionAddr.getValue(0);                 // Size of the option struct.
                if (optSize >= 16)
                {
                    argSize = optionAddr.getValue(4);                     // Size of memory required for arguments.
                    argAddr = optionAddr.getValue(8);                     // Arguments (memory area of size argSize).
                    int keyAddr = optionAddr.getValue(12);                // Pointer to an encryption key (may not be used).

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

            return(hleKernelLoadExec(filename, argSize, argAddr));
        }
Ejemplo n.º 27
0
        public virtual int sceNetResolverStartNtoA(int rid, PspString hostname, TPointer32 addr, int timeout, int retry)
        {
            try
            {
                InetAddress inetAddress     = InetAddress.getByName(hostname.String);
                int         resolvedAddress = sceNetInet.bytesToInternetAddress(inetAddress.Address);
                addr.setValue(resolvedAddress);
                //if (log.DebugEnabled)
                {
                    Console.WriteLine(string.Format("sceNetResolverStartNtoA returning address 0x{0:X8}('{1}')", resolvedAddress, sceNetInet.internetAddressToString(resolvedAddress)));
                }
                //else if (log.InfoEnabled)
                {
                    Console.WriteLine(string.Format("sceNetResolverStartNtoA resolved '{0}' into '{1}'", hostname.String, sceNetInet.internetAddressToString(resolvedAddress)));
                }
            }
            catch (UnknownHostException e)
            {
                Console.WriteLine(e);
                return(SceKernelErrors.ERROR_NET_RESOLVER_INVALID_HOST);
            }

            return(0);
        }
Ejemplo n.º 28
0
        public virtual int kuKernelLoadModule(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("kuKernelLoadModule 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));
        }
Ejemplo n.º 29
0
 public virtual int sceKernelPrintf(CpuState cpu, PspString formatString)
 {
     return(hleKernelPrintf(cpu, formatString, stdout));
 }
Ejemplo n.º 30
0
 public virtual int sceLibUpdateDL_34243B86(PspString release)
 {
     // E.g. release is "6.60"
     return(0);
 }