コード例 #1
0
        // For Ptp sockets, data in read as a byte stream. Data is not organized in packets.
        // Read as much data as the provided buffer can contain.
        public virtual int recv(TPointer data, TPointer32 dataLengthAddr, int timeout, int nonblock)
        {
            int result = 0;

            try
            {
                SceKernelThreadInfo thread = Modules.ThreadManForUserModule.CurrentThread;
                if (pollRecv(data, dataLengthAddr, thread))
                {
                    // Recv completed immediately
                    result = thread.cpuContext._v0;
                }
                else if (nonblock != 0)
                {
                    // Recv cannot be completed in non-blocking mode
                    result = SceKernelErrors.ERROR_NET_ADHOC_NO_DATA_AVAILABLE;
                }
                else
                {
                    // Block current thread
                    BlockedPdpAction blockedPdpAction = new BlockedPtpRecv(this, data, dataLengthAddr, timeout);
                    blockedPdpAction.blockCurrentThread();
                }
            }
            catch (IOException e)
            {
                result = SceKernelErrors.ERROR_NET_ADHOC_DISCONNECTED;
                Console.WriteLine("recv", e);
            }

            return(result);
        }
コード例 #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected bool pollRecv(pspsharp.HLE.TPointer data, pspsharp.HLE.TPointer32 dataLengthAddr, pspsharp.HLE.kernel.types.SceKernelThreadInfo thread) throws java.io.IOException
        protected internal virtual bool pollRecv(TPointer data, TPointer32 dataLengthAddr, SceKernelThreadInfo thread)
        {
            int  Length    = dataLengthAddr.getValue();
            bool completed = false;

            if (Length > 0)
            {
                if (RcvdData <= 0 || receivedMessage != null)
                {
                    update();
                }

                if (RcvdData > 0)
                {
                    if (Length > RcvdData)
                    {
                        Length = RcvdData;
                    }
                    // Copy the data already received
                    dataLengthAddr.setValue(Length);
                    Memory mem = Memory.Instance;
                    mem.memcpy(data.Address, buffer.addr, Length);
                    if (RcvdData > Length)
                    {
                        // Shift the remaining buffer data to the beginning of the buffer
                        mem.memmove(buffer.addr, buffer.addr + Length, RcvdData - Length);
                    }
                    rcvdData -= Length;

                    //if (log.DebugEnabled)
                    {
                        Console.WriteLine(string.Format("Returned received data: {0:D} bytes", Length));
                        if (log.TraceEnabled)
                        {
                            log.trace(string.Format("Returned data: {0}", Utilities.getMemoryDump(data.Address, Length)));
                        }
                    }
                    setReturnValue(thread, 0);
                    completed = true;
                }
            }

            return(completed);
        }
コード例 #3
0
        private void startCommandWithPageAddress()
        {
            needPageAddress = false;

            switch (command)
            {
            case PSP_NAND_COMMAND_READ_ID:
                if (pageAddress == 0)
                {
                    // This ID will configure:
                    // - sceNandGetPageSize returning 0x200
                    // - sceNandGetPagesPerBlock returning 0x20
                    // - sceNandGetTotalBlocks returning 0x800
                    data[0] = 0xEC;                             // Manufacturer's code (SAMSUNG)
                    data[1] = 0x75;                             // Device code (K9F5608U0C)
                }
                break;

            case PSP_NAND_COMMAND_READ_EXTRA:
                TPointer spare = dataMemory.Pointer;
                sceNandModule.hleNandReadPages(pageAddress >> 10, TPointer.NULL, spare, 1, true, true, true);
                break;
            }
        }
コード例 #4
0
 /// <summary>
 /// Creates a MemoryReader to read values from memory.
 /// </summary>
 /// <param name="address"> the address and memory where to start reading. </param>
 /// <param name="Length">  the maximum number of bytes that can be read. </param>
 /// <param name="step">    when step == 1, read 8-bit values
 ///                when step == 2, read 16-bit values
 ///                when step == 4, read 32-bit values
 ///                other value for step are not allowed. </param>
 /// <returns>        the MemoryReader </returns>
 public static IMemoryReader getMemoryReader(TPointer address, int Length, int step)
 {
     return(getMemoryReader(address.Memory, address.Address, Length, step));
 }
コード例 #5
0
        private void startDma(int dmaControl)
        {
            this.dmaControl = dmaControl;

            if ((dmaControl & DMA_CONTROL_START) != 0)
            {
                int ppn      = dmaAddress >> 10;
                int scramble = getScramble(ppn);

                // Read or write operation?
                if ((dmaControl & DMA_CONTROL_WRITE) != 0)
                {
                    int lbn = endianSwap16(pageEccMemory.read16(6) & 0xFFFF);
                    if (lbn == 0xFFFF)
                    {
                        //if (log.DebugEnabled)
                        {
                            Console.WriteLine(string.Format("writing to ppn=0x{0:X} with lbn=0x{1:X} ignored", ppn, lbn));
                        }
                    }
                    else
                    {
                        TPointer spare = pageEccMemory.Pointer;
                        sceNandModule.hleNandWriteSparePages(ppn, spare, 1, true, true, true);

                        TPointer user = pageDataMemory.Pointer;

                        // Updating the scramble as the LBN corresponding to the PPN might have been moved
                        scramble = getScramble(ppn);
                        if (scramble != 0)
                        {
                            sceNand.descramblePage(scramble, ppn, MMIOHandlerNandPage.Instance.Data, scrambleBuffer);
                            user = scrambleBufferMemory.Pointer;
                        }

                        sceNandModule.hleNandWriteUserPages(ppn, user, 1, true, true);

                        //if (log.DebugEnabled)
                        {
                            sbyte[] userBytes = new sbyte[sceNand.pageSize];
                            user = scramble != 0 ? scrambleBufferMemory.Pointer : pageDataMemory.Pointer;
                            for (int i = 0; i < userBytes.Length; i++)
                            {
                                userBytes[i] = user.getValue8(i);
                            }
                            sbyte[] spareBytes = new sbyte[16];
                            spare = pageEccMemory.Pointer;
                            for (int i = 0; i < spareBytes.Length; i++)
                            {
                                spareBytes[i] = spare.getValue8(i);
                            }
                            Console.WriteLine(string.Format("hleNandWritePages ppn=0x{0:X}, lbn=0x{1:X}, scramble=0x{2:X}: {3}{4}Spare: {5}", ppn, lbn, scramble, Utilities.getMemoryDump(userBytes), lineSeparator, Utilities.getMemoryDump(spareBytes)));
                        }
                    }

                    triggerInterrupt(PSP_NAND_INTR_WRITE_COMPLETED);
                }
                else
                {
                    TPointer user  = scramble != 0 ? scrambleBufferMemory.Pointer : pageDataMemory.Pointer;
                    TPointer spare = pageEccMemory.Pointer;
                    sceNandModule.hleNandReadPages(ppn, user, spare, 1, true, true, true);

                    //if (log.DebugEnabled)
                    {
                        sbyte[] bytes = new sbyte[sceNand.pageSize];
                        user = scramble != 0 ? scrambleBufferMemory.Pointer : pageDataMemory.Pointer;
                        for (int i = 0; i < bytes.Length; i++)
                        {
                            bytes[i] = user.getValue8(i);
                        }
                        Console.WriteLine(string.Format("hleNandReadPages ppn=0x{0:X}, scramble=0x{1:X}: {2}", ppn, scramble, Utilities.getMemoryDump(bytes)));
                    }

                    if (scramble != 0)
                    {
                        sceNand.scramblePage(scramble, ppn, scrambleBuffer, MMIOHandlerNandPage.Instance.Data);
                    }

                    triggerInterrupt(PSP_NAND_INTR_READ_COMPLETED);
                }
            }
        }
コード例 #6
0
        private int hleUtilsBufferCopyWithRange()
        {
            TPointer outAddr = new TPointer(Memory, normalizeAddress(destAddr));
            TPointer inAddr  = new TPointer(Memory, normalizeAddress(sourceAddr));

            int inSize;
            int outSize;
            int dataSize;
            int dataOffset;

            switch (command)
            {
            case PSP_KIRK_CMD_ENCRYPT:
            case PSP_KIRK_CMD_ENCRYPT_FUSE:
                // AES128_CBC_Header
                dataSize = inAddr.getValue32(16);
                inSize   = dataSize + 20;
                outSize  = dataSize + 20;
                break;

            case PSP_KIRK_CMD_DECRYPT:
            case PSP_KIRK_CMD_DECRYPT_FUSE:
                // AES128_CBC_Header
                dataSize = inAddr.getValue32(16);
                inSize   = dataSize + 20;
                outSize  = dataSize;
                break;

            case PSP_KIRK_CMD_DECRYPT_PRIVATE:
                // AES128_CMAC_Header
                dataSize   = inAddr.getValue32(112);
                dataOffset = inAddr.getValue32(116);
                inSize     = 144 + Utilities.alignUp(dataSize, 15) + dataOffset;
                outSize    = Utilities.alignUp(dataSize, 15);
                break;

            case PSP_KIRK_CMD_PRIV_SIG_CHECK:
                // AES128_CMAC_Header
                dataSize   = inAddr.getValue32(112);
                dataOffset = inAddr.getValue32(116);
                inSize     = 144 + Utilities.alignUp(dataSize, 15) + dataOffset;
                outSize    = 0;
                break;

            case PSP_KIRK_CMD_SHA1_HASH:
                // SHA1_Header
                inSize  = inAddr.getValue32(0) + 4;
                outSize = 20;
                break;

            case PSP_KIRK_CMD_ECDSA_GEN_KEYS:
                inSize  = 0;
                outSize = 0x3C;
                break;

            case PSP_KIRK_CMD_ECDSA_MULTIPLY_POINT:
                inSize  = 0x3C;
                outSize = 0x28;
                break;

            case PSP_KIRK_CMD_PRNG:
                inSize  = 0;
                outSize = 0x10;                         // TODO Unknown outSize?
                break;

            case PSP_KIRK_CMD_ECDSA_SIGN:
                inSize  = 0x34;
                outSize = 0x28;
                break;

            case PSP_KIRK_CMD_ECDSA_VERIFY:
                inSize  = 0x64;
                outSize = 0;
                break;

            case PSP_KIRK_CMD_INIT:
                inSize  = 0;
                outSize = 0;
                break;

            case PSP_KIRK_CMD_CERT_VERIFY:
                inSize  = 0xB8;
                outSize = 0;
                break;

            default:
                Console.WriteLine(string.Format("MMIOHandlerKirk.hleUtilsBufferCopyWithRange unimplemented KIRK command 0x{0:X}", command));
                result = PSP_KIRK_INVALID_OPERATION;
                return(0);
            }

            //if (log.DebugEnabled)
            {
                Console.WriteLine(string.Format("hleUtilsBufferCopyWithRange input: {0}", Utilities.getMemoryDump(inAddr, inSize)));
            }

            foreach (int commandToBeDumped in commandsToBeDumped)
            {
                if (command == commandToBeDumped)
                {
                    string dumpFileName = string.Format("dump.hleUtilsBufferCopyWithRange.{0:D}", dumpIndex++);
                    Console.WriteLine(string.Format("MMIOHandlerKirk: hleUtilsBufferCopyWithRange dumping command=0x{0:X}, outputSize=0x{1:X}, inputSize=0x{2:X}, input dumped into file '{3}'", command, outSize, inSize, dumpFileName));
                    try
                    {
                        System.IO.Stream dump        = new System.IO.FileStream(dumpFileName, System.IO.FileMode.Create, System.IO.FileAccess.Write);
                        sbyte[]          inputBuffer = new sbyte[inSize];
                        for (int i = 0; i < inSize; i++)
                        {
                            inputBuffer[i] = inAddr.getValue8(i);
                        }
                        dump.Write(inputBuffer, 0, inputBuffer.Length);
                        dump.Close();
                    }
                    catch (IOException)
                    {
                    }
                }
            }

            result = Modules.semaphoreModule.hleUtilsBufferCopyWithRange(outAddr, outSize, inAddr, inSize, command);

            //if (log.DebugEnabled)
            {
                Console.WriteLine(string.Format("hleUtilsBufferCopyWithRange result=0x{0:X}, output: {1}", result, Utilities.getMemoryDump(outAddr, outSize)));
            }

            if (result != 0)
            {
                string dumpFileName = string.Format("dump.hleUtilsBufferCopyWithRange.{0:D}", dumpIndex++);
                Console.WriteLine(string.Format("MMIOHandlerKirk: hleUtilsBufferCopyWithRange returned error result=0x{0:X} for command=0x{1:X}, outputSize=0x{2:X}, inputSize=0x{3:X}, input dumped into file '{4}'", result, command, outSize, inSize, dumpFileName));
                try
                {
                    System.IO.Stream dump        = new System.IO.FileStream(dumpFileName, System.IO.FileMode.Create, System.IO.FileAccess.Write);
                    sbyte[]          inputBuffer = new sbyte[inSize];
                    for (int i = 0; i < inSize; i++)
                    {
                        inputBuffer[i] = inAddr.getValue8(i);
                    }
                    dump.Write(inputBuffer, 0, inputBuffer.Length);
                    dump.Close();
                }
                catch (IOException)
                {
                }
            }

            return(System.Math.Max(inSize, outSize));
        }
コード例 #7
0
 public override int ioRead(TPointer outputPointer, int outputLength)
 {
     return(doRead(outputPointer, null, 0, outputLength));
 }
コード例 #8
0
        private int doRead(TPointer outputPointer, sbyte[] outputBuffer, int outputOffset, int outputLength)
        {
            if (EOF)
            {
                return(-1);
            }

            int readLength = 0;
            int readAddr   = outputPointer != null ? outputPointer.Address : 0;

            while (remainingPacketLength > 0 && readLength < outputLength)
            {
                int maxReadLength = System.Math.Min(remainingPacketLength, outputLength - readLength);
                int l;
                if (outputBuffer != null)
                {
                    l = vFile.ioRead(outputBuffer, outputOffset, maxReadLength);
                }
                else if (outputPointer != null)
                {
                    l = vFile.ioRead(new TPointer(outputPointer.Memory, readAddr), maxReadLength);
                }
                else
                {
                    l = maxReadLength;
                }

                if (l > 0)
                {
                    remainingPacketLength -= l;
                    readLength            += l;
                    readAddr     += l;
                    outputOffset += l;
                    position     += l;
                }
                else if (l < 0)
                {
                    break;
                }
            }

            if (remainingPacketLength > 0)
            {
                return(readLength);
            }

            while (!EOF && readLength < outputLength)
            {
                long startIndex = vFile.Position;
                int  startCode  = 0xFF;
                while ((startCode & PACKET_START_CODE_MASK) != PACKET_START_CODE_PREFIX && !EOF)
                {
                    startCode = (startCode << 8) | read8();
                }
                //if (log.DebugEnabled)
                {
                    Console.WriteLine(string.Format("StartCode 0x{0:X8}, offset {1:X8}, skipped {2:D}", startCode, vFile.Position, vFile.Position - startIndex - 4));
                }

                switch (startCode)
                {
                case PACK_START_CODE:
                {
                    skip(10);
                    break;
                }

                case SYSTEM_HEADER_START_CODE:
                {
                    skip(14);
                    break;
                }

                case PADDING_STREAM:
                case PRIVATE_STREAM_2:
                {
                    int Length = read16();
                    skip(Length);
                    break;
                }

                case PRIVATE_STREAM_1:
                {
                    // Audio stream
                    int       Length    = read16();
                    PesHeader pesHeader = new PesHeader(audioChannel);
                    Length = readPesHeader(pesHeader, Length, startCode);
                    if (pesHeader.Channel == audioChannel || audioChannel < 0)
                    {
                        int packetLength = 0;
                        while (packetLength < Length && readLength < outputLength)
                        {
                            int maxReadLength = System.Math.Min(Length - packetLength, outputLength - readLength);
                            int l;
                            if (outputBuffer != null)
                            {
                                l = vFile.ioRead(outputBuffer, outputOffset, maxReadLength);
                            }
                            else if (outputPointer != null)
                            {
                                l = vFile.ioRead(new TPointer(outputPointer.Memory, readAddr), maxReadLength);
                            }
                            else
                            {
                                l = maxReadLength;
                            }

                            if (l > 0)
                            {
                                readLength   += l;
                                readAddr     += l;
                                outputOffset += l;
                                packetLength += l;
                                position     += l;
                            }
                            else if (l < 0)
                            {
                                break;
                            }
                        }
                        remainingPacketLength = Length - packetLength;
                    }
                    else
                    {
                        skip(Length);
                    }
                    break;
                }

                case 0x1E0:
                case 0x1E1:
                case 0x1E2:
                case 0x1E3:
                case 0x1E4:
                case 0x1E5:
                case 0x1E6:
                case 0x1E7:
                case 0x1E8:
                case 0x1E9:
                case 0x1EA:
                case 0x1EB:
                case 0x1EC:
                case 0x1ED:
                case 0x1EE:
                case 0x1EF:
                {
                    // Video Stream, skipped
                    int Length = read16();
                    skip(Length);
                    break;
                }

                default:
                {
                    Console.WriteLine(string.Format("Unknown StartCode 0x{0:X8}, offset {1:X8}", startCode, vFile.Position));
                }
                break;
                }
            }

            return(readLength);
        }
コード例 #9
0
 protected internal BlockedPtpRecv(PtpObject ptpObject, TPointer data, TPointer32 dataLengthAddr, int timeout) : base(ptpObject, timeout)
 {
     this.data           = data;
     this.dataLengthAddr = dataLengthAddr;
 }
コード例 #10
0
 public override int ioRead(TPointer outputPointer, int outputLength)
 {
     return(base.ioRead(outputPointer, outputLength));
 }