Last active
June 13, 2023 06:55
-
-
Save nanpuyue/81d4a3ae1b3a18b6ba640a70ad86ca14 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// date: 2023-06-12 | |
// license: GPLv3 https://www.gnu.org/licenses/gpl-3.0.txt | |
// author: nanpuyue <[email protected]> https://blog.nanpuyue.com | |
// build: gcc -fPIC -shared -o hook_uname.so hook_uname.c -ldl | |
// usage: LD_PRELOAD=./hook_uname.so uname -a | |
#include <string.h> | |
#include <dlfcn.h> | |
#include <sys/utsname.h> | |
typedef int (*uname_t) (struct utsname *); | |
int uname(struct utsname *buf) { | |
static uname_t _uname = NULL; | |
if(!_uname) { | |
_uname = (uname_t) dlsym(RTLD_NEXT, "uname"); | |
if (!_uname) { | |
return -1; | |
} | |
} | |
int ret = _uname(buf); | |
if (!ret) { | |
strncpy(buf->version, "custom_version", 15); | |
strncpy(buf->release, "5.15.0", 7); | |
} | |
return ret; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment