@@ -26,56 +26,6 @@ namespace TokenViewer
2626{
2727 public partial class MainForm : Form
2828 {
29- private class ProcessTokenEntry : IDisposable
30- {
31- public int ProcessId { get ; }
32- public string Name { get ; }
33- public string ImagePath { get ; }
34- public string CommandLine { get ; }
35- public NtToken ProcessToken { get ; }
36-
37- public ProcessTokenEntry ( int process_id , string name , string image_path , string command_line , NtToken process_token )
38- {
39- ProcessId = process_id ;
40- Name = name ;
41- ImagePath = image_path ;
42- CommandLine = command_line ;
43- ProcessToken = process_token . Duplicate ( ) ;
44- }
45-
46- public ProcessTokenEntry ( NtProcess process , NtToken process_token )
47- : this ( process . ProcessId , process . Name , process . Win32ImagePath , process . CommandLine , process_token )
48- {
49- }
50-
51- public virtual void Dispose ( )
52- {
53- ProcessToken ? . Dispose ( ) ;
54- }
55- }
56-
57- private class ThreadTokenEntry : ProcessTokenEntry
58- {
59- public string ThreadName { get ; }
60- public int ThreadId { get ; }
61- public NtToken ThreadToken { get ; }
62-
63- public ThreadTokenEntry ( NtProcess process , NtToken process_token ,
64- int thread_id , string thread_name , NtToken thread_token )
65- : base ( process , process_token )
66- {
67- ThreadName = thread_name ;
68- ThreadId = thread_id ;
69- ThreadToken = thread_token . Duplicate ( ) ;
70- }
71-
72- public override void Dispose ( )
73- {
74- ThreadToken ? . Dispose ( ) ;
75- base . Dispose ( ) ;
76- }
77- }
78-
7929 private static void ResizeColumns ( ListView view )
8030 {
8131 view . AutoResizeColumns ( ColumnHeaderAutoResizeStyle . ColumnContent ) ;
@@ -109,6 +59,7 @@ private IEnumerable<ListViewItem> CreateThreads(NtProcess entry, NtToken process
10959 {
11060 return ret ;
11161 }
62+
11263 using ( var threads = new DisposableList < NtThread > ( query_process . Result . GetThreads ( ThreadAccessRights . QueryLimitedInformation ) ) )
11364 {
11465 foreach ( NtThread thread in threads )
@@ -122,7 +73,7 @@ private IEnumerable<ListViewItem> CreateThreads(NtProcess entry, NtToken process
12273 item . SubItems . Add ( thread . ThreadId . ToString ( ) ) ;
12374 item . SubItems . Add ( token . User . ToString ( ) ) ;
12475 item . SubItems . Add ( token . ImpersonationLevel . ToString ( ) ) ;
125- item . Tag = new ThreadTokenEntry ( query_process . Result , token , thread . ThreadId , thread . Description , token ) ;
76+ item . Tag = new ThreadTokenEntry ( query_process . Result , process_token , thread . ThreadId , thread . Description , token ) ;
12677 ret . Add ( item ) ;
12778 }
12879 }
@@ -302,7 +253,7 @@ private void openTokenToolStripMenuItem_Click(object sender, EventArgs e)
302253 {
303254 if ( item . Tag is ProcessTokenEntry process )
304255 {
305- TokenForm . OpenForm ( process . ProcessToken , $ "{ item . SubItems [ 1 ] . Text } :{ item . SubItems [ 0 ] . Text } ", true ) ;
256+ TokenForm . OpenForm ( process , $ "{ item . SubItems [ 1 ] . Text } :{ item . SubItems [ 0 ] . Text } ", true , false ) ;
306257 }
307258 }
308259 }
@@ -431,7 +382,7 @@ private void btnCurrentProcess_Click(object sender, EventArgs e)
431382 {
432383 try
433384 {
434- TokenForm . OpenForm ( NtToken . OpenProcessToken ( ) , "Current" , false ) ;
385+ TokenForm . OpenForm ( new ProcessTokenEntry ( NtProcess . Current ) , "Current" , false , false ) ;
435386 }
436387 catch ( NtException ex )
437388 {
@@ -469,7 +420,7 @@ private void toolStripMenuItemOpenThreadToken_Click(object sender, EventArgs e)
469420 {
470421 if ( thread . ThreadToken != null )
471422 {
472- TokenForm . OpenForm ( thread . ThreadToken , $ "{ thread . Name } :{ thread . ProcessId } .{ thread . ThreadId } ", true ) ;
423+ TokenForm . OpenForm ( thread , $ "{ thread . Name } :{ thread . ProcessId } .{ thread . ThreadId } ", true , true ) ;
473424 }
474425 }
475426 }
@@ -483,7 +434,7 @@ private void openProcessTokenToolStripMenuItem_Click(object sender, EventArgs e)
483434 {
484435 if ( thread . ProcessToken != null )
485436 {
486- TokenForm . OpenForm ( thread . ProcessToken , $ "{ thread . Name } :{ thread . ProcessId } ", true ) ;
437+ TokenForm . OpenForm ( ( ProcessTokenEntry ) thread , $ "{ thread . Name } :{ thread . ProcessId } ", true , false ) ;
487438 }
488439 }
489440 }
0 commit comments