Jump to content

I just managed to create a algorithm that do some encryption but there are several problems..


Recommended Posts

Posted (edited)

hello,

today I tried create an algorithm that makes encryption to the script like CodeCrypter..

the the reason why I do not use CodeCrypter is because it is hard to understand how to make a >simple process -

So after 4 days I realize that the hard way is probably the shortest ..
So I wrote an algorithm that does only this kind of encryption...

 

this is the code:

#include <Array.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>


;#include "AES.au3"
;#include <String.au3>
;#include <Crypt.au3>

#AutoIt3Wrapper_Run_AU3Check=n

Global $aEmpty[1]
$aEmpty[0] = 0





$ScriptFile = FileOpenDialog("Select a au3 script","","Autoit Script (*.au3)")

$Final = EncScript($ScriptFile)
ShowOutput($Final)

Func EncScript($ScriptFile , $EncExecute = '"Execute(""BinaryToString("&Execute("StringToBinary($String)")&")"")"' )
    Local $mScript , $aScript , $NewLine , $IsCond , $LeftString , $RightString , $var
    Local $Output = "" , $aTmp1 = $aEmpty , $String

    $mScript = FileRead($ScriptFile)
    $aScript = StringSplit($mScript,@CRLF,1)

    For $a = 1 To $aScript[0]
        If LineIsActive($aScript[$a]) Then
            $NewLine = RemoveTabsSpases($aScript[$a])
            _ArrayAdd($aTmp1,$NewLine)
            $aTmp1[0] = $aTmp1[0]+1
        EndIf
    Next


    ;_ArrayDisplay($aTmp1)
    $IsCond = 1
    $LeftString = ""
    $RightString = ""
    For $a = 1 To $aTmp1[0]
        ;If StringLeft($aTmp1[$a],6) <> "While " And StringLeft($aTmp1[$a],3) <> "Do " And StringLeft($aTmp1[$a],4) <> "For " And

        If StringLeft($aTmp1[$a],3) = "If " Or StringLeft($aTmp1[$a],7) = "ElseIf " Then

            If StringRight($aTmp1[$a],5) = " Then" Then
                $RightString = " Then"
            Else
                $var = StringSplit($aTmp1[$a],"Then",1)
                If $var[0] = 2 Then
                    $RightString = "Then "&$var[2]
                Else
                    If $IsCond <> 0 Then $IsCond = 0
                EndIf

            EndIf

            If StringLeft($aTmp1[$a],3) = "If " Then
                $LeftString = "If "
            Else
                $LeftString = "ElseIf "
            EndIf

        ElseIf StringLeft($aTmp1[$a],5) = "Else " Then
            $LeftString = "Else "

        ElseIf StringLeft($aTmp1[$a],1) = "$" Then
            ; just for prevent the else case ...
            $var = StringSplit($aTmp1[$a],"=",1)
            If $var[0] = 2 Then
                $LeftString = $var[1]
                $RightString = $var[2]

                If DetectFuncString($LeftString) Then
                    $String = $LeftString
                    $LeftString = Execute($EncExecute)
                EndIf

                If DetectFuncString($RightString) Then
                    $String = $LeftString
                    $RightString = Execute($EncExecute)
                EndIf

                $IsCond = 0
                $aTmp1[$a] = $LeftString&" = "&$RightString

            EndIf

        ElseIf StringLeft($aTmp1[$a],5) = "Local" Or StringLeft($aTmp1[$a],6) = "Global" Or StringLeft($aTmp1[$a],3) = "Dim" Then
            If $IsCond <> 0 Then $IsCond = 0

        Else
            If $IsCond <> 0 Then $IsCond = 0
            ;$String = $aTmp1[$a]
        EndIf

        If $IsCond = 1 Then
            $aTmp1[$a] = $LeftString&Execute($EncExecute)&$RightString
        Else

        EndIf


        $IsCond = 1
        $LeftString = ""
        $RightString = ""
    Next


    For $a = 1 To $aTmp1[0]
        $Output = $Output&$aTmp1[$a]
        If $a < $aTmp1[0] Then $Output = $Output&@CRLF
    Next

    Return $Output
EndFunc




Func LineIsActive($Line)
    Local $Output = False
    If Not StringIsSpace($Line) And $Line <> "" Then
        Local $var = StringSplit($Line,"",1)
        For $a = 1 To $var[0]
            If Not StringIsSpace($var[$a]) Then
                If $var[$a] <> ";" Then
                    $Output = True
                EndIf
                ExitLoop
            EndIf
        Next
    EndIf
    Return $Output
EndFunc




Func RemoveTabsSpases($Line)
    Local $Output = $Line
    While 1
        If StringLeft($Output,1) = " " Or StringLeft($Output,1) = " " Then
            $Output = StringTrimLeft($Output,1)
        ElseIf StringRight($Output,1) = " " Or StringRight($Output,1) = "   " Then
            $Output = StringTrimRight($Output,1)
        Else
            ExitLoop
        EndIf
    WEnd
    Return $Output
EndFunc

Func StringBetween($MainString,$LeftString,$RightString)
    Local $Output = $MainString
    If $LeftString <> "" Then $Output = StringTrimLeft($Output,StringLen($LeftString))
    If $RightString <> "" Then $Output = StringTrimRight($Output,StringLen($RightString))
    Return $Output
EndFunc


Func DetectFuncString($String)
    Local $Output = False , $var1 , $tmp
    If StringInStr($String,")") > 0 And StringInStr($String,"(") > 0 Then
        $var1 = StringSplit($String,"",1)
        $tmp = _ArraySearch($var1,"(",1)
        If $tmp > 0 And $var1[$var1[0]] = ")" Then $Output = True
    EndIf
    Return $Output
EndFunc




Func ShowOutput($EditData)
    Local $Form2 , $GuiEdit , $nMsg , $Label1 , $Close_Button ,  $Save_Button , $Save
    #Region ### START Koda GUI section ### Form=
    $Form2 = GUICreate("", 513, 564, 331, 104)
    $GuiEdit = GUICtrlCreateEdit("", 24, 48, 465, 449, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_READONLY,$ES_WANTRETURN,$WS_VSCROLL))
    GUICtrlSetData(-1, $EditData)
    $Label1 = GUICtrlCreateLabel("Result:", 24, 16, 54, 24)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    $Close_Button = GUICtrlCreateButton("Close", 120, 512, 121, 41)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    $Save_Button = GUICtrlCreateButton("Save script", 269, 512, 121, 41)
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE , $Close_Button
                 GUIDelete1($Form2)
                ExitLoop
            Case $Save_Button
                $Save = FileSaveDialog("Save Script","","Autoit Script (*.au3)",16)
                If Not @error Then
                    FileWrite($Save,$EditData)
                    MsgBox(64,"","Script saved!")
                EndIf
        EndSwitch
    WEnd
EndFunc


Func GUIDelete1($GuiName)
    Local $handle
    $handle = WinGetHandle($GuiName)
    GUIDelete($handle)
EndFunc   ;==>GUIDelete1

image:

post-66583-0-21241100-1388004263_thumb.j

 

the problem is that few lines are not working after this process and it causes the script to crash ..

can you tell me what is wrong?

I know the code looks terrible .. But it works pretty well ..
just, in some cases, it not working right ..

thanks for helpers!

Edited by Guest
Posted (edited)

i get a loot of this error:

 

D:???????DATADesktoptest5test_my_enc.au3 (191) : ==> Subscript used with non-Array variable.:
For $a = 1 To $SettingsSections[0]
For $a = 1 To $SettingsSections^ ERROR

 

Excuse, I forgot to mention what are the problems ..

In fact, this is the only error I get ..
I do not understand why this is happening.

By the way,
I changed the following lines -

I replaced line:

$aTmp1[$a] = $LeftString&" = "&$RightString

with:

$aTmp1[$a] = $LeftString&" = "&$RightString&"   ;   "&$aTmp1[$a]

and line:

$aTmp1[$a] = $LeftString&Execute($EncExecute)&$RightString

with:

$aTmp1[$a] = $LeftString&Execute($EncExecute)&$RightString&"    ;   "&$aTmp1[$a]

This way, the original lines will be written as notes

Edited by Guest

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
×
×
  • Create New...