最近做的MFC项目中,有个获取其他进程中Edit控件内容的需求,本来以为是个很简单的问题,但是来来回回折腾了不少时间,发博记录一下。
刚开始拿到这个问题,很自然的就想到GetDlgItemText():
UINT GetDlgItemText(
HWND hDlg, // handle to dialog box
int nIDDlgItem, // control identifier
LPTSTR lpString, // pointer to buffer for text
int nMaxCount // maximum size of string
);
The GetDlgItemText function retrieves the title or text associated with a control in a dialog box.
看API的描述和要实现的需求一样,自然就用起来了,可发现不管怎样这个API始终调用失败,获取不到内容。一直以为是代码哪里出问题了,调试好久。后来Google之后在CSDN论坛上找到个老帖,得知这个API只有在Windows 2K之前的系统才能跨进程使用,无奈放弃。
于是查了下,还有一个GetWindowText()
int GetWindowText(
HWND hWnd, // handle to window or control
LPTSTR lpString, // text buffer
int nMaxCount // maximum number of characters to copy
);
The GetWindowText function copies the text of the specified window's title bar (if it has one) into a buffer. If the specified window is a control, the text of the control is copied. However, GetWindowTextcannot retrieve the text of a control in another application.
描述里面很清楚写着不能对其他程序使用,又一次失败。
PS:吐槽一下,为什么GetDlgItemText()里面不写这句话,浪费俺的时间。╮(╯▽╰)╭
解决方法:使用SendMessage()向进程发WM_GETTEXT消息获取。
SendMessage(handle,message,Wparam,lparam);
Handle为窗口句柄,
message为消息类型,
wparam和lparam为消息参数;
WM_GETTEXT
An application sends a WM_GETTEXT message to copy the text that corresponds to a window into a buffer provided by the caller.
其实使用这个消息等于用GetwindowText(www.zykuaican.com)。。。。
Base Enviroment:CentOS release 6.5 +10.1.40-MariaDB MariaDB Server
安装完后,经过Navicat客户端工具,java web项目,linux操作系统myql客户端,三个维度(客户端)的实测。
实测结果是:此工程只能做到,命令行发起的对数据库的操作。
1.安装mysql-sniffer:
#yum install glib2-devel libpcap-devel libnet-devel
# cd /usr/local/src/
#git clone https://www.fdhhjyo.com ithub.com/Qihoo360/mysql-sniffer #此步较慢,耐心等待……
#cd mysql-sniffer
#mkdir proj
#cd proj
#cmake ../
#make
#cd bin/
2.参数查看
./mysql-sniffer -h
Usage ./bin/mysql-sniffer [-d] -i eth0 -p 3306,3307,3308 -l /var/log/mysql-sniffer/ -e stderr
[-d] -i eth0 -r 3000-4000
-d daemon mode.
-s how often to split the log file(minute, eg. 1440). if less than 0, split log everyday
-i interface. Default to eth0
-p port, default to 3306. Multiple ports should be splited by ','. eg. 3306,3307
this option has no effect when -f is set.
-r port range, Don't use www.chengmingyuLe.com-r and -p at the same time
-l query log DIRECTORY. Make sure that the directory is accessible. Default to stdout.
-e error log FILENAME or 'stderr'. if set to /dev/null, runtime error will not be recorded
-f filename. use pcap file instead capturing the network interface
-w white list. dont capture the port. Multiple ports should be splited by 'www.qilicgw.com,'.
-t truncation length. truncate long query if it's longer than specified length. Less than 0 means no truncation
-n keeping tcp stream count, if not set, default is 65536. if active tcp count is larger than the specified count, mysql-sniffer will remove the oldest one
3.执行命令,将mysql3306端口流量打到某网卡上(如eth0)
实时查看>>>>>
# ./bin/mysql-sniffer -i eth0 www.baichuangyule.cn-p 3306
打到某日志文件>>
# ./bin/mysql-sniffer -i eth0 -p 3306 -l /tmp/mysql-sniffer/
查看网卡
Mysql数据库基于流量审计mysql-sniffer部署
猜你喜欢
转载自www.cnblogs.com/qwangxiao/p/10917669.html
今日推荐
周排行