Ejemplo n.º 1
0
  SwellAPPInitializer()
  {
    void *(*SWELLAPI_GetFunc)(const char *name)=NULL;
#ifdef SWELL_LOAD_SWELL_DYLIB
    char fn[4096];
    const int nSize=sizeof(fn)-64;
    char lnk[64];
    sprintf(lnk,"/proc/%d/exe",getpid());
    int sz=readlink(lnk,fn,nSize);
    if (sz<0)sz=0;
    else if (sz>=nSize)sz=nSize-1;
    fn[sz]=0;
    char *p=fn;
    while (*p) p++;
    while (p >= fn && *p != '/') p--;
    strcpy(++p,"libSwell.so");

    void *tmp = dlopen(fn,RTLD_LAZY);
    if (!tmp)
    {
      printf("Error loading '%s': %s\n",fn,dlerror());
      exit(2);
    }
    const char *preload_fn = (const char *)dlsym(tmp,"SWELL_WANT_LOAD_LIBRARY");
    if (preload_fn && *preload_fn)
      dlopen(preload_fn,RTLD_LAZY|RTLD_GLOBAL);

#else
    void *tmp = dlopen(NULL,RTLD_LAZY);
#endif

    if (tmp) *(void **)&SWELLAPI_GetFunc = dlsym(tmp,"SWELLAPI_GetFunc"); 
    //printf("tmp=%08x, SWELLAPI_GetFunc=%08x\n",tmp,SWELLAPI_GetFunc);
      
    if (SWELLAPI_GetFunc && SWELLAPI_GetFunc(NULL)!=(void*)0x100) SWELLAPI_GetFunc=0;
      
#ifdef SWELL_LOAD_SWELL_DYLIB
    __loaded_getfunc = SWELLAPI_GetFunc;
#endif
    int x;
    for (x = 0; x < sizeof(api_tab)/sizeof(api_tab[0]); x ++)
    {
      *api_tab[x].func=SWELLAPI_GetFunc?SWELLAPI_GetFunc(api_tab[x].name):0;
      if (!*api_tab[x].func)
      {
        printf("SWELL API not found: %s\n",api_tab[x].name);
#ifdef SWELL_LOAD_SWELL_DYLIB
        exit(1);
#endif
        *api_tab[x].func = (void*)&dummyFunc;
      }
    }
  }
Ejemplo n.º 2
0
  SwellAPPInitializer()
  {
    void *(*SWELLAPI_GetFunc)(const char *name)=NULL;
    void *tmp = dlopen(NULL,RTLD_LAZY);

    if (tmp) *(void **)&SWELLAPI_GetFunc = dlsym(tmp,"SWELLAPI_GetFunc"); 
    //printf("tmp=%08x, SWELLAPI_GetFunc=%08x\n",tmp,SWELLAPI_GetFunc);
      
    if (SWELLAPI_GetFunc && SWELLAPI_GetFunc(NULL)!=(void*)0x100) SWELLAPI_GetFunc=0;
      
    int x;
    for (x = 0; x < sizeof(api_tab)/sizeof(api_tab[0]); x ++)
    {
      *api_tab[x].func=SWELLAPI_GetFunc?SWELLAPI_GetFunc(api_tab[x].name):0;
      if (!*api_tab[x].func)
      {
        printf("SWELL API not found: %s\n",api_tab[x].name);
        *api_tab[x].func = (void*)&dummyFunc;
      }
    }
  }