feat: mode-based REPL auto-imports via activate script
source activate — core (Proxmark3, Cmd, PM3Status, etc.) source activate sim — + SimSession, all transponder models source activate sniff — + SniffSession, trace decoders source activate all — everything Sets PM3PY_MODE env var and PYTHONSTARTUP for the venv. Prompt shows current mode: (pm3py:sim) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
101
.pythonstartup.py
Normal file
101
.pythonstartup.py
Normal file
@@ -0,0 +1,101 @@
|
||||
"""Auto-imports for interactive REPL sessions.
|
||||
|
||||
Usage: activate — core imports (Proxmark3, Cmd, etc.)
|
||||
activate sim — + SimSession, all transponder models
|
||||
activate sniff — + SniffSession, trace decoders
|
||||
activate all — everything
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
|
||||
_MODE = os.environ.get("PM3PY_MODE", "core")
|
||||
|
||||
# --- Import groups ---
|
||||
|
||||
CORE = [
|
||||
("pm3py", "Proxmark3"),
|
||||
("pm3py", "Cmd"),
|
||||
("pm3py", "PM3Status"),
|
||||
("pm3py", "PM3Error"),
|
||||
("pm3py", "PM3Response"),
|
||||
]
|
||||
|
||||
SIM = [
|
||||
("pm3py.sim", "SimSession"),
|
||||
("pm3py.sim", "DualInterfaceSession"),
|
||||
("pm3py.sim", "SoftwareMedium"),
|
||||
("pm3py.sim", "TableCompiler"),
|
||||
("pm3py.sim", "RFFrame"),
|
||||
# Transponder models
|
||||
("pm3py.transponders.hf.iso14443a.base", "Tag14443A_3"),
|
||||
("pm3py.transponders.hf.iso14443a.base", "Tag14443A_4"),
|
||||
("pm3py.transponders.hf.iso14443a.nxp.mifare_classic", "MifareClassicTag"),
|
||||
("pm3py.transponders.hf.iso14443a.nxp.desfire", "DesfireTag"),
|
||||
("pm3py.transponders.hf.iso14443a.ndef", "NfcType2Tag"),
|
||||
("pm3py.transponders.hf.iso14443a.ndef", "NfcType4Tag"),
|
||||
("pm3py.transponders.hf.iso15693.base", "Tag15693"),
|
||||
("pm3py.transponders.hf.iso15693.type5", "NfcType5Tag"),
|
||||
("pm3py.transponders.hf.iso15693.nxp.nxp_icode", "NxpIcodeTag"),
|
||||
("pm3py.transponders.hf.iso15693.nxp.icode_slix", "IcodeSlixTag"),
|
||||
("pm3py.transponders.hf.iso15693.nxp.icode_slix2", "IcodeSlix2Tag"),
|
||||
("pm3py.transponders.hf.iso15693.nxp.icode3", "Icode3Tag"),
|
||||
("pm3py.transponders.hf.iso15693.nxp.icode_dna", "IcodeDnaTag"),
|
||||
("pm3py.transponders.hf.iso15693.nxp.ntag5_platform", "Ntag5PlatformTag"),
|
||||
("pm3py.transponders.hf.iso15693.nxp.ntag5_switch", "Ntag5SwitchTag"),
|
||||
("pm3py.transponders.hf.iso15693.nxp.ntag5_link", "Ntag5LinkTag"),
|
||||
("pm3py.transponders.hf.iso15693.nxp.ntag5_boost", "Ntag5BoostTag"),
|
||||
("pm3py.transponders.lf.em.em4100", "EM4100Tag"),
|
||||
("pm3py.transponders.lf.hid.hid", "HIDProxTag"),
|
||||
("pm3py.transponders.lf.atmel.t5577", "T5577Tag"),
|
||||
("pm3py.transponders.implants", "xEM"),
|
||||
("pm3py.transponders.implants", "xNT"),
|
||||
("pm3py.transponders.implants", "xM1"),
|
||||
("pm3py.transponders.implants", "FlexDF"),
|
||||
("pm3py.transponders.implants", "NExT"),
|
||||
]
|
||||
|
||||
SNIFF = [
|
||||
("pm3py.sniff", "SniffSession"),
|
||||
("pm3py.trace", "parse_tracelog"),
|
||||
("pm3py.trace", "decode_15693"),
|
||||
("pm3py.trace", "decode_ndef_annotation"),
|
||||
("pm3py.trace", "format_sniff_line"),
|
||||
]
|
||||
|
||||
# --- Mode selection ---
|
||||
|
||||
MODES = {
|
||||
"core": [CORE],
|
||||
"sim": [CORE, SIM],
|
||||
"sniff": [CORE, SNIFF],
|
||||
"all": [CORE, SIM, SNIFF],
|
||||
}
|
||||
|
||||
groups = MODES.get(_MODE, [CORE])
|
||||
imports = []
|
||||
for group in groups:
|
||||
imports.extend(group)
|
||||
|
||||
# --- Load ---
|
||||
|
||||
loaded = {}
|
||||
failed = {}
|
||||
|
||||
for module_name, attr_name in imports:
|
||||
try:
|
||||
module = __import__(module_name, fromlist=[attr_name])
|
||||
obj = getattr(module, attr_name)
|
||||
globals()[attr_name] = obj
|
||||
loaded[attr_name] = module_name
|
||||
except Exception as e:
|
||||
failed[attr_name] = (module_name, str(e))
|
||||
|
||||
# --- Report ---
|
||||
|
||||
if loaded:
|
||||
print(f"[pm3py:{_MODE}] Loaded: {', '.join(loaded.keys())}")
|
||||
|
||||
if failed:
|
||||
print(f"\n[pm3py:{_MODE}] Failed:")
|
||||
for name, (mod, err) in failed.items():
|
||||
print(f" {name} from {mod} -> {err}")
|
||||
21
activate
Normal file
21
activate
Normal file
@@ -0,0 +1,21 @@
|
||||
# pm3py venv activation with mode-based auto-imports.
|
||||
# Usage: source activate — core (Proxmark3, Cmd, etc.)
|
||||
# source activate sim — + SimSession, transponder models
|
||||
# source activate sniff — + SniffSession, trace decoders
|
||||
# source activate all — everything
|
||||
#
|
||||
# Then: python — REPL with auto-imports
|
||||
# ipython — IPython with auto-imports (if installed)
|
||||
|
||||
# Activate the venv
|
||||
source "$(dirname "${BASH_SOURCE[0]}")/.venv/bin/activate"
|
||||
|
||||
# Set mode and PYTHONSTARTUP
|
||||
export PM3PY_MODE="${1:-core}"
|
||||
export PYTHONSTARTUP="$(dirname "${BASH_SOURCE[0]}")/.pythonstartup.py"
|
||||
|
||||
# Update prompt to show mode
|
||||
PS1="(pm3py:${PM3PY_MODE}) ${_OLD_VIRTUAL_PS1:-\$ }"
|
||||
export PS1
|
||||
|
||||
echo "pm3py env ready (mode: ${PM3PY_MODE}). Run 'python' for REPL with auto-imports."
|
||||
Reference in New Issue
Block a user