I learned a technique recently that we can patch the Delphi VCL source
without changing the original source code. This is great as we can
fixed bugs we faced.
I can do the followings:
1. Patch public function: I can use FastCodePatch.pas. FastCodePatch
doesn't seems to work if the functions is declared in package.
2. Patch public methods in class: I can use CodeRedirect. It works even
class is declared in package.
But how to patch the folowings:
1. Patch private function (or in package)
2. Patch private or protected methods
--
Best regards,
Chau Chee Yang
E Stream Software Sdn Bhd
URL: www.sql.com.my
SQL Financial Accounting
> 1. Patch private function (or in package)
> 2. Patch private or protected methods
- Private methods in packages are easy. They are exported and you can
use GetProcAddress to get their addresses.
- Protected functions can be patched by using a cracker class:
type
TListCracker = class(TList);
CodeRedirect(@TListCracker.Get, ...);
- Private methods and functions that aren't in a package are not that
easy to patch. You must first find a function/method that calls the
private function/method. The simpler that function/method is, the
easier you can find the relative calling address by inspecting the CPU
view.
Here is an example to get the System.GetDynaMethod function address:
function GetAddrGetDynaMethod: Pointer;
var
P: PByteArray;
begin
P := GetActualAddr(GetCallDynaInstAddr);
while P[0] <> $E9 do
begin
if (P[0] = $E8) and (P[2] = $FF) and (P[3] = $FF) and (P[4] = $FF)
then
begin
Result := Pointer(Integer(@P[5]) + PInteger(@P[1])^);
Exit;
end;
Inc(PByte(P));
end;
Result := nil;
end;
--
Regards,
Andreas Hausladen
procedure MoveNibblesToRight(var BcdVal: TBcd; BcdIn: TBcd);
This procedure is private. How to patch this function in the following
2 situations:
1. compile my app as single EXE.
2. Compile my app with runtime package. FmtBcd.pas is keep in
'dbrtl100.bpl' package.
> I found some bugs in unit FmtBcd.pas. If I want to patch this method:
The easiest way would be to patch BcdAdd() and NormalizeBcd() which are
both public and are the only functions that call MoveNibblesToRight
directly or indirectly.
--
Regards,
Andreas Hausladen
> The easiest way would be to patch BcdAdd() and NormalizeBcd() which
> are both public and are the only functions that call
> MoveNibblesToRight directly or indirectly.
In other words: You copy the code for BcdAdd and NormalizeBcd and all
thier private dependencies to the patching unit and then you fix the
bug in MoveNibblesToRight there.
--
Regards,
Andreas Hausladen