Jump to content

exe2au3


Recommended Posts

I wrote some code to open a file and wanted to make sure I had the right path in the exe, so I used this application and what was 6 k turned into 62 k - I then looked at the code and found a lot of things that were not mine.

I think I have the answer, but want to make sure - all calls to external functions are added to the exe file and therefore when it is brought back into a au3 file it comes with it.

Is this right?

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

  • Moderators

You'll see where it says Start Include/String.au3 and End Include/String.au3 as an example when decompiled. But the Entire include file is included, not just the functions you are using.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

You'll see where it says Start Include/String.au3 and End Include/String.au3 as an example when decompiled. But the Entire include file is included, not just the functions you are using.

I get it now. Thanks.

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

Here is a cleanup script I made some time ago to cleanup decompiled scripts for something to do. It will backup your script by FileMove. Worked ok when last tested.

Global Const $IDYES = 6

If $CMDLINE[0] = 1 Then
    ; Use Commandline selection
    $file_source = $CMDLINE[1]
    If StringInStr($file_source, '\') Then
        $split = StringSplit($file_source, '\')
        If Not @error Then
            $path = StringReplace($file_source, '\' & $split[$split[0]], '')
            If @extended And FileExists($path) Then
                FileChangeDir($path)
            EndIf
        EndIf
    EndIf
Else
    ; Use FileOpenDialog selection
    While True
        $file_source = FileOpenDialog('Choose a decompiled Au3 file to process', @WorkingDir, 'AutoIt files (*.au3)')
        If @error Then
            If MsgBox(0x40024, @ScriptName, 'Do you want to quit') = $IDYES Then
                Exit
            EndIf
        Else
            ExitLoop
        EndIf
    WEnd
EndIf
; Check that file does indeed exist, else exit
If Not FileExists($file_source) Then Exit
; Read whole file at once
$file_read = FileRead($file_source, FileGetSize($file_source))
If Not @error And $file_read Then
    ; Split the file into an array
    $line = StringSplit($file_read, @CRLF, 1)
    $file_read = ''
    If Not @error And IsArray($line) Then
        Global $contents_script, $contents_include
        ; Loop to process each element of the array
        For $i = 1 To $line[0]
            Select
                Case _StringLeft($line[$i], '; <AUT2EXE VERSION')
                    ; Skip 1st few lines
                    While Not _StringLeft($line[$i], '; <AUT2EXE INCLUDE-START:')
                        ; Increase element index
                        $i += 1
                    WEnd
                    ContinueLoop
                Case _StringLeft($line[$i], '; -----------------')
                    ; Skip separator lines
                    ContinueLoop
                Case _StringLeft($line[$i], '; <AUT2EXE INCLUDE-START:')
                    ; Change Include code section start into #include <...>
                    If StringInStr($line[$i], '\') Then
                        $split = StringSplit($line[$i], '\')
                        If Not @error Then
                            $contents_script = '#include <' & $split[$split[0]]
                            $file_include = StringTrimRight($split[$split[0]], 1)
                        EndIf
                    Else
                        $contents_script = StringReplace($line[$i], '; <AUT2EXE INCLUDE-START: ', '#include <')
                    EndIf
                    ; Increase element index
                    $i += 1
                    ; Process Include code section
                    While Not _StringLeft($line[$i], '; <AUT2EXE INCLUDE-END:')
                        If _StringLeft($line[$i], '; <AUT2EXE INCLUDE-START:') Then
                            ; Decrease element index, Clear Include variable and restart the For loop
                            $i -= 1
                            $contents_include = ''
                            ContinueLoop 2
                        EndIf
                        ; Concatenate Include lines
                        $contents_include &= @CRLF & $line[$i]
                        ; Increase element index
                        $i += 1
                    WEnd
                    ; Write Include file, clear Include variable and restart the For loop
                    If Not FileExists($file_include) Then
                        FileWrite($file_include, $contents_include)
                    EndIf
                    $contents_include = ''
                    ContinueLoop
                Case _StringLeft($line[$i], '; <AUT2EXE INCLUDE-END:')
                    ; Skip Include-end lines
                    ContinueLoop
            EndSelect
            ; Concatenate Script lines
            $contents_script &= @CRLF & $line[$i]
        Next
    EndIf
EndIf
;~ ConsoleWrite(StringStripCR($contents_script) & @LF)
;~ ConsoleWrite(StringStripCR($contents_include) & @LF)

If FileMove($file_source, StringTrimRight($file_source, 4) & '.bak.au3') Then
    FileWrite($file_source, $contents_script)
EndIf

Exit

Func _StringLeft(ByRef $string, $substring)
    Local $substring_length = StringLen($substring)
    If $substring_length Then
        Return StringLeft($string, $substring_length) = $substring
    EndIf
EndFunc

Compile it and drop a script on it.

It perhaps could be improved more. :whistle:

Edit:

Removed the last line in the code as it should have been outside the [ codetag ]

Edited by MHz
Link to comment
Share on other sites

That is F#$ing amazing. I wish I could understand it, maybe in time. I think if I could understand it - I would add a status to it.

Thanks for the great tool - I luv autoIT and all the great people on this forum that give their time so freely.

Wish the rest of the world would be so kind!

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

  • Moderators

Following your example MHz, I took a stab at it:

If $CMDLINE[0] = 1 Then
    $hFile_Source = $CMDLINE[1]
    If StringInStr($hFile_Source, '\') Then
        $aSplit = StringSplit($hFile_Source, '\')
        If Not @error Then
            $sPath = StringReplace($hFile_Source, '\' & $aSplit[$aSplit[0]], '')
            If @extended And FileExists($sPath) Then
                FileChangeDir($sPath)
            EndIf
        EndIf
    EndIf
Else
    While True
        $hFile_Source = FileOpenDialog('Choose a decompiled Au3 file to process', @WorkingDir, 'AutoIt files (*.au3)')
        If @error Then
            If MsgBox(0x40024, @ScriptName, 'Do you want to quit') = 6 Then
                Exit
            EndIf
        Else
            ExitLoop
        EndIf
    WEnd
EndIf

Global $hRead = FileRead($hFile_Source)
If @error Or Not $hRead Then Exit

Global $sAUTStart = "; <AUT2EXE INCLUDE-START: ", $sAUTEnd = "; <AUT2EXE INCLUDE-END: "
Global $sSeperator = "; ----------------------------------------------------------------------------"
$aIncStrings = _SRE_Between($hRead, $sAUTStart, ">")
If Not IsArray($aIncStrings) Then Exit

Global $aStringIncSE[UBound($aIncStrings)][3], $sHoldString, $nCount = 6
For $iCount = 1 To UBound($aIncStrings) - 2
    $aStringIncSE[$iCount][0] = $sAUTStart & $aIncStrings[$iCount] & '>'
    $aStringIncSE[$iCount][1] = $sAUTEnd & $aIncStrings[$iCount] & '>'
    $aStringIncSE[$iCount][2] = '#include ' & '"' & $aIncStrings[$iCount]  & '"'
Next

$hRead = StringSplit($hRead, @LF, 1)
Global $xCount = 7, $iFound
While $xCount < ($hRead[0] - 5)
    If StringInStr($hRead[$xCount], $sAUTStart) Then
        For $iCount = 1 To UBound($aStringIncSE, 1) - 1
            If StringLeft($hRead[$xCount], StringLen($aStringIncSE[$iCount][0])) = $aStringIncSE[$iCount][0] Then
                $sHoldString &= $aStringIncSE[$iCount][2] & @LF
                $xCount += 1
                $iFound = Not $iFound
                ExitLoop
            EndIf
        Next
        If $iFound Then
            While 1
                If StringLeft($hRead[$xCount], StringLen($sAUTEnd)) = $sAUTEnd Then
                    $xCount += 3
                    $iFound = Not $iFound
                    ExitLoop
                EndIf
                $xCount += 1
            WEnd
        EndIf
    ElseIf StringLeft($hRead[$xCount], StringLen($sSeperator)) = $sSeperator Then
        $xCount += 1
    Else
        $sHoldString &= $hRead[$xCount] & @LF
        $xCount += 1
    EndIf
WEnd

If FileMove($hFile_Source, StringTrimRight($hFile_Source, 4) & '.bak.au3') Then
    FileWrite($hFile_Source, StringTrimRight(StringTrimLeft($sHoldString, 2), 2))
EndIf
Exit

Func _SRE_Between($s_String, $s_Start, $s_End)
    $a_Array = StringRegExp($s_String, '(?:' & $s_Start & ')(.*?)(?:' & $s_End & ')', 3)
    If IsArray($a_Array) Then Return $a_Array
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I must say - I will have to compare these two scripts to see why SmOke_n's is so much faster. And I like both ways of opening the file - the second way seems to be user friendly.

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

Link to comment
Share on other sites

Nice, only thing that I could see as a weakness was StringSplit() with error check and @LF is only 1 character so the 3rd parameter seems unnecessary. But a nice recode. Just need a Gui like Exe2Aut now to top it off. :whistle:

I think we should just add the code to the Exe2Aut - with a check box, checked you get your code only and unchecked you get all the code - if that is possible?

All by me:

"Sometimes you have to go back to where you started, to get to where you want to go." 

"Everybody catches up with everyone, eventually" 

"As you teach others, you are really teaching yourself."

From my dad

"Do not worry about yesterday, as the only thing that you can control is tomorrow."

 

WindowsError.gif

WIKI | Tabs; | Arrays; | Strings | Wiki Arrays | How to ask a Question | Forum Search | FAQ | Tutorials | Original FAQ | ONLINE HELP | UDF's Wiki | AutoIt PDF

AutoIt Snippets | Multple Guis | Interrupting a running function | Another Send

StringRegExp | StringRegExp Help | RegEXTester | REG TUTOR | Reg TUTOT 2

AutoItSetOption | Macros | AutoIt Snippets | Wrapper | Autoit  Docs

SCITE | SciteJump | BB | MyTopics | Programming | UDFs | AutoIt 123 | UDFs Form | UDF

Learning to script | Tutorials | Documentation | IE.AU3 | Games? | FreeSoftware | Path_Online | Core Language

Programming Tips

Excel Changes

ControlHover.UDF

GDI_Plus

Draw_On_Screen

GDI Basics

GDI_More_Basics

GDI Rotate

GDI Graph

GDI  CheckExistingItems

GDI Trajectory

Replace $ghGDIPDll with $__g_hGDIPDll

DLL 101?

Array via Object

GDI Swimlane

GDI Plus French 101 Site

GDI Examples UEZ

GDI Basic Clock

GDI Detection

Ternary operator

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