We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Help: disasm with duplicate visual pointing references
I'm learning about RE and just find out pwndbg.

Using splitmind (saw it in FEATURES readme) with a custom setup of window/pane splitting, I got some "duplicate" visual references pointing to the same instruction in DISASM section.

I don't know if it's the right place to ask for help or not, sorry if it's not the right one   

![image](https://user-images.githubusercontent.com/6990857/80813910-4c0ae780-8ba1-11ea-9ef3-239a5153c32d.png)

I'm playing aroung with this:
https://crackmes.one/crackme/5d22b9d833c5d410dc4d0c9f

```
Gdb:       10.0.50.20200307-git
Python:    3.8.2 (default, Apr  8 2020, 14:31:25)  [GCC 9.3.0]
Pwndbg:    1.1.0 build: 3cf9b31
Capstone:  4.0.1024
Unicorn:   1.0.1
alacritty: 0.4.2
tmux:      3.1
zsh:       zsh 5.8 (x86_64-pc-linux-gnu)
OS:
DISTRIB_ID=ManjaroLinux
DISTRIB_RELEASE=20.0
DISTRIB_CODENAME=Lysia
DISTRIB_DESCRIPTION="Manjaro Linux"
```

My .gdbinit
```
source /home/lucasbertin/Projetos/OSS/pwndbg/gdbinit.py
set context-clear-screen on
set follow-fork-mode parent

source /home/lucasbertin/Projetos/OSS/splitmind/gdbinit.py
python
import splitmind
(splitmind.Mind()
  .tell_splitter(show_titles=True)
  .tell_splitter(set_title="Main")

  .right(display="backtrace", size="25%")

  .above(of="main", display="disasm", banner="top", size="85%")
  .right(of="disasm", display="legend")
  .below(of="legend", display="stack")

  .show("regs", on="legend")
  .below(of="backtrace", cmd='tty; tail -f /dev/null', clearing=False)
  .below(cmd="python3")
).build(nobanner=True)
end

set context-code-lines 30
set context-source-code-lines 30
set context-sections  "regs args code disasm stack backtrace"
```

Any tips or hints are welcome, thanks!!

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pwndbg/commands/nearpc.py`
Content:
```
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 from __future__ import absolute_import
4 from __future__ import division
5 from __future__ import print_function
6 from __future__ import unicode_literals
7 
8 import argparse
9 import codecs
10 
11 import gdb
12 from capstone import *
13 
14 import pwndbg.arguments
15 import pwndbg.color
16 import pwndbg.color.context as C
17 import pwndbg.color.disasm as D
18 import pwndbg.color.nearpc as N
19 import pwndbg.color.theme
20 import pwndbg.config
21 import pwndbg.disasm
22 import pwndbg.functions
23 import pwndbg.ida
24 import pwndbg.regs
25 import pwndbg.strings
26 import pwndbg.symbol
27 import pwndbg.ui
28 import pwndbg.vmmap
29 from pwndbg.color import message
30 
31 
32 def ljust_padding(lst):
33     longest_len = max(map(len, lst)) if lst else 0
34     return [s.ljust(longest_len) for s in lst]
35 
36 nearpc_branch_marker = pwndbg.color.theme.Parameter('nearpc-branch-marker', '    ↓', 'branch marker line for nearpc command')
37 nearpc_branch_marker_contiguous = pwndbg.color.theme.Parameter('nearpc-branch-marker-contiguous', ' ', 'contiguous branch marker line for nearpc command')
38 pwndbg.color.theme.Parameter('highlight-pc', True, 'whether to highlight the current instruction')
39 pwndbg.color.theme.Parameter('nearpc-prefix', '►', 'prefix marker for nearpc command')
40 pwndbg.config.Parameter('left-pad-disasm', True, 'whether to left-pad disassembly')
41 nearpc_lines = pwndbg.config.Parameter('nearpc-lines', 10, 'number of additional lines to print for the nearpc command')
42 show_args = pwndbg.config.Parameter('nearpc-show-args', True, 'show call arguments below instruction')
43 
44 parser = argparse.ArgumentParser(description='''Disassemble near a specified address.''')
45 parser.add_argument("pc", type=int, nargs="?", default=None, help="Address to dissassemble near.")
46 parser.add_argument("lines", type=int, nargs="?", default=None, help="Number of lines to show on either side of the address.")
47 #parser.add_argument("to_string", type=bool, nargs="?", default=False, help="Whether to print it or not.") #TODO make sure this should not be exposed
48 parser.add_argument("emulate", type=bool, nargs="?", default=False, help="Whether to emulate instructions to find the next ones or just linearly disassemble.")
49 @pwndbg.commands.ArgparsedCommand(parser)
50 @pwndbg.commands.OnlyWhenRunning
51 def nearpc(pc=None, lines=None, to_string=False, emulate=False):
52     """
53     Disassemble near a specified address.
54     """
55 
56     # Repeating nearpc (pressing enter) makes it show next addresses
57     # (writing nearpc explicitly again will reset its state)
58     if nearpc.repeat:
59         pc = nearpc.next_pc
60 
61     result = []
62 
63     # Fix the case where we only have one argument, and
64     # it's a small value.
65     if lines is None and (pc is None or int(pc) < 0x100):
66         lines = pc
67         pc    = None
68 
69     if pc is None:
70         pc = pwndbg.regs.pc
71 
72     if lines is None:
73         lines = nearpc_lines // 2
74 
75     pc    = int(pc)
76     lines = int(lines)
77 
78     # Check whether we can even read this address
79     if not pwndbg.memory.peek(pc):
80         result.append(message.error('Invalid address %#x' % pc))
81 
82     # # Load source data if it's available
83     # pc_to_linenos = collections.defaultdict(lambda: [])
84     # lineno_to_src = {}
85     # frame = gdb.selected_frame()
86     # if frame:
87     #     sal = frame.find_sal()
88     #     if sal:
89     #         symtab = sal.symtab
90     #         objfile = symtab.objfile
91     #         sourcefilename = symtab.filename
92     #         with open(sourcefilename, 'r') as sourcefile:
93     #             lineno_to_src = {i:l for i,l in enumerate(sourcefile.readlines())}
94 
95     #         for line in symtab.linetable():
96     #             pc_to_linenos[line.pc].append(line.line)
97     instructions = pwndbg.disasm.near(pc, lines, emulate=emulate, show_prev_insns=not nearpc.repeat)
98 
99     if pwndbg.memory.peek(pc) and not instructions:
100         result.append(message.error('Invalid instructions at %#x' % pc))
101 
102     # In case $pc is in a new map we don't know about,
103     # this will trigger an exploratory search.
104     pwndbg.vmmap.find(pc)
105 
106     # Gather all addresses and symbols for each instruction
107     symbols = [pwndbg.symbol.get(i.address) for i in instructions]
108     addresses = ['%#x' % i.address for i in instructions]
109 
110     nearpc.next_pc = instructions[-1].address + instructions[-1].size if instructions else 0
111 
112     # Format the symbol name for each instruction
113     symbols = ['<%s> ' % sym if sym else '' for sym in symbols]
114 
115     # Pad out all of the symbols and addresses
116     if pwndbg.config.left_pad_disasm and not nearpc.repeat:
117         symbols   = ljust_padding(symbols)
118         addresses = ljust_padding(addresses)
119 
120     prev = None
121 
122     # Print out each instruction
123     for address_str, symbol, instr in zip(addresses, symbols, instructions):
124         asm    = D.instruction(instr)
125         prefix_sign  = pwndbg.config.nearpc_prefix
126 
127         # Show prefix only on the specified address and don't show it while in repeat-mode
128         show_prefix = instr.address == pc and not nearpc.repeat
129         prefix = ' %s' % (prefix_sign if show_prefix else ' ' * len(prefix_sign))
130         prefix = N.prefix(prefix)
131 
132         pre = pwndbg.ida.Anterior(instr.address)
133         if pre:
134             result.append(N.ida_anterior(pre))
135 
136         # Colorize address and symbol if not highlighted
137         # symbol is fetched from gdb and it can be e.g. '<main+8>'
138         if instr.address != pc or not pwndbg.config.highlight_pc or nearpc.repeat:
139             address_str = N.address(address_str)
140             symbol = N.symbol(symbol)
141         elif pwndbg.config.highlight_pc:
142             prefix = C.highlight(prefix)
143             address_str = C.highlight(address_str)
144             symbol = C.highlight(symbol)
145 
146         line   = ' '.join((prefix, address_str, symbol, asm))
147 
148         # If there was a branch before this instruction which was not
149         # contiguous, put in some ellipses.
150         if prev and prev.address + prev.size != instr.address:
151             result.append(N.branch_marker('%s' % nearpc_branch_marker))
152 
153         # Otherwise if it's a branch and it *is* contiguous, just put
154         # and empty line.
155         elif prev and any(g in prev.groups for g in (CS_GRP_CALL, CS_GRP_JUMP, CS_GRP_RET)):
156             if len('%s' % nearpc_branch_marker_contiguous) > 0:
157                 result.append('%s' % nearpc_branch_marker_contiguous)
158 
159         # For syscall instructions, put the name on the side
160         if instr.address == pc:
161             syscall_name = pwndbg.arguments.get_syscall_name(instr)
162             if syscall_name:
163                 line += ' <%s>' % N.syscall_name(syscall_name)
164 
165         result.append(line)
166 
167         # For call instructions, attempt to resolve the target and
168         # determine the number of arguments.
169         if show_args:
170             result.extend(['%8s%s' % ('', arg) for arg in pwndbg.arguments.format_args(instruction=instr)])
171 
172         prev = instr
173 
174     if not to_string:
175         print('\n'.join(result))
176 
177     return result
178 
179 
180 parser = argparse.ArgumentParser(description='''Like nearpc, but will emulate instructions from the current $PC forward.''')
181 parser.add_argument("pc", type=int, nargs="?", default=None, help="Address to emulate near.")
182 parser.add_argument("lines", type=int, nargs="?", default=None, help="Number of lines to show on either side of the address.")
183 @pwndbg.commands.ArgparsedCommand(parser)
184 @pwndbg.commands.OnlyWhenRunning
185 def emulate(pc=None, lines=None, to_string=False, emulate=True):
186     """
187     Like nearpc, but will emulate instructions from the current $PC forward.
188     """
189     nearpc.repeat = emulate_command.repeat
190     return nearpc(pc, lines, to_string, emulate)
191 
192 
193 emulate_command = emulate
194 
195 
196 parser = argparse.ArgumentParser(description='''Compatibility layer for PEDA's pdisass command.''')
197 parser.add_argument("pc", type=int, nargs="?", default=None, help="Address to disassemble near.")
198 parser.add_argument("lines", type=int, nargs="?", default=None, help="Number of lines to show on either side of the address.")
199 @pwndbg.commands.ArgparsedCommand(parser)
200 @pwndbg.commands.OnlyWhenRunning
201 def pdisass(pc=None, lines=None, to_string=False):
202     """
203     Compatibility layer for PEDA's pdisass command
204     """
205     nearpc.repeat = pdisass.repeat
206     return nearpc(pc, lines, to_string, False)
207 
208 
209 nearpc.next_pc = 0
210
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pwndbg/commands/nearpc.py b/pwndbg/commands/nearpc.py
--- a/pwndbg/commands/nearpc.py
+++ b/pwndbg/commands/nearpc.py
@@ -119,13 +119,16 @@
 
     prev = None
 
+    first_pc = True
+
     # Print out each instruction
     for address_str, symbol, instr in zip(addresses, symbols, instructions):
         asm    = D.instruction(instr)
         prefix_sign  = pwndbg.config.nearpc_prefix
 
         # Show prefix only on the specified address and don't show it while in repeat-mode
-        show_prefix = instr.address == pc and not nearpc.repeat
+        # or when showing current instruction for the second time
+        show_prefix = instr.address == pc and not nearpc.repeat and first_pc
         prefix = ' %s' % (prefix_sign if show_prefix else ' ' * len(prefix_sign))
         prefix = N.prefix(prefix)
 
@@ -138,10 +141,11 @@
         if instr.address != pc or not pwndbg.config.highlight_pc or nearpc.repeat:
             address_str = N.address(address_str)
             symbol = N.symbol(symbol)
-        elif pwndbg.config.highlight_pc:
+        elif pwndbg.config.highlight_pc and first_pc:
             prefix = C.highlight(prefix)
             address_str = C.highlight(address_str)
             symbol = C.highlight(symbol)
+            first_pc = False
 
         line   = ' '.join((prefix, address_str, symbol, asm))

{"golden_diff": "diff --git a/pwndbg/commands/nearpc.py b/pwndbg/commands/nearpc.py\n--- a/pwndbg/commands/nearpc.py\n+++ b/pwndbg/commands/nearpc.py\n@@ -119,13 +119,16 @@\n \n     prev = None\n \n+    first_pc = True\n+\n     # Print out each instruction\n     for address_str, symbol, instr in zip(addresses, symbols, instructions):\n         asm    = D.instruction(instr)\n         prefix_sign  = pwndbg.config.nearpc_prefix\n \n         # Show prefix only on the specified address and don't show it while in repeat-mode\n-        show_prefix = instr.address == pc and not nearpc.repeat\n+        # or when showing current instruction for the second time\n+        show_prefix = instr.address == pc and not nearpc.repeat and first_pc\n         prefix = ' %s' % (prefix_sign if show_prefix else ' ' * len(prefix_sign))\n         prefix = N.prefix(prefix)\n \n@@ -138,10 +141,11 @@\n         if instr.address != pc or not pwndbg.config.highlight_pc or nearpc.repeat:\n             address_str = N.address(address_str)\n             symbol = N.symbol(symbol)\n-        elif pwndbg.config.highlight_pc:\n+        elif pwndbg.config.highlight_pc and first_pc:\n             prefix = C.highlight(prefix)\n             address_str = C.highlight(address_str)\n             symbol = C.highlight(symbol)\n+            first_pc = False\n \n         line   = ' '.join((prefix, address_str, symbol, asm))\n", "issue": "Help: disasm with duplicate visual pointing references\nI'm learning about RE and just find out pwndbg.\r\n\r\nUsing splitmind (saw it in FEATURES readme) with a custom setup of window/pane splitting, I got some \"duplicate\" visual references pointing to the same instruction in DISASM section.\r\n\r\nI don't know if it's the right place to ask for help or not, sorry if it's not the right one   \r\n\r\n![image](https://user-images.githubusercontent.com/6990857/80813910-4c0ae780-8ba1-11ea-9ef3-239a5153c32d.png)\r\n\r\nI'm playing aroung with this:\r\nhttps://crackmes.one/crackme/5d22b9d833c5d410dc4d0c9f\r\n\r\n```\r\nGdb:       10.0.50.20200307-git\r\nPython:    3.8.2 (default, Apr  8 2020, 14:31:25)  [GCC 9.3.0]\r\nPwndbg:    1.1.0 build: 3cf9b31\r\nCapstone:  4.0.1024\r\nUnicorn:   1.0.1\r\nalacritty: 0.4.2\r\ntmux:      3.1\r\nzsh:       zsh 5.8 (x86_64-pc-linux-gnu)\r\nOS:\r\nDISTRIB_ID=ManjaroLinux\r\nDISTRIB_RELEASE=20.0\r\nDISTRIB_CODENAME=Lysia\r\nDISTRIB_DESCRIPTION=\"Manjaro Linux\"\r\n```\r\n\r\nMy .gdbinit\r\n```\r\nsource /home/lucasbertin/Projetos/OSS/pwndbg/gdbinit.py\r\nset context-clear-screen on\r\nset follow-fork-mode parent\r\n\r\nsource /home/lucasbertin/Projetos/OSS/splitmind/gdbinit.py\r\npython\r\nimport splitmind\r\n(splitmind.Mind()\r\n  .tell_splitter(show_titles=True)\r\n  .tell_splitter(set_title=\"Main\")\r\n\r\n  .right(display=\"backtrace\", size=\"25%\")\r\n\r\n  .above(of=\"main\", display=\"disasm\", banner=\"top\", size=\"85%\")\r\n  .right(of=\"disasm\", display=\"legend\")\r\n  .below(of=\"legend\", display=\"stack\")\r\n\r\n  .show(\"regs\", on=\"legend\")\r\n  .below(of=\"backtrace\", cmd='tty; tail -f /dev/null', clearing=False)\r\n  .below(cmd=\"python3\")\r\n).build(nobanner=True)\r\nend\r\n\r\nset context-code-lines 30\r\nset context-source-code-lines 30\r\nset context-sections  \"regs args code disasm stack backtrace\"\r\n```\r\n\r\nAny tips or hints are welcome, thanks!!\n", "before_files": [{"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\nfrom __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\nfrom __future__ import unicode_literals\n\nimport argparse\nimport codecs\n\nimport gdb\nfrom capstone import *\n\nimport pwndbg.arguments\nimport pwndbg.color\nimport pwndbg.color.context as C\nimport pwndbg.color.disasm as D\nimport pwndbg.color.nearpc as N\nimport pwndbg.color.theme\nimport pwndbg.config\nimport pwndbg.disasm\nimport pwndbg.functions\nimport pwndbg.ida\nimport pwndbg.regs\nimport pwndbg.strings\nimport pwndbg.symbol\nimport pwndbg.ui\nimport pwndbg.vmmap\nfrom pwndbg.color import message\n\n\ndef ljust_padding(lst):\n    longest_len = max(map(len, lst)) if lst else 0\n    return [s.ljust(longest_len) for s in lst]\n\nnearpc_branch_marker = pwndbg.color.theme.Parameter('nearpc-branch-marker', '    \u2193', 'branch marker line for nearpc command')\nnearpc_branch_marker_contiguous = pwndbg.color.theme.Parameter('nearpc-branch-marker-contiguous', ' ', 'contiguous branch marker line for nearpc command')\npwndbg.color.theme.Parameter('highlight-pc', True, 'whether to highlight the current instruction')\npwndbg.color.theme.Parameter('nearpc-prefix', '\u25ba', 'prefix marker for nearpc command')\npwndbg.config.Parameter('left-pad-disasm', True, 'whether to left-pad disassembly')\nnearpc_lines = pwndbg.config.Parameter('nearpc-lines', 10, 'number of additional lines to print for the nearpc command')\nshow_args = pwndbg.config.Parameter('nearpc-show-args', True, 'show call arguments below instruction')\n\nparser = argparse.ArgumentParser(description='''Disassemble near a specified address.''')\nparser.add_argument(\"pc\", type=int, nargs=\"?\", default=None, help=\"Address to dissassemble near.\")\nparser.add_argument(\"lines\", type=int, nargs=\"?\", default=None, help=\"Number of lines to show on either side of the address.\")\n#parser.add_argument(\"to_string\", type=bool, nargs=\"?\", default=False, help=\"Whether to print it or not.\") #TODO make sure this should not be exposed\nparser.add_argument(\"emulate\", type=bool, nargs=\"?\", default=False, help=\"Whether to emulate instructions to find the next ones or just linearly disassemble.\")\n@pwndbg.commands.ArgparsedCommand(parser)\n@pwndbg.commands.OnlyWhenRunning\ndef nearpc(pc=None, lines=None, to_string=False, emulate=False):\n    \"\"\"\n    Disassemble near a specified address.\n    \"\"\"\n\n    # Repeating nearpc (pressing enter) makes it show next addresses\n    # (writing nearpc explicitly again will reset its state)\n    if nearpc.repeat:\n        pc = nearpc.next_pc\n\n    result = []\n\n    # Fix the case where we only have one argument, and\n    # it's a small value.\n    if lines is None and (pc is None or int(pc) < 0x100):\n        lines = pc\n        pc    = None\n\n    if pc is None:\n        pc = pwndbg.regs.pc\n\n    if lines is None:\n        lines = nearpc_lines // 2\n\n    pc    = int(pc)\n    lines = int(lines)\n\n    # Check whether we can even read this address\n    if not pwndbg.memory.peek(pc):\n        result.append(message.error('Invalid address %#x' % pc))\n\n    # # Load source data if it's available\n    # pc_to_linenos = collections.defaultdict(lambda: [])\n    # lineno_to_src = {}\n    # frame = gdb.selected_frame()\n    # if frame:\n    #     sal = frame.find_sal()\n    #     if sal:\n    #         symtab = sal.symtab\n    #         objfile = symtab.objfile\n    #         sourcefilename = symtab.filename\n    #         with open(sourcefilename, 'r') as sourcefile:\n    #             lineno_to_src = {i:l for i,l in enumerate(sourcefile.readlines())}\n\n    #         for line in symtab.linetable():\n    #             pc_to_linenos[line.pc].append(line.line)\n    instructions = pwndbg.disasm.near(pc, lines, emulate=emulate, show_prev_insns=not nearpc.repeat)\n\n    if pwndbg.memory.peek(pc) and not instructions:\n        result.append(message.error('Invalid instructions at %#x' % pc))\n\n    # In case $pc is in a new map we don't know about,\n    # this will trigger an exploratory search.\n    pwndbg.vmmap.find(pc)\n\n    # Gather all addresses and symbols for each instruction\n    symbols = [pwndbg.symbol.get(i.address) for i in instructions]\n    addresses = ['%#x' % i.address for i in instructions]\n\n    nearpc.next_pc = instructions[-1].address + instructions[-1].size if instructions else 0\n\n    # Format the symbol name for each instruction\n    symbols = ['<%s> ' % sym if sym else '' for sym in symbols]\n\n    # Pad out all of the symbols and addresses\n    if pwndbg.config.left_pad_disasm and not nearpc.repeat:\n        symbols   = ljust_padding(symbols)\n        addresses = ljust_padding(addresses)\n\n    prev = None\n\n    # Print out each instruction\n    for address_str, symbol, instr in zip(addresses, symbols, instructions):\n        asm    = D.instruction(instr)\n        prefix_sign  = pwndbg.config.nearpc_prefix\n\n        # Show prefix only on the specified address and don't show it while in repeat-mode\n        show_prefix = instr.address == pc and not nearpc.repeat\n        prefix = ' %s' % (prefix_sign if show_prefix else ' ' * len(prefix_sign))\n        prefix = N.prefix(prefix)\n\n        pre = pwndbg.ida.Anterior(instr.address)\n        if pre:\n            result.append(N.ida_anterior(pre))\n\n        # Colorize address and symbol if not highlighted\n        # symbol is fetched from gdb and it can be e.g. '<main+8>'\n        if instr.address != pc or not pwndbg.config.highlight_pc or nearpc.repeat:\n            address_str = N.address(address_str)\n            symbol = N.symbol(symbol)\n        elif pwndbg.config.highlight_pc:\n            prefix = C.highlight(prefix)\n            address_str = C.highlight(address_str)\n            symbol = C.highlight(symbol)\n\n        line   = ' '.join((prefix, address_str, symbol, asm))\n\n        # If there was a branch before this instruction which was not\n        # contiguous, put in some ellipses.\n        if prev and prev.address + prev.size != instr.address:\n            result.append(N.branch_marker('%s' % nearpc_branch_marker))\n\n        # Otherwise if it's a branch and it *is* contiguous, just put\n        # and empty line.\n        elif prev and any(g in prev.groups for g in (CS_GRP_CALL, CS_GRP_JUMP, CS_GRP_RET)):\n            if len('%s' % nearpc_branch_marker_contiguous) > 0:\n                result.append('%s' % nearpc_branch_marker_contiguous)\n\n        # For syscall instructions, put the name on the side\n        if instr.address == pc:\n            syscall_name = pwndbg.arguments.get_syscall_name(instr)\n            if syscall_name:\n                line += ' <%s>' % N.syscall_name(syscall_name)\n\n        result.append(line)\n\n        # For call instructions, attempt to resolve the target and\n        # determine the number of arguments.\n        if show_args:\n            result.extend(['%8s%s' % ('', arg) for arg in pwndbg.arguments.format_args(instruction=instr)])\n\n        prev = instr\n\n    if not to_string:\n        print('\\n'.join(result))\n\n    return result\n\n\nparser = argparse.ArgumentParser(description='''Like nearpc, but will emulate instructions from the current $PC forward.''')\nparser.add_argument(\"pc\", type=int, nargs=\"?\", default=None, help=\"Address to emulate near.\")\nparser.add_argument(\"lines\", type=int, nargs=\"?\", default=None, help=\"Number of lines to show on either side of the address.\")\n@pwndbg.commands.ArgparsedCommand(parser)\n@pwndbg.commands.OnlyWhenRunning\ndef emulate(pc=None, lines=None, to_string=False, emulate=True):\n    \"\"\"\n    Like nearpc, but will emulate instructions from the current $PC forward.\n    \"\"\"\n    nearpc.repeat = emulate_command.repeat\n    return nearpc(pc, lines, to_string, emulate)\n\n\nemulate_command = emulate\n\n\nparser = argparse.ArgumentParser(description='''Compatibility layer for PEDA's pdisass command.''')\nparser.add_argument(\"pc\", type=int, nargs=\"?\", default=None, help=\"Address to disassemble near.\")\nparser.add_argument(\"lines\", type=int, nargs=\"?\", default=None, help=\"Number of lines to show on either side of the address.\")\n@pwndbg.commands.ArgparsedCommand(parser)\n@pwndbg.commands.OnlyWhenRunning\ndef pdisass(pc=None, lines=None, to_string=False):\n    \"\"\"\n    Compatibility layer for PEDA's pdisass command\n    \"\"\"\n    nearpc.repeat = pdisass.repeat\n    return nearpc(pc, lines, to_string, False)\n\n\nnearpc.next_pc = 0\n", "path": "pwndbg/commands/nearpc.py"}], "after_files": [{"content": "#!/usr/bin/env python\n# -*- coding: utf-8 -*-\nfrom __future__ import absolute_import\nfrom __future__ import division\nfrom __future__ import print_function\nfrom __future__ import unicode_literals\n\nimport argparse\nimport codecs\n\nimport gdb\nfrom capstone import *\n\nimport pwndbg.arguments\nimport pwndbg.color\nimport pwndbg.color.context as C\nimport pwndbg.color.disasm as D\nimport pwndbg.color.nearpc as N\nimport pwndbg.color.theme\nimport pwndbg.config\nimport pwndbg.disasm\nimport pwndbg.functions\nimport pwndbg.ida\nimport pwndbg.regs\nimport pwndbg.strings\nimport pwndbg.symbol\nimport pwndbg.ui\nimport pwndbg.vmmap\nfrom pwndbg.color import message\n\n\ndef ljust_padding(lst):\n    longest_len = max(map(len, lst)) if lst else 0\n    return [s.ljust(longest_len) for s in lst]\n\nnearpc_branch_marker = pwndbg.color.theme.Parameter('nearpc-branch-marker', '    \u2193', 'branch marker line for nearpc command')\nnearpc_branch_marker_contiguous = pwndbg.color.theme.Parameter('nearpc-branch-marker-contiguous', ' ', 'contiguous branch marker line for nearpc command')\npwndbg.color.theme.Parameter('highlight-pc', True, 'whether to highlight the current instruction')\npwndbg.color.theme.Parameter('nearpc-prefix', '\u25ba', 'prefix marker for nearpc command')\npwndbg.config.Parameter('left-pad-disasm', True, 'whether to left-pad disassembly')\nnearpc_lines = pwndbg.config.Parameter('nearpc-lines', 10, 'number of additional lines to print for the nearpc command')\nshow_args = pwndbg.config.Parameter('nearpc-show-args', True, 'show call arguments below instruction')\n\nparser = argparse.ArgumentParser(description='''Disassemble near a specified address.''')\nparser.add_argument(\"pc\", type=int, nargs=\"?\", default=None, help=\"Address to dissassemble near.\")\nparser.add_argument(\"lines\", type=int, nargs=\"?\", default=None, help=\"Number of lines to show on either side of the address.\")\n#parser.add_argument(\"to_string\", type=bool, nargs=\"?\", default=False, help=\"Whether to print it or not.\") #TODO make sure this should not be exposed\nparser.add_argument(\"emulate\", type=bool, nargs=\"?\", default=False, help=\"Whether to emulate instructions to find the next ones or just linearly disassemble.\")\n@pwndbg.commands.ArgparsedCommand(parser)\n@pwndbg.commands.OnlyWhenRunning\ndef nearpc(pc=None, lines=None, to_string=False, emulate=False):\n    \"\"\"\n    Disassemble near a specified address.\n    \"\"\"\n\n    # Repeating nearpc (pressing enter) makes it show next addresses\n    # (writing nearpc explicitly again will reset its state)\n    if nearpc.repeat:\n        pc = nearpc.next_pc\n\n    result = []\n\n    # Fix the case where we only have one argument, and\n    # it's a small value.\n    if lines is None and (pc is None or int(pc) < 0x100):\n        lines = pc\n        pc    = None\n\n    if pc is None:\n        pc = pwndbg.regs.pc\n\n    if lines is None:\n        lines = nearpc_lines // 2\n\n    pc    = int(pc)\n    lines = int(lines)\n\n    # Check whether we can even read this address\n    if not pwndbg.memory.peek(pc):\n        result.append(message.error('Invalid address %#x' % pc))\n\n    # # Load source data if it's available\n    # pc_to_linenos = collections.defaultdict(lambda: [])\n    # lineno_to_src = {}\n    # frame = gdb.selected_frame()\n    # if frame:\n    #     sal = frame.find_sal()\n    #     if sal:\n    #         symtab = sal.symtab\n    #         objfile = symtab.objfile\n    #         sourcefilename = symtab.filename\n    #         with open(sourcefilename, 'r') as sourcefile:\n    #             lineno_to_src = {i:l for i,l in enumerate(sourcefile.readlines())}\n\n    #         for line in symtab.linetable():\n    #             pc_to_linenos[line.pc].append(line.line)\n    instructions = pwndbg.disasm.near(pc, lines, emulate=emulate, show_prev_insns=not nearpc.repeat)\n\n    if pwndbg.memory.peek(pc) and not instructions:\n        result.append(message.error('Invalid instructions at %#x' % pc))\n\n    # In case $pc is in a new map we don't know about,\n    # this will trigger an exploratory search.\n    pwndbg.vmmap.find(pc)\n\n    # Gather all addresses and symbols for each instruction\n    symbols = [pwndbg.symbol.get(i.address) for i in instructions]\n    addresses = ['%#x' % i.address for i in instructions]\n\n    nearpc.next_pc = instructions[-1].address + instructions[-1].size if instructions else 0\n\n    # Format the symbol name for each instruction\n    symbols = ['<%s> ' % sym if sym else '' for sym in symbols]\n\n    # Pad out all of the symbols and addresses\n    if pwndbg.config.left_pad_disasm and not nearpc.repeat:\n        symbols   = ljust_padding(symbols)\n        addresses = ljust_padding(addresses)\n\n    prev = None\n\n    first_pc = True\n\n    # Print out each instruction\n    for address_str, symbol, instr in zip(addresses, symbols, instructions):\n        asm    = D.instruction(instr)\n        prefix_sign  = pwndbg.config.nearpc_prefix\n\n        # Show prefix only on the specified address and don't show it while in repeat-mode\n        # or when showing current instruction for the second time\n        show_prefix = instr.address == pc and not nearpc.repeat and first_pc\n        prefix = ' %s' % (prefix_sign if show_prefix else ' ' * len(prefix_sign))\n        prefix = N.prefix(prefix)\n\n        pre = pwndbg.ida.Anterior(instr.address)\n        if pre:\n            result.append(N.ida_anterior(pre))\n\n        # Colorize address and symbol if not highlighted\n        # symbol is fetched from gdb and it can be e.g. '<main+8>'\n        if instr.address != pc or not pwndbg.config.highlight_pc or nearpc.repeat:\n            address_str = N.address(address_str)\n            symbol = N.symbol(symbol)\n        elif pwndbg.config.highlight_pc and first_pc:\n            prefix = C.highlight(prefix)\n            address_str = C.highlight(address_str)\n            symbol = C.highlight(symbol)\n            first_pc = False\n\n        line   = ' '.join((prefix, address_str, symbol, asm))\n\n        # If there was a branch before this instruction which was not\n        # contiguous, put in some ellipses.\n        if prev and prev.address + prev.size != instr.address:\n            result.append(N.branch_marker('%s' % nearpc_branch_marker))\n\n        # Otherwise if it's a branch and it *is* contiguous, just put\n        # and empty line.\n        elif prev and any(g in prev.groups for g in (CS_GRP_CALL, CS_GRP_JUMP, CS_GRP_RET)):\n            if len('%s' % nearpc_branch_marker_contiguous) > 0:\n                result.append('%s' % nearpc_branch_marker_contiguous)\n\n        # For syscall instructions, put the name on the side\n        if instr.address == pc:\n            syscall_name = pwndbg.arguments.get_syscall_name(instr)\n            if syscall_name:\n                line += ' <%s>' % N.syscall_name(syscall_name)\n\n        result.append(line)\n\n        # For call instructions, attempt to resolve the target and\n        # determine the number of arguments.\n        if show_args:\n            result.extend(['%8s%s' % ('', arg) for arg in pwndbg.arguments.format_args(instruction=instr)])\n\n        prev = instr\n\n    if not to_string:\n        print('\\n'.join(result))\n\n    return result\n\n\nparser = argparse.ArgumentParser(description='''Like nearpc, but will emulate instructions from the current $PC forward.''')\nparser.add_argument(\"pc\", type=int, nargs=\"?\", default=None, help=\"Address to emulate near.\")\nparser.add_argument(\"lines\", type=int, nargs=\"?\", default=None, help=\"Number of lines to show on either side of the address.\")\n@pwndbg.commands.ArgparsedCommand(parser)\n@pwndbg.commands.OnlyWhenRunning\ndef emulate(pc=None, lines=None, to_string=False, emulate=True):\n    \"\"\"\n    Like nearpc, but will emulate instructions from the current $PC forward.\n    \"\"\"\n    nearpc.repeat = emulate_command.repeat\n    return nearpc(pc, lines, to_string, emulate)\n\n\nemulate_command = emulate\n\n\nparser = argparse.ArgumentParser(description='''Compatibility layer for PEDA's pdisass command.''')\nparser.add_argument(\"pc\", type=int, nargs=\"?\", default=None, help=\"Address to disassemble near.\")\nparser.add_argument(\"lines\", type=int, nargs=\"?\", default=None, help=\"Number of lines to show on either side of the address.\")\n@pwndbg.commands.ArgparsedCommand(parser)\n@pwndbg.commands.OnlyWhenRunning\ndef pdisass(pc=None, lines=None, to_string=False):\n    \"\"\"\n    Compatibility layer for PEDA's pdisass command\n    \"\"\"\n    nearpc.repeat = pdisass.repeat\n    return nearpc(pc, lines, to_string, False)\n\n\nnearpc.next_pc = 0\n", "path": "pwndbg/commands/nearpc.py"}]}