I don't have code for you, but I can specify pointers:
This is just a graph problem. You must use objdump -Tto dump a dynamic symbol table for a given binary or shared object. You will see many lines of output, and flags may be a little confusing, but the important part is if these characters are either *UND*, or they will have the name of the segment ( .textetc.).
Whenever you see *UND*, this means that it is an undefined character that must be allowed. Certain characters are permission objects.
With this and a little Python you can find what you need.
source
share