Jump to content

AutoIt3 Crash and Burn


 Share

Recommended Posts

I am workng on a script that wraps executables and their dependencies. Right now it is just supposed to generate another au3 file dynamically based on settings in the project INI file. You can dl the files as they are if you find them attached. Well here is the code that I have:

Global $IniProjFile = "Test.ini"
Global $DestFolder = @TempDir & "\Temp" & Int(Random(0, 999))

ExeWrap( $IniProjFile )

Func ExeWrap( $IniFile )
   
   Local $AppName, $OutFile, $ExeFile, $IncCount
   Local $Includes
   Local $i, $file
   
   $AppName = IniRead( $IniFile, "Main", "AppName", "" )
   $ExeFile = IniRead( $IniFile, "Main", "ExeFile", "" )
   $OutFile = IniRead( $IniFile, "Main", "TempFile", "" )
   $IncCount = IniRead( $IniFile, "Main", "IncludeCount", "" )
   
   ReDim $Includes[ $IncCount ]
   
   If $IncCount <> 0 Then
      For $i = 0 to $IncCount - 1
         $Includes[0] = IniRead( $IniFile, "Includes", "Include" & $i, "" )
      Next
   EndIf
   
   $file = FileOpen( $OutFile, 2 )
   
   If( $file = -1 ) Then
      
   EndIf
   
   If ( StringRight( $DestFolder, 1 ) <> "\" ) Then
      $DestFolder = $DestFolder & "\"
   EndIf
   
   FileWriteLine( $file, "#comments-start" )
   FileWriteLine( $file, FillString( "*", 135 )
   FileWriteLine( $file, "*    This code was generated using ExeWrap, by Matthew Babcock                                                                       *" )
   FileWriteLine( $file, FillString( "*", 135 )
   FileWriteLine( $file, "#comments-end" )
   FileWriteLine( $file, "" )
   FileWriteLine( $file, "FileInstall( " & $ExeFile & ", " & $DestFolder & ", " & "1 )" )
   For $i = 0 to UBound($Includes) - 1
      FileWriteLine( $file, "FileInstall( " & $Includes[$i] & ", " & $DestFolder & ", " & "1 )" )
   Next
   FileWriteLine( $file, "" )
   FileWriteLine( $file, "RunWait( """ & $DestFolder & ParseFile( $ExeFile ) & """ )"
   FileWriteLine( $file, "" )
   FileWriteLine( $file, "FileDelete( """ & $DestFolder & ParseFile( $ExeFile ) & """ )"
   For $i = 0 to UBound($Includes) - 1
      FileWriteLine( $file, "FileDelete( " & $DestFolder & ParseFile($Includes[$i]) & """ )"
   Next
   
   FileClose( $file )
   
EndFunc

Func ParseFile( $FullPath )
   
   Local $tmp

   $tmp = StringSplit( $FullPath, "\" )
   Return $tmp[$tmp[0]] 

EndFunc

Func FillString( $char, $length )
   
   Dim $i, $tmpString
   
   $tmpString = ""
   
   For $i = 1 to $length
      $tmpString = $tmpString & $char
   Next
   
   Return $tmpString
   
EndFunc

The INI file currently contains:

[Main]
AppName=Test Application
ExeFile=E:\Documents and Settings\Matt\Desktop\Project1.exe
TempFile=Test.au3
IncludeCount=1

[Includes]
Include0=E:\Documents and Settings\Matt\Desktop\service.txt

The way this should work is you point the ExeFile key at any executable (full path only) and it should include the executable into the dynamically created AU3 file using FileInstall(). The code is pretty self-explainitory, but I don't understand why AutoIt3.exe blows up when it is run.

Any suggestions?

*** Matt @ MPCS

EDIT: Posted outdated version... new version posted

EDIT: Fixed typo

Edited by Matt @ MPCS
Link to comment
Share on other sites

  • Developers

I am workng on a script that wraps executables and their dependencies. Right now it is just supposed to generate another au3 file dynamically based on settings in the project INI file. You can dl the files as they are if you find them attached. Well here is the code that I have:

The way this should work is you point the ExeFile key at any executable (full path only) and it should include the executable into the dynamically created AU3 file using FileInstall(). The code is pretty self-explainitory, but I don't understand why AutoIt3.exe blows up when it is run.

Any suggestions?

*** Matt @ MPCS

EDIT: Posted outdated version... new version  posted

EDIT: Fixed typo

<{POST_SNAPBACK}>

You where missing a couple of closing brackets and "" ....

See if this works for you:

EDIT: runs ok in 3.0.102... i also get the crash and burn in 3.0.103...

Global $IniProjFile = "Test.ini"
Global $DestFolder = @TempDir & "\Temp" & Int(Random(0, 999))

ExeWrap( $IniProjFile )


Func ExeWrap( $IniFile )
   
   Local $AppName, $OutFile, $ExeFile, $IncCount
   Local $Includes
   Local $i, $file
   
   $AppName = IniRead( $IniFile, "Main", "AppName", "" )
   $ExeFile = IniRead( $IniFile, "Main", "ExeFile", "" )
   $OutFile = IniRead( $IniFile, "Main", "TempFile", "" )
   $IncCount = IniRead( $IniFile, "Main", "IncludeCount", "" )
   
   ReDim $Includes[ $IncCount ]
   
   If $IncCount <> 0 Then
      For $i = 0 to $IncCount - 1
         $Includes[0] = IniRead( $IniFile, "Includes", "Include" & $i, "" )
      Next
   EndIf
   
   $file = FileOpen( $OutFile, 2 )
   
   If( $file = -1 ) Then
      
   EndIf
   
   If ( StringRight( $DestFolder, 1 ) <> "\" ) Then
      $DestFolder = $DestFolder & "\"
   EndIf
   
   FileWriteLine( $file, "#comments-start" )
   FileWriteLine( $file, FillString( "*", 135 ))
   FileWriteLine( $file, "*    This code was generated using ExeWrap, by Matthew Babcock                                                                       *" )
   FileWriteLine( $file, FillString( "*", 135 ))
   FileWriteLine( $file, "#comments-end" )
   FileWriteLine( $file, "" )
   FileWriteLine( $file, "FileInstall( """ & $ExeFile & """, """ & $DestFolder & """,1 )" )
   For $i = 0 to UBound($Includes) - 1
      FileWriteLine( $file, "FileInstall( """ & $Includes[$i] & ", " & $DestFolder & """,1 )" )
   Next
   FileWriteLine( $file, "" )
   FileWriteLine( $file, "RunWait( """ & $DestFolder & ParseFile( $ExeFile ) & """ )")
   FileWriteLine( $file, "" )
   FileWriteLine( $file, "FileDelete( """ & $DestFolder & ParseFile( $ExeFile ) & """ )")
   For $i = 0 to UBound($Includes) - 1
      FileWriteLine( $file, "FileDelete( """ & $DestFolder & ParseFile($Includes[$i]) & """ )")
   Next
   
   FileClose( $file )
   
EndFunc

Func ParseFile( $FullPath )
   
   Local $tmp

   $tmp = StringSplit( $FullPath, "\" )
   Return $tmp[$tmp[0]] 

EndFunc

Func FillString( $char, $length )
   
   Dim $i, $tmpString
   
   $tmpString = ""
   
   For $i = 1 to $length
      $tmpString = $tmpString & $char
   Next
   
   Return $tmpString
   
EndFunc
Edited by JdeB

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

Thanks JdeB, I figured that out after tinkering around with it for a little while longer, but that wouldn't cause it to crash. There were several syntax errors, but I think what was causing it to crash was that I was ReDimming $Includes without declaring it as an array first.

The following code works (also attached):

Global $IniProjFile = "Test.ini"
Global $DestFolder = @TempDir & "\Temp" & Int(Random(0, 999))

ExeWrap( $IniProjFile )

Func ExeWrap( $IniFile )
   
   Local $AppName, $OutFile, $ExeFile, $IncCount
   Local $Includes[1]
   Local $i, $file
   
   $AppName = IniRead( $IniFile, "Main", "AppName", "" )
   $ExeFile = IniRead( $IniFile, "Main", "ExeFile", "" )
   $OutFile = IniRead( $IniFile, "Main", "TempFile", "" )
   $IncCount = IniRead( $IniFile, "Main", "IncludeCount", "" )
   
   ReDim $Includes[ $IncCount ]
   
   If $IncCount <> 0 Then
      For $i = 0 to $IncCount - 1
         $Includes[0] = IniRead( $IniFile, "Includes", "Include" & $i, "" )
      Next
   EndIf
   
   $file = FileOpen( $OutFile, 2 )
   
   If( $file = -1 ) Then
      
   EndIf
   
   If ( StringRight( $DestFolder, 1 ) <> "\" ) Then
      $DestFolder = $DestFolder & "\"
   EndIf
   
   FileWriteLine( $file, "#comments-start" )
   FileWriteLine( $file, FillString( "*", "135" ) )
   FileWriteLine( $file, "*    This code was generated using ExeWrap, by Matthew Babcock                                                                       *" )
   FileWriteLine( $file, FillString( "*", "135" ) )
   FileWriteLine( $file, "#comments-end" )
   FileWriteLine( $file, "" )
   FileWriteLine( $file, "FileInstall( """ & $ExeFile & """, """ & $DestFolder & """, " & "1 )" )
   For $i = 0 to UBound($Includes) - 1
      FileWriteLine( $file, "FileInstall( """ & $Includes[$i] & """, """ & $DestFolder & """, " & "1 )" )
   Next
   FileWriteLine( $file, "" )
   FileWriteLine( $file, "RunWait( """ & $DestFolder & ParseFile( $ExeFile ) & """ )" )
   FileWriteLine( $file, "" )
   FileWriteLine( $file, "FileDelete( """ & $DestFolder & ParseFile( $ExeFile ) & """ )" )
   For $i = 0 to UBound($Includes) - 1
      FileWriteLine( $file, "FileDelete( """ & $DestFolder & ParseFile($Includes[$i]) & """ )" )
   Next
   
   FileClose( $file )
   
EndFunc

Func ParseFile( $FullPath )
   
   Local $tmp

   $tmp = StringSplit( $FullPath, "\" )
   Return $tmp[$tmp[0]] 

EndFunc

Func FillString( $char, $length )
   
   Dim $i, $tmpString
   
   $tmpString = ""
   
   For $i = 1 to Number($length)
      $tmpString = $tmpString & $char
   Next
   
   Return $tmpString
   
EndFunc

The INI File:

[Main]
AppName=Test Application
ExeFile=E:\Documents and Settings\Matt\Desktop\Project1.exe
TempFile=Test.au3
IncludeCount=1

[Includes]
Include0=E:\Documents and Settings\Matt\Desktop\service.txt

And this script successfully generated:

#comments-start
****************************************************************************************************

***********************************
*    This code was generated using ExeWrap, by Matthew Babcock                                                                       *
****************************************************************************************************

***********************************
#comments-end

FileInstall( "E:\Documents and Settings\Matt\Desktop\Project1.exe", "E:\DOCUME~1\Matt\LOCALS~1\Temp\Temp489\", 1 )
FileInstall( "E:\Documents and Settings\Matt\Desktop\service.txt", "E:\DOCUME~1\Matt\LOCALS~1\Temp\Temp489\", 1 )

RunWait( "E:\DOCUME~1\Matt\LOCALS~1\Temp\Temp489\Project1.exe" )

FileDelete( "E:\DOCUME~1\Matt\LOCALS~1\Temp\Temp489\Project1.exe" )
FileDelete( "E:\DOCUME~1\Matt\LOCALS~1\Temp\Temp489\service.txt" )

Is there a way that I can compile this script on a machine that doesn;t have autoit installed? I would probably have to include the AU2EXE utility with the generator. Does anyone know a good way to do this?

Like I said the goal of this project is to generate an executable that contains an executable that requires runtime files. I was designing it with Visual Basic applications in mind. Any suggestions/questions are welcome.

*** Matt @ MPCS

EDIT: lol forgot to attach the current script version

ExeWrap.au3

Edited by Matt @ MPCS
Link to comment
Share on other sites

  • Developers

You where missing a couple of closing brackets and "" ....

See if this works for you:

EDIT: runs ok in 3.0.102...   i also get the crash and burn in 3.0.103...

<{POST_SNAPBACK}>

Jon, the above script crashes on : ReDim $Includes[ $IncCount ] with a 0xc0000005 !

Matt @ MPCS, agree it shouldn't crash... change the Redim to Dim... that fixes it for now...

Edited by JdeB

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

  • Developers

@Jdeb

I just changed the following:

Local $Includes

To:

Local $Includes[1]

and it works fine.

*** Matt @ MPCS

<{POST_SNAPBACK}>

Yeap... same result...

Mmmh....Similar bug was fixed in an earlier 103 version see: http://www.autoitscript.com/forum/index.ph...indpost&p=28456 :ph34r:

Edited by JdeB

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

When I got that error I searched the forum for "crashed" and found that thread, but I am running 103... so shouldn't have been fixed? I have only had this version for less than a month so I thought it was up to date (minus the most recent changes in InetGet). I guess not.

I am however still looking for a solution to compile the generated script. Have any suggestions?

Link to comment
Share on other sites

  • Developers

When I got that error I searched the forum for "crashed" and found that thread, but I am running 103... so shouldn't have been fixed? I have only had this version for less than a month so I thought it was up to date (minus the most recent changes in InetGet). I guess not.

I am however still looking for a solution to compile the generated script. Have any suggestions?

<{POST_SNAPBACK}>

Something like?

$rc = runwait(@ProgramFilesDir & "\autoit3\aut2exe\aut2exe /in" & $OutFile)

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

I was thinking of something a little more advanced than that, but that'll work for the first version. That will work if they have AutoIt installed... but if I wanted to give this wrapper to a random VB coder then it won't work. The way I understand it, when you compile an autoit script you are really just merging the autoit interpreter and the script being compiled... then when it is run it refers to the location inside the executable of the script for the code. Is that right?

*** Matt @ MPCS

Link to comment
Share on other sites

  • Developers

I was thinking of something a little more advanced than that, but that'll work for the first version. That will work if they have AutoIt installed... but if I wanted to give this wrapper to a random VB coder then it won't work. The way I understand it, when you compile an autoit script you are really just merging the autoit interpreter and the script being compiled... then when it is run it refers to the location inside the executable of the script for the code. Is that right?

*** Matt @ MPCS

<{POST_SNAPBACK}>

yes...

You need the following files to be able to compile the script and could include those with a fileinstall and remove when done:

Aut2Exe.exe

AutoItSC.bin

upx.exe

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

  • Administrators

When I got that error I searched the forum for "crashed" and found that thread, but I am running 103... so shouldn't have been fixed? I have only had this version for less than a month so I thought it was up to date (minus the most recent changes in InetGet). I guess not.

I am however still looking for a solution to compile the generated script. Have any suggestions?

The error fixed was crashing on ReDim on an undeclared variable. This is slightly different as the variable is declared it gets past that check and BOOM.
Link to comment
Share on other sites

I don't blame you Jon... and as long as I can use my solution and have it work I am a happy camper. You may consider a more permenant fix for the future though. No rush for me though :ph34r: I ve got my script working really well.

*** Matt @ MPCS

Link to comment
Share on other sites

  • Administrators

I don't blame you Jon... and as long as I can use my solution and have it work I am a happy camper. You may consider a more permenant fix for the future though. No rush for me though :ph34r: I ve got my script working really well.

*** Matt @ MPCS

I've fixed it at this end to give an error if you try and redim a non-array var.
Link to comment
Share on other sites

  • Administrators

Sounds like a quick fix, but I am sure it is what I would have done.

*** Matt @ MPCS

It's equally easy to make it automatically dim it instead, but I'm not sure what redim should do when it's being asked to redim something that hasn't been dimmed.
Link to comment
Share on other sites

  • Developers

It's equally easy to make it automatically dim it instead, but I'm not sure what redim should do when it's being asked to redim something that hasn't been dimmed.

<{POST_SNAPBACK}>

my vote goes to making it userfriendly and let it DIM a var if it "isn't defined yet" or "isn't Dimmed as Array"

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

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