Exemplo n.º 1
0
        private static byte[] getKey(String rifIn, String actIn, String idps)
        {
            if (rifIn == null || actIn == null)
            {
                return(null);
            }
            byte[]     result  = null;
            FileStream rifFile = File.Open(rifIn, FileMode.Open);


            byte[] rif0x40    = new byte[0x10];
            byte[] rif0x50    = new byte[0x10];
            byte[] encrif0x40 = new byte[0x10];
            byte[] encrif0x50 = new byte[0x10];
            rifFile.Seek(0x40, SeekOrigin.Begin);
            rifFile.Read(encrif0x40, 0, encrif0x40.Length);
            rifFile.Read(encrif0x50, 0, encrif0x50.Length);
            rifFile.Close();
            ToolsImpl.aesecbDecrypt(RIFKEY, encrif0x40, 0x00, rif0x40, 0, 0x10); //Decryp firzt 0x10 bytes of RIF
            //System.out.println("rif0x40= " + ConversionUtils.getHexString(rif0x40));
            long index = ConversionUtils.be32(rif0x40, 0xC);                     //

            if (index < 0x80)
            {
                byte[] actDat = decryptACTDAT(actIn, idps);
                byte[] datKey = new byte[0x10];
                result = new byte[0x10];
                ConversionUtils.arraycopy(actDat, (int)index * 16, datKey, 0, 0x10);
                ToolsImpl.aesecbDecrypt(datKey, encrif0x50, 0, result, 0, 0x10);
            }
            return(result);
        }
Exemplo n.º 2
0
        private static byte[] decryptACTDAT(String actIn, String IDPSFile)
        {
            FileStream actFile = File.Open(actIn, FileMode.Open);

            byte[] actdat = new byte[0x800];
            byte[] result = new byte[actdat.Length];
            actFile.Seek(0x10, SeekOrigin.Begin);
            actFile.Read(actdat, 0, actdat.Length);
            actFile.Close();
            byte[] key = getPerConsoleKey(IDPSFile);
            ToolsImpl.aesecbDecrypt(key, actdat, 0, result, 0, actdat.Length);
            return(result);
        }
Exemplo n.º 3
0
        public byte[] getKey(String rapFile)
        {
            BinaryReader raf = new BinaryReader(File.OpenRead(rapFile));

            byte[] read = raf.ReadBytes(0x10);
            //        RandomAccessFile raf = new RandomAccessFile(rapFile, "r");
            //        byte[] read = new byte[0x10];
            //        raf.readFully(read);
            //        raf.close();
            raf.Close();
            byte[] intermediate = new byte[read.Length];
            ToolsImpl.aesecbDecrypt(rapKey, read, 0, intermediate, 0, read.Length);
            for (int loop = 0; loop < 5; loop++)
            {
                for (int loop2 = 0; loop2 < 0x10; loop2++)
                {
                    int index = indexTable[loop2];
                    intermediate[index] = (byte)(intermediate[index] ^ key1[index]);
                }
                for (int loop2 = 0xF; loop2 > 0; loop2--)
                {
                    int index1 = indexTable[loop2];
                    int index2 = indexTable[loop2 - 1];
                    intermediate[index1] = (byte)(intermediate[index1] ^ intermediate[index2]);
                }
                int acum = 0;
                for (int loop2 = 0; loop2 < 0x10; loop2++)
                {
                    int  index   = indexTable[loop2];
                    byte current = (byte)(intermediate[index] - acum);
                    intermediate[index] = current;
                    if (acum != 1 || current != 0xFF)
                    {
                        int aux1 = current & 0xFF;
                        int aux2 = key2[index] & 0xFF;
                        acum = (aux1 < aux2) ? 1 : 0;
                    }
                    current             = (byte)(current - key2[index]);
                    intermediate[index] = current;
                }
            }
            return(intermediate);
        }