MCPcopy
hub / github.com/Gallopsled/pwntools / check_cycle_

Function check_cycle_

pwnlib/regsort.py:44–69  ·  view source on GitHub ↗
(reg, assignments, path, mapping)

Source from the content-addressed store, hash-verified

42 return check_cycle_(reg, assignments, [], mapping)
43
44def check_cycle_(reg, assignments, path, mapping):
45 target = assignments.get(reg)
46 if target is None:
47 real_reg = mapping.get(reg, reg)
48 reg, target = next((k, v) for k,v in assignments.items() if mapping.get(k, k) == real_reg)
49 path.append(reg)
50
51 real_target = mapping.get(target, target)
52
53 # No cycle, some other value (e.g. 1)
54 if all(real_target != mapping.get(k, k) for k in assignments):
55 return []
56
57 # Found a cycle
58 if any(real_target == mapping.get(k, k) for k in path):
59 # Does the cycle *start* with target?
60 # This determines whether the original register is
61 # in the cycle, or just depends on registers in one.
62 if real_target == mapping.get(path[0], path[0]):
63 return path
64
65 # Just depends on one.
66 return []
67
68 # Recurse
69 return check_cycle_(target, assignments, path, mapping)
70
71def extract_dependencies(reg, assignments, mapping=None):
72 """Return a list of all registers which directly

Callers 1

check_cycleFunction · 0.85

Calls 3

itemsMethod · 0.80
appendMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected