使用windbg搜索整个代码,查找特定的调用指令

5

是否有可能搜索整个可执行内存空间,以查找调用特定方法的所有位置?例如,我想找到从哪些函数中调用了MyApplcation!MyFunction。使用“s”命令搜索特定optcode不是一个选项,因为在我的情况下,call命令使用相对代码路径,所以optcode取决于call指令本身所在的位置。


可能是Windbg命令的每个结果作为脚本参数的重复问题。 - conio
2个回答

11

0:000> lm m calc

Browse full module list
start    end        module name
005f0000 006b0000   calc       (pdb symbols)          e:\symbols\calc.pdb
\971D2945E998438C847643A9DB39C88E2\calc.pdb

0:000> $$ 让我们搜索在 calc 内存空间内调用 operator new 函数的所有调用者

0:000> # op*new 5f0000 l?(6b0000-5f0000)

输出

calc!WinMain+0x213:
005f17e7 e89a0a0000      call    calc!operator new (005f2286)
calc!WinMain+0x272:
005f1843 e83e0a0000      call    calc!operator new (005f2286)
calc!operator new+0x26:
005f229d 0f84fcb80200    je      calc!operator new+0x11 (0061db9f)
calc!operator new[]+0x26:
005f32b1 0f8438a90200    je      calc!operator new[]+0x11 (0061dbef)
calc!CCalculatorState::storeAndFire+0x7:
005f33c9 e83becffff      call    calc!operator new (005f2009)
calc!CCalculatorState::storeAndFire+0x76:
005f3437 e84aeeffff      call    calc!operator new (005f2286)
calc!CCalculatorState::storeAndFire+0x8a:
005f3447 e83aeeffff      call    calc!operator new (005f2286)
calc!CUIController::UpdateTwoLineDisplay+0x56:
005f35c7 e8cefcffff      call    calc!operator new[] (005f329a)
calc!ATL::CAutoVectorPtr<ATL::CAtlREMatchContext<ATL::CAtlRECharTraitsW>::MatchGroup>::Allocate+0x7:
005f3a8c e81ae8ffff      call    calc!operator new+0x30 (005f22ab)
calc!ATL::CAutoVectorPtr<ATL::CAtlREMatchContext<ATL::CAtlRECharTraitsW>::MatchGroup>::Allocate+0x27:
005f3aac e8e9f7ffff      call    calc!operator new[] (005f329a)
calc!ATL::CAtlREMatchContext<ATL::CAtlRECharTraitsW>::CAtlREMatchContext<ATL::CAtlRECharTraitsW>+0x7:
005f3b52 e8b2e4ffff      call    calc!operator new (005f2009)
calc!ATL::CAutoVectorPtr<void *>::Allocate+0x7:

@conio,我撤销了你的编辑,因为在Windbg中,$是内联注释的运算符。$ rollback $ whatever foo $ omg将在Windbg命令窗口中内联插入该注释,请查看Windbg文档,用#代替0:000> $ xxxxxxxxxxxxx不正确。请修改。 - blabb
抱歉。它不是单个空格块的一部分,所以我猜它是一个打字错误。(如果你真的想在WinDbg提示符中添加注释,我认为你需要两个美元符号。请查看Windbg文档。) - conio
只是一个小的补充:即使文档中说要使用“L Size”语法来执行“#”命令,它也可以接受WinDbg的常规范围语法。因此,不必在那里进行“结束地址-开始地址”的数学计算,而是可以省略“L”,并将结束地址放在“# op*new 5f0000 6b0000”中(已在版本10.0.19041.685中测试)。 - OzgurH
这个问题是关于特定调用MyApplcation!MyFunction的,但是你的回答似乎提供了在整个dll中查找new操作符所有用法的解决方案,不是吗? - BornToCode

2
与上面的答案类似,只是详细说明如何找到文本段开始位置和大小。
!dh -f abc.exe
0000000140000000 image base

!dh -s abc.exe
SECTION HEADER #1
   .text name
  124D6A virtual size
    1000 virtual address
  124E00 size of raw data
     400 file pointer to raw data

Add RVA of .text 1000 to image base 140000000 and dissemble the entire text segment
u 140001000 L124D6A

Or
Use # command to find the function in the disassembly
# GetSimpleProtocol 140001000 L124D6A

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接