@isopodlabs/binary_libs 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +21 -0
- package/README.md +4 -1
- package/dist/CompoundDocument.d.ts +10 -10
- package/dist/CompoundDocument.js +45 -43
- package/dist/arch.js +2 -2
- package/dist/clr.d.ts +75 -54
- package/dist/clr.js +126 -114
- package/dist/cvinfo.d.ts +26 -0
- package/dist/cvinfo.js +930 -0
- package/dist/elf.d.ts +26 -20
- package/dist/elf.js +61 -61
- package/dist/mach.d.ts +176 -146
- package/dist/mach.js +101 -101
- package/dist/pe.d.ts +162 -132
- package/dist/pe.js +178 -172
- package/package.json +46 -43
- package/dist/CompoundDocument.js.map +0 -1
- package/dist/arch.js.map +0 -1
- package/dist/clr.js.map +0 -1
- package/dist/elf.js.map +0 -1
- package/dist/mach.js.map +0 -1
- package/dist/pe.js.map +0 -1
package/dist/clr.js
CHANGED
|
@@ -24,7 +24,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.CLR = void 0;
|
|
27
|
-
|
|
27
|
+
exports.ReadCLR = ReadCLR;
|
|
28
|
+
const bin = __importStar(require("@isopodlabs/binary"));
|
|
28
29
|
const pe = __importStar(require("./pe"));
|
|
29
30
|
//-----------------------------------------------------------------------------
|
|
30
31
|
// CLR
|
|
@@ -44,12 +45,12 @@ const CLR_FLAGS = {
|
|
|
44
45
|
FLAGS_TRACKDEBUGDATA: 0x00010000,
|
|
45
46
|
};
|
|
46
47
|
const CLR_HEADER = {
|
|
47
|
-
cb:
|
|
48
|
-
MajorRuntimeVersion:
|
|
49
|
-
MinorRuntimeVersion:
|
|
48
|
+
cb: bin.UINT32_LE,
|
|
49
|
+
MajorRuntimeVersion: bin.UINT16_LE,
|
|
50
|
+
MinorRuntimeVersion: bin.UINT16_LE,
|
|
50
51
|
MetaData: pe.DATA_DIRECTORY,
|
|
51
|
-
Flags:
|
|
52
|
-
EntryPoint:
|
|
52
|
+
Flags: bin.asFlags(bin.UINT32_LE, CLR_FLAGS),
|
|
53
|
+
EntryPoint: bin.UINT32_LE,
|
|
53
54
|
Resources: pe.DATA_DIRECTORY,
|
|
54
55
|
StrongNameSignature: pe.DATA_DIRECTORY,
|
|
55
56
|
CodeManagerTable: pe.DATA_DIRECTORY,
|
|
@@ -58,28 +59,28 @@ const CLR_HEADER = {
|
|
|
58
59
|
//ManagedNativeHeader: pe.DATA_DIRECTORY,
|
|
59
60
|
};
|
|
60
61
|
const STREAM_HDR = {
|
|
61
|
-
Offset:
|
|
62
|
-
Size:
|
|
63
|
-
Name:
|
|
64
|
-
unused:
|
|
62
|
+
Offset: bin.UINT32_LE, // Memory offset to start of this stream from start of the metadata root (§II.24.2.1)
|
|
63
|
+
Size: bin.UINT32_LE, // Size of this stream in bytes, shall be a multiple of 4.
|
|
64
|
+
Name: bin.NullTerminatedStringType(), // Name of the stream as null-terminated variable length array of ASCII characters, padded to the next 4-byte boundary with \0 characters. The name is limited to 32 characters.
|
|
65
|
+
unused: bin.AlignType(4),
|
|
65
66
|
};
|
|
66
67
|
const METADATA_ROOT = {
|
|
67
|
-
Signature:
|
|
68
|
-
MajorVersion:
|
|
69
|
-
MinorVersion:
|
|
70
|
-
Reserved:
|
|
71
|
-
Version:
|
|
72
|
-
unknown:
|
|
73
|
-
Streams:
|
|
68
|
+
Signature: bin.UINT32_LE, //'BSJB'
|
|
69
|
+
MajorVersion: bin.UINT16_LE,
|
|
70
|
+
MinorVersion: bin.UINT16_LE,
|
|
71
|
+
Reserved: bin.UINT32_LE, // always 0
|
|
72
|
+
Version: bin.StringType(bin.UINT32_LE, 'utf8', true),
|
|
73
|
+
unknown: bin.UINT16_LE,
|
|
74
|
+
Streams: bin.ArrayType(bin.UINT16_LE, STREAM_HDR)
|
|
74
75
|
};
|
|
75
76
|
const CLR_TABLES = {
|
|
76
|
-
Reserved:
|
|
77
|
-
MajorVersion:
|
|
78
|
-
MinorVersion:
|
|
79
|
-
HeapSizes:
|
|
80
|
-
Reserved2:
|
|
81
|
-
Valid:
|
|
82
|
-
Sorted:
|
|
77
|
+
Reserved: bin.UINT32_LE, // Reserved, always 0 (§II.24.1).
|
|
78
|
+
MajorVersion: bin.UINT8, // Major version of table schemata; shall be 2 (§II.24.1).
|
|
79
|
+
MinorVersion: bin.UINT8, // Minor version of table schemata; shall be 0 (§II.24.1).
|
|
80
|
+
HeapSizes: bin.UINT8, // Bit vector for heap sizes.
|
|
81
|
+
Reserved2: bin.UINT8, // Reserved, always 1 (§II.24.1).
|
|
82
|
+
Valid: bin.UINT64_LE, // Bit vector of present tables, let n be the number of bits that are 1.
|
|
83
|
+
Sorted: bin.UINT64_LE, // Bit vector of sorted tables.
|
|
83
84
|
};
|
|
84
85
|
var TABLE;
|
|
85
86
|
(function (TABLE) {
|
|
@@ -139,7 +140,7 @@ function bytesToGuid(bytes) {
|
|
|
139
140
|
hexArray.slice(8, 10).join('') + '-' +
|
|
140
141
|
hexArray.slice(10, 16).join('');
|
|
141
142
|
}
|
|
142
|
-
class clr_stream extends
|
|
143
|
+
class clr_stream extends bin.stream {
|
|
143
144
|
heaps;
|
|
144
145
|
heap_sizes;
|
|
145
146
|
table_counts;
|
|
@@ -150,7 +151,7 @@ class clr_stream extends binary.stream {
|
|
|
150
151
|
this.table_counts = table_counts;
|
|
151
152
|
}
|
|
152
153
|
getOffset(big) {
|
|
153
|
-
return (big ?
|
|
154
|
+
return (big ? bin.UINT32_LE : bin.UINT16_LE).get(this);
|
|
154
155
|
}
|
|
155
156
|
getHeap(heap) {
|
|
156
157
|
return this.heaps[heap].subarray(this.getOffset(!!(this.heap_sizes & (1 << heap))));
|
|
@@ -162,9 +163,9 @@ class clr_stream extends binary.stream {
|
|
|
162
163
|
const thresh = 0xffff >> B;
|
|
163
164
|
for (const i of trans) {
|
|
164
165
|
if (this.table_counts[i] > thresh)
|
|
165
|
-
return
|
|
166
|
+
return bin.UINT32_LE.get(this);
|
|
166
167
|
}
|
|
167
|
-
return
|
|
168
|
+
return bin.UINT16_LE.get(this);
|
|
168
169
|
}
|
|
169
170
|
getString() {
|
|
170
171
|
const mem = this.getHeap(HEAP.String);
|
|
@@ -178,7 +179,7 @@ class clr_stream extends binary.stream {
|
|
|
178
179
|
return this.getHeap(HEAP.Blob);
|
|
179
180
|
}
|
|
180
181
|
}
|
|
181
|
-
class clr_dummy extends
|
|
182
|
+
class clr_dummy extends bin.dummy {
|
|
182
183
|
heap_sizes;
|
|
183
184
|
table_counts;
|
|
184
185
|
constructor(heap_sizes, table_counts) {
|
|
@@ -187,7 +188,7 @@ class clr_dummy extends binary.dummy {
|
|
|
187
188
|
this.table_counts = table_counts;
|
|
188
189
|
}
|
|
189
190
|
getOffset(big) {
|
|
190
|
-
return (big ?
|
|
191
|
+
return (big ? bin.UINT32_LE : bin.UINT16_LE).get(this);
|
|
191
192
|
}
|
|
192
193
|
getHeap(heap) {
|
|
193
194
|
return this.getOffset(!!(this.heap_sizes & (1 << heap)));
|
|
@@ -199,9 +200,9 @@ class clr_dummy extends binary.dummy {
|
|
|
199
200
|
const thresh = 0xffff >> B;
|
|
200
201
|
for (const i of trans) {
|
|
201
202
|
if (this.table_counts[i] > thresh)
|
|
202
|
-
return
|
|
203
|
+
return bin.UINT32_LE.get(this);
|
|
203
204
|
}
|
|
204
|
-
return
|
|
205
|
+
return bin.UINT16_LE.get(this);
|
|
205
206
|
}
|
|
206
207
|
getString() { return this.getHeap(HEAP.String); }
|
|
207
208
|
getGUID() { return this.getHeap(HEAP.GUID); }
|
|
@@ -221,7 +222,7 @@ const clr_Blob = {
|
|
|
221
222
|
};
|
|
222
223
|
const Signature = clr_Blob;
|
|
223
224
|
const CustomAttributeValue = clr_Blob;
|
|
224
|
-
const clr_Code =
|
|
225
|
+
const clr_Code = bin.UINT32_LE;
|
|
225
226
|
function Indexed(table) {
|
|
226
227
|
return {
|
|
227
228
|
get(s) { return s.getIndex(table); }
|
|
@@ -255,7 +256,7 @@ const TypeOrMethodDef = CodedIndex([TABLE.TypeDef, TABLE.MethodDef], 1);
|
|
|
255
256
|
const ResolutionScope = CodedIndex([TABLE.Module, TABLE.ModuleRef, TABLE.AssemblyRef, TABLE.TypeRef], 2);
|
|
256
257
|
const TableReaders = {
|
|
257
258
|
[TABLE.Module]: {
|
|
258
|
-
generation:
|
|
259
|
+
generation: bin.UINT16_LE,
|
|
259
260
|
name: clr_String,
|
|
260
261
|
mvid: clr_GUID,
|
|
261
262
|
encid: clr_GUID,
|
|
@@ -267,7 +268,7 @@ const TableReaders = {
|
|
|
267
268
|
namespce: clr_String,
|
|
268
269
|
},
|
|
269
270
|
[TABLE.TypeDef]: {
|
|
270
|
-
flags:
|
|
271
|
+
flags: bin.UINT32_LE,
|
|
271
272
|
name: clr_String,
|
|
272
273
|
namespce: clr_String,
|
|
273
274
|
extends: TypeDefOrRef,
|
|
@@ -275,21 +276,21 @@ const TableReaders = {
|
|
|
275
276
|
methods: IndexedList(TABLE.MethodDef),
|
|
276
277
|
},
|
|
277
278
|
[TABLE.Field]: {
|
|
278
|
-
flags:
|
|
279
|
+
flags: bin.UINT16_LE,
|
|
279
280
|
name: clr_String,
|
|
280
281
|
signature: Signature,
|
|
281
282
|
},
|
|
282
283
|
[TABLE.MethodDef]: {
|
|
283
284
|
code: clr_Code,
|
|
284
|
-
implflags:
|
|
285
|
-
flags:
|
|
285
|
+
implflags: bin.UINT16_LE,
|
|
286
|
+
flags: bin.UINT16_LE,
|
|
286
287
|
name: clr_String,
|
|
287
288
|
signature: Signature,
|
|
288
289
|
paramlist: IndexedList(TABLE.Param),
|
|
289
290
|
},
|
|
290
291
|
[TABLE.Param]: {
|
|
291
|
-
flags:
|
|
292
|
-
sequence:
|
|
292
|
+
flags: bin.UINT16_LE,
|
|
293
|
+
sequence: bin.UINT16_LE,
|
|
293
294
|
name: clr_String,
|
|
294
295
|
},
|
|
295
296
|
[TABLE.InterfaceImpl]: {
|
|
@@ -302,7 +303,7 @@ const TableReaders = {
|
|
|
302
303
|
signature: Signature,
|
|
303
304
|
},
|
|
304
305
|
[TABLE.Constant]: {
|
|
305
|
-
type:
|
|
306
|
+
type: bin.UINT16_LE,
|
|
306
307
|
parent: HasConstant,
|
|
307
308
|
value: clr_Blob,
|
|
308
309
|
},
|
|
@@ -316,17 +317,17 @@ const TableReaders = {
|
|
|
316
317
|
native_type: clr_Blob,
|
|
317
318
|
},
|
|
318
319
|
[TABLE.DeclSecurity]: {
|
|
319
|
-
action:
|
|
320
|
+
action: bin.UINT16_LE,
|
|
320
321
|
parent: HasDeclSecurity,
|
|
321
322
|
permission_set: clr_Blob,
|
|
322
323
|
},
|
|
323
324
|
[TABLE.ClassLayout]: {
|
|
324
|
-
packing_size:
|
|
325
|
-
class_size:
|
|
325
|
+
packing_size: bin.UINT16_LE,
|
|
326
|
+
class_size: bin.UINT32_LE,
|
|
326
327
|
parent: Indexed(TABLE.TypeDef),
|
|
327
328
|
},
|
|
328
329
|
[TABLE.FieldLayout]: {
|
|
329
|
-
offset:
|
|
330
|
+
offset: bin.UINT32_LE,
|
|
330
331
|
field: Indexed(TABLE.Field),
|
|
331
332
|
},
|
|
332
333
|
[TABLE.StandAloneSig]: {
|
|
@@ -337,7 +338,7 @@ const TableReaders = {
|
|
|
337
338
|
event_list: IndexedList(TABLE.Event),
|
|
338
339
|
},
|
|
339
340
|
[TABLE.Event]: {
|
|
340
|
-
flags:
|
|
341
|
+
flags: bin.UINT16_LE,
|
|
341
342
|
name: clr_String,
|
|
342
343
|
event_type: TypeDefOrRef,
|
|
343
344
|
},
|
|
@@ -346,12 +347,12 @@ const TableReaders = {
|
|
|
346
347
|
property_list: IndexedList(TABLE.Property),
|
|
347
348
|
},
|
|
348
349
|
[TABLE.Property]: {
|
|
349
|
-
flags:
|
|
350
|
+
flags: bin.UINT16_LE,
|
|
350
351
|
name: clr_String,
|
|
351
352
|
type: Signature,
|
|
352
353
|
},
|
|
353
354
|
[TABLE.MethodSemantics]: {
|
|
354
|
-
flags:
|
|
355
|
+
flags: bin.UINT16_LE,
|
|
355
356
|
method: Indexed(TABLE.MethodDef),
|
|
356
357
|
association: HasSemantics,
|
|
357
358
|
},
|
|
@@ -367,70 +368,70 @@ const TableReaders = {
|
|
|
367
368
|
signature: clr_Blob,
|
|
368
369
|
},
|
|
369
370
|
[TABLE.ImplMap]: {
|
|
370
|
-
flags:
|
|
371
|
+
flags: bin.UINT16_LE,
|
|
371
372
|
member_forwarded: MemberForwarded,
|
|
372
373
|
name: clr_String,
|
|
373
374
|
scope: Indexed(TABLE.ModuleRef),
|
|
374
375
|
},
|
|
375
376
|
[TABLE.FieldRVA]: {
|
|
376
|
-
rva:
|
|
377
|
+
rva: bin.UINT32_LE,
|
|
377
378
|
field: Indexed(TABLE.Field),
|
|
378
379
|
},
|
|
379
380
|
[TABLE.Assembly]: {
|
|
380
|
-
hashalg:
|
|
381
|
-
major:
|
|
382
|
-
minor:
|
|
383
|
-
build:
|
|
384
|
-
rev:
|
|
385
|
-
flags:
|
|
381
|
+
hashalg: bin.UINT32_LE,
|
|
382
|
+
major: bin.UINT16_LE,
|
|
383
|
+
minor: bin.UINT16_LE,
|
|
384
|
+
build: bin.UINT16_LE,
|
|
385
|
+
rev: bin.UINT16_LE,
|
|
386
|
+
flags: bin.UINT32_LE,
|
|
386
387
|
publickey: clr_Blob,
|
|
387
388
|
name: clr_String,
|
|
388
389
|
culture: clr_String,
|
|
389
390
|
},
|
|
390
391
|
[TABLE.AssemblyProcessor]: {
|
|
391
|
-
processor:
|
|
392
|
+
processor: bin.UINT32_LE,
|
|
392
393
|
},
|
|
393
394
|
[TABLE.AssemblyOS]: {
|
|
394
|
-
platform:
|
|
395
|
-
minor:
|
|
396
|
-
major:
|
|
395
|
+
platform: bin.UINT32_LE,
|
|
396
|
+
minor: bin.UINT32_LE,
|
|
397
|
+
major: bin.UINT32_LE,
|
|
397
398
|
},
|
|
398
399
|
[TABLE.AssemblyRef]: {
|
|
399
|
-
major:
|
|
400
|
-
minor:
|
|
401
|
-
build:
|
|
402
|
-
rev:
|
|
403
|
-
flags:
|
|
400
|
+
major: bin.UINT16_LE,
|
|
401
|
+
minor: bin.UINT16_LE,
|
|
402
|
+
build: bin.UINT16_LE,
|
|
403
|
+
rev: bin.UINT16_LE,
|
|
404
|
+
flags: bin.UINT32_LE,
|
|
404
405
|
publickey: clr_Blob,
|
|
405
406
|
name: clr_String,
|
|
406
407
|
culture: clr_String,
|
|
407
408
|
hashvalue: clr_Blob,
|
|
408
409
|
},
|
|
409
410
|
[TABLE.AssemblyRefProcessor]: {
|
|
410
|
-
processor:
|
|
411
|
+
processor: bin.UINT32_LE,
|
|
411
412
|
assembly: Indexed(TABLE.AssemblyRef),
|
|
412
413
|
},
|
|
413
414
|
[TABLE.AssemblyRefOS]: {
|
|
414
|
-
platform:
|
|
415
|
-
major:
|
|
416
|
-
minor:
|
|
415
|
+
platform: bin.UINT32_LE,
|
|
416
|
+
major: bin.UINT32_LE,
|
|
417
|
+
minor: bin.UINT32_LE,
|
|
417
418
|
assembly: Indexed(TABLE.AssemblyRef),
|
|
418
419
|
},
|
|
419
420
|
[TABLE.File]: {
|
|
420
|
-
flags:
|
|
421
|
+
flags: bin.UINT32_LE,
|
|
421
422
|
name: clr_String,
|
|
422
423
|
hash: clr_Blob,
|
|
423
424
|
},
|
|
424
425
|
[TABLE.ExportedType]: {
|
|
425
|
-
flags:
|
|
426
|
-
typedef_id:
|
|
426
|
+
flags: bin.UINT32_LE,
|
|
427
|
+
typedef_id: bin.UINT32_LE, //(a 4-byte index into a TypeDef table of another module in this Assembly).
|
|
427
428
|
name: clr_String,
|
|
428
429
|
namespce: clr_String,
|
|
429
430
|
implementation: Implementation,
|
|
430
431
|
},
|
|
431
432
|
[TABLE.ManifestResource]: {
|
|
432
|
-
data:
|
|
433
|
-
flags:
|
|
433
|
+
data: bin.UINT32_LE,
|
|
434
|
+
flags: bin.UINT32_LE,
|
|
434
435
|
name: clr_String,
|
|
435
436
|
implementation: Implementation,
|
|
436
437
|
},
|
|
@@ -439,8 +440,8 @@ const TableReaders = {
|
|
|
439
440
|
enclosing_class: Indexed(TABLE.TypeDef),
|
|
440
441
|
},
|
|
441
442
|
[TABLE.GenericParam]: {
|
|
442
|
-
number:
|
|
443
|
-
flags:
|
|
443
|
+
number: bin.UINT16_LE,
|
|
444
|
+
flags: bin.UINT16_LE,
|
|
444
445
|
owner: TypeOrMethodDef,
|
|
445
446
|
name: clr_String,
|
|
446
447
|
},
|
|
@@ -454,20 +455,20 @@ const TableReaders = {
|
|
|
454
455
|
},
|
|
455
456
|
};
|
|
456
457
|
const ResourceManagerHeader = {
|
|
457
|
-
magic:
|
|
458
|
-
version:
|
|
459
|
-
skip:
|
|
458
|
+
magic: bin.UINT32_LE,
|
|
459
|
+
version: bin.UINT32_LE,
|
|
460
|
+
skip: bin.UINT32_LE,
|
|
460
461
|
};
|
|
461
462
|
const ResourceManager = {
|
|
462
|
-
reader:
|
|
463
|
-
set:
|
|
464
|
-
version:
|
|
465
|
-
num_resources:
|
|
466
|
-
types:
|
|
463
|
+
reader: bin.StringType(bin.UINT8), // Class name of IResourceReader to parse this file
|
|
464
|
+
set: bin.StringType(bin.UINT8), // Class name of ResourceSet to parse this file
|
|
465
|
+
version: bin.UINT32_LE,
|
|
466
|
+
num_resources: bin.UINT32_LE,
|
|
467
|
+
types: bin.ArrayType(bin.UINT32_LE, bin.StringType(bin.UINT8)),
|
|
467
468
|
};
|
|
468
469
|
const ResourceEntry = {
|
|
469
|
-
name:
|
|
470
|
-
offset:
|
|
470
|
+
name: bin.StringType(bin.UINT8, 'utf16le', false, 1),
|
|
471
|
+
offset: bin.UINT32_LE,
|
|
471
472
|
};
|
|
472
473
|
class CLR {
|
|
473
474
|
raw;
|
|
@@ -477,10 +478,10 @@ class CLR {
|
|
|
477
478
|
tables;
|
|
478
479
|
Resources;
|
|
479
480
|
constructor(pe, clr_data) {
|
|
480
|
-
this.header =
|
|
481
|
+
this.header = bin.read(new bin.stream(clr_data), CLR_HEADER);
|
|
481
482
|
const meta_data = pe.GetDataDir(this.header.MetaData);
|
|
482
|
-
const meta_root = meta_data &&
|
|
483
|
-
if (meta_root?.Signature !=
|
|
483
|
+
const meta_root = meta_data && bin.read(new bin.stream(meta_data.data), METADATA_ROOT);
|
|
484
|
+
if (meta_root?.Signature != bin.utils.stringCode('BSJB'))
|
|
484
485
|
throw new Error("Invalid CLR");
|
|
485
486
|
let table_data;
|
|
486
487
|
for (const h of meta_root.Streams) {
|
|
@@ -504,21 +505,21 @@ class CLR {
|
|
|
504
505
|
}
|
|
505
506
|
}
|
|
506
507
|
if (table_data) {
|
|
507
|
-
const stream = new
|
|
508
|
-
this.table_info =
|
|
508
|
+
const stream = new bin.stream(table_data);
|
|
509
|
+
this.table_info = bin.read(stream, CLR_TABLES);
|
|
509
510
|
const table_counts = [];
|
|
510
511
|
//read counts
|
|
511
|
-
for (let b = this.table_info.Valid; b; b =
|
|
512
|
-
const i =
|
|
513
|
-
table_counts[i] =
|
|
512
|
+
for (let b = this.table_info.Valid; b; b = bin.utils.clearLowest(b)) {
|
|
513
|
+
const i = bin.utils.lowestSetIndex(b);
|
|
514
|
+
table_counts[i] = bin.UINT32_LE.get(stream);
|
|
514
515
|
}
|
|
515
516
|
this.raw = stream.remainder();
|
|
516
517
|
const stream1 = new clr_dummy(this.table_info.HeapSizes, table_counts);
|
|
517
518
|
let offset = 0;
|
|
518
|
-
for (let b = this.table_info.Valid; b; b =
|
|
519
|
-
const i =
|
|
519
|
+
for (let b = this.table_info.Valid; b; b = bin.utils.clearLowest(b)) {
|
|
520
|
+
const i = bin.utils.lowestSetIndex(b);
|
|
520
521
|
stream1.seek(0);
|
|
521
|
-
|
|
522
|
+
bin.read(stream1, TableReaders[i]);
|
|
522
523
|
this.tables[i] = { offset, count: table_counts[i], size: stream1.tell() };
|
|
523
524
|
offset += this.tables[i].size * this.tables[i].count;
|
|
524
525
|
}
|
|
@@ -530,7 +531,7 @@ class CLR {
|
|
|
530
531
|
if (table) {
|
|
531
532
|
const stream2 = new clr_stream(this.raw, this.heaps, this.table_info.HeapSizes, Object.values(this.tables).map(i => i.count));
|
|
532
533
|
stream2.seek(table.offset + i * table.size);
|
|
533
|
-
return
|
|
534
|
+
return bin.read(stream2, TableReaders[t]);
|
|
534
535
|
}
|
|
535
536
|
}
|
|
536
537
|
getTable(t) {
|
|
@@ -540,7 +541,7 @@ class CLR {
|
|
|
540
541
|
stream2.seek(table.offset);
|
|
541
542
|
const result = [];
|
|
542
543
|
for (let i = 0; i < table.count; i++)
|
|
543
|
-
result.push(
|
|
544
|
+
result.push(bin.read(stream2, TableReaders[t]));
|
|
544
545
|
return result;
|
|
545
546
|
}
|
|
546
547
|
}
|
|
@@ -548,8 +549,8 @@ class CLR {
|
|
|
548
549
|
if (this.Resources) {
|
|
549
550
|
for (const i of this.getTable(TABLE.ManifestResource)) {
|
|
550
551
|
if (i.name == block) {
|
|
551
|
-
const data0 = new
|
|
552
|
-
const size =
|
|
552
|
+
const data0 = new bin.stream(this.Resources.subarray(i.data));
|
|
553
|
+
const size = bin.UINT32_LE.get(data0);
|
|
553
554
|
return getResources(data0.read_buffer(size));
|
|
554
555
|
}
|
|
555
556
|
}
|
|
@@ -562,8 +563,8 @@ class CLR {
|
|
|
562
563
|
if (this.Resources) {
|
|
563
564
|
const result = {};
|
|
564
565
|
for (const i of this.getTable(TABLE.ManifestResource)) {
|
|
565
|
-
const data0 = new
|
|
566
|
-
const size =
|
|
566
|
+
const data0 = new bin.stream(this.Resources.subarray(i.data));
|
|
567
|
+
const size = bin.UINT32_LE.get(data0);
|
|
567
568
|
const resources = getResources(data0.read_buffer(size));
|
|
568
569
|
if (resources)
|
|
569
570
|
Object.assign(result, resources);
|
|
@@ -574,15 +575,15 @@ class CLR {
|
|
|
574
575
|
}
|
|
575
576
|
exports.CLR = CLR;
|
|
576
577
|
function getResources(data) {
|
|
577
|
-
const stream = new
|
|
578
|
-
const manager0 =
|
|
578
|
+
const stream = new bin.stream(data);
|
|
579
|
+
const manager0 = bin.read(stream, ResourceManagerHeader);
|
|
579
580
|
if (manager0.magic == 0xBEEFCACE) {
|
|
580
|
-
const manager =
|
|
581
|
-
|
|
582
|
-
const
|
|
583
|
-
const
|
|
584
|
-
const start =
|
|
585
|
-
const entries =
|
|
581
|
+
const manager = bin.read_more(stream, ResourceManager, manager0);
|
|
582
|
+
bin.AlignType(8).get(stream);
|
|
583
|
+
const _hashes = bin.readn(stream, bin.UINT32_LE, manager.num_resources);
|
|
584
|
+
const _offsets = bin.readn(stream, bin.UINT32_LE, manager.num_resources);
|
|
585
|
+
const start = bin.UINT32_LE.get(stream);
|
|
586
|
+
const entries = bin.readn(stream, ResourceEntry, manager.num_resources);
|
|
586
587
|
const resources = {};
|
|
587
588
|
const decoder = new TextDecoder('utf-8');
|
|
588
589
|
for (let j = 0; j < manager.num_resources; j++) {
|
|
@@ -595,13 +596,24 @@ function getResources(data) {
|
|
|
595
596
|
}
|
|
596
597
|
}
|
|
597
598
|
// hook into PE reader
|
|
598
|
-
|
|
599
|
-
|
|
599
|
+
/*
|
|
600
|
+
pe.DIRECTORIES.CLR_DESCRIPTOR.read = (pe: pe.PE, data: binary.MappedMemory) => {
|
|
601
|
+
function fix_names(table: any[]) {
|
|
600
602
|
if ('name' in table[0])
|
|
601
603
|
return Object.fromEntries(table.map(i => [i.name, i]));
|
|
602
604
|
return table;
|
|
603
605
|
}
|
|
604
606
|
const clr = new CLR(pe, data.data);
|
|
605
|
-
return Object.fromEntries(Object.entries(clr.tables).map(([k, v]) => [TABLE[+k], fix_names(clr.getTable(+k))]));
|
|
607
|
+
return Object.fromEntries(Object.entries(clr.tables).map(([k, v]) => [TABLE[+k], fix_names(clr.getTable(+k)!)]));
|
|
606
608
|
};
|
|
609
|
+
*/
|
|
610
|
+
function ReadCLR(pe, data) {
|
|
611
|
+
function fix_names(table) {
|
|
612
|
+
if ('name' in table[0])
|
|
613
|
+
return Object.fromEntries(table.map(i => [i.name, i]));
|
|
614
|
+
return table;
|
|
615
|
+
}
|
|
616
|
+
const clr = new CLR(pe, data.data);
|
|
617
|
+
return Object.fromEntries(Object.entries(clr.tables).map(([k, _]) => [TABLE[+k], fix_names(clr.getTable(+k))]));
|
|
618
|
+
}
|
|
607
619
|
//# sourceMappingURL=clr.js.map
|
package/dist/cvinfo.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as binary from '@isopodlabs/binary';
|
|
2
|
+
declare const Decimal_base: (new (s: binary._stream) => {
|
|
3
|
+
reserved: number;
|
|
4
|
+
scale: number;
|
|
5
|
+
sign: number;
|
|
6
|
+
mhi: number;
|
|
7
|
+
mlo: bigint;
|
|
8
|
+
} & {
|
|
9
|
+
write(w: binary._stream): void;
|
|
10
|
+
}) & {
|
|
11
|
+
get: <X extends abstract new (...args: any) => any>(this: X, s: binary._stream) => InstanceType<X>;
|
|
12
|
+
put: (s: binary._stream, v: any) => void;
|
|
13
|
+
};
|
|
14
|
+
export declare class Decimal extends Decimal_base {
|
|
15
|
+
toNumber(): number;
|
|
16
|
+
}
|
|
17
|
+
export declare const CV_MMASK = 1792;
|
|
18
|
+
export declare const CV_TMASK = 240;
|
|
19
|
+
export declare const CV_SMASK = 15;
|
|
20
|
+
export declare const CV_MSHIFT = 8;
|
|
21
|
+
export declare const CV_TSHIFT = 4;
|
|
22
|
+
export declare const CV_SSHIFT = 0;
|
|
23
|
+
export declare function CV_MODE(typ: number): number;
|
|
24
|
+
export declare function CV_TYPE(typ: number): number;
|
|
25
|
+
export declare function CV_SUBT(typ: number): number;
|
|
26
|
+
export {};
|