Skip to content

Instantly share code, notes, and snippets.

@WinMin
Created July 22, 2020 06:00
Show Gist options
  • Save WinMin/9995619167482e0a317236656d56cbfe to your computer and use it in GitHub Desktop.
Save WinMin/9995619167482e0a317236656d56cbfe to your computer and use it in GitHub Desktop.
show protocol in gdb debug
from scapy.all import *
from scapy.layers.http import *
import gdb
class ShowProcto(gdb.Command):
"""
Usage: xpr/size memaddr procto_type
Exaple:
(gdb) xpr/20 0x7fffffffe238 TCP
"""
def __init__(self):
super(self.__class__,self).__init__("xpr",gdb.COMMAND_USER)
def invoke(self,args,from_ttt):
argv = gdb.string_to_argv(args)
func = Ether
if len(argv) < 2:
raise gdb.GdbError("args too short,type help xpr")
if len(argv) > 2:
func = getattr(scapy.all,argv[2])
startAddr = int(argv[1],16)
bytesLen = int(argv[0][1:])
proc = gdb.inferiors()[0]
data = proc.read_memory(startAddr,bytesLen).tobytes()
if func(data).show_summary:
func(data).show2()
else:
raise
ShowProcto()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment