Leaderboard
Popular Content
Showing content with the highest reputation on 06/27/2014 in all areas
-
I have wrote a lot of binary code library for AutoIt before. I also discover many ways to generate binary code for AutoIt in the past. However, all of them have limitation or need some extra effort. Recently, I think I found the best and easiest way to generate the binary code. So I wrote this UDF, may be my last one about binary code. The Features:Both AutoIt x86 and x64 version are supported.Windows API and static variables can be use (code relocation supported).Decompression at run-time with smallest footprint LZMA decoder.Allocated memory blocks are released automatically.Most C source code works without modification.Two step or one step script generation, very easy to use.How It Works: The C source code must be compiled by MinGW GCC with "-S -masm=intel" option. Output is GAS syntax assembly file.BinaryCall Tool is able to convert the GAS syntax assembly file (*.s) to FASM syntax (*.asm). During the conversion, global symbols will be stored as "Symbol Jump Table" at the head of the file. The output file should be able to be assembled to binary file under command line by FASM.EXE. This syntax conversion is step 1.The step 2 is to assemble the file. BinaryCall Tool will use the embedded FASM to assemble every file twice to generate the relocation table. "BinaryCall.inc" will be included automatically before assembling to detect the Windows API and generate the "API Jump table". All the results will be compressed and converted to AutoIt script output.There are two major functions in the output script. _BinaryCall_Create() function allocates memorys, decompress the binary, relocates the address in memory, and fills the "API Jump Table"._BinaryCall_SymbolList() converts the "Symbol Jump Table" to memory addresses, and then store them as pointers in a DllStruct variable.Finally, we can use DllCallAddress() to call the memory address stored in the DllStruct.Step by Step Tutorial: Write C source code:#include <windows.h> void main() { MessageBox(0, "Hello", "Welcome Message", 1); }Use GCC MinGW 32/64 to compile the source code: gcc -S -masm=intel -m32 MessageBox.cUse BinaryCall Tool "GAS2AU3 Converter", select "MessageBox.s": If Not @AutoItX64 Then Local $Code = '...' Local $Reloc = '...' Local $Symbol[] = ["main"] Local $CodeBase = _BinaryCall_Create($Code, $Reloc) If @Error Then Exit Local $SymbolList = _BinaryCall_SymbolList($CodeBase, $Symbol) If @Error Then Exit EndIfPaste the output script, call the main() in AutoIt: #Include "BinaryCall.au3" ; Paste output here DllCallAddress("none:cdecl", DllStructGetData($SymbolList, "main"))Try to run it! Change Log:v1.0Initial release.v1.1A lot of improvement for GAS2ASM converter and FASM header file.Add many C Run-Time library as inline asm subroutines.Add command-line to argc/argv parser for easy calling main() function.Add ability to redirect stdio.More C source code can work without modification in this version. Following open source projects are tested. And Yes, they can run as binary code library in AutoIt now. SQLite 3.8.5 TCC 0.9.26 PuTTY beta 0.63 v1.2Dynamic-link library (DLL) calling is supported now. If the C program requires a DLL file to run, just put it together with the source file. BinaryCall Tool will searches *.dll and exports all the symbols in these DLL files automatically. Of course, you need these DLL files when run the output script. However, it also works if you loaded them by last version of MemoryDll UDF.To add more Windows API library easily by editing the ini file.Better error handling and more error messages in output script.Add zero padding to avoid short jumps that crash the relocation table.BinaryCall Tool accepts drag and drop files now.Some small bug fixed. BinaryCall 1.0.zip BinaryCall 1.1.zip BinaryCall 1.2.zip3 points
-
Some of Jerome Herr's processing code samples in AutoIt
UEZ and 2 others reacted to DatMCEyeBall for a topic
I wrote this after seeing Jerome Herr's post on Tumblr and looking at the code here. A few Google searches later, I came up with these. #include <GDIPlus.au3> #include <Math.au3> ;~ #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w- 7 Opt("GUIOnEventMode", 1) Global Const $nPI = 3.1415926535897932384626433832795 Global Const $nTWOPI = $nPI * 2 Global $iNum = 25 Global $nStep, $nSz, $nTheta $nStep = 20 Global $iMaxRad = ($iNum - 1) * $nStep Global $fClose = False Global $iW = $iMaxRad, $iH = $iMaxRad Global $hGUI = GUICreate('"Wave" by Jerome Herr | Written in AutoIt3 by EyeZiS', $iW, $iH) GUISetOnEvent(-3, "_Exit") _GDIPlus_Startup() Global $hCtxt = _GDIPlus_GraphicsCreateFromHWND($hGUI) Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hCtxt) Global $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2) Global $hPen = _GDIPlus_PenCreate(0xFFFFFFFF, 3, 2) Global $hTimer = TimerInit() GUISetState() While Not $fClose If TimerDiff($hTimer) >= 33 Then $hTimer = TimerInit() _Draw() _GDIPlus_GraphicsDrawImage($hCtxt, $hBitmap, 0, 0) ConsoleWrite(TimerDiff($hTimer) & @CRLF) EndIf Sleep(33 - TimerDiff($hTimer) - 1) WEnd _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_GraphicsDispose($hCtxt) GUIDelete() Func _Draw() _GDIPlus_GraphicsClear($hGraphics, 0xFF000000) Local $nArcEnd, $nOffset, $nDrawOffset For $i = 0 To $iNum - 1 $nSz = $i * $nStep $nOffset = $nTWOPI / $iNum * $i $nDrawOffset = $iMaxRad / 2 - $nSz / 2 $nArcEnd = _Degree(_Map(Sin($nTheta + $nOffset), -1, 1, $nPI, $nTWOPI) - $nPI) _GDIPlus_GraphicsDrawArc($hGraphics, $nDrawOffset, $nDrawOffset, $nSz, $nSz, 0, $nArcEnd, $hPen) _GDIPlus_GraphicsDrawArc($hGraphics, $nDrawOffset, $nDrawOffset, $nSz, $nSz, 180, $nArcEnd, $hPen) Next $nTheta += 0.0523 If $nTheta > $nTWOPI Then $nTheta = Mod($nTheta, $nTWOPI) EndIf EndFunc ;==>_Draw Func _Exit() $fClose = True EndFunc ;==>_Exit Func _Map($nVar, $nMin1, $nMax1, $nMin2, $nMax2) Return $nMin2 + ($nMax2 - $nMin2) * (($nVar - $nMin1) / ($nMax1 - $nMin1)) EndFunc ;==>_Map Playing with hue: #include <GDIPlus.au3> #include <Math.au3> #include <WinAPIGdi.au3> ;~ #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w- 7 Opt("GUIOnEventMode", 1) Global Const $nPI = 3.1415926535897932384626433832795 Global Const $nTWOPI = $nPI * 2 Global $iNum = 25 Global $nStep, $nSz, $nTheta Global $iStHue = 0 $nStep = 20 Global $iMaxRad = ($iNum - 1) * $nStep Global $fClose = False Global $iW = $iMaxRad, $iH = $iMaxRad Global $hGUI = GUICreate('"Wave" by Jerome Herr | Written in AutoIt3 by EyeZiS', $iW, $iH) GUISetOnEvent(-3, "_Exit") _GDIPlus_Startup() Global $hCtxt = _GDIPlus_GraphicsCreateFromHWND($hGUI) Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iW, $iH, $hCtxt) Global $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetSmoothingMode($hGraphics, 2) Global $hPen = _GDIPlus_PenCreate(0xFFFFFFFF, 3, 2) Global $hTimer = TimerInit() GUISetState() While Not $fClose If TimerDiff($hTimer) >= 33 Then $hTimer = TimerInit() _Draw() _GDIPlus_GraphicsDrawImage($hCtxt, $hBitmap, 0, 0) ConsoleWrite("Draw: " & TimerDiff($hTimer) & @CRLF) EndIf Sleep(33 - TimerDiff($hTimer) - 1) WEnd _GDIPlus_PenDispose($hPen) _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_GraphicsDispose($hCtxt) GUIDelete() Func _Draw() _GDIPlus_GraphicsClear($hGraphics, 0x7F000000) Local $nArcEnd, $nOffset, $nDrawOffset For $i = 0 To $iNum - 1 $nSz = $i * $nStep $nOffset = $nTWOPI / $iNum * $i $nDrawOffset = $iMaxRad / 2 - $nSz / 2 $nArcEnd = _Degree(_Map(Sin($nTheta + $nOffset), -1, 1, $nPI, $nTWOPI) - $nPI) _GDIPlus_PenSetColor($hPen, "0xFF" & Hex(_WinAPI_ColorHLSToRGB($iStHue + $i, 120, 240), 6)) _GDIPlus_GraphicsDrawArc($hGraphics, $nDrawOffset, $nDrawOffset, $nSz, $nSz, 0, $nArcEnd, $hPen) _GDIPlus_GraphicsDrawArc($hGraphics, $nDrawOffset, $nDrawOffset, $nSz, $nSz, 180, $nArcEnd, $hPen) Next $nTheta += 0.0523 $iStHue += 0.5 _ModIfGreater($nTheta, $nTWOPI) _ModIfGreater($iStHue, 239) EndFunc ;==>_Draw Func _Exit() $fClose = True EndFunc ;==>_Exit Func _Map($nVar, $nMin1, $nMax1, $nMin2, $nMax2) Return $nMin2 + ($nMax2 - $nMin2) * (($nVar - $nMin1) / ($nMax1 - $nMin1)) EndFunc ;==>_Map Func _ModIfGreater(ByRef $nVar, $nMod) $nVar = ($nVar > $nMod) ? (Mod($nVar, $nMod)) : ($nVar) EndFunc >#6 - Trunk in space >#7 - Lava Lamp >#8 - Wavy Thing3 points -
Some of Jerome Herr's processing code samples in AutoIt
DatMCEyeBall and one other reacted to UEZ for a topic
I adapted the Wavy example to AutoIt: ;original java code by Jared "BlueThen" C. -> http://www.openprocessing.org/sketch/5671 ;converted to AutoIt by UEZ 2014 #AutoIt3Wrapper_UseX64=n #AutoIt3Wrapper_Run_Au3Stripper=y #Au3Stripper_Parameters=/so #AutoIt3Wrapper_Run_After=del /f /q "%scriptdir%\%scriptfile%_stripped.au3" #pragma compile(UPX, False) #pragma compile(Icon, "c:\Program Files (x86)\AutoIt3\Aut2Exe\Icons\AutoIt_Main_v10_48x48_RGB-A.ico") #pragma compile(inputboxres, False) #AutoIt3Wrapper_Run_After=upx.exe --best --lzma "%out%" #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) _GDIPlus_Startup() Global $ghGDIPDll = $__g_hGDIPDll Global Const $iW = 500, $iH = 500, $sTitle = "GDI+ Wavy / FPS: " Global Const $hGUI = GUICreate($sTitle & "0", $iW, $iH) GUISetState() Global Const $hBmp = _GDIPlus_BitmapCreateFromScan0($iW, $iH) Global Const $hHBITMAP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBmp) _GDIPlus_BitmapDispose($hBmp) Global Const $hDC = _WinAPI_GetDC($hGUI) Global Const $hDC_Backbuffer = _WinAPI_CreateCompatibleDC($hDC) Global Const $DC_Obj = _WinAPI_SelectObject($hDC_Backbuffer, $hHBITMAP) Global Const $hGfxCtx = _GDIPlus_GraphicsCreateFromHDC($hDC_Backbuffer) _GDIPlus_GraphicsSetSmoothingMode($hGfxCtx, 2) Global Const $hBrush = _GDIPlus_BrushCreateSolid(), $hBrushL = _GDIPlus_BrushCreateSolid(0xFF555555), $hBrushR = _GDIPlus_BrushCreateSolid(0xFFAAAAAA), $hPen = _GDIPlus_PenCreate(0xFF000000), $hPath = _GDIPlus_PathCreate() GUISetOnEvent($GUI_EVENT_Close, "_Exit") Global Const $halfw = $iW / 2, $halfh = $iH / 2, $iSquares = 14, $iSquareshalf = $iSquares / 2, $iHeight = 40, $iSize = 17, $iSizehalf = $iSize / 2, $iCount = 4 Global $x, $y, $z, $a = 9999998, $xm, $xt, $zm, $zt, $isox1, $isoy1, $isox2, $isoy2, $isox3, $isoy3, $isox4, $isoy4, $iColor, $iFPS = 0 Global $fSpeed = 0.1, $fPhase = 0.55, $fPerspective = 0.5, $fPower = 24 Global $tPoints = DllStructCreate("float coordinates[" & $iCount * 2 & "]") Global Const $ghGDI32Dll = DllOpen("gdi32.dll") AdlibRegister("ShowFPS", 1000) Do $a -= $fSpeed DllCall($__g_hGDIPDll, "int", "GdipGraphicsClear", "handle", $hGfxCtx, "dword", 0xF0101010) For $x = -$iSquareshalf To $iSquareshalf - 1 For $z = -$iSquareshalf To $iSquareshalf - 1 $y = ($fPower * Sin($fPhase * Sqrt((0 - $x) * (0 - $x) + (0 - $z) * (0 - $z)) + $a)) $xm = $x * $iSize - $iSizehalf $xt = $x * $iSize + $iSizehalf $zm = $z * $iSize - $iSizehalf $zt = $z * $iSize + $iSizehalf $isox1 = ($xm - $zm + $halfw) $isoy1 = (($xm + $zm) * $fPerspective + $halfh) $isox2 = ($xm - $zt + $halfw) $isoy2 = (($xm + $zt) * $fPerspective + $halfh) $isox3 = ($xt - $zt + $halfw) $isoy3 = (($xt + $zt) * $fPerspective + $halfh) $isox4 = ($xt - $zm + $halfw) $isoy4 = (($xt + $zm) * $fPerspective + $halfh) ;draw left side $tPoints.coordinates((1)) = $isox2 $tPoints.coordinates((2)) = $isoy2 - $y $tPoints.coordinates((3)) = $isox3 $tPoints.coordinates((4)) = $isoy3 - $y $tPoints.coordinates((5)) = $isox3 $tPoints.coordinates((6)) = $isoy3 + $iHeight $tPoints.coordinates((7)) = $isox2 $tPoints.coordinates((8)) = $isoy2 + $iHeight DllCall($__g_hGDIPDll, "int", "GdipResetPath", "handle", $hPath) DllCall($__g_hGDIPDll, "int", "GdipAddPathPolygon", "handle", $hPath, "struct*", $tPoints, "int", $iCount) ;~ DllCall($__g_hGDIPDll, "int", "GdipDrawPath", "handle", $hGfxCtx, "handle", $hPen, "handle", $hPath) DllCall($__g_hGDIPDll, "int", "GdipFillPath", "handle", $hGfxCtx, "handle", $hBrushL, "handle", $hPath) ;draw right side $tPoints.coordinates((1)) = $isox3 $tPoints.coordinates((2)) = $isoy3 - $y $tPoints.coordinates((3)) = $isox4 $tPoints.coordinates((4)) = $isoy4 - $y $tPoints.coordinates((5)) = $isox4 $tPoints.coordinates((6)) = $isoy4 + $iHeight $tPoints.coordinates((7)) = $isox3 $tPoints.coordinates((8)) = $isoy3 + $iHeight DllCall($__g_hGDIPDll, "int", "GdipResetPath", "handle", $hPath) DllCall($__g_hGDIPDll, "int", "GdipAddPathPolygon", "handle", $hPath, "struct*", $tPoints, "int", $iCount) ;~ DllCall($__g_hGDIPDll, "int", "GdipDrawPath", "handle", $hGfxCtx, "handle", $hPen, "handle", $hPath) DllCall($__g_hGDIPDll, "int", "GdipFillPath", "handle", $hGfxCtx, "handle", $hBrushR, "handle", $hPath) ;draw top rectangle $tPoints.coordinates((1)) = $isox1 $tPoints.coordinates((2)) = $isoy1 - $y $tPoints.coordinates((3)) = $isox2 $tPoints.coordinates((4)) = $isoy2 - $y $tPoints.coordinates((5)) = $isox3 $tPoints.coordinates((6)) = $isoy3 - $y $tPoints.coordinates((7)) = $isox4 $tPoints.coordinates((8)) = $isoy4 - $y $iColor = Int((4 + $y * 0.066666) * 48) $iColor = $iColor < 0x00 ? 0x00 : $iColor > 0xFF ? 0xFF : $iColor DllCall($__g_hGDIPDll, "int", "GdipSetSolidFillColor", "handle", $hBrush, "dword", 0xFF000000 + $iColor * 0x10000 + $iColor * 0x100 + $iColor) DllCall($__g_hGDIPDll, "int", "GdipResetPath", "handle", $hPath) DllCall($__g_hGDIPDll, "int", "GdipAddPathPolygon", "handle", $hPath, "struct*", $tPoints, "int", $iCount) ;~ DllCall($__g_hGDIPDll, "int", "GdipDrawPath", "handle", $hGfxCtx, "handle", $hPen, "handle", $hPath) DllCall($__g_hGDIPDll, "int", "GdipFillPath", "handle", $hGfxCtx, "handle", $hBrush, "handle", $hPath) Next Next DllCall($ghGDI32Dll, "bool", "BitBlt", "ptr", $hDC, "int", 0, "int", 0, "int", $iW, "int", $iH, "ptr", $hDC_Backbuffer, "int", 0, "int", 0, "dword", $SRCCOPY) $iFPS += 1 Until False * Sleep(10) Func ShowFPS() WinSetTitle($hGUI, "", $sTitle & $iFPS) $iFPS = 0 EndFunc Func _Exit() AdlibUnRegister("ShowFPS") _GDIPlus_PathDispose($hPath) _GDIPlus_BrushDispose($hBrush) _GDIPlus_BrushDispose($hBrushL) _GDIPlus_BrushDispose($hBrushR) _GDIPlus_PenDispose($hPen) _WinAPI_SelectObject($hDC_Backbuffer, $DC_Obj) _GDIPlus_GraphicsDispose($hGfxCtx) _WinAPI_DeleteObject($hHBITMAP) _WinAPI_ReleaseDC($hGUI, $hDC) _GDIPlus_Shutdown() GUIDelete($hGUI) DllClose($ghGDI32Dll) Exit EndFunc Edit1: optimized the code a little bit - now slightly faster. Edit2: still some more optimizations which increases the fps speed Edit3: squeezed still a few fps Br, UEZ2 points -
TCC is a small and fast C compiler. And the LibTCC use TCC as a backend for dynamic code generation. With LibTCC, we can add some C source to speed up the time-consuming subroutines. For example: Func Fib($n) Local $C $C = 'int fib(int n) ' & @LF $C &= '{ ' & @LF $C &= ' if (n <= 2) ' & @LF $C &= ' return 1; ' & @LF $C &= ' else ' & @LF $C &= ' return fib(n-1) + fib(n-2); ' & @LF $C &= '} ' Local $TCC = TCC_New() TCC_Compile_String($TCC, $C) Local $Size = TCC_Relocate($TCC, 0) Local $CodeBuffer = _MemVirtualAlloc(0, $Size, $MEM_COMMIT, $PAGE_EXECUTE_READWRITE) TCC_Relocate($TCC, $CodeBuffer) Local $Ptr = TCC_Get_Symbol($TCC, "fib") Local $Ret = MemoryFuncCall("int:cdecl", $Ptr, "int", $n) _MemVirtualFree($CodeBuffer, 0, $MEM_RELEASE) TCC_Delete($TCC) Return $Ret[0] EndFunc There is also an example using the C source (MD5.C) to count the MD5 in AutoIt (Include in the ZIP). Just like run the C source as script. For detail usage of the LibTCC functions. Please see libtcc.h in the TCC source. (The examples already demonstrate most functions) AutoIt x64 it not supported now. LibTCC.zip 2011/08/03 Update Note: Fix the bug in TCC_Run, thanks rchockxm.Add example for TCC_RunLibTCC.zip 2011/08/29 Update Note: Add some function to generated binary code that can be used in other script without LibTCC. If the C source using Windows API, then the code can't run on other system. A solution is getting the API address in AutoIt and pass it to C code by function pointer. NOTICE: These functions and examples need my LibTCC_Binary.zip1 point
-
I have already published a lot of AutoIt UDF about algorithm, but all of them only support 32 bits or so called X86 system. Recently I got a computer with Windows 7 64 bits, so I finally added X64 support to most of my old projects. Besides, I also added some new. For example, some compression algorithm and SHA3 Candidates. Following are the algorithms list: Checksum CRC16 CRC32 ADLER32 Compression FastLZ LZF LZMA LZMAT MiniLZO QuickLZ Encode Base64 ARC4 XXTEA DES AES Hash Checksums (CRC16/CRC32/ADLER32) MD2 MD4 MD5 SHA1 SHA2 (SHA224/256/384/512) SHA3 Candidates BLAKE BMW (Blue Midnight Wish) CUBEHASH ECHO SHABAL SKEIN Some points to mention: All of the subroutines have one or more examples to demonstrate the usage. Since the function and usage of subroutine are easy to understand. A complete subroutines and parameters list are unavailability now. Sorry for my lazy. All of the subroutines here invoked by Lazycat's method (through CallWindowProc API). My MemoryDLL UDF is not necessary this time. Although MemoryFuncCall (part of MemoryDLL) is still good, but inevitably, it is slower than CallWindowProc. Some subroutines have the same name with my old machine code version UDF. But for some reason, I rearrange the position of the parameters. Please not mix up. If you notice, yes, checksums are duplicated. But they receive different parameters. One is the old style, and another use the same interface as other hashes. Choose what you like, but don't use them in the same time. Some algorithm already supported by the standard UDF "Encryption.au3". But I still provide them, because some system lack of the full support of Windows Crypt Library. If you are looking for only one hash algorithm, for example, used in encryption, I suggested "SHABAL_TINY.au3". Although it is a bit slower then SHABAL, but it is smaller, and it supports different size of output (from 32 to 512 bits).AutoIt Machine Code Algorithm Collection.zip1 point
-
The bumper thread of missing winapi examples.
argumentum reacted to JohnOne for a topic
As I look through _WinAPI_* entries in the help file there are many without examples. It's quite a task for any one person to undertake, so I propose anyone who can be bothered every now and then, figure one out and post an example here. I'd suggest not using the help forum as that defeats the object. I'll go first with an easy one from near the top. EDIT: (regarding guinness' below post) If you wish your example to be considered for help file entry, please follow his instructions. If you don't care then don't worry, just the example will do however you like. EDIT2: The links below are to the examples, not the online help. EDIT3: If anyone wants to modify any examples to be help file worthy you are most welcome to. _WinAPI_ArrayToStruct _WinAPI_AbortPath >_WinAPI_AdjustWindowRectEx >_WinAPI_GetDefaultUserProfileDirectory >_WinAPI_DeleteFile >_WinAPI_GetAsyncKeyState >_WinAPI_GetCurrentDirectory >_WinAPI_GetDefaultPrinter >_WinAPI_GetDeviceCaps >_WinAPI_GetDriveType >_WinAPI_GetErrorMessage >_WinAPI_GetFileType >_WinAPI_GetGraphicsMode >_WinAPI_GetGuiResources >_WinAPI_GetPEType >_WinAPI_GetPolyFillMode >_WinAPI_GetPriorityClass >_WinAPI_GetProcessHandleCount >_WinAPI_GetProcessIoCounters >_WinAPI_GetProfilesDirectory >_WinAPI_GetROP2 >_WinAPI_GetStartupInfo >_WinAPI_GetStdHandle >_WinAPI_GetSystemDEPPolicy >_WinAPI_GetSystemInfo >_WinAPI_GetSystemMetrics >_WinAPI_GetSystemTimes >_WinAPI_GetSystemWow64Directory >_WinAPI_GetTempFileName >_WinAPI_GetVersionEx >_WinAPI_GetWindowDC >_WinAPI_GetWindowFileName >_WinAPI_GetWindowHeight >_WinAPI_GetWindowWidth >_WinAPI_GlobalMemoryStatus >_WinAPI_HiByte >_WinAPI_InflateRect >_WinAPI_IsChild >_WinAPI_IsClassName >_WinAPI_IsElevated >_WinAPI_LoByte >_WinAPI_OpenProcess1 point -
Function Name Lister 06/27/2014
obiwanceleri reacted to jaberwacky for a topic
Hi. Have you ever tried to manually maintain a list of function names for your various projects? What I mean is when you start an AutoIt project you might have tried to maintain a running list of all of the functions that are in your project. This is fine when your project is small. When the project grows out of control then you may be like me and you simply stop maintaining that list. So I am hacking together a simple script to automate that process. Instructions: 1) Paste this into your user options file (Scite -> Options -> Open User Options File): # 37 FunctionNameLister command.37.$(au3)="$(SciteDefaultHome)\FunctionNameLister\FunctionNameLister.exe" "$(FilePath)" command.name.37.$(au3)=FunctionNameLister command.shortcut.37.$(au3)=Ctrl+Shift+Alt+f command.save.before.37.$(au3)=1 command.is.filter.37.$(au3)=1 Note: the number 37 may be changed to a number which suits you. 2) Create a folder named FunctionNameLister in the "...AutoIt3SciTE" directory. 3) Place the FunctionNameLister.exe into the folder that was created in step 2. FunctionNameLister.zip downloads:26 4) Browse to an AutoIt source. Paste the following two lines wherever you would like for your list of function names to appear in your source: #region ; Functions #endregion ; Functions Press Ctrl + Shift + Alt + f. Updates: Here is just the main code for those interested. The zip file contains the required exe. #AutoIt3Wrapper_UseX64=n #AutoIt3Wrapper_AU3Check_Parameters=-w 1 -w 2 -w 3 -w 4 -w 6 -w 7 -d -q #Region ; Functions ; alert ; backup_original_copy ; create_function_list_string ; erase_function_list ; file_stream_read_line ; get_source_path ; main ; write_function_list_to_string #EndRegion ; Functions #include-once #include "SciTE Director.au3" #include <Array.au3> #include <File.au3> #include <String.au3> ; These tags are required to be in the au3 source in order for FunctionNameLister to work properly. ; They may be changed by editing the settings.ini file. Const $tag_begin = IniRead(@ScriptDir & "\settings.ini", "Tags", "TagBegin", "#Region ; Functions") Const $tag_end = IniRead(@ScriptDir & "\settings.ini", "Tags", "TagEnd", "#EndRegion ; Functions") ; Constants for FileStream functionality. Const $file_stream_eof = -1 Const $file_stream_other_error = 1 main() Switch @error Case 0 alert("FunctionNameLister was successful.") Case 1 alert("You must provide a path to an au3 source.", True) Case 2 alert("Could not make a back up of the original file.", True) Case 3 alert("Could not find the required tags.", True) EndSwitch Func main() Local Const $source_path = get_source_path() If @error Then Return SetError(1, 0, False) EndIf Switch backup_original_copy($source_path) Case True Local Const $autoit_source = erase_function_list($source_path) ; find the function names and write them to an array -- thanks Yashied Local Const $func_list = StringRegExp(StringRegExpReplace($autoit_source, "(?ims)#c[^#]+#c", ''), "(?ims)^\s*func\s*([^(]*)", 3) Local Const $func_string = create_function_list_string($func_list, True) Local Const $file_overwrite = FileOpen($source_path, $FO_OVERWRITE) Switch $file_overwrite <> -1 Case True Local Const $new_au3 = write_function_list_to_string($func_string, $autoit_source) If @error Then Return SetError(3, 0, False) EndIf FileWrite($file_overwrite, $new_au3) FileClose($file_overwrite) scite_close($source_path) scite_open($source_path) EndSwitch Case False Return SetError(2, 0, False) EndSwitch Return True EndFunc Func get_source_path() Local $source_path Select Case UBound($cmdline) <= 1 $source_path = FileOpenDialog("Browse to an au3 source.", '', "AU3 (*.au3)" ) If @error Then Return SetError(1, 0, False) EndIf Case Else $source_path = $cmdline[1] EndSelect Return $source_path EndFunc Func backup_original_copy(Const $source_path) Local $drive, $dir, $name, $ext _PathSplit($source_path, $drive, $dir, $name, $ext) Local Const $backup_path = _PathMake($drive, $dir, $name, ".BAK") Return FileCopy($source_path, $backup_path, 1) ? True : SetError(1, 0, False) EndFunc Func write_function_list_to_string(Const $func_string, Const $autoit_source) Local Const $tag_position = StringInStr($autoit_source, $tag_begin) If Not $tag_position Then Return SetError(1, 0, False) EndIf Local Const $tag_length = StringLen($tag_begin) Local Const $insert_string = ((StringInStr($func_string, $tag_end) > 0) ? $func_string : ($func_string & $tag_end)) Return _StringInsert($autoit_source, $insert_string & @CRLF, ($tag_position + $tag_length + 1)) EndFunc Func create_function_list_string($func_array, Const $sort) If Not IsArray($func_array) Then Return SetError(1, 0, False) If $sort Then _ArraySort($func_array, 0) Local $func_string = '' For $function In $func_array $func_string &= "; " & $function & @CRLF Next Return $func_string EndFunc Func erase_function_list(Const $source_path) Local $line = '' Local $autoit_source = '' Local $within_func_list = False Do $line = file_stream_read_line($source_path) Switch @error Case 0 Switch $line Case $tag_begin $within_func_list = True $autoit_source &= $tag_begin & @CRLF ContinueLoop Case $tag_end Switch $within_func_list Case True $within_func_list = False ContinueLoop EndSwitch EndSwitch Case $file_stream_eof, $file_stream_other_error ExitLoop EndSwitch Switch $within_func_list Case False $autoit_source &= $line & @CRLF Case True Select Case StringLeft($line, 1) <> ';' $within_func_list = False EndSelect EndSwitch Until False Return $autoit_source EndFunc Func file_stream_read_line(Const $path) Local Const $file_stream_close = -2 Local Const $file_stream_ready = -3 Local Const $file_stream_open_error = -1 Local Static $file_open = FileOpen($path, $FO_READ) Switch $path Case $file_stream_close FileClose($file_open) $file_open = $file_stream_ready Return True EndSwitch Select Case $file_open = $file_stream_open_error $file_open = $file_stream_ready Return SetError(2, 1, False) Case $file_open = $file_stream_ready $file_open = FileOpen($path, $FO_READ) Switch $file_open Case $file_stream_open_error $file_open = $file_stream_ready Return SetError(2, 2, False) EndSwitch ContinueCase Case $file_open >= 0 Local Const $file_line = FileReadLine($file_open) Switch @error Case 0 Return $file_line Case $file_stream_eof FileClose($file_open) $file_open = $file_stream_ready Return SetError($file_stream_eof, 0, False) Case $file_stream_other_error FileClose($file_open) $file_open = $file_stream_ready Return SetError($file_stream_other_error, 0, False) EndSwitch EndSelect EndFunc Func alert(Const $message, Const $error = False) Switch @Compiled Case True Switch $error Case False MsgBox($MB_OK, "FunctionNameLister", $message) Case True MsgBox($MB_OK + $MB_ICONERROR, "FunctionNameLister", $message) EndSwitch Case False Switch $error Case False ConsoleWrite(@CRLF & "> " & $message & @CRLF & @CRLF) Case True ConsoleWrite(@CRLF & "! " & $message & @CRLF & @CRLF) EndSwitch EndSwitch EndFunc1 point -
Porting AutoIt to Linux?
SlowCoder74 reacted to Melba23 for a topic
SlowCoder74, Most of AutoIt depends on the Windows API - so there is no chance of it being ported to any other OS. M231 point -
simpel question about Text in a GUI button
Palestinian reacted to Melba23 for a topic
Merchants, Just double the ampersand: $GUI[19] = GUICtrlCreateButton("Clear && Save", 207, 90, 69, 17) M231 point -
Has anyone ever created a Virus Scanner with AutoIt?
somdcomputerguy reacted to guinness for a topic
Leave it to the experts methinks.1 point -
Perforator v1.25 build 2015-06-30 beta - perforate your GUI easily
mesale0077 reacted to UEZ for a topic
The problem is the AnimateWindow function from user32.dll. You have to use a workaround for the fading method. Something like this here: Func GUI_Fader($hGUI, $bFadeIn = True, $iSpeed = 1, $iSleep = 10) Local $i Switch $bFadeIn Case True For $i = 0x00 To 0xFF Step $iSpeed WinSetTrans($hGUI, "", $i) Sleep($iSleep) Next Case False For $i = 0xFF to 0x00 Step - $iSpeed WinSetTrans($hGUI, "", $i) Sleep($iSleep) Next EndSwitch EndFunc Br, UEZ1 point -
Recursion limit is pretty standard in most high-level programming languages.1 point
-
Hm. Why wouldn't one be allowed to write and use function like this: Func Adlib($vFunc, $bDereg = False) ($bDereg ? AdlibUnRegister : AdlibRegister)($vFunc) EndFunc ...in AutoIt that's perfectly valid, but AU3Check after being "fixed" by jpm will say you have error in the code. Why?1 point
-
In my new program, I need custom buttons of system dialog. After search on the internet, I found the way. Instead of using GUICreate, this code just hook the system dialog. The hook type is WH_CBT, See MSDN for more information. Except button text, is there any other interesting thing can be modified ? ; ============================================================================= ; MsgBoxEx And InputBoxEx Examples ; Purpose: Custom Buttons Of System Dialog ; Author: Ward ; ============================================================================= #Include <WinAPI.au3> MsgBoxEx("Button1|Button2", 1, "MsgBoxEx", "Test") MsgBoxEx("|Button3||||Button1|Button2", 3, "MsgBoxEx", "Test") InputBoxEx("Button1|Button2", "InputBoxEx", "Prompt") Func MsgBoxEx($CustomButton, $Flag, $Title, $Text, $Timeout = 0, $Hwnd = 0) Assign("MsgBoxEx:CustomButton", $CustomButton, 2) Local $CBT_ProcCB = DllCallbackRegister("MsgBoxEx_CBT_Proc", "long", "int;hwnd;lparam") Local $CBT_Hook = _WinAPI_SetWindowsHookEx($WH_CBT, DllCallbackGetPtr($CBT_ProcCB), 0, _WinAPI_GetCurrentThreadId()) Local $Ret = MsgBox($Flag, $Title, $Text, $Timeout, $Hwnd) Local $Error = @Error _WinAPI_UnhookWindowsHookEx($CBT_Hook) DllCallbackFree($CBT_ProcCB) Assign("MsgBoxEx:CustomButton", 0, 2) Return SetError($Error, 0, $Ret) EndFunc Func MsgBoxEx_CBT_Proc($nCode, $wParam, $lParam) If $nCode = 5 Then ; HCBT_ACTIVATE Local $CustomButton = StringSplit(Eval("MsgBoxEx:CustomButton"), "|") For $i = 1 To $CustomButton[0] ControlSetText($wParam, "", $i, $CustomButton[$i]) Next EndIf Return _WinAPI_CallNextHookEx(0, $nCode, $wParam, $lParam) EndFunc Func InputBoxEx($CustomButton, $Title, $Prompt, $Default = "", $Password = "", $Width = Default, $Height = Default, $Left = Default, $Top = Default, $Timeout = Default, $Hwnd = Default) Assign("InputBoxEx:CustomButton", $CustomButton, 2) Local $CBT_ProcCB = DllCallbackRegister("InputBoxEx_CBT_Proc", "long", "int;hwnd;lparam") Local $CBT_Hook = _WinAPI_SetWindowsHookEx($WH_CBT, DllCallbackGetPtr($CBT_ProcCB), 0, _WinAPI_GetCurrentThreadId()) Local $Ret = InputBox($Title, $Prompt, $Default, $Password, $Width, $Height, $Left, $Top, $Timeout, $Hwnd) Local $Error = @Error _WinAPI_UnhookWindowsHookEx($CBT_Hook) DllCallbackFree($CBT_ProcCB) Assign("InputBoxEx:CustomButton", 0, 2) Return SetError($Error, 0, $Ret) EndFunc Func InputBoxEx_CBT_Proc($nCode, $wParam, $lParam) If $nCode = 5 Then ; HCBT_ACTIVATE Local $CustomButton = StringSplit(Eval("InputBoxEx:CustomButton"), "|") For $i = 1 To $CustomButton[0] ControlSetText($wParam, "", $i, $CustomButton[$i]) Next EndIf Return _WinAPI_CallNextHookEx(0, $nCode, $wParam, $lParam) EndFunc1 point
-
How to detect and disable a button if a user clicks it two or more times?
KEHT reacted to Richard Robertson for a topic
In your code for when they click it, add a GUICtrlSetState($control, $GUI_DISABLE) at the top, and when you finish, add a GUICtrlSetState($control, $GUI_ENABLE). Of course, $control is the id of your button. Edit: Smoke posted before I finished reading.1 point