wolf9228

ASM download project

15 posts in this topic

#1 ·  Posted (edited)

Through the project can  downloaded  files using the Thread function  and assembly language also  the project allows to download files on the memory or to a file directly

project Files

ASM_Download.zip

New project Files

New_ASM_Download.zip

New2 project Files

New2_ASM_Download.zip

New3 project Files

New3_ASM_Download.zip

ASM_Download.au3

#include <Memory.au3>
#include <WinAPI.au3>
Global $tagInetHandle = "DWORD Complete;DWORD Pause;DWORD MemBool;DWORD Error;DWORD MovePos;DWORD BytesAtaTime;DWORD" & _
" FileSize;DWORD  NuOfBytesRead;PTR  hLockData;PTR hFile;DWORD  lpNumberOfBytesWritten;DWORD Cancel;PTR HIntOpenUrl;" & _
"PTR   MemAddress;PTR   MemInetHandle;PTR   StringUrl;PTR    HIntOpen;PTR  MemData;PTR    MemString;DWORD   FreeHandle"
Global $tagInetHandlesPtr = "DWORD Update;DWORD CompleteAll;PTR InetHandlesPtr;PTR FreeInetHandles;DWORD LOOP" & _
";DWORD MovePos;PTR ThModule",$Wininet = DllOpen( "Wininet.dll" ) ,$HIntOpen  , $InetHandles , $Threadhandle = 0
Global $MsvcrtModule  = _WinAPI_LoadLibrary( "Msvcrt.dll" )
Global $WininethModule =   _WinAPI_LoadLibrary("Wininet.dll")
Global $Kernel32Module =  _WinAPI_LoadLibrary("Kernel32.dll")
Global $_wtol = _WinAPI_GetProcAddress($MsvcrtModule,"_wtol")
Global $memset = _WinAPI_GetProcAddress($MsvcrtModule,"memset")
Global $WriteFile = _WinAPI_GetProcAddress($Kernel32Module,"WriteFile")
Global $GlobalLock = _WinAPI_GetProcAddress($Kernel32Module,"GlobalLock")
Global $GlobalFree = _WinAPI_GetProcAddress($Kernel32Module,"GlobalFree")
Global $CloseHandle = _WinAPI_GetProcAddress($Kernel32Module,"CloseHandle")
Global $GlobalReAlloc = _WinAPI_GetProcAddress($Kernel32Module,"GlobalReAlloc")
Global $HttpQueryInfoW = _WinAPI_GetProcAddress($WininethModule,"HttpQueryInfoW")
Global $InternetOpenUrlW = _WinAPI_GetProcAddress($WininethModule,"InternetOpenUrlW")
Global $InternetReadFile = _WinAPI_GetProcAddress($WininethModule,"InternetReadFile")
Global $InternetCloseHandle = _WinAPI_GetProcAddress($WininethModule,"InternetCloseHandle")
Global $PtrSize = DllStructGetSize(DllStructCreate("PTR")) , $lpdwBufferStruct
Global $DwordSize = DllStructGetSize(DllStructCreate("DWORD"))
Global $ASMVER = DllStructCreate("DWORD VER1;PTR VER2;PTR VER3")
Global $HandleSize =  DllStructGetSize( DllStructCreate( $tagInetHandle ) )
Global $InetHandlesPtr =  DllStructCreate( $tagInetHandlesPtr)
Global $FreeInetHandle = LoadFreeInetHandle()
Global $StartDownLoad =   LoadStartDownLoad()
Global $FileDownLoad  =   LoadFileDownLoad( )
Global $MemDownLoad   =    LoadMemDownLoad( )
Global $ThreadProc     =    LoadThreadProc( )
Func DownloadFile($lpszUrl,$BytesAtaTime,$Memory = True,$FileName = "")
Local $hFile = 0
if ($BytesAtaTime < 1) Then Return SetError(1,0,0)
if Not($HIntOpen) Then $HIntOpen = InternetOpen("OPEN")
if Not ($HIntOpen) Then Return SetError(2,0,0)
if Not($Memory) Then
$hFile = _WinAPI_CreateFile($FileName,1)
if Not($hFile) Then Return SetError(3,0,0)
EndIf
Local $nhMemory = _MemGlobalAlloc($HandleSize,$GHND)
Local $hLockHandle = _MemGlobalLock($nhMemory)
Local $InetHandle = DllStructCreate($tagInetHandle,$hLockHandle)
DllStructSetData($InetHandle,"HIntOpen",$HIntOpen)
DllStructSetData($InetHandle,"BytesAtaTime",$BytesAtaTime)
DllStructSetData($InetHandle,"hFile",$hFile)
DllStructSetData($InetHandle,"MemInetHandle",$nhMemory)
Local $vhMemory = _MemGlobalAlloc($BytesAtaTime,$GHND)
Local $hLockData = _MemGlobalLock($vhMemory)
DllStructSetData($InetHandle,"hLockData",$hLockData)
DllStructSetData($InetHandle,"MemData",$vhMemory)
DllStructSetData($InetHandle,"MemBool",$Memory)
Local $StaLen = (StringLen($lpszUrl) + 1)
Local $nhMemory = _MemGlobalAlloc(($StaLen * 2),$GHND)
Local $hLockString = _MemGlobalLock($nhMemory)
DllStructSetData($InetHandle,"StringUrl",$hLockString)
DllStructSetData($InetHandle, "MemString" , $nhMemory)
DllStructSetData(DllStructCreate("WCHAR[" & $StaLen & "]",$hLockString),1,$lpszUrl)
Local $Count = DllStructGetData($InetHandles,"Count")
if @error Then
$Count = 1
Local $NewSize = ($DwordSize + $PtrSize)
Local $vhMemory = _MemGlobalAlloc($NewSize,$GHND)
Local $NewhLockHandles = _MemGlobalLock($vhMemory)
$InetHandles = DllStructCreate("DWORD Count;PTR InetHandle[1]",$NewhLockHandles)
DllStructSetData($InetHandles,"InetHandle",$hLockHandle)
DllStructSetData($InetHandles,"Count",1)
DllStructSetData($InetHandlesPtr,"InetHandlesPtr",$NewhLockHandles)
Else
$Count += 1
Local $OldhLockHandles = DllStructGetData($InetHandlesPtr,"InetHandlesPtr")
Local $NewSize = ($DwordSize + ($PtrSize * $Count))
Local $vhMemory = _MemGlobalAlloc($NewSize,$GHND)
Local $NewhLockHandles  = _MemGlobalLock($vhMemory)
_MemMoveMemory($OldhLockHandles,$NewhLockHandles,$NewSize)
$InetHandles = DllStructCreate("DWORD Count;PTR InetHandle[" & $Count & "]",$NewhLockHandles )
DllStructSetData($InetHandles,"InetHandle",$hLockHandle,$Count)
DllStructSetData($InetHandles,"Count",$Count)
DllStructSetData($InetHandlesPtr,"FreeInetHandles",GlobalHandle($OldhLockHandles))
DllStructSetData($InetHandlesPtr,"InetHandlesPtr" ,$NewhLockHandles)
DllStructSetData($InetHandlesPtr,"Update",1)
EndIf
if Not($Threadhandle) Then
$Threadhandle  = CreateThread(DllStructGetPtr($ThreadProc))
DllStructSetData($InetHandlesPtr ,"ThModule",$Threadhandle)
EndIf
Return SetError(0,0,$hLockHandle)
EndFunc
Func CloseThreadLoop()
if ( DllStructGetData($InetHandlesPtr ,"CompleteAll" ) <> 2 ) Then Return False
_MemGlobalFree(GlobalHandle(DllStructGetData($InetHandlesPtr,"InetHandlesPtr")))
_WinAPI_CloseHandle($Threadhandle)
InternetCloseHandle($HIntOpen)
DllCallAddress("PTR:CDECL",$memset,"PTR",DllStructGetPtr($InetHandlesPtr),"INT",0,"UINT_PTR",DllStructGetSize($InetHandlesPtr))
$Threadhandle = 0
$InetHandles = 0
$HIntOpen = 0
Return True
EndFunc
Func LoadThreadProc()
Local $OffSetUpdate = 0 , $OffSetCompleteAll = $DwordSize
Local $OffSetInetHandlesPtr = ($OffSetCompleteAll + $DwordSize)
Local $OffSetFreeHandle = (($DwordSize * 10) + ($PtrSize * 9))
Local $OffSetFreeInetHandles = ($OffSetInetHandlesPtr + $PtrSize)
Local $OffSetLOOP = ($OffSetFreeInetHandles + $PtrSize)
Local $OffSetMovePos = ($OffSetLOOP + $DwordSize)
Local $OffSetPause = $DwordSize , $OffSetComplete = 0
Local $OffSetCount = 0 , $OffSetInetHandles = $DwordSize
Local $OffSetMemBool = ($DwordSize * 2)
Local $Start,$Free,$JZFree,$LOOP,$End,$JZEnd,$JMPStart1,$JMPStart2,$Out,$JZLOOP1,$JZMemDown,$JMPEndLoop
Local $InetHandlesPtrPtr = DllStructGetPtr($InetHandlesPtr) ,$JMPLOOP,$JZOut,$MemDown,$EndLoop,$JZLOOP2
Local $FileDownLoadPtr = DllStructGetPtr( $FileDownLoad ) , $VER3PTR = DllStructGetPtr( $ASMVER,"VER3")
Local $JZLOOP3 ,  $JZFreeNext  ,  $FreeNext ,$JMPLOOP2 , $VER2PTR = DllStructGetPtr( $ASMVER , "VER2" )
Local $FreeInetHandlePtr=DllStructGetPtr($FreeInetHandle),$MemDownLoadPtr=DllStructGetPtr($MemDownLoad)
For $i = 1 To 2
$_ASMCode =  "0x"
; Start: //
$Start = BinaryLen($_ASMCode)
$_ASMCode &= "BB" & HexBinary($InetHandlesPtrPtr) ;mov ebx,$InetHandlesPtrPtr
$_ASMCode &= "C643" & Hex($OffSetCompleteAll,2) & Hex(0,2) ;mov [ebx + $OffSetCompleteAll],0
$_ASMCode &= "807B" & Hex($OffSetUpdate,2) & Hex(1,2) ;CMP [ebx + $OffSetUpdate],1
$_ASMCode &= "74" & Hex($Free - $JZFree,2) ;JZ JZFree
$JZFree = BinaryLen($_ASMCode)
$_ASMCode &= "C643" & Hex($OffSetLOOP,2) & Hex(0,2) ;mov [ebx + $OffSetLOOP],0
; $LOOP: //
$LOOP = BinaryLen($_ASMCode)
$_ASMCode &= "BB" & HexBinary($InetHandlesPtrPtr) ;mov ebx,$InetHandlesPtrPtr
$_ASMCode &= "8B43" & Hex($OffSetLOOP,2) ;mov eax,[ebx + $OffSetLOOP]
$_ASMCode &= "8B53" & Hex($OffSetInetHandlesPtr,2) ;mov edx,[ebx + $OffSetInetHandlesPtr]
$_ASMCode &= "3B02" ;CMP eax,[edx]
$_ASMCode &= "74" & Hex($End - $JZEnd,2) ;JZ $End
$JZEnd = BinaryLen($_ASMCode)
$_ASMCode &= "8043" & Hex($OffSetLOOP,2) & Hex(1,2) ;add [ebx + $OffSetLOOP],1
$_ASMCode &= "83C2" & Hex($OffSetInetHandles,2) ;add edx,$OffSetInetHandles
$_ASMCode &= "8B43" & Hex($OffSetMovePos,2) ;mov eax,[ebx + $OffSetMovePos]
$_ASMCode &= "03D0" ;add edx,eax
$_ASMCode &= "8B12" ;mov edx,[edx]
$_ASMCode &= "B8" & HexBinary($VER2PTR) ;mov eax,$VER2PTR
$_ASMCode &= "8910" ;mov [eax],edx
$_ASMCode &= "83FA" & Hex(0,2) ;CMP edx,0
$_ASMCode &= "74" & Hex(($EndLoop - $JZLOOP1),2) ;JZ $EndLoop
$JZLOOP1 = BinaryLen($_ASMCode)
$_ASMCode &= "C643" & Hex($OffSetCompleteAll,2) & Hex(1,2) ;mov [ebx + $OffSetCompleteAll],1
$_ASMCode &= "807A" & Hex($OffSetFreeHandle,2) & Hex(0,2) ;CMP [edx + $OffSetFreeHandle],0
$_ASMCode &= "74" & Hex(($FreeNext - $JZFreeNext),2) ;JZ $FreeNext
$JZFreeNext = BinaryLen($_ASMCode)
$_ASMCode &= "B8" & HexBinary($FreeInetHandlePtr) ;mov eax,$FreeInetHandle
$_ASMCode &= "FFD0" ;call eax
$_ASMCode &= "EB" & Hex(($EndLoop - $JMPLOOP2),2) ;JMP $EndLoop
$JMPLOOP2 = BinaryLen($_ASMCode)
; $FreeNex: //
$FreeNext = BinaryLen($_ASMCode)
$_ASMCode &= "807A" & Hex($OffSetComplete,2) & Hex(1,2) ;CMP [edx + $OffSetComplete],1 // Complete
$_ASMCode &= "74" & Hex(($EndLoop - $JZLOOP2),2) ;JZ $EndLoop
$JZLOOP2 = BinaryLen($_ASMCode)
$_ASMCode &= "807A" & Hex($OffSetPause,2) & Hex(1,2) ;CMP [edx + $OffSetPause],1 // Pause
$_ASMCode &= "74" & Hex(($EndLoop - $JZLOOP3),2) ;JZ $EndLoop
$JZLOOP3 = BinaryLen($_ASMCode)
$_ASMCode &= "807A" & Hex($OffSetMemBool,2) & Hex(1,2) ;CMP [edx + $OffSetMemBool],1
$_ASMCode &= "74" & Hex($MemDown - $JZMemDown,2) ;JZ $MemDown
$JZMemDown = BinaryLen($_ASMCode)
$_ASMCode &= "52" ;push edx
$_ASMCode &= "B8" & HexBinary($FileDownLoadPtr) ;mov eax,$FileDownLoadPtr
$_ASMCode &= "FFD0" ;call eax
$_ASMCode &= "EB" & Hex(($EndLoop - $JMPEndLoop),2) ;JMP $EndLoop
$JMPEndLoop = BinaryLen($_ASMCode)
; $MemDown: //
$MemDown = BinaryLen($_ASMCode)
$_ASMCode &= "52" ;push edx
$_ASMCode &= "B8" & HexBinary($MemDownLoadPtr) ;mov eax,$MemDownLoadPtr
$_ASMCode &= "FFD0" ;call eax
; $EndLoop: //
$EndLoop = BinaryLen($_ASMCode)
$_ASMCode &= "BB" & HexBinary($InetHandlesPtrPtr) ;mov ebx,$InetHandlesPtrPtr
$_ASMCode &= "8043" & Hex($OffSetMovePos,2) & Hex($PtrSize,2) ;add [ebx + $OffSetMovePos],$PtrSize
$JMPLOOP = BinaryLen($_ASMCode)
$_ASMCode &= "E9" & HexBinary(-(($JMPLOOP - $LOOP) + 5)) ;JMP $LOOP
; $Free: //
$Free = BinaryLen($_ASMCode)
$_ASMCode &= "BB" & HexBinary($InetHandlesPtrPtr) ;mov ebx,$InetHandlesPtrPtr
$_ASMCode &= "C643" & Hex($OffSetUpdate,2) & Hex(0,2) ;mov [ebx + $OffSetUpdate],0
$_ASMCode &= "8B43" & Hex($OffSetFreeInetHandles,2) ;mov eax,[ebx + $OffSetFreeInetHandles]
$_ASMCode &= "50" ;push eax
$_ASMCode &= "B8" & HexBinary($GlobalFree) ;mov eax,$GlobalFree
$_ASMCode &= "FFD0" ;call eax
$JMPStart1 = BinaryLen($_ASMCode)
$_ASMCode &= "E9" & HexBinary(-(($JMPStart1 - $Start) + 5)) ;JMP Start
; $End: //
$End = BinaryLen($_ASMCode)
$_ASMCode &= "BB" & HexBinary($InetHandlesPtrPtr) ;mov ebx,$InetHandlesPtrPtr
$_ASMCode &= "807B" & Hex($OffSetCompleteAll,2) & Hex(0,2) ;CMP [ebx + $OffSetCompleteAll],0
$_ASMCode &= "74" & Hex($Out - $JZOut,2) ;JZ $Out
$JZOut = BinaryLen($_ASMCode)
$_ASMCode &= "C643" & Hex($OffSetLOOP,2) & Hex(0,2) ;mov [ebx + $OffSetLOOP],0
$_ASMCode &= "C643" & Hex($OffSetMovePos,2) & Hex(0,2) ;mov [ebx + $OffSetMovePos],0
$JMPStart2 = BinaryLen($_ASMCode)
$_ASMCode &= "E9" & HexBinary(-(($JMPStart2 - $Start) + 5)) ;JMP Start
; $Out: //
$Out = BinaryLen($_ASMCode)
$_ASMCode &= "C643" & Hex($OffSetCompleteAll,2) & Hex(2,2) ;mov [edx + $OffSetCompleteAll],2
$_ASMCode &= "C3"
Next
$AddressSt = DllStructCreate("byte[" & BinaryLen($_ASMCode) & "]")
DllStructSetData($AddressSt,1,$_ASMCode)
Return $AddressSt
EndFunc
Func LoadMemDownLoad()
Local $OffSetInetHandle = $PtrSize
Local $VER1PTR = DllStructGetPtr( $ASMVER ,"VER1")
Local $VER2PTR = DllStructGetPtr( $ASMVER ,"VER2")
Local $OffSetComplete = 0
Local $OffSetByteAtaTime =  ( $DwordSize * 5)
Local $OffSetNuOfBytesRead = ($DwordSize * 7)
Local $OffSethLockData = ($DwordSize * 8)
Local $OffSethFile = (($DwordSize * 8) + $PtrSize)
Local $OffSetNuOfBytesWn = (($DwordSize * 8) + ($PtrSize * 2))
Local $OffSetHIntOpenUrl = (($DwordSize * 10) + ($PtrSize * 2))
Local $OffSetCancel = (($DwordSize * 9) + ($PtrSize * 2))
Local $OffSetMemData = (($DwordSize * 10) + ($PtrSize * 7))
Local $OffSetMemString = (($DwordSize * 10) + ($PtrSize * 8))
Local $OffSetMovePos = ($DwordSize * 4)
Local $Complete , $JZCancel , $JZComplete2  , $JZComplete , $MemFree
Local $vStartDownLoad,$vJZStartDownLoad,$JMP__Next,$__Next,$JZCancel2
Local $StartDownLoadPtr = DllStructGetPtr($StartDownLoad)
For $i = 1 To 2
$_ASMCode =  "0x"
$_ASMCode &= "8B5C24" & Hex($OffSetInetHandle,2) ;mov ebx,[esp + $OffSetInetHandle]
$_ASMCode &= "B8" & HexBinary($VER2PTR) ;mov eax,$VER2PTR
$_ASMCode &= "8918" ;mov [eax],ebx
$_ASMCode &= "807B" & Hex($OffSetHIntOpenUrl,2) & Hex(0,2) ;CMP [ebx + $OffSetHIntOpenUrl],0
$_ASMCode &= "74" & Hex($vStartDownLoad - $vJZStartDownLoad,2) ;JZ $vStartDownLoad
$vJZStartDownLoad = BinaryLen($_ASMCode)
$_ASMCode &= "EB" & Hex(($__Next - $JMP__Next),2) ;JMP __Next
$JMP__Next = BinaryLen($_ASMCode)
; StartDownLoad: //
$vStartDownLoad = BinaryLen($_ASMCode)
$_ASMCode &= "53" ;push ebx
$_ASMCode &= "B8" & HexBinary($StartDownLoadPtr) ;mov eax,$StartDownLoadPtr
$_ASMCode &= "FFD0" ;call eax
$_ASMCode &= "B8" & HexBinary(0) ;mov eax,0
$_ASMCode &= "C2" & Hex($PtrSize,2) & Hex(0,2) ;ret ($PtrSize) & "00" // Args Size
; __Next: //
$__Next = BinaryLen($_ASMCode)
$_ASMCode &= "807A" & Hex($OffSetCancel,2) & Hex(1,2) ;CMP [edx + $OffSetCancel],1 // Cancel
$_ASMCode &= "0F84" & HexBinary(($Complete - $JZCancel)) ;JZ Complete;
$JZCancel = BinaryLen($_ASMCode)
$_ASMCode &= "68" & HexBinary(0x0042) ;push $GHND = 0x0042
$_ASMCode &= "8B43" & Hex($OffSetMovePos,2) ;mov eax,[ebx + $OffSetMovePos]
$_ASMCode &= "0343" & Hex($OffSetByteAtaTime,2) ;add eax,[ebx + $OffSetByteAtaTime]
$_ASMCode &= "50" ;push eax
$_ASMCode &= "FF73" & Hex($OffSetMemData,2) ;push [ebx + $OffSetMemData]
$_ASMCode &= "B8" & HexBinary($GlobalReAlloc) ;mov eax,$GlobalReAlloc
$_ASMCode &= "FFD0" ;call eax
$_ASMCode &= "BB" & HexBinary($VER2PTR) ;mov ebx,$VER2PTR
$_ASMCode &= "8B1B" ;mov ebx,[ebx]
$_ASMCode &= "8943" & Hex($OffSetMemData,2) ;mov [ebx + $OffSetMemData],eax
$_ASMCode &= "50" ;push eax
$_ASMCode &= "B8" & HexBinary($GlobalLock) ;mov eax,$GlobalLock
$_ASMCode &= "FFD0" ;call eax
$_ASMCode &= "BB" & HexBinary($VER2PTR) ;mov ebx,$VER2PTR
$_ASMCode &= "8B1B" ;mov ebx,[ebx]
$_ASMCode &= "8943" & Hex($OffSethLockData,2) ;mov [ebx + $OffSethLockData],eax
$_ASMCode &= "C643" & Hex($OffSetNuOfBytesRead,2) & Hex(0,2) ;mov [ebx + $OffSetNuOfBytesRead],0
$_ASMCode &= "83C3" & Hex($OffSetNuOfBytesRead,2) ;add ebx,$OffSetNuOfBytesRead
$_ASMCode &= "53" ;push ebx
$_ASMCode &= "BB" & HexBinary($VER2PTR) ;mov ebx,$VER2PTR
$_ASMCode &= "8B1B" ;mov ebx,[ebx]
$_ASMCode &= "FF73" & Hex($OffSetByteAtaTime,2) ;push [ebx + $OffSetByteAtaTime]
$_ASMCode &= "8B53" & Hex($OffSetMovePos,2) ;mov edx,[ebx + $OffSetMovePos]
$_ASMCode &= "8B43" & Hex($OffSethLockData,2) ;mov eax,[ebx + $OffSethLockData]
$_ASMCode &= "03C2" ;add eax,edx
$_ASMCode &= "50" ;push eax
$_ASMCode &= "FF73" & Hex($OffSetHIntOpenUrl,2) ;push [ebx + $OffSetHIntOpenUrl]
$_ASMCode &= "B8" & HexBinary($InternetReadFile) ;mov eax,$InternetReadFile
$_ASMCode &= "FFD0" ;call eax
$_ASMCode &= "BB" & HexBinary($VER1PTR) ;mov ebx,$VER1PTR
$_ASMCode &= "8903" ;mov [ebx],eax
$_ASMCode &= "BB" & HexBinary($VER2PTR) ;mov ebx,$VER2PTR
$_ASMCode &= "8B1B" ;mov ebx,[ebx]
$_ASMCode &= "8B43" & Hex($OffSetNuOfBytesRead,2) ;mov eax,[ebx + $OffSetNuOfBytesRead]
$_ASMCode &= "0143" & Hex($OffSetMovePos,2) ;add [ebx + $OffSetMovePos],eax
$_ASMCode &= "BB" & HexBinary($VER1PTR) ;mov ebx,$VER1PTR
$_ASMCode &= "8B03" ;mov eax,[ebx]
$_ASMCode &= "83F8" & Hex(0,2) ;CMP eax,0
$_ASMCode &= "74" & Hex(($Complete - $JZComplete),2) ;JZ Complete
$JZComplete = BinaryLen($_ASMCode)

$_ASMCode &= "BB" & HexBinary($VER2PTR) ;mov ebx,$VER2PTR
$_ASMCode &= "8B1B" ;mov ebx,[ebx]
$_ASMCode &= "807B" & Hex($OffSetNuOfBytesRead,2) & Hex(0,2) ;CMP [ebx + $OffSetNuOfBytesRead],0
$_ASMCode &= "74" & Hex(($Complete - $JZComplete2),2) ;JZ Complete
$JZComplete2 = BinaryLen($_ASMCode)
$_ASMCode &= "B8" & HexBinary(0) ;mov eax,0
$_ASMCode &= "C2" & Hex($PtrSize,2) & Hex(0,2) ;ret ($PtrSize) & "00" // Args Size
; Complete: //
$Complete = BinaryLen($_ASMCode)
$_ASMCode &= "BB" & HexBinary($VER2PTR) ;mov ebx,$VER2PTR
$_ASMCode &= "8B1B" ;mov ebx,[ebx]
$_ASMCode &= "C643" & Hex($OffSetComplete,2) & Hex(1,2) ;mov [ebx + $OffSetComplete],1
$_ASMCode &= "FF73" & Hex($OffSetHIntOpenUrl,2) ;push [ebx + $OffSetHIntOpenUrl]
$_ASMCode &= "B8" & HexBinary($InternetCloseHandle) ;mov eax,$InternetCloseHandle
$_ASMCode &= "FFD0" ;call eax
$_ASMCode &= "BB" & HexBinary($VER2PTR) ;mov ebx,$VER2PTR
$_ASMCode &= "8B1B" ;mov ebx,[ebx]
$_ASMCode &= "FF73" & Hex($OffSetMemString,2) ;push [ebx + $OffSetMemString]
$_ASMCode &= "B8" & HexBinary($GlobalFree) ;mov eax,$GlobalFree
$_ASMCode &= "FFD0" ;call eax
$_ASMCode &= "807A" & Hex($OffSetCancel,2) & Hex(1,2) ;CMP [edx + $OffSetCancel],1 // Cancel
$_ASMCode &= "0F84" & HexBinary(($MemFree - $JZCancel2)) ;JZ $MemFree;
$JZCancel2 = BinaryLen($_ASMCode)
$_ASMCode &= "68" & HexBinary(0x0042) ;push $GHND = 0x0042
$_ASMCode &= "8B43" & Hex($OffSetMovePos,2) ;mov eax,[ebx + $OffSetMovePos]
$_ASMCode &= "50" ;push eax
$_ASMCode &= "FF73" & Hex($OffSetMemData,2) ;push [ebx + $OffSetMemData]
$_ASMCode &= "B8" & HexBinary($GlobalReAlloc) ;mov eax,$GlobalReAlloc
$_ASMCode &= "FFD0" ;call eax
$_ASMCode &= "BB" & HexBinary($VER2PTR) ;mov ebx,$VER2PTR
$_ASMCode &= "8B1B" ;mov ebx,[ebx]
$_ASMCode &= "8943" & Hex($OffSetMemData,2) ;mov [ebx + $OffSetMemData],eax
$_ASMCode &= "50" ;push eax
$_ASMCode &= "B8" & HexBinary($GlobalLock) ;mov eax,$GlobalLock
$_ASMCode &= "FFD0" ;call eax
$_ASMCode &= "BB" & HexBinary($VER2PTR) ;mov ebx,$VER2PTR
$_ASMCode &= "8B1B" ;mov ebx,[ebx]
$_ASMCode &= "8943" & Hex($OffSethLockData,2) ;mov [ebx + $OffSethLockData],eax
$_ASMCode &= "B8" & HexBinary(0) ;mov eax,0
$_ASMCode &= "C2" & Hex($PtrSize,2) & Hex(0,2) ;ret ($PtrSize) & "00" // Args Size
; MemFree: //
$MemFree = BinaryLen($_ASMCode)
$_ASMCode &= "BB" & HexBinary($VER2PTR) ;mov ebx,$VER2PTR
$_ASMCode &= "8B1B" ;mov ebx,[ebx]
$_ASMCode &= "FF73" & Hex($OffSetMemData,2) ;push [ebx + $OffSetMemData]
$_ASMCode &= "B8" & HexBinary($GlobalFree) ;mov eax,$GlobalFree
$_ASMCode &= "FFD0" ;call eax
$_ASMCode &= "B8" & HexBinary(0) ;mov eax,0
$_ASMCode &= "C2" & Hex($PtrSize,2) & Hex(0,2) ;ret ($PtrSize) & "00" // Args Size
Next
$AddressSt = DllStructCreate("byte[" & BinaryLen($_ASMCode) & "]")
DllStructSetData($AddressSt,1,$_ASMCode)
Return $AddressSt
EndFunc
Func LoadFileDownLoad()
Local $OffSetInetHandle = $PtrSize
Local $VER1PTR = DllStructGetPtr( $ASMVER ,"VER1")
Local $VER2PTR = DllStructGetPtr( $ASMVER ,"VER2")
Local $OffSetComplete = 0
Local $OffSetByteAtaTime =  ( $DwordSize * 5)
Local $OffSetNuOfBytesRead = ($DwordSize * 7)
Local $OffSethLockData = ($DwordSize * 8)
Local $OffSethFile = (($DwordSize * 8) + $PtrSize)
Local $OffSetNuOfBytesWn = (($DwordSize * 8) + ($PtrSize * 2))
Local $OffSetHIntOpenUrl = (($DwordSize * 10) + ($PtrSize * 2))
Local $OffSetCancel = (($DwordSize * 9) + ($PtrSize * 2))
Local $OffSetMemData = (($DwordSize * 10) + ($PtrSize * 7))
Local $OffSetMemString = (($DwordSize * 10) + ($PtrSize * 8))
Local $OffSetMovePos = ($DwordSize * 4)
Local $Complete , $JZCancel , $JZComplete2 , $JZComplete
Local $vStartDownLoad,$vJZStartDownLoad,$JMP__Next,$__Next
Local $StartDownLoadPtr = DllStructGetPtr($StartDownLoad)
For $i = 1 To 2
$_ASMCode =  "0x"
$_ASMCode &= "8B5C24" & Hex($OffSetInetHandle,2) ;mov ebx,[esp + $OffSetInetHandle]
$_ASMCode &= "B8" & HexBinary($VER2PTR) ;mov eax,$VER2PTR
$_ASMCode &= "8918" ;mov [eax],ebx
$_ASMCode &= "807B" & Hex($OffSetHIntOpenUrl,2) & Hex(0,2) ;CMP [ebx + $OffSetHIntOpenUrl],0
$_ASMCode &= "74" & Hex($vStartDownLoad - $vJZStartDownLoad,2) ;JZ $vStartDownLoad
$vJZStartDownLoad = BinaryLen($_ASMCode)
$_ASMCode &= "EB" & Hex(($__Next - $JMP__Next),2) ;JMP __Next
$JMP__Next = BinaryLen($_ASMCode)
; StartDownLoad: //
$vStartDownLoad = BinaryLen($_ASMCode)
$_ASMCode &= "53" ;push ebx
$_ASMCode &= "B8" & HexBinary($StartDownLoadPtr) ;mov eax,$StartDownLoadPtr
$_ASMCode &= "FFD0" ;call eax
$_ASMCode &= "B8" & HexBinary(0) ;mov eax,0
$_ASMCode &= "C2" & Hex($PtrSize,2) & Hex(0,2) ;ret ($PtrSize) & "00" // Args Size
; __Next: //
$__Next = BinaryLen($_ASMCode)
$_ASMCode &= "807A" & Hex($OffSetCancel,2) & Hex(1,2) ;CMP [edx + $OffSetCancel],1 // Cancel
$_ASMCode &= "0F84" & HexBinary(($Complete - $JZCancel)) ;JZ Complete;
$JZCancel = BinaryLen($_ASMCode)
$_ASMCode &= "C643" & Hex($OffSetNuOfBytesRead,2) & Hex(0,2) ;mov [ebx + $OffSetNuOfBytesRead],0
$_ASMCode &= "83C3" & Hex($OffSetNuOfBytesRead,2) ;add ebx,$OffSetNuOfBytesRead
$_ASMCode &= "53" ;push ebx
$_ASMCode &= "BB" & HexBinary($VER2PTR) ;mov ebx,$VER2PTR
$_ASMCode &= "8B1B" ;mov ebx,[ebx]
$_ASMCode &= "FF73" & Hex($OffSetByteAtaTime,2) ;push [ebx + $OffSetByteAtaTime]
$_ASMCode &= "FF73" & Hex($OffSethLockData,2) ;push [ebx + $OffSethLockData]
$_ASMCode &= "FF73" & Hex($OffSetHIntOpenUrl,2) ;push [ebx + $OffSetHIntOpenUrl]
$_ASMCode &= "B8" & HexBinary($InternetReadFile) ;mov eax,$InternetReadFile
$_ASMCode &= "FFD0" ;call eax
$_ASMCode &= "BB" & HexBinary($VER1PTR) ;mov ebx,$VER1PTR
$_ASMCode &= "8903" ;mov [ebx],eax
$_ASMCode &= "BB" & HexBinary($VER2PTR) ;mov ebx,$VER2PTR
$_ASMCode &= "8B1B" ;mov ebx,[ebx]
$_ASMCode &= "68" & HexBinary(0) ;push lpOverlapped = 0
$_ASMCode &= "83C3" & Hex($OffSetNuOfBytesWn,2) ;add ebx,$OffSetNuOfBytesWn
$_ASMCode &= "53" ;push ebx
$_ASMCode &= "BB" & HexBinary($VER2PTR) ;mov ebx,$VER2PTR
$_ASMCode &= "8B1B" ;mov ebx,[ebx]
$_ASMCode &= "FF73" & Hex($OffSetNuOfBytesRead,2) ;push [ebx + $OffSetNuOfBytesRead]
$_ASMCode &= "FF73" & Hex($OffSethLockData,2) ;push [ebx + $OffSethLockData]
$_ASMCode &= "FF73" & Hex($OffSethFile,2) ;push [ebx + $OffSethFile]
$_ASMCode &= "B8" & HexBinary($WriteFile) ;mov eax,$WriteFile
$_ASMCode &= "FFD0" ;call eax
$_ASMCode &= "BB" & HexBinary($VER2PTR) ;mov ebx,$VER2PTR
$_ASMCode &= "8B1B" ;mov ebx,[ebx]
$_ASMCode &= "8B43" & Hex($OffSetNuOfBytesRead,2) ;mov eax,[ebx + $OffSetNuOfBytesRead]
$_ASMCode &= "0143" & Hex($OffSetMovePos,2) ;add [ebx + $OffSetMovePos],eax
$_ASMCode &= "BB" & HexBinary($VER1PTR) ;mov ebx,$VER1PTR
$_ASMCode &= "8B03" ;mov eax,[ebx]
$_ASMCode &= "83F8" & Hex(0,2) ;CMP eax,0
$_ASMCode &= "74" & Hex(($Complete - $JZComplete),2) ;JZ Complete
$JZComplete = BinaryLen($_ASMCode)
$_ASMCode &= "BB" & HexBinary($VER2PTR) ;mov ebx,$VER2PTR
$_ASMCode &= "8B1B" ;mov ebx,[ebx]
$_ASMCode &= "807B" & Hex($OffSetNuOfBytesRead,2) & Hex(0,2) ;CMP [ebx + $OffSetNuOfBytesRead],0
$_ASMCode &= "74" & Hex(($Complete - $JZComplete2),2) ;JZ Complete
$JZComplete2 = BinaryLen($_ASMCode)
$_ASMCode &= "B8" & HexBinary(0) ;mov eax,0
$_ASMCode &= "C2" & Hex($PtrSize,2) & Hex(0,2) ;ret ($PtrSize) & "00" // Args Size
; Complete: //
$Complete = BinaryLen($_ASMCode)
$_ASMCode &= "BB" & HexBinary($VER2PTR) ;mov ebx,$VER2PTR
$_ASMCode &= "8B1B" ;mov ebx,[ebx]
$_ASMCode &= "C643" & Hex($OffSetComplete,2) & Hex(1,2) ;mov [ebx + $OffSetComplete],1
$_ASMCode &= "FF73" & Hex($OffSetHIntOpenUrl,2) ;push [ebx + $OffSetHIntOpenUrl]
$_ASMCode &= "B8" & HexBinary($InternetCloseHandle) ;mov eax,$InternetCloseHandle
$_ASMCode &= "FFD0" ;call eax
$_ASMCode &= "BB" & HexBinary($VER2PTR) ;mov ebx,$VER2PTR
$_ASMCode &= "8B1B" ;mov ebx,[ebx]
$_ASMCode &= "FF73" & Hex($OffSethFile,2) ;push [ebx + $OffSethFile]
$_ASMCode &= "B8" & HexBinary($CloseHandle) ;mov eax,$CloseHandle
$_ASMCode &= "FFD0" ;call eax
$_ASMCode &= "BB" & HexBinary($VER2PTR) ;mov ebx,$VER2PTR
$_ASMCode &= "8B1B" ;mov ebx,[ebx]
$_ASMCode &= "FF73" & Hex($OffSetMemData,2) ;push [ebx + $OffSetMemData]
$_ASMCode &= "B8" & HexBinary($GlobalFree) ;mov eax,$GlobalFree
$_ASMCode &= "FFD0" ;call eax
$_ASMCode &= "BB" & HexBinary($VER2PTR) ;mov ebx,$VER2PTR
$_ASMCode &= "8B1B" ;mov ebx,[ebx]
$_ASMCode &= "FF73" & Hex($OffSetMemString,2) ;push [ebx + $OffSetMemString]
$_ASMCode &= "B8" & HexBinary($GlobalFree) ;mov eax,$GlobalFree
$_ASMCode &= "FFD0" ;call eax
$_ASMCode &= "B8" & HexBinary(0) ;mov eax,0
$_ASMCode &= "C2" & Hex($PtrSize,2) & Hex(0,2) ;ret ($PtrSize) & "00" // Args Size
Next
$AddressSt = DllStructCreate("byte[" & BinaryLen($_ASMCode) & "]")
DllStructSetData($AddressSt,1,$_ASMCode)
Return $AddressSt
EndFunc
Func LoadStartDownLoad()
Local $OffSetInetHandle = $PtrSize
Local $OffSetFileSize = ($DwordSize * 6)
Local $OffSetComplete = 0  , $OffSetError = ( $DwordSize * 3 )
Local $OffSetHIntOpenUrl = (($DwordSize * 10) + ($PtrSize * 2))
Local $OffSetStringUrl = (($DwordSize * 10) + ($PtrSize * 5))
Local $OffSetHIntOpen = (($DwordSize * 10) + ($PtrSize * 6))
Local $OffSetMemData = (($DwordSize * 10) + ($PtrSize * 7))
Local $OffSetMemString = (($DwordSize * 10) + ($PtrSize * 8))
Local $OffSetMemBool = ($DwordSize * 2)
Local $OffSethFile = (($DwordSize * 8) + $PtrSize)
Local $lpdwBufferLength = 100 ,  $dwInfoLevel = 5
$lpdwBufferStruct = DllStructCreate("WCHAR[100]")
Local $BufPtr = DllStructGetPtr($lpdwBufferStruct)
Local $VER1PTR = DllStructGetPtr( $ASMVER ,"VER1")
Local $VER2PTR = DllStructGetPtr( $ASMVER ,"VER2")
Local $Error,$JZError,$JZReturn,$Return
For $i = 1 To 2
$_ASMCode =  "0x"
$_ASMCode &= "8B5C24" & Hex($OffSetInetHandle,2) ;mov ebx,[esp + $OffSetInetHandle]
$_ASMCode &= "B8" & HexBinary($VER2PTR) ;mov eax,$VER2PTR
$_ASMCode &= "8918" ;mov [eax],ebx
$_ASMCode &= "B8" & HexBinary(0) ;mov eax,0
$_ASMCode &= "50" ;push eax
$_ASMCode &= "50" ;push eax
$_ASMCode &= "50" ;push eax
$_ASMCode &= "50" ;push eax
$_ASMCode &= "FF73" & Hex($OffSetStringUrl,2) ;push [ebx + $OffSetStringUrl]
$_ASMCode &= "FF73" & Hex($OffSetHIntOpen,2) ;push [ebx + $OffSetHIntOpen]
$_ASMCode &= "B8" & HexBinary($InternetOpenUrlW) ;mov eax,$InternetOpenUrlW
$_ASMCode &= "FFD0" ;call eax
$_ASMCode &= "83F8" & Hex(0,2) ;CMP eax,0
$_ASMCode &= "74" & Hex($Error - $JZError,2) ;JZ Error
$JZError = BinaryLen($_ASMCode)
$_ASMCode &= "BB" & HexBinary($VER2PTR) ;mov ebx,$VER2PTR
$_ASMCode &= "8B1B" ;mov ebx,[ebx]
$_ASMCode &= "8943" & Hex($OffSetHIntOpenUrl,2) ;mov [ebx + $OffSetHIntOpenUrl],eax
$_ASMCode &= "B8" & HexBinary(0) ;mov eax,0
$_ASMCode &= "50" ;push eax
$_ASMCode &= "B8" & HexBinary($VER1PTR) ;mov eax,$VER1PTR
$_ASMCode &= "C600" & Hex($lpdwBufferLength,2) ;mov [eax],$lpdwBufferLength
$_ASMCode &= "50" ;push eax
$_ASMCode &= "B8" & HexBinary($BufPtr) ;mov eax,$BufPtr
$_ASMCode &= "C600" & Hex(0,2) ;mov [eax],0
$_ASMCode &= "50" ;push eax
$_ASMCode &= "B8" & HexBinary($dwInfoLevel) ;mov eax,$dwInfoLevel
$_ASMCode &= "50" ;push eax
$_ASMCode &= "FF73" & Hex($OffSetHIntOpenUrl,2) ;push [ebx + $OffSetHIntOpenUrl]
$_ASMCode &= "B8" & HexBinary($HttpQueryInfoW) ;mov eax,$HttpQueryInfoW
$_ASMCode &= "FFD0" ;call eax
$_ASMCode &= "B8" & HexBinary($BufPtr) ;mov eax,$BufPtr
$_ASMCode &= "50" ;push eax
$_ASMCode &= "B8" & HexBinary($_wtol) ;mov eax,$_wtol
$_ASMCode &= "FFD0" ;call eax
$_ASMCode &= "83C4" & Hex($DwordSize,2) ;add esp,$DwordSize
$_ASMCode &= "BB" & HexBinary($VER2PTR) ;mov ebx,$VER2PTR
$_ASMCode &= "8B1B" ;mov ebx,[ebx]
$_ASMCode &= "8943" & Hex($OffSetFileSize,2) ;mov [ebx + $OffSetFileSize],eax
$_ASMCode &= "B8" & HexBinary(1) ;mov eax,1
$_ASMCode &= "C2" & Hex($PtrSize,2) & Hex(0,2) ;ret ($PtrSize) & "00" // Args Size
; $Error: //
$Error = BinaryLen($_ASMCode)
$_ASMCode &= "BB" & HexBinary($VER2PTR) ;mov ebx,$VER2PTR
$_ASMCode &= "8B1B" ;mov ebx,[ebx]
$_ASMCode &= "C643" & Hex($OffSetComplete,2) & Hex(1,2) ;mov [ebx + $OffSetComplete],1
$_ASMCode &= "C643" & Hex($OffSetError,2) & Hex(1,2) ;mov [ebx + $OffSetError],1
$_ASMCode &= "FF73" & Hex($OffSetMemData,2) ;push [ebx + $OffSetMemData]
$_ASMCode &= "B8" & HexBinary($GlobalFree) ;mov eax,$GlobalFree
$_ASMCode &= "FFD0" ;call eax
$_ASMCode &= "BB" & HexBinary($VER2PTR) ;mov ebx,$VER2PTR
$_ASMCode &= "8B1B" ;mov ebx,[ebx]
$_ASMCode &= "FF73" & Hex($OffSetMemString,2) ;push [ebx + $OffSetMemString]
$_ASMCode &= "B8" & HexBinary($GlobalFree) ;mov eax,$GlobalFree
$_ASMCode &= "FFD0" ;call eax
$_ASMCode &= "BB" & HexBinary($VER2PTR) ;mov ebx,$VER2PTR
$_ASMCode &= "8B1B" ;mov ebx,[ebx]
$_ASMCode &= "807A" & Hex($OffSetMemBool,2) & Hex(1,2) ;CMP [edx + $OffSetMemBool],1
$JZReturn = BinaryLen($_ASMCode)
$_ASMCode &= "74" & Hex($Return - $JZReturn,2) ;JZ Return
$_ASMCode &= "FF73" & Hex($OffSethFile,2) ;push [ebx + $OffSethFile]
$_ASMCode &= "B8" & HexBinary($CloseHandle) ;mov eax,$CloseHandle
$_ASMCode &= "FFD0" ;call eax
; $Return: //
$Return = BinaryLen($_ASMCode)
$_ASMCode &= "B8" & HexBinary(0) ;mov eax,0
$_ASMCode &= "C2" & Hex($PtrSize,2) & Hex(0,2) ;ret ($PtrSize) & "00" // Args Size
Next
$AddressSt = DllStructCreate("byte[" & BinaryLen($_ASMCode) & "]")
DllStructSetData($AddressSt,1,$_ASMCode)
Return $AddressSt
EndFunc
Func LoadFreeInetHandle()
Local $VER2PTR = DllStructGetPtr( $ASMVER , "VER2" )
Local $InetHandlesPtrPtr = DllStructGetPtr($InetHandlesPtr)
Local $OffSetMemData = (($DwordSize * 10) + ($PtrSize * 7))
Local $OffSetMemString = (($DwordSize * 10) + ($PtrSize * 8))
Local $OffSetHIntOpenUrl = (($DwordSize * 10) + ($PtrSize * 2))
Local $OffSethFile = (($DwordSize * 8) + $PtrSize)
Local $OffSetMemInetHandle = (($DwordSize * 10) + ($PtrSize * 3))
Local $OffSetUpdate = 0 , $OffSetCompleteAll = $DwordSize
Local $OffSetInetHandlesPtr = ($OffSetCompleteAll + $DwordSize)
Local $OffSetFreeHandle = (($DwordSize * 10) + ($PtrSize * 9))
Local $OffSetFreeInetHandles = ($OffSetInetHandlesPtr + $PtrSize)
Local $OffSetLOOP = ($OffSetFreeInetHandles + $PtrSize)
Local $OffSetMovePos = ($OffSetLOOP + $DwordSize)
Local $OffSetMemBool = ($DwordSize * 2)
Local $OffSetPause = $DwordSize  , $OffSetComplete = 0
Local $OffSetInetHandles = $DwordSize
Local $__Next,$JZ__Next,$JZMemDown,$MemDown,$JMP__Next
For $i = 1 To 2
$_ASMCode =  "0x"
$_ASMCode &= "BB" & HexBinary($InetHandlesPtrPtr) ;mov ebx,$InetHandlesPtrPtr
$_ASMCode &= "8B43" & Hex($OffSetMovePos,2) ;mov eax,[ebx + $OffSetMovePos]
$_ASMCode &= "8B53" & Hex($OffSetInetHandlesPtr,2) ;mov edx,[ebx + $OffSetInetHandlesPtr]
$_ASMCode &= "83C2" & Hex($OffSetInetHandles,2) ;add edx,$OffSetInetHandles
$_ASMCode &= "03D0" ;add edx,eax
$_ASMCode &= "8B12" ;mov edx,[edx]
$_ASMCode &= "B8" & HexBinary($VER2PTR) ;mov eax,$VER2PTR
$_ASMCode &= "8910" ;mov [eax],edx
$_ASMCode &= "807A" & Hex($OffSetComplete,2) & Hex(1,2) ;CMP [edx + $OffSetComplete],1 // Complete
$_ASMCode &= "0F84" & HexBinary($__Next - $JZ__Next) ;JZ JZ__Next
$JZ__Next = BinaryLen($_ASMCode)
$_ASMCode &= "807A" & Hex($OffSetMemBool,2) & Hex(1,2) ;CMP [edx + $OffSetMemBool],1
$_ASMCode &= "74" & Hex($MemDown - $JZMemDown,2) ;JZ $MemDown
$JZMemDown = BinaryLen($_ASMCode)
$_ASMCode &= "FF73" & Hex($OffSetHIntOpenUrl,2) ;push [ebx + $OffSetHIntOpenUrl]
$_ASMCode &= "B8" & HexBinary($InternetCloseHandle) ;mov eax,$InternetCloseHandle
$_ASMCode &= "FFD0" ;call eax
$_ASMCode &= "BB" & HexBinary($VER2PTR) ;mov ebx,$VER2PTR
$_ASMCode &= "8B1B" ;mov ebx,[ebx]
$_ASMCode &= "FF73" & Hex($OffSethFile,2) ;push [ebx + $OffSethFile]
$_ASMCode &= "B8" & HexBinary($CloseHandle) ;mov eax,$CloseHandle
$_ASMCode &= "FFD0" ;call eax
$_ASMCode &= "BB" & HexBinary($VER2PTR) ;mov ebx,$VER2PTR
$_ASMCode &= "8B1B" ;mov ebx,[ebx]
$_ASMCode &= "FF73" & Hex($OffSetMemData,2) ;push [ebx + $OffSetMemData]
$_ASMCode &= "B8" & HexBinary($GlobalFree) ;mov eax,$GlobalFree
$_ASMCode &= "FFD0" ;call eax
$_ASMCode &= "BB" & HexBinary($VER2PTR) ;mov ebx,$VER2PTR
$_ASMCode &= "8B1B" ;mov ebx,[ebx]
$_ASMCode &= "FF73" & Hex($OffSetMemString,2) ;push [ebx + $OffSetMemString]
$_ASMCode &= "B8" & HexBinary($GlobalFree) ;mov eax,$GlobalFree
$_ASMCode &= "FFD0" ;call eax
$_ASMCode &= "BB" & HexBinary($VER2PTR) ;mov ebx,$VER2PTR
$_ASMCode &= "8B1B" ;mov ebx,[ebx]
$_ASMCode &= "FF73" & Hex($OffSetMemInetHandle,2) ;push [ebx + $OffSetMemInetHandle]
$_ASMCode &= "B8" & HexBinary($GlobalFree) ;mov eax,$GlobalFree
$_ASMCode &= "FFD0" ;call eax
$_ASMCode &= "EB" & Hex(($__Next - $JMP__Next),2) ;JMP __Next
$JMP__Next = BinaryLen($_ASMCode)
; $MemDown: //
$MemDown = BinaryLen($_ASMCode)
$_ASMCode &= "FF73" & Hex($OffSetHIntOpenUrl,2) ;push [ebx + $OffSetHIntOpenUrl]
$_ASMCode &= "B8" & HexBinary($InternetCloseHandle) ;mov eax,$InternetCloseHandle
$_ASMCode &= "FFD0" ;call eax
$_ASMCode &= "BB" & HexBinary($VER2PTR) ;mov ebx,$VER2PTR
$_ASMCode &= "8B1B" ;mov ebx,[ebx]
$_ASMCode &= "FF73" & Hex($OffSetMemData,2) ;push [ebx + $OffSetMemData]
$_ASMCode &= "B8" & HexBinary($GlobalFree) ;mov eax,$GlobalFree
$_ASMCode &= "FFD0" ;call eax
$_ASMCode &= "BB" & HexBinary($VER2PTR) ;mov ebx,$VER2PTR
$_ASMCode &= "8B1B" ;mov ebx,[ebx]
$_ASMCode &= "FF73" & Hex($OffSetMemString,2) ;push [ebx + $OffSetMemString]
$_ASMCode &= "B8" & HexBinary($GlobalFree) ;mov eax,$GlobalFree
$_ASMCode &= "FFD0" ;call eax
$_ASMCode &= "BB" & HexBinary($VER2PTR) ;mov ebx,$VER2PTR
$_ASMCode &= "8B1B" ;mov ebx,[ebx]
$_ASMCode &= "FF73" & Hex($OffSetMemInetHandle,2) ;push [ebx + $OffSetMemInetHandle]
$_ASMCode &= "B8" & HexBinary($GlobalFree) ;mov eax,$GlobalFree
$_ASMCode &= "FFD0" ;call eax
; $__Next: //
$__Next = BinaryLen($_ASMCode)
$_ASMCode &= "BB" & HexBinary($InetHandlesPtrPtr) ;mov ebx,$InetHandlesPtrPtr
$_ASMCode &= "8B43" & Hex($OffSetMovePos,2) ;mov eax,[ebx + $OffSetMovePos]
$_ASMCode &= "8B53" & Hex($OffSetInetHandlesPtr,2) ;mov edx,[ebx + $OffSetInetHandlesPtr]
$_ASMCode &= "03D0" ;add edx,eax
$_ASMCode &= "83C2" & Hex($OffSetInetHandles,2) ;add edx,$OffSetInetHandles
$_ASMCode &= "68" & HexBinary($PtrSize) ; push $PtrSize
$_ASMCode &= "68" & HexBinary(0) ; push 0
$_ASMCode &= "52" ;push edx
$_ASMCode &= "B8" & HexBinary($memset) ;mov eax,$memset
$_ASMCode &= "FFD0" ;call eax
$_ASMCode &= "83C4" & Hex(($DwordSize + ($PtrSize * 2)),2) ;add esp,(($DwordSize * 2) + $PtrSize)
$_ASMCode &= "C2" & Hex(0,2) & Hex(0,2) ;ret (0) & "00" // Args Size
Next
$AddressSt = DllStructCreate("byte[" & BinaryLen($_ASMCode) & "]")
DllStructSetData($AddressSt,1,$_ASMCode)
Return $AddressSt
EndFunc
Func DownloadReSetPause($HLockHandle)
Local $InetHandle = DllStructCreate($tagInetHandle,$HLockHandle)
if @error Then Return SetError(1,0,False)
$Pause = DllStructGetData($InetHandle,"Pause")
if @error Then Return SetError(2,0,False)
$Complete = DllStructGetData($InetHandle,"Complete")
if @error Or ($Complete) Then Return SetError(3,0,False)
DllStructSetData($InetHandle,"Pause",Not($Pause))
if @error Then Return SetError(4,0,False)
Return SetError(0,0,True)
EndFunc
Func DownloadCancel($HLockHandle)
Local $InetHandle = DllStructCreate($tagInetHandle,$HLockHandle)
if @error Then Return SetError(1,0,False)
$Cancel = DllStructGetData($InetHandle,"Cancel")
if @error Or ($Cancel) Then Return SetError(2,0,False)
$Complete = DllStructGetData($InetHandle,"Complete")
if @error Or ($Complete) Then Return SetError(3,0,False)
$Pause = DllStructGetData($InetHandle,"Pause")
if @error Then Return SetError(4,0,False)
if ($Pause) Then DownloadReSetPause($InetHandle)
if @error Then Return SetError(5,0,False)
DllStructSetData($InetHandle,"Cancel",1)
if @error Then Return SetError(6,0,False)
Return SetError(0,0,True)
EndFunc
Func DownloadGetInfo($HLockHandle)
Local $InetHandle = DllStructCreate($tagInetHandle,$HLockHandle)
if @error Then Return SetError(1,0,0)
$MemBool = DllStructGetData($InetHandle,"MemBool")
if @error Then Return SetError(2,0,0)
Local $InfoArray[11]
if ($MemBool) Then
$InfoArray[0] = $MemBool
$InfoArray[1] = DllStructGetData($InetHandle,"Complete")
$InfoArray[2] = DllStructGetData($InetHandle,"Pause")
$InfoArray[3] = DllStructGetData($InetHandle,"Cancel")
$InfoArray[4] = DllStructGetData($InetHandle,"Error")
$InfoArray[5] = DllStructGetData($InetHandle,"MovePos")
$InfoArray[6] = DllStructGetData($InetHandle,"FileSize")
$InfoArray[7] = DllStructGetData($InetHandle,"BytesAtaTime")
$InfoArray[8] = DllStructGetData($InetHandle,"NuOfBytesRead")
$InfoArray[9] = DllStructGetData($InetHandle,"hLockData")
$InfoArray[10] = DllStructGetData($InetHandle,"MemData")
Else
$InfoArray[0] = $MemBool
$InfoArray[1] = DllStructGetData($InetHandle,"Complete")
$InfoArray[2] = DllStructGetData($InetHandle,"Pause")
$InfoArray[3] = DllStructGetData($InetHandle,"Cancel")
$InfoArray[4] = DllStructGetData($InetHandle,"Error")
$InfoArray[5] = DllStructGetData($InetHandle,"MovePos")
$InfoArray[6] = DllStructGetData($InetHandle,"FileSize")
$InfoArray[7] = DllStructGetData($InetHandle,"BytesAtaTime")
$InfoArray[8] = DllStructGetData($InetHandle,"NuOfBytesRead")
$InfoArray[9] = 0
$InfoArray[10] = 0
EndIf
Return SetError(0,0,$InfoArray)
EndFunc
Func DownloadFreeHLockHandle($HLockHandle)
Local $InetHandle = DllStructCreate($tagInetHandle,$HLockHandle)
if @error Then Return SetError(1,0,0)
DllStructSetData($InetHandle,"FreeHandle",1)
if @error Then Return SetError(2,0,False)
Return SetError(0,0,True)
EndFunc
Func HexBinary($Value)
Return Hex(Binary($Value))
EndFunc
Func CreateThread($lpStartAddress,$lpParameter = 0)
$Return = DllCall("Kernel32.dll","ptr","CreateThread","ptr",0,"DWORD",0 _
,"ptr",$lpStartAddress,"ptr",$lpParameter,"DWORD",0,"DWORD*",0)
if @error Or $Return[0] = 0 Then Return SetError(1,0,0)
$lpThreadId = $Return[6]
Return SetError(0,$lpThreadId,$Return[0])
EndFunc
Func GlobalHandle($pMem)
$HGLOBAL = DllCall("Kernel32.dll","ptr","GlobalHandle","ptr",$pMem)
if @error Or $HGLOBAL[0] = 0 Then Return SetError(1,0,0)
Return SetError(0,0,$HGLOBAL[0])
EndFunc
Func InternetReadFile($hFile,$lpBuffer,$dwNumberOfBytesToRead)
$DLLSDWORD = DllStructCreate("DWORD")
$lpdwNumberOfBytesRead = DllStructGetPtr($DLLSDWORD)
$BOOL = DllCall($Wininet,"BOOL","InternetReadFile","HANDLE",$hFile,"ptr",$lpBuffer, _
"DWORD",$dwNumberOfBytesToRead,"ptr",$lpdwNumberOfBytesRead)
if @error Or $BOOL[0] = 0 Then Return SetError(1,0,0)
Return SetError(0,0,DllStructGetData($DLLSDWORD,1))
EndFunc
Func HttpQueryInfo($hRequest,$dwInfoLevel,$lpdwIndex = 0)
Local $lpdwBufferLength = 1000
$DLLSDWORD = DllStructCreate("DWORD")
DllStructSetData($DLLSDWORD,1,$lpdwBufferLength)
$LPDWORDLENGTH = DllStructGetPtr($DLLSDWORD)
$DLLSlpvBuffer = DllStructCreate("WCHAR[" & $lpdwBufferLength & "]")
$lpvBuffer = DllStructGetPtr($DLLSlpvBuffer)
$BOOL = DllCall($Wininet,"BOOL","HttpQueryInfoW","HANDLE",$hRequest,"DWORD",$dwInfoLevel, _
"ptr",$lpvBuffer,"ptr",$LPDWORDLENGTH,"DWORD",$lpdwIndex)
if @error Or $BOOL[0] = 0 Then Return SetError(1,0,0)
Return SetError(0,0,DllStructGetData($DLLSlpvBuffer,1))
EndFunc
Func InternetOpenUrl($hInternet,$lpszUrl,$lpszHeaders,$dwHeadersLength,$dwFlags,$dwContext)
$HINTERNET = DllCall($Wininet,"HANDLE","InternetOpenUrlW","HANDLE",$hInternet,"wstr",$lpszUrl, _
"wstr",$lpszHeaders,"DWORD",$dwHeadersLength,"DWORD",$dwFlags,"ptr",$dwContext)
if @error Or Not ($HINTERNET[0]) Then Return SetError(1,0,0)
Return SetError(0,0,$HINTERNET[0])
EndFunc
Func InternetOpen($lpszAgent,$dwAccessType = 0,$lpszProxyName = "",$lpszProxyBypass = "",$dwFlags = 0)
$HINTERNET = DllCall($Wininet,"HANDLE","InternetOpenW","wstr",$lpszAgent,"DWORD",$dwAccessType, _
"wstr",$lpszProxyName,"wstr",$lpszProxyBypass,"DWORD",$dwFlags)
if @error Or Not ($HINTERNET[0]) Then Return SetError(1,0,0)
Return SetError(0,0,$HINTERNET[0])
EndFunc
Func InternetCloseHandle($hInternet)
$BOOL = DllCall($Wininet,"BOOL","InternetCloseHandle","HANDLE",$hInternet)
if @error Or $BOOL[0] = 0 Then Return SetError(1,0,0)
Return SetError(0,0,$BOOL[0])
EndFunc
 

DownloadExample.au3

#include <WinAPI.au3>
#include <Memory.au3>
#include <ProgressConstants.au3>
#Include <GuiButton.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include "ASM_Download.au3"
#Include "GUICtrlSetOnEventEx.au3"
Global $Array
$controlID1 = DownloaderMultiFiles($Array,"http://www.swfmax.com/get/SWF.max.exe",@ScriptDir & "\Dir1\SWF.max.exe")
GUICtrlSetOnEventEx($controlID1,$BN_CLICKED,"Clicked_Pause_Buttons")
GUICtrlSetOnEventEx($controlID1 + 1,$BN_CLICKED,"Clicked_Cancel_Buttons")
$controlID2 = DownloaderMultiFiles($Array,"http://download.winzip.com/winzip150.exe",@ScriptDir & "\Dir1\winzip150.exe")
GUICtrlSetOnEventEx($controlID2,$BN_CLICKED,"Clicked_Pause_Buttons")
GUICtrlSetOnEventEx($controlID2 + 1,$BN_CLICKED,"Clicked_Cancel_Buttons")
;---------------------------Memory----------------------------------------------------------------------------------------------
$controlID3 = DownloaderMultiFiles($Array,"http://www.flash-swf-converter.com/downloads/swfconverter.exe","",True) ;True Memory
GUICtrlSetOnEventEx($controlID3,$BN_CLICKED,"Clicked_Pause_Buttons")
GUICtrlSetOnEventEx($controlID3 + 1,$BN_CLICKED,"Clicked_Cancel_Buttons")
;---------------------------Memory----------------------------------------------------------------------------------------------
$controlID4 = DownloaderMultiFiles($Array,"http://www.win-rar.com/fileadmin/winrar-versions/wrar420.exe",@ScriptDir & "\Dir2\wrar420.exe")
GUICtrlSetOnEventEx($controlID4,$BN_CLICKED,"Clicked_Pause_Buttons")
GUICtrlSetOnEventEx($controlID4 + 1,$BN_CLICKED,"Clicked_Cancel_Buttons")
$controlID5 = DownloaderMultiFiles($Array,"http://bookstore.ashrae.biz/journal/download.php?file=ASHRAE-D-AJ10Jan05-20091230.pdf",@ScriptDir & "\Dir2\20091230.pdf")
GUICtrlSetOnEventEx($controlID5,$BN_CLICKED,"Clicked_Pause_Buttons")
GUICtrlSetOnEventEx($controlID5 + 1,$BN_CLICKED,"Clicked_Cancel_Buttons")

While 1
ProgressLoop()
;---------------------------Memory----------------------------------------------
$DownlHandle = EnvGet(($controlID3 + 1))
$InfoArray = DownloadGetInfo($DownlHandle)
if Not @error Then
$Complete = $InfoArray[1]
if $Complete Then
Local $nBytes
$hLockData = $InfoArray[9]
$FileSize = $InfoArray[6]
;-----------------For Unknown Size --------------------------
$MemData = $InfoArray[10]
$FileSize = _MemGlobalSize($MemData)
;-----------------For Unknown Size --------------------------
$hFile = _WinAPI_CreateFile(@ScriptDir & "\Dir2\" & "Memory_swfconverter.exe",1)
_WinAPI_WriteFile($hFile,$hLockData,$FileSize,$nBytes)
_WinAPI_CloseHandle($hFile)
DownloadFreeHLockHandle($DownlHandle)
EndIf
EndIf
;---------------------------Memory----------------------------------------------
if CloseThreadLoop() Then
MsgBox(0,"Msg","ThreadClose")
ExitLoop
EndIf
WEnd
GUIDelete($Array[0][0])
$Array = 0
$controlID1 = DownloaderMultiFiles($Array,"http://www.swfmax.com/get/SWF.max.exe",@ScriptDir & "\Dir1\SWF.max.exe")
GUICtrlSetOnEventEx($controlID1,$BN_CLICKED,"Clicked_Pause_Buttons")
GUICtrlSetOnEventEx($controlID1 + 1,$BN_CLICKED,"Clicked_Cancel_Buttons")
$controlID2 = DownloaderMultiFiles($Array,"http://download.winzip.com/winzip150.exe",@ScriptDir & "\Dir1\winzip150.exe")
GUICtrlSetOnEventEx($controlID2,$BN_CLICKED,"Clicked_Pause_Buttons")
GUICtrlSetOnEventEx($controlID2 + 1,$BN_CLICKED,"Clicked_Cancel_Buttons")
;---------------------------Memory----------------------------------------------------------------------------------------------
$controlID3 = DownloaderMultiFiles($Array,"http://www.flash-swf-converter.com/downloads/swfconverter.exe","",True) ;True Memory
GUICtrlSetOnEventEx($controlID3,$BN_CLICKED,"Clicked_Pause_Buttons")
GUICtrlSetOnEventEx($controlID3 + 1,$BN_CLICKED,"Clicked_Cancel_Buttons")
;---------------------------Memory----------------------------------------------------------------------------------------------
$controlID4 = DownloaderMultiFiles($Array,"http://www.win-rar.com/fileadmin/winrar-versions/wrar420.exe",@ScriptDir & "\Dir2\wrar420.exe")
GUICtrlSetOnEventEx($controlID4,$BN_CLICKED,"Clicked_Pause_Buttons")
GUICtrlSetOnEventEx($controlID4 + 1,$BN_CLICKED,"Clicked_Cancel_Buttons")
$controlID5 = DownloaderMultiFiles($Array,"http://bookstore.ashrae.biz/journal/download.php?file=ASHRAE-D-AJ10Jan05-20091230.pdf",@ScriptDir & "\Dir2\20091230.pdf")
GUICtrlSetOnEventEx($controlID5,$BN_CLICKED,"Clicked_Pause_Buttons")
GUICtrlSetOnEventEx($controlID5 + 1,$BN_CLICKED,"Clicked_Cancel_Buttons")

While 1
ProgressLoop()
;---------------------------Memory----------------------------------------------
$DownlHandle = EnvGet(($controlID3 + 1))
$InfoArray = DownloadGetInfo($DownlHandle)
if Not @error Then
$Complete = $InfoArray[1]
if $Complete Then
Local $nBytes
$hLockData = $InfoArray[9]
$FileSize = $InfoArray[6]
;-----------------For Unknown Size --------------------------
$MemData = $InfoArray[10]
$FileSize = _MemGlobalSize($MemData)
;-----------------For Unknown Size --------------------------
$hFile = _WinAPI_CreateFile(@ScriptDir & "\Dir2\" & "Memory_swfconverter.exe",1)
_WinAPI_WriteFile($hFile,$hLockData,$FileSize,$nBytes)
_WinAPI_CloseHandle($hFile)
DownloadFreeHLockHandle($DownlHandle)
EndIf
EndIf
;---------------------------Memory----------------------------------------------
if CloseThreadLoop() Then
MsgBox(0,"Msg","ThreadClose")
ExitLoop
EndIf
WEnd

GUIDelete($Array[0][0])
$Array = 0
$controlID1 = DownloaderMultiFiles($Array,"http://msft.digitalrivercontent.net/win/X17-59463.iso",@ScriptDir & "\Dir1\X17-59463.iso")
GUICtrlSetOnEventEx($controlID1,$BN_CLICKED,"Clicked_Pause_Buttons")
GUICtrlSetOnEventEx($controlID1 + 1,$BN_CLICKED,"Clicked_Cancel_Buttons")
While 1
ProgressLoop()
if CloseThreadLoop() Then
MsgBox(0,"Msg","ThreadClose")
ExitLoop
EndIf
WEnd
Func Clicked_Pause_Buttons($ControlID,$NotificationCode)
$WPARAM = OnEventExGetWParam($ControlID,$NotificationCode)
$LPARAM = OnEventExGetLParam($ControlID,$NotificationCode)
$HWND = OnEventExGetHWND($ControlID,$NotificationCode)
For $i = 0 To UBound($Array) - 1
if $ControlID = $Array[$i][5] Then ExitLoop
Next
$Array[$i][9] = Not $Array[$i][9]
if ($Array[$i][9]) Then
GUICtrlSetData($ControlID,"Reset")
Else
GUICtrlSetData($ControlID,"Pause")
EndIf
$DownlHandle = EnvGet($ControlID)
DownloadReSetPause(Ptr($DownlHandle))
EndFunc
Func Clicked_Cancel_Buttons($ControlID,$NotificationCode)
$WPARAM = OnEventExGetWParam($ControlID,$NotificationCode)
$LPARAM = OnEventExGetLParam($ControlID,$NotificationCode)
$HWND = OnEventExGetHWND($ControlID,$NotificationCode)
$DownlHandle = EnvGet($ControlID)
DownloadCancel(Ptr($DownlHandle))
EndFunc
Func ProgressLoop()
Local $CompleteAll = False
For $i = 0 To UBound($Array) - 1
$ProgressTime = $Array[$i][8]
Sleep($ProgressTime)
$InfoArray = DownloadGetInfo($Array[$i][7])
if Not @error Then
$MemBool = $InfoArray[0]
$Complete = $InfoArray[1]
$MovePos = $InfoArray[5]
$FileSize = $InfoArray[6]
GUICtrlSetData($Array[$i][3],(100 / $FileSize) * $MovePos)
if ($MovePos) Then
if ($FileSize) Then
GUICtrlSetData($Array[$i][4],"( " & StringLeft(int($MovePos / 1024) / 1000 ,12) _
& " OF " & StringLeft(int($FileSize /1024) / 1000 ,12) & " ) MB")
Else
GUICtrlSetData($Array[$i][4],"( " & StringLeft(int($MovePos / 1024) / 1000 ,12) _
& " OF Unknown ) MB")
EndIf
Else
GUICtrlSetData($Array[$i][4],"( " & StringLeft(int($MovePos / 1024) / 1000 ,12) _
& " OF " & StringLeft(int($FileSize /1024) / 1000 ,12) & " ) MB")
EndIf
If ($Complete) Then
GUICtrlSetBkColor($Array[$i][4] - 2, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetBkColor($Array[$i][4], $GUI_BKCOLOR_TRANSPARENT)
if Not($MemBool) Then DownloadFreeHLockHandle($Array[$i][7])
Else
$CompleteAll = True
EndIf
EndIf
Next
Return $CompleteAll
EndFunc
Func DownloaderMultiFiles(ByRef $Array,$link,$FileName,$MemBool = False,$ProgressTime = 100)
if Not IsArray($Array) Then
Dim $Array[1][10]
$Array[0][0] = GUICreate("Downloader Progress", 785, 160, 5, 200, _
BitOR($WS_MINIMIZEBOX,$WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW _
,$WS_GROUP,$WS_BORDER,$WS_CLIPSIBLINGS))
GUISetState(@SW_SHOW)
Else
ReDim $Array[UBound($Array) + 1][10]
EndIf
If Not($MemBool) Then
$OutDir = StringSplit($FileName,"\")
if Not FileExists(StringTrimRight($FileName,StringLen($OutDir[$OutDir[0]]))) _
Then DirCreate(StringTrimRight($FileName,StringLen($OutDir[$OutDir[0]])))
$Array[UBound($Array) - 1][1] = $link
$Array[UBound($Array) - 1][2] = $FileName
GUICtrlCreateLabel(StringLeft($OutDir[$OutDir[0]],23), 10, 10 + ((UBound($Array) - 1) * 30), 170, 20, BitOR($SS_CENTER,$WS_BORDER))
Else
$Array[UBound($Array) - 1][1] = $link
GUICtrlCreateLabel("< [ Memory ] >", 10, 10 + ((UBound($Array) - 1) * 30), 170, 20, BitOR($SS_CENTER,$WS_BORDER))
EndIf
GUICtrlSetFont(-1, 10, 600, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xFFFFFF)
$Array[UBound($Array) - 1][3] = GUICtrlCreateProgress(190, 10 + ((UBound($Array) - 1) * 30), 200, 20)
$Array[UBound($Array) - 1][4] = GUICtrlCreateLabel("", 400, 10 + ((UBound($Array) - 1) * 30), 250, 20,BitOR($SS_CENTER,$WS_BORDER))
GUICtrlSetFont(-1, 10, 600, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xFFFFFF)
$Array[UBound($Array) - 1][5] = GUICtrlCreateButton("Pause", 655, 10 + ((UBound($Array) - 1) * 30), 60,20)
GUICtrlSetFont(-1, 10, 600, 0, "MS Sans Serif")
$Array[UBound($Array) - 1][6] = GUICtrlCreateButton("Cancel", 720, 10 + ((UBound($Array) - 1) * 30), 60,20)
GUICtrlSetFont(-1, 10, 600, 0, "MS Sans Serif")
$Array[UBound($Array) - 1][7]  = DownloadFile($Array[UBound($Array) - 1][1],30000,$MemBool,$Array[UBound($Array) - 1][2])
EnvSet($Array[UBound($Array) - 1][5],$Array[UBound($Array) - 1][7])
EnvSet($Array[UBound($Array) - 1][6],$Array[UBound($Array) - 1][7])
$Array[UBound($Array) - 1][8] = $ProgressTime
Return $Array[UBound($Array) - 1][5]
EndFunc
 

 

GUICtrlSetOnEventEx.au3

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $NotifyStruct = 0 , $TagNotifyStruct = ""
; GUICtrlSetOnEventEx($Control_ID_HWnd,$NotificationCode,$Function)
;$NotificationCode ==> (WM_COMMAND Notification Code And WM_NOTIFY Notification Code)
;$Function ==> ($ControlID,$NotificationCode) ; Return :Note use
Func GUICtrlSetOnEventEx($Control_ID_HWnd,$NotificationCode,$Function)
$handle = DLLCallbackRegister($Function,"none","int;int")
if $handle = 0 Then Return False
DllCallbackFree($handle)
if IsHWnd($Control_ID_HWnd) Then
$hWnd = $Control_ID_HWnd
$ControlID = DllCall("user32.dll", "int", "GetDlgCtrlID", "hwnd", $hWnd)
If @error Then Return False
$ControlID = $ControlID[0]
if Not ($ControlID) Then Return False
Else
$ControlID = $Control_ID_HWnd
$hWnd = GUICtrlGetHandle($ControlID)
if Not IsHWnd($hWnd) Then Return False
EndIf
$iNotificationCode = $NotificationCode
if StringInStr($NotificationCode,"-") Then _
$iNotificationCode = StringReplace($NotificationCode,"-","A")
if Not IsDllStruct($NotifyStruct) Then
Local $count = 1
$Len = StringLen($Function)
$TagNotifyStruct = _
"int count;WPARAM WPARAM;LPARAM LPARAM;int Test;int " & String($hWnd & $iNotificationCode) &  _
";HWND HWND" & String($count) &  ";int ControlID" & String($count) & ";int NotificationCode" & _
String($count) & ";char Function" & String($count) & "[" & String($Len) & "]"
$NotifyStruct = DllStructCreate($TagNotifyStruct)
DllStructSetData($NotifyStruct,"count",$count)
DllStructSetData($NotifyStruct,String($hWnd & $iNotificationCode),$count)
DllStructSetData($NotifyStruct,"HWND" & String($count),$hWnd)
DllStructSetData($NotifyStruct,"ControlID" & String($count),$ControlID)
DllStructSetData($NotifyStruct,"NotificationCode" & String($count),$NotificationCode)
DllStructSetData($NotifyStruct,"Function" & String($count),$Function)
Else
$count = DllStructGetData($NotifyStruct,String($hWnd & $iNotificationCode))
if ($count) Then Return False
Local $count = DllStructGetData($NotifyStruct,"count") + 1
$Len = StringLen($Function)
$TagNotifyStruct &= _
";int " & String($hWnd & $iNotificationCode) & ";HWND HWND" & String($count) & _
";int NotificationCode" & String($count) & ";int ControlID" & String($count) & _
";char Function" & String($count) & "[" & String($Len) & "]"
$iLength = DllStructGetSize($NotifyStruct)
$iNotifyStruct = DllStructCreate($TagNotifyStruct)
DllCall("kernel32.dll","none","RtlMoveMemory","ptr",DllStructGetPtr($iNotifyStruct) _
,"ptr",DllStructGetPtr($NotifyStruct),"ulong_ptr",$iLength)
$NotifyStruct = $iNotifyStruct
DllStructSetData($NotifyStruct,"count",$count)
DllStructSetData($NotifyStruct,String($hWnd & $iNotificationCode),$count)
DllStructSetData($NotifyStruct,"HWND" & String($count),$hWnd)
DllStructSetData($NotifyStruct,"ControlID" & String($count),$ControlID)
DllStructSetData($NotifyStruct,"NotificationCode" & String($count),$NotificationCode)
DllStructSetData($NotifyStruct,"Function" & String($count),$Function)
EndIf
GUIRegisterMsg($WM_NOTIFY,"OnEventExProc")
GUIRegisterMsg($WM_COMMAND,"OnEventExProc")
Return True
EndFunc
Func OnEventExProc($hWnd,$Msg,$wParam,$lParam)
Select
Case $Msg = $WM_NOTIFY
Local $OnEventExtagNMHDR = "hwnd hWndFrom;uint_ptr IDFrom;INT Code"
$tNMHDR = DllStructCreate($OnEventExtagNMHDR, $lParam)
$MsgHwnd = DllStructGetData($tNMHDR, "hWndFrom")
$MsgCode = DllStructGetData($tNMHDR, "Code")
Case $Msg = $WM_COMMAND
$MsgHwnd = $lParam
$MsgCode = BitShift($wParam, 16)
EndSelect
$iMsgCode = $MsgCode
if StringInStr($MsgCode,"-") Then _
$iMsgCode = StringReplace($MsgCode,"-","A")
$count = DllStructGetData($NotifyStruct,String($MsgHwnd & $iMsgCode))
if Not ($count) Then Return $GUI_RUNDEFMSG
DllStructSetData($NotifyStruct,"WPARAM",$wParam)
DllStructSetData($NotifyStruct,"LPARAM",$lParam)
$OnEvHWND = DllStructGetData($NotifyStruct,"HWND" & String($count))
$ControlID = DllStructGetData($NotifyStruct,"ControlID" & String($count))
$OnEvNotificationCode = DllStructGetData($NotifyStruct,"NotificationCode" & String($count))
$OnEvFunction = DllStructGetData($NotifyStruct,"Function" & String($count))
DllStructSetData($NotifyStruct,"Test",1)
if ($MsgHwnd = $OnEvHWND And $MsgCode = $OnEvNotificationCode) Then _
Call($OnEvFunction,$ControlID,$OnEvNotificationCode)
DllStructSetData($NotifyStruct,"Test",0)
Return $GUI_RUNDEFMSG
EndFunc
Func OnEventExGetWParam($ControlID,$NotificationCode)
$Test = DllStructGetData($NotifyStruct,"Test")
if Not ($Test) Then Return False
$hWnd = GUICtrlGetHandle($ControlID)
if Not IsHWnd($hWnd) Then Return False
$iNotificationCode = $NotificationCode
if StringInStr($NotificationCode,"-") Then _
$iNotificationCode = StringReplace($NotificationCode,"-","A")
$count = DllStructGetData($NotifyStruct,String($hWnd & $iNotificationCode))
if Not ($count) Then Return False
Return DllStructGetData($NotifyStruct,"WPARAM")
EndFunc
Func OnEventExGetLParam($ControlID,$NotificationCode)
$Test = DllStructGetData($NotifyStruct,"Test")
if Not ($Test) Then Return False
$hWnd = GUICtrlGetHandle($ControlID)
if Not IsHWnd($hWnd) Then Return False
$iNotificationCode = $NotificationCode
if StringInStr($NotificationCode,"-") Then _
$iNotificationCode = StringReplace($NotificationCode,"-","A")
$count = DllStructGetData($NotifyStruct,String($hWnd & $iNotificationCode))
if Not ($count) Then Return False
Return DllStructGetData($NotifyStruct,"LPARAM")
EndFunc
Func OnEventExGetHWND($ControlID,$NotificationCode)
$Test = DllStructGetData($NotifyStruct,"Test")
if Not ($Test) Then Return False
$hWnd = GUICtrlGetHandle($ControlID)
if Not IsHWnd($hWnd) Then Return False
$iNotificationCode = $NotificationCode
if StringInStr($NotificationCode,"-") Then _
$iNotificationCode = StringReplace($NotificationCode,"-","A")
$count = DllStructGetData($NotifyStruct,String($hWnd & $iNotificationCode))
if Not ($count) Then Return False
Return DllStructGetData($NotifyStruct,"HWND" & String($count))
EndFunc
 
Edited by wolf9228
1 person likes this

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Wow thank you!
I was looking for a method how to read a web page into a variable without having to stop the loop.
If that's what you offer (that's what I understood) then I'm giving you a big thanks!

Edited by gil900

Share this post


Link to post
Share on other sites

Wow thank you!

I was looking for a method how to read a web page into a variable without having to stop the loop.

If that's what you offer (that's what I understood) then I'm giving you a big thanks!

 

Yes, this is really what I am doing in this project, thank you very much gil900  :bye: 

 


صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites

I'm hoping someone might outline it's purpose.

 

Hello thank you for the compliment greeting :bye:

3 people like this

صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

The code looks almost like obfuscated code without obfuscation and it works.

can you please give example how to read this test page:

https://googledrive.com/host/0B-dsGBArc-IuVHdIRFFyUV8xSXc/host-in-drive.html

into a variable without stopping the loop?

 

Thanks

Edited by gil900

Share this post


Link to post
Share on other sites

This can be very useful for some projects. Thanks for sharing.


When the words fail... music speaks

Share this post


Link to post
Share on other sites

Wonderful brother :) 

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I can not see where it is Exit from the Thread(that created with CreateThread) in your example

Does the function DownloadFreeHLockHandle closes also the thread ?

Do I need to call ExitThread or DownloadFreeHLockHandle  is enough?

From what I read, I can't see how DownloadFreeHLockHandle is close the thread

Edited by gil900

Share this post


Link to post
Share on other sites

I can not see where it is Exit from the Thread(that created with CreateThread) in your example

Does the function DownloadFreeHLockHandle closes also the thread ?

Do I need to call ExitThread or DownloadFreeHLockHandle  is enough?

From what I read, I can't see how DownloadFreeHLockHandle is close the thread

 

To stop the thread loop use The DownloadCancel($DownlHandle) Function

To Close the thread use The DownloadFreeHLockHandle Function

The thread closure by _WinAPI_CloseHandle Function

Thank you :)




صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Thank you.
What do you fixed or improved in the new UDF?

I made a few adjustments to the old UDF. I deleted the option to download directly to disk (because I do not need it), and I also did some syntax optimizations which will make the code run faster.

I also added the function (I wrote)
ASM_ReturnData($hLockHandle)

That what it does is to return the downloaded information(in the memory) directly to a normal variable.

Feel free to look

ASM_Download_gil900.rar

Some questions and issues:

1) What is the purpose of $BytesAtaTime ?

2) The Function fail to download pages when it unable to know the size of the page/file ( HttpQueryInfo($HIntOpenUrl, 5) is fail to get the size when the size is unknown).

with files it usually works but not with webpags..

I do not must it will work also with normal website(file with an unknown size) (I use it to load a file into memory)
But it would be better if it will work also with a file with an unknown size because then I can use it for other purposes
:)

Edited by gil900

Share this post


Link to post
Share on other sites

Thank you.

What do you fixed or improved in the new UDF?

I made a few adjustments to the old UDF. I deleted the option to download directly to disk (because I do not need it), and I also did some syntax optimizations which will make the code run faster.

I also added the function (I wrote) ASM_ReturnData($hLockHandle)

That what it does is to return the downloaded information(in the memory) directly to a normal variable.

Feel free to look

ASM_Download_gil900.rar

Some questions and issues:

1) What is the purpose of $BytesAtaTime ?

2) The Function fail to download pages when it unable to know the size of the page/file ( HttpQueryInfo($HIntOpenUrl, 5) is fail to get the size when the size is unknown).

with files it usually works but not with webpags..

I do not must it will work also with normal website(file with an unknown size) (I use it to load a file into memory)

But it would be better if it will work also with a file with an unknown size because then I can use it for other purposes :)

 

What is the purpose of $BytesAtaTime ?

By variable you can determine the size of readable data each time call the InternetReadFile function during Loops

The project has been developed ... Thanks. :)


صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Thank you. :)
But I decided at the end to use
  >WinHTTP UDF

Because that although the download is done in another thread, it still causes my GUI to freeze for about 2 - 4.3 seconds(I tested it also with the original UDF) so eventually I get about the same as I get in much more documented and tested UDF.

Sory but I really appreciate your hard work!!

Edited by gil900

Share this post


Link to post
Share on other sites

Thank you. :)

But I decided at the end to use  >WinHTTP UDF

Because that although the download is done in another thread, it still causes my GUI to freeze for about 2 - 4.3 seconds(I tested it also with the original UDF) so eventually I get about the same as I get in much more documented and tested UDF.

Sory but I really appreciate your hard work!!

 

Thank you :bye:


صرح السماء كان هنا

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now