Jump to content

Flatten .au3 to have includes as part of the raw code


Recommended Posts

So this is a dumb question, and the wrong way to solve a problem.

I have a random error in a script that is already out in the wild compiled as an .exe and I get the "crash" that tells me what line it failed at in the code.

Of course this does not match the line numbers in my source .au3 file.

It also does not seem to prevent the script from doing it's job so its probably crashing on the last iteration of a loop.

 

Because the error is quite rare and already in the wild and I know what line # is causing it, is there a way with Scite to basically produce the same raw code that would be present in the compiled .exe?

 

This way I can match up the line causing the issue and fix it?

 

Regards,

 

Link to comment
Share on other sites

Au3stripper with /mo parameter.

/mo : Just merges the Include files into the source and strips the Comments.
      This is similar to aut2exe and helps finding the errorline.

Link to comment
Share on other sites

1 hour ago, TheXman said:

Au3stripper with /mo parameter.

/mo : Just merges the Include files into the source and strips the Comments.
      This is similar to aut2exe and helps finding the errorline.

 

Thanks that was what I was looking for earlier, just couldn't find the parameter I needed.

It actually did not help with my problem as the 1000 lines is far short of the line 3000 that reported an error, but at least now I know a new skill.

 

I'll have to wait until I find another computer with the issue and see if I can recreate it then I will figure it out.

 

Thanks for the help.

Link to comment
Share on other sites

You're welcome. :thumbsup:

On a totally different subject, thank you, I've enjoyed a lot of your Youtube content related to network hardware.  Even though I'm retired, I still enjoy playing with that stuff too.  :)

Link to comment
Share on other sites

I've been deploying software to another department inside my company that doesn't have any shared access with us. To see when they're having an issue, I debug to a log and send an email to myself on any error that I can't recover. I send email without user interaction and attach the debug log and the error message.

Similarly, you could a have a wrapper program that launches your main program that will send an email if the exit code isn't 0... which is the default if there is an error, I think :)

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager
InputBoxes - Simple Input boxes for various variable types

Link to comment
Share on other sites

Additional Info :  https://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/Au3Stripper.html

#Au3Stripper_Parameters=/MO

/MergeOnly
/MO
Will produce a scriptfile as AUT2EXE includes in the Compiled EXE. This allows you to find the proper linenumber when errors are reported.
Note: Make sure you remove the #pragma lines or else the linenumbers will be off by the that number of records

@ViciousXUSMC :

Run the master script through au3stripper with the /MO parameter and check the produced [scriptname]_stripped.au3 for the linenumber in the error - but be aware of #Pragma statements, if you use any.

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

For the fun ...
I formerly made for myself a litle tool to do this. It's rough (of course) but maybe it could help
Sorry for the french language. It should be understandable though

Please be indulgent  :)

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>

Global Const $__LISTVIEWCONSTANT_WM_SETREDRAW = 0x000B
Opt("GUIDataSeparatorChar", ChrW(9617))

$gui = GUICreate("test", 520, 360, -1, 150)
$listview = GUICtrlCreateListView("Lignes", 10, 50, 500, 300)
GUICtrlSetFont($listview, 8.5, 0, 0, "Tahoma")
GUICtrlSendMsg($listview, $LVM_SETCOLUMNWIDTH, 0, 480)
GuiCtrlCreateLabel("Ligne à chercher :", 20, 17, 100, 20)
$Input = GUICtrlCreateInput("", 110, 15, 40, 20)
$Vazi = GUICtrlCreateButton("Charger le script", 180, 15, 120, 20)
GUISetState(@SW_SHOW)


While 1
 Switch GUIGetMsg()
   Case $GUI_EVENT_CLOSE
         Exit
   Case $Vazi
          $n = GuiCtrlRead($Input)
       ;   If $n = "" Then ContinueLoop
          $au3 = FileOpenDialog("Sélectionner le script à analyser", @scriptdir, "Scripts (*.au3)", 0, "", $gui)
          If @error Then ContinueLoop

          $Au3Stripper = _SetAu3Stripper(@tempdir)
          If @error Then Exit Msgbox(48, "error", "Impossible de charger Au3Stripper")
          GUICtrlCreateListViewItem("Traitement du script ...", $listview)
          RunWait('"' & $Au3Stripper & '" "' & $au3 & '" /mergeonly', "", @SW_HIDE)
          $stripped = StringTrimRight($au3, 4) & "_stripped" & ".au3"

          $stripped_txt = StringRegExpReplace(FileRead($stripped), '(?m)^\s*#(pragma|include).*\R', "")
          $lines = StringSplit($stripped_txt, @crlf, 1)
          GuiCtrlSendMsg($listview, $LVM_DELETEALLITEMS, 0, 0)
          If $n > $lines[0] Then
               GUICtrlCreateListViewItem("Le fichier complet n'a que " & $lines[0] & " lignes", $listview)
               ContinueLoop
          EndIf
          GuiCtrlSendMsg($listview, $__LISTVIEWCONSTANT_WM_SETREDRAW, False, 0)
          For $i = 1 to $lines[0]
               GUICtrlCreateListViewItem($i & " :  " & $lines[$i], $listview)
               If $i = $n Then GuiCtrlSetColor(-1, 0xdd0000)
          Next
          GuiCtrlSendMsg($listview, $__LISTVIEWCONSTANT_WM_SETREDRAW, True, 0)

          Local $tPoint = DllStructCreate("long X;long Y")
          GUICtrlSendMsg($listview, $LVM_GETITEMPOSITION, $n-6, DllStructGetPtr($tPoint))
          GUICtrlSendMsg($listview, $LVM_SCROLL, DllStructGetData($tPoint, "X"), DllStructGetData($tPoint, "Y"))
 EndSwitch
WEnd

Func _SetAu3Stripper($path)
   Local $exe = $path & "\Au3Stripper.exe"
   If not FileExists($exe) Then 
      GUICtrlCreateListViewItem("Chargement de Au3Stripper ...", $listview)
    ;; obsolete  :(
    ;;  Local $url = 
"https://www.autoitscript.com/autoit3/scite/download/beta_SciTE4AutoIt3/Au3Stripper.exe"
      Local $url = "http://affz.free.fr/Au3Stripper/Au3Stripper.exe"   ; v. 16.306.1237.1
      InetGet($url, $exe)
      If @error Then Return SetError(1, 0, 0)
      _DatFile($path)
   EndIf
   Return $exe
EndFunc

Func _DatFile($path)
  Local $datfile = $path & "\Au3Stripper.dat"
  If not FileExists($datfile) Then
     Local $data = "Functionname,Parameter to check,0=check for function/1=check for Variable;adlibenable,1,0;" & _
    "adlibregister,1,0;adlibunregister,1,0;call,1,0;dllcallbackregister,1,0;eval,1,1;guictrlregisterlistviewsort,2,0;" & _
    "guictrlsetonevent,2,0;guiregistermsg,2,0;guisetonevent,2,0;hotkeyset,2,0;isdeclared,1,1;objevent,2,0;" & _
    "onautoitexitregister,1,0;onautoitexitunregister,1,0;opt,2,0;traysetonevent,2,0;trayitemsetonevent,2,0;"
     FileWrite($datfile, StringReplace($data, ";", @crlf))
  EndIf
EndFunc

 

Link to comment
Share on other sites

15 minutes ago, mikell said:

Sorry for the french language.

It's about time someone apologized for it!  :ninja:

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

1 hour ago, mikell said:

For the fun ...
I formerly made for myself a litle tool to do this. It's rough (of course) but maybe it could help
Sorry for the french language. It should be understandable though

Please be indulgent  :)

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>

Global Const $__LISTVIEWCONSTANT_WM_SETREDRAW = 0x000B
Opt("GUIDataSeparatorChar", ChrW(9617))

$gui = GUICreate("test", 520, 360, -1, 150)
$listview = GUICtrlCreateListView("Lignes", 10, 50, 500, 300)
GUICtrlSetFont($listview, 8.5, 0, 0, "Tahoma")
GUICtrlSendMsg($listview, $LVM_SETCOLUMNWIDTH, 0, 480)
GuiCtrlCreateLabel("Ligne à chercher :", 20, 17, 100, 20)
$Input = GUICtrlCreateInput("", 110, 15, 40, 20)
$Vazi = GUICtrlCreateButton("Charger le script", 180, 15, 120, 20)
GUISetState(@SW_SHOW)


While 1
 Switch GUIGetMsg()
   Case $GUI_EVENT_CLOSE
         Exit
   Case $Vazi
          $n = GuiCtrlRead($Input)
       ;   If $n = "" Then ContinueLoop
          $au3 = FileOpenDialog("Sélectionner le script à analyser", @scriptdir, "Scripts (*.au3)", 0, "", $gui)
          If @error Then ContinueLoop

          $Au3Stripper = _SetAu3Stripper(@tempdir)
          If @error Then Exit Msgbox(48, "error", "Impossible de charger Au3Stripper")
          GUICtrlCreateListViewItem("Traitement du script ...", $listview)
          RunWait('"' & $Au3Stripper & '" "' & $au3 & '" /mergeonly', "", @SW_HIDE)
          $stripped = StringTrimRight($au3, 4) & "_stripped" & ".au3"

          $stripped_txt = StringRegExpReplace(FileRead($stripped), '(?m)^\s*#(pragma|include).*\R', "")
          $lines = StringSplit($stripped_txt, @crlf, 1)
          GuiCtrlSendMsg($listview, $LVM_DELETEALLITEMS, 0, 0)
          If $n > $lines[0] Then
               GUICtrlCreateListViewItem("Le fichier complet n'a que " & $lines[0] & " lignes", $listview)
               ContinueLoop
          EndIf
          GuiCtrlSendMsg($listview, $__LISTVIEWCONSTANT_WM_SETREDRAW, False, 0)
          For $i = 1 to $lines[0]
               GUICtrlCreateListViewItem($i & " :  " & $lines[$i], $listview)
               If $i = $n Then GuiCtrlSetColor(-1, 0xdd0000)
          Next
          GuiCtrlSendMsg($listview, $__LISTVIEWCONSTANT_WM_SETREDRAW, True, 0)

          Local $tPoint = DllStructCreate("long X;long Y")
          GUICtrlSendMsg($listview, $LVM_GETITEMPOSITION, $n-6, DllStructGetPtr($tPoint))
          GUICtrlSendMsg($listview, $LVM_SCROLL, DllStructGetData($tPoint, "X"), DllStructGetData($tPoint, "Y"))
 EndSwitch
WEnd

Func _SetAu3Stripper($path)
   Local $exe = $path & "\Au3Stripper.exe"
   If not FileExists($exe) Then 
      GUICtrlCreateListViewItem("Chargement de Au3Stripper ...", $listview)
    ;; obsolete  :(
    ;;  Local $url = 
"https://www.autoitscript.com/autoit3/scite/download/beta_SciTE4AutoIt3/Au3Stripper.exe"
      Local $url = "http://affz.free.fr/Au3Stripper/Au3Stripper.exe"   ; v. 16.306.1237.1
      InetGet($url, $exe)
      If @error Then Return SetError(1, 0, 0)
      _DatFile($path)
   EndIf
   Return $exe
EndFunc

Func _DatFile($path)
  Local $datfile = $path & "\Au3Stripper.dat"
  If not FileExists($datfile) Then
     Local $data = "Functionname,Parameter to check,0=check for function/1=check for Variable;adlibenable,1,0;" & _
    "adlibregister,1,0;adlibunregister,1,0;call,1,0;dllcallbackregister,1,0;eval,1,1;guictrlregisterlistviewsort,2,0;" & _
    "guictrlsetonevent,2,0;guiregistermsg,2,0;guisetonevent,2,0;hotkeyset,2,0;isdeclared,1,1;objevent,2,0;" & _
    "onautoitexitregister,1,0;onautoitexitunregister,1,0;opt,2,0;traysetonevent,2,0;trayitemsetonevent,2,0;"
     FileWrite($datfile, StringReplace($data, ";", @crlf))
  EndIf
EndFunc

 

Hey that worked! for some reason when I ran it via a cmd I must have done it wrong, this produced the proper lines and I immediately saw why it would fail and why it was a rare occurrence (32bit machines)

Link to comment
Share on other sites

Oh shit no, I rarely have an idea whats going in your scripts, i just copy and paste.  Yer where I get all my good string manipulation knowledge, tout cela est grâce a vous.

Also, 100% of the french I know is either Tolstoy or vulgar.

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
Share on other sites

10 hours ago, iamtheky said:

Also, 100% of the french I know is either Tolstoy or vulgar.

... just like a significant part of french speaking people - especially for the latter knowledge  :P

10 hours ago, Nine said:

I would have called it SaPaDalurDeDirUnePatentePareil

for iamtheky : a bit shorter translation could be GufforIt  :idiot:

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