首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在gdb中查看ASCII中的寄存器内容

在gdb中查看ASCII中的寄存器内容
EN

Stack Overflow用户
提问于 2019-04-07 01:40:39
回答 2查看 2.1K关注 0票数 2

假设,我现在处于这个位置,我想以ascii格式查看cl、ch、cx、ecx等的内容。

该怎么办呢?

下面是layout asm命令中显示的子例程。

代码语言:javascript
复制
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
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-04-07 20:04:25

这将定义一个asciiprint宏,该宏将将其参数寄存器的值打印为字符序列,从最小有效字节到大多数字符。

代码语言:javascript
复制
(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
代码语言:javascript
复制
(gdb) set $rcx=0x6b63616a70616c66
(gdb) asciiprint $rcx
flapjack
(gdb) asciiprint $ecx
flap
(gdb) asciiprint $cx
fl
(gdb) asciiprint $cl
f
(gdb) asciiprint $ch
l
票数 4
EN

Stack Overflow用户

发布于 2019-04-07 05:19:30

我不确定这是否是您想要的,但是如果您键入以下命令:

代码语言:javascript
复制
print (char)$ch

..。您将看到寄存器ch的值为ASCII字符:

代码语言:javascript
复制
$3 = 70 'F'

但是,这只适用于字节寄存器。如果以这种方式打印16位或32位寄存器,则只会打印低字节。

您可以使用右移位在某些寄存器中打印8位作为ASCII字符。下面的示例将将ecx的位27.20打印为ASCII字符:

代码语言:javascript
复制
print (char)(((long)$ecx)>>20)
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55554914

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档