@isopodlabs/binary_libs 0.2.3 → 1.0.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/dist/elf.js +12 -13
- package/dist/mach.d.ts +1 -0
- package/dist/mach.js +19 -33
- package/dist/pe.js +4 -4
- package/package.json +3 -3
package/dist/elf.js
CHANGED
|
@@ -41,7 +41,7 @@ const OSABI = {
|
|
|
41
41
|
HPUX: 1, // HP-UX operating system
|
|
42
42
|
STANDALONE: 255, // Standalone (embedded)application
|
|
43
43
|
};
|
|
44
|
-
const Ident =
|
|
44
|
+
const Ident = {
|
|
45
45
|
//enum {MAGIC = '\177ELF'};
|
|
46
46
|
magic: binary.UINT32_LE,
|
|
47
47
|
file_class: binary.asEnum(binary.UINT8, CLASS),
|
|
@@ -53,7 +53,7 @@ const Ident = binary.SizeType(16, {
|
|
|
53
53
|
abiversion: binary.UINT8,
|
|
54
54
|
pad: binary.ArrayType(7, binary.UINT8),
|
|
55
55
|
})
|
|
56
|
-
}
|
|
56
|
+
};
|
|
57
57
|
const ET = {
|
|
58
58
|
NONE: 0, // No file type
|
|
59
59
|
REL: 1, // Relocatable file
|
|
@@ -679,10 +679,10 @@ class ELFFile {
|
|
|
679
679
|
data;
|
|
680
680
|
constructor(s) {
|
|
681
681
|
super(s);
|
|
682
|
-
const flags = (this.p_flags.R ? binary.
|
|
683
|
-
| (this.p_flags.W ? binary.
|
|
684
|
-
| (this.p_flags.X ? binary.
|
|
685
|
-
this.data = new binary.MappedMemory(s.buffer_at(Number(this.p_offset), Number(this.p_filesz)),
|
|
682
|
+
const flags = (this.p_flags.R ? 1 /* binary.MEM.READ */ : 0)
|
|
683
|
+
| (this.p_flags.W ? 2 /* binary.MEM.WRITE */ : 0)
|
|
684
|
+
| (this.p_flags.X ? 4 /* binary.MEM.EXECUTE */ : 0);
|
|
685
|
+
this.data = new binary.MappedMemory(s.buffer_at(Number(this.p_offset), Number(this.p_filesz)), Number(this.p_vaddr), flags);
|
|
686
686
|
}
|
|
687
687
|
}
|
|
688
688
|
class Shdr extends binary.ReadClass({
|
|
@@ -700,10 +700,10 @@ class ELFFile {
|
|
|
700
700
|
data;
|
|
701
701
|
constructor(s) {
|
|
702
702
|
super(s);
|
|
703
|
-
const flags = binary.
|
|
704
|
-
| (this.sh_flags.WRITE ? binary.
|
|
705
|
-
| (this.sh_flags.EXECINSTR ? binary.
|
|
706
|
-
this.data = new binary.MappedMemory(s.buffer_at(Number(this.sh_offset), Number(this.sh_size)),
|
|
703
|
+
const flags = 1 /* binary.MEM.READ */
|
|
704
|
+
| (this.sh_flags.WRITE ? 2 /* binary.MEM.WRITE */ : 0)
|
|
705
|
+
| (this.sh_flags.EXECINSTR ? 4 /* binary.MEM.EXECUTE */ : 0);
|
|
706
|
+
this.data = new binary.MappedMemory(s.buffer_at(Number(this.sh_offset), Number(this.sh_size)), Number(this.sh_addr), flags);
|
|
707
707
|
}
|
|
708
708
|
}
|
|
709
709
|
const h = binary.read(s, Ehdr);
|
|
@@ -721,10 +721,9 @@ class ELFFile {
|
|
|
721
721
|
d_tag: binary.asEnum(Sword, DT_TAG),
|
|
722
722
|
d_val: Xword,
|
|
723
723
|
};
|
|
724
|
-
const reloc = RELOC[h.e_machine];
|
|
725
724
|
const Rel = {
|
|
726
725
|
r_offset: Addr,
|
|
727
|
-
r_info: Pair(
|
|
726
|
+
r_info: Pair(binary.asEnum(PairHalf, RELOC[h.e_machine]), PairHalf, be),
|
|
728
727
|
};
|
|
729
728
|
const Rela = {
|
|
730
729
|
...Rel,
|
|
@@ -759,7 +758,7 @@ class ELFFile {
|
|
|
759
758
|
if (+sym.st_shndx) {
|
|
760
759
|
const section = sh[+sym.st_shndx];
|
|
761
760
|
const offset = Number(sym.st_value.value) - Number(section.sh_addr.value);
|
|
762
|
-
const flags = sym.st_info.type === 'FUNC' ? section.data.flags : section.data.flags & ~binary.
|
|
761
|
+
const flags = sym.st_info.type === 'FUNC' ? section.data.flags : section.data.flags & ~4 /* binary.MEM.EXECUTE */;
|
|
763
762
|
sym.data = new binary.MappedMemory(section.data.data.subarray(offset, offset + Number(sym.st_size)), Number(sym.st_value.value), flags);
|
|
764
763
|
}
|
|
765
764
|
return [binary.utils.decodeTextTo0(names.subarray(sym.st_name), 'utf8'), sym];
|
package/dist/mach.d.ts
CHANGED
|
@@ -508,5 +508,6 @@ export declare class FATMachFile {
|
|
|
508
508
|
archs: binary.ReadType<typeof fat_arch>[];
|
|
509
509
|
static check(data: Uint8Array): boolean;
|
|
510
510
|
constructor(data: Uint8Array, mem?: binary.memory);
|
|
511
|
+
load(file: binary.endianStream, mem?: binary.memory): void;
|
|
511
512
|
}
|
|
512
513
|
export {};
|
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 ? binary.
|
|
427
|
+
const prot = this.flags.ATTRIBUTES.SYS.SOME_INSTRUCTIONS ? 4 /* binary.MEM.EXECUTE */ : 0 /* binary.MEM.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,31 +1038,10 @@ class MachFile {
|
|
|
1038
1038
|
}
|
|
1039
1039
|
exports.MachFile = MachFile;
|
|
1040
1040
|
const FAT_MAGIC = 0xcafebabe;
|
|
1041
|
+
const FAT_CIGAM = 0xbebafeca;
|
|
1041
1042
|
class FATMachFile {
|
|
1042
1043
|
archs = [];
|
|
1043
1044
|
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 {
|
|
1066
1045
|
switch (binary.UINT32_BE.get(new binary.stream(data))) {
|
|
1067
1046
|
case FAT_MAGIC:
|
|
1068
1047
|
case FAT_CIGAM:
|
|
@@ -1071,26 +1050,33 @@ export class FATMachFile {
|
|
|
1071
1050
|
return false;
|
|
1072
1051
|
}
|
|
1073
1052
|
}
|
|
1074
|
-
|
|
1075
|
-
constructor(data: Uint8Array, mem?: binary.memory) {
|
|
1053
|
+
constructor(data, mem) {
|
|
1076
1054
|
switch (binary.UINT32_BE.get(new binary.stream(data))) {
|
|
1077
|
-
case FAT_MAGIC:
|
|
1078
|
-
|
|
1055
|
+
case FAT_MAGIC:
|
|
1056
|
+
this.load(new binary.endianStream(data, false), mem);
|
|
1057
|
+
break;
|
|
1058
|
+
case FAT_CIGAM:
|
|
1059
|
+
this.load(new binary.endianStream(data, true), mem);
|
|
1060
|
+
break;
|
|
1079
1061
|
default:
|
|
1080
1062
|
throw new Error('not a fat mach file');
|
|
1081
1063
|
}
|
|
1082
1064
|
}
|
|
1083
|
-
|
|
1084
|
-
load(file: binary.endianStream, mem?: binary.memory) {
|
|
1065
|
+
load(file, mem) {
|
|
1085
1066
|
const header = binary.read(file, fat_header);
|
|
1086
1067
|
this.archs = header.archs;
|
|
1087
1068
|
for (const arch of header.archs) {
|
|
1088
|
-
const cpu
|
|
1089
|
-
const data
|
|
1069
|
+
const cpu = CPU_TYPE[arch.cputype];
|
|
1070
|
+
const data = file.buffer_at(arch.offset, arch.size);
|
|
1090
1071
|
arch.cpusubtype = binary.Enum(CPU_SUBTYPES[cpu])(+arch.cpusubtype);
|
|
1091
|
-
arch.contents
|
|
1072
|
+
arch.contents = new MachFile(data, mem);
|
|
1092
1073
|
}
|
|
1093
1074
|
}
|
|
1094
1075
|
}
|
|
1095
|
-
|
|
1076
|
+
exports.FATMachFile = FATMachFile;
|
|
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
|
+
}
|
|
1096
1082
|
*/
|
package/dist/pe.js
CHANGED
|
@@ -167,10 +167,10 @@ class Section extends binary.ReadClass({
|
|
|
167
167
|
}
|
|
168
168
|
}
|
|
169
169
|
get flags() {
|
|
170
|
-
return binary.
|
|
171
|
-
| (this.Characteristics.MEM_READ ? binary.
|
|
172
|
-
| (this.Characteristics.MEM_WRITE ? binary.
|
|
173
|
-
| (this.Characteristics.MEM_EXECUTE ? binary.
|
|
170
|
+
return 8 /* binary.MEM.RELATIVE */
|
|
171
|
+
| (this.Characteristics.MEM_READ ? 1 /* binary.MEM.READ */ : 0)
|
|
172
|
+
| (this.Characteristics.MEM_WRITE ? 2 /* binary.MEM.WRITE */ : 0)
|
|
173
|
+
| (this.Characteristics.MEM_EXECUTE ? 4 /* binary.MEM.EXECUTE */ : 0);
|
|
174
174
|
}
|
|
175
175
|
}
|
|
176
176
|
exports.DIRECTORIES = {
|