Question

I'm creating a library to provide access to another library. The library in question is a vendor, so not everyone should access this library. One solution to do so is to put the library on a specific group (AIX) and then put everyone that can compile using it in the same group. This solution don't works here because there are a lot of new people coming in and out, and the user that compiles (Its a process that do this operation) is not the same as the user that can access the code. The solution i'm trying to archive is. Every application have an pattern on their directory. /Aplications/Group/... So i can get the Group using the folder when the program runs. What i am trying to do is. Create a library that checks the directory and then loads the library using (loadAndInit) the dlopen function on AIX that already loads all the symbols, so i don't need the dlsym. The problem is, i want to put the binary code of the library i want to load inside my source code.

WHY: Because if App -> Lib (Loads) -> Vendor, nothing can limit the developer from doing an link by hand or compiling by hand the App -> Vendor. And the structure that call the compilation process cannot limit that.

What i have tried.

Convertlib

FILE* file=fopen("vendor.so", "rb");
int c;
do{
   c=getc(file);
   if(c > 0)
      printf("\\x%02x", c);
}while(c!=EOF);

Then i have a little script that puts the output of this file as a

char *lib=(char* (malloc(sizeof(char) * /* lib size */));
lib="/*output of the Convertlib*/

Then i try to load it using fmemopen, so i dont create a temporary file just a file descriptor inside my process area.

To load it i do

FILE* vendorLib=fmemopen(lib, /*libSize*/, "r");
char path[50];
sprintf("/proc/%d/fd/%d", getpid(), fileno(vendorLib));
loadAndInit(path, 0, "");

If i call directly a lib (i have it to test) and dont load using the hex formated library it works. But as i converted my binary code to hex and i'm trying to load it, it dont work. Should i convert back to load it on the memory and use it as an library again?

This seems the only solution to work with, as the library is a vendor i cannot change it and it is the only way i see to limit the access because we have here more than 1000 programmers

Was it helpful?

Solution

I solved it using

printf("\x%02x", thechar);

Inside the getc loop

So i wrote it inside a memcpy then i copy to the memory so the binary file is stored as HEX data.

Works perfectly

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top