AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Win32/Win64 API (native code) Delphi Subclassing einer fremden Application, warum funzt das net ?
Thema durchsuchen
Ansicht
Themen-Optionen

Subclassing einer fremden Application, warum funzt das net ?

Ein Thema von stoxx · begonnen am 9. Nov 2003 · letzter Beitrag vom 5. Sep 2008
Antwort Antwort
Benutzerbild von stoxx
stoxx

Registriert seit: 13. Aug 2003
1.111 Beiträge
 
#1

Re: Subclassing einer fremden Application, warum funzt das n

  Alt 12. Nov 2003, 03:18
Hallo Hagen,

ich komme hier echt nicht weiter.
Mein Problem ist, dass ich noch nie irgendwas in Assembler programmiert habe.
Auch habe ich von Befehlen wie : VirtualAllocEx heute das erste mal gehört, und habe weder mit diesen Funktionen gearbeitet, noch wüsste ich sie einzusetzen.
Geschweige denn, die richtigen Parameter zu verwenden.
Ehrlich gesagt bin ich nicht davon überzeugt, dass man mit meinem Wissen aus Deinen Hinweisen einen funktionierenden Code schreiben kann.

Um noch ehrlicher zu sein, ich bekomms alleine nicht hin und bräuchte die fertige Lösung.
... also im Moment bin ich am Ende mit meinem Latein


Code:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type

  PHookData = ^THookData;
  THookData = packed record
    WindowProc: array[0..511] of Byte;
    ThreadCode: array[0..511] of Byte;

   
    SaveWindowProc: Pointer;
    hWnd: HWnd;
    GetWindowLong: function(hWnd : HWND; nIndex : INTEGER ): LongInt; stdcall;
    SetWindowLong: function(hWnd : HWND; nIndex : INTEGER; wNewLong : LongInt): LongInt; stdcall;
    ExitThread: procedure(dwExitCode : DWORD); stdcall;
    CallWndProc: function(lpPrevWndFunc : TFNWndProc; hWnd: HWND; Msg: WORD; wParam: WPARAM;  
      lParam: LPARAM): lResult; stdcall;
    VirtualFree: function(lpAddress : Pointer; dwSize : DWORD; dwFreeType : DWORD) : bool;  
      stdcall;

  end;



  TForm1 = class(TForm)
    Button1: TButton;
  private

  public

  end;



var
  Form1: TForm1;

implementation

{$R *.dfm}


function MyWndProc(hWnd: HWND; Msg: WORD; wParam: WPARAM; lParam: LPARAM): LResult; stdcall; forward;

////////////////////////////////////////////////////////////////////////////////

procedure WndProcDispatcher;
asm
     CALL @@1 
@@1: POP  EAX
     SUB  EAX,2    //  Opcode size für CALL @@1, somit EAX = Memory
     POP  EDX
     PUSH EAX
     PUSH EDX
     JMP  MyWndProc
end;

/////////////////////////////////////////////////////////////////////////////////

function MyWndProc(hWnd: HWND; Msg: WORD; wParam: WPARAM; lParam: LPARAM): lResult; stdcall;
const
  MemorySize = SizeOf(THookData );
var
  Memory: PHookData;
begin

  if Msg = wm_Destroy then
  begin
    Memory.CallWndProc(Memory.SaveWindowProc, hWnd, Msg, wParam, lParam);
    asm
      MOV EAX,Memory
       POP EDX
       PUSH EAX
       PUSH MemorySize
       PUSH 0
       PUSH EDX
       JMP [EAX].THookData.VirtualFree

    end;
  end else
    if Msg = wm_Close then
    begin
    end else
      Result := Memory.CallWndProc(Memory.SaveWindowProc, hWnd, Msg, wParam, lParam);
end;

/////////////////////////////////////////////////////////////////////////////////

function ThreadProc(Memory: PHookData): Dword; stdcall;
begin
  Memory.SaveWindowProc := Pointer ( Memory.GetWindowLong(Memory.hWnd, gwl_WndProc) );
  Memory.SetWindowLong(Memory.hWnd, gwl_WndProc, Memory.WndProcDispatcher);
  Memory.ExitThread(0);
end;

/////////////////////////////////////////////////////////////////////////////////

procedure SubClassWnd(hWnd);
var
  Memory: PHookData;
  ProcSize: Integer;
  ThreadFunc: Pointer;

begin
  ProcSize := PChar(@Subclass) - PChar(@MyWndProc);
  Memory := VirtualAllocEx(..., SizeOf(THookData), ...);
  Move(@WndProcDispatcher, Memory^, ProcSize);
  Memory.hWnd := hWnd;

   ???

end;


end.
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 15:26 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz