Created
November 22, 2018 01:49
-
-
Save simons-public/5890e7b5ca7e2375ba24223ce815f23a to your computer and use it in GitHub Desktop.
Example for loading steamfixes
This file contains hidden or 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
| #define _GNU_SOURCE | |
| #include <stdio.h> | |
| #include <string.h> | |
| #include <stdlib.h> | |
| #include <dlfcn.h> | |
| #define LOADER "steamfixes" | |
| typedef ssize_t (*execve_func_t)(const char* filename, char* const argv[], char* const envp[]); | |
| static execve_func_t sys_execve = NULL; | |
| int execve(const char* filename, char* const argv[], char* const envp[]) { | |
| char* appid; | |
| appid = secure_getenv("SteamAppId"); | |
| /* checking for LOADER in the filename prevents infinite looping */ | |
| if (appid != NULL && strcmp(filename, LOADER) != 0) | |
| { | |
| #ifdef DEBUG | |
| printf("Hooked SteamAppId: %s\n", appid); | |
| printf("Running %s with %s\n", filename, LOADER); | |
| #endif | |
| char new_fn[] = LOADER; | |
| char *new_argv[20]; | |
| new_argv[0] = LOADER; | |
| int i = 1; | |
| while(*argv != NULL) | |
| { | |
| new_argv[i] = *argv; | |
| argv++; | |
| i++; | |
| } | |
| sys_execve = dlsym(RTLD_NEXT, "execve"); | |
| return sys_execve(new_fn, new_argv, envp); | |
| } else { | |
| /* return origininal execve */ | |
| sys_execve = dlsym(RTLD_NEXT, "execve"); | |
| return sys_execve(filename, argv, envp); | |
| } | |
| } |
This file contains hidden or 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
| loader.so: | |
| gcc -std=c99 -DDEBUG -g -o loader.so --shared loader.c -Wall | |
| clean: | |
| rm loader.so |
This file contains hidden or 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
| #!/bin/sh | |
| PATH=$PATH:. | |
| function print(){ | |
| echo $(tput setaf 2)$@$(tput sgr0) | |
| } | |
| if [ ! -f loader.so ]; then | |
| print Compile loader.so with \'make\' first | |
| exit 0 | |
| fi | |
| print Testing without SteamAppId in env | |
| LD_PRELOAD=${PWD}/loader.so sh -c 'whoami' | |
| print End test | |
| print Testing with SteamAppId in env | |
| SteamAppId=555 LD_PRELOAD=${PWD}/loader.so sh -c 'whoami' | |
| print End test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment