Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi c++ zu delphi (kleines snippet) (https://www.delphipraxis.net/74381-c-zu-delphi-kleines-snippet.html)

smc 2. Aug 2006 10:22


c++ zu delphi (kleines snippet)
 
kann mir zufällig jemand dieses c++ snippet delphinizen?

Code:
VOID stilleto_Hook(PDWORD pstilletoHook, DWORD dwstilletoOffset)
{
   DWORD dwOldProtect;
   
   g_stilletoOffset = dwstilletoOffset;
   
   if(pstilletoHook && g_stilletoOffset && VirtualProtect(pstilletoHook, 4, PAGE_EXECUTE_READWRITE, &dwOldProtect))
   {
      g_pOrigstilletoFunc = *pstilletoHook + (PtrToUlong(pstilletoHook) + 4);
      *pstilletoHook = PtrToUlong(stilleto_Stub) - (PtrToUlong(pstilletoHook) + 4);
      VirtualProtect(pstilletoHook, 4, dwOldProtect, &dwOldProtect);
   }
}
danke schonmal :)

NicoDE 2. Aug 2006 10:52

Re: c++ zu delphi (kleines snippet)
 
Dort wird mit globalen Variablen hantiert (in unschöner Weise). Es wäre für die 'Übersetzung' hilfreich, wenn man mehr Informationen hätte...

ps: Ich würde solch unangenehmen Code (meine Meinung) anders schreiben - nicht nur in Delphi.

smc 23. Aug 2006 08:48

Re: c++ zu delphi (kleines snippet)
 
will eigentl. nur wissen das da genau passiert, da ich c++ nicht so gut verstehe hätte ich in delphi mehr chancen das korrekt zu lesen

hätte noch die header datei und das (steht oben drüber):

DWORD g_stilletoOffset = NULL;
DWORD g_pOrigstilletoDamageFunc = NULL;

NicoDE 23. Aug 2006 08:57

Re: c++ zu delphi (kleines snippet)
 
Zitat:

Zitat von smc
will eigentl. nur wissen das da genau passiert,

Hier mal eine 1:1 Übersetzung:
Delphi-Quellcode:
procedure stilleto_Hook(pstilletoHook: PDWORD; dwstilletoOffset: DWORD);
var
  dwOldProtect: DWORD;
begin
  g_stilletoOffset := dwstilletoOffset;

  if (pstilletoHook <> nil) and (g_stilletoOffset <> 0) and
    VirtualProtect(pstilletoHook, 4, PAGE_EXECUTE_READWRITE, dwOldProtect) then
  begin
    g_pOrigstilletoFunc := pstilletoHook^ + (ULONG(pstilletoHook) + 4);
    pstilletoHook^ := ULONG(stilleto_Stub) - (ULONG(pstilletoHook) + 4);
    VirtualProtect(pstilletoHook, 4, dwOldProtect, dwOldProtect);
  end;
end;

WoTo 23. Aug 2006 09:12

Re: c++ zu delphi (kleines snippet)
 
Hallo,

hier meine Umsetzung:

Delphi-Quellcode:
type
  pStilleToHook = ^stilletoHook;
  g_pOrigstilletoFunc = procedure of Object;


var
  g_stilletoOffset : integer;
  g_pOrigstilletoDamageFunc : integer;
  stilletoHook: integer;
  AdwstilletoOffset : integer;

procedure stilleto_Hook(ApstilletoHook: pStilleToHook; dwstilletoOffset : integer);
var
  dwOldProtect : integer;
begin
  g_StilleToOffset := dwStilleToOffset;
  if (pstilletoHook <> NIL) AND (g_stilletoOffset <> 0) AND (VirtualProtect(pstilletoHook,4,PAGE_EXECUTE_READWRITE, dwOldProtect))
  then begin
    g_pOrigstilletoFunc = pstilletoHook^ + (Ulong(pstilletoHook) + 4);
    pstilletoHook^ = Ulong(stilleto_Stub) - (Ulong(pstilletoHook) + 4);
    VirtualProtect(pstilletoHook, 4, dwOldProtect, dwOldProtect);
  end;
end;

begin
  g_stilletoOffset := 0;
  g_pOrigstilletoDamageFunc := 0;

  StilleTo_Hook(pStilleToHook, AdwstilletoOffset);
end.
Bei der If-Abfrage bin ich mir nicht sicher.

Bis denne,
Woto


Alle Zeitangaben in WEZ +1. Es ist jetzt 11:23 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz