示例#1
0
        void Rebuild(List <FileItems> inputFiles, string outputFile)
        {
            Stream stream = null;

            try
            {
                stream = new FileStream(outputFile, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                using (StreamWriter writer = new StreamWriter(stream))
                {
                    BinaryReader reader   = new BinaryReader(stream);
                    ARF_HEADER   arf_head = new ARF_HEADER
                    {
                        e_magic     = 0x00020001,
                        e_unknown   = 0x00000000,
                        e_filesize  = 0xadafea,
                        e_reserved0 = 0,
                        e_nsections = 0x1b,
                        e_reserved1 = 0
                    };

                    int video = 0;

                    ARF_ITEMS[] arf_item = new ARF_ITEMS[arf_head.e_nsections];

                    long Offset = Marshal.SizeOf(typeof(ARF_ITEMS)) * arf_head.e_nsections + Marshal.SizeOf(typeof(ARF_HEADER));

                    for (int x = 0; x < inputFiles.Count; x++)
                    {
                        FileInfo       f    = new FileInfo(inputFiles[x].fileName);
                        FileSystemInfo f1   = new FileInfo(inputFiles[x].fileName);
                        string         name = f1.Name;

                        FileItems.SegmentType id = inputFiles[x].id;

                        arf_item[x].e_id            = (uint)id;
                        arf_item[x].e_sectionoffset = (uint)Offset;
                        arf_item[x].e_sectionlen    = (uint)f.Length;


                        arf_item[x].e_indice = 0;

                        if (id == FileItems.SegmentType.video || id == FileItems.SegmentType.video_idx)
                        {
                            arf_item[x].e_indice = (uint)video;
                        }

                        if (id == FileItems.SegmentType.video_idx)
                        {
                            video++;
                        }

                        arf_item[x].e_reserved1 = 0;
                        arf_item[x].e_reserved2 = 0;
                        arf_item[x].e_reserved3 = 0;
                        arf_item[x].e_reserved4 = 0;
                        Offset += f.Length + 1;
                    }

                    arf_head.e_filesize = (uint)(Offset - 1);
                    writer.Write(GetBytes(arf_head));

                    for (int x = 0; x < arf_head.e_nsections; x++)
                    {
                        writer.Write(GetBytes(arf_item[x]));
                    }



                    Offset = 0;

                    foreach (FileItems file in inputFiles)
                    {
                        FileStream   streamOrigin = new FileStream(file.fileName, FileMode.Open, FileAccess.Read);
                        BinaryReader readerOrigin = new BinaryReader(streamOrigin);

                        try
                        {
                            var bytes = readerOrigin.ReadBytes((int)streamOrigin.Length);
                            writer.Write(bytes);
                        }
                        catch (OutOfMemoryException)
                        {
                            MessageBox.Show("Error", "The program just ran out of memory!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            MessageBox.Show("Info", "This may be fixed someday...", MessageBoxButtons.OK, MessageBoxIcon.Information);

                            Application.Exit();
                        }

                        Offset += streamOrigin.Length;
                        //long  pad = (Offset % 4);
                        //if (pad!=0)
                        writer.Write((byte)0);//x);

                        // writer.Flush();
                    }

                    logs.Items.Add("[=] Re-constructed File: " + outputFile);
                    MessageBox.Show("Reconstruction completed", "Corrected", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    writer.Dispose();
                    writer.Close();
                }
            }
            catch (IOException)
            {
                MessageBox.Show("The directory is not valid", "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            finally
            {
                if (stream != null)
                {
                    stream.Dispose();
                }
            }
        }
示例#2
0
        void Rebuild(List <FileItems> inputFiles, string outputFile)
        {
            FileStream stream = null;

            try
            {
                stream = new FileStream(outputFile, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                using (BinaryWriter writer = new BinaryWriter(stream))
                {
                    // Number of sections of the .arf file
                    int    nsections     = inputFiles.Count;
                    String nsections_hex = nsections.ToString("X");

                    BinaryReader reader   = new BinaryReader(stream);
                    ARF_HEADER   arf_head = new ARF_HEADER
                    {
                        e_magic     = 0x00020001,
                        e_unknown   = 0x00000000,
                        e_filesize  = 0xadafea,
                        e_reserved0 = 0,
                        e_nsections = UInt32.Parse(nsections_hex, System.Globalization.NumberStyles.AllowHexSpecifier),
                        e_reserved1 = 0
                    };

                    ARF_ITEMS[] arf_item = new ARF_ITEMS[arf_head.e_nsections];
                    long        Offset   = Marshal.SizeOf(typeof(ARF_ITEMS)) * arf_head.e_nsections + Marshal.SizeOf(typeof(ARF_HEADER));
                    for (int x = 0; x < inputFiles.Count; x++)
                    {
                        FileInfo       f  = new FileInfo(inputFiles[x].fileName);
                        FileSystemInfo f1 = new FileInfo(inputFiles[x].fileName);

                        FileItems.SegmentType id = inputFiles[x].id;
                        arf_item[x].e_id            = (uint)id;
                        arf_item[x].e_sectionoffset = (uint)Offset;
                        arf_item[x].e_sectionlen    = (uint)f.Length;

                        // Index of file
                        arf_item[x].e_index = (uint)inputFiles[x].index;

                        arf_item[x].e_reserved1 = 0;
                        arf_item[x].e_reserved2 = 0;
                        arf_item[x].e_reserved3 = 0;
                        arf_item[x].e_reserved4 = 0;
                        Offset += f.Length + 1;
                    }

                    arf_head.e_filesize = (uint)(Offset - 1);
                    writer.Write(GetBytes(arf_head));
                    for (int x = 0; x < arf_head.e_nsections; x++)
                    {
                        writer.Write(GetBytes(arf_item[x]));
                    }
                    Offset = 0;

                    foreach (FileItems file in inputFiles)
                    {
                        FileStream   streamOrigin = new FileStream(file.fileName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                        BinaryReader readerOrigin = new BinaryReader(streamOrigin);

                        try
                        {
                            var bytes = readerOrigin.ReadBytes((int)streamOrigin.Length);
                            writer.Write(bytes);
                        }
                        catch (OutOfMemoryException)
                        {
                            MessageBox.Show("Error", "The program just ran out of memory!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            MessageBox.Show("Info", "This may be fixed someday...", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            Application.Exit();
                        }

                        Offset += streamOrigin.Length;
                        //long  pad = (Offset % 4);
                        //if (pad!=0)
                        writer.Write((byte)0);//x);
                    }
                    writer.Flush();
                    ToLog("[=] Re-constructed file: " + outputFile);
                    MessageBox.Show("Reconstruction completed", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    writer.Dispose();
                    writer.Close();
                }
            }
            catch (IOException)
            {
                MessageBox.Show("The directory is not valid", "Sorry", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            finally
            {
                if (stream != null)
                {
                    stream.Dispose();
                }
            }
        }