@isopodlabs/binary_libs 0.2.1 → 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/elf.d.ts CHANGED
@@ -1,4 +1,44 @@
1
1
  import * as binary from '@isopodlabs/binary';
2
+ declare const PT: {
3
+ readonly NULL: 0;
4
+ readonly LOAD: 1;
5
+ readonly DYNAMIC: 2;
6
+ readonly INTERP: 3;
7
+ readonly NOTE: 4;
8
+ readonly SHLIB: 5;
9
+ readonly PHDR: 6;
10
+ readonly TLS: 7;
11
+ readonly LOOS: 1610612736;
12
+ readonly UNWIND: 1684333904;
13
+ readonly EH_FRAME: 1685382480;
14
+ readonly GNU_STACK: 1685382481;
15
+ readonly GNU_RELRO: 1685382482;
16
+ readonly OS_SCE: 1879047936;
17
+ readonly HIOS: 1879048191;
18
+ readonly LOPROC: 1879048192;
19
+ readonly HIPROC: 2147483647;
20
+ };
21
+ declare const SHT: {
22
+ readonly NULL: 0;
23
+ readonly PROGBITS: 1;
24
+ readonly SYMTAB: 2;
25
+ readonly STRTAB: 3;
26
+ readonly RELA: 4;
27
+ readonly HASH: 5;
28
+ readonly DYNAMIC: 6;
29
+ readonly NOTE: 7;
30
+ readonly NOBITS: 8;
31
+ readonly REL: 9;
32
+ readonly SHLIB: 10;
33
+ readonly DYNSYM: 11;
34
+ readonly LOOS: 1610612736;
35
+ readonly HIOS: 1879048191;
36
+ readonly LOPROC: 1879048192;
37
+ readonly HIPROC: 2147483647;
38
+ readonly LOUSER: 2147483648;
39
+ readonly HIUSER: 4294967295;
40
+ readonly PS3_RELA: number;
41
+ };
2
42
  export declare class ELFFile {
3
43
  static check(data: Uint8Array): boolean;
4
44
  segments: [string, {
@@ -84,7 +124,7 @@ export declare class ELFFile {
84
124
  st_name: number;
85
125
  }][] | undefined;
86
126
  constructor(data: Uint8Array);
87
- getSegmentByType(type: "TLS" | "LOOS" | "HIOS" | "LOPROC" | "HIPROC" | "NULL" | "LOAD" | "DYNAMIC" | "INTERP" | "NOTE" | "SHLIB" | "PHDR" | "UNWIND" | "EH_FRAME" | "GNU_STACK" | "GNU_RELRO" | "OS_SCE"): {
127
+ getSegmentByType(type: keyof typeof PT): {
88
128
  data: binary.MappedMemory;
89
129
  p_type: string;
90
130
  p_flags: Record<string, bigint | boolean> | Record<string, number | boolean>;
@@ -95,7 +135,7 @@ export declare class ELFFile {
95
135
  p_memsz: number | bigint;
96
136
  p_align: number | bigint;
97
137
  } | undefined;
98
- getSectionByType(type: "LOOS" | "HIOS" | "LOPROC" | "HIPROC" | "REL" | "NULL" | "DYNAMIC" | "NOTE" | "SHLIB" | "PROGBITS" | "SYMTAB" | "STRTAB" | "RELA" | "HASH" | "NOBITS" | "DYNSYM" | "LOUSER" | "HIUSER" | "PS3_RELA"): {
138
+ getSectionByType(type: keyof typeof SHT): {
99
139
  data: binary.MappedMemory;
100
140
  sh_name: number;
101
141
  sh_type: string;
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 = binary.SizeType(16, {
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 = {
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,9 +679,9 @@ class ELFFile {
679
679
  data;
680
680
  constructor(s) {
681
681
  super(s);
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);
682
+ const flags = (this.p_flags.R ? binary.MappedMemory.READ : 0)
683
+ | (this.p_flags.W ? binary.MappedMemory.WRITE : 0)
684
+ | (this.p_flags.X ? binary.MappedMemory.EXECUTE : 0);
685
685
  this.data = new binary.MappedMemory(s.buffer_at(Number(this.p_offset), Number(this.p_filesz)), +this.p_vaddr, flags);
686
686
  }
687
687
  }
@@ -700,9 +700,9 @@ class ELFFile {
700
700
  data;
701
701
  constructor(s) {
702
702
  super(s);
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);
703
+ const flags = binary.MappedMemory.READ
704
+ | (this.sh_flags.WRITE ? binary.MappedMemory.WRITE : 0)
705
+ | (this.sh_flags.EXECINSTR ? binary.MappedMemory.EXECUTE : 0);
706
706
  this.data = new binary.MappedMemory(s.buffer_at(Number(this.sh_offset), Number(this.sh_size)), +this.sh_addr, flags);
707
707
  }
708
708
  }
@@ -721,9 +721,10 @@ 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];
724
725
  const Rel = {
725
726
  r_offset: Addr,
726
- r_info: Pair(binary.asEnum(PairHalf, RELOC[h.e_machine]), PairHalf, be),
727
+ r_info: Pair(reloc ? binary.asEnum(PairHalf, reloc) : PairHalf, PairHalf, be),
727
728
  };
728
729
  const Rela = {
729
730
  ...Rel,
@@ -758,7 +759,7 @@ class ELFFile {
758
759
  if (+sym.st_shndx) {
759
760
  const section = sh[+sym.st_shndx];
760
761
  const offset = Number(sym.st_value.value) - Number(section.sh_addr.value);
761
- const flags = sym.st_info.type === 'FUNC' ? section.data.flags : section.data.flags & ~4 /* binary.MEM.EXECUTE */;
762
+ const flags = sym.st_info.type === 'FUNC' ? section.data.flags : section.data.flags & ~binary.MappedMemory.EXECUTE;
762
763
  sym.data = new binary.MappedMemory(section.data.data.subarray(offset, offset + Number(sym.st_size)), Number(sym.st_value.value), flags);
763
764
  }
764
765
  return [binary.utils.decodeTextTo0(names.subarray(sym.st_name), 'utf8'), sym];