From 51efae2e18f2c13d9a056a21ccb824565632a8e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mariusz=20Koz=C5=82owski?= Date: Sun, 29 Sep 2024 11:21:32 +0200 Subject: [PATCH] Print memrc arch and kernel uname info This should make anlyzing logs easier. --- Makefile | 4 ++-- memcr.c | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 6c16e5c..3543ad8 100644 --- a/Makefile +++ b/Makefile @@ -104,7 +104,7 @@ endif PCFLAGS += -Wstrict-prototypes -fno-stack-protector -fpie -nostdlib -ffreestanding -fomit-frame-pointer -Wa,--noexecstack -GIT_VERSION = $(shell (git describe --dirty 2>/dev/null || echo "unknown") | sed 's/^v//') +GIT_VERSION = $(shell (git describe --dirty=+ 2>/dev/null || echo "unknown") | sed 's/^v//') GOFF = ./gen-offsets.sh @@ -143,7 +143,7 @@ $(B)/cpu.o: arch/$(ARCH)/cpu.c $(CC) $(MCFLAGS) -c $^ -o $@ $(B)/memcr.o: memcr.c $(B)/parasite-blob.h - $(CC) $(MCFLAGS) -DGIT_VERSION='"$(GIT_VERSION)"' -I$(B) -c $< -o $@ + $(CC) $(MCFLAGS) -DGIT_VERSION='"$(GIT_VERSION)"' -DARCH_NAME='"$(ARCH)"' -I$(B) -c $< -o $@ $(B)/memcr: $(B)/memcr.o $(B)/cpu.o $(B)/enter.o $(CC) $(MCFLAGS) $^ $(LDFLAGS) -o $@ diff --git a/memcr.c b/memcr.c index 8a27357..a6b33d5 100644 --- a/memcr.c +++ b/memcr.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -65,6 +66,10 @@ #include "arch/enter.h" #include "parasite-blob.h" +#ifndef ARCH_NAME +#define ARCH_NAME "unknown" +#endif + #define NT_PRSTATUS 1 #define __round_mask(x, y) ((__typeof__(x))((y)-1)) @@ -2838,7 +2843,15 @@ static int user_interactive_mode(pid_t pid) static void print_version(void) { - fprintf(stdout, "[i] memcr version %s\n", GIT_VERSION); + int ret; + struct utsname utsn; + char buf[256] = { 0 }; + + ret = uname(&utsn); + if (!ret) + snprintf(buf, sizeof(buf), " kernel %s %s", utsn.release, utsn.machine); + + fprintf(stdout, "[i] memcr %s %s%s\n", GIT_VERSION, ARCH_NAME, buf); } static void usage(const char *name, int status)