-
Notifications
You must be signed in to change notification settings - Fork 28.2k
/
cli.js
executable file
·59 lines (53 loc) · 1.57 KB
/
cli.js
1
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
#!/usr/bin/env node
const program = require("commander");
const { constants, promises: fs } = require("fs");
const path = require("path");
const { inject } = require("./api.js");
async function main(filename, resourceName, resource, options) {
if (options.outputApiHeader) {
// Handles --output-api-header.
console.log(
await fs.readFile(path.join(__dirname, "postject-api.h"), "utf-8")
);
process.exit();
}
let resourceData;
try {
await fs.access(resource, constants.R_OK);
resourceData = await fs.readFile(resource);
} catch {
console.log("Can't read resource file");
process.exit(1);
}
try {
await inject(filename, resourceName, resourceData, {
machoSegmentName: options.machoSegmentName,
overwrite: options.overwrite,
});
} catch (err) {
console.log(err.message);
process.exit(1);
}
}
if (require.main === module) {
program
.name("postject")
.description(
"Inject arbitrary read-only resources into an executable for use at runtime"
)
.argument("<filename>", "The executable to inject into")
.argument(
"<resource_name>",
"The resource name to use (section name on Mach-O and ELF, resource name for PE)"
)
.argument("<resource>", "The resource to inject")
.option(
"--macho-segment-name <segment_name>",
"Name for the Mach-O segment",
"__POSTJECT"
)
.option("--output-api-header", "Output the API header to stdout")
.option("--overwrite", "Overwrite the resource if it already exists")
.action(main)
.parse(process.argv);
}