-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathextlang_core.h
More file actions
99 lines (78 loc) · 2.69 KB
/
extlang_core.h
File metadata and controls
99 lines (78 loc) · 2.69 KB
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
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
// extlang_core.h — C++ expression language for IDA
//
// Bridges clinglite::Interpreter to IDA's extlang_t interface.
// This header is safe to include from files that don't include pro.h.
#pragma once
#include <clinglite/clinglite.h>
template <class T> class _qstring;
typedef _qstring<char> qstring;
class idc_value_t;
struct extlang_t;
namespace idacpp {
enum class FileEntrypoint {
Auto,
Main,
None,
};
struct FileExecOptions {
std::vector<std::string> args;
FileEntrypoint entrypoint = FileEntrypoint::Auto;
};
/// Snapshot of the runtime lifecycle.
/// Fields sessionReady, extlangInstalled, lastFile*, lastEntrypoint*, and
/// lastError are managed by extlang_core.
/// Fields rcLoaded and startupScriptLoaded are set by the host (plugin or
/// standalone) after their respective operations complete.
struct RuntimeStatus {
bool sessionReady = false;
bool extlangInstalled = false;
bool rcLoaded = false;
bool startupScriptLoaded = false;
std::string lastFileExecuted;
std::string lastFileNamespace;
std::string lastEntrypointChosen;
std::string lastError;
};
/// Set up IDA SDK PCH in interpreter options.
void prepareOptions(clinglite::Options& opts);
/// Initialize and register the C++ extlang with IDA.
void init(clinglite::Interpreter* interp);
/// Get the Session used by the extlang (for CLI tab, etc.).
/// Returns nullptr if not initialized.
clinglite::Session* getSession();
/// Compile and load a .cpp file into the active session.
/// If requestedNamespace is non-empty, the file is wrapped in that namespace.
bool compileFile(
const std::string& file,
const char* requestedNamespace = nullptr,
std::string* error = nullptr);
/// Load a .cpp file and optionally invoke a conventional entrypoint.
/// When entrypoint is Auto, probes for main(argc, argv), then main().
bool execFile(
const std::string& file,
const FileExecOptions& options = {},
clinglite::Value* result = nullptr,
std::string* error = nullptr);
/// Convert a Cling value to IDC.
bool valueToIdc(
const clinglite::Value& src,
idc_value_t* dst,
qstring* errbuf = nullptr);
/// Convert an IDC value into a C++ literal string.
bool idcToLiteral(
std::string* out,
const idc_value_t& v,
qstring* errbuf = nullptr);
/// Return a snapshot of the runtime status.
RuntimeStatus getRuntimeStatus();
/// Reset the runtime status snapshot.
void resetRuntimeStatus();
/// Install the extlang (calls install_extlang).
void install();
/// Unregister and clean up the extlang.
void remove();
/// Get the extlang_t pointer for direct callback invocation.
const extlang_t* getExtlang();
/// Cleanup interpreter reference.
void term();
} // namespace idacpp