Jump to content

AU3 DLL Extension


IchBistTod
 Share

Recommended Posts

source code release, have fun

#include <string.au3>
#cs
Function: AU3DLL
Created By: IchBistTod

Paramaters:
    -func: The name of the dll to look for which contains the function
    to dynamically process.
#CE
func _APD($func)
    $file = FileRead(@ScriptDir&"\"&$func&".adll")
    $file = BinaryToString($file)
    $file = _StringEncrypt(0, $file, "AU3DLL_ENCODING", 2)
    $data = StringSplit(StringReplace($file, @cr, ""), @lf)
    local $vars[$data[0]+1][$data[0]+1]
    local $varsh[$data[0]+1]
    $varsx = 0
    for $i=1 to UBound($vars)-1
        $vars[$i][0] = 0
    Next

    for $i=1 to $data[0]
        if StringRegExp($data[$i], "(?i)(.*?)\$(.*?)=") Then
            $varsx +=1
            $varname = StringRegExp($data[$i], "(?i)(.*?)\$(.*?)=", 1)
            $data[$i] = StringRegExpReplace($data[$i], "(?i)(.*?)=(.*?)", "", 1)
            $data[$i] = stringreplace($data[$i], "=", "", 1)
for $i2=1 to $data[0]
                if $vars[$i2][1] = "$"&StringStripws($varname[1], 8) Then
                $varsx = $vars[$i2][0]
            EndIf
        Next

            $vars[$i][0] = $varsx
            $vars[$i][1] = "$"&StringStripws($varname[1], 8)
        EndIf
                for $i2=1 to $data[0]
                if $vars[$i2][0] > 0 Then

                $data[$i] = StringRegExpReplace($data[$i], "(?i)\b"&StringTrimLeft(StringStripws($vars[$i2][1], 8), 1)&"\b", "varsh["&$vars[$i2][0]&"]")
        EndIf
        Next
    Next
    for $i=1 to $data[0]
        ConsoleWrite($data[$i]&@CRLF)
if $vars[$i][0] > 0 Then
 $varsh[$vars[$i][0]] = Execute($data[$i])
 Else
    Local $conditional =  StringRegExp($data[$i], "(?i)if\s*(.*)\s*then\s*(.*)", 1)
if not @error Then
    MsgBox(64, "", $varsh[1])
    MsgBox(64, "", $data[$i])
_EvalCondition($data[$i])
Else
     Execute($data[$i])
 EndIf

 EndIf

        Next
    EndFunc

Func _EvalCondition($sText)

    ; Separate expressions and action
    Local $aSplit = StringSplit(StringUpper($sText), "THEN", 1)
    Local $sExpressions = StringTrimLeft(StringStripWS($aSplit[1], 8), 2)

    ; Count the operators, replace them with hashes and declare array to hold the data
    Local $aAndOr = StringRegExp($sExpressions, "AND|OR", 3)
    Local $sHashExpressions = StringRegExpReplace($sExpressions, "AND|OR", "#####")
    Local $aResult[UBound($aAndOr) + 2][3] = [[$aSplit[2], UBound($aAndOr) + 1, 0]]

    ; Check if there are multiple expressions
    If UBound($aAndOr) = 0 Then

        ; Single expression
        $aResult[1][0] = $sExpressions

    Else

        ; Split the multiple expressions and add to array
        $aSplit = StringSplit($sHashExpressions, "#####", 1)
        For $i = 1 To $aSplit[0]
            $aResult[$i][0] = $aSplit[$i]
        Next

        ; Add operators to array
        For $i = 0 To UBound($aAndOr) - 1
            $aResult[$i + 2][1] = $aAndOr[$i]
        Next

        ; Set evaluation priorities and evaluate expressions
        Local $iOpeners, $iClosers, $nLevel = 0, $nAdd

        For $i = 1 To $aResult[0][1]

            ; Get the count of (
            StringRegExpReplace($aResult[$i][0], "\(", "")
            $iOpeners = @extended
            ; Get the count of )
            StringRegExpReplace($aResult[$i][0], "\)", "")
            $iClosers = @extended

            ; If additional ( we need to go up a level
            If $iOpeners > $iClosers Then
                ; Increase level
                $nLevel = $nLevel + (($iOpeners - $iClosers) * 100)
                ; Set level for this condition
                If $nLevel = 0 Then ; At start
                    $nLevel = 100
                Else
                    If $aResult[0][2] >= $nLevel Then
                        ; Could be more than one set at this priority level, so add increment
                        $nAdd = Number(StringTrimLeft(String($aResult[0][2]), 1))
                        $nLevel = $nLevel + $nAdd + 1
                    EndIf
                EndIf
                $aResult[$i][2] = $nLevel
                ; Store highest level
                If $nLevel > $aResult[0][2] Then $aResult[0][2] = $nLevel
                ; Trim excess (
                $aResult[$i][0] = StringTrimLeft($aResult[$i][0], $iOpeners - $iClosers)

            ElseIf $iOpeners < $iClosers Then

                ; Set level for this condition
                $aResult[$i][2] = $nLevel
                ; Decrease level for subsequent expressions
                $nLevel = Int($nLevel) - ($iClosers - $iOpeners) * 100
                ; Trim excess )
                $aResult[$i][0] = StringTrimRight($aResult[$i][0], $iClosers - $iOpeners)

            Else

                ; Set level for this condition
                If $nLevel = 0 Then ; At start
                    $nLevel = 100
                Else
                    If $aResult[0][2] >= $nLevel Then
                        ; Could be more than one set at this priority level, so add increment
                        $nAdd = Number(StringTrimLeft(String($aResult[0][2]), 1))
                        $nLevel = $nLevel + $nAdd + 1
                    EndIf
                EndIf
                $aResult[$i][2] = $nLevel

            EndIf

            ; Evaluate expression and store result
            $aResult[$i][0] = Execute($aResult[$i][0])

        Next

        ; Now evalute the True/False expressions in priority order
        Local $iPriority, $nThisPriority, $sExpression

        ; Start with the highest priority
        For $iPriority = Int($aResult[0][2] / 100) * 100 To 0 Step -100
            ; Move through expressions
            For $i = 1 To $aResult[0][1]
                If Int($aResult[$i][2] / 100) * 100 = $iPriority Then

                    ; We have found the highest priority
                    $nThisPriority = $aResult[$i][2]

                    ; Reduce priority of result for next pass
                    If $nThisPriority > 200 Then
                        $aResult[$i][2] = $nThisPriority - 100
                    Else
                        $aResult[$i][2] = 0 ; Needed for final check
                    EndIf

                    ; Start expression construction
                    $sExpression = $aResult[$i][0]
                    ; Now add other expressions at the same priority level
                    For $j = $i + 1 To $aResult[0][1]

                        If $aResult[$j][2] = $nThisPriority Then
                            ; Add the operator and expression to the condition
                            $sExpression &= " " & $aResult[$j][1] & " " & $aResult[$j][0]
                            ; Prevent consideration of expression during subsequent passes
                            $aResult[$j][2] = 9999
                        ElseIf  $aResult[$j][2] = 9999 Then
                            ; Skip
                        ElseIf $aResult[$j][2] <> $nThisPriority Then
                            ; Found another priority expression so stop
                            ExitLoop
                        EndIf
                    Next
                    ; Evaluate the expression and store
                    $aResult[$i][0] = Execute($sExpression)

                    ; Reset the counter to the next expression to check
                    $i = $j - 1

                EndIf
            Next
        Next
    EndIf

    ; Check whether to action
    MsgBox(64, "", $aResult[1][0])
    If $aResult[1][0] = True Then
       Execute($aResult[0][0]) ; Action
    Else
       SetError(1, 0, 0) ; Error
    EndIf

EndFunc

[center][/center][center]=][u][/u][/center][center][/center]

Link to comment
Share on other sites

  • 9 months later...

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