本文介绍了在gdb中查看ASCII中的寄存器内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我现在在这个位置,我想以ascii格式查看cl,ch,cx,ecx等的内容.
Suppose, I am at this position now, and I want to see the content of cl, ch, cx, ecx, etc in ascii format.
该怎么办?
以下是layout asm
命令中显示的子例程.
The following is the subroutine displayed in the layout asm
command.
RemCharCodeFromAToB:
; standard entry sequence
push ebp ; save the previous value of ebp for the benefi$
mov ebp, esp ; copy esp -> ebp so that ebp can be used as a $
; accessing arguments
; [ebp + 0] = old ebp stack frame
; [ebp + 4] = return address
mov edx, [ebp + 8] ; string address
while_loop_rcc:
mov cl, [edx] ; obtain the address of the 1st character of the string
cmp cl, 0 ; check the null value
je while_loop_exit_rcc ; exit if the null-character is reached
mov al, cl ; save cl
mov cl, [ebp + 16] ; end-char
push cx ; push end-char
mov cl, [ebp + 12] ; start-char
push cx ; push start-char
push ax; ; push ch
call IsBetweenAandB
add esp, 12
cmp eax, 0 ; if(ch is not between 'a' and 'e')
je inner_loop_exit_rcc
mov eax, edx ; copy the current address
inner_loop_rcc:
mov cl, [eax+1]
cmp cl, 0
je inner_loop_exit_rcc
mov [eax], cl
inc eax
jmp inner_loop_rcc
inner_loop_exit_rcc:
inc edx ; increment the address
jmp while_loop_rcc ; start the loop again
while_loop_exit_rcc:
; standard exit sequence
mov esp, ebp ; restore esp with ebp
pop ebp ; remove ebp from stack
ret ; return the value of temporary variable
- 完整的asm代码在这里.
- C ++代码在这里.
- Makefile 在这里.
- Full asm code is here.
- C++ code is here.
- Makefile is here.
推荐答案
这将定义一个asciiprint
宏,该宏会将其参数寄存器的值打印为从最低有效字节到最高字节的字符序列.
This will define an asciiprint
macro, which will print its argument register's value as a sequence of characters, from least significant byte to most.
(gdb) define asciiprint
set $len = sizeof($arg0)
set $val = (unsigned long long)($arg0)
while $len-- > 0
set $char = $val & 0xff
if $char >= 0x20 && $char <= 0x7e
printf "%c", $char
else
printf "\\x%02x", $char
end
set $val >>= 8
end
printf "\n"
end
(gdb) set $rcx=0x6b63616a70616c66
(gdb) asciiprint $rcx
flapjack
(gdb) asciiprint $ecx
flap
(gdb) asciiprint $cx
fl
(gdb) asciiprint $cl
f
(gdb) asciiprint $ch
l
这篇关于在gdb中查看ASCII中的寄存器内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!