@@ -12,45 +12,69 @@ namespace ReClassNET.Forms
1212{
1313 public partial class ProcessInfoForm : IconForm
1414 {
15+ private readonly RemoteProcess process ;
1516 private readonly ClassNodeView classesView ;
1617
18+ /// <summary>The context menu of the sections grid view.</summary>
19+ public ContextMenuStrip GridContextMenu => sectionContextMenuStrip ;
20+
1721 public ProcessInfoForm ( RemoteProcess process , ClassNodeView classesView )
1822 {
1923 Contract . Requires ( process != null ) ;
2024 Contract . Requires ( classesView != null ) ;
2125
26+ this . process = process ;
2227 this . classesView = classesView ;
2328
2429 InitializeComponent ( ) ;
2530
31+ modulesDataGridView . AutoGenerateColumns = false ;
2632 sectionsDataGridView . AutoGenerateColumns = false ;
2733
2834 if ( process . IsValid )
2935 {
30- DataTable dt = new DataTable ( ) ;
31- dt . Columns . Add ( "address" , typeof ( string ) ) ;
32- dt . Columns . Add ( "address_val" , typeof ( IntPtr ) ) ;
33- dt . Columns . Add ( "size" , typeof ( ulong ) ) ;
34- dt . Columns . Add ( "name" , typeof ( string ) ) ;
35- dt . Columns . Add ( "protection" , typeof ( string ) ) ;
36- dt . Columns . Add ( "type" , typeof ( string ) ) ;
37- dt . Columns . Add ( "module" , typeof ( string ) ) ;
38-
39- process . NativeHelper . EnumerateRemoteSectionsAndModules ( process . Process . Handle , delegate ( IntPtr baseAddress , IntPtr regionSize , string name , NativeMethods . StateEnum state , NativeMethods . AllocationProtectEnum protection , NativeMethods . TypeEnum type , string modulePath )
40- {
41- var row = dt . NewRow ( ) ;
42- row [ "address" ] = baseAddress . ToString ( "X" ) ;
43- row [ "address_val" ] = baseAddress ;
44- row [ "size" ] = ( ulong ) regionSize . ToInt64 ( ) ;
45- row [ "name" ] = name ;
46- row [ "protection" ] = protection . ToString ( ) ;
47- row [ "type" ] = type . ToString ( ) ;
48- row [ "module" ] = Path . GetFileName ( modulePath ) ;
49- dt . Rows . Add ( row ) ;
50- } ,
51- null ) ;
52-
53- sectionsDataGridView . DataSource = dt ;
36+ var sections = new DataTable ( ) ;
37+ sections . Columns . Add ( "address" , typeof ( string ) ) ;
38+ sections . Columns . Add ( "size" , typeof ( ulong ) ) ;
39+ sections . Columns . Add ( "name" , typeof ( string ) ) ;
40+ sections . Columns . Add ( "protection" , typeof ( string ) ) ;
41+ sections . Columns . Add ( "type" , typeof ( string ) ) ;
42+ sections . Columns . Add ( "module" , typeof ( string ) ) ;
43+ sections . Columns . Add ( "section" , typeof ( Section ) ) ;
44+
45+ var modules = new DataTable ( ) ;
46+ modules . Columns . Add ( "address" , typeof ( string ) ) ;
47+ modules . Columns . Add ( "size" , typeof ( ulong ) ) ;
48+ modules . Columns . Add ( "path" , typeof ( string ) ) ;
49+ modules . Columns . Add ( "module" , typeof ( Module ) ) ;
50+
51+ process . NativeHelper . EnumerateRemoteSectionsAndModules (
52+ process . Process . Handle ,
53+ delegate ( Section section )
54+ {
55+ var row = sections . NewRow ( ) ;
56+ row [ "address" ] = section . Start . ToString ( "X" ) ;
57+ row [ "size" ] = ( ulong ) section . Size . ToInt64 ( ) ;
58+ row [ "name" ] = section . Name ;
59+ row [ "protection" ] = section . Protection . ToString ( ) ;
60+ row [ "type" ] = section . Type . ToString ( ) ;
61+ row [ "module" ] = section . ModuleName ;
62+ row [ "section" ] = section ;
63+ sections . Rows . Add ( row ) ;
64+ } ,
65+ delegate ( Module module )
66+ {
67+ var row = modules . NewRow ( ) ;
68+ row [ "address" ] = module . Start . ToString ( "X" ) ;
69+ row [ "size" ] = ( ulong ) module . Size . ToInt64 ( ) ;
70+ row [ "path" ] = module . Path ;
71+ row [ "module" ] = module ;
72+ modules . Rows . Add ( row ) ;
73+ }
74+ ) ;
75+
76+ sectionsDataGridView . DataSource = sections ;
77+ modulesDataGridView . DataSource = modules ;
5478 }
5579 }
5680
@@ -70,59 +94,143 @@ protected override void OnFormClosed(FormClosedEventArgs e)
7094
7195 #region Event Handler
7296
73- private void sectionsDataGridView_CellMouseDown ( object sender , DataGridViewCellMouseEventArgs e )
97+ private void SelectRow_CellMouseDown ( object sender , DataGridViewCellMouseEventArgs e )
7498 {
99+ var dgv = sender as DataGridView ;
100+ if ( dgv == null )
101+ {
102+ return ;
103+ }
104+
75105 if ( e . Button == MouseButtons . Right )
76106 {
77107 int row = e . RowIndex ;
78108 if ( e . RowIndex != - 1 )
79109 {
80- sectionsDataGridView . Rows [ row ] . Selected = true ;
110+ dgv . Rows [ row ] . Selected = true ;
81111 }
82112 }
83113 }
84114
85115 private void setCurrentClassAddressToolStripMenuItem_Click ( object sender , EventArgs e )
86116 {
87- var address = GetSelectedRegionAddress ( ) ;
88- if ( address != IntPtr . Zero )
117+ var classNode = classesView . SelectedClass ;
118+ if ( classNode == null )
89119 {
90- var node = classesView . SelectedClass ;
91- if ( node != null )
92- {
93- node . Address = address ;
94- }
120+ return ;
121+ }
122+
123+ IntPtr address ;
124+ if ( GetToolStripSourceControl ( sender ) == modulesDataGridView )
125+ {
126+ address = GetSelectedModule ( ) ? . Start ?? IntPtr . Zero ;
127+ }
128+ else
129+ {
130+ address = GetSelectedSection ( ) ? . Start ?? IntPtr . Zero ;
95131 }
132+
133+ classNode . Address = address ;
96134 }
97135
98136 private void createClassAtAddressToolStripMenuItem_Click ( object sender , EventArgs e )
99137 {
100- var address = GetSelectedRegionAddress ( ) ;
101- if ( address != IntPtr . Zero )
138+ var node = ClassNode . Create ( ) ;
139+ node . AddBytes ( 64 ) ;
140+
141+ if ( GetToolStripSourceControl ( sender ) == modulesDataGridView )
142+ {
143+ node . Address = GetSelectedModule ( ) ? . Start ?? IntPtr . Zero ;
144+ }
145+ else
146+ {
147+ node . Address = GetSelectedSection ( ) ? . Start ?? IntPtr . Zero ;
148+ }
149+
150+ classesView . SelectedClass = node ;
151+ }
152+
153+ private void dumpToolStripMenuItem_Click ( object sender , EventArgs e )
154+ {
155+ string fileName = string . Empty ;
156+ string initialDirectory = string . Empty ;
157+ IntPtr address ;
158+ IntPtr size ;
159+
160+ if ( GetToolStripSourceControl ( sender ) == modulesDataGridView )
102161 {
103- var node = ClassNode . Create ( ) ;
104- node . Address = address ;
105- node . AddBytes ( 64 ) ;
162+ var module = GetSelectedModule ( ) ;
163+ if ( module == null )
164+ {
165+ return ;
166+ }
167+
168+ fileName = $ "{ Path . GetFileNameWithoutExtension ( module . Name ) } _Dumped{ Path . GetExtension ( module . Name ) } ";
169+ initialDirectory = Path . GetDirectoryName ( module . Path ) ;
170+ address = module . Start ;
171+ size = module . Size ;
172+ }
173+ else
174+ {
175+ var section = GetSelectedSection ( ) ;
176+ if ( section == null )
177+ {
178+ return ;
179+ }
106180
107- classesView . SelectedClass = node ;
181+ fileName = $ "Section_{ section . Start . ToString ( "X" ) } _{ section . End . ToString ( "X" ) } .dat";
182+ address = section . Start ;
183+ size = section . Size ;
184+ }
185+
186+ using ( var sfd = new SaveFileDialog ( ) )
187+ {
188+ sfd . FileName = fileName ;
189+ sfd . InitialDirectory = initialDirectory ;
190+
191+ if ( sfd . ShowDialog ( ) == DialogResult . OK )
192+ {
193+ var data = process . ReadRemoteMemory ( address , size . ToInt32 ( ) ) ;
194+ using ( var bw = new BinaryWriter ( sfd . OpenFile ( ) ) )
195+ {
196+ bw . Write ( data ) ;
197+ }
198+ }
108199 }
109200 }
110201
111202 private void sectionsDataGridView_CellMouseDoubleClick ( object sender , DataGridViewCellMouseEventArgs e )
112203 {
113204 setCurrentClassAddressToolStripMenuItem_Click ( sender , e ) ;
205+
206+ Close ( ) ;
114207 }
115208
116209 #endregion
117210
118- private IntPtr GetSelectedRegionAddress ( )
211+ private Control GetToolStripSourceControl ( object sender )
212+ {
213+ return ( ( sender as ToolStripMenuItem ) ? . GetCurrentParent ( ) as ContextMenuStrip ) ? . SourceControl ;
214+ }
215+
216+ private Module GetSelectedModule ( )
217+ {
218+ var row = modulesDataGridView . SelectedRows . Cast < DataGridViewRow > ( ) . FirstOrDefault ( ) ? . DataBoundItem as DataRowView ;
219+ if ( row != null )
220+ {
221+ return row [ "module" ] as Module ;
222+ }
223+ return null ;
224+ }
225+
226+ private Section GetSelectedSection ( )
119227 {
120228 var row = sectionsDataGridView . SelectedRows . Cast < DataGridViewRow > ( ) . FirstOrDefault ( ) ? . DataBoundItem as DataRowView ;
121229 if ( row != null )
122230 {
123- return ( IntPtr ) row [ "address_val" ] ;
231+ return row [ "section" ] as Section ;
124232 }
125- return IntPtr . Zero ;
233+ return null ;
126234 }
127235 }
128236}
0 commit comments