[20220314]利用vim下使用gdb进行各种进制转换插件.txt
[20220314]利用vim下使用gdb进行各种进制转换插件.txt
--//前一段时间学习使用gdb进行各种进制转换,当时遇到有时候16进制与10进制一起运算的问题,当时我使用tpt的calc脚本来解决这个
--//问题来解决。当然bc以及bash也可以就是比较麻烦,比如。
$ echo $((0xa+10))
20
--//有时候我还给使用bccalc_linux插件转换为16进制,我后面发现gdb比较简单,不过我发现我的测试环境不支持gdb+管道,centos
--//7.8以上版本可以。尝试自己写一个插件完成这类换行操作。
--//参考链接 http://blog.itpub.net/267265/viewspace-2864628/ =>[20220304]使用gdb完成各种进制转换.txt
(gdb) help x
Examine memory: x/FMT ADDRESS.
ADDRESS is an expression for the memory address to examine.
FMT is a repeat count followed by a format letter and a size letter.
Format letters are o(octal), x(hex), d(decimal), u(unsigned decimal),
t(binary), f(float), a(address), i(instruction), c(char) and s(string).
Size letters are b(byte), h(halfword), w(word), g(giant, 8 bytes).
The specified number of objects of the specified size are printed
according to the format.
Defaults for format and size letters are those previously used.
Default count is 1. Default address is following last thing printed
with this command or "print".
--//在bash下执行,因为不支持管道,写成如下:
$ echo -e 'p /x 1212\nquit\n' >| /tmp/gdb.txt ; gdb -q -x /tmp/gdb.txt| awk '{print $NF}'
0x4bc
$ echo p/x 1212 >| /tmp/gdb.txt ; echo quit >> /tmp/gdb.txt ;gdb -q -x /tmp/gdb.txt| awk '{print $NF}'
0x4bc
$ cat gdb.vim
noremap <Leader>px Yp!!sed -e 's+^+p /x +' -e 's+$+\nquit\n+' >\| /tmp/gdb.txt && gdb -q -x /tmp/gdb.txt \| awk '{print $NF}'<CR>kA = <ESC>J
noremap <Leader>pd Yp!!sed -e 's+^+p /d +' -e 's+$+\nquit\n+' >\| /tmp/gdb.txt && gdb -q -x /tmp/gdb.txt \| awk '{print $NF}'<CR>kA = <ESC>J
noremap <Leader>po Yp!!sed -e 's+^+p /o +' -e 's+$+\nquit\n+' >\| /tmp/gdb.txt && gdb -q -x /tmp/gdb.txt \| awk '{print $NF}'<CR>kA = <ESC>J
noremap <Leader>pt Yp!!sed -e 's+^+p /t +' -e 's+$+\nquit\n+' >\| /tmp/gdb.txt && gdb -q -x /tmp/gdb.txt \| awk '{print $NF}'<CR>kA = <ESC>J
"" noremap <Leader>px Yp!!sed -e 's+^+p /x +' -e 's+$+\nquit\n+' \| gdb -q \| awk 'NR==1{print $NF}'<CR>kA = <ESC>J
"" noremap <Leader>pd Yp!!sed -e 's+^+p /d +' -e 's+$+\nquit\n+' \| gdb -q \| awk 'NR==1{print $NF}'<CR>kA = <ESC>J
"" noremap <Leader>po Yp!!sed -e 's+^+p /o +' -e 's+$+\nquit\n+' \| gdb -q \| awk 'NR==1{print $NF}'<CR>kA = <ESC>J
"" noremap <Leader>pt Yp!!sed -e 's+^+p /t +' -e 's+$+\nquit\n+' \| gdb -q \| awk 'NR==1{print $NF}'<CR>kA = <ESC>J
--//如果你gdb支持管道,注解上面部分,取消下面的注解。
--//临时调用可以执行:source ~/gdb.vim
--//还可以进行简单混合进制的计算例子:
12 * 0xa
--//打入\pd,显示如下:
12 * 0xa = 120
--//还不完善,有时间完善善看看。主要看中gdb能做一些特殊运算。
BBED> set dba 4,135
DBA 0x01000087 (16777351 4,135)
16777351 & 0x3ffff = 135
16777351 >> 22 = 4
16777351 & 0x3ffff
16777351 & 0x3ffff
--//当然在windows下就不行了,因为没有安装gdb,我尝试在Cygwin64 Terminal下安装gdb。
"" windows
noremap <Leader>px Yp!!sed -e "s+^+p /x +" \| gdb -q \| gawk "NR==1{print $NF}"<CR>kA = <ESC>J
noremap <Leader>pd Yp!!sed -e "s+^+p /d +" \| gdb -q \| gawk "NR==1{print $NF}"<CR>kA = <ESC>J
noremap <Leader>po Yp!!sed -e "s+^+p /o +" \| gdb -q \| gawk "NR==1{print $NF}"<CR>kA = <ESC>J
noremap <Leader>pt Yp!!sed -e "s+^+p /t +" \| gdb -q \| gawk "NR==1{print $NF}"<CR>kA = <ESC>J
--//注意,环境变量Path加入cygwin的安装路径。D:\tools\cygwin64\bin;另外awk在cygwin是链接,它没有后缀.exe.
--//我直接使用gawk。如果想使用awk修改如下:
$ ln gawk.exe awk.exe
$ ls -l awk*
lrwxrwxrwx 1 Administrator None 8 Mar 14 15:36 awk -> gawk.exe
-rwxr-xr-x 3 Administrator None 641024 Oct 30 04:46 awk.exe
--//注我的测试软连接不行。
--//最终我修改整理如下:
$ cat gdb.vim
"" gdb Low version for linux
noremap <Leader>px Yp!!sed -e 's+^+p /x +' >\| /tmp/gdb.txt && gdb -q -x /tmp/gdb.txt \| awk 'NR==1{print $NF}'<CR>kA = <ESC>J
noremap <Leader>pd Yp!!sed -e 's+^+p /d +' >\| /tmp/gdb.txt && gdb -q -x /tmp/gdb.txt \| awk 'NR==1{print $NF}'<CR>kA = <ESC>J
noremap <Leader>po Yp!!sed -e 's+^+p /o +' >\| /tmp/gdb.txt && gdb -q -x /tmp/gdb.txt \| awk 'NR==1{print $NF}'<CR>kA = <ESC>J
noremap <Leader>pt Yp!!sed -e 's+^+p /t +' >\| /tmp/gdb.txt && gdb -q -x /tmp/gdb.txt \| awk 'NR==1{print $NF}'<CR>kA = <ESC>J
"" gdb high version for linux
"" noremap <Leader>px Yp!!sed -e 's+^+p /x +' \| gdb -q \| awk 'NR==1{print $NF}'<CR>kA = <ESC>J
"" noremap <Leader>pd Yp!!sed -e 's+^+p /d +' \| gdb -q \| awk 'NR==1{print $NF}'<CR>kA = <ESC>J
"" noremap <Leader>po Yp!!sed -e 's+^+p /o +' \| gdb -q \| awk 'NR==1{print $NF}'<CR>kA = <ESC>J
"" noremap <Leader>pt Yp!!sed -e 's+^+p /t +' \| gdb -q \| awk 'NR==1{print $NF}'<CR>kA = <ESC>J
"" gdb for windwows, you must be cygwin + gdb.
""noremap <Leader>px Yp!!sed -e "s+^+p /x +" \| gdb -q \| gawk "NR==1{print $NF}"<CR>kA = <ESC>J
""noremap <Leader>pd Yp!!sed -e "s+^+p /d +" \| gdb -q \| gawk "NR==1{print $NF}"<CR>kA = <ESC>J
""noremap <Leader>po Yp!!sed -e "s+^+p /o +" \| gdb -q \| gawk "NR==1{print $NF}"<CR>kA = <ESC>J
""noremap <Leader>pt Yp!!sed -e "s+^+p /t +" \| gdb -q \| gawk "NR==1{print $NF}"<CR>kA = <ESC>J