• gdb 的配置、插件plugin与多彩显示


    gdb可以使用python来进行配置,为自动化调试与格式化显示提供非常方便的功能,具体可以自行搜索。加载了以下介绍的界面程序,还是可以在gdb运行的时候继续加载自己定义的python插件脚本,只要自己的脚本不设计到界面定义就行,不然界面会乱。因此,用下面的插件,就不能用gdbtui了,不然界面就变了,虽然gdbtui也非常好用。其实,用了gdb-dashboard就基本可以不用tui了,因为tui就只有一个自动显示source的功能,这个功能gdb-dashboard也有。

    gdb还有一些开源的配置插件,都是在 ~/.gdbinit 里直接写代码,或间接加载代码 ( 如 source /home/hzh/disk2/github/pwndbg/gdbinit.py 或 sourc /home/hzh/disk2/github/gdb-dashboard/.gdbinit)。这些开源插件如下,按我最喜欢的优先级进行排序:

    1、gdb-dashboard

    https://github.com/cyrus-and/gdb-dashboard

    它主要是能自动显示很多彩色的窗口,支持简单的代码语法高亮,我最喜欢的功能就是它可以设置在不同的tty里显示不同的窗口(后来发现gef也可以,即gef config context.redirect,所以gef应该排第一了),这个功能让我把它排第一。

    请注意,它的源代码窗口最大只能显示10行代码(就算在全新的窗口显示也是这样),我们可以通过修改它的配置文件来让它满屏显示:

    dashboard source -style height 40

    其中40就是终端的最大行数,可以用:

    tput lines

    得到,但是我们一般将得到的数值减去2,避免屏幕溢出。

    附加:

    其实gdb-dashboard配置代码里的:

    try:
        width, height = Dashboard.get_term_size(fd)                                                                                                                       
    except:
        width, height = Dashboard.get_term_size()

    是可以得到终端的长宽的。

    2、gef

    https://github.com/hugsy/gef

    它需要本机安装有 pyenv (一个管理python版本的软件)。但是可以手动将其改掉,就是将它的 gef.py 里的 site_packages_dir 直接改称自己的python site_packages 目录,可以这样得到:

    $  python -c 'import site; print(site.getsitepackages())'

    改变source code 显示窗的高度:   gef config 可以打印和配置所有的配置选项,要打印某条配置的帮助直接敲入如 gef config context.redirect。另如: gef config context.nb_lines_code 25  可以配置source code窗口的大小,配置后不用重启,直接敲 context 就可以更新显示。

    配置窗体的显示或隐藏:  全部显示:  gef config context.layout "legend regs stack code args source memory threads trace extra", 部分显示只需要删掉其中一些就行了,其中的code是说的汇编代码。一般调试主要使用 gef config context.layout "-legend -regs stack -code args source memory threads trace extra"

    • legend : a text explanation of the color code
    • regs : the state of registers
    • stack : the content of memory pointed by $sp register
    • code : the code being executed
    • args : if stopping at a function calls, print the call arguments
    • source : if compiled with source, this will show the corresponding line of source code
    • threads : all the threads
    • trace : the execution call trace
    • extra : if an automatic behavior is detected (vulnerable format string, heap vulnerability, etc.) it will be displayed in this pane
    • memory : peek into arbitrary memory locations

    若gef运行在tmux环境里,它的 tmux-setup 命令能将自己的界面split成左右两半,左边只输入命令,右边是context窗口,这样可以实现gdb(及gef)命令与显示窗体分离,比较清爽。

    文档:

    https://gef.readthedocs.io/en/master/

    3、PwnDbg

    https://github.com/pwndbg/pwndbg

    它不需要安装pyenv,但还是将它排在gef的后面,因为gef实在是轻巧且配置灵活,其实它们都差不多,都是主要调试二进制文件的(破解?),方便查看heap,stack及内存的值等,打印出来阅读方便。

    修改source code显示行数的方法:

    在配置文件搜索 context-source-code-lines 或 source_code_lines,将里面的10改称你要的,需要重启。

    可以在调试的时候使用 config source 或 config tty来获取帮助,这只是获取帮助,没有在线配置功能,智能改配置文件然后重启。

    每次刷新主显示窗口,敲 context 就可以。

    文档:

    https://browserpwndbg.readthedocs.io/en/docs/

    4、radare2

    https://github.com/radareorg/radare2

    主要拿来做逆向工程用的,二进制文件分析。

    5、peda

    https://github.com/longld/peda

    和PwnDbg及gef差不多,但是代码很久没更新了。

    6、Gdbinit

    https://github.com/gdbinit/Gdbinit

    就是一般的gdb彩色显示配置,功能简单,入门级。

    最后,gdb-dashboard、PwnDbg、gef、radare2、peda、Gdbinit 的自动切换,其实就是切换配置文件:

    先把他们全部装上,当然你可以选择自己感兴趣的安装,他们的配置都需要通过 ~/.gdbinit 来配置,因此他们是互斥的,配置里只能配置一种,但是可以用下面的这种方法解决,下面的示例只写了 peda、PwnDbg和gef,其它自己加。

    1、Open your .gdbinit file, delete any contents and paste the following configuration:

    define init-peda
    source ~/peda/peda.py
    end
    document init-peda
    Initializes the PEDA (Python Exploit Development Assistant for GDB) framework
    end
    
    define init-pwndbg
    source ~/.gdbinit_pwndbg
    end
    document init-pwndbg
    Initializes PwnDBG
    end
    
    define init-gef
    source ~/.gdbinit-gef.py
    end
    document init-gef
    Initializes GEF (GDB Enhanced Features)
    end

    Then, create the following 3 files in one of your $PATH folder:

    First create a file named by gdb-peda and paste the following:

    #!/bin/sh
    exec gdb -q -ex init-peda "$@"

    Then gdb-pwndbg:

    #!/bin/sh
    exec gdb -q -ex init-pwndbg "$@"

    Then gdb-gef:

    #!/bin/sh
    exec gdb -q -ex init-gef "$@"

    最后修改它们的可执行权限:

    chmod +x /usr/bin/gdb-*

    然后你就可以使用 gdb-peda, gdb-pwndbg 或 gdb-gef 来运行相应的gdb plugin版了。

  • 相关阅读:
    [POJ 2096] Collecting Bugs
    [POJ 3774] Scout YYF I
    [HDU 4418] Time travel
    [hdu 4586] Play the Dice
    [HDU 4507] 吉哥系列故事――恨7不成妻
    [HDU 4734] F(x)
    [Codeforces] Round #352 (Div. 2)
    刷题向》关于一道像差分约束的数学题BZOJ1045(NORMAL)
    刷题向》关于一道奇怪的贪心(田忌赛马)BZOJ1034(NORMAL-)
    刷题向》关于线段树的区间开根号 BZOJ3211(NORMAL+)
  • 原文地址:https://www.cnblogs.com/welhzh/p/13958736.html
Copyright © 2020-2023  润新知