Autor Beitrag
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Di 04.09.07 02:07 
Hi,

wie ich in diesem Thread angedeutet habe, möchte ich hier ein kleines Kommandozeilen-Tool vorstellen, mit dem man komfortabel die Mapfiles von Delphi dazu nutzen kann, um Fehler in einer EXE-Datei zu finden, ohne den Debugger zu starten.

Dies ist besonders dann hilfreich, wenn man ein Programm an z.B. einen Kunden rausgegeben hat und dieser in seiner Version (die natürlich keine Debug-Symbole enthält) eine Zugriffsverletzung oder einen anderen Bug findet. Da in einem solchen Fall oftmals die Version des Kunden nicht die aktuelle Entwickler-Version sein wird, kann man (vorausgesetzt man hat die zur Release-Version zugehörige Mapfile von Delphi), die zum Zeitpunkt der Compilierung gültigen Debug-Informationen zurückgewinnen.

Das Programm unterstützt derzeit folgende Syntax:
ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
Omorphia Mapfile Address Processor v0.1
=======================================

OmMAP Version 0.1 by BenBE

Syntax:
    OmMAP file [@address] [addresslist ...]

Parameters:
    file        This parameter is either the executable or the
                mapfile you want to query addresses from.
                If you specify an executable the extension is
                automatically changed to .MAP and a standard Delphi
                application is assumed.
    @address    The module base address
                If this parameter is missing, a default address
                of 0x00400000 is assumed.
    addresslist A list of addresses you want to query
                Specification is expected in Hex. Optional prefixes
                like $ and 0x are ignored.

Preparations:
In order for this to work you'll need the following things:
  - A mapfile for the executable
    To create one open project->options->linker->mapfile and
    select the option 'detailled'.
  - (optional) Debug-Information for the system DCUs
    You can create them at project->options->compiler by
    checking the 'Debug DCU' checkbox at the right.
  - A clean built EXE (in case you just change the settings)

Notes:
  - A mapfile is valid only for the EXE version it was created of.
  - No TD32 or external debug Information are required (except the Mapfile).
  - If the binary is given, will try to autodetect base address.
  - If the Image Base Address is specified '@cs' addresses are assumed
    to be relative to the code segment.
  - Use at your own risk.

(C) Copyright 2005-2007 by Benny Baumann (BenBE)
This Software uses parts and adaptions of the Omorphia library.


Die Funktion zum automatischen Auslesen der Basis-Adresse einer EXE ist vorgesehen, derzeit aber noch nicht implementiert.

Wenn man keine Adressliste angibt, gelangt man in den interaktiven Modus, der durch eingabe einer Adresse unterhalb der Basis-Adresse beendet wird.

Aber am besten ich geb mal ein Beispiel (und damit man mal einen kleinen Einblick bekommt die Beispiel-Daten von Gausi's NEMP):
ausblenden volle Höhe Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
OmMAP.exe "nemp.map" @00400000 5AC7AE 4073B3 404853 4047EC 42E01C 40D661
Omorphia Mapfile Address Processor v0.1
=======================================

OmMAP Version 0.1 by BenBE

Parsing arguments ...
- Mapfile: Success
  Mapfile: nemp.map

- Image Base Address: Override
  BasePtr: 0x00400000

Noninteractive mode:

Querying: 0x005AC7AE
================================
Unit:           nemp
  - Start:      0x005AC0E4
  - End:        0x005AC913
File:           Nemp_ConstantsAndTypes.pas
  - Line:       927
  - Location:   0x005AC0E2
  - Offset:     0x000006CC
Symbol:         Finalization
  - Routine:    Finalization
  - Location:   0x005AC0E4
  - Offset:     0x000006CA
Canonical:      nemp(Nemp_ConstantsAndTypes.pas, line 927): Finalization+0x6CA
================================

Querying: 0x004073B3
================================
Unit:           SysInit
  - Start:      0x004072B0
  - End:        0x004073EF
Symbol:         @InitExe
  - Routine:    @InitExe
  - Location:   0x00407374
  - Offset:     0x0000003F
Canonical:      SysInit: @InitExe+0x3F
================================

Querying: 0x00404853
================================
Unit:           System
  - Start:      0x00401000
  - End:        0x004072AE
Symbol:         @StartExe
  - Routine:    @StartExe
  - Location:   0x00404814
  - Offset:     0x0000003F
Canonical:      System: @StartExe+0x3F
================================

Querying: 0x004047EC
================================
Unit:           System
  - Start:      0x00401000
  - End:        0x004072AE
Symbol:         InitUnits
  - Routine:    InitUnits
  - Location:   0x004047B4
  - Offset:     0x00000038
Canonical:      System: InitUnits+0x38
================================

Querying: 0x0042E01C
================================
Unit:           gnugettext
  - Start:      0x0042A624
  - End:        0x0042E0D3
File:           gnuGettext.pas
  - Line:       2791
  - Location:   0x0042DFFC
  - Offset:     0x00000020
Symbol:         gnugettext
  - Routine:    gnugettext
  - Location:   0x0042DEBC
  - Offset:     0x00000160
Canonical:      gnugettext(2791): gnugettext+0x160
================================

Querying: 0x0040D661
================================
Unit:           SysUtils
  - Start:      0x0040C834
  - End:        0x0041501B
File:           FastMM4.pas
  - Line:       7669
  - Location:   0x0040C49F
  - Offset:     0x000011C2
Symbol:         LowerCase
  - Routine:    LowerCase
  - Location:   0x0040D648
  - Offset:     0x00000019
Canonical:      SysUtils(FastMM4.pas, line 7669): LowerCase+0x19
================================


Kleine Anm.: Die Angabe der Unit und der Datei für die erste Adresse weichen auf Grund einer Eigenheit des Parsers ab. Korrekt wäre Datei System.pas, da die erste abgefragte Adresse vom Compiler-generierter Startup-Code ist.

Aber genug der Vorrede. Im Anhang gibt's das Teil zum Selber testen :mrgreen:

Bin für jegliche Anregungen und Verbesserungen offen.

Version History:

  • Version 0.1.0.1:
    - Inittial Release
  • Version 0.1.0.2:
    - Add. Autodetection für Image Base Address
  • Version 0.1.0.3:
    - Fix: Falsche Dateizuordnung, wenn Zeileninfo für eine Datei nicht verfügbar
    - Chg: Initialization-Routine als "Initialization" statt Unitname unter Routine eingetragen.


BenBE.
Einloggen, um Attachments anzusehen!
_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.


Zuletzt bearbeitet von BenBE am Do 06.09.07 18:19, insgesamt 1-mal bearbeitet
BenBE Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Di 04.09.07 20:53 
Es gab ein kleines Update für dieses Programm. Dieses Update implementiert die bisher fehlende Funktion für das automatische Auslesen der Image-Basis-Adresse. Den Download gibt's wie immer im ersten Post.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
BenBE Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Do 06.09.07 18:25 
Auch heute wieder ein paar kleinere Anpassungen. Die erste Änderunge betrifft den im ersten Post angesprochenen Fehler mit den Ausgaben der falschen Units. Hab jetzt ne kleine Bereichsprüfung eingebaut, jetzt verwendet er für jede Unit nur noch Symbole, die auch im Segment dieser Unit liegen. Liegt ein gefundenes Zeilensymbol außerhalb der Unit, wird es verworfen.

Die andere Änderung ist eine Kleinigkeit bzgl. der Namensgebung. Wenn man in einer Unit einen Initialization-Abschnitt hat, wird dieser in der Mapfile als Symbol vom Namen der Unit eingetragen. In der neuen Version wird als Symbolname immer noch der Name in der Mapfile verwendet, als Routine steht nun aber initialization da.

Bin wie immer auf weitere Verbesserungsvorschläge und eure Meinung gespannt.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.