StimpsoO Posted February 18, 2011 Share Posted February 18, 2011 Hi, I have an AutoIt script that reads data in from an XML file. I would like to package the xml file us as part of the exe, so that it is a single file at run time. I have amended my code to use #AutoIt3Wrapper_Res_File_Add for this purpose, but I am having trouble accessing this file at run time. My original code referenced a file in the current directory and worked just fine, the code was as follows: #include <IE.au3> _IEErrorHandlerRegister() #Include <_XMLDomWrapper.au3> $sXmlFile = ("PlacingDataPackage.xml") $oOXml = _XMLFileOpen ($sXmlFile) $retval = _XMLGetValue("/placingDataPackage/user/userName") MsgBox(0, "Debug", $retval[1]) I have now ammened the code to use a resource file: #AutoIt3Wrapper_Res_File_Add=PlacingDataPackage.xml, rt_rcdata, PDP_1 #include <IE.au3> _IEErrorHandlerRegister() #Include <_XMLDomWrapper.au3> #include <resources.au3> $sXmlFile = _ResourceGetAsString("PDP_1") $oOXml = _XMLFileOpen ($sXmlFile) $retval = _XMLGetValue("/placingDataPackage/user/userName") MsgBox(0, "Debug", $retval[1]) but this fails with the following message "Subscript used with non-Array variable". am I making some mistake in my syntax or is this not the correct way to go about what I am trying to achieve? Any help would be appreciated. Link to comment Share on other sites More sharing options...
wolf9228 Posted February 18, 2011 Share Posted February 18, 2011 (edited) Hi, I have an AutoIt script that reads data in from an XML file. I would like to package the xml file us as part of the exe, so that it is a single file at run time. I have amended my code to use #AutoIt3Wrapper_Res_File_Add for this purpose, but I am having trouble accessing this file at run time. My original code referenced a file in the current directory and worked just fine, the code was as follows: #include <IE.au3> _IEErrorHandlerRegister() #Include <_XMLDomWrapper.au3> $sXmlFile = ("PlacingDataPackage.xml") $oOXml = _XMLFileOpen ($sXmlFile) $retval = _XMLGetValue("/placingDataPackage/user/userName") MsgBox(0, "Debug", $retval[1]) I have now ammened the code to use a resource file: #AutoIt3Wrapper_Res_File_Add=PlacingDataPackage.xml, rt_rcdata, PDP_1 #include <IE.au3> _IEErrorHandlerRegister() #Include <_XMLDomWrapper.au3> #include <resources.au3> $sXmlFile = _ResourceGetAsString("PDP_1") $oOXml = _XMLFileOpen ($sXmlFile) $retval = _XMLGetValue("/placingDataPackage/user/userName") MsgBox(0, "Debug", $retval[1]) but this fails with the following message "Subscript used with non-Array variable". am I making some mistake in my syntax or is this not the correct way to go about what I am trying to achieve? Any help would be appreciated. _XMLDomWrapper library You are using the _XMLDomWrapper library You can load the file by the _XMLFileOpen function The return value of the _ResourceGetAsString function is a String Data and not a file path To do this process you must use the _XMLLoadXML function ;=============================================================================== ; Function Name: _XMLLoadXML ; Description: Creates an instance for a string of XML . ; Parameters: $strXML - The XML to load into the document ; Syntax: _XMLLoadXML($strXML) ; Return Value(s): On Success - 1 ; On Failure - -1 and set @error to ; 1 - failed to create object, @Extended = MSXML reason ; 2 - no object found (MSXML required for _XML functions ; ; Author(s): Stephen Podhajecki <gehossafats@netmdc.com>,Lukasz Suleja,Tom Hohmann ;=============================================================================== Func _XMLLoadXML($strXML,$strNameSpc="", $iVer = -1, $bValOnParse = True) Edited February 18, 2011 by wolf9228 صرح السماء كان هنا Link to comment Share on other sites More sharing options...
StimpsoO Posted February 18, 2011 Author Share Posted February 18, 2011 Thanks Wolf, I can now see the issue with the return type of _ResourceGetAsString /headslap I have now re-coded as follows: #AutoIt3Wrapper_Res_File_Add=PlacingDataPackage.xml, rt_rcdata, PDP_1 #include <IE.au3> _IEErrorHandlerRegister() #Include <_XMLDomWrapper.au3> #include <resources.au3> $oOXml = _XMLLoadXML(_ResourceGetAsString("PDP_1")) MsgBox(0, "Debug", $oOXml) The code now runs without failure, but the contents of the message box is blank. This suggests that the XML file is not getting loaded into the variable. Link to comment Share on other sites More sharing options...
wolf9228 Posted February 18, 2011 Share Posted February 18, 2011 (edited) Thanks Wolf, I can now see the issue with the return type of _ResourceGetAsString /headslap I have now re-coded as follows: #AutoIt3Wrapper_Res_File_Add=PlacingDataPackage.xml, rt_rcdata, PDP_1 #include <IE.au3> _IEErrorHandlerRegister() #Include <_XMLDomWrapper.au3> #include <resources.au3> $oOXml = _XMLLoadXML(_ResourceGetAsString("PDP_1")) MsgBox(0, "Debug", $oOXml) The code now runs without failure, but the contents of the message box is blank. This suggests that the XML file is not getting loaded into the variable. Full Example First Download the ResHacker.exe program http://www.angusj.com/resourcehacker/ and Download This version Of Resources UDF Place the ResHacker program on the same folder as the AutoIt3Wrapper program On this path C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe Filename.xml Place the XML file on Driver D <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> AutoitXml.au3 ; compile using AutoIt3Wrapper.exe And ResHacker.exe ;Resource Hacker ;ResHacker.exe ;http://www.angusj.com/resourcehacker/ ;#AutoIt3Wrapper_Res_File_Add= ; Filename[,Section [,ResName[,LanguageCode]]] to be added. ;FileFullName = D:\Filename.xml ;ResType = 10 ;$RT_RCDATA ;ResName = "xml1" ;ResLang = 0 #AutoIt3Wrapper_UseUpx=N ;You should not use the Upx option #AutoIt3Wrapper_Res_File_Add=D:\Filename.xml,10,xml1,0 #include "resources.au3" #include "_XMLDomWrapper.au3" ; compile using AutoIt3Wrapper.exe And ResHacker.exe ;Resource Hacker ;ResHacker.exe ;http://www.angusj.com/resourcehacker/ ;#AutoIt3Wrapper_Res_File_Add= ; Filename[,Section [,ResName[,LanguageCode]]] to be added. ;FileFullName = D:\Filename.xml ;ResType = 10 ;$RT_RCDATA ;ResName = "xml1" ;ResLang = 0 #AutoIt3Wrapper_UseUpx=N ;You should not use the Upx option #AutoIt3Wrapper_Res_File_Add=D:\Filename.xml,10,xml1,0 ;ResType = 10 ;$RT_RCDATA ;ResName = "xml1" ;ResLang = 0 $strXML = _ResourceGetAsString("xml1",10,0) $Rt = _XMLLoadXML($strXML) if $Rt <> -1 Then MsgBox(0,"","Success") compile AutoitXml.au3 using the AutoIt3Wrapper.exe Edited February 18, 2011 by wolf9228 صرح السماء كان هنا Link to comment Share on other sites More sharing options...
Developers Jos Posted February 18, 2011 Developers Share Posted February 18, 2011 Why install Reshacker for this? That isn't needed any more since v2. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
GEOSoft Posted February 18, 2011 Share Posted February 18, 2011 And even then it didn't have to be in the same folder as the wrapper if they used the right download location. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
wolf9228 Posted February 18, 2011 Share Posted February 18, 2011 Why install Reshacker for this?That isn't needed any more since v2.JosI do not know about the new developmentIs it possible use the resource functions To update the Autoit executable FileBeginUpdateResourceUpdateResourceEndUpdateResourceThank you صرح السماء كان هنا Link to comment Share on other sites More sharing options...
wolf9228 Posted February 18, 2011 Share Posted February 18, 2011 And even then it didn't have to be in the same folder as the wrapper if they used the right download location.To be able to update the resource information of the Compiled Scripts you need to download reshacker.exe to the:c:\Program Files\AutoIT3\SciTE\Autoit3Wrapper subdirectory to enable the resource update function of CompileAU3.Using Autoit3 Production and (optional) Beta version together with SciTE4AutoIT3 Installation:Download and install the latest AutoIT3 Production version from HEREThis will install AutoIt3 in c:\Program Files\AutoIT3Download and install the latest AutoIT3 Beta version from HERE (Optional)This Beta will be installed in c:\Program Files\AutoIT3\BetaDownload and install the latest SciTE4AutoIT3 from HEREThis will install SciTE in c:\Program Files\AutoIT3\SciTESelect Edit for Open if you want your script to open in SciTE when you double click an AU3 file.To be able to update the resource information of the Compiled Scripts you need to download reshacker.exe to the:c:\Program Files\AutoIT3\SciTE\Autoit3Wrapper subdirectory to enable the resource update function of CompileAU3. AutoIt3Wrapper will perform the following tasks for you when wrapping Aut2Exe (Compile):Read the command line options which are supported by aut2exe. Read any info from the Scriptname.Ini file as defaults if its available. Read the input script searching for compiler directives. If found, it will override any other setting. Run program(s) defined by the Run_Before directive(s). Run Tylo's AU3Check program (Optional) to verify the script. When errors are encountered you will be prompted if you want to continue or stop the compile process. Run Tidy (Optional) at Run and Compilation time. Run Obfuscator (Optional) after the Obfuscated source will also be checked by AU3Check. Run aut2exe.exe, return code reported to console. Run RC.exe (optional) return code reported to console. Run reshack.exe (optional) return code reported to console. Run UPX when requested. Run program(s) defined by the Run_After directive(s). صرح السماء كان هنا Link to comment Share on other sites More sharing options...
Developers Jos Posted February 18, 2011 Developers Share Posted February 18, 2011 Not sure where you got this posted information from, but I know that the doc's aren't 100% in the current published helpfile, but the one on my SVN repo for the next release is containing the correct information. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
StimpsoO Posted February 18, 2011 Author Share Posted February 18, 2011 Hi Again, thanks for your input so far, tbh I'm getting a little confused. Do I need to use reshacker to achieve what I want to do or can I used standard Autoit functionality? I know that I need to include resources.au3 to work with resource files and the _XMLDomWrapper.au3 for the xml commands, but Jos suggested that reshacker is not required. Link to comment Share on other sites More sharing options...
Developers Jos Posted February 18, 2011 Developers Share Posted February 18, 2011 Hi Again, thanks for your input so far, tbh I'm getting a little confused. Do I need to use reshacker to achieve what I want to do or can I used standard Autoit functionality? I know that I need to include resources.au3 to work with resource files and the _XMLDomWrapper.au3 for the xml commands, but Jos suggested that reshacker is not required.Try it and you know whether I am right or not SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
StimpsoO Posted February 18, 2011 Author Share Posted February 18, 2011 I have tried but I can't seem to get it working without reshacker. That is not really a problem, it just seems a bit neater if I can do it without. Taking a very simple example: <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> and #include <resources.au3> #AutoIt3Wrapper_UseUpx=N #AutoIt3Wrapper_Res_File_Add=Filename.xml,10,xml1,0 $strXML = _ResourceGetAsString("xml1",10,0) MsgBox(0, "Debug", $strXML) This compiles and runs but the message box is blank suggesting that the text of the xml file has not been loaded into the $strXML variable. Link to comment Share on other sites More sharing options...
Developers Jos Posted February 18, 2011 Developers Share Posted February 18, 2011 I have tried but I can't seem to get it working without reshacker. That is not really a problem, it just seems a bit neater if I can do it without. What does the SciTE output pane show when you compile? SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
StimpsoO Posted February 18, 2011 Author Share Posted February 18, 2011 It doesn't seem to throw any errors >"C:\Program Files (x86)\AutoIt3\SciTE\..\aut2exe\aut2exe.exe" /in "C:\Users\Home\Documents\MY AutoIt\Test2.au3" Ultimate Packer for eXecutables Copyright (C) 1996 - 2008 UPX 3.03w Markus Oberhumer, Laszlo Molnar & John Reiser Apr 27th 2008 File size Ratio Format Name -------------------- ------ ----------- ----------- 646144 -> 300544 46.51% win32/pe Test2.exe Packed 1 file. >Exit code: 0 Time: 3.634 Link to comment Share on other sites More sharing options...
Developers Jos Posted February 18, 2011 Developers Share Posted February 18, 2011 You need to load the full SciTE4AutoIt3 installer to make the AUtoIt3Wrapper directives work since that is part of that installer. Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
StimpsoO Posted February 18, 2011 Author Share Posted February 18, 2011 Ah good point, just came from work to home and only installed the basic AutoIt compiler here. Thanks Link to comment Share on other sites More sharing options...
wolf9228 Posted February 19, 2011 Share Posted February 19, 2011 Hi Again, thanks for your input so far, tbh I'm getting a little confused. Do I need to use reshacker to achieve what I want to do or can I used standard Autoit functionality? I know that I need to include resources.au3 to work with resource files and the _XMLDomWrapper.au3 for the xml commands, but Jos suggested that reshacker is not required. All Files ;This code can update the resource files of All Autoit versions ;Important before use this code must compile the AutoIt file without using UPX option ; AutoIt file ==> AutoitXml.exe UpdateResource.au3 expandcollapse popup#Include <WinAPI.au3> ;This code can update the resource files of All Autoit versions ;Important before use this code must compile the AutoIt file without using UPX option ; AutoIt file ==> AutoitXml.exe Global $AutoitScriptCodeDataStruct = 0 ,$ImageFileName = "" $hUpdate = BeginUpdateResource("AutoitXml.exe","New_AutoitXml.exe") $strXml = _ "<note>" & @CRLF & _ "<to>Tove</to>" & @CRLF & _ "<from>Jani</from>" & @CRLF & _ "<heading>Reminder</heading>" & @CRLF & _ "<body>Don't forget me this weekend!</body>" & @CRLF & _ "</note>" $DataStruct = StringToDataStruct($strXml) UpdateResource($hUpdate,10,"xml1",DllStructGetPtr($DataStruct),DllStructGetSize($DataStruct)) EndUpdateResource($hUpdate) Func BeginUpdateResource($pFileName = "Autoit.exe",$OutFile = "NewExeFile.exe",$bDeleteExistingResources = False) ;---------------------------------------------------------------Begins ;Get Image File WithOut Autoit Script Code And Save it In $OutFile = "NewExeFile.exe" Local $OF_READWRITE = 0x00000002 ,$OF_CREATE = 0x00001000 Local $FullPath = "" if $pFileName == $OutFile Then $SplitA = StringSplit($OutFile,"\") For $i = 1 To $SplitA[0] if $i = $SplitA[0] Then $FullPath &= "New_" & $SplitA[$i] Else $FullPath &= $SplitA[$i] & "\" EndIf Next $OutFile = $FullPath EndIf $ImageFileName = $OutFile $hFile = _WinAPI_CreateFile($pFileName, 2, 2) if Not ($hFile) Then Return -1 $HFILE1 = WINAPIOpenFile($OutFile,$OF_CREATE + $OF_READWRITE) $HFILE2 = WINAPIOpenFile($OutFile,$OF_CREATE + $OF_READWRITE) If Not ($HFILE1) Or Not ($HFILE2) Then Return -2 $IMAGE_DOS_HEADER = READ_IMAGE_DOS_HEADER($hFile,0) WRITE_IMAGE_DOS_HEADER($HFILE1,0,$IMAGE_DOS_HEADER) $MovePos = DllStructGetData($IMAGE_DOS_HEADER,"lfanew") $lfanew = $MovePos $Signature = READ_Signature($hFile,$MovePos) $IMAGE_NT_SIGNATURE_MAC = 0x00004550 ;C++6 WINNT.H $IMAGE_NT_SIGNATURE = 0x50450000 ;C++6 WINNT.H if DllStructGetData($Signature,"Signature") <> $IMAGE_NT_SIGNATURE_MAC And _ DllStructGetData($Signature,"Signature") <> $IMAGE_NT_SIGNATURE Then Return -3 WRITE_Signature($HFILE1,$MovePos,$Signature) $MovePos += DllStructGetSize($Signature) $IMAGE_FILE_HEADER = READ_IMAGE_FILE_HEADER($hFile,$MovePos) WRITE_IMAGE_FILE_HEADER($HFILE1,$MovePos,$IMAGE_FILE_HEADER) $MovePos += DllStructGetSize($IMAGE_FILE_HEADER) $IMAGE_OPTIONAL_HEADER = READ_IMAGE_OPTIONAL_HEADER($hFile,$MovePos) $IMAGE_NT_OPTIONAL_HDR32_MAGIC = 0x10b ;C++6 WINNT.H $IMAGE_NT_OPTIONAL_HDR64_MAGIC = 0x20b ;C++6 WINNT.H if DllStructGetData($IMAGE_OPTIONAL_HEADER,"Magic") <> $IMAGE_NT_OPTIONAL_HDR32_MAGIC _ And DllStructGetData($IMAGE_OPTIONAL_HEADER,"Magic") <> $IMAGE_NT_OPTIONAL_HDR64_MAGIC _ Then Return -4 $IMovePos = $MovePos WRITE_IMAGE_OPTIONAL_HEADER($HFILE1,$MovePos,$IMAGE_OPTIONAL_HEADER) $NumberOfSections = DllStructGetData($IMAGE_FILE_HEADER,"NumberOfSections") $MovePos += DllStructGetSize($IMAGE_OPTIONAL_HEADER) $JMovePos = $MovePos $SizeOfHeaders = DllStructGetData($IMAGE_OPTIONAL_HEADER,"SizeOfHeaders") ;SizeOf IMAGE_SECTION_HEADER ==> 40 $RemainderSize = $SizeOfHeaders - ($MovePos + $NumberOfSections * 40) $DataPos = ($MovePos + $NumberOfSections * 40) $DataStruct = READ_Data($hFile,$DataPos,$RemainderSize) WRITE_Data($HFILE2,$DataPos,$DataStruct) For $i = 1 To $NumberOfSections $IMAGE_SECTION_HEADER = READ_IMAGE_SECTION_HEADER($hFile,$MovePos) WRITE_IMAGE_SECTION_HEADER($HFILE1,$MovePos,$IMAGE_SECTION_HEADER) $PointerToRawData = DllStructGetData($IMAGE_SECTION_HEADER,"PointerToRawData") $SizeOfRawData = DllStructGetData($IMAGE_SECTION_HEADER,"SizeOfRawData") $VirtualAddress = DllStructGetData($IMAGE_SECTION_HEADER,"VirtualAddress") $ByteStruct = READ_SECTION($hFile,$PointerToRawData,$SizeOfRawData) WRITE_SECTION($HFILE2,$PointerToRawData,$byteStruct) $MovePos += DllStructGetSize($IMAGE_SECTION_HEADER) Next _WinAPI_CloseHandle($hFile) _WinAPI_CloseHandle($HFILE1) _WinAPI_CloseHandle($HFILE2) ;Get Image File WithOut Autoit Script Code And Save it In $OutFile = "NewExeFile.exe" ;-------------------------------------------------------------------------------- end $ImageFileSize = FileGetSize($OutFile) ;Get Image File Size WithOut Autoit Script Code $AutoitFileSize = FileGetSize($pFileName) ;Get Autoit File Size With Autoit Script Code $pFileName = "Autoit.exe" $AutoitScriptCodeSize = $AutoitFileSize - $ImageFileSize ;Get Autoit Script Code Size $AutoitScriptCodeDataStruct = FileToDataStruct($pFileName,2,$ImageFileSize,0) ;Flag = 2 Char ;$iPos = $ImageFileSize ;$iMethod = $FILE_BEGIN ;Get Autoit Script Code in DataStruct $HANDLE = DllCall("kernel32.dll","HANDLE","BeginUpdateResource","str", _ $OutFile,"BOOL",$bDeleteExistingResources) ;BeginUpdateResource New Image File ==> $OutFile if @error Then Return -5 Else if $HANDLE[0] = 0 Then Return -5 Return $HANDLE[0] EndIf EndFunc Func UpdateResource($hUpdate,$lpType,$lpName,$lpData,$cbData,$wLanguage = 0) if IsString($lpType) Then $DataType1 = "str" $lpType = StringUpper($lpType) ELSE $DataType1 = "long" $lpType = Int($lpType) EndIf if IsString($lpName) Then $DataType2 = "str" $lpName = StringUpper($lpName) ELSE $DataType2 = "long" $lpName = Int($lpName) EndIf $BOOL = DllCall("kernel32.dll","BOOL","UpdateResource","HANDLE",$hUpdate,$DataType1 _ ,$lpType,$DataType2,$lpName,"WORD",$wLanguage,"ptr",$lpData,"DWORD",$cbData) if Not @error Then Return $BOOL[0] Return 0 EndFunc Func EndUpdateResource($hUpdate,$fDiscard = False) Local $nBytes $BOOL = DllCall("kernel32.dll","BOOL","EndUpdateResource","HANDLE",$hUpdate,"BOOL",$fDiscard) if @error Then Return -1 if $BOOL[0] = 0 Then Return -1 $hFile = _WinAPI_CreateFile($ImageFileName,2,4) ;$ImageFileName = $OutFile if Not($hFile) Then Return -2 _WinAPI_SetFilePointer($hFile,0,2) ;Set File Pointer To The End Byte Or To The End Char Of File $AutoitScriptCodeDataStruct_Size = DllStructGetSize($AutoitScriptCodeDataStruct) $AutoitScriptCodeDataStruct_PTR = DllStructGetPtr($AutoitScriptCodeDataStruct) $BOOL = _WinAPI_WriteFile($hFile,$AutoitScriptCodeDataStruct_PTR,$AutoitScriptCodeDataStruct_Size,$nBytes) ;Write In The End Of New File $ImageFileName Autoit Script Code Data It Is Encrypted data if Not ($BOOL) Then Return -3 _WinAPI_CloseHandle($hFile) Return 1 EndFunc Func FileToDataStruct($FileName,$Flag = 1,$iPos = 0 ,$iMethod = 0) ;$Flag=1 Return BYTE DataStruct ;$Flag=2 Return Char DataStruct ;iPos Number of bytes to move the file pointer ;$iMethod ;[optional] The starting point for the file pointer move. ;Can be one of the predefined values: ;$FILE_BEGIN = 0 - The starting point is zero (0) or the beginning of the file ;$FILE_CURRENT = 1 - The starting point is the current value of the file pointer. ;$FILE_END = 2 - The starting point is the current end-of-file position. ;Implicit value is $FILE_BEGIN = 0 Local $iRead $FileSize = FileGetSize($FileName) if $FileSize = 0 Then Return -1 $hFile = _WinAPI_CreateFile($FileName, 2, 2) if Not($hFile) Then Return -2 _WinAPI_SetFilePointer($hFile,$iPos,$iMethod) if $Flag <> 1 Then $DataStruct = DllStructCreate("char[" & $FileSize & "]") Else $DataStruct = DllStructCreate("byte[" & $FileSize & "]") EndIf $BOOL = _WinAPI_ReadFile($hFile, DllStructGetPtr($DataStruct),$FileSize,$iRead) if @error Then Return -3 _WinAPI_CloseHandle($hFile) if $BOOL Then Return $DataStruct Else Return -3 EndIf EndFunc Func StringToDataStruct($Text,$Flag = 1) ;$Flag=1 Return BYTE DataStruct ;$Flag=2 Return Char DataStruct $Len = StringLen($Text) if $Len = 0 Then Return -1 if $Flag <> 1 Then $DataStruct = DllStructCreate("char[" & $Len & "]") Else $DataStruct = DllStructCreate("byte[" & $Len & "]") EndIf DllStructSetData($DataStruct,1,$Text) Return $DataStruct EndFunc Func CRE_IMAGE_SECTION_HEADER($BytePtr = 0) Local $IMAGE_SIZEOF_SHORT_NAME = 8 $Tag = _ ;// IMAGE_SECTION_HEADER C++6 WINNT.H without union "byte Name[" & $IMAGE_SIZEOF_SHORT_NAME & "];" & _ "dword Misc;" & _ "dword VirtualAddress;" & _ "dword SizeOfRawData;" & _ "dword PointerToRawData;" & _ "dword PointerToRelocations;" & _ "dword PointerToLinenumbers;" & _ "ushort NumberOfRelocations;" & _ "ushort NumberOfLinenumbers;" & _ "dword Characteristics" if ($BytePtr) Then _ Return MRtlMoveMemory($Tag,$BytePtr,40) ;reading the IMAGE_SECTION_HEADER Return DllStructCreate($Tag) ;Create EndFunc Func CRE_IMAGE_OPTIONAL_HEADER($BytePtr = 0) Local $Tag = _ ;// IMAGE_OPTIONAL_HEADER C++6 WINNT.H "ushort Magic;" & _ "ubyte MajorLinkerVersion;" & _ "ubyte MinorLinkerVersion;" & _ "dword SizeOfCode;" & _ "dword SizeOfInitializedData;" & _ "dword SizeOfUninitializedData;" & _ "dword AddressOfEntryPoint;" & _ "dword BaseOfCode;" & _ "dword BaseOfData;" & _ "dword ImageBase;" & _ "dword SectionAlignment;" & _ "dword FileAlignment;" & _ "ushort MajorOperatingSystemVersion;" & _ "ushort MinorOperatingSystemVersion;" & _ "ushort MajorImageVersion;" & _ "ushort MinorImageVersion;" & _ "ushort MajorSubsystemVersion;" & _ "ushort MinorSubsystemVersion;" & _ "dword Win32VersionValue;" & _ "dword SizeOfImage;" & _ "dword SizeOfHeaders;" & _ "dword CheckSum;" & _ "ushort Subsystem;" & _ "ushort DllCharacteristics;" & _ "dword SizeOfStackReserve;" & _ "dword SizeOfStackCommit;" & _ "dword SizeOfHeapReserve;" & _ "dword SizeOfHeapCommit;" & _ "dword LoaderFlags;" & _ "dword NumberOfRvaAndSizes;" & _ "byte byteData[128]" ; 128 ==> sizeof(IMAGE_DATA_DIRECTORY) * IMAGE_NUMBEROF_DIRECTORY_ENTRIES if ($BytePtr) Then _ Return MRtlMoveMemory($Tag,$BytePtr,224) Return DllStructCreate($Tag) ;Create EndFunc Func CRE_IMAGE_FILE_HEADER ($BytePtr = 0) $Tag = _ ;//File header format C++6 WINNT.H "ushort Machine;" & _ "ushort NumberOfSections;" & _ "dword TimeDateStamp;" & _ "dword PointerToSymbolTable;" & _ "dword NumberOfSymbols;" & _ "ushort SizeOfOptionalHeader;" & _ "ushort Characteristics" if ($BytePtr) Then _ Return MRtlMoveMemory($Tag,$BytePtr,20) ;reading the File header format Return DllStructCreate($Tag) ;Create EndFunc Func CRE_IMAGE_DOS_HEADER($BytePtr = 0) $Tag = _ ;// DOS .EXE header C++6 WINNT.H "ushort magic;" & _ ;// Magic number "ushort cblp;" & _ ;// Bytes on last page of file "ushort cp;" & _ ;// Pages in file "ushort crlc;" & _ ;// Relocations "ushort cparhdr;" & _ ;// Size of header in paragraphs "ushort minalloc;" & _ ;// Minimum extra paragraphs needed "ushort maxalloc;" & _ ;// Maximum extra paragraphs needed "ushort ss;" & _ ;// Initial (relative) SS value "ushort sp;" & _ ;// Initial SP value "ushort csum;" & _ ;// Checksum "ushort ip;" & _ ;// Initial IP value "ushort cs;" & _ ;// Initial (relative) CS value "ushort lfarlc;" & _ ;// File address of relocation table "ushort ovno;" & _ ;// Overlay number "ushort res[4];" & _ ;// Reserved words "ushort oemid;" & _ ;// OEM identifier (for e_oeminfo) "ushort oeminfo;" & _ ;// OEM information; e_oemid specific "ushort res2[10];" & _ ;// Reserved words "dword lfanew" ;// File address of new e if ($BytePtr) Then _ Return MRtlMoveMemory($Tag,$BytePtr,64) ;reading the dos header Return DllStructCreate($Tag) ;Create EndFunc Func READ_SECTION($hFile,$MovePos,$Size) Local $nBytes _WinAPI_SetFilePointer($hFile,$MovePos) $byteStruct = DllStructCreate("byte[" & $Size & "]") $byteStructPtr = DllStructGetPtr($byteStruct) _WinAPI_ReadFile($hFile,$byteStructPtr,$Size,$nBytes) Return $byteStruct EndFunc Func WRITE_SECTION($hFile,$MovePos,$byteStruct) Local $nBytes _WinAPI_SetFilePointer($hFile,$MovePos) $Size = DllStructGetSize($byteStruct) $byteStructPtr = DllStructGetPtr($byteStruct) _WinAPI_WriteFile($hFile,$byteStructPtr,$Size,$nBytes) EndFunc Func READ_Data($hFile,$MovePos,$Size) Local $nBytes _WinAPI_SetFilePointer($hFile,$MovePos) $byteStruct = DllStructCreate("BYTE[" & $Size & "]") $byteStructPtr = DllStructGetPtr($byteStruct) _WinAPI_ReadFile($hFile,$byteStructPtr,$Size,$nBytes) Return $byteStruct EndFunc Func WRITE_Data($hFile,$MovePos,$byteStruct) Local $nBytes _WinAPI_SetFilePointer($hFile,$MovePos) $Size = DllStructGetSize($byteStruct) $byteStructPtr = DllStructGetPtr($byteStruct) _WinAPI_WriteFile($hFile,$byteStructPtr,$Size,$nBytes) EndFunc Func READ_IMAGE_DOS_HEADER($hFile,$MovePos) Local $nBytes _WinAPI_SetFilePointer($hFile,$MovePos) $IMAGE_DOS_HEADER = CRE_IMAGE_DOS_HEADER() $Size = DllStructGetSize($IMAGE_DOS_HEADER) $PIMAGE_DOS_HEADER = DllStructGetPtr($IMAGE_DOS_HEADER) _WinAPI_ReadFile($hFile,$PIMAGE_DOS_HEADER,$Size,$nBytes) Return $IMAGE_DOS_HEADER EndFunc Func WRITE_IMAGE_DOS_HEADER($hFile,$MovePos,$IMAGE_DOS_HEADER) Local $nBytes _WinAPI_SetFilePointer($hFile,$MovePos) $Size = DllStructGetSize($IMAGE_DOS_HEADER) $PIMAGE_DOS_HEADER = DllStructGetPtr($IMAGE_DOS_HEADER) Return _WinAPI_WriteFile($hFile,$PIMAGE_DOS_HEADER,$Size,$nBytes) EndFunc Func READ_Signature($hFile,$MovePos) Local $nBytes _WinAPI_SetFilePointer($hFile,$MovePos) $Tag_Signature = "dword Signature" $Signature = DllStructCreate($Tag_Signature) $PSignature = DllStructGetPtr($Signature) $Size = DllStructGetSize($Signature) _WinAPI_ReadFile($hFile,$PSignature,$Size,$nBytes) Return $Signature EndFunc Func WRITE_Signature($hFile,$MovePos,$Signature) Local $nBytes _WinAPI_SetFilePointer($hFile,$MovePos) $Size = DllStructGetSize($Signature) $PSignature = DllStructGetPtr($Signature) Return _WinAPI_WriteFile($hFile,$PSignature,$Size,$nBytes) EndFunc Func READ_IMAGE_FILE_HEADER($hFile,$MovePos) Local $nBytes _WinAPI_SetFilePointer($hFile,$MovePos) $IMAGE_FILE_HEADER = CRE_IMAGE_FILE_HEADER() $Size = DllStructGetSize($IMAGE_FILE_HEADER) $PIMAGE_FILE_HEADER = DllStructGetPtr($IMAGE_FILE_HEADER) _WinAPI_ReadFile($hFile,$PIMAGE_FILE_HEADER,$Size,$nBytes) Return $IMAGE_FILE_HEADER EndFunc Func WRITE_IMAGE_FILE_HEADER($hFile,$MovePos,$IMAGE_FILE_HEADER) Local $nBytes _WinAPI_SetFilePointer($hFile,$MovePos) $Size = DllStructGetSize($IMAGE_FILE_HEADER) $PIMAGE_FILE_HEADER = DllStructGetPtr($IMAGE_FILE_HEADER) Return _WinAPI_WriteFile($hFile,$PIMAGE_FILE_HEADER,$Size,$nBytes) EndFunc Func READ_IMAGE_OPTIONAL_HEADER($hFile,$MovePos) Local $nBytes _WinAPI_SetFilePointer($hFile,$MovePos) $IMAGE_OPTIONAL_HEADER = CRE_IMAGE_OPTIONAL_HEADER() $Size = DllStructGetSize($IMAGE_OPTIONAL_HEADER) $PIMAGE_OPTIONAL_HEADER = DllStructGetPtr($IMAGE_OPTIONAL_HEADER) _WinAPI_ReadFile($hFile,$PIMAGE_OPTIONAL_HEADER,$Size,$nBytes) Return $IMAGE_OPTIONAL_HEADER EndFunc Func WRITE_IMAGE_OPTIONAL_HEADER($hFile,$MovePos,$IMAGE_OPTIONAL_HEADER) Local $nBytes _WinAPI_SetFilePointer($hFile,$MovePos) $Size = DllStructGetSize($IMAGE_OPTIONAL_HEADER) $PIMAGE_OPTIONAL_HEADER = DllStructGetPtr($IMAGE_OPTIONAL_HEADER) Return _WinAPI_WriteFile($hFile,$PIMAGE_OPTIONAL_HEADER,$Size,$nBytes) EndFunc Func READ_IMAGE_SECTION_HEADER($hFile,$MovePos) Local $nBytes _WinAPI_SetFilePointer($hFile,$MovePos) $IMAGE_SECTION_HEADER = CRE_IMAGE_SECTION_HEADER() $Size = DllStructGetSize($IMAGE_SECTION_HEADER) $PIMAGE_SECTION_HEADER = DllStructGetPtr($IMAGE_SECTION_HEADER) _WinAPI_ReadFile($hFile,$PIMAGE_SECTION_HEADER,$Size,$nBytes) Return $IMAGE_SECTION_HEADER EndFunc Func WRITE_IMAGE_SECTION_HEADER($hFile,$MovePos,$IMAGE_SECTION_HEADER) Local $nBytes if $MovePos <> 0 Then _WinAPI_SetFilePointer($hFile,$MovePos) $Size = DllStructGetSize($IMAGE_SECTION_HEADER) $PIMAGE_SECTION_HEADER = DllStructGetPtr($IMAGE_SECTION_HEADER) Return _WinAPI_WriteFile($hFile,$PIMAGE_SECTION_HEADER,$Size,$nBytes) EndFunc Func RtlMoveMemory($sourcePtr,$destPtr,$MovePos) DllCall("Kernel32.dll","none","RtlMoveMemory","ptr",$sourcePtr,"ptr",$destPtr,"dword",$MovePos) EndFunc Func MRtlMoveMemory($Tag_Struct,$Ptr,$MovePos) $Struct = DllStructCreate($Tag_Struct) $StructPtr = DllStructGetPtr($Struct) DllCall("Kernel32.dll","none","RtlMoveMemory","ptr",$StructPtr,"ptr",$Ptr,"dword",$MovePos) Return $Struct EndFunc Func WINAPIOpenFile($lpFileName,$uStyle) $Tag_OFSTRUCT = _ "byte cBytes;" & _ "byte fFixedDisk;" & _ "ushort nErrCode;" & _ "ushort Reserved1;" & _ "ushort Reserved2;" & _ "char szPathName[260]" $OFSTRUCT = DllStructCreate($Tag_OFSTRUCT) $lpReOpenBuff = DllStructGetPtr($OFSTRUCT) $HFILE = DllCall("Kernel32.dll","hwnd","OpenFile","str",$lpFileName,"ptr",$lpReOpenBuff,"long",$uStyle) if Not @error Then Return $HFILE[0] Return 0 EndFunc Resource Functions ;http://msdn.microsoft.com/en-us/library/ff468902%28v=VS.85%29.aspx AutoitXml.au3 AutoIt file Example expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseUpx=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #Include <WinAPI.au3> #include "_XMLDomWrapper.au3" $strXML = StrGetResource("xml1",10) if @error Then Exit MsgBox(0,"",$strXML) $Rt = _XMLLoadXML($strXML) if $Rt <> -1 Then MsgBox(0,"","Success") ;http://msdn.microsoft.com/en-us/library/ff468902%28v=VS.85%29.aspx ;Resource Functions Func StrGetResource($lpName,$lpType) Local $NDataType , $TDataType if IsString($lpName) Then $lpName = StringUpper($lpName) $NDataType = "wstr" Else $NDataType = "long" EndIf if IsString($lpType) Then $lpType = StringUpper($lpType) $TDataType = "wstr" Else $TDataType = "long" EndIf $hModule = _WinAPI_GetModuleHandle(0) $HRSRC = DllCall("Kernel32.dll","ptr","FindResourceW","ptr", _ $hModule,$NDataType,$lpName,$TDataType,$lpType) if @error Or $HRSRC[0] = 0 Then Return SetError(1,0,0) $HRSRC = $HRSRC[0] $HGLOBAL = DllCall("Kernel32.dll","ptr","LoadResource","ptr",$hModule,"ptr",$HRSRC) if @error Or $HGLOBAL[0] = 0 Then Return SetError(2,0,0) $HGLOBAL = $HGLOBAL[0] $LPVOID = DllCall("Kernel32.dll","ptr","LockResource","ptr",$HGLOBAL) if @error Or $LPVOID[0] = 0 Then Return SetError(3,0,0) $LPVOID = $LPVOID[0] $ResSize = DllCall("Kernel32.dll","DWORD","SizeofResource","ptr",$hModule,"ptr",$HRSRC) if @error Or _WinAPI_GetLastError() <> 0 Then Return SetError(4,0,0) $ResSize = $ResSize[0] $DataStruct = DllStructCreate("CHAR[" & $ResSize & "]",$LPVOID) Return SetError(0,0,DllStructGetData($DataStruct,1)) EndFunc صرح السماء كان هنا Link to comment Share on other sites More sharing options...
GEOSoft Posted February 19, 2011 Share Posted February 19, 2011 You don't need any UDFs at all. Just use the built in directives in Scite. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
wolf9228 Posted February 19, 2011 Share Posted February 19, 2011 Not sure where you got this posted information from, but I know that the doc's aren't 100% in the current published helpfile, but the one on my SVN repo for the next release is containing the correct information. صرح السماء كان هنا Link to comment Share on other sites More sharing options...
GEOSoft Posted February 19, 2011 Share Posted February 19, 2011 And I can tell you right now that back when The Wrapper was still using Resource Hacker, the wrapper was modified to read the registry for a key that gave the path to RH. That path is only in the registry if you use my installer version of Resource Hacker and the download for that is in my signature. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now