├── .gitignore ├── LICENSE ├── README.md ├── client ├── Updater.au3 ├── example.au3 └── include │ ├── BinaryCall.au3 │ └── JSON.au3 └── server ├── download.php ├── index.php └── version.php /.gitignore: -------------------------------------------------------------------------------- 1 | BackUp/ 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Juno_okyo 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AutoIt Updater 2 | 3 | An updater for your AutoIt applications 4 | 5 | ## Screenshot 6 | 7 | ![AutoIt Updater](https://i.imgur.com/U63k3Uj.gif) 8 | 9 | ## Demo Video 10 | 11 | https://www.youtube.com/watch?v=nXamlwH-5Co 12 | 13 | ## License 14 | 15 | This work is licensed under a [MIT LICENSE](LICENSE). 16 | -------------------------------------------------------------------------------- /client/Updater.au3: -------------------------------------------------------------------------------- 1 | #include-once 2 | 3 | #Region Includes 4 | #include 5 | #include ; by Ward 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #EndRegion Includes 12 | 13 | ; #INDEX# ======================================================================================================================= 14 | ; Title .........: AutoIt Updater 15 | ; UDF Version....: 1.0.0 16 | ; AutoIt Version : 3.3.14.2 17 | ; Description ...: An updater for your AutoIt applications 18 | ; Author(s) .....: Juno_okyo 19 | ; =============================================================================================================================== 20 | 21 | ; #CONSTANTS# =================================================================================================================== 22 | Global Const $UPDATER_VERSION = '1.0.0' 23 | Global Const $UPDATER_USER_AGENT = 'AutoIt Updater v' & $UPDATER_VERSION 24 | ; =============================================================================================================================== 25 | 26 | ; #FUNCTION# ==================================================================================================================== 27 | ; Author ........: Juno_okyo 28 | ; =============================================================================================================================== 29 | Func _update($serverURL, $currentVersion, $beta = False, $parentGUI = 0, $message = 'You are using the latest version!') 30 | Local $channel = ($beta) ? 'beta' : 'stable' 31 | Local $unknowError = 'Something wrong happened.' 32 | Local $response = __request($serverURL & 'version.php?channel=' & _urlEncode($channel)) 33 | 34 | If @error Then 35 | __MsgBox(16, 'Error', 'Server URL is invalid.', $parentGUI) 36 | Return False 37 | EndIf 38 | 39 | Local $json = Json_Decode($response) 40 | Local $latestVersion = Json_Get($json, '["data"]["version"]') 41 | If @error Then 42 | __MsgBox(16, 'Error', $unknowError, $parentGUI) 43 | Return False 44 | EndIf 45 | 46 | Local $compare = _VersionCompare($currentVersion, $latestVersion) 47 | If @error Then 48 | __MsgBox(16, 'Error', $unknowError, $parentGUI) 49 | Return False 50 | EndIf 51 | 52 | ; New version available 53 | If $compare == -1 Then 54 | Local $changelog = Json_Get($json, '["data"]["changelog"]') 55 | 56 | ; Show Changelog GUI 57 | Opt('GUIOnEventMode', 0) 58 | Opt('GUICloseOnESC', 0) 59 | 60 | #Region ### START Koda GUI section ### 61 | Local $formUpdate = GUICreate('New version is available', 457, 270, -1, -1, -1, -1, $parentGUI) 62 | GUISetFont(12, 400, 0, 'Arial') 63 | Local $Edit = GUICtrlCreateEdit('', 8, 8, 441, 217, BitOR($ES_AUTOVSCROLL, $ES_READONLY, $ES_WANTRETURN, $WS_HSCROLL, $WS_VSCROLL)) 64 | GUICtrlSetData(-1, $changelog) 65 | GUIStartGroup() 66 | Local $btnUpdate = GUICtrlCreateButton('Update now', 102, 235, 107, 25) 67 | GUICtrlSetFont(-1, 12, 400, 0, 'Arial') 68 | Local $btnCancel = GUICtrlCreateButton('Cancel', 246, 235, 107, 25) 69 | GUICtrlSetFont(-1, 12, 400, 0, 'Arial') 70 | GUIStartGroup() 71 | GUISetState(@SW_SHOW, $formUpdate) 72 | #EndRegion ### END Koda GUI section ### 73 | 74 | Local $iMsg = 0 75 | While 1 76 | $iMsg = GUIGetMsg() 77 | Switch $iMsg 78 | Case $btnUpdate 79 | GUISetState(@SW_HIDE, $formUpdate) 80 | Local $fileName = Json_Get($json, '["data"]["name"]') 81 | Local $url = $serverURL & 'download.php?channel=' & _urlEncode($channel) 82 | $url &= '&version=' & _urlEncode($latestVersion) 83 | $url &= '&file=' & _urlEncode($fileName) 84 | 85 | Local $filePath = __downloader($url, $fileName, $fileName) 86 | If @error Then 87 | If __MsgBox(32 + 4, 'Error', 'Download failed. Do you want to open download url in the browser?', $parentGUI) == 6 Then 88 | ShellExecute($url) 89 | EndIf 90 | Else 91 | ; Run setup file 92 | ShellExecute($filePath) 93 | EndIf 94 | ExitLoop 95 | 96 | Case $btnCancel 97 | ExitLoop 98 | 99 | Case $GUI_EVENT_CLOSE 100 | ExitLoop 101 | EndSwitch 102 | WEnd 103 | 104 | GUIDelete($formUpdate) 105 | Else 106 | __MsgBox(64, 'Updater', $message, $parentGUI) 107 | Return False 108 | EndIf 109 | EndFunc ;==>_update 110 | 111 | #Region 112 | Func __downloader($sSourceURL, $sTargetName, $sVisibleName, $sTargetDir = @TempDir, $bProgressOff = True, $iEndMsgTime = 2000, $sDownloaderTitle = "Downloader") 113 | ; Declare some general vars 114 | Local $iMBbytes = 1048576 115 | 116 | ; If the target directory doesn't exist -> create the dir 117 | If Not FileExists($sTargetDir) Then DirCreate($sTargetDir) 118 | 119 | ; Get download and target info 120 | Local $sTargetPath = $sTargetDir & "\" & $sTargetName 121 | Local $iFileSize = InetGetSize($sSourceURL) 122 | Local $hFileDownload = InetGet($sSourceURL, $sTargetPath, $INET_LOCALCACHE, $INET_DOWNLOADBACKGROUND) 123 | 124 | ; Show progress UI 125 | ProgressOn($sDownloaderTitle, "Downloading " & $sVisibleName) 126 | 127 | ; Keep checking until download completed 128 | Do 129 | Sleep(250) 130 | 131 | ; Set vars 132 | Local $iDLPercentage = Round(InetGetInfo($hFileDownload, $INET_DOWNLOADREAD) * 100 / $iFileSize, 0) 133 | Local $iDLBytes = Round(InetGetInfo($hFileDownload, $INET_DOWNLOADREAD) / $iMBbytes, 2) 134 | Local $iDLTotalBytes = Round($iFileSize / $iMBbytes, 2) 135 | 136 | ; Update progress UI 137 | If IsNumber($iDLBytes) And $iDLBytes >= 0 Then 138 | ProgressSet($iDLPercentage, $iDLPercentage & "% - Downloaded " & $iDLBytes & " MB of " & $iDLTotalBytes & " MB") 139 | Else 140 | ProgressSet(0, "Downloading '" & $sVisibleName & "'") 141 | EndIf 142 | Until InetGetInfo($hFileDownload, $INET_DOWNLOADCOMPLETE) 143 | 144 | ; If the download was successfull, return the target location 145 | If InetGetInfo($hFileDownload, $INET_DOWNLOADSUCCESS) Then 146 | ProgressSet(100, "Downloading '" & $sVisibleName & "' completed") 147 | If $bProgressOff Then 148 | Sleep($iEndMsgTime) 149 | ProgressOff() 150 | EndIf 151 | Return $sTargetPath 152 | ; If the download failed, set @error and return False 153 | Else 154 | Local $errorCode = InetGetInfo($hFileDownload, $INET_DOWNLOADERROR) 155 | ProgressSet(0, "Downloading '" & $sVisibleName & "' failed." & @CRLF & "Error code: " & $errorCode) 156 | If $bProgressOff Then 157 | Sleep($iEndMsgTime) 158 | ProgressOff() 159 | EndIf 160 | SetError(1, $errorCode, False) 161 | EndIf 162 | EndFunc ;==>__downloader 163 | 164 | Func __request($url) 165 | If StringLen($url) == 0 Then Return SetError(1, 0, False) 166 | 167 | Local $oHTTP = ObjCreate('WinHttp.WinHttpRequest.5.1') 168 | $oHTTP.Option(6) = False 169 | $oHTTP.Open('get', $url, False) 170 | $oHTTP.SetRequestHeader('User-Agent', $UPDATER_USER_AGENT) 171 | $oHTTP.SetRequestHeader('Content-Type', 'application/vnd.api+json') 172 | $oHTTP.Send() 173 | $oHTTP.WaitForResponse 174 | Return $oHTTP.Responsetext 175 | EndFunc ;==>__request 176 | 177 | Func _urlEncode($vData) 178 | If IsBool($vData) Then Return $vData 179 | Local $aData = StringToASCIIArray($vData, Default, Default, 2) 180 | Local $sOut = '', $total = UBound($aData) - 1 181 | For $i = 0 To $total 182 | Switch $aData[$i] 183 | Case 45, 46, 48 To 57, 65 To 90, 95, 97 To 122, 126 184 | $sOut &= Chr($aData[$i]) 185 | Case 32 186 | $sOut &= '+' 187 | Case Else 188 | $sOut &= '%' & Hex($aData[$i], 2) 189 | EndSwitch 190 | Next 191 | Return $sOut 192 | EndFunc ;==>_urlEncode 193 | 194 | Func __MsgBox($flag, $title, $text, $parentGUI = 0) 195 | ; Top most 196 | $flag += 262144 197 | 198 | If $parentGUI == 0 Then 199 | MsgBox($flag, $title, $text) 200 | Else 201 | MsgBox($flag, $title, $text, 0, $parentGUI) 202 | EndIf 203 | EndFunc ;==>__MsgBox 204 | #EndRegion 205 | -------------------------------------------------------------------------------- /client/example.au3: -------------------------------------------------------------------------------- 1 | #cs ---------------------------------------------------------------------------- 2 | 3 | AutoIt Version: 3.3.14.2 4 | Author: Juno_okyo 5 | 6 | Copyright (C) 2016 Juno_okyo. All rights reserved. 7 | 8 | This file is part of AutoIt Updater which is released under MIT LICENSE. 9 | See file LICENSE or go to for full license details: 10 | https://github.com/J2TeaM/autoit-updater/blob/master/LICENSE 11 | 12 | #ce ---------------------------------------------------------------------------- 13 | 14 | #NoTrayIcon 15 | 16 | #Region Includes 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include "Updater.au3" 22 | #EndRegion Includes 23 | 24 | _Singleton(@ScriptName) 25 | 26 | #Region Options 27 | Opt('MustDeclareVars', 1) 28 | Opt('WinTitleMatchMode', 2) 29 | Opt('GUICloseOnESC', 0) 30 | Opt('GUIOnEventMode', 1) 31 | #EndRegion Options 32 | 33 | ; Script Start - Add your code below here 34 | Global Const $VERSION = '1.0.0' 35 | Global Const $SERVER_UPDATE = 'http://localhost/autoit-updater/' 36 | 37 | #Region ### START Koda GUI section ### 38 | Global $FormMain = GUICreate('AutoIt Updater Demo v' & $VERSION, 591, 284, -1, -1) 39 | Global $MenuItem1 = GUICtrlCreateMenu('&File') 40 | Global $MenuItem2 = GUICtrlCreateMenuItem('&Exit', $MenuItem1) 41 | GUICtrlSetOnEvent(-1, 'FormMainClose') 42 | Global $MenuItem3 = GUICtrlCreateMenu('&Help') 43 | Global $MenuItem4 = GUICtrlCreateMenuItem('Check for &Update...', $MenuItem3) 44 | GUICtrlSetOnEvent(-1, 'MenuUpdateClick') 45 | GUICtrlCreateMenuItem('', $MenuItem3) 46 | Global $MenuItem6 = GUICtrlCreateMenuItem('&About', $MenuItem3) 47 | GUICtrlSetOnEvent(-1, 'MenuAboutClick') 48 | GUISetFont(12, 400, 0, 'Arial') 49 | GUISetOnEvent($GUI_EVENT_CLOSE, 'FormMainClose') 50 | Global $Label1 = GUICtrlCreateLabel('Demo by Juno_okyo', 149, 120, 293, 42) 51 | GUICtrlSetFont(-1, 25, 400, 0, 'Arial') 52 | GUISetState(@SW_SHOW) 53 | #EndRegion ### END Koda GUI section ### 54 | 55 | While 1 56 | Sleep(100) 57 | WEnd 58 | 59 | Func MenuAboutClick() 60 | MsgBox(64 + 262144, 'About', 'Version: ' & $VERSION, 0, $FormMain) 61 | EndFunc 62 | 63 | Func MenuUpdateClick() 64 | _update($SERVER_UPDATE, $VERSION, False, $FormMain) 65 | Opt('GUIOnEventMode', 1) ; _update() will turn-off this option, so we need to reset 66 | EndFunc ;==>MenuUpdateClick 67 | 68 | Func FormMainClose() 69 | Exit 70 | EndFunc ;==>FormMainClose 71 | -------------------------------------------------------------------------------- /client/include/BinaryCall.au3: -------------------------------------------------------------------------------- 1 | ; ============================================================================= 2 | ; AutoIt BinaryCall UDF (2014.7.24) 3 | ; Purpose: Allocate, Decompress, And Prepare Binary Machine Code 4 | ; Author: Ward 5 | ; ============================================================================= 6 | 7 | #Include-once 8 | 9 | Global $__BinaryCall_Kernel32dll = DllOpen('kernel32.dll') 10 | Global $__BinaryCall_Msvcrtdll = DllOpen('msvcrt.dll') 11 | Global $__BinaryCall_LastError = "" 12 | 13 | Func _BinaryCall_GetProcAddress($Module, $Proc) 14 | Local $Ret = DllCall($__BinaryCall_Kernel32dll, 'ptr', 'GetProcAddress', 'ptr', $Module, 'str', $Proc) 15 | If @Error Or Not $Ret[0] Then Return SetError(1, @Error, 0) 16 | Return $Ret[0] 17 | EndFunc 18 | 19 | Func _BinaryCall_LoadLibrary($Filename) 20 | Local $Ret = DllCall($__BinaryCall_Kernel32dll, "handle", "LoadLibraryW", "wstr", $Filename) 21 | If @Error Then Return SetError(1, @Error, 0) 22 | Return $Ret[0] 23 | EndFunc 24 | 25 | Func _BinaryCall_lstrlenA($Ptr) 26 | Local $Ret = DllCall($__BinaryCall_Kernel32dll, "int", "lstrlenA", "ptr", $Ptr) 27 | If @Error Then Return SetError(1, @Error, 0) 28 | Return $Ret[0] 29 | EndFunc 30 | 31 | Func _BinaryCall_Alloc($Code, $Padding = 0) 32 | Local $Length = BinaryLen($Code) + $Padding 33 | Local $Ret = DllCall($__BinaryCall_Kernel32dll, "ptr", "VirtualAlloc", "ptr", 0, "ulong_ptr", $Length, "dword", 0x1000, "dword", 0x40) 34 | If @Error Or Not $Ret[0] Then Return SetError(1, @Error, 0) 35 | If BinaryLen($Code) Then 36 | Local $Buffer = DllStructCreate("byte[" & $Length & "]", $Ret[0]) 37 | DllStructSetData($Buffer, 1, $Code) 38 | EndIf 39 | Return $Ret[0] 40 | EndFunc 41 | 42 | Func _BinaryCall_RegionSize($Ptr) 43 | Local $Buffer = DllStructCreate("ptr;ptr;dword;uint_ptr;dword;dword;dword") 44 | Local $Ret = DllCall($__BinaryCall_Kernel32dll, "int", "VirtualQuery", "ptr", $Ptr, "ptr", DllStructGetPtr($Buffer), "uint_ptr", DllStructGetSize($Buffer)) 45 | If @Error Or $Ret[0] = 0 Then Return SetError(1, @Error, 0) 46 | Return DllStructGetData($Buffer, 4) 47 | EndFunc 48 | 49 | Func _BinaryCall_Free($Ptr) 50 | Local $Ret = DllCall($__BinaryCall_Kernel32dll, "bool", "VirtualFree", "ptr", $Ptr, "ulong_ptr", 0, "dword", 0x8000) 51 | If @Error Or $Ret[0] = 0 Then 52 | $Ret = DllCall($__BinaryCall_Kernel32dll, "bool", "GlobalFree", "ptr", $Ptr) 53 | If @Error Or $Ret[0] <> 0 Then Return SetError(1, @Error, False) 54 | EndIf 55 | Return True 56 | EndFunc 57 | 58 | Func _BinaryCall_Release($CodeBase) 59 | Local $Ret = _BinaryCall_Free($CodeBase) 60 | Return SetError(@Error, @Extended, $Ret) 61 | EndFunc 62 | 63 | Func _BinaryCall_MemorySearch($Ptr, $Length, $Binary) 64 | Static $CodeBase 65 | If Not $CodeBase Then 66 | If @AutoItX64 Then 67 | $CodeBase = _BinaryCall_Create('0x4883EC084D85C94889C8742C4C39CA72254C29CA488D141131C9EB0848FFC14C39C97414448A1408453A140874EE48FFC04839D076E231C05AC3', '', 0, True, False) 68 | Else 69 | $CodeBase = _BinaryCall_Create('0x5589E58B4D14578B4508568B550C538B7D1085C9742139CA721B29CA8D341031D2EB054239CA740F8A1C17381C1074F34039F076EA31C05B5E5F5DC3', '', 0, True, False) 70 | EndIf 71 | If Not $CodeBase Then Return SetError(1, 0, 0) 72 | EndIf 73 | 74 | $Binary = Binary($Binary) 75 | Local $Buffer = DllStructCreate("byte[" & BinaryLen($Binary) & "]") 76 | DllStructSetData($Buffer, 1, $Binary) 77 | 78 | Local $Ret = DllCallAddress("ptr:cdecl", $CodeBase, "ptr", $Ptr, "uint", $Length, "ptr", DllStructGetPtr($Buffer), "uint", DllStructGetSize($Buffer)) 79 | Return $Ret[0] 80 | EndFunc 81 | 82 | Func _BinaryCall_Base64Decode($Src) 83 | Static $CodeBase 84 | If Not $CodeBase Then 85 | If @AutoItX64 Then 86 | $CodeBase = _BinaryCall_Create('0x41544989CAB9FF000000555756E8BE000000534881EC000100004889E7F3A44C89D6E98A0000004439C87E0731C0E98D0000000FB66E01440FB626FFC00FB65E020FB62C2C460FB62424408A3C1C0FB65E034189EB41C1E4024183E3308A1C1C41C1FB044509E34080FF634189CC45881C08744C440FB6DFC1E5044489DF4088E883E73CC1FF0209C7418D44240241887C08014883C10380FB63742488D841C1E3064883C60483E03F4409D841884408FF89F389C84429D339D30F8C67FFFFFF4881C4000100005B5E5F5D415CC35EC3E8F9FFFFFF000000000000000000000000000000000000000000000000000000000000000000000000000000000000003E0000003F3435363738393A3B3C3D00000063000000000102030405060708090A0B0C0D0E0F101112131415161718190000000000001A1B1C1D1E1F202122232425262728292A2B2C2D2E2F30313233', '', 132, True, False) 87 | Else 88 | $CodeBase = _BinaryCall_Create('0x55B9FF00000089E531C05756E8F10000005381EC0C0100008B55088DBDF5FEFFFFF3A4E9C00000003B45140F8FC20000000FB65C0A028A9C1DF5FEFFFF889DF3FEFFFF0FB65C0A038A9C1DF5FEFFFF889DF2FEFFFF0FB65C0A018985E8FEFFFF0FB69C1DF5FEFFFF899DECFEFFFF0FB63C0A89DE83E630C1FE040FB6BC3DF5FEFFFFC1E70209FE8B7D1089F3881C074080BDF3FEFFFF63745C0FB6B5F3FEFFFF8BBDECFEFFFF8B9DE8FEFFFF89F083E03CC1E704C1F80209F88B7D1088441F0189D883C00280BDF2FEFFFF6374278A85F2FEFFFFC1E60683C10483E03F09F088441F0289D883C0033B4D0C0F8C37FFFFFFEB0231C081C40C0100005B5E5F5DC35EC3E8F9FFFFFF000000000000000000000000000000000000000000000000000000000000000000000000000000000000003E0000003F3435363738393A3B3C3D00000063000000000102030405060708090A0B0C0D0E0F101112131415161718190000000000001A1B1C1D1E1F202122232425262728292A2B2C2D2E2F30313233', '', 132, True, False) 89 | EndIf 90 | If Not $CodeBase Then Return SetError(1, 0, Binary("")) 91 | EndIf 92 | 93 | $Src = String($Src) 94 | Local $SrcLen = StringLen($Src) 95 | Local $SrcBuf = DllStructCreate("char[" & $SrcLen & "]") 96 | DllStructSetData($SrcBuf, 1, $Src) 97 | 98 | Local $DstLen = Int(($SrcLen + 2) / 4) * 3 + 1 99 | Local $DstBuf = DllStructCreate("byte[" & $DstLen & "]") 100 | 101 | Local $Ret = DllCallAddress("uint:cdecl", $CodeBase, "ptr", DllStructGetPtr($SrcBuf), "uint", $SrcLen, "ptr", DllStructGetPtr($DstBuf), "uint", $DstLen) 102 | If $Ret[0] = 0 Then Return SetError(2, 0, Binary("")) 103 | Return BinaryMid(DllStructGetData($DstBuf, 1), 1, $Ret[0]) 104 | EndFunc 105 | 106 | Func _BinaryCall_Base64Encode($Src) 107 | Static $CodeBase 108 | If Not $CodeBase Then 109 | If @AutoItX64 Then 110 | $CodeBase = _BinaryCall_Create('AwAAAARiAQAAAAAAAAArkuFQDAlvIp0qAgbDnjr76UDZs1EPNIP2K18t9s6SNTbd43IB7HfdyPM8VfD/o36z4AmSW2m2AIsC6Af3fKNsHU4BdQKGd0PQXHxPSX0iNqp1YAKovksqQna06NeKMoOYqryTUX4WgpHjokhp6zY2sEFSIjcL7dW3FDoNVz4bGPyZHRvjFwmqvr7YGlNYKwNoh+SYCXmIgVPVZ63Vz1fbT33/QFpWmWOeBRqs4J+c8Qp6zJFsK345Pjw0I8kMSsnho4F4oNzQ2OsAbmIioaQ6Ma2ziw5NH+M+t4SpEeHDnBdUTTL20sxWZ0yKruFAsBIRoHvM7LYcid2eBV2d5roSjnkwMG0g69LNjs1fHjbI/9iU/hJwpSsgl4fltXdZG659/li13UFY89M7UfckiZ9XOeBM0zadgNsy8r8M3rEAAA==') 111 | Else 112 | $CodeBase = _BinaryCall_Create('AwAAAARVAQAAAAAAAAAqr7blBndrIGnmhhfXD7R1fkOTKhicg1W6MCtStbz+CsneBEg0bbHH1sqTLmLfY7A6LqZl6LYWT5ULVj6MXgugPbBn9wKsSU2ZCcBBPNkx09HVPdUaKnbqghDGj/C5SHoF+A/5g+UgE1C5zJZORjJ8ljs5lt2Y9lA4BsY7jVKX2vmDvHK1NnSR6nVwh7Pb+Po/UpNcy5sObVWDKkYSCCtCIjKIYqOe3c6k8Xsp4eritCUprXEVvCFi7K5Z6HFXdm3nZsFcE+eSJ1WkRnVQbWcmpjGMGka61C68+CI7tsQ13UnCFWNSpDrCbzUejMZh8HdPgEc5vCg3pKMKin/NavNpB6+87Y9y7HIxmKsPdjDT30u9hUKWnYiRe3nrwKyVDsiYpKU/Nse368jHag5B5or3UKA+nb2+eY8JwzgA') 113 | EndIf 114 | If Not $CodeBase Then Return SetError(1, 0, Binary("")) 115 | EndIf 116 | 117 | $Src = Binary($Src) 118 | Local $SrcLen = BinaryLen($Src) 119 | Local $SrcBuf = DllStructCreate("byte[" & $SrcLen & "]") 120 | DllStructSetData($SrcBuf, 1, $Src) 121 | 122 | Local $DstLen = Int(($SrcLen + 2) / 3) * 4 + 1 123 | Local $DstBuf = DllStructCreate("char[" & $DstLen & "]") 124 | 125 | Local $Ret = DllCallAddress("uint:cdecl", $CodeBase, "ptr", DllStructGetPtr($SrcBuf), "uint", $SrcLen, "ptr", DllStructGetPtr($DstBuf), "uint", $DstLen) 126 | If $Ret[0] = 0 Then Return Binary("") 127 | Return StringMid(DllStructGetData($DstBuf, 1), 1, $Ret[0]) 128 | EndFunc 129 | 130 | Func _BinaryCall_LzmaDecompress($Src) 131 | Static $CodeBase 132 | If Not $CodeBase Then 133 | If @AutoItX64 Then 134 | $CodeBase = _BinaryCall_Create(_BinaryCall_Base64Decode('QVcxwEFWQVVBVFVXSInXVkiJzlMx20iB7OgAAABEiiFBgPzgdgnpyQAAAEGD7C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HgA74IAAAASY28RgQBAADrEUmNvgQCAAC5EAAAAL4AAQAAiU3MuAEAAABJifvoYQEAAInCKfJy8gNVzEGD+QSJVcwPg7kAAABBg8EHuQMAAAA50XICidHB4Qa4AQAAAEmNvE9gAwAAvkAAAABJifvoHwEAAEGJwkEp8nLwQYP6BHJ4RInWRIlV0NHug2XQAf/Og03QAkGD+g5zFYnx0mXQi0XQRCnQTY20R14FAADrLIPuBOi6AAAA0evRZdBBOdhyBv9F0EEp2P/OdedNjbdEBgAAwWXQBL4EAAAAvwEAAACJ+E2J8+ioAAAAqAF0Awl90NHn/8516+sERIlV0P9F0EyJ74tNzEiJ+IPBAkgrRSBIOUXQd1RIif5IK3XQSItVGKyqSDnXcwT/yXX1SYn9D7bwTDttGA+C9fz//+gwAAAAKcBIi1UQTCtlCESJIkiLVWBMK20gRIkqSIPEKEFcQV1BXUFfW13DXli4AQAAAOvSgfsAAAABcgHDweMITDtlAHPmQcHgCEWKBCRJg8QBwynATY0cQ4H7AAAAAXMVweMITDtlAHPBQcHgCEWKBCRJg8QBidlBD7cTwekLD6/KQTnIcxOJy7kACAAAKdHB6QVmQQELAcDDKcvB6gVBKchmQSkTAcCDwAHDSLj////////////gbXN2Y3J0LmRsbHxtYWxsb2MASLj////////////gZnJlZQA=')) 135 | Else 136 | $CodeBase = _BinaryCall_Create(_BinaryCall_Base64Decode('VYnlVzH/VlOD7EyLXQiKC4D54A+HxQAAADHA6wWD6S2I0ID5LI1QAXfziEXmMcDrBYPpCYjQgPkIjVABd/OIReWLRRSITeSLUwkPtsmLcwWJEA+2ReUBwbgAAwAA0+CNhABwDgAAiQQk6EcEAACJNCSJRdToPAQAAItV1InHi0Xkhf+JArgBAAAAdDaF9nQyi0UQg8MNiRQkiXQkFIl8JBCJRCQYjUXgiUQkDItFDIlcJASD6A2JRCQI6CkAAACLVdSJRdSJFCToAQQAAItF1IXAdAqJPCQx/+jwAwAAg8RMifhbXl9dw1dWU1WJ5YtFJAFFKFD8i3UYAXUc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4QQDRegByOsGD7bAA0XEi23IjWxFACnAjWxFAIH7AAAAAXMci0wkOMFkJCAIO0wkXHOcihH/RCQ4weMIiFQkIInZD7dVAMHpCw+vyjlMJCBzF4nLuQAIAAAp0cHpBWYBTQABwI1sJEDDweoFKUwkICnLZilVAAHAg8ABjWwkQMO4///////gbXN2Y3J0LmRsbHxtYWxsb2MAuP//////4GZyZWUA')) 137 | EndIf 138 | If Not $CodeBase Then Return SetError(1, 0, Binary("")) 139 | EndIf 140 | 141 | $Src = Binary($Src) 142 | Local $SrcLen = BinaryLen($Src) 143 | Local $SrcBuf = DllStructCreate("byte[" & $SrcLen & "]") 144 | DllStructSetData($SrcBuf, 1, $Src) 145 | 146 | Local $Ret = DllCallAddress("ptr:cdecl", $CodeBase, "ptr", DllStructGetPtr($SrcBuf), "uint_ptr", $SrcLen, "uint_ptr*", 0, "uint*", 0) 147 | If $Ret[0] Then 148 | Local $DstBuf = DllStructCreate("byte[" & $Ret[3] & "]", $Ret[0]) 149 | Local $Output = DllStructGetData($DstBuf, 1) 150 | DllCall($__BinaryCall_Msvcrtdll, "none:cdecl", "free", "ptr", $Ret[0]) 151 | 152 | Return $Output 153 | EndIf 154 | Return SetError(2, 0, Binary("")) 155 | EndFunc 156 | 157 | Func _BinaryCall_Relocation($Base, $Reloc) 158 | Local $Size = Int(BinaryMid($Reloc, 1, 2)) 159 | 160 | For $i = 3 To BinaryLen($Reloc) Step $Size 161 | Local $Offset = Int(BinaryMid($Reloc, $i, $Size)) 162 | Local $Ptr = $Base + $Offset 163 | DllStructSetData(DllStructCreate("ptr", $Ptr), 1, DllStructGetData(DllStructCreate("ptr", $Ptr), 1) + $Base) 164 | Next 165 | EndFunc 166 | 167 | Func _BinaryCall_ImportLibrary($Base, $Length) 168 | Local $JmpBin, $JmpOff, $JmpLen, $DllName, $ProcName 169 | If @AutoItX64 Then 170 | $JmpBin = Binary("0x48B8FFFFFFFFFFFFFFFFFFE0") 171 | $JmpOff = 2 172 | Else 173 | $JmpBin = Binary("0xB8FFFFFFFFFFE0") 174 | $JmpOff = 1 175 | EndIf 176 | $JmpLen = BinaryLen($JmpBin) 177 | 178 | Do 179 | Local $Ptr = _BinaryCall_MemorySearch($Base, $Length, $JmpBin) 180 | If $Ptr = 0 Then ExitLoop 181 | 182 | Local $StringPtr = $Ptr + $JmpLen 183 | Local $StringLen = _BinaryCall_lstrlenA($StringPtr) 184 | Local $String = DllStructGetData(DllStructCreate("char[" & $StringLen & "]", $StringPtr), 1) 185 | Local $Split = StringSplit($String, "|") 186 | 187 | If $Split[0] = 1 Then 188 | $ProcName = $Split[1] 189 | ElseIf $Split[0] = 2 Then 190 | If $Split[1] Then $DllName = $Split[1] 191 | $ProcName = $Split[2] 192 | EndIf 193 | 194 | If $DllName And $ProcName Then 195 | Local $Handle = _BinaryCall_LoadLibrary($DllName) 196 | If Not $Handle Then 197 | $__BinaryCall_LastError = "LoadLibrary fail on " & $DllName 198 | Return SetError(1, 0, False) 199 | EndIf 200 | 201 | Local $Proc = _BinaryCall_GetProcAddress($Handle, $ProcName) 202 | If Not $Proc Then 203 | $__BinaryCall_LastError = "GetProcAddress failed on " & $ProcName 204 | Return SetError(2, 0, False) 205 | EndIf 206 | 207 | DllStructSetData(DllStructCreate("ptr", $Ptr + $JmpOff), 1, $Proc) 208 | EndIf 209 | 210 | Local $Diff = Int($Ptr - $Base + $JmpLen + $StringLen + 1) 211 | $Base += $Diff 212 | $Length -= $Diff 213 | 214 | Until $Length <= $JmpLen 215 | Return True 216 | EndFunc 217 | 218 | Func _BinaryCall_CodePrepare($Code) 219 | If Not $Code Then Return "" 220 | If IsBinary($Code) Then Return $Code 221 | 222 | $Code = String($Code) 223 | If StringLeft($Code, 2) = "0x" Then Return Binary($Code) 224 | If StringIsXDigit($Code) Then Return Binary("0x" & $Code) 225 | 226 | Return _BinaryCall_LzmaDecompress(_BinaryCall_Base64Decode($Code)) 227 | EndFunc 228 | 229 | Func _BinaryCall_SymbolFind($CodeBase, $Identify, $Length = Default) 230 | $Identify = Binary($Identify) 231 | 232 | If IsKeyword($Length) Then 233 | $Length = _BinaryCall_RegionSize($CodeBase) 234 | EndIf 235 | 236 | Local $Ptr = _BinaryCall_MemorySearch($CodeBase, $Length, $Identify) 237 | If $Ptr = 0 Then Return SetError(1, 0, 0) 238 | 239 | Return $Ptr + BinaryLen($Identify) 240 | EndFunc 241 | 242 | Func _BinaryCall_SymbolList($CodeBase, $Symbol) 243 | If Not IsArray($Symbol) Or $CodeBase = 0 Then Return SetError(1, 0, 0) 244 | 245 | Local $Tag = "" 246 | For $i = 0 To UBound($Symbol) - 1 247 | $Tag &= "ptr " & $Symbol[$i] & ";" 248 | Next 249 | 250 | Local $SymbolList = DllStructCreate($Tag) 251 | If @Error Then Return SetError(1, 0, 0) 252 | 253 | For $i = 0 To UBound($Symbol) - 1 254 | $CodeBase = _BinaryCall_SymbolFind($CodeBase, $Symbol[$i]) 255 | DllStructSetData($SymbolList, $Symbol[$i], $CodeBase) 256 | Next 257 | Return $SymbolList 258 | EndFunc 259 | 260 | Func _BinaryCall_Create($Code, $Reloc = '', $Padding = 0, $ReleaseOnExit = True, $LibraryImport = True) 261 | Local $BinaryCode = _BinaryCall_CodePrepare($Code) 262 | If Not $BinaryCode Then Return SetError(1, 0, 0) 263 | 264 | Local $BinaryCodeLen = BinaryLen($BinaryCode) 265 | Local $TotalCodeLen = $BinaryCodeLen + $Padding 266 | 267 | Local $CodeBase = _BinaryCall_Alloc($BinaryCode, $Padding) 268 | If Not $CodeBase Then Return SetError(2, 0, 0) 269 | 270 | If $Reloc Then 271 | $Reloc = _BinaryCall_CodePrepare($Reloc) 272 | If Not $Reloc Then Return SetError(3, 0, 0) 273 | _BinaryCall_Relocation($CodeBase, $Reloc) 274 | EndIf 275 | 276 | If $LibraryImport Then 277 | If Not _BinaryCall_ImportLibrary($CodeBase, $BinaryCodeLen) Then 278 | _BinaryCall_Free($CodeBase) 279 | Return SetError(4, 0, 0) 280 | EndIf 281 | EndIf 282 | 283 | If $ReleaseOnExit Then 284 | _BinaryCall_ReleaseOnExit($CodeBase) 285 | EndIf 286 | 287 | Return SetError(0, $TotalCodeLen, $CodeBase) 288 | EndFunc 289 | 290 | Func _BinaryCall_CommandLineToArgv($CommandLine, ByRef $Argc, $IsUnicode = False) 291 | Static $SymbolList 292 | If Not IsDllStruct($SymbolList) Then 293 | Local $Code 294 | If @AutoItX64 Then 295 | $Code = 'AwAAAASuAgAAAAAAAAAkL48ClEB9jTEOeYv4yYTosNjFNgf81Ag4vS2VP4y4wxFa+4yMI7GDB7CG+xn4JE3cdEVvk8cMp4oIuS3DgTxlcKHGVIg94tvzG/256bizZfGtAETQUCPQjW5+JSx2C/Y4C0VNJMKTlSCHiV5AzXRZ5gw3WFghbtkCCFxWOX+RDSI2oH/vROEOnqc0jfKTo17EBjqX+dW3QxrUe45xsbyYTZ9ccIGySgcOAxetbRiSxQnz8BOMbJyfrbZbuVJyGpKrXFLh/5MlBZ09Cim9qgflbGzmkrGStT9QL1f+O2krzyOzgaWWqhWL6S+y0G32RWVi0uMLR/JOGLEW/+Yg/4bzkeC0lKELT+RmWAatNa38BRfaitROMN12moRDHM6LYD1lzPLnaiefSQRVti561sxni/AFkYoCb5Lkuyw4RIn/r/flRiUg5w48YkqBBd9rXkaXrEoKwPg6rmOvOCZadu//B6HN4+Ipq5aYNuZMxSJXmxwXVRSQZVpSfLS2ATZMd9/Y7kLqrKy1H4V76SgI/d9OKApfKSbQ8ZaKIHBCsoluEip3UDOB82Z21zd933UH5l0laGWLIrTz7xVGkecjo0NQzR7LyhhoV3xszlIuw2v8q0Q/S9LxB5G6tYbOXo7lLjNIZc0derZz7DNeeeJ9dQE9hp8unubaTBpulPxTNtRjog==' 296 | Else 297 | $Code = 'AwAAAAR6AgAAAAAAAABcQfD553vjya/3DmalU0BKqABevUb/60GZ55rMwmzpQfPSRUlIl04lEiS8RDrXpS0EoBUe+uzDgZd37nVu9wsJ4fykqYvLoMz3ApxQbTBKleOIRSla6I0V8dNP3P7rHeUfjH0jCho0RvhhVpf0o4ht/iZptauxaoy1zQ19TkPZ/vf5Im8ecY6qEdHNzjo2H60jVwiOJ+1J47TmQRwxJ+yKLakq8QNxtKkRIB9B9ugfo3NAL0QslDxbyU0dSgw2aOPxV+uttLzYNnWbLBZVQbchcKgLRjC/32U3Op576sOYFolB1Nj4/33c7MRgtGLjlZfTB/4yNvd4/E+u3U6/Q4MYApCfWF4R/d9CAdiwgIjCYUkGDExKjFtHbAWXfWh9kQ7Q/GWUjsfF9BtHO6924Cy1Ou+BUKksqsxmIKP4dBjvvmz9OHc1FdtR9I63XKyYtlUnqVRtKwlNrYAZVCSFsyAefMbteq1ihU33sCsLkAnp1LRZ2wofgT1/JtT8+GO2s/n52D18wM70RH2n5uJJv8tlxQc1lwbmo4XQvcbcE91U2j9glvt2wC1pkP0hF23Nr/iiIEZHIPAOAHvhervlHE830LSHyUx8yh5Tjojr0gdLvQ==' 298 | EndIf 299 | Local $CodeBase = _BinaryCall_Create($Code) 300 | If @Error Then Return SetError(1, 0, 0) 301 | 302 | Local $Symbol[] = ["ToArgvW","ToArgvA"] 303 | $SymbolList = _BinaryCall_SymbolList($CodeBase, $Symbol) 304 | If @Error Then Return SetError(1, 0, 0) 305 | EndIf 306 | 307 | Local $Ret 308 | If $IsUnicode Then 309 | $Ret = DllCallAddress("ptr:cdecl", DllStructGetData($SymbolList, "ToArgvW"), "wstr", $CommandLine, "int*", 0) 310 | Else 311 | $Ret = DllCallAddress("ptr:cdecl", DllStructGetData($SymbolList, "ToArgvA"), "str", $CommandLine, "int*", 0) 312 | EndIf 313 | 314 | If Not @Error And $Ret[0] <> 0 Then 315 | _BinaryCall_ReleaseOnExit($Ret[0]) 316 | $Argc = $Ret[2] 317 | Return $Ret[0] 318 | Else 319 | Return SetError(2, 0, 0) 320 | EndIf 321 | EndFunc 322 | 323 | Func _BinaryCall_StdioRedirect($Filename = "CON", $Flag = 1 + 2 + 4) 324 | Static $SymbolList 325 | If Not IsDllStruct($SymbolList) Then 326 | Local $Code, $Reloc 327 | If @AutoItX64 Then 328 | $Code = 'AwAAAASjAQAAAAAAAAAkL48ClEB9jTEOeYv4yYTosNjFM1rLNdMULriZUDxTj+ZdkQ01F5zKL+WDCScfQKKLn66EDmcA+gXIkPcZV4lyz8VPw8BPZlNB5KymydM15kCA+uqvmBc1V0NJfzgsF0Amhn0JhM/ZIguYCHxywMQ1SgKxUb05dxDg8WlX/2aPfSolcX47+4/72lPDNTeT7d7XRdm0ND+eCauuQcRH2YOahare9ASxuU4IMHCh2rbZYHwmTNRiQUB/8dLGtph93yhmwdHtyMPLX2x5n6sdA1mxua9htLsLTulE05LLmXbRYXylDz0A' 329 | $Reloc = 'AwAAAAQIAAAAAAAAAAABAB7T+CzGn9ScQAC=' 330 | Else 331 | $Code = 'AwAAAASVAQAAAAAAAABcQfD553vjya/3DmalU0BKqABaUcndypZ3mTYUkHxlLV/lKZPrXYWXgNATjyiowkUQGDVYUy5THQwK4zYdU7xuGf7qfVDELc1SNbiW3NgD4D6N6ZM7auI1jPaThsPfA/ouBcx2aVQX36fjmViTZ8ZLzafjJeR7d5OG5s9sAoIzFLTZsqrFlkIJedqDAOfhA/0mMrkavTWnsio6yTbic1dER0DcEsXpLn0vBNErKHoagLzAgofHNLeFRw5yHWz5owR5CYL7rgiv2k51neHBWGx97A==' 332 | $Reloc = 'AwAAAAQgAAAAAAAAAAABABfyHS/VRkdjBBzbtGPD6vtmVH/IsGHYvPsTv2lGuqJxGlAA' 333 | EndIf 334 | 335 | Local $CodeBase = _BinaryCall_Create($Code, $Reloc) 336 | If @Error Then Return SetError(1, 0, 0) 337 | 338 | Local $Symbol[] = ["StdinRedirect","StdoutRedirect","StderrRedirect"] 339 | $SymbolList = _BinaryCall_SymbolList($CodeBase, $Symbol) 340 | If @Error Then Return SetError(1, 0, 0) 341 | EndIf 342 | 343 | If BitAND($Flag, 1) Then DllCallAddress("none:cdecl", DllStructGetData($SymbolList, "StdinRedirect"), "str", $Filename) 344 | If BitAND($Flag, 2) Then DllCallAddress("none:cdecl", DllStructGetData($SymbolList, "StdoutRedirect"), "str", $Filename) 345 | If BitAND($Flag, 4) Then DllCallAddress("none:cdecl", DllStructGetData($SymbolList, "StderrRedirect"), "str", $Filename) 346 | EndFunc 347 | 348 | Func _BinaryCall_StdinRedirect($Filename = "CON") 349 | Local $Ret = _BinaryCall_StdioRedirect($Filename, 1) 350 | Return SetError(@Error, @Extended, $Ret) 351 | EndFunc 352 | 353 | Func _BinaryCall_StdoutRedirect($Filename = "CON") 354 | Local $Ret = _BinaryCall_StdioRedirect($Filename, 2) 355 | Return SetError(@Error, @Extended, $Ret) 356 | EndFunc 357 | 358 | Func _BinaryCall_StderrRedirect($Filename = "CON") 359 | Local $Ret = _BinaryCall_StdioRedirect($Filename, 4) 360 | Return SetError(@Error, @Extended, $Ret) 361 | EndFunc 362 | 363 | Func _BinaryCall_ReleaseOnExit($Ptr) 364 | OnAutoItExitRegister('__BinaryCall_DoRelease') 365 | __BinaryCall_ReleaseOnExit_Handle($Ptr) 366 | EndFunc 367 | 368 | Func __BinaryCall_DoRelease() 369 | __BinaryCall_ReleaseOnExit_Handle() 370 | EndFunc 371 | 372 | Func __BinaryCall_ReleaseOnExit_Handle($Ptr = Default) 373 | Static $PtrList 374 | 375 | If @NumParams = 0 Then 376 | If IsArray($PtrList) Then 377 | For $i = 1 To $PtrList[0] 378 | _BinaryCall_Free($PtrList[$i]) 379 | Next 380 | EndIf 381 | Else 382 | If Not IsArray($PtrList) Then 383 | Local $InitArray[1] = [0] 384 | $PtrList = $InitArray 385 | EndIf 386 | 387 | If IsPtr($Ptr) Then 388 | Local $Array = $PtrList 389 | Local $Size = UBound($Array) 390 | ReDim $Array[$Size + 1] 391 | $Array[$Size] = $Ptr 392 | $Array[0] += 1 393 | $PtrList = $Array 394 | EndIf 395 | EndIf 396 | EndFunc 397 | -------------------------------------------------------------------------------- /client/include/JSON.au3: -------------------------------------------------------------------------------- 1 | ; ============================================================================================================================ 2 | ; File : Json.au3 (2015.01.08) 3 | ; Purpose : A Non-Strict JavaScript Object Notation (JSON) Parser UDF 4 | ; Author : Ward 5 | ; Dependency: BinaryCall.au3 6 | ; Website : http://www.json.org/index.html 7 | ; 8 | ; Source : jsmn.c 9 | ; Author : zserge 10 | ; Website : http://zserge.com/jsmn.html 11 | ; 12 | ; Source : json_string_encode.c, json_string_decode.c 13 | ; Author : Ward 14 | ; ============================================================================================================================ 15 | 16 | ; ============================================================================================================================ 17 | ; Public Functions: 18 | ; Json_StringEncode($String, $Option = 0) 19 | ; Json_StringDecode($String) 20 | ; Json_IsObject(ByRef $Object) 21 | ; Json_IsNull(ByRef $Null) 22 | ; Json_Encode($Data, $Option = 0, $Indent = Default, $ArraySep = Default, $ObjectSep = Default, $ColonSep = Default) 23 | ; Json_Decode($Json, $InitTokenCount = 1000) 24 | ; Json_ObjCreate() 25 | ; Json_ObjPut(ByRef $Object, $Key, $Value) 26 | ; Json_ObjGet(ByRef $Object, $Key) 27 | ; Json_ObjDelete(ByRef $Object, $Key) 28 | ; Json_ObjExists(ByRef $Object, $Key) 29 | ; Json_ObjGetCount(ByRef $Object) 30 | ; Json_ObjGetKeys(ByRef $Object) 31 | ; Json_ObjClear(ByRef $Object) 32 | ; Json_Put(ByRef $Var, $Notation, $Data, $CheckExists = False) 33 | ; Json_Get(ByRef $Var, $Notation) 34 | ; ============================================================================================================================ 35 | 36 | #Include-once 37 | #Include 38 | 39 | ; The following constants can be combined to form options for Json_Encode() 40 | Global Const $JSON_UNESCAPED_UNICODE = 1 ; Encode multibyte Unicode characters literally 41 | Global Const $JSON_UNESCAPED_SLASHES = 2 ; Don't escape / 42 | Global Const $JSON_HEX_TAG = 4 ; All < and > are converted to \u003C and \u003E 43 | Global Const $JSON_HEX_AMP = 8 ; All &s are converted to \u0026 44 | Global Const $JSON_HEX_APOS = 16 ; All ' are converted to \u0027 45 | Global Const $JSON_HEX_QUOT = 32 ; All " are converted to \u0022 46 | Global Const $JSON_UNESCAPED_ASCII = 64 ; Don't escape ascii charcters between chr(1) ~ chr(0x1f) 47 | Global Const $JSON_PRETTY_PRINT = 128 ; Use whitespace in returned data to format it 48 | Global Const $JSON_STRICT_PRINT = 256 ; Make sure returned JSON string is RFC4627 compliant 49 | Global Const $JSON_UNQUOTED_STRING = 512 ; Output unquoted string if possible (conflicting with $Json_STRICT_PRINT) 50 | 51 | ; Error value returnd by Json_Decode() 52 | Global Const $JSMN_ERROR_NOMEM = -1 ; Not enough tokens were provided 53 | Global Const $JSMN_ERROR_INVAL = -2 ; Invalid character inside JSON string 54 | Global Const $JSMN_ERROR_PART = -3 ; The string is not a full JSON packet, more bytes expected 55 | 56 | Func __Jsmn_RuntimeLoader($ProcName = "") 57 | Static $SymbolList 58 | If Not IsDllStruct($SymbolList) Then 59 | Local $Code 60 | If @AutoItX64 Then 61 | $Code = 'AwAAAAQfCAAAAAAAAAA1HbEvgTNrvX54gCiWSTVmt5v7RCdoFJ/zhkKmwcm8yVqZPjJBoVhNHHAIzrHWKbZh1J0QAUaHB5zyQTilTmWa9O0OKeLrk/Jg+o7CmMzjEk74uPongdHv37nwYXvg97fiHvjP2bBzI9gxSkKq9Cqh/GxSHIlZPYyW76pXUt//25Aqs2Icfpyay/NFd50rW7eMliH5ynkrp16HM1afithVrO+LpSaz/IojowApmXnBHUncHliDqbkx6/AODUkyDm1hj+AiEZ9Me1Jy+hBQ1/wC/YnuuYSJvNAKp6XDnyc8Nwr54Uqx5SbUW2CezwQQ7aXX/HFiHSKpQcFW/gi8oSx5nsoxUXVjxeNI/L7z6GF2mfu3Tnpt7hliWEdA2r2VB+TIM7Pgwl9X3Ge0T3KJQUaRtLJZcPvVtOuKXr2Q9wy7hl80hVRrt9zYrbjBHXLrRx/HeIMkZwxhmKo/dD/vvaNgE+BdU8eeJqFBJK2alrK2rh2WkRynftyepm1WrdKrz/5KhQPp/4PqH+9IADDjoGBbfvJQXdT+yiO8DtfrVnd+JOEKsKEsdgeM3UXx5r6tEHO9rYWbzbnyEi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/uGfHFAzjF8DUY1vqJCgn0GQ8ANtiiElX/+Wnc9HWi2bEEXItbm4yv97QrEPvJG9nPRBKWGiAQsIA5J+WryX5NrfEfRPk0QQwyl16lpHlw6l0UMuk7S21xjQgyWo0MywfzoBWW7+t4HH9sqavvP4dYAw81BxXqVHQhefUOS23en4bFUPWE98pAN6bul+kS767vDK34yTC3lA2a8wLrBEilmFhdB74fxbAl+db91PivhwF/CR4Igxr35uLdof7+jAYyACopQzmsbHpvAAwT2lapLix8H03nztAC3fBqFSPBVdIv12lsrrDw4dfhJEzq7AbL/Y7L/nIcBsQ/3UyVnZk4kZP1KzyPCBLLIQNpCVgOLJzQuyaQ6k2QCBy0eJ0ppUyfp54LjwVg0X7bwncYbAomG4ZcFwTQnC2AX3oYG5n6Bz4SLLjxrFsY+v/SVa+GqH8uePBh1TPkHVNmzjXXymEf5jROlnd+EjfQdRyitkjPrg2HiQxxDcVhCh5J2L5+6CY9eIaYgrbd8zJnzAD8KnowHwh2bi4JLgmt7ktJ1XGizox7cWf3/Dod56KAcaIrSVw9XzYybdJCf0YRA6yrwPWXbwnzc/4+UDkmegi+AoCEMoue+cC7vnYVdmlbq/YLE/DWJX383oz2Ryq8anFrZ8jYvdoh8WI+dIugYL2SwRjmBoSwn56XIaot/QpMo3pYJIa4o8aZIZrjvB7BXO5aCDeMuZdUMT6AXGAGF1AeAWxFd2XIo1coR+OplMNDuYia8YAtnSTJ9JwGYWi2dJz3xrxsTQpBONf3yn8LVf8eH+o5eXc7lzCtHlDB+YyI8V9PyMsUPOeyvpB3rr9fDfNy263Zx33zTi5jldgP2OetUqGfbwl+0+zNYnrg64bluyIN/Awt1doDCQkCKpKXxuPaem/SyCHrKjg' 64 | EndIf 65 | 66 | Local $Symbol[] = ["jsmn_parse","jsmn_init","json_string_decode","json_string_encode"] 67 | Local $CodeBase = _BinaryCall_Create($Code) 68 | If @Error Then Exit MsgBox(16, "Json", "Startup Failure!") 69 | 70 | $SymbolList = _BinaryCall_SymbolList($CodeBase, $Symbol) 71 | If @Error Then Exit MsgBox(16, "Json", "Startup Failure!") 72 | EndIf 73 | If $ProcName Then Return DllStructGetData($SymbolList, $ProcName) 74 | EndFunc 75 | 76 | Func Json_StringEncode($String, $Option = 0) 77 | Static $Json_StringEncode = __Jsmn_RuntimeLoader("json_string_encode") 78 | Local $Length = StringLen($String) * 6 + 1 79 | Local $Buffer = DllStructCreate("wchar[" & $Length & "]") 80 | Local $Ret = DllCallAddress("int:cdecl", $Json_StringEncode, "wstr", $String, "ptr", DllStructGetPtr($Buffer), "uint", $Length, "int", $Option) 81 | Return SetError($Ret[0], 0, DllStructGetData($Buffer, 1)) 82 | EndFunc 83 | 84 | Func Json_StringDecode($String) 85 | Static $Json_StringDecode = __Jsmn_RuntimeLoader("json_string_decode") 86 | Local $Length = StringLen($String) + 1 87 | Local $Buffer = DllStructCreate("wchar[" & $Length & "]") 88 | Local $Ret = DllCallAddress("int:cdecl", $Json_StringDecode, "wstr", $String, "ptr", DllStructGetPtr($Buffer), "uint", $Length) 89 | Return SetError($Ret[0], 0, DllStructGetData($Buffer, 1)) 90 | EndFunc 91 | 92 | Func Json_Decode($Json, $InitTokenCount = 1000) 93 | Static $Jsmn_Init = __Jsmn_RuntimeLoader("jsmn_init"), $Jsmn_Parse = __Jsmn_RuntimeLoader("jsmn_parse") 94 | If $Json = "" Then $Json = '""' 95 | Local $TokenList, $Ret 96 | Local $Parser = DllStructCreate("uint pos;int toknext;int toksuper") 97 | Do 98 | DllCallAddress("none:cdecl", $Jsmn_Init, "ptr", DllStructGetPtr($Parser)) 99 | $TokenList = DllStructCreate("byte[" & ($InitTokenCount * 20) & "]") 100 | $Ret = DllCallAddress("int:cdecl", $Jsmn_Parse, "ptr", DllStructGetPtr($Parser), "wstr", $Json, "ptr", DllStructGetPtr($TokenList), "uint", $InitTokenCount) 101 | $InitTokenCount *= 2 102 | Until $Ret[0] <> $JSMN_ERROR_NOMEM 103 | 104 | Local $Next = 0 105 | Return SetError($Ret[0], 0, _Json_Token($Json, DllStructGetPtr($TokenList), $Next)) 106 | EndFunc 107 | 108 | Func _Json_Token(ByRef $Json, $Ptr, ByRef $Next) 109 | If $Next = -1 Then Return Null 110 | 111 | Local $Token = DllStructCreate("int;int;int;int", $Ptr + ($Next * 20)) 112 | Local $Type = DllStructGetData($Token, 1) 113 | Local $Start = DllStructGetData($Token, 2) 114 | Local $End = DllStructGetData($Token, 3) 115 | Local $Size = DllStructGetData($Token, 4) 116 | $Next += 1 117 | 118 | If $Type = 0 And $Start = 0 And $End = 0 And $Size = 0 Then ; Null Item 119 | $Next = -1 120 | Return Null 121 | EndIf 122 | 123 | Switch $Type 124 | Case 0 ; Json_PRIMITIVE 125 | Local $Primitive = StringMid($Json, $Start + 1, $End - $Start) 126 | Switch $Primitive 127 | Case "true" 128 | Return True 129 | Case "false" 130 | Return False 131 | Case "null" 132 | Return Null 133 | Case Else 134 | If StringRegExp($Primitive, "^[+\-0-9]") Then 135 | Return Number($Primitive) 136 | Else 137 | Return Json_StringDecode($Primitive) 138 | EndIf 139 | EndSwitch 140 | 141 | Case 1 ; Json_OBJECT 142 | Local $Object = Json_ObjCreate() 143 | For $i = 0 To $Size - 1 Step 2 144 | Local $Key = _Json_Token($Json, $Ptr, $Next) 145 | Local $Value = _Json_Token($Json, $Ptr, $Next) 146 | If Not IsString($Key) Then $Key = Json_Encode($Key) 147 | 148 | If $Object.Exists($Key) Then $Object.Remove($Key) 149 | $Object.Add($Key, $Value) 150 | Next 151 | Return $Object 152 | 153 | Case 2 ; Json_ARRAY 154 | Local $Array[$Size] 155 | For $i = 0 To $Size - 1 156 | $Array[$i] = _Json_Token($Json, $Ptr, $Next) 157 | Next 158 | Return $Array 159 | 160 | Case 3 ; Json_STRING 161 | Return Json_StringDecode(StringMid($Json, $Start + 1, $End - $Start)) 162 | EndSwitch 163 | EndFunc 164 | 165 | Func Json_IsObject(ByRef $Object) 166 | Return (IsObj($Object) And ObjName($Object) = "Dictionary") 167 | EndFunc 168 | 169 | Func Json_IsNull(ByRef $Null) 170 | Return IsKeyword($Null) Or (Not IsObj($Null) And VarGetType($Null) = "Object") 171 | EndFunc 172 | 173 | Func Json_Encode_Compact($Data, $Option = 0) 174 | Select 175 | Case IsString($Data) 176 | Return '"' & Json_StringEncode($Data, $Option) & '"' 177 | 178 | Case IsNumber($Data) 179 | Return $Data 180 | 181 | Case IsArray($Data) And UBound($Data, 0) = 1 182 | Local $Json = "[" 183 | For $i = 0 To UBound($Data) - 1 184 | $Json &= Json_Encode_Compact($Data[$i], $Option) & "," 185 | Next 186 | If StringRight($Json, 1) = "," Then $Json = StringTrimRight($Json, 1) 187 | Return $Json & "]" 188 | 189 | Case Json_IsObject($Data) 190 | Local $Json = "{" 191 | Local $Keys = $Data.Keys() 192 | For $i = 0 To UBound($Keys) - 1 193 | $Json &= '"' & Json_StringEncode($Keys[$i], $Option) & '":' & Json_Encode_Compact($Data.Item($Keys[$i]), $Option) & "," 194 | Next 195 | If StringRight($Json, 1) = "," Then $Json = StringTrimRight($Json, 1) 196 | Return $Json & "}" 197 | 198 | Case IsBool($Data) 199 | Return StringLower($Data) 200 | 201 | Case IsPtr($Data) 202 | Return Number($Data) 203 | 204 | Case IsBinary($Data) 205 | Return '"' & Json_StringEncode(BinaryToString($Data, 4), $Option) & '"' 206 | 207 | Case Else ; Keyword, DllStruct, Object 208 | Return "null" 209 | EndSelect 210 | EndFunc 211 | 212 | Func Json_Encode_Pretty($Data, $Option, $Indent, $ArraySep, $ObjectSep, $ColonSep, $ArrayCRLF = Default, $ObjectCRLF = Default, $NextIdent = "") 213 | Local $ThisIdent = $NextIdent, $Json = "" 214 | Select 215 | Case IsString($Data) 216 | Local $String = Json_StringEncode($Data, $Option) 217 | If BitAND($Option, $Json_UNQUOTED_STRING) And Not BitAND($Option, $Json_STRICT_PRINT) And Not StringRegExp($String, "[\s,:]") And Not StringRegExp($String, "^[+\-0-9]") Then 218 | Return $String 219 | Else 220 | Return '"' & $String & '"' 221 | EndIf 222 | 223 | Case IsArray($Data) And UBound($Data, 0) = 1 224 | If UBound($Data) = 0 Then Return "[]" 225 | If IsKeyword($ArrayCRLF) Then 226 | $ArrayCRLF = "" 227 | Local $Match = StringRegExp($ArraySep, "[\r\n]+$", 3) 228 | If IsArray($Match) Then $ArrayCRLF = $Match[0] 229 | EndIf 230 | 231 | If $ArrayCRLF Then $NextIdent &= $Indent 232 | Local $Length = UBound($Data) - 1 233 | For $i = 0 To $Length 234 | If $ArrayCRLF Then $Json &= $NextIdent 235 | $Json &= Json_Encode_Pretty($Data[$i], $Option, $Indent, $ArraySep, $ObjectSep, $ColonSep, $ArrayCRLF, $ObjectCRLF, $NextIdent) 236 | If $i < $Length Then $Json &= $ArraySep 237 | Next 238 | 239 | If $ArrayCRLF Then Return "[" & $ArrayCRLF & $Json & $ArrayCRLF & $ThisIdent & "]" 240 | Return "[" & $Json & "]" 241 | 242 | Case Json_IsObject($Data) 243 | If $Data.Count = 0 Then Return "{}" 244 | If IsKeyword($ObjectCRLF) Then 245 | $ObjectCRLF = "" 246 | Local $Match = StringRegExp($ObjectSep, "[\r\n]+$", 3) 247 | If IsArray($Match) Then $ObjectCRLF = $Match[0] 248 | EndIf 249 | 250 | If $ObjectCRLF Then $NextIdent &= $Indent 251 | Local $Keys = $Data.Keys() 252 | Local $Length = UBound($Keys) - 1 253 | For $i = 0 To $Length 254 | If $ObjectCRLF Then $Json &= $NextIdent 255 | $Json &= Json_Encode_Pretty(String($Keys[$i]), $Option, $Indent, $ArraySep, $ObjectSep, $ColonSep) & $ColonSep _ 256 | & Json_Encode_Pretty($Data.Item($Keys[$i]), $Option, $Indent, $ArraySep, $ObjectSep, $ColonSep, $ArrayCRLF, $ObjectCRLF, $NextIdent) 257 | If $i < $Length Then $Json &= $ObjectSep 258 | Next 259 | 260 | If $ObjectCRLF Then Return "{" & $ObjectCRLF & $Json & $ObjectCRLF & $ThisIdent & "}" 261 | Return "{" & $Json & "}" 262 | 263 | Case Else 264 | Return Json_Encode_Compact($Data, $Option) 265 | 266 | EndSelect 267 | EndFunc 268 | 269 | Func Json_Encode($Data, $Option = 0, $Indent = Default, $ArraySep = Default, $ObjectSep = Default, $ColonSep = Default) 270 | If BitAND($Option, $Json_PRETTY_PRINT) Then 271 | Local $Strict = BitAND($Option, $Json_STRICT_PRINT) 272 | 273 | If IsKeyword($Indent) Then 274 | $Indent = @Tab 275 | Else 276 | $Indent = Json_StringDecode($Indent) 277 | If StringRegExp($Indent, "[^\t ]") Then $Indent = @Tab 278 | EndIf 279 | 280 | If IsKeyword($ArraySep) Then 281 | $ArraySep = "," & @CRLF 282 | Else 283 | $ArraySep = Json_StringDecode($ArraySep) 284 | If $ArraySep = "" Or StringRegExp($ArraySep, "[^\s,]|,.*,") Or ($Strict And Not StringRegExp($ArraySep, ",")) Then $ArraySep = "," & @CRLF 285 | EndIf 286 | 287 | If IsKeyword($ObjectSep) Then 288 | $ObjectSep = "," & @CRLF 289 | Else 290 | $ObjectSep = Json_StringDecode($ObjectSep) 291 | If $ObjectSep = "" Or StringRegExp($ObjectSep, "[^\s,]|,.*,") Or ($Strict And Not StringRegExp($ObjectSep, ",")) Then $ObjectSep = "," & @CRLF 292 | EndIf 293 | 294 | If IsKeyword($ColonSep) Then 295 | $ColonSep = ": " 296 | Else 297 | $ColonSep = Json_StringDecode($ColonSep) 298 | If $ColonSep = "" Or StringRegExp($ColonSep, "[^\s,:]|[,:].*[,:]") Or ($Strict And (StringRegExp($ColonSep, ",") Or Not StringRegExp($ColonSep, ":"))) Then $ColonSep = ": " 299 | EndIf 300 | 301 | Return Json_Encode_Pretty($Data, $Option, $Indent, $ArraySep, $ObjectSep, $ColonSep) 302 | 303 | ElseIf BitAND($Option, $Json_UNQUOTED_STRING) Then 304 | Return Json_Encode_Pretty($Data, $Option, "", ",", ",", ":") 305 | Else 306 | Return Json_Encode_Compact($Data, $Option) 307 | EndIf 308 | EndFunc 309 | 310 | Func Json_ObjCreate() 311 | Local $Object = ObjCreate('Scripting.Dictionary') 312 | $Object.CompareMode = 0 313 | Return $Object 314 | EndFunc 315 | 316 | Func Json_ObjPut(ByRef $Object, $Key, $Value) 317 | $Key = String($Key) 318 | If $Object.Exists($Key) Then $Object.Remove($Key) 319 | $Object.Add($Key, $Value) 320 | EndFunc 321 | 322 | Func Json_ObjGet(ByRef $Object, $Key) 323 | $Key = String($Key) 324 | If $Object.Exists($Key) Then Return $Object.Item($Key) 325 | Return SetError(1, 0, '') 326 | EndFunc 327 | 328 | Func Json_ObjDelete(ByRef $Object, $Key) 329 | $Key = String($Key) 330 | If $Object.Exists($Key) Then $Object.Remove($Key) 331 | EndFunc 332 | 333 | Func Json_ObjExists(ByRef $Object, $Key) 334 | Return $Object.Exists(String($Key)) 335 | EndFunc 336 | 337 | Func Json_ObjGetCount(ByRef $Object) 338 | Return $Object.Count 339 | EndFunc 340 | 341 | Func Json_ObjGetKeys(ByRef $Object) 342 | Return $Object.Keys() 343 | EndFunc 344 | 345 | Func Json_ObjClear(ByRef $Object) 346 | Return $Object.RemoveAll() 347 | EndFunc 348 | 349 | ; Both dot notation and square bracket notation can be supported 350 | Func Json_Put(ByRef $Var, $Notation, $Data, $CheckExists = False) 351 | Local $Match = StringRegExp($Notation, "(^\[([^\]]+)\])|(^\.([^\.\[]+))", 3) 352 | If IsArray($Match) Then 353 | Local $Index 354 | If UBound($Match) = 4 Then 355 | $Index = String(Json_Decode($Match[3])) ; only string using dot notation 356 | $Notation = StringTrimLeft($Notation, StringLen($Match[2])) 357 | Else 358 | $Index = Json_Decode($Match[1]) 359 | $Notation = StringTrimLeft($Notation, StringLen($Match[0])) 360 | EndIf 361 | 362 | If IsString($Index) Then 363 | If $CheckExists And (Not Json_IsObject($Var) Or Not Json_ObjExists($Var, $Index)) Then 364 | Return SetError(1, 0, False) ; no specific object 365 | EndIf 366 | 367 | If Not Json_IsObject($Var) Then $Var = Json_ObjCreate() 368 | If $Notation Then 369 | Local $Item = Json_ObjGet($Var, $Index) 370 | Local $Ret = Json_Put($Item, $Notation, $Data, $CheckExists) 371 | Local $Error = @Error 372 | If Not $Error Then Json_ObjPut($Var, $Index, $Item) 373 | Return SetError($Error, 0, $Ret) 374 | Else 375 | Json_ObjPut($Var, $Index, $Data) 376 | Return True 377 | EndIf 378 | 379 | ElseIf IsInt($Index) Then 380 | If $Index < 0 Or ($CheckExists And (Not IsArray($Var) Or UBound($Var, 0) <> 1 Or $Index >= UBound($Var))) Then 381 | Return SetError(1, 0, False) ; no specific object 382 | EndIf 383 | 384 | If Not IsArray($Var) Or UBound($Var, 0) <> 1 Then 385 | Dim $Var[$Index + 1] 386 | ElseIf $Index >= UBound($Var) Then 387 | ReDim $Var[$Index + 1] 388 | EndIf 389 | 390 | If $Notation Then 391 | Local $Ret = Json_Put($Var[$Index], $Notation, $Data, $CheckExists) 392 | Return SetError(@Error, 0, $Ret) 393 | Else 394 | $Var[$Index] = $Data 395 | Return True 396 | EndIf 397 | 398 | EndIf 399 | EndIf 400 | Return SetError(2, 0, False) ; invalid notation 401 | EndFunc 402 | 403 | ; Both dot notation and square bracket notation can be supported 404 | Func Json_Get(ByRef $Var, $Notation) 405 | Local $Match = StringRegExp($Notation, "(^\[([^\]]+)\])|(^\.([^\.\[]+))", 3) 406 | If IsArray($Match) Then 407 | Local $Index 408 | If UBound($Match) = 4 Then 409 | $Index = String(Json_Decode($Match[3])) ; only string using dot notation 410 | $Notation = StringTrimLeft($Notation, StringLen($Match[2])) 411 | Else 412 | $Index = Json_Decode($Match[1]) 413 | $Notation = StringTrimLeft($Notation, StringLen($Match[0])) 414 | EndIf 415 | 416 | Local $Item 417 | If IsString($Index) And Json_IsObject($Var) And Json_ObjExists($Var, $Index) Then 418 | $Item = Json_ObjGet($Var, $Index) 419 | ElseIf IsInt($Index) And IsArray($Var) And UBound($Var, 0) = 1 And $Index >= 0 And $Index < UBound($Var) Then 420 | $Item = $Var[$Index] 421 | Else 422 | Return SetError(1, 0, "") ; no specific object 423 | EndIf 424 | 425 | If Not $Notation Then Return $Item 426 | Local $Ret = Json_Get($Item, $Notation) 427 | Return SetError(@Error, 0, $Ret) 428 | EndIf 429 | Return SetError(2, 0, "") ; invalid notation 430 | EndFunc 431 | -------------------------------------------------------------------------------- /server/download.php: -------------------------------------------------------------------------------- 1 | ', ':', '"', '/', '\\', '|', '?', '*'); 28 | return str_replace($filter, '', $fileName); 29 | } 30 | 31 | if (isset($_GET['channel'], $_GET['version'], $_GET['file']) && ! empty($_GET['file'])) { 32 | $channel = strtolower($_GET['channel']); 33 | if (in_array($channel, array('stable', 'beta')) && ! empty($_GET['version'])) { 34 | $slash = DIRECTORY_SEPARATOR; 35 | 36 | // download.php?channel=stable&version=1.0.0&file=setup.exe 37 | $path = __DIR__ . $slash . 'files' . $slash . $channel . $slash . $_GET['version'] . $slash . filter($_GET['file']); 38 | downloadFile($path); 39 | } 40 | } 41 | 42 | exit('error'); 43 | -------------------------------------------------------------------------------- /server/index.php: -------------------------------------------------------------------------------- 1 |
PASSWORD:
'; 23 | exit; 24 | } 25 | 26 | // must be in UTF-8 or `basename` doesn't work 27 | setlocale(LC_ALL,'en_US.UTF-8'); 28 | 29 | if (isset($_REQUEST['file'])) { 30 | $tmp = realpath($_REQUEST['file']); 31 | if($tmp === false) 32 | err(404,'File or Directory Not Found'); 33 | if(substr($tmp, 0,strlen(__DIR__)) !== __DIR__) 34 | err(403,'Forbidden'); 35 | } 36 | 37 | if( ! $_COOKIE['_sfm_xsrf']) 38 | setcookie('_sfm_xsrf',bin2hex(openssl_random_pseudo_bytes(16))); 39 | 40 | if($_POST) { 41 | if($_COOKIE['_sfm_xsrf'] !== $_POST['xsrf'] || !$_POST['xsrf']) 42 | err(403,'XSRF Failure'); 43 | } 44 | 45 | function showable($file) { 46 | return ( ! in_array($file, array(basename(__FILE__), 'download.php', 'version.php'))); 47 | } 48 | 49 | if (isset($_GET['do']) OR isset($_POST['do'])) { 50 | $file = $_REQUEST['file'] ?: '.'; 51 | $action = (isset($_GET['do'])) ? $_GET['do'] : $_POST['do']; 52 | $action = strtolower($action); 53 | 54 | switch ($action) { 55 | case 'logout': 56 | session_destroy(); 57 | header('Location: ?'); 58 | exit; 59 | 60 | case 'list': 61 | if (is_dir($file)) { 62 | $directory = $file; 63 | $result = array(); 64 | $files = array_diff(scandir($directory), array('.','..')); 65 | foreach($files as $entry) if (showable($entry)) { 66 | $i = $directory . '/' . $entry; 67 | $stat = stat($i); 68 | $result[] = array( 69 | 'mtime' => $stat['mtime'], 70 | 'size' => $stat['size'], 71 | 'name' => basename($i), 72 | 'path' => preg_replace('@^\./@', '', $i), 73 | 'is_dir' => is_dir($i), 74 | 'is_deleteable' => $allow_delete && ((!is_dir($i) && is_writable($directory)) || 75 | (is_dir($i) && is_writable($directory) && is_recursively_deleteable($i))), 76 | 77 | 78 | 'is_readable' => is_readable($i), 79 | 'is_writable' => is_writable($i), 80 | 'is_executable' => is_executable($i), 81 | ); 82 | } 83 | } else { 84 | err(412,'Not a Directory'); 85 | } 86 | header('Content-Type: application/json'); 87 | echo json_encode(array('success' => true, 'is_writable' => is_writable($file), 'results' =>$result)); 88 | exit; 89 | 90 | case 'delete': 91 | if($allow_delete) { 92 | rmrf($file); 93 | header('Content-Type: application/json'); 94 | echo json_encode(array('success' => true)); 95 | } 96 | exit; 97 | 98 | case 'mkdir': 99 | // don't allow actions outside root. we also filter out slashes to catch args like './../outside' 100 | $dir = $_POST['name']; 101 | $dir = str_replace('/', '', $dir); 102 | if(substr($dir, 0, 2) === '..') 103 | exit; 104 | chdir($file); 105 | @mkdir($_POST['name']); 106 | header('Content-Type: application/json'); 107 | echo json_encode(array('success' => true)); 108 | exit; 109 | 110 | case 'upload': 111 | var_dump($_POST); 112 | var_dump($_FILES); 113 | var_dump($_FILES['file_data']['tmp_name']); 114 | var_dump(move_uploaded_file($_FILES['file_data']['tmp_name'], $file.'/'.$_FILES['file_data']['name'])); 115 | exit; 116 | 117 | case 'download': 118 | $filename = basename($file); 119 | header('Content-Type: ' . mime_content_type($file)); 120 | header('Content-Length: '. filesize($file)); 121 | header(sprintf('Content-Disposition: attachment; filename=%s', 122 | strpos('MSIE',$_SERVER['HTTP_REFERER']) ? rawurlencode($filename) : "\"$filename\"" )); 123 | ob_flush(); 124 | readfile($file); 125 | exit; 126 | } 127 | } 128 | 129 | function rmrf($dir) { 130 | if(is_dir($dir)) { 131 | $files = array_diff(scandir($dir), array('.','..')); 132 | foreach ($files as $file) 133 | rmrf("$dir/$file"); 134 | rmdir($dir); 135 | } else { 136 | unlink($dir); 137 | } 138 | } 139 | 140 | function is_recursively_deleteable($d) { 141 | $stack = array($d); 142 | while($dir = array_pop($stack)) { 143 | if(!is_readable($dir) || !is_writable($dir)) 144 | return false; 145 | $files = array_diff(scandir($dir), array('.','..')); 146 | foreach($files as $file) if(is_dir($file)) { 147 | $stack[] = "$dir/$file"; 148 | } 149 | } 150 | return true; 151 | } 152 | 153 | function err($code,$msg) { 154 | header('Content-Type: application/json'); 155 | echo json_encode(array('error' => array('code'=>intval($code), 'msg' => $msg))); 156 | exit; 157 | } 158 | 159 | function asBytes($ini_v) { 160 | $ini_v = trim($ini_v); 161 | $s = array('g'=> 1<<30, 'm' => 1<<20, 'k' => 1<<10); 162 | return intval($ini_v) * ($s[strtolower(substr($ini_v,-1))] ?: 1); 163 | } 164 | 165 | $MAX_UPLOAD_SIZE = min(asBytes(ini_get('post_max_size')), asBytes(ini_get('upload_max_filesize'))); 166 | ?> 167 | 168 | 169 | 170 | 171 | Simple PHP File Manager 172 | 208 | 209 | 427 | 428 | 429 |
430 |
431 | 432 | 433 | 434 |
435 |
436 | Drag Files Here To Upload 437 | or 438 | 439 |
440 | 441 |
442 | 443 |
444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 |
NameSizeModifiedPermissionsActions
457 | 458 | 459 | -------------------------------------------------------------------------------- /server/version.php: -------------------------------------------------------------------------------- 1 | $data)); 22 | exit; 23 | } 24 | 25 | if (isset($_SERVER['HTTP_USER_AGENT']) AND strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'autoit updater') !== FALSE) { 26 | if (isset($_GET['channel'])) { 27 | $channel = strtolower($_GET['channel']); 28 | 29 | if (file_exists(FILES_DIR . $channel)) { 30 | // Get latest version 31 | $dirs = scandir(FILES_DIR . $channel, 1); 32 | $dirs = array_filter($dirs, function($file) { 33 | return ( ! in_array($file, array('.', '..')) && is_dir(FILES_DIR . strtolower($_GET['channel']) . DIRECTORY_SEPARATOR . $file)); 34 | }); 35 | $latestVersion = array_shift($dirs); 36 | unset($dirs); 37 | 38 | // Get setup and changelog 39 | $path = FILES_DIR . $channel . DIRECTORY_SEPARATOR . $latestVersion . DIRECTORY_SEPARATOR; 40 | $dirs = scandir($path); 41 | $txt = array_filter($dirs, function($file) { 42 | $extension = explode('.', $file); 43 | return strtolower(end($extension)) === 'txt'; 44 | }); 45 | $exe = array_filter($dirs, function($file) { 46 | $extension = explode('.', $file); 47 | return strtolower(end($extension)) === 'exe'; 48 | }); 49 | 50 | if (count($txt) > 0 && count($exe) > 0) { 51 | $changelog = array_shift($txt); 52 | $setup = array_shift($exe); 53 | unset($txt, $exe); 54 | 55 | $data = array( 56 | 'version' => $latestVersion, 57 | 'name' => $setup, 58 | 'changelog' => getChangelog($path . $changelog) 59 | ); 60 | 61 | showData($data); 62 | } 63 | } 64 | } 65 | } 66 | 67 | showData(NULL); 68 | --------------------------------------------------------------------------------