2
2
using BrightIdeasSoftware ;
3
3
using Microsoft . Win32 . SafeHandles ;
4
4
using System ;
5
- using System . Diagnostics ;
6
5
using System . Collections . Generic ;
6
+ using System . Diagnostics ;
7
7
using System . Drawing ;
8
8
using System . IO ;
9
9
using System . Runtime . InteropServices ;
@@ -22,28 +22,24 @@ public MainForm()
22
22
{
23
23
InitializeComponent ( ) ;
24
24
25
- // Add placeholder text to filters textbox.
25
+ // Add placeholder text to filters textbox
26
26
SendMessage ( tbFilters . Handle , EM_SETCUEBANNER , 0 , "Filters (e.g. 9C412000 br=64 !ec=C000000D)" ) ;
27
27
28
- // Setup HexBoxes.
28
+ // Setup HexBoxes
29
29
InitializeHexBox ( hbInput , ( int ) nudInputSize . Value ) ;
30
30
InitializeHexBox ( hbOutput , ( int ) nudOutputSize . Value ) ;
31
31
32
- // Setup TreeListView.
32
+ // Setup TreeListView
33
33
InitializeTreeListView ( ) ;
34
34
35
- // Setup initial parameters.
35
+ // Setup initial parameters
36
36
tbDevicePath . Text = @"\\.\PhysicalDrive0" ;
37
37
tbIOCTL . Text = "70000" ;
38
38
tbAccessMask . Text = "20000000" ;
39
39
cmbACL . SelectedItem = "ANY_ACCESS" ;
40
40
}
41
41
42
- /// <summary>
43
- /// Initialize the given buffer view.
44
- /// </summary>
45
- /// <param name="hexBox"></param>
46
- /// <param name="size"></param>
42
+ // Initialize the given buffer view
47
43
private void InitializeHexBox ( HexBox hexBox , int size )
48
44
{
49
45
hexBox . Visible = true ;
@@ -60,37 +56,35 @@ private void InitializeHexBox(HexBox hexBox, int size)
60
56
hexBox . ByteProvider = new DynamicByteProvider ( new byte [ size ] ) ;
61
57
}
62
58
63
- /// <summary>
64
- /// Initialize the Request History views.
65
- /// </summary>
59
+ // Initialize the Request History views
66
60
private void InitializeTreeListView ( )
67
61
{
68
- // Add colours to request rows.
62
+ // Add colours to request rows
69
63
tlvRequestHistory . FormatRow += ( sender , eventArgs ) =>
70
64
{
71
65
Request transmission = ( Request ) eventArgs . Model ;
72
66
if ( transmission . IsFavourite )
73
- eventArgs . Item . BackColor = System . Drawing . Color . LightYellow ;
67
+ eventArgs . Item . BackColor = Color . LightYellow ;
74
68
else if ( transmission . ReturnValue > 0 )
75
- eventArgs . Item . BackColor = System . Drawing . Color . MistyRose ;
69
+ eventArgs . Item . BackColor = Color . MistyRose ;
76
70
} ;
77
71
78
- // Rename requests when double-clicked or F2 is pressed.
72
+ // Rename requests when double-clicked or F2 is pressed
79
73
tlvRequestHistory . CellEditActivation = BrightIdeasSoftware . ObjectListView . CellEditActivateMode . DoubleClick ;
80
74
81
- // How to identify if a row has children.
75
+ // How to identify if a row has children
82
76
tlvRequestHistory . CanExpandGetter = delegate ( Object tx )
83
77
{
84
78
return ( ( Request ) tx ) . Children . Count > 0 ;
85
79
} ;
86
80
87
- // Where row children are located.
81
+ // Where row children are located
88
82
tlvRequestHistory . ChildrenGetter = delegate ( Object tx )
89
83
{
90
84
return ( ( Request ) tx ) . Children ;
91
85
} ;
92
86
93
- // Populate HexBoxes when the selection changes.
87
+ // Populate HexBoxes when the selection changes
94
88
tlvRequestHistory . SelectionChanged += ( sender , eventArgs ) =>
95
89
{
96
90
if ( tlvRequestHistory . SelectedIndex == - 1 ) return ;
@@ -110,11 +104,7 @@ private void InitializeTreeListView()
110
104
} ;
111
105
}
112
106
113
- /// <summary>
114
- /// Validate provided device path.
115
- /// </summary>
116
- /// <param name="sender"></param>
117
- /// <param name="e"></param>
107
+ // Validate provided DeviceName
118
108
private void tbDevicePath_TextChanged ( object sender , EventArgs e )
119
109
{
120
110
Guid guid ;
@@ -142,11 +132,7 @@ private void tbDevicePath_TextChanged(object sender, EventArgs e)
142
132
tbDevicePath . BackColor = Color . MistyRose ;
143
133
}
144
134
145
- /// <summary>
146
- /// Validate that provided IOCTL is legitimate.
147
- /// </summary>
148
- /// <param name="sender"></param>
149
- /// <param name="e"></param>
135
+ // Validate that provided IOCTL is legitimate
150
136
private void tbIOCTL_TextChanged ( object sender , EventArgs e )
151
137
{
152
138
Point toolTipCoords = tbIOCTL . Location ;
@@ -169,12 +155,15 @@ private void tbIOCTL_TextChanged(object sender, EventArgs e)
169
155
170
156
private void btnSend_Click ( object sender , EventArgs e )
171
157
{
172
- uint fa_mask = Convert . ToUInt32 ( "20000000" , 16 ) ;
173
- if ( tbAccessMask . Enabled == true ) {
158
+ uint fa_mask = Convert . ToUInt32 ( "20000000" , 16 ) ;
159
+ // if Access mask is enabled use that value
160
+ if ( tbAccessMask . Enabled == true )
161
+ {
174
162
fa_mask = Convert . ToUInt32 ( tbAccessMask . Text , 16 ) ;
175
163
}
176
164
else
177
165
{
166
+ // otherwise gather the human readable ACL
178
167
switch ( cmbACL . SelectedItem )
179
168
{
180
169
case "ANY_ACCESS" :
@@ -189,13 +178,14 @@ private void btnSend_Click(object sender, EventArgs e)
189
178
case "WRITE_DATA" :
190
179
fa_mask = Convert . ToUInt32 ( FileAccess . Write ) ;
191
180
break ;
192
- default :
181
+ default :
193
182
fa_mask = 0 ;
194
183
break ;
195
184
196
185
}
197
186
}
198
- Debug . WriteLine ( "\n Access Mask: " + fa_mask ) ;
187
+ Debug . WriteLine ( "\n Access Mask: " + fa_mask ) ;
188
+
199
189
SafeFileHandle sfh = CreateFile (
200
190
tbDevicePath . Text . Trim ( ) ,
201
191
dwDesiredAccess : ( FileAccess ) fa_mask ,
@@ -217,10 +207,12 @@ private void btnSend_Click(object sender, EventArgs e)
217
207
218
208
if ( sfh . IsInvalid )
219
209
{
210
+ // invalid DeviceName
220
211
errorCode = Marshal . GetLastWin32Error ( ) ;
221
212
}
222
213
else
223
214
{
215
+ // create buffer with specified content in memory
224
216
long hbInputLength = ( ( DynamicByteProvider ) hbInput . ByteProvider ) . Length ;
225
217
MemSet ( Marshal . UnsafeAddrOfPinnedArrayElement ( inputBuffer , 0 ) , 0 , ( int ) hbInputLength ) ;
226
218
@@ -232,18 +224,19 @@ private void btnSend_Click(object sender, EventArgs e)
232
224
233
225
long hbOutputLength = ( ( DynamicByteProvider ) hbOutput . ByteProvider ) . Length ;
234
226
MemSet ( Marshal . UnsafeAddrOfPinnedArrayElement ( outputBuffer , 0 ) , 0 , ( int ) hbOutputLength ) ;
227
+ // execute DeviceIoControl request
235
228
DeviceIoControl ( sfh , ioctl , inputBuffer , inputSize , outputBuffer , outputSize , ref returnedBytes , IntPtr . Zero ) ;
236
-
229
+ // gather error code
237
230
errorCode = Marshal . GetLastWin32Error ( ) ;
238
231
sfh . Close ( ) ;
239
-
232
+ // update Input/Output views
240
233
DynamicByteProvider requestData = new DynamicByteProvider ( inputBuffer ) ;
241
234
hbInput . ByteProvider = requestData ;
242
235
243
236
DynamicByteProvider responseData = new DynamicByteProvider ( outputBuffer ) ;
244
237
hbOutput . ByteProvider = responseData ;
245
238
}
246
-
239
+ // update request view
247
240
Request newTx = new Request ( ) ;
248
241
newTx . RequestName = String . Format (
249
242
"0x{0:X} ({1:X4}-{2:D5})" ,
@@ -283,11 +276,7 @@ private void btnSend_Click(object sender, EventArgs e)
283
276
return ;
284
277
}
285
278
286
- /// <summary>
287
- /// Mark the selected request as a favourite.
288
- /// </summary>
289
- /// <param name="sender"></param>
290
- /// <param name="e"></param>
279
+ // Mark the selected request as a favourite
291
280
private void btnStarRequest_Click ( object sender , EventArgs e )
292
281
{
293
282
if ( tlvRequestHistory . SelectedIndex == - 1 ) return ;
@@ -300,11 +289,7 @@ private void btnOpenDB_Click(object sender, EventArgs e)
300
289
// ToDo
301
290
}
302
291
303
- /// <summary>
304
- /// Filters results in the Request History view (TODO).
305
- /// </summary>
306
- /// <param name="sender"></param>
307
- /// <param name="e"></param>
292
+ // Filters results in the Request History view (TODO)
308
293
private void tbFilters_TextChanged ( object sender , EventArgs e )
309
294
{
310
295
tlvRequestHistory . ModelFilter = null ;
@@ -314,11 +299,7 @@ private void tbFilters_TextChanged(object sender, EventArgs e)
314
299
} ) ;
315
300
}
316
301
317
- /// <summary>
318
- /// Shows the About window.
319
- /// </summary>
320
- /// <param name="sender"></param>
321
- /// <param name="e"></param>
302
+ // Shows the About window
322
303
private void btnAbout_Click ( object sender , EventArgs e )
323
304
{
324
305
if ( Application . OpenForms [ "AboutForm" ] as AboutForm == null )
@@ -333,6 +314,7 @@ private void btnAbout_Click(object sender, EventArgs e)
333
314
}
334
315
}
335
316
317
+ // parse and validate Access Mask
336
318
private void tbAccessMask_TextChanged ( object sender , EventArgs e )
337
319
{
338
320
Point toolTipCoords = tbAccessMask . Location ;
@@ -354,12 +336,14 @@ private void tbAccessMask_TextChanged(object sender, EventArgs e)
354
336
355
337
}
356
338
339
+ // update input panel when the InputSize is changed
357
340
private void nudInputSize_ValueChanged ( object sender , EventArgs e )
358
341
{
359
342
DynamicByteProvider dbpData = new DynamicByteProvider ( new byte [ ( int ) nudInputSize . Value ] ) ;
360
343
hbInput . ByteProvider = dbpData ;
361
344
}
362
345
346
+ // update output panel when the OutputSize is changed
363
347
private void nudOutputSize_ValueChanged ( object sender , EventArgs e )
364
348
{
365
349
DynamicByteProvider dbpData = new DynamicByteProvider ( new byte [ ( int ) nudOutputSize . Value ] ) ;
@@ -372,6 +356,7 @@ private void hbInput_ByteProviderChanged(object sender, EventArgs e)
372
356
//nudInputSize.Value = (int)dbpData;
373
357
}
374
358
359
+ // show the settings form
375
360
private void btnSettings_Click ( object sender , EventArgs e )
376
361
{
377
362
if ( Application . OpenForms [ "SettingsForm" ] as SettingsForm == null )
@@ -386,6 +371,7 @@ private void btnSettings_Click(object sender, EventArgs e)
386
371
}
387
372
}
388
373
374
+ // enable/disable access mask
389
375
private void chkEnableAccessMask_CheckedChanged ( object sender , EventArgs e )
390
376
{
391
377
if ( chkEnableAccessMask . Checked == true )
@@ -398,7 +384,7 @@ private void chkEnableAccessMask_CheckedChanged(object sender, EventArgs e)
398
384
tbAccessMask . Enabled = false ;
399
385
cmbACL . Enabled = true ;
400
386
}
401
-
387
+
402
388
}
403
389
}
404
390
}
0 commit comments