Exemple #1
0
        void HeaderReader(int HeaderLenght, ref FARCFile[] Files, ref KKtIO reader)
        {
            if (Files == null)
            {
                int  Count    = 0;
                long Position = reader.BaseStream.Position;
                while (reader.BaseStream.Position < HeaderLenght)
                {
                    reader.NullTerminated(0x00);
                    reader.ReadInt32();
                    if (Signature != Farc.FArc)
                    {
                        reader.ReadInt32();
                    }
                    reader.ReadInt32();
                    if (Signature == Farc.FARC && FT)
                    {
                        reader.ReadInt32();
                    }
                    Count++;
                }
                reader.Seek(Position, 0);
                Files = new FARCFile[Count];
            }

            int LocalMode = 0;

            for (int i = 0; i < Files.Length; i++)
            {
                Files[i].Name   = Text.ToUTF8(reader.NullTerminated(0x00));
                Files[i].Offset = reader.ReadInt32Endian(true);
                if (Signature != Farc.FArc)
                {
                    Files[i].SizeComp = reader.ReadInt32Endian(true);
                }
                Files[i].SizeUnc = reader.ReadInt32Endian(true);
                if (Signature == Farc.FARC && FT)
                {
                    LocalMode     = reader.ReadInt32Endian(true);
                    Files[i].GZip = (LocalMode & 2) == 2;
                    Files[i].ECB  = (LocalMode & 4) == 4;
                }
            }
        }
Exemple #2
0
        public static void Decrypt(int I, string file)
        {
            KKtIO reader = KKtIO.OpenReader(file);

            if (reader.ReadInt64() != 0x454C494641564944)
            {
                reader.Close();
                Encrypt(I, file);
            }
            else
            {
                Console.Title = "PD_Tool: DIVAFILE Decryptor - File: " + Path.GetFileName(file);
                reader.ReadUInt32();
                int    StreamLenght = (int)reader.Length;
                int    FileLenght   = reader.ReadInt32();
                byte[] decrypted    = new byte[StreamLenght];
                reader.Seek(0, 0);
                using (AesManaged crypto = new AesManaged())
                {
                    crypto.Key     = Key;
                    crypto.IV      = new byte[16];
                    crypto.Mode    = CipherMode.ECB;
                    crypto.Padding = PaddingMode.Zeros;
                    using (CryptoStream cryptoData = new CryptoStream(reader.BaseStream,
                                                                      crypto.CreateDecryptor(crypto.Key, crypto.IV), CryptoStreamMode.Read))
                        cryptoData.Read(decrypted, 0, StreamLenght);
                }
                KKtIO writer = KKtIO.OpenWriter(file, FileLenght);
                for (int i = 0x10; i < StreamLenght && i < FileLenght + 0x10; i++)
                {
                    writer.Write(decrypted[i]);
                }
                writer.Close();
            }
            Console.Title = "PD_Tool";
        }
Exemple #3
0
        public static int BINReader(ref AUTH Data, string file)
        {
            Data = new AUTH {
                dataArray = new string[4], Name = new List <string>(), Value = new List <string>()
            };
            KKtIO reader = KKtIO.OpenReader(file + ".bin");

            reader.Format  = KKtMain.Format.F;
            Data.Signature = reader.ReadInt32();
            if (Data.Signature != 0x44334123)
            {
                return(0);
            }
            Data.Signature = reader.ReadInt32();
            if (Data.Signature != 0x5F5F5F41)
            {
                return(0);
            }
            reader.ReadInt64();

            byte[] STRData     = reader.ReadBytes((int)(reader.Length - reader.Position));
            string TempSTRData = "";

            foreach (byte a in STRData)
            {
                if (a == 0x0A)
                {
                    if (!TempSTRData.StartsWith("#"))
                    {
                        Data.dataArray = TempSTRData.Split('=');
                        Data.Name.Add(Data.dataArray[0]);
                        Data.Value.Add(Data.dataArray[1]);
                    }
                    TempSTRData = "";
                }
                else
                {
                    TempSTRData += Convert.ToChar(a);
                }
            }

            for (int i = 0; i < Data.Name.Count; i++)
            {
                if (Data.Name[i] == "category.length")
                {
                    Data.Category = new string[int.Parse(Data.Value[i])];
                }
                else if (Data.Name[i] == "uid.length")
                {
                    Data.UID = new UID[int.Parse(Data.Value[i])];
                }
            }

            if (Data.Category != null)
            {
                for (int i0 = 0; i0 < Data.Category.Length; i0++)
                {
                    for (int i = 0; i < Data.Name.Count; i++)
                    {
                        if (Data.Name[i] == "category." + i0 + ".value")
                        {
                            Data.Category[i0] = Data.Value[i];
                        }
                    }
                }
            }

            if (Data.UID != null)
            {
                for (int i0 = 0; i0 < Data.UID.Length; i0++)
                {
                    Data.UID[i0].Category = "";
                    Data.UID[i0].Size     = -1;
                    Data.UID[i0].Value    = "";
                    for (int i = 0; i < Data.Name.Count; i++)
                    {
                        if (Data.Name[i] == "uid." + i0 + ".category")
                        {
                            Data.UID[i0].Category = Data.Value[i];
                        }
                        else if (Data.Name[i] == "uid." + i0 + ".size")
                        {
                            Data.UID[i0].Size = int.Parse(Data.Value[i]);
                        }
                        else if (Data.Name[i] == "uid." + i0 + ".value")
                        {
                            Data.UID[i0].Value = Data.Value[i];
                        }
                    }
                }
            }

            reader.Close();
            return(1);
        }
Exemple #4
0
        public int DEXReader()
        {
            KKtIO reader = KKtIO.OpenReader(filepath + ext);

            Header = new KKtMain.Header();

            Header.Format    = KKtMain.Format.F;
            Header.Signature = reader.ReadInt32();
            if (Header.Signature == 0x43505845)
            {
                Header = reader.ReadHeader(true);
            }
            if (Header.Signature != 0x64)
            {
                return(0);
            }

            Offset = reader.Position - 0x4;
            DEX    = new EXP[reader.ReadInt32()];
            int DEXOffset = reader.ReadInt32();

            if (reader.ReadInt32() == 0x00)
            {
                Header.Format = KKtMain.Format.X;
            }

            reader.Seek(DEXOffset + Offset, 0);
            for (int i0 = 0; i0 < DEX.Length; i0++)
            {
                DEX[i0] = new EXP {
                    Main = new List <EXPElement>(), Eyes = new List <EXPElement>()
                }
            }
            ;

            for (int i0 = 0; i0 < DEX.Length; i0++)
            {
                DEX[i0].MainOffset = reader.ReadInt32();
                if (Header.Format == KKtMain.Format.X)
                {
                    reader.ReadInt32();
                }
                DEX[i0].EyesOffset = reader.ReadInt32();
                if (Header.Format == KKtMain.Format.X)
                {
                    reader.ReadInt32();
                }
            }
            for (int i0 = 0; i0 < DEX.Length; i0++)
            {
                DEX[i0].NameOffset = reader.ReadInt32();
                if (Header.Format == KKtMain.Format.X)
                {
                    reader.ReadInt32();
                }
            }

            for (int i0 = 0; i0 < DEX.Length; i0++)
            {
                EXPElement element = new EXPElement();
                reader.Seek(DEX[i0].MainOffset + Offset, 0);
                while (true)
                {
                    element.Frame = reader.ReadSingle();
                    element.Both  = reader.ReadUInt16();
                    element.ID    = reader.ReadUInt16();
                    element.Value = reader.ReadSingle();
                    element.Trans = reader.ReadSingle();
                    DEX[i0].Main.Add(element);

                    if (element.Frame == 999999 || element.Both == 0xFFFF)
                    {
                        break;
                    }
                }

                reader.Seek(DEX[i0].EyesOffset + Offset, 0);
                while (true)
                {
                    element.Frame = reader.ReadSingle();
                    element.Both  = reader.ReadUInt16();
                    element.ID    = reader.ReadUInt16();
                    element.Value = reader.ReadSingle();
                    element.Trans = reader.ReadSingle();
                    DEX[i0].Eyes.Add(element);

                    if (element.Frame == 999999 || element.Both == 0xFFFF)
                    {
                        break;
                    }
                }

                reader.Seek(DEX[i0].NameOffset + Offset, 0);
                DEX[i0].Name = KKtText.ToUTF8(reader.NullTerminated());
            }

            reader.Close();
            return(1);
        }
Exemple #5
0
        public int STRReader()
        {
            KKtIO reader = KKtIO.OpenReader(filepath + ext);

            reader.Format    = KKtMain.Format.F;
            Header.Signature = reader.ReadInt32();
            if (Header.Signature == 0x41525453)
            {
                Header          = reader.ReadHeader(true);
                STR             = new List <String>();
                POF             = KKtMain.AddPOF(Header);
                reader.Position = Header.Lenght;

                Count  = reader.ReadInt32Endian();
                Offset = reader.ReadInt32Endian();
                if (Offset == 0)
                {
                    Offset         = Count;
                    OffsetX        = reader.ReadInt64();
                    Count          = reader.ReadInt64();
                    reader.XOffset = Header.Lenght;
                    reader.Format  = KKtMain.Format.X;
                }
                reader.LongPosition = reader.IsX ? Offset + reader.XOffset : Offset;

                for (int i = 0; i < Count; i++)
                {
                    String Str = new String
                    {
                        StrOffset = reader.GetOffset(ref POF).ReadInt32Endian(),
                        ID        = reader.ReadInt32Endian()
                    };
                    if (reader.IsX)
                    {
                        Str.StrOffset += (int)OffsetX;
                    }
                    STR.Add(Str);
                }
                for (int i = 0; i < Count; i++)
                {
                    reader.LongPosition = STR[i].StrOffset + (reader.IsX ? reader.XOffset : 0);
                    STR[i] = new String {
                        ID = STR[i].ID, Str = KKtText.
                                              ToUTF8(reader.NullTerminated()), StrOffset = STR[i].StrOffset
                    };
                }
                reader.Seek(POF.Offset, 0);
                reader.ReadPOF(ref POF);
            }
            else
            {
                reader.Seek(-4, (SeekOrigin)1);
                int i = 0;
                STR = new List <String>();
                while (reader.LongPosition > 0 && reader.LongPosition < reader.LongLength)
                {
                    int a = reader.ReadInt32();
                    if (a != 0)
                    {
                        reader.Seek(-4, (SeekOrigin)1);
                        STR.Add(new String {
                            Str = KKtText.ToUTF8(reader.NullTerminated()), ID = i
                        });
                        i++;
                    }
                    else
                    {
                        break;
                    }
                }
                Count = STR.Count;
            }

            reader.Close();
            return(1);
        }