Jump to content
Jaska

dlsym and symbols

Recommended Posts

I have a trouble understanding how dlsym works. My goal is to implement binary level localization for Delphi generated MachO (macOS and iOS) and ELF (Android and Linux) files. I have written classes to manipulate MachO and ELF files. Basically what I need to so is to find the symbols for resources (strings, forms and other resources). These symbols point to the resource segment in the file. The resource segment contain all the resources and their lengths.

 

When writing the localized files I generate new resource segment data and then update the symbol values to point to the new address in the resource segment. As far as I know this is all I need to do.

 

When I run the localized application, RTL calls dlsym to get the address where the symbol points. Now here is the problem. I expect dlsym to find the symbol, read the n_value and return it. Using a MachO viewer app I can see that the symbols' n_values have been updated and the resource segment also is updated.

 

Still dlsym returns the old address. The same address that was the original value of the symbol's n_value (that no longer is there because it was overwritten during the localization process).

 

So I believe that dlsym does not get the value it returns by locating the symbol and returning its n_value but there is some other section in the MachO file that also contains the same n_value and dlsym returns that. Is this the case? If it is what is this other section I need to update.

Edited by Jaska
Typo

Share this post


Link to post

Are you patching the compiled binaries or are you generating resource modules for use with the RTL's built-in localization system?

Share this post


Link to post
7 minutes ago, Jaska said:

I will do both. Just like I have done for Windows

Ah, I didn't realize who you represented. I'll let you figure it out for yourself then 🙂

Share this post


Link to post

I got this working. In addition of patching the resource data and symbols you need to patch the symbol offsets in the export section of the dyld_info_only part.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×