1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| import os
import shutil
import binascii
def process_file(src_path, dest_path):
with open(src_path, 'rb') as src_file:
file_content = src_file.read()
# Recherche de toutes les occurrences de la séquence d'octets spécifiée
sequence_to_find = binascii.unhexlify('A10404F60000000004A40101')
occurrences = [i for i in range(len(file_content)) if file_content.startswith(sequence_to_find, i)]
if occurrences:
# Si des occurrences sont trouvées, copie du fichier à destination
shutil.copy2(src_path, dest_path)
# Suppression des 1262 octets pour chaque occurrence
modified_content = file_content
for index in occurrences:
modified_content = modified_content[:index + len(sequence_to_find)] + modified_content[index + len(sequence_to_find) + 1262:]
# Écriture du contenu modifié dans le nouveau fichier
with open(dest_path, 'wb') as dest_file:
dest_file.write(modified_content)
def copy_files_with_exception(src_folder, dest_folder):
if not os.path.exists(dest_folder):
os.makedirs(dest_folder)
for root, dirs, files in os.walk(src_folder):
for file in files:
src_path = os.path.join(root, file)
dest_path = os.path.join(dest_folder, file)
process_file(src_path, dest_path)
if __name__ == "__main__":
src_folder = os.path.join(os.path.expanduser('~'), 'Desktop', 'Encode', 'X')
dest_folder = os.path.join(os.path.expanduser('~'), 'Desktop', 'Encode', 'Z')
copy_files_with_exception(src_folder, dest_folder) |
Partager