hexcore-remill 0.1.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.
@@ -0,0 +1,103 @@
1
+ /**
2
+ * HexCore Remill - N-API Wrapper Header
3
+ * Lifts machine code to LLVM IR bitcode
4
+ *
5
+ * Copyright (c) HikariSystem. All rights reserved.
6
+ * Licensed under MIT License.
7
+ */
8
+
9
+ #ifndef HEXCORE_REMILL_WRAPPER_H
10
+ #define HEXCORE_REMILL_WRAPPER_H
11
+
12
+ #include <napi.h>
13
+ #include <string>
14
+ #include <vector>
15
+ #include <memory>
16
+ #include <cstdint>
17
+
18
+ // Forward declarations
19
+ namespace llvm {
20
+ class LLVMContext;
21
+ class Module;
22
+ } // namespace llvm
23
+
24
+ namespace remill {
25
+ class Arch;
26
+ class IntrinsicTable;
27
+ } // namespace remill
28
+
29
+ /**
30
+ * Result of lifting a single instruction or block of bytes.
31
+ */
32
+ struct LiftResult {
33
+ bool success;
34
+ std::string ir; // LLVM IR as text
35
+ std::string error; // Error message if !success
36
+ uint64_t address; // Start address
37
+ uint64_t bytesConsumed; // How many input bytes were consumed
38
+ };
39
+
40
+ /**
41
+ * RemillLifter — N-API ObjectWrap that owns an Arch + LLVMContext.
42
+ *
43
+ * Lifecycle:
44
+ * const lifter = new RemillLifter('amd64');
45
+ * const result = lifter.liftBytes(buffer, 0x401000);
46
+ * lifter.close();
47
+ */
48
+ class RemillLifter : public Napi::ObjectWrap<RemillLifter> {
49
+ public:
50
+ static Napi::Object Init(Napi::Env env, Napi::Object exports);
51
+
52
+ explicit RemillLifter(const Napi::CallbackInfo& info);
53
+ ~RemillLifter();
54
+
55
+ // Public for AsyncWorker access
56
+ LiftResult DoLift(const uint8_t* bytes, size_t length, uint64_t address);
57
+ Napi::Object LiftResultToJS(Napi::Env env, const LiftResult& result);
58
+
59
+ private:
60
+ // --- JS-visible methods ---
61
+ Napi::Value LiftBytes(const Napi::CallbackInfo& info);
62
+ Napi::Value LiftBytesAsync(const Napi::CallbackInfo& info);
63
+ Napi::Value GetArch(const Napi::CallbackInfo& info);
64
+ static Napi::Value GetSupportedArchs(const Napi::CallbackInfo& info);
65
+ Napi::Value Close(const Napi::CallbackInfo& info);
66
+ Napi::Value IsOpen(const Napi::CallbackInfo& info);
67
+
68
+ // --- State ---
69
+ std::string archName_;
70
+ bool closed_ = false;
71
+
72
+ std::unique_ptr<llvm::LLVMContext> context_;
73
+ std::unique_ptr<llvm::Module> semanticsModule_;
74
+ std::unique_ptr<const remill::Arch> arch_; // Arch::Get returns unique_ptr
75
+ std::unique_ptr<remill::IntrinsicTable> intrinsics_;
76
+ };
77
+
78
+ /**
79
+ * AsyncWorker for non-blocking lift operations.
80
+ */
81
+ class LiftBytesWorker : public Napi::AsyncWorker {
82
+ public:
83
+ LiftBytesWorker(
84
+ Napi::Env env,
85
+ RemillLifter* lifter,
86
+ std::vector<uint8_t> bytes,
87
+ uint64_t address);
88
+
89
+ void Execute() override;
90
+ void OnOK() override;
91
+ void OnError(const Napi::Error& error) override;
92
+
93
+ Napi::Promise::Deferred& GetDeferred() { return deferred_; }
94
+
95
+ private:
96
+ RemillLifter* lifter_;
97
+ std::vector<uint8_t> bytes_;
98
+ uint64_t address_;
99
+ LiftResult result_;
100
+ Napi::Promise::Deferred deferred_;
101
+ };
102
+
103
+ #endif // HEXCORE_REMILL_WRAPPER_H