Exemplo n.º 1
0
        public static void dumpfiles(string listfile)
        {
            string workingdir = Directory.GetCurrentDirectory();

            filearc newfile = new filearc();

            using (FileStream filestream = File.OpenRead(listfile))
            {
                using (BinaryReader streamread = new BinaryReader(filestream))
                {
                    newfile.numfolders = streamread.ReadInt32();
                    newfile.numfiles   = streamread.ReadInt32();
                    int unk = streamread.ReadInt32();
                    Console.WriteLine("posis " + streamread.BaseStream.Position);

                    byte[] strprocess = streamread.ReadBytes(52);
                    newfile.archivename = Encoding.UTF8.GetString(strprocess).TrimEnd('\0');

                    try
                    {
                        if (!File.Exists(Path.Combine(workingdir, newfile.archivename)))
                        {
                            Console.WriteLine("binary file " + newfile.archivename + " not found");
                            return;
                        }
                    }
                    catch (ArgumentException)
                    {
                        Console.WriteLine("binary file path invalid");
                        return;
                    }

                    Console.WriteLine("arcname " + newfile.archivename);

                    Console.WriteLine("posis " + streamread.BaseStream.Position);


                    //archivename = streamread.ReadString(24);


                    for (int i = 0; i < newfile.numfolders; i++)
                    {
                        //Console.WriteLine("fposst " + streamread.BaseStream.Position);
                        Console.WriteLine("numfolders " + newfile.numfolders);
                        filemetadata metadata = new filemetadata();

                        metadata.isfolder = true;

                        metadata.size1 = streamread.ReadUInt32();
                        metadata.size2 = streamread.ReadUInt32();
                        metadata.pos   = streamread.ReadUInt32();

                        Console.WriteLine("fpos " + streamread.BaseStream.Position + " and " + metadata.size1);

                        string path = Encoding.UTF8.GetString(streamread.ReadBytes(116)).TrimEnd('\0');
                        //metadata.findex = streamread.ReadInt32();
                        if (i == newfile.numfolders - 1)
                        {
                            metadata.findex = streamread.ReadUInt32();
                        }

                        //Console.WriteLine("fsize1 " + metadata.size1);

                        //Console.WriteLine("fsize2 " + metadata.size2);

                        //Console.WriteLine("fpos " + metadata.pos);

                        Console.WriteLine("fpath " + path);

                        Console.WriteLine("lastfpos " + streamread.BaseStream.Position);

                        metadata.path = path;

                        newfile.folderlist.Add(metadata);
                    }
                    foreach (filemetadata folder in newfile.folderlist)
                    {
                        for (int i = 0; i < folder.size1; i++)
                        {
                            filemetadata metadata = new filemetadata();
                            metadata.size1 = streamread.ReadUInt32();
                            metadata.size2 = streamread.ReadUInt32();
                            metadata.pos   = streamread.ReadUInt32();

                            Console.WriteLine("mypos " + streamread.BaseStream.Position);

                            string path = Encoding.UTF8.GetString(streamread.ReadBytes(52)).TrimEnd('\0');

                            Console.WriteLine(path);

                            metadata.path = path;

                            if (newfile.folderlist.Count > 0)
                            {
                                metadata.infolder = folder.path;
                            }

                            newfile.filelist.Add(metadata);

                            Console.WriteLine("forfin");
                        }
                    }
                }
            }

            //Console.WriteLine(Path.Combine(workingdir, "d"));
            // File.WriteAllLines(Path.Combine(workingdir, "debugout@"+"test.txt"), br);
            Console.WriteLine(Path.Combine(workingdir, newfile.archivename));

            //byte[] archive = File.ReadAllBytes(Path.Combine(workingdir, newfile.archivename));

            using (FileStream filestream = File.OpenRead(Path.Combine(workingdir, newfile.archivename)))
            {
                using (BinaryReader readfile = new BinaryReader(filestream))
                {
                    foreach (filemetadata folder in newfile.folderlist)
                    {
                        string outpath = Path.Combine(workingdir, @"output", @folder.path);

                        new FileInfo(@outpath).Directory.Create();

                        Console.WriteLine(outpath + " folnum " + newfile.folderlist.Count + " foldpath " + folder.path);
                    }

                    foreach (filemetadata file in newfile.filelist)
                    {
                        if (file.isfolder == false)
                        {
                            readfile.BaseStream.Position = file.pos;

                            byte[] fbytes  = readfile.ReadBytes(Convert.ToInt32(file.size1));
                            string outpath = Path.Combine(workingdir, @"output", @file.infolder, @file.path);

                            new FileInfo(outpath).Directory.Create();

                            File.WriteAllBytes(outpath, fbytes);

                            Console.WriteLine("infolder " + file.infolder + " filepath " + file.path + " outpath " + outpath);
                        }
                    }
                }
            }

            return;
        }
Exemplo n.º 2
0
        public static void dumpfiles(byte[] listfile, string outtxt = "")
        {
            string workingdir = Directory.GetCurrentDirectory();

            filearc      newfile   = new filearc();
            StreamWriter outwriter = null;

            if (outtxt != "")
            {
                outwriter = File.CreateText(outtxt);
            }
            using (MemoryStream filestream = new MemoryStream(listfile))
            {
                using (BinaryReader streamread = new BinaryReader(filestream))
                {
                    newfile.numfolders = streamread.ReadInt32();
                    newfile.numfiles   = streamread.ReadInt32();
                    int unk = streamread.ReadInt32();

                    Console.WriteLine("posis " + streamread.BaseStream.Position);

                    byte[] strprocess = streamread.ReadBytes(52);


                    newfile.archivename = Encoding.UTF8.GetString(strprocess).TrimEnd('\0');

                    Console.WriteLine("arcname " + newfile.archivename);

                    Console.WriteLine("posis " + streamread.BaseStream.Position);
                    if (outwriter != null)
                    {
                        outwriter.WriteLine("Archive name: " + newfile.archivename);
                    }

                    //archivename = streamread.ReadString(24);


                    for (int i = 0; i < newfile.numfolders; i++)
                    {
                        //Console.WriteLine("fposst " + streamread.BaseStream.Position);
                        Console.WriteLine("numfolders " + newfile.numfolders);
                        filemetadata metadata = new filemetadata();

                        metadata.isfolder = true;

                        metadata.size1 = streamread.ReadInt32();
                        metadata.size2 = streamread.ReadInt32();
                        metadata.pos   = streamread.ReadInt32();

                        Console.WriteLine("fpos " + streamread.BaseStream.Position + " and " + metadata.size1);

                        string path = Encoding.UTF8.GetString(streamread.ReadBytes(116)).TrimEnd('\0');
                        //metadata.findex = streamread.ReadInt32();
                        if (i == newfile.numfolders - 1)
                        {
                            metadata.findex = streamread.ReadInt32();
                        }

                        //Console.WriteLine("fsize1 " + metadata.size1);

                        //Console.WriteLine("fsize2 " + metadata.size2);

                        //Console.WriteLine("fpos " + metadata.pos);
                        if (outwriter != null)
                        {
                            outwriter.WriteLine(path);
                        }
                        Console.WriteLine("fpath " + path);

                        Console.WriteLine("lastfpos " + streamread.BaseStream.Position);

                        metadata.path = path;

                        newfile.folderlist.Add(metadata);
                    }
                    foreach (filemetadata folder in newfile.folderlist)
                    {
                        for (int i = 0; i < folder.size1; i++)
                        {
                            filemetadata metadata = new filemetadata();
                            metadata.size1 = streamread.ReadInt32();
                            metadata.size2 = streamread.ReadInt32();
                            metadata.pos   = streamread.ReadInt32();

                            Console.WriteLine("mypos " + streamread.BaseStream.Position);

                            string path = Encoding.UTF8.GetString(streamread.ReadBytes(52)).TrimEnd('\0');

                            Console.WriteLine(path);

                            metadata.path = path;

                            if (newfile.folderlist.Count > 0)
                            {
                                metadata.infolder = folder.path;
                            }

                            newfile.filelist.Add(metadata);

                            Console.WriteLine("forfin");
                        }
                    }
                }
            }
            if (outwriter != null)
            {
                outwriter.Close();
                return;
            }
            //Console.WriteLine(Path.Combine(workingdir, "d"));
            // File.WriteAllLines(Path.Combine(workingdir, "debugout@"+"test.txt"), br);
            Console.WriteLine(Path.Combine(workingdir, newfile.archivename));

            byte[] archive = File.ReadAllBytes(Path.Combine(workingdir, newfile.archivename));

            using (MemoryStream filestream = new MemoryStream(archive))
            {
                using (BinaryReader readfile = new BinaryReader(filestream))
                {
                    foreach (filemetadata folder in newfile.folderlist)
                    {
                        string outpath = Path.Combine(workingdir, @"output", @folder.path);

                        new FileInfo(@outpath).Directory.Create();

                        Console.WriteLine(outpath + " folnum " + newfile.folderlist.Count + " foldpath " + folder.path);
                    }

                    foreach (filemetadata file in newfile.filelist)
                    {
                        if (file.isfolder == false)
                        {
                            readfile.BaseStream.Position = file.pos;

                            byte[] fbytes  = readfile.ReadBytes(file.size1);
                            string outpath = Path.Combine(workingdir, @"output", @file.infolder, @file.path);

                            new FileInfo(outpath).Directory.Create();

                            File.WriteAllBytes(outpath, fbytes);

                            Console.WriteLine("infolder " + file.infolder + " filepath " + file.path + " outpath " + outpath);
                        }
                    }
                }
            }

            return;
        }
Exemplo n.º 3
0
        public static void buildfiles(List <String> @inputdirlist, string @outputdir, string binfile, bool firstfol = false)
        {
            string workingdir = Directory.GetCurrentDirectory();

            filearc newfile = new filearc();

            newfile.binaryfiledir = binfile;

            uint filepos = 0;
            uint fpos    = 0;
            uint j       = 0; //filecnt related

            //for (int indirs = 0; indirs < inputdirlist.Count; indirs++)
            foreach (string inputdir in inputdirlist)
            {
                string pathname = new DirectoryInfo(inputdir).Name;

                Console.WriteLine(inputdir + " in ");

                Directory.CreateDirectory(inputdir);

                string[] allfiles   = Directory.GetFiles(inputdir, "*.*", SearchOption.AllDirectories);
                string[] allfolders = Directory.GetDirectories(inputdir, "*.*", SearchOption.AllDirectories);

                newfile.numfiles += allfiles.Length;

                for (int i = 0; i < allfolders.Length; i++)
                {
                    string folpathstr = (firstfol) ? allfolders[i].Substring(inputdir.IndexOf(pathname), allfolders[i].Length - inputdir.IndexOf(pathname)) : allfolders[i].Substring(inputdir.IndexOf(pathname) + pathname.Length + 1, allfolders[i].Length - inputdir.IndexOf(pathname) - (pathname.Length + 1));

                    Console.WriteLine(" fo " + allfolders[i] + " fopathstr " + folpathstr);

                    filemetadata folder = new filemetadata();

                    folder.path = folpathstr;

                    folder.size1 = Convert.ToUInt32(Directory.GetFiles(allfolders[i]).Length);

                    Console.WriteLine(allfolders[i] + " len " + folder.size1);

                    folder.size2 = j;

                    Console.WriteLine(" fo " + allfolders[i]);

                    folder.associated_indir = inputdir;

                    string usepath = (firstfol)? Path.Combine(Directory.GetParent(folder.associated_indir).FullName, folder.path) : Path.Combine(folder.associated_indir, folder.path);

                    Console.WriteLine("asspath " + usepath + " and path " + folder.path + " usepath " + usepath);

                    //System.Environment.Exit(0);

                    string[] folfiles = Directory.GetFiles(usepath);

                    if (folder.size1 > 0)
                    {
                        int existindex = newfile.folderlist.FindIndex(item => item.path == folder.path);

                        Console.WriteLine("existi " + existindex);

                        //this shit doesnt even work
                        if (existindex > -1)
                        {
                            //merge folder contents

                            newfile.folderlist[existindex].size1 += folder.size1;

                            newfile.folderlist[existindex].folfiles.AddRange(folfiles.ToList());
                        }
                        else
                        {
                            folder.folfiles.AddRange(folfiles.ToList());

                            newfile.folderlist.Add(folder);
                        }
                    }


                    j += folder.size1;

                    Console.WriteLine("folder size " + folder.size1 + " folder size2 " + folder.size2 + " folder path " + folder.path + " what " + newfile.folderlist.Count);
                }

                newfile.numfolders = newfile.folderlist.Count;
            }


            foreach (filemetadata folder in newfile.folderlist)
            {
                string[] folfiles = folder.folfiles.ToArray();

                folder.pos = fpos;

                Console.WriteLine("pos " + folder.pos);

                Console.WriteLine("should be \\" + folder.associated_indir + "\\ potentially also \\" + folder.path + "\\ literaly me \\" + Path.Combine(folder.associated_indir, folder.path));

                Console.WriteLine("2 len" + folfiles.Length);

                string pathname = new DirectoryInfo(folder.associated_indir).Name;

                for (int i = 0; i < folfiles.Length; i++)
                {
                    //Console.WriteLine(i + " dir " + allfiles[i]);

                    filemetadata file = new filemetadata();

                    file.fdata = File.ReadAllBytes(folfiles[i]);

                    file.size1 = Convert.ToUInt32(file.fdata.Length);
                    file.size2 = Convert.ToUInt32(file.fdata.Length);

                    file.path = Path.GetFileName(folfiles[i]);

                    file.infolder = (firstfol) ? folfiles[i].Substring(folder.associated_indir.IndexOf(pathname) + pathname.Length + 1, folfiles[i].Length - folder.associated_indir.IndexOf(pathname) - (pathname.Length + 1)) : folfiles[i].Substring(folder.associated_indir.IndexOf(pathname) + pathname.Length + 1, folfiles[i].Length - folder.associated_indir.IndexOf(pathname) - (pathname.Length + 1));

                    Console.WriteLine(" her u o po " + newfile.filelist.Count);

                    Console.WriteLine("file path " + file.path + " file folder " + file.infolder + " fofiles len " + folfiles.Length);

                    int existindex = newfile.filelist.FindIndex(item => item.path == file.path && item.infolder == file.infolder);

                    Console.WriteLine("existi file " + existindex + " path " + file.path + " inf " + file.infolder);
                    Console.WriteLine("fpathmaster " + folfiles[i] + " len " + file.fdata.Length);

                    //this shit doesnt even work
                    if (existindex > -1)
                    {
                        //merge folder contents

                        //newfile.folderlist[existindex].size1 += folder.size1;

                        //newfile.folderlist[existindex].folfiles.AddRange(folfiles.ToList());
                        newfile.filelist[existindex] = file;
                        folder.size1 -= 1;
                    }
                    else
                    {
                        newfile.filelist.Add(file);
                    }
                }
            }
            //Console.WriteLine("past for " + "files " + allfiles.Length + " folders " + allfolders.Length + " rootfolder " + rootfolder.path);


            new FileInfo(outputdir).Directory.Create();
            System.IO.File.WriteAllBytes(outputdir, newfile.ToArray());
            Console.WriteLine("saved to " + outputdir);
            using (FileStream outstream = new FileStream(newfile.binaryfiledir, FileMode.Create))
            {
                using (BinaryWriter outfile = new BinaryWriter(outstream))
                {
                    foreach (filemetadata file in newfile.filelist)
                    {
                        outfile.Write(file.fdata);
                        outfile.Flush();
                    }
                }
            }
        }
Exemplo n.º 4
0
        public static void buildfiles(string @inputdir, string @outputdir, string binfile)
        {
            string workingdir = Directory.GetCurrentDirectory();

            string pathname = new DirectoryInfo(inputdir).Name;

            int filepos = 0;

            //workingdir = Path.Combine(workingdir, inputdir);

            filearc newfile = new filearc();

            newfile.binaryfiledir = binfile;

            filemetadata rootfolder = new filemetadata();

            rootfolder.size1 = Directory.GetFiles(inputdir).Length;
            rootfolder.path  = inputdir;

            //newfile.folderlist.Add(rootfolder);

            Console.WriteLine(inputdir + " in ");

            Directory.CreateDirectory(inputdir);

            string[] allfiles   = Directory.GetFiles(inputdir, "*.*", SearchOption.AllDirectories);
            string[] allfolders = Directory.GetDirectories(inputdir, "*.*", SearchOption.AllDirectories);

            for (int z = 0; z < allfolders.Length; z++)
            {
                //newfile.numfolders++;
            }

            //newfile.numfolders++;

            newfile.numfiles = allfiles.Length;

            for (int i = 0, j = 0; i < allfolders.Length; i++)
            {
                string folpathstr = allfolders[i].Substring(inputdir.IndexOf(pathname) + pathname.Length + 1, allfolders[i].Length - inputdir.IndexOf(pathname) - (pathname.Length + 1));
                if (i == 0)
                {
                    //j += rootfolder.size1;
                }

                Console.WriteLine(" fo " + allfolders[i]);

                filemetadata folder = new filemetadata();

                folder.path = folpathstr;

                folder.size1 = Directory.GetFiles(allfolders[i]).Length;

                Console.WriteLine(allfolders[i] + " len " + folder.size1);

                folder.size2 = j;

                Console.WriteLine(" fo " + allfolders[i]);

                if (folder.size1 > 0)
                {
                    newfile.folderlist.Add(folder);
                }

                j += folder.size1;

                Console.WriteLine("folder size " + folder.size1 + " folder size2 " + folder.size2 + " folder path " + folder.path + " what " + newfile.folderlist.Count);
            }

            int fpos = 0;

            foreach (filemetadata folder in newfile.folderlist)
            {
                folder.pos = fpos;

                Console.WriteLine("1");

                Console.WriteLine("should be  " + inputdir + " potentially also " + folder.path + " literaly me " + Path.Combine(inputdir, folder.path));

                string[] folfiles = Directory.GetFiles(Path.Combine(inputdir, folder.path));

                Console.WriteLine("2 len" + folfiles.Length);

                for (int i = 0; i < folfiles.Length; i++)
                {
                    //Console.WriteLine(i + " dir " + allfiles[i]);

                    filemetadata file = new filemetadata();

                    file.fdata = File.ReadAllBytes(folfiles[i]);

                    file.size1 = file.fdata.Length;
                    file.size2 = file.fdata.Length;

                    file.path = Path.GetFileName(folfiles[i]);

                    file.infolder = Path.GetDirectoryName(folfiles[i]);

                    file.pos = filepos;

                    //Console.WriteLine("file path " + file.path + " file folder " + file.infolder);

                    newfile.filelist.Add(file);

                    filepos += file.size1;

                    fpos += file.size1;
                }
            }

            newfile.numfolders = newfile.folderlist.Count;


            //Console.WriteLine("past for " + "files " + allfiles.Length + " folders " + allfolders.Length + " rootfolder " + rootfolder.path);


            new FileInfo(outputdir).Directory.Create();
            System.IO.File.WriteAllBytes(outputdir, newfile.ToArray());
            Console.WriteLine("saved to " + outputdir);
            using (FileStream outstream = new FileStream(newfile.binaryfiledir, FileMode.OpenOrCreate))
            {
                using (BinaryWriter outfile = new BinaryWriter(outstream))
                {
                    foreach (filemetadata file in newfile.filelist)
                    {
                        outfile.Write(file.fdata);
                        outfile.Flush();
                    }
                }
            }
        }