// TODO: Analyze this method and figure out if this can be done without attempting execution private static string SearchSafeDiscVersion(string file, byte[] fileContent) { Process exe; string version = ""; DateTime timestart; if (!EVORE.IsEXE(fileContent)) { return(""); } string tempexe = EVORE.MakeTempFile(fileContent); string[] DependentDlls = EVORE.CopyDependentDlls(file, fileContent); try { Directory.Delete(Path.Combine(Path.GetTempPath(), "~e*"), true); } catch { } try { File.Delete(Path.Combine(Path.GetTempPath(), "~e*")); } catch { } exe = EVORE.StartSafe(tempexe); if (exe == null) { return(""); } timestart = DateTime.Now; do { if (Directory.GetDirectories(Path.GetTempPath(), "~e*").Length > 0) { string[] files = Directory.GetFiles(Directory.GetDirectories(Path.GetTempPath(), "~e*")[0], "~de*.tmp"); if (files.Length > 0) { StreamReader sr; try { sr = new StreamReader(files[0], Encoding.Default); string FileContent = sr.ReadToEnd(); sr.Close(); int position = FileContent.IndexOf("%ld.%ld.%ld, %ld, %s,") - 1; if (position > -1) { version = FileContent.Substring(position + 28, 12); } break; } catch { } } } } while (!exe.HasExited && DateTime.Now.Subtract(timestart).TotalSeconds < 20); if (!exe.HasExited) { exe.Kill(); } exe.Close(); try { Directory.Delete(Path.Combine(Path.GetTempPath(), "~e*"), true); } catch { } try { File.Delete(Path.Combine(Path.GetTempPath(), "~e*")); File.Delete(tempexe); } catch { } if (DependentDlls != null) { for (int i = 0; i < DependentDlls.Length; i--) { try { File.Delete(DependentDlls[i]); } catch (Exception ex) { Console.WriteLine("!error while deleting file " + DependentDlls[i] + "; " + ex.Message); } } } return(version); }
// TODO: Analyze this method and figure out if this can be done without attempting execution private static string SearchProtectDiscVersion(string file, byte[] fileContent) { string version = ""; DateTime timestart; if (!EVORE.IsEXE(fileContent)) { return(""); } string tempexe = EVORE.MakeTempFile(fileContent); string[] DependentDlls = EVORE.CopyDependentDlls(file, fileContent); try { File.Delete(Path.Combine(Path.GetTempPath(), "a*.tmp")); } catch { } try { File.Delete(Path.Combine(Path.GetTempPath(), "PCD*.sys")); } catch { } if (Directory.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ProtectDisc"))) { try { File.Delete(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ProtectDisc", "p*.dll")); } catch { } } Process exe = EVORE.StartSafe(tempexe); if (exe == null) { return(""); } Process[] processes = new Process[0]; timestart = DateTime.Now; do { exe.Refresh(); string[] files = null; //check for ProtectDisc 8.2-x if (Directory.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ProtectDisc"))) { files = Directory.GetFiles(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ProtectDisc"), "p*.dll"); } if (files != null) { if (files.Length > 0) { FileVersionInfo fvinfo = FileVersionInfo.GetVersionInfo(files[0]); if (fvinfo.FileVersion != "") { version = fvinfo.FileVersion.Replace(" ", "").Replace(",", "."); //ProtectDisc 9 uses a ProtectDisc-Core dll version 8.0.x if (version.StartsWith("8.0")) { version = ""; } fvinfo = null; break; } } } //check for ProtectDisc 7.1-8.1 files = Directory.GetFiles(Path.GetTempPath(), "a*.tmp"); if (files.Length > 0) { FileVersionInfo fvinfo = FileVersionInfo.GetVersionInfo(files[0]); if (fvinfo.FileVersion != "") { version = fvinfo.FileVersion.Replace(" ", "").Replace(",", "."); fvinfo = null; break; } } if (exe.HasExited) { break; } processes = Process.GetProcessesByName(exe.ProcessName); if (processes.Length == 2) { processes[0].Refresh(); processes[1].Refresh(); if (processes[1].WorkingSet64 > exe.WorkingSet64) { exe = processes[1]; } else if (processes[0].WorkingSet64 > exe.WorkingSet64) //else if (processes[0].Modules.Count > exe.Modules.Count) { exe = processes[0]; } } } while (processes.Length > 0 && DateTime.Now.Subtract(timestart).TotalSeconds < 20); Thread.Sleep(500); if (!exe.HasExited) { processes = Process.GetProcessesByName(exe.ProcessName); if (processes.Length == 2) { try { processes[0].Kill(); } catch { } processes[0].Close(); try { processes[1].Kill(); } catch { } } else { exe.Refresh(); try { exe.Kill(); } catch { } } } exe.Close(); Thread.Sleep(500); if (Directory.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ProtectDisc"))) { try { File.Delete(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ProtectDisc", "p*.dll")); } catch { } } try { File.Delete(Path.Combine(Path.GetTempPath(), "a*.tmp")); } catch { } try { File.Delete(Path.Combine(Path.GetTempPath(), "PCD*.sys")); } catch { } File.Delete(tempexe); if (DependentDlls != null) { for (int i = 0; i < DependentDlls.Length; i++) { try { File.Delete(DependentDlls[i]); } catch (Exception ex) { Console.WriteLine("!error while deleting file " + DependentDlls[i] + "; " + ex.Message); } } } return(version); }