Giter VIP home page Giter VIP logo

ahkzmq's People

Contributors

telppa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

pa-0

ahkzmq's Issues

有没有办法线程安全?

实在不想让数据转来转去在栈上出现,所以需要一个线程安全队列来存储数据。但是没见人在 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



zeromq 集成到 ahk 的使用场景

  1. zeromq 有大多数语言的包装,所以可以通过 zeromq 调用不同语言实现的服务。
  2. 推送是一个场景。
  3. ahk 作为自动化服务方,但是并不作为 zeromq 服务器端存在,因为大多数的 ahk 应用都在内网。所以可以通过 zeromq 双向调用暴露一个服务。应用层协议可以实现为双向 jsonrpc 调用。异步方式实现,server 端实现 router 模式,client 端实现 dealer 模式。
  4. ahk 作为上层界面,并不稳定,最好不要实现单进程应用。所以可以通过 zeromq 实现多进程应用。
  5. node python 都有打包工具。配合 ahk 和 zeromq 组合实现应用。关键服务可以放到服务器端实现。
  6. 不够安全的地方,libzmq 作为开源实现,函数容易被 hook。就算你实现了双向认证,那只是解决了网络层面。
  7. Autohotkey 也容易被 hook,导出原始脚本。
  8. ahk v1 是一个单线程应用,看一下源码,大量的全局变量实现。虽然你可以通过 api 函数 createthread 创建一个线程,但线程同步并不容易。使用临界区也不行,容易崩溃。要想稳定实现功能最好转到 C++/C 实现,然后将 ahk 回调函数指针注册到模块里。
  9. 如果你把 ahk 程序当做 zeromq 工作队列模型发布出去。那么你可以分布式计算,比如爬虫…………

另一个使用场景,辅助逆向,堪比 frida

Autohotkey_H + MinHook + ClassMemory + ahkzmq ,你完全可以把 Autohotkey.dll 注入目标进程,然后通过脚本来 hook 目标函数,然后对目标进程进行内存漫游,然后对敢兴趣的数据通过 ahkzmq 传输出来。 也可以通过 ahkzmq 控制目标进程函数调用,把目标进程当做一个运行时。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.