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

Function regsort

pwnlib/regsort.py:122–448  ·  view source on GitHub ↗

Sorts register dependencies. Given a dictionary of registers to desired register contents, return the optimal order in which to set the registers to those contents. The implementation assumes that it is possible to move from any register to any other register. If a de

(in_out, all_regs, mapping = None, tmp = None, xchg = True, randomize = None)

Source from the content-addressed store, hash-verified

120 return False
121
122def regsort(in_out, all_regs, mapping = None, tmp = None, xchg = True, randomize = None):
123 """
124 Sorts register dependencies.
125
126 Given a dictionary of registers to desired register contents,
127 return the optimal order in which to set the registers to
128 those contents.
129
130 The implementation assumes that it is possible to move from
131 any register to any other register.
132
133 If a dependency cycle is encountered, one of the following will
134 occur:
135
136 - If ``xchg`` is :const:`True`, it is assumed that dependency cyles can
137 be broken by swapping the contents of two register (a la the
138 ``xchg`` instruction on i386).
139 - If ``xchg`` is not set, but not all destination registers in
140 ``in_out`` are involved in a cycle, one of the registers
141 outside the cycle will be used as a temporary register,
142 and then overwritten with its final value.
143 - If ``xchg`` is not set, and all registers are involved in
144 a dependency cycle, the named register ``temporary`` is used
145 as a temporary register.
146 - If the dependency cycle cannot be resolved as described above,
147 an exception is raised.
148
149 Arguments:
150
151 in_out(dict):
152 Dictionary of desired register states.
153 Keys are registers, values are either registers or any other value.
154 all_regs(list):
155 List of all possible registers.
156 Used to determine which values in ``in_out`` are registers, versus
157 regular values.
158 tmp(obj, str):
159 Named register (or other sentinel value) to use as a temporary
160 register. If ``tmp`` is a named register **and** appears
161 as a source value in ``in_out``, dependencies are handled
162 appropriately. ``tmp`` cannot be a destination register
163 in ``in_out``.
164 If ``bool(tmp)==True``, this mode is enabled.
165 xchg(obj):
166 Indicates the existence of an instruction which can swap the
167 contents of two registers without use of a third register.
168 If ``bool(xchg)==False``, this mode is disabled.
169 random(bool):
170 Randomize as much as possible about the order or registers.
171
172 Returns:
173
174 A list of tuples of ``(src, dest)``.
175
176 Each register may appear more than once, if a register is used
177 as a temporary register, and later overwritten with its final
178 value.
179

Callers

nothing calls this directly

Calls 10

extract_dependenciesFunction · 0.85
check_cycleFunction · 0.85
depends_on_cycleFunction · 0.85
resolve_orderFunction · 0.85
itemsMethod · 0.80
appendMethod · 0.80
errorMethod · 0.80
valuesMethod · 0.80
popMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected