Created
April 20, 2020 20:28
-
-
Save learn-more/9ab29251d84a48a5142f41ad73054599 to your computer and use it in GitHub Desktop.
Dump unique imported modules
This file contains hidden or 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
import sys | |
import pefile | |
import glob | |
import os | |
def main(base_dir): | |
print('Printing the first occurence of an import from', base_dir) | |
known_imports = [] | |
for filename in glob.iglob(os.path.join(base_dir, '**', '*.exe'), recursive=True): | |
pe = pefile.PE(filename, fast_load=True) | |
pe.parse_data_directories(directories= [pefile.DIRECTORY_ENTRY['IMAGE_DIRECTORY_ENTRY_IMPORT']]) | |
for import_entry in pe.DIRECTORY_ENTRY_IMPORT: | |
module = import_entry.dll.decode('ascii').lower() | |
if not module in known_imports: | |
print(os.path.basename(filename), '->', module) | |
known_imports.append(module) | |
if __name__ == '__main__': | |
for arg in sys.argv[1:]: | |
main(arg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment