Jump to content

extraction with Cabinet.dll


Recommended Posts

Hi,

I am trying to extract the files from .cab archives. I found the APIs to extact the files with cabinet.dll.

I tried to create the functions as they describe but i am unable to find the reason; why autoit crashes when i call the 1st function..

here is my attempt code: i tried this code at WIN7 32Bit.

#include 
#include 
Global $hCabDll = DllOpen("Cabinet.dll")
Global $hFDI
Global $ERF ; "int erfOper;int erfType;boolean fError"; create this structure b4 FDI Create
Global $hCabFile ; use this for IO opreations
Global $FNF_MEM_ALLOC, $mem[1000], $mi = 0 ; just for testing
Global Enum $fdintCABINET_INFO, _   ; General information about cabinet
        $fdintPARTIAL_FILE, _           ; First file in cabinet is continuation
        $fdintCOPY_FILE, _              ; File to be copied
        $fdintCLOSE_FILE_INFO, _        ; close the file, set relevant info
        $fdintNEXT_CABINET, _           ; File continued to next cabinet
        $fdintENUMERATE ; Enumeration status
Global Const $FDIERROR_NONE = 0x00;No error.
Global Const $FDIERROR_CABINET_NOT_FOUND = 0x01;The cabinet file was not found.
Global Const $FDIERROR_NOT_A_CABINET = 0x02;The cabinet file does not have the correct format.
Global Const $FDIERROR_UNKNOWN_CABINET_VERSION = 0x03 ;The cabinet file has an unknown version number.
Global Const $FDIERROR_CORRUPT_CABINE = 0x04;The cabinet file is corrupt.
Global Const $FDIERROR_ALLOC_FAIL = 0x05;Insufficient memory.
Global Const $FDIERROR_BAD_COMPR_TYPE = 0x06;Unknown compression type used in the cabinet folder.
Global Const $FDIERROR_MDI_FAIL = 0x07;Failure decompressing data from the cabinet file.
Global Const $FDIERROR_TARGET_FILE = 0x08;Failure writing to the target file.
Global Const $FDIERROR_RESERVE_MISMATCH = 0x09;The cabinets within a set do not have the same RESERVE sizes.
Global Const $FDIERROR_WRONG_CABINET = 0x0A;The cabinet returned by fdintNEXT_CABINET is incorrect.
Global Const $FDIERROR_USER_ABORT = 0x0B ;FDI abort

Global $CBK_Alloc = DllCallbackRegister("FNALLOC", "ptr", "ulong")
Global $CBK_Free = DllCallbackRegister("FNFREE", "none", "hwnd")
Global $CBK_Open = DllCallbackRegister("FNOPEN", "hwnd", "str;int;int"); not sure abt str :/
Global $CBK_Read = DllCallbackRegister("FNREAD", "int", "hwnd;ptr;uint")
Global $CBK_Write = DllCallbackRegister("FNWRITE", "int", "hwnd;ptr;uint")
Global $CBK_Close = DllCallbackRegister("FNCLOSE", "int", "hwnd;")
Global $CBK_Sneek = DllCallbackRegister("FNSEEK", "int", "hwnd;long;int")
ConsoleWrite("Callback: "&$CBK_Alloc & @CRLF)
ConsoleWrite("Callback: "&$CBK_Free & @CRLF)
ConsoleWrite("Callback: "&$CBK_Open & @CRLF)
ConsoleWrite("Callback: "&$CBK_Read & @CRLF)
ConsoleWrite("Callback: "&$CBK_Write & @CRLF)
ConsoleWrite("Callback: "&$CBK_Close & @CRLF)
ConsoleWrite("Callback: "&$CBK_Sneek & @CRLF)
FDI_CREATE()
ConsoleWrite(@error & @CRLF)
While 1
    Sleep(100)
WEnd

Func FDI_CREATE()
    $ERF = DllStructCreate("int erfOper;int erfType;boolean fError")
;~   __in   PFNALLOC pfnalloc,
;~   __in   PFNFREE pfnfree,
;~   __in   PFNOPEN pfnopen,
;~   __in   PFNREAD pfnread,
;~   __in   PFNWRITE pfnwrite,
;~   __in   PFNCLOSE pfnclose,
;~   __in   PFNSEEK pfnseek,
;~   __in   int cpuType,
;~   __inout  PERF perf
    $hFDI = DllCall($hCabDll, "HWND", "FDICreate", _
            "ptr", DllCallbackGetPtr($CBK_Alloc), _
            "ptr", DllCallbackGetPtr($CBK_Free), _
            "ptr", DllCallbackGetPtr($CBK_Open), _
            "ptr", DllCallbackGetPtr($CBK_Read), _
            "ptr", DllCallbackGetPtr($CBK_Write), _
            "ptr", DllCallbackGetPtr($CBK_Close), _
            "ptr", DllCallbackGetPtr($CBK_Sneek), _
            "int", -1, _ ;cpuUNKNOWN = -1,FDI should determine the CPU type.
            "ptr", DllStructGetPtr($ERF))
    If @error Then
        Return SetError(1)
    ElseIf Not $hFDI[0] Then
        Return SetError(2)
    EndIf
    $hFDI = $hFDI[0]
    Return $hFDI ;<- You weren't returning the handle
EndFunc   ;==>FDI_CREATE
;~ void FNALLOC(
;~  ULONG cb ;The number of bytes to allocate.
;~ );
Func FNALLOC($cb)
    Local $pSpace = _MemVirtualAlloc(0, $cb, $MEM_COMMIT, $PAGE_READWRITE)
    ConsoleWrite("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!FNALLOC " & $cb & "    " & $pSpace & @CRLF)
    Return $pSpace
EndFunc   ;==>FNALLOC
;~ void FNFREE(
;~   [in, optional]  void HUGE *pv
;~ );
Func FNFREE($pMEM)
    ConsoleWrite("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!FNFREE " & $pMEM & @CRLF)
    #forceref $pMEM
    _MemVirtualFree($pMEM, 0, $MEM_RELEASE)
EndFunc   ;==>FNFREE
;~ void FNOPEN(
;~   [in]  LPSTR pszFile,
;~      int oflag,
;~      int pmode
;~ );
Func FNOPEN($pszFile, $oflag, $pmode)
    ConsoleWrite("FOpen" & @CRLF)
    Local $Access, $Creation
    If BitAND($oflag, 02) Then          ; O_RDWR 02
        $Access = 6 ; read & write
    ElseIf BitAND($oflag, 01) = 01 Then ;O_WRONLY 01
        $Access = 4 ; write
    Else                                ;O_RDONLY         00
        $Access = 2 ; read
    EndIf
    If BitAND($oflag, 0100) = 0100 Then ;O_CREAT 0100
        $Creation = 1                   ; CREATE_ALWAYS
    Else
        $Creation = 2                   ; OPEN_EXISTING
    EndIf
    $res = _WinAPI_CreateFile($pszFile, $Creation, $Access, 2, 1)
    If $res = 0 Then
        Return -1
    Else
        Return $res
    EndIf
EndFunc   ;==>FNOPEN

;~ void FNREAD(
;~   [in]   INT_PTR hf, ; hwnd of file
;~   [out]  void FAR *pv[bcount(cb)], ;Pointer to the buffer that receives the data read from a file.
;~          UINT cb;The maximum number of bytes to be read.
;~ );
Func FNREAD($hf, $pv, $cb)
;~  #forceref $hf,$pv
    ConsoleWrite("FRead : " & $cb & @CRLF)
    Local $iRead
    $res = _WinAPI_ReadFile($hf, $pv, $cb, $iRead)
    If $res Then
        ConsoleWrite("Done! " & @CRLF)
        Return $iRead
    Else
        ConsoleWrite("!Read Fail." & @CRLF)
        Return -1
    EndIf
EndFunc   ;==>FNREAD
;~ void FNWRITE(
;~   [in]  INT_PTR hf, ; hwnd of file
;~   [in]  void FAR *pv[bcount(cb)], Pointer to the buffer containing the data to be written.
;~      UINT cb ;The maximum number of bytes to be written.
;~ )
Func FNWRITE($hf, $pv, $cb);
;~  #forceref $hf,$pv
    ConsoleWrite("FWrite" & @CRLF)
    Local $iWrite
    $res = _WinAPI_WriteFile($hf, $pv, $cb, $iWrite)
    If $res Then
        ConsoleWrite("Done! " & @CRLF)
        Return $iWrite
    Else
        ConsoleWrite("!Write Fail." & @CRLF)
        Return -1
    EndIf

EndFunc   ;==>FNWRITE

;~ void FNSEEK(
;~   [in]  INT_PTR hf,
;~      long dist,
;~      int seektype
;~ );
Func FNSEEK($hf, $dist, $seektype)
    ConsoleWrite("FSneek" & @CRLF)
    Local $res = _WinAPI_SetFilePointer($hf, $dist, $seektype)
    Return $res
EndFunc   ;==>FNSEEK

;~ void FNCLOSE(
;~   [in]  INT_PTR hf
;~ );
Func FNCLOSE($hf)
;~  #forceref $hf
    ConsoleWrite("FClose" & @CRLF)
    $res = _WinAPI_CloseHandle($hf)
    If $res Then
        Return 0
    Else
        Return -1
    EndIf
EndFunc   ;==>FNCLOSE

;~  void FNFDINOTIFY(
;~  FDINOTIFICATIONTYPE fdint,
;~  PFDINOTIFICATION pfdin
;~ );
Func fdiCallBack($fdint, $pfdin)
;~ typedef struct _FDINOTIFICATION {
;~   LONG   cb;
;~   char FAR *psz1; Null-Terminated String (Points to a 256 character buffer)
;~   char FAR *psz2;
;~   char FAR *psz3;
;~   void FAR *pv;
;~   INT_PTR  hf;
;~   USHORT   date;
;~   USHORT   time;
;~   USHORT   attribs;
;~   USHORT   setID;
;~   USHORT   iCabinet;
;~   USHORT   iFolder;
;~   FDIERROR fdie;
;~ } FDINOTIFICATION, *PFDINOTIFICATION;
    Local $FDINOTIFICATION = DllStructCreate("long cb;ptr psz1;ptr psz2;ptr psz3;ptr pv;ptr hf;ushort date;ushort time;ushort attribs;ushort setID;ushort iCabinet;ushort iFolder;int fdie", $pfdin)
    Switch $fdint
        Case $fdintCABINET_INFO ;General information about cabinet
        Case $fdintPARTIAL_FILE ; First file in cabinet is continuation
        Case $fdintCOPY_FILE ; File to be copied
        Case $fdintCLOSE_FILE_INFO ; close the file, set relevant info
        Case $fdintNEXT_CABINET ; File continued to next cabinet
        Case $fdintENUMERATE ; Enumeration status
    EndSwitch
EndFunc   ;==>fdiCallBack

here is ref link from MSDN : http://msdn.microsoft.com/en-us/library/bb432271(v=vs.85).aspx

Thanks in Advance.

Edited by Digisoul

73 108 111 118 101 65 117 116 111 105 116

Link to comment
Share on other sites

Have you tried it using the to do what you want? I don't know if it will work on a cab file but it's worth a shot.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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...