News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Winhttp asynchronous

Started by TouEnMasm, August 25, 2021, 05:46:10 PM

Previous topic - Next topic

TouEnMasm

Hello,
This time ,it's fully tested and must be in the very few number of samples who works in asynchronous mode (There is only  a few c++ existing and working)
The sample will give a full information of what is happened in the callback and save the result in download .htm and made a report.
in the screen and in rapport.txt.
The exe accept command line parameters or batch (see check.bat).
The source need /safeseh to work without too many problems
Winhttp errors and HTTP_status are reported,the WINHTTP_CALLBACK_STATUS_REQUEST_ERROR give now an answer in text and give valuable informations .
Use JWASM to compile (/safeseh)

Quote
HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Date: Wed, 25 Aug 2021 07:06:12 GMT
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8
Expires: Wed, 25 Aug 2021 07:05:12 GMT
P3P: CP="NON UNI COM NAV STA LOC CURa DEVa PSAa PSDa OUR IND"
Set-Cookie: MUID=3FA559A961F86FB23B394937604C6ED6; domain=.bing.com; expires=Mon, 19-Sep-2022 07:06:12 GMT; path=/
Set-Cookie: MUIDB=3FA559A961F86FB23B394937604C6ED6; expires=Mon, 19-Sep-2022 07:06:12 GMT; path=/; HttpOnly
Set-Cookie: _EDGE_S=F=1&SID=2AC07C33CB67613A17F96CADCAD3607A; domain=.bing.com; path=/; HttpOnly
Set-Cookie: _EDGE_V=1; domain=.bing.com; expires=Mon, 19-Sep-2022 07:06:12 GMT; path=/; HttpOnly
Set-Cookie: SRCHD=AF=NOFORM; domain=.bing.com; expires=Mon, 19-Sep-2022 07:06:12 GMT; path=/
Set-Cookie: SRCHUID=V=2&GUID=135D188FB00C49DA9E193E214FB23495&dmnchg=1; domain=.bing.com; expires=Mon, 19-Sep-2022 07:06:12 GMT; path=/
Set-Cookie: SRCHUSR=DOB=20210825; domain=.bing.com; expires=Mon, 19-Sep-2022 07:06:12 GMT; path=/
Set-Cookie: SRCHHPGUSR=SRCHLANG=fr; domain=.bing.com; expires=Mon, 19-Sep-2022 07:06:12 GMT; path=/
Set-Cookie: _SS=SID=2AC07C33CB67613A17F96CADCAD3607A; domain=.bing.com; path=/
X-SNR-Routing: 1
X-Cache: CONFIG_NOCACHE
X-MSEdge-Ref: Ref A: DFC8A63D54344001AF7071FB13997BE4 Ref B: PRAEDGE0919 Ref C: 2021-08-25T07:06:12Z




Fa is a musical note to play with CL

bomz

invoke GetStdHandle,STD_ERROR_HANDLE or STD_OUTPUT_HANDLE

you need not only download http://www.bing.com/search?q=useragent but run scripts to get reaserch result
so you need offline browser, not console download manager

"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --headless --disable-gpu --dump-dom !_url!

IEInspector HTTP Analyzer

Quote(Request-Line):GET /search?q=useragent HTTP/1.1
Host:www.bing.com
Connection:keep-alive
Upgrade-Insecure-Requests:1
User-Agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Sec-Fetch-Site:none
Sec-Fetch-Mode:navigate
Sec-Fetch-User:?1
Sec-Fetch-Dest:document
sec-ch-ua:"Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"
sec-ch-ua-mobile:?0
sec-ch-ua-full-version:"92.0.4515.159"
sec-ch-ua-arch:"x86"
sec-ch-ua-platform:"Windows"
sec-ch-ua-platform-version:"6.1"
sec-ch-ua-model:""
Accept-Language:ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7
Cookie:MUID=18AA8E6567076A4D1F349E7363076CE2; MUIDB=18AA8E6567076A4D1F349E7363076CE2; SRCHD=AF=NOFORM; SRCHUID=V=2&GUID=77633CDE97564DB784A4C09CA0A6AC5E&dmnchg=1; _EDGE_S=SID=16E5C2E8E4AA65102E1CD276E5B464B7; _SS=SID=16E5C2E8E4AA65102E1CD276E5B464B7; ABDEF=V=13&ABDV=13&MRNB=1629885620684&MRB=0; SRCHUSR=DOB=20210823&T=1629885627000&TPC=1629885622000; SRCHHPGUSR=SRCHLANG=ru&BRW=M&BRH=M&CW=1280&CH=881&SW=1280&SH=1024&DPR=1&UTC=420&DM=0&WTS=63765482427&HV=1629885624; ipv6=hit=1629889223847&t=4
Accept-Encoding:gzip, deflate

TouEnMasm


Problem is simple,in synchronous it work without problem.
In asynchronous ,instead of receive data i receive a header with no interest.
How can this be changed ?
Fa is a musical note to play with CL

bomz

may be no-redirect. analyze what your application do with traffic analyzer, it help find big part of mistakes

interesting if http redirect to https flag secure change or not

bomz

[ebx].REQUEST_CONTEXT.SessionHandle
cool. I always forget how use assume

bomz

how you want decide problem http to https redirection?
how change this flag WINHTTP_FLAG_SECURE ?

LiaoMi

Quote from: TouEnMasm on August 25, 2021, 05:46:10 PM
Hello,
This project need to be verify.
There is no bug,no failed (very easy to do in asynchronous mode).
The sample will give a full information of what is happened in the callback and save the result in donnload .htm
The exe accept command line parameters or batch (see check.bat).
At the instant,I get very usefull informations from the server like this one below.
Need help to establish a correct dialog with the server
The source need /safeseh to work without too many problems

Quote
HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Date: Wed, 25 Aug 2021 07:06:12 GMT
Transfer-Encoding: chunked
Content-Type: text/html; charset=utf-8
Expires: Wed, 25 Aug 2021 07:05:12 GMT
P3P: CP="NON UNI COM NAV STA LOC CURa DEVa PSAa PSDa OUR IND"
Set-Cookie: MUID=3FA559A961F86FB23B394937604C6ED6; domain=.bing.com; expires=Mon, 19-Sep-2022 07:06:12 GMT; path=/
Set-Cookie: MUIDB=3FA559A961F86FB23B394937604C6ED6; expires=Mon, 19-Sep-2022 07:06:12 GMT; path=/; HttpOnly
Set-Cookie: _EDGE_S=F=1&SID=2AC07C33CB67613A17F96CADCAD3607A; domain=.bing.com; path=/; HttpOnly
Set-Cookie: _EDGE_V=1; domain=.bing.com; expires=Mon, 19-Sep-2022 07:06:12 GMT; path=/; HttpOnly
Set-Cookie: SRCHD=AF=NOFORM; domain=.bing.com; expires=Mon, 19-Sep-2022 07:06:12 GMT; path=/
Set-Cookie: SRCHUID=V=2&GUID=135D188FB00C49DA9E193E214FB23495&dmnchg=1; domain=.bing.com; expires=Mon, 19-Sep-2022 07:06:12 GMT; path=/
Set-Cookie: SRCHUSR=DOB=20210825; domain=.bing.com; expires=Mon, 19-Sep-2022 07:06:12 GMT; path=/
Set-Cookie: SRCHHPGUSR=SRCHLANG=fr; domain=.bing.com; expires=Mon, 19-Sep-2022 07:06:12 GMT; path=/
Set-Cookie: _SS=SID=2AC07C33CB67613A17F96CADCAD3607A; domain=.bing.com; path=/
X-SNR-Routing: 1
X-Cache: CONFIG_NOCACHE
X-MSEdge-Ref: Ref A: DFC8A63D54344001AF7071FB13997BE4 Ref B: PRAEDGE0919 Ref C: 2021-08-25T07:06:12Z


Hi TouEnMasm,

Windows7_SDK_x64
:arrow_down:

bomz

MSDN say 12175 error get more information from callback function
how interpret this number 246FD64 ?
Quote
   Аh\Л Internet Status: 10000 Data: 246FD64
12175

TouEnMasm

LiaoMi  :thumbsup:
QuoteMany thanks for the samples in c
bomz
Quotehow interpret this number 246FD64 ?
use the GetWinHttpError function given in the source code.

I suspect that the winhttp need a proxy to work https://docs.microsoft.com/en-us/archive/msdn-magazine/2008/august/windows-with-c-asynchronous-winhttp
I will study all that and hope to get an answer
Fa is a musical note to play with CL

bomz

your internal GetWinHttpError function return 12175, winhttpcallback back 4 bytes - 246FD64h  (38206820), which more look like part of some text string

TouEnMasm


An error can be describe in winerror.h in decimal or hexadecimal value (just to made things more simple !)
I get L'identificateur de pool de média ne représente pas un pool de média valide.     (2F8F = 12175)
BAD MEDIA



Fa is a musical note to play with CL

bomz

QuoteERROR_WINHTTP_SECURE_FAILURE

12175

One or more errors were found in the Secure Sockets Layer (SSL) certificate sent by the server. To determine what type of error was encountered, check for a WINHTTP_CALLBACK_STATUS_SECURE_FAILURE notification in a status callback function. For more information, see WINHTTP_STATUS_CALLBACK.

TouEnMasm

Finally found a bad use of the WINHTTP_CALLBACK_STATUS_HEADERS_AVAILABLE event.
The WinHttpQueryHeaders function can do manything like download the headers .
The good answer is to just get the informations he give and let's go.
Further macro had been added to simplify the code.
I have updated the source in the first post
Fa is a musical note to play with CL

TouEnMasm

The macro to enter a crical section nee to be modify :

;*******************************************************************
CSER MACRO fonction:REQ,parameters:VARARG
local etiquette
change CATSTR <">,<fonction>,<",0>
.data
etiquette db change
.code
@@:
invoke TryEnterCriticalSection,addr CriticalSection ;------- +1
.if eax == 1
invoke fonction,parameters
.if eax==0
.if dword ptr [phrase] != 0
invoke printf,addr phrase
.endif
invoke GetWinHttpError,addr etiquette
mov hr,0
.else
mov hr,eax
.endif
invoke LeaveCriticalSection,addr CriticalSection ;------ -1 ,always 0 like that
.else
;inc echecenter
invoke Sleep,10
jmp @B
.endif
EXITM <>
ENDM
;*******************************************************************

The TryEnterCriticalSection function give a better stabiity.The Number of failed to enter are beetween 0,2 .

The WINHTTP_CALLBACK_STATUS_REQUEST_ERROR event need also a modify:
add this line at the end : invoke SetEvent,Hevent <<<<<< stop the wait loop
This is needed when a site don't accept the http  (I have try it on my site)

STATUS_REQUEST_ERROR                  <<<< coming from  WINHTTP_CALLBACK_STATUS_REQUEST_ERROR  event
ERROR_WINHTTP_INVALID_SERVER_RESPONSE        <<<<<<<< the fault
<Status:Request error exit
Ha Status: sendrequest complete
WinHttpQueryDataAvailableERROR_WINHTTP_INCORRECT_HANDLE_STATE
<Ha Status: sendrequest complete
Nombre Echec critical :0
Status: Handle Closing
Status: Handle Closing


In the init proc,change LeaveCriticalSection by DeleteCriticalSection

Fa is a musical note to play with CL

TouEnMasm


Added the redirect event who allow to download all url.
added the report for the HTTP_STATUS.

Fa is a musical note to play with CL