@isopodlabs/binary_libs 0.2.2 → 0.2.3
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/arch.d.ts +11 -19
- package/dist/clr.d.ts +398 -396
- package/dist/elf.d.ts +42 -2
- package/dist/elf.js +9 -8
- package/dist/mach.d.ts +402 -288
- package/dist/mach.js +33 -19
- package/dist/pe.d.ts +88 -86
- package/dist/pe.js +4 -4
- package/package.json +3 -3
package/dist/mach.js
CHANGED
|
@@ -424,7 +424,7 @@ function section(bits) {
|
|
|
424
424
|
data;
|
|
425
425
|
constructor(s) {
|
|
426
426
|
super(s);
|
|
427
|
-
const prot = this.flags.ATTRIBUTES.SYS.SOME_INSTRUCTIONS ?
|
|
427
|
+
const prot = this.flags.ATTRIBUTES.SYS.SOME_INSTRUCTIONS ? binary.MappedMemory.EXECUTE : binary.MappedMemory.NONE;
|
|
428
428
|
this.data = (async () =>
|
|
429
429
|
//new binary.utils.MappedMemory(await s.file.get(BigInt(this.addr), Number(this.size)), Number(this.addr), prot)
|
|
430
430
|
new binary.MappedMemory(s.subdata(+this.offset, Number(this.size)), Number(this.addr), prot))();
|
|
@@ -1038,10 +1038,31 @@ class MachFile {
|
|
|
1038
1038
|
}
|
|
1039
1039
|
exports.MachFile = MachFile;
|
|
1040
1040
|
const FAT_MAGIC = 0xcafebabe;
|
|
1041
|
-
const FAT_CIGAM = 0xbebafeca;
|
|
1042
1041
|
class FATMachFile {
|
|
1043
1042
|
archs = [];
|
|
1044
1043
|
static check(data) {
|
|
1044
|
+
return binary.UINT32_BE.get(new binary.stream(data)) === FAT_MAGIC;
|
|
1045
|
+
}
|
|
1046
|
+
constructor(data, mem) {
|
|
1047
|
+
const file = new binary.endianStream(data, true);
|
|
1048
|
+
const header = binary.read(file, fat_header);
|
|
1049
|
+
this.archs = header.archs;
|
|
1050
|
+
for (const arch of header.archs) {
|
|
1051
|
+
const cpu = CPU_TYPE[arch.cputype];
|
|
1052
|
+
const data = file.buffer_at(arch.offset, arch.size);
|
|
1053
|
+
arch.cpusubtype = binary.Enum(CPU_SUBTYPES[cpu])(+arch.cpusubtype);
|
|
1054
|
+
arch.contents = new MachFile(data, mem);
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
exports.FATMachFile = FATMachFile;
|
|
1059
|
+
/*
|
|
1060
|
+
const FAT_CIGAM = 0xbebafeca;
|
|
1061
|
+
|
|
1062
|
+
export class FATMachFile {
|
|
1063
|
+
archs: binary.ReadType<typeof fat_arch>[] = [];
|
|
1064
|
+
|
|
1065
|
+
static check(data: Uint8Array): boolean {
|
|
1045
1066
|
switch (binary.UINT32_BE.get(new binary.stream(data))) {
|
|
1046
1067
|
case FAT_MAGIC:
|
|
1047
1068
|
case FAT_CIGAM:
|
|
@@ -1050,33 +1071,26 @@ class FATMachFile {
|
|
|
1050
1071
|
return false;
|
|
1051
1072
|
}
|
|
1052
1073
|
}
|
|
1053
|
-
|
|
1074
|
+
|
|
1075
|
+
constructor(data: Uint8Array, mem?: binary.memory) {
|
|
1054
1076
|
switch (binary.UINT32_BE.get(new binary.stream(data))) {
|
|
1055
|
-
case FAT_MAGIC:
|
|
1056
|
-
|
|
1057
|
-
break;
|
|
1058
|
-
case FAT_CIGAM:
|
|
1059
|
-
this.load(new binary.endianStream(data, true), mem);
|
|
1060
|
-
break;
|
|
1077
|
+
case FAT_MAGIC: this.load(new binary.endianStream(data, false), mem); break;
|
|
1078
|
+
case FAT_CIGAM: this.load(new binary.endianStream(data, true), mem); break;
|
|
1061
1079
|
default:
|
|
1062
1080
|
throw new Error('not a fat mach file');
|
|
1063
1081
|
}
|
|
1064
1082
|
}
|
|
1065
|
-
|
|
1083
|
+
|
|
1084
|
+
load(file: binary.endianStream, mem?: binary.memory) {
|
|
1066
1085
|
const header = binary.read(file, fat_header);
|
|
1067
1086
|
this.archs = header.archs;
|
|
1068
1087
|
for (const arch of header.archs) {
|
|
1069
|
-
const cpu
|
|
1070
|
-
const data
|
|
1088
|
+
const cpu = CPU_TYPE[arch.cputype as keyof typeof CPU_TYPE];
|
|
1089
|
+
const data = file.buffer_at(arch.offset, arch. size);
|
|
1071
1090
|
arch.cpusubtype = binary.Enum(CPU_SUBTYPES[cpu])(+arch.cpusubtype);
|
|
1072
|
-
arch.contents
|
|
1091
|
+
arch.contents = new MachFile(data, mem);
|
|
1073
1092
|
}
|
|
1074
1093
|
}
|
|
1075
1094
|
}
|
|
1076
|
-
|
|
1077
|
-
/*
|
|
1078
|
-
export function freestanding<T extends CMD>(s: binary.stream, cmd: T) : binary.ReadType<typeof cmd_table[T]>;
|
|
1079
|
-
export function freestanding(s: binary.stream, cmd: CMD) {
|
|
1080
|
-
return binary.read(s, cmd_table[cmd]);
|
|
1081
|
-
}
|
|
1095
|
+
|
|
1082
1096
|
*/
|
package/dist/pe.d.ts
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
import * as binary from '@isopodlabs/binary';
|
|
2
|
+
declare const DOS_HEADER: {
|
|
3
|
+
magic: binary.TypeT<number>;
|
|
4
|
+
cblp: binary.TypeT<number>;
|
|
5
|
+
cp: binary.TypeT<number>;
|
|
6
|
+
crlc: binary.TypeT<number>;
|
|
7
|
+
cparhdr: binary.TypeT<number>;
|
|
8
|
+
minalloc: binary.TypeT<number>;
|
|
9
|
+
maxalloc: binary.TypeT<binary.hex<number | bigint>>;
|
|
10
|
+
ss: binary.TypeT<number>;
|
|
11
|
+
sp: binary.TypeT<number>;
|
|
12
|
+
csum: binary.TypeT<number>;
|
|
13
|
+
ip: binary.TypeT<number>;
|
|
14
|
+
cs: binary.TypeT<number>;
|
|
15
|
+
lfarlc: binary.TypeT<number>;
|
|
16
|
+
ovno: binary.TypeT<number>;
|
|
17
|
+
};
|
|
18
|
+
declare const EXE_HEADER: {
|
|
19
|
+
res: binary.TypeT<number[]>;
|
|
20
|
+
oemid: binary.TypeT<number>;
|
|
21
|
+
oeminfo: binary.TypeT<number>;
|
|
22
|
+
res2: binary.TypeT<number[]>;
|
|
23
|
+
lfanew: binary.TypeT<number>;
|
|
24
|
+
};
|
|
2
25
|
export declare class pe_stream extends binary.stream {
|
|
3
26
|
pe: PE;
|
|
4
27
|
constructor(pe: PE, data: Uint8Array);
|
|
@@ -31,95 +54,74 @@ export declare const DATA_DIRECTORY: {
|
|
|
31
54
|
VirtualAddress: binary.TypeT<number>;
|
|
32
55
|
Size: binary.TypeT<number>;
|
|
33
56
|
};
|
|
34
|
-
type Directory =
|
|
35
|
-
|
|
36
|
-
|
|
57
|
+
type Directory = binary.ReadType<typeof DATA_DIRECTORY>;
|
|
58
|
+
declare const OPTIONAL_HEADER: {
|
|
59
|
+
Magic: binary.TypeT<string>;
|
|
60
|
+
MajorLinkerVersion: binary.TypeT<number>;
|
|
61
|
+
MinorLinkerVersion: binary.TypeT<number>;
|
|
62
|
+
SizeOfCode: binary.TypeT<number>;
|
|
63
|
+
SizeOfInitializedData: binary.TypeT<number>;
|
|
64
|
+
SizeOfUninitializedData: binary.TypeT<number>;
|
|
65
|
+
AddressOfEntryPoint: binary.TypeT<binary.hex<number | bigint>>;
|
|
66
|
+
BaseOfCode: binary.TypeT<binary.hex<number | bigint>>;
|
|
67
|
+
};
|
|
68
|
+
declare const OPTIONAL_HEADER32: {
|
|
69
|
+
BaseOfData: binary.TypeT<binary.hex<number | bigint>>;
|
|
70
|
+
ImageBase: binary.TypeT<binary.hex<number | bigint>>;
|
|
71
|
+
SectionAlignment: binary.TypeT<number>;
|
|
72
|
+
FileAlignment: binary.TypeT<number>;
|
|
73
|
+
MajorOperatingSystemVersion: binary.TypeT<number>;
|
|
74
|
+
MinorOperatingSystemVersion: binary.TypeT<number>;
|
|
75
|
+
MajorImageVersion: binary.TypeT<number>;
|
|
76
|
+
MinorImageVersion: binary.TypeT<number>;
|
|
77
|
+
MajorSubsystemVersion: binary.TypeT<number>;
|
|
78
|
+
MinorSubsystemVersion: binary.TypeT<number>;
|
|
79
|
+
Win32VersionValue: binary.TypeT<number>;
|
|
80
|
+
SizeOfImage: binary.TypeT<number>;
|
|
81
|
+
SizeOfHeaders: binary.TypeT<number>;
|
|
82
|
+
CheckSum: binary.TypeT<number>;
|
|
83
|
+
Subsystem: binary.TypeT<number>;
|
|
84
|
+
DllCharacteristics: binary.TypeT<Record<string, bigint | boolean> | Record<string, number | boolean>>;
|
|
85
|
+
SizeOfStackReserve: binary.TypeT<number>;
|
|
86
|
+
SizeOfStackCommit: binary.TypeT<number>;
|
|
87
|
+
SizeOfHeapReserve: binary.TypeT<number>;
|
|
88
|
+
SizeOfHeapCommit: binary.TypeT<number>;
|
|
89
|
+
LoaderFlags: binary.TypeT<number>;
|
|
90
|
+
DataDirectory: binary.TypeT<Record<string, {
|
|
91
|
+
VirtualAddress: number;
|
|
92
|
+
Size: number;
|
|
93
|
+
}>>;
|
|
94
|
+
};
|
|
95
|
+
declare const OPTIONAL_HEADER64: {
|
|
96
|
+
ImageBase: binary.TypeT<binary.hex<number | bigint>>;
|
|
97
|
+
SectionAlignment: binary.TypeT<number>;
|
|
98
|
+
FileAlignment: binary.TypeT<number>;
|
|
99
|
+
MajorOperatingSystemVersion: binary.TypeT<number>;
|
|
100
|
+
MinorOperatingSystemVersion: binary.TypeT<number>;
|
|
101
|
+
MajorImageVersion: binary.TypeT<number>;
|
|
102
|
+
MinorImageVersion: binary.TypeT<number>;
|
|
103
|
+
MajorSubsystemVersion: binary.TypeT<number>;
|
|
104
|
+
MinorSubsystemVersion: binary.TypeT<number>;
|
|
105
|
+
Win32VersionValue: binary.TypeT<number>;
|
|
106
|
+
SizeOfImage: binary.TypeT<number>;
|
|
107
|
+
SizeOfHeaders: binary.TypeT<number>;
|
|
108
|
+
CheckSum: binary.TypeT<number>;
|
|
109
|
+
Subsystem: binary.TypeT<number>;
|
|
110
|
+
DllCharacteristics: binary.TypeT<Record<string, bigint | boolean> | Record<string, number | boolean>>;
|
|
111
|
+
SizeOfStackReserve: binary.TypeT<bigint>;
|
|
112
|
+
SizeOfStackCommit: binary.TypeT<bigint>;
|
|
113
|
+
SizeOfHeapReserve: binary.TypeT<bigint>;
|
|
114
|
+
SizeOfHeapCommit: binary.TypeT<bigint>;
|
|
115
|
+
LoaderFlags: binary.TypeT<number>;
|
|
116
|
+
DataDirectory: binary.TypeT<Record<string, {
|
|
117
|
+
VirtualAddress: number;
|
|
118
|
+
Size: number;
|
|
119
|
+
}>>;
|
|
37
120
|
};
|
|
38
121
|
export declare class PE {
|
|
39
122
|
static check(data: Uint8Array): boolean;
|
|
40
|
-
header:
|
|
41
|
-
|
|
42
|
-
cblp: number;
|
|
43
|
-
cp: number;
|
|
44
|
-
crlc: number;
|
|
45
|
-
cparhdr: number;
|
|
46
|
-
minalloc: number;
|
|
47
|
-
maxalloc: binary.hex<number | bigint>;
|
|
48
|
-
ss: number;
|
|
49
|
-
sp: number;
|
|
50
|
-
csum: number;
|
|
51
|
-
ip: number;
|
|
52
|
-
cs: number;
|
|
53
|
-
lfarlc: number;
|
|
54
|
-
ovno: number;
|
|
55
|
-
} & {
|
|
56
|
-
res: number[];
|
|
57
|
-
oemid: number;
|
|
58
|
-
oeminfo: number;
|
|
59
|
-
res2: number[];
|
|
60
|
-
lfanew: number;
|
|
61
|
-
};
|
|
62
|
-
opt?: {
|
|
63
|
-
Magic: string;
|
|
64
|
-
MajorLinkerVersion: number;
|
|
65
|
-
MinorLinkerVersion: number;
|
|
66
|
-
SizeOfCode: number;
|
|
67
|
-
SizeOfInitializedData: number;
|
|
68
|
-
SizeOfUninitializedData: number;
|
|
69
|
-
AddressOfEntryPoint: binary.hex<number | bigint>;
|
|
70
|
-
BaseOfCode: binary.hex<number | bigint>;
|
|
71
|
-
} & ({
|
|
72
|
-
BaseOfData: binary.hex<number | bigint>;
|
|
73
|
-
ImageBase: binary.hex<number | bigint>;
|
|
74
|
-
SectionAlignment: number;
|
|
75
|
-
FileAlignment: number;
|
|
76
|
-
MajorOperatingSystemVersion: number;
|
|
77
|
-
MinorOperatingSystemVersion: number;
|
|
78
|
-
MajorImageVersion: number;
|
|
79
|
-
MinorImageVersion: number;
|
|
80
|
-
MajorSubsystemVersion: number;
|
|
81
|
-
MinorSubsystemVersion: number;
|
|
82
|
-
Win32VersionValue: number;
|
|
83
|
-
SizeOfImage: number;
|
|
84
|
-
SizeOfHeaders: number;
|
|
85
|
-
CheckSum: number;
|
|
86
|
-
Subsystem: number;
|
|
87
|
-
DllCharacteristics: Record<string, bigint | boolean> | Record<string, number | boolean>;
|
|
88
|
-
SizeOfStackReserve: number;
|
|
89
|
-
SizeOfStackCommit: number;
|
|
90
|
-
SizeOfHeapReserve: number;
|
|
91
|
-
SizeOfHeapCommit: number;
|
|
92
|
-
LoaderFlags: number;
|
|
93
|
-
DataDirectory: Record<string, {
|
|
94
|
-
VirtualAddress: number;
|
|
95
|
-
Size: number;
|
|
96
|
-
}>;
|
|
97
|
-
} | {
|
|
98
|
-
ImageBase: binary.hex<number | bigint>;
|
|
99
|
-
SectionAlignment: number;
|
|
100
|
-
FileAlignment: number;
|
|
101
|
-
MajorOperatingSystemVersion: number;
|
|
102
|
-
MinorOperatingSystemVersion: number;
|
|
103
|
-
MajorImageVersion: number;
|
|
104
|
-
MinorImageVersion: number;
|
|
105
|
-
MajorSubsystemVersion: number;
|
|
106
|
-
MinorSubsystemVersion: number;
|
|
107
|
-
Win32VersionValue: number;
|
|
108
|
-
SizeOfImage: number;
|
|
109
|
-
SizeOfHeaders: number;
|
|
110
|
-
CheckSum: number;
|
|
111
|
-
Subsystem: number;
|
|
112
|
-
DllCharacteristics: Record<string, bigint | boolean> | Record<string, number | boolean>;
|
|
113
|
-
SizeOfStackReserve: bigint;
|
|
114
|
-
SizeOfStackCommit: bigint;
|
|
115
|
-
SizeOfHeapReserve: bigint;
|
|
116
|
-
SizeOfHeapCommit: bigint;
|
|
117
|
-
LoaderFlags: number;
|
|
118
|
-
DataDirectory: Record<string, {
|
|
119
|
-
VirtualAddress: number;
|
|
120
|
-
Size: number;
|
|
121
|
-
}>;
|
|
122
|
-
});
|
|
123
|
+
header: binary.ReadType<typeof DOS_HEADER> & binary.ReadType<typeof EXE_HEADER>;
|
|
124
|
+
opt?: binary.ReadType<typeof OPTIONAL_HEADER> & (binary.ReadType<typeof OPTIONAL_HEADER32> | binary.ReadType<typeof OPTIONAL_HEADER64>);
|
|
123
125
|
sections: Section[];
|
|
124
126
|
constructor(data: Uint8Array);
|
|
125
127
|
get directories(): Record<string, {
|
package/dist/pe.js
CHANGED
|
@@ -167,10 +167,10 @@ class Section extends binary.ReadClass({
|
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
169
|
get flags() {
|
|
170
|
-
return
|
|
171
|
-
| (this.Characteristics.MEM_READ ?
|
|
172
|
-
| (this.Characteristics.MEM_WRITE ?
|
|
173
|
-
| (this.Characteristics.MEM_EXECUTE ?
|
|
170
|
+
return binary.MappedMemory.RELATIVE
|
|
171
|
+
| (this.Characteristics.MEM_READ ? binary.MappedMemory.READ : 0)
|
|
172
|
+
| (this.Characteristics.MEM_WRITE ? binary.MappedMemory.WRITE : 0)
|
|
173
|
+
| (this.Characteristics.MEM_EXECUTE ? binary.MappedMemory.EXECUTE : 0);
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
exports.DIRECTORIES = {
|