All pastes #365454 Raw Edit

loljews

public c v1 · immutable
#365454 ·published 2007-02-20 23:41 UTC
rendered paste body
#define _GNU_SOURCE#include <dlfcn.h>#include <libgen.h>#include <linux/limits.h>#include <stdarg.h>#include <stdio.h>#include <stdint.h>#include <stdlib.h>#include <string.h>#include <sys/mman.h>#include <sys/types.h>#include <unistd.h>#define DLSYM_GOT_260B	0x0804adb0#define DLOPEN_GOT_260B 0x0804b830//from sdk#define	RF_DEPTHHACK	0x000008		// for view weapon Z crunching#define	RF_NOSHADOW	0x000010		// don't add stencil shadows#define CG_R_ADDREFENTITYTOSCENE 60typedef int syscall_t(int command, ...);typedef void dllEntry_t(syscall_t *);syscall_t  *orig_syscall = NULL;dllEntry_t *orig_dllEntry = NULL;void *cgameLibHandle = NULL;// do t3h depthhackint our_syscall(int command, ...) {	int arg[10];	va_list args;	va_start(args, command);	int count = 0;	for (; count < 10; count++)		arg[count] = va_arg(args, int);	va_end(args);	if( command == CG_R_ADDREFENTITYTOSCENE ){		// arg[0] passes pointer to a refEntity_t, just change renderfx at right offset (which is 4)		//refEnt->renderfx |= RF_DEPTHHACK | RF_NOSHADOW;		*(int *)(arg[0]+4) |= RF_DEPTHHACK | RF_NOSHADOW;	}	return orig_syscall(command, arg[0], arg[1], arg[2], arg[3], arg[4], arg[5], arg[6], arg[7], arg[8], arg[9]);}void cg_dllEntry(syscall_t *syscallptr) {	orig_syscall = syscallptr;	orig_dllEntry(our_syscall);}// detour dllEntry so we can intercept cgame's syscallvoid *our_dlsym(void *handle, const char *symbol) {	void *result = dlsym(handle, symbol);	// Hook dllEntry		if (!strcmp(symbol, "dllEntry") && handle ==  cgameLibHandle ) {		orig_dllEntry = result;		return cg_dllEntry;	}	return result;}// get the libhandle to cgamevoid *our_dlopen(const char *filename, int flag) {	void *result = dlopen(filename, flag);	if (result && filename)		if (strstr(filename, "cgame.mp.i386.so"))						cgameLibHandle = result;}//this is the dll initat0rvoid __attribute__ ((constructor)) hookInit() {	char exeFilename[PATH_MAX];	memset(exeFilename, 0, sizeof(exeFilename));	if (readlink("/proc/self/exe", exeFilename, sizeof(exeFilename)) <= 0) {		printf("Can't find et.x86\n");		exit(1);	}	// Find et.x86	if (!strcmp(basename(exeFilename), "et.x86")) {		// hook dlsym() and dlopen() through GOT		*(void **)DLSYM_GOT_260B = our_dlsym;		*(void **)DLOPEN_GOT_260B = our_dlopen;	}}