如何查看LPVOID类型变量的内容

发布于 2024-12-07 10:07:53 字数 90 浏览 0 评论 0原文

我有一个 C 函数,它采用 LPVOID 类型的参数。传入的值是 \0 分隔的字符数组。如何在 Visual Studio / Windbg 中转换参数以查看传入值?

I have a C function that takes a parameter of type LPVOID. The values that gets passed in is \0 seperated array of characters. How can I cast the parameter to see the incoming value in visual studio / windbg?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

乖乖哒 2024-12-14 10:07:53

您可以在脚本中执行此操作。类似下面的内容可以工作,它假设 char * 字符串并且列表以双 NULL 结尾(如 MULTI_SZ):

$ Print a MULTI_SZ value in the debugger. Note that 
$ this script assume a char* string

$ Grab the argument to the script
r @$t0 = ${$arg1}

$ while *str != NULL
.while (by(@$t0) != 0) 
{

    $ Print the string
    da @$t0

    $ There's no strlen in this language, so find the NULL
    .while (by(@$t0) != 0) 
    {
        r @$t0 = @$t0 + 1
    }

    $ String points to the NULL. Add one.
    r @$t0 = @$t0 + 1
}

保存到文本文件,然后在 WinDBG 中运行以下命令:

0:000> $>a<c:\dumps\multisz.txt 0x012210ec
012210ec  "Foo"
012210f0  "Bar"
012210f4  "FooBar"

You can do this in a script. Something like the following would work, which assumes char * strings and that the list ends in double NULLs (like a MULTI_SZ):

$ Print a MULTI_SZ value in the debugger. Note that 
$ this script assume a char* string

$ Grab the argument to the script
r @$t0 = ${$arg1}

$ while *str != NULL
.while (by(@$t0) != 0) 
{

    $ Print the string
    da @$t0

    $ There's no strlen in this language, so find the NULL
    .while (by(@$t0) != 0) 
    {
        r @$t0 = @$t0 + 1
    }

    $ String points to the NULL. Add one.
    r @$t0 = @$t0 + 1
}

Save to a text file and then run the following in WinDBG:

0:000> $>a<c:\dumps\multisz.txt 0x012210ec
012210ec  "Foo"
012210f0  "Bar"
012210f4  "FooBar"
回忆凄美了谁 2024-12-14 10:07:53

没有任何演员可以让您在观察窗口中观察到这一点。对于 VS,您必须在空分隔块开头的地址上打开一个内存窗口。

在 WinDbg 命令 db 中转储原始内存以及 ASCII 转换。如果块大于 128 字节,则将选项 l 添加到命令中。例如,这将为局部变量 pVoid 打印出前 0x200 字节:
db poi pVoid l200

There is no cast that would allow you to observe that in watch windows. For VS you will have to open up a memory window on the address at the beginning of the null separated block.

In WinDbg command db <my_address> dumps raw memory along with ASCII conversion. If block is larger than 128 bytes, then add option l to the command. E.g this will print out first 0x200 bytes for local variable pVoid:
db poi pVoid l200

莫相离 2024-12-14 10:07:53

只需转换为 char* 就可以了。

  void f(LPVOID s)
  {
      char* ss = (char*) s; // put breakpoint here or watch the variable
      for(char* r = ss; *r != '\0'; r += (strlen(r)+1)) { // iterate the string
          printf("%s \n", r);
       }   
  }

Simply casting to char* should work.

  void f(LPVOID s)
  {
      char* ss = (char*) s; // put breakpoint here or watch the variable
      for(char* r = ss; *r != '\0'; r += (strlen(r)+1)) { // iterate the string
          printf("%s \n", r);
       }   
  }
影子的影子 2024-12-14 10:07:53

又是一个很晚的答案,但可以利用 Windbg 中的 dpa 来打印列表,

lpvoid:\>dir /b
lpvoid.cpp

lpvoid:\>type lpvoid.cpp
#include <stdio.h>
#include <windows.h>

    int somefunc(LPVOID blah)
    {
        printf("%s\n",*(PCHAR *)blah);
        return 0;
    }
    int main (void)
    {
        PCHAR foo[] = { "yay" , "boy" , "dog" , "cat" , "monkey" , "weedinducedweird
    o" };
        somefunc( foo);
        return 0;
    }

    lpvoid:\>cl /Zi /nologo lpvoid.cpp
    lpvoid.cpp

    lpvoid:\>dir /b *.exe
    lpvoid.exe

    lpvoid:\>lpvoid.exe
    yay

在 somefunc 上设置 bp 或者如果地址上没有符号,例如 bp 401020
在参数上使用 dpa (这里是废话)或使用 dpa @esp+8

    lpvoid:\>cdb -c "bp somefunc \"dpa poi(blah) l?6;q\";g;q" lpvoid.exe | grep -A 6
     yay
    0013ff60  00417c60 "yay"
    0013ff64  00417c64 "boy"
    0013ff68  00417c68 "dog"
    0013ff6c  00417c6c "cat"
    0013ff70  00417c70 "monkey"
    0013ff74  00417c78 "weedinducedweirdo"
    quit:

假设这里没有符号

lpvoid:\>cdb -c "bp 401020 \"dpa (@esp+8) l?6;q\";g;q" lpvoid.exe | grep -A 6 ya
y
0013ff60  00417c60 "yay"
0013ff64  00417c64 "boy"
0013ff68  00417c68 "dog"
0013ff6c  00417c6c "cat"
0013ff70  00417c70 "monkey"
0013ff74  00417c78 "weedinducedweirdo"
quit:

again a very late a answer but dpa in windbg can be leveraged to print the list

lpvoid:\>dir /b
lpvoid.cpp

lpvoid:\>type lpvoid.cpp
#include <stdio.h>
#include <windows.h>

    int somefunc(LPVOID blah)
    {
        printf("%s\n",*(PCHAR *)blah);
        return 0;
    }
    int main (void)
    {
        PCHAR foo[] = { "yay" , "boy" , "dog" , "cat" , "monkey" , "weedinducedweird
    o" };
        somefunc( foo);
        return 0;
    }

    lpvoid:\>cl /Zi /nologo lpvoid.cpp
    lpvoid.cpp

    lpvoid:\>dir /b *.exe
    lpvoid.exe

    lpvoid:\>lpvoid.exe
    yay

set a bp on somefunc or if you do not have symbols on address lik bp 401020
use dpa on the argument (blah here) or use dpa @esp+8

    lpvoid:\>cdb -c "bp somefunc \"dpa poi(blah) l?6;q\";g;q" lpvoid.exe | grep -A 6
     yay
    0013ff60  00417c60 "yay"
    0013ff64  00417c64 "boy"
    0013ff68  00417c68 "dog"
    0013ff6c  00417c6c "cat"
    0013ff70  00417c70 "monkey"
    0013ff74  00417c78 "weedinducedweirdo"
    quit:

assuming no symbols here

lpvoid:\>cdb -c "bp 401020 \"dpa (@esp+8) l?6;q\";g;q" lpvoid.exe | grep -A 6 ya
y
0013ff60  00417c60 "yay"
0013ff64  00417c64 "boy"
0013ff68  00417c68 "dog"
0013ff6c  00417c6c "cat"
0013ff70  00417c70 "monkey"
0013ff74  00417c78 "weedinducedweirdo"
quit:
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文