Skip to content

Commit

Permalink
feat: add setup.py
Browse files Browse the repository at this point in the history
- Install as pip file without user configuration (only tested on mac)
- Only available for wireshark 4-4 version
  • Loading branch information
JahazielLem committed Dec 26, 2024
1 parent 2a2a91f commit e59e572
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@
*.pyc
*.hex
*.txt
build/
pycatsniffer.egg-info/
6 changes: 5 additions & 1 deletion pycatsniffer_bv3/cat_sniffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,11 @@ def setup_sniffer(
sniffer_collector.run_workers()


if __name__ == "__main__":
def main():
typer.echo(PROMPT_HEADER)
signal.signal(signal.SIGINT, signal_handler)
app()


if __name__ == "__main__":
main()
100 changes: 100 additions & 0 deletions pycatsniffer_bv3/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
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 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, "plugins\\wireshark\\4-4")
dissector_file = "dissectors/windows/catsniffer.dll"
elif platform.system() == "Darwin":
dissectors_path = os.path.join(program_path, "PlugIns/wireshark/4-4/epan/")
dissector_file = "dissectors/mac/catsniffer.so"
else:
dissectors_path = os.path.join(program_path, "PlugIns/wireshark/4-4")
dissector_file = "dissectors/linux/catsniffer.so"

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


setup(
name="pycatsniffer",
version="1.0",
description="CatSniffer BV3: A tool for sniffing ZigBee, LoRa, and other protocols",
author="Kevin Leon",
url="https://github.com/ElectronicCats/CatSniffer-Tools",
packages=find_packages(include=["Modules", "Modules.*"]),
py_modules=["cat_sniffer"],
entry_points={
"console_scripts": [
"pycatsniffer=cat_sniffer:main",
],
},
install_requires=[
"click",
"pyserial",
"typer",
"pywin32" if platform.system() == "Windows" else "",
],
include_package_data=True,
package_data={"Modules": ["*.py"]},
data_files=wireshark_files(),
)

0 comments on commit e59e572

Please sign in to comment.