Jump to content

Execute Script


met94
 Share

Recommended Posts

I have encoded autoit code.

My program has to decode this and execute.

Any ideas how to do it?

Encode

$file = FileOpen("kupa.txt", 0) ;in kupa.txt is autoit code of other program
$chars = FileRead($file)

$encoded = _Base64Encode($chars)
FileWrite("data.dat", $encoded)

Func _Base64Encode($input)

    $input = Binary($input)

    Local $struct = DllStructCreate("byte[" & BinaryLen($input) & "]")

    DllStructSetData($struct, 1, $input)

    Local $strc = DllStructCreate("int")

    Local $a_Call = DllCall("Crypt32.dll", "int", "CryptBinaryToString", _
            "ptr", DllStructGetPtr($struct), _
            "int", DllStructGetSize($struct), _
            "int", 1, _
            "ptr", 0, _
            "ptr", DllStructGetPtr($strc))

    If @error Or Not $a_Call[0] Then
        Return SetError(1, 0, "") ; error calculating the length of the buffer needed
    EndIf

    Local $a = DllStructCreate("char[" & DllStructGetData($strc, 1) & "]")

    $a_Call = DllCall("Crypt32.dll", "int", "CryptBinaryToString", _
            "ptr", DllStructGetPtr($struct), _
            "int", DllStructGetSize($struct), _
            "int", 1, _
            "ptr", DllStructGetPtr($a), _
            "ptr", DllStructGetPtr($strc))

    If @error Or Not $a_Call[0] Then
        Return SetError(2, 0, ""); error encoding
    EndIf

    Return DllStructGetData($a, 1)

EndFunc   ;==>_Base64Encode

Decode

#include <Security.au3>
#include <Process.au3>
$file = FileOpen("data.dat", 0)
$chars = FileRead($file)

$decoded = _Base64Decode($chars)

$odkodowany = BinaryToString($decoded)

Func _Base64Decode($input_string)

    Local $struct = DllStructCreate("int")

    $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", _
            "str", $input_string, _
            "int", 0, _
            "int", 1, _
            "ptr", 0, _
            "ptr", DllStructGetPtr($struct, 1), _
            "ptr", 0, _
            "ptr", 0)

    If @error Or Not $a_Call[0] Then
        Return SetError(1, 0, "") ; error calculating the length of the buffer needed
    EndIf

    Local $a = DllStructCreate("byte[" & DllStructGetData($struct, 1) & "]")

    $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", _
            "str", $input_string, _
            "int", 0, _
            "int", 1, _
            "ptr", DllStructGetPtr($a), _
            "ptr", DllStructGetPtr($struct, 1), _
            "ptr", 0, _
            "ptr", 0)

    If @error Or Not $a_Call[0] Then
        Return SetError(2, 0, ""); error decoding
    EndIf

    Return DllStructGetData($a, 1)

EndFunc   ;==>_Base64Decode

There is decoding, but I don't know how to execute decoded autoit code from data.dat.

Help.

Link to comment
Share on other sites

Try this may be it helps:

after decode your *.dat it will be contain decode data(autoitscript in this case)

and after this just assimilate for .dat

assoc .dat=fakefile
ftype fakefile="%programfiles%\AutoIt3\AutoIt3.exe" "%1"

with run() command.

I think this would help to you.

And after execution of your .dat file do not forget deassoc .dat to original...

EDIT: autoit cli parameter

Edited by Sh3llC043r
[size="5"] [/size]
Link to comment
Share on other sites

Thanks for help, but I can't do it because program has to work on computer without autoit.

I tried to use AutoIt3ExecuteLine but it shows me error on line 1 "Unable to parse line."

#include <Security.au3>
#include <Process.au3>
$file = FileOpen("data.dat", 0)
$chars = FileRead($file)

$decoded = _Base64Decode($chars)

$odkodowany = BinaryToString($decoded)

$cmd = $odkodowany
Run(@AutoItExe & ' /AutoIt3ExecuteLine "' & $Cmd & '"')

Func _Base64Decode($input_string)

    Local $struct = DllStructCreate("int")

    $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", _
            "str", $input_string, _
            "int", 0, _
            "int", 1, _
            "ptr", 0, _
            "ptr", DllStructGetPtr($struct, 1), _
            "ptr", 0, _
            "ptr", 0)

    If @error Or Not $a_Call[0] Then
        Return SetError(1, 0, "") ; error calculating the length of the buffer needed
    EndIf

    Local $a = DllStructCreate("byte[" & DllStructGetData($struct, 1) & "]")

    $a_Call = DllCall("Crypt32.dll", "int", "CryptStringToBinary", _
            "str", $input_string, _
            "int", 0, _
            "int", 1, _
            "ptr", DllStructGetPtr($a), _
            "ptr", DllStructGetPtr($struct, 1), _
            "ptr", 0, _
            "ptr", 0)

    If @error Or Not $a_Call[0] Then
        Return SetError(2, 0, ""); error decoding
    EndIf

    Return DllStructGetData($a, 1)

EndFunc   ;==>_Base64Decode

Decoded data.dat

$oMyError = ObjEvent(""AutoIt.Error"",""MyErrFunc"")
Func MyErrFunc()
    $HexNumber = Hex($oMyError.number, 8)
    FileWrite(""Error.txt"", ""COM Error Details:"" & @CRLF & @CRLF & _
            ""err.description is: "" & @TAB & $oMyError.description & @CRLF & _
            ""err.windescription:"" & @TAB & $oMyError.windescription & @CRLF & _
            ""err.number is: "" & @TAB & $HexNumber & @CRLF & _
            ""err.lastdllerror is: "" & @TAB & $oMyError.lastdllerror & @CRLF & _
            ""err.scriptline is: "" & @TAB & $oMyError.scriptline & @CRLF & _
            ""err.source is: "" & @TAB & $oMyError.source & @CRLF & _
            ""err.helpfile is: "" & @TAB & $oMyError.helpfile & @CRLF & _
            ""err.helpcontext is: "" & @TAB & $oMyError.helpcontext _
            )
    SetError(1)
    Sleep(100)
EndFunc

Autoit msgbox with error:

Posted Image

Any ideas how to fix it?

Link to comment
Share on other sites

  • Developers

should work with /AutoIt3ExecuteScript:

Run(@AutoItExe & ' /AutoIt3ExecuteScript "data.dat"')
Edited by 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

  • Developers

Posted Image

Nice screen capture but I am missing any question in your post.

You will have to decode whatever is in the file into readable script lines and save that into a file... then run the file with the command I have given.

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

  • Developers

So i think to do somethink like what you say you need write your interpreter for autoit.

This is really so hard.

Why are you making things so complex here?

Each compiled script can act as a stub for a new script.

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

  • Developers

But how?Sorry i cant seem it yet and i have`nt any ideas somethink like.

Any helps will be appreciated in this case.

By using:

should work with /AutoIt3ExecuteScript:

Run(@AutoItExe & ' /AutoIt3ExecuteScript "scriptfile.au3"')

@AutoItExe will be your compiled script name when you use this line in your own compiled script.

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

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