Add Lock to synchronize print statements and prevent stdout corruption when multiple threads write simultaneously. Example corruption before:

```
DYLIB:/Applications/NordVPN.app/Contents/Frameworks/norddropFFI.framework/Versions/A/norddropFFI

/* No comment provided by engineer. */
"Update Error!" = "Virhe p�ivEXECUTE:/Applications/KnockKnock.app/Contents/MacOS/KnockKnock
```
This commit is contained in:
Karol Mazurek
2025-12-06 21:38:19 +01:00
parent 1fda24819c
commit cac76ae2aa
+4 -1
View File
@@ -4,6 +4,7 @@ import sys
import argparse import argparse
import struct import struct
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
from threading import Lock
import stat import stat
class MachOFileFinder: class MachOFileFinder:
@@ -37,6 +38,7 @@ class MachOFileFinder:
self.directory_path = directory_path self.directory_path = directory_path
self.recursive = recursive self.recursive = recursive
self.only_arm64 = only_arm64 self.only_arm64 = only_arm64
self.print_lock = Lock()
def isRegularFile(self, file_path): def isRegularFile(self, file_path):
"""Check if the specified file is a regular file.""" """Check if the specified file is a regular file."""
@@ -178,7 +180,8 @@ class MachOFileFinder:
# Check if the file is a Mach-O binary or FAT binary # Check if the file is a Mach-O binary or FAT binary
file_type = self.getMachoInfo(file_path) file_type = self.getMachoInfo(file_path)
if file_type: if file_type:
print(f"{file_type}:{file_path}") with self.print_lock:
print(f"{file_type}:{file_path}")
def processFiles(self): def processFiles(self):
"""Walk through the directory and process files using threading for faster execution.""" """Walk through the directory and process files using threading for faster execution."""