Skip to content

Instantly share code, notes, and snippets.

@buzzer-re
Created August 9, 2023 02:44
Show Gist options
  • Save buzzer-re/10cf4ac4ff0b1a505fbf7f81b0586bc0 to your computer and use it in GitHub Desktop.
Save buzzer-re/10cf4ac4ff0b1a505fbf7f81b0586bc0 to your computer and use it in GitHub Desktop.
Hunt for some exported function name on a given directory
# 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