49 lines
1.8 KiB
Python
49 lines
1.8 KiB
Python
import os
|
|
import shutil
|
|
import tempfile
|
|
from dataclasses import dataclass
|
|
from typing import List, Optional
|
|
|
|
@dataclass
|
|
class EntryPoint:
|
|
entry_point: Optional[str] = None
|
|
extraction_path: Optional[str] = None
|
|
|
|
def clean_up_temp_files(directory_path: str) -> None:
|
|
"""Remove temporary files and directories"""
|
|
try:
|
|
if os.path.exists(directory_path):
|
|
if os.path.isfile(directory_path):
|
|
os.remove(directory_path)
|
|
else:
|
|
shutil.rmtree(directory_path, ignore_errors=True)
|
|
except Exception as e:
|
|
print(f"Failed to clean up {directory_path}: {e}")
|
|
|
|
def extract_pyinstaller_exe(exe_path: str) -> str:
|
|
"""Extract PyInstaller executable contents"""
|
|
temp_dir = tempfile.mkdtemp(prefix="pyinstaller_extract_")
|
|
|
|
# In a real implementation, you would use pyinstxtractor or similar tools
|
|
# Here we just return the temporary directory
|
|
return temp_dir
|
|
|
|
def find_payload_files(directory: str, extension: str, exclude_pattern: str) -> List[str]:
|
|
"""Find files with specific extension in directory"""
|
|
result = []
|
|
for root, _, files in os.walk(directory):
|
|
for file in files:
|
|
if file.endswith(extension) and exclude_pattern not in file:
|
|
result.append(os.path.join(root, file))
|
|
return result
|
|
|
|
def decompile_pyc(pyc_file: str) -> str:
|
|
"""Decompile .pyc file to source code"""
|
|
# In a real implementation, you would use uncompyle6 or decompyle3
|
|
# Here we just return a placeholder
|
|
return f"# Decompiled content of {pyc_file}\n"
|
|
|
|
def attempts_to_get_entry_point(file_path: str) -> EntryPoint:
|
|
"""Try various methods to find the entry point"""
|
|
# In a real implementation, this would be more complex
|
|
return EntryPoint(entry_point=file_path)
|