@isopodlabs/binary_libs 1.2.1 → 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/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/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 +133 -103
- package/dist/pe.js +99 -95
- package/package.json +4 -5
package/dist/pe.js
CHANGED
|
@@ -27,16 +27,17 @@ exports.DLLImports = exports.PE = exports.DATA_DIRECTORY = exports.DIRECTORIES =
|
|
|
27
27
|
exports.ReadExports = ReadExports;
|
|
28
28
|
exports.ReadImports = ReadImports;
|
|
29
29
|
exports.ReadResourceDirectory = ReadResourceDirectory;
|
|
30
|
-
const
|
|
30
|
+
const bin = __importStar(require("@isopodlabs/binary"));
|
|
31
|
+
const clr_1 = require("./clr");
|
|
31
32
|
class MyDate extends Date {
|
|
32
33
|
constructor(x) { super(x * 1000); }
|
|
33
34
|
valueOf() { return this.getTime() / 1000; }
|
|
34
35
|
toString() { return super.toString(); }
|
|
35
36
|
}
|
|
36
|
-
const uint16 =
|
|
37
|
-
const uint32 =
|
|
38
|
-
const uint64 =
|
|
39
|
-
const TIMEDATE =
|
|
37
|
+
const uint16 = bin.UINT16_LE;
|
|
38
|
+
const uint32 = bin.UINT32_LE;
|
|
39
|
+
const uint64 = bin.UINT64_LE;
|
|
40
|
+
const TIMEDATE = bin.as(uint32, MyDate);
|
|
40
41
|
//-----------------------------------------------------------------------------
|
|
41
42
|
// COFF
|
|
42
43
|
//-----------------------------------------------------------------------------
|
|
@@ -63,7 +64,7 @@ const MACHINES = {
|
|
|
63
64
|
THUMB: 0x1c2,
|
|
64
65
|
WCEMIPSV2: 0x169,
|
|
65
66
|
};
|
|
66
|
-
const MACHINE =
|
|
67
|
+
const MACHINE = bin.asEnum(uint16, MACHINES);
|
|
67
68
|
const FILE_HEADER = {
|
|
68
69
|
Machine: MACHINE,
|
|
69
70
|
NumberOfSections: uint16,
|
|
@@ -117,47 +118,47 @@ const SECTION_CHARACTERISTICS = {
|
|
|
117
118
|
MEM_READ: 0x40000000,
|
|
118
119
|
MEM_WRITE: 0x80000000,
|
|
119
120
|
};
|
|
120
|
-
class Section extends
|
|
121
|
-
Name:
|
|
121
|
+
class Section extends bin.ReadClass({
|
|
122
|
+
Name: bin.StringType(8),
|
|
122
123
|
VirtualSize: uint32,
|
|
123
|
-
VirtualAddress:
|
|
124
|
+
VirtualAddress: bin.asHex(uint32),
|
|
124
125
|
SizeOfRawData: uint32,
|
|
125
|
-
PointerToRawData:
|
|
126
|
-
PointerToRelocations:
|
|
127
|
-
PointerToLinenumbers:
|
|
128
|
-
NumberOfRelocations:
|
|
129
|
-
NumberOfLinenumbers:
|
|
130
|
-
Characteristics:
|
|
126
|
+
PointerToRawData: bin.asHex(uint32),
|
|
127
|
+
PointerToRelocations: bin.asHex(uint32),
|
|
128
|
+
PointerToLinenumbers: bin.asHex(uint32),
|
|
129
|
+
NumberOfRelocations: bin.INT16_LE,
|
|
130
|
+
NumberOfLinenumbers: bin.INT16_LE,
|
|
131
|
+
Characteristics: bin.asFlags(uint32, SECTION_CHARACTERISTICS)
|
|
131
132
|
}) {
|
|
132
133
|
data;
|
|
133
134
|
constructor(r) {
|
|
134
135
|
super(r);
|
|
135
136
|
try {
|
|
136
|
-
this.data = new
|
|
137
|
+
this.data = new bin.MappedMemory(r.buffer_at(+this.PointerToRawData, this.SizeOfRawData), BigInt(this.VirtualAddress.value), this.flags);
|
|
137
138
|
}
|
|
138
139
|
catch (e) {
|
|
139
140
|
console.log(e);
|
|
140
141
|
}
|
|
141
142
|
}
|
|
142
143
|
get flags() {
|
|
143
|
-
return
|
|
144
|
-
| (this.Characteristics.MEM_READ ?
|
|
145
|
-
| (this.Characteristics.MEM_WRITE ?
|
|
146
|
-
| (this.Characteristics.MEM_EXECUTE ?
|
|
144
|
+
return bin.MappedMemory.RELATIVE
|
|
145
|
+
| (this.Characteristics.MEM_READ ? bin.MappedMemory.READ : 0)
|
|
146
|
+
| (this.Characteristics.MEM_WRITE ? bin.MappedMemory.WRITE : 0)
|
|
147
|
+
| (this.Characteristics.MEM_EXECUTE ? bin.MappedMemory.EXECUTE : 0);
|
|
147
148
|
}
|
|
148
149
|
}
|
|
149
150
|
exports.Section = Section;
|
|
150
151
|
class COFF {
|
|
151
152
|
static check(data) {
|
|
152
|
-
const header =
|
|
153
|
+
const header = bin.read(new bin.stream(data), FILE_HEADER);
|
|
153
154
|
return MACHINES[header.Machine] !== undefined;
|
|
154
155
|
}
|
|
155
156
|
header;
|
|
156
157
|
opt;
|
|
157
158
|
sections;
|
|
158
159
|
constructor(data) {
|
|
159
|
-
const file = new
|
|
160
|
-
this.header =
|
|
160
|
+
const file = new bin.stream(data);
|
|
161
|
+
this.header = bin.read(file, FILE_HEADER);
|
|
161
162
|
if (this.header.SizeOfOptionalHeader) {
|
|
162
163
|
console.log("COFF: SizeOfOptionalHeader", this.header.SizeOfOptionalHeader);
|
|
163
164
|
}
|
|
@@ -179,45 +180,46 @@ const SYMBOL = {
|
|
|
179
180
|
Value: uint16,
|
|
180
181
|
//}
|
|
181
182
|
Type: uint16,
|
|
182
|
-
Symbol:
|
|
183
|
-
Module:
|
|
183
|
+
Symbol: bin.NullTerminatedStringType(),
|
|
184
|
+
Module: bin.NullTerminatedStringType(),
|
|
184
185
|
};
|
|
185
|
-
class COFFSymbol extends
|
|
186
|
+
class COFFSymbol extends bin.ReadClass(SYMBOL) {
|
|
186
187
|
static check(data) {
|
|
187
|
-
const test =
|
|
188
|
+
const test = bin.read(new bin.stream(data), SYMBOL);
|
|
188
189
|
return test.a === 0 && test.b === 0xffff && test.c === 0 && test.Architecture != 'UNKNOWN';
|
|
189
190
|
}
|
|
190
191
|
constructor(data) {
|
|
191
|
-
super(new
|
|
192
|
+
super(new bin.stream(data));
|
|
192
193
|
}
|
|
193
194
|
}
|
|
194
195
|
exports.COFFSymbol = COFFSymbol;
|
|
195
196
|
//-----------------------------------------------------------------------------
|
|
196
197
|
// PE
|
|
197
198
|
//-----------------------------------------------------------------------------
|
|
198
|
-
class pe_stream extends
|
|
199
|
+
class pe_stream extends bin.stream {
|
|
199
200
|
pe;
|
|
200
201
|
constructor(pe, data) {
|
|
201
202
|
super(data);
|
|
202
203
|
this.pe = pe;
|
|
203
204
|
}
|
|
205
|
+
translate_rva(addr) { return this.pe.GetDataRVA(addr); }
|
|
204
206
|
get_rva() { return this.pe.GetDataRVA(uint32.get(this))?.data; }
|
|
205
207
|
}
|
|
206
208
|
exports.pe_stream = pe_stream;
|
|
209
|
+
const RVA_BLOB = {
|
|
210
|
+
get(s) { return s.get_rva(); },
|
|
211
|
+
put(_s) { }
|
|
212
|
+
};
|
|
207
213
|
const RVA_STRING = {
|
|
208
|
-
get(s) { return
|
|
214
|
+
get(s) { return bin.utils.decodeTextTo0(s.get_rva(), 'utf8'); },
|
|
209
215
|
put(_s) { }
|
|
210
216
|
};
|
|
211
217
|
const RVA_ARRAY16 = {
|
|
212
|
-
get(s) { return
|
|
218
|
+
get(s) { return bin.utils.to16(s.get_rva()); },
|
|
213
219
|
put(_s) { }
|
|
214
220
|
};
|
|
215
221
|
const RVA_ARRAY32 = {
|
|
216
|
-
get(s) { return
|
|
217
|
-
put(_s) { }
|
|
218
|
-
};
|
|
219
|
-
const RVA_ARRAY64 = {
|
|
220
|
-
get(s) { return binary.utils.to64(s.get_rva()); },
|
|
222
|
+
get(s) { return bin.utils.to32(s.get_rva()); },
|
|
221
223
|
put(_s) { }
|
|
222
224
|
};
|
|
223
225
|
const DOS_HEADER = {
|
|
@@ -227,7 +229,7 @@ const DOS_HEADER = {
|
|
|
227
229
|
crlc: uint16,
|
|
228
230
|
cparhdr: uint16,
|
|
229
231
|
minalloc: uint16,
|
|
230
|
-
maxalloc:
|
|
232
|
+
maxalloc: bin.asHex(uint16),
|
|
231
233
|
ss: uint16,
|
|
232
234
|
sp: uint16,
|
|
233
235
|
csum: uint16,
|
|
@@ -237,28 +239,31 @@ const DOS_HEADER = {
|
|
|
237
239
|
ovno: uint16,
|
|
238
240
|
};
|
|
239
241
|
const EXE_HEADER = {
|
|
240
|
-
res:
|
|
242
|
+
res: bin.ArrayType(4, uint16),
|
|
241
243
|
oemid: uint16,
|
|
242
244
|
oeminfo: uint16,
|
|
243
|
-
res2:
|
|
244
|
-
lfanew:
|
|
245
|
+
res2: bin.ArrayType(10, uint16),
|
|
246
|
+
lfanew: bin.INT32_LE,
|
|
247
|
+
};
|
|
248
|
+
const NoInfo = {
|
|
249
|
+
read: (pe, data) => data
|
|
245
250
|
};
|
|
246
251
|
exports.DIRECTORIES = {
|
|
247
252
|
EXPORT: { read: (pe, data) => ReadExports(new pe_stream(pe, data.data)) },
|
|
248
253
|
IMPORT: { read: (pe, data) => ReadImports(new pe_stream(pe, data.data)) },
|
|
249
|
-
RESOURCE: { read: (pe, data) => ReadResourceDirectory(new
|
|
250
|
-
EXCEPTION:
|
|
251
|
-
SECURITY:
|
|
252
|
-
BASERELOC:
|
|
253
|
-
DEBUG_DIR:
|
|
254
|
-
ARCHITECTURE:
|
|
255
|
-
GLOBALPTR:
|
|
256
|
-
TLS:
|
|
257
|
-
LOAD_CONFIG:
|
|
258
|
-
BOUND_IMPORT:
|
|
259
|
-
IAT:
|
|
260
|
-
DELAY_IMPORT:
|
|
261
|
-
CLR_DESCRIPTOR: {},
|
|
254
|
+
RESOURCE: { read: (pe, data) => ReadResourceDirectory(new pe_stream(pe, data.data)) },
|
|
255
|
+
EXCEPTION: NoInfo, // Exception Directory
|
|
256
|
+
SECURITY: NoInfo, // Security Directory
|
|
257
|
+
BASERELOC: NoInfo, // Base Relocation Table
|
|
258
|
+
DEBUG_DIR: NoInfo, // Debug Directory
|
|
259
|
+
ARCHITECTURE: NoInfo, // Architecture Specific Data
|
|
260
|
+
GLOBALPTR: NoInfo, // RVA of GP
|
|
261
|
+
TLS: NoInfo,
|
|
262
|
+
LOAD_CONFIG: NoInfo, // Load Configuration Directory
|
|
263
|
+
BOUND_IMPORT: NoInfo, // Bound Import Directory in headers
|
|
264
|
+
IAT: NoInfo, // Import Address Table
|
|
265
|
+
DELAY_IMPORT: NoInfo,
|
|
266
|
+
CLR_DESCRIPTOR: { read: clr_1.ReadCLR },
|
|
262
267
|
};
|
|
263
268
|
exports.DATA_DIRECTORY = {
|
|
264
269
|
VirtualAddress: uint32,
|
|
@@ -284,18 +289,18 @@ const DLLCHARACTERISTICS = {
|
|
|
284
289
|
TERMINAL_SERVER_AWARE: 0x8000, // Terminal Server aware
|
|
285
290
|
};
|
|
286
291
|
const OPTIONAL_HEADER = {
|
|
287
|
-
Magic:
|
|
288
|
-
MajorLinkerVersion:
|
|
289
|
-
MinorLinkerVersion:
|
|
292
|
+
Magic: bin.asEnum(uint16, MAGIC),
|
|
293
|
+
MajorLinkerVersion: bin.UINT8,
|
|
294
|
+
MinorLinkerVersion: bin.UINT8,
|
|
290
295
|
SizeOfCode: uint32,
|
|
291
296
|
SizeOfInitializedData: uint32,
|
|
292
297
|
SizeOfUninitializedData: uint32,
|
|
293
|
-
AddressOfEntryPoint:
|
|
294
|
-
BaseOfCode:
|
|
298
|
+
AddressOfEntryPoint: bin.asHex(uint32),
|
|
299
|
+
BaseOfCode: bin.asHex(uint32),
|
|
295
300
|
};
|
|
296
301
|
const OPTIONAL_HEADER32 = {
|
|
297
|
-
BaseOfData:
|
|
298
|
-
ImageBase:
|
|
302
|
+
BaseOfData: bin.asHex(uint32),
|
|
303
|
+
ImageBase: bin.asHex(uint32),
|
|
299
304
|
SectionAlignment: uint32,
|
|
300
305
|
FileAlignment: uint32,
|
|
301
306
|
MajorOperatingSystemVersion: uint16,
|
|
@@ -309,16 +314,16 @@ const OPTIONAL_HEADER32 = {
|
|
|
309
314
|
SizeOfHeaders: uint32,
|
|
310
315
|
CheckSum: uint32,
|
|
311
316
|
Subsystem: uint16,
|
|
312
|
-
DllCharacteristics:
|
|
317
|
+
DllCharacteristics: bin.asFlags(uint16, DLLCHARACTERISTICS),
|
|
313
318
|
SizeOfStackReserve: uint32,
|
|
314
319
|
SizeOfStackCommit: uint32,
|
|
315
320
|
SizeOfHeapReserve: uint32,
|
|
316
321
|
SizeOfHeapCommit: uint32,
|
|
317
322
|
LoaderFlags: uint32,
|
|
318
|
-
DataDirectory:
|
|
323
|
+
DataDirectory: bin.objectWithNames(bin.ArrayType(uint32, exports.DATA_DIRECTORY), bin.names(Object.keys(exports.DIRECTORIES))),
|
|
319
324
|
};
|
|
320
325
|
const OPTIONAL_HEADER64 = {
|
|
321
|
-
ImageBase:
|
|
326
|
+
ImageBase: bin.asHex(uint64),
|
|
322
327
|
SectionAlignment: uint32,
|
|
323
328
|
FileAlignment: uint32,
|
|
324
329
|
MajorOperatingSystemVersion: uint16,
|
|
@@ -332,34 +337,34 @@ const OPTIONAL_HEADER64 = {
|
|
|
332
337
|
SizeOfHeaders: uint32,
|
|
333
338
|
CheckSum: uint32,
|
|
334
339
|
Subsystem: uint16,
|
|
335
|
-
DllCharacteristics:
|
|
340
|
+
DllCharacteristics: bin.asFlags(uint16, DLLCHARACTERISTICS),
|
|
336
341
|
SizeOfStackReserve: uint64,
|
|
337
342
|
SizeOfStackCommit: uint64,
|
|
338
343
|
SizeOfHeapReserve: uint64,
|
|
339
344
|
SizeOfHeapCommit: uint64,
|
|
340
345
|
LoaderFlags: uint32,
|
|
341
|
-
DataDirectory:
|
|
346
|
+
DataDirectory: bin.objectWithNames(bin.ArrayType(uint32, exports.DATA_DIRECTORY), bin.names(Object.keys(exports.DIRECTORIES))),
|
|
342
347
|
};
|
|
343
348
|
class PE {
|
|
344
349
|
static check(data) {
|
|
345
|
-
return uint16.get(new
|
|
350
|
+
return uint16.get(new bin.stream(data)) === bin.utils.stringCode("MZ");
|
|
346
351
|
}
|
|
347
352
|
header;
|
|
348
353
|
opt;
|
|
349
354
|
sections;
|
|
350
355
|
constructor(data) {
|
|
351
|
-
const file = new
|
|
352
|
-
this.header =
|
|
356
|
+
const file = new bin.stream(data);
|
|
357
|
+
this.header = bin.read(file, { ...DOS_HEADER, ...EXE_HEADER });
|
|
353
358
|
file.seek(this.header.lfanew);
|
|
354
|
-
if (uint32.get(file) ==
|
|
355
|
-
const h =
|
|
359
|
+
if (uint32.get(file) == bin.utils.stringCode("PE\0\0")) {
|
|
360
|
+
const h = bin.read(file, FILE_HEADER);
|
|
356
361
|
if (h.SizeOfOptionalHeader) {
|
|
357
|
-
const opt = new
|
|
358
|
-
const opt1 =
|
|
362
|
+
const opt = new bin.stream(file.read_buffer(h.SizeOfOptionalHeader));
|
|
363
|
+
const opt1 = bin.read(opt, OPTIONAL_HEADER);
|
|
359
364
|
if (opt1.Magic == 'NT32')
|
|
360
|
-
this.opt =
|
|
365
|
+
this.opt = bin.read_more(opt, OPTIONAL_HEADER32, opt1);
|
|
361
366
|
else if (opt1.Magic == 'NT64')
|
|
362
|
-
this.opt =
|
|
367
|
+
this.opt = bin.read_more(opt, OPTIONAL_HEADER64, opt1);
|
|
363
368
|
}
|
|
364
369
|
this.sections = Array.from({ length: h.NumberOfSections }, () => new Section(file));
|
|
365
370
|
}
|
|
@@ -385,7 +390,7 @@ class PE {
|
|
|
385
390
|
GetDataRVA(rva, size) {
|
|
386
391
|
const sect = this.FindSectionRVA(rva);
|
|
387
392
|
if (sect && sect.data)
|
|
388
|
-
return sect.data.at(rva, size);
|
|
393
|
+
return sect.data.at(BigInt(rva), size);
|
|
389
394
|
}
|
|
390
395
|
GetDataRaw(addr, size) {
|
|
391
396
|
const sect = this.FindSectionRaw(addr);
|
|
@@ -403,10 +408,11 @@ class PE {
|
|
|
403
408
|
if (dir?.Size) {
|
|
404
409
|
const data = this.GetDataDir(dir);
|
|
405
410
|
const info = exports.DIRECTORIES[name];
|
|
406
|
-
if (data && info
|
|
411
|
+
if (data && 'read' in info && info.read)
|
|
407
412
|
return info.read(this, data);
|
|
408
413
|
return data;
|
|
409
414
|
}
|
|
415
|
+
return undefined;
|
|
410
416
|
}
|
|
411
417
|
}
|
|
412
418
|
exports.PE = PE;
|
|
@@ -416,8 +422,8 @@ exports.PE = PE;
|
|
|
416
422
|
const EXPORT_DIRECTORY = {
|
|
417
423
|
ExportFlags: uint32, // Reserved, must be 0.
|
|
418
424
|
TimeDateStamp: TIMEDATE, // The time and date that the export data was created.
|
|
419
|
-
MajorVersion:
|
|
420
|
-
MinorVersion:
|
|
425
|
+
MajorVersion: bin.asHex(uint16), // The major version number. The major and minor version numbers can be set by the user.
|
|
426
|
+
MinorVersion: bin.asHex(uint16), // The minor version number.
|
|
421
427
|
DLLName: RVA_STRING, // The address of the ASCII string that contains the name of the DLL. This address is relative to the image base.
|
|
422
428
|
OrdinalBase: uint32, // The starting ordinal number for exports in this image. This field specifies the starting ordinal number for the export address table. It is usually set to 1.
|
|
423
429
|
NumberEntries: uint32, // The number of entries in the export address table.
|
|
@@ -427,7 +433,7 @@ const EXPORT_DIRECTORY = {
|
|
|
427
433
|
OrdinalTable: RVA_ARRAY16, // RVA from base of image
|
|
428
434
|
};
|
|
429
435
|
function ReadExports(file) {
|
|
430
|
-
const dir =
|
|
436
|
+
const dir = bin.read(file, EXPORT_DIRECTORY);
|
|
431
437
|
const addresses = dir.FunctionTable;
|
|
432
438
|
const names = dir.NameTable;
|
|
433
439
|
const ordinals = dir.OrdinalTable;
|
|
@@ -436,7 +442,7 @@ function ReadExports(file) {
|
|
|
436
442
|
const sect = file.pe.FindSectionRVA(addresses[i]);
|
|
437
443
|
if (sect) {
|
|
438
444
|
const ordinal = (ordinals && i < dir.NumberNames ? ordinals[i] : i) + dir.OrdinalBase;
|
|
439
|
-
const name = names && i < dir.NumberNames ?
|
|
445
|
+
const name = names && i < dir.NumberNames ? bin.utils.decodeTextTo0(file.pe.GetDataRVA(names[i])?.data, 'utf8') : '';
|
|
440
446
|
result.push({ ordinal, name, address: addresses[i] });
|
|
441
447
|
}
|
|
442
448
|
}
|
|
@@ -456,11 +462,11 @@ class DLLImports extends Array {
|
|
|
456
462
|
exports.DLLImports = DLLImports;
|
|
457
463
|
const RVA_ITA64 = {
|
|
458
464
|
get(s) {
|
|
459
|
-
const r =
|
|
465
|
+
const r = bin.utils.to64(s.get_rva());
|
|
460
466
|
if (r) {
|
|
461
467
|
const result = Array.from(r.subarray(0, r.indexOf(0n)), i => i >> 63n
|
|
462
468
|
? `ordinal_${i - (1n << 63n)}`
|
|
463
|
-
:
|
|
469
|
+
: bin.utils.decodeTextTo0(s.pe.GetDataRVA(Number(i))?.data.subarray(2), 'utf8'));
|
|
464
470
|
Object.setPrototypeOf(result, DLLImports.prototype);
|
|
465
471
|
return result;
|
|
466
472
|
}
|
|
@@ -477,7 +483,7 @@ const IMPORT_DESCRIPTOR = {
|
|
|
477
483
|
function ReadImports(file) {
|
|
478
484
|
const result = [];
|
|
479
485
|
while (file.remaining()) {
|
|
480
|
-
const r =
|
|
486
|
+
const r = bin.read(file, IMPORT_DESCRIPTOR);
|
|
481
487
|
if (!r.Characteristics)
|
|
482
488
|
break;
|
|
483
489
|
result.push([r.DllName, r.FirstThunk]);
|
|
@@ -487,16 +493,14 @@ function ReadImports(file) {
|
|
|
487
493
|
//-----------------------------------------------------------------------------
|
|
488
494
|
// resources
|
|
489
495
|
//-----------------------------------------------------------------------------
|
|
490
|
-
class RESOURCE_DATA_ENTRY extends
|
|
491
|
-
|
|
496
|
+
class RESOURCE_DATA_ENTRY extends bin.ReadClass({
|
|
497
|
+
Data: RVA_BLOB,
|
|
492
498
|
Size: uint32,
|
|
493
499
|
CodePage: uint32,
|
|
494
500
|
Reserved: uint32,
|
|
495
501
|
}) {
|
|
496
|
-
data
|
|
497
|
-
|
|
498
|
-
super(file);
|
|
499
|
-
this.data = data.slice(this.OffsetToData, this.OffsetToData + this.Size).data;
|
|
502
|
+
get data() {
|
|
503
|
+
return this.Data.slice(0, this.Size);
|
|
500
504
|
}
|
|
501
505
|
}
|
|
502
506
|
const RESOURCE_DIRECTORY = {
|
|
@@ -506,7 +510,7 @@ const RESOURCE_DIRECTORY = {
|
|
|
506
510
|
MinorVersion: uint16,
|
|
507
511
|
NumberOfNamedEntries: uint16,
|
|
508
512
|
NumberOfIdEntries: uint16,
|
|
509
|
-
entries:
|
|
513
|
+
entries: bin.ArrayType(s => s.obj.NumberOfNamedEntries + s.obj.NumberOfIdEntries, {
|
|
510
514
|
u0: uint32,
|
|
511
515
|
u1: uint32,
|
|
512
516
|
})
|
|
@@ -536,17 +540,17 @@ const IRT = {
|
|
|
536
540
|
24: 'MANIFEST',
|
|
537
541
|
241: 'TOOLBAR',
|
|
538
542
|
};
|
|
539
|
-
function ReadResourceDirectory(file,
|
|
540
|
-
const dir =
|
|
541
|
-
const id_type =
|
|
543
|
+
function ReadResourceDirectory(file, type = 0) {
|
|
544
|
+
const dir = bin.read(file, RESOURCE_DIRECTORY);
|
|
545
|
+
const id_type = bin.StringType(uint16, 'utf16le');
|
|
542
546
|
const topbit = 0x80000000;
|
|
543
547
|
const result = {};
|
|
544
548
|
for (const i of dir.entries) {
|
|
545
549
|
const id = i.u0 & topbit ? id_type.get(file.seek(i.u0 & ~topbit)) : !type ? IRT[i.u0] : i.u0;
|
|
546
550
|
file.seek(i.u1 & ~topbit);
|
|
547
551
|
result[id] = i.u1 & topbit
|
|
548
|
-
? ReadResourceDirectory(file,
|
|
549
|
-
: new RESOURCE_DATA_ENTRY(file
|
|
552
|
+
? ReadResourceDirectory(file, type || i.u0)
|
|
553
|
+
: new RESOURCE_DATA_ENTRY(file);
|
|
550
554
|
}
|
|
551
555
|
return result;
|
|
552
556
|
}
|
package/package.json
CHANGED
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
],
|
|
20
20
|
"scripts": {
|
|
21
21
|
"build": "tsc",
|
|
22
|
+
"watch": "tsc -watch -p ./",
|
|
22
23
|
"lint": "eslint \"src/**/*.ts\"",
|
|
23
|
-
"test": "echo \"No tests specified\" && exit 0",
|
|
24
24
|
"patch": "ts-patch install"
|
|
25
25
|
},
|
|
26
26
|
"keywords": [
|
|
@@ -39,11 +39,10 @@
|
|
|
39
39
|
"eslint": "^9.21.0",
|
|
40
40
|
"ts-node": "^10.9.2",
|
|
41
41
|
"ts-patch": "^3.3.0",
|
|
42
|
-
"typescript": "~5.5.0",
|
|
43
42
|
"typescript-eslint": "^8.26.0"
|
|
44
43
|
},
|
|
44
|
+
"version": "1.3.0",
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@isopodlabs/binary": "^1.
|
|
47
|
-
}
|
|
48
|
-
"version": "1.2.1"
|
|
46
|
+
"@isopodlabs/binary": "^1.6.0"
|
|
47
|
+
}
|
|
49
48
|
}
|