[HELP] Invoke InternetReadFile API

Iniciado por Swellow, 6 Noviembre 2011, 22:17 PM

0 Miembros y 1 Visitante están viendo este tema.

Swellow

I've tried almost everything to Invoke that API and I always failed...

I suceed with InternetOpen/InternetOpelUrl/InternetCloseHandle but not that one :/

Private Declare Function InternetReadFile Lib "wininet.dll" (ByVal hFile As Long, ByVal lpBuffer As String, ByVal dwNumberOfBytesToRead As Long, lNumberOfBytesRead As Long) As Integer

        bDoLoop = InternetReadFile(hInternetOpen, strArray, Len(strArray), lNumberOfBytes)


Can anyone help please?

BlackZeroX

.
Código (vb) [Seleccionar]


Const scUserAgent = "API-Guide test program"
Const INTERNET_OPEN_TYPE_DIRECT = 1
Const INTERNET_OPEN_TYPE_PROXY = 3
Const INTERNET_FLAG_RELOAD = &H80000000
Const sURL = "http://www.microsoft.com/index.htm"
Private Declare Function InternetOpen Lib "wininet" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Private Declare Function InternetCloseHandle Lib "wininet" (ByRef hInet As Long) As Long
Private Declare Function InternetReadFile Lib "wininet" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
Private Declare Function InternetOpenUrl Lib "wininet" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long
Private Sub Form_Load()
    'KPD-Team 1999
    'URL: http://www.allapi.net/
    'E-Mail: KPDTeam@Allapi.net

    Dim hOpen As Long, hFile As Long, sBuffer As String, Ret As Long
    'Create a buffer for the file we're going to download
    sBuffer = Space(1000)
    'Create an internet connection
    hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
    'Open the url
    hFile = InternetOpenUrl(hOpen, sURL, vbNullString, ByVal 0&, INTERNET_FLAG_RELOAD, ByVal 0&)
    'Read the first 1000 bytes of the file
    InternetReadFile hFile, sBuffer, 1000, Ret
    'clean up
    InternetCloseHandle hFile
    InternetCloseHandle hOpen
    'Show our file
    MsgBox sBuffer
End Sub



http://allapi.mentalis.org/apilist/InternetReadFile.shtml

Dulces Lunas!¡.
The Dark Shadow is my passion.

Swellow

Thanks for your answer man but its not that that I want. I want to Invoke the API using CallAPIByName.

x64core

Cita de: Swellow en  6 Noviembre 2011, 22:44 PM
Thanks for your answer man but its not that that I want. I want to Invoke the API using CallAPIByName.

which callApibyname use?

Swellow


x64core

made several cobein  :-\
specify link or the code

BlackZeroX

#6
.
I do not see the problem.

for more information: http://msdn.microsoft.com/en-us/library/windows/desktop/aa385103%28v=vs.85%29.aspx

prototype:
Código (Vb) [Seleccionar]

Public Function CallAPIByName(ByVal sLib As String, ByVal sMod As String, ParamArray Params()) As Long


API to Call

Código (cpp) [Seleccionar]


BOOL InternetReadFile(
  __in   HINTERNET hFile,
  __out  LPVOID lpBuffer,
  __in   DWORD dwNumberOfBytesToRead,
  __out  LPDWORD lpdwNumberOfBytesRead
);

Requirements

Minimum supported client Windows 2000 Professional
Minimum supported server Windows 2000 Server
Header Wininet.h
Library Wininet.lib
DLL Wininet.dll



Código (vb) [Seleccionar]


dim hFile as long
dim bBuff(0 to 999) as byte ' lpBuffer = varptr(bBuff(0))
dim dwNumberOfBytesToRead as long
dim lpdwNumberOfBytesRead as long
dim bRes as boolean

dwNumberOfBytesToRead = 1000
bRes = callapybyname("wininet", "InternetReadFile", hFile, varptr(bBuff(0)), dwNumberOfBytesToRead, varptr(lpdwNumberOfBytesRead) )



Dulces Lunas!¡.
The Dark Shadow is my passion.

BlackZeroX

#7
Example FULL:

Código (vb) [Seleccionar]


Option Explicit

Const scUserAgent = "UserAngent InfraExplorer Plugin."
Const INTERNET_OPEN_TYPE_DIRECT = 1
Const INTERNET_OPEN_TYPE_PROXY = 3
Const INTERNET_FLAG_RELOAD = &H80000000
Const sURL = "http://infrangelux.sytes.net/ScanX/?ip=www.google.com.mx&port=80&nohtml=3"

Private Sub Form_Load()
    Dim hOpen       As Long
    Dim hFile       As Long
    Dim bBuffer()   As Byte
    Dim Ret         As Long
    ReDim bBuffer(0 To 0)
    hOpen = lCallApiByName("wininet", "InternetOpenW", StrPtr(scUserAgent), INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0)
    hFile = lCallApiByName("wininet", "InternetOpenUrlW", hOpen, StrPtr(sURL), 0, 0, INTERNET_FLAG_RELOAD, 0)
    Call lCallApiByName("wininet", "InternetReadFile", hFile, VarPtr(bBuffer(0)), 1, VarPtr(Ret))
    Call lCallApiByName("wininet", "InternetCloseHandle", hFile)
    Call lCallApiByName("wininet", "InternetCloseHandle", hOpen)
    MsgBox IIf(Val(StrConv(bBuffer, vbUnicode)) = 1, "Port Enabled", "Port Disabled")
End Sub



Dulces Lunas!¡.
The Dark Shadow is my passion.

Swellow

#8
@BlackZeroX (Astaroth)
Thanks a lot man!