1 |
/* printf */ |
/* printf, sscanf, fgets, fprintf */ |
2 |
#include <stdio.h> |
#include <stdio.h> |
3 |
/* EXIT_SUCCESS */ |
/* exit, EXIT_SUCCESS, malloc, free */ |
4 |
#include <stdlib.h> |
#include <stdlib.h> |
5 |
/* NULL */ |
/* NULL */ |
6 |
#include <stddef.h> |
#include <stddef.h> |
7 |
/* dlopen, dlsym, dlerror */ |
/* dlopen, dlsym, dlerror */ |
8 |
#include <dlfcn.h> |
#include <dlfcn.h> |
9 |
/* assert */ |
/* strcmp, strcpy, strlen, strcat, strdup */ |
|
#include <assert.h> |
|
|
/* strcat */ |
|
10 |
#include <string.h> |
#include <string.h> |
11 |
|
|
12 |
#define HASHTBLSIZE 65536 |
#define HASHTBLSIZE 65536 |
196 |
} |
} |
197 |
|
|
198 |
/* Mangle a symbol name to a valid C identifier name */ |
/* Mangle a symbol name to a valid C identifier name */ |
199 |
char *mangle_(const char *old_string){ |
char *mangle_str(const char *old_string){ |
200 |
char validchars[] |
char validchars[] |
201 |
="0123456789abcdef"; |
="0123456789abcdef"; |
202 |
char *new_string, *current; |
char *new_string, *current; |
205 |
strcpy(new_string, "sx_"); /* Stack eXternal */ |
strcpy(new_string, "sx_"); /* Stack eXternal */ |
206 |
current=new_string+3; |
current=new_string+3; |
207 |
while(old_string[0] != '\0'){ |
while(old_string[0] != '\0'){ |
208 |
current[0]=validchars[old_string[0]/16]; |
current[0]=validchars[(unsigned char)(old_string[0])/16]; |
209 |
current[1]=validchars[old_string[0]%16]; |
current[1]=validchars[(unsigned char)(old_string[0])%16]; |
210 |
current+=2; |
current+=2; |
211 |
old_string++; |
old_string++; |
212 |
} |
} |
231 |
return; |
return; |
232 |
} |
} |
233 |
|
|
234 |
new_string= mangle_((const char *)(env->head->item->content.ptr)); |
new_string= mangle_str((const char *)(env->head->item->content.ptr)); |
235 |
|
|
236 |
toss(env); |
toss(env); |
237 |
if(env->err) return; |
if(env->err) return; |
294 |
funcptr= dlsym(handle, in_string); /* Get function pointer */ |
funcptr= dlsym(handle, in_string); /* Get function pointer */ |
295 |
dlerr=dlerror(); |
dlerr=dlerror(); |
296 |
if(dlerr != NULL) { /* If no function was found */ |
if(dlerr != NULL) { /* If no function was found */ |
297 |
mangled=mangle_(in_string); |
mangled=mangle_str(in_string); |
298 |
funcptr= dlsym(handle, mangled); /* try mangling it */ |
funcptr= dlsym(handle, mangled); /* try mangling it */ |
299 |
free(mangled); |
free(mangled); |
300 |
dlerr=dlerror(); |
dlerr=dlerror(); |