├── Anchor.ahk ├── AnchorL.ahk ├── Auth.ahk ├── Bin.ahk ├── BinGet.ahk ├── Class_LV_InCellEdit.ahk ├── ColURL.ahk ├── DLLPack.ahk ├── EWinHook.ahk ├── ExcelToObj.ahk ├── ExtListView.ahk ├── FileVerInfo.ahk ├── Icon.ahk ├── IniParser.ahk ├── Json4Ahk.ahk ├── LVX.ahk ├── LV_EX.ahk ├── LV_SortArrow.ahk ├── MCode.ahk ├── MD5.ahk ├── MatchItemFromList.ahk ├── NetShareEnum.ahk ├── PECreateEmpty.ahk ├── PipeRun.ahk ├── Process.ahk ├── README.md ├── SB.ahk ├── StdoutToVar.ahk ├── SysProcInfo.ahk ├── TaskDialog.ahk ├── TermWait.ahk ├── TrayIcon.ahk ├── UpdRes.ahk ├── WinEvents.ahk ├── WinHttpRequest.ahk ├── Zip.ahk └── type.ahk /Anchor.ahk: -------------------------------------------------------------------------------- 1 | /* 2 | Function: Anchor 3 | Defines how controls should be automatically positioned relative to the new dimensions of a window when resized. 4 | 5 | Parameters: 6 | cl - a control HWND, associated variable name or ClassNN to operate on 7 | a - (optional) one or more of the anchors: 'x', 'y', 'w' (width) and 'h' (height), 8 | optionally followed by a relative factor, e.g. "x h0.5" 9 | r - (optional) true to redraw controls, recommended for GroupBox and Button types 10 | 11 | Examples: 12 | > "xy" ; bounds a control to the bottom-left edge of the window 13 | > "w0.5" ; any change in the width of the window will resize the width of the control on a 2:1 ratio 14 | > "h" ; similar to above but directrly proportional to height 15 | 16 | Remarks: 17 | To assume the current window size for the new bounds of a control (i.e. resetting) simply omit the second and third parameters. 18 | However if the control had been created with DllCall() and has its own parent window, 19 | the container AutoHotkey created GUI must be made default with the +LastFound option prior to the call. 20 | For a complete example see anchor-example.ahk. 21 | 22 | License: 23 | - Version 4.60a 24 | - Dedicated to the public domain (CC0 1.0) 25 | */ 26 | Anchor(i, a = "", r = false) { 27 | static c, cs = 12, cx = 255, cl = 0, g, gs = 8, gl = 0, gpi, gw, gh, z = 0, k = 0xffff 28 | If z = 0 29 | VarSetCapacity(g, gs * 99, 0), VarSetCapacity(c, cs * cx, 0), z := true 30 | If (!WinExist("ahk_id" . i)) { 31 | GuiControlGet, t, Hwnd, %i% 32 | If ErrorLevel = 0 33 | i := t 34 | Else ControlGet, i, Hwnd, , %i% 35 | } 36 | VarSetCapacity(gi, 68, 0), DllCall("GetWindowInfo", "UInt", gp := DllCall("GetParent", "UInt", i), "UInt", &gi) 37 | , giw := NumGet(gi, 28, "Int") - NumGet(gi, 20, "Int"), gih := NumGet(gi, 32, "Int") - NumGet(gi, 24, "Int") 38 | If (gp != gpi) { 39 | gpi := gp 40 | Loop, %gl% 41 | If (NumGet(g, cb := gs * (A_Index - 1)) == gp) { 42 | gw := NumGet(g, cb + 4, "Short"), gh := NumGet(g, cb + 6, "Short"), gf := 1 43 | Break 44 | } 45 | If (!gf) 46 | NumPut(gp, g, gl), NumPut(gw := giw, g, gl + 4, "Short"), NumPut(gh := gih, g, gl + 6, "Short"), gl += gs 47 | } 48 | ControlGetPos, dx, dy, dw, dh, , ahk_id %i% 49 | Loop, %cl% 50 | If (NumGet(c, cb := cs * (A_Index - 1)) == i) { 51 | If a = 52 | { 53 | cf = 1 54 | Break 55 | } 56 | giw -= gw, gih -= gh, as := 1, dx := NumGet(c, cb + 4, "Short"), dy := NumGet(c, cb + 6, "Short") 57 | , cw := dw, dw := NumGet(c, cb + 8, "Short"), ch := dh, dh := NumGet(c, cb + 10, "Short") 58 | Loop, Parse, a, xywh 59 | If A_Index > 1 60 | av := SubStr(a, as, 1), as += 1 + StrLen(A_LoopField) 61 | , d%av% += (InStr("yh", av) ? gih : giw) * (A_LoopField + 0 ? A_LoopField : 1) 62 | DllCall("SetWindowPos", "UInt", i, "Int", 0, "Int", dx, "Int", dy 63 | , "Int", InStr(a, "w") ? dw : cw, "Int", InStr(a, "h") ? dh : ch, "Int", 4) 64 | If r != 0 65 | DllCall("RedrawWindow", "UInt", i, "UInt", 0, "UInt", 0, "UInt", 0x0101) ; RDW_UPDATENOW | RDW_INVALIDATE 66 | Return 67 | } 68 | If cf != 1 69 | cb := cl, cl += cs 70 | bx := NumGet(gi, 48), by := NumGet(gi, 16, "Int") - NumGet(gi, 8, "Int") - gih - NumGet(gi, 52) 71 | If cf = 1 72 | dw -= giw - gw, dh -= gih - gh 73 | NumPut(i, c, cb), NumPut(dx - bx, c, cb + 4, "Short"), NumPut(dy - by, c, cb + 6, "Short") 74 | , NumPut(dw, c, cb + 8, "Short"), NumPut(dh, c, cb + 10, "Short") 75 | Return, true 76 | } 77 | -------------------------------------------------------------------------------- /AnchorL.ahk: -------------------------------------------------------------------------------- 1 | ; ---------------------------------------------------------------------------------------------------------------------- 2 | ; Function .....: AnchorL 3 | ; Description ..: Defines controls positioning on window resize. 4 | ; Parameters ...: i - a control HWND, associated variable name or ClassNN to operate on. 5 | ; ..............: a - (optional) one or more of the anchors: 'x', 'y', 'w' (width) and 'h' (height), optionally followed 6 | ; ..............: by a relative factor, e.g. "x h0.5". 7 | ; ..............: r - (optional) true to redraw controls, recommended for GroupBox and Button types. 8 | ; AHK Version ..: AHK_L x32/64 ANSI/Unicode 9 | ; Author .......: polyethene 10 | ; License ......: CC0 1.0 11 | ; Version ......: 4.60a 12 | ; Remarks ......: To assume the current window size for the new bounds of a control (i.e. resetting) simply omit the 13 | ; ..............: second and third parameters. However if the control had been created with DllCall() and has its own 14 | ; ..............: parent window, the container AutoHotkey created GUI must be made default with the +LastFound option 15 | ; ..............: prior to the call. For a complete example see anchor-example.ahk. 16 | ; ---------------------------------------------------------------------------------------------------------------------- 17 | AnchorL(i, a:="", r:=False) { 18 | Static c, cs := 12, cx := 255, cl := 0, g, gs := 8, gl := 0, gpi, gw, gh, z := 0, k := 0xffff 19 | If ( z == 0 ) 20 | VarSetCapacity(g, gs * 99, 0), VarSetCapacity(c, cs * cx, 0), z := True 21 | If ( !WinExist("ahk_id" i) ) { 22 | GuiControlGet, t, Hwnd, %i% 23 | If ( ErrorLevel == 0 ) 24 | i := t 25 | Else ControlGet, i, Hwnd,, %i% 26 | } 27 | VarSetCapacity(gi, 68, 0), DllCall( "GetWindowInfo", Ptr,gp:=DllCall("GetParent",Ptr,i), Ptr,&gi ) 28 | , giw := NumGet(gi, 28, "Int") - NumGet(gi, 20, "Int"), gih := NumGet(gi, 32, "Int") - NumGet(gi, 24, "Int") 29 | If ( gp != gpi ) { 30 | gpi := gp 31 | Loop, %gl% 32 | If ( NumGet(g, cb := gs * (A_Index - 1)) == gp ) { 33 | gw := NumGet(g, cb + 4, "Short"), gh := NumGet(g, cb + 6, "Short"), gf := 1 34 | Break 35 | } 36 | If ( !gf ) 37 | NumPut(gp, g, gl), NumPut(gw := giw, g, gl + 4, "Short"), NumPut(gh := gih, g, gl + 6, "Short"), gl += gs 38 | } 39 | ControlGetPos, dx, dy, dw, dh,, ahk_id %i% 40 | Loop, %cl% 41 | If ( NumGet(c, cb := cs * (A_Index - 1)) == i ) { 42 | If ( !a ) 43 | { 44 | cf := 1 45 | Break 46 | } 47 | giw -= gw, gih -= gh, as := 1, dx := NumGet(c, cb + 4, "Short"), dy := NumGet(c, cb + 6, "Short") 48 | , cw := dw, dw := NumGet(c, cb + 8, "Short"), ch := dh, dh := NumGet(c, cb + 10, "Short") 49 | Loop, Parse, a, xywh 50 | If ( A_Index > 1 ) 51 | av := SubStr(a, as, 1), as += 1 + StrLen(A_LoopField) 52 | , d%av% += (InStr("yh", av) ? gih : giw) * (A_LoopField + 0 ? A_LoopField : 1) 53 | DllCall( "SetWindowPos", Ptr,i, Ptr,0, Int,dx, Int,dy, Int,InStr(a,"w")?dw:cw, Int,InStr(a,h)?dh:ch, Int,4 ) 54 | If ( r != 0 ) 55 | DllCall( "RedrawWindow", Ptr,i, Ptr,0, Ptr,0, UInt,0x0101) ; RDW_UPDATENOW | RDW_INVALIDATE 56 | Return 57 | } 58 | If ( cf != 1 ) 59 | cb := cl, cl += cs 60 | bx := NumGet(gi, 48), by := NumGet(gi, 16, "Int") - NumGet(gi, 8, "Int") - gih - NumGet(gi, 52) 61 | If ( cf == 1 ) 62 | dw -= giw - gw, dh -= gih - gh 63 | NumPut(i, c, cb), NumPut(dx - bx, c, cb + 4, "Short"), NumPut(dy - by, c, cb + 6, "Short") 64 | , NumPut(dw, c, cb + 8, "Short"), NumPut(dh, c, cb + 10, "Short") 65 | Return, true 66 | } 67 | -------------------------------------------------------------------------------- /Auth.ahk: -------------------------------------------------------------------------------- 1 | ; ---------------------------------------------------------------------------------------------------------------------- 2 | ; Name .........: Auth library 3 | ; Description ..: This library is a collection of functions that deal with privileges and access rights. 4 | ; AHK Version ..: AHK_L 1.1.13.01 x32/64 Unicode 5 | ; Author .......: Cyruz (http://ciroprincipe.info) 6 | ; License ......: WTFPL - http://www.wtfpl.net/txt/copying/ 7 | ; Changelog ....: Oct. 25, 2011 - v0.1 - First version. 8 | ; ..............: Dic. 27, 2013 - v0.2 - Added AccessRights_RunAsAdmin. 9 | ; ..............: Feb. 05, 2014 - v0.3 - Code refactoring. Unicode and x64 version. Added AccessRights_EnableSeDebug. 10 | ; ..............: Jan. 17, 2015 - v0.4 - Changed library name to Auth. Generalized AccessRights_EnableSeDebug for all 11 | ; ..............: privileges and converted to Auth_AdjustPrivileges. Added Auth_AdjustPrivilege. 12 | ; ---------------------------------------------------------------------------------------------------------------------- 13 | 14 | ; ---------------------------------------------------------------------------------------------------------------------- 15 | ; Function .....: Auth_RunAsAdmin 16 | ; Description ..: Run the current AutoHotkey script as administrator. 17 | ; Author .......: shajul 18 | ; ---------------------------------------------------------------------------------------------------------------------- 19 | Auth_RunAsAdmin() { 20 | Global 21 | If ( !A_IsAdmin ) { 22 | Loop, %0% ; For each parameter 23 | sParams .= A_Space . %A_Index% 24 | Local ShellExecute 25 | ShellExecute := (A_IsUnicode) ? "Shell32.dll\ShellExecute" : "Shell32.dll\ShellExecuteA" 26 | A_IsCompiled 27 | ? DllCall( ShellExecute, UInt,0, Str,"RunAs", Str,A_ScriptFullPath, Str,sParams , Str,A_WorkingDir, Int,1 ) 28 | : DllCall( ShellExecute, UInt,0, Str,"RunAs", Str,A_AhkPath, Str,"""" A_ScriptFullPath """ " sParams 29 | , Str,A_WorkingDir, Int,1 ) 30 | ExitApp 31 | } 32 | } 33 | 34 | ; ---------------------------------------------------------------------------------------------------------------------- 35 | ; Function .....: Auth_RunAsUser 36 | ; Description ..: Run a program as limited user, stripping all eventual administrator rights. 37 | ; Parameters ...: sCmdLine - Commandline to be executed. 38 | ; ---------------------------------------------------------------------------------------------------------------------- 39 | Auth_RunAsUser(sCmdLine) 40 | { 41 | hMod := DllCall( "LoadLibrary", Str,"Advapi32.dll" ) 42 | 43 | ; PROCESS_QUERY_INFORMATION = 0x0400 44 | hProc := DllCall( "OpenProcess", UInt,0x0400, Int,0, UInt,DllCall("GetCurrentProcessId") ) 45 | 46 | ; TOKEN_ASSIGN_PRIMARY = 0x0001 ; TOKEN_DUPLICATE = 0x0002 47 | ; TOKEN_QUERY = 0x0008 ; TOKEN_ADJUST_DEFAULT = 0x0080 48 | DllCall( "Advapi32.dll\OpenProcessToken", Ptr,hProc, UInt,0x0001|0x0002|0x0008|0x0080, PtrP,hToken ) 49 | 50 | ; The flag LUA_TOKEN doesn't work on XP, we need to deny the Administrators SID. 51 | If A_OSVersion in WIN_2000,WIN_XP 52 | { ; Create an Administrators SID and fill SID structure. 53 | bOldSys = 1 54 | 55 | ; * [IMPORTANT] 56 | ; * The Well-Known Administrators SID needs 2 subauthorities: 57 | ; * SECURITY_BUILTIN_DOMAIN_RID and DOMAIN_ALIAS_RID_ADMINS. 58 | ; * http://msdn.microsoft.com/en-us/library/windows/desktop/aa379597.aspx 59 | szSid := DllCall( "Advapi32.dll\GetSidLengthRequired", UChar,2 ) 60 | VarSetCapacity(pSid, szSid, 0) 61 | 62 | ; Well-Known SID Structures - http://msdn.microsoft.com/en-us/library/cc980032.aspx 63 | ; WELL_KNOWN_SID_TYPE { ... WinBuiltinAdministratorsSid = 26 ... } 64 | DllCall( "Advapi32.dll\CreateWellKnownSid", UInt,26, Ptr,0, Ptr,&pSid, UIntP,szSid ) 65 | 66 | ; SID_AND_ATTRIBUTES - http://msdn.microsoft.com/en-us/library/aa379595 67 | VarSetCapacity( SIDATTR, (A_PtrSize == 4) ? 8 : 16, 0 ) 68 | NumPut( &pSid, &SIDATTR, 0, "Ptr" ) 69 | ; Missing SE_GROUP_USE_FOR_DENY_ONLY 70 | } 71 | 72 | ; Restrict the token (deny the Administrators SID on XP). 73 | ; DISABLE_MAX_PRIVILEGE = 0x1 ; LUA_TOKEN = 0x4 74 | DllCall( "Advapi32.dll\CreateRestrictedToken", Ptr,hToken, UInt,(bOldSys)?0x1:0x4, UInt,(bOldSys)?1:0 75 | , Ptr,(bOldSys)?&SIDATTR:0, UInt,0, Ptr,0, UInt,0, Ptr,0 76 | , PtrP,hResToken ) 77 | 78 | ; We can set integrity levels only on Windows Vista/7/8. 79 | If A_OSVersion in WIN_VISTA,WIN_7,WIN_8 80 | { ; Create an integrity SID and set the integrity level. 81 | 82 | ; * [IMPORTANT] 83 | ; * The Well-Known Integrity SIDs need 1 subauthority. 84 | ; * In our case, we need SECURITY_MANDATORY_LOW_RID or SECURITY_MANDATORY_MEDIUM_RID. 85 | ; * http://msdn.microsoft.com/en-us/library/bb625963.aspx 86 | szSid := DllCall( "Advapi32.dll\GetSidLengthRequired", UChar,1 ) 87 | VarSetCapacity(pSid, szSid, 0) 88 | 89 | ; Well-Known SID Structures - http://msdn.microsoft.com/en-us/library/cc980032.aspx 90 | ; WELL_KNOWN_SID_TYPE { ... WinLowLabelSid = 66, WinMediumLabelSid = 67 ...} 91 | DllCall( "Advapi32.dll\CreateWellKnownSid", UInt,66, UInt,0, Ptr,&pSid, UIntP,szSid ) 92 | 93 | ; SE_GROUP_INTEGRITY = 0x00000020L 94 | VarSetCapacity( SIDATTR, (A_PtrSize == 4) ? 8 : 16, 0 ) 95 | NumPut( &pSid, &SIDATTR, 0, "Ptr" ) 96 | NumPut( 0x00000020L, &SIDATTR, (A_PtrSize == 4) ? 4 : 8, "UInt" ) 97 | 98 | ; TOKEN_INFORMATION_CLASS = {... TokenIntegrityLevel = 25 ...} 99 | DllCall( "Advapi32.dll\SetTokenInformation", Ptr,hResToken, UInt,25, Ptr,&SIDATTR, UInt,A_PtrSize*2 ) 100 | } 101 | 102 | ; PROCESS_INFORMATION struct - http://msdn.microsoft.com/en-us/library/ms684873 103 | ; STARTUPINFO struct - http://msdn.microsoft.com/en-us/library/ms686331 104 | lpDesktop := "winsta0\default" 105 | VarSetCapacity( PROCINFO, (A_PtrSize == 4) ? 16 : 24, 0 ) 106 | VarSetCapacity( STARTINFO, (A_PtrSize == 4) ? 68 : 104, 0 ) 107 | NumPut( (A_PtrSize == 4) ? 68 : 104, &STARTINFO, 0, "UInt" ) 108 | NumPut( &lpDesktop , &STARTINFO, A_PtrSize*2, "Ptr" ) 109 | 110 | ; Run the process with the restricted token. 111 | ; NORMAL_PRIORITY_CLASS = 0x00000020 112 | DllCall( "Advapi32.dll\CreateProcessAsUser", Ptr,hResToken, Ptr,0, Str,sCmdLine, Ptr,0, Ptr,0, Int,0 113 | , UInt,0x00000020, Ptr,0, Ptr,0, Ptr,&STARTINFO, Ptr,&PROCINFO ) 114 | 115 | ; Close handles and free libraries and structures. 116 | DllCall( "Advapi32.dll\FreeSid", Ptr,pSid ) 117 | DllCall( "CloseHandle", Ptr,hProc ) 118 | DllCall( "CloseHandle", Ptr,hToken ) 119 | DllCall( "CloseHandle", Ptr,hResToken ) 120 | DllCall( "CloseHandle", Ptr,NumGet(&PROCINFO,0) ) 121 | DllCall( "CloseHandle", Ptr,NumGet(&PROCINFO,A_PtrSize) ) 122 | DllCall( "FreeLibrary", Ptr,hMod ) 123 | } 124 | 125 | ; ---------------------------------------------------------------------------------------------------------------------- 126 | ; Function .....: Auth_AdjustPrivileges 127 | ; Description ..: Adjust process privileges. 128 | ; Parameters ...: arrPriv - Array of objects describing the privileges to adjust. If = 0 all privileges will be 129 | ; ..............: disabled. It has the following structure: 130 | ; ..............: arrPriv[n].privilege - Privilege name as a constant string: http://goo.gl/uHkV0S. 131 | ; ..............: arrPriv[n].state - 0 to disable, 2 to enable, 4 to remove from the list. 132 | ; ..............: nPid - PID of the process to be adjusted, if = 0 the current process will be adjusted. 133 | ; Return .......: Number of processed privileges or 0 if all the privileges are disabled. 134 | ; Example ......: Auth_AdjustPrivileges([ { "privilege" : "SeDebugPrivilege", "state" : 2 } 135 | ; ..............: , { "privilege" : "SeCreatePageFilePrivilege", "state" : 2 } ]) 136 | ; ---------------------------------------------------------------------------------------------------------------------- 137 | Auth_AdjustPrivileges(ByRef arrPriv, nPid:=0) { 138 | If ( (!isObject(arrPriv) && arrPriv != 0) || (isObject(arrPriv) && !arrPriv.MaxIndex()) ) 139 | Throw Exception("Parameters error.", "Auth_AdjustPrivileges") 140 | 141 | Try { 142 | ; PROCESS_QUERY_INFORMATION = 0x400 143 | If ( !hProc := DllCall( "OpenProcess", UInt,0x0400, Int,0, UInt,(nPid)?nPid:DllCall("GetCurrentProcessId") ) ) 144 | Throw Exception("Error: " A_LastError, "OpenProcess") 145 | ; TOKEN_ADJUST_PRIVILEGES = 0x0020, TOKEN_QUERY = 0x0008 146 | If ( !DllCall( "Advapi32.dll\OpenProcessToken", Ptr,hProc, UInt,0x0020|0x0008, PtrP,hToken ) ) 147 | Throw Exception("Error: " A_LastError, "OpenProcessToken") 148 | 149 | If ( isObject(arrPriv) ) { 150 | ; TOKEN_PRIVILEGES size = 16, LUID_AND_ATTRIBUTES size = 12 151 | VarSetCapacity( TOKPRIV, 4+(arrPriv.MaxIndex()*12), 0 ) ; TOKEN_PRIVILEGES structure: http://goo.gl/AGXeAp. 152 | Loop % arrPriv.MaxIndex() 153 | { 154 | nOfft := (A_Index - 1) * 12, VarSetCapacity( LUID, 8, 0 ) 155 | If ( !DllCall( "Advapi32.dll\LookupPrivilegeValue", Ptr,0, Str,arrPriv[A_Index].privilege, Ptr,&LUID ) ) 156 | Continue 157 | NumPut( NumGet( &LUID, 0, "UInt" ), &TOKPRIV, nOfft+4, "UInt" ) ; LUID_AND_ATTRIBUTES > LUID > LoPart. 158 | NumPut( NumGet( &LUID, 4, "UInt" ), &TOKPRIV, nOfft+8, "UInt" ) ; LUID_AND_ATTRIBUTES > LUID > HiPart. 159 | NumPut( arrPriv[A_Index].state, &TOKPRIV, nOfft+12, "UInt" ) ; LUID_AND_ATTRIBUTES > Attributes. 160 | nDone++ 161 | } 162 | If ( !nDone ) 163 | Throw Exception("No privileges processed.") 164 | NumPut( nDone, &TOKPRIV, 0, "UInt" ) ; TOKEN_PRIVILEGES > PrivilegeCount. 165 | } 166 | 167 | If ( !DllCall( "Advapi32.dll\AdjustTokenPrivileges", Ptr,hToken, Int,(arrPriv==0)?1:0 168 | , Ptr,(arrPriv==0)?0:&TOKPRIV, UInt,0, Ptr,0, Ptr,0 ) ) 169 | Throw Exception("Error: " A_LastError, "AdjustTokenPrivileges") 170 | } 171 | Finally { 172 | hToken ? DllCall( "CloseHandle", Ptr,hToken ) 173 | hProc ? DllCall( "CloseHandle", Ptr,hProc ) 174 | } 175 | Return nDone 176 | } 177 | 178 | ; ---------------------------------------------------------------------------------------------------------------------- 179 | ; Function .....: Auth_AdjustPrivilege 180 | ; Description ..: Enable or disable a privilege on the current script instance. 181 | ; Parameters ...: nPrivilege - Number identifying the privilege to enable/disable. 182 | ; ..............: nEnable - 1 for enabling, 0 for disabling. 183 | ; Remarks ......: These are the privileges known values: 184 | ; ..............: SeAssignPrimaryTokenPrivilege - 3 - Replace a process token 185 | ; ..............: SeAuditPrivilege - 21 - Generate audit entries 186 | ; ..............: SeBackupPrivilege - 17 - Grant all file read access (ACL Bypass) 187 | ; ..............: SeChangeNotifyPrivilege - 23 - Receive file/folder change notifications 188 | ; ..............: SeCreateGlobalPrivilege - 30 - Create global objects 189 | ; ..............: SeCreatePagefilePrivilege - 15 - Create pagefile 190 | ; ..............: SeCreatePermanentPrivilege - 16 - Create permanent shared object 191 | ; ..............: SeCreateSymbolicLinkPrivilege - 33 - Create symbolic links 192 | ; ..............: SeCreateTokenPrivilege - 2 - Create a token 193 | ; ..............: SeDebugPrivilege - 20 - Open any process (ACL Bypass) 194 | ; ..............: SeEnableDelegationPrivilege - 27 - Trust users for delegation 195 | ; ..............: SeImpersonatePrivilege - 29 - Enable thread impersonation 196 | ; ..............: SeIncreaseBasePriorityPrivilege - 14 - Increase process priority 197 | ; ..............: SeIncreaseQuotaPrivilege - 5 - Increase process memory quota 198 | ; ..............: SeIncreaseWorkingSetPrivilege - 30 - Increase process WS 199 | ; ..............: SeLoadDriverPrivilege - 10 - Load/Unload driver 200 | ; ..............: SeLockMemoryPrivilege - 4 - Lock pages in memory 201 | ; ..............: SeMachineAccountPrivilege - 6 - Create user account 202 | ; ..............: SeManageVolumePrivilege - 28 - Manage files on a volume 203 | ; ..............: SeProfileSingleProcessPrivilege - 13 - Gather process profiling info 204 | ; ..............: SeRelabelPrivilege - 32 - Modify object label 205 | ; ..............: SeRemoteShutdownPrivilege - 24 - Shutdown a remote computer 206 | ; ..............: SeRestorePrivilege - 18 - Grant all file write access (ACL Bypass) 207 | ; ..............: SeSecurityPrivilege - 8 - Manage auditying and security log 208 | ; ..............: SeShutdownPrivilege - 19 - Initiate Shutdown 209 | ; ..............: SeSyncAgentPrivilege - 26 - Use directory sync services 210 | ; ..............: SeSystemEnvironmentPrivilege - 22 - Modify firmware environment values 211 | ; ..............: SeSystemProfilePrivilege - 11 - Gather system profiling info 212 | ; ..............: SeSystemtimePrivilege - 12 - Change time 213 | ; ..............: SeTakeOwnershipPrivilege - 9 - Change object owner (ACL Bypass) 214 | ; ..............: SeTcbPrivilege - 7 - Idetify as a trusted, protected subsystem 215 | ; ..............: SeTimeZonePrivilege - 34 - Change time zone 216 | ; ..............: SeTrustedCredManAccessPrivilege - 31 - Access the Credential Manager (trusted caller) 217 | ; ..............: SeUndockPrivilege - 25 - Remove from docking station 218 | ; ..............: SeUnsolicitedInputPrivilege - 35 ? - Read unsolicited input (from terminal device) 219 | ; ---------------------------------------------------------------------------------------------------------------------- 220 | Auth_AdjustPrivilege(nPrivilege, nEnable:=1) { 221 | DllCall( "ntdll.dll\RtlAdjustPrivilege", UInt,nPrivilege, Int,nEnable, Int,0, Int,0 ) 222 | } 223 | -------------------------------------------------------------------------------- /Bin.ahk: -------------------------------------------------------------------------------- 1 | ; ---------------------------------------------------------------------------------------------------------------------- 2 | ; Name .........: Bin library 3 | ; Description ..: This library is a collection of functions that deal with binary data and numbers. 4 | ; AHK Version ..: AHK_L 1.1.13.01 x32/64 ANSI/Unicode 5 | ; License ......: WTFPL - http://www.wtfpl.net/txt/copying/ 6 | ; Changelog ....: Jan. 21, 2015 - v0.1 - First version. 7 | ; ..............: Jan. 22, 2015 - v0.1.1 - Moved Bin_GetBitmap in a separated library (BinGet). 8 | ; ..............: Feb. 20, 2016 - v0.1.2 - Added Bin_BytesView function. 9 | ; ..............: Feb. 28, 2016 - v0.1.3 - Added Bin_ToBits and Bin_FromBits functions. 10 | ; ..............: Mar. 01, 2016 - v0.1.4 - Modified Bin_ToHex and Bin_CryptToString parameters to accept the buffer 11 | ; ..............: address instead of the buffer reference itself. Size is now compulsory. 12 | ; ---------------------------------------------------------------------------------------------------------------------- 13 | 14 | ; ---------------------------------------------------------------------------------------------------------------------- 15 | ; Function .....: Bin_ToHex 16 | ; Description ..: Convert a binary buffer to a RAW hexadecimal string. 17 | ; Parameters ...: sHex - ByRef variable that will receive the buffer as hexadecimal string. 18 | ; ..............: nAdrBuf - Address of the buffer. 19 | ; ..............: nSzBuf - Size of the buffer. 20 | ; Return .......: String length. 21 | ; ---------------------------------------------------------------------------------------------------------------------- 22 | Bin_ToHex(ByRef sHex, nAdrBuf, nSzBuf) 23 | { 24 | VarSetCapacity(sHex, nSzBuf*4+32, 0) ; Try to avoid dynamic reallocation, 1 byte -> max 4 chars (0x12). 25 | f := A_FormatInteger 26 | SetFormat, Integer, Hex 27 | Loop %nSzBuf% 28 | sHex .= *nAdrBuf++ 29 | SetFormat, Integer, %f% 30 | sHex := RegExReplace(sHex, "S)x(?=.0x|.$)|0x(?=..0x|..$)") 31 | Return StrLen(sHex) 32 | } 33 | 34 | ; ---------------------------------------------------------------------------------------------------------------------- 35 | ; Function .....: Bin_FromHex 36 | ; Description ..: Convert a RAW hexadecimal string to binary data. 37 | ; Parameters ...: cBuf - Variable that will receive the binary data. 38 | ; ..............: sHex - Hexadecimal string to be converted. 39 | ; Return .......: Buffer size. 40 | ; ---------------------------------------------------------------------------------------------------------------------- 41 | Bin_FromHex(ByRef cBuf, ByRef sHex) 42 | { 43 | VarSetCapacity(cBuf, nSzBuf:=StrLen(sHex)//2, 0) 44 | Loop %nSzBuf% 45 | NumPut("0x" SubStr(sHex, 2*A_Index-1, 2), cBuf, A_Index-1, "UChar") 46 | Return nSzBuf 47 | } 48 | 49 | ; ---------------------------------------------------------------------------------------------------------------------- 50 | ; Function .....: Bin_CryptToString 51 | ; Description ..: Convert a binary buffer to a string, using the CryptBinaryToString system function. Default to hex. 52 | ; Parameters ...: sStr - ByRef variable that will receive the buffer as a string. 53 | ; ..............: nAdrBuf - Address of the buffer. 54 | ; ..............: nSzBuf - Size of the buffer. 55 | ; ..............: nFlags - Flags for the CryptBinaryToString function: http://goo.gl/huxbgT. 56 | ; Return .......: String length. 57 | ; Remarks ......: The default flag value of 0x4 return a string with a ending CRLF. So final length is 2 bytes bigger. 58 | ; ---------------------------------------------------------------------------------------------------------------------- 59 | Bin_CryptToString(ByRef sStr, nAdrBuf, nSzBuf, nFlags:=0x4) 60 | { 61 | DllCall( "Crypt32.dll\CryptBinaryToString", Ptr,nAdrBuf, UInt,nSzBuf, UInt,nFlags, Ptr,0, UIntP,nLen ) 62 | VarSetCapacity(cHex, nLen*(A_IsUnicode ? 2 : 1), 0) 63 | DllCall( "Crypt32.dll\CryptBinaryToString", Ptr,nAdrBuf, UInt,nSzBuf, UInt,nFlags, Ptr,&cHex, UIntP,nLen ) 64 | sStr := StrGet(&cHex, nLen, (A_IsUnicode ? "UTF-16" : "CP0")), cHex := "" 65 | Return nLen 66 | } 67 | 68 | ; ---------------------------------------------------------------------------------------------------------------------- 69 | ; Function .....: Bin_CryptFromString 70 | ; Description ..: Convert a string to binary data. Default from hex. 71 | ; Parameters ...: cBuf - Variable that will receive the binary data. 72 | ; ..............: sStr - String to be converted. 73 | ; ..............: nFlags - Flags for the CryptStringToBinary function: http://goo.gl/FsgBwI. 74 | ; Return .......: Buffer size. 75 | ; ---------------------------------------------------------------------------------------------------------------------- 76 | Bin_CryptFromString(ByRef cBuf, ByRef sStr, nFlags:=0x4) 77 | { 78 | DllCall( "Crypt32.dll\CryptStringToBinary", Ptr,&sStr, UInt,StrLen(sStr), UInt,nFlags 79 | , Ptr,0, UIntP,nSzBuf, Ptr,0, Ptr,0 ) 80 | VarSetCapacity(cBuf, nSzBuf) 81 | DllCall( "Crypt32.dll\CryptStringToBinary", Ptr,&sStr, UInt,StrLen(sStr), UInt,nFlags 82 | , Ptr,&cBuf, UIntP,nSzBuf, Ptr,0, Ptr,0 ) 83 | Return nSzBuf 84 | } 85 | 86 | ; ---------------------------------------------------------------------------------------------------------------------- 87 | ; Function .....: Bin_ToBits 88 | ; Description ..: Convert a integer to its binary string representation in bits. 89 | ; Parameters ...: nInt - Integer to be converted. 90 | ; ..............: nBits - Number of bits to use. 91 | ; Return .......: String containing the binary representation of the integer in bits. 92 | ; ---------------------------------------------------------------------------------------------------------------------- 93 | Bin_ToBits(nInt, nBits:=32) 94 | { 95 | Loop %nBits% 96 | sBin := nInt & 1 sBin, nInt := nInt >> 1 97 | Return sBin 98 | } 99 | 100 | ; ---------------------------------------------------------------------------------------------------------------------- 101 | ; Function .....: Bin_FromBits 102 | ; Description ..: Convert a binary string of bits to a integer. 103 | ; Parameters ...: sBin - String containing the binary representation of the integer in bits. 104 | ; Return .......: Converted integer. 105 | ; ---------------------------------------------------------------------------------------------------------------------- 106 | Bin_FromBits(sBin) 107 | { 108 | Loop % (nLen := StrLen(sBin)) 109 | nInt += ( (nBit := SubStr(sBin, nLen-(A_Index-1), 1)) == 1 ) ? 1 << A_Index-1 : 0 110 | Return nInt 111 | } 112 | 113 | ; ---------------------------------------------------------------------------------------------------------------------- 114 | ; Function .....: Bin_BytesView 115 | ; Description ..: Show a bytes view of a buffer. 116 | ; Parameters ...: nAdrBuf - Address of the buffer. 117 | ; ..............: nSzBuf - Size of the buffer. 118 | ; ..............: nCols - How many column to show in the view. Must be multiple of 8 and >= 8. 119 | ; ..............: nRows - How many rows to show in the view before the scrolling bar will appear. 120 | ; ..............: sFormat - Format of the offset: "u" for unsigned decimal int, "X" for unsigned hexadecimal int. 121 | ; ..............: nSpaces - How many spaces between bytes in the view. Must be > 0. 122 | ; ---------------------------------------------------------------------------------------------------------------------- 123 | Bin_BytesView(nAdrBuf, nSzBuf, nCols:=16, nRows:=20, sFormat:="u", nSpaces:=3) 124 | { 125 | Static IMAGE_ICON := 1 126 | , SB_VERT := 1 127 | , SB_THUMBPOSITION := 4 128 | , CRYPT_STRING_HEX := 0x0004 129 | , WM_SETICON := 0x0080 130 | , WM_KEYUP := 0x0101 131 | , WM_COMMAND := 0x0111 132 | , WM_VSCROLL := 0x0115 133 | , WM_LBUTTONUP := 0x0202 134 | , EM_GETSEL := 0x00B0 135 | , EM_LINELENGTH := 0x00C1 136 | , EM_SETLIMITTEXT := 0x00C5 137 | , EN_VSCROLL := 0x0602 138 | , hEdit1, hEdit2, sOfftFormat, nByteLen, nHdrCols, nRowLen 139 | , cbSubclassProc := RegisterCallback("Bin_BytesView",, 6) 140 | 141 | If ( sFormat == hEdit2 ) 142 | { ; Subclass call to catch scrollbar thumb scrolling and calculate offset. 143 | If ( nSzBuf == WM_VSCROLL ) 144 | DllCall( "PostMessage", Ptr,hEdit1, UInt,WM_VSCROLL, Ptr,nCols, Ptr,nRows ) 145 | If ( nSzBuf == WM_LBUTTONUP || nSzBuf == WM_KEYUP ) 146 | { 147 | DllCall( "SendMessage", Ptr,hEdit2, UInt,EM_GETSEL, UIntP,nStart, UIntP,nEnd ) 148 | nOfft := ((nStart // nRowLen) * nHdrCols) + (Mod(nStart, nRowLen) // nByteLen) 149 | GuiControl, _BV:, Static1, % "Offset: " Format("{1:02" sOfftFormat "}" , nOfft) 150 | } 151 | Return DllCall( "DefSubclassProc", Ptr,nAdrBuf, UInt,nSzBuf, Ptr,nCols, Ptr,nRows ) 152 | } 153 | 154 | If ( nCols == WM_COMMAND ) 155 | { ; OnMessage call to catch scrolling. It doesn't notify of thumb scrolling. 156 | If ( nAdrBuf >> 16 == EN_VSCROLL ) 157 | nPos := DllCall( "GetScrollPos", Ptr,hEdit2, Int,SB_VERT ) 158 | , DllCall( "PostMessage", Ptr,hEdit1, UInt,WM_VSCROLL, Ptr,(nPos<<16)+SB_THUMBPOSITION, Ptr,0 ) 159 | Return 160 | } 161 | 162 | Else 163 | { ; Normal function call. 164 | If ( !nSzBuf || nSzBuf + 0 != nSzBuf || Mod(nCols, 8) != 0 || nSpaces < 1 ) 165 | { ; Ensures parameters integrity and a column size no less than 8. 166 | MsgBox, 0x10, BytesView, Wrong parameter(s)? 167 | Return 168 | } ( nSzBuf <= 8 ) ? nCols := 8 169 | 170 | ; Strings population (offset column, offset header and bytes dump view). 171 | sSpaces := Format("{1:" nSpaces "s}", A_Space) 172 | Loop % Ceil(nSzBuf / nCols) 173 | sOffsetCol .= Format("{1:0" StrLen(nSzBuf) sFormat "}", (A_Index-1)*nCols) "`n" 174 | Loop %nCols% 175 | sOffsetHdr .= Format("{1:02" sFormat "}" , A_Index-1) (( A_Index != nCols ) ? sSpaces : "") 176 | Loop %nSzBuf% 177 | sDump .= Format("{1:02X}", NumGet(nAdrBuf+0, A_Index-1, "UChar")) 178 | . (( Mod(A_Index, nCols) != 0 ) ? sSpaces : "`n") 179 | sDump := RTrim(sDump) 180 | 181 | Gui, _BV: +HwndhWnd 182 | Gui, _BV: Color, 909090 183 | Gui, _BV: Font, s8, Courier New ; Fallback font. 184 | Gui, _BV: Font, s8, Consolas ; Preferred font (available only on OS > Vista). 185 | Gui, _BV: Margin, 5, 5 186 | Gui, _BV: Add, Edit, ym+21 r%nRows% HwndhEdit1 -E0x200 ReadOnly -VScroll, %sOffsetCol% 187 | Gui, _BV: Add, Edit, x+5 ym+21 r%nRows% HwndhEdit2 -E0x200 +WantTab Section, %sOffsetHdr% 188 | GuiControlGet, nE1Pos, _BV: Pos, Edit1 189 | GuiControlGet, nE2Pos, _BV: Pos, Edit2 190 | Gui, _BV: Add, Text, % "w" nE2PosW - 95 " xs y+5 HwndhText1", Offset: 00 191 | Gui, _BV: Add, Button, w90 x+5 -Theme +0x8000, &Close 192 | Gui, _BV: Add, Edit, % "w" nE2PosW " xm+" nE1PosW + 5 " ym -E0x200 ReadOnly -VScroll", %sOffsetHdr% 193 | 194 | GuiControl, _BV:, Edit2, %sDump% ; Workaround edit control memory allocation limit. 195 | GuiControl, _BV: Focus, Edit2 ; Set focus on the bytes view. 196 | DllCall( "PostMessage", Ptr,hEdit2, UInt,EM_SETLIMITTEXT, Ptr,1, Ptr,0 ) ; Disable text editing. 197 | 198 | ; Set window and taskbar/alt-tab icon. 199 | hIcon := DllCall( "LoadImage", Ptr,DllCall("GetModuleHandle",Str,"Shell32.dll") 200 | , Ptr,13, UInt,IMAGE_ICON, Int,32, Int,32, UInt,0 ) 201 | d := A_DetectHiddenWindows 202 | DetectHiddenWindows, On 203 | SendMessage, WM_SETICON, 0, hIcon,, ahk_id %hWnd% 204 | SendMessage, WM_SETICON, 1, hIcon,, ahk_id %hWnd% 205 | DetectHiddenWindows, %d% 206 | 207 | ; The EN_VSCROLL notification code is sent through the WM_COMMAND message, so we monitor it to get 208 | ; notification about scrolling with mousewheel, keyboard and scrollbar arrows. This notification 209 | ; is not sent when scrolling through the scrollbar thumb, so we need to subclass the edit control 210 | ; to make it work. We use subclassing also for offset calculation so we set the required static 211 | ; variables to be used when receiving the subclass call. 212 | sOfftFormat := sFormat, nByteLen := nSpaces + 2, nHdrCols := nCols, nRowLen := (nByteLen * (nCols-1)) + 4 213 | DllCall( "SetWindowSubclass", Ptr,hEdit2, Ptr,cbSubclassProc, Ptr,hEdit2, Ptr,0 ) 214 | OnMessage(WM_COMMAND, A_ThisFunc) 215 | 216 | Gui, _BV: Show,, BytesView 217 | WinWaitClose ; Prevent early return. 218 | Return 219 | 220 | _BVBUTTONCLOSE: 221 | DllCall( "RemoveWindowSubclass", Ptr,hEdit2, Ptr,cbSubclassProc, Ptr,hEdit2 ) 222 | Gui, _BV: Destroy 223 | Return 224 | ;_BVBUTTONCLOSE 225 | } 226 | } 227 | -------------------------------------------------------------------------------- /BinGet.ahk: -------------------------------------------------------------------------------- 1 | ; ---------------------------------------------------------------------------------------------------------------------- 2 | ; Name .........: BinGet library 3 | ; Description ..: This library is a collection of functions that return different kind of data from binary buffers. 4 | ; AHK Version ..: AHK_L 1.1.13.01 x32/64 ANSI/Unicode 5 | ; Author .......: Cyruz - http://ciroprincipe.info 6 | ; License ......: WTFPL - http://www.wtfpl.net/txt/copying/ 7 | ; Changelog ....: Jan. 22, 2015 - v0.1 - First version. 8 | ; ..............: Jul. 30, 2015 - v0.1.1 - Added error management. 9 | ; ---------------------------------------------------------------------------------------------------------------------- 10 | 11 | ; ---------------------------------------------------------------------------------------------------------------------- 12 | ; Function .....: BinGet_Bitmap 13 | ; Description ..: Create a bitmap from a binary buffer and return a handle to it. 14 | ; Parameters ...: adrBuf - Pointer to the binary data buffer containing the bitmap. 15 | ; ..............: szBuf - Size of the buffer. 16 | ; Return .......: Handle to the bitmap on success, 0 on error. 17 | ; Code from ....: SKAN - http://goo.gl/iknYZB 18 | ; ---------------------------------------------------------------------------------------------------------------------- 19 | BinGet_Bitmap(adrBuf, szBuf) 20 | { 21 | If ( hGlob := DllCall( "GlobalAlloc", UInt,2, UInt,szBuf, Ptr ) ) ; GMEM_MOVEABLE = 2 22 | pGlob := DllCall( "GlobalLock", Ptr,hGlob, Ptr ) 23 | , DllCall( "RtlMoveMemory", Ptr,pGlob, Ptr,adrBuf, UInt,szBuf ) 24 | , DllCall( "GlobalUnlock", Ptr,hGlob ) 25 | Else Return 0, ErrorLevel := "GlobalAlloc: error allocating memory`nLast error = " A_LastError 26 | 27 | If ( ( e := DllCall( "ole32.dll\CreateStreamOnHGlobal", Ptr,hGlob, Int,1, PtrP,pStream ) ) != 0 ) 28 | Return 0, ErrorLevel := "CreateStreamOnHGlobal: error creating stream`nReturn value = " e 29 | 30 | If ( hGdip := DllCall( "LoadLibrary", Str,"Gdiplus.dll" ) ) 31 | { 32 | VarSetCapacity( si, 16, 0 ), NumPut( 1, si, "UChar" ) 33 | If ( ( e := DllCall( "Gdiplus.dll\GdiplusStartup", PtrP,gdipToken, Ptr,&si, Ptr,0 ) ) == 0 ) 34 | DllCall( "Gdiplus.dll\GdipCreateBitmapFromStream", Ptr,pStream, PtrP,pBitmap ) 35 | , DllCall( "Gdiplus.dll\GdipCreateHBITMAPFromBitmap", Ptr,pBitmap, PtrP,hBitmap, UInt,0 ) 36 | , DllCall( "Gdiplus.dll\GdipDisposeImage", Ptr,pBitmap ) 37 | , DllCall( "Gdiplus.dll\GdiplusShutdown", Ptr,gdipToken ) 38 | Else Return 0, ErrorLevel := "GdiplusStartup: error starting Gdiplus`nReturn value = " e 39 | 40 | DllCall( "FreeLibrary", Ptr,hGdip ) 41 | } Else Return 0, ErrorLevel := "LoadLibrary: error loading Gdiplus.dll`nLast error = " A_LastError 42 | 43 | ObjRelease(pStream) 44 | Return hBitmap ? hBitmap : 0 45 | } 46 | 47 | ; ---------------------------------------------------------------------------------------------------------------------- 48 | ; Function .....: BinGet_Icon 49 | ; Description ..: Create an icon from a binary buffer and return a handle to it. 50 | ; Parameters ...: adrBuf - Pointer to the binary data buffer containing the icon. 51 | ; ..............: nIconWidth - Width of the desired icon (used to retrieve the icon inside a multi-icon file). 52 | ; ..............: szBuf - If the buffer contains raw, single icon data, we can specify its size and avoid data 53 | ; ..............: structure parsing. This can be useful when loading icon resources (type 3) from PE files. 54 | ; Return .......: Handle to the icon on success, 0 on error. 55 | ; Remarks ......: The function is based on the implicit structure of an icon file (.ico): 56 | ; ..............: ICONDIR structure: 57 | ; ..............: { sizeof(ICONDIR) = 6 + sizeof(ICONDIRENTRY) * n 58 | ; ..............: Offset Type Name Description 59 | ; ..............: 00 WORD idReserved // Reserved (must be 0). 60 | ; ..............: 02 WORD idType // Resource type (1 for icons). 61 | ; ..............: 04 WORD idCount // How many images? 62 | ; ..............: 06 ICONDIRENTRY idEntries[n] // The entries for each icon. 63 | ; ..............: } 64 | ; ..............: ICONDIRENTRY structure: 65 | ; ..............: { sizeof(ICONDIRENTRY) = 16 66 | ; ..............: Offset Type Name Description 67 | ; ..............: 06 BYTE bWidth; // Width, in pixels, of the image. 68 | ; ..............: 07 BYTE bHeight; // Height, in pixels, of the image. 69 | ; ..............: 08 BYTE bColorCount; // Number of colors in image (0 if >=8bpp). 70 | ; ..............: 09 BYTE bReserved; // Reserved. 71 | ; ..............: 10 WORD wPlanes; // Color Planes. 72 | ; ..............: 12 WORD BitCount; // Bits per pixel. 73 | ; ..............: 14 DWORD dwBytesInRes; // How many bytes in this resource? 74 | ; ..............: 18 DWORD dwImageOffset; // Where in the file is this image? 75 | ; ..............: } 76 | ; Info .........: CreateIconFromResourceEx function - https://goo.gl/Fij4ZA 77 | ; ---------------------------------------------------------------------------------------------------------------------- 78 | BinGet_Icon(adrBuf, nIconWidth, szBuf:=0) 79 | { 80 | If ( !szBuf ) 81 | { 82 | Loop % NumGet( adrBuf+0, 4, "UShort" ) 83 | { 84 | nOfft := 6 + 16*(A_Index-1) 85 | If ( NumGet( adrBuf+0, nOfft, "UChar" ) == nIconWidth ) 86 | { 87 | szBuf := NumGet( adrBuf+0, nOfft+8, "UInt" ) 88 | adrBuf += NumGet( adrBuf+0, nOfft+12, "UInt" ) 89 | Break 90 | } 91 | } 92 | } 93 | ; VERSION = 0x30000 94 | Return DllCall( "CreateIconFromResourceEx", Ptr,adrBuf, UInt,szBuf, Int,1, UInt,0x30000 95 | , Int,nIconWidth, Int,nIconWidth, UInt,0 ) 96 | } 97 | -------------------------------------------------------------------------------- /ColURL.ahk: -------------------------------------------------------------------------------- 1 | ; ---------------------------------------------------------------------------------------------------------------------- 2 | ; Name .........: URL & HTML collection 3 | ; Description ..: Various functions dealing with URLs and HTML code. 4 | ; AHK Version ..: AHK_L 1.1.13.01 x32/64 Ansi/Unicode 5 | ; Author .......: Cyruz (http://ciroprincipe.info) 6 | ; License ......: WTFPL - http://www.wtfpl.net/txt/copying/ 7 | ; Changelog ....: Apr. 06, 2014 - v0.1 - First version. 8 | ; ---------------------------------------------------------------------------------------------------------------------- 9 | 10 | ; ---------------------------------------------------------------------------------------------------------------------- 11 | ; Function .....: ColURL_OpenURL 12 | ; Description ..: Open an URL and return the server response. 13 | ; Parameters ...: sURL - String containing the URL to open. 14 | ; Return .......: Server response as a string. 15 | ; ---------------------------------------------------------------------------------------------------------------------- 16 | ColURL_OpenURL(sURL) { 17 | hMod := DllCall( "Kernel32.dll\LoadLibrary", Str,"Wininet.dll" ) 18 | hInet := DllCall( "Wininet.dll\InternetOpen", Str,"AutoHotkey", UInt,0, Str,"", Str,"", UInt,0 ) 19 | hURL := DllCall( "Wininet.dll\InternetOpenUrl", Ptr,hInet, Str,sURL, Str,"", Int,0, UInt,0x80000000, UInt,0 ) 20 | VarSetCapacity(cBuf, 1024, 0), VarSetCapacity(nRead, 4, 0) 21 | 22 | Loop 23 | { 24 | bFlag := DllCall( "Wininet.dll\InternetReadFile", Ptr,hURL, Ptr,&cBuf, UInt,1024, Ptr,&nRead ) 25 | szBuf := NumGet(nRead) 26 | If ( (bFlag) && (!szBuf) ) 27 | Break 28 | sRetStr := sRetStr . StrGet(&cBuf, szBuf, A_FileEncoding) 29 | } 30 | 31 | DllCall( "Wininet.dll\InternetCloseHandle", Ptr,hInet ) 32 | DllCall( "Wininet.dll\InternetCloseHandle", Ptr,hURL ) 33 | DllCall( "Kernel32.dll\FreeLibrary", Ptr,hMod ) 34 | Return sRetStr 35 | } 36 | 37 | ; ---------------------------------------------------------------------------------------------------------------------- 38 | ; Function .....: ColURL_ComUrl2Mhtml 39 | ; Description ..: Creates a MHTML file from the given URL. 40 | ; Parameters ...: sURL - Working URL. 41 | ; ..............: sDestPath - Destination file path. 42 | ; ..............: nFlags - MHTML flags, it can be the OR of the followings: 43 | ; ..............: CdoSuppressImages := 1 44 | ; ..............: CdoSuppressBGSounds := 2 45 | ; ..............: CdoSuppressFrames := 4 46 | ; ..............: CdoSuppressObjects := 8 47 | ; ..............: CdoSuppressStyleSheets := 16 48 | ; ..............: CdoSuppressAll := 31 49 | ; ..............: (leave it empty to suppress nothing) 50 | ; ---------------------------------------------------------------------------------------------------------------------- 51 | ColURL_ComUrl2Mhtml(sURL, sDestPath="", nFlags=0) { 52 | objIMsg := ComObjCreate("{CD000001-8B95-11D1-82DB-00C04FB1625D}") ; IMessage Interface 53 | objIMsg.CreateMHTMLBody(sURL, nFlags) 54 | objIMsg.GetStream().SaveToFile((sDestPath) ? sDestPath : A_WorkingDir . "\url.mht", 2) ; adSaveCreateOverWrite = 2 55 | } 56 | 57 | ; ---------------------------------------------------------------------------------------------------------------------- 58 | ; Function .....: ColURL_ComUnHtml 59 | ; Description ..: Strips the html tags from the given string. 60 | ; Parameters ...: sHtml - String containing the html code. 61 | ; Return .......: String without html tags. 62 | ; ---------------------------------------------------------------------------------------------------------------------- 63 | ColURL_ComUnHthml(sHtml) { 64 | objHtml := ComObjCreate("HtmlFile") 65 | objHtml.Write(sHtml) 66 | Return objHtml.documentElement.innerText 67 | } 68 | -------------------------------------------------------------------------------- /DLLPack.ahk: -------------------------------------------------------------------------------- 1 | /* 2 | +-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+ +-+-+-+ +-+-+-+-+-+-+-+-+ 3 | |R|e|s|o|u|r|c|e|-|O|n|l|y| |D|L|L| |f|o|r| |D|u|m|m|i|e|s|!| 4 | +-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+ +-+-+-+ +-+-+-+-+-+-+-+-+ 5 | 6 | - Humble 36L wrapper to create and use DLL resources in AutoHotkey Scripting Language - 7 | 8 | By SKAN - Suresh Kumar A N ( arian.suresh@gmail.com ) 9 | Created: 05-Sep-2010 / Last Modified: 01-Jun-2011 / Version: 0.7u 10 | 11 | For usage, please refer Forum Topic: www.autohotkey.com/forum/viewtopic.php?t=62180 12 | 13 | */ 14 | 15 | 16 | DllPackFiles( Folder, DLL, Section="Files" ) { 17 | IfNotExist,%DLL%, SetEnv,DLL,% DLLCreateEmpty( DLL ) 18 | VarSetCapacity(Bin,64,Ix:=0) 19 | If hUPD := DllCall( "BeginUpdateResource", Str,DLL, Int,0 ) 20 | Loop, %Folder%\*.* { 21 | VarSetCapacity( Bin,0 ) 22 | FileRead, Bin, *c %A_LoopFileLongPath% 23 | If nSize := VarSetCapacity(Bin) 24 | DllCall( "UpdateResource", UInt,hUpd, Str,DllCall( "CharUpper", Str,Section, Str ), Str 25 | ,DllCall( "CharUpper", Str,A_LoopFileName, Str ), Int,0, UInt,&Bin, UInt,nSize ),Ix:=Ix+1 26 | } Return Ix, DllCall( "EndUpdateResource", UInt,hUpd, Int,0 ) 27 | } 28 | 29 | 30 | DllCreateEmpty( F="empty.dll" ) { ; www.autohotkey.com/forum/viewtopic.php?p=381161#381161 31 | ; Creates Empty Resource-Only DLL (1024 bytes) / CD:05-Sep-2010 | LM:01-Jun-2011 - by SKAN 32 | IfNotEqual,A_Tab, % TS:=A_NowUTC, EnvSub,TS,1970,S 33 | Src := "0X5A4DY3CXC0YC0X4550YC4X1014CYD4X210E00E0YD8XA07010BYE0X200YECX1000YF0X1000YF4X1" 34 | . "0000YF8X1000YFCX200Y100X4Y108X4Y110X2000Y114X200Y11CX4000003Y120X40000Y124X1000Y128X1" 35 | . "00000Y12CX1000Y134X10Y148X1000Y14CX10Y1B8X7273722EY1BCX63Y1C0X10Y1C4X1000Y1C8X200Y1CC" 36 | . "X200Y1DCX40000040", VarSetCapacity( Trg,1024,0 ), Numput( TS,Trg,200 ), DA:=0x40000000 37 | Loop, Parse, Src, XY 38 | Mod( A_Index,2 ) ? O := "0x" A_LoopField : NumPut( "0x" A_LoopField, Trg, O ) 39 | If ( hF := DllCall( "CreateFile", Str,F, UInt,DA, UInt,2,Int,0,UInt,2,Int,0,Int,0 ) ) > 0 40 | B := DllCall( "_lwrite", UInt,hF,Str,Trg,UInt,1024 ), DllCall( "CloseHandle",UInt,hF ) 41 | Loop %F% 42 | Return B ? A_LoopFileLongPath : 43 | } 44 | 45 | 46 | DllRead( ByRef Var, Filename, Section, Key ) { ; Functionality and Parameters are 47 | VarSetCapacity( Var,64 ), VarSetCapacity( Var,0 ) ; identical to IniRead command ;-) 48 | If hMod := DllCall( "LoadLibrary", Str,Filename ) 49 | If hRes := DllCall( "FindResource", UInt,hMod, Str,Key, Str,Section ) 50 | If hData := DllCall( "LoadResource", UInt,hMod, UInt,hRes ) 51 | If pData := DllCall( "LockResource", UInt,hData ) 52 | Return VarSetCapacity( Var,nSize := DllCall( "SizeofResource", UInt,hMod, UInt,hRes ),32) 53 | , DllCall( "RtlMoveMemory", UInt,&Var, UInt,pData, UInt,nSize ) 54 | , DllCall( "FreeLibrary", UInt,hMod ) 55 | Return DllCall( "FreeLibrary", UInt,hMod ) >> 32 56 | } -------------------------------------------------------------------------------- /EWinHook.ahk: -------------------------------------------------------------------------------- 1 | ; ---------------------------------------------------------------------------------------------------------------------- 2 | ; Name .........: EWinHook library 3 | ; Description ..: Implement the SetWinEventHook Win32 API. 4 | ; AHK Version ..: AHK_L 1.1.13.01 x32 Unicode 5 | ; Author .......: Cyruz - http://ciroprincipe.info 6 | ; License ......: WTFPL - http://www.wtfpl.net/txt/copying/ 7 | ; Changelog ....: Nov. 20, 2013 - v0.1 - First revision. 8 | ; ---------------------------------------------------------------------------------------------------------------------- 9 | 10 | ; ---------------------------------------------------------------------------------------------------------------------- 11 | ; Function .....: EWinHook_SetWinEventHook 12 | ; Description ..: Sets an event hook function for a range of events. 13 | ; Parameters ...: eventMin - Lowest event constant to handle. Pass the name as a string (eg: "EVENT_MIN"). 14 | ; ..............: eventMax - Highest event constant to handle. Pass the name as a string (eg: "EVENT_MAX"). 15 | ; ..............: hmodWinEventProc - Handle to the DLL containing the hook function at lpfnWinEventProc or NULL. 16 | ; ..............: lpfnWinEventProc - Name or pointer to the hook function. Must be a WinEventProc callback function. 17 | ; ..............: idProcess - PID from which the hook will receive events or 0 for all desktop process. 18 | ; ..............: idThread - Thread ID from which the hook will receive events or 0 for all desktop threads. 19 | ; ..............: dwflags - Flag values specifying hook location and events to skip. Specify the value or 20 | ; ..............: the combination of values as a string. The accepted values are: 21 | ; ..............: "WINEVENT_INCONTEXT" 22 | ; ..............: "WINEVENT_INCONTEXT | WINEVENT_SKIPOWNPROCESS" 23 | ; ..............: "WINEVENT_INCONTEXT | WINEVENT_SKIPOWNTHREAD" 24 | ; ..............: "WINEVENT_OUTOFCONTEXT" 25 | ; ..............: "WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS" 26 | ; ..............: "WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNTHREAD" 27 | ; Return .......: -1 - CoInitialize error. Check A_LastError error code: 28 | ; ..............: E_INVALIDARG = 0x80070057 29 | ; ..............: E_OUTOFMEMORY = 0x8007000E 30 | ; ..............: E_UNEXPECTED = 0x8000FFFF 31 | ; ..............: 0 - Parameters or SetWinEventHook error. 32 | ; ..............: HWINEVENTHOOK - Value identifying the event hook instance. 33 | ; Remarks ......: Remember to create a WinEventProc callback function to take care of all the messages. 34 | ; ..............: A_LastError is set also in case of success of CoInitialize. 35 | ; ..............: The possible success values are: S_OK = 0x00000000 36 | ; ..............: S_FALSE = 0x00000001 37 | ; ..............: RPC_E_CHANGED_MODE = 0x80010106 38 | ; Info .........: CoInitialize - http://goo.gl/UhCKNo 39 | ; ..............: SetWinEventHook - http://goo.gl/DosZa9 40 | ; ..............: WinEventProc - http://goo.gl/wUZU08 41 | ; ---------------------------------------------------------------------------------------------------------------------- 42 | EWinHook_SetWinEventHook(eventMin, eventMax, hmodWinEventProc, lpfnWinEventProc, idProcess, idThread, dwflags) { 43 | Static S_OK := 0x00000000, S_FALSE := 0x00000001 44 | , RPC_E_CHANGED_MODE := 0x80010106, E_INVALIDARG := 0x80070057 45 | , E_OUTOFMEMORY := 0x8007000E, E_UNEXPECTED := 0x8000FFFF 46 | , EVENT_MIN := 0x00000001, EVENT_MAX := 0x7FFFFFFF 47 | , EVENT_SYSTEM_SOUND := 0x0001, EVENT_SYSTEM_ALERT := 0x0002 48 | , EVENT_SYSTEM_FOREGROUND := 0x0003, EVENT_SYSTEM_MENUSTART := 0x0004 49 | , EVENT_SYSTEM_MENUEND := 0x0005, EVENT_SYSTEM_MENUPOPUPSTART := 0x0006 50 | , EVENT_SYSTEM_MENUPOPUPEND := 0x0007, EVENT_SYSTEM_CAPTURESTART := 0x0008 51 | , EVENT_SYSTEM_CAPTUREEND := 0x0009, EVENT_SYSTEM_MOVESIZESTART := 0x000A 52 | , EVENT_SYSTEM_MOVESIZEEND := 0x000B, EVENT_SYSTEM_CONTEXTHELPSTART := 0x000C 53 | , EVENT_SYSTEM_CONTEXTHELPEND := 0x000D, EVENT_SYSTEM_DRAGDROPSTART := 0x000E 54 | , EVENT_SYSTEM_DRAGDROPEND := 0x000F, EVENT_SYSTEM_DIALOGSTART := 0x0010 55 | , EVENT_SYSTEM_DIALOGEND := 0x0011, EVENT_SYSTEM_SCROLLINGSTART := 0x0012 56 | , EVENT_SYSTEM_SCROLLINGEND := 0x0013, EVENT_SYSTEM_SWITCHSTART := 0x0014 57 | , EVENT_SYSTEM_SWITCHEND := 0x0015, EVENT_SYSTEM_MINIMIZESTART := 0x0016 58 | , EVENT_SYSTEM_MINIMIZEEND := 0x0017, EVENT_SYSTEM_DESKTOPSWITCH := 0x0020 59 | , EVENT_SYSTEM_END := 0x00FF, EVENT_OEM_DEFINED_START := 0x0101 60 | , EVENT_OEM_DEFINED_END := 0x01FF, EVENT_UIA_EVENTID_START := 0x4E00 61 | , EVENT_UIA_EVENTID_END := 0x4EFF, EVENT_UIA_PROPID_START := 0x7500 62 | , EVENT_UIA_PROPID_END := 0x75FF, EVENT_CONSOLE_CARET := 0x4001 63 | , EVENT_CONSOLE_UPDATE_REGION := 0x4002, EVENT_CONSOLE_UPDATE_SIMPLE := 0x4003 64 | , EVENT_CONSOLE_UPDATE_SCROLL := 0x4004, EVENT_CONSOLE_LAYOUT := 0x4005 65 | , EVENT_CONSOLE_START_APPLICATION := 0x4006, EVENT_CONSOLE_END_APPLICATION := 0x4007 66 | , EVENT_CONSOLE_END := 0x40FF, EVENT_OBJECT_CREATE := 0x8000 67 | , EVENT_OBJECT_DESTROY := 0x8001, EVENT_OBJECT_SHOW := 0x8002 68 | , EVENT_OBJECT_HIDE := 0x8003, EVENT_OBJECT_REORDER := 0x8004 69 | , EVENT_OBJECT_FOCUS := 0x8005, EVENT_OBJECT_SELECTION := 0x8006 70 | , EVENT_OBJECT_SELECTIONADD := 0x8007, EVENT_OBJECT_SELECTIONREMOVE := 0x8008 71 | , EVENT_OBJECT_SELECTIONWITHIN := 0x8009, EVENT_OBJECT_STATECHANGE := 0x800A 72 | , EVENT_OBJECT_LOCATIONCHANGE := 0x800B, EVENT_OBJECT_NAMECHANGE := 0x800C 73 | , EVENT_OBJECT_DESCRIPTIONCHANGE := 0x800D, EVENT_OBJECT_VALUECHANGE := 0x800E 74 | , EVENT_OBJECT_PARENTCHANGE := 0x800F, EVENT_OBJECT_HELPCHANGE := 0x8010 75 | , EVENT_OBJECT_DEFACTIONCHANGE := 0x8011, EVENT_OBJECT_ACCELERATORCHANGE := 0x8012 76 | , EVENT_OBJECT_INVOKED := 0x8013, EVENT_OBJECT_TEXTSELECTIONCHANGED := 0x8014 77 | , EVENT_OBJECT_CONTENTSCROLLED := 0x8015, EVENT_SYSTEM_ARRANGMENTPREVIEW := 0x8016 78 | , EVENT_OBJECT_END := 0x80FF, EVENT_AIA_START := 0xA000 79 | , EVENT_AIA_END := 0xAFFF, WINEVENT_OUTOFCONTEXT := 0x0000 80 | , WINEVENT_SKIPOWNTHREAD := 0x0001, WINEVENT_SKIPOWNPROCESS := 0x0002 81 | , WINEVENT_INCONTEXT := 0x0004 82 | 83 | ; eventMin/eventMax check 84 | If ( !%eventMin% || !%eventMax% ) 85 | Return 0 86 | 87 | ; dwflags check 88 | If ( !RegExMatch( dwflags 89 | , "S)^\s*(WINEVENT_(?:INCONTEXT|OUTOFCONTEXT))\s*\|\s*(WINEVENT_SKIPOWN(?:PROCESS|" 90 | . "THREAD))[^\S\n\r]*$|^\s*(WINEVENT_(?:INCONTEXT|OUTOFCONTEXT))[^\S\n\r]*$" 91 | , dwfArray ) ) 92 | Return 0 93 | dwflags := (dwfArray1 && dwfArray2) ? %dwfArray1% | %dwfArray2% : %dwfArray3% 94 | 95 | nCheck := DllCall( "CoInitialize", Ptr,0 ) 96 | DllCall( "SetLastError", UInt,nCheck ) ; SetLastError in case of success/error 97 | 98 | If ( nCheck == E_INVALIDARG || nCheck == E_OUTOFMEMORY || nCheck == E_UNEXPECTED ) 99 | Return -1 100 | 101 | If ( isFunc(lpfnWinEventProc) ) 102 | lpfnWinEventProc := RegisterCallback(lpfnWinEventProc) 103 | 104 | hWinEventHook := DllCall( "SetWinEventHook", UInt,%eventMin%, UInt,%eventMax%, Ptr,hmodWinEventProc 105 | , Ptr,lpfnWinEventProc, UInt,idProcess, UInt,idThread, UInt,dwflags ) 106 | Return (hWinEventHook) ? hWinEventHook : 0 107 | } 108 | 109 | ; ---------------------------------------------------------------------------------------------------------------------- 110 | ; Function .....: EWinHook_UnhookWinEvent 111 | ; Description ..: Remove a previously istantiated hook. 112 | ; Parameters ...: hWinEventHook - Handle to the event hook returned in the previous call to SetWinEventHook. 113 | ; Return .......: 1 - Success 114 | ; ..............: 0 - Error 115 | ; Info .........: UnhookWinEvent - http://goo.gl/9dDjE3 116 | ; ..............: CoUninitialize - http://goo.gl/bWYQ2a 117 | ; Changelog ....: Nov. 20, 2013 - v0.1 - First revision. 118 | ; ---------------------------------------------------------------------------------------------------------------------- 119 | EWinHook_UnhookWinEvent(hWinEventHook) { 120 | nCheck := DllCall( "UnhookWinEvent", Ptr,hWinEventHook ) 121 | DllCall( "CoUninitialize" ) 122 | Return nCheck 123 | } 124 | 125 | /* EXAMPLE CODE: 126 | hHook := EWinHook_SetWinEventHook( "EVENT_OBJECT_CREATE", "EVENT_OBJECT_DESTROY", 0, "WinProcCallback", 0, 0 127 | , "WINEVENT_OUTOFCONTEXT" ) 128 | Run, calc.exe 129 | Sleep, 3000 130 | Process, Close, calc.exe 131 | EWinHook_UnhookWinEvent(hHook) 132 | Return 133 | 134 | WinProcCallback(hWinEventHook, event, hwnd, idObject, idChild, dwEventThread, dwmsEventTime) { 135 | DetectHiddenWindows, On 136 | WinGetClass, sClass, ahk_id %hwnd% 137 | If ( sClass == "CalcFrame" ) 138 | FileAppend, 139 | ( LTrim 140 | hWinEventHook: %hWinEventHook% 141 | hwnd: %hwnd% 142 | idObject: %idObject% 143 | idChild: %idChild% 144 | dwEventThread: %dwEventThread% 145 | dwmsEventTime: %dwmsEventTime%`n`n 146 | ), test.txt 147 | } 148 | */ -------------------------------------------------------------------------------- /ExcelToObj.ahk: -------------------------------------------------------------------------------- 1 | ; Function: ExcelToObj 2 | ; Author: tmplinshi 3 | ; Tested On: AHK: 1.1.14.03 U32 | OS: WinXP_SP3 | Microsoft Excel: 2010 4 | ; ================================================================= 5 | ; Parameters: 6 | ; ExcelFile - Path to xls/xlsx file 7 | ; ResultObj - Structure is [ [], [], ... ] 8 | ; Format - Can be "csv" (default) or "html" 9 | ExcelToObj(ExcelFile, ByRef ResultObj, Format = "csv") { 10 | static xlCSV := 6, xlHTML := 44 11 | 12 | ; Make sure ExcelFile is fullpath 13 | Loop, % ExcelFile 14 | ExcelFile := A_LoopFileLongPath 15 | 16 | ; Temp files 17 | If (Format = "html") { 18 | TempDir := A_Temp "\.ExcelToObj." A_Now 19 | TempFile := TempDir "\1.html" 20 | FileRemoveDir, % TempDir, 1 21 | FileCreateDir, % TempDir 22 | } 23 | Else 24 | TempFile := A_Temp "\.ExcelToObj." A_Now ".csv" 25 | 26 | ; Convert excel file to csv or html 27 | oExcel := ComObjCreate("Excel.Application") 28 | oExcel.Workbooks.Open(ExcelFile) 29 | oExcel.Visible := False 30 | oExcel.DisplayAlerts := False 31 | oExcel.ActiveWorkbook.SaveAs( TempFile, (Format = "html") ? xlHTML : xlCSV ) 32 | oExcel.Quit() 33 | 34 | ; Extract data 35 | If (Format = "html") { 36 | ; 37 | ; Read stylesheet.css 38 | ; 39 | FileRead, content, % TempDir "\1.files\stylesheet.css" 40 | content := RegExReplace(content, "m`a)^\.") 41 | content := RegExReplace(content, "\bfont-family:.*?;") 42 | content := RegExReplace(content, "\s") 43 | 44 | Pos := 1, style := [] 45 | While ( Pos := RegExMatch(content, "([^{]+){(.*?)}", Match, Pos + StrLen(Match)) ) 46 | style[Match1] := Match2 47 | 48 | ; 49 | ; Read sheet001.html 50 | ; 51 | FileRead, html, % TempDir "\1.files\sheet001.html" 52 | 53 | ; Replace class="..." to style="..." 54 | For ClassName, style_value in style 55 | StringReplace, html, html, % "class=""" ClassName """", % "style=""" style_value """", All 56 | 57 | ; Save html data to object 58 | ResultObj := [], Pos := 1 59 | While ( Pos := RegExMatch(html, "si)", tr_data, Pos + StrLen(tr_data)) ) { 60 | tr_data := RegExReplace(tr_data, "(<\w+[^\r\n>]+)[\r\n]+\s*", "$1 ") 61 | 62 | obj_td := [], Pos2 := 1, td_list := "" 63 | While ( Pos2 := RegExMatch(tr_data, "si)(.*?)", td_data, Pos2 + StrLen(td_data)) ) 64 | td_list .= td_data1, obj_td.Insert(td_data1) 65 | 66 | If ( Trim(td_list, " `t`r`n") != "" ) ; Exclude empty rows 67 | ResultObj.Insert( obj_td ) 68 | } 69 | 70 | FileRemoveDir, % TempDir, 1 71 | } 72 | Else ; If (Format = "csv") 73 | { 74 | FileRead, content, % TempFile 75 | content := RegExReplace(content, "m`a)^[, \t]+$") 76 | content := Trim(content, "`r`n") 77 | content := RegExReplace(content, "[\r\n]+([\s\x22]+)", "$1") 78 | 79 | ResultObj := [] 80 | Loop, Parse, content, `n, `r 81 | { 82 | ResultObj.Insert( [] ), RowNum := A_Index 83 | Loop, parse, A_LoopField, CSV 84 | ResultObj[RowNum].Insert(A_LoopField) 85 | } 86 | 87 | FileDelete, % TempFile 88 | } 89 | } -------------------------------------------------------------------------------- /ExtListView.ahk: -------------------------------------------------------------------------------- 1 | ; ---------------------------------------------------------------------------------------------------------------------- 2 | ; Name .........: ExtListView library 3 | ; Description ..: Collection of functions dealing with the ListViews of external processes. 4 | ; AHK Version ..: AHK_L 1.1.13.01 x32/64 ANSI/Unicode 5 | ; Author .......: Cyruz - http://ciroprincipe.info 6 | ; License ......: WTFPL - http://www.wtfpl.net/txt/copying/ 7 | ; Changelog ....: May 18, 2013 - v0.1 - First revision. 8 | ; ..............: Jun. 28, 2013 - v0.2 - Added resizable buffer option. 9 | ; ..............: Feb. 04, 2014 - v0.3 - Unicode and x64 compatibility. 10 | ; ..............: Apr. 10, 2014 - v1.0 - Code refactoring. Added encoding option and simple error management. 11 | ; ..............: May 04, 2014 - v1.1 - Detached the handles and memory allocation code. 12 | ; ..............: May 05, 2014 - v1.2 - Created ExtListView_GetAllItems and ExtListView_ToggleSelection functions. 13 | ; ..............: May 06, 2014 - v2.0 - Complete rewrite of the library. Code more modular and updateable. Separated 14 | ; ..............: code for De/Initialization, GetNextItem and GetItemText. 15 | ; ---------------------------------------------------------------------------------------------------------------------- 16 | 17 | ; ---------------------------------------------------------------------------------------------------------------------- 18 | ; Function .....: ExtListView_GetSingleItem 19 | ; Description ..: Get the first item with the desired state. 20 | ; Parameters ...: objLV - External ListView initialized object. 21 | ; ..............: sState - Status of the searched item. Common statuses are: 22 | ; ..............: LVNI_ALL - 0x0000 23 | ; ..............: LVNI_FOCUSED - 0x0001 24 | ; ..............: LVNI_SELECTED - 0x0002 25 | ; ..............: LVNI_CUT - 0x0004 26 | ; ..............: LVNI_DROPHILITED - 0x0008 27 | ; ..............: nCol - Column of the desired item (0-based index). 28 | ; Info .........: For more info on the sState parameter have a look at the MSDN docs for the LVM_GETNEXTITEM message: 29 | ; ..............: http://msdn.microsoft.com/en-us/library/windows/desktop/bb761057%28v=vs.85%29.aspx 30 | ; Return .......: Single item as a string. 31 | ; ---------------------------------------------------------------------------------------------------------------------- 32 | ExtListView_GetSingleItem(ByRef objLV, sState, nCol) { 33 | Try { 34 | 35 | If ( (nRow := ExtListView_GetNextItem(objLV, -1, sState)) != 0xFFFFFFFF ) 36 | sItem := ExtListView_GetItemText(objLV, nRow, nCol) 37 | 38 | } Catch e 39 | Throw e 40 | 41 | Return (sItem) ? sItem : 0 42 | } 43 | 44 | ; ---------------------------------------------------------------------------------------------------------------------- 45 | ; Function .....: ExtListView_GetAllItems 46 | ; Description ..: Get all items that share the same status on the target ListView. 47 | ; Parameters ...: objLV - External ListView initialized object. 48 | ; ..............: sState - Status of the searched item. Common statuses are: 49 | ; ..............: LVNI_ALL - 0x0000 50 | ; ..............: LVNI_FOCUSED - 0x0001 51 | ; ..............: LVNI_SELECTED - 0x0002 52 | ; ..............: LVNI_CUT - 0x0004 53 | ; ..............: LVNI_DROPHILITED - 0x0008 54 | ; Info .........: For more infor on the sState parameter have a look at the MSDN docs for the LVM_GETNEXTITEM message: 55 | ; ..............: http://msdn.microsoft.com/en-us/library/windows/desktop/bb761057%28v=vs.85%29.aspx 56 | ; Return .......: Multidimensional array containing ListView's items. Eg: array[row][column] := "SomeString". 57 | ; ---------------------------------------------------------------------------------------------------------------------- 58 | ExtListView_GetAllItems(ByRef objLV, sState:=0x0000) { 59 | Try { 60 | 61 | nRow := -1, objList := [] 62 | Loop 63 | { 64 | If ( (nRow := ExtListView_GetNextItem(objLV, nRow, sState)) == 0xFFFFFFFF ) 65 | Break 66 | x := A_Index, objList[x] := [] 67 | Loop % objLV.cols 68 | objList[x][A_Index] := ExtListView_GetItemText(objLV, nRow, A_Index-1) 69 | } 70 | 71 | } Catch e 72 | Throw e 73 | 74 | Return ( objList.MaxIndex() ) ? objList : 0 75 | } 76 | 77 | ; ---------------------------------------------------------------------------------------------------------------------- 78 | ; Function .....: ExtListView_ToggleSelection 79 | ; Description ..: Select/deselect items in the target ListView. 80 | ; Parameters ...: objLV - External ListView initialized object. 81 | ; ..............: bSelect - 1 for selection, 0 for deselection. 82 | ; ..............: nItem - -1 for all items or "n" (0-based) for a specific ListView item. 83 | ; ---------------------------------------------------------------------------------------------------------------------- 84 | ExtListView_ToggleSelection(ByRef objLV, bSelect:=1, nItem:=-1) { 85 | VarSetCapacity( LVITEM, 20, 0 ) 86 | NumPut( 0x0008, LVITEM, 0 ) ; mask = LVIF_STATE = 0x0008. 87 | NumPut( nItem, LVITEM, 4 ) ; iItem. 88 | NumPut( 0, LVITEM, 8 ) ; iSubItem. 89 | NumPut( (bSelect) ? 0x0002 : 0x0000, LVITEM, 12 ) ; state = LVIS_SELECTED = 0x0002 or 0x0000 (reset mask). 90 | NumPut( 0x0002, LVITEM, 16 ) ; stateMask = LVIS_SELECTED = 0x0002. 91 | 92 | If ( !DllCall( "WriteProcessMemory", Ptr,objLV.hproc, Ptr,objLV.pwritebuf, Ptr,&LVITEM, UInt,20, UInt,0 ) ) 93 | Throw Exception("objLV.pwritebuf: error writing memory", "WriteProcessMemory", "LastError: " A_LastError) 94 | SendMessage, 0x102B, % nItem, % objLV.pwritebuf,, % "ahk_id " objLV.hlv 95 | } 96 | 97 | ; ---------------------------------------------------------------------------------------------------------------------- 98 | ; Function .....: ExtListView_GetNextItem 99 | ; Description ..: Get the next item in the target ListView. 100 | ; Parameters ...: objLV - External ListView initialized object. 101 | ; ..............: nRow - Row where to start the search for the next item (0-based index). 102 | ; ..............: lParam - Status of the searched item. Common statuses are: 103 | ; ..............: LVNI_ALL - 0x0000 104 | ; ..............: LVNI_FOCUSED - 0x0001 105 | ; ..............: LVNI_SELECTED - 0x0002 106 | ; ..............: LVNI_CUT - 0x0004 107 | ; ..............: LVNI_DROPHILITED - 0x0008 108 | ; Info .........: LVM_GETNEXTITEM - http://msdn.microsoft.com/en-us/library/windows/desktop/bb761057%28v=vs.85%29.aspx 109 | ; Return .......: Item content as a string. 110 | ; ---------------------------------------------------------------------------------------------------------------------- 111 | ExtListView_GetNextItem(ByRef objLV, nRow, lParam:=0x0000) { 112 | ; LVM_GETNEXTITEM = LVM_FIRST (0x1000) + 12 = 0x100C. 113 | SendMessage, 0x100C, %nRow%, %lParam%,, % "ahk_id " objLV.hlv 114 | Return ErrorLevel 115 | } 116 | 117 | ; ---------------------------------------------------------------------------------------------------------------------- 118 | ; Function .....: ExtListView_GetItemText 119 | ; Description ..: Get the text of the desired item. 120 | ; Parameters ...: objLV - External ListView initialized object. 121 | ; ..............: nRow - Row of the desired item (0-based index). 122 | ; ..............: nCol - Column of the desired item (0-based index). 123 | ; Return .......: Item content as a string. 124 | ; ---------------------------------------------------------------------------------------------------------------------- 125 | ExtListView_GetItemText(ByRef objLV, nRow, nCol) { 126 | VarSetCapacity( LVITEM, objLV.szwritebuf, 0 ) 127 | NumPut( 0x0001, LVITEM, 0 ) ; mask = LVIF_TEXT = 0x0001. 128 | NumPut( nRow, LVITEM, 4 ) ; iItem = Row to retrieve (0 = 1st row). 129 | NumPut( nCol, LVITEM, 8 ) ; iSubItem = The column index of the item to retrieve. 130 | NumPut( objLV.preadbuf, LVITEM, 20 ) ; pszText = Pointer to item text string. 131 | NumPut( objLV.szreadbuf, LVITEM, (A_PtrSize == 4) ? 24 : 32 ) ; cchTextMax = Number of TCHARs in the buffer. 132 | 133 | If ( !DllCall( "WriteProcessMemory", Ptr,objLV.hproc, Ptr,objLV.pwritebuf, Ptr,&LVITEM, UInt,objLV.szwritebuf 134 | , UInt,0 ) ) 135 | Throw Exception("objLV.pwritebuf: error writing memory", "WriteProcessMemory", "LastError: " A_LastError) 136 | 137 | ; LVM_GETITEMTEXTA = LVM_FIRST (0x1000) + 45 = 0x102D. 138 | ; LVM_GETITEMTEXTW = LVM_FIRST (0x1000) + 115 = 0x1073. 139 | LVM_GETITEMTEXT := (objLV.senc == "UTF-8" || objLV.senc == "UTF-16") ? 0x1073 : 0x102D 140 | SendMessage, %LVM_GETITEMTEXT%, %nRow%, % objLV.pwritebuf,, % "ahk_id " objLV.hlv 141 | 142 | VarSetCapacity(cRecvBuf, objLV.szreadbuf, 1) 143 | If ( !DllCall( "ReadProcessMemory", Ptr,objLV.hproc, Ptr,objLV.preadbuf, Ptr,&cRecvBuf, UInt,objLV.szreadbuf 144 | , Ptr,0 ) ) 145 | Throw Exception("objLV.preadbuf: error reading memory", "ReadProcessMemory", "LastError: " A_LastError) 146 | 147 | Return StrGet(&cRecvBuf, objLV.szreadbuf, objLV.senc) 148 | } 149 | 150 | ; ---------------------------------------------------------------------------------------------------------------------- 151 | ; Function .....: ExtListView_Initialize 152 | ; Description ..: Initialize the object containing ListView's related data. 153 | ; Parameters ...: sWnd - Title of the window containing the ListView. 154 | ; ..............: szReadBuf - Size of the buffer used for reading the target process memory. It must be capable enough 155 | ; ..............: to hold the longest cell in the ListView. 156 | ; ..............: sEnc - Target ListView's encoding. "CP0" for ANSI, "UTF-8" or "UTF-16" for Unicode. 157 | ; Return .......: objLV - External ListView initialized object with the following keys: 158 | ; ..............: objLV.swnd - Title of the window owning the ListView. 159 | ; ..............: objLV.hwnd - Handle to the window owning the ListView. 160 | ; ..............: objLV.hproc - Handle to the process owning the ListView. 161 | ; ..............: objLV.hlv - Handle to the ListView. 162 | ; ..............: objLV.hhdr - Handle to the header of the ListView. 163 | ; ..............: objLV.rows - Number of rows in the ListView. 164 | ; ..............: objLV.cols - Number of columns in the ListView. 165 | ; ..............: objLV.senc - Encoding used by the process owning the ListView. 166 | ; ..............: objLV.pwritebuf - Address to the buffer used to write the LVITEM message to the target ListView. 167 | ; ..............: objLV.szwritebuf - Size of the write buffer. 168 | ; ..............: objLV.preadbuf - Address to the buffer used to read the answer to the message sent. 169 | ; ..............: objLV.szreadbuf - Size of the read buffer. 170 | ; ---------------------------------------------------------------------------------------------------------------------- 171 | ExtListView_Initialize(sWnd, szReadBuf:=1024, sEnc:="CP0") { 172 | objLV := Object() 173 | objLV.swnd := sWnd 174 | objLV.hwnd := WinExist(sWnd) 175 | objLV.szwritebuf := (A_PtrSize == 4) ? 28 : 36 ; Size of LVITEM 176 | objLV.szreadbuf := szReadBuf 177 | objLV.senc := sEnc 178 | 179 | ControlGet, hLv, Hwnd,, SysListView321, % "ahk_id " objLV.hwnd 180 | objLV.hlv := hLv 181 | 182 | DllCall( "GetWindowThreadProcessId", Ptr,hLv, PtrP,dwProcessId ) 183 | ; PROCESS_VM_OPERATION = 0x0008, PROCESS_VM_READ = 0x0010, PROCESS_VM_WRITE = 0x0020. 184 | If ( !(objLV.hproc := DllCall( "OpenProcess", UInt,0x0008|0x0010|0x0020, Int,0, UInt,dwProcessId )) ) 185 | Throw Exception("objLV.hproc: error opening process", "OpenProcess", "LastError: " A_LastError) 186 | 187 | ; LVM_GETITEMCOUNT = LVM_FIRST (0x1000) + 4 = 0x1004. 188 | SendMessage, 0x1004, 0, 0,, % "ahk_id " objLV.hlv 189 | objLV.rows := ErrorLevel 190 | 191 | ; LVM_GETHEADER = LVM_FIRST (0x1000) + 31 = 0x101F. 192 | SendMessage, 0x101F, 0, 0,, % "ahk_id " objLV.hlv 193 | objLV.hhdr := ErrorLevel 194 | 195 | ; HDM_GETITEMCOUNT = HDM_FIRST (0x1200) + 0 = 0x1200. 196 | SendMessage, 0x1200, 0, 0,, % "ahk_id " objLV.hhdr 197 | objLV.cols := ErrorLevel 198 | 199 | ; Allocate memory on the target process before returning the object. 200 | If ( !__ExtListView_AllocateMemory(objLV) ) 201 | Throw Exception("Error allocating memory", "__ExtListView_Initialize", "LastError: " A_LastError) 202 | 203 | Return objLV 204 | } 205 | 206 | ; ---------------------------------------------------------------------------------------------------------------------- 207 | ; Function .....: ExtListView_DeInitialize 208 | ; Description ..: DeInitialize the object. 209 | ; Parameters ...: objLV - External ListView initialized object. 210 | ; ---------------------------------------------------------------------------------------------------------------------- 211 | ExtListView_DeInitialize(ByRef objLV) { 212 | ; Free the previously allocated memory on the target process. 213 | If ( !__ExtListView_DeAllocateMemory(objLV) ) 214 | Throw Exception("Error deallocating memory", "__ExtListView_DeInitialize", "LastError: " A_LastError) 215 | DllCall( "CloseHandle", Ptr,objLV.hproc ) 216 | objLV := "" 217 | } 218 | 219 | ; ---------------------------------------------------------------------------------------------------------------------- 220 | ; Function .....: ExtListView_CheckInitObject 221 | ; Description ..: Check if the object is still referring to a valid ListView. 222 | ; Parameters ...: objLV - External ListView initialized object. 223 | ; Return .......: 0 if false, handle of the window containing the ListView if true. 224 | ; ---------------------------------------------------------------------------------------------------------------------- 225 | ExtListView_CheckInitObject(ByRef objLV) { 226 | Return WinExist("ahk_id " objLV.hwnd) 227 | } 228 | 229 | ; ---------------------------------------------------------------------------------------------------------------------- 230 | ; Function .....: __ExtListView_AllocateMemory 231 | ; Description ..: Allocates memory into the target process. 232 | ; Parameters ...: objLV - External ListView initialized object. 233 | ; ---------------------------------------------------------------------------------------------------------------------- 234 | __ExtListView_AllocateMemory(ByRef objLV) { 235 | ; MEM_COMMIT = 0x1000, PAGE_READWRITE = 0x4. 236 | If ( !(objLV.pwritebuf := DllCall( "VirtualAllocEx", Ptr,objLV.hproc, Ptr,0, UInt,objLV.szwritebuf, UInt,0x1000 237 | , UInt,0x4 )) ) 238 | Return 0 239 | If ( !(objLV.preadbuf := DllCall( "VirtualAllocEx", Ptr,objLV.hproc, Ptr,0, UInt,objLV.szreadbuf, UInt,0x1000 240 | , UInt,0x4 )) ) 241 | Return 0 242 | Return 1 243 | } 244 | 245 | ; ---------------------------------------------------------------------------------------------------------------------- 246 | ; Function .....: __ExtListView_DeAllocateMemory 247 | ; Description ..: Frees previously allocated memory. 248 | ; Parameters ...: objLV - External ListView initialized object. 249 | ; ---------------------------------------------------------------------------------------------------------------------- 250 | __ExtListView_DeAllocateMemory(ByRef objLV) { 251 | ; MEM_RELEASE = 0x8000. 252 | If ( !DllCall( "VirtualFreeEx", Ptr,objLV.hproc, Ptr,objLV.pwritebuf, UInt,0, UInt,0x8000 ) ) 253 | Return 0 254 | objLV.Remove("pwritebuf") 255 | If ( !DllCall( "VirtualFreeEx", Ptr,objLV.hproc, Ptr,objLV.preadbuf, UInt,0, UInt,0x8000 ) ) 256 | Return 0 257 | objLV.Remove("preadbuf") 258 | Return 1 259 | } 260 | 261 | /* EXAMPLE CODE: 262 | 263 | OnExit, QUIT 264 | WINTITLE = Active Directory Users and Computers ahk_class MMCMainFrame 265 | objLV := ExtListView_Initialize(WINTITLE) 266 | HotKey, IfWinActive, %WINTITLE% 267 | HotKey, ^!g, TOGGLESEL 268 | Return 269 | 270 | TOGGLESEL: 271 | ( ExtListView_CheckInitObject(objLV) ) ? objLV := ExtListView_Initialize(WINTITLE) 272 | ExtListView_ToggleSelection(objLV, 1, 0) 273 | Return 274 | 275 | QUIT: 276 | ExtListView_DeInitialize(objLV) 277 | ExitApp 278 | 279 | */ -------------------------------------------------------------------------------- /FileVerInfo.ahk: -------------------------------------------------------------------------------- 1 | ; ---------------------------------------------------------------------------------------------------------------------- 2 | ; Function .....: FileVerInfo 3 | ; Description ..: Return Version Information for the selected file. 4 | ; Parameters ...: sFile - Path to the file. 5 | ; ..............: sVerStr - Pipe-separated list of the properties to retrieve. If empty, it gets all properties. 6 | ; Return .......: 0 on error or associative bidimensional array on success. Array is structured as the following: 7 | ; ..............: objVersions[objFileVer1, objFileVer2, ..., objFileVerN] 8 | ; ..............: objFileVer properties = Language, Codepage and all version properties requested to the function. 9 | ; AHK Version ..: AHK_L x32/64 Unicode 10 | ; Author .......: Cyruz - http://ciroprincipe.info 11 | ; License ......: WTFPL - http://www.wtfpl.net/txt/copying/ 12 | ; Changelog ....: Nov. 17, 2012 - v0.1 - First revision. 13 | ; ..............: Jan. 07, 2014 - v0.2 - Unicode and x64 version. Return an object, not anymore a string. 14 | ; ---------------------------------------------------------------------------------------------------------------------- 15 | FileVerInfo(sFile, sVerStr:="") { 16 | Static LANGUAGES := "0401:Arabic|0415:Polish|0402:Bulgarian|0416:Portuguese (Brazil)|0403:Catalan|0417:Rhaeto-Roman" 17 | . "ic|0404:Traditional Chinese|0418:Romanian|0405:Czech|0419:Russian|0406:Danish|041A:Croato-Serb" 18 | . "ian (Latin)|0407:German|041B:Slovak|0408:Greek|041C:Albanian|0409:U.S. English|041D:Swedish|04" 19 | . "0A:Castilian Spanish|041E:Thai|040B:Finnish|041F:Turkish|040C:French|0420:Urdu|040D:Hebrew|042" 20 | . "1:Bahasa|040E:Hungarian|0804:Simplified Chinese|040F:Icelandic|0807:Swiss German|0410:Italian|" 21 | . "0809:U.K. English|0411:Japanese|080A:Spanish (Mexico)|0412:Korean|080C:Belgian French|0413:Dut" 22 | . "ch|0C0C:Canadian French|0414:Norwegian ? Bokmal|100C:Swiss French|0810:Swiss Italian|0816:Port" 23 | . "uguese (Portugal)|0813:Belgian Dutch|081A:Serbo-Croatian (Cyrillic)|0814:Norwegian ? Nynorsk" 24 | , CODEPAGES := "0000:7-bit ASCII|03A4:Japan (Shift ? JIS X-0208)|03B5:Korea (Shift ? KSC 5601)|03B6:Taiwan (Bi" 25 | . "g5)|04B0:Unicode|04E2:Latin-2 (Eastern European)|04E3:Cyrillic|04E4:Multilingual|04E5:Greek|04" 26 | . "E6:Turkish|04E7:Hebrew|04E8:Arabic" 27 | , VERSTRING := "Comments|CompanyName|FileDescription|FileVersion|InternalName|LegalCopyright|LegalTrademarks|O" 28 | . "riginalFilename|ProductName|ProductVersion|PrivateBuild|SpecialBuild" 29 | 30 | 31 | If ( sVerStr == "" ) 32 | sVerStr := VERSTRING 33 | 34 | If ( !szBuf := DllCall( "Version.dll\GetFileVersionInfoSize", Str,sFile, Ptr,0 ) ) 35 | Return 0, ErrorLevel := "GetFileVersionInfoSize error`nLast error = " A_LastError 36 | 37 | VarSetCapacity(cBuf, szBuf, 0) 38 | If ( !DllCall( "Version.dll\GetFileVersionInfo", Str,sFile, UInt,0, UInt,szBuf, Ptr,&cBuf ) ) 39 | Return 0, ErrorLevel := "GetFileVersionInfo error`nLast error = " A_LastError 40 | 41 | If ( !DllCall( "Version.dll\VerQueryValue", Ptr,&cBuf, Str,"\\VarFileInfo\\Translation", PtrP,addrVerBuf 42 | , PtrP,szVerBuf ) ) 43 | Return 0, ErrorLevel := "VerQueryValue error" 44 | 45 | VarSetCapacity( sLangCp, 18 ) 46 | DllCall( "msvcrt\swprintf", Str,sLangCp, Str,"%04X%04X", UShort,NumGet(addrVerBuf+0,"UShort") 47 | , UShort,NumGet(addrVerBuf+2,"UShort") ) 48 | 49 | objVersions := Object() 50 | Loop % szVerBuf/4 ; LANGUAGE + CODEPAGE = 4 byte 51 | { 52 | RegExMatch( LANGUAGES, "S)" SubStr( sLangCp, 1, 4 ) ":([^\|]*)", OutLang ) 53 | RegExMatch( CODEPAGES, "S)" SubStr( sLangCp, 5, 4 ) ":([^\|]*)", OutCode ) 54 | objFileVer := { "Language": OutLang1, "Codepage": OutCode1 } 55 | Loop, PARSE, sVerStr, | 56 | If ( A_LoopField ) 57 | DllCall( "Version.dll\VerQueryValue", Ptr,&cBuf, Str,"\\StringFileInfo\\" sLangCp "\\" A_LoopField 58 | , PtrP,addrVerBuf, PtrP,szVerBuf ) 59 | , objFileVer[A_LoopField] := StrGet( addrVerBuf, szVerBuf, "UTF-16" ) 60 | objVersions[A_Index] := objFileVer, objFileVer := "" 61 | } 62 | Return objVersions 63 | } 64 | 65 | /* EXAMPLE CODE: 66 | objVerCalc := FileVerInfo("C:\Windows\System32\calc.exe") 67 | Loop % objVerCalc.MaxIndex() 68 | MsgBox, % "Language: " objVerCalc[A_Index].Language 69 | . "`nCodepage: " objVerCalc[A_Index].Codepage 70 | . "`nComments: " objVerCalc[A_Index].Comments 71 | . "`nCompanyName: " objVerCalc[A_Index].CompanyName 72 | . "`nFileDescription: " objVerCalc[A_Index].FileDescription 73 | . "`nFileVersion: " objVerCalc[A_Index].FileVersion 74 | . "`nInternalName: " objVerCalc[A_Index].InternalName 75 | . "`nLegalCopyright: " objVerCalc[A_Index].LegalCopyright 76 | . "`nLegalTrademarks: " objVerCalc[A_Index].LegalTrademarks 77 | . "`nOriginalFilename: " objVerCalc[A_Index].OriginalFilename 78 | . "`nProductName: " objVerCalc[A_Index].ProductName 79 | . "`nProductVersion: " objVerCalc[A_Index].ProductVersion 80 | . "`nPrivateBuild: " objVerCalc[A_Index].PrivateBuild 81 | . "`nSpecialBuild: " objVerCalc[A_Index].SpecialBuild 82 | */ -------------------------------------------------------------------------------- /Icon.ahk: -------------------------------------------------------------------------------- 1 | ; ---------------------------------------------------------------------------------------------------------------------- 2 | ; Name .........: Icon library 3 | ; Description ..: Functions library to manage icons (creating, loading, destroying). 4 | ; AHK Version ..: AHK_L 1.1.13.01 x32/64 Unicode 5 | ; Author .......: Cyruz - http://ciroprincipe.info 6 | ; License ......: WTFPL - http://www.wtfpl.net/txt/copying/ 7 | ; Changelog ....: Jul. 30, 2015 - v0.1 - First version. 8 | ; ---------------------------------------------------------------------------------------------------------------------- 9 | 10 | ; ---------------------------------------------------------------------------------------------------------------------- 11 | ; Function .....: Icon_Create 12 | ; Description ..: Create an icon from a binary buffer and return a handle to it. 13 | ; Parameters ...: adrBuf - Pointer to the binary data buffer containing the icon. 14 | ; ..............: nIconWidth - Width of the desired icon (used to retrieve the icon inside a multi-icon file). 15 | ; ..............: szBuf - If the buffer contains raw, single icon data, we can specify its size and avoid data 16 | ; ..............: structure parsing. This can be useful when loading icon resources (type 3) from PE files. 17 | ; Return .......: Handle to the icon on success, 0 on error. 18 | ; Info .........: CreateIconFromResourceEx function - https://goo.gl/Fij4ZA 19 | ; ---------------------------------------------------------------------------------------------------------------------- 20 | Icon_Create(adrBuf, nIconWidth, szBuf:=0) 21 | { 22 | If ( !szBuf ) 23 | { 24 | Loop % NumGet( adrBuf+0, 4, "UShort" ) 25 | { 26 | nOfft := 6 + 16*(A_Index-1) 27 | If ( NumGet( adrBuf+0, nOfft, "UChar" ) == nIconWidth ) 28 | { 29 | szBuf := NumGet( adrBuf+0, nOfft+8, "UInt" ) 30 | adrBuf += NumGet( adrBuf+0, nOfft+12, "UInt" ) 31 | Break 32 | } 33 | } 34 | } 35 | ; VERSION = 0x30000 36 | Return DllCall( "CreateIconFromResourceEx", Ptr,adrBuf, UInt,szBuf, Int,1, UInt,0x30000 37 | , Int,nIconWidth, Int,nIconWidth, UInt,0 ) 38 | } 39 | 40 | ; ---------------------------------------------------------------------------------------------------------------------- 41 | ; Name .........: Icon_Load function 42 | ; Description ..: Load an icon from a PE file as a resource or from an icon file. 43 | ; Parameters ...: sBinFile - Can be: 44 | ; ..............: * 0 to load a resource from the current process executable. 45 | ; ..............: * The module name or the full path to its executable/dll to load a resource from it. 46 | ; ..............: * -1 or any negative integer to load the icon from an icon file. 47 | ; ..............: sResName - The name of the resource or its integer identifier. If sBinFile is a negative integer, it 48 | ; ..............: should be the full path to an icon file. 49 | ; ..............: nWidth - Desired icon's width. 50 | ; Return .......: Handle to the icon on success or -1 on error. 51 | ; Info .........: LoadIconWihScalDown function - https://goo.gl/4DCmxW 52 | ; ---------------------------------------------------------------------------------------------------------------------- 53 | Icon_Load(sBinFile, sResName, nWidth) 54 | { 55 | If ( sBinFile < 0 ) 56 | hLib := 0 57 | Else 58 | { 59 | If ( !hLib := DllCall( "GetModuleHandle", Ptr,(sBinFile?&sBinFile:0) ) ) 60 | { 61 | ; If the DLL isn't already loaded, load it as a data file. 62 | If ( !hLib := DllCall( "LoadLibraryEx", Str,sBinFile, Ptr,0, UInt,0x2 ) ) 63 | Return -1, ErrorLevel := "LoadLibraryEx error`nReturn value = " hLib "`nLast error = " A_LastError 64 | bLoaded := 1 65 | } 66 | } 67 | 68 | Try 69 | { 70 | If ( DllCall( "LoadIconWithScaleDown", Ptr,hLib, Ptr,(sResName+0==sResName?sResName:&sResName) 71 | , Int,nWidth, Int,nWidth, PtrP,hIcon ) != 0 ) ; S_OK = 0 72 | Return -1, ErrorLevel := "LoadIconWithScaleDown error`nReturn value = " e 73 | } 74 | Finally 75 | { 76 | ; If we loaded the DLL, free it now. 77 | If ( bLoaded ) 78 | DllCall( "FreeLibrary", Ptr,hLib ) 79 | } 80 | 81 | Return hIcon 82 | } 83 | 84 | ; ---------------------------------------------------------------------------------------------------------------------- 85 | ; Name .........: Icon_Destroy function 86 | ; Description ..: Destroy an icon handle. 87 | ; Parameters ...: hIcon - Handle to the icon to be destroyed. 88 | ; Info .........: DestroyIcon function - https://goo.gl/LaivE8 89 | ; ---------------------------------------------------------------------------------------------------------------------- 90 | Icon_Destroy(hIcon) 91 | { 92 | Return DllCall( "DestroyIcon", Ptr,hIcon ) 93 | } -------------------------------------------------------------------------------- /IniParser.ahk: -------------------------------------------------------------------------------- 1 | ; ---------------------------------------------------------------------------------------------------------------------- 2 | ; Function .....: IniParser 3 | ; Description ..: Parse ini files and return an array of objects. 4 | ; Parameters ...: sFile - Path to the file to parse. 5 | ; Return .......: Array of object (__SECTION and relative keys as properties). 6 | ; AHK Version ..: AHK_L x32/64 Unicode 7 | ; Author .......: Cyruz - http://ciroprincipe.info 8 | ; License ......: WTFPL - http://www.wtfpl.net/txt/copying/ 9 | ; Changelog ....: Jun. 28, 2013 - ver 0.1 - First revision 10 | ; ---------------------------------------------------------------------------------------------------------------------- 11 | IniParser(sFile) { 12 | arrSection := Object(), idx := 0 13 | Loop, READ, %sFile% 14 | If ( RegExMatch(A_LoopReadline, "S)^\s*\[(.*)\]\s*$", sSecMatch) ) 15 | ++idx, arrSection[idx] := Object("__SECTION", sSecMatch1) 16 | Else If ( RegExMatch(A_LoopReadLine, "S)^\s*(\w+)\s*\=\s*(.*)\s*$", sKeyValMatch) ) 17 | arrSection[idx].Insert(sKeyValMatch1, sKeyValMatch2) 18 | Return arrSection 19 | } 20 | 21 | /* EXAMPLE CODE: 22 | obj := IniParser("test.ini") 23 | For idx, item in obj 24 | For k, v in item 25 | If (k == "__SECTION") 26 | MsgBox, Ini Section: %v% 27 | Else 28 | MsgBox, % k . " - " . v 29 | Return 30 | */ -------------------------------------------------------------------------------- /Json4Ahk.ahk: -------------------------------------------------------------------------------- 1 | ; ---------------------------------------------------------------------------------------------------------------------- 2 | ; Name .........: Json4Ahk library 3 | ; Description ..: Provide 2 simple functions to deal with JSON. 4 | ; AHK Version ..: AHK_L 1.1.13.01 x32 Unicode (ScriptControl COM object is not x64 compatible) 5 | ; Author .......: Wicked (http://www.autohotkey.com/board/topic/95262-obj-json-obj/#entry600438) 6 | ; Lib. Author ..: Cyruz (http://ciroprincipe.info) 7 | ; License ......: WTFPL - http://www.wtfpl.net/txt/copying/ 8 | ; Changelog ....: Jan. 17, 2014 - v0.1 - First version. 9 | ; ---------------------------------------------------------------------------------------------------------------------- 10 | 11 | ; ---------------------------------------------------------------------------------------------------------------------- 12 | ; Function .....: Json4Ahk_Encode 13 | ; Description ..: Encode an AHK object into a JSON string. 14 | ; Parameters ...: objAhk - AutoHotkey object to encode. 15 | ; Return .......: JSON string describing the object. 16 | ; ---------------------------------------------------------------------------------------------------------------------- 17 | Json4Ahk_Encode(objAhk) { 18 | For x, y in objAhk 19 | s .= ((a := (objAhk.SetCapacity(0) == (objAhk.MaxIndex() - objAhk.MinIndex() + 1))) ? "" : """" x """:") 20 | . (IsObject(y) ? %A_ThisFunc%(y) : """" y """") "," 21 | Return ((a) ? "[" RTrim(s, ",") "]" : "{" RTrim(s, ",") "}") 22 | } 23 | 24 | ; ---------------------------------------------------------------------------------------------------------------------- 25 | ; Function .....: Json4Ahk_Decode 26 | ; Description ..: Decode a JSON string into an AHK object. 27 | ; Parameters ...: sJson - JSON string describing the object. 28 | ; ..............: sKey - Optional key to retrieve. 29 | ; Return .......: AutoHotkey object or requested value. 30 | ; ---------------------------------------------------------------------------------------------------------------------- 31 | Json4Ahk_Decode(sJson, sKey:="") { 32 | Static oJson := ComObjCreate("ScriptControl") 33 | oJson.Language:="JScript" 34 | Return oJson.Eval("(" sJson ((sKey != "") ? ")." sKey : ")")) 35 | } 36 | -------------------------------------------------------------------------------- /LVX.ahk: -------------------------------------------------------------------------------- 1 | /* 2 | Title: LVX Library 3 | 4 | Row colouring and cell editing functions for ListView controls. 5 | 6 | Remarks: 7 | Cell editing code adapted from Michas ; 8 | row colouring by evl . 9 | Many thanks to them for providing the code base of these functions! 10 | 11 | License: 12 | - Version 1.04 by Titan 13 | - zlib License 14 | */ 15 | 16 | /* 17 | 18 | Function: LVX_Setup 19 | Initalization function for the LVX library. Must be called before all other functions. 20 | 21 | Parameters: 22 | name - associated variable name (or Hwnd) of ListView control to setup for colouring and cell editing. 23 | 24 | */ 25 | LVX_Setup(name) { 26 | global lvx 27 | If name is xdigit 28 | h = %name% 29 | Else GuiControlGet, h, Hwnd, %name% 30 | VarSetCapacity(lvx, 4 + 255 * 9, 0) 31 | NumPut(h + 0, lvx) 32 | OnMessage(0x4e, "WM_NOTIFY") 33 | LVX_SetEditHotkeys() ; initialize default hotkeys 34 | } 35 | 36 | /* 37 | 38 | Function: LVX_CellEdit 39 | Makes the specified cell editable with an Edit control overlay. 40 | 41 | Parameters: 42 | r - (optional) row number (default: 1) 43 | c - (optional) column (default: 1) 44 | set - (optional) true to automatically set the cell to the new user-input value (default: true) 45 | 46 | Remarks: 47 | The Edit control may be slightly larger than its corresponding row, 48 | depending on the current font setting. 49 | 50 | */ 51 | LVX_CellEdit(set = true) { 52 | global lvx, lvxb 53 | static i = 1, z = 48, e, h, k = "Enter|Esc|NumpadEnter" 54 | If i 55 | { 56 | Gui, %A_Gui%:Add, Edit, Hwndh ve Hide r1 57 | ;make row resize to fit this height.. then back 58 | h += i := 0 59 | } 60 | If r < 1 61 | r = %A_EventInfo% 62 | If !LV_GetNext() 63 | Return 64 | If !(A_Gui or r) 65 | Return 66 | l := NumGet(lvx) 67 | SendMessage, 4135, , , , ahk_id %l% ; LVM_GETTOPINDEX 68 | vti = %ErrorLevel% 69 | VarSetCapacity(xy, 16, 0) 70 | ControlGetPos, bx, t, , , , ahk_id %l% 71 | bw = 0 72 | by = 0 73 | bpw = 0 74 | SendMessage, 4136, , , , ahk_id %l% ; LVM_GETCOUNTPERPAGE 75 | Loop, %ErrorLevel% { 76 | cr = %A_Index% 77 | NumPut(cr - 1, xy, 4), NumPut(2, xy) ; LVIR_LABEL 78 | SendMessage, 4152, vti + cr - 1, &xy, , ahk_id %l% ; LVM_GETSUBITEMRECT 79 | by := NumGet(xy, 4) 80 | If (LV_GetNext() - vti == cr) 81 | Break 82 | } 83 | by += t + 1 84 | cr-- 85 | VarSetCapacity(xy, 16, 0) 86 | CoordMode, Mouse, Relative 87 | MouseGetPos, mx 88 | Loop, % LV_GetCount("Col") { 89 | cc = %A_Index% 90 | NumPut(cc - 1, xy, 4), NumPut(2, xy) ; LVIR_LABEL 91 | SendMessage, 4152, cr, &xy, , ahk_id %l% ; LVM_GETSUBITEMRECT 92 | bx += bw := NumGet(xy, 8) - NumGet(xy, 0) 93 | If !bpw 94 | bpw := NumGet(xy, 0) 95 | If (mx <= bx) 96 | Break 97 | } 98 | bx -= bw - bpw - 2 99 | LV_GetText(t, cr + 1, cc) 100 | GuiControl, , e, %t% 101 | ControlMove, , bx, by, bw, , ahk_id %h% 102 | GuiControl, Show, e 103 | GuiControl, Focus, e 104 | VarSetCapacity(g, z, 0) 105 | NumPut(z, g) 106 | LVX_SetEditHotkeys(~1, h) 107 | Loop { 108 | DllCall("GetGUIThreadInfo", "UInt", 0, "Str", g) 109 | If (lvxb or NumGet(g, 12) != h) 110 | Break 111 | Sleep, 100 112 | } 113 | GuiControlGet, t, , e 114 | If (set and lvxb != 2) 115 | LVX_SetText(t, cr + 1, cc) 116 | GuiControl, Hide, e 117 | Return, lvxb == 2 ? "" : t 118 | } 119 | 120 | /* 121 | 122 | Function: LVX_SetText 123 | Set the text of a specified cell. 124 | 125 | Parameters: 126 | text - new text content of cell 127 | row - (optional) row number 128 | col - (optional) column number 129 | 130 | */ 131 | LVX_SetText(text, row = 1, col = 1) { 132 | global lvx 133 | l := NumGet(lvx) 134 | row-- 135 | VarSetCapacity(d, 60, 0) 136 | SendMessage, 4141, row, &d, , ahk_id %l% ; LVM_GETITEMTEXT 137 | NumPut(col - 1, d, 8) 138 | NumPut(&text, d, 20) 139 | SendMessage, 4142, row, &d, , ahk_id %l% ; LVM_SETITEMTEXT 140 | } 141 | 142 | /* 143 | 144 | Function: LVX_SetEditHotkeys 145 | Change accept/cancel hotkeys in cell editing mode. 146 | 147 | Parameters: 148 | enter - comma seperated list of hotkey names/modifiers that will save 149 | the current input text and close editing mode 150 | esc - same as above but will ignore text entry (i.e. to cancel) 151 | 152 | Remarks: 153 | The default hotkeys are Enter and Esc (Escape) respectively, 154 | and such will be used if either parameter is blank or omitted. 155 | 156 | */ 157 | LVX_SetEditHotkeys(enter = "Enter,NumpadEnter", esc = "Esc") { 158 | global lvx, lvxb 159 | static h1, h0 160 | If (enter == ~1) { 161 | If esc > 0 162 | { 163 | lvxb = 0 164 | Hotkey, IfWinNotActive, ahk_id %esc% 165 | } 166 | Loop, Parse, h1, `, 167 | Hotkey, %A_LoopField%, _lvxb 168 | Loop, Parse, h0, `, 169 | Hotkey, %A_LoopField%, _lvxc 170 | Hotkey, IfWinActive 171 | Return 172 | } 173 | If enter != 174 | h1 = %enter% 175 | If esc != 176 | h0 = %esc% 177 | } 178 | 179 | _lvxc: ; these labels are for internal use: 180 | lvxb++ 181 | _lvxb: 182 | lvxb++ 183 | LVX_SetEditHotkeys(~1, -1) 184 | Return 185 | 186 | /* 187 | 188 | Function: LVX_SetColour 189 | Set the background and/or text colour of a specific row on a ListView control. 190 | 191 | Parameters: 192 | index - row index (1-based) 193 | back - (optional) background row colour, must be hex code in RGB format (default: 0xffffff) 194 | text - (optional) similar to above, except for font colour (default: 0x000000) 195 | 196 | Remarks: 197 | Sorting will not affect coloured rows. 198 | 199 | */ 200 | LVX_SetColour(index, back = 0xffffff, text = 0x000000) { 201 | global lvx 202 | a := (index - 1) * 9 + 5 203 | NumPut(LVX_RevBGR(text) + 0, lvx, a) 204 | If !back 205 | back = 0x010101 ; since we can't use null 206 | NumPut(LVX_RevBGR(back) + 0, lvx, a + 4) 207 | h := NumGet(lvx) 208 | WinSet, Redraw, , ahk_id %h% 209 | } 210 | 211 | /* 212 | 213 | Function: LVX_RevBGR 214 | Helper function for internal use. Converts RGB to BGR. 215 | 216 | Parameters: 217 | i - BGR hex code 218 | 219 | */ 220 | LVX_RevBGR(i) { 221 | Return, (i & 0xff) << 16 | (i & 0xffff) >> 8 << 8 | i >> 16 222 | } 223 | 224 | /* 225 | Function: LVX_Notify 226 | Handler for WM_NOTIFY events on ListView controls. Do not use this function. 227 | */ 228 | LVX_Notify(wParam, lParam, msg) { 229 | global lvx 230 | If (NumGet(lParam + 0) == NumGet(lvx) and NumGet(lParam + 8, 0, "Int") == -12) { 231 | st := NumGet(lParam + 12) 232 | If st = 1 233 | Return, 0x20 234 | Else If (st == 0x10001) { 235 | a := NumGet(lParam + 36) * 9 + 9 236 | If NumGet(lvx, a) 237 | NumPut(NumGet(lvx, a - 4), lParam + 48), NumPut(NumGet(lvx, a), lParam + 52) 238 | } 239 | } 240 | } 241 | 242 | WM_NOTIFY(wParam, lParam, msg, hwnd) { 243 | ; if you have your own WM_NOTIFY function you will need to merge the following three lines: 244 | global lvx 245 | If (NumGet(lParam + 0) == NumGet(lvx)) 246 | Return, LVX_Notify(wParam, lParam, msg) 247 | } -------------------------------------------------------------------------------- /LV_EX.ahk: -------------------------------------------------------------------------------- 1 | ; ====================================================================================================================== 2 | ; Namespace: LV_EX 3 | ; Function: Some additional functions to use with AHK GUI ListView controls. 4 | ; Tested with: AHK 1.1.13.01 (A32/U32/U64) 5 | ; Tested on: Win 7 (x64) 6 | ; Changelog: 7 | ; 1.0.00.00/2013-12-30/just me - initial release 8 | ; Notes: 9 | ; In terms of Microsoft 10 | ; Item stands for the whole row or the first column of the row 11 | ; SubItem stands for the second to last column of a row 12 | ; All functions require the handle to the ListView (HWND). You get this handle using the 'Hwnd' option when 13 | ; creating the control per 'Gui, Add, HwndHwndOfLV ...' or using 'GuiControlGet, HwndOfLV, Hwnd, MyListViewVar' 14 | ; after control creation. 15 | ; ====================================================================================================================== 16 | ; This software is provided 'as-is', without any express or implied warranty. 17 | ; In no event will the authors be held liable for any damages arising from the use of this software. 18 | ; ====================================================================================================================== 19 | ; ====================================================================================================================== 20 | ; LV_EX_CalcViewSize - Calculates the approximate width and height required to display a given number of items. 21 | ; ====================================================================================================================== 22 | LV_EX_CalcViewSize(HLV, Rows := 0) { 23 | Static LVM_APPROXIMATEVIEWRECT := 0x1040 24 | SendMessage, % LVM_APPROXIMATEVIEWRECT, % (Rows - 1), 0, , % "ahk_id " . HLV 25 | If (ErrorLevel <> "FAIL") 26 | Return {W: (ErrorLevel & 0xFFFF), H: (ErrorLevel >> 16) & 0xFFFF} 27 | Return False 28 | } 29 | ; ====================================================================================================================== 30 | ; LV_EX_FindString - Searches the first column for an item containing the specified string. 31 | ; ====================================================================================================================== 32 | LV_EX_FindString(HLV, Str, Start := 0, Partial := False) { 33 | Static LVM_FINDITEM := A_IsUnicode ? 0x1053 : 0x100D ; LVM_FINDITEMW : LVM_FINDITEMA 34 | Static LVFI_PARTIAL := 0x0008 35 | Static LVFI_STRING := 0x0002 36 | Static LVFISize := 40 37 | VarSetCapacity(LVFINDINFO, LVFISize, 0) 38 | Flags := LVFI_STRING 39 | If (Partial) 40 | Flags |= LVFI_PARTIAL 41 | NumPut(Flags, LVFINDINFO, 0, "UInt") 42 | NumPut(&Str, LVFINDINFO, A_PtrSize, "Ptr") 43 | SendMessage, % LVM_FINDITEM, % (Start - 1), % &LVFINDINFO, , % "ahk_id " . HLV 44 | Return (ErrorLevel > 0x7FFFFFFF ? 0 : ErrorLevel + 1) 45 | } 46 | ; ====================================================================================================================== 47 | ; LV_EX_FindStringEx - Searches all columns or the specified column for a subitem containing the specified string. 48 | ; ====================================================================================================================== 49 | LV_EX_FindStringEx(HLV, Str, Column := 0, Start := 0, Partial := False) { 50 | Len := StrLen(Str) 51 | Row := Col := 0 52 | ControlGet, ItemList, List, , , % "ahk_id " . HLV 53 | Loop, Parse, ItemList, `n 54 | { 55 | If (A_Index > Start) { 56 | Row := A_Index 57 | Columns := StrSplit(A_LoopField, "`t") 58 | If (Column + 0) > 0 { 59 | If (Partial) { 60 | If (SubStr(Columns[Column], 1, Len) = Str) 61 | Col := Column 62 | } 63 | Else { 64 | If (Columns[Column] = Str) 65 | Col := Column 66 | } 67 | } 68 | Else { 69 | For Index, ColumnText In Columns { 70 | If (Partial) { 71 | If (SubStr(ColumnText, 1, Len) = Str) 72 | Col := Index 73 | } 74 | Else { 75 | If (ColumnText = Str) 76 | Col := Index 77 | } 78 | } Until (Col > 0) 79 | } 80 | } 81 | } Until (Col > 0) 82 | Return (Col > 0) ? {Row: Row, Col: Column} : 0 83 | } 84 | ; ====================================================================================================================== 85 | ; LV_EX_GetColumnOrder - Gets the current left-to-right order of columns in a list-view control. 86 | ; ====================================================================================================================== 87 | LV_EX_GetColumnOrder(HLV) { 88 | Static HDM_GETITEMCOUNT := 0x1200 89 | Static LVM_GETCOLUMNORDERARRAY := 0x103B 90 | Header := LV_EX_GetHeader(HLV) 91 | SendMessage, % HDM_GETITEMCOUNT, 0, 0, , % "ahk_id " . Header 92 | If (ErrorLevel > 0x7FFFFFFF) 93 | Return False 94 | Cols := ErrorLevel 95 | VarSetCapacity(COA, Cols * 4, 0) 96 | SendMessage, % LVM_GETCOLUMNORDERARRAY, % Cols, % &COA, , % "ahk_id " . HLV 97 | If (ErrorLevel = 0) || !(ErrorLevel + 0) 98 | Return False 99 | ColArray := [] 100 | Loop, %Cols% 101 | ColArray.Insert(NumGet(COA, 4 * (A_Index - 1), "Int") + 1) 102 | Return ColArray 103 | } 104 | ; ====================================================================================================================== 105 | ; LV_EX_GetColumnWidth - Gets the width of a column in report or list view. 106 | ; ====================================================================================================================== 107 | LV_EX_GetColumnWidth(HLV, Column) { 108 | Static LVM_GETCOLUMNWIDTH := 0x101D 109 | SendMessage, % LVM_GETCOLUMNWIDTH, % (Column - 1), 0, , % "ahk_id " . HLV 110 | Return ErrorLevel 111 | } 112 | ; ====================================================================================================================== 113 | ; LV_EX_GetExtendedStyle - Gets the extended styles that are currently in use for a given list-view control. 114 | ; ====================================================================================================================== 115 | LV_EX_GetExtendedStyle(HLV) { 116 | Static LVM_GETEXTENDEDLISTVIEWSTYLE := 0x1037 117 | SendMessage, % LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0, , % "ahk_id " . HLV 118 | Return ErrorLevel 119 | } 120 | ; ====================================================================================================================== 121 | ; LV_EX_GetHeader - Retrieves the handle to the header control used by the list-view control. 122 | ; ====================================================================================================================== 123 | LV_EX_GetHeader(HLV) { 124 | Static LVM_GETHEADER := 0x101F 125 | SendMessage, % LVM_GETHEADER, 0, 0, , % "ahk_id " . HLV 126 | Return ErrorLevel 127 | } 128 | ; ====================================================================================================================== 129 | ; LV_EX_GetItemParam - Retrieves the value of the item's lParam field. 130 | ; ====================================================================================================================== 131 | LV_EX_GetItemParam(HLV, Row) { 132 | Static LVM_GETITEM := A_IsUnicode ? 0x104B : 0x1005 ; LVM_GETITEMW : LVM_GETITEMA 133 | Static LVITEMSize := 48 + (A_PtrSize * 3) 134 | Static LVIF_PARAM := 0x00000004 135 | Static OffParam := 24 + (A_PtrSize * 2) 136 | VarSetCapacity(LVITEM, LVITEMSize, 0) 137 | NumPut(LVIF_PARAM, LVITEM, 0, "UInt") 138 | NumPut(Row - 1, LVITEM, 4, "Int") 139 | SendMessage, % LVM_SETITEM, 0, % &LVITEM, , % "ahk_id " . HLV 140 | Return NumGet(LVITEM, OffParam, "UPtr") 141 | } 142 | ; ====================================================================================================================== 143 | ; LV_EX_GetItemRect - Retrieves the bounding rectangle for all or part of an item in the current view. 144 | ; ====================================================================================================================== 145 | LV_EX_GetItemRect(HLV, Row := 1, LVIR := 0) { 146 | Static LVM_GETITEMRECT := 0x100E 147 | VarSetCapacity(RECT, 16, 0) 148 | NumPut(LVIR, RECT, 0, "Int") 149 | SendMessage, % LVM_GETITEMRECT, % (Row - 1), % &RECT, , % "ahk_id " . HLV 150 | If (ErrorLevel = 0) || !(ErrorLevel + 0) 151 | Return False 152 | Result := {} 153 | Result.X := NumGet(RECT, 0, "Int") 154 | Result.Y := NumGet(RECT, 4, "Int") 155 | Result.R := NumGet(RECT, 8, "Int") 156 | Result.B := NumGet(RECT, 12, "Int") 157 | Result.W := Result.R - Result.X 158 | Result.H := Result.B - Result.Y 159 | Return Result 160 | } 161 | ; ====================================================================================================================== 162 | ; LV_EX_GetItemState - Retrieves the state of a list-view item. 163 | ; ====================================================================================================================== 164 | LV_EX_GetItemState(HLV, Row) { 165 | Static LVM_GETITEMSTATE := 0x102C 166 | Static LVIS := {Cut: 0x04, DropHilited: 0x08, Focused: 0x01, Selected: 0x02, Checked: 0x2000} 167 | Static ALLSTATES := 0xFFFF ; not defined in MSDN 168 | SendMessage, % LVM_GETITEMSTATE, % (Row - 1), % ALLSTATES, , % "ahk_id " . HLV 169 | If (ErrorLevel + 0) { 170 | States := ErrorLevel 171 | Result := {} 172 | For Key, Value In LVIS 173 | Result[Key] := !!(States & Value) 174 | Return Result 175 | } 176 | Return False 177 | } 178 | ; ====================================================================================================================== 179 | ; LV_EX_GetRowHeight - Gets the height of the specified row. 180 | ; ====================================================================================================================== 181 | LV_EX_GetRowHeight(HLV, Row := 1) { 182 | Return LV_EX_GetItemRect(HLV, Row).H 183 | } 184 | ; ====================================================================================================================== 185 | ; LV_EX_GetRowsPerPage - Calculates the number of items that can fit vertically in the visible area of a list-view 186 | ; control when in list or report view. Only fully visible items are counted. 187 | ; ====================================================================================================================== 188 | LV_EX_GetRowsPerPage(HLV) { 189 | Static LVM_GETCOUNTPERPAGE := 0x1028 190 | SendMessage, % LVM_GETCOUNTPERPAGE, 0, 0, , % "ahk_id " . HLV 191 | Return ErrorLevel 192 | } 193 | ; ====================================================================================================================== 194 | ; LV_EX_GetSubItemRect - Retrieves information about the bounding rectangle for a subitem in a list-view control. 195 | ; ====================================================================================================================== 196 | LV_EX_GetSubItemRect(HLV, Column, Row := 1, LVIR := 0) { 197 | Static LVM_GETSUBITEMRECT := 0x1038 198 | VarSetCapacity(RECT, 16, 0) 199 | NumPut(LVIR, RECT, 0, "Int") 200 | NumPut(Column - 1, RECT, 4, "Int") 201 | If (Column = 1) 202 | W := LV_EX_GetColumnWidth(HLV, 1) 203 | SendMessage, % LVM_GETSUBITEMRECT, % (Row - 1), % &RECT, , % "ahk_id " . HLV 204 | If (ErrorLevel = 0) || !(ErrorLevel + 0) 205 | Return False 206 | Result := {} 207 | Result.X := NumGet(RECT, 0, "Int") 208 | Result.Y := NumGet(RECT, 4, "Int") 209 | Result.R := Column = 1 ? Result.X + W : NumGet(RECT, 8, "Int") 210 | Result.B := NumGet(RECT, 12, "Int") 211 | Result.W := Column = 1 ? W : Result.R - Result.X 212 | Result.H := Result.B - Result.Y 213 | Return Result 214 | } 215 | ; ====================================================================================================================== 216 | ; LV_EX_GetTopIndex - Retrieves the index of the topmost visible item when in list or report view. 217 | ; ====================================================================================================================== 218 | LV_EX_GetTopIndex(HLV) { 219 | Static LVM_GETTOPINDEX := 0x1027 220 | SendMessage, % LVM_GETTOPINDEX, 0, 0, , % "ahk_id " . HLV 221 | Return (ErrorLevel + 1) 222 | } 223 | ; ====================================================================================================================== 224 | ; LV_EX_GetView - Retrieves the current view of a list-view control. 225 | ; ====================================================================================================================== 226 | LV_EX_GetView(HLV) { 227 | Static LVM_GETVIEW := 0x108F 228 | Static Views := {0x00: "Icon", 0x01: "Report", 0x02: "IconSmall", 0x03: "List", 0x04: "Tile"} 229 | SendMessage, % LVM_GETVIEW, 0, 0, , % "ahk_id " . HLV 230 | Return Views[ErrorLevel] 231 | } 232 | ; ====================================================================================================================== 233 | ; LV_EX_IsRowChecked - Indicates if a row in the list-view control is checked. 234 | ; ====================================================================================================================== 235 | LV_EX_IsRowChecked(HLV, Row) { 236 | Return LV_EX_GetItemState(HLV, Row).Checked 237 | } 238 | ; ====================================================================================================================== 239 | ; LV_EX_IsRowFocused - Indicates if a row in the list-view control is focused. 240 | ; ====================================================================================================================== 241 | LV_EX_IsRowFocused(HLV, Row) { 242 | Return LV_EX_GetItemState(HLV, Row).Focused 243 | } 244 | ; ====================================================================================================================== 245 | ; LV_EX_IsRowSelected - Indicates if a row in the list-view control is selected. 246 | ; ====================================================================================================================== 247 | LV_EX_IsRowSelected(HLV, Row) { 248 | Return LV_EX_GetItemState(HLV, Row).Selected 249 | } 250 | ; ====================================================================================================================== 251 | ; LV_EX_IsRowVisible - Indicates if a row in the list-view control is visible. 252 | ; ====================================================================================================================== 253 | LV_EX_IsRowVisible(HLV, Row) { 254 | Static LVM_ISITEMVISIBLE := 0x10B6 255 | SendMessage, % LVM_ISITEMVISIBLE, % (Row - 1), 0, , % "ahk_id " . HLV 256 | Return ErrorLevel 257 | } 258 | ; ====================================================================================================================== 259 | ; CommCtrl.h: 260 | ; These next to methods make it easy to identify an item that can be repositioned within listview. 261 | ; For example: 262 | ; Many developers use the lParam to store an identifier that is unique. Unfortunatly, in order to find this item, 263 | ; they have to iterate through all of the items in the listview. 264 | ; Listview will maintain a unique identifier. The upper bound is the size of a DWORD. 265 | ; ====================================================================================================================== 266 | ; LV_EX_MapIDToIndex - Maps the ID of an item to an index. 267 | ; ====================================================================================================================== 268 | LV_EX_MapIDToIndex(HLV, ID) { 269 | Static LVM_MAPIDTOINDEX := 0x10B5 270 | SendMessage, % LVM_MAPIDTOINDEX, % ID, 0, , % "ahk_id " . HLV 271 | Return (ErrorLevel + 1) 272 | } 273 | ; ====================================================================================================================== 274 | ; LV_EX_MapIndexToID - Maps the index of an item to a unique ID. 275 | ; ====================================================================================================================== 276 | LV_EX_MapIndexToID(HLV, Index) { 277 | Static LVM_MAPINDEXTOID := 0x10B4 278 | SendMessage, % LVM_MAPINDEXTOID, % (Index - 1), 0, , % "ahk_id " . HLV 279 | Return ErrorLevel 280 | } 281 | ; ====================================================================================================================== 282 | ; LV_EX_RedrawRows - Forces a list-view control to redraw a range of items. 283 | ; ====================================================================================================================== 284 | LV_EX_RedrawRows(HLV, FirstRow, LastRow := -1) { 285 | Static LVM_GETITEMCOUNT := 0x1004 286 | Static LVM_REDRAWITEMS := 0x1015 287 | If (LastRow = -1) { 288 | SendMessage, % LVM_GETITEMCOUNT, 0, 0, , % "ahk_id " . HLV 289 | LastRow := Errorlevel 290 | } 291 | SendMessage, % LVM_REDRAWITEMS, % (FirstRow - 1), % (LastRow - 1), , % "ahk_id " . HLV 292 | Return ErrorLevel 293 | } 294 | ; ====================================================================================================================== 295 | ; LV_EX_SetBkImage - Sets the background image in a list-view control. 296 | ; ====================================================================================================================== 297 | LV_EX_SetBkImage(HLV, ImagePath, Width := "", Height := "") { 298 | Static KnownControls := [] 299 | Static LVM_SETBKIMAGE := A_IsUnicode ? 0x108A : 0x1044 ; LVM_SETBKIMAGEW : LVM_SETBKIMAGEA 300 | Static LVS_EX_DOUBLEBUFFER := 0x00010000 301 | Static LVBKIF_TYPE_WATERMARK := 0x10000000 302 | Static LVBKIF_FLAG_ALPHABLEND := 0x20000000 303 | Static OSVERSION := (V := DllCall("Kernel32.dll\GetVersion", "UInt") & 0xFF) . "." . ((V >> 8) & 0xFF) 304 | Static STM_GETIMAGE := 0x0173 305 | HBITMAP := 0 306 | If (ImagePath) && FileExist(ImagePath) { 307 | W := H := "" 308 | If (Width = "") && (Height = "") { 309 | VarSetCapacity(RECT, 16, 0) 310 | DllCall("User32.dll\GetClientRect", "Ptr", HLV, "Ptr", &RECT) 311 | ControlGetPos, , , , HH, , % "ahk_id " . LV_EX_GetHeader(HLV) 312 | Width := NumGet(RECT, 8, "Int") 313 | Height := NumGet(RECT, 12, "Int") - HH 314 | } 315 | HMod := DllCall("Kernel32.dll\LoadLibrary", "Str", "Gdiplus.dll", "UPtr") 316 | VarSetCapacity(SI, 24, 0), NumPut(1, SI, "UInt") 317 | DllCall("Gdiplus.dll\GdiplusStartup", "PtrP", Token, "Ptr", &SI, "Ptr", 0) 318 | DllCall("Gdiplus.dll\GdipCreateBitmapFromFile", "WStr", ImagePath, "PtrP", Bitmap) 319 | DllCall("Gdiplus.dll\GdipCreateHBITMAPFromBitmap", "Ptr", Bitmap, "PtrP", HBITMAP, "UInt", 0x00FFFFFF) 320 | DllCall("Gdiplus.dll\GdipDisposeImage", "Ptr", Bitmap) 321 | DllCall("Gdiplus.dll\GdiplusShutdown", "Ptr", Token) 322 | DllCall("Kernel32.dll\FreeLibrary", "Ptr", HMod) 323 | HBITMAP := DllCall("User32.dll\CopyImage" 324 | , "Ptr", HBITMAP, "UInt", 0, "Int", Width, "Int", Height, "UInt", 0x2008, "UPtr") 325 | If !(HBITMAP) 326 | Return False 327 | } 328 | ; Set extended style LVS_EX_DOUBLEBUFFER to avoid drawing issues 329 | If !KnownControls.HasKey(HLV) { 330 | LV_EX_SetExtendedStyle(HLV, LVS_EX_DOUBLEBUFFER, LVS_EX_DOUBLEBUFFER) 331 | KnownControls[HLV] := True 332 | } 333 | Flags := LVBKIF_TYPE_WATERMARK 334 | If (OSVERSION >= 6) ; LVBKIF_FLAG_ALPHABLEND prevents to show the image on WinXP 335 | Flags |= LVBKIF_FLAG_ALPHABLEND 336 | LVBKIMAGESize := A_PtrSize = 8 ? 40 : 24 337 | VarSetCapacity(LVBKIMAGE, LVBKIMAGESize, 0) 338 | NumPut(Flags, LVBKIMAGE, 0, "UInt") 339 | NumPut(HBITMAP, LVBKIMAGE, A_PtrSize, "UPtr") 340 | SendMessage, % LVM_SETBKIMAGE, 0, % &LVBKIMAGE, , % "ahk_id " . HLV 341 | Return ErrorLevel 342 | } 343 | ; ====================================================================================================================== 344 | ; LV_EX_SetColumnOrder - Sets the left-to-right order of columns in a list-view control. 345 | ; ====================================================================================================================== 346 | LV_EX_SetColumnOrder(HLV, ColArray) { 347 | Static LVM_SETCOLUMNORDERARRAY := 0x103A 348 | Cols := ColArray.MaxIndex() 349 | VarSetCapacity(COA, Cols * 4, 0) 350 | For I, R In ColArray 351 | NumPut(R - 1, COA, (A_Index - 1) * 4, "Int") 352 | SendMessage, % LVM_SETCOLUMNORDERARRAY, % Cols, % &COA, , % "ahk_id " . HLV 353 | Return ErrorLevel 354 | } 355 | ; ====================================================================================================================== 356 | ; LV_EX_SetExtendedStyle - Sets extended styles in list-view controls. 357 | ; ====================================================================================================================== 358 | LV_EX_SetExtendedStyle(HLV, StyleMask, Styles) { 359 | Static LVM_SETEXTENDEDLISTVIEWSTYLE := 0x1036 360 | SendMessage, % LVM_SETEXTENDEDLISTVIEWSTYLE, % StyleMask, % Styles, , % "ahk_id " . HLV 361 | Return ErrorLevel 362 | } 363 | ; ====================================================================================================================== 364 | ; LV_EX_SetItemIndent - Sets the indent of the first column to the specified number of icon widths. 365 | ; ====================================================================================================================== 366 | LV_EX_SetItemIndent(HLV, Row, NumIcons) { 367 | Static LVM_SETITEM := A_IsUnicode ? 0x104C : 0x1006 ; LVM_SETITEMW : LVM_SETITEMA 368 | Static LVITEMSize := 48 + (A_PtrSize * 3) 369 | Static LVIF_INDENT := 0x00000010 370 | Static OffIndent := 24 + (A_PtrSize * 3) 371 | VarSetCapacity(LVITEM, LVITEMSize, 0) 372 | NumPut(LVIF_INDENT, LVITEM, 0, "UInt") 373 | NumPut(Row - 1, LVITEM, 4, "Int") 374 | NumPut(NumIcons, LVITEM, OffIndent, "Int") 375 | SendMessage, % LVM_SETITEM, 0, % &LVITEM, , % "ahk_id " . HLV 376 | Return ErrorLevel 377 | } 378 | ; ====================================================================================================================== 379 | ; LV_EX_SetItemParam - Sets the lParam field of the item to the specified value. 380 | ; ====================================================================================================================== 381 | LV_EX_SetItemParam(HLV, Row, Value) { 382 | Static LVM_SETITEM := A_IsUnicode ? 0x104C : 0x1006 ; LVM_SETITEMW : LVM_SETITEMA 383 | Static LVITEMSize := 48 + (A_PtrSize * 3) 384 | Static LVIF_PARAM := 0x00000004 385 | Static OffParam := 24 + (A_PtrSize * 2) 386 | VarSetCapacity(LVITEM, LVITEMSize, 0) 387 | NumPut(LVIF_PARAM, LVITEM, 0, "UInt") 388 | NumPut(Row - 1, LVITEM, 4, "Int") 389 | NumPut(Value, LVITEM, OffParam, "UPtr") 390 | SendMessage, % LVM_SETITEM, 0, % &LVITEM, , % "ahk_id " . HLV 391 | Return ErrorLevel 392 | } 393 | ; ====================================================================================================================== 394 | ; LV_EX_SetSubItemImage - Assigns an image from the list-view's image list to this subitem. 395 | ; ====================================================================================================================== 396 | LV_EX_SetSubItemImage(HLV, Row, Column, ImageIndex) { 397 | Static KnownControls := [] 398 | Static LVS_EX_SUBITEMIMAGES := 0x00000002 399 | Static LVM_SETITEM := A_IsUnicode ? 0x104C : 0x1006 ; LVM_SETITEMW : LVM_SETITEMA 400 | Static LVITEMSize := 48 + (A_PtrSize * 3) 401 | Static LVIF_IMAGE := 0x00000002 402 | Static OffImage := 20 + (A_PtrSize * 2) 403 | If !KnownControls.HasKey(HLV) { 404 | LV_EX_SetExtendedStyle(HLV, LVS_EX_SUBITEMIMAGES, LVS_EX_SUBITEMIMAGES) 405 | KnownControls[HLV] := True 406 | } 407 | VarSetCapacity(LVITEM, LVITEMSize, 0) 408 | NumPut(LVIF_IMAGE, LVITEM, 0, "UInt") 409 | NumPut(Row - 1, LVITEM, 4, "Int") 410 | NumPut(Column - 1, LVITEM, 8, "Int") 411 | NumPut(ImageIndex - 1, LVITEM, OffImage, "Int") 412 | SendMessage, % LVM_SETITEM, 0, % &LVITEM, , % "ahk_id " . HLV 413 | Return ErrorLevel 414 | } 415 | ; ====================================================================================================================== 416 | ; LV_EX_SubItemHitTest - Gets the column (subitem) at the passed coordinates or the position of the mouse cursor. 417 | ; ====================================================================================================================== 418 | LV_EX_SubItemHitTest(HLV, X := -1, Y := -1) { 419 | Static LVM_SUBITEMHITTEST := 0x1039 420 | VarSetCapacity(POINT, 8, 0) 421 | If (X = -1) || (Y = -1) { 422 | DllCall("User32.dll\GetCursorPos", "Ptr", &POINT) 423 | DllCall("User32.dll\ScreenToClient", "Ptr", HLV, "Ptr", &POINT) 424 | VarSetCapacity(LVHITTESTINFO, 24, 0) 425 | NumPut(NumGet(POINT, 0, "Int"), LVHITTESTINFO, 0, "Int") 426 | NumPut(NumGet(POINT, 4, "Int"), LVHITTESTINFO, 4, "Int") 427 | } Else { 428 | NumPut(X, LVHITTESTINFO, 0, "Int") 429 | NumPut(Y, LVHITTESTINFO, 4, "Int") 430 | } 431 | SendMessage, % LVM_SUBITEMHITTEST, 0, % &LVHITTESTINFO, , % "ahk_id " . HLV 432 | Return ErrorLevel > 0x7FFFFFFF ? 0 : (NumGet(LVHITTESTINFO, 16, "Int") + 1) 433 | } 434 | ; ====================================================================================================================== -------------------------------------------------------------------------------- /LV_SortArrow.ahk: -------------------------------------------------------------------------------- 1 | ; LV_SortArrow by Solar. http://www.autohotkey.com/forum/viewtopic.php?t=69642 2 | ; h = ListView handle 3 | ; c = 1 based index of the column 4 | ; d = Optional direction to set the arrow. "asc" or "up". "desc" or "down". 5 | LV_SortArrow(h, c, d="") { 6 | static ptr, ptrSize, lvColumn, LVM_GETCOLUMN, LVM_SETCOLUMN 7 | if (!ptr) 8 | ptr := A_PtrSize ? ("ptr", ptrSize := A_PtrSize) : ("uint", ptrSize := 4) 9 | ,LVM_GETCOLUMN := A_IsUnicode ? (4191, LVM_SETCOLUMN := 4192) : (4121, LVM_SETCOLUMN := 4122) 10 | ,VarSetCapacity(lvColumn, ptrSize + 4), NumPut(1, lvColumn, "uint") 11 | c -= 1, DllCall("SendMessage", ptr, h, "uint", LVM_GETCOLUMN, "uint", c, ptr, &lvColumn) 12 | if ((fmt := NumGet(lvColumn, 4, "int")) & 1024) { 13 | if (d && d = "asc" || d = "up") 14 | return 15 | NumPut(fmt & ~1024 | 512, lvColumn, 4, "int") 16 | } else if (fmt & 512) { 17 | if (d && d = "desc" || d = "down") 18 | return 19 | NumPut(fmt & ~512 | 1024, lvColumn, 4, "int") 20 | } else { 21 | Loop % DllCall("SendMessage", ptr, DllCall("SendMessage", ptr, h, "uint", 4127), "uint", 4608) 22 | if ((i := A_Index - 1) != c) 23 | DllCall("SendMessage", ptr, h, "uint", LVM_GETCOLUMN, "uint", i, ptr, &lvColumn) 24 | ,NumPut(NumGet(lvColumn, 4, "int") & ~1536, lvColumn, 4, "int") 25 | ,DllCall("SendMessage", ptr, h, "uint", LVM_SETCOLUMN, "uint", i, ptr, &lvColumn) 26 | NumPut(fmt | (d && d = "desc" || d = "down" ? 512 : 1024), lvColumn, 4, "int") 27 | } 28 | return DllCall("SendMessage", ptr, h, "uint", LVM_SETCOLUMN, "uint", c, ptr, &lvColumn) 29 | } -------------------------------------------------------------------------------- /MCode.ahk: -------------------------------------------------------------------------------- 1 | ; ---------------------------------------------------------------------------------------------------------------------- 2 | ; Function .....: MCode 3 | ; Description ..: Allocate memory and write Machine Code there. 4 | ; Parameters ...: cBuf - Binary buffer that will receive the machine code. 5 | ; ..............: sHex - Hexadecimal representation of the machine code as a string. 6 | ; Author .......: Laszlo - http://www.autohotkey.com/board/topic/19483-machine-code-functions-bit-wizardry/ 7 | ; ---------------------------------------------------------------------------------------------------------------------- 8 | MCode(ByRef cBuf, ByRef sHex) { 9 | VarSetCapacity(cBuf, szBuf:=StrLen(sHex)//2) 10 | Loop %szBuf% 11 | NumPut("0x" . SubStr(sHex, 2*A_Index-1, 2), cBuf, A_Index-1, "UChar") 12 | } 13 | 14 | ; ---------------------------------------------------------------------------------------------------------------------- 15 | ; Function .....: MCode_2 16 | ; Description ..: Allocate memory and write Machine Code there. 17 | ; Parameters ...: sMcode - String describing the machine code. 18 | ; Author .......: Bentschi 19 | ; ---------------------------------------------------------------------------------------------------------------------- 20 | MCode_2(ByRef sMcode) { 21 | Static e := {1:4, 2:1}, c := (A_PtrSize=8) ? "x64" : "x86" 22 | If ( !RegExMatch(sMcode, "^([0-9]+),(" c ":|.*?," c ":)([^,]+)", m) ) 23 | Return 24 | If ( !DllCall( "Crypt32.dll\CryptStringToBinary", Str,m3, UInt,0, UInt,e[m1], Ptr,0, UInt*,s, Ptr,0, Ptr, 0 ) ) 25 | Return 26 | p := DllCall( "GlobalAlloc", UInt,0, Ptr,s, Ptr ) 27 | If ( c == "x64" ) 28 | DllCall( "VirtualProtect", Ptr,p, Ptr,s, UInt,0x40, UInt*,op ) 29 | If ( DllCall( "Crypt32.dll\CryptStringToBinary", Str,m3, UInt,0, UInt,e[m1], Ptr,p, UInt*,s, Ptr,0, Ptr,0 ) ) 30 | Return p 31 | DllCall( "GlobalFree", Ptr,p ) 32 | } -------------------------------------------------------------------------------- /MD5.ahk: -------------------------------------------------------------------------------- 1 | ; =================================================================================== 2 | ; AHK Version ...: AHK_L 1.1.14.03 x64 Unicode 3 | ; Win Version ...: Windows 7 Professional x64 SP1 4 | ; Description ...: Checksum: MD5 5 | ; Calc MD5-Hash from String / Hex / File / Address 6 | ; http://en.wikipedia.org/wiki/MD5 7 | ; Version .......: 2014.02.26-1986 8 | ; Author ........: Bentschi 9 | ; Modified ......: jNizM 10 | ; =================================================================================== 11 | 12 | /* 13 | ; GLOBAL SETTINGS =================================================================== 14 | 15 | #Warn 16 | #NoEnv 17 | #SingleInstance Force 18 | SetBatchLines, -1 19 | 20 | ; SCRIPT ============================================================================ 21 | 22 | str := "The quick brown fox jumps over the lazy dog" 23 | MsgBox, % "String:`n" (str) "`n`nMD5:`n" MD5(str) 24 | 25 | hex := "54686520717569636b2062726f776e20666f78206a756d7073206f76657220746865206c617a7920646f67" 26 | MsgBox, % "Hex:`n" (hex) "`n`nMD5:`n" HexMD5(hex) 27 | 28 | file := "C:\Windows\notepad.exe" 29 | MsgBox, % "File:`n" (file) "`n`nMD5:`n" FileMD5(file) 30 | 31 | ExitApp 32 | */ 33 | 34 | ; MD5 =============================================================================== 35 | MD5(string, encoding = "UTF-8") 36 | { 37 | return CalcStringHash(string, 0x8003, encoding) 38 | } 39 | HexMD5(hexstring) 40 | { 41 | return CalcHexHash(hexstring, 0x8003) 42 | } 43 | FileMD5(filename) 44 | { 45 | return CalcFileHash(filename, 0x8003, 64 * 1024) 46 | } 47 | AddrMD5(addr, length) 48 | { 49 | return CalcAddrHash(addr, length, 0x8003) 50 | } 51 | 52 | ; CalcAddrHash ====================================================================== 53 | CalcAddrHash(addr, length, algid, byref hash = 0, byref hashlength = 0) 54 | { 55 | static h := [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, "a", "b", "c", "d", "e", "f"] 56 | static b := h.minIndex() 57 | hProv := hHash := o := "" 58 | if (DllCall("advapi32\CryptAcquireContext", "Ptr*", hProv, "Ptr", 0, "Ptr", 0, "UInt", 24, "UInt", 0xF0000000)) 59 | { 60 | if (DllCall("advapi32\CryptCreateHash", "Ptr", hProv, "UInt", algid, "UInt", 0, "UInt", 0, "Ptr*", hHash)) 61 | { 62 | if (DllCall("advapi32\CryptHashData", "Ptr", hHash, "Ptr", addr, "UInt", length, "UInt", 0)) 63 | { 64 | if (DllCall("advapi32\CryptGetHashParam", "Ptr", hHash, "UInt", 2, "Ptr", 0, "UInt*", hashlength, "UInt", 0)) 65 | { 66 | VarSetCapacity(hash, hashlength, 0) 67 | if (DllCall("advapi32\CryptGetHashParam", "Ptr", hHash, "UInt", 2, "Ptr", &hash, "UInt*", hashlength, "UInt", 0)) 68 | { 69 | loop % hashlength 70 | { 71 | v := NumGet(hash, A_Index - 1, "UChar") 72 | o .= h[(v >> 4) + b] h[(v & 0xf) + b] 73 | } 74 | } 75 | } 76 | } 77 | DllCall("advapi32\CryptDestroyHash", "Ptr", hHash) 78 | } 79 | DllCall("advapi32\CryptreleaseContext", "Ptr", hProv, "UInt", 0) 80 | } 81 | return o 82 | } 83 | 84 | ; CalcStringHash ==================================================================== 85 | CalcStringHash(string, algid, encoding = "UTF-8", byref hash = 0, byref hashlength = 0) 86 | { 87 | chrlength := (encoding = "CP1200" || encoding = "UTF-16") ? 2 : 1 88 | length := (StrPut(string, encoding) - 1) * chrlength 89 | VarSetCapacity(data, length, 0) 90 | StrPut(string, &data, floor(length / chrlength), encoding) 91 | return CalcAddrHash(&data, length, algid, hash, hashlength) 92 | } 93 | 94 | ; CalcHexHash ======================================================================= 95 | CalcHexHash(hexstring, algid) 96 | { 97 | length := StrLen(hexstring) // 2 98 | VarSetCapacity(data, length, 0) 99 | loop % length 100 | { 101 | NumPut("0x" SubStr(hexstring, 2 * A_Index -1, 2), data, A_Index - 1, "Char") 102 | } 103 | return CalcAddrHash(&data, length, algid) 104 | } 105 | 106 | ; CalcFileHash ====================================================================== 107 | CalcFileHash(filename, algid, continue = 0, byref hash = 0, byref hashlength = 0) 108 | { 109 | fpos := "" 110 | if (!(f := FileOpen(filename, "r"))) 111 | { 112 | return 113 | } 114 | f.pos := 0 115 | if (!continue && f.length > 0x7fffffff) 116 | { 117 | return 118 | } 119 | if (!continue) 120 | { 121 | VarSetCapacity(data, f.length, 0) 122 | f.rawRead(&data, f.length) 123 | f.pos := oldpos 124 | return CalcAddrHash(&data, f.length, algid, hash, hashlength) 125 | } 126 | hashlength := 0 127 | while (f.pos < f.length) 128 | { 129 | readlength := (f.length - fpos > continue) ? continue : f.length - f.pos 130 | VarSetCapacity(data, hashlength + readlength, 0) 131 | DllCall("RtlMoveMemory", "Ptr", &data, "Ptr", &hash, "Ptr", hashlength) 132 | f.rawRead(&data + hashlength, readlength) 133 | h := CalcAddrHash(&data, hashlength + readlength, algid, hash, hashlength) 134 | } 135 | return h 136 | } -------------------------------------------------------------------------------- /MatchItemFromList.ahk: -------------------------------------------------------------------------------- 1 | ; Written by TheGood - http://www.autohotkey.com/board/topic/35990-string-matching-using-trigrams/ 2 | 3 | MatchItemFromList(iPtr, iCount, sItem) { 4 | 5 | /* 6 | ;iPtr is a pointer to the list of string pointers 7 | ;Here is an example on how to use it 8 | ;Prepare the list of pointers 9 | VarSetCapacity(ptr, iCount * 4, 0) ;iCount = the number of items in the list 10 | ;Add the string pointers to the list 11 | i := &ptr 12 | Loop %iCount% 13 | i := NumPut(&sList%A_Index%, i+0) 14 | ;Call function 15 | MatchItemFromList(&ptr, iCount, sItem) 16 | */ 17 | 18 | ;Get length 19 | iLength := StrLen(sItem) 20 | iTrigrams := iLength - 2 21 | 22 | ;Retrieve all the strings 23 | Loop %iCount% 24 | sList%A_Index% := DllCall("MulDiv", int, NumGet(iPtr+0, (A_Index - 1) * 4), int, 1, int, 1, str) 25 | 26 | ;Check for a clean match first 27 | Loop %iCount% 28 | If (sList%A_Index% = sItem) 29 | Return (100 << 16) + A_Index 30 | 31 | ;CREATE ARRAY OF TRIGRAMS FOR sItem 32 | If (iLength < 3) 33 | Return 0 ;Invalid item 34 | Else { ;Get trigram count 35 | Loop %iTrigrams% { 36 | 37 | ;Check if the trigram we're about to extract is unique 38 | i := InStr(sItem, SubStr(sItem, A_Index, 3), False, 1) 39 | If i And (i < A_Index) { 40 | sItem_%i% += 1 ;Not unique. Add count to original 41 | sItem_%A_Index% := 0 ;Discard current index 42 | } Else sItem_%A_Index% := InStrCount(sItem, SubStr(sItem, A_Index, 3)) 43 | } 44 | } 45 | 46 | ;COMPARE TRIGRAMS 47 | Loop %iCount% { 48 | i := A_Index 49 | If (StrLen(sList%i%) < 3) 50 | Return 0 ;Invalid item 51 | Else { 52 | Loop %iTrigrams% ;Get trigram count 53 | If sItem_%A_Index% 54 | sList%i%_Diff += Abs(InStrCount(sList%i%, SubStr(sItem, A_Index, 3)) - sItem_%A_Index%) 55 | } 56 | } 57 | 58 | iBestI := 0 59 | iBestD := 0x10000 60 | Loop %iCount% { 61 | If (sList%A_Index%_Diff < iBestD) { 62 | iBestD := sList%A_Index%_Diff 63 | iBestI := A_Index 64 | } 65 | } 66 | 67 | ;Put the winning index in the low-word and a number between 0 and 100 representing the "fitness" of the match in the high-word 68 | Return (Round((iTrigrams - iBestD) * 100 / iTrigrams) << 16) + iBestI 69 | } 70 | 71 | ;Returns the number of times a trigrams occurs in a string 72 | InStrCount(ByRef Haystack, Trigram) { 73 | j := 0, i := 1 74 | Loop { 75 | i := InStr(Haystack, Trigram, False, i) 76 | If Not i 77 | Return j 78 | j += 1, i += 3 79 | } 80 | } 81 | 82 | 83 | /* EXAMPLE: 84 | 85 | MyItem = 2008 - The Dark Knight 86 | 87 | s1 := "The Dark Knight's Dog" 88 | s2 := "The Dark Knight [2008]" 89 | s3 := "Dark Nights" 90 | s4 := "Dark Nightmares on Elm Street" 91 | 92 | VarSetCapacity(ptr, 16) 93 | i := &ptr 94 | Loop 4 95 | i := NumPut(&s%A_Index%, i+0) 96 | 97 | ;Call function 98 | i := MatchItemFromList(&ptr, 4, MyItem), l := i & 0xFFFF, h := i >> 16 99 | MsgBox % "Winning index: " l "`nWinning title: " s%l% "`nMatch fitness: " h "%" 100 | 101 | Return 102 | 103 | */ -------------------------------------------------------------------------------- /NetShareEnum.ahk: -------------------------------------------------------------------------------- 1 | ; ---------------------------------------------------------------------------------------------------------------------- 2 | ; Function .....: NetShareEnum 3 | ; Description ..: Implements the NetShareEnum Win32 API. Retrieves information about each shared resource on a server. 4 | ; Parameters ...: sName - DNS name of the computer where to run the function. If empty, will be localhost. 5 | ; Return .......: -1 - NetShareEnum error. 6 | ; ..............: -2 - NetApiBufferFree error. 7 | ; ..............: In case of success an array of objects describing the shares will be returned. The array has the 8 | ; ..............: following structure: 9 | ; ..............: Array[n] -> Object.netname 10 | ; ..............: -> Object.type 11 | ; ..............: -> Object.remark 12 | ; ..............: -> Object.permissions 13 | ; ..............: -> Object.max_uses 14 | ; ..............: -> Object.current_uses 15 | ; ..............: -> Object.path 16 | ; ..............: -> Object.passwd 17 | ; ..............: -> Object.reserved 18 | ; ..............: -> Object.security_descriptor 19 | ; Remarks ......: The information returned are described by the SHARE_INFO_502 structure: 20 | ; ..............: http://msdn.microsoft.com/en-us/library/windows/desktop/bb525410%28v=vs.85%29.aspx 21 | ; AHK Version ..: AHK_L 1.1.13.01 x32/64 Unicode 22 | ; Author .......: Cyruz (http://ciroprincipe.info) 23 | ; License ......: WTFPL - http://www.wtfpl.net/txt/copying/ 24 | ; Changelog ....: Apr. 13, 2014 - v0.1 - First version. 25 | ; ---------------------------------------------------------------------------------------------------------------------- 26 | NetShareEnum(sName:="") { 27 | Static szS_I_502 := (A_PtrSize == 4) ? 40 : 72 28 | 29 | ; Level = 502 30 | If ( DllCall( "Netapi32.dll\NetShareEnum", Ptr,(sName)?&sName:0, UInt,502, PtrP,S_I_502, UInt,-1, UIntP,nER 31 | , UIntP,nTE, UIntP,nResume ) ) 32 | Return -1 33 | objShare := Object() 34 | Loop %nER% 35 | { 36 | addr := S_I_502 + szS_I_502 * (A_Index-1) 37 | objShare.Insert({ "netname" : StrGet(NumGet(addr+0, 0, "Ptr"), "UTF-16") 38 | , "type" : NumGet(addr+0, A_PtrSize, "UInt") 39 | , "remark" : StrGet(NumGet(addr+0, A_PtrSize * 2, "Ptr"), "UTF-16") 40 | , "permissions" : NumGet(addr+0, A_PtrSize * 3, "UInt") 41 | , "max_uses" : NumGet(addr+0, (A_PtrSize == 4) ? 16 : 28, "UInt") 42 | , "current_uses" : NumGet(addr+0, (A_PtrSize == 4) ? 20 : 32, "UInt") 43 | , "path" : StrGet(NumGet(addr+0, (A_PtrSize == 4) ? 24 : 40, "Ptr"), "UTF-16") 44 | , "passwd" : StrGet(NumGet(addr+0, (A_PtrSize == 4) ? 28 : 48, "Ptr"), "UTF-16") 45 | , "reserved" : StrGet(NumGet(addr+0, (A_PtrSize == 4) ? 32 : 56, "Ptr"), "UTF-16") 46 | , "security_descriptor" : NumGet(addr+0, (A_PtrSize == 4) ? 36 : 64, "Ptr") }) 47 | } 48 | If ( DllCall( "Netapi32.dll\NetApiBufferFree", Ptr,S_I_502 ) ) 49 | Return -2 50 | Return objShare 51 | } -------------------------------------------------------------------------------- /PECreateEmpty.ahk: -------------------------------------------------------------------------------- 1 | ; ---------------------------------------------------------------------------------------------------------------------- 2 | ; Function .....: PECreateEmpty 3 | ; Description ..: Create an empty PE binary file. This dummy executable was created with Visual C++ 2010 Express, with 4 | ; ..............: all possible optimizations so that the final size is 1KB. If run, this executable will show a message 5 | ; ..............: box and return. 6 | ; Parameters ...: sFile - Path to the file to be created. 7 | ; Author .......: Cyruz - http://ciroprincipe.info 8 | ; License ......: WTFPL - http://www.wtfpl.net/txt/copying/ 9 | ; Changelog ....: Jan. 12, 2015 - v0.1 - First Version. 10 | ; ---------------------------------------------------------------------------------------------------------------------- 11 | PECreateEmpty(sFile) { 12 | Static sDummy := "" ; Dummy executable. 13 | . "4d5a90000300000004000000ffff0000b8000000000000004000000000000000000000000000000000000000000000000000000000000000" 14 | . "00000000c00000000e1fba0e00b409cd21b8014ccd21546869732070726f6772616d2063616e6e6f742062652072756e20696e20444f5320" 15 | . "6d6f64652e0d0d0a240000000000000061af10dc25ce7e8f25ce7e8f25ce7e8f2cb6ed8f26ce7e8f25ce7f8f24ce7e8f4ab8d58f24ce7e8f" 16 | . "4ab8e38f24ce7e8f5269636825ce7e8f0000000000000000504500004c010100a4a8b2540000000000000000e00003010b010a0000020000" 17 | . "0000000000000000ca1000000010000000200000000040000010000000020000050001000000000005000100000000000020000000020000" 18 | . "00000000020000850000100000100000000010000010000000000000100000000000000000000000e4100000280000000000000000000000" 19 | . "000000000000000000000000000000000000000000000000101000001c000000000000000000000000000000000000000000000000000000" 20 | . "0000000000000000000000000000000000100000080000000000000000000000000000000000000000000000000000002e74657874000000" 21 | . "2e01000000100000000200000002000000000000000000000000000020000060000000000000000000000000000000000000000000000000" 22 | . "00000000000000001411000000000000000000000000000000000000a4a8b254000000000200000079000000501000005002000054686973" 23 | . "20697320612064756d6d792065786563757461626c652e0044756d6d79000000525344537702078caf1e054581291db9c1339ef103000000" 24 | . "3030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030303030" 25 | . "3030303030303030303030303030303030303030303030303030303030303030303030303030303000006a006848104000682c1040006a00" 26 | . "ff150010400033c040c210000c11000000000000000000002211000000100000000000000000000000000000000000000000000014110000" 27 | . "000000000e024d657373616765426f7841005553455233322e646c6c00000000000000000000000000000000000000000000000000000000" 28 | . "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" 29 | . "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" 30 | . "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" 31 | . "0000000000000000000000000000000" 32 | If ( !IsObject(objFile := FileOpen(sFile, "w")) ) 33 | Return 0 34 | szBuf := VarSetCapacity(cBuf, StrLen(sDummy)//2) 35 | Loop % StrLen(sDummy)//2 ; Laszlo's MCode. 36 | NumPut("0x" . SubStr(sDummy, 2*A_Index-1, 2), cBuf, A_Index-1, "Char") 37 | objFile.RawWrite(&cBuf, szBuf) 38 | objFile.Close() 39 | Return 1 40 | } 41 | -------------------------------------------------------------------------------- /PipeRun.ahk: -------------------------------------------------------------------------------- 1 | ; ---------------------------------------------------------------------------------------------------------------------- 2 | ; Function .....: PipeRun 3 | ; Description ..: Runs an AutoHotkey script dynamically through a pipe. 4 | ; Parameters ...: sScript - Script to execute. 5 | ; ..............: sExe - Path to the desired AutoHotkey executable. 6 | ; Return .......: -1 if the executable doesn't exists, 0 on pipe error, 1 on success. 7 | ; AHK Version ..: AHK_L x32/64 Unicode 8 | ; Author .......: Cyruz (http://ciroprincipe.info) - from a lexikos idea and code (http://goo.gl/6H4UPB) 9 | ; License ......: WTFPL - http://www.wtfpl.net/txt/copying/ 10 | ; Changelog ....: Dic. 07, 2013 - v0.1 - First version. 11 | ; ---------------------------------------------------------------------------------------------------------------------- 12 | PipeRun(sScript, sExe:="") { 13 | If ( !sExe || !FileExist(sExe) ) { 14 | If ( A_AhkPath ) 15 | sExe := A_AhkPath 16 | Else Return -1 17 | } 18 | 19 | ; Before reading the file, AutoHotkey calls GetFileAttributes(). This causes the 20 | ; pipe to close, so we must create a second pipe for the actual file contents. 21 | hPipe_fake := DllCall( "CreateNamedPipe", Str,"\\.\pipe\AHKPipe", UInt,2, UInt,0 22 | , UInt,255, UInt,0, UInt,0, UInt,0, Ptr,0, Ptr ) 23 | hPipe_real := DllCall( "CreateNamedPipe", Str,"\\.\pipe\AHKPipe", UInt,2, UInt,0 24 | , UInt,255, UInt,0, UInt,0, UInt,0, Ptr,0, Ptr ) 25 | If ( hPipe_fake == -1 || hPipe_real == -1 ) 26 | Return 0 27 | 28 | ; Standard AHK needs a UTF-8 BOM to work via pipe. 29 | sScript := ((A_IsUnicode) ? chr(0xfeff) : chr(239) chr(187) chr(191)) . sScript 30 | nSize := (StrLen(sScript)+1)*((A_IsUnicode) ? 2 : 1) 31 | Run, %sExe% "\\.\pipe\AHKPipe" 32 | DllCall( "ConnectNamedPipe", Ptr,hPipe_fake, Ptr,0 ) 33 | DllCall( "CloseHandle", Ptr,hPipe_fake ) 34 | DllCall( "ConnectNamedPipe", Ptr,hPipe_real, Ptr,0 ) 35 | DllCall( "WriteFile", Ptr,hPipe_real, Str,sScript, UInt,nSize, UInt,0, Ptr,0 ) 36 | DllCall( "CloseHandle", Ptr,hPipe_real ) 37 | Return 1 38 | } -------------------------------------------------------------------------------- /Process.ahk: -------------------------------------------------------------------------------- 1 | ; ---------------------------------------------------------------------------------------------------------------------- 2 | ; Name .........: Process library 3 | ; Description ..: Processes related functions library. 4 | ; AHK Version ..: AHK_L 1.1.13.01 x32/64 Unicode 5 | ; Author .......: Cyruz (http://ciroprincipe.info) 6 | ; License ......: WTFPL - http://www.wtfpl.net/txt/copying/ 7 | ; Changelog ....: Jul. 28, 2015 - v0.1 - First verision. 8 | ; ---------------------------------------------------------------------------------------------------------------------- 9 | 10 | ; ---------------------------------------------------------------------------------------------------------------------- 11 | ; Function .....: Process_GetImageFileName 12 | ; Description ..: Return the full path of the process. 13 | ; Parameters ...: nPid - Id of the process. 14 | ; Return .......: Process filename as a string. 15 | ; ---------------------------------------------------------------------------------------------------------------------- 16 | Process_GetImageFileName(nPid) 17 | { 18 | ; PROCESS_ALL_ACCESS = 0x0001F0FFF 19 | hProc := DllCall( "OpenProcess", UInt,0x0001F0FFF, Int,0, Ptr,nPid ) 20 | 21 | szBuf := VarSetCapacity( cBuf, 32767, 0 ) ; MAX filename length = 32767. 22 | nLen := DllCall( "Psapi.dll\GetProcessImageFileName", Ptr,hProc, Ptr,&cBuf, UInt,szBuf ) 23 | 24 | nFileName := StrGet( &cBuf, nLen ) 25 | DllCall( "CloseHandle", Ptr,hProc ) 26 | 27 | Return nFileName 28 | } 29 | 30 | ; ---------------------------------------------------------------------------------------------------------------------- 31 | ; Function .....: Process_GetParentPid 32 | ; Description ..: Return the process id of the parent process of the given process id. 33 | ; Parameters ...: nPid - Id of the process whose we need the parent id. 34 | ; Return .......: Parent process id. 35 | ; Remarks ......: NtQueryInformationProcess called with ProcessBasicInformation as ProcessInformationClass returns a PEB 36 | ; ..............: structure with the following layout: 37 | ; ..............: ###################################################### 38 | ; ..............: typedef struct _PROCESS_BASIC_INFORMATION 39 | ; ..............: { 40 | ; ..............: PVOID ExitStatus; 41 | ; ..............: PPEB PebBaseAddress; 42 | ; ..............: PVOID AffinityMask; 43 | ; ..............: PVOID BasePriority; 44 | ; ..............: ULONG_PTR UniqueProcessId; 45 | ; ..............: PVOID InheritedFromUniqueProcessId; 46 | ; ..............: } PROCESS_BASIC_INFORMATION; 47 | ; ..............: 48 | ; ..............: OFFSET | SIZE 49 | ; ..............: [0] | [4/8] PVOID ExitStatus 50 | ; ..............: [4/8] | [4/8] PPEB PebBaseAddress 51 | ; ..............: [8/16] | [4/8] PVOID AffinityMask 52 | ; ..............: [12/24] | [4/8] PVOID BasePriority 53 | ; ..............: [16/32] | [4/8] ULONG_PTR UniqueProcessId 54 | ; ..............: [20/40] | [4/8] PVOID InheritedFromUniqueProcessId 55 | ; ..............: 56 | ; ..............: 32 bit size = 4 + 4 + 4 + 4 + 4 + 4 = 24 bytes 57 | ; ..............: 64 bit size = 8 + 8 + 8 + 8 + 8 + 8 = 48 bytes 58 | ; ..............: ###################################################### 59 | ; ---------------------------------------------------------------------------------------------------------------------- 60 | Process_GetParentPid(nPid) 61 | { 62 | ; PROCESS_ALL_ACCESS = 0x0001F0FFF 63 | hProc := DllCall( "OpenProcess", UInt,0x0001F0FFF, Int,0, Ptr,nPid ) 64 | 65 | ; ProcessBasicInformation = 0 66 | szBuf := VarSetCapacity( cBuf, A_PtrSize*6, 0 ) 67 | DllCall( "Ntdll.dll\NtQueryInformationProcess", Ptr,hProc, Int,0, Ptr,&cBuf, UInt,szBuf ) 68 | 69 | nParentPid := Numget( &cBuf, A_PtrSize*5, "Ptr" ) 70 | DllCall( "CloseHandle", Ptr,hProc ) 71 | 72 | Return nParentPid 73 | } 74 | 75 | ; ---------------------------------------------------------------------------------------------------------------------- 76 | ; Function .....: Process_GetSystemHandles 77 | ; Description ..: Return a collection of all the system handles. 78 | ; Parameters ...: sPidList - Comma separated list of the PIDs for which we want to retrieve the handles. 79 | ; Return .......: An associative array, with PIDs as indexes, where each element is an array of objects describing the 80 | ; ..............: handles. Each object is a direct implementation of the _SYSTEM_HANDLE_TABLE_ENTRY_INFO struct. 81 | ; ..............: The associative array is structured as the following: 82 | ; ..............: Array[PID] -> Array[n] -> Object.ObjectTypeNumber 83 | ; ..............: .Flags 84 | ; ..............: .Handle 85 | ; ..............: .Object 86 | ; ..............: .GrantedAccess 87 | ; Remarks ......: The structures used are not well documented, so this is what I discovered: 88 | ; ..............: 89 | ; ..............: The following are the structures used by NtQuerySystemInformation to return the handles: 90 | ; ..............: ########################################################### 91 | ; ..............: typedef struct _SYSTEM_HANDLE_TABLE_ENTRY_INFO 92 | ; ..............: { 93 | ; ..............: ULONG ProcessId; 94 | ; ..............: BYTE ObjectTypeNumber; 95 | ; ..............: BYTE Flags; 96 | ; ..............: USHORT Handle; 97 | ; ..............: PVOID Object; 98 | ; ..............: ACCESS_MASK GrantedAccess; 99 | ; ..............: } SYSTEM_HANDLE, *PSYSTEM_HANDLE; 100 | ; ..............: 101 | ; ..............: OFFSET | SIZE 102 | ; ..............: [0] | [4] ULONG ProcessId 103 | ; ..............: [4] | [1] BYTE ObjectTypeNumber 104 | ; ..............: [5] | [1] BYTE Flags 105 | ; ..............: [6] | [2] USHORT Handle 106 | ; ..............: [8] | [4/8] PVOID Object 107 | ; ..............: [12/16] | [4] ACCESS_MASK GrantedAccess 108 | ; ..............: 109 | ; ..............: 32 bit size = 4 + 1 + 1 + 2 + 4 + 4 = 16 bytes 110 | ; ..............: 64 bit size = 4 + 1 + 1 + 2 + 8 + 4 + 4(padding) = 24 bytes 111 | ; ..............: ########################################################### 112 | ; ..............: typedef struct _SYSTEM_HANDLE_INFORMATION 113 | ; ..............: { 114 | ; ..............: ULONG HandleCount; 115 | ; ..............: SYSTEM_HANDLE Handles[1]; 116 | ; ..............: } SYSTEM_HANDLE_INFORMATION, *PSYSTEM_HANDLE_INFORMATION; 117 | ; ..............: 118 | ; ..............: OFFSET | SIZE 119 | ; ..............: [0] | [4] ULONG HandleCount 120 | ; ..............: [4] | [16/24] SYSTEM_HANDLE Handles[1] 121 | ; ..............: 122 | ; ..............: 32 bit size = 4 + 16*n = 20 bytes if n = 1 123 | ; ..............: 64 bit size = 4 + 24*n + 4(padding) = 32 bytes if n = 1 124 | ; ..............: ########################################################### 125 | ; ---------------------------------------------------------------------------------------------------------------------- 126 | Process_GetSystemHandles(sPidList:="") 127 | { 128 | ; SystemHandleInformation = 16 129 | ; We need the first call to get the required size as nOutLen. 130 | szBuf := VarSetCapacity( cBuf, 1024, 0 ) 131 | DllCall( "Ntdll.dll\NtQuerySystemInformation", UInt,16, Ptr,&cBuf, UInt,szBuf, UIntP,nOutLen ) 132 | ; We adjust the buffer size and call the function again. 133 | szBuf := VarSetCapacity( cBuf, nOutLen, 0 ) 134 | DllCall( "Ntdll.dll\NtQuerySystemInformation", UInt,16, Ptr,&cBuf, UInt,szBuf, UIntP,nOutLen ) 135 | 136 | arrPids := [], nIdx := 4 ; Start from 4 because of HandleCount. 137 | Loop % NumGet(&cBuf, 0, "UInt") ; HandleCount. 138 | { 139 | nPid := NumGet(&cBuf, nIdx+0, "UInt") 140 | If ( sPidList != "" && !InStr(sPidList, nPid) ) 141 | Continue ; Go on with next PID if this one is not in the list. 142 | If ( !arrPids.HasKey(nPid) ) 143 | arrPids[nPid] := [] 144 | arrPids[nPid].Insert({ "ObjectTypeNumber": NumGet( &cBuf, nIdx+4, "UChar" ) 145 | , "Flags": NumGet( &cBuf, nIdx+5, "UChar" ) 146 | , "Handle": NumGet( &cBuf, nIdx+6, "UShort" ) 147 | , "Object": NumGet( &cBuf, nIdx+8, "Ptr" ) 148 | , "GrantedAccess": NumGet( &cBuf, nIdx+8+A_PtrSize, "UInt" ) }) 149 | nIdx += (A_PtrSize == 4) ? 16 : 24 150 | } 151 | 152 | VarSetCapacity(cBuf, 0) ; Free buffer. 153 | Return arrPids 154 | } 155 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | AutoHotkey libraries for my projects 2 | -------------------------------- 3 | cyruz - http://ciroprincipe.info -------------------------------------------------------------------------------- /SB.ahk: -------------------------------------------------------------------------------- 1 | ; SB_SetProgress 2 | ; (w) by DerRaphael / Released under the Terms of EUPL 1.0 3 | ; see http://ec.europa.eu/idabc/en/document/7330 for details 4 | 5 | SB_SetProgress(Value=0,Seg=1,Ops="") 6 | { 7 | ; Definition of Constants 8 | Static SB_GETRECT := 0x40a ; (WM_USER:=0x400) + 10 9 | , SB_GETPARTS := 0x406 10 | , SB_PROGRESS ; Container for all used hwndBar:Seg:hProgress 11 | , PBM_SETPOS := 0x402 ; (WM_USER:=0x400) + 2 12 | , PBM_SETRANGE32 := 0x406 13 | , PBM_SETBARCOLOR := 0x409 14 | , PBM_SETBKCOLOR := 0x2001 15 | , dwStyle := 0x50000001 ; forced dwStyle WS_CHILD|WS_VISIBLE|PBS_SMOOTH 16 | 17 | ; Find the hWnd of the currentGui's StatusbarControl 18 | Gui,+LastFound 19 | ControlGet,hwndBar,hWnd,,msctls_statusbar321 20 | 21 | if (!StrLen(hwndBar)) { 22 | rErrorLevel := "FAIL: No StatusBar Control" ; Drop ErrorLevel on Error 23 | } else If (Seg<=0) { 24 | rErrorLevel := "FAIL: Wrong Segment Parameter" ; Drop ErrorLevel on Error 25 | } else if (Seg>0) { 26 | ; Segment count 27 | SendMessage, SB_GETPARTS, 0, 0,, ahk_id %hwndBar% 28 | SB_Parts := ErrorLevel - 1 29 | If ((SB_Parts!=0) && (SB_Parts Int 36 | ; Segment Size :: 0-base Index => 1. Element -> #0 37 | SendMessage,SB_GETRECT,Seg-1,&RECT,,ahk_id %hwndBar% 38 | If ErrorLevel 39 | Loop,4 40 | n%A_index% := NumGet(RECT,(a_index-1)*4,"Int") 41 | else 42 | rErrorLevel := "FAIL: Segmentdimensions" ; Drop ErrorLevel on Error 43 | } else { ; We dont have any parts, so use the entire statusbar for our progress 44 | n1 := n2 := 0 45 | ControlGetPos,,,n3,n4,,ahk_id %hwndBar% 46 | } ; if SB_Parts 47 | 48 | If (InStr(SB_Progress,":" Seg ":")) { 49 | 50 | hWndProg := (RegExMatch(SB_Progress, hwndBar "\:" seg "\:(?P([^,]+|.+))",p)) ? phWnd : 51 | 52 | } else { 53 | 54 | If (RegExMatch(Ops,"i)-smooth")) 55 | dwStyle ^= 0x1 56 | 57 | hWndProg := DllCall("CreateWindowEx","uint",0,"str","msctls_progress32" 58 | ,"uint",0,"uint", dwStyle 59 | ,"int",0,"int",0,"int",0,"int",0 ; segment-progress :: X/Y/W/H 60 | ,"uint",DllCall("GetAncestor","uInt",hwndBar,"uInt",1) ; gui hwnd 61 | ,"uint",0,"uint",0,"uint",0) 62 | 63 | SB_Progress .= (StrLen(SB_Progress) ? "," : "") hwndBar ":" Seg ":" hWndProg 64 | 65 | } ; If InStr Prog <-> Seg 66 | 67 | ; HTML Colors 68 | Black:=0x000000,Green:=0x008000,Silver:=0xC0C0C0,Lime:=0x00FF00,Gray:=0x808080 69 | Olive:=0x808000,White:=0xFFFFFF,Yellow:=0xFFFF00,Maroon:=0x800000,Navy:=0x000080 70 | Red:=0xFF0000,Blue:=0x0000FF,Fuchsia:=0xFF00FF,Aqua:=0x00FFFF 71 | 72 | If (RegExMatch(ops,"i)\bBackground(?P[a-z0-9]+)\b",bg)) { 73 | if ((strlen(bgC)=6)&&(RegExMatch(bgC,"i)([0-9a-f]{6})"))) 74 | bgC := "0x" bgC 75 | else if !(RegExMatch(bgC,"i)^0x([0-9a-f]{1,6})")) 76 | bgC := %bgC% 77 | if (bgC+0!="") 78 | SendMessage, PBM_SETBKCOLOR, 0 79 | , ((bgC&255)<<16)+(((bgC>>8)&255)<<8)+(bgC>>16) ; BGR 80 | ,, ahk_id %hwndProg% 81 | } ; If RegEx BGC 82 | If (RegExMatch(ops,"i)\bc(?P[a-z0-9]+)\b",fg)) { 83 | if ((strlen(fgC)=6)&&(RegExMatch(fgC,"i)([0-9a-f]{6})"))) 84 | fgC := "0x" fgC 85 | else if !(RegExMatch(fgC,"i)^0x([0-9a-f]{1,6})")) 86 | fgC := %fgC% 87 | if (fgC+0!="") 88 | SendMessage, PBM_SETBARCOLOR, 0 89 | , ((fgC&255)<<16)+(((fgC>>8)&255)<<8)+(fgC>>16) ; BGR 90 | ,, ahk_id %hwndProg% 91 | } ; If RegEx FGC 92 | 93 | If ((RegExMatch(ops,"i)(?P[^ ])?range((?P\-?\d+)\-(?P\-?\d+))?",r)) 94 | && (rIn!="-") && (rHi>rLo)) { ; Set new LowRange and HighRange 95 | SendMessage,0x406,rLo,rHi,,ahk_id %hWndProg% 96 | } else if ((rIn="-") || (rLo>rHi)) { ; restore defaults on remove or invalid values 97 | SendMessage,0x406,0,100,,ahk_id %hWndProg% 98 | } ; If RegEx Range 99 | 100 | If (RegExMatch(ops,"i)\bEnable\b")) 101 | Control, Enable,,, ahk_id %hWndProg% 102 | If (RegExMatch(ops,"i)\bDisable\b")) 103 | Control, Disable,,, ahk_id %hWndProg% 104 | If (RegExMatch(ops,"i)\bHide\b")) 105 | Control, Hide,,, ahk_id %hWndProg% 106 | If (RegExMatch(ops,"i)\bShow\b")) 107 | Control, Show,,, ahk_id %hWndProg% 108 | 109 | ControlGetPos,xb,yb,,,,ahk_id %hwndBar% 110 | ControlMove,,xb+n1,yb+n2,n3-n1,n4-n2,ahk_id %hwndProg% 111 | SendMessage,PBM_SETPOS,value,0,,ahk_id %hWndProg% 112 | 113 | } ; if Seg greater than count 114 | } ; if Seg greater zero 115 | 116 | If (regExMatch(rErrorLevel,"^FAIL")) { 117 | ErrorLevel := rErrorLevel 118 | Return -1 119 | } else 120 | Return hWndProg 121 | 122 | } -------------------------------------------------------------------------------- /StdoutToVar.ahk: -------------------------------------------------------------------------------- 1 | ; ---------------------------------------------------------------------------------------------------------------------- 2 | ; Function .....: StdoutToVar_CreateProcess 3 | ; Description ..: Runs a command line program and returns its output. 4 | ; Parameters ...: sCmd - Commandline to execute. 5 | ; ..............: sEncoding - Encoding used by the target process. Look at StrGet() for possible values. 6 | ; ..............: sDir - Working directory. 7 | ; ..............: nExitCode - Process exit code, receive it as a byref parameter. 8 | ; Return .......: Command output as a string on success, empty string on error. 9 | ; AHK Version ..: AHK_L x32/64 Unicode/ANSI 10 | ; Author .......: Sean (http://goo.gl/o3VCO8), modified by nfl and by Cyruz 11 | ; License ......: WTFPL - http://www.wtfpl.net/txt/copying/ 12 | ; Changelog ....: Feb. 20, 2007 - Sean version. 13 | ; ..............: Sep. 21, 2011 - nfl version. 14 | ; ..............: Nov. 27, 2013 - Cyruz version (code refactored and exit code). 15 | ; ..............: Mar. 09, 2014 - Removed input, doesn't seem reliable. Some code improvements. 16 | ; ..............: Mar. 16, 2014 - Added encoding parameter as pointed out by lexikos. 17 | ; ..............: Jun. 02, 2014 - Corrected exit code error. 18 | ; ---------------------------------------------------------------------------------------------------------------------- 19 | StdoutToVar_CreateProcess(sCmd, sEncoding:="CP0", sDir:="", ByRef nExitCode:=0) { 20 | DllCall( "CreatePipe", PtrP,hStdOutRd, PtrP,hStdOutWr, Ptr,0, UInt,0 ) 21 | DllCall( "SetHandleInformation", Ptr,hStdOutWr, UInt,1, UInt,1 ) 22 | 23 | VarSetCapacity( pi, (A_PtrSize == 4) ? 16 : 24, 0 ) 24 | siSz := VarSetCapacity( si, (A_PtrSize == 4) ? 68 : 104, 0 ) 25 | NumPut( siSz, si, 0, "UInt" ) 26 | NumPut( 0x100, si, (A_PtrSize == 4) ? 44 : 60, "UInt" ) 27 | NumPut( hStdInRd, si, (A_PtrSize == 4) ? 56 : 80, "Ptr" ) 28 | NumPut( hStdOutWr, si, (A_PtrSize == 4) ? 60 : 88, "Ptr" ) 29 | NumPut( hStdOutWr, si, (A_PtrSize == 4) ? 64 : 96, "Ptr" ) 30 | 31 | If ( !DllCall( "CreateProcess", Ptr,0, Ptr,&sCmd, Ptr,0, Ptr,0, Int,True, UInt,0x08000000 32 | , Ptr,0, Ptr,sDir?&sDir:0, Ptr,&si, Ptr,&pi ) ) 33 | Return "" 34 | , DllCall( "CloseHandle", Ptr,hStdOutWr ) 35 | , DllCall( "CloseHandle", Ptr,hStdOutRd ) 36 | 37 | DllCall( "CloseHandle", Ptr,hStdOutWr ) ; The write pipe must be closed before reading the stdout. 38 | VarSetCapacity(sTemp, 4095) 39 | While ( DllCall( "ReadFile", Ptr,hStdOutRd, Ptr,&sTemp, UInt,4095, PtrP,nSize, Ptr,0 ) ) 40 | sOutput .= StrGet(&sTemp, nSize, sEncoding) 41 | 42 | DllCall( "GetExitCodeProcess", Ptr,NumGet(pi,0), UIntP,nExitCode ) 43 | DllCall( "CloseHandle", Ptr,NumGet(pi,0) ) 44 | DllCall( "CloseHandle", Ptr,NumGet(pi,A_PtrSize) ) 45 | DllCall( "CloseHandle", Ptr,hStdOutRd ) 46 | Return sOutput 47 | } 48 | -------------------------------------------------------------------------------- /TaskDialog.ahk: -------------------------------------------------------------------------------- 1 | ; ====================================================================================================================== 2 | ; TaskDialog -> msdn.microsoft.com/en-us/library/bb760540(v=vs.85).aspx 3 | ; Main: String to be used for the main instruction (mandatory). 4 | ; Extra: String used for additional text that appears below the main instruction (optional). 5 | ; Default: 0 - no additional text. 6 | ; Title: String to be used for the task dialog title (optional). 7 | ; Default: "" - A_ScriptName. 8 | ; Buttons: Specifies the push buttons displayed in the dialog box (optional). 9 | ; This parameter may be a combination of the integer values defined in TDBTNS or a list of string keys 10 | ; separated by pipe (|), space, comma, or LF (`n). 11 | ; list of the string keys. 12 | ; Default: 0 - OK button 13 | ; Icon: Specifies the icon to display in the task dialog (optional). 14 | ; This parameter can be one of the keys defined in TDICON or a HICON handle to a 32*32 sized icon. 15 | ; Default: 0 - no icon 16 | ; Width: Specifies the width of the task dialog's client area, in pixels. 17 | ; If you pass -1 the width of the task dialog is determined by the width of its content (Extra) area. 18 | ; Default: 0 - the task dialog manager will calculate the ideal width. 19 | ; Parent: HWND of the owner window of the task dialog to be created(optional). 20 | ; If a valid window handle is specified, the task dialog will become modal. 21 | ; Pass -1 to set the task dialog 'AlwaysOnTop'. 22 | ; Default: 0 - no owner window 23 | ; Timeout: Timeout in seconds, which can contain a decimal point. 24 | ; Due to the use of the TDN_TIMER notification the precision will be about 200 ms. 25 | ; Default: 0 - no timeout 26 | ; Returns: An integer value identifying the button pressed by the user: 27 | ; -1 = Timeout, 1 = OK, 2 = CANCEL, 4 = RETRY, 6 = YES, 7 = NO, 8 = CLOSE 28 | ; If the function fails, ErrorLevel will be set and the return value will be 0. 29 | ; Remarks: Depending on the settings of TaskDialogUseMsgBoxOnXP() the function can display a MsgBox instead of 30 | ; the task dialog on Win XP. In that case you should only use icons and in particular button combinations 31 | ; also supported by the MsgBox command: 32 | ; Icon: 1/"WARN", 2/"ERROR", 3/"INFO", "QUESTION" 33 | ; Buttons: 1/"OK", 9/"OK|CANCEL", 6/"YES|NO", 14/"YES|NO|CANCEL", 24/"RETRY|CANCEL" 34 | ; Other icons won't be shown, other button combinations won't show all specified buttons. 35 | ; Version: 2014-09-26 36 | ; ====================================================================================================================== 37 | TaskDialog(Main, Extra := "", Title := "", Buttons := 0, Icon := 0, Width := 0, Parent := 0, TimeOut := 0) { 38 | Static TDCB := RegisterCallback("TaskDialogCallback", "Fast") 39 | , TDCSize := (4 * 8) + (A_PtrSize * 16) 40 | , TDBTNS := {OK: 1, YES: 2, NO: 4, CANCEL: 8, RETRY: 16, CLOSE: 32} 41 | , TDF := {HICON_MAIN: 0x0002, ALLOW_CANCEL: 0x0008, CALLBACK_TIMER: 0x0800, SIZE_TO_CONTENT: 0x01000000} 42 | , TDICON := {1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9 43 | , WARN: 1, ERROR: 2, INFO: 3, SHIELD: 4, BLUE: 5, YELLOW: 6, RED: 7, GREEN: 8, GRAY: 9 44 | , QUESTION: 0} 45 | , HQUESTION := DllCall("User32.dll\LoadIcon", "Ptr", 0, "Ptr", 0x7F02, "UPtr") 46 | , DBUX := DllCall("User32.dll\GetDialogBaseUnits", "UInt") & 0xFFFF 47 | , OffParent := 4 48 | , OffFlags := OffParent + (A_PtrSize * 2) 49 | , OffBtns := OffFlags + 4 50 | , OffTitle := OffBtns + 4 51 | , OffIcon := OffTitle + A_PtrSize 52 | , OffMain := OffIcon + A_PtrSize 53 | , OffExtra := OffMain + A_PtrSize 54 | , OffCB := (4 * 7) + (A_PtrSize * 14) 55 | , OffCBData := OffCB + A_PtrSize 56 | , OffWidth := OffCBData + A_PtrSize 57 | ; ------------------------------------------------------------------------------------------------------------------- 58 | If ((DllCall("Kernel32.dll\GetVersion", "UInt") & 0xFF) < 6) { 59 | If TaskDialogUseMsgBoxOnXP() 60 | Return TaskDialogMsgBox(Main, Extra, Title, Buttons, Icon, Parent, Timeout) 61 | Else { 62 | MsgBox, 16, %A_ThisFunc%, You need at least Win Vista / Server 2008 to use %A_ThisFunc%(). 63 | ErrorLevel := "You need at least Win Vista / Server 2008 to use " . A_ThisFunc . "()." 64 | Return 0 65 | } 66 | } 67 | ; ------------------------------------------------------------------------------------------------------------------- 68 | Flags := Width = 0 ? TDF.SIZE_TO_CONTENT : 0 69 | If (Title = "") 70 | Title := A_ScriptName 71 | BTNS := 0 72 | If Buttons Is Integer 73 | BTNS := Buttons & 0x3F 74 | Else 75 | For Each, Btn In StrSplit(Buttons, ["|", " ", ",", "`n"]) 76 | BTNS |= (B := TDBTNS[Btn]) ? B : 0 77 | ICO := (I := TDICON[Icon]) ? 0x10000 - I : 0 78 | If Icon Is Integer 79 | If ((Icon & 0xFFFF) <> Icon) ; caller presumably passed HICON 80 | ICO := Icon 81 | If (Icon = "Question") 82 | ICO := HQUESTION 83 | If (ICO > 0xFFFF) 84 | Flags |= TDF.HICON_MAIN 85 | AOT := Parent < 0 ? !(Parent := 0) : False ; AlwaysOnTop 86 | ; ------------------------------------------------------------------------------------------------------------------- 87 | PTitle := A_IsUnicode ? &Title : TaskDialogToUnicode(Title, WTitle) 88 | PMain := A_IsUnicode ? &Main : TaskDialogToUnicode(Main, WMain) 89 | PExtra := Extra = "" ? 0 : A_IsUnicode ? &Extra : TaskDialogToUnicode(Extra, WExtra) 90 | VarSetCapacity(TDC, TDCSize, 0) ; TASKDIALOGCONFIG structure 91 | NumPut(TDCSize, TDC, "UInt") 92 | NumPut(Parent, TDC, OffParent, "Ptr") 93 | NumPut(BTNS, TDC, OffBtns, "Int") 94 | NumPut(PTitle, TDC, OffTitle, "Ptr") 95 | NumPut(ICO, TDC, OffIcon, "Ptr") 96 | NumPut(PMain, TDC, OffMain, "Ptr") 97 | NumPut(PExtra, TDC, OffExtra, "Ptr") 98 | If (AOT) || (TimeOut > 0) { 99 | If (TimeOut > 0) { 100 | Flags |= TDF.CALLBACK_TIMER 101 | TimeOut := Round(Timeout * 1000) 102 | } 103 | TD := {AOT: AOT, Timeout: Timeout} 104 | NumPut(TDCB, TDC, OffCB, "Ptr") 105 | NumPut(&TD, TDC, OffCBData, "Ptr") 106 | } 107 | NumPut(Flags, TDC, OffFlags, "UInt") 108 | If (Width > 0) 109 | NumPut(Width * 4 / DBUX, TDC, OffWidth, "UInt") 110 | If !(RV := DllCall("Comctl32.dll\TaskDialogIndirect", "Ptr", &TDC, "IntP", Result, "Ptr", 0, "Ptr", 0, "UInt")) 111 | Return TD.TimedOut ? -1 : Result 112 | ErrorLevel := "The call of TaskDialogIndirect() failed!`nReturn value: " . RV . "`nLast error: " . A_LastError 113 | Return 0 114 | } 115 | ; ====================================================================================================================== 116 | ; Call this function once passing 1/True if you want a MsgBox to be displayed instead of the task dialog on Win XP. 117 | ; ====================================================================================================================== 118 | TaskDialogUseMsgBoxOnXP(UseIt := "") { 119 | Static UseMsgBox := False 120 | If (UseIt <> "") 121 | UseMsgBox := !!UseIt 122 | Return UseMsgBox 123 | } 124 | ; ====================================================================================================================== 125 | ; Internally used functions 126 | ; ====================================================================================================================== 127 | TaskDialogMsgBox(Main, Extra, Title := "", Buttons := 0, Icon := 0, Parent := 0, TimeOut := 0) { 128 | Static MBICON := {1: 0x30, 2: 0x10, 3: 0x40, WARN: 0x30, ERROR: 0x10, INFO: 0x40, QUESTION: 0x20} 129 | , TDBTNS := {OK: 1, YES: 2, NO: 4, CANCEL: 8, RETRY: 16} 130 | BTNS := 0 131 | If Buttons Is Integer 132 | BTNS := Buttons & 0x1F 133 | Else 134 | For Each, Btn In StrSplit(Buttons, ["|", " ", ",", "`n"]) 135 | BTNS |= (B := TDBTNS[Btn]) ? B : 0 136 | Options := 0 137 | Options |= (I := MBICON[Icon]) ? I : 0 138 | Options |= Parent = -1 ? 262144 : Parent > 0 ? 8192 : 0 139 | If ((BTNS & 14) = 14) 140 | Options |= 0x03 ; Yes/No/Cancel 141 | Else If ((BTNS & 6) = 6) 142 | Options |= 0x04 ; Yes/No 143 | Else If ((BTNS & 24) = 24) 144 | Options |= 0x05 ; Retry/Cancel 145 | Else If ((BTNS & 9) = 9) 146 | Options |= 0x01 ; OK/Cancel 147 | Main .= Extra <> "" ? "`n`n" . Extra : "" 148 | MsgBox, % Options, %Title%, %Main%, %TimeOut% 149 | IfMsgBox, OK 150 | Return 1 151 | IfMsgBox, Cancel 152 | Return 2 153 | IfMsgBox, Retry 154 | Return 4 155 | IfMsgBox, Yes 156 | Return 6 157 | IfMsgBox, No 158 | Return 7 159 | IfMsgBox, TimeOut 160 | Return -1 161 | Return 0 162 | } 163 | ; ====================================================================================================================== 164 | TaskDialogToUnicode(String, ByRef Var) { 165 | VarSetCapacity(Var, StrPut(String, "UTF-16") * 2, 0) 166 | StrPut(String, &Var, "UTF-16") 167 | Return &Var 168 | } 169 | ; ====================================================================================================================== 170 | TaskDialogCallback(H, N, W, L, D) { 171 | Static TDM_CLICK_BUTTON := 0x0466 172 | , TDN_CREATED := 0 173 | , TDN_TIMER := 4 174 | TD := Object(D) 175 | If (N = TDN_TIMER) && (W > TD.Timeout) { 176 | TD.TimedOut := True 177 | PostMessage, %TDM_CLICK_BUTTON%, 2, 0, , ahk_id %H% ; IDCANCEL = 2 178 | } 179 | Else If (N = TDN_CREATED) && TD.AOT { 180 | DHW := A_DetectHiddenWindows 181 | DetectHiddenWindows, On 182 | WinSet, AlwaysOnTop, On, ahk_id %H% 183 | DetectHiddenWindows, %DHW% 184 | } 185 | Return 0 186 | } -------------------------------------------------------------------------------- /TermWait.ahk: -------------------------------------------------------------------------------- 1 | ; ---------------------------------------------------------------------------------------------------------------------- 2 | ; Name .........: TermWait library 3 | ; Description ..: Implement the RegisterWaitForSingleObject Windows API. 4 | ; AHK Version ..: AHK_L 1.1.13.01 x32/64 Unicode 5 | ; Author .......: Cyruz (http://ciroprincipe.info) & SKAN (http://goo.gl/EpCq0Z) 6 | ; License ......: WTFPL - http://www.wtfpl.net/txt/copying/ 7 | ; Changelog ....: Sep. 15, 2012 - v0.1 - First revision. 8 | ; ..............: Jan. 02, 2014 - v0.2 - AHK_L Unicode and x64 version. 9 | ; ---------------------------------------------------------------------------------------------------------------------- 10 | 11 | ; ---------------------------------------------------------------------------------------------------------------------- 12 | ; Function .....: TermWait_WaitForProcTerm 13 | ; Description ..: This function initializes a global structure and start an asynchrounous thread to wait for program 14 | ; ..............: termination. The global structure is used to pass arbitrary data at offset 24/36. Offsets are: 15 | ; ..............: < +0 = hWnd | +4/+8 = nMsgId | +8/+12 = nPid | +12/+16 = hProc | +16/+24 = hWait | +20/+32 = sDataIn > 16 | ; Parameters ...: hWnd - Handle of the window that will receive the notification. 17 | ; ..............: nMsgId - Generic message ID (msg). 18 | ; ..............: nPid - PID of the process that needs to be waited for. 19 | ; ..............: sDataIn - Arbitrary data (use this to pass any data in string form). 20 | ; Return .......: Address of global allocated structure. 21 | ; ---------------------------------------------------------------------------------------------------------------------- 22 | TermWait_WaitForProcTerm(hWnd, nMsgId, nPid, ByRef sDataIn:="") { 23 | Static addrCallback := RegisterCallback("__TermWait_TermNotifier") 24 | 25 | szDataIn := VarSetCapacity( sDataIn ) 26 | pGlobal := DllCall( "GlobalAlloc", UInt,0x0040, UInt,(A_PtrSize==4)?20+szDataIn:32+szDataIn ) 27 | hProc := DllCall( "OpenProcess", UInt,0x00100000, UInt,0, UInt,nPid ) 28 | 29 | NumPut( hWnd, pGlobal+0 ) 30 | NumPut( nMsgId, (A_PtrSize == 4) ? pGlobal+4 : pGlobal+8 ) 31 | NumPut( nPid, (A_PtrSize == 4) ? pGlobal+8 : pGlobal+12 ) 32 | NumPut( hProc, (A_PtrSize == 4) ? pGlobal+12 : pGlobal+16 ) 33 | 34 | DllCall( "RtlMoveMemory", Ptr,(A_PtrSize==4)?pGlobal+20:pGlobal+32, Ptr,&sDataIn, UInt,szDataIn ) 35 | DllCall( "RegisterWaitForSingleObject", Ptr,(A_PtrSize==4)?pGlobal+16:pGlobal+24, Ptr,hProc, Ptr,addrCallback 36 | , Ptr,pGlobal, UInt,0xFFFFFFFF, UInt,0x00000004|0x00000008 ) 37 | Return pGlobal 38 | } 39 | 40 | ; ---------------------------------------------------------------------------------------------------------------------- 41 | ; Function .....: TermWait_StopWaiting 42 | ; Description ..: This function cleans all handles and frees global allocated memory. 43 | ; Parameters ...: pGlobal - Global structure address. 44 | ; ---------------------------------------------------------------------------------------------------------------------- 45 | TermWait_StopWaiting(pGlobal) { 46 | DllCall( "UnregisterWait", UInt,NumGet((A_PtrSize==4)?pGlobal+16:pGlobal+24) ) 47 | DllCall( "CloseHandle", UInt,NumGet((A_PtrSize==4)?pGlobal+12:pGlobal+16) ) 48 | DllCall( "GlobalFree", UInt,pGlobal ) 49 | } 50 | 51 | ; ---------------------------------------------------------------------------------------------------------------------- 52 | ; Function .....: __TermWait_TermNotifier 53 | ; Description ..: This callback is called when a monitored process signal its closure. It gets executed on a different 54 | ; ..............: thread because of the RegisterWaitForSingleObject, so it could interferee with the normal AutoHotkey 55 | ; ..............: behaviour (eg. it's not bug free). 56 | ; Parameters ...: pGlobal - Global structure. 57 | ; ---------------------------------------------------------------------------------------------------------------------- 58 | __TermWait_TermNotifier(pGlobal) { ; THIS FUNCTION GETS EXECUTED IN A DIFFERENT THREAD!!! 59 | DllCall( "SendNotifyMessage", Ptr,NumGet(pGlobal+0), UInt,NumGet((A_PtrSize==4)?pGlobal+4:pGlobal+8) 60 | , UInt,0, UInt,pGlobal ) 61 | } 62 | 63 | /* EXAMPLE CODE: 64 | #SingleInstance force 65 | #Persistent 66 | 67 | MSGID := 0x8500 ; msg 68 | OnMessage(MSGID, "AHK_TERMNOTIFY") 69 | 70 | Gui, +LastFound +HwndhWnd 71 | 72 | Run, %A_WinDir%\System32\cmd.exe,,, nPid 73 | sSomeData := "WTF! I was waiting for " . nPid . " to terminate. Now it's not running anymore. I'm cool." 74 | TermWait_WaitForProcTerm(hWnd, MSGID, nPid, sSomeData) 75 | Return 76 | 77 | AHK_TERMNOTIFY(wParam, lParam) { 78 | ; ... DO SOMETHING 79 | MsgBox, % DllCall("MulDiv", Int, lParam+20, Int, 1, Int, 1, Str) 80 | ; ... DO SOMETHING 81 | TermWait_StopWaiting(lParam) 82 | } 83 | */ -------------------------------------------------------------------------------- /TrayIcon.ahk: -------------------------------------------------------------------------------- 1 | ; ---------------------------------------------------------------------------------------------------------------------- 2 | ; Name .........: TrayIcon library 3 | ; Description ..: Provide some useful functions to deal with Tray icons. 4 | ; AHK Version ..: AHK_L 1.1.13.01 x32/64 Unicode 5 | ; Author .......: Cyruz (http://ciroprincipe.info) - from a Sean idea and code (http://goo.gl/dh0xIX) 6 | ; Thanks .......: FanaticGuru 7 | ; License ......: WTFPL - http://www.wtfpl.net/txt/copying/ 8 | ; Changelog ....: Dic. 31, 2013 - v0.1 - First revision. 9 | ; ..............: Jan. 16, 2014 - v0.2 - Added NotifyIconOverflowWindow parsing and DetectHiddenWindows management. 10 | ; ..............: Jul. 28, 2015 - v0.2.1 - Added TrayIcon_SetIcon function. 11 | ; ---------------------------------------------------------------------------------------------------------------------- 12 | 13 | ; ---------------------------------------------------------------------------------------------------------------------- 14 | ; Function .....: TrayIcon_GetInfo 15 | ; Description ..: Get a series of useful information about tray icons. 16 | ; Parameters ...: sExeName - The exe or the PID for which we are searching the tray icon data. Leave it empty to 17 | ; ..............: receive data for all tray icons. 18 | ; Return .......: oTrayInfo - An array of objects containing tray icons data. Any entry is structured like this: 19 | ; ..............: oTrayInfo[A_Index].idx - 0 based tray icon index. 20 | ; ..............: oTrayInfo[A_Index].idcmd - Command identifier associated with the button. 21 | ; ..............: oTrayInfo[A_Index].pid - Process ID. 22 | ; ..............: oTrayInfo[A_Index].uid - Application defined identifier for the icon. 23 | ; ..............: oTrayInfo[A_Index].msgid - Application defined callback message. 24 | ; ..............: oTrayInfo[A_Index].hicon - Handle to the tray icon. 25 | ; ..............: oTrayInfo[A_Index].hwnd - Window handle. 26 | ; ..............: oTrayInfo[A_Index].class - Window class. 27 | ; ..............: oTrayInfo[A_Index].process - Process executable. 28 | ; ..............: oTrayInfo[A_Index].tooltip - Tray icon tooltip. 29 | ; ..............: oTrayInfo[A_Index].place - Place where to find the icon. 30 | ; Info .........: TB_BUTTONCOUNT message - http://goo.gl/DVxpsg 31 | ; ..............: TB_GETBUTTON message - http://goo.gl/2oiOsl 32 | ; ..............: TBBUTTON structure - http://goo.gl/EIE21Z 33 | ; ---------------------------------------------------------------------------------------------------------------------- 34 | TrayIcon_GetInfo(sExeName:="") 35 | { 36 | d := A_DetectHiddenWindows 37 | DetectHiddenWindows, On 38 | 39 | oTrayInfo := Object() 40 | For key, sTrayPlace in ["Shell_TrayWnd", "NotifyIconOverflowWindow"] 41 | { 42 | idxTB := TrayIcon_GetTrayBar() 43 | WinGet, pidTaskbar, PID, ahk_class %sTrayPlace% 44 | 45 | hProc := DllCall( "OpenProcess", UInt,0x38, Int,0, UInt,pidTaskbar ) 46 | pRB := DllCall( "VirtualAllocEx", Ptr,hProc, Ptr,0, UInt,20, UInt,0x1000, UInt,0x4 ) 47 | 48 | szBtn := VarSetCapacity( btn, (A_Is64bitOS) ? 32 : 24, 0 ) 49 | szNfo := VarSetCapacity( nfo, (A_Is64bitOS) ? 32 : 24, 0 ) 50 | szTip := VarSetCapacity( tip, 128 * 2, 0 ) 51 | 52 | SendMessage, 0x418, 0, 0, ToolbarWindow32%idxTB%, ahk_class %sTrayPlace% ; TB_BUTTONCOUNT 53 | Loop, %ErrorLevel% 54 | { 55 | SendMessage, 0x417, A_Index - 1, pRB, ToolbarWindow32%idxTB%, ahk_class %sTrayPlace% ; TB_GETBUTTON 56 | 57 | DllCall( "ReadProcessMemory", Ptr,hProc, Ptr,pRB, Ptr,&btn, UInt,szBtn, UInt,0 ) 58 | 59 | iBitmap := NumGet( btn, 0 ) 60 | idCmd := NumGet( btn, 4 ) 61 | Statyle := NumGet( btn, 8 ) 62 | dwData := NumGet( btn, (A_Is64bitOS) ? 16 : 12 ) 63 | iString := NumGet( btn, (A_Is64bitOS) ? 24 : 16 ) 64 | 65 | DllCall( "ReadProcessMemory", Ptr,hProc, Ptr,dwData, Ptr,&nfo, UInt,szNfo, UInt,0 ) 66 | 67 | hWnd := NumGet( nfo, 0 ) 68 | uID := NumGet( nfo, (A_Is64bitOS) ? 8 : 4 ) 69 | nMsg := NumGet( nfo, (A_Is64bitOS) ? 12 : 8 ) 70 | hIcon := NumGet( nfo, (A_Is64bitOS) ? 24 : 20 ) 71 | 72 | WinGet, pid, PID, ahk_id %hWnd% 73 | WinGet, sProcess, ProcessName, ahk_id %hWnd% 74 | WinGetClass, sClass, ahk_id %hWnd% 75 | 76 | If ( !sExeName || (sExeName == sProcess) || (sExeName == pid) ) 77 | DllCall( "ReadProcessMemory", Ptr,hProc, Ptr,iString, Ptr,&tip, UInt,szTip, UInt,0 ) 78 | , oTrayInfo.Insert({ "idx": A_Index-1, "idcmd": idCmd, "pid": pid, "uid": uID, "msgid": nMsg 79 | , "hicon": hIcon, "hwnd": hWnd, "class": sClass, "process": sProcess 80 | , "tooltip": StrGet(&tip, "UTF-16"), "place": sTrayPlace }) 81 | } 82 | 83 | DllCall( "VirtualFreeEx", Ptr,hProc, Ptr,pRB, UInt,0, UInt,0x8000 ) 84 | DllCall( "CloseHandle", Ptr,hProc ) 85 | } 86 | DetectHiddenWindows, %d% 87 | Return ( oTrayInfo.MaxIndex() > 0 ) ? oTrayInfo : 0 88 | } 89 | 90 | ; ---------------------------------------------------------------------------------------------------------------------- 91 | ; Function .....: TrayIcon_Hide 92 | ; Description ..: Hide or unhide a tray icon. 93 | ; Parameters ...: idCmd - Command identifier associated with the button. 94 | ; ..............: sTrayPlace - Place where to find the icon ("Shell_TrayWnd" or "NotifyIconOverflowWindow"). 95 | ; ..............: bHide - True for hide, False for unhide. 96 | ; Info .........: TB_HIDEBUTTON message - http://goo.gl/oelsAa 97 | ; ---------------------------------------------------------------------------------------------------------------------- 98 | TrayIcon_Hide(idCmd, sTrayPlace:="Shell_TrayWnd", bHide:=True) 99 | { 100 | d := A_DetectHiddenWindows 101 | DetectHiddenWindows, On 102 | idxTB := TrayIcon_GetTrayBar() 103 | SendMessage, 0x404, idCmd, bHide, ToolbarWindow32%idxTB%, ahk_class %sTrayPlace% ; TB_HIDEBUTTON = 0x404 104 | SendMessage, 0x1A, 0, 0, , ahk_class %sTrayPlace% 105 | DetectHiddenWindows, %d% 106 | } 107 | 108 | ; ---------------------------------------------------------------------------------------------------------------------- 109 | ; Function .....: TrayIcon_Remove 110 | ; Description ..: Remove a Tray icon. It should be more reliable than TrayIcon_Delete. 111 | ; Parameters ...: hWnd - Window handle. 112 | ; ..............: uId - Application defined identifier for the icon. 113 | ; ---------------------------------------------------------------------------------------------------------------------- 114 | TrayIcon_Remove(hWnd, uId) 115 | { 116 | VarSetCapacity( NID, (A_PtrSize == 4) ? (A_IsUnicode ? 828 : 444) : 848, 0 ) 117 | NumPut( sz, NID, 0 ), NumPut( hWnd, NID, A_PtrSize ), NumPut( uId, NID, A_PtrSize*2 ) 118 | DllCall( "Shell32.dll\Shell_NotifyIcon", UInt,2, Ptr,&NID ) 119 | } 120 | 121 | ; ---------------------------------------------------------------------------------------------------------------------- 122 | ; Function .....: TrayIcon_Delete 123 | ; Description ..: Delete a tray icon. 124 | ; Parameters ...: idx - 0 based tray icon index. 125 | ; ..............: sTrayPlace - Place where to find the icon ("Shell_TrayWnd" or "NotifyIconOverflowWindow"). 126 | ; Info .........: TB_DELETEBUTTON message - http://goo.gl/L0pY4R 127 | ; ---------------------------------------------------------------------------------------------------------------------- 128 | TrayIcon_Delete(idx, sTrayPlace:="Shell_TrayWnd") 129 | { 130 | d := A_DetectHiddenWindows 131 | DetectHiddenWindows, On 132 | idxTB := TrayIcon_GetTrayBar() 133 | SendMessage, 0x416, idx, 0, ToolbarWindow32%idxTB%, ahk_class %sTrayPlace% ; TB_DELETEBUTTON = 0x416 134 | SendMessage, 0x1A, 0, 0, , ahk_class %sTrayPlace% 135 | DetectHiddenWindows, %d% 136 | } 137 | 138 | ; ---------------------------------------------------------------------------------------------------------------------- 139 | ; Function .....: TrayIcon_Move 140 | ; Description ..: Move a tray icon. 141 | ; Parameters ...: idxOld - 0 based index of the tray icon to move. 142 | ; ..............: idxNew - 0 based index where to move the tray icon. 143 | ; ..............: sTrayPlace - Place where to find the icon ("Shell_TrayWnd" or "NotifyIconOverflowWindow"). 144 | ; Info .........: TB_MOVEBUTTON message - http://goo.gl/1F6wPw 145 | ; ---------------------------------------------------------------------------------------------------------------------- 146 | TrayIcon_Move(idxOld, idxNew, sTrayPlace:="Shell_TrayWnd") 147 | { 148 | d := A_DetectHiddenWindows 149 | DetectHiddenWindows, On 150 | idxTB := TrayIcon_GetTrayBar() 151 | SendMessage, 0x452, idxOld, idxNew, ToolbarWindow32%idxTB%, ahk_class %sTrayPlace% ; TB_MOVEBUTTON = 0x452 152 | DetectHiddenWindows, %d% 153 | } 154 | 155 | ; ---------------------------------------------------------------------------------------------------------------------- 156 | ; Function .....: TrayIcon_Set 157 | ; Description ..: Modify icon with the given index for the given window. 158 | ; Parameters ...: hWnd - Window handle. 159 | ; ..............: uId - Application defined identifier for the icon. 160 | ; ..............: hIcon - Handle to the tray icon. 161 | ; ..............: hIconSmall - Handle to the small icon, for window menubar. Optional. 162 | ; ..............: hIconBig - Handle to the big icon, for taskbar. Optional. 163 | ; Return .......: True on success, false on failure. 164 | ; Info .........: NOTIFYICONDATA structure - https://goo.gl/1Xuw5r 165 | ; ..............: Shell_NotifyIcon function - https://goo.gl/tTSSBM 166 | ; ---------------------------------------------------------------------------------------------------------------------- 167 | TrayIcon_Set(hWnd, uId, hIcon, hIconSmall:=0, hIconBig:=0) 168 | { 169 | d := A_DetectHiddenWindows 170 | DetectHiddenWindows, On 171 | ; WM_SETICON = 0x80 172 | If ( hIconSmall ) 173 | SendMessage, 0x80, 0, hIconSmall,, ahk_id %hWnd% 174 | If ( hIconBig ) 175 | SendMessage, 0x80, 1, hIconBig,, ahk_id %hWnd% 176 | DetectHiddenWindows, %d% 177 | 178 | sz := VarSetCapacity( NID, (A_PtrSize == 4) ? (A_IsUnicode ? 828 : 444) : 848, 0 ) 179 | NumPut( sz, NID, 0 ) 180 | NumPut( hWnd, NID, (A_PtrSize == 4) ? 4 : 8 ) 181 | NumPut( uId, NID, (A_PtrSize == 4) ? 8 : 16 ) 182 | NumPut( 2, NID, (A_PtrSize == 4) ? 12 : 20 ) 183 | NumPut( hIcon, NID, (A_PtrSize == 4) ? 20 : 32 ) 184 | 185 | ; NIM_MODIFY := 0x1 186 | Return DllCall( "Shell32.dll\Shell_NotifyIcon", UInt,0x1, Ptr,&NID ) 187 | } 188 | 189 | ; ---------------------------------------------------------------------------------------------------------------------- 190 | ; Function .....: TrayIcon_GetTrayBar 191 | ; Description ..: Get the tray icon handle. 192 | ; Return .......: Tray icon handle. 193 | ; ---------------------------------------------------------------------------------------------------------------------- 194 | TrayIcon_GetTrayBar() 195 | { 196 | d := A_DetectHiddenWindows 197 | DetectHiddenWindows, On 198 | WinGet, ControlList, ControlList, ahk_class Shell_TrayWnd 199 | RegExMatch( ControlList, "(?<=ToolbarWindow32)\d+(?!.*ToolbarWindow32)", nTB ) 200 | 201 | Loop, %nTB% 202 | { 203 | ControlGet, hWnd, hWnd,, ToolbarWindow32%A_Index%, ahk_class Shell_TrayWnd 204 | hParent := DllCall( "GetParent", Ptr,hWnd ) 205 | WinGetClass, sClass, ahk_id %hParent% 206 | If ( sClass != "SysPager" ) 207 | Continue 208 | idxTB := A_Index 209 | Break 210 | } 211 | 212 | DetectHiddenWindows, %d% 213 | Return idxTB 214 | } 215 | 216 | ; ---------------------------------------------------------------------------------------------------------------------- 217 | ; Function .....: TrayIcon_GetHotItem 218 | ; Description ..: Get the index of tray's hot item. 219 | ; Return .......: Index of tray's hot item. 220 | ; Info .........: TB_GETHOTITEM message - http://goo.gl/g70qO2 221 | ; ---------------------------------------------------------------------------------------------------------------------- 222 | TrayIcon_GetHotItem() 223 | { 224 | idxTB := TrayIcon_GetTrayBar() 225 | SendMessage, 0x447, 0, 0, ToolbarWindow32%idxTB%, ahk_class Shell_TrayWnd ; TB_GETHOTITEM = 0x447 226 | Return ErrorLevel << 32 >> 32 227 | } 228 | -------------------------------------------------------------------------------- /UpdRes.ahk: -------------------------------------------------------------------------------- 1 | ; ---------------------------------------------------------------------------------------------------------------------- 2 | ; Name .........: UpdRes library 3 | ; Description ..: This library allows to load a resource from a PE file and update it. It's something written in a 4 | ; ..............: couple of minutes, so don't expect it to work in all situations. 5 | ; AHK Version ..: AHK_L 1.1.13.01 x32/64 Unicode 6 | ; Author .......: Cyruz (http://ciroprincipe.info) 7 | ; License ......: WTFPL - http://www.wtfpl.net/txt/copying/ 8 | ; Changelog ....: May 24, 2014 - v0.1 - First version. 9 | ; ..............: Jan. 11, 2015 - v0.2 - Added the UpdateArrayOfResources and UpdateDirOfResources functions. 10 | ; ..............: Jul. 28, 2015 - v0.3 - Added EnumerateResources function and better error management. 11 | ; ---------------------------------------------------------------------------------------------------------------------- 12 | 13 | ; ---------------------------------------------------------------------------------------------------------------------- 14 | ; Function .....: UpdRes_LockResource 15 | ; Description ..: Load the specified resource and retrieve a pointer to its binary data. 16 | ; Parameters ...: sBinFile - PE file whose resource is to be retrieved. If = 0 the resource will be retrieved in the 17 | ; ..............: current process. 18 | ; ..............: sResName - The name of the resource or its integer identifier. 19 | ; ..............: nResType - The resource type. 20 | ; ..............: szData - Byref parameter containing the size of the resource data. 21 | ; Return .......: A pointer to the first byte of the resource, 0 on error. 22 | ; Info .........: Resource Types - http://msdn.microsoft.com/en-us/library/windows/desktop/ms648009%28v=vs.85%29.aspx 23 | ; ---------------------------------------------------------------------------------------------------------------------- 24 | UpdRes_LockResource(sBinFile, sResName, nResType, ByRef szData) 25 | { 26 | If ( !hLib := DllCall( "GetModuleHandle", Ptr,(sBinFile?&sBinFile:0) ) ) 27 | { 28 | ; If the DLL isn't already loaded, load it as a data file. 29 | If ( !hLib := DllCall( "LoadLibraryEx", Str,sBinFile, Ptr,0, UInt,0x2 ) ) 30 | Return 0, ErrorLevel := "LoadLibraryEx error`nReturn value = " hLib "`nLast error = " A_LastError 31 | bLoaded := 1 32 | } 33 | 34 | Try 35 | { 36 | If ( !hRes := DllCall( "FindResource", Ptr,hLib, Ptr,(sResName+0==sResName?sResname:&sResName), Ptr,nResType ) ) 37 | Return 0, ErrorLevel := "FindResource error`nReturn value = " hRes "`nLast error = " A_LastError 38 | 39 | If ( !szData := DllCall( "SizeofResource", Ptr,hLib, Ptr,hRes ) ) 40 | Return 0, ErrorLevel := "SizeofResource error`nReturn value = " szData "`nLast error = " A_LastError 41 | 42 | If ( !hData := DllCall( "LoadResource", Ptr,hLib, Ptr,hRes ) ) 43 | Return 0, ErrorLevel := "LoadResource error`nReturn value = " hData "`nLast error = " A_LastError 44 | 45 | If ( !pData := DllCall( "LockResource", Ptr,hData ) ) 46 | Return 0, ErrorLevel := "LockResource error`nReturn value = " pData "`nLast error = " A_LastError 47 | } 48 | Finally 49 | { 50 | ; If we loaded the DLL, free it now. 51 | If ( bLoaded ) 52 | DllCall( "FreeLibrary", Ptr,hLib ) 53 | } 54 | 55 | Return pData 56 | } 57 | 58 | ; ---------------------------------------------------------------------------------------------------------------------- 59 | ; Function .....: UpdRes_UpdateResource 60 | ; Description ..: Update the specified resource in the specified PE file. 61 | ; Parameters ...: sBinFile - PE file whose resource is to be updated. 62 | ; ..............: bDelOld - Delete all old resources if 1 or leave them intact if 0. 63 | ; ..............: sResName - The name of the resource. 64 | ; ..............: nResType - The resource type. 65 | ; ..............: nLangId - Language identifier of the resource to be updated. 66 | ; ..............: pData - Pointer to resource data. Must not point to ANSI data. 67 | ; ..............: szData - Size of the resource data. 68 | ; Return .......: 1 on success, 0 on error. 69 | ; Info .........: Lang. Identifiers - http://msdn.microsoft.com/en-us/library/windows/desktop/dd318691%28v=vs.85%29.aspx 70 | ; ---------------------------------------------------------------------------------------------------------------------- 71 | UpdRes_UpdateResource(sBinFile, bDelOld, sResName, nResType, nLangId, pData, szData) 72 | { 73 | If ( !hMod := DllCall( "BeginUpdateResource", Str,sBinFile, Int,bDelOld ) ) 74 | Return 0, ErrorLevel := "BeginUpdateResource error`nReturn value = " hMod "`nLast error = " A_LastError 75 | 76 | If ( !e := DllCall( "UpdateResource", Ptr,hMod, Ptr,nResType, Str,sResName, UInt,nLangId, Ptr,pData, UInt,szData ) ) 77 | Return 0, ErrorLevel := "UpdateResource error`nReturn value = " e "`nLast error = " A_LastError 78 | 79 | If ( !e := DllCall( "EndUpdateResource", Ptr,hMod, Int,0 ) ) 80 | Return 0, ErrorLevel := "EndUpdateResource error`nReturn value = " e "`nLast error = " A_LastError 81 | 82 | Return 1 83 | } 84 | 85 | ; ---------------------------------------------------------------------------------------------------------------------- 86 | ; Function .....: UpdRes_UpdateArrayOfResources 87 | ; Description ..: Update the specified array of resources in the specified PE file. 88 | ; Parameters ...: sBinFile - PE file whose resources are to be updated. 89 | ; ..............: bDelOld - Delete all old resources if 1 or leave them intact if 0. 90 | ; ..............: objRes - Array of objects describing the resources to update. Must be structured as follows: 91 | ; ..............: objRes[n].ResName - The name of the resource. 92 | ; ..............: objRes[n].ResType - The resource type. 93 | ; ..............: objRes[n].LangId - Language identifier of the resource to be updated. 94 | ; ..............: objRes[n].DataAddr - Pointer to resource data. Must not point to ANSI data. 95 | ; ..............: objRes[n].DataSize - Size of the resource data. 96 | ; Return .......: Number of resources updated on success, 0 on error. 97 | ; ---------------------------------------------------------------------------------------------------------------------- 98 | UpdRes_UpdateArrayOfResources(sBinFile, bDelOld, ByRef objRes) 99 | { 100 | If ( !IsObject(objRes) ) 101 | Return 0, ErrorLevel := "Array of resources object is not an object." 102 | 103 | If ( !hMod := DllCall( "BeginUpdateResource", Str,sBinFile, Int,bDelOld ) ) 104 | Return 0, ErrorLevel := "BeginUpdateResource error`nReturn value = " hMod "`nLast error = " A_LastError 105 | 106 | Loop % objRes.MaxIndex() 107 | { 108 | If ( !DllCall( "UpdateResource", Ptr,hMod, Ptr,objRes[A_Index].ResType, Str,objRes[A_Index].ResName 109 | , UInt,objRes[A_Index].LangId, Ptr,objRes[A_Index].DataAddr 110 | , UInt,objRes[A_Index].DataSize ) ) 111 | Continue 112 | nUpdated := A_Index 113 | } 114 | 115 | If ( !e := DllCall( "EndUpdateResource", Ptr,hMod, Int,0 ) ) 116 | Return 0, ErrorLevel := "EndUpdateResource error`nReturn value = " e "`nLast error = " A_LastError 117 | 118 | Return nUpdated 119 | } 120 | 121 | ; ---------------------------------------------------------------------------------------------------------------------- 122 | ; Function .....: UpdRes_UpdateDirOfResources 123 | ; Description ..: Add the resources in the desired directory in the specified PE file. Only the file in the root 124 | ; ..............: directory will be added, any subdirectory will be ignored. All the resources will be added with the 125 | ; ..............: same resource type and language identifier. 126 | ; Parameters ...: sResDir - Directory containing the resources to add to the PE file. 127 | ; ..............: sBinFile - PE file whose resources are to be updated. 128 | ; ..............: bDelOld - Delete all old resources if 1 or leave them intact if 0. 129 | ; ..............: nResType - The resource type. 130 | ; ..............: nLangId - Language identifier of the resources to be updated. 131 | ; Return .......: Number of resources updated on success, 0 on error. 132 | ; ---------------------------------------------------------------------------------------------------------------------- 133 | UpdRes_UpdateDirOfResources(sResDir, sBinFile, bDelOld, nResType, nLangId) 134 | { 135 | If ( !FileExist(sBinFile) || !InStr(FileExist(sResDir), "D") ) 136 | Return 0, ErrorLevel := "Binary file or resources directory not existing." 137 | 138 | Try 139 | { 140 | objRes := Object() 141 | Loop, %sResDir%\*.* 142 | { 143 | objFile := FileOpen(A_LoopFileLongPath, "r") 144 | ; PAGE_READONLY = 2 145 | If ( !hMap := DllCall( "CreateFileMapping", Ptr,objFile.__Handle, Ptr,0, UInt,2, UInt,0, UInt,0, Ptr,0 ) ) 146 | { 147 | objFile.Close() 148 | Continue 149 | } 150 | ; FILE_MAP_READ = 4 151 | If ( !pMap := DllCall( "MapViewOfFile", Ptr,hMap, UInt,4, UInt,0, UInt,0, UInt,0 ) ) 152 | { 153 | DllCall( "CloseHandle", Ptr,hMap ), objFile.Close() 154 | Continue 155 | } 156 | objRes.Insert({ "ResName" : A_LoopFileName 157 | , "ResType" : nResType 158 | , "LangId" : nLangId 159 | , "DataAddr" : pMap 160 | , "DataSize" : objFile.Length 161 | , "__oFile" : objFile 162 | , "__hMap" : hMap 163 | , "__pMap" : pMap }) 164 | } 165 | nUpdated := UpdRes_UpdateArrayOfResources(sBinFile, bDelOld, objRes) 166 | } 167 | Finally 168 | { 169 | Loop % objRes.MaxIndex() 170 | DllCall( "UnmapViewOfFile", Ptr,objRes[A_Index].__pMap ) 171 | , DllCall( "CloseHandle", Ptr,objRes[A_Index].__hMap ) 172 | , objRes[A_Index].__oFile.Close() 173 | ObjRelease(objRes) 174 | } 175 | 176 | Return nUpdated 177 | } 178 | 179 | ; ---------------------------------------------------------------------------------------------------------------------- 180 | ; Function .....: UpdRes_EnumerateResources 181 | ; Description ..: Enumerate all the resources of a specific type inside a binary file. 182 | ; Parameters ...: sBinFile - PE file whose resources are to be enumerated. If = 0 the current process resources will be 183 | ; ..............: enumerated. 184 | ; ..............: nResType - The resource type. 185 | ; Return .......: List of enumerated resources, 0 on error. 186 | ; Info .........: EnumResourceNames: https://msdn.microsoft.com/en-us/library/windows/desktop/ms648037(v=vs.85).aspx 187 | ; ---------------------------------------------------------------------------------------------------------------------- 188 | UpdRes_EnumerateResources(sBinFile, nResType) 189 | { 190 | If ( !hLib := DllCall( "GetModuleHandle", Ptr,(sBinFile?&sBinFile:0) ) ) 191 | { 192 | ; If the DLL isn't already loaded, load it as a data file. 193 | If ( !hLib := DllCall( "LoadLibraryEx", Str,sBinFile, Ptr,0, UInt,0x2 ) ) 194 | Return 0, ErrorLevel := "LoadLibraryEx error`nReturn value = " hLib "`nLast error = " A_LastError 195 | bLoaded := 1 196 | } 197 | 198 | Try 199 | { 200 | ; Enumerate the resources of type nResType. 201 | cbEnum := RegisterCallback( "__UpdRes_EnumeratorCallback" ), adrEnumList := 0 202 | DllCall( "EnumResourceNames", Ptr,hLib, Ptr,nResType, Ptr,cbEnum, Ptr,&adrEnumList ) 203 | DllCall( "GlobalFree", Ptr,cbEnum ) 204 | } 205 | Finally 206 | { 207 | ; If we loaded the DLL, free it now. 208 | If ( bLoaded ) 209 | DllCall( "FreeLibrary", Ptr,hLib ) 210 | } 211 | 212 | ; Recover the address of the enumeration string and get it. 213 | Return StrGet(NumGet(&adrEnumList)) 214 | } 215 | 216 | ; ---------------------------------------------------------------------------------------------------------------------- 217 | ; Function .....: __UpdRes_EnumeratorCallback 218 | ; Description ..: Enumerator callback for the UpdRes_EnumerateResources function. Do not call directly. 219 | ; Info .........: EnumResNameProc: https://msdn.microsoft.com/en-us/library/windows/desktop/ms648034(v=vs.85).aspx 220 | ; ---------------------------------------------------------------------------------------------------------------------- 221 | __UpdRes_EnumeratorCallback(hModule, lpszType, lpszName, lParam) 222 | { 223 | Static sEnumList := "" 224 | 225 | ; Concatenate the string and put its address in the lParam parameter. 226 | sEnumList .= "[Type] " lpszType " [Name] " lpszName "`n" 227 | NumPut( &sEnumList, lParam+0 ) 228 | 229 | Return true 230 | } 231 | -------------------------------------------------------------------------------- /WinEvents.ahk: -------------------------------------------------------------------------------- 1 | ; ---------------------------------------------------------------------------------------------------------------------- 2 | ; Name .........: WinEvents library 3 | ; Description ..: Minimal Windows Events API implementation. It can be used to attach events to the Windows Events Logs. 4 | ; AHK Version ..: AHK_L 1.1.13.01 x32/64 Unicode 5 | ; Author .......: Cyruz (http://ciroprincipe.info) 6 | ; License ......: WTFPL - http://www.wtfpl.net/txt/copying/ 7 | ; Changelog ....: Sep. 30, 2012 - v0.1 - First revision. 8 | ; ..............: Oct. 06, 2012 - v0.2 - Fixed some wrong behaviours. 9 | ; ..............: Jan. 09, 2014 - v0.3 - Unicode and x64 version. Now it uses arrays instead of continuation sections. 10 | ; ---------------------------------------------------------------------------------------------------------------------- 11 | 12 | ; ---------------------------------------------------------------------------------------------------------------------- 13 | ; Function .....: WinEvents_RegisterForEvents 14 | ; Description ..: Register the application to send Windows log events. 15 | ; Parameters ...: sLogName - Can be "Application", "System" or a custom event log name. 16 | ; Return .......: Handle to the registered source on success, NULL on failure. 17 | ; ---------------------------------------------------------------------------------------------------------------------- 18 | WinEvents_RegisterForEvents(sLogName) { 19 | Return DllCall( "Advapi32.dll\RegisterEventSource", Ptr,0, Str,sLogName ) 20 | } 21 | 22 | ; ---------------------------------------------------------------------------------------------------------------------- 23 | ; Function .....: WinEvents_DeregisterForEvents 24 | ; Description ..: Deregister the previously registered application. 25 | ; Parameters ...: hSource - Handle to a previously registered events source with RegisterForEvents. 26 | ; Return .......: Nonzero if the function succeeds or zero if it fails. 27 | ; ---------------------------------------------------------------------------------------------------------------------- 28 | WinEvents_DeregisterForEvents(hSource) { 29 | Return DllCall( "Advapi32.dll\DeregisterEventSource", Ptr,hSource ) 30 | } 31 | 32 | ; ---------------------------------------------------------------------------------------------------------------------- 33 | ; Function .....: WinEvents_SendWinLogEvent 34 | ; Description ..: Write an entry at the end of the specified Windows event log. 35 | ; Parameters ...: hSource - Handle to a previously registered events source with RegisterForEvents. 36 | ; ..............: evType - Can be: "EVENTLOG_SUCCESS" 37 | ; ..............: "EVENTLOG_AUDIT_FAILURE" 38 | ; ..............: "EVENTLOG_AUDIT_SUCCESS" 39 | ; ..............: "EVENTLOG_ERROR_TYPE" 40 | ; ..............: "EVENTLOG_INFORMATION_TYPE" 41 | ; ..............: "EVENTLOG_WARNING_TYPE" 42 | ; ..............: evId - Event ID, can be any dword value. 43 | ; ..............: evCat - Any value, used to organize events in categories. 44 | ; ..............: arrStrings - A simple array of strings (each max 31839 chars). 45 | ; ..............: pData - A buffer containing the binary data. 46 | ; Return .......: Nonzero if the function succeeds or zero if it fails. 47 | ; ---------------------------------------------------------------------------------------------------------------------- 48 | WinEvents_SendWinLogEvent(hSource, evType, evId, evCat:=0, ByRef arrStrings:=0, ByRef pData:=0) { 49 | Static EVENTLOG_SUCCESS := 0x0000, EVENTLOG_AUDIT_FAILURE := 0x0010, EVENTLOG_AUDIT_SUCCESS := 0x0008 50 | , EVENTLOG_ERROR_TYPE := 0x0001, EVENTLOG_INFORMATION_TYPE := 0x0004, EVENTLOG_WARNING_TYPE := 0x0002 51 | 52 | If ( evType != "EVENTLOG_SUCCESS" && evType != "EVENTLOG_AUDIT_FAILURE" && evType != "EVENTLOG_AUDIT_SUCCESS" 53 | && evType != "EVENTLOG_ERROR_TYPE" && evType != "EVENTLOG_INFORMATION_TYPE" && evType != "EVENTLOG_WARNING_TYPE" ) 54 | Return 0 55 | 56 | nLen := arrStrings.MaxIndex() 57 | VarSetCapacity(arrFinal, nLen*A_PtrSize) 58 | Loop %nLen% ; Fills the array of strings 59 | NumPut(arrStrings.GetAddress(A_Index), arrFinal, (A_Index-1)*A_PtrSize, "Ptr") 60 | 61 | Return DllCall( "Advapi32.dll\ReportEvent", UInt,hSource, UShort,%evType%, UShort,evCat, UInt,evId, Ptr,0 62 | , UShort,nLen, UInt,szData:=VarSetCapacity(pData), Ptr,(nLen)?&arrFinal:0 63 | , Ptr,(szData)?&pData:0 ) 64 | } 65 | 66 | /* EXAMPLE CODE: 67 | ; Register the application for sending events. 68 | hSource := WinEvents_RegisterForEvents("Application") 69 | 70 | ; Send a simple INFORMATION_TYPE Event with ID 0x0123 to the Application log. 71 | WinEvents_SendWinLogEvent(hSource, "EVENTLOG_INFORMATION_TYPE", 0x0123) 72 | 73 | ; Array of strings. 74 | arrStr := [ "This is the first test string." 75 | , "Yay, this is the second test string." 76 | , "This is the third and final test string." ] 77 | 78 | 79 | ; Some hex data (a simple icon). 80 | inDataHex = 81 | ( Join 82 | 000001000100101010000100040028010000160000002800000010000000200000000100040000000000C00000 83 | 0000000000000000000000000000000000C6080800CE101000CE181800D6212100D6292900E13F3F00E7525200 84 | EF5A5A00EF636300F76B6B00F7737300FF7B7B00FFC6C600FFCEC600FFDEDE00FFFFFF00CCCCCCCCCCCCCCCCC0 85 | 0000000000000CC11111111111111CC22222CFFE22222CC33333CFFE33333CC44444CFFE44444CC55555CFFE55 86 | 555CC55555CFFE55555CC55555CFFE55555CC66666CFFE66666CC77777777777777CC88888CFFC88888CC99999 87 | CFFC99999CCAAAAAAAAAAAAAACCBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCC00000000000000000000000000000000 88 | 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 89 | 000000 90 | ) 91 | 92 | ; -- MCode by Laszlo. 93 | VarSetCapacity(inData, StrLen(inDataHex)//2) 94 | Loop % StrLen(inDataHex)//2 95 | NumPut("0x" . SubStr(inDataHex, 2*A_Index-1, 2), inData, A_Index-1, "UChar") 96 | ; -- 97 | 98 | ; Send a SUCCESS Event with ID 0x0001, arrStr as string and inData as binary data, to the Application log. 99 | WinEvents_SendWinLogEvent(hSource, "EVENTLOG_WARNING_TYPE", 0x0001, 0, arrStr, inData) 100 | 101 | ; Deregister the application. 102 | WinEvents_DeregisterForEvents(hSource) 103 | */ -------------------------------------------------------------------------------- /WinHttpRequest.ahk: -------------------------------------------------------------------------------- 1 | ; WinHttpRequest 2 | ; Version: 1.00 / 2014-4-3 / tmplinshi 3 | ; Tested On: [AHK] 1.1.14.03 A32/U32 | [OS] WinXP SP3 4 | ; 5 | ; Usage is similar to HTTPRequest (by VxE), 6 | ; Please visit the HTTPRequest page (http://goo.gl/CcnNOY) for more details. 7 | ; 8 | ; Supported Options: 9 | ; NO_AUTO_REDIRECT 10 | ; Timeout: Seconds 11 | ; Proxy: IP:Port 12 | ; Codepage: 65001 13 | ; Charset: utf-8 14 | ; SaveAs: FileName 15 | ; Return: 16 | ; Success = -1, Timeout = 0, No response = Empty String 17 | ; 18 | ; How to clear cookie: 19 | ; WinHttpRequest( [] ) 20 | ; 21 | ; Thanks: 22 | ; VxE for his HTTPRequest (http://goo.gl/CcnNOY) 23 | WinHttpRequest( URL, ByRef In_POST__Out_Data="", ByRef In_Out_HEADERS="", Options="" ) 24 | { 25 | static nothing := ComObjError(0) 26 | static oHTTP := ComObjCreate("WinHttp.WinHttpRequest.5.1") 27 | static oADO := ComObjCreate("adodb.stream") 28 | 29 | ; Clear cookie: WinHttpRequest( [] ) 30 | If IsObject(URL) { 31 | oHTTP := ComObjCreate("WinHttp.WinHttpRequest.5.1") 32 | Return 33 | } 34 | 35 | ; POST or GET 36 | If (In_POST__Out_Data != "") || InStr(Options, "Method: POST") 37 | oHTTP.Open("POST", URL, True) 38 | Else 39 | oHTTP.Open("GET", URL, True) 40 | 41 | ; HEADERS 42 | If In_Out_HEADERS 43 | { 44 | In_Out_HEADERS := Trim(In_Out_HEADERS, " `t`r`n") 45 | Loop, Parse, In_Out_HEADERS, `n, `r 46 | { 47 | If !( _pos := InStr(A_LoopField, ":") ) 48 | Continue 49 | 50 | Header_Name := SubStr(A_LoopField, 1, _pos-1) 51 | Header_Value := SubStr(A_LoopField, _pos+1) 52 | 53 | If ( Trim(Header_Value) != "" ) 54 | oHTTP.SetRequestHeader( Header_Name, Header_Value ) 55 | } 56 | } 57 | 58 | If (In_POST__Out_Data != "") 59 | oHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded") 60 | 61 | ; Options 62 | If Options 63 | { 64 | Loop, Parse, Options, `n, `r 65 | { 66 | If ( _pos := InStr(A_LoopField, "Timeout:") ) 67 | Timeout := SubStr(A_LoopField, _pos+8) 68 | Else If ( _pos := InStr(A_LoopField, "Proxy:") ) 69 | oHTTP.SetProxy( 2, SubStr(A_LoopField, _pos+6) ) 70 | Else If ( _pos := InStr(A_LoopField, "Codepage:") ) 71 | oHTTP.Option(2) := SubStr(A_LoopField, _pos+9) 72 | } 73 | 74 | oHTTP.Option(6) := InStr(Options, "NO_AUTO_REDIRECT") ? 0 : 1 75 | } 76 | 77 | ; Send... 78 | oHTTP.Send(In_POST__Out_Data) 79 | ReturnCode := oHTTP.WaitForResponse(Timeout ? Timeout : -1) 80 | 81 | ; Handle "SaveAs:" and "Charset:" 82 | If InStr(Options, "SaveAs:") 83 | { 84 | RegExMatch(Options, "i)SaveAs:[ \t]*\K[^\r\n]+", SavePath) 85 | 86 | oADO.Type := 1 87 | oADO.Open() 88 | oADO.Write( oHTTP.ResponseBody ) 89 | oADO.SaveToFile( SavePath, 2 ) 90 | oADO.Close() 91 | 92 | In_POST__Out_Data := "" 93 | } 94 | Else If InStr(Options, "Charset:") 95 | { 96 | RegExMatch(Options, "i)Charset:[ \t]*\K\w+", Encoding) 97 | 98 | oADO.Type := 1 99 | oADO.Mode := 3 100 | oADO.Open() 101 | oADO.Write( oHTTP.ResponseBody() ) 102 | oADO.Position := 0 103 | oADO.Type := 2 104 | oADO.Charset := Encoding 105 | In_POST__Out_Data := IsByRef(In_POST__Out_Data) ? oADO.ReadText() : "" 106 | } 107 | Else 108 | In_POST__Out_Data := IsByRef(In_POST__Out_Data) ? oHTTP.ResponseText : "" 109 | 110 | ; output headers 111 | In_Out_HEADERS := "HTTP/1.1 " oHTTP.Status() "`n" oHTTP.GetAllResponseHeaders() 112 | 113 | Return, ReturnCode ; Success = -1, Timeout = 0, No response = Empty String 114 | } -------------------------------------------------------------------------------- /Zip.ahk: -------------------------------------------------------------------------------- 1 | ; ---------------------------------------------------------------------------------------------------------------------- 2 | ; Name .........: Zip library 3 | ; Description ..: Implements basic zip features using Windows built-in zip support. 4 | ; AHK Version ..: AHK_L 1.1.13.01 x32/64 Unicode 5 | ; Author .......: shajul (http://goo.gl/t3rtix) - Cyruz (http://ciroprincipe.info) 6 | ; License ......: WTFPL - http://www.wtfpl.net/txt/copying/ 7 | ; Changelog ....: Mar. 03, 2014 - v0.1 - First version. 8 | ; ---------------------------------------------------------------------------------------------------------------------- 9 | 10 | ; ---------------------------------------------------------------------------------------------------------------------- 11 | ; Function .....: Zip_Add 12 | ; Description ..: Creates a zip archive with the provided files. 13 | ; Parameters ...: sZip - Path to the zip file to be created. 14 | ; ..............: sFiles - Path to the folder or file to be added to the zip (files can be passed as wildcard: *.*). 15 | ; Return .......: 1 on success, 0 on error. 16 | ; ---------------------------------------------------------------------------------------------------------------------- 17 | Zip_Add(sZip, sFiles) { 18 | If ( !FileExist(sZip) ) { ; Create an empty file zip. 19 | HEADER1 := "PK" . Chr(5) . Chr(6), VarSetCapacity(HEADER2, 18, 0) 20 | If ( !IsObject(oFile := FileOpen(sZip, "w")) ) 21 | Return 0 22 | oFile.Write(HEADER1) 23 | oFile.RawWrite(HEADER2, 18) 24 | oFile.close() 25 | } 26 | objShell := ComObjCreate("Shell.Application") 27 | objZip := objShell.Namespace(sZip) 28 | If ( InStr(FileExist(sFiles), "D") ) 29 | sFiles .= (SubStr(sFiles, 0) == "\") ? "*.*" : "\*.*" 30 | Loop, %sFiles%, 1 31 | { 32 | nZipped := objZip.Items().Count + 1 33 | objZip.CopyHere(A_LoopFileLongPath, 16) 34 | Loop 35 | { ; This loop is required to check if the file has been zipped. 36 | Sleep, 50 37 | If ( nZipped == objZip.Items().Count ) 38 | Break 39 | } 40 | } 41 | Return 1 42 | } 43 | 44 | ; ---------------------------------------------------------------------------------------------------------------------- 45 | ; Function .....: Zip_Extract 46 | ; Description ..: Extract the zip archive to the specified folder. 47 | ; Parameters ...: sZip - Path to the zip file to be extracted. 48 | ; ..............: sDir - Path to the directory where the archive will be extracted. 49 | ; Return .......: 1 on success, 0 on error. 50 | ; ---------------------------------------------------------------------------------------------------------------------- 51 | Zip_Extract(sZip, sDir) { 52 | If ( !InStr(FileExist(sDir), "D") ) { 53 | FileCreateDir, %sDir% 54 | If ( ErrorLevel ) 55 | Return 0 56 | } 57 | objShell := ComObjCreate("Shell.Application") 58 | nZipped := objShell.Namespace(sZip).Items().Count 59 | objShell.Namespace(sDir).CopyHere(objShell.Namespace(sZip).Items, 16) 60 | Loop 61 | { ; This loop is required to check if the zip content has been extracted. 62 | Sleep, 50 63 | nUnzipped := objShell.Namespace(sDir).Items().Count 64 | If ( nUnzipped == nZipped ) 65 | Break 66 | } 67 | Return 1 68 | } 69 | -------------------------------------------------------------------------------- /type.ahk: -------------------------------------------------------------------------------- 1 | ; type(v) by lexikos - http://ahkscript.org/boards/viewtopic.php?f=6&t=2306&sid=8e1b4d1358e28ecf577a7aca4d22f9b9 2 | 3 | ; Object version - depends on current float format including a decimal point. 4 | type(v) { 5 | if IsObject(v) 6 | return "Object" 7 | return v="" || [v].GetCapacity(1) ? "String" : InStr(v,".") ? "Float" : "Integer" 8 | } 9 | 10 | ; COM version - reports the wrong type for integers outside 32-bit range. 11 | com_type(ByRef v) { 12 | if IsObject(v) 13 | return "Object" 14 | a := ComObjArray(0xC, 1) 15 | a[0] := v 16 | DllCall("oleaut32\SafeArrayAccessData", "ptr", ComObjValue(a), "ptr*", ap) 17 | type := NumGet(ap+0, "ushort") 18 | DllCall("oleaut32\SafeArrayUnaccessData", "ptr", ComObjValue(a)) 19 | return type=3?"Integer" : type=8?"String" : type=5?"Float" : type 20 | } --------------------------------------------------------------------------------