1
1
///
2
- /// <reference path="JSProvider.d.ts" />
2
+ /// <reference path="../extra/ JSProvider.d.ts" />
3
3
///
4
4
"use strict" ;
5
5
@@ -28,7 +28,7 @@ const PAGE_EXECUTE_READWRITE = 0x40;
28
28
const PAGE_EXECUTE_WRITECOPY = 0x80 ;
29
29
const PAGE_GUARD = 0x100 ;
30
30
const PAGE_NOCACHE = 0x200 ;
31
- const PAGE_WRITECOMBINE = 0x400 ;
31
+ const PAGE_WRITECOMBINE = 0x400 ;
32
32
33
33
var PERMISSIONS = { } ;
34
34
PERMISSIONS [ PAGE_EXECUTE ] = "PAGE_EXECUTE" ;
@@ -64,46 +64,40 @@ VAD_TYPES[VadRotatePhysical] = "VadRotatePhysical";
64
64
VAD_TYPES [ VadLargePageSection ] = "VadLargePageSection" ;
65
65
66
66
67
- function SizeAsHumanReadableString ( size )
68
- {
67
+ function SizeAsHumanReadableString ( size ) {
69
68
let step = 1024 ;
70
- if ( Math . abs ( size ) < step )
69
+ if ( Math . abs ( size ) < step )
71
70
return `${ size } B` ;
72
71
73
- let units = [ 'kB' , 'MB' , 'GB' , 'TB' , 'PB' , 'EB' , 'ZB' , 'YB' ] ;
72
+ let units = [ 'kB' , 'MB' , 'GB' , 'TB' , 'PB' , 'EB' , 'ZB' , 'YB' ] ;
74
73
let u = - 1 ;
75
- do
76
- {
74
+ do {
77
75
size /= step ;
78
76
++ u ;
79
77
}
80
- while ( Math . abs ( size ) >= step && u < units . length - 1 ) ;
78
+ while ( Math . abs ( size ) >= step && u < units . length - 1 ) ;
81
79
return `${ size . toFixed ( 1 ) } ${ units [ u ] } ` ;
82
80
}
83
81
84
82
85
- function MakeQword ( hi , lo )
86
- {
83
+ function MakeQword ( hi , lo ) {
87
84
return hi . bitwiseShiftLeft ( 32 ) . add ( lo ) ;
88
85
}
89
86
90
87
91
- function AlignHexString ( value )
92
- {
88
+ function AlignHexString ( value ) {
93
89
return value . toString ( 16 ) . padStart ( 10 , "0" ) ;
94
90
}
95
91
96
92
97
93
/**
98
94
*
99
95
*/
100
- class Vad
101
- {
96
+ class Vad {
102
97
/**
103
98
*
104
99
*/
105
- constructor ( level , address , pMmProtectToValue )
106
- {
100
+ constructor ( level , address , pMmProtectToValue ) {
107
101
this . Level = level ;
108
102
this . Address = address ;
109
103
this . VadObject = host . createTypedObject ( this . Address , "nt" , "_MMVAD" ) ;
@@ -114,7 +108,7 @@ class Vad
114
108
//
115
109
this . __ProtectionIndex = this . VadObject . Core . u . VadFlags . Protection ;
116
110
this . __MmProtectToValue = pMmProtectToValue ;
117
- this . __Protection = u32 ( this . __MmProtectToValue . add ( 4 * this . __ProtectionIndex ) ) ;
111
+ this . __Protection = u32 ( this . __MmProtectToValue . add ( 4 * this . __ProtectionIndex ) ) ;
118
112
119
113
//
120
114
// The 3-bit is an index in VAD_TYPES (see MI_VAD_TYPES - https://www.nirsoft.net/kernel_struct/vista/MI_VAD_TYPE.html)
@@ -131,8 +125,7 @@ class Vad
131
125
/**
132
126
*
133
127
*/
134
- get Protection ( )
135
- {
128
+ get Protection ( ) {
136
129
var p = [ ] ;
137
130
if ( this . __Protection & PAGE_EXECUTE )
138
131
p . push ( PERMISSIONS [ this . __Protection & PAGE_EXECUTE ] ) ;
@@ -163,67 +156,59 @@ class Vad
163
156
/**
164
157
*
165
158
*/
166
- get VadType ( )
167
- {
159
+ get VadType ( ) {
168
160
return VAD_TYPES [ this . __VadType ] ;
169
161
}
170
162
171
163
172
164
/**
173
165
*
174
166
*/
175
- get Filename ( )
176
- {
177
- if ( this . __VadType == VadNone )
167
+ get Filename ( ) {
168
+ if ( this . __VadType == VadNone )
178
169
return "" ;
179
170
180
- try
181
- {
171
+ try {
182
172
let ControlArea = host . createTypedObject ( this . VadObject . Subsection . ControlArea . address , "nt" , "_CONTROL_AREA" ) ;
183
173
let FileObjectAddress = ControlArea . FilePointer . Value . bitwiseAnd ( - 16 ) ;
184
174
let FileObject = host . createTypedObject ( FileObjectAddress , "nt" , "_FILE_OBJECT" ) ;
185
- return host . memory . readWideString ( FileObject . FileName . Buffer . address , FileObject . FileName . Length / 2 ) ;
186
- }
187
- catch ( e )
188
- {
189
- return "" ;
190
- }
175
+ return host . memory . readWideString ( FileObject . FileName . Buffer . address , FileObject . FileName . Length / 2 ) ;
176
+ }
177
+ catch ( e ) {
178
+ return "" ;
179
+ }
191
180
}
192
181
193
182
/**
194
183
*
195
184
*/
196
- IsInRange ( address )
197
- {
185
+ IsInRange ( address ) {
198
186
return ( address . compareTo ( this . VaStart ) >= 0 && address . compareTo ( this . VaEnd ) < 0 ) ;
199
187
}
200
188
201
189
/**
202
190
*
203
191
*/
204
- toString ( )
205
- {
192
+ toString ( ) {
206
193
let txt = "VAD(" ;
207
194
txt += `Address=${ this . Address . toString ( 16 ) } , VpnStart=${ AlignHexString ( this . VpnStart ) } , VpnEnd=${ AlignHexString ( this . VpnEnd ) } `
208
- txt += `, Protection=${ this . Protection } , VadType=${ this . VadType } ` ;
209
- txt += `, Size=${ SizeAsHumanReadableString ( this . Size ) } ` ;
195
+ txt += `, Protection=${ this . Protection } , VadType=${ this . VadType } ` ;
196
+ txt += `, Size=${ SizeAsHumanReadableString ( this . Size ) } ` ;
210
197
211
- if ( this . Filename )
198
+ if ( this . Filename )
212
199
txt += `, Filename=${ this . Filename } ` ;
213
200
txt += ")" ;
214
201
return txt ;
215
202
}
216
203
}
217
204
218
205
219
- class VadList
220
- {
206
+ class VadList {
221
207
222
208
/**
223
209
*
224
210
*/
225
- constructor ( process )
226
- {
211
+ constructor ( process ) {
227
212
this . __process = process ;
228
213
this . __entries_by_level = new Array ( ) ;
229
214
this . __pMmProtectToValue = host . getModuleSymbolAddress ( "nt" , "MmProtectToValue" ) ;
@@ -233,12 +218,10 @@ class VadList
233
218
/**
234
219
* MaxLevel getter
235
220
*/
236
- get MaxLevel ( )
237
- {
238
- let MaxLevel = 0 ;
221
+ get MaxLevel ( ) {
222
+ let MaxLevel = 0 ;
239
223
240
- for ( let vad of this )
241
- {
224
+ for ( let vad of this ) {
242
225
if ( vad . Level > MaxLevel )
243
226
MaxLevel = vad . Level ;
244
227
}
@@ -250,25 +233,22 @@ class VadList
250
233
/**
251
234
* Average level getter
252
235
*/
253
- get AverageLevel ( )
254
- {
255
- return this . __entries_by_level . indexOf ( Math . max ( ...this . __entries_by_level ) ) ;
236
+ get AverageLevel ( ) {
237
+ return this . __entries_by_level . indexOf ( Math . max ( ...this . __entries_by_level ) ) ;
256
238
}
257
239
258
240
259
241
/**
260
242
* Process getter
261
243
*/
262
- get Process ( )
263
- {
244
+ get Process ( ) {
264
245
return this . __process ;
265
246
}
266
247
267
248
/**
268
249
* Help
269
250
*/
270
- get [ Symbol . metadataDescriptor ] ( )
271
- {
251
+ get [ Symbol . metadataDescriptor ] ( ) {
272
252
return {
273
253
Process :
274
254
{
@@ -279,16 +259,15 @@ class VadList
279
259
MaxLevel : {
280
260
PreferShow : true ,
281
261
Help : "The maximum level of recursion for the process's VADs."
282
- } ,
262
+ } ,
283
263
} ;
284
264
}
285
265
286
266
287
267
/**
288
268
*
289
269
*/
290
- * [ Symbol . iterator ] ( )
291
- {
270
+ * [ Symbol . iterator ] ( ) {
292
271
for ( let vad of this . __Walk ( 0 , this . __process . VadRoot . Root . address ) )
293
272
yield vad ;
294
273
}
@@ -297,11 +276,10 @@ class VadList
297
276
/**
298
277
*
299
278
*/
300
- * __Walk ( level , VadAddress )
301
- {
279
+ * __Walk ( level , VadAddress ) {
302
280
var nodeObject = host . createTypedObject ( VadAddress , "nt" , "_RTL_BALANCED_NODE" ) ;
303
281
304
- if ( nodeObject . isNull || nodeObject . Left == undefined || nodeObject . Right == undefined )
282
+ if ( nodeObject . isNull || nodeObject . Left == undefined || nodeObject . Right == undefined )
305
283
return ;
306
284
307
285
if ( this . __entries_by_level . length < level + 1 )
@@ -311,11 +289,11 @@ class VadList
311
289
312
290
yield new Vad ( level , VadAddress , this . __pMmProtectToValue ) ;
313
291
314
- if ( nodeObject . Left )
315
- yield * this . __Walk ( level + 1 , nodeObject . Left . address ) ;
292
+ if ( nodeObject . Left )
293
+ yield * this . __Walk ( level + 1 , nodeObject . Left . address ) ;
316
294
317
- if ( nodeObject . Right )
318
- yield * this . __Walk ( level + 1 , nodeObject . Right . address ) ;
295
+ if ( nodeObject . Right )
296
+ yield * this . __Walk ( level + 1 , nodeObject . Right . address ) ;
319
297
}
320
298
321
299
/**
@@ -324,30 +302,25 @@ class VadList
324
302
* @param {host.Int64 } virtualAddress An address to find in the process
325
303
* @returns {Vad } If the function finds the VAD, it returns a Vad object, else it returns null
326
304
*/
327
- LookupVad ( virtualAddress )
328
- {
305
+ LookupVad ( virtualAddress ) {
329
306
var currentLevel = 0 ;
330
307
var currentVadAddress = this . __process . VadRoot . Root . address ;
331
308
332
- while ( currentVadAddress . compareTo ( 0 ) != 0 )
333
- {
309
+ while ( currentVadAddress . compareTo ( 0 ) != 0 ) {
334
310
var currentVad = new Vad ( currentLevel , currentVadAddress , this . __pMmProtectToValue ) ;
335
311
336
- if ( currentVad . IsInRange ( virtualAddress ) )
337
- {
312
+ if ( currentVad . IsInRange ( virtualAddress ) ) {
338
313
return currentVad ;
339
314
}
340
315
341
316
currentLevel += 1 ;
342
317
343
318
var currentNodeObject = host . createTypedObject ( currentVadAddress , "nt" , "_RTL_BALANCED_NODE" ) ;
344
319
345
- if ( currentVad . VaStart . compareTo ( virtualAddress ) > 0 )
346
- {
320
+ if ( currentVad . VaStart . compareTo ( virtualAddress ) > 0 ) {
347
321
currentVadAddress = currentNodeObject . Left . address ;
348
- }
349
- else
350
- {
322
+ }
323
+ else {
351
324
currentVadAddress = currentNodeObject . Right . address ;
352
325
}
353
326
}
@@ -360,10 +333,8 @@ class VadList
360
333
/**
361
334
*
362
335
*/
363
- class ProcessVads
364
- {
365
- get Vads ( )
366
- {
336
+ class ProcessVads {
337
+ get Vads ( ) {
367
338
return new VadList ( this ) ;
368
339
}
369
340
}
@@ -372,12 +343,11 @@ class ProcessVads
372
343
/**
373
344
*
374
345
*/
375
- function initializeScript ( )
376
- {
346
+ function initializeScript ( ) {
377
347
//log("[+] Extending EPROCESS with Vads property...");
378
348
379
349
return [
380
350
new host . apiVersionSupport ( 1 , 3 ) ,
381
- new host . typeSignatureExtension ( ProcessVads , "_EPROCESS" ) ,
351
+ new host . typeSignatureExtension ( ProcessVads , "_EPROCESS" ) ,
382
352
] ;
383
353
}
0 commit comments