【问题标题】:windbg script causes memory access violationwindbg 脚本导致内存访问冲突
【发布时间】:2015-09-11 02:17:51
【问题描述】:

我正在使用以下windbg脚本在读取文件时在缓冲区中遇到某个值时中断

bp ReadFile

.while(1)
{
  g

  $$ Get parameters of ReadFile()
  r $t0 = dwo(esp+4)
  r $t1 = dwo(esp+8)
  r $t2 = dwo(esp+0x0c)

  $$ Execute until return is reached
  pt

  $$ Read magic value in the buffer
  $$ CHANGE position in buffer here
  r $t5 = dwo(@$t1+0x00)

  $$ Check if magic value matches
  $$ CHANGE constant here
  .if(@$t5 == 0x70170000)
  {
    $$db @$t1

    $$ break
    .break
  }
}

$$ Clear BP for ReadFile (assume it is the 0th one)
bc 0

我在运行此脚本时遇到以下内存访问冲突。

Memory access error at ');;  $$ Check if magic value matches;  $$ CHANGE constant here;  .if(@$t5 == 0x70170000);  {;    $$db @$t1;;    $$ break;    .break;  };'

为什么会这样?

【问题讨论】:

  • @$t5 取消引用 $t5 变量指向的内存,在您的情况下,内存地址错误/不可访问。检查应分配给该变量的地址的逻辑。你到底想用这个脚本做什么?
  • @MaximilianGerhardt 当文件读取期间的输出缓冲区以 0x70170000 开始时,我试图中断。 $t1 包含输出缓冲区的内存地址。 $t5 应该包含地址 $t1 的内存内容。
  • 假设 esp 是有效的,唯一突出的是 @$t1 不是一个有效的地址,它是报告访问错误的 dwo(@$t1+0x00)
  • @ThomasWeller 是的。这怎么可能? $t1 应该有指向输出缓冲区的指针。相反,它包含一个空指针00000000
  • k 在顶部说002c6b78 76fe9d12 KERNELBASE!ReadFile,所以脚本应该在ReadFile()。我也通过查看反汇编验证了这一点。

标签: windbg


【解决方案1】:

如果你需要在 kernel32!ReadFile 读取缓冲区内容,你需要保存缓冲区地址并使用 gu 退出函数(goup 或 step out)

当 ReadFile esp+8 中断时指向缓冲区,因此保存并退出

r $t1 = poi(@esp+8);gu

缓冲区的第一个 Dword 是 poi(@$t1) 将其与所需的 Dword 进行比较 并使用 .if .else 采取必要的措施

.if( poi(@$t1) != 636c6163 ) {gc} .else {db @$t1 l10;gc}

将所有这些放在一行中,脚本应该是

bp k*32!ReadFile "r $t1 =poi(@esp+8);gu;.if((poi(@$t1))!=636c6163){gc}.else{db @$t1 l10;gc}"

这里 636c6163 是 'clac' (calc reversed) 使用你想要的 dword 而不是这个

在 calc.exe xp sp3 32 位上运行的示例

bl
bp k*32!ReadFile "r $t1=poi(@esp+8);gu;.if((poi(@$t1))!=636c6163){gc}.else{db @$t1 l10;gc}"
.bpcmds
bp0 0x7c801812  "r $t1 = poi(@esp+8);gu;.if( (poi(@$t1))!=636c6163){gc}.else{db @$t1 l10;gc}"
0:002> g
00b865b0  63 61 6c 63 5f 77 68 61-74 69 73 5f 69 6e 74 72  calc_whatis_intr
00374df0  63 61 6c 63 00 ab ab ab-ab ab ab ab ab fe ee fe  calc............

【讨论】:

    猜你喜欢
    • 2012-05-22
    • 1970-01-01
    • 1970-01-01
    • 2010-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-22
    相关资源
    最近更新 更多