'Display nearby disassembly at $PC of current execution context
Usage:
MYNAME [linecount]'

@msg.bufferize
def context_code(self, *arg):

    (count,) = normalize_argv(arg, 1)
    if (count is None):
        count = 8
    if (not self._is_running()):
        return
    pc = peda.getreg('pc')
    if peda.is_address(pc):
        inst = peda.get_disasm(pc)
    else:
        inst = None
    text = blue(('[%s]' % 'code'.center(78, '-')))
    msg(text)
    if inst:
        text = ''
        opcode = inst.split(': DCTB ')[(-1)].split()[0]
        if ('call' in opcode):
            text += peda.disassemble_around(pc, count)
            msg(format_disasm_code(text, pc))
            self.dumpargs()
        elif ('j' in opcode):
            jumpto = peda.testjump(inst)
            if jumpto:
                code = peda.disassemble_around(pc, count)
                code = code.splitlines()
                pc_idx = 999
                for (idx, line) in enumerate(code):
                    if (('0x%x' % pc) in line.split(':')[0]):
                        pc_idx = idx
                    if (idx <= pc_idx):
                        text += (line + '\n')
                    else:
                        text += ('    |    %s\n' % line.strip())
                text = (format_disasm_code(text, pc) + '\n')
                text += '    |->'
                code = peda.get_disasm(jumpto, (count // 2))
                if (not code):
                    code = '            Cannot    evaluate    jump    destination\n'
                code = code.splitlines()
                text += (red(code[0]) + '\n')
                for line in code[1:]:
                    text += ('                            %s\n' % line.strip())
                text += red('JUMP    is    taken'.rjust(79))
            else:
                text += format_disasm_code(peda.disassemble_around(pc, count), pc)
                text += ('\n' + green('JUMP    is    NOT    taken'.rjust(79)))
            msg(text.rstrip())
        else:
            text += peda.disassemble_around(pc, count)
            msg(format_disasm_code(text, pc))
    else:
        msg(('Invalid    $PC    address:    0x%x' % pc), 'red')
    return
