From db55eb598a63fb1f9856d437697c26cdc529ad44 Mon Sep 17 00:00:00 2001 From: ko1N Date: Wed, 27 Mar 2024 01:48:52 +0100 Subject: [PATCH] Added mf_ prefix to all functions exported to c/cpp. This ensures we do not get confilcts with other libraries such as spice (thanks to reactiion for reporting) --- memflow-ffi/examples/c/find_process.c | 26 +++++------ memflow-ffi/examples/c/module_dump.c | 27 ++++++----- memflow-ffi/examples/c/module_list.c | 25 +++++----- memflow-ffi/examples/c/phys_mem.c | 8 ++-- memflow-ffi/examples/c/process_list.c | 19 ++++---- memflow-ffi/examples/cpp/plist.cpp | 16 +++---- memflow-ffi/memflow.h | 66 +++++++++++++-------------- memflow-ffi/memflow.hpp | 66 +++++++++++++-------------- memflow-ffi/src/architecture/mod.rs | 12 ++--- memflow-ffi/src/architecture/x86.rs | 2 +- memflow-ffi/src/log.rs | 20 ++++---- memflow-ffi/src/plugins/mod.rs | 18 ++++---- memflow-ffi/src/types/mod.rs | 2 +- 13 files changed, 151 insertions(+), 156 deletions(-) diff --git a/memflow-ffi/examples/c/find_process.c b/memflow-ffi/examples/c/find_process.c index b3f3ba2b..419d1aeb 100644 --- a/memflow-ffi/examples/c/find_process.c +++ b/memflow-ffi/examples/c/find_process.c @@ -11,7 +11,6 @@ struct FindProcessContext { }; bool find_process(struct FindProcessContext *find_context, Address addr) { - if (find_context->found) { return false; } @@ -39,14 +38,13 @@ bool find_process(struct FindProcessContext *find_context, Address addr) { } int main(int argc, char *argv[]) { - int ret = 0; // enable info level logging - log_init(3); + mf_log_init(3); // load all available plugins - Inventory *inventory = inventory_scan(); + Inventory *inventory = mf_inventory_scan(); printf("inventory initialized: %p\n", inventory); const char *conn_name = argc > 1 ? argv[1] : "qemu"; @@ -59,9 +57,9 @@ int main(int argc, char *argv[]) { // initialize the connector plugin if (conn) { - if (inventory_create_connector(inventory, conn_name, conn_arg, conn)) { - log_error("unable to initialize connector"); - inventory_free(inventory); + if (mf_inventory_create_connector(inventory, conn_name, conn_arg, conn)) { + mf_log_error("unable to initialize connector"); + mf_inventory_free(inventory); return 1; } @@ -70,9 +68,9 @@ int main(int argc, char *argv[]) { // initialize the OS plugin OsInstance os; - if (inventory_create_os(inventory, os_name, os_arg, conn, &os)) { - log_error("unable to initialize os plugin"); - inventory_free(inventory); + if (mf_inventory_create_os(inventory, os_name, os_arg, conn, &os)) { + mf_log_error("unable to initialize os plugin"); + mf_inventory_free(inventory); return 1; } @@ -113,16 +111,16 @@ int main(int argc, char *argv[]) { mf_processinstance_drop(target_process); } else { printf("Unable to find %s\n", target_proc); - log_debug_errorcode(ret); + mf_log_debug_errorcode(ret); } // This will also free the connector here // as it was _moved_ into the os by `inventory_create_os` mf_osinstance_drop(os); - log_info("os plugin/connector freed"); + mf_log_info("os plugin/connector freed"); - inventory_free(inventory); - log_info("inventory freed"); + mf_inventory_free(inventory); + mf_log_info("inventory freed"); return 0; } diff --git a/memflow-ffi/examples/c/module_dump.c b/memflow-ffi/examples/c/module_dump.c index a18b3b49..a93e6538 100644 --- a/memflow-ffi/examples/c/module_dump.c +++ b/memflow-ffi/examples/c/module_dump.c @@ -26,14 +26,13 @@ To read from a specific module the following steps have to be done: #include int main(int argc, char *argv[]) { - int ret = 0; // enable info level logging - log_init(4); + mf_log_init(4); // load all available plugins - Inventory *inventory = inventory_scan(); + Inventory *inventory = mf_inventory_scan(); printf("inventory initialized: %p\n", inventory); const char *conn_name = argc > 1 ? argv[1] : "qemu"; @@ -48,9 +47,9 @@ int main(int argc, char *argv[]) { // initialize the connector plugin if (conn) { - if (inventory_create_connector(inventory, conn_name, conn_arg, conn)) { - log_error("unable to initialize connector"); - inventory_free(inventory); + if (mf_inventory_create_connector(inventory, conn_name, conn_arg, conn)) { + mf_log_error("unable to initialize connector"); + mf_inventory_free(inventory); return 1; } @@ -59,9 +58,9 @@ int main(int argc, char *argv[]) { // initialize the OS plugin OsInstance os; - if (inventory_create_os(inventory, os_name, os_arg, conn, &os)) { - log_error("unable to initialize os plugin"); - inventory_free(inventory); + if (mf_inventory_create_os(inventory, os_name, os_arg, conn, &os)) { + mf_log_error("unable to initialize os plugin"); + mf_inventory_free(inventory); return 1; } @@ -104,23 +103,23 @@ int main(int argc, char *argv[]) { free(module_buffer); } else { printf("unable to find module: %s\n", target_module); - log_debug_errorcode(ret); + mf_log_debug_errorcode(ret); } // cleanup the processinstance mf_processinstance_drop(target_process); } else { printf("unable to find process: %s\n", target_proc); - log_debug_errorcode(ret); + mf_log_debug_errorcode(ret); } // This will also free the connector here // as it was _moved_ into the os by `inventory_create_os` mf_osinstance_drop(os); - log_info("os plugin/connector freed"); + mf_log_info("os plugin/connector freed"); - inventory_free(inventory); - log_info("inventory freed"); + mf_inventory_free(inventory); + mf_log_info("inventory freed"); return 0; } diff --git a/memflow-ffi/examples/c/module_list.c b/memflow-ffi/examples/c/module_list.c index 9cc52ad7..449b524a 100644 --- a/memflow-ffi/examples/c/module_list.c +++ b/memflow-ffi/examples/c/module_list.c @@ -4,14 +4,13 @@ #include int main(int argc, char *argv[]) { - int ret = 0; // enable info level logging - log_init(3); + mf_log_init(3); // load all available plugins - Inventory *inventory = inventory_scan(); + Inventory *inventory = mf_inventory_scan(); printf("inventory initialized: %p\n", inventory); const char *conn_name = argc > 1 ? argv[1] : "qemu"; @@ -24,9 +23,9 @@ int main(int argc, char *argv[]) { // initialize the connector plugin if (conn) { - if (inventory_create_connector(inventory, conn_name, conn_arg, conn)) { - log_error("unable to initialize connector"); - inventory_free(inventory); + if (mf_inventory_create_connector(inventory, conn_name, conn_arg, conn)) { + mf_log_error("unable to initialize connector"); + mf_inventory_free(inventory); return 1; } @@ -35,9 +34,9 @@ int main(int argc, char *argv[]) { // initialize the OS plugin OsInstance os; - if (inventory_create_os(inventory, os_name, os_arg, conn, &os)) { - log_error("unable to initialize os plugin"); - inventory_free(inventory); + if (mf_inventory_create_os(inventory, os_name, os_arg, conn, &os)) { + mf_log_error("unable to initialize os plugin"); + mf_inventory_free(inventory); return 1; } @@ -65,16 +64,16 @@ int main(int argc, char *argv[]) { mf_processinstance_drop(target_process); } else { printf("Unable to find %s\n", target_proc); - log_debug_errorcode(ret); + mf_log_debug_errorcode(ret); } // This will also free the connector here // as it was _moved_ into the os by `inventory_create_os` mf_osinstance_drop(os); - log_info("os plugin/connector freed"); + mf_log_info("os plugin/connector freed"); - inventory_free(inventory); - log_info("inventory freed"); + mf_inventory_free(inventory); + mf_log_info("inventory freed"); return 0; } diff --git a/memflow-ffi/examples/c/phys_mem.c b/memflow-ffi/examples/c/phys_mem.c index aee04155..caa858a3 100644 --- a/memflow-ffi/examples/c/phys_mem.c +++ b/memflow-ffi/examples/c/phys_mem.c @@ -4,16 +4,16 @@ int main(int argc, char *argv[]) { // enable debug level logging - log_init(3); + mf_log_init(3); - Inventory *inv = inventory_scan(); + Inventory *inv = mf_inventory_scan(); printf("inv: %p\n", inv); const char *conn_name = argc > 1 ? argv[1] : "kvm"; const char *conn_arg = argc > 2 ? argv[2] : ""; ConnectorInstance conn; - if (!inventory_create_connector(inv, conn_name, conn_arg, &conn)) { + if (!mf_inventory_create_connector(inv, conn_name, conn_arg, &conn)) { for (int i = 0; i < 1000 * 1000; i++) { uint8_t buffer[0x1000]; @@ -39,7 +39,7 @@ int main(int argc, char *argv[]) { printf("conn dropped!\n"); } - inventory_free(inv); + mf_inventory_free(inv); printf("inv freed!\n"); return 0; diff --git a/memflow-ffi/examples/c/process_list.c b/memflow-ffi/examples/c/process_list.c index 79765d0c..7c6080a4 100644 --- a/memflow-ffi/examples/c/process_list.c +++ b/memflow-ffi/examples/c/process_list.c @@ -3,12 +3,11 @@ #include bool list_processes(OsInstance *os, Address addr) { - int ret; ProcessInstance process; if ((ret = mf_osinstance_process_by_address(os, addr, &process))) { - log_debug_errorcode(ret); + mf_log_debug_errorcode(ret); return true; } @@ -18,7 +17,7 @@ bool list_processes(OsInstance *os, Address addr) { if ((ret = mf_processinstance_primary_module(&process, &primary_module))) { // no primary module found, continue iteration - this should _never_ happen printf("%d\t%s\t0x%lx\tN/A\n", info->pid, info->name, info->address); - log_debug_errorcode(ret); + mf_log_debug_errorcode(ret); return true; } @@ -63,10 +62,10 @@ bool list_processes(OsInstance *os, Address addr) { int main(int argc, char *argv[]) { // enable debug level logging - log_init(2); + mf_log_init(2); // load all available plugins - Inventory *inventory = inventory_scan(); + Inventory *inventory = mf_inventory_scan(); printf("inventory initialized: %p\n", inventory); @@ -79,9 +78,9 @@ int main(int argc, char *argv[]) { // initialize the connector plugin if (conn) { - if (inventory_create_connector(inventory, conn_name, conn_arg, conn)) { + if (mf_inventory_create_connector(inventory, conn_name, conn_arg, conn)) { printf("unable to initialize connector\n"); - inventory_free(inventory); + mf_inventory_free(inventory); return 1; } @@ -90,9 +89,9 @@ int main(int argc, char *argv[]) { // initialize the OS plugin OsInstance os; - if (inventory_create_os(inventory, os_name, os_arg, conn, &os)) { + if (mf_inventory_create_os(inventory, os_name, os_arg, conn, &os)) { printf("unable to initialize os plugin\n"); - inventory_free(inventory); + mf_inventory_free(inventory); return 1; } @@ -118,7 +117,7 @@ int main(int argc, char *argv[]) { mf_osinstance_drop(os); printf("os plugin/connector freed\n"); - inventory_free(inventory); + mf_inventory_free(inventory); printf("inventory freed\n"); return 0; diff --git a/memflow-ffi/examples/cpp/plist.cpp b/memflow-ffi/examples/cpp/plist.cpp index 80af30df..6196101f 100644 --- a/memflow-ffi/examples/cpp/plist.cpp +++ b/memflow-ffi/examples/cpp/plist.cpp @@ -5,12 +5,12 @@ void fmt_arch(char *arch, int n, ArchitectureIdent ident); int main(int argc, char *argv[]) { - log_init(LevelFilter::LevelFilter_Info); + mf_log_init(LevelFilter::LevelFilter_Info); - Inventory *inventory = inventory_scan(); + Inventory *inventory = mf_inventory_scan(); if (!inventory) { - log_error("unable to create inventory"); + mf_log_error("unable to create inventory"); return 1; } @@ -24,9 +24,9 @@ int main(int argc, char *argv[]) { ConnectorInstance<> connector, *conn = conn_name[0] ? &connector : nullptr; if (conn) { - if (inventory_create_connector(inventory, conn_name, conn_arg, &connector)) { + if (mf_inventory_create_connector(inventory, conn_name, conn_arg, &connector)) { printf("unable to initialize connector\n"); - inventory_free(inventory); + mf_inventory_free(inventory); return 1; } @@ -35,13 +35,13 @@ int main(int argc, char *argv[]) { OsInstance<> os; - if (inventory_create_os(inventory, os_name, os_arg, conn, &os)) { + if (mf_inventory_create_os(inventory, os_name, os_arg, conn, &os)) { printf("unable to initialize OS\n"); - inventory_free(inventory); + mf_inventory_free(inventory); return 1; } - inventory_free(inventory); + mf_inventory_free(inventory); printf("os initialized: %p\n", os.container.instance.instance); diff --git a/memflow-ffi/memflow.h b/memflow-ffi/memflow.h index c64bb943..92f0fd34 100644 --- a/memflow-ffi/memflow.h +++ b/memflow-ffi/memflow.h @@ -2419,7 +2419,7 @@ extern const struct ArchitectureObj *X86_64; /** * Initialize logging with selected logging level. */ -void log_init(LevelFilter level_filter); +void mf_log_init(LevelFilter level_filter); /** * Logs a error message via log::error! @@ -2428,7 +2428,7 @@ void log_init(LevelFilter level_filter); * * The provided string must be a valid null-terminated char array. */ -void log_error(const char *s); +void mf_log_error(const char *s); /** * Logs a warning message via log::warn! @@ -2437,7 +2437,7 @@ void log_error(const char *s); * * The provided string must be a valid null-terminated char array. */ -void log_warn(const char *s); +void mf_log_warn(const char *s); /** * Logs a info message via log::info! @@ -2446,7 +2446,7 @@ void log_warn(const char *s); * * The provided string must be a valid null-terminated char array. */ -void log_info(const char *s); +void mf_log_info(const char *s); /** * Logs a debug message via log::debug! @@ -2455,7 +2455,7 @@ void log_info(const char *s); * * The provided string must be a valid null-terminated char array. */ -void log_debug(const char *s); +void mf_log_debug(const char *s); /** * Logs a trace message via log::trace! @@ -2464,17 +2464,17 @@ void log_debug(const char *s); * * The provided string must be a valid null-terminated char array. */ -void log_trace(const char *s); +void mf_log_trace(const char *s); /** * Logs an error code with custom log level. */ -void log_errorcode(Level level, int32_t error); +void mf_log_errorcode(Level level, int32_t error); /** * Logs an error with debug log level. */ -void log_debug_errorcode(int32_t error); +void mf_log_debug_errorcode(int32_t error); /** * Sets new maximum log level. @@ -2483,14 +2483,14 @@ void log_debug_errorcode(int32_t error); * if it is not supplied, plugins will not have their log levels updated, potentially leading to * lower performance, or less logging than expected. */ -void log_set_max_level(LevelFilter level_filter, const struct Inventory *inventory); +void mf_log_set_max_level(LevelFilter level_filter, const struct Inventory *inventory); /** * Helper to convert `Address` to a `PhysicalAddress` * * This will create a `PhysicalAddress` with `UNKNOWN` PageType. */ -struct PhysicalAddress addr_to_paddr(Address address); +struct PhysicalAddress mf_addr_to_paddr(Address address); /** * Create a new connector inventory @@ -2505,7 +2505,7 @@ struct PhysicalAddress addr_to_paddr(Address address); * Inventory is inherently unsafe, because it loads shared libraries which can not be * guaranteed to be safe. */ -struct Inventory *inventory_scan(void); +struct Inventory *mf_inventory_scan(void); /** * Create a new inventory with custom path string @@ -2514,7 +2514,7 @@ struct Inventory *inventory_scan(void); * * `path` must be a valid null terminated string */ -struct Inventory *inventory_scan_path(const char *path); +struct Inventory *mf_inventory_scan_path(const char *path); /** * Add a directory to an existing inventory @@ -2523,7 +2523,7 @@ struct Inventory *inventory_scan_path(const char *path); * * `dir` must be a valid null terminated string */ -int32_t inventory_add_dir(struct Inventory *inv, const char *dir); +int32_t mf_inventory_add_dir(struct Inventory *inv, const char *dir); /** * Create a connector with given arguments @@ -2544,10 +2544,10 @@ int32_t inventory_add_dir(struct Inventory *inv, const char *dir); * Any error strings returned by the connector must not be outputed after the connector gets * freed, because that operation could cause the underlying shared library to get unloaded. */ -int32_t inventory_create_connector(struct Inventory *inv, - const char *name, - const char *args, - MuConnectorInstanceArcBox *out); +int32_t mf_inventory_create_connector(struct Inventory *inv, + const char *name, + const char *args, + MuConnectorInstanceArcBox *out); /** * Create a OS instance with given arguments @@ -2575,11 +2575,11 @@ int32_t inventory_create_connector(struct Inventory *inv, * Any error strings returned by the connector must not be outputed after the connector gets * freed, because that operation could cause the underlying shared library to get unloaded. */ -int32_t inventory_create_os(struct Inventory *inv, - const char *name, - const char *args, - ConnectorInstanceArcBox *mem, - MuOsInstanceArcBox *out); +int32_t mf_inventory_create_os(struct Inventory *inv, + const char *name, + const char *args, + ConnectorInstanceArcBox *mem, + MuOsInstanceArcBox *out); /** * Free a os plugin @@ -2589,7 +2589,7 @@ int32_t inventory_create_os(struct Inventory *inv, * `os` must point to a valid `OsInstance` that was created using one of the provided * functions. */ -void os_drop(OsInstanceArcBox *os); +void mf_os_drop(OsInstanceArcBox *os); /** * Clone a connector @@ -2603,7 +2603,7 @@ void os_drop(OsInstanceArcBox *os); * `conn` has to point to a a valid `CloneablePhysicalMemory` created by one of the provided * functions. */ -void connector_clone(const ConnectorInstanceArcBox *conn, MuConnectorInstanceArcBox *out); +void mf_connector_clone(const ConnectorInstanceArcBox *conn, MuConnectorInstanceArcBox *out); /** * Free a connector instance @@ -2616,7 +2616,7 @@ void connector_clone(const ConnectorInstanceArcBox *conn, MuConnectorInstanceArc * There has to be no instance of `PhysicalMemory` created from the input `conn`, because they * will become invalid. */ -void connector_drop(ConnectorInstanceArcBox *conn); +void mf_connector_drop(ConnectorInstanceArcBox *conn); /** * Free a connector inventory @@ -2626,17 +2626,17 @@ void connector_drop(ConnectorInstanceArcBox *conn); * `inv` must point to a valid `Inventory` that was created using one of the provided * functions. */ -void inventory_free(struct Inventory *inv); +void mf_inventory_free(struct Inventory *inv); -uint8_t arch_bits(const struct ArchitectureObj *arch); +uint8_t mf_arch_bits(const struct ArchitectureObj *arch); -Endianess arch_endianess(const struct ArchitectureObj *arch); +Endianess mf_arch_endianess(const struct ArchitectureObj *arch); -uintptr_t arch_page_size(const struct ArchitectureObj *arch); +uintptr_t mf_arch_page_size(const struct ArchitectureObj *arch); -uintptr_t arch_size_addr(const struct ArchitectureObj *arch); +uintptr_t mf_arch_size_addr(const struct ArchitectureObj *arch); -uint8_t arch_address_space_bits(const struct ArchitectureObj *arch); +uint8_t mf_arch_address_space_bits(const struct ArchitectureObj *arch); /** * Free an architecture reference @@ -2645,9 +2645,9 @@ uint8_t arch_address_space_bits(const struct ArchitectureObj *arch); * * `arch` must be a valid heap allocated reference created by one of the API's functions. */ -void arch_free(struct ArchitectureObj *arch); +void mf_arch_free(struct ArchitectureObj *arch); -bool is_x86_arch(const struct ArchitectureObj *arch); +bool mf_is_x86_arch(const struct ArchitectureObj *arch); static CArc_c_void ctx_arc_clone(CArc_c_void *self) { CArc_c_void ret = *self; ret.instance = self->clone_fn(self->instance); diff --git a/memflow-ffi/memflow.hpp b/memflow-ffi/memflow.hpp index a3e2ceae..283ebd6e 100644 --- a/memflow-ffi/memflow.hpp +++ b/memflow-ffi/memflow.hpp @@ -2996,7 +2996,7 @@ extern const ArchitectureObj *X86_64; /** * Initialize logging with selected logging level. */ -void log_init(LevelFilter level_filter); +void mf_log_init(LevelFilter level_filter); /** * Logs a error message via log::error! @@ -3005,7 +3005,7 @@ void log_init(LevelFilter level_filter); * * The provided string must be a valid null-terminated char array. */ -void log_error(const char *s); +void mf_log_error(const char *s); /** * Logs a warning message via log::warn! @@ -3014,7 +3014,7 @@ void log_error(const char *s); * * The provided string must be a valid null-terminated char array. */ -void log_warn(const char *s); +void mf_log_warn(const char *s); /** * Logs a info message via log::info! @@ -3023,7 +3023,7 @@ void log_warn(const char *s); * * The provided string must be a valid null-terminated char array. */ -void log_info(const char *s); +void mf_log_info(const char *s); /** * Logs a debug message via log::debug! @@ -3032,7 +3032,7 @@ void log_info(const char *s); * * The provided string must be a valid null-terminated char array. */ -void log_debug(const char *s); +void mf_log_debug(const char *s); /** * Logs a trace message via log::trace! @@ -3041,17 +3041,17 @@ void log_debug(const char *s); * * The provided string must be a valid null-terminated char array. */ -void log_trace(const char *s); +void mf_log_trace(const char *s); /** * Logs an error code with custom log level. */ -void log_errorcode(Level level, int32_t error); +void mf_log_errorcode(Level level, int32_t error); /** * Logs an error with debug log level. */ -void log_debug_errorcode(int32_t error); +void mf_log_debug_errorcode(int32_t error); /** * Sets new maximum log level. @@ -3060,14 +3060,14 @@ void log_debug_errorcode(int32_t error); * if it is not supplied, plugins will not have their log levels updated, potentially leading to * lower performance, or less logging than expected. */ -void log_set_max_level(LevelFilter level_filter, const Inventory *inventory); +void mf_log_set_max_level(LevelFilter level_filter, const Inventory *inventory); /** * Helper to convert `Address` to a `PhysicalAddress` * * This will create a `PhysicalAddress` with `UNKNOWN` PageType. */ -PhysicalAddress addr_to_paddr(Address address); +PhysicalAddress mf_addr_to_paddr(Address address); /** * Create a new connector inventory @@ -3082,7 +3082,7 @@ PhysicalAddress addr_to_paddr(Address address); * Inventory is inherently unsafe, because it loads shared libraries which can not be * guaranteed to be safe. */ -Inventory *inventory_scan(); +Inventory *mf_inventory_scan(); /** * Create a new inventory with custom path string @@ -3091,7 +3091,7 @@ Inventory *inventory_scan(); * * `path` must be a valid null terminated string */ -Inventory *inventory_scan_path(const char *path); +Inventory *mf_inventory_scan_path(const char *path); /** * Add a directory to an existing inventory @@ -3100,7 +3100,7 @@ Inventory *inventory_scan_path(const char *path); * * `dir` must be a valid null terminated string */ -int32_t inventory_add_dir(Inventory *inv, const char *dir); +int32_t mf_inventory_add_dir(Inventory *inv, const char *dir); /** * Create a connector with given arguments @@ -3121,10 +3121,10 @@ int32_t inventory_add_dir(Inventory *inv, const char *dir); * Any error strings returned by the connector must not be outputed after the connector gets * freed, because that operation could cause the underlying shared library to get unloaded. */ -int32_t inventory_create_connector(Inventory *inv, - const char *name, - const char *args, - MuConnectorInstanceArcBox *out); +int32_t mf_inventory_create_connector(Inventory *inv, + const char *name, + const char *args, + MuConnectorInstanceArcBox *out); /** * Create a OS instance with given arguments @@ -3152,11 +3152,11 @@ int32_t inventory_create_connector(Inventory *inv, * Any error strings returned by the connector must not be outputed after the connector gets * freed, because that operation could cause the underlying shared library to get unloaded. */ -int32_t inventory_create_os(Inventory *inv, - const char *name, - const char *args, - ConnectorInstanceArcBox *mem, - MuOsInstanceArcBox *out); +int32_t mf_inventory_create_os(Inventory *inv, + const char *name, + const char *args, + ConnectorInstanceArcBox *mem, + MuOsInstanceArcBox *out); /** * Free a os plugin @@ -3166,7 +3166,7 @@ int32_t inventory_create_os(Inventory *inv, * `os` must point to a valid `OsInstance` that was created using one of the provided * functions. */ -void os_drop(OsInstanceArcBox *os); +void mf_os_drop(OsInstanceArcBox *os); /** * Clone a connector @@ -3180,7 +3180,7 @@ void os_drop(OsInstanceArcBox *os); * `conn` has to point to a a valid `CloneablePhysicalMemory` created by one of the provided * functions. */ -void connector_clone(const ConnectorInstanceArcBox *conn, MuConnectorInstanceArcBox *out); +void mf_connector_clone(const ConnectorInstanceArcBox *conn, MuConnectorInstanceArcBox *out); /** * Free a connector instance @@ -3193,7 +3193,7 @@ void connector_clone(const ConnectorInstanceArcBox *conn, MuConnectorInstanceArc * There has to be no instance of `PhysicalMemory` created from the input `conn`, because they * will become invalid. */ -void connector_drop(ConnectorInstanceArcBox *conn); +void mf_connector_drop(ConnectorInstanceArcBox *conn); /** * Free a connector inventory @@ -3203,17 +3203,17 @@ void connector_drop(ConnectorInstanceArcBox *conn); * `inv` must point to a valid `Inventory` that was created using one of the provided * functions. */ -void inventory_free(Inventory *inv); +void mf_inventory_free(Inventory *inv); -uint8_t arch_bits(const ArchitectureObj *arch); +uint8_t mf_arch_bits(const ArchitectureObj *arch); -Endianess arch_endianess(const ArchitectureObj *arch); +Endianess mf_arch_endianess(const ArchitectureObj *arch); -uintptr_t arch_page_size(const ArchitectureObj *arch); +uintptr_t mf_arch_page_size(const ArchitectureObj *arch); -uintptr_t arch_size_addr(const ArchitectureObj *arch); +uintptr_t mf_arch_size_addr(const ArchitectureObj *arch); -uint8_t arch_address_space_bits(const ArchitectureObj *arch); +uint8_t mf_arch_address_space_bits(const ArchitectureObj *arch); /** * Free an architecture reference @@ -3222,9 +3222,9 @@ uint8_t arch_address_space_bits(const ArchitectureObj *arch); * * `arch` must be a valid heap allocated reference created by one of the API's functions. */ -void arch_free(ArchitectureObj *arch); +void mf_arch_free(ArchitectureObj *arch); -bool is_x86_arch(const ArchitectureObj *arch); +bool mf_is_x86_arch(const ArchitectureObj *arch); } // extern "C" diff --git a/memflow-ffi/src/architecture/mod.rs b/memflow-ffi/src/architecture/mod.rs index b0f2fb18..ae7b1f8b 100644 --- a/memflow-ffi/src/architecture/mod.rs +++ b/memflow-ffi/src/architecture/mod.rs @@ -3,27 +3,27 @@ use memflow::architecture::{ArchitectureObj, Endianess}; pub mod x86; #[no_mangle] -pub extern "C" fn arch_bits(arch: &ArchitectureObj) -> u8 { +pub extern "C" fn mf_arch_bits(arch: &ArchitectureObj) -> u8 { arch.bits() } #[no_mangle] -pub extern "C" fn arch_endianess(arch: &ArchitectureObj) -> Endianess { +pub extern "C" fn mf_arch_endianess(arch: &ArchitectureObj) -> Endianess { arch.endianess() } #[no_mangle] -pub extern "C" fn arch_page_size(arch: &ArchitectureObj) -> usize { +pub extern "C" fn mf_arch_page_size(arch: &ArchitectureObj) -> usize { arch.page_size() } #[no_mangle] -pub extern "C" fn arch_size_addr(arch: &ArchitectureObj) -> usize { +pub extern "C" fn mf_arch_size_addr(arch: &ArchitectureObj) -> usize { arch.size_addr() } #[no_mangle] -pub extern "C" fn arch_address_space_bits(arch: &ArchitectureObj) -> u8 { +pub extern "C" fn mf_arch_address_space_bits(arch: &ArchitectureObj) -> u8 { arch.address_space_bits() } @@ -33,6 +33,6 @@ pub extern "C" fn arch_address_space_bits(arch: &ArchitectureObj) -> u8 { /// /// `arch` must be a valid heap allocated reference created by one of the API's functions. #[no_mangle] -pub unsafe extern "C" fn arch_free(arch: &'static mut ArchitectureObj) { +pub unsafe extern "C" fn mf_arch_free(arch: &'static mut ArchitectureObj) { let _ = Box::from_raw(arch); } diff --git a/memflow-ffi/src/architecture/x86.rs b/memflow-ffi/src/architecture/x86.rs index 5af59c53..79617b82 100644 --- a/memflow-ffi/src/architecture/x86.rs +++ b/memflow-ffi/src/architecture/x86.rs @@ -10,7 +10,7 @@ pub static X86_32_PAE: &ArchitectureObj = &x86::x32_pae::ARCH; pub static X86_64: &ArchitectureObj = &x86::x64::ARCH; #[no_mangle] -pub extern "C" fn is_x86_arch(arch: &ArchitectureObj) -> bool { +pub extern "C" fn mf_is_x86_arch(arch: &ArchitectureObj) -> bool { x86::is_x86_arch(*arch) } diff --git a/memflow-ffi/src/log.rs b/memflow-ffi/src/log.rs index 6610ebe7..e1165f55 100644 --- a/memflow-ffi/src/log.rs +++ b/memflow-ffi/src/log.rs @@ -9,7 +9,7 @@ use std::os::raw::c_char; /// Initialize logging with selected logging level. #[no_mangle] -pub extern "C" fn log_init(level_filter: LevelFilter) { +pub extern "C" fn mf_log_init(level_filter: LevelFilter) { simplelog::TermLogger::init( level_filter, simplelog::Config::default(), @@ -27,7 +27,7 @@ pub extern "C" fn log_init(level_filter: LevelFilter) { /// /// The provided string must be a valid null-terminated char array. #[no_mangle] -pub unsafe extern "C" fn log_error(s: *const c_char) { +pub unsafe extern "C" fn mf_log_error(s: *const c_char) { if !s.is_null() { let c_str = CStr::from_ptr(s); if let Ok(r_str) = c_str.to_str() { @@ -42,7 +42,7 @@ pub unsafe extern "C" fn log_error(s: *const c_char) { /// /// The provided string must be a valid null-terminated char array. #[no_mangle] -pub unsafe extern "C" fn log_warn(s: *const c_char) { +pub unsafe extern "C" fn mf_log_warn(s: *const c_char) { if !s.is_null() { let c_str = CStr::from_ptr(s); if let Ok(r_str) = c_str.to_str() { @@ -57,7 +57,7 @@ pub unsafe extern "C" fn log_warn(s: *const c_char) { /// /// The provided string must be a valid null-terminated char array. #[no_mangle] -pub unsafe extern "C" fn log_info(s: *const c_char) { +pub unsafe extern "C" fn mf_log_info(s: *const c_char) { if !s.is_null() { let c_str = CStr::from_ptr(s); if let Ok(r_str) = c_str.to_str() { @@ -72,7 +72,7 @@ pub unsafe extern "C" fn log_info(s: *const c_char) { /// /// The provided string must be a valid null-terminated char array. #[no_mangle] -pub unsafe extern "C" fn log_debug(s: *const c_char) { +pub unsafe extern "C" fn mf_log_debug(s: *const c_char) { if !s.is_null() { let c_str = CStr::from_ptr(s); if let Ok(r_str) = c_str.to_str() { @@ -87,7 +87,7 @@ pub unsafe extern "C" fn log_debug(s: *const c_char) { /// /// The provided string must be a valid null-terminated char array. #[no_mangle] -pub unsafe extern "C" fn log_trace(s: *const c_char) { +pub unsafe extern "C" fn mf_log_trace(s: *const c_char) { if !s.is_null() { let c_str = CStr::from_ptr(s); if let Ok(r_str) = c_str.to_str() { @@ -98,7 +98,7 @@ pub unsafe extern "C" fn log_trace(s: *const c_char) { /// Logs an error code with custom log level. #[no_mangle] -pub extern "C" fn log_errorcode(level: Level, error: i32) { +pub extern "C" fn mf_log_errorcode(level: Level, error: i32) { if let Some(error) = NonZeroI32::new(error) { log::log!(level, "{}", ::from_int_err(error)); } @@ -106,8 +106,8 @@ pub extern "C" fn log_errorcode(level: Level, error: i32) { /// Logs an error with debug log level. #[no_mangle] -pub extern "C" fn log_debug_errorcode(error: i32) { - log_errorcode(Level::Debug, error) +pub extern "C" fn mf_log_debug_errorcode(error: i32) { + mf_log_errorcode(Level::Debug, error) } /// Sets new maximum log level. @@ -116,7 +116,7 @@ pub extern "C" fn log_debug_errorcode(error: i32) { /// if it is not supplied, plugins will not have their log levels updated, potentially leading to /// lower performance, or less logging than expected. #[no_mangle] -pub extern "C" fn log_set_max_level(level_filter: LevelFilter, inventory: Option<&Inventory>) { +pub extern "C" fn mf_log_set_max_level(level_filter: LevelFilter, inventory: Option<&Inventory>) { if let Some(inventory) = inventory { inventory.set_max_log_level(level_filter); } else { diff --git a/memflow-ffi/src/plugins/mod.rs b/memflow-ffi/src/plugins/mod.rs index 48e31ee9..6eee7c10 100644 --- a/memflow-ffi/src/plugins/mod.rs +++ b/memflow-ffi/src/plugins/mod.rs @@ -25,7 +25,7 @@ use log::trace; /// Inventory is inherently unsafe, because it loads shared libraries which can not be /// guaranteed to be safe. #[no_mangle] -pub unsafe extern "C" fn inventory_scan() -> &'static mut Inventory { +pub unsafe extern "C" fn mf_inventory_scan() -> &'static mut Inventory { to_heap(Inventory::scan()) } @@ -35,7 +35,7 @@ pub unsafe extern "C" fn inventory_scan() -> &'static mut Inventory { /// /// `path` must be a valid null terminated string #[no_mangle] -pub unsafe extern "C" fn inventory_scan_path( +pub unsafe extern "C" fn mf_inventory_scan_path( path: *const c_char, ) -> Option<&'static mut Inventory> { let rpath = CStr::from_ptr(path).to_string_lossy(); @@ -51,7 +51,7 @@ pub unsafe extern "C" fn inventory_scan_path( /// /// `dir` must be a valid null terminated string #[no_mangle] -pub unsafe extern "C" fn inventory_add_dir(inv: &mut Inventory, dir: *const c_char) -> i32 { +pub unsafe extern "C" fn mf_inventory_add_dir(inv: &mut Inventory, dir: *const c_char) -> i32 { let rdir = CStr::from_ptr(dir).to_string_lossy(); inv.add_dir(PathBuf::from(rdir.to_string())) @@ -76,7 +76,7 @@ pub unsafe extern "C" fn inventory_add_dir(inv: &mut Inventory, dir: *const c_ch /// Any error strings returned by the connector must not be outputed after the connector gets /// freed, because that operation could cause the underlying shared library to get unloaded. #[no_mangle] -pub unsafe extern "C" fn inventory_create_connector( +pub unsafe extern "C" fn mf_inventory_create_connector( inv: &mut Inventory, name: *const c_char, args: *const c_char, @@ -123,7 +123,7 @@ pub unsafe extern "C" fn inventory_create_connector( /// Any error strings returned by the connector must not be outputed after the connector gets /// freed, because that operation could cause the underlying shared library to get unloaded. #[no_mangle] -pub unsafe extern "C" fn inventory_create_os( +pub unsafe extern "C" fn mf_inventory_create_os( inv: &mut Inventory, name: *const c_char, args: *const c_char, @@ -163,7 +163,7 @@ pub unsafe extern "C" fn inventory_create_os( /// `os` must point to a valid `OsInstance` that was created using one of the provided /// functions. #[no_mangle] -pub unsafe extern "C" fn os_drop(os: &mut OsInstanceArcBox<'static>) { +pub unsafe extern "C" fn mf_os_drop(os: &mut OsInstanceArcBox<'static>) { trace!("connector_drop: {:?}", os as *mut _); std::ptr::drop_in_place(os); } @@ -179,7 +179,7 @@ pub unsafe extern "C" fn os_drop(os: &mut OsInstanceArcBox<'static>) { /// `conn` has to point to a a valid `CloneablePhysicalMemory` created by one of the provided /// functions. #[no_mangle] -pub unsafe extern "C" fn connector_clone( +pub unsafe extern "C" fn mf_connector_clone( conn: &ConnectorInstanceArcBox<'static>, out: &mut MuConnectorInstanceArcBox<'static>, ) { @@ -197,7 +197,7 @@ pub unsafe extern "C" fn connector_clone( /// There has to be no instance of `PhysicalMemory` created from the input `conn`, because they /// will become invalid. #[no_mangle] -pub unsafe extern "C" fn connector_drop(conn: &mut ConnectorInstanceArcBox<'static>) { +pub unsafe extern "C" fn mf_connector_drop(conn: &mut ConnectorInstanceArcBox<'static>) { trace!("connector_drop: {:?}", conn as *mut _); std::ptr::drop_in_place(conn) } @@ -209,7 +209,7 @@ pub unsafe extern "C" fn connector_drop(conn: &mut ConnectorInstanceArcBox<'stat /// `inv` must point to a valid `Inventory` that was created using one of the provided /// functions. #[no_mangle] -pub unsafe extern "C" fn inventory_free(inv: &'static mut Inventory) { +pub unsafe extern "C" fn mf_inventory_free(inv: &'static mut Inventory) { trace!("inventory_free: {:?}", inv as *mut _); let _ = Box::from_raw(inv); } diff --git a/memflow-ffi/src/types/mod.rs b/memflow-ffi/src/types/mod.rs index 760b66e9..2506e2d2 100644 --- a/memflow-ffi/src/types/mod.rs +++ b/memflow-ffi/src/types/mod.rs @@ -4,6 +4,6 @@ use memflow::types::{Address, PhysicalAddress}; /// /// This will create a `PhysicalAddress` with `UNKNOWN` PageType. #[no_mangle] -pub extern "C" fn addr_to_paddr(address: Address) -> PhysicalAddress { +pub extern "C" fn mf_addr_to_paddr(address: Address) -> PhysicalAddress { address.into() }