Jump to content
Sign in to follow this  
tonyatcodeleakers

[help] Adding unknown function search

Recommended Posts

tonyatcodeleakers

im working on a syntax check for the gsc language, not anything too ridiculous it currently checks for open parentheses, quotations, and brackets.

But im looking to be able to check for unknown functions and im at a loss on how to go about doing it.

for those of you who do not know the language i want to be able to search for a string that has "thread" or "::" (minus quotations of course) in it, and then i want to be able to get the text that follows the "thread" or "::" that stops at a semicolon or comma

example

::tony;

thread tony();

i then would take this text and do this

$bob = StringInStr ( $edittext, "tony" & @crlf & "{")

$bob2 = StringInStr ( $edittext, "tony()" & @crlf & "{")

if $bob = 0 and $bob2 = 0 then; tell user the error

Edited by tonyatcodeleakers

Share this post


Link to post
Share on other sites
SmOke_N

#include <Array.au3>; for array display only
Global $gs_String = "string value here"
Global $ga_Funcs = StringRegExp($gs_String, "(?ims)(?:\:\:|thread\s+)(\w+)", 3)
_ArrayDisplay($ga_Funcs)

Note:

Won't do much if someone is using a function name or example within a string.

It will return a false positive then.

eg:

(Guessing on syntax based on the the one example of gsc I looked at)

Variable = "::myFunction; is an example of a function n So is thread myFunction()"

On the above, the variable "Variable" contains the syntax for functions you're basing your rules on within a string, so you'd return myFunction ( twice ) because you didn't strip strings first.

Lots of rules for building an obfuscation or rule based function/variable/string finding udfs.

Edited by SmOke_N

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.

Share this post


Link to post
Share on other sites
tonyatcodeleakers

Thank you, I will test once i get home tonight.

And rarley does something like Variable = "::myFunction; is an example of a function n So is thread myFunction()" show up so thats not an issue

Share this post


Link to post
Share on other sites
tonyatcodeleakers

I dont mean to double post, or ask to be spoon fed but im at a lose.

this is how i set it up, only issue is it doesnt work -_-. It either never detects the error or detects everything as an error. What am i doing wrong. thanks again

$ga_Funcs1 = StringRegExp(_GUICtrlRichEdit_GetText( $edit ), "(?ims)(?:\:\:|thread\s+)(\w+)", 3)
$ga_Funcs2 = _ArrayToString($ga_Funcs1, "|")
$ga_Funcs = StringSplit ( $ga_Funcs2, "|" )
For $i = 1 To UBound( $ga_Funcs ) - 1
$bob = StringInStr (_GUICtrlRichEdit_GetText( $edit ), $ga_Funcs[$i] & "()" & @crlf & "{")
$bob1 = StringInStr ( _GUICtrlRichEdit_GetText( $edit ), $ga_Funcs[$i] & "( )" & @crlf & "{")
if $bob = 0 and $bob1 then
$errort = 1
$errortxt &= "WARNING: Unknown Function(s) :( " & @CRLF & @CRLF
EndIf
Next

Share this post


Link to post
Share on other sites
SmOke_N

Posting a txt file with an example of the input string would be nice.

This is pseudo code, not tested at all or even syntax checked.

But is a direction I would take:

#include <Array.au3>

; pass the edit areas text to function
; should return unknown function(s) array

Global $gh_EditControl = 0 ; put something here

Global $gs_EditText = _GUICtrlRichEdit_GetText($gh_EditControl)
Global $ga_UnknownFuncs = _gsc_getUnknownFuncs($gs_EditText)
If @error Then
    MsgBox(16 + 262144, "Error", "Track down SetError(" & @error & ", 0, 0)")
Else
    _ArrayDisplay($ga_UnknownFuncs, "Unknown Funcs")
EndIf


Func _gsc_getUnknownFuncs($s_intext)
    
    If StringLen(StringStripWS($s_intext, 8)) = 0 Then
        ; invalid string
        Return SetError(1, 0, 0)
    EndIf
    
    Local $a_srefuncs = StringRegExp($s_intext, "(?ims)(?:\:\:|thread\s+)(\w+)", 3)
    If @error Then
        ; no functions found
        Return SetError(2, 0, 0)
    EndIf
    
    ; get a unique array
    Local $a_funcs = _ArrayUnique($a_srefuncs)
    
    Local $s_unknown = "", $s_pattern
    Local $s_patternend = "\E\s*\((?:[\w\s,]*)\)\v*\{"
    For $ifunc = 0 To UBound($a_funcs) - 1
        ; find functions with parenthesis and curly bracket ext after (possible) vertical space line
        ; allow for possible parameters (eg. [\w\s,])
        $s_pattern = "(?is)\W\Q" & $a_funcs[$ifunc] & $s_patternend
        If Not StringRegExp($s_intext, $s_pattern) Then
            $s_unknown &= $a_funcs[$ifunc] & @LF
        EndIf
    Next
    
    $s_unknown = StringTrimRight($s_unknown, 1)
    If Not $s_unknown Then
        ; no unknown functions found
        Return SetError(3, 0, 0)
    EndIf
    
    ; return 1 dimension array of unknown funcs
    Return StringSplit($s_unknown, @LF)
EndFunc
  • Like 1

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.

Share this post


Link to post
Share on other sites
tonyatcodeleakers

Hmm, It still shows up even if it isnt a unknown function :(

Im going to mess around and if i dont get any luck ill report back. Wish me luck

EDit:

heres an example script i made if it helps

<snip>

Edited by Melba23
Code removed

Share this post


Link to post
Share on other sites
Melba23

tonyatcodeleakers,

That looks like a game-bot. Please read the Forum rules (the link is also at bottom right of each page) - particularly the bit about not discussing game automation - before you post again. Thread locked.

Subsequent conversations have indicated that the removed code, although game-related, is not a game-bot nor game code. And as the use of AutoIt on this code by the OP is not at all game-related, I am reopening the thread. :)

M23

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
tonyatcodeleakers

Okay, here is a revised example to fit the governments rules :shifty:

here are two examples of code that are correct, and two that are not and should show an unknown function error

WORKING

#include Example
Main()
{
self thread tony();
}

tony()
{
}

#include Example
Main()
{
self ::tony; //also can be followed by a comma instead of a semi colon with more variables that do not effect the function but they dont matter.
}

tony()
{
}

NON Working

#include Example
Main()
{
self thread tony();
}

#include Example
Main()
{
self ::tony;
}
Edited by tonyatcodeleakers

Share this post


Link to post
Share on other sites
mikell

With this text

include Example
Main()
{
self thread tony();
}

tony()
{
}

{
self thread bill();
}

{
self ::john;
}

{
self ::bob;
}

bob()
{
}

Try this

#include <Array.au3>

Global $gs_String = FileRead("1.txt")
Global $ga_Funcs = StringRegExp($gs_String, "(?is)(?:::|thread\s+)(\w+)", 3)
_ArrayDisplay($ga_Funcs, "all")

For $i = UBound($ga_Funcs)-1 to 0 step -1
If StringRegExp($gs_String, '(?is)\v' & $ga_Funcs[$i] & '\(\)\s') Then _ArrayDelete($ga_Funcs, $i)
Next
_ArrayDisplay($ga_Funcs, "wrong")
Edited by mikell

Share this post


Link to post
Share on other sites
tonyatcodeleakers

With this text

include Example
Main()
{
self thread tony();
}

tony()
{
}

{
self thread bill();
}

{
self ::john;
}

{
self ::bob;
}

bob()
{
}

Try this

#include <Array.au3>

Global $gs_String = FileRead("1.txt")
Global $ga_Funcs = StringRegExp($gs_String, "(?is)(?:::|thread\s+)(\w+)", 3)
_ArrayDisplay($ga_Funcs, "all")

For $i = UBound($ga_Funcs)-1 to 0 step -1
If StringRegExp($gs_String, '(?is)\v' & $ga_Funcs[$i] & '\(\)\s') Then _ArrayDelete($ga_Funcs, $i)
Next
_ArrayDisplay($ga_Funcs, "wrong")

Thank you, this works, other than the fact if the function has parameters such as

tony(height, length, width)
{
}

it doesnt detect it and shows an error.

Hmm so now the question is how do i get it to also check for functions that may have parameters? and sometimes there are as many as 10 parameters so that could become an issue :(

Share this post


Link to post
Share on other sites
mikell

No no, just change this line for this new one

If StringRegExp($gs_String, '(?is)\v' & $ga_Funcs[$i] & '\(.*?\)\s') Then _ArrayDelete($ga_Funcs, $i)

Edited by mikell

Share this post


Link to post
Share on other sites
tonyatcodeleakers

No no, just change this line for this new one

If StringRegExp($gs_String, '(?is)\v' & $ga_Funcs[$i] & '\(.*?\)\s') Then _ArrayDelete($ga_Funcs, $i)

Now it shows all functions as errors again -__-

Share this post


Link to post
Share on other sites
mikell

Argh :)

I could not copy your complete text before M23 fired it, but now with his agreement you can post it again ?

Share this post


Link to post
Share on other sites
PhoenixXL

Check this - I've performed the tests with the text provided by mikell

#include <Array.au3>
#include <Misc.au3>

Global $S_Text = FileRead("file.txt")
_Functions_InArray_SRE($S_Text)

;Pattern to be used

;== Declared Functions ==
;self (thread )?(::)?tony(?(1)\((\w*?)\)|)[;,]


Func _Functions_InArray_SRE($String)

;The following is the array of arrays.
$aaDeclared_Func = StringRegExp($String, "self (thread (?:(\w*?)\([^()]*\))|(?:::(\w*?)))[;,]", 4)
;Lets make the array of arrays a simple 1D array with the required capturing group i.e. 2 & 3 which captures the function name
$Temp = $aaDeclared_Func
GetArrayFromArrays($Temp, 2)
GetArrayFromArrays($aaDeclared_Func, 3)
_ArrayConcatenate($aaDeclared_Func, $Temp)
DeleteBlank($aaDeclared_Func)

;The following is the array of arrays.
$aaImplemented_Func = StringRegExp($String, "[\v^](\w*?)\([^()]*\)", 4)
;Lets make the array of arrays a simple 1D array with the required capturing group i.e. 1 which captures the function name
GetArrayFromArrays($aaImplemented_Func, 1)

;Lets see the results obtained till now
_ArrayDisplay($aaDeclared_Func, "Declared Functions")
_ArrayDisplay($aaImplemented_Func, "Implemented Functions")

EndFunc ;==>_Functions_InArray_SRE

Func GetArrayFromArrays(ByRef $Array, $iIndex)

Local $iUbound = UBound($Array), $l
Local $aIndexed_Array[$iUbound], $aErr[$iUbound]

For $i = 0 To $iUbound - 1
$l = $Array[$i]
;The returned array that show the error occured
$aErr[$i] = _Iif(IsArray($l) = 0, 1, 0)
$aErr[$i] = _Iif($iIndex >= UBound($l), BitOR($aErr[$i], 2), $aErr[$i])
If $aErr[$i] Then ContinueLoop ;halt the loop in case of error

If $l[$iIndex] Then $aIndexed_Array[$i] = $l[$iIndex]
Next

$Array = $aIndexed_Array

Return $aErr
EndFunc ;==>GetArrayFromArrays

Func DeleteBlank(ByRef $Array)
For $i = UBound($Array) -1 To 0 Step -1
If $Array[$i] Then ContinueLoop
_ArrayDelete($Array, $i)
Next
EndFunc
Regards :) Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
tonyatcodeleakers

ill test but the texts mike provided are not corectly formatted so it may be wrong.

and @mike, ill pm both you and phonix the original example.

Share this post


Link to post
Share on other sites
mikell

OK, I copied your text into a txt file , the script below returns for me 12 funcs and no errors

#include

Global $gs_String = FileRead("1.txt")
Global $ga_Funcs = StringRegExp($gs_String, "(?is)(?:::|thread\s+)(\w+)", 3)
_ArrayDisplay($ga_Funcs, "all")

For $i = UBound($ga_Funcs)-1 to 0 step -1
If StringRegExp($gs_String, '(?is)\v\s*' & $ga_Funcs[$i] & '\([^\)]*\)\s') Then _ArrayDelete($ga_Funcs, $i)
Next
_ArrayDisplay($ga_Funcs, "wrong")
If @error = 1 Then Msgbox(0,'', "no errors")

Edited by mikell

Share this post


Link to post
Share on other sites
PhoenixXL

thread onPlayerConnect();

Is this function even valid ? if yes, delete the "self " in the first SRE pattern

I modified the script to show Unknown functions as well

#include <Array.au3>
#include <Misc.au3>

Global $S_Text = FileRead("file.txt")
_Functions_InArray_SRE($S_Text)


Func _Functions_InArray_SRE($String)

;The following is the array of arrays.
$aaDeclared_Func = StringRegExp($String, "(thread (?:(\w*?)\([^()]*\))|(?:::(\w*?)))[;,]", 4)
;Lets make the array of arrays a simple 1D array with the required capturing group i.e. 2 & 3 which captures the function name
$Temp = $aaDeclared_Func
GetArrayFromArrays($Temp, 2)
GetArrayFromArrays($aaDeclared_Func, 3)
_ArrayConcatenate($aaDeclared_Func, $Temp)
DeleteBlank($aaDeclared_Func)

;The following is the array of arrays.
$aaImplemented_Func = StringRegExp($String, "[\v^](\w*?)\([^()]*\)", 4)
;Lets make the array of arrays a simple 1D array with the required capturing group i.e. 1 which captures the function name
GetArrayFromArrays($aaImplemented_Func, 1)

$aUnknow_Func = ArrayInverse($aaImplemented_Func, $aaDeclared_Func)

;Lets see the results obtained till now
_ArrayDisplay($aaDeclared_Func, "Declared Functions")
_ArrayDisplay($aaImplemented_Func, "Implemented Functions")
_ArrayDisplay($aUnknow_Func, "Unknown Functions")
EndFunc ;==>_Functions_InArray_SRE

Func GetArrayFromArrays(ByRef $Array, $iIndex)

Local $iUbound = UBound($Array), $l
Local $aIndexed_Array[$iUbound], $aErr[$iUbound]

For $i = 0 To $iUbound - 1
$l = $Array[$i]
;The returned array that show the error occured
$aErr[$i] = _Iif(IsArray($l) = 0, 1, 0)
$aErr[$i] = _Iif($iIndex >= UBound($l), BitOR($aErr[$i], 2), $aErr[$i])
If $aErr[$i] Then ContinueLoop ;halt the loop in case of error

If $l[$iIndex] Then $aIndexed_Array[$i] = $l[$iIndex]
Next

$Array = $aIndexed_Array

Return $aErr
EndFunc ;==>GetArrayFromArrays

Func DeleteBlank(ByRef $Array)
For $i = UBound($Array) - 1 To 0 Step -1
If $Array[$i] Then ContinueLoop
_ArrayDelete($Array, $i)
Next
EndFunc ;==>DeleteBlank

Func ArrayInverse($aBase, $aSubtract)
;Return the array of the values that are present in $aSubtract but not in $aBase
Local $aReturn_Array[1]
Local $iUbound_1 = UBound($aBase) - 1
Local $iUbound_2 = UBound($aSubtract) - 1
For $i = 0 To $iUbound_1
For $j = 0 To $iUbound_2
If $aBase[$i] = $aSubtract[$j] Then
ContinueLoop 2
ElseIf $j = $iUbound_2 Then
_ArrayAdd($aReturn_Array, $aBase[$i])
EndIf
Next
Next
_ArrayDelete($aReturn_Array, 0)
Return $aReturn_Array
EndFunc ;==>ArrayInverse
Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Share this post


Link to post
Share on other sites
mikell

PhoenixXL

As it was defined by tonyatcodeleakers this func is returned valid by my script ^^

Share this post


Link to post
Share on other sites
tonyatcodeleakers

thread onPlayerConnect();

Is this function even valid ?

could you elaborate?

AND YESS, thank you mikell, ill include credit to you, phonex, and smoke. Im going to test it on some other mods and report back if it works.

Share this post


Link to post
Share on other sites
tonyatcodeleakers

Okay it works, now i need to leave exclusions, like as an example certain functions are called internally and are not going to be listed. (eg if you use include<>)

So would it be ideal to also include all the files that may be included and have it check for the files included and search them also?

other than that THANK YOU ALL

EDIT: I figured it all out, i added a function list of internal functions and ill be adding more as i find them.

Thank you to all that helped, and ill make sure to add you to the credits list in my help file :)

Edited by tonyatcodeleakers

Share this post


Link to post
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
Sign in to follow this  

×