Advanced Debugging
About AdvDbg Consult Train Services Products Tools Community Contact  
欢迎光临 高端调试 登录 | 注册 | FAQ
 
  ACPI调试
Linux内核调试
Windows内核调试
 
  调试战役
调试原理
新工具观察
 
  Linux
Windows Vista
Windows
 
  Linux驱动
WDF
WDM
 
  PCI Express
PCI/PCI-X
USB
无线通信协议
 
  64位CPU
ARM
IA-32
  CPU Info Center
 
  ACPI标准
系统认证
Desktop
服务器
 
  Embedded Linux
嵌入式开发工具
VxWorks
WinCE
嵌入式Windows
 
  格蠹调试套件(GDK)
  格蠹学院
  小朱书店
  老雷的微博
  《软件调试》
  《格蠹汇编》
  《软件调试(第二版)》
沪ICP备11027180号-1

.Net程序调试

帖子发起人: 手语   发起时间: 2008-12-17 13:26 下午   回复: 7

Print Search
帖子排序:    
   2008-12-17, 13:26 下午
neilhsu 离线,最后访问时间: 2009/12/23 17:02:23 手语

发帖数前10位
男
注册: 2008-06-06
发 贴: 73
请教一个.Net程序中PInvoke的问题
Reply Quote

今天帮同事调试一个.Net程序,结果发现一个很奇怪的问题:

同事的.Net程序通过PInvoke调用一个native exe模块(A.exe)中的函数B()。(类似于调用Dll中的函数,我不懂.Net,不知道这么描述对吗)

运行的时候发生AV。

跟踪发现B()又调用了另一个native dll模块(C.dll)中的输出函数D()。

AV发生的过程是B()通过IAT调用D(),但是IAT中D()的地址明显有问题。

通过观察IAT中附近的其他地址,我感觉这个A.exe的IAT在被load到.Net进程的地址空间的时候没有被重定位。

所以A.exe的IAT中的地址都是有问题的。

现在的问题是,这种情况有可能发生吗?是Loader的问题还是正常情况?

有什么好地解决办法?

往各路大侠指点。多谢。


鸿鹄安知燕雀之志
IP 地址: 已记录   报告
   2008-12-18, 19:43 下午
Raymond 离线,最后访问时间: 2020/7/3 3:40:25 格蠹老雷

发帖数前10位
注册: 2005-12-19
发 贴: 1,303
Re: 请教一个.Net程序中PInvoke的问题
Reply Quote

根据描述,涉及两个进程是吧?无论是哪个进程发生AV,都可以使用JIT调试方法在发生AV后以JIT方式附加调试器。如果是本地程序发生AV,那么WinDBG.exe -I将WinDBG设置为JIT调试器。如果是.Net程序发生AV,那么需要产生一个netapp.exe.config文件放在同一目录中,并保有如下内容:

<configuration>
    <system.windows.forms jitDebugging="true" />
</configuration>

如果确实需要调试.Net进程,那么使用WinDBG+SOS扩展模块可以很好的按照需要做本地调试和观察.Net的世界。

 

 


IP 地址: 已记录   报告
   2008-12-18, 20:16 下午
neilhsu 离线,最后访问时间: 2009/12/23 17:02:23 手语

发帖数前10位
男
注册: 2008-06-06
发 贴: 73
Re: 请教一个.Net程序中PInvoke的问题
Reply Quote
老雷
终于等到回复了^_^

只有一个进程,就是那个.Net程序
它把native exe (A.exe)当作dll load起来
然后调用了A.exe的输出函数B()。
我不理解的是,为什么A.exe被load到进程空间之后,没有进行重定位。
A的IAT表里全是初始值,并没有被重定位到进程中相应模块的输出函数去。
按理说,exe或者dll应该没什么区别。
当然普通exe应该不输出函数,B()是程序员特意输出的。
鸿鹄安知燕雀之志
IP 地址: 已记录   报告
   2008-12-18, 20:17 下午
neilhsu 离线,最后访问时间: 2009/12/23 17:02:23 手语

发帖数前10位
男
注册: 2008-06-06
发 贴: 73
Re: 请教一个.Net程序中PInvoke的问题
Reply Quote
我不太了解.Net的程序
那个写.Net的同事跟我说,他也是用LoadLibrary的方式把A.exe load到进程空间的。
鸿鹄安知燕雀之志
IP 地址: 已记录   报告
   2008-12-18, 23:34 下午
Raymond 离线,最后访问时间: 2020/7/3 3:40:25 格蠹老雷

发帖数前10位
注册: 2005-12-19
发 贴: 1,303
Re: 请教一个.Net程序中PInvoke的问题
Reply Quote
既然是使用LoadLibrary来加载,那么就可能根本与.Net没有关系了,即使有关系,也可以使用WinDBG将其当作本地程序来调试。记得我跟踪过更新IAT的过程,在有符号的情况下,比较好理解,所以还是建议使用调试器来找根源。或者先写个本地的小程序来Load这个特殊的EXE看有没有问题。
IP 地址: 已记录   报告
   2008-12-19, 13:44 下午
neilhsu 离线,最后访问时间: 2009/12/23 17:02:23 手语

发帖数前10位
男
注册: 2008-06-06
发 贴: 73
Re: 请教一个.Net程序中PInvoke的问题
Reply Quote
嗯,我有空就去跟一下,今天活有点忙。

刚才刚收到代码
他是这么调的
这种调用走LoadLibrary()吗?
我如果在托管进程里下LoadLibrary()的断点能拦下来吗?

[DllImport("A.exe", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl, SetLastError=true)]
private static extern UInt16 B(string msgText);

public static UInt16 ShowHelp(string msgText)
{
UInt16 result = B(msgText);
return result;
}
鸿鹄安知燕雀之志
IP 地址: 已记录   报告
   2008-12-19, 15:09 下午
neilhsu 离线,最后访问时间: 2009/12/23 17:02:23 手语

发帖数前10位
男
注册: 2008-06-06
发 贴: 73
Re: 请教一个.Net程序中PInvoke的问题
Reply Quote

依稀记得VC编译的EXE默认是不带重定位表的

这个应该就是原因吧

刚才做了个实验,跟.Net无关。

两个exe都是native的也一样。

等我想明白了再更新


鸿鹄安知燕雀之志
IP 地址: 已记录   报告
   2011-04-14, 15:04 下午
victor12 离线,最后访问时间: 2010/10/10 7:10:17 victor12

发帖数前200位
注册: 2010-10-11
发 贴: 5
Re: 请教一个.Net程序中PInvoke的问题
Reply Quote

Golf Brilliant - Tiger Dupe 12 Review

 

Well it looks like even the Tiger can get out of the Woods. Every year Tiger Dupe Golf set the ambition for all over amateur in this genre. Like the John Madden amateur set the ambition for NFL Amateur Tiger Dupe has consistently set the golf clubs for sale

ambition for golf games. Admitting contempo ..should we say troubles, the Tiger has kept his top contour job with EA Sports. Afterwards all Lee Westwood golf would be boring, lets be honest!.This years Tiger Dupe golf, Tiger Dupe 12 brings you that little bit added as you can now play the Augusta masters!. The angelic beaker has assuredly TaylorMade R11 Driver

been brought to Tiger Dupe Golf. It seems that the Augusta Master accept been adored until the cartoon engine can accord this august beforehand the amends it deserves.The aboriginal affair you will apprehension about Tiger Dupe 12 is the absorption to detail as the 3D GRASS acts added like grass and the beheld presentation and annotation gives the bold that added bit of accuracy and adds to the drama.


IP 地址: 已记录   报告
高端调试 » 软件调试 » .Net程序调试 » 请教一个.Net程序中PInvoke的问题

 
Legal Notice Privacy Statement Corporate Governance Corporate Governance
(C)2004-2020 ADVDBG.ORG All Rights Reserved.