Galapo
Members-
Posts
10 -
Joined
-
Last visited
Profile Information
-
WWW
http://galapo.boot-land.net
Galapo's Achievements
Seeker (1/7)
0
Reputation
-
libcurl.au3 "certificate verify failed"
Galapo replied to Galapo's topic in AutoIt General Help and Support
Hi zorphnog, Thanks indeed for that! I just tested and the function is now working for the server I was having troubles with. So the idea is to convert the value to hex for use within the AutoIt function. Finally I get the idea of how these dll calls work. Thanks again, Galapo. -
With the _DllCallBack function comes the handy libcurl.au3 to handle dll calls to the cURL libcurl.dll. Running the function on sites with an invalid certificate produces an error: "error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed". Using curl.exe from the commandline and specifying to turn off certificate validation allows for successful downloading, eg 'curl.exe -k https://o.aolcdn.com -o output.txt'. The documentation says that the same is possible also with libcurl.dll, ie with a call like curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE). My question is, how might we go about this with with the AutoIt function and is it possible? #include "DllCallBack.au3" ; From libcurl headers Global Const $CURLOPT_URL = 0x2712 Global Const $CURLOPT_WRITEDATA = 0x2711 Global Const $CURLOPT_WRITEFUNCTION = 0x4E2B Global Const $CURLOPT_PROGRESSFUNCTION = 0x4E58 Global Const $CURLOPT_NOPROGRESS = 0x2B Global Const $CURLOPT_ERRORBUFFER = 0x271A Global Const $CURLOPT_TRANSFERTEXT = 0x35 Global Const $CURL_ERROR_SIZE = 0x100 ; Load and initialize curl $hDll_LibCurl = DllOpen("libcurl.dll") $hCurlHandle = DllCall($hDll_LibCurl, "ptr:cdecl", "curl_easy_init") $hCurlHandle = $hCurlHandle[0] ; Register Callback function's ; typedef int (*curl_progress_callback)(void *clientp,double dltotal,double dlnow,double ultotal,double ulnow); $pProgress = _DllCallBack ("_Progress", "ptr;double;double;double;double",$_DllCallBack_Cdecl) ; size_t function( void *ptr, size_t size, size_t nmemb, void *stream); $pWriteFunc = _DllCallBack ("_WriteFunc", "ptr;uint;uint;ptr",$_DllCallBack_Cdecl) ; Create a buffer for error messages and Url $CURL_ERROR = DllStructCreate("char[" & $CURL_ERROR_SIZE + 1 & "]") $URL = DllStructCreate("char[256]") DllStructSetData($URL, 1, "https://o.aolcdn.com") ; Setup Task ;DllCall($hDll_LibCurl, "uint:cdecl", "curl_easy_setopt", "ptr", $hCurlHandle, "uint", $CURLOPT_TRANSFERTEXT, "int", 1) DllCall($hDll_LibCurl, "uint:cdecl", "curl_easy_setopt", "ptr", $hCurlHandle, "uint", $CURLOPT_URL, "ptr", DllStructGetPtr($URL)) DllCall($hDll_LibCurl, "uint:cdecl", "curl_easy_setopt", "ptr", $hCurlHandle, "uint", $CURLOPT_NOPROGRESS, "int", 0) DllCall($hDll_LibCurl, "uint:cdecl", "curl_easy_setopt", "ptr", $hCurlHandle, "uint", $CURLOPT_PROGRESSFUNCTION, "ptr", $pProgress) DllCall($hDll_LibCurl, "uint:cdecl", "curl_easy_setopt", "ptr", $hCurlHandle, "uint", $CURLOPT_WRITEFUNCTION, "ptr", $pWriteFunc) DllCall($hDll_LibCurl, "uint:cdecl", "curl_easy_setopt", "ptr", $hCurlHandle, "uint", $CURLOPT_ERRORBUFFER, "ptr", DllStructGetPtr($CURL_ERROR)) ; Perform task Global $g_nTimer = TimerInit(), $g_hFileOut = FileOpen("libcurl_dummy",2+16) ProgressOn("Downloading", "") $nPerform = DllCall($hDll_LibCurl, "uint:cdecl", "curl_easy_perform", "ptr", $hCurlHandle) $nPerform = $nPerform[0] If $nPerform <> 0 Then ; libcurl reported an error ConsoleWrite("! " & DllStructGetData($CURL_ERROR, 1) & @CRLF) EndIf ; The progress function which gets called Func _Progress($clientp, $dltotal, $dlnow, $ultotal, $ulnow) If TimerDiff($g_nTimer) > 250 Then ProgressSet($dlnow / $dltotal * 100, StringFormat("%.2fKb (%.1f%%)", $dlnow / 1024, $dlnow / $dltotal * 100)) $g_nTimer = TimerInit() EndIf Return 0 ; Continue EndFunc ;==>_Progress ; This Callback function recieves the data downloaded Func _WriteFunc ($ptr,$nSize,$nMemb,$pStream) Local $vData = DllStructCreate ("byte[" & $nSize*$nMemb & "]",$ptr) FileWrite($g_hFileOut,DllStructGetData($vData,1)) Return $nSize*$nMemb EndFunc ; Cleanup ProgressOff() FileClose($g_hFileOut) DllCall($hDll_LibCurl, "none:cdecl", "curl_easy_cleanup", "ptr", $hCurlHandle) $URL = 0 $CURL_ERROR = 0 _DllCallBack_Free ($pProgress) _DllCallBack_Free ($pWriteFunc) Thanks, Galapo.
-
For completeness, answer to the above question is provided here: http://www.autoitscript.com/forum/index.php?showtopic=70679 Regards, Galapo.
-
A slight adjustment for my purposes: Global Const $EDS_RAWMODE = 0x2 Dim $DEVMODE, $DllRet, $enum = 0 $DEVMODE = DllStructCreate("char dmDeviceName[32];ushort dmSpecVersion;ushort dmDriverVersion;short dmSize;" & _ "ushort dmDriverExtra;dword dmFields;short dmOrientation;short dmPaperSize;short dmPaperLength;" & _ "short dmPaperWidth;short dmScale;short dmCopies;short dmDefaultSource;short dmPrintQuality;" & _ "short dmColor;short dmDuplex;short dmYResolution;short dmTTOption;short dmCollate;" & _ "byte dmFormName[32];dword dmBitsPerPel;int dmPelsWidth;dword dmPelsHeight;" & _ "dword dmDisplayFlags;dword dmDisplayFrequency") DllStructSetData($DEVMODE, "dmSize", DllStructGetSize($DEVMODE)) Do $DllRet = DllCall("user32.dll", "int", "EnumDisplaySettingsEx", "ptr", 0, "dword", $enum, _ "ptr", DllStructGetPtr($DEVMODE), "dword", 0) $DllRet = $DllRet[0] $enum += 1 ConsoleWrite("Width = " & DllStructGetData($DEVMODE, "dmPelsWidth") / 65536 & " " & _ "Height = " & DllStructGetData($DEVMODE, "dmPelsHeight") / 65536 & " " & _ "Bits = " & DllStructGetData($DEVMODE, "dmBitsPerPel") / 65536 & " " & _ "Frequency = " & DllStructGetData($DEVMODE, "dmDisplayFrequency") / 65536 & @CRLF) Until $DllRet = 0 $DEVMODE = 0 Thanks again for your help with this! Regards, Galapo.
-
Looking back, I think I inadvertently posted a request in the wrong area here. Hopefully this is now in a more appropriate area. To repeat my request: Does anyone know how to modify the monitor info code by fisofo to retreive an array of supported resolutions rather than the current display? ; modified by fisofo ; Last Modified: Jan 20, 2007 Global Const $DISPLAY_DEVICE_ATTACHED_TO_DESKTOP = 0x00000001 Global Const $DISPLAY_DEVICE_MULTI_DRIVER = 0x00000002 Global Const $DISPLAY_DEVICE_PRIMARY_DEVICE = 0x00000004 Global Const $DISPLAY_DEVICE_MIRRORING_DRIVER = 0x00000008 Global Const $DISPLAY_DEVICE_ACTIVE = 0x00000001 Global Const $DISPLAY_DEVICE_ATTACHED = 0x00000002 Global Const $ENUM_CURRENT_SETTINGS = -1 Global Const $ENUM_REGISTRY_SETTINGS = -2 Global Const $MONITORINFO = "int;int[4];int[4];int" Global Const $RECT = "long;long;long;long" Global Const $DEVMODE = "byte[32];short;short;short;short;int;int[2];int;int" & _ ";short;short;short;short;short;byte[32]" & _ ";short;ushort;int;int;int;int" Global Const $POINTL = "long;long" Global Const $DISPLAY_DEVICE = "int;char[32];char[128];int;char[128];char[128]" MonitoInfo() Func MonitoInfo() Dim $MonitorPos[1][5] $dev = 0 $id = 0 $dll = DllOpen("user32.dll") $msg = "" Dim $dd = DllStructCreate($DISPLAY_DEVICE) DllStructSetData($dd, 1, DllStructGetSize($dd)) $EnumDisplays = DllCall($dll, "int", "EnumDisplayDevices", _ "ptr", 0, _ "int", $dev, _ "ptr", DllStructGetPtr($dd), _ "int", 0) $StateFlag = Number(StringMid(Hex(DllStructGetData($dd, 4)), 3)) While $EnumDisplays[0] <> 0 If ($StateFlag <> $DISPLAY_DEVICE_MIRRORING_DRIVER) And ($StateFlag <> 0) Then;ignore virtual mirror displays ;get information about the display's position and the current display mode Dim $dm = DllStructCreate($DEVMODE) DllStructSetData($dm, 4, DllStructGetSize($dm)) $EnumDisplaysEx = DllCall($dll, "int", "EnumDisplaySettingsEx", _ "str", DllStructGetData($dd, 2), _ "int", $ENUM_CURRENT_SETTINGS, _ "ptr", DllStructGetPtr($dm), _ "int", 0) If $EnumDisplaysEx[0] = 0 Then DllCall($dll, "int", "EnumDisplaySettingsEx", _ "str", DllStructGetData($dd, 2), _ "int", $ENUM_REGISTRY_SETTINGS, _ "ptr", DllStructGetPtr($dm), _ "int", 0) EndIf ;get the monitor handle and workspace Dim $hm Dim $mi = DllStructCreate($MONITORINFO) DllStructSetData($mi, 1, DllStructGetSize($mi)) If Mod($StateFlag, 2) <> 0 Then; $DISPLAY_DEVICE_ATTACHED_TO_DESKTOP ;display is enabled. only enabled displays have a monitor handle $hm = DllCall($dll, "hwnd", "MonitorFromPoint", _ "int", DllStructGetData($dm, 7, 1), _ "int", DllStructGetData($dm, 7, 2), _ "int", 0) If $hm[0] <> 0 Then DllCall($dll, "int", "GetMonitorInfo", _ "hwnd", $hm[0], _ "ptr", DllStructGetPtr($mi)) EndIf EndIf ;format information about this monitor If $hm[0] <> 0 Then $id += 1 ReDim $MonitorPos[$id+1][5] $MonitorPos[$id][0] = $hm[0] $MonitorPos[$id][1] = DllStructGetData($mi, 3, 1) $MonitorPos[$id][2] = DllStructGetData($mi, 3, 2) $MonitorPos[$id][3] = DllStructGetData($mi, 3, 3) $MonitorPos[$id][4] = DllStructGetData($mi, 3, 4) ;workspace and monitor handle ;workspace: x,y - x,y HMONITOR: handle $msg &= "workspace:" & $hm[0] & ": " & _ DllStructGetData($mi, 3, 1) & "," & _ DllStructGetData($mi, 3, 2) & " to " & _ DllStructGetData($mi, 3, 3) & "," & _ DllStructGetData($mi, 3, 4) & Chr(13) EndIf EndIf $dev += 1 $EnumDisplays = DllCall($dll, "int", "EnumDisplayDevices", _ "ptr", 0, _ "int", $dev, _ "ptr", DllStructGetPtr($dd), _ "int", 0) $StateFlag = Number(StringMid(Hex(DllStructGetData($dd, 4)), 3)) WEnd $MonitorPos[0][0] = $id DllClose($dll) MsgBox(0,"",$msg) Return $MonitorPos EndFunc This is for my simple SetResolution app: http://www.boot-land.net/forums/?showtopic=2897 At the moment I'm just using rescopy.exe from here and parsing its output. However, someone wants to use SetResolution under 64bit and rescopy doesn't function under 64bit. I realise a call to WMI will work (and it does as I've tried). But the problem there is that a call to WMI for supported resolutions doesn't work properly under PE. EnumDisplaySettingsEx is the way to go, but it is quite complex to say the least! There's possible code from here which could be ported: DEVMODE mode; ZeroMemory(&mode, sizeof(DEVMODE)); mode.dmSize = sizeof(DEVMODE); mode.dmDriverExtra = 0; if (EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &mode)) { _tprintf(_T("\nCurrent: h%u v%u b%u f%u\n"), mode.dmPelsWidth, mode.dmPelsHeight, mode.dmBitsPerPel, mode.dmDisplayFrequency); } _tprintf("Supported modes:\n"); for(DWORD index = 0;;++index) { ZeroMemory(&mode, sizeof(DEVMODE)); mode.dmSize = sizeof(DEVMODE); mode.dmDriverExtra = 0; DWORD res = EnumDisplaySettingsEx(NULL, index, &mode, 0 ); if (!res) break; _tprintf(_T("h%u v%u b%u f%u\n"), mode.dmPelsWidth, mode.dmPelsHeight, mode.dmBitsPerPel, mode.dmDisplayFrequency); } Regards and thanks for any help, Galapo.
-
There's possible code from here which could be ported: http://www.boot-land.net/forums/index.php?...ost&p=34246 DEVMODE mode; ZeroMemory(&mode, sizeof(DEVMODE)); mode.dmSize = sizeof(DEVMODE); mode.dmDriverExtra = 0; if (EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &mode)) { _tprintf(_T("\nCurrent: h%u v%u b%u f%u\n"), mode.dmPelsWidth, mode.dmPelsHeight, mode.dmBitsPerPel, mode.dmDisplayFrequency); } _tprintf("Supported modes:\n"); for(DWORD index = 0;;++index) { ZeroMemory(&mode, sizeof(DEVMODE)); mode.dmSize = sizeof(DEVMODE); mode.dmDriverExtra = 0; DWORD res = EnumDisplaySettingsEx(NULL, index, &mode, 0 ); if (!res) break; _tprintf(_T("h%u v%u b%u f%u\n"), mode.dmPelsWidth, mode.dmPelsHeight, mode.dmBitsPerPel, mode.dmDisplayFrequency); } Regards, Galapo.
-
Does anyone know how to modify the code from the first post to retreive an array of supported resolutions rather than the current display? This is for my simple SetResolution app: http://www.boot-land.net/forums/?showtopic=2897 At the moment I'm just using rescopy.exe from here http://www.naughter.com/qres.html and parsing its output. However, under someone wants to use SetResolution under 64bit and rescopy doesn't function under 64bit. I realise a call to WMI will work (and it does as I've tried). But the problem there is that a call to WMI for supported resolutions doesn't work properly under PE. EnumDisplaySettingsEx is the way to go, but it is quite complex to say the least! Regards, Galapo.