Exemple #1
0
        internal static long SkipExeHeader(ArcView file, byte[] signature)
        {
            var exe = new ExeFile(file);

            if (exe.ContainsSection(".rsrc"))
            {
                var offset = exe.FindString(exe.Sections[".rsrc"], signature);
                if (offset != -1 && 0 != file.View.ReadUInt32(offset + signature.Length))
                {
                    return(offset);
                }
            }
            var section = exe.Overlay;

            while (section.Offset < file.MaxOffset)
            {
                var offset = exe.FindString(section, signature, 0x10);
                if (-1 == offset)
                {
                    break;
                }
                if (0 != file.View.ReadUInt32(offset + signature.Length))
                {
                    return(offset);
                }
                section.Offset = offset + 0x10;
                section.Size   = (uint)(file.MaxOffset - section.Offset);
            }
            return(0);
        }
Exemple #2
0
        static readonly uint DefaultKey = 0xAC52AE58; // 0x24B70413

        public override ArcFile TryOpen(ArcView file)
        {
            uint signature     = file.View.ReadUInt32(0);
            bool is_inside_exe = false;
            long base_offset   = 0;
            uint arc_key       = 0;

            if (0x5A4D == (signature & 0xFFFF)) // 'MZ'
            {
                var exe = new ExeFile(file);
                if (exe.Overlay.Size <= 4 || !file.View.AsciiEqual(exe.Overlay.Offset, "DPMX"))
                {
                    return(null);
                }
                base_offset   = exe.Overlay.Offset;
                arc_key       = FindExeKey(exe, base_offset);
                is_inside_exe = true;
            }
            else if (0x584D5044 != signature)
            {
                return(null);
            }
            int count = file.View.ReadInt32(base_offset + 8);

            if (!IsSaneCount(count))
            {
                return(null);
            }
            long index_offset = base_offset + 0x10 + file.View.ReadUInt32(base_offset + 0xC);
            uint data_size    = (uint)(file.MaxOffset - (index_offset + 32 * count));

            base_offset += file.View.ReadUInt32(base_offset + 4);
            var dir = new List <Entry> (count);

            for (int i = 0; i < count; ++i)
            {
                var name = file.View.ReadString(index_offset, 0x10);
                index_offset += 0x14;
                var entry = Create <DpmEntry> (name);
                entry.Key    = file.View.ReadUInt32(index_offset);
                entry.Offset = file.View.ReadUInt32(index_offset + 4) + base_offset;
                entry.Size   = file.View.ReadUInt32(index_offset + 8);
                if (!entry.CheckPlacement(file.MaxOffset))
                {
                    return(null);
                }
                dir.Add(entry);
                index_offset += 0xC;
            }
            if (is_inside_exe)
            {
                return(new DpmArchive(file, this, dir, arc_key, data_size));
            }
            else
            {
                return(new DpmArchive(file, this, dir));
            }
        }
Exemple #3
0
        internal long FindYser(ArcView file)
        {
            var exe    = new ExeFile(file);
            var offset = exe.FindAsciiString(exe.Overlay, "YSER", 0x10);

            if (-1 == offset)
            {
                return(0);
            }
            uint header_size = file.View.ReadUInt32(offset + 4);

            return(offset + header_size);
        }
Exemple #4
0
        BinScheme FindScheme(ArcView bin_file)
        {
            var bin_name = Path.GetFileName(bin_file.Name).ToUpperInvariant();

            foreach (var game in KnownSchemes.Values)
            {
                BinScheme scheme;
                if (game.TryGetValue(bin_name, out scheme) && bin_file.MaxOffset == scheme.Size)
                {
                    return(scheme);
                }
            }
            if (bin_file.MaxOffset >= uint.MaxValue)
            {
                return(null);
            }
            var bin_dir   = VFS.GetDirectoryName(bin_file.Name);
            var game_dir  = Directory.GetParent(bin_dir).FullName;
            var exe_files = VFS.GetFiles(VFS.CombinePath(game_dir, "*.exe"));

            if (!exe_files.Any())
            {
                return(null);
            }
            var last_idx = new byte[12];

            LittleEndian.Pack((uint)bin_file.MaxOffset, last_idx, 0);
            LittleEndian.Pack((uint)bin_file.MaxOffset, last_idx, 4);
            foreach (var exe_entry in exe_files)
            {
                using (var exe_file = VFS.OpenView(exe_entry))
                {
                    var exe = new ExeFile(exe_file);
                    if (!exe.ContainsSection(".data"))
                    {
                        continue;
                    }
                    var data_section = exe.Sections[".data"];
                    var idx_pos      = exe.FindString(data_section, last_idx, 4);
                    if (idx_pos > 0)
                    {
                        return(ParseIndexTable(exe_file, data_section, idx_pos, bin_name));
                    }
                }
            }
            return(null);
        }
Exemple #5
0
        static uint FindExeKey(ExeFile exe, long dpm_offset)
        {
            if (!exe.ContainsSection(".rdata"))
            {
                return(DefaultKey);
            }
            uint base_offset  = (uint)(dpm_offset - 0x10000);
            var  offset_str   = base_offset.ToString() + '\0';
            var  offset_bytes = Encoding.ASCII.GetBytes(offset_str);
            var  key_pos      = exe.FindString(exe.Sections[".rdata"], offset_bytes);

            if (-1 == key_pos)
            {
                return(DefaultKey);
            }
            return(exe.View.ReadUInt32(key_pos + 0x17));
        }
Exemple #6
0
        private void LoadExe(string path)
        {
            if (!Directory.Exists(path))
            {
                return;
            }
            var d     = new DirectoryInfo(path);
            var files = new ExeFiles();

            files.Name = d.FullName;
            foreach (var each in d.GetFiles().Where(p => !p.Attributes.HasFlag(FileAttributes.Hidden) &&
                                                    allowsExeExtensions.Contains(Path.GetExtension(p.FullName).ToLower())))
            {
                var file = new ExeFile();
                file.FileName = Path.GetFileNameWithoutExtension(each.Name);
                file.Path     = each.FullName;
                files.Add(file);
            }

            this.ExeFiles.Add(files);
        }
Exemple #7
0
        public List <Assembly> LoadNamedAssemblies(string AsmName, ref string Bindir)
        {
            string          Name        = null;
            Assembly        asm         = null;
            List <Assembly> Assemblies  = new List <Assembly>();
            var             AsmFiles    = Directory.GetFiles(Bindir, "*.dll", SearchOption.AllDirectories);
            var             AsmExeFiles = Directory.GetFiles(Bindir, "*.exe", SearchOption.AllDirectories);

            if (AsmName != null)
            {
                foreach (string dll in AsmFiles)
                {
                    Name = dll.Substring(dll.LastIndexOf(@"\"), dll.Length - dll.LastIndexOf(@"\")).Replace(@"\", "").Replace(".dll", "");
                    if (AsmName == Name)
                    {
                        asm = null;
                        asm = Assembly.LoadFrom(dll);
                        Assemblies.Add(asm);
                        break;
                    }
                }

                if (AsmExeFiles.Count() > 0)
                {
                    foreach (string ExeFile in AsmExeFiles)
                    {
                        Name = ExeFile.Substring(ExeFile.LastIndexOf(@"\"), ExeFile.Length - ExeFile.LastIndexOf(@"\")).Replace(@"\", "").Replace(".exe", "");
                        if (Name == AsmName)
                        {
                            asm = null;
                            asm = Assembly.LoadFile(ExeFile);
                            Assemblies.Add(asm);
                            break;
                        }
                    }
                }
            }

            return(Assemblies);
        }
        private NamedPipeClientStream StartHostService()
        {
            var isWindows = true;

#if NETCOREAPP
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                isWindows = false;
            }
#endif
            string folder      = Path.GetDirectoryName(ExeFile);
            string exeFullPath = ExeFile;
            if (folder.IsNullOrEmpty())
            {
                if (isWindows)
                {
                    folder      = Path.GetDirectoryName(Assembly.GetAssembly(typeof(T)).Location).Replace("\\lib\\", "\\bin\\");
                    exeFullPath = Path.Combine(folder, ExeFile);
                }
                else
                {
                    folder      = Path.GetDirectoryName(Assembly.GetAssembly(typeof(T)).Location).Replace("/lib/", "/bin/");
                    Arguments   = string.Concat(Path.Combine(folder, ExeFile.Replace(".exe", ".dll")), " ", Arguments);
                    exeFullPath = "dotnet";
                }
            }

            if (!File.Exists(exeFullPath) && isWindows ||
                !isWindows && string.IsNullOrEmpty(Arguments))
            {
                throw new Exception($"Process path not found: {exeFullPath}");
            }

            // start the host process
            ProcessStartInfo psi = new ProcessStartInfo()
            {
                UseShellExecute  = true,
                FileName         = exeFullPath,
                WorkingDirectory = folder,
                Arguments        = Arguments,
                WindowStyle      = Visible ? ProcessWindowStyle.Normal : ProcessWindowStyle.Hidden
            };
            Process process = Process.Start(psi);

            // wait for service to become available
            bool ServiceReady()
            {
                pipeClient =
                    new NamedPipeClientStream(".", process.Id.ToString(), PipeDirection.InOut,
                                              PipeOptions.Asynchronous);

                pipeClient.Connect();
                if (pipeClient.IsConnected)
                {
                    return(true);
                }
                return(false);
            }

            Retry(ServiceReady, StartTimeout, RetryInterval);
            return(pipeClient);
        }
Exemple #9
0
        uint SkipExeData(ArcView file)
        {
            var exe = new ExeFile(file);

            return((uint)exe.Overlay.Offset);
        }
Exemple #10
0
        private static void Main(string[] args)
        {
            ConfigureLogging();

            string flatFilename    = null;
            string structuredOut   = null;
            string disassemblyFile = null;

            var options = new OptionSet
            {
                { "f|flat=", "Dump flat output to file", _ => flatFilename = _ },
                { "o|out=", "Dump structured output to file", _ => structuredOut = _ },
                { "d|disassembly=", "Disassemble associated .exe when available to file", _ => disassemblyFile = _ }
            };

            IList <string> extraArgs;

            try
            {
                extraArgs = options.Parse(args);
            }
            catch (OptionException e)
            {
                logger.Error(e.Message);
                options.WriteOptionDescriptions(Console.Out);
                Console.WriteLine("Note that '-' is a valid filename, resulting in outputting to the console");
                return;
            }

            if (extraArgs.Count != 1)
            {
                logger.Error("Please provide a .SYM file for processing");
                options.WriteOptionDescriptions(Console.Out);
                Console.WriteLine("Note that '-' is a valid filename, resulting in outputting to the console");
                return;
            }

            if (flatFilename != null)
            {
                logger.Info($"Dumping {extraArgs[0]} to {flatFilename} in flat format");
                using (var fs = new FileStream(extraArgs[0], FileMode.Open))
                {
                    // ReSharper disable once ObjectCreationAsStatement
                    new SymFile(new BinaryReader(fs), flatFilename);
                }
            }

            if (structuredOut == null && disassemblyFile == null)
            {
                return;
            }

            SymFile symFile;

            using (var fs = new FileStream(extraArgs[0], FileMode.Open))
            {
                symFile = new SymFile(new BinaryReader(fs), null);
                if (structuredOut != null)
                {
                    logger.Info($"Dumping {extraArgs[0]} to {structuredOut} in structured format");
                    using (var outFs = structuredOut == "-" ? Console.Out : File.CreateText(structuredOut))
                    {
                        symFile.Dump(outFs);
                    }
                }
            }

            if (disassemblyFile == null)
            {
                return;
            }

            var exeFilename = Path.ChangeExtension(extraArgs[0], "EXE");

            if (!File.Exists(exeFilename))
            {
                logger.Warn($"EXE file {exeFilename} does not exist, skipping disassembly");
                return;
            }

            logger.Info($"Dumping {exeFilename} disassembly to {disassemblyFile}");
            using (var fs = new EndianBinaryReader(new FileStream(exeFilename, FileMode.Open)))
            {
                var exeFile = new ExeFile(fs, symFile);
                exeFile.Disassemble();
                using (var outFs = disassemblyFile == "-" ? Console.Out : File.CreateText(disassemblyFile))
                    using (var writer = new IndentedTextWriter(outFs))
                    {
                        exeFile.Dump(writer);
                    }
            }
        }
Exemple #11
0
        void ChanagePanel(int index)
        {
            switch (Index)
            {
                case 0:
                    pnl1.BackColor = Color.FromArgb(28, 28, 28);
                    lbl1.BackColor = Color.FromArgb(28, 28, 28);
                    break;
                case 1:
                    pnl2.BackColor = Color.FromArgb(28, 28, 28);
                    lbl2.BackColor = Color.FromArgb(28, 28, 28);
                    break;
                case 2:
                    pnl3.BackColor = Color.FromArgb(28, 28, 28);
                    lbl3.BackColor = Color.FromArgb(28, 28, 28);
                    break;
                case 3:
                    pnl4.BackColor = Color.FromArgb(28, 28, 28);
                    lbl4.BackColor = Color.FromArgb(28, 28, 28);
                    break;
                case 4:
                    pnl5.BackColor = Color.FromArgb(28, 28, 28);
                    lbl5.BackColor = Color.FromArgb(28, 28, 28);
                    break;
                case 5:
                    pnl6.BackColor = Color.FromArgb(28, 28, 28);
                    lbl6.BackColor = Color.FromArgb(28, 28, 28);
                    break;
                case 6:
                    pnl7.BackColor = Color.FromArgb(28, 28, 28);
                    lbl7.BackColor = Color.FromArgb(28, 28, 28);
                    break;
                case 7:
                    pnl8.BackColor = Color.FromArgb(28, 28, 28);
                    lbl8.BackColor = Color.FromArgb(28, 28, 28);
                    break;
                case 8:
                    pnl9.BackColor = Color.FromArgb(28, 28, 28);
                    lbl9.BackColor = Color.FromArgb(28, 28, 28);
                    break;
                case 9:
                    pnl0.BackColor = Color.FromArgb(28, 28, 28);
                    lbl0.BackColor = Color.FromArgb(28, 28, 28);
                    break;
            }

            switch (index)
            {
                case 0:
                    pnl1.BackColor = Color.Maroon;
                    lbl1.BackColor = Color.Maroon;
                    break;
                case 1:
                    pnl2.BackColor = Color.Maroon;
                    lbl2.BackColor = Color.Maroon;
                    break;
                case 2:
                    pnl3.BackColor = Color.Maroon;
                    lbl3.BackColor = Color.Maroon;
                    break;
                case 3:
                    pnl4.BackColor = Color.Maroon;
                    lbl4.BackColor = Color.Maroon;
                    break;
                case 4:
                    pnl5.BackColor = Color.Maroon;
                    lbl5.BackColor = Color.Maroon;
                    break;
                case 5:
                    pnl6.BackColor = Color.Maroon;
                    lbl6.BackColor = Color.Maroon;
                    break;
                case 6:
                    pnl7.BackColor = Color.Maroon;
                    lbl7.BackColor = Color.Maroon;
                    break;
                case 7:
                    pnl8.BackColor = Color.Maroon;
                    lbl8.BackColor = Color.Maroon;
                    break;
                case 8:
                    pnl9.BackColor = Color.Maroon;
                    lbl9.BackColor = Color.Maroon;
                    break;
                case 9:
                    pnl0.BackColor = Color.Maroon;
                    lbl0.BackColor = Color.Maroon;
                    break;
            }

            for (int i = 0; i < 10; i++)
            {
                if (i == Index)
                {
                    ((XmlElement)xnRoot.ChildNodes[i]).SetAttribute("current", "false");
                }
                if (i == index)
                {
                    xeCurrent = (XmlElement)xnRoot.ChildNodes[i];
                    xeCurrent.SetAttribute("current", "true");

                    RemoveKey(picQ);
                    RemoveKey(picW);
                    RemoveKey(picE);
                    RemoveKey(picR);
                    RemoveKey(picT);
                    RemoveKey(picY);
                    RemoveKey(picU);
                    RemoveKey(picI);
                    RemoveKey(picO);
                    RemoveKey(picP);
                    RemoveKey(picA);
                    RemoveKey(picS);
                    RemoveKey(picD);
                    RemoveKey(picF);
                    RemoveKey(picG);
                    RemoveKey(picH);
                    RemoveKey(picJ);
                    RemoveKey(picK);
                    RemoveKey(picL);
                    RemoveKey(picSemicolon);
                    RemoveKey(picZ);
                    RemoveKey(picX);
                    RemoveKey(picC);
                    RemoveKey(picV);
                    RemoveKey(picB);
                    RemoveKey(picN);
                    RemoveKey(picM);
                    RemoveKey(picComma);
                    RemoveKey(picPeriod);
                    RemoveKey(picQuestion);

                    foreach (XmlElement xe in xeCurrent.ChildNodes)
                    {
                        ExeFile exeFile;

                        try
                        {
                            exeFile = new ExeFile()
                            {
                                Path = xe.GetAttribute("path"),
                                Icon = new Bitmap(new MemoryStream(HexStringToByteArray(xe.GetAttribute("icon"))))
                            };
                        }
                        catch
                        {
                            continue;
                        }


                        switch (xe.GetAttribute("name"))
                        {
                            case "Q":
                                AddKey(picQ, exeFile);
                                break;
                            case "W":
                                AddKey(picW, exeFile);
                                break;
                            case "E":
                                AddKey(picE, exeFile);
                                break;
                            case "R":
                                AddKey(picR, exeFile);
                                break;
                            case "T":
                                AddKey(picT, exeFile);
                                break;
                            case "Y":
                                AddKey(picY, exeFile);
                                break;
                            case "U":
                                AddKey(picU, exeFile);
                                break;
                            case "I":
                                AddKey(picI, exeFile);
                                break;
                            case "O":
                                AddKey(picO, exeFile);
                                break;
                            case "P":
                                AddKey(picP, exeFile);
                                break;
                            case "A":
                                AddKey(picA, exeFile);
                                break;
                            case "S":
                                AddKey(picS, exeFile);
                                break;
                            case "D":
                                AddKey(picD, exeFile);
                                break;
                            case "F":
                                AddKey(picF, exeFile);
                                break;
                            case "G":
                                AddKey(picG, exeFile);
                                break;
                            case "H":
                                AddKey(picH, exeFile);
                                break;
                            case "J":
                                AddKey(picJ, exeFile);
                                break;
                            case "K":
                                AddKey(picK, exeFile);
                                break;
                            case "L":
                                AddKey(picL, exeFile);
                                break;
                            case "Semicolon":
                                AddKey(picSemicolon, exeFile);
                                break;
                            case "Z":
                                AddKey(picZ, exeFile);
                                break;
                            case "X":
                                AddKey(picX, exeFile);
                                break;
                            case "C":
                                AddKey(picC, exeFile);
                                break;
                            case "V":
                                AddKey(picV, exeFile);
                                break;
                            case "B":
                                AddKey(picB, exeFile);
                                break;
                            case "N":
                                AddKey(picN, exeFile);
                                break;
                            case "M":
                                AddKey(picM, exeFile);
                                break;
                            case "Comma":
                                AddKey(picComma, exeFile);
                                break;
                            case "Period":
                                AddKey(picPeriod, exeFile);
                                break;
                            case "Question":
                                AddKey(picQuestion, exeFile);
                                break;
                        }
                    }

                }
            }

            Index = index;

            BeginInvoke(new SaveSetting(xdSetting.Save), "configure.xml");
        }
Exemple #12
0
 bool AddKey(PictureBox pic, ExeFile exeFile)
 {
     try
     {
         pic.Tag = exeFile.Path;
         pic.BackgroundImage = exeFile.Icon;
         pic.MouseClick += pictureBox_MouseClick;
         pic.MouseDown += pictureBox_MouseDown;
         return true;
     }
     catch
     {
         RemoveKey(pic);
         return false;
     }
 }
Exemple #13
0
        void pictureBox_DragDrop(object sender, DragEventArgs e)
        {
            PictureBox pic = (PictureBox)sender;

            string path = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(0).ToString();
            string icon = "";

            if (path.Substring(path.Length - 4, 4) == ".lnk")
            {
                IWshRuntimeLibrary.IWshShortcut shortcut = (IWshRuntimeLibrary.IWshShortcut)shell.CreateShortcut(path);
                path = shortcut.TargetPath;
                icon = shortcut.IconLocation.Split(',')[0];
            }

            ExeFile exeFile = new ExeFile
            {
                Path = path
            };

            try
            {
                if (((System.Array)e.Data.GetData(DataFormats.FileDrop)).Length == 1)
                {
                    if (icon != "")
                    {
                        exeFile.Icon = System.Drawing.Icon.ExtractAssociatedIcon(icon).ToBitmap();
                    }
                    else
                    {
                        exeFile.Icon = System.Drawing.Icon.ExtractAssociatedIcon(path).ToBitmap();
                    }
                }
                else
                {
                    exeFile.Icon = new Bitmap(new MemoryStream(HexStringToByteArray(((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(1).ToString())));
                }
            }
            catch
            {
                return;
            }

            if (pic.Tag != null)
            {
                RemoveKey(pic);

                foreach (XmlElement xe in xeCurrent.ChildNodes)
                {
                    if (xe.GetAttribute("name") == pic.Name.Substring(3))
                    {
                        xeCurrent.RemoveChild(xe);
                    }
                }
            }

            if (AddKey(pic, exeFile))
            {
                MemoryStream ms = new MemoryStream();
                exeFile.Icon.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                byte[] byteIcon = ms.GetBuffer();

                XmlElement xeKey = xdSetting.CreateElement("Key");
                xeKey.SetAttribute("name", pic.Name.Substring(3));
                xeKey.SetAttribute("path", exeFile.Path);
                xeKey.SetAttribute("icon", ByteArrayToHexString(byteIcon));
                xeCurrent.AppendChild(xeKey);
            }

            BeginInvoke(new SaveSetting(xdSetting.Save), "configure.xml");
        }