Skip to content

Commit

Permalink
Merge branch 'main' of github.com:memflow/memflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ko1N committed Apr 2, 2024
2 parents 68faf4f + db55eb5 commit 99889b6
Show file tree
Hide file tree
Showing 13 changed files with 151 additions and 156 deletions.
26 changes: 12 additions & 14 deletions memflow-ffi/examples/c/find_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ struct FindProcessContext {
};

bool find_process(struct FindProcessContext *find_context, Address addr) {

if (find_context->found) {
return false;
}
Expand Down Expand Up @@ -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";
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
27 changes: 13 additions & 14 deletions memflow-ffi/examples/c/module_dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ To read from a specific module the following steps have to be done:
#include <errno.h>

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";
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
25 changes: 12 additions & 13 deletions memflow-ffi/examples/c/module_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
#include <string.h>

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";
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
8 changes: 4 additions & 4 deletions memflow-ffi/examples/c/phys_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand All @@ -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;
Expand Down
19 changes: 9 additions & 10 deletions memflow-ffi/examples/c/process_list.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
#include <stdio.h>

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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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);

Expand All @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions memflow-ffi/examples/cpp/plist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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);

Expand Down

0 comments on commit 99889b6

Please sign in to comment.