Skip to content

Commit

Permalink
feat: Change to local pluggins
Browse files Browse the repository at this point in the history
  • Loading branch information
JahazielLem committed Dec 26, 2024
1 parent 270a757 commit 3f345fe
Showing 1 changed file with 13 additions and 55 deletions.
68 changes: 13 additions & 55 deletions pycatsniffer_bv3/setup.py
Original file line number Diff line number Diff line change
@@ -1,79 +1,37 @@
from setuptools import setup, find_packages
import subprocess
import shutil
import platform
import locale
import os


def get_program_path(program_name):
try:
program_path = shutil.which(program_name)
if program_path:
if platform.system() == "Darwin":
return program_path.replace("/MacOS/wireshark", "")
else:
return os.path.dirname(program_path)

system_language = locale.getdefaultlocale()[0]
is_spanish = system_language.startswith("es")

system = platform.system()
if system == "Windows":
common_paths = [
"C:\\Program Files\\Wireshark\\Wireshark.exe",
"C:\\Program Files (x86)\\Wireshark\\Wireshark.exe",
]
if is_spanish:
common_paths.extend(
[
"C:\\Archivos de programa\\Wireshark\\Wireshark.exe",
"C:\\Archivos de programa (x86)\\Wireshark\\Wireshark.exe",
]
)
for path in common_paths:
if shutil.which(path):
return path
elif system == "Darwin":
result = subprocess.run(
["mdfind", "kMDItemFSName=Wireshark"], capture_output=True, text=True
)
if result.stdout:
return result.stdout.strip().split("\n")[0]
elif system == "Linux":
for path in ["/usr/bin/wireshark", "/usr/local/bin/wireshark"]:
if shutil.which(path):
return path

return None
except Exception:
return None
def create_path(path):
if not os.path.exists(path):
os.makedirs(path)


def wireshark_files():
program_name = "wireshark"
program_path = get_program_path(program_name)
dissectors_path = ""
dissector_file = ""
if not program_path:
# Si no se encuentra Wireshark, devuelve una lista vacía
return []

if platform.system() == "Windows":
dissectors_path = os.path.join(
program_path.replace("Wireshark.exe"), "plugins\\epan\\4-4"
os.getenv("APPDATA"), "Wireshark", "plugins", "4.4", "epan"
)
dissector_file = "dissectors/windows/catsniffer.dll"
elif platform.system() == "Darwin":
dissectors_path = os.path.join(program_path, "PlugIns/wireshark/4-4/epan/")
dissectors_path = os.path.join(
os.getenv("HOME"), ".local", "lib", "wireshark", "plugins", "4-4", "epan"
)
dissector_file = "dissectors/mac/catsniffer.so"
else:
dissectors_path = os.path.join(program_path, "PlugIns/wireshark/4-4")
dissectors_path = os.path.join(
os.getenv("HOME"), ".local", "lib", "wireshark", "plugins", "4.4", "epan"
)
dissector_file = "dissectors/linux/catsniffer.so"

shutil.copyfile(
dissector_file, os.path.join(dissectors_path, os.path.basename(dissector_file))
)
create_path(dissectors_path)
complete_path = os.path.join(dissectors_path, os.path.basename(dissector_file))
shutil.copyfile(dissector_file, complete_path)
return [(dissectors_path, [dissector_file])]


Expand Down

0 comments on commit 3f345fe

Please sign in to comment.