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:
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):
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
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.
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.