@isopodlabs/binary_libs 0.1.5 → 0.2.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 CHANGED
@@ -9,16 +9,15 @@ This package provides readers for various library formats, using the @isopodlabs
9
9
  ELF
10
10
  ```typescript
11
11
  class ELFFile {
12
- segments: [string, any][];
13
- sections: [string, any][];
14
- symbols?: [string, any][];
15
- dynamic_symbols?: [string, any][];
16
- header: any;
17
12
  static check(data: Uint8Array): boolean;
18
- constructor(data: Uint8Array);
19
- getSymbols(type: binary.Type, data: Uint8Array, names: Uint8Array): [string, any][];
13
+ segments: [string, Segment][];
14
+ sections: [string, Section][];
15
+ header: Header;
16
+ getSymbols(): [string, Symbol][];
17
+ getDynamicSymbols(): [string, Symbol][];
18
+ getSegmentByType(type: string): Segment | undefined;
19
+ getSectionByType(type: string): Section | undefined;
20
20
  }
21
-
22
21
  ```
23
22
 
24
23
  ### pe
@@ -26,7 +25,9 @@ Portable Executable
26
25
  ```typescript
27
26
  class PE {
28
27
  static check(data: Uint8Array): boolean;
29
- constructor(data: Uint8Array);
28
+ header: Header;
29
+ opt?: OptHeader;
30
+ sections: Section[];
30
31
  get directories(): {
31
32
  [k: string]: any;
32
33
  } | undefined;
@@ -43,87 +44,51 @@ class PE {
43
44
  Common Language Runtime (embedded in pe files)
44
45
  ```typescript
45
46
  class CLR {
46
- header: any;
47
- table_info: any;
47
+ header: Header;
48
+ table_info: TableInfo;
48
49
  heaps: Uint8Array[];
49
50
  tables: Record<TABLE, Table>;
50
- raw?: Uint8Array;
51
51
  Resources?: Uint8Array;
52
- constructor(pe: pe.PE, clr_data: Uint8Array);
53
52
  getEntry(t: TABLE, i: number): any;
54
- getTable(t: TABLE.Module): ({ generation: number; name: string; mvid: string; encid: string; encbaseid: string; } & {})[];
55
- getTable(t: TABLE.TypeRef): ({ scope: number; name: string; namespce: string; } & {})[];
56
- getTable(t: TABLE.TypeDef): ({ flags: number; name: string; namespce: string; extends: number; fields: number; methods: number; } & {})[];
57
- getTable(t: TABLE.Field): ({ flags: number; name: string; signature: Uint8Array; } & {})[];
58
- getTable(t: TABLE.MethodDef): ({ code: number; implflags: number; flags: number; name: string; signature: Uint8Array; paramlist: number; } & {})[];
59
- getTable(t: TABLE.Param): ({ flags: number; sequence: number; name: string; } & {})[];
60
- getTable(t: TABLE.InterfaceImpl): ({ clss: number; interfce: number; } & {})[];
61
- getTable(t: TABLE.MemberRef): ({ clss: number; name: string; signature: Uint8Array; } & {})[];
62
- getTable(t: TABLE.Constant): ({ type: number; parent: number; value: Uint8Array; } & {})[];
63
- getTable(t: TABLE.CustomAttribute): ({ parent: number; type: number; value: Uint8Array; } & {})[];
64
- getTable(t: TABLE.FieldMarshal): ({ parent: number; native_type: Uint8Array; } & {})[];
65
- getTable(t: TABLE.DeclSecurity): ({ action: number; parent: number; permission_set: Uint8Array; } & {})[];
66
- getTable(t: TABLE.ClassLayout): ({ packing_size: number; class_size: number; parent: number; } & {})[];
67
- getTable(t: TABLE.FieldLayout): ({ offset: number; field: number; } & {})[];
68
- getTable(t: TABLE.StandAloneSig): ({ signature: Uint8Array; } & {})[];
69
- getTable(t: TABLE.EventMap): ({ parent: number; event_list: number; } & {})[];
70
- getTable(t: TABLE.Event): ({ flags: number; name: string; event_type: number; } & {})[];
71
- getTable(t: TABLE.PropertyMap): ({ parent: number; property_list: number; } & {})[];
72
- getTable(t: TABLE.Property): ({ flags: number; name: string; type: Uint8Array; } & {})[];
73
- getTable(t: TABLE.MethodSemantics): ({ flags: number; method: number; association: number; } & {})[];
74
- getTable(t: TABLE.MethodImpl): ({ clss: number; method_body: number; method_declaration: number; } & {})[];
75
- getTable(t: TABLE.ModuleRef): ({ name: string; } & {})[];
76
- getTable(t: TABLE.TypeSpec): ({ signature: Uint8Array; } & {})[];
77
- getTable(t: TABLE.ImplMap): ({ flags: number; member_forwarded: number; name: string; scope: number; } & {})[];
78
- getTable(t: TABLE.FieldRVA): ({ rva: number; field: number; } & {})[];
79
- getTable(t: TABLE.Assembly): ({ hashalg: number; major: number; minor: number; build: number; rev: number; flags: number; publickey: Uint8Array; name: string; culture: string; } & {})[];
80
- getTable(t: TABLE.AssemblyProcessor): ({ processor: number; } & {})[];
81
- getTable(t: TABLE.AssemblyOS): ({ platform: number; minor: number; major: number; } & {})[];
82
- getTable(t: TABLE.AssemblyRef): ({ major: number; minor: number; build: number; rev: number; flags: number; publickey: Uint8Array; name: string; culture: string; hashvalue: Uint8Array; } & {})[];
83
- getTable(t: TABLE.AssemblyRefProcessor): ({ processor: number; assembly: number; } & {})[];
84
- getTable(t: TABLE.AssemblyRefOS): ({ platform: number; major: number; minor: number; assembly: number; } & {})[];
85
- getTable(t: TABLE.File): ({ flags: number; name: string; hash: Uint8Array; } & {})[];
86
- getTable(t: TABLE.ExportedType): ({ flags: number; typedef_id: number; name: string; namespce: string; implementation: number; } & {})[];
87
- getTable(t: TABLE.ManifestResource): ({ data: number; flags: number; name: string; implementation: number; } & {})[];
88
- getTable(t: TABLE.NestedClass): ({ nested_class: number; enclosing_class: number; } & {})[];
89
- getTable(t: TABLE.GenericParam): ({ number: number; flags: number; owner: number; name: string; } & {})[];
90
- getTable(t: TABLE.MethodSpec): ({ method: number; instantiation: Uint8Array; } & {})[];
91
- getTable(t: TABLE.GenericParamConstraint): ({ owner: number; constraint: number; } & {})[];
53
+ getTable(t: TABLE): any;
92
54
  getResources(block: string): Record<string, any> | undefined;
93
55
  getResource(block: string, name: string): any;
94
- allResources(): {} | undefined;
56
+ allResources(): any;
95
57
  }
96
58
  ```
97
59
  ### mach
98
60
  Apple libraries
99
61
  ```typescript
100
- declare function segment(bits: 32 | 64): {
101
- get(s: mach_stream): Promise<{
102
- data: binary.utils.MappedMemory | undefined;
103
- segname: string;
104
- vmaddr: number | bigint;
105
- vmsize: number | bigint;
106
- fileoff: number | bigint;
107
- filesize: number | bigint;
108
- maxprot: number;
109
- initprot: number;
110
- nsects: number;
111
- flags: Record<string, bigint | boolean> | Record<string, number | boolean>;
112
- sections: Record<string, any> | undefined;
113
- } & {}>;
62
+ interface Segment {
63
+ data: binary.utils.MappedMemory | undefined;
64
+ segname: string;
65
+ vmaddr: number | bigint;
66
+ vmsize: number | bigint;
67
+ fileoff: number | bigint;
68
+ filesize: number | bigint;
69
+ maxprot: number;
70
+ initprot: number;
71
+ nsects: number;
72
+ flags: Record<string, bigint | boolean> | Record<string, number | boolean>;
73
+ sections: Record<string, any> | undefined;
114
74
  };
115
- export declare class MachFile {
116
- header: any;
117
- commands: { cmd: CMD; data: any; }[];
118
- ready: Promise<void>;
75
+ class MachFile {
119
76
  static check(data: Uint8Array): boolean;
77
+ header: Header;
78
+ commands: { cmd: CMD; data: any; }[];
120
79
  constructor(data: Uint8Array, mem?: binary.utils.memory);
121
- load(data: Uint8Array, be: boolean, bits: 32 | 64, mem?: binary.utils.memory): Promise<void>;
122
- getCommand(cmd: number): any;
123
- getSegment(name: string): Promise<{ data: binary.utils.MappedMemory | undefined; segname: string; vmaddr: number | bigint; vmsize: number | bigint; fileoff: number | bigint; filesize: number | bigint; maxprot: number; initprot: number; nsects: number; flags: Record<string, bigint | boolean> | Record<string, number | boolean>; sections: Record<string, any> | undefined; } & {}> | undefined;
80
+ getCommand(cmd: CMD): any;
81
+ getSegment(name: string): Segment;
124
82
  }
125
83
  class FATMachFile {
126
- archs: ({ cputype: string; cpusubtype: string | number; offset: number; size: number; align: number; contents: MachFile | undefined; } & {})[];
84
+ archs: {
85
+ cputype: string;
86
+ cpusubtype: string | number;
87
+ offset: number;
88
+ size: number;
89
+ align: number;
90
+ contents: MachFile | undefined;
91
+ }[];
127
92
  static check(data: Uint8Array): boolean;
128
93
  constructor(data: Uint8Array, mem?: binary.utils.memory);
129
94
  load(file: binary.stream_endian, mem?: binary.utils.memory): void;
@@ -134,19 +99,18 @@ class FATMachFile {
134
99
  Archive files for static linking
135
100
 
136
101
  ```typescript
137
- type HEADER = {
138
- name: string;
139
- date: number;
140
- uid: number;
141
- gid: number;
142
- mode: number;
143
- size: number;
144
- fmag: string;
145
- contents: any;
146
- };
147
102
  declare class ArchFile {
148
- members: HEADER[];
149
103
  static check(data: Uint8Array): boolean;
104
+ members: {
105
+ name: string;
106
+ date: number;
107
+ uid: number;
108
+ gid: number;
109
+ mode: number;
110
+ size: number;
111
+ fmag: string;
112
+ contents: any;
113
+ }[];
150
114
  constructor(data: Uint8Array);
151
115
  }
152
116
  ```
@@ -40,26 +40,7 @@ declare const Header_base: (new (s: binary._stream) => {
40
40
  } & {
41
41
  write(w: binary._stream): void;
42
42
  }) & {
43
- get: (s: binary._stream) => {
44
- magic: bigint;
45
- id: Uint8Array;
46
- revision: number;
47
- version: number;
48
- byteorder: number;
49
- sector_shift: number;
50
- mini_shift: number;
51
- unused1: void;
52
- num_directory: number;
53
- num_fat: number;
54
- first_directory: number;
55
- transaction: void;
56
- mini_cutoff: number;
57
- first_mini: number;
58
- num_mini: number;
59
- first_difat: number;
60
- num_difat: number;
61
- difat: Uint8Array;
62
- };
43
+ get: <X extends abstract new (...args: any) => any>(this: X, s: binary._stream) => InstanceType<X>;
63
44
  put: (s: binary._stream, v: any) => void;
64
45
  };
65
46
  export declare class Header extends Header_base {
@@ -85,22 +66,7 @@ declare const DirEntry_base: (new (s: binary._stream) => {
85
66
  } & {
86
67
  write(w: binary._stream): void;
87
68
  }) & {
88
- get: (s: binary._stream) => {
89
- name: string;
90
- name_size: number;
91
- type: number;
92
- colour: number;
93
- left: number;
94
- right: number;
95
- root: number;
96
- guid: Uint8Array;
97
- flags: number;
98
- creation: bigint;
99
- modification: bigint;
100
- sec_id: number;
101
- size: number;
102
- unused: number;
103
- };
69
+ get: <X extends abstract new (...args: any) => any>(this: X, s: binary._stream) => InstanceType<X>;
104
70
  put: (s: binary._stream, v: any) => void;
105
71
  };
106
72
  declare class DirEntry extends DirEntry_base {
package/dist/arch.d.ts CHANGED
@@ -10,6 +10,7 @@ export type HEADER = {
10
10
  contents: any;
11
11
  };
12
12
  export declare class ArchFile {
13
+ static check(data: Uint8Array): boolean;
13
14
  members: {
14
15
  name: string;
15
16
  date: number;
@@ -20,7 +21,6 @@ export declare class ArchFile {
20
21
  fmag: string;
21
22
  contents: any;
22
23
  }[];
23
- static check(data: Uint8Array): boolean;
24
24
  constructor(data: Uint8Array);
25
25
  }
26
26
  export {};
package/dist/arch.js CHANGED
@@ -43,10 +43,10 @@ const SYM64 = {
43
43
  offset: binary.asInt(binary.StringType(4))
44
44
  };
45
45
  class ArchFile {
46
- members = [];
47
46
  static check(data) {
48
47
  return binary.utils.decodeText(data.subarray(0, 8), 'utf8') == '!<arch>\n';
49
48
  }
49
+ members = [];
50
50
  constructor(data) {
51
51
  const s = new binary.stream(data);
52
52
  const header = binary.read(s, binary.StringType(8));
package/dist/clr.d.ts CHANGED
@@ -53,33 +53,237 @@ declare class clr_stream extends binary.stream {
53
53
  getGUID(): string;
54
54
  getBlob(): Uint8Array;
55
55
  }
56
- declare class Indexed {
57
- table: number;
58
- constructor(table: number);
59
- get(s: clr_stream): number;
60
- }
61
- declare class IndexedList extends Indexed {
62
- get(s: clr_stream): number;
63
- }
64
- declare class CodedIndex {
65
- trans: number[];
66
- B: number;
67
- constructor(trans: number[], B: number);
68
- get(s: clr_stream): number;
69
- }
70
56
  interface Table {
71
57
  count: number;
72
58
  size: number;
73
59
  offset: number;
74
60
  }
75
61
  export declare class CLR {
76
- header: any;
77
- table_info: any;
62
+ private raw?;
63
+ header: {
64
+ cb: number;
65
+ MajorRuntimeVersion: number;
66
+ MinorRuntimeVersion: number;
67
+ MetaData: never;
68
+ Flags: Record<string, bigint | boolean> | Record<string, number | boolean>;
69
+ EntryPoint: number;
70
+ Resources: never;
71
+ StrongNameSignature: never;
72
+ CodeManagerTable: never;
73
+ VTableFixups: never;
74
+ ExportAddressTableJumps: never;
75
+ };
76
+ table_info: {
77
+ Reserved: number;
78
+ MajorVersion: number;
79
+ MinorVersion: number;
80
+ HeapSizes: number;
81
+ Reserved2: number;
82
+ Valid: bigint;
83
+ Sorted: bigint;
84
+ } | undefined;
78
85
  heaps: Uint8Array[];
79
86
  tables: Record<TABLE, Table>;
80
- raw?: Uint8Array;
81
87
  Resources?: Uint8Array;
82
88
  constructor(pe: pe.PE, clr_data: Uint8Array);
89
+ getEntry(t: TABLE.Module, i: number): {
90
+ generation: number;
91
+ name: string;
92
+ mvid: string;
93
+ encid: string;
94
+ encbaseid: string;
95
+ };
96
+ getEntry(t: TABLE.TypeRef, i: number): {
97
+ scope: number;
98
+ name: string;
99
+ namespce: string;
100
+ };
101
+ getEntry(t: TABLE.TypeDef, i: number): {
102
+ flags: number;
103
+ name: string;
104
+ namespce: string;
105
+ extends: number;
106
+ fields: number;
107
+ methods: number;
108
+ };
109
+ getEntry(t: TABLE.Field, i: number): {
110
+ flags: number;
111
+ name: string;
112
+ signature: Uint8Array;
113
+ };
114
+ getEntry(t: TABLE.MethodDef, i: number): {
115
+ code: number;
116
+ implflags: number;
117
+ flags: number;
118
+ name: string;
119
+ signature: Uint8Array;
120
+ paramlist: number;
121
+ };
122
+ getEntry(t: TABLE.Param, i: number): {
123
+ flags: number;
124
+ sequence: number;
125
+ name: string;
126
+ };
127
+ getEntry(t: TABLE.InterfaceImpl, i: number): {
128
+ clss: number;
129
+ interfce: number;
130
+ };
131
+ getEntry(t: TABLE.MemberRef, i: number): {
132
+ clss: number;
133
+ name: string;
134
+ signature: Uint8Array;
135
+ };
136
+ getEntry(t: TABLE.Constant, i: number): {
137
+ type: number;
138
+ parent: number;
139
+ value: Uint8Array;
140
+ };
141
+ getEntry(t: TABLE.CustomAttribute, i: number): {
142
+ parent: number;
143
+ type: number;
144
+ value: Uint8Array;
145
+ };
146
+ getEntry(t: TABLE.FieldMarshal, i: number): {
147
+ parent: number;
148
+ native_type: Uint8Array;
149
+ };
150
+ getEntry(t: TABLE.DeclSecurity, i: number): {
151
+ action: number;
152
+ parent: number;
153
+ permission_set: Uint8Array;
154
+ };
155
+ getEntry(t: TABLE.ClassLayout, i: number): {
156
+ packing_size: number;
157
+ class_size: number;
158
+ parent: number;
159
+ };
160
+ getEntry(t: TABLE.FieldLayout, i: number): {
161
+ offset: number;
162
+ field: number;
163
+ };
164
+ getEntry(t: TABLE.StandAloneSig, i: number): {
165
+ signature: Uint8Array;
166
+ };
167
+ getEntry(t: TABLE.EventMap, i: number): {
168
+ parent: number;
169
+ event_list: number;
170
+ };
171
+ getEntry(t: TABLE.Event, i: number): {
172
+ flags: number;
173
+ name: string;
174
+ event_type: number;
175
+ };
176
+ getEntry(t: TABLE.PropertyMap, i: number): {
177
+ parent: number;
178
+ property_list: number;
179
+ };
180
+ getEntry(t: TABLE.Property, i: number): {
181
+ flags: number;
182
+ name: string;
183
+ type: Uint8Array;
184
+ };
185
+ getEntry(t: TABLE.MethodSemantics, i: number): {
186
+ flags: number;
187
+ method: number;
188
+ association: number;
189
+ };
190
+ getEntry(t: TABLE.MethodImpl, i: number): {
191
+ clss: number;
192
+ method_body: number;
193
+ method_declaration: number;
194
+ };
195
+ getEntry(t: TABLE.ModuleRef, i: number): {
196
+ name: string;
197
+ };
198
+ getEntry(t: TABLE.TypeSpec, i: number): {
199
+ signature: Uint8Array;
200
+ };
201
+ getEntry(t: TABLE.ImplMap, i: number): {
202
+ flags: number;
203
+ member_forwarded: number;
204
+ name: string;
205
+ scope: number;
206
+ };
207
+ getEntry(t: TABLE.FieldRVA, i: number): {
208
+ rva: number;
209
+ field: number;
210
+ };
211
+ getEntry(t: TABLE.Assembly, i: number): {
212
+ hashalg: number;
213
+ major: number;
214
+ minor: number;
215
+ build: number;
216
+ rev: number;
217
+ flags: number;
218
+ publickey: Uint8Array;
219
+ name: string;
220
+ culture: string;
221
+ };
222
+ getEntry(t: TABLE.AssemblyProcessor, i: number): {
223
+ processor: number;
224
+ };
225
+ getEntry(t: TABLE.AssemblyOS, i: number): {
226
+ platform: number;
227
+ minor: number;
228
+ major: number;
229
+ };
230
+ getEntry(t: TABLE.AssemblyRef, i: number): {
231
+ major: number;
232
+ minor: number;
233
+ build: number;
234
+ rev: number;
235
+ flags: number;
236
+ publickey: Uint8Array;
237
+ name: string;
238
+ culture: string;
239
+ hashvalue: Uint8Array;
240
+ };
241
+ getEntry(t: TABLE.AssemblyRefProcessor, i: number): {
242
+ processor: number;
243
+ assembly: number;
244
+ };
245
+ getEntry(t: TABLE.AssemblyRefOS, i: number): {
246
+ platform: number;
247
+ major: number;
248
+ minor: number;
249
+ assembly: number;
250
+ };
251
+ getEntry(t: TABLE.File, i: number): {
252
+ flags: number;
253
+ name: string;
254
+ hash: Uint8Array;
255
+ };
256
+ getEntry(t: TABLE.ExportedType, i: number): {
257
+ flags: number;
258
+ typedef_id: number;
259
+ name: string;
260
+ namespce: string;
261
+ implementation: number;
262
+ };
263
+ getEntry(t: TABLE.ManifestResource, i: number): {
264
+ data: number;
265
+ flags: number;
266
+ name: string;
267
+ implementation: number;
268
+ };
269
+ getEntry(t: TABLE.NestedClass, i: number): {
270
+ nested_class: number;
271
+ enclosing_class: number;
272
+ };
273
+ getEntry(t: TABLE.GenericParam, i: number): {
274
+ number: number;
275
+ flags: number;
276
+ owner: number;
277
+ name: string;
278
+ };
279
+ getEntry(t: TABLE.MethodSpec, i: number): {
280
+ method: number;
281
+ instantiation: Uint8Array;
282
+ };
283
+ getEntry(t: TABLE.GenericParamConstraint, i: number): {
284
+ owner: number;
285
+ constraint: number;
286
+ };
83
287
  getEntry(t: TABLE, i: number): any;
84
288
  getTable(t: TABLE.Module): {
85
289
  generation: number;
@@ -279,8 +483,9 @@ export declare class CLR {
279
483
  owner: number;
280
484
  constraint: number;
281
485
  }[];
486
+ getTable(t: TABLE): any;
282
487
  getResources(block: string): Record<string, any> | undefined;
283
488
  getResource(block: string, name: string): any;
284
- allResources(): {} | undefined;
489
+ allResources(): any;
285
490
  }
286
491
  export {};
package/dist/clr.js CHANGED
@@ -222,278 +222,236 @@ const clr_Blob = {
222
222
  const Signature = clr_Blob;
223
223
  const CustomAttributeValue = clr_Blob;
224
224
  const clr_Code = binary.UINT32_LE;
225
- class Indexed {
226
- table;
227
- constructor(table) {
228
- this.table = table;
229
- }
230
- get(s) { return s.getIndex(this.table); }
225
+ function Indexed(table) {
226
+ return {
227
+ get(s) { return s.getIndex(table); }
228
+ };
231
229
  }
232
- class IndexedList extends Indexed {
233
- get(s) { return s.getIndex(this.table); }
230
+ function IndexedList(table) {
231
+ return {
232
+ get(s) { return s.getIndex(table); }
233
+ };
234
234
  }
235
- class CodedIndex {
236
- trans;
237
- B;
238
- constructor(trans, B) {
239
- this.trans = trans;
240
- this.B = B;
241
- }
242
- get(s) { return s.getCodedIndex(this.B, this.trans); }
235
+ function CodedIndex(trans, B) {
236
+ return {
237
+ get(s) { return s.getCodedIndex(B, trans); }
238
+ };
243
239
  }
244
- const TypeDefOrRef = new CodedIndex([TABLE.TypeDef, TABLE.TypeRef, TABLE.TypeSpec], 2);
245
- const HasConstant = new CodedIndex([TABLE.Field, TABLE.Param, TABLE.Property], 2);
246
- const HasCustomAttribute = new CodedIndex([
240
+ const TypeDefOrRef = CodedIndex([TABLE.TypeDef, TABLE.TypeRef, TABLE.TypeSpec], 2);
241
+ const HasConstant = CodedIndex([TABLE.Field, TABLE.Param, TABLE.Property], 2);
242
+ const HasCustomAttribute = CodedIndex([
247
243
  TABLE.MethodDef, TABLE.Field, TABLE.TypeRef, TABLE.TypeDef, TABLE.Param, TABLE.InterfaceImpl, TABLE.MemberRef, TABLE.Module, TABLE.DeclSecurity, TABLE.Property, TABLE.Event, TABLE.StandAloneSig,
248
244
  TABLE.ModuleRef, TABLE.TypeSpec, TABLE.Assembly, TABLE.AssemblyRef, TABLE.File, TABLE.ExportedType, TABLE.ManifestResource, TABLE.GenericParam, TABLE.GenericParamConstraint, TABLE.MethodSpec,
249
245
  ], 5);
250
- const HasFieldMarshall = new CodedIndex([TABLE.Field, TABLE.Param], 1);
251
- const HasDeclSecurity = new CodedIndex([TABLE.TypeDef, TABLE.MethodDef, TABLE.Assembly], 2);
252
- const MemberRefParent = new CodedIndex([TABLE.TypeDef, TABLE.TypeRef, TABLE.ModuleRef, TABLE.MethodDef, TABLE.TypeSpec], 1);
253
- const HasSemantics = new CodedIndex([TABLE.Event, TABLE.Property], 1);
254
- const MethodDefOrRef = new CodedIndex([TABLE.MethodDef, TABLE.MemberRef], 1);
255
- const MemberForwarded = new CodedIndex([TABLE.Field, TABLE.MethodDef], 1);
256
- const Implementation = new CodedIndex([TABLE.File, TABLE.AssemblyRef, TABLE.ExportedType], 2);
257
- const CustomAttributeType = new CodedIndex([0, 0, TABLE.MethodDef, TABLE.MemberRef], 3);
258
- const TypeOrMethodDef = new CodedIndex([TABLE.TypeDef, TABLE.MethodDef], 1);
259
- const ResolutionScope = new CodedIndex([TABLE.Module, TABLE.ModuleRef, TABLE.AssemblyRef, TABLE.TypeRef], 2);
260
- const ENTRY_Module = {
261
- generation: binary.UINT16_LE,
262
- name: clr_String,
263
- mvid: clr_GUID,
264
- encid: clr_GUID,
265
- encbaseid: clr_GUID,
266
- };
267
- const ENTRY_TypeRef = {
268
- scope: ResolutionScope,
269
- name: clr_String,
270
- namespce: clr_String,
271
- };
272
- const ENTRY_TypeDef = {
273
- flags: binary.UINT32_LE,
274
- name: clr_String,
275
- namespce: clr_String,
276
- extends: TypeDefOrRef,
277
- fields: new IndexedList(TABLE.Field),
278
- methods: new IndexedList(TABLE.MethodDef),
279
- };
280
- const ENTRY_Field = {
281
- flags: binary.UINT16_LE,
282
- name: clr_String,
283
- signature: Signature,
284
- };
285
- const ENTRY_MethodDef = {
286
- code: clr_Code,
287
- implflags: binary.UINT16_LE,
288
- flags: binary.UINT16_LE,
289
- name: clr_String,
290
- signature: Signature,
291
- paramlist: new IndexedList(TABLE.Param),
292
- };
293
- const ENTRY_Param = {
294
- flags: binary.UINT16_LE,
295
- sequence: binary.UINT16_LE,
296
- name: clr_String,
297
- };
298
- const ENTRY_InterfaceImpl = {
299
- clss: new Indexed(TABLE.TypeDef),
300
- interfce: TypeDefOrRef,
301
- };
302
- const ENTRY_MemberRef = {
303
- clss: MemberRefParent,
304
- name: clr_String,
305
- signature: Signature,
306
- };
307
- const ENTRY_Constant = {
308
- type: binary.UINT16_LE,
309
- parent: HasConstant,
310
- value: clr_Blob,
311
- };
312
- const ENTRY_CustomAttribute = {
313
- parent: HasCustomAttribute,
314
- type: CustomAttributeType,
315
- value: CustomAttributeValue,
316
- };
317
- const ENTRY_FieldMarshal = {
318
- parent: HasFieldMarshall,
319
- native_type: clr_Blob,
320
- };
321
- const ENTRY_DeclSecurity = {
322
- action: binary.UINT16_LE,
323
- parent: HasDeclSecurity,
324
- permission_set: clr_Blob,
325
- };
326
- const ENTRY_ClassLayout = {
327
- packing_size: binary.UINT16_LE,
328
- class_size: binary.UINT32_LE,
329
- parent: new Indexed(TABLE.TypeDef),
330
- };
331
- const ENTRY_FieldLayout = {
332
- offset: binary.UINT32_LE,
333
- field: new Indexed(TABLE.Field),
334
- };
335
- const ENTRY_StandAloneSig = {
336
- signature: Signature,
337
- };
338
- const ENTRY_EventMap = {
339
- parent: new Indexed(TABLE.TypeDef),
340
- event_list: new IndexedList(TABLE.Event),
341
- };
342
- const ENTRY_Event = {
343
- flags: binary.UINT16_LE,
344
- name: clr_String,
345
- event_type: TypeDefOrRef,
346
- };
347
- const ENTRY_PropertyMap = {
348
- parent: new Indexed(TABLE.TypeDef),
349
- property_list: new IndexedList(TABLE.Property),
350
- };
351
- const ENTRY_Property = {
352
- flags: binary.UINT16_LE,
353
- name: clr_String,
354
- type: Signature,
355
- };
356
- const ENTRY_MethodSemantics = {
357
- flags: binary.UINT16_LE,
358
- method: new Indexed(TABLE.MethodDef),
359
- association: HasSemantics,
360
- };
361
- const ENTRY_MethodImpl = {
362
- clss: new Indexed(TABLE.TypeDef),
363
- method_body: MethodDefOrRef,
364
- method_declaration: MethodDefOrRef,
365
- };
366
- const ENTRY_ModuleRef = {
367
- name: clr_String,
368
- };
369
- const ENTRY_TypeSpec = {
370
- signature: clr_Blob,
371
- };
372
- const ENTRY_ImplMap = {
373
- flags: binary.UINT16_LE,
374
- member_forwarded: MemberForwarded,
375
- name: clr_String,
376
- scope: new Indexed(TABLE.ModuleRef),
377
- };
378
- const ENTRY_FieldRVA = {
379
- rva: binary.UINT32_LE,
380
- field: new Indexed(TABLE.Field),
381
- };
382
- const ENTRY_Assembly = {
383
- hashalg: binary.UINT32_LE,
384
- major: binary.UINT16_LE,
385
- minor: binary.UINT16_LE,
386
- build: binary.UINT16_LE,
387
- rev: binary.UINT16_LE,
388
- flags: binary.UINT32_LE,
389
- publickey: clr_Blob,
390
- name: clr_String,
391
- culture: clr_String,
392
- };
393
- const ENTRY_AssemblyProcessor = {
394
- processor: binary.UINT32_LE,
395
- };
396
- const ENTRY_AssemblyOS = {
397
- platform: binary.UINT32_LE,
398
- minor: binary.UINT32_LE,
399
- major: binary.UINT32_LE,
400
- };
401
- const ENTRY_AssemblyRef = {
402
- major: binary.UINT16_LE,
403
- minor: binary.UINT16_LE,
404
- build: binary.UINT16_LE,
405
- rev: binary.UINT16_LE,
406
- flags: binary.UINT32_LE,
407
- publickey: clr_Blob,
408
- name: clr_String,
409
- culture: clr_String,
410
- hashvalue: clr_Blob,
411
- };
412
- const ENTRY_AssemblyRefProcessor = {
413
- processor: binary.UINT32_LE,
414
- assembly: new Indexed(TABLE.AssemblyRef),
415
- };
416
- const ENTRY_AssemblyRefOS = {
417
- platform: binary.UINT32_LE,
418
- major: binary.UINT32_LE,
419
- minor: binary.UINT32_LE,
420
- assembly: new Indexed(TABLE.AssemblyRef),
421
- };
422
- const ENTRY_File = {
423
- flags: binary.UINT32_LE,
424
- name: clr_String,
425
- hash: clr_Blob,
426
- };
427
- const ENTRY_ExportedType = {
428
- flags: binary.UINT32_LE,
429
- typedef_id: binary.UINT32_LE, //(a 4-byte index into a TypeDef table of another module in this Assembly).
430
- name: clr_String,
431
- namespce: clr_String,
432
- implementation: Implementation,
433
- };
434
- const ENTRY_ManifestResource = {
435
- data: binary.UINT32_LE,
436
- flags: binary.UINT32_LE,
437
- name: clr_String,
438
- implementation: Implementation,
439
- };
440
- const ENTRY_NestedClass = {
441
- nested_class: new Indexed(TABLE.TypeDef),
442
- enclosing_class: new Indexed(TABLE.TypeDef),
443
- };
444
- const ENTRY_GenericParam = {
445
- number: binary.UINT16_LE,
446
- flags: binary.UINT16_LE,
447
- owner: TypeOrMethodDef,
448
- name: clr_String,
449
- };
450
- const ENTRY_MethodSpec = {
451
- method: MethodDefOrRef,
452
- instantiation: Signature,
453
- };
454
- const ENTRY_GenericParamConstraint = {
455
- owner: new Indexed(TABLE.GenericParam),
456
- constraint: TypeDefOrRef,
457
- };
246
+ const HasFieldMarshall = CodedIndex([TABLE.Field, TABLE.Param], 1);
247
+ const HasDeclSecurity = CodedIndex([TABLE.TypeDef, TABLE.MethodDef, TABLE.Assembly], 2);
248
+ const MemberRefParent = CodedIndex([TABLE.TypeDef, TABLE.TypeRef, TABLE.ModuleRef, TABLE.MethodDef, TABLE.TypeSpec], 1);
249
+ const HasSemantics = CodedIndex([TABLE.Event, TABLE.Property], 1);
250
+ const MethodDefOrRef = CodedIndex([TABLE.MethodDef, TABLE.MemberRef], 1);
251
+ const MemberForwarded = CodedIndex([TABLE.Field, TABLE.MethodDef], 1);
252
+ const Implementation = CodedIndex([TABLE.File, TABLE.AssemblyRef, TABLE.ExportedType], 2);
253
+ const CustomAttributeType = CodedIndex([0, 0, TABLE.MethodDef, TABLE.MemberRef], 3);
254
+ const TypeOrMethodDef = CodedIndex([TABLE.TypeDef, TABLE.MethodDef], 1);
255
+ const ResolutionScope = CodedIndex([TABLE.Module, TABLE.ModuleRef, TABLE.AssemblyRef, TABLE.TypeRef], 2);
458
256
  const TableReaders = {
459
- [TABLE.Module]: ENTRY_Module,
460
- [TABLE.TypeRef]: ENTRY_TypeRef,
461
- [TABLE.TypeDef]: ENTRY_TypeDef,
462
- [TABLE.Field]: ENTRY_Field,
463
- [TABLE.MethodDef]: ENTRY_MethodDef,
464
- [TABLE.Param]: ENTRY_Param,
465
- [TABLE.InterfaceImpl]: ENTRY_InterfaceImpl,
466
- [TABLE.MemberRef]: ENTRY_MemberRef,
467
- [TABLE.Constant]: ENTRY_Constant,
468
- [TABLE.CustomAttribute]: ENTRY_CustomAttribute,
469
- [TABLE.FieldMarshal]: ENTRY_FieldMarshal,
470
- [TABLE.DeclSecurity]: ENTRY_DeclSecurity,
471
- [TABLE.ClassLayout]: ENTRY_ClassLayout,
472
- [TABLE.FieldLayout]: ENTRY_FieldLayout,
473
- [TABLE.StandAloneSig]: ENTRY_StandAloneSig,
474
- [TABLE.EventMap]: ENTRY_EventMap,
475
- [TABLE.Event]: ENTRY_Event,
476
- [TABLE.PropertyMap]: ENTRY_PropertyMap,
477
- [TABLE.Property]: ENTRY_Property,
478
- [TABLE.MethodSemantics]: ENTRY_MethodSemantics,
479
- [TABLE.MethodImpl]: ENTRY_MethodImpl,
480
- [TABLE.ModuleRef]: ENTRY_ModuleRef,
481
- [TABLE.TypeSpec]: ENTRY_TypeSpec,
482
- [TABLE.ImplMap]: ENTRY_ImplMap,
483
- [TABLE.FieldRVA]: ENTRY_FieldRVA,
484
- [TABLE.Assembly]: ENTRY_Assembly,
485
- [TABLE.AssemblyProcessor]: ENTRY_AssemblyProcessor,
486
- [TABLE.AssemblyOS]: ENTRY_AssemblyOS,
487
- [TABLE.AssemblyRef]: ENTRY_AssemblyRef,
488
- [TABLE.AssemblyRefProcessor]: ENTRY_AssemblyRefProcessor,
489
- [TABLE.AssemblyRefOS]: ENTRY_AssemblyRefOS,
490
- [TABLE.File]: ENTRY_File,
491
- [TABLE.ExportedType]: ENTRY_ExportedType,
492
- [TABLE.ManifestResource]: ENTRY_ManifestResource,
493
- [TABLE.NestedClass]: ENTRY_NestedClass,
494
- [TABLE.GenericParam]: ENTRY_GenericParam,
495
- [TABLE.MethodSpec]: ENTRY_MethodSpec,
496
- [TABLE.GenericParamConstraint]: ENTRY_GenericParamConstraint,
257
+ [TABLE.Module]: {
258
+ generation: binary.UINT16_LE,
259
+ name: clr_String,
260
+ mvid: clr_GUID,
261
+ encid: clr_GUID,
262
+ encbaseid: clr_GUID,
263
+ },
264
+ [TABLE.TypeRef]: {
265
+ scope: ResolutionScope,
266
+ name: clr_String,
267
+ namespce: clr_String,
268
+ },
269
+ [TABLE.TypeDef]: {
270
+ flags: binary.UINT32_LE,
271
+ name: clr_String,
272
+ namespce: clr_String,
273
+ extends: TypeDefOrRef,
274
+ fields: IndexedList(TABLE.Field),
275
+ methods: IndexedList(TABLE.MethodDef),
276
+ },
277
+ [TABLE.Field]: {
278
+ flags: binary.UINT16_LE,
279
+ name: clr_String,
280
+ signature: Signature,
281
+ },
282
+ [TABLE.MethodDef]: {
283
+ code: clr_Code,
284
+ implflags: binary.UINT16_LE,
285
+ flags: binary.UINT16_LE,
286
+ name: clr_String,
287
+ signature: Signature,
288
+ paramlist: IndexedList(TABLE.Param),
289
+ },
290
+ [TABLE.Param]: {
291
+ flags: binary.UINT16_LE,
292
+ sequence: binary.UINT16_LE,
293
+ name: clr_String,
294
+ },
295
+ [TABLE.InterfaceImpl]: {
296
+ clss: Indexed(TABLE.TypeDef),
297
+ interfce: TypeDefOrRef,
298
+ },
299
+ [TABLE.MemberRef]: {
300
+ clss: MemberRefParent,
301
+ name: clr_String,
302
+ signature: Signature,
303
+ },
304
+ [TABLE.Constant]: {
305
+ type: binary.UINT16_LE,
306
+ parent: HasConstant,
307
+ value: clr_Blob,
308
+ },
309
+ [TABLE.CustomAttribute]: {
310
+ parent: HasCustomAttribute,
311
+ type: CustomAttributeType,
312
+ value: CustomAttributeValue,
313
+ },
314
+ [TABLE.FieldMarshal]: {
315
+ parent: HasFieldMarshall,
316
+ native_type: clr_Blob,
317
+ },
318
+ [TABLE.DeclSecurity]: {
319
+ action: binary.UINT16_LE,
320
+ parent: HasDeclSecurity,
321
+ permission_set: clr_Blob,
322
+ },
323
+ [TABLE.ClassLayout]: {
324
+ packing_size: binary.UINT16_LE,
325
+ class_size: binary.UINT32_LE,
326
+ parent: Indexed(TABLE.TypeDef),
327
+ },
328
+ [TABLE.FieldLayout]: {
329
+ offset: binary.UINT32_LE,
330
+ field: Indexed(TABLE.Field),
331
+ },
332
+ [TABLE.StandAloneSig]: {
333
+ signature: Signature,
334
+ },
335
+ [TABLE.EventMap]: {
336
+ parent: Indexed(TABLE.TypeDef),
337
+ event_list: IndexedList(TABLE.Event),
338
+ },
339
+ [TABLE.Event]: {
340
+ flags: binary.UINT16_LE,
341
+ name: clr_String,
342
+ event_type: TypeDefOrRef,
343
+ },
344
+ [TABLE.PropertyMap]: {
345
+ parent: Indexed(TABLE.TypeDef),
346
+ property_list: IndexedList(TABLE.Property),
347
+ },
348
+ [TABLE.Property]: {
349
+ flags: binary.UINT16_LE,
350
+ name: clr_String,
351
+ type: Signature,
352
+ },
353
+ [TABLE.MethodSemantics]: {
354
+ flags: binary.UINT16_LE,
355
+ method: Indexed(TABLE.MethodDef),
356
+ association: HasSemantics,
357
+ },
358
+ [TABLE.MethodImpl]: {
359
+ clss: Indexed(TABLE.TypeDef),
360
+ method_body: MethodDefOrRef,
361
+ method_declaration: MethodDefOrRef,
362
+ },
363
+ [TABLE.ModuleRef]: {
364
+ name: clr_String,
365
+ },
366
+ [TABLE.TypeSpec]: {
367
+ signature: clr_Blob,
368
+ },
369
+ [TABLE.ImplMap]: {
370
+ flags: binary.UINT16_LE,
371
+ member_forwarded: MemberForwarded,
372
+ name: clr_String,
373
+ scope: Indexed(TABLE.ModuleRef),
374
+ },
375
+ [TABLE.FieldRVA]: {
376
+ rva: binary.UINT32_LE,
377
+ field: Indexed(TABLE.Field),
378
+ },
379
+ [TABLE.Assembly]: {
380
+ hashalg: binary.UINT32_LE,
381
+ major: binary.UINT16_LE,
382
+ minor: binary.UINT16_LE,
383
+ build: binary.UINT16_LE,
384
+ rev: binary.UINT16_LE,
385
+ flags: binary.UINT32_LE,
386
+ publickey: clr_Blob,
387
+ name: clr_String,
388
+ culture: clr_String,
389
+ },
390
+ [TABLE.AssemblyProcessor]: {
391
+ processor: binary.UINT32_LE,
392
+ },
393
+ [TABLE.AssemblyOS]: {
394
+ platform: binary.UINT32_LE,
395
+ minor: binary.UINT32_LE,
396
+ major: binary.UINT32_LE,
397
+ },
398
+ [TABLE.AssemblyRef]: {
399
+ major: binary.UINT16_LE,
400
+ minor: binary.UINT16_LE,
401
+ build: binary.UINT16_LE,
402
+ rev: binary.UINT16_LE,
403
+ flags: binary.UINT32_LE,
404
+ publickey: clr_Blob,
405
+ name: clr_String,
406
+ culture: clr_String,
407
+ hashvalue: clr_Blob,
408
+ },
409
+ [TABLE.AssemblyRefProcessor]: {
410
+ processor: binary.UINT32_LE,
411
+ assembly: Indexed(TABLE.AssemblyRef),
412
+ },
413
+ [TABLE.AssemblyRefOS]: {
414
+ platform: binary.UINT32_LE,
415
+ major: binary.UINT32_LE,
416
+ minor: binary.UINT32_LE,
417
+ assembly: Indexed(TABLE.AssemblyRef),
418
+ },
419
+ [TABLE.File]: {
420
+ flags: binary.UINT32_LE,
421
+ name: clr_String,
422
+ hash: clr_Blob,
423
+ },
424
+ [TABLE.ExportedType]: {
425
+ flags: binary.UINT32_LE,
426
+ typedef_id: binary.UINT32_LE, //(a 4-byte index into a TypeDef table of another module in this Assembly).
427
+ name: clr_String,
428
+ namespce: clr_String,
429
+ implementation: Implementation,
430
+ },
431
+ [TABLE.ManifestResource]: {
432
+ data: binary.UINT32_LE,
433
+ flags: binary.UINT32_LE,
434
+ name: clr_String,
435
+ implementation: Implementation,
436
+ },
437
+ [TABLE.NestedClass]: {
438
+ nested_class: Indexed(TABLE.TypeDef),
439
+ enclosing_class: Indexed(TABLE.TypeDef),
440
+ },
441
+ [TABLE.GenericParam]: {
442
+ number: binary.UINT16_LE,
443
+ flags: binary.UINT16_LE,
444
+ owner: TypeOrMethodDef,
445
+ name: clr_String,
446
+ },
447
+ [TABLE.MethodSpec]: {
448
+ method: MethodDefOrRef,
449
+ instantiation: Signature,
450
+ },
451
+ [TABLE.GenericParamConstraint]: {
452
+ owner: Indexed(TABLE.GenericParam),
453
+ constraint: TypeDefOrRef,
454
+ },
497
455
  };
498
456
  const ResourceManagerHeader = {
499
457
  magic: binary.UINT32_LE,
@@ -512,22 +470,12 @@ const ResourceEntry = {
512
470
  offset: binary.UINT32_LE,
513
471
  };
514
472
  class CLR {
473
+ raw;
515
474
  header;
516
475
  table_info;
517
476
  heaps = [];
518
477
  tables;
519
- raw;
520
478
  Resources;
521
- /*
522
- static async load(dll: string) {
523
- const p = await pe.PE.load(dll);
524
- if (p) {
525
- const clr_data = p.GetDataDir(p.opt.DataDirectory.CLR_DESCRIPTOR);
526
- if (clr_data)
527
- return new CLR(p, clr_data);
528
- }
529
- }
530
- */
531
479
  constructor(pe, clr_data) {
532
480
  this.header = binary.read(new binary.stream(clr_data), CLR_HEADER);
533
481
  const meta_data = pe.GetDataDir(this.header.MetaData);
package/dist/elf.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import * as binary from '@isopodlabs/binary';
2
2
  export declare class ELFFile {
3
+ static check(data: Uint8Array): boolean;
3
4
  segments: [string, {
4
5
  data: binary.MappedMemory;
5
6
  p_type: string;
@@ -39,7 +40,6 @@ export declare class ELFFile {
39
40
  e_shnum: number;
40
41
  e_shstrndx: number;
41
42
  };
42
- static check(data: Uint8Array): boolean;
43
43
  getDynamic: () => {
44
44
  d_tag: string;
45
45
  d_val: number | bigint;
package/dist/elf.js CHANGED
@@ -47,7 +47,7 @@ const Ident = {
47
47
  file_class: binary.asEnum(binary.UINT8, CLASS),
48
48
  encoding: binary.asEnum(binary.UINT8, DATA),
49
49
  version: binary.UINT8,
50
- _: binary.If(obj => obj.file_class === 'CLASS64', {
50
+ _: binary.If(s => s.obj.file_class === 'CLASS64', {
51
51
  //64 bit only
52
52
  osabi: binary.asEnum(binary.UINT8, OSABI),
53
53
  abiversion: binary.UINT8,
@@ -616,12 +616,12 @@ function readDataAs(data, type) {
616
616
  return binary.RemainingArrayType(type).get(new binary.stream(data.data));
617
617
  }
618
618
  class ELFFile {
619
- segments;
620
- sections;
621
- header;
622
619
  static check(data) {
623
620
  return binary.utils.decodeText(data.subarray(0, 4), 'utf8') === '\x7fELF';
624
621
  }
622
+ segments;
623
+ sections;
624
+ header;
625
625
  getDynamic;
626
626
  getRel;
627
627
  getRelA;
package/dist/mach.d.ts CHANGED
@@ -61,15 +61,19 @@ export declare enum CMD {
61
61
  DYLD_CHAINED_FIXUPS = 2147483700
62
62
  }
63
63
  export declare class MachFile {
64
- header: any;
65
- commands: {
66
- cmd: CMD;
67
- data: any;
68
- }[];
69
- ready: Promise<void>;
70
64
  static check(data: Uint8Array): boolean;
65
+ header: {
66
+ magic: number;
67
+ cputype: string;
68
+ cpusubtype: string | number;
69
+ filetype: string;
70
+ ncmds: number;
71
+ sizeofcmds: number;
72
+ flags: Record<string, bigint | boolean> | Record<string, number | boolean>;
73
+ };
74
+ private commands;
71
75
  constructor(data: Uint8Array, mem?: binary.memory);
72
- load(data: Uint8Array, be: boolean, bits: 32 | 64, mem?: binary.memory): Promise<void>;
76
+ load(data: Uint8Array, be: boolean, bits: 64 | 32, mem?: binary.memory): void;
73
77
  getCommand(cmd: CMD.SEGMENT): {
74
78
  data: binary.MappedMemory | undefined;
75
79
  segname: string;
package/dist/mach.js CHANGED
@@ -966,9 +966,6 @@ const cmd_table = {
966
966
  },
967
967
  };
968
968
  class MachFile {
969
- header;
970
- commands = [];
971
- ready;
972
969
  static check(data) {
973
970
  switch (binary.UINT32_BE.get(new binary.stream(data))) {
974
971
  case 0xfeedface:
@@ -980,25 +977,27 @@ class MachFile {
980
977
  return false;
981
978
  }
982
979
  }
980
+ header;
981
+ commands = [];
983
982
  constructor(data, mem) {
984
983
  const magic = binary.UINT32_LE.get(new binary.stream(data));
985
984
  switch (magic) {
986
985
  case 0xfeedface:
987
- this.ready = this.load(data, false, 32, mem);
986
+ this.load(data, false, 32, mem);
988
987
  break;
989
988
  case 0xcefaedfe:
990
- this.ready = this.load(data, true, 32, mem);
989
+ this.load(data, true, 32, mem);
991
990
  break;
992
991
  case 0xfeedfacf:
993
- this.ready = this.load(data, false, 64, mem);
992
+ this.load(data, false, 64, mem);
994
993
  break;
995
994
  case 0xcffaedfe:
996
- this.ready = this.load(data, true, 64, mem);
995
+ this.load(data, true, 64, mem);
997
996
  break;
998
997
  default: throw new Error('not a mach file');
999
998
  }
1000
999
  }
1001
- async load(data, be, bits, mem) {
1000
+ load(data, be, bits, mem) {
1002
1001
  const file = new binary.endianStream(data, be);
1003
1002
  const h = binary.read(file, header);
1004
1003
  const cpu = CPU_TYPE[h.cputype];
@@ -1008,14 +1007,14 @@ class MachFile {
1008
1007
  for (let i = 0; i < h.ncmds; ++i) {
1009
1008
  const cmd = binary.read(file, command);
1010
1009
  const file2 = new mach_stream(data, file.read_buffer(cmd.cmdsize - 8), file.be, mem);
1011
- const result = await binary.read(file2, cmd_table[cmd.cmd] ?? {});
1010
+ const result = binary.read(file2, cmd_table[cmd.cmd] ?? {});
1012
1011
  this.commands.push({ cmd: cmd.cmd, data: result });
1013
1012
  }
1014
1013
  this.header = h;
1015
1014
  const funcs = this.getCommand(CMD.FUNCTION_STARTS);
1016
1015
  if (funcs) {
1017
1016
  const array = funcs.contents;
1018
- const text = await this.getSegment('__TEXT');
1017
+ const text = this.getSegment('__TEXT');
1019
1018
  let acc = BigInt(text?.vmaddr ?? 0);
1020
1019
  for (const i in array)
1021
1020
  array[i] = (acc += BigInt(array[i]));
package/dist/pe.d.ts CHANGED
@@ -16,18 +16,7 @@ declare const Section_base: (new (s: binary._stream) => {
16
16
  NumberOfLinenumbers: number;
17
17
  Characteristics: Record<string, bigint | boolean> | Record<string, number | boolean>;
18
18
  }) & {
19
- get: (s: binary._stream) => {
20
- Name: string;
21
- VirtualSize: number;
22
- VirtualAddress: binary.hex<number | bigint>;
23
- SizeOfRawData: number;
24
- PointerToRawData: binary.hex<number | bigint>;
25
- PointerToRelocations: binary.hex<number | bigint>;
26
- PointerToLinenumbers: binary.hex<number | bigint>;
27
- NumberOfRelocations: number;
28
- NumberOfLinenumbers: number;
29
- Characteristics: Record<string, bigint | boolean> | Record<string, number | boolean>;
30
- };
19
+ get: <X extends abstract new (...args: any) => any>(this: X, s: binary._stream) => InstanceType<X>;
31
20
  };
32
21
  declare class Section extends Section_base {
33
22
  data?: binary.MappedMemory;
@@ -47,7 +36,7 @@ type Directory = {
47
36
  Size: number;
48
37
  };
49
38
  export declare class PE {
50
- private data;
39
+ static check(data: Uint8Array): boolean;
51
40
  header: {
52
41
  magic: number;
53
42
  cblp: number;
@@ -132,20 +121,16 @@ export declare class PE {
132
121
  }>;
133
122
  });
134
123
  sections: Section[];
135
- static check(data: Uint8Array): boolean;
136
124
  constructor(data: Uint8Array);
137
125
  get directories(): Record<string, {
138
126
  VirtualAddress: number;
139
127
  Size: number;
140
- } & {}> | undefined;
128
+ }> | undefined;
141
129
  FindSectionRVA(rva: number): Section | undefined;
142
130
  FindSectionRaw(addr: number): Section | undefined;
143
131
  GetDataRVA(rva: number, size?: number): binary.MappedMemory | undefined;
144
132
  GetDataRaw(addr: number, size: number): Uint8Array | undefined;
145
- GetDataDir(dir: {
146
- VirtualAddress: number;
147
- Size: number;
148
- }): binary.MappedMemory | undefined;
133
+ GetDataDir(dir: Directory): binary.MappedMemory | undefined;
149
134
  ReadDirectory(name: string): any;
150
135
  }
151
136
  export declare function ReadExports(file: pe_stream): (string | number | binary.MappedMemory | undefined)[][];
package/dist/pe.js CHANGED
@@ -271,15 +271,13 @@ const OPTIONAL_HEADER64 = {
271
271
  DataDirectory: binary.objectWithNames(binary.ArrayType(uint32, exports.DATA_DIRECTORY), binary.names(Object.keys(exports.DIRECTORIES))),
272
272
  };
273
273
  class PE {
274
- data;
275
- header;
276
- opt;
277
- sections;
278
274
  static check(data) {
279
275
  return uint16.get(new binary.stream(data)) === binary.utils.stringCode("MZ");
280
276
  }
277
+ header;
278
+ opt;
279
+ sections;
281
280
  constructor(data) {
282
- this.data = data;
283
281
  const file = new binary.stream(data);
284
282
  this.header = binary.read(file, { ...DOS_HEADER, ...EXE_HEADER });
285
283
  file.seek(this.header.lfanew);
@@ -438,7 +436,7 @@ const RESOURCE_DIRECTORY = {
438
436
  MinorVersion: uint16,
439
437
  NumberOfNamedEntries: uint16,
440
438
  NumberOfIdEntries: uint16,
441
- entries: binary.ArrayType(obj => obj.NumberOfNamedEntries + obj.NumberOfIdEntries, {
439
+ entries: binary.ArrayType(s => s.obj.NumberOfNamedEntries + s.obj.NumberOfIdEntries, {
442
440
  u0: uint32,
443
441
  u1: uint32,
444
442
  })
package/package.json CHANGED
@@ -16,7 +16,8 @@
16
16
  "scripts": {
17
17
  "build": "tsc",
18
18
  "lint": "eslint \"src/**/*.ts\"",
19
- "test": "echo \"No tests specified\" && exit 0"
19
+ "test": "echo \"No tests specified\" && exit 0",
20
+ "patch": "ts-patch install"
20
21
  },
21
22
  "keywords": [
22
23
  "binary",
@@ -40,5 +41,5 @@
40
41
  "dependencies": {
41
42
  "@isopodlabs/binary": "^1.0.3"
42
43
  },
43
- "version": "0.1.5"
44
+ "version": "0.2.1"
44
45
  }