お知らせ

電子会議

ライブラリ

パレット

Delphi FAQ検索

Delphi FAQ一覧

サンプル蔵





FDelphi FAQ
16番会議室「玉石混淆みんなで作るSample蔵」に寄せられたサンプル

"Mapファイルの整形"

この発言に対し以下のコメントが寄せられています
#01411 tach さん RE:Mapファイルの整形

こんにちは、 tachです。 .mapファイルを読み込んで、実行時のメソッドのエントリー アドレス(と思われる)を別ファイルに出力するサンプル。 m(8)#13637で、手作業が面倒なので作りました。 Nagaoさんに感謝。 バグ、制限 マップファイルは[詳細表示]で作成すること。 D4以外ではマップファイルの出力形式が違うかもしれないので、 修正が必要かもしれません。 ----------- Memo - 1, Panel上に Label & Edit - それぞれ2, button - 3を配置します。 ------ここからソース------ unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; type TForm1 = class(TForm) Panel1: TPanel; Button1: TButton; Button2: TButton; Button3: TButton; Memo1: TMemo; OpenDialog1: TOpenDialog; SaveDialog1: TSaveDialog; Edit1: TEdit; Edit2: TEdit; Label1: TLabel; Label2: TLabel; procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Edit1Change(Sender: TObject); private { Private 宣言 } FWorkList: TStringList; FResultList: TStringList; public { Public 宣言 } end; var Form1: TForm1; implementation {$R *.DFM} var ImageBaseValue: Cardinal = $400000; CodeBaseValue: Cardinal = $1000; StartLineString: String = ' Address Publics by Name'; procedure TForm1.FormCreate(Sender: TObject); begin FWorkList := TStringList.Create; FResultList := TStringList.Create; FResultList.Sorted := True; Label1.Caption := 'ImageBase in Hex'; Label2.Caption := 'CodeBase in Hex'; Edit1.Text := IntToHex(ImageBaseValue, 6); Edit2.Text := IntToHex(CodeBaseValue, 6); OpenDialog1.Filter := 'Map File(*.map)|*.map'; SaveDialog1.Filter := 'Text File(*.txt)|*.txt'; SaveDialog1.Options := [ofOverwritePrompt, ofHideReadOnly, ofCreatePrompt]; end; procedure TForm1.FormDestroy(Sender: TObject); begin if Assigned(FWorkList) then FWorkList.Free; if Assigned(FResultList) then FResultList.Free; end; function ConvertAddr(Value: String; BaseValue: Cardinal): String; var ib, ie: Integer; S: String; begin Result := ''; if Value = '' then Exit; ib := LastDelimiter(':', Value); if ib < 1 then Exit; inc(ib); // ' 0001:0040abcd Txxxx.hogehoge' << Value; // ib points '0' next to ':'; ie := ib; while not (Value[ie] in [#0, ' ']) do Inc(ie); // ie points ' ' in next to 'd'; if ie >= Length(Value) then Exit; S := Copy(Value, ib, ie - ib); // S := '0040abcd' while Value[ie] = ' ' do Inc(ie); // ie points 'Txxxx' Result := Format('%8.8x: %s', [Cardinal(StrToInt('$' + S)) + BaseValue, Copy(Value, ie, Length(Value))]); end; procedure TrimList(Dest, List: TStringList; const StartLine: String); const SC1: String = ' 000'; SC2: String = ' 0001:'; var i, Count: integer; S: String; BaseValue: Cardinal; begin if not Assigned(List) or (not Assigned(Dest)) then raise Exception.Create('List is Nil.'); i := 0; Count := List.Count - 1; Dest.Clear; while (i < Count) and (CompareText(List.Strings[i], StartLine) <> 0) do Inc(i); Inc(i, 2); // one for StartLine, the other for EmptyLine. BaseValue := ImageBaseValue + CodeBaseValue; while (i < Count)do begin S := List.Strings[i]; if StrLComp(PChar(S), PChar(SC1), Length(SC1)) <> 0 then Exit; if StrLComp(PChar(S), PChar(SC2), Length(SC2)) = 0 then Dest.Add(ConvertAddr(S, BaseValue)); inc(i); end; end; procedure TForm1.Button1Click(Sender: TObject); begin with OpenDialog1 do begin if Execute then FWorkList.LoadFromFile(FileName); end; end; procedure TForm1.Button2Click(Sender: TObject); begin TrimList(FResultList, FWorkList, StartLineString); Memo1.Lines.Assign(FResultList); end; procedure TForm1.Button3Click(Sender: TObject); begin if (FWorkList.Count > 0) and (CompareText(Memo1.Lines.Text, FResultList.Text) = 0) then with SaveDialog1 do begin FileName := ChangeFileExt(OpenDialog1.FileName, '.txt'); if Execute then Memo1.Lines.SaveToFile(FileName); end; end; procedure TForm1.Edit1Change(Sender: TObject); var tmp, tmp1: Cardinal; Edit: TEdit; S: String; begin if (Sender = nil) or not(Sender is TEdit) then Exit; Edit := Sender as TEdit; if Edit = Edit1 then tmp1 := ImageBaseValue else tmp1 := CodeBaseValue; if (Edit.Text = '') or not (Edit.Text[1] = '$') then S := '$' else S := ''; try if Edit = Edit1 then begin tmp := StrToInt(S + Edit.Text); ImageBaseValue := tmp; end else begin tmp := StrToInt(S + Edit.Text); CodeBaseValue := tmp; end; except on E: EConvertError do begin Edit.OnChange := nil; Edit.Text := IntToHex(tmp1, 1); Edit.OnChange := Edit1Change; Application.ShowException(E); end; else raise; end; end; end. ------ End -----  Original document by tach 氏 ID:(YIU01245)



ここにあるドキュメントは NIFTY SERVEの Delphi Users' Forum の16番会議室「玉石混淆みんなで作るSample蔵」に投稿されたサンプルです。これらのサンプルはボーランド株式会社がサポートする公式のものではありません。また、必ずしも動作が検証されているものではありません。これらのサンプルを使用したことに起因するいかなる損害も投稿者、およびフォーラムスタッフはその責めを負いません。使用者のリスクの範疇でご使用下さい。

Copyright 1996-2002 Delphi Users' Forum