Created
August 9, 2023 02:44
-
-
Save buzzer-re/10cf4ac4ff0b1a505fbf7f81b0586bc0 to your computer and use it in GitHub Desktop.
Hunt for some exported function name on a given directory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A Python script using LIEF to search a specific exported function name in a directories | |
# This is useful when you don't know the DLL name but (somehow) knows the exported function name | |
import sys | |
import lief | |
import os | |
import logging | |
lief.logging.set_level(lief.logging.LOGGING_LEVEL.CRITICAL) | |
DLL_CHAR = 0x2000 | |
def main(): | |
if len(sys.argv) < 2: | |
print(f"Usage: {sys.argv[0]} directory exported_function_name") | |
sys.exit(1) | |
directory = sys.argv[1] | |
exported_function_name = sys.argv[2] | |
sys.stderr = open(os.devnull, "w") | |
for root, dirs, files in os.walk(directory): | |
for file in files: | |
filepath = os.path.join(root, file) | |
try: | |
pe: lief.PE.Binary = lief.parse(filepath) | |
for exported_function in pe.exported_functions: | |
if exported_function.name == exported_function_name: | |
print(f"Found {exported_function_name} in DLL {filepath}") | |
break | |
except: continue | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment