@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 +21 -0
- package/README.md +136 -133
- package/dist/CompoundDocument.js +2 -1
- package/dist/arch.js +25 -7
- package/dist/clr.js +1 -0
- package/dist/cvinfo.d.ts +26 -0
- package/dist/cvinfo.js +930 -0
- package/dist/elf.js +1 -0
- package/dist/mach.js +1 -0
- package/dist/pe.d.ts +58 -24
- package/dist/pe.js +123 -52
- package/package.json +49 -45
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
##
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
1
|
+
# Binary Libs
|
|
2
|
+
[](https://www.npmjs.com/package/@isopodlabs/binary_libs)
|
|
3
|
+
[](https://github.com/adrianstephens/binary_libs)
|
|
4
|
+
[](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.
|
package/dist/CompoundDocument.js
CHANGED
|
@@ -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(
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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,
|
|
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
package/dist/cvinfo.d.ts
ADDED
|
@@ -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 {};
|