import logging
import re
import sys
logging.disable(logging.CRITICAL)
_DRIVE = re.compile(r"([A-Za-z]):[\\/]")
def _drive_of(*fields):
for f in fields:
if isinstance(f, str):
m = _DRIVE.search(f)
if m:
return m.group(1).upper()
return None
def _run_plugin(hive, plugin_cls):
plugin = plugin_cls(hive, as_json=True)
plugin.run()
return plugin.entries
def main(argv):
if len(argv) != 2:
print("usage: shellbags_oracle.py <hive-path>", file=sys.stderr)
return 2
hive_path = argv[1]
from regipy.registry import RegistryHive
from regipy.plugins.ntuser.shellbags_ntuser import ShellBagNtuserPlugin
from regipy.plugins.usrclass.shellbags_usrclass import ShellBagUsrclassPlugin
hive = RegistryHive(hive_path)
raw = []
for plugin_cls in (ShellBagNtuserPlugin, ShellBagUsrclassPlugin):
try:
raw.extend(_run_plugin(hive, plugin_cls))
except Exception: continue
out = []
for e in raw:
value = e.get("value")
path = e.get("path") or ""
drive = _drive_of(value, path) or "-"
shell_type = (e.get("shell_type") or "").replace("\t", " ")
out.append(f"{drive}\t{shell_type}\t{path}")
if out:
sys.stdout.write("\n".join(out) + "\n")
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv))