@isopodlabs/binary_libs 1.1.0 → 1.1.1
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/README.md +2 -0
- package/dist/arch.js +2 -2
- package/dist/clr.js +1 -1
- package/dist/mach.d.ts +14 -25
- package/dist/mach.js +10 -8
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
This package provides readers for various library formats, using the @isopodlabs/binary binary file loading library
|
|
4
4
|
|
|
5
|
+
## ☕ Support My Work
|
|
6
|
+
If you use this package, consider [buying me a tea](https://coff.ee/adrianstephens) to support future updates!
|
|
5
7
|
|
|
6
8
|
## Supported File Types
|
|
7
9
|
|
package/dist/arch.js
CHANGED
|
@@ -70,13 +70,13 @@ class ArchFile {
|
|
|
70
70
|
const offsets = binary.ArrayType(binary.INT32_BE, binary.INT32_BE).get(s2);
|
|
71
71
|
member.name = 'Symbols';
|
|
72
72
|
member.contents = offsets.map(offset => [
|
|
73
|
-
binary.NullTerminatedStringType.get(s2),
|
|
73
|
+
binary.NullTerminatedStringType().get(s2),
|
|
74
74
|
offset
|
|
75
75
|
]);
|
|
76
76
|
}
|
|
77
77
|
else if (member.name == '/SYM') {
|
|
78
78
|
const s2 = new binary.stream(data);
|
|
79
|
-
const syms = binary.ArrayType(binary.INT32_BE, binary.NullTerminatedStringType).get(s2);
|
|
79
|
+
const syms = binary.ArrayType(binary.INT32_BE, binary.NullTerminatedStringType()).get(s2);
|
|
80
80
|
member.contents = syms.map(name => ({
|
|
81
81
|
name,
|
|
82
82
|
offset: binary.INT32_BE.get(s2)
|
package/dist/clr.js
CHANGED
|
@@ -60,7 +60,7 @@ const CLR_HEADER = {
|
|
|
60
60
|
const STREAM_HDR = {
|
|
61
61
|
Offset: binary.UINT32_LE, // Memory offset to start of this stream from start of the metadata root (§II.24.2.1)
|
|
62
62
|
Size: binary.UINT32_LE, // Size of this stream in bytes, shall be a multiple of 4.
|
|
63
|
-
Name: binary.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.
|
|
63
|
+
Name: binary.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.
|
|
64
64
|
unused: binary.AlignType(4),
|
|
65
65
|
};
|
|
66
66
|
const METADATA_ROOT = {
|
package/dist/mach.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as binary from '@isopodlabs/binary';
|
|
2
2
|
declare class mach_stream extends binary.endianStream {
|
|
3
3
|
base: Uint8Array;
|
|
4
|
+
memflags: number;
|
|
4
5
|
mem?: binary.memory | undefined;
|
|
5
|
-
constructor(base: Uint8Array, data: Uint8Array, be: boolean, mem?: binary.memory | undefined);
|
|
6
|
+
constructor(base: Uint8Array, data: Uint8Array, be: boolean, memflags: number, mem?: binary.memory | undefined);
|
|
6
7
|
subdata(offset: number, size?: number): Uint8Array;
|
|
7
8
|
substream(offset: number, size?: number): mach_stream;
|
|
8
9
|
getmem(address: bigint, size: number): Uint8Array | Promise<Uint8Array> | undefined;
|
|
@@ -82,10 +83,10 @@ declare const cmd_table: {
|
|
|
82
83
|
get(s: mach_stream): {
|
|
83
84
|
data: binary.MappedMemory | undefined;
|
|
84
85
|
segname: string;
|
|
85
|
-
vmaddr: number
|
|
86
|
-
vmsize: number
|
|
87
|
-
fileoff: number
|
|
88
|
-
filesize: number
|
|
86
|
+
vmaddr: binary.hex<number | bigint>;
|
|
87
|
+
vmsize: binary.hex<number | bigint>;
|
|
88
|
+
fileoff: binary.hex<number | bigint>;
|
|
89
|
+
filesize: binary.hex<number | bigint>;
|
|
89
90
|
maxprot: number;
|
|
90
91
|
initprot: number;
|
|
91
92
|
nsects: number;
|
|
@@ -97,10 +98,10 @@ declare const cmd_table: {
|
|
|
97
98
|
get(s: mach_stream): {
|
|
98
99
|
data: binary.MappedMemory | undefined;
|
|
99
100
|
segname: string;
|
|
100
|
-
vmaddr: bigint
|
|
101
|
-
vmsize: bigint
|
|
102
|
-
fileoff: bigint
|
|
103
|
-
filesize: bigint
|
|
101
|
+
vmaddr: binary.hex<number | bigint>;
|
|
102
|
+
vmsize: binary.hex<number | bigint>;
|
|
103
|
+
fileoff: binary.hex<number | bigint>;
|
|
104
|
+
filesize: binary.hex<number | bigint>;
|
|
104
105
|
maxprot: number;
|
|
105
106
|
initprot: number;
|
|
106
107
|
nsects: number;
|
|
@@ -481,22 +482,10 @@ export declare class MachFile {
|
|
|
481
482
|
getSegment(name: string): {
|
|
482
483
|
data: binary.MappedMemory | undefined;
|
|
483
484
|
segname: string;
|
|
484
|
-
vmaddr: number
|
|
485
|
-
vmsize: number
|
|
486
|
-
fileoff: number
|
|
487
|
-
filesize: number
|
|
488
|
-
maxprot: number;
|
|
489
|
-
initprot: number;
|
|
490
|
-
nsects: number;
|
|
491
|
-
flags: Record<string, bigint | boolean> | Record<string, number | boolean>;
|
|
492
|
-
sections: Record<string, any> | undefined;
|
|
493
|
-
} | {
|
|
494
|
-
data: binary.MappedMemory | undefined;
|
|
495
|
-
segname: string;
|
|
496
|
-
vmaddr: bigint;
|
|
497
|
-
vmsize: bigint;
|
|
498
|
-
fileoff: bigint;
|
|
499
|
-
filesize: bigint;
|
|
485
|
+
vmaddr: binary.hex<number | bigint>;
|
|
486
|
+
vmsize: binary.hex<number | bigint>;
|
|
487
|
+
fileoff: binary.hex<number | bigint>;
|
|
488
|
+
filesize: binary.hex<number | bigint>;
|
|
500
489
|
maxprot: number;
|
|
501
490
|
initprot: number;
|
|
502
491
|
nsects: number;
|
package/dist/mach.js
CHANGED
|
@@ -27,17 +27,19 @@ exports.FATMachFile = exports.MachFile = exports.CMD = void 0;
|
|
|
27
27
|
const binary = __importStar(require("@isopodlabs/binary"));
|
|
28
28
|
class mach_stream extends binary.endianStream {
|
|
29
29
|
base;
|
|
30
|
+
memflags;
|
|
30
31
|
mem;
|
|
31
|
-
constructor(base, data, be, mem) {
|
|
32
|
+
constructor(base, data, be, memflags, mem) {
|
|
32
33
|
super(data, be);
|
|
33
34
|
this.base = base;
|
|
35
|
+
this.memflags = memflags;
|
|
34
36
|
this.mem = mem;
|
|
35
37
|
}
|
|
36
38
|
subdata(offset, size) {
|
|
37
39
|
return this.base.subarray(offset, size && offset + size);
|
|
38
40
|
}
|
|
39
41
|
substream(offset, size) {
|
|
40
|
-
return new mach_stream(this.base, this.subdata(offset, size), this.be, this.mem);
|
|
42
|
+
return new mach_stream(this.base, this.subdata(offset, size), this.be, this.memflags, this.mem);
|
|
41
43
|
}
|
|
42
44
|
getmem(address, size) {
|
|
43
45
|
return this.mem?.get(address, size);
|
|
@@ -405,7 +407,7 @@ const SECTION_FLAGS = binary.BitFields({
|
|
|
405
407
|
})],
|
|
406
408
|
});
|
|
407
409
|
function section(bits) {
|
|
408
|
-
const type = binary.UINT(bits);
|
|
410
|
+
const type = binary.asHex(binary.UINT(bits));
|
|
409
411
|
class Section extends binary.Class({
|
|
410
412
|
//data: binary.DontRead<binary.utils.MappedMemory>(),
|
|
411
413
|
sectname: fixed_string16,
|
|
@@ -424,7 +426,7 @@ function section(bits) {
|
|
|
424
426
|
data;
|
|
425
427
|
constructor(s) {
|
|
426
428
|
super(s);
|
|
427
|
-
const prot = this.flags.ATTRIBUTES.SYS.SOME_INSTRUCTIONS ? binary.MappedMemory.EXECUTE |
|
|
429
|
+
const prot = this.flags.ATTRIBUTES.SYS.SOME_INSTRUCTIONS ? binary.MappedMemory.EXECUTE | s.memflags : s.memflags;
|
|
428
430
|
this.data = (async () =>
|
|
429
431
|
//new binary.utils.MappedMemory(await s.file.get(BigInt(this.addr), Number(this.size)), Number(this.addr), prot)
|
|
430
432
|
new binary.MappedMemory(s.subdata(+this.offset, Number(this.size)), Number(this.addr), prot))();
|
|
@@ -439,7 +441,7 @@ const SEGMENT_FLAGS = {
|
|
|
439
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.
|
|
440
442
|
};
|
|
441
443
|
function segment(bits) {
|
|
442
|
-
const type = binary.UINT(bits);
|
|
444
|
+
const type = binary.asHex(binary.UINT(bits));
|
|
443
445
|
const fields = {
|
|
444
446
|
data: binary.DontRead(),
|
|
445
447
|
segname: fixed_string16, // segment name
|
|
@@ -458,7 +460,7 @@ function segment(bits) {
|
|
|
458
460
|
const o = binary.read(s, fields);
|
|
459
461
|
async function load() {
|
|
460
462
|
const data = await s.getmem(BigInt(Number(o.vmaddr)), Number(o.filesize)) ?? s.subdata(Number(o.fileoff), Number(o.filesize));
|
|
461
|
-
o.data = new binary.MappedMemory(data, Number(o.vmaddr), o.initprot |
|
|
463
|
+
o.data = new binary.MappedMemory(data, Number(o.vmaddr), o.initprot | s.memflags);
|
|
462
464
|
//const sect = section(bits);
|
|
463
465
|
if (o.nsects) {
|
|
464
466
|
o.sections = binary.objectWithNames(binary.ArrayType(o.nsects, section(bits)), binary.field('sectname')).get(s);
|
|
@@ -1006,7 +1008,7 @@ class MachFile {
|
|
|
1006
1008
|
file.skip(4);
|
|
1007
1009
|
for (let i = 0; i < h.ncmds; ++i) {
|
|
1008
1010
|
const cmd = binary.read(file, command);
|
|
1009
|
-
const file2 = new mach_stream(data, file.read_buffer(cmd.cmdsize - 8), file.be, mem);
|
|
1011
|
+
const file2 = new mach_stream(data, file.read_buffer(cmd.cmdsize - 8), file.be, h.filetype === 'EXECUTE' ? 0 : binary.MappedMemory.RELATIVE, mem);
|
|
1010
1012
|
const result = binary.read(file2, cmd_table[cmd.cmd] ?? {});
|
|
1011
1013
|
this.commands.push({ cmd: cmd.cmd, data: result });
|
|
1012
1014
|
}
|
|
@@ -1015,7 +1017,7 @@ class MachFile {
|
|
|
1015
1017
|
if (funcs) {
|
|
1016
1018
|
const array = funcs.contents;
|
|
1017
1019
|
const text = this.getSegment('__TEXT');
|
|
1018
|
-
let acc = BigInt(text?.vmaddr ?? 0);
|
|
1020
|
+
let acc = BigInt(text?.vmaddr.value ?? 0);
|
|
1019
1021
|
for (const i in array)
|
|
1020
1022
|
array[i] = (acc += BigInt(array[i]));
|
|
1021
1023
|
}
|
package/package.json
CHANGED