修改已有的应用程序

来源:互联网 发布:java开发工程师规划 编辑:程序博客网 时间:2024/05/05 07:08

FindControl
函数可以通过句柄得到TwinControl类
FindVclControl
函数可以通过绝对坐标得到TWinControl类
FindVclControl内部还是调用了FindControl 函数,

使用这几个函数就可以修改别人的程序类,哈哈。
但是他们有使用的限制
1、只能是Delphi或bcb程序
2、在同一个进程中,别人的程序,不同进程怎么办呢,当然了进程注入。
3、在注入的Dll中使用系统FindControl只能返回nil,原因在FindControl内部 
 检查是否同一个进程
  if (Handle <> 0) and (GetWindowThreadProcessID(Handle, OwningProcess) <> 0) and
     (OwningProcess = GetCurrentProcessId) then
  begin    if GlobalFindAtom(PChar(ControlAtomString)) = ControlAtom then
      Result := Pointer(GetProp(Handle, MakeIntAtom(ControlAtom)))
    else
      Result := ObjectFromHWnd(Handle);
  end;

ControlAtomString的形成 , ControlAtomString := Format('ControlOfs%.8X%.8X',

[HInstance, GetCurrentThreadID]);
在注入dll中形成ControlAtomString 当然不会和要注入程序的ControlAtomString 相同了,

怎么办呢,只有重新做一个FindControl了

新的FindControl
function FindControlEx(Handle: HWnd): TWinControl;
var
  OwningProcess: DWORD;
  ControlAtomString:string;
  RM_GetObjectInstance:Cardinal;
begin
  Result := nil;
  if (Handle <> 0) and (GetWindowThreadProcessID(Handle, OwningProcess) <> 0) and
     (OwningProcess = GetCurrentProcessId) then
  begin
    ControlAtomString:=Format('ControlOfs%.8X%.8X', [GetModuleHandle(nil),

GetWindowThreadProcessID(Handle, OwningProcess)]);
    if GlobalFindAtom(PChar(ControlAtomString)) <>0 then
      Result := Pointer(GetProp(Handle, MakeIntAtom(GlobalFindAtom(PChar

(ControlAtomString)))))
    else
    begin
      RM_GetObjectInstance := RegisterWindowMessage(PChar(ControlAtomString));
      Result:=Pointer(SendMessage(Handle, RM_GetObjectInstance, 0, 0));
    end;
  end;
end;

原创粉丝点击