Jump to content

Using urlmon.dll for GZIP decompressing


Recommended Posts

Hello, everyone.

I'd like to use urlmon.dll (a library which is a part of Internet Explorer) for decompressing GZIP-compressed data. I've found a small piece of code (in C, I assume) that does it, however, my knowledge is currently not enough to port is to AutoIt. Whould anyone be so kind as to help? The code follows.

#include <windows.h>
#include <atlbase.h>
#include <urlmon.h>

bool UngzipFile(const char* pszInFile, const char* pszOutFile)
{
//create decoding object instance
CComPtr pEFF;
HRESULT hr = pEFF.CoCreateInstance(CLSID_StdEncodingFilterFac);
CComPtr pDF;
//accquire suitable filter
if (!pEFF ||
FAILED(pEFF->GetDefaultFilter(L”gzip”,
L”text”,
&pDF)))
{
return false;
}
//open input gzip file
HANDLE hInFile = CreateFile(pszInFile,
GENERIC_READ,
0,
NULL,
OPEN_EXISTING,
0,
NULL);

if (hInFile == INVALID_HANDLE_VALUE)
{
return false;
}
//create output file
HANDLE hOutFile = CreateFile(pszOutFile,
GENERIC_WRITE,
0,
NULL,
CREATE_ALWAYS,
0,
NULL);
if (hOutFile == INVALID_HANDLE_VALUE)
{
CloseHandle(hInFile);
return false;
}
//truncate out file if exist
SetEndOfFile(hOutFile);

unsigned long uFilePtr = 0,
uLenHi,
uLenLo = GetFileSize(hInFile, &uLenHi);

//temporary in/out buffers
BYTE inBuff[1024],outBuff[16384];

while (uFilePtr < uLenLo)
{
SetFilePointer(hInFile,uFilePtr,NULL,FILE_BEGIN);
DWORD dwInBuffSize, dwOutBuffSize = sizeof(outBuff);
ReadFile(hInFile,
(VOID*)inBuff,
sizeof(inBuff),
&dwInBuffSize,
NULL);

long dwRead = 0,dwWritten = 0;
//decode chunk of data
hr = pDF->DoDecode(0,
dwInBuffSize,
(BYTE*)inBuff,
dwOutBuffSize,
(BYTE*)outBuff,
dwInBuffSize,
&dwRead,
&dwWritten,
0);

// increment file position with size of actually
// decoded data and write decoded chunk
uFilePtr+=dwRead;
ULONG dwFileWritten;
WriteFile(hOutFile,
(VOID*)outBuff,
dwWritten,
&dwFileWritten,
NULL);
}
//close in/out file handles
CloseHandle(hOutFile);
CloseHandle(hInFile);

return true;
}

Thanks in advance.

Edited by naaloh
Link to comment
Share on other sites

Why not use 7-Zip and this wrapper >> OR

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

You will need the experimental ObjCreateInterface. Since I only have Wine here, I cannot test it:

Global Const $IID_IDataFilter = "{69d14c80-c18e-11d0-a9ce-006097942311}"
Global Const $vTable_IDataFilter = "DoEncode hresult(DWORD;LONG;ptr;LONG;ptr;LONG;LONG*;LONG *;DWORD); DoDecode hresult(DWORD;LONG;ptr;LONG;ptr;LONG;LONG*;LONG *;DWORD);SetEncodingLevel hresult(DWORD);"


Global Const $CLSID_StdEncodingFilterFac = "{54c37cd0-d944-11d0-a9f4-006097942311}"

Global Const $IID_IEncodingFilterFactory = "{70bdde00-c18e-11d0-a9ce-006097942311}"
Global Const $vTable_IEncodingFilterFactory = "FindBestFilter hresult(wstr;wstr;struct;ptr*);GetDefaultFilter hresult(wstr;wstr;ptr*);"
$oFilterFactory = ObjCreateInterface($CLSID_StdEncodingFilterFac, Default, $vTable_IEncodingFilterFactory)

Dim $ptr
$oFilterFactory.GetDefaultFilter("gzip", "text", $ptr)
$oFilter = ObjCreateInterface($ptr, Default, $vTable_IDataFilter)

$oFilter.DoDecode(...)

Btw, you will find the vtables and IIDs when using keywords like CINTERFACE, define, UUID, MIDL_INTERFACE, ...

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

Wow, so many replies in such a short time, and much helpful replies, too. Thank you kindly, 69255 and ProgAndy, your help is much appreciated. I'll test the script by 69255 as soon as I can. The only thing that's somewhat confusing is that the description of ObjCreateInterface states "may be changed or removed without notice". Do you think there's a big chance for its removal? I'm concerned, since its removal would presumably render using urlmon.dll impossible.

To answer guinness and KaFu: I would prefer not to use external libraries as long as I can make do with system ones.

Link to comment
Share on other sites

The only thing that's somewhat confusing is that the description of ObjCreateInterface states "may be changed or removed without notice". Do you think there's a big chance for its removal?

The functionality itself is not supposed to be removed, but the function definition (parameters) is not frozen yet and can change anytime.

Could you elaborate more on this? One thing I still don't understand is how to get the CLSID, IID, and vTable. It's pretty much impossible to do anything without them.

Just do a Google search and then find the correct result, e.g this

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...