https://github.com/MahdiSafsaf i/DebugEngine
"Случайно вот наткнулся - библиотечка у чувака со всякими низкоуровневыми штуками на дельфях (x32 + x64), может быть тебе что-нибудь оттуда где-нибудь пригодится.'
Посмотрел. Там есть что почерпнуть.
Цитата оттуда:
"Случайно вот наткнулся - библиотечка у чувака со всякими низкоуровневыми штуками на дельфях (x32 + x64), может быть тебе что-нибудь оттуда где-нибудь пригодится.'
Посмотрел. Там есть что почерпнуть.
Цитата оттуда:
DebugEngine
What is DebugEngine ?
DebugEngine is a collection of utils related to debug stuff (stack trace, CPU registers snaphot, debug info,...). Basically, I started to write a commercial error log plugin for Delphi, then I noticed that my internal framework got bigger and bigger. So I decided to share it with the community in hope it will be useful.
Features:
DebugEngine has a lot of functions and utilities allowing to you to do for example:
- Support x86 and x64 architecture.
- Accessing Delphi debug info.
- Getting address of symbol from its name.
- Delphi map parsing and map converter to binary format.
- Remove and restore Delphi debug info from PE file.
- Smart stack trace.
- Try blocks trace.
- Updatting resource of Delphi app even if it was linked with debug info.
- Inserting custom debug info into PE file.
- CPU registers snapshot.
- Accessing vector registers.
- Disasm and comment function with Debug info.
- Enumerating exception handlers.
- Delphi exception stack trace hook.
- Delphi string detection.
- PE utils.
- Disasm utils.
- ...
Getting started:
Please refer to the Wiki page and see Demo included with the library. Note that all public functions are documented (XML doc). However if you don't understand something, please feel free to contact me.
И:
И:
Getting address of symbol:
Use
GetSymbolAddress
function to get address of symbol.function GetSymbolAddress(ModuleHandle: THandle; const UnitName, SymbolName: string): Pointer;
- ModuleHandle = Module handle where the symbol is located. If you pass zero (0), the function will use the current module handle.
- UnitName = Optional, unit name where the symbol was declared. This is useful when many units declare the same symbol.
- SymbolName = symbol name.
- Return value = If the function succeeds, the return value is the address of the symbol. Otherwise it returns nil.
Example:
var
P: Pointer;
begin
{ Private variable System.MemoryManager }
P := GetSymbolAddress(0, 'System', 'MemoryManager');
{ Private method System.SetExceptionHandler }
P := GetSymbolAddress(0, '', 'SetExceptionHandler');
{ Protected method TCustomForm.CloseModal }
P := GetSymbolAddress(0, '', 'TCustomForm.CloseModal');
{ Windows api }
P := GetSymbolAddress(GetModuleHandle(user32), '', 'MessageBoxA');
end;
Using DebugEngine stack trace when error occurs:
All what you need to do is to include
DebugEngine.HookException
unit into your project. And each time an error occurs, you will be able to get the stack trace from the point where the error occurred.uses
DebugEngine.HookException;
{...}
procedure Foo;
begin
try
DoSomething;
except
on E: Exception do
ShowMessage(E.StackTrace);
end;
end;
Disasm and comment function:
If you plan to use this feature, you need first to update UnivDisasm.Config.inc file and tell UnivDisasm that you need display feature (
Define NEED_DISPLAY
). By default, I turned this option off just for optimization. So if you are going to use Disasm and comment feature, you should enable it again.function DisasmAndCommentFunction(FunctionStartAddress: Pointer; var FunctionEndAddress: Pointer; CallBackFunction: TDisasmCallBack; UserData: Pointer)
: Boolean;
- FunctionStartAddress = Function address that you want to disasm.
- FunctionEndAddress = End address where the disasm will stop. If not specified, UnivDisasm will break on the first
ret
instruction. - CallBackFunction = A pointer to
TDisasmCallBack
function. This function will be called byDisasmAndCommentFunction
each time it decodes an instruction. - UserData = Optional data to pass to CallBackFunction function.
Example:
procedure DisasmCallBack(var Info: TDisasmInfo; UserData: Pointer);
var
S: String;
begin
with TMemo(UserData).Lines, Info do
begin
S := Format('[$%p]: %s', [Address, InstStr]);
if not comment.IsEmpty then
S := S + ' ; ' + comment;
Add(S);
end;
end;
var
P: Pointer;
begin
P := nil;
{LogMem = TMemo}
LogMem.Clear;
LogMem.Lines.BeginUpdate;
try
DisasmAndCommentFunction(@TMain.BtnLegRegSnapClick, P, DisasmCallBack, LogMem);
finally
LogMem.Lines.EndUpdate;
end;
Комментариев нет:
Отправить комментарий