-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.ts
53 lines (45 loc) · 1.76 KB
/
main.ts
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
import yargs from "yargs";
import * as frida from "frida";
import * as fs from "fs";
import * as path from "path";
enum InitializeResult {
Success,
HostFxrLoadError,
InitializeRuntimeConfigError,
GetRuntimeDelegateError,
EntryPointError,
}
yargs(process.argv.slice(2))
.scriptName("net-core-injector")
.usage("$0 <cmd> <args>")
.command("inject <process_name> <bootstrapper> <runtime_config_path> <assembly_path> <type_name> <method_name>", "inject C# library into process", (yargs) => {
yargs
.positional("process_name", {type: "string"})
.positional("bootstrapper", {type: "string"})
.positional("runtime_config_path", {type: "string"})
.positional("assembly_path", {type: "string"})
.positional("type_name", {type: "string"})
.positional("method_name", {type: "string"})
}, async (argv: any) => {
const session = await frida.attach(argv.process_name);
const source = fs.readFileSync("dist/agent.js", "utf8");
const script = await session.createScript(source);
await script.load();
const api: any = script.exports;
const ret = await api.inject(
path.resolve(argv.bootstrapper),
path.resolve(argv.runtime_config_path),
path.resolve(argv.assembly_path),
argv.type_name,
argv.method_name,
);
const initialize_result = InitializeResult[ret] ?? "Unknown";
console.log(`[*] api.inject() => ${ret} (InitializeResult::${initialize_result})`);
if (ret !== 0) {
console.log(`An error occurred while injection into ${argv.process_name}`);
}
await script.unload();
})
.demandCommand(1)
.help()
.argv;