telppa / ahkzmq Goto Github PK
View Code? Open in Web Editor NEWAutohotkey bindings for ZeroMQ
Autohotkey bindings for ZeroMQ
没有,我就自己先尝试搞一下。
Autohotkey_H + MinHook + ClassMemory + ahkzmq ,你完全可以把 Autohotkey.dll 注入目标进程,然后通过脚本来 hook 目标函数,然后对目标进程进行内存漫游,然后对敢兴趣的数据通过 ahkzmq 传输出来。 也可以通过 ahkzmq 控制目标进程函数调用,把目标进程当做一个运行时。
实在不想让数据转来转去在栈上出现,所以需要一个线程安全队列来存储数据。但是没见人在 ahk 1 版本上用过临界区 ,不知是否管用?
还是这个例子 ,io 轮训需要开启一个新的线程,不然阻塞 UI 线程。获取完数据塞入队列返回。 UI 线程从队列里取数据执行。
我看你发布了这个项目 https://github.com/telppa/Structor , 是不是能把临界区结构体给转一下使用?
#Noenv
#persistent
SetBatchLines -1
global hwnd_main := 0
global WM_NULL := 0x0000
global lp_process_ui_callback := RegisterCallback("process_ui_callback")
global lp_recevie_message := RegisterCallback("recevie_message")
global hThread := 0
global msg
global exit_flag := 0
;global CriSec := CriticalSection()
global message_queue := []
recevie_message() {
Critical
zmq := new ZeroMQ
; keypair := zmq.curve_keypair()
; MsgBox, % keypair.1 "`n" keypair.2
context := zmq.context()
socket := context.socket(zmq.SUB)
socket.setsockopt_string(zmq.CURVE_SERVERKEY, "HIm0q5eoJ}Ur7-&prX?y{%wiI3L)I8>ge%sE}l/k", "utf-8")
socket.setsockopt_string(zmq.CURVE_PUBLICKEY, "YHtx0zuc(ZkWoXaozP*JP+Kg<!#Dt.2S>oNUXn?Y", "utf-8")
socket.setsockopt_string(zmq.CURVE_SECRETKEY, "{r]PaKZ%WD.q$VAk=E5jMeFkMkSep.Lk]voT/db+", "utf-8")
socket.connect("tcp://192.168.79.129:3002")
filter := "10001"
socket.setsockopt_string(zmq.SUBSCRIBE, filter, "utf-8")
poller := zmq.poller([[socket, zmq.POLLIN]])
loop
{
if (exit_flag == 1)
break
socks := poller.poll()
if (socks[1]) {
msg := socket.recv_string(zmq.DONTWAIT, "utf-8", false)
if (msg is integer && msg < 0) {
if (socket.errno() == zmq.EAGAIN)
continue
if (socket.errno() == zmq.EINTR)
continue
}
;ToolTip % "weather: " msg[1] msg[2]
; 这里不应该直接给 UI 线程赋值,应该 postmessage
;GuiControl, Text, TestText, % msg.1 msg.2
;EnterCriticalSection(CriSec)
message_queue.Push(msg)
;LeaveCriticalSection(CriSec)
PostMessage, WM_NULL, 0, lp_process_ui_callback, , ahk_id %hwnd_main%
}
}
}
process_ui_callback()
{
;EnterCriticalSection(CriSec)
if (message_queue.Length() > 0) {
msg := message_queue.RemoveAt(1)
}
;LeaveCriticalSection(CriSec)
GuiControl, Text, TestText, % msg.1 " " msg.2 " " msg.3
}
Gui, +AlwaysOnTop +hWndhwnd_main
Gui, Add, Text, w1200 vTestText, 等待回调UI
Gui, Add, Button, gStart, Start
Gui, Add, Button, gGoButton, Exit
Gui, Show, w1200 h100,接收zeromq消息
OnMessage(WM_NULL, "ON_WM_NULL")
return
ON_WM_NULL(wParam, lParam)
{
if (lParam != 0) {
DllCall(lParam)
}
; Func := Func("process_ui_callback")
; Func.Call(msg)
}
Start:
if (!hThread)
hThread := DllCall("CreateThread", Ptr, 0, Ptr, 0, Ptr, lp_recevie_message, Ptr, 0, UInt, 0, Ptr, 0)
return
GoButton:
exit_flag := 1
DllCall("WaitForSingleObject", "PTR", hThread, "UInt", 0xFFFFFFFF)
DllCall("CloseHandle", "PTR", hThread)
ExitApp
return
#Include %A_LineFile%\..\..\ZeroMQ\ZeroMQ.ahk
https://github.com/wyrover/jsonrpc-over-ahkzmq 帮忙看看吧,DEALER 模式发送会崩溃,socket 太忙了,你的测试用例因为都是一发一收阻塞式调用,所以没有问题。
我看下 node 的封装,要想生产级应用还得封装很多。看下这里 https://github.com/zeromq/zeromq.js/blob/17a1a3d7089b45c7b4ff24bd0e64bd78217692e6/binding.cc#L1262
我用 node 的 "zeromq": "^5.3.1" 建立的 pub 模式, ahk 的订阅端接收不到,阻塞在 this.zmq_msg_recv 函数
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.