Created
June 15, 2023 09:42
-
-
Save LuxNoBulIshit/0ffc37d7e71ed524e92b6ec2bfafc6e7 to your computer and use it in GitHub Desktop.
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 pefile | |
| from pathlib import Path | |
| import concurrent.futures | |
| import art | |
| from tqdm import tqdm | |
| from colorama import Fore, init | |
| # Initialize colorama | |
| init() | |
| def print_green(text): | |
| print(f"{Fore.GREEN}{text}{Fore.RESET}") | |
| def find_exe_files(directory): | |
| # Use pathlib to find all .exe files in the directory | |
| print_green("Searching for .exe files in the directory...") | |
| try: | |
| return [str(path) for path in Path(directory).rglob('*.exe')] | |
| except OSError as e: | |
| print_green(f"Error finding .exe files: {e}") | |
| return [] | |
| def check_sections(file_path): | |
| try: | |
| pe = pefile.PE(file_path) | |
| section_names = [section.Name.decode().rstrip('\x00') for section in pe.sections] | |
| if "CPADinfo" in section_names and ".00cfg" in section_names: | |
| return file_path | |
| else: | |
| return None | |
| except (pefile.PEFormatError, FileNotFoundError, OSError) as e: | |
| return None | |
| # Define the root directory of the C: drive | |
| directory = "C:\\" | |
| text = art.text2art("ElectroNCutioner") | |
| print(text) | |
| print_green("Starting search from the root directory...") | |
| # Find all exe files | |
| exe_files = find_exe_files(directory) | |
| print_green(f"Found {len(exe_files)} .exe files.") | |
| # Create a list to hold the paths to the EXE files that contain the sections | |
| matching_files = [] | |
| # Create a ThreadPoolExecutor | |
| with concurrent.futures.ThreadPoolExecutor() as executor: | |
| # Create a progress bar | |
| progress = tqdm(total=len(exe_files), desc="Processing files", dynamic_ncols=True) | |
| futures = [executor.submit(check_sections, file) for file in exe_files] | |
| for future in concurrent.futures.as_completed(futures): | |
| result = future.result() | |
| if result is not None: | |
| matching_files.append(result) | |
| # Update the progress bar | |
| progress.update(1) | |
| # Close the progress bar | |
| progress.close() | |
| print_green(f"Found {len(matching_files)} matching files.") | |
| # Write all the paths of the EXE files that contain both the "CPADinfo" and ".00cfg" sections to a file | |
| try: | |
| with open("C:\\Users\\Public\\matching_files.txt", 'w') as f: | |
| for file in matching_files: | |
| f.write(file + '\n') | |
| print_green("Successfully wrote matching file paths to matching_files.txt.") | |
| except (FileNotFoundError, OSError) as e: | |
| print_green(f"Unable to write to file: {e}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment