Einzelnen Beitrag anzeigen

Olli
(Gast)

n/a Beiträge
 
#8

Re: DLL Injection & Zugreifen auf Edit

  Alt 7. Sep 2006, 12:22
Das kommt drauf an. Wenn es eine Subklasse ("Derivat") von EDIT ist, kannst du es auf gleichem Wege auslesen. Ist ja nicht so, daß WM_GETTEXT (und die entsprechende Funktion) nicht auch für andere Fensterklassen als EDIT funktionieren würde. Die Fensterklasse muß halt nur diese Nachricht unterstützen ...

Nachdem im Sommer 2002 EDA mit Source in der c't war, schossen irgendwie gleichartige Delphitools wie Pilze aus dem Boden ...
http://assarbad.info/stuff/eda_previ...2003-10-12.rar (neueste und bisher letzte aktualisierte Version)


Nachtrag: Aussehen ist nicht immer relevant. Beispielsweise sehen viele der Widgets in Firefox so aus, wie man sie von Windows gewohnt ist, dennoch haben die eine ganz andere Methode zum Zeichnen und die EDITs sind z.B. keine. Wenn das Fenster aber schon direkt ein eigenes Handle hat und du anhand der Umrandung feststellen kannst, daß nur dieses vermeintliche Memo mit dem Klassennamen gemeint ist, hast du gute Chancen. Versuche es also.

Folgende beide Funktionen sind aus EDA 2.7
Delphi-Quellcode:
function GetTextFromWndW(hwnd: HWND): WideString;
(*
  Functionality:
    This function gets the text associated with the given window.
    [GENERIC]
*)

var
  l: integer;
  pwc: PWideChar;
begin
// Get length of text ... could cause buffer overflow if not error checked!!!
  l := SendMessageW(hwnd, WM_GETTEXTLENGTH, 0, 0);
  if l > 0 then
  begin
// Allocate memory
    l := l + 2;
    pwc := GetMemory(l * sizeof(pwc^));
    if Assigned(pwc) then
    try
// Fill allocated memory with zeroes
      ZeroMemory(pwc, l * sizeof(pwc^));
// Get text (max len = l-1 characters)
      SendMessageW(hwnd, WM_GETTEXT, l - 1, Integer(pwc));
{
  For the problems concerning InternalGetWindowText(), see its declaration!

      InternalGetWindowText(hwnd, pwc, l);

  GetWindowText(hwnd, pwc, l) also does not work, because it can only retrieve
  the text of your own application. Not that of another process!
}

// Set return value
      SetString(result, pwc, lstrlenW(pwc));
    finally
// Free allocated memory
      FreeMemory(pwc);
    end;
  end;
end;

function GetTextFromWndA(hwnd: HWND): AnsiString;
(*
  Functionality:
    This function gets the text associated with the given window.
    [GENERIC]
*)

var
  l: integer;
  pc: PAnsiChar;
begin
// Get length of text ... could cause buffer overflow if not error checked!!!
  l := SendMessageA(hwnd, WM_GETTEXTLENGTH, 0, 0);
  if l > 0 then
  begin
// Allocate memory
    l := l + 2;
    pc := GetMemory(l);
    if Assigned(pc) then
    try
// Fill allocated memory with zeroes
      ZeroMemory(pc, l);
// Get text (max len = l)
      SendMessageA(hwnd, WM_GETTEXT, l - 1, Integer(pc));
// Set return value
      SetString(result, pc, lstrlenA(pc));
    finally
// Free allocated memory
      FreeMemory(pc);
    end;
  end;
end;
Desweiteren gibt es etwas zu beachten bei Windows 9x/Me wenn man den Klassennamen ermitteln will:
Delphi-Quellcode:
function GetClassNameFromWndW(hwnd: HWND): WideString;
(*
  Functionality:
    This function fills a string with the classname of the window given as the
    parameter.
    [GENERIC]
*)

var
  pwc: PWideChar;
const
  maxbufsize = 32767 * sizeof(WideChar);
  //Win9x does not like buffer size above 32k-1 - I also reported this to MS
  //after 8 month I got no feedback yet ... I guess this is MS's policy 2002-10-31
begin
// Default return value
  result := emptystring;
// Allocate memory
  pwc := GetMemory(maxbufsize);
// If successful ...
  if Assigned(pwc) then
  try
// Fill with zeroes
    ZeroMemory(pwc, maxbufsize);
// If Window still exists ...
    if IsWindow(hwnd) then
// Get its class name and write it into PC
      if GetClassnameW(hwnd, pwc, maxbufsize) > 0 then
// Copy PC as return value
        SetString(Result, pwc, lstrlenW(pwc));
  finally
// Free allocated memory
    FreeMemory(pwc);
  end;
end;

function GetClassNameFromWndA(hwnd: HWND): AnsiString;
(*
  Functionality:
    This function fills a string with the classname of the window given as the
    parameter.
    [GENERIC]
*)

var
  pc: PAnsiChar;
const
  maxbufsize = 32767;
//Win9x does not like buffer size above 32k-1 - I also reported this to MS
//after 8 month I got no feedback yet ... I guess this is MS's policy 2002-10-31
begin
// Default return value
  result := emptystring;
// Allocate memory
  pc := GetMemory(maxbufsize);
// If successful ...
  if Assigned(pc) then
  try
// Fill with zeroes
    ZeroMemory(pc, maxbufsize);
// If Window still exists ...
    if IsWindow(hwnd) then
// Get its class name and write it into PC
      if GetClassname(hwnd, pc, maxbufsize) > 0 then
// Copy PC as return value
        SetString(Result, pc, lstrlen(pc));
  finally
// Free allocated memory
    FreeMemory(pc);
  end;
end;
  Mit Zitat antworten Zitat