@isopodlabs/binary_libs 0.1.4 → 0.2.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/README.md +49 -85
- package/dist/CompoundDocument.d copy.ts +95 -0
- package/dist/CompoundDocument.d.ts +2 -36
- package/dist/arch.d copy.ts +18 -0
- package/dist/arch.d.ts +1 -1
- package/dist/arch.js +1 -1
- package/dist/clr.d copy.ts +409 -0
- package/dist/clr.d.ts +223 -18
- package/dist/clr.js +224 -276
- package/dist/elf.d copy.ts +152 -0
- package/dist/elf.d.ts +1 -1
- package/dist/elf.js +4 -4
- package/dist/mach.d copy.ts +505 -0
- package/dist/mach.d.ts +12 -8
- package/dist/mach.js +120 -65
- package/dist/pe.d copy.ts +144 -0
- package/dist/pe.d.ts +4 -19
- package/dist/pe.js +4 -6
- package/package.json +3 -2
package/dist/mach.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.FATMachFile = exports.MachFile = void 0;
|
|
26
|
+
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;
|
|
@@ -255,6 +255,62 @@ const fat_header = {
|
|
|
255
255
|
archs: binary.ArrayType(uint32, fat_arch)
|
|
256
256
|
};
|
|
257
257
|
const REQ_DYLD = 0x80000000;
|
|
258
|
+
var CMD;
|
|
259
|
+
(function (CMD) {
|
|
260
|
+
CMD[CMD["SEGMENT"] = 1] = "SEGMENT";
|
|
261
|
+
CMD[CMD["SYMTAB"] = 2] = "SYMTAB";
|
|
262
|
+
CMD[CMD["SYMSEG"] = 3] = "SYMSEG";
|
|
263
|
+
CMD[CMD["THREAD"] = 4] = "THREAD";
|
|
264
|
+
CMD[CMD["UNIXTHREAD"] = 5] = "UNIXTHREAD";
|
|
265
|
+
CMD[CMD["LOADFVMLIB"] = 6] = "LOADFVMLIB";
|
|
266
|
+
CMD[CMD["IDFVMLIB"] = 7] = "IDFVMLIB";
|
|
267
|
+
// IDENT = 0x08, // object identification info (obsolete)
|
|
268
|
+
CMD[CMD["FVMFILE"] = 9] = "FVMFILE";
|
|
269
|
+
// PREPAGE = 0x0a, // prepage command (internal use)
|
|
270
|
+
CMD[CMD["DYSYMTAB"] = 11] = "DYSYMTAB";
|
|
271
|
+
CMD[CMD["LOAD_DYLIB"] = 12] = "LOAD_DYLIB";
|
|
272
|
+
CMD[CMD["ID_DYLIB"] = 13] = "ID_DYLIB";
|
|
273
|
+
CMD[CMD["LOAD_DYLINKER"] = 14] = "LOAD_DYLINKER";
|
|
274
|
+
CMD[CMD["ID_DYLINKER"] = 15] = "ID_DYLINKER";
|
|
275
|
+
CMD[CMD["PREBOUND_DYLIB"] = 16] = "PREBOUND_DYLIB";
|
|
276
|
+
CMD[CMD["ROUTINES"] = 17] = "ROUTINES";
|
|
277
|
+
CMD[CMD["SUB_FRAMEWORK"] = 18] = "SUB_FRAMEWORK";
|
|
278
|
+
CMD[CMD["SUB_UMBRELLA"] = 19] = "SUB_UMBRELLA";
|
|
279
|
+
CMD[CMD["SUB_CLIENT"] = 20] = "SUB_CLIENT";
|
|
280
|
+
CMD[CMD["SUB_LIBRARY"] = 21] = "SUB_LIBRARY";
|
|
281
|
+
CMD[CMD["TWOLEVEL_HINTS"] = 22] = "TWOLEVEL_HINTS";
|
|
282
|
+
CMD[CMD["PREBIND_CKSUM"] = 23] = "PREBIND_CKSUM";
|
|
283
|
+
CMD[CMD["LOAD_WEAK_DYLIB"] = 2147483672] = "LOAD_WEAK_DYLIB";
|
|
284
|
+
CMD[CMD["SEGMENT_64"] = 25] = "SEGMENT_64";
|
|
285
|
+
CMD[CMD["ROUTINES_64"] = 26] = "ROUTINES_64";
|
|
286
|
+
CMD[CMD["UUID"] = 27] = "UUID";
|
|
287
|
+
CMD[CMD["RPATH"] = 2147483676] = "RPATH";
|
|
288
|
+
CMD[CMD["CODE_SIGNATURE"] = 29] = "CODE_SIGNATURE";
|
|
289
|
+
CMD[CMD["SEGMENT_SPLIT_INFO"] = 30] = "SEGMENT_SPLIT_INFO";
|
|
290
|
+
CMD[CMD["REEXPORT_DYLIB"] = 2147483679] = "REEXPORT_DYLIB";
|
|
291
|
+
CMD[CMD["LAZY_LOAD_DYLIB"] = 32] = "LAZY_LOAD_DYLIB";
|
|
292
|
+
CMD[CMD["ENCRYPTION_INFO"] = 33] = "ENCRYPTION_INFO";
|
|
293
|
+
CMD[CMD["DYLD_INFO"] = 34] = "DYLD_INFO";
|
|
294
|
+
CMD[CMD["DYLD_INFO_ONLY"] = 2147483682] = "DYLD_INFO_ONLY";
|
|
295
|
+
CMD[CMD["LOAD_UPWARD_DYLIB"] = 2147483683] = "LOAD_UPWARD_DYLIB";
|
|
296
|
+
CMD[CMD["VERSION_MIN_MACOSX"] = 36] = "VERSION_MIN_MACOSX";
|
|
297
|
+
CMD[CMD["VERSION_MIN_IPHONEOS"] = 37] = "VERSION_MIN_IPHONEOS";
|
|
298
|
+
CMD[CMD["FUNCTION_STARTS"] = 38] = "FUNCTION_STARTS";
|
|
299
|
+
CMD[CMD["DYLD_ENVIRONMENT"] = 39] = "DYLD_ENVIRONMENT";
|
|
300
|
+
CMD[CMD["MAIN"] = 2147483688] = "MAIN";
|
|
301
|
+
CMD[CMD["DATA_IN_CODE"] = 41] = "DATA_IN_CODE";
|
|
302
|
+
CMD[CMD["SOURCE_VERSION"] = 42] = "SOURCE_VERSION";
|
|
303
|
+
CMD[CMD["DYLIB_CODE_SIGN_DRS"] = 43] = "DYLIB_CODE_SIGN_DRS";
|
|
304
|
+
CMD[CMD["ENCRYPTION_INFO_64"] = 44] = "ENCRYPTION_INFO_64";
|
|
305
|
+
CMD[CMD["LINKER_OPTION"] = 45] = "LINKER_OPTION";
|
|
306
|
+
CMD[CMD["LINKER_OPTIMIZATION_HINT"] = 46] = "LINKER_OPTIMIZATION_HINT";
|
|
307
|
+
CMD[CMD["VERSION_MIN_TVOS"] = 47] = "VERSION_MIN_TVOS";
|
|
308
|
+
CMD[CMD["VERSION_MIN_WATCHOS"] = 48] = "VERSION_MIN_WATCHOS";
|
|
309
|
+
CMD[CMD["NOTE"] = 49] = "NOTE";
|
|
310
|
+
CMD[CMD["BUILD_VERSION"] = 50] = "BUILD_VERSION";
|
|
311
|
+
CMD[CMD["DYLD_EXPORTS_TRIE"] = 2147483699] = "DYLD_EXPORTS_TRIE";
|
|
312
|
+
CMD[CMD["DYLD_CHAINED_FIXUPS"] = 2147483700] = "DYLD_CHAINED_FIXUPS";
|
|
313
|
+
})(CMD || (exports.CMD = CMD = {}));
|
|
258
314
|
;
|
|
259
315
|
const str = {
|
|
260
316
|
get(s) {
|
|
@@ -810,94 +866,94 @@ function routines(bits) {
|
|
|
810
866
|
}
|
|
811
867
|
//const cmd_table : {[K in CMD]?: binary.TypeReader2} = {
|
|
812
868
|
const cmd_table = {
|
|
813
|
-
[
|
|
814
|
-
[
|
|
815
|
-
[
|
|
816
|
-
[
|
|
817
|
-
[
|
|
818
|
-
[
|
|
819
|
-
[
|
|
820
|
-
[
|
|
821
|
-
[
|
|
822
|
-
[
|
|
823
|
-
[
|
|
824
|
-
[
|
|
825
|
-
[
|
|
826
|
-
[
|
|
827
|
-
[
|
|
828
|
-
[
|
|
829
|
-
[
|
|
830
|
-
[
|
|
831
|
-
[
|
|
869
|
+
[CMD.SEGMENT]: segment(32),
|
|
870
|
+
[CMD.SEGMENT_64]: segment(64),
|
|
871
|
+
[CMD.LOADFVMLIB]: fvmlib,
|
|
872
|
+
[CMD.IDFVMLIB]: fvmlib,
|
|
873
|
+
[CMD.LOAD_DYLIB]: dylib,
|
|
874
|
+
[CMD.ID_DYLIB]: dylib,
|
|
875
|
+
[CMD.LOAD_WEAK_DYLIB]: dylib,
|
|
876
|
+
[CMD.REEXPORT_DYLIB]: dylib,
|
|
877
|
+
[CMD.LAZY_LOAD_DYLIB]: dylib,
|
|
878
|
+
[CMD.LOAD_UPWARD_DYLIB]: dylib,
|
|
879
|
+
[CMD.SUB_FRAMEWORK]: str,
|
|
880
|
+
[CMD.SUB_UMBRELLA]: str,
|
|
881
|
+
[CMD.SUB_CLIENT]: str,
|
|
882
|
+
[CMD.SUB_LIBRARY]: str,
|
|
883
|
+
[CMD.LOAD_DYLINKER]: str,
|
|
884
|
+
[CMD.ID_DYLINKER]: str,
|
|
885
|
+
[CMD.DYLD_ENVIRONMENT]: str,
|
|
886
|
+
[CMD.RPATH]: str,
|
|
887
|
+
[CMD.PREBOUND_DYLIB]: {
|
|
832
888
|
name: str,
|
|
833
889
|
nmodules: uint32,
|
|
834
890
|
linked_modules: str,
|
|
835
891
|
},
|
|
836
|
-
[
|
|
837
|
-
[
|
|
838
|
-
[
|
|
839
|
-
[
|
|
840
|
-
[
|
|
841
|
-
[
|
|
842
|
-
[
|
|
892
|
+
[CMD.THREAD]: thread_command,
|
|
893
|
+
[CMD.UNIXTHREAD]: thread_command,
|
|
894
|
+
[CMD.ROUTINES]: routines(32),
|
|
895
|
+
[CMD.ROUTINES_64]: routines(64),
|
|
896
|
+
[CMD.SYMTAB]: symtab,
|
|
897
|
+
[CMD.TWOLEVEL_HINTS]: count_table(hint),
|
|
898
|
+
[CMD.PREBIND_CKSUM]: {
|
|
843
899
|
cksum: uint32,
|
|
844
900
|
},
|
|
845
|
-
[
|
|
901
|
+
[CMD.UUID]: {
|
|
846
902
|
uuid: binary.Buffer(16),
|
|
847
903
|
},
|
|
848
|
-
[
|
|
849
|
-
[
|
|
850
|
-
[
|
|
851
|
-
[
|
|
852
|
-
[
|
|
853
|
-
[
|
|
854
|
-
[
|
|
855
|
-
[
|
|
856
|
-
[
|
|
904
|
+
[CMD.CODE_SIGNATURE]: blob,
|
|
905
|
+
[CMD.SEGMENT_SPLIT_INFO]: blob,
|
|
906
|
+
[CMD.FUNCTION_STARTS]: blobArray(binary.ULEB128),
|
|
907
|
+
[CMD.DATA_IN_CODE]: blobArray(data_in_code_entry),
|
|
908
|
+
[CMD.DYLIB_CODE_SIGN_DRS]: blob,
|
|
909
|
+
[CMD.LINKER_OPTIMIZATION_HINT]: blob,
|
|
910
|
+
[CMD.DYLD_EXPORTS_TRIE]: blob,
|
|
911
|
+
[CMD.DYLD_CHAINED_FIXUPS]: blob, //blobT(dyld_chained_fixups),
|
|
912
|
+
[CMD.ENCRYPTION_INFO]: {
|
|
857
913
|
cryptoff: uint32, // file offset of encrypted range
|
|
858
914
|
cryptsize: uint32, // file size of encrypted range
|
|
859
915
|
cryptid: uint32, // which enryption system, 0 means not-encrypted yet
|
|
860
916
|
},
|
|
861
|
-
[
|
|
917
|
+
[CMD.ENCRYPTION_INFO_64]: {
|
|
862
918
|
cryptoff: uint32, // file offset of encrypted range
|
|
863
919
|
cryptsize: uint32, // file size of encrypted range
|
|
864
920
|
cryptid: uint32, // which enryption system, 0 means not-encrypted yet
|
|
865
921
|
pad: uint32, // must be zero
|
|
866
922
|
},
|
|
867
|
-
[
|
|
868
|
-
[
|
|
869
|
-
[
|
|
870
|
-
[
|
|
871
|
-
[
|
|
872
|
-
[
|
|
873
|
-
[
|
|
923
|
+
[CMD.VERSION_MIN_MACOSX]: version_min,
|
|
924
|
+
[CMD.VERSION_MIN_IPHONEOS]: version_min,
|
|
925
|
+
[CMD.VERSION_MIN_TVOS]: version_min,
|
|
926
|
+
[CMD.VERSION_MIN_WATCHOS]: version_min,
|
|
927
|
+
[CMD.DYLD_INFO]: dyldinfo,
|
|
928
|
+
[CMD.DYLD_INFO_ONLY]: dyldinfo,
|
|
929
|
+
[CMD.SYMSEG]: blob, //OBSOLETE
|
|
874
930
|
// [CMD.IDENT]: {},//OBSOLETE
|
|
875
|
-
[
|
|
931
|
+
[CMD.FVMFILE]: {
|
|
876
932
|
name: str,
|
|
877
933
|
header_addr: uint32,
|
|
878
934
|
},
|
|
879
|
-
[
|
|
935
|
+
[CMD.MAIN]: {
|
|
880
936
|
entryoff: uint32, // file (__TEXT) offset of entry point
|
|
881
937
|
stacksize: uint32, // if not zero, initialize stack size
|
|
882
938
|
},
|
|
883
|
-
[
|
|
939
|
+
[CMD.SOURCE_VERSION]: {
|
|
884
940
|
version: binary.as(binary.UINT64_BE, binary.BitFields({ a: 24, b: 10, c: 10, d: 10, e: 10 })) // A.B.C.D.E packed as a24.b10.c10.d10.e10
|
|
885
941
|
},
|
|
886
|
-
[
|
|
942
|
+
[CMD.BUILD_VERSION]: {
|
|
887
943
|
platform: binary.asEnum(uint32, PLATFORM),
|
|
888
944
|
minos: version,
|
|
889
945
|
sdk: version,
|
|
890
946
|
tools: binary.objectWithNames(binary.ArrayType(uint32, { tool: binary.as(uint32, binary.Enum(TOOL)), version }), binary.field('tool')),
|
|
891
947
|
},
|
|
892
|
-
[
|
|
948
|
+
[CMD.LINKER_OPTION]: {
|
|
893
949
|
count: uint32, // number of strings following
|
|
894
950
|
},
|
|
895
|
-
[
|
|
951
|
+
[CMD.NOTE]: {
|
|
896
952
|
data_owner: fixed_string16, // owner name for this LC_NOTE
|
|
897
953
|
data: blob
|
|
898
954
|
},
|
|
899
955
|
// [CMD.PREPAGE]: {},
|
|
900
|
-
[
|
|
956
|
+
[CMD.DYSYMTAB]: {
|
|
901
957
|
localsym: index_table, // local symbols
|
|
902
958
|
extdefsym: index_table, // externally defined symbols
|
|
903
959
|
undefsym: index_table, // undefined symbols
|
|
@@ -910,9 +966,6 @@ const cmd_table = {
|
|
|
910
966
|
},
|
|
911
967
|
};
|
|
912
968
|
class MachFile {
|
|
913
|
-
header;
|
|
914
|
-
commands = [];
|
|
915
|
-
ready;
|
|
916
969
|
static check(data) {
|
|
917
970
|
switch (binary.UINT32_BE.get(new binary.stream(data))) {
|
|
918
971
|
case 0xfeedface:
|
|
@@ -924,25 +977,27 @@ class MachFile {
|
|
|
924
977
|
return false;
|
|
925
978
|
}
|
|
926
979
|
}
|
|
980
|
+
header;
|
|
981
|
+
commands = [];
|
|
927
982
|
constructor(data, mem) {
|
|
928
983
|
const magic = binary.UINT32_LE.get(new binary.stream(data));
|
|
929
984
|
switch (magic) {
|
|
930
985
|
case 0xfeedface:
|
|
931
|
-
this.
|
|
986
|
+
this.load(data, false, 32, mem);
|
|
932
987
|
break;
|
|
933
988
|
case 0xcefaedfe:
|
|
934
|
-
this.
|
|
989
|
+
this.load(data, true, 32, mem);
|
|
935
990
|
break;
|
|
936
991
|
case 0xfeedfacf:
|
|
937
|
-
this.
|
|
992
|
+
this.load(data, false, 64, mem);
|
|
938
993
|
break;
|
|
939
994
|
case 0xcffaedfe:
|
|
940
|
-
this.
|
|
995
|
+
this.load(data, true, 64, mem);
|
|
941
996
|
break;
|
|
942
997
|
default: throw new Error('not a mach file');
|
|
943
998
|
}
|
|
944
999
|
}
|
|
945
|
-
|
|
1000
|
+
load(data, be, bits, mem) {
|
|
946
1001
|
const file = new binary.endianStream(data, be);
|
|
947
1002
|
const h = binary.read(file, header);
|
|
948
1003
|
const cpu = CPU_TYPE[h.cputype];
|
|
@@ -952,14 +1007,14 @@ class MachFile {
|
|
|
952
1007
|
for (let i = 0; i < h.ncmds; ++i) {
|
|
953
1008
|
const cmd = binary.read(file, command);
|
|
954
1009
|
const file2 = new mach_stream(data, file.read_buffer(cmd.cmdsize - 8), file.be, mem);
|
|
955
|
-
const result =
|
|
1010
|
+
const result = binary.read(file2, cmd_table[cmd.cmd] ?? {});
|
|
956
1011
|
this.commands.push({ cmd: cmd.cmd, data: result });
|
|
957
1012
|
}
|
|
958
1013
|
this.header = h;
|
|
959
|
-
const funcs = this.getCommand(
|
|
1014
|
+
const funcs = this.getCommand(CMD.FUNCTION_STARTS);
|
|
960
1015
|
if (funcs) {
|
|
961
1016
|
const array = funcs.contents;
|
|
962
|
-
const text =
|
|
1017
|
+
const text = this.getSegment('__TEXT');
|
|
963
1018
|
let acc = BigInt(text?.vmaddr ?? 0);
|
|
964
1019
|
for (const i in array)
|
|
965
1020
|
array[i] = (acc += BigInt(array[i]));
|
|
@@ -973,9 +1028,9 @@ class MachFile {
|
|
|
973
1028
|
}
|
|
974
1029
|
getSegment(name) {
|
|
975
1030
|
for (const i of this.commands) {
|
|
976
|
-
if (i.cmd ===
|
|
1031
|
+
if (i.cmd === CMD.SEGMENT && i.data.segname === name)
|
|
977
1032
|
return i.data;
|
|
978
|
-
if (i.cmd ===
|
|
1033
|
+
if (i.cmd === CMD.SEGMENT_64 && i.data.segname === name)
|
|
979
1034
|
return i.data;
|
|
980
1035
|
;
|
|
981
1036
|
}
|
|
@@ -0,0 +1,144 @@
|
|
|
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
|
+
};
|
|
25
|
+
export declare class pe_stream extends binary.stream {
|
|
26
|
+
pe: PE;
|
|
27
|
+
constructor(pe: PE, data: Uint8Array);
|
|
28
|
+
get_rva(): Uint8Array | undefined;
|
|
29
|
+
}
|
|
30
|
+
declare const Section_base: (new (s: binary._stream) => {
|
|
31
|
+
Name: string;
|
|
32
|
+
VirtualSize: number;
|
|
33
|
+
VirtualAddress: binary.hex<number | bigint>;
|
|
34
|
+
SizeOfRawData: number;
|
|
35
|
+
PointerToRawData: binary.hex<number | bigint>;
|
|
36
|
+
PointerToRelocations: binary.hex<number | bigint>;
|
|
37
|
+
PointerToLinenumbers: binary.hex<number | bigint>;
|
|
38
|
+
NumberOfRelocations: number;
|
|
39
|
+
NumberOfLinenumbers: number;
|
|
40
|
+
Characteristics: Record<string, bigint | boolean> | Record<string, number | boolean>;
|
|
41
|
+
}) & {
|
|
42
|
+
get: <X extends abstract new (...args: any) => any>(this: X, s: binary._stream) => InstanceType<X>;
|
|
43
|
+
};
|
|
44
|
+
declare class Section extends Section_base {
|
|
45
|
+
data?: binary.MappedMemory;
|
|
46
|
+
constructor(r: binary.stream);
|
|
47
|
+
get flags(): number;
|
|
48
|
+
}
|
|
49
|
+
interface DirectoryInfo {
|
|
50
|
+
read?: (pe: PE, data: binary.MappedMemory) => any;
|
|
51
|
+
}
|
|
52
|
+
export declare const DIRECTORIES: Record<string, DirectoryInfo>;
|
|
53
|
+
export declare const DATA_DIRECTORY: {
|
|
54
|
+
VirtualAddress: binary.TypeT<number>;
|
|
55
|
+
Size: binary.TypeT<number>;
|
|
56
|
+
};
|
|
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
|
+
}>>;
|
|
120
|
+
};
|
|
121
|
+
export declare class PE {
|
|
122
|
+
private data;
|
|
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>);
|
|
125
|
+
sections: Section[];
|
|
126
|
+
static check(data: Uint8Array): boolean;
|
|
127
|
+
constructor(data: Uint8Array);
|
|
128
|
+
get directories(): Record<string, {
|
|
129
|
+
VirtualAddress: number;
|
|
130
|
+
Size: number;
|
|
131
|
+
}> | undefined;
|
|
132
|
+
FindSectionRVA(rva: number): Section | undefined;
|
|
133
|
+
FindSectionRaw(addr: number): Section | undefined;
|
|
134
|
+
GetDataRVA(rva: number, size?: number): binary.MappedMemory | undefined;
|
|
135
|
+
GetDataRaw(addr: number, size: number): Uint8Array | undefined;
|
|
136
|
+
GetDataDir(dir: Directory): binary.MappedMemory | undefined;
|
|
137
|
+
ReadDirectory(name: string): any;
|
|
138
|
+
}
|
|
139
|
+
export declare function ReadExports(file: pe_stream): (string | number | binary.MappedMemory | undefined)[][];
|
|
140
|
+
export declare class DLLImports extends Array {
|
|
141
|
+
}
|
|
142
|
+
export declare function ReadImports(file: pe_stream): [string, any][];
|
|
143
|
+
export declare function ReadResourceDirectory(file: binary.stream, data: binary.MappedMemory, type?: number): Record<string, any>;
|
|
144
|
+
export {};
|
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
|
-
|
|
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
|
-
}
|
|
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(
|
|
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.
|
|
44
|
+
"version": "0.2.0"
|
|
44
45
|
}
|