More robust search for filename in memory at runtime
This commit is contained in:
parent
98b8ef391f
commit
47661cecc5
31
usb-driver.c
31
usb-driver.c
@ -674,6 +674,18 @@ long int _Z14isModuleLoadedPci(char *module_name, int i) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void cpr_segv_handler(int sig, siginfo_t *info, void *context) {
|
||||||
|
void *newmem;
|
||||||
|
|
||||||
|
DPRINTF("SEGV at %p, mapping memory\n", info->si_addr);
|
||||||
|
errno = 0;
|
||||||
|
newmem = mmap(info->si_addr, 1, PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED, -1, 0);
|
||||||
|
if (newmem != info->si_addr) {
|
||||||
|
perror("libusb-driver.so: Can't map memory, crashing now");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* XilCommNS::CPortResources::Instance() */
|
/* XilCommNS::CPortResources::Instance() */
|
||||||
void* _ZN9XilCommNS14CPortResources8InstanceEv() {
|
void* _ZN9XilCommNS14CPortResources8InstanceEv() {
|
||||||
static void* (*func) (void) = NULL;
|
static void* (*func) (void) = NULL;
|
||||||
@ -682,16 +694,33 @@ void* _ZN9XilCommNS14CPortResources8InstanceEv() {
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!func) {
|
if (!func) {
|
||||||
|
struct sigaction act, oldact;
|
||||||
|
int sighand_installed = 0;
|
||||||
|
|
||||||
func = (void* (*) (void)) dlsym(RTLD_NEXT, "_ZN9XilCommNS14CPortResources8InstanceEv");
|
func = (void* (*) (void)) dlsym(RTLD_NEXT, "_ZN9XilCommNS14CPortResources8InstanceEv");
|
||||||
|
|
||||||
|
DPRINTF("Installing signal-handler for SIGSEGV\n");
|
||||||
|
bzero(&act, sizeof(struct sigaction));
|
||||||
|
act.sa_sigaction = cpr_segv_handler;
|
||||||
|
act.sa_flags = SA_SIGINFO;
|
||||||
|
if (sigaction(SIGSEGV, &act, &oldact) == 0) {
|
||||||
|
sighand_installed = 1;
|
||||||
|
}
|
||||||
|
|
||||||
DPRINTF("Searching for filename starting at %p\n", func);
|
DPRINTF("Searching for filename starting at %p\n", func);
|
||||||
for(i = 0; i < 16384; i++) {
|
for(i = 0; i < 32768; i++) {
|
||||||
if (!strcmp(((char*)func)+i, "/proc/sys/dev/parport/%s/base-addr")) {
|
if (!strcmp(((char*)func)+i, "/proc/sys/dev/parport/%s/base-addr")) {
|
||||||
filename = ((char*)func)+i;
|
filename = ((char*)func)+i;
|
||||||
DPRINTF("Filename found at offset %p\n", (void*)(filename - ((char*)func)));
|
DPRINTF("Filename found at offset %p\n", (void*)(filename - ((char*)func)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (sighand_installed) {
|
||||||
|
DPRINTF("Restoring signal-handler for SIGSEGV\n");
|
||||||
|
sigaction(SIGSEGV, &oldact, NULL);
|
||||||
|
}
|
||||||
|
if (!filename)
|
||||||
|
fprintf(stderr, "libusb-driver.so: Can't find memory to patch, parallel cables will probably not work!\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filename) {
|
if (filename) {
|
||||||
|
Reference in New Issue
Block a user