codebread 1.0.4__py3-none-any.whl → 1.0.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
codebread/analyzer.py CHANGED
@@ -9,6 +9,7 @@ from typing import Callable, Dict, Optional
9
9
  from . import __version__
10
10
  from .classifier import classify
11
11
  from .connections import build_graph
12
+ from .deobfuscate import scan_obfuscation
12
13
  from .parsers import parse_file
13
14
  from .scanner import read_text, scan
14
15
 
@@ -40,6 +41,11 @@ def analyze(root: str,
40
41
  from .parsers.generic_parser import redact_secrets
41
42
  src = redact_secrets(src)
42
43
  info.source = src
44
+ if text:
45
+ info.obfuscation = [
46
+ {"line": f.line, "kind": f.kind, "original": f.original, "decoded": f.decoded}
47
+ for f in scan_obfuscation(text, meta["language"])
48
+ ]
43
49
  parsed.append(info)
44
50
  for w in info.warnings:
45
51
  if w.startswith("Unsupported:"):
@@ -78,6 +84,8 @@ def _annotate_tree(node: Dict, by_path: Dict) -> None:
78
84
  node["nFunctions"] = len(info.functions)
79
85
  if info.warnings and "warning" not in node:
80
86
  node["warning"] = "parse"
87
+ if info.obfuscation:
88
+ node["obfuscated"] = True
81
89
  return
82
90
  layers = set()
83
91
  for child in node.get("children", []):
codebread/connections.py CHANGED
@@ -209,7 +209,7 @@ def build_graph(files: List[FileInfo], tree: Dict,
209
209
  "loc": f.loc, "warnings": f.warnings,
210
210
  "nFunctions": len(f.functions),
211
211
  "imports": f.imports[:30], "dbConfig": f.db_config,
212
- "source": f.source,
212
+ "source": f.source, "obfuscation": f.obfuscation,
213
213
  })
214
214
  for fn in f.functions:
215
215
  nid = f"{f.path}::{fn.name}@{fn.line}"
@@ -393,6 +393,7 @@ def build_graph(files: List[FileInfo], tree: Dict,
393
393
  # ---- stats ---------------------------------------------------------
394
394
  n_fns = sum(1 for n in nodes if n["kind"] in ("function", "method"))
395
395
  n_orphans = sum(1 for n in nodes if n.get("orphan"))
396
+ n_obfuscated = sum(1 for f in files if f.obfuscation)
396
397
  stats = {
397
398
  "files": len(files),
398
399
  "functions": n_fns,
@@ -402,6 +403,7 @@ def build_graph(files: List[FileInfo], tree: Dict,
402
403
  "warnings": len(warnings) + sum(len(f.warnings) for f in files),
403
404
  "orphans": n_orphans,
404
405
  "cycles": len(cycles),
406
+ "obfuscated": n_obfuscated,
405
407
  }
406
408
  return {"nodes": nodes, "edges": edges, "tree": tree,
407
409
  "warnings": warnings, "cycles": cycles, "stats": stats}