Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
542 views
in Technique[技术] by (71.8m points)

android - How to rename dynamic symbols in arm elf .so file?

I need to modify a so inside an Android APK. The task is to rename the dynamic symbols in side the so (which is the function name).

For example, change from Java_com_example_abc_.... to Java_com_yahoo_zzz_....

I try to use WinHex directly search and replace text words, the apk startup error. Seems like the .hash section also needs to be updated, but i do not know how to update the .hash section.

My question is what is the correct or preferable way to rename the dynamic Symbol?

I heave been stuck for 3 days, please help me, thank you very much!

Found a post might related, but he didn't gave the alternative solution. https://sourceware.org/ml/binutils/2006-03/msg00266.html

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I heave been stuck for 3 days, please help me,

What you are trying to achieve is effectively impossible.

ELF files have complicated internal structure, and what you want to do requires that you break it up and re-assemble the parts. An analogy would be to break an Intel CPU into transistors and re-assemble an AMD CPU from them.

Found a post might related

It is related. Quote:

Basically it does the following:

  1. loop over .dynsym and re-create .dynstr
  2. re-create the .hash table from scratch
  3. calculate new lma/vma, new memory layout (.dynstr size changed!)
  4. fix the contents of .dynamic, according to the new layout
  5. fix .rel.dyn
  6. fix .rel.plt
  7. fix .dynsym again
  8. write out the new section contents

In copy_section: exclude the rewritten sections from being copyied.

Currently it seems to create a syntactically valid ELF file, but as the distance between .plt and .got changes, the relative addressing in .plt is broken. Additionally the .got has to be fixed again.

So the author managed to glue together something that looks like an AMD CPU, but which doesn't work.

Sure, you can spend another 2 weeks to understand what the author did, and then another 3 weeks to fix the remaining broken pieces. And after that, you may get something that kind of sometimes works.

Your time is likely better spent elsewhere.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...