@isopodlabs/binary_libs 1.1.1 → 1.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/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Adrian Stephens
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,134 +1,137 @@
1
- # Binary Libs
2
-
3
- This package provides readers for various library formats, using the @isopodlabs/binary binary file loading library
4
-
5
- ## ☕ Support My Work
6
- If you use this package, consider [buying me a tea](https://coff.ee/adrianstephens) to support future updates!
7
-
8
- ## Supported File Types
9
-
10
- ### elf
11
- ELF
12
- ```typescript
13
- class ELFFile {
14
- static check(data: Uint8Array): boolean;
15
- segments: [string, Segment][];
16
- sections: [string, Section][];
17
- header: Header;
18
- getSymbols(): [string, Symbol][];
19
- getDynamicSymbols(): [string, Symbol][];
20
- getSegmentByType(type: string): Segment | undefined;
21
- getSectionByType(type: string): Section | undefined;
22
- }
23
- ```
24
-
25
- ### pe
26
- Portable Executable
27
- ```typescript
28
- class PE {
29
- static check(data: Uint8Array): boolean;
30
- header: Header;
31
- opt?: OptHeader;
32
- sections: Section[];
33
- get directories(): {
34
- [k: string]: any;
35
- } | undefined;
36
- FindSectionRVA(rva: number): Section | undefined;
37
- FindSectionRaw(addr: number): Section | undefined;
38
- GetDataRVA(rva: number, size?: number): binary.utils.MappedMemory | undefined;
39
- GetDataRaw(addr: number, size: number): Uint8Array | undefined;
40
- GetDataDir(dir: { VirtualAddress: number; Size: number; } & {}): binary.utils.MappedMemory | undefined;
41
- ReadDirectory(name: string): any;
42
- }
43
- ```
44
-
45
- ### clr
46
- Common Language Runtime (embedded in pe files)
47
- ```typescript
48
- class CLR {
49
- header: Header;
50
- table_info: TableInfo;
51
- heaps: Uint8Array[];
52
- tables: Record<TABLE, Table>;
53
- Resources?: Uint8Array;
54
- getEntry(t: TABLE, i: number): any;
55
- getTable(t: TABLE): any;
56
- getResources(block: string): Record<string, any> | undefined;
57
- getResource(block: string, name: string): any;
58
- allResources(): any;
59
- }
60
- ```
61
- ### mach
62
- Apple libraries
63
- ```typescript
64
- interface Segment {
65
- data: binary.utils.MappedMemory | undefined;
66
- segname: string;
67
- vmaddr: number | bigint;
68
- vmsize: number | bigint;
69
- fileoff: number | bigint;
70
- filesize: number | bigint;
71
- maxprot: number;
72
- initprot: number;
73
- nsects: number;
74
- flags: Record<string, bigint | boolean> | Record<string, number | boolean>;
75
- sections: Record<string, any> | undefined;
76
- };
77
- class MachFile {
78
- static check(data: Uint8Array): boolean;
79
- header: Header;
80
- commands: { cmd: CMD; data: any; }[];
81
- constructor(data: Uint8Array, mem?: binary.utils.memory);
82
- getCommand(cmd: CMD): any;
83
- getSegment(name: string): Segment;
84
- }
85
- class FATMachFile {
86
- archs: {
87
- cputype: string;
88
- cpusubtype: string | number;
89
- offset: number;
90
- size: number;
91
- align: number;
92
- contents: MachFile | undefined;
93
- }[];
94
- static check(data: Uint8Array): boolean;
95
- constructor(data: Uint8Array, mem?: binary.utils.memory);
96
- load(file: binary.stream_endian, mem?: binary.utils.memory): void;
97
- }
98
- ```
99
-
100
- ### arch
101
- Archive files for static linking
102
-
103
- ```typescript
104
- declare class ArchFile {
105
- static check(data: Uint8Array): boolean;
106
- members: {
107
- name: string;
108
- date: number;
109
- uid: number;
110
- gid: number;
111
- mode: number;
112
- size: number;
113
- fmag: string;
114
- contents: any;
115
- }[];
116
- constructor(data: Uint8Array);
117
- }
118
- ```
119
-
120
- ### CompoundDocument
121
- Not a library format at all, but useful for loading some related files
122
- ```typescript
123
- class Reader {
124
- entries: DirEntry[];
125
- private entry_chain;
126
- constructor(sectors: Uint8Array, header: Header);
127
- find(name: string, i?: number): DirEntry | undefined;
128
- read(e: DirEntry): Uint8Array;
129
- write(e: DirEntry, data: Uint8Array): void;
130
- }
131
- ```
132
- ## License
133
-
1
+ # Binary Libs
2
+ [![npm version](https://img.shields.io/npm/v/@isopodlabs/binary_libs.svg)](https://www.npmjs.com/package/@isopodlabs/binary_libs)
3
+ [![GitHub stars](https://img.shields.io/github/stars/adrianstephens/binary_libs.svg?style=social)](https://github.com/adrianstephens/binary_libs)
4
+ [![License](https://img.shields.io/npm/l/@isopodlabs/binary_libs.svg)](LICENSE.txt)
5
+
6
+ This package provides readers for various library formats, using the @isopodlabs/binary binary file loading library
7
+
8
+ ## Support My Work
9
+ If you use this package, consider [buying me a cup of tea](https://coff.ee/adrianstephens) to support future updates!
10
+
11
+ ## Supported File Types
12
+
13
+ ### elf
14
+ ELF
15
+ ```typescript
16
+ class ELFFile {
17
+ static check(data: Uint8Array): boolean;
18
+ segments: [string, Segment][];
19
+ sections: [string, Section][];
20
+ header: Header;
21
+ getSymbols(): [string, Symbol][];
22
+ getDynamicSymbols(): [string, Symbol][];
23
+ getSegmentByType(type: string): Segment | undefined;
24
+ getSectionByType(type: string): Section | undefined;
25
+ }
26
+ ```
27
+
28
+ ### pe
29
+ Portable Executable
30
+ ```typescript
31
+ class PE {
32
+ static check(data: Uint8Array): boolean;
33
+ header: Header;
34
+ opt?: OptHeader;
35
+ sections: Section[];
36
+ get directories(): {
37
+ [k: string]: any;
38
+ } | undefined;
39
+ FindSectionRVA(rva: number): Section | undefined;
40
+ FindSectionRaw(addr: number): Section | undefined;
41
+ GetDataRVA(rva: number, size?: number): binary.utils.MappedMemory | undefined;
42
+ GetDataRaw(addr: number, size: number): Uint8Array | undefined;
43
+ GetDataDir(dir: { VirtualAddress: number; Size: number; } & {}): binary.utils.MappedMemory | undefined;
44
+ ReadDirectory(name: string): any;
45
+ }
46
+ ```
47
+
48
+ ### clr
49
+ Common Language Runtime (embedded in pe files)
50
+ ```typescript
51
+ class CLR {
52
+ header: Header;
53
+ table_info: TableInfo;
54
+ heaps: Uint8Array[];
55
+ tables: Record<TABLE, Table>;
56
+ Resources?: Uint8Array;
57
+ getEntry(t: TABLE, i: number): any;
58
+ getTable(t: TABLE): any;
59
+ getResources(block: string): Record<string, any> | undefined;
60
+ getResource(block: string, name: string): any;
61
+ allResources(): any;
62
+ }
63
+ ```
64
+ ### mach
65
+ Apple libraries
66
+ ```typescript
67
+ interface Segment {
68
+ data: binary.utils.MappedMemory | undefined;
69
+ segname: string;
70
+ vmaddr: number | bigint;
71
+ vmsize: number | bigint;
72
+ fileoff: number | bigint;
73
+ filesize: number | bigint;
74
+ maxprot: number;
75
+ initprot: number;
76
+ nsects: number;
77
+ flags: Record<string, bigint | boolean> | Record<string, number | boolean>;
78
+ sections: Record<string, any> | undefined;
79
+ };
80
+ class MachFile {
81
+ static check(data: Uint8Array): boolean;
82
+ header: Header;
83
+ commands: { cmd: CMD; data: any; }[];
84
+ constructor(data: Uint8Array, mem?: binary.utils.memory);
85
+ getCommand(cmd: CMD): any;
86
+ getSegment(name: string): Segment;
87
+ }
88
+ class FATMachFile {
89
+ archs: {
90
+ cputype: string;
91
+ cpusubtype: string | number;
92
+ offset: number;
93
+ size: number;
94
+ align: number;
95
+ contents: MachFile | undefined;
96
+ }[];
97
+ static check(data: Uint8Array): boolean;
98
+ constructor(data: Uint8Array, mem?: binary.utils.memory);
99
+ load(file: binary.stream_endian, mem?: binary.utils.memory): void;
100
+ }
101
+ ```
102
+
103
+ ### arch
104
+ Archive files for static linking
105
+
106
+ ```typescript
107
+ declare class ArchFile {
108
+ static check(data: Uint8Array): boolean;
109
+ members: {
110
+ name: string;
111
+ date: number;
112
+ uid: number;
113
+ gid: number;
114
+ mode: number;
115
+ size: number;
116
+ fmag: string;
117
+ contents: any;
118
+ }[];
119
+ constructor(data: Uint8Array);
120
+ }
121
+ ```
122
+
123
+ ### CompoundDocument
124
+ Not a library format at all, but useful for loading some related files
125
+ ```typescript
126
+ class Reader {
127
+ entries: DirEntry[];
128
+ private entry_chain;
129
+ constructor(sectors: Uint8Array, header: Header);
130
+ find(name: string, i?: number): DirEntry | undefined;
131
+ read(e: DirEntry): Uint8Array;
132
+ write(e: DirEntry, data: Uint8Array): void;
133
+ }
134
+ ```
135
+ ## License
136
+
134
137
  This project is licensed under the MIT License. See the LICENSE file for more details.
@@ -148,7 +148,7 @@ const COLOUR = {
148
148
  RED: 0, BLACK: 1
149
149
  };
150
150
  class DirEntry extends binary.Class({
151
- name: binary.StringType(64, 'utf16le'),
151
+ name: binary.StringType(32, 'utf16le'),
152
152
  name_size: binary.UINT16_LE,
153
153
  type: binary.UINT8,
154
154
  colour: binary.UINT8,
@@ -298,3 +298,4 @@ class Reader extends Master {
298
298
  }
299
299
  }
300
300
  exports.Reader = Reader;
301
+ //# sourceMappingURL=CompoundDocument.js.map
package/dist/arch.js CHANGED
@@ -52,7 +52,9 @@ class ArchFile {
52
52
  const header = binary.read(s, binary.StringType(8));
53
53
  if (header !== '!<arch>\n')
54
54
  throw new Error('Invalid archive file format');
55
+ const nullTerminatedString = binary.NullTerminatedStringType();
55
56
  let long_names;
57
+ let blanks = 0;
56
58
  while (s.remaining() > 0) {
57
59
  const member = binary.read(s, _HEADER);
58
60
  const data = s.read_buffer(member.size);
@@ -67,16 +69,31 @@ class ArchFile {
67
69
  }
68
70
  if (member.name == '') {
69
71
  const s2 = new binary.stream(data);
70
- const offsets = binary.ArrayType(binary.INT32_BE, binary.INT32_BE).get(s2);
71
- member.name = 'Symbols';
72
- member.contents = offsets.map(offset => [
73
- binary.NullTerminatedStringType().get(s2),
74
- offset
75
- ]);
72
+ switch (++blanks) {
73
+ case 1: {
74
+ const offsets = binary.ArrayType(binary.INT32_BE, binary.INT32_BE).get(s2);
75
+ member.name = 'Symbols';
76
+ member.contents = offsets.map(offset => [
77
+ nullTerminatedString.get(s2),
78
+ offset
79
+ ]);
80
+ break;
81
+ }
82
+ case 2: { // microsoft symbols
83
+ const member_offsets = binary.ArrayType(binary.INT32_LE, binary.INT32_LE).get(s2);
84
+ const indices = binary.ArrayType(binary.INT32_LE, binary.INT16_LE).get(s2);
85
+ member.name = 'Symbols2';
86
+ member.contents = indices.map(i => [
87
+ nullTerminatedString.get(s2),
88
+ i
89
+ ]);
90
+ break;
91
+ }
92
+ }
76
93
  }
77
94
  else if (member.name == '/SYM') {
78
95
  const s2 = new binary.stream(data);
79
- const syms = binary.ArrayType(binary.INT32_BE, binary.NullTerminatedStringType()).get(s2);
96
+ const syms = binary.ArrayType(binary.INT32_BE, nullTerminatedString).get(s2);
80
97
  member.contents = syms.map(name => ({
81
98
  name,
82
99
  offset: binary.INT32_BE.get(s2)
@@ -94,3 +111,4 @@ class ArchFile {
94
111
  }
95
112
  }
96
113
  exports.ArchFile = ArchFile;
114
+ //# sourceMappingURL=arch.js.map
package/dist/clr.js CHANGED
@@ -604,3 +604,4 @@ pe.DIRECTORIES.CLR_DESCRIPTOR.read = (pe, data) => {
604
604
  const clr = new CLR(pe, data.data);
605
605
  return Object.fromEntries(Object.entries(clr.tables).map(([k, v]) => [TABLE[+k], fix_names(clr.getTable(+k))]));
606
606
  };
607
+ //# sourceMappingURL=clr.js.map
@@ -0,0 +1,26 @@
1
+ import * as binary from '@isopodlabs/binary';
2
+ declare const Decimal_base: (new (s: binary._stream) => {
3
+ reserved: number;
4
+ scale: number;
5
+ sign: number;
6
+ mhi: number;
7
+ mlo: bigint;
8
+ } & {
9
+ write(w: binary._stream): void;
10
+ }) & {
11
+ get: <X extends abstract new (...args: any) => any>(this: X, s: binary._stream) => InstanceType<X>;
12
+ put: (s: binary._stream, v: any) => void;
13
+ };
14
+ export declare class Decimal extends Decimal_base {
15
+ toNumber(): number;
16
+ }
17
+ export declare const CV_MMASK = 1792;
18
+ export declare const CV_TMASK = 240;
19
+ export declare const CV_SMASK = 15;
20
+ export declare const CV_MSHIFT = 8;
21
+ export declare const CV_TSHIFT = 4;
22
+ export declare const CV_SSHIFT = 0;
23
+ export declare function CV_MODE(typ: number): number;
24
+ export declare function CV_TYPE(typ: number): number;
25
+ export declare function CV_SUBT(typ: number): number;
26
+ export {};