您现在的位置:首页 >> 基础算法 >> window基础 >> 内容

通过崩溃地址找错误行数之Delphi版

时间:2011/9/3 15:31:46 点击:

  核心提示:DELPHI下生成MAP文件的方法:偶只知道下面两种,如果谁知道其他的方法敬请告知多谢 生成详细的MAP信息的方法 1.project-options-Linker-Mapfile选择detailed...
DELPHI下生成MAP文件的方法:偶只知道下面两种,如果谁知道其他的方法 敬请告知 多谢
生成详细的MAP信息的方法
1. project -> options -> Linker -> Map file 选择detailed.
2. D:\Fred\Code\DELPHI\MyPas\ErrLineByAddr2>dcc32 -GD project1.dpr

我们的代码为:
unit Unit1;

//{$D+,L+}

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  I, J: Integer;
  p: PChar;
begin
  I := 10;
  J := 0;
  //I := I div J;  // 32
  //ShowMessage(IntToStr(I));
  p := nil;
  p^ := 'A';  // 38
end;

end.
// 想必大家看到了 会有返回0地址错误....我们这里就是要让它崩溃,让我让你崩溃 ^_^
然后执行 点击 然后出错 我的机器上 崩溃地址为0044d946 

如果要查找代码行号,需要使用下面的公式做一些十六进制的减法运算:
崩溃行偏移 = 崩溃地址(Crash Address) - 基地址(ImageBase Address) - 0x1000 
减去后得到 0004c946 然后查找 0004c946 
0044d946 - 00400000 = 0004d946 - 00001000 = 0004c946 <= 后面列出的 
0004C946 就是它了 我们用ultraedit32之类的工具打开 .map文件 搜索 0004C94,找到了,然后就找
<= 0004c946的那个地址 然后看到了
Line numbers for Unit1(Unit1.pas) segment .text

    37 0001:0004C944    38 0001:0004C946    39 0001:0004C949    41 0001:0004C97C
    41 0001:0004C983

38 0001:0004C946    就是它了。。。unit1.pas的第38行!!去代码里看一下 果然就是38行 

作者:网络 来源:转载
共有评论 0相关评论
发表我的评论
  • 大名:
  • 内容:
  • 盒子文章(www.2ccc.com) © 2024 版权所有 All Rights Reserved.
  • 沪ICP备05001939号