Display nearby disassembly at $PC of current execution context Usage: MYNAME [linecount]
(self, *arg)
| 4257 | |
| 4258 | @msg.bufferize |
| 4259 | def context_code(self, *arg): |
| 4260 | """ |
| 4261 | Display nearby disassembly at $PC of current execution context |
| 4262 | Usage: |
| 4263 | MYNAME [linecount] |
| 4264 | """ |
| 4265 | (count,) = normalize_argv(arg, 1) |
| 4266 | |
| 4267 | if count is None: |
| 4268 | count = 8 |
| 4269 | |
| 4270 | if not self._is_running(): |
| 4271 | return |
| 4272 | |
| 4273 | pc = peda.getreg("pc") |
| 4274 | if peda.is_address(pc): |
| 4275 | inst = peda.get_disasm(pc) |
| 4276 | else: |
| 4277 | inst = None |
| 4278 | |
| 4279 | text = blue("[%s]" % "code".center(78, "-")) |
| 4280 | msg(text) |
| 4281 | if inst: # valid $PC |
| 4282 | text = "" |
| 4283 | opcode = inst.split(":\t")[-1].split()[0] |
| 4284 | # stopped at function call |
| 4285 | if "call" in opcode: |
| 4286 | text += peda.disassemble_around(pc, count) |
| 4287 | msg(format_disasm_code(text, pc)) |
| 4288 | self.dumpargs() |
| 4289 | # stopped at jump |
| 4290 | elif "j" in opcode: |
| 4291 | jumpto = peda.testjump(inst) |
| 4292 | if jumpto: # JUMP is taken |
| 4293 | code = peda.disassemble_around(pc, count) |
| 4294 | code = code.splitlines() |
| 4295 | pc_idx = 999 |
| 4296 | for (idx, line) in enumerate(code): |
| 4297 | if ("0x%x" % pc) in line.split(":")[0]: |
| 4298 | pc_idx = idx |
| 4299 | if idx <= pc_idx: |
| 4300 | text += line + "\n" |
| 4301 | else: |
| 4302 | text += " | %s\n" % line.strip() |
| 4303 | text = format_disasm_code(text, pc) + "\n" |
| 4304 | text += " |->" |
| 4305 | code = peda.get_disasm(jumpto, count//2) |
| 4306 | if not code: |
| 4307 | code = " Cannot evaluate jump destination\n" |
| 4308 | |
| 4309 | code = code.splitlines() |
| 4310 | text += red(code[0]) + "\n" |
| 4311 | for line in code[1:]: |
| 4312 | text += " %s\n" % line.strip() |
| 4313 | text += red("JUMP is taken".rjust(79)) |
| 4314 | else: # JUMP is NOT taken |
| 4315 | text += format_disasm_code(peda.disassemble_around(pc, count), pc) |
| 4316 | text += "\n" + green("JUMP is NOT taken".rjust(79)) |
no test coverage detected