static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); NtToken.EnableDebugPrivilege(); try { if (args.Length == 0) { Application.Run(new MainForm()); } else { if (args.Length < 3) { var handle = new SafeKernelObjectHandle(new IntPtr(int.Parse(args[0])), true); using (var section = NtSection.FromHandle(handle)) { bool read_only = args.Length > 1 ? args[1].Equals("--readonly") : !section.IsAccessGranted(SectionAccessRights.MapWrite); using (var map = read_only ? section.MapRead() : section.MapReadWrite()) { using (SectionEditorForm frm = new SectionEditorForm(map, GetName(section, map), read_only)) { Application.Run(frm); } } } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); NtToken.EnableDebugPrivilege(); try { if (args.Length == 0) { Application.Run(new MainForm()); } else { int handle = -1; string text = String.Empty; bool read_only = false; bool delete_file = false; string filename = string.Empty; OptionSet opts = new OptionSet() { { "handle=", "Specify an inherited handle to view.", v => handle = int.Parse(v) }, { "readonly", "Specify view section readonly", v => read_only = v != null }, { "file=", "Specify a file to view", v => filename = v }, { "delete", "Delete file after viewing", v => delete_file = v != null }, }; opts.Parse(args); if (handle > 0) { using (var section = NtSection.FromHandle(new SafeKernelObjectHandle(new IntPtr(handle), true))) { read_only = read_only || !section.IsAccessGranted(SectionAccessRights.MapWrite); using (var map = read_only ? section.MapRead() : section.MapReadWrite()) { using (SectionEditorForm frm = new SectionEditorForm(map, GetName(section, map), read_only)) { Application.Run(frm); } } } } else if (File.Exists(filename)) { try { using (var file = NtFile.Open(NtFileUtils.DosFileNameToNt(filename), null, FileAccessRights.ReadData, FileShareMode.Read | FileShareMode.Delete, FileOpenOptions.NonDirectoryFile)) { using (NtSection section = NtSection.CreateReadOnlyDataSection(file)) { using (var map = section.MapRead()) { using (SectionEditorForm frm = new SectionEditorForm(map, filename, true, file.Length)) { Application.Run(frm); } } } } } finally { if (delete_file) { File.Delete(filename); } } } else { throw new Exception("Invalid command line arguments"); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }