1

I'm having the exact same problem as a person that asked this question: How to hide the exported symbols name within a shared library

I decided to follow instructions given by Alexander (3rd answer) but after including a generated header to my main program in C, i get the error undefined reference to function

head.h

#define SecretFunc1 abab

application.c

#include <stdio.h>
#include "head.h"

int main(){
    SecretFunc1();
    return 0;   
}

libdyn.c

#include <stdio.h>
int SecretFunc1(){
    return 2
}

I've built the dynamic library into .so file, then after trying to build the app with: gcc app.c -L<path> -ldyn -o sample In function main undefined reference to abab

I don't really know what to do.

Narza
  • 13
  • 2
  • If your intention is to "obfuscate" the symbol names as that answer suggests, you need need to include `heah.h` in `libdyn.c` as well, because otherwise `application.c` expects a function named `abab`, while `libdyn.c` provides it as `SecretFunc1`. But I don't see the point of it. Can you clarify? The compiler should also have warned you, that `abab` is implicitly declared in `application.c`. You should provide an explicit declaration for it. – walnut Aug 28 '19 at 08:34
  • It's for the excercise I got. I need to change a specific library symbols names so that you cannot tell what they do, after reading elf tables. – Narza Aug 28 '19 at 08:44
  • It is unclear what your exercise requires you to achieve specifically. In particular it is unclear what is given to you and what you should submit as a solution. – n. m. could be an AI Aug 28 '19 at 08:50
  • include `"head.h"` also in the implementation.... if you don't you are actually implementing `SecretFunction`, not `abab` – Luis Colorado Sep 06 '19 at 11:01
  • Implementing a shared object with scrambled names is a bet to project crash. – Luis Colorado Sep 10 '19 at 10:40

1 Answers1

1

After (partial) preprocessing, your application.c would look like this:

#include <stdio.h>

int main(){
    abab();
    return 0;   
}

This should, first of all, give you a warning, that abab is declared implicitly, which usually is not a good idea. You should declare the function (in a header file shared by application.c and libdyn.c):

int SecretFunc1(void);

When compiling to an object file, this object file will have a reference to the symbol abab.

After compiling libdyn.c to an object file, it will provide a symbol named SecretFunc1. Therefore, the linker will not match it to the reference abab in application.o.

You need to rename the function in all files using it, e.g. by including head.h in libdyn.c as well or better putting both the renaming macro and the declaration in a libdyn.h that is included in both libdyn.c and application.c.

walnut
  • 21,629
  • 4
  • 23
  • 59