续hook获取实例TDBGrid的问题

gdhuman 2008-07-19 03:10:34
源帖
http://topic.csdn.net/u/20080716/11/865f670a-eb9b-4b3f-848c-3219cd777672.html
根据你发给我的参考,下载了DEMO看了一下,都是DELPHI的代码,确实不好看
例如下面2个函数

function FindControl(Handle: HWnd): TWinControl;
var
OwningProcess: DWORD;
begin
Result := nil;
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 := Pointer(SendMessage(Handle, RM_GetObjectInstance, 0, 0));
end;
end;

我的翻译是这样
TWinControl  FindControl1(HWND Handle)
{
DWORD OwningProcess;
TWinControl Result;
Result = NULL;
if ((Handle != 0) && (GetWindowThreadProcessId(Handle, &OwningProcess)!= 0)&&
(&OwningProcess = GetCurrentProcessId))
{

if (GlobalFindAtom(PChar(ControlAtomString)) = ControlAtom)
Result = Pointer(GetProp(Handle, MakeIntAtom(ControlAtom)));
else
Result = Pointer(SendMessage(Handle, RM_GetObjectInstance, 0, 0));
return Result;
}

错误好多
还有另一个函数
procedure InstallHook(MainWnd, DestWnd: HWND); stdcall;
begin
if P^.hkMsg = 0 then
P^.hkMsg := SetWindowsHookEx(WH_GETMESSAGE, @GetMsgProc, HInstance, 0);
P^.HostWnd := MainWnd;
P^.HostPID := GetCurrentProcessId;
P^.DestWnd := DestWnd;
end;


void __stdcall InstallHook(HWND MainWnd, HWND DestWnd)
{
if (P^.hkMsg = 0)
{
P^.hkMsg = SetWindowsHookEx(WH_GETMESSAGE, @GetMsgProc, HInstance, 0);
P^.HostWnd = MainWnd;
P^.HostPID = GetCurrentProcessId;
P^.DestWnd = DestWnd;
}

}

错误太多了,请妖哥帮忙
...全文
436 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
ccrun.com 2008-07-23
  • 打赏
  • 举报
回复
Form中容器的多少和FindControl没有什么影响。
你说的"增加个TREEVIEW界面",是想看看子容器树吧?Spy4Win目前的版本就可以看到的,选中Form后,在窗口-->列举子窗口就可以看到了。
gdhuman 2008-07-22
  • 打赏
  • 举报
回复
因为有些FORM下面有多个容器,一时间不好找
gdhuman 2008-07-22
  • 打赏
  • 举报
回复
我用过您的SPY4 我建议您在下一个版本增加个TREEVIEW界面,对FORM以下的窗体和控件有明显的"属于"的分类
您说的强制转换是不是
StringGird1=(StringGrid*)FindControl(句柄)
ccrun.com 2008-07-22
  • 打赏
  • 举报
回复
也未必啊。你可以将DBGrid强制转换成StringGrid来获取Cells的内容。(当然,这一切还是在远程执行)
gdhuman 2008-07-22
  • 打赏
  • 举报
回复
那是不是就没希望了
ccrun.com 2008-07-22
  • 打赏
  • 举报
回复
有可能是在数据集中设置了某个字段的OnGetText事件,进行了解密。
gdhuman 2008-07-22
  • 打赏
  • 举报
回复
我还是下载了DELPHI7.0改好了代码,
有些窗口测试成功,能返回所有字段的值,但有例外窗口的dbgrid接收不到某个列的值,只是某个列,其他列正常,观察该数据库,刚好这个字段是加密的字段,是不是因为这个dbgrid响应某个函数而程序得不到该列的值,值是空,但该程序窗口的这个字段不是空的,这会是什么样一种情况

问完结贴,再次谢谢妖哥
ccrun.com 2008-07-21
  • 打赏
  • 举报
回复
Delphi的Dll中initialization段和finalization段在C++中可以在DllEntryPoint函数中处理:

int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
switch(reason)
{
case DLL_PROCESS_ATTACH:
{
ControlAtomString = String().sprintf("ControlOfs%.8X%.8X", GetModuleHandle(NULL), GetCurrentThreadID());
ControlAtom = GlobalAddAtom(ControlAtomString.c_str());
RM_GetObjectInstance = RegisterWindowMessage(ControlAtomString.c_str());

break;
}
case DLL_PROCESS_DETACH:
{
GlobalDeleteAtom(ControlAtom);
ControlAtomString = "";

break;
}
default:
break;
}
return 1;
}
gdhuman 2008-07-21
  • 打赏
  • 举报
回复
原来还差这几句
我翻译过来总是出错,是放在DLL里面的数据初始化
initialization
ControlAtomString := Format('ControlOfs%.8X%.8X', [GetModuleHandle(nil), GetCurrentThreadID]);
ControlAtom := GlobalAddAtom(PChar(ControlAtomString));
RM_GetObjectInstance := RegisterWindowMessage(PChar(ControlAtomString));
finalization
GlobalDeleteAtom(ControlAtom);
ControlAtomString := '';
end.


麻烦妖哥下
gdhuman 2008-07-20
  • 打赏
  • 举报
回复
MyFindControl是定义在DLL里面的全局变量,要以何中方式查看其变量
String  ControlAtomString;
ATOM ControlAtom ;
DWORD RM_GETOBJECTINSTANCE;
extern "C" __declspec(dllexport) TWinControl* __stdcall MyFindControl(HANDLE hWnd);
int WINAPI DllEntryPoint(HINSTANCE hinst, unsigned long reason, void* lpReserved)
{
return 1;
}
//---------------------------------------------------------------------------
TWinControl* __stdcall MyFindControl(HANDLE hWnd)
{
DWORD dwOwningProcess;
if(hWnd != NULL && GetWindowThreadProcessId(hWnd, &dwOwningProcess) != 0
&& dwOwningProcess == GetCurrentProcessId())
{
if(GlobalFindAtom(ControlAtomString.c_str()) == ControlAtom)
return (TWinControl *)GetProp(hWnd, MAKEINTATOM(ControlAtom));
else
return (TWinControl *)SendMessage(hWnd, RM_GETOBJECTINSTANCE, 0, 0);
}
return NULL;
}


我在FORM上面放置了一个DBGrid 是不是如果方法正确,DBGrid就会显示另一个程序DBGRID的信息呢,谢谢你
ccrun.com 2008-07-20
  • 打赏
  • 举报
回复
单步看看,每一条语句执行完以后看看结果,再分析可能出错的原因。DestWnd的值如果正确,继续看MyFindControl是否返回正确的值。
gdhuman 2008-07-20
  • 打赏
  • 举报
回复
你的小工具我用过,而且一直保存在电脑里哈哈,句柄是正确的,请 妖哥指教,
ccrun.com 2008-07-20
  • 打赏
  • 举报
回复
判断句柄是否正确可以用另外的Spy类工具来探测一下。比如偶的小工具:Spy4Win,呵呵,广告一下。
gdhuman 2008-07-20
  • 打赏
  • 举报
回复
是的,不过我的这几行代码好象没有注入,DBGridEx和TFrmCenterQry是我用PE找到的,句柄应该是正确的,怎么才能判断句柄是否正确 谢谢妖哥
ccrun.com 2008-07-20
  • 打赏
  • 举报
回复
DestWnd在FindWindowEx以后是否取到正确的句柄?
gdhuman 2008-07-20
  • 打赏
  • 举报
回复
HWND DestMain,DestWnd;
DestMain = FindWindow("TFrmCenterQry", "");

DestWnd = FindWindowEx(DestMain, 0, "TDBGridEx", NULL);

if(DestMain==NULL)ShowMessage("没有找到");
DBGrid1=(TDBGrid*)MyFindControl(DestMain);
妖哥,这样差了什么步骤
ccrun.com 2008-07-19
  • 打赏
  • 举报
回复
原理是一样的,只要成功注入,可以访问目标进程中任意的VCL对象。
我认为BCB挺好的,VC和资源和Delphi的资源稍加改动就可以使用了。
gdhuman 2008-07-19
  • 打赏
  • 举报
回复
http://nishuixingzhou.bokee.com/4853833.html
这里有一编跨进程获取其他程序的DBGrid内容
可惜是DELPHI的,哎,难道当时选错了语言
BCB的资源太少太少了
ccrun.com 2008-07-19
  • 打赏
  • 举报
回复
从代码上来看,P是一个全局的指针,指向一个自定义的结构体变量。
gdhuman 2008-07-19
  • 打赏
  • 举报
回复
妖哥,InstallHook函数内 ,没有定义P为什么类型的指针,这样有用吗?
加载更多回复(1)

1,178

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 数据库及相关技术
社区管理员
  • 数据库及相关技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧