@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/mach.js
CHANGED
|
@@ -24,8 +24,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.FATMachFile = exports.MachFile = exports.CMD = void 0;
|
|
27
|
-
const
|
|
28
|
-
class mach_stream extends
|
|
27
|
+
const bin = __importStar(require("@isopodlabs/binary"));
|
|
28
|
+
class mach_stream extends bin.endianStream {
|
|
29
29
|
base;
|
|
30
30
|
memflags;
|
|
31
31
|
mem;
|
|
@@ -45,12 +45,12 @@ class mach_stream extends binary.endianStream {
|
|
|
45
45
|
return this.mem?.get(address, size);
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
const uint16 =
|
|
49
|
-
const uint32 =
|
|
50
|
-
const uint64 =
|
|
51
|
-
const int32 =
|
|
52
|
-
const xint32 =
|
|
53
|
-
const xint64 =
|
|
48
|
+
const uint16 = bin.UINT16;
|
|
49
|
+
const uint32 = bin.UINT32;
|
|
50
|
+
const uint64 = bin.UINT64;
|
|
51
|
+
const int32 = bin.INT32;
|
|
52
|
+
const xint32 = bin.asHex(uint32);
|
|
53
|
+
const xint64 = bin.asHex(uint64);
|
|
54
54
|
const FILETYPE = {
|
|
55
55
|
OBJECT: 1, // Relocatable object file
|
|
56
56
|
EXECUTE: 2, // Executable file
|
|
@@ -237,24 +237,24 @@ const HEADER_FLAGS = {
|
|
|
237
237
|
};
|
|
238
238
|
const header = {
|
|
239
239
|
magic: uint32, // mach magic number identifier
|
|
240
|
-
cputype:
|
|
241
|
-
cpusubtype:
|
|
242
|
-
filetype:
|
|
240
|
+
cputype: bin.as(uint32, bin.Enum(CPU_TYPE)),
|
|
241
|
+
cpusubtype: bin.as(uint32, (x) => x), //binary.Enum(CPU_SUBTYPE)),
|
|
242
|
+
filetype: bin.as(uint32, bin.Enum(FILETYPE)),
|
|
243
243
|
ncmds: uint32, // number of load commands
|
|
244
244
|
sizeofcmds: uint32, // the size of all the load commands
|
|
245
|
-
flags:
|
|
245
|
+
flags: bin.as(uint32, bin.Flags(HEADER_FLAGS, true))
|
|
246
246
|
};
|
|
247
247
|
const fat_arch = {
|
|
248
|
-
cputype:
|
|
249
|
-
cpusubtype:
|
|
250
|
-
offset:
|
|
251
|
-
size:
|
|
252
|
-
align:
|
|
253
|
-
contents:
|
|
248
|
+
cputype: bin.as(uint32, bin.Enum(CPU_TYPE)),
|
|
249
|
+
cpusubtype: bin.as(uint32, (x) => x), //binary.Enum(CPU_SUBTYPE)),
|
|
250
|
+
offset: bin.UINT32_BE, // file offset to this object file
|
|
251
|
+
size: bin.UINT32_BE, // size of this object file
|
|
252
|
+
align: bin.UINT32_BE, // alignment as a power of 2
|
|
253
|
+
contents: bin.DontRead(),
|
|
254
254
|
};
|
|
255
255
|
const fat_header = {
|
|
256
256
|
magic: uint32, // FAT_MAGIC
|
|
257
|
-
archs:
|
|
257
|
+
archs: bin.ArrayType(uint32, fat_arch)
|
|
258
258
|
};
|
|
259
259
|
const REQ_DYLD = 0x80000000;
|
|
260
260
|
var CMD;
|
|
@@ -317,7 +317,7 @@ var CMD;
|
|
|
317
317
|
const str = {
|
|
318
318
|
get(s) {
|
|
319
319
|
const off = uint32.get(s); // offset to the string
|
|
320
|
-
return
|
|
320
|
+
return bin.utils.decodeTextTo0(s.buffer_at(off - 8), 'utf8');
|
|
321
321
|
}
|
|
322
322
|
};
|
|
323
323
|
const index_table = {
|
|
@@ -339,13 +339,13 @@ function blobT(type) {
|
|
|
339
339
|
const size = uint32.get(s);
|
|
340
340
|
return {
|
|
341
341
|
data: s.subdata(offset, size),
|
|
342
|
-
contents:
|
|
342
|
+
contents: bin.read(s.substream(offset, size), type)
|
|
343
343
|
};
|
|
344
344
|
}
|
|
345
345
|
};
|
|
346
346
|
}
|
|
347
347
|
function blobArray(type) {
|
|
348
|
-
return blobT(
|
|
348
|
+
return blobT(bin.RemainingArrayType(type));
|
|
349
349
|
}
|
|
350
350
|
function count_table(type) {
|
|
351
351
|
return {
|
|
@@ -353,18 +353,18 @@ function count_table(type) {
|
|
|
353
353
|
const offset = uint32.get(s);
|
|
354
354
|
const count = uint32.get(s);
|
|
355
355
|
if (count)
|
|
356
|
-
return
|
|
356
|
+
return bin.readn(s.substream(offset), type, count);
|
|
357
357
|
}
|
|
358
358
|
};
|
|
359
359
|
}
|
|
360
|
-
const fixed_string16 =
|
|
361
|
-
const version =
|
|
360
|
+
const fixed_string16 = bin.StringType(16);
|
|
361
|
+
const version = bin.asFlags(uint32, { major: 0xffff0000, minor: 0xff00, patch: 0xff }, false);
|
|
362
362
|
const command = {
|
|
363
|
-
cmd:
|
|
363
|
+
cmd: bin.as(uint32, v => v),
|
|
364
364
|
cmdsize: uint32,
|
|
365
365
|
};
|
|
366
|
-
const SECTION_FLAGS =
|
|
367
|
-
TYPE: [8,
|
|
366
|
+
const SECTION_FLAGS = bin.BitFields({
|
|
367
|
+
TYPE: [8, bin.Enum({
|
|
368
368
|
REGULAR: 0x0, // regular section
|
|
369
369
|
ZEROFILL: 0x1, // zero fill on demand section
|
|
370
370
|
CSTRING_LITERALS: 0x2, // section with only literal C strings
|
|
@@ -389,13 +389,13 @@ const SECTION_FLAGS = binary.BitFields({
|
|
|
389
389
|
THREAD_LOCAL_VARIABLE_POINTERS: 0x14, // pointers to TLV descriptors
|
|
390
390
|
THREAD_LOCAL_INIT_FUNCTION_POINTERS: 0x15, // functions to call to initialize TLV values
|
|
391
391
|
})],
|
|
392
|
-
ATTRIBUTES: [24,
|
|
393
|
-
SYS: [16,
|
|
392
|
+
ATTRIBUTES: [24, bin.BitFields({
|
|
393
|
+
SYS: [16, bin.Flags({
|
|
394
394
|
SOME_INSTRUCTIONS: 0x0004, // section contains some machine instructions
|
|
395
395
|
EXT_RELOC: 0x0002, // section has external relocation entries
|
|
396
396
|
LOC_RELOC: 0x0001, // section has local relocation entries
|
|
397
397
|
}, true)],
|
|
398
|
-
USR: [8,
|
|
398
|
+
USR: [8, bin.Flags({
|
|
399
399
|
PURE_INSTRUCTIONS: 0x80, // section contains only true machine instructions
|
|
400
400
|
NO_TOC: 0x40, // section contains coalesced symbols that are not to be in a ranlib table of contents
|
|
401
401
|
STRIP_STATIC_SYMS: 0x20, // ok to strip static symbols in this section in files with the MH_DYLDLINK flag
|
|
@@ -407,8 +407,8 @@ const SECTION_FLAGS = binary.BitFields({
|
|
|
407
407
|
})],
|
|
408
408
|
});
|
|
409
409
|
function section(bits) {
|
|
410
|
-
const type =
|
|
411
|
-
class Section extends
|
|
410
|
+
const type = bin.asHex(bin.UINT(bits));
|
|
411
|
+
class Section extends bin.Class({
|
|
412
412
|
//data: binary.DontRead<binary.utils.MappedMemory>(),
|
|
413
413
|
sectname: fixed_string16,
|
|
414
414
|
segname: fixed_string16,
|
|
@@ -418,18 +418,18 @@ function section(bits) {
|
|
|
418
418
|
align: uint32, // section alignment (power of 2)
|
|
419
419
|
reloff: xint32, // file offset of relocation entries
|
|
420
420
|
nreloc: uint32, // number of relocation entries
|
|
421
|
-
flags:
|
|
421
|
+
flags: bin.as(uint32, SECTION_FLAGS), // flags (section type and attributes)
|
|
422
422
|
reserved1: uint32, // reserved (for offset or index)
|
|
423
423
|
reserved2: uint32, // reserved (for count or sizeof)
|
|
424
|
-
_:
|
|
424
|
+
_: bin.AlignType(bits / 8)
|
|
425
425
|
}) {
|
|
426
426
|
data;
|
|
427
427
|
constructor(s) {
|
|
428
428
|
super(s);
|
|
429
|
-
const prot = this.flags.ATTRIBUTES.SYS.SOME_INSTRUCTIONS ?
|
|
429
|
+
const prot = this.flags.ATTRIBUTES.SYS.SOME_INSTRUCTIONS ? bin.MappedMemory.EXECUTE | s.memflags : s.memflags;
|
|
430
430
|
this.data = (async () =>
|
|
431
431
|
//new binary.utils.MappedMemory(await s.file.get(BigInt(this.addr), Number(this.size)), Number(this.addr), prot)
|
|
432
|
-
new
|
|
432
|
+
new bin.MappedMemory(s.subdata(+this.offset, Number(this.size)), BigInt(this.addr.value), prot))();
|
|
433
433
|
}
|
|
434
434
|
}
|
|
435
435
|
return Section;
|
|
@@ -441,9 +441,9 @@ const SEGMENT_FLAGS = {
|
|
|
441
441
|
PROTECTED_VERSION_1: 0x8, // This segment is protected. If the segment starts at file offset 0, the first page of the segment is not protected. All other pages of the segment are protected.
|
|
442
442
|
};
|
|
443
443
|
function segment(bits) {
|
|
444
|
-
const type =
|
|
444
|
+
const type = bin.asHex(bin.UINT(bits));
|
|
445
445
|
const fields = {
|
|
446
|
-
data:
|
|
446
|
+
data: bin.DontRead(),
|
|
447
447
|
segname: fixed_string16, // segment name
|
|
448
448
|
vmaddr: type, // memory address of this segment
|
|
449
449
|
vmsize: type, // memory size of this segment
|
|
@@ -452,18 +452,18 @@ function segment(bits) {
|
|
|
452
452
|
maxprot: uint32, // maximum VM protection
|
|
453
453
|
initprot: uint32, // initial VM protection
|
|
454
454
|
nsects: uint32, // number of sections in segment
|
|
455
|
-
flags:
|
|
456
|
-
sections:
|
|
455
|
+
flags: bin.as(uint32, bin.Flags(SEGMENT_FLAGS, true)), // flags
|
|
456
|
+
sections: bin.DontRead(), //binary.ReadType<typeof section(bits)>)),
|
|
457
457
|
};
|
|
458
458
|
return {
|
|
459
459
|
get(s) {
|
|
460
|
-
const o =
|
|
460
|
+
const o = bin.read(s, fields);
|
|
461
461
|
async function load() {
|
|
462
462
|
const data = await s.getmem(BigInt(Number(o.vmaddr)), Number(o.filesize)) ?? s.subdata(Number(o.fileoff), Number(o.filesize));
|
|
463
|
-
o.data = new
|
|
463
|
+
o.data = new bin.MappedMemory(data, BigInt(o.vmaddr.value), o.initprot | s.memflags);
|
|
464
464
|
//const sect = section(bits);
|
|
465
465
|
if (o.nsects) {
|
|
466
|
-
o.sections =
|
|
466
|
+
o.sections = bin.objectWithNames(bin.ArrayType(o.nsects, section(bits)), bin.field('sectname')).get(s);
|
|
467
467
|
//o.sections = Object.fromEntries(Array.from({length: o.nsects}, (_,i)=>new sect(s)).map(s => [s.sectname, s]));
|
|
468
468
|
}
|
|
469
469
|
}
|
|
@@ -525,9 +525,9 @@ const thread_command = {
|
|
|
525
525
|
// ...
|
|
526
526
|
};
|
|
527
527
|
// SYMTAB
|
|
528
|
-
const nlist_flags =
|
|
528
|
+
const nlist_flags = bin.BitFields({
|
|
529
529
|
ext: 1,
|
|
530
|
-
type: [3,
|
|
530
|
+
type: [3, bin.Enum({
|
|
531
531
|
UNDF: 0, // undefined, n_sect == NO_SECT
|
|
532
532
|
ABS: 1, // absolute, n_sect == NO_SECT
|
|
533
533
|
INDR: 5, // indirect
|
|
@@ -535,7 +535,7 @@ const nlist_flags = binary.BitFields({
|
|
|
535
535
|
SECT: 7, // defined in section number n_sect
|
|
536
536
|
})],
|
|
537
537
|
pext: 1,
|
|
538
|
-
stab: [3,
|
|
538
|
+
stab: [3, bin.Enum({})],
|
|
539
539
|
});
|
|
540
540
|
/*
|
|
541
541
|
//masks
|
|
@@ -581,8 +581,8 @@ const nlist_flags = binary.BitFields({
|
|
|
581
581
|
LENG = 0xfe, // second stab entry with length information
|
|
582
582
|
}
|
|
583
583
|
*/
|
|
584
|
-
const nlist_desc =
|
|
585
|
-
ref: [3,
|
|
584
|
+
const nlist_desc = bin.BitFields({
|
|
585
|
+
ref: [3, bin.Enum({
|
|
586
586
|
UNDEFINED_NON_LAZY: 0,
|
|
587
587
|
UNDEFINED_LAZY: 1,
|
|
588
588
|
DEFINED: 2,
|
|
@@ -590,7 +590,7 @@ const nlist_desc = binary.BitFields({
|
|
|
590
590
|
PRIVATE_UNDEFINED_NON_LAZY: 4,
|
|
591
591
|
PRIVATE_UNDEFINED_LAZY: 5,
|
|
592
592
|
})],
|
|
593
|
-
flags: [5,
|
|
593
|
+
flags: [5, bin.Flags({
|
|
594
594
|
ARM_THUMB_DEF: 1 << 0, // symbol is a Thumb function (ARM)
|
|
595
595
|
REF_DYNAMIC: 1 << 1,
|
|
596
596
|
NO_DEAD_STRIP: 1 << 2, // symbol is not to be dead stripped
|
|
@@ -608,10 +608,10 @@ const nlist_desc = binary.BitFields({
|
|
|
608
608
|
function nlist(bits) {
|
|
609
609
|
return {
|
|
610
610
|
strx: uint32, // index into the string table
|
|
611
|
-
flags:
|
|
612
|
-
sect:
|
|
613
|
-
desc:
|
|
614
|
-
value:
|
|
611
|
+
flags: bin.as(bin.UINT8, nlist_flags),
|
|
612
|
+
sect: bin.UINT8, // section number or NO_SECT
|
|
613
|
+
desc: bin.as(uint16, nlist_desc),
|
|
614
|
+
value: bin.UINT(bits),
|
|
615
615
|
//const char *name(const char *s) const { return s ? s + strx : ""; }
|
|
616
616
|
//FLAGS type() const { return FLAGS(flags & TYPE); }
|
|
617
617
|
//FLAGS stab() const { return FLAGS(flags & STAB); }
|
|
@@ -619,9 +619,9 @@ function nlist(bits) {
|
|
|
619
619
|
}
|
|
620
620
|
const symtab = {
|
|
621
621
|
get(s) {
|
|
622
|
-
const sym =
|
|
623
|
-
const str =
|
|
624
|
-
return sym?.map(v => [
|
|
622
|
+
const sym = bin.read(s, count_table(nlist(64)));
|
|
623
|
+
const str = bin.read(s, blob);
|
|
624
|
+
return sym?.map(v => [bin.utils.decodeTextTo0(str.subarray(v.strx), 'utf8'), v]);
|
|
625
625
|
}
|
|
626
626
|
};
|
|
627
627
|
// DYSYMTAB
|
|
@@ -650,11 +650,11 @@ function module(bits) {
|
|
|
650
650
|
objc_module_info_addr: uint64, // for this module address of the start of the (__OBJC, __module_info) section
|
|
651
651
|
};
|
|
652
652
|
}
|
|
653
|
-
const symbol_ref =
|
|
653
|
+
const symbol_ref = bin.as(uint32, bin.BitFields({
|
|
654
654
|
symbol_index: 24, // index into the symbol table
|
|
655
655
|
flags: 8
|
|
656
656
|
}));
|
|
657
|
-
const hint =
|
|
657
|
+
const hint = bin.as(uint32, bin.BitFields({
|
|
658
658
|
sub_image: 8, // index into the sub images
|
|
659
659
|
toc: 24 // index into the table of contents
|
|
660
660
|
}));
|
|
@@ -662,9 +662,9 @@ const version_min = {
|
|
|
662
662
|
version,
|
|
663
663
|
reserved: uint32, // zero
|
|
664
664
|
};
|
|
665
|
-
const REBASE =
|
|
665
|
+
const REBASE = bin.BitFields({
|
|
666
666
|
immediate: 4,
|
|
667
|
-
opcode: [4,
|
|
667
|
+
opcode: [4, bin.Enum({
|
|
668
668
|
DONE: 0,
|
|
669
669
|
SET_TYPE_IMM: 1,
|
|
670
670
|
SET_SEGMENT_AND_OFFSET_ULEB: 2,
|
|
@@ -679,9 +679,9 @@ const REBASE = binary.BitFields({
|
|
|
679
679
|
//TYPE_TEXT_ABSOLUTE32 = 2,
|
|
680
680
|
//TYPE_TEXT_PCREL32 = 3,
|
|
681
681
|
});
|
|
682
|
-
const BIND =
|
|
682
|
+
const BIND = bin.BitFields({
|
|
683
683
|
immediate: 4,
|
|
684
|
-
opcode: [4,
|
|
684
|
+
opcode: [4, bin.Enum({
|
|
685
685
|
DONE: 0,
|
|
686
686
|
SET_DYLIB_ORDINAL_IMM: 1,
|
|
687
687
|
SET_DYLIB_ORDINAL_ULEB: 2,
|
|
@@ -744,7 +744,7 @@ const PLATFORM = {
|
|
|
744
744
|
const dyld_chained_starts_in_segment = {
|
|
745
745
|
size: uint32, ///< Size of this, including chain_starts entries
|
|
746
746
|
page_size: uint16, ///< Page size in bytes (0x1000 or 0x4000)
|
|
747
|
-
pointer_format:
|
|
747
|
+
pointer_format: bin.asEnum(uint16, {
|
|
748
748
|
ARM64E: 1,
|
|
749
749
|
'64': 2,
|
|
750
750
|
'32': 3,
|
|
@@ -760,14 +760,14 @@ const dyld_chained_starts_in_segment = {
|
|
|
760
760
|
}),
|
|
761
761
|
segment_offset: xint64, // VM offset from the __TEXT segment
|
|
762
762
|
max_valid_pointer: xint32, // Values beyond this are not pointers on 32-bit
|
|
763
|
-
pages:
|
|
763
|
+
pages: bin.ArrayType(uint16, bin.asEnum(uint16, {
|
|
764
764
|
NONE: 0xFFFF,
|
|
765
765
|
MULTI: 0x8000, // page which has multiple starts
|
|
766
766
|
LAST: 0x8000, // last chain_start for a given page
|
|
767
767
|
}))
|
|
768
768
|
};
|
|
769
|
-
const dyld_chained_starts_in_image =
|
|
770
|
-
const dyld_chained_import =
|
|
769
|
+
const dyld_chained_starts_in_image = bin.ArrayType(uint32, bin.OffsetType(uint32, dyld_chained_starts_in_segment));
|
|
770
|
+
const dyld_chained_import = bin.as(uint32, bin.BitFields({
|
|
771
771
|
lib_ordinal: 8,
|
|
772
772
|
weak_import: 1,
|
|
773
773
|
name_offset: 23,
|
|
@@ -777,7 +777,7 @@ const dyld_chained_import_addend = {
|
|
|
777
777
|
addend: int32,
|
|
778
778
|
};
|
|
779
779
|
const dyld_chained_import_addend64 = {
|
|
780
|
-
import:
|
|
780
|
+
import: bin.as(uint64, bin.BitFields({
|
|
781
781
|
lib_ordinal: 16,
|
|
782
782
|
weak_import: 1,
|
|
783
783
|
reserved: 15,
|
|
@@ -785,18 +785,18 @@ const dyld_chained_import_addend64 = {
|
|
|
785
785
|
})),
|
|
786
786
|
addend: uint64,
|
|
787
787
|
};
|
|
788
|
-
class dyld_chained_fixups extends
|
|
788
|
+
class dyld_chained_fixups extends bin.ReadClass({
|
|
789
789
|
fixups_version: uint32, // currently 0
|
|
790
|
-
starts:
|
|
791
|
-
imports:
|
|
792
|
-
symbols:
|
|
790
|
+
starts: bin.OffsetType(uint32, dyld_chained_starts_in_image),
|
|
791
|
+
imports: bin.OffsetType(uint32, bin.Remainder), // offset of imports table in chain_data
|
|
792
|
+
symbols: bin.OffsetType(uint32, bin.Remainder), // offset of symbol strings in chain_data
|
|
793
793
|
imports_count: uint32, // number of imported symbol names
|
|
794
|
-
imports_format:
|
|
794
|
+
imports_format: bin.asEnum(uint32, {
|
|
795
795
|
IMPORT: 1,
|
|
796
796
|
IMPORT_ADDEND: 2,
|
|
797
797
|
IMPORT_ADDEND64: 3
|
|
798
798
|
}),
|
|
799
|
-
symbols_format:
|
|
799
|
+
symbols_format: bin.asEnum(uint32, {
|
|
800
800
|
UNCOMPRESSED: 0,
|
|
801
801
|
ZLIB: 1,
|
|
802
802
|
}),
|
|
@@ -804,29 +804,29 @@ class dyld_chained_fixups extends binary.ReadClass({
|
|
|
804
804
|
imports2;
|
|
805
805
|
constructor(s) {
|
|
806
806
|
super(s);
|
|
807
|
-
const imports = new
|
|
807
|
+
const imports = new bin.endianStream(this.imports, s.be);
|
|
808
808
|
switch (this.imports_format) {
|
|
809
809
|
case 'IMPORT': {
|
|
810
|
-
this.imports2 =
|
|
810
|
+
this.imports2 = bin.withNames(bin.readn(imports, dyld_chained_import, this.imports_count), imp => bin.utils.decodeTextTo0(this.symbols.subarray(Number(imp.name_offset))));
|
|
811
811
|
break;
|
|
812
812
|
}
|
|
813
813
|
case 'IMPORT_ADDEND':
|
|
814
|
-
this.imports2 =
|
|
814
|
+
this.imports2 = bin.withNames(bin.readn(imports, dyld_chained_import_addend, this.imports_count), imp => bin.utils.decodeTextTo0(this.symbols.subarray(Number(imp.import.name_offset))));
|
|
815
815
|
break;
|
|
816
816
|
case 'IMPORT_ADDEND64':
|
|
817
|
-
this.imports2 =
|
|
817
|
+
this.imports2 = bin.withNames(bin.readn(imports, dyld_chained_import_addend64, this.imports_count), imp => bin.utils.decodeTextTo0(this.symbols.subarray(Number(imp.import.name_offset))));
|
|
818
818
|
break;
|
|
819
819
|
}
|
|
820
820
|
}
|
|
821
821
|
}
|
|
822
|
-
const dyld_chained_ptr_64_bind =
|
|
822
|
+
const dyld_chained_ptr_64_bind = bin.as(uint64, bin.BitFields({
|
|
823
823
|
ordinal: 24,
|
|
824
824
|
addend: 8,
|
|
825
825
|
reserved: 19,
|
|
826
826
|
next: 12,
|
|
827
827
|
bind: 1, // set to 1
|
|
828
828
|
}));
|
|
829
|
-
const dyld_chained_ptr_64_rebase =
|
|
829
|
+
const dyld_chained_ptr_64_rebase = bin.as(uint64, bin.BitFields({
|
|
830
830
|
target: 36,
|
|
831
831
|
high8: 8,
|
|
832
832
|
reserved: 7,
|
|
@@ -837,7 +837,7 @@ const dyld_chained_ptr_64_rebase = binary.as(uint64, binary.BitFields({
|
|
|
837
837
|
const data_in_code_entry = {
|
|
838
838
|
offset: xint32, // from header to start of data range
|
|
839
839
|
length: uint16, // number of bytes in data range
|
|
840
|
-
kind:
|
|
840
|
+
kind: bin.as(uint16, bin.Enum({
|
|
841
841
|
DATA: 0x0001,
|
|
842
842
|
JUMP_TABLE8: 0x0002,
|
|
843
843
|
JUMP_TABLE16: 0x0003,
|
|
@@ -854,7 +854,7 @@ const tlv_descriptor = {
|
|
|
854
854
|
};
|
|
855
855
|
*/
|
|
856
856
|
function routines(bits) {
|
|
857
|
-
const type =
|
|
857
|
+
const type = bin.UINT(bits);
|
|
858
858
|
return {
|
|
859
859
|
init_address: type, // address of initialization routine
|
|
860
860
|
init_module: type, // index into the module table that the init routine is defined in
|
|
@@ -901,11 +901,11 @@ const cmd_table = {
|
|
|
901
901
|
cksum: uint32,
|
|
902
902
|
},
|
|
903
903
|
[CMD.UUID]: {
|
|
904
|
-
uuid:
|
|
904
|
+
uuid: bin.Buffer(16),
|
|
905
905
|
},
|
|
906
906
|
[CMD.CODE_SIGNATURE]: blob,
|
|
907
907
|
[CMD.SEGMENT_SPLIT_INFO]: blob,
|
|
908
|
-
[CMD.FUNCTION_STARTS]: blobArray(
|
|
908
|
+
[CMD.FUNCTION_STARTS]: blobArray(bin.ULEB128),
|
|
909
909
|
[CMD.DATA_IN_CODE]: blobArray(data_in_code_entry),
|
|
910
910
|
[CMD.DYLIB_CODE_SIGN_DRS]: blob,
|
|
911
911
|
[CMD.LINKER_OPTIMIZATION_HINT]: blob,
|
|
@@ -939,13 +939,13 @@ const cmd_table = {
|
|
|
939
939
|
stacksize: uint32, // if not zero, initialize stack size
|
|
940
940
|
},
|
|
941
941
|
[CMD.SOURCE_VERSION]: {
|
|
942
|
-
version:
|
|
942
|
+
version: bin.as(bin.UINT64_BE, bin.BitFields({ a: 24, b: 10, c: 10, d: 10, e: 10 })) // A.B.C.D.E packed as a24.b10.c10.d10.e10
|
|
943
943
|
},
|
|
944
944
|
[CMD.BUILD_VERSION]: {
|
|
945
|
-
platform:
|
|
945
|
+
platform: bin.asEnum(uint32, PLATFORM),
|
|
946
946
|
minos: version,
|
|
947
947
|
sdk: version,
|
|
948
|
-
tools:
|
|
948
|
+
tools: bin.objectWithNames(bin.ArrayType(uint32, { tool: bin.as(uint32, bin.Enum(TOOL)), version }), bin.field('tool')),
|
|
949
949
|
},
|
|
950
950
|
[CMD.LINKER_OPTION]: {
|
|
951
951
|
count: uint32, // number of strings following
|
|
@@ -969,7 +969,7 @@ const cmd_table = {
|
|
|
969
969
|
};
|
|
970
970
|
class MachFile {
|
|
971
971
|
static check(data) {
|
|
972
|
-
switch (
|
|
972
|
+
switch (bin.UINT32_BE.get(new bin.stream(data))) {
|
|
973
973
|
case 0xfeedface:
|
|
974
974
|
case 0xcefaedfe:
|
|
975
975
|
case 0xfeedfacf:
|
|
@@ -982,7 +982,7 @@ class MachFile {
|
|
|
982
982
|
header;
|
|
983
983
|
commands = [];
|
|
984
984
|
constructor(data, mem) {
|
|
985
|
-
const magic =
|
|
985
|
+
const magic = bin.UINT32_LE.get(new bin.stream(data));
|
|
986
986
|
switch (magic) {
|
|
987
987
|
case 0xfeedface:
|
|
988
988
|
this.load(data, false, 32, mem);
|
|
@@ -1000,16 +1000,16 @@ class MachFile {
|
|
|
1000
1000
|
}
|
|
1001
1001
|
}
|
|
1002
1002
|
load(data, be, bits, mem) {
|
|
1003
|
-
const file = new
|
|
1004
|
-
const h =
|
|
1003
|
+
const file = new bin.endianStream(data, be);
|
|
1004
|
+
const h = bin.read(file, header);
|
|
1005
1005
|
const cpu = CPU_TYPE[h.cputype];
|
|
1006
|
-
h.cpusubtype =
|
|
1006
|
+
h.cpusubtype = bin.Enum(CPU_SUBTYPES[cpu])(+h.cpusubtype);
|
|
1007
1007
|
if (bits === 64)
|
|
1008
1008
|
file.skip(4);
|
|
1009
1009
|
for (let i = 0; i < h.ncmds; ++i) {
|
|
1010
|
-
const cmd =
|
|
1011
|
-
const file2 = new mach_stream(data, file.read_buffer(cmd.cmdsize - 8), file.be, h.filetype === 'EXECUTE' ? 0 :
|
|
1012
|
-
const result =
|
|
1010
|
+
const cmd = bin.read(file, command);
|
|
1011
|
+
const file2 = new mach_stream(data, file.read_buffer(cmd.cmdsize - 8), file.be, h.filetype === 'EXECUTE' ? 0 : bin.MappedMemory.RELATIVE, mem);
|
|
1012
|
+
const result = bin.read(file2, cmd_table[cmd.cmd] ?? {});
|
|
1013
1013
|
this.commands.push({ cmd: cmd.cmd, data: result });
|
|
1014
1014
|
}
|
|
1015
1015
|
this.header = h;
|
|
@@ -1044,7 +1044,7 @@ const FAT_CIGAM = 0xbebafeca;
|
|
|
1044
1044
|
class FATMachFile {
|
|
1045
1045
|
archs = [];
|
|
1046
1046
|
static check(data) {
|
|
1047
|
-
switch (
|
|
1047
|
+
switch (bin.UINT32_BE.get(new bin.stream(data))) {
|
|
1048
1048
|
case FAT_MAGIC:
|
|
1049
1049
|
case FAT_CIGAM:
|
|
1050
1050
|
return true;
|
|
@@ -1053,24 +1053,24 @@ class FATMachFile {
|
|
|
1053
1053
|
}
|
|
1054
1054
|
}
|
|
1055
1055
|
constructor(data, mem) {
|
|
1056
|
-
switch (
|
|
1056
|
+
switch (bin.UINT32_BE.get(new bin.stream(data))) {
|
|
1057
1057
|
case FAT_MAGIC:
|
|
1058
|
-
this.load(new
|
|
1058
|
+
this.load(new bin.endianStream(data, true), mem);
|
|
1059
1059
|
break;
|
|
1060
1060
|
case FAT_CIGAM:
|
|
1061
|
-
this.load(new
|
|
1061
|
+
this.load(new bin.endianStream(data, false), mem);
|
|
1062
1062
|
break;
|
|
1063
1063
|
default:
|
|
1064
1064
|
throw new Error('not a fat mach file');
|
|
1065
1065
|
}
|
|
1066
1066
|
}
|
|
1067
1067
|
load(file, mem) {
|
|
1068
|
-
const header =
|
|
1068
|
+
const header = bin.read(file, fat_header);
|
|
1069
1069
|
this.archs = header.archs;
|
|
1070
1070
|
for (const arch of header.archs) {
|
|
1071
1071
|
const cpu = CPU_TYPE[arch.cputype];
|
|
1072
1072
|
const data = file.buffer_at(arch.offset, arch.size);
|
|
1073
|
-
arch.cpusubtype =
|
|
1073
|
+
arch.cpusubtype = bin.Enum(CPU_SUBTYPES[cpu])(+arch.cpusubtype);
|
|
1074
1074
|
arch.contents = new MachFile(data, mem);
|
|
1075
1075
|
}
|
|
1076
1076
|
}
|