Created
February 26, 2014 23:49
-
-
Save maestrith/9241300 to your computer and use it in GitHub Desktop.
Posted using AHK Studio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
checkfiles(){ | |
if !FileExist("scilexer.dll") | |
urldownloadtofile,http://www.maestrith.com/files/AHKStudio/SciLexer.dll,SciLexer.dll | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class s{ | |
static ctrl:=[],lc:="" | |
__New(window="",pos=""){ | |
win:=window?window:1 | |
Gui,%win%:Add,custom,classScintilla hwndsc w500 h400 %pos% +1387331584 gnotify | |
this.sc:=sc,s.ctrl[sc]:=this,t:=[] | |
for a,b in {fn:2184,ptr:2185} | |
this[a]:=DllCall("SendMessageA","UInt",sc,"int",b,int,0,int,0) | |
v.focus:=sc | |
this.2660(1) | |
for a,b in [[2563,1],[2565,1],[2614,1],[2402,0x15,75],[2051,32,0xaaaaaa],[2052,32,0],[2050],[2051,22,0xff00ff],[2409,22,1],[2242,1,0],[2059,22,1]]{ | |
b.2:=b.2?b.2:0,b.3:=b.3?b.3:0 | |
this[b.1](b.2,b.3) | |
} | |
this.2077(0,"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_.0123456789") | |
return this | |
} | |
__Delete(){ | |
m("should not happen") | |
} | |
__Get(x*){ | |
return DllCall(this.fn,"Ptr",this.ptr,"UInt",x.1,int,0,int,0,"Cdecl") | |
} | |
__Call(code,lparam=0,wparam=0){ | |
if (code="getseltext"){ | |
VarSetCapacity(text,this.2161),length:=this.2161(0,&text) | |
return StrGet(&text,length,"cp0") | |
} | |
if (code="textrange"){ | |
VarSetCapacity(text,abs(lparam-wparam)),VarSetCapacity(textrange,12,0),NumPut(lparam,textrange,0),NumPut(wparam,textrange,4),NumPut(&text,textrange,8) | |
this.2162(0,&textrange) | |
return strget(&text,"","cp0") | |
} | |
if (code="gettext"){ | |
cap:=VarSetCapacity(text,vv:=this.2182),this.2182(vv,&text),t:=strget(&text,vv,"cp0") | |
return t | |
} | |
wp:=(wparam+0)!=""?"Int":"AStr" | |
if wparam.1 | |
wp:="AStr" | |
if wparam=0 | |
wp:="int" | |
return DllCall(this.fn,"Ptr",this.ptr,"UInt",code,int,lparam,wp,wparam,"Cdecl") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Socket{ | |
static __eventMsg:=0x9987,list:=[] | |
__New(s=-1){ | |
static init | |
if (!init){ | |
DllCall("LoadLibrary","str","ws2_32","ptr") | |
VarSetCapacity(wsadata,394+A_PtrSize) | |
DllCall("ws2_32\WSAStartup","ushort",0x0000,"ptr",&wsadata) | |
DllCall("ws2_32\WSAStartup","ushort",NumGet(wsadata,2,"ushort"),"ptr",&wsadata) | |
OnMessage(Socket.__eventMsg,"SocketEventProc") | |
init := 1 | |
} | |
this.socket:=s | |
if s>0 | |
this.list[s]:=this | |
} | |
bind(host,port){ | |
if ((this.socket!=-1)||(!(faddr:=next:=this.AddrInfo(host,port)))) | |
return 0 | |
while (next){ | |
sockaddrlen := NumGet(next+0, 16, "uint") | |
sockaddr := NumGet(next+0, 16+(2*A_PtrSize), "ptr") | |
if ((this.socket := DllCall("ws2_32\socket", "int", NumGet(next+0, 4, "int"), "int",1, "int",6,"ptr"))!=-1){ | |
if (DllCall("ws2_32\bind", "ptr", this.socket, "ptr", sockaddr, "uint", sockaddrlen, "int")=0){ | |
socket.list[this.socket]:=this | |
DllCall("ws2_32\freeaddrinfo", "ptr", faddr) | |
return Socket.__eventProcRegister(this, 0x29) | |
} | |
this.disconnect() | |
} | |
next := NumGet(next+0, 16+(3*A_PtrSize), "ptr") | |
} | |
this.lastError := DllCall("ws2_32\WSAGetLastError") | |
return 0 | |
} | |
listen(backlog=32){ | |
flan:=DllCall("ws2_32\listen", "ptr", this.socket, "int", backlog) | |
return flan | |
} | |
AddrInfo(host,port){ | |
VarSetCapacity(hints,8*A_PtrSize,0) | |
for a,b in {6:8,1:12} | |
NumPut(a,hints,b) | |
DllCall("ws2_32\getaddrinfo",astr,host,astr,port,"uptr",hints,"ptr*",results) | |
return results | |
} | |
msgSize(){ | |
VarSetCapacity(argp,4,0) | |
if (DllCall("ws2_32\ioctlsocket","ptr",this.socket,"uint",0x4004667F,"ptr",&argp)!=0) | |
return 0 | |
return NumGet(argp,0,"int") | |
} | |
__eventProcRegister(obj,msg){ | |
a:=SocketEventProc([1]) | |
a[obj.socket]:=obj | |
this.current:=a[obj.socket] | |
return (DllCall("ws2_32\WSAAsyncSelect","ptr",obj.socket,"ptr",A_ScriptHwnd,"uint",Socket.__eventMsg,"uint",msg)=0)?1:0 | |
} | |
__Delete(){ | |
this.disconnect() | |
} | |
accept(){ | |
if ((s := DllCall("ws2_32\accept", "ptr", this.socket, "ptr", 0, "int", 0, "ptr"))!=-1){ | |
newsock:=new Socket(s) | |
newsock.__protocolId := 6 | |
newsock.__socketType := 1 | |
Socket.__eventProcRegister(newsock, 0x21) | |
return newsock | |
} | |
return 0 | |
} | |
disconnect(){ | |
a:=SocketEventProc([1]) | |
a.remove(this.socket) | |
DllCall("ws2_32\WSAAsyncSelect","ptr",this.socket,"ptr",A_ScriptHwnd,"uint",0,"uint",0)=0 | |
DllCall("ws2_32\closesocket","ptr",this.socket,"int") | |
this.socket:=-1 | |
return 1 | |
} | |
} | |
;---------------------------------------end socket-------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
connect(server="",port=6667){ | |
connect: | |
server:=127.0.0.1 | |
sock:=new socket(server,port) | |
if (sock.socket=-1) | |
return m("Unable to connect") | |
return | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#SingleInstance,Force | |
checkfiles() | |
rxml:=new xml("recv") | |
v:=[] | |
global hwnd,v,rxml | |
gui() | |
v.hwnd:=hwnd,v.msg:=[] | |
return | |
#Include class socket.ahk | |
#Include msgbox.ahk | |
#Include SocketEventProc.ahk | |
#Include onrecv.ahk | |
#Include connect.ahk | |
#Include xml.ahk | |
#Include gui.ahk | |
#Include load.ahk | |
#Include run.ahk | |
#Include send.ahk | |
#Include encode.ahk | |
#Include decode.ahk | |
#Include getvar.ahk | |
#Include exit.ahk | |
#Include class s.ahk | |
#Include checkfiles.ahk | |
#Include notify.ahk | |
#Include display.ahk | |
#Include hwnd.ahk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Base64UTF8Decode(ByRef base64){ | |
if (base64 = "") | |
return | |
cp := StringToBinary(result, base64, 1) | |
return StrGet(&result, cp, "utf-8") | |
} | |
StringToBinary(ByRef bin, hex, fmt=12) { | |
DllCall("Crypt32.dll\CryptStringToBinary", "ptr",&hex, "uint",StrLen(hex), "uint",fmt, "ptr",0, "uint*",cp:=0, "ptr",0,"ptr",0) ; get size | |
VarSetCapacity(bin, cp) | |
DllCall("Crypt32.dll\CryptStringToBinary", "ptr",&hex, "uint",StrLen(hex), "uint",fmt, "ptr",&bin, "uint*",cp, "ptr",0,"ptr",0) | |
return cp | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
display(store){ | |
start:=1 | |
sc:=v.sc | |
while,start:=RegExMatch(store,"<\?.+\?>(<.+>)" Chr(0),found,start){ | |
start:=start+StrLen(found)-10 | |
rxml.xml.loadxml(found) | |
Loop,2 | |
rxml.Transform() | |
if rxml.ssn("//init"){ | |
GuiControl,-Disabled,Button1 | |
GuiControl,+Disabled,Button2 | |
GuiControl,-Disabled,SysTreeView321 | |
} | |
if InStr(rxml[],"<property"){ | |
if sc.2006 | |
sc.2003(sc.2006,"`r`n") | |
if property:=rxml.sn("//property"){ | |
while,pp:=property.item[A_Index-1]{ | |
type:=ssn(pp,"@type").text,fullname:=ssn(pp,"@fullname").text | |
if (type="object"){ | |
sc.2003(sc.2006,"`r`nObject: ") | |
end:=sc.2006 | |
sc.2003(sc.2006,fullname) | |
sc.2032(end,255) | |
sc.2033(StrLen(fullname),22) | |
} | |
else | |
sc.2003(sc.2006,"`r`n" ssn(pp,"@type").text ": " fullname " = " Base64UTF8Decode(pp.text)) | |
} | |
} | |
}else{ | |
disp:=sc.2006?"`r`n" rxml[]:rxml[] | |
sc.2003(sc.2006,disp) | |
} | |
if InStr(store,"stopped"){ | |
GuiControl,+Disabled,SysTreeView321 | |
GuiControl,-Disabled,Button2 | |
WinSetTitle,% "ahk_id" v.hwnd,,Job Complete | |
} | |
} | |
sc.2629 | |
return | |
disp:=rxml[] | |
store:=disp?disp:store | |
return sock | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BinaryToString(ByRef bin, sz=0, fmt=12) { | |
n := sz>0 ? sz : VarSetCapacity(bin) | |
DllCall("Crypt32.dll\CryptBinaryToString", "ptr",&bin, "uint",n, "uint",fmt, "ptr",0, "uint*",cp:=0) ; get size | |
VarSetCapacity(str, cp*(A_IsUnicode ? 2:1)) | |
DllCall("Crypt32.dll\CryptBinaryToString", "ptr",&bin, "uint",n, "uint",fmt, "str",str, "uint*",cp) | |
return str | |
} | |
Base64UTF8Encode(ByRef textdata) { | |
if (textdata = "") | |
return | |
VarSetCapacity(rawdata, StrPut(textdata, "utf-8")), sz := StrPut(textdata, &rawdata, "utf-8") - 1 | |
return BinaryToString(rawdata, sz, 0x40000001) | |
} | |
;http://www.autohotkey.com/forum/viewtopic.php?p=238120#238120 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exit(){ | |
GuiClose: | |
GuiEscape: | |
send("stop",socket.current) | |
ExitApp | |
return | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getvar(){ | |
getvar: | |
ControlGetText,vv,Edit1,% "ahk_id" v.hwnd | |
if !vv | |
return | |
send("property_get -n " vv,socket.current) | |
return | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gui(){ | |
Gui,+hwndhwnd | |
hwnd(1,hwnd) | |
IfWinActive,ahk_id%hwnd% | |
Hotkey,Esc,GuiEscape,On | |
DllCall("LoadLibrary","str","scilexer.dll") | |
v.sc:=new s(1,"xm ym w800 h400") | |
Gui,Add,TreeView,w300 h200 Section AltSubmit gset Disabled | |
Gui,Add,Button,grun x+10 ys Disabled,Run | |
Gui,Add,Button,gload,Load File | |
Gui,Add,Edit,w200 | |
Gui,Add,Button,x+10 ggetvar Default,Get Variable | |
for a,b in ["Feature","Property"] | |
v.tv[b]:=TV_Add(b) | |
for a,b in ["max_children","max_data","max_depth"] | |
TV_Add(b,v.tv.feature) | |
for a,b in ["property_set"] | |
v.tv.propertyset:=TV_Add("property_set",v.tv.property) | |
for a,b in v.tv | |
if b is number | |
TV_Modify(b,"Expand") | |
Gui,Show | |
ControlFocus,Edit1,% hwnd([1]) | |
} | |
set: | |
if (A_GuiEvent="S"||A_GuiEvent="Normal"){ | |
if (TV_GetParent(A_EventInfo)=v.tv.feature){ | |
TV_GetText(feature,A_EventInfo) | |
InputBox,value,Value,Input a number for %feature%,,,,,,,,20 | |
if ErrorLevel | |
return | |
if value not between 0 and 3001 | |
{ | |
m("Please choose a number between 0 and 3000") | |
return | |
} | |
send("feature_set -n " feature " -v" value,socket.current) | |
} | |
if (A_EventInfo=v.tv.propertyset){ | |
InputBox,property,Property,Property Name | |
if ErrorLevel | |
return | |
InputBox,value,Property Value,Porperty Value | |
if ErrorLevel | |
return | |
send("property_set -n " property " -- " Base64UTF8Encode(value),socket.current) | |
} | |
} | |
return | |
setrange: | |
ControlGetText,range,Edit2,% "ahk_id" v.hwnd | |
if range not between 1 and 3000 | |
{ | |
m("Please choose a number between 1 and 3000") | |
return | |
} | |
send("feature_set -n max_children -v" range,socket.current) | |
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hwnd(win,hwnd=""){ | |
static window:=[] | |
if (win.rem){ | |
Gui,% win.rem ":Destroy" | |
window.remove[win.rem] | |
} | |
if IsObject(win) | |
return "ahk_id" window[win.1] | |
if !hwnd | |
return window[win] | |
window[win]:=hwnd | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
load(){ | |
load: | |
FileSelectFile,file,,,,*.ahk | |
if ErrorLevel | |
return | |
sock:=new socket() | |
sock.bind("127.0.0.1",9000) | |
sock.listen("127.0.0.1",9000) | |
SplitPath,file,,dir | |
Run, "%A_AhkPath%" /Debug "%file%",%dir% | |
WinSetTitle,ahk_id%hwnd%,,File Opened %file% | |
ControlSetText,Edit2,20,% "ahk_id" v.hwnd | |
return | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
m(x*){ | |
for a,b in x | |
list.=b "`n" | |
MsgBox,% list | |
} | |
t(x*){ | |
for a,b in x | |
list.=b "`n" | |
Tooltip,% list | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
notify(){ | |
notify: | |
sc:=v.sc | |
fn:=[],info:=A_EventInfo | |
for a,b in {0:"Obj",2:"Code",4:"ch",7:"text",6:"modType",9:"linesadded",8:"length",3:"position"} | |
fn[b]:=NumGet(Info+(A_PtrSize*a)) | |
if (fn.code=2027){ | |
find:=sc.textrange(sc.2266(fn.position,0),sc.2267(fn.position,0)) | |
send("property_get -n " find,socket.current) | |
} | |
return | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
onrecv(sock){ | |
Critical | |
length:=sock.msgsize() | |
VarSetCapacity(buffer, length) | |
r:=DllCall("ws2_32\recv","ptr",sock.socket,"ptr",&buffer,"int",length,"int",0) | |
v.msg.Insert({length:length,buffer:buffer}) | |
if !v.timer{ | |
v.timer:=1 | |
SetTimer,buffer,On | |
} | |
} | |
recvText(this,wait=1,encoding="UTF-8"){ | |
Critical | |
length:=this.msgsize() | |
VarSetCapacity(buffer, length) | |
r:=DllCall("ws2_32\recv","ptr",this.socket,"ptr",&buffer,"int",length,"int",0) | |
v.msg.Insert({length:length,buffer:buffer}) | |
SetTimer,buffer,On | |
} | |
buffer: | |
length:=v.msg.1.length,buffer:=v.msg.1.buffer | |
loop,%length%{ | |
cc:=NumGet(&buffer,A_Index-1,"uchar") | |
chr:=chr(cc) | |
if (cc=0){ | |
if msg is number | |
msg:="" | |
else | |
display(msg),msg:="" | |
} | |
else | |
msg.=chr | |
} | |
v.msg.remove(1) | |
if !v.msg.1{ | |
v.timer:="" | |
SetTimer,buffer,Off | |
} | |
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
run(){ | |
Run: | |
send("run",socket.current) | |
GuiControl,+Disabled,Button1 | |
return | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
send(message,sock){ | |
message.=Chr(0) | |
len:=strlen(message) | |
VarSetCapacity(buffer,len) | |
ll:=StrPut(message,&buffer,"utf-8") | |
flan:=DllCall("ws2_32\send",uint,sock.socket,uptr,&buffer,"int",ll, "int", 0, "cdecl") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SocketEventProc(info*){ | |
Critical | |
static count:=0 | |
global id | |
static a:=[] | |
if info.1.1 | |
return a | |
if (info.3=socket.__eventmsg){ | |
if (info.2&0xFFFF=1){ | |
onrecv(a[info.1]) | |
} | |
if (info.2&0xffff=8){ | |
sock:=socket.list[info.1] | |
ss:=sock.accept() | |
} | |
if (info.2&0xFFFF=32) | |
return a[info.1].disconnect() | |
} | |
} | |
recv(this,byref buffer){ | |
Critical | |
length:=this.msgsize() | |
if (length){ | |
VarSetCapacity(buffer, length) | |
if ((r:=DllCall("ws2_32\recv","ptr",this.socket,"ptr",&buffer,"int",length,"int",0))<=0) | |
return 0 | |
return r | |
} | |
return 0 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class xml{ | |
keep:=[] | |
__New(param*){ | |
root:=param.1 | |
file:=file?file:root ".xml" | |
temp:=ComObjCreate("MSXML2.DOMDocument"),temp.setProperty("SelectionLanguage","XPath") | |
this.xml:=temp | |
this.xml:=this.CreateElement(temp,root) | |
xml.keep[root]:=this | |
} | |
CreateElement(doc,root){ | |
return doc.AppendChild(this.xml.CreateElement(root)).parentnode | |
} | |
ssn(node){ | |
return this.xml.SelectSingleNode(node) | |
} | |
sn(node){ | |
return this.xml.SelectNodes(node) | |
} | |
__Get(x=""){ | |
return this.xml.xml | |
} | |
transform(){ | |
static | |
if !IsObject(xsl){ | |
xsl:=ComObjCreate("MSXML2.DOMDocument") | |
style= | |
( | |
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | |
<xsl:output method="xml" indent="yes" encoding="UTF-8"/> | |
<xsl:template match="@*|node()"> | |
<xsl:copy> | |
<xsl:apply-templates select="@*|node()"/> | |
<xsl:for-each select="@*"> | |
<xsl:text></xsl:text> | |
</xsl:for-each> | |
</xsl:copy> | |
</xsl:template> | |
</xsl:stylesheet> | |
) | |
xsl.loadXML(style),style:=null | |
} | |
this.xml.transformNodeToObject(xsl,this.xml) | |
} | |
ea(ph){ | |
list:=[] | |
if IsObject(ph) | |
nodes:=ph.SelectNodes("@*") | |
else | |
nodes:=this.sn(ph "/@*") | |
while,n:=nodes.item(A_Index-1) | |
list[n.nodename]:=n.text | |
return list | |
} | |
} | |
ssn(node,path){ | |
return node.SelectSingleNode(path) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment