Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

fdeps - list external function references in scripts


  • Please log in to reply
7 replies to this topic
corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004
Here's a relatively simple little utility for checking AutoHotkey scripts for unresolved function references. Either run the utility then browse to an AutoHotkey script to test or just drag and drop a script onto the fdeps.exe icon in explorer.

The source is now available for this compiled script but is still a bit of a mess. Enjoy :) , and Please report any bugs if found.

This utility does not currently check for missing functions detected in a script in #Include files or in the Standard or User libraries. This utility was mainly designed to check scripts for external function dependencies to help when determining the files that need to be included with a script when distributing.

Download v0.03beta (194k)

Posted Image

Comments and/or suggestions welcome :) ...

; **********************************************************************************  
; ** Ahkx_fdeps v0.0.2 by corrupt    modified: September 2, 2007   
; **********************************************************************************  
; <COMPILER: v1.0.47.04>
#NoTrayIcon
about = fdeps v0.03beta - by corrupt (Ahkx series)

; **********************************************************************************  
; ** - Check if a script has been specified. Terminate if not specified. 
; ********************************************************************************** 
path1 = %1%%2%%3%%4%%5%%6%%7%%8%%9%
If path1=
  FileSelectFile, path1, 3,, Please select an AutoHotkey file to test, AutoHotkey scripts (*.ahk; *.ahkx)
If path1=
{
  MsgBox, 16, %about%, Error: File not specified., 2
  ExitApp
}
; **********************************************************************************  
; ** retrieve script & initialize values
; **********************************************************************************   
FileRead, ReadVar, %path1%
spos := 1
funct :=  ","

; **********************************************************************************  
; ** remove comments
; **********************************************************************************  
OutputVar := RegExReplace(ReadVar, "m)(?:(?:^\s*\;[^\n]*$)|(?:\s+\;[^\n]*$)|(?:\s*\/\*(?:.*\R)*?\*\/))", "")

; **********************************************************************************  
; ** - remove continuation lines (method#2)
; **********************************************************************************  
OutputVar := RegExReplace(OutputVar, "`am)^\((?:.*\R)*\)", "")

; **********************************************************************************  
; ** remove quoted items (same line)
; **********************************************************************************
OutputVar := RegExReplace(OutputVar, "m)(?:("""")|(""[^\n]*""))", "")

; **********************************************************************************  
; ** - determine function references and included functions
; ** - known issue: function references may be detected within multi-line quotes,    
; ** literal text is not currently ignored in commands (possibly fixed in a later release)
; **********************************************************************************  
Loop,
{
FoundPos := RegExMatch(OutputVar, "m)([^[#_@\$\?\[\]a-zA-Z0-9\n]*)([a-zA-Z0-9\_]+)\([^\n]*(?:\)|\R,.*\))[\s\R]*(\{?)\S?", func, spos)
  If !(FoundPos)
    break
  If func3={
  {
    If func1=
      Built_in .= "," . func2
  }
  Else
    funct .=  func2 . ","
  spos := FoundPos + StrLen(func1) + StrLen(func2) ; - 1
}

; **********************************************************************************  
; ** exclude built-in functions/syntax exceptions
; **********************************************************************************  
Built_in .= ",NumGet,NumPut,RegisterCallback"
Built_in .= ",If,FileExist,GetKeyState,InStr,RegExMatch,RegExReplace,SubStr,StrLen,WinActive,WinExist,Asc,Chr,IsLabel,DllCall"
Built_in .= ",OnMessage,VarSetCapacity,Abs,Ceil,Exp,Floor,Log,Ln,Mod,Round,Sqrt,Sin,ASin,ACos,ATan,LV_Add,LV_Insert"
Built_in .= ",LV_Modify,LV_Delete,LV_ModifyCol,LV_InsertCol,LV_DeleteCol,LV_GetCount,LV_GetText,SB_SetText,TV_Add,TV_Modify"
Built_in .= ",TV_Delete,TV_GetSelection,TV_GetCount,TV_GetParent,TV_GetChild,TV_GetPrev,TV_GetNext,TV_GetText,TV_Get,IL_Destroy,, ,"

; **********************************************************************************  
; ** - build function list and generate output
; **********************************************************************************
Loop, Parse, funct, `,
{
  If !InStr(Built_in, "," . A_LoopField . ",") {
    Built_in .= A_LoopField . ","
    If A_LoopField is not digit 
      A_out .= A_LoopField . ", "
  }
}
If A_out=
  MsgBox, 64, %about%, Unresolved function references not detected.
Else
{
  StringTrimRight, A_out, A_out, 2 
  MsgBox, 48, %about%, % "Possible unresolved function references detected: `n`n" . A_out
}
ExitApp



trik
  • Members
  • 1317 posts
  • Last active: Jun 11 2010 11:48 PM
  • Joined: 15 Jul 2007
:Applause: is it AHK based?

corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004

:Applause: is it AHK based?

Yes, it's a compiled AutoHotkey script :) .

trik
  • Members
  • 1317 posts
  • Last active: Jun 11 2010 11:48 PM
  • Joined: 15 Jul 2007
I figured. How did you make it non de-compilable?

corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004

I figured. How did you make it non de-compilable?

Nothing fancy. I used the built-in option for now... ;) :

In v1.0.46.10+, the /NoDecompile switch (if present) prevents exe2ahk from being able to decompile the script even when the correct password is given. This provides an additional layer of protection that goes beyond having a long, elaborate password.



corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004
Updated to v0.02beta

- fixed: If(myvar) was detected as a missing If function
- fixed: removed detection within quoted strings (same line)
- fixed: code was ignored between sets of multi-line comments

corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004
The source is now available for this compiled script but is still a bit of a mess. I didn't have to wait very long to get my question answered as to whether the /NoDecompile option is very effective, unfortunately :( (which was the main reason for not providing the source initially). Enjoy :) , and Please report any bugs when/if found.

corrupt
  • Members
  • 2558 posts
  • Last active: Nov 01 2014 03:23 PM
  • Joined: 29 Dec 2004
Updated to v0.03beta

- fixed: NumGet, NumPut and RegisterCallback were detected as missing functions