Sign in to follow this  
Followers 0
step887

IStorage interface

8 posts in this topic

So I am trying to use autoit to extract out a ole2 file

I am open the file using StgOpenStorage (http://msdn.microsoft.com/en-us/library/aa380341(v=vs.85).aspxdllcall, but I am not sure how to make that into an autoit object

I was trying to get CLSID using ReadClassStg (http://msdn.microsoft.com/en-us/library/aa380302(v=vs.85).aspx)

 
then maybe use ObjCreateInterface, but autoit crashes with everything I tried.
 
I maybe going about this wrong way, can anyone assist
#include <array.au3>
Global $S_ok = 0
Global $s_false = 1
Global Const $tagGUID = "ulong Data1;ushort Data2;ushort Data3;byte Data4[8]"
Local $tStg = DllStructCreate('int')
Local $pStg = DllStructGetPtr($tStg)

Local $aGUID = DllStructCreate($tagGUID)
Local $pGUID = DllStructGetPtr($aGUID)


Local $filename = 'c:\users\stephen\desktop\doc1.doc'
If Not _isOleFile($filename) Then
    MsgBox(0, 'error', 'Not Ole')
    Exit
EndIf
$ret = DllCall("Ole32.dll", 'int', 'StgOpenStorage', 'wstr', $filename, 'ptr', 0, 'int', BitOR(0x00400000, 0, 0x00000040), 'ptr', 0, 'int', 0, 'ptr', $pStg) ;~   STGM_DIRECT_SWMR | STGM_READ | STGM_SHARE_DENY_NONE
ConsoleWrite($pStg & @CRLF)
$ret = DllCall("Ole32.dll", 'int', 'ReadClassStg', 'ptr', $pStg, 'struct*', $pGUID)

;StgOpenStorage function http://msdn.microsoft.com/en-us/library/aa380341(v=vs.85).aspx
;STGM Constants   http://msdn.microsoft.com/en-us/library/windows/desktop/aa380337(v=vs.85).aspx
;COM Error Codes (STG, RPC) http://msdn.microsoft.com/en-us/library/windows/desktop/dd542645(v=vs.85).aspx
;IStorage interface http://msdn.microsoft.com/en-us/library/aa380015(v=vs.85).aspx
Func _isOleFile($afilename)
    $ret = DllCall("Ole32.dll", 'int', 'StgIsStorageFile', 'wstr', $afilename)
    If $ret[0] = $S_ok Then
        Return True
    Else
        Return False
    EndIf
EndFunc   ;==>_isOleFile
doc1 is just a doc file with embedded image
 
 
 
 
 

 

 

 

Doc1.doc

Share this post


Link to post
Share on other sites



Run this and tell us which one of the included error codes you get (if any).

#AutoIt3Wrapper_AU3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 6 -w 7 -d

#include <Constants.au3>

#include <Array.au3>

Global Const $S_OK = 0
Global Const $S_FALSE = 1
Global Const $STG_E_INVALIDFUNCTION = 0x80030001
Global Const $STG_E_FILENOTFOUND = 0x80030002
Global Const $STG_E_PATHNOTFOUND = 0x80030003
Global Const $STG_E_TOOMANYOPENFILES = 0x80030004
Global Const $STG_E_ACCESSDENIED = 0x80030005
Global Const $STG_E_INVALIDHANDLE = 0x80030006
Global Const $STG_E_INSUFFICIENTMEMORY = 0x80030008
Global Const $STG_E_INVALIDPOINTER = 0x80030009
Global Const $STG_E_NOMOREFILES = 0x80030012
Global Const $STG_E_DISKISWRITEPROTECTED = 0x80030013
Global Const $STG_E_SEEKERROR = 0x80030019
Global Const $STG_E_WRITEFAULT = 0x8003001D
Global Const $STG_E_READFAULT = 0x8003001E
Global Const $STG_E_SHAREVIOLATION = 0x80030020
Global Const $STG_E_LOCKVIOLATION = 0x80030021
Global Const $STG_E_FILEALREADYEXISTS = 0x80030050
Global Const $STG_E_INVALIDPARAMETER = 0x80030057
Global Const $STG_E_MEDIUMFULL = 0x80030070
Global Const $STG_E_PROPSETMISMATCHED = 0x800300F0
Global Const $STG_E_ABNORMALAPIEXIT = 0x800300FA
Global Const $STG_E_INVALIDHEADER = 0x800300FB
Global Const $STG_E_INVALIDNAME = 0x800300FC
Global Const $STG_E_UNKNOWN = 0x800300FD
Global Const $STG_E_UNIMPLEMENTEDFUNCTION = 0x800300FE
Global Const $STG_E_INVALIDFLAG = 0x800300FF
Global Const $STG_E_INUSE = 0x80030100
Global Const $STG_E_NOTCURRENT = 0x80030101
Global Const $STG_E_REVERTED = 0x80030102
Global Const $STG_E_CANTSAVE = 0x80030103
Global Const $STG_E_OLDFORMAT = 0x80030104
Global Const $STG_E_OLDDLL = 0x80030105
Global Const $STG_E_SHAREREQUIRED = 0x80030106
Global Const $STG_E_NOTFILEBASEDSTORAGE = 0x80030107
Global Const $STG_E_EXTANTMARSHALLINGS = 0x80030108 
Global Const $STG_E_DOCFILECORRUPT = 0x80030109 
Global Const $STG_E_BADBASEADDRESS = 0x80030110 
Global Const $STG_E_DOCFILETOOLARGE = 0x80030111
Global Const $STG_E_NOTSIMPLEFORMAT = 0x80030112
Global Const $STG_E_INCOMPLETE = 0x80030201
Global Const $STG_E_TERMINATED = 0x80030202
Global Const $STG_S_CONVERTED = 0x00030200 

Global Const $filename = 'c:\users\stephen\desktop\doc1.doc'

If Not _isOleFile($filename) Then
    MsgBox($MB_OK + $MB_ICONEXCLAMATION, 'Error', 'Not Ole')
    Exit
EndIf

Global Const $tStg = DllStructCreate('int')

Global Const $pStg = DllStructGetPtr($tStg)

Global Const $StgOpenStorage = DllCall("Ole32.dll", 'int',   'StgOpenStorage',              _
                                                    'wstr',  $filename,                     _
                                                    'ptr',   0,                             _
                                                    'dword', BitOR(0x00400000, 0x00000040), _
                                                    'ptr',   0,                             _
                                                    'dword', 0,                             _
                                                    'ptr',   $pStg) ; STGM_DIRECT_SWMR | STGM_READ | STGM_SHARE_DENY_NONE

if @error then 
  MsgBox($MB_OK + $MB_ICONEXCLAMATION, "Error", @error & " $StgOpenStorage: " & $StgOpenStorage)
  exit
endif

ConsoleWrite("$StgOpenStorage: " & $StgOpenStorage[0] & @CRLF)

Global Const $tagGUID = "ulong Data1;ushort Data2;ushort Data3;byte Data4[8]"

Global Const $aGUID = DllStructCreate($tagGUID)

Global Const $pGUID = DllStructGetPtr($aGUID)

Global Const $ReadClassStg = DllCall("Ole32.dll", 'int', 'ReadClassStg', 'ptr', $pStg, 'struct*', $pGUID)

if @error then 
  MsgBox($MB_OK + $MB_ICONEXCLAMATION, "Error", @error & " $ReadClassStg: " & $ReadClassStg)
  exit
endif
ConsoleWrite("$ReadClassStg: " & $ReadClassStg[0] & @CRLF)

;StgOpenStorage function http://msdn.microsoft.com/en-us/library/aa380341(v=vs.85).aspx
;STGM Constants   http://msdn.microsoft.com/en-us/library/windows/desktop/aa380337(v=vs.85).aspx
;COM Error Codes (STG, RPC) http://msdn.microsoft.com/en-us/library/windows/desktop/dd542645(v=vs.85).aspx
;IStorage interface http://msdn.microsoft.com/en-us/library/aa380015(v=vs.85).aspx
Func _isOleFile(Const $afilename)
    Local Const $ret = DllCall("Ole32.dll", 'int', 'StgIsStorageFile', 'wstr', $afilename)
    
    If $ret[0] = $S_OK Then
        Return True
    Else
        Return False
    EndIf
EndFunc

Share this post


Link to post
Share on other sites

in the console. I get

$StgOpenStorage: 0
!>20:14:46 AutoIt3.exe ended.rc:-1073741819
>Exit code: -1073741819    Time: 2.824

Share this post


Link to post
Share on other sites

I found this 

http://www.developerfusion.com/article/84406/com-structured-storage-from-net/

 

Open the file In most cases the first thing that you need to do when working with a structured storage file is to open it. Another helper function does this job – StgOpenStorage. Its definition can be found at PINVOKE.NET:[DllImport(“ole32.dll”)]
    static extern int StgOpenStorage(
        [MarshalAs(UnmanagedType.LPWStr)]
        string pwcsName, IStorage pstgPriority],
        STGM grfMode, IntPtr snbExclude, uint reserved,
        out IStorage ppstgOpen);

 

Which I do with 

$ret = DllCall("Ole32.dll", 'int', 'StgOpenStorage', 'wstr', $filename, 'ptr', 0, 'int', BitOR(0x00400000, 0, 0x00000040), 'ptr', 0, 'int', 0, 'ptr', $pStg) ;~   STGM_DIRECT_SWMR | STGM_READ | STGM_SHARE_DENY_NONE

They do a comimport:

 

[ComImport]
[Guid(“0000000b-0000-0000-C000-000000000046”)]
[interfaceType(ComInterfaceType.InterfaceIsIUnknown)]
interface IStorage
{
    void CreateStream(
    /* [string][in] */ string pwcsName,
    /* [in] */ uint grfMode,
    /* [in] */ uint reserved1,
    /* [in] */ uint reserved2,
    /* [out] */ out IStream ppstm);

 

Is there is any way to do this in autoit?  I tried 

Global $obj = ObjCreateInterface( "000000b-0000-0000-C000-000000000046" , "0000000B-0000-0000-C000-000000000046",$pStg )

I am not that good with COM objects, so any help is appreciated

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

 

in the console. I get

BUt you didn't see a MsgBox pop up?  That means you didn't run my example.

I apologize, my example doesn't do what I remeber I thought I had it do.  *SplaceFalm*

Sorry.

Edited by jaberwocky6669

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Sorry, i have a problem with istorage too. (note: my nickname not joke!)

Have 1-lv compound-file (only streams). Can not read streams. Trying:

#include <Array.au3>

Global $cUsrFile1c = "D:\my.md"

If StringLeft(_ArrayToString(DllCall("Ole32.dll", 'int', 'StgIsStorageFile', 'wstr', $cUsrFile1c), "#"),2) <> "0#" Then
    MsgBox(16, '<Error!>', $cUsrFile1c & " == if NOT iStorage-file !");
    Exit -1
EndIf
MsgBox(64, '<Ok>', $cUsrFile1c & " is iStorage-file ...");

Local $cMsg=""
Local $tStgOpened = DllStructCreate("int")
Local $pStgOpened = DllStructGetPtr($tStgOpened)
Global $aStgOpened = DllCall("Ole32.dll", "int", "StgOpenStorage", _
'wstr', $cUsrFile1c, _
'ptr', 0, _
'dword', BitOR(0x00400000, 0, 0x00000040), _    ; = STGM_DIRECT_SWMR | STGM_READ | STGM_SHARE_DENY_NONE
'ptr', 0, _
'dword', 0, _
'ptr', $pStgOpened )
$cMsg = "IStorage interface pointer (" & VarGetType ($pStgOpened) & ") = " & $pStgOpened
If IsArray($aStgOpened) Then
    $cMsg &= @CRLF & "Return Array = " & UBound($aStgOpened)
    If UBound($aStgOpened) = 0 Then
        MsgBox (16, "debug: <StgOpenStorage ERROR>", $cMsg)
        Exit -1
    EndIf
Else
    $cMsg &= @CRLF & "(ERROR) Return(" & VarGetType($aStgOpened) & ") = " & $aStgOpened
    MsgBox (16, "debug: <StgOpenStorage>", $cMsg )  ;******* HERE!
    Exit -1
EndIf
MsgBox (64, "debug: <StgOpenStorage>", $cMsg & "  " & $aStgOpened[0])
_ArrayDisplay( $aStgOpened, 'debug: <StgOpenStorage>')

$cMsg = ""
Local $cStreamName = "Container.Contents" & ChrW(0x0000)
Local $tStreamOpened = DllStructCreate("int")
Local $pStreamOpened = DllStructGetPtr($tStreamOpened)
Global $aStreamOpened = DllCall("Ole32.dll", 'int', 'OpenStream', _
'wchar', $cStreamName, _
'void',  0, _
'dword', BitOR(0x00400000, 0, 0x00000040), _    ; = STGM_DIRECT_SWMR | STGM_READ | STGM_SHARE_DENY_NONE
'dword', 0, _
"ptr", $pStreamOpened )
$cMsg = "ISream interface pointer (" & VarGetType($pStreamOpened) & ") = " & $pStreamOpened
If IsArray($aStreamOpened) Then
    $cMsg &= @CRLF & "Return Array = " & UBound($aStreamOpened) & " / " & $aStreamOpened[0]
    MsgBox (64, "debug: <OpenStream>", $cMsg)
    _ArrayDisplay( $aStreamOpened, '<OpenStream>')
Else
    $cMsg &= @CRLF & "(ERROR) Return(" & VarGetType($aStreamOpened) & ") = " & $aStreamOpened
    MsgBox (16, "debug: <OpenStream>", $cMsg )
    Exit -2
EndIf

;******* HERE! == "... (ERROR) Return(Int32) = 0

Edited by n000b

Share this post


Link to post
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
Sign in to follow this  
Followers 0