Leaderboard
Popular Content
Showing content with the highest reputation on 11/08/2020 in all areas
-
May I have some help about Recordset question?
WinMacBear and one other reacted to mLipok for a topic
You should try my ADO.au3 UDF.2 points -
MMC is subject to automation by COM. have a look at these MSDN articles: MMC 2.0 Automation Object Model Using VBScript with the MMC 2.0 Automation Object Model also, it took a while, but i managed to hunt-down this piece of code i once made according to the above. (even considered making it a full-blown UDF someday, but...) you can get the idea from this example. it involves the "Users and Groups" snap-in, but you can adapt it. oh, and it comes with a bonus - how to implement a COM Error Handler in a UDF, so it does not collide with whatever COM Error Handler the main script employs. enjoy! ; MSDN root topic: https://msdn.microsoft.com/en-us/library/aa815049(v=vs.85).aspx ; MSDN VB example: https://msdn.microsoft.com/en-us/library/aa815371(v=vs.85).aspx #RequireAdmin #AutoIt3Wrapper_UseX64=Y ; UDF Global $__g_MMC_oCOMError = Null Global $__g_MMC_iCOMError = 0 Global $__g_MMC_sCOMError = '' Func _MMC_GroupShowProperties($sGroup) $__g_MMC_oCOMError = ObjEvent('AutoIt.Error', '__MMC_COMError') Local Const $sMMC_NodeTypeGUID_Groups = '{5D6179CA-17EC-11D1-9AA9-00C04FD8FE93}' Local $oMMC_Application, $oMMC_Document Local $oMMC_Views, $oMMC_View Local $oMMC_Items, $oMMC_Item $oMMC_Application = ObjCreate('MMC20.Application') $oMMC_Application.Load('lusrmgr.msc') $oMMC_Application.Show() $oMMC_Document = $oMMC_Application.Document $oMMC_Views = $oMMC_Document.Views $oMMC_View = $oMMC_Views.Item(1) ; the ListView results pane (?) $oMMC_Items = $oMMC_View.ListItems() For $oMMC_Item In $oMMC_Items If $oMMC_Item.Nodetype = $sMMC_NodeTypeGUID_Groups Then $oMMC_View.ExecuteScopeNodeMenuItem('_EXPLORE', $oMMC_Item) Next $oMMC_View = $oMMC_Views.Item(2) ; the ListView results pane $oMMC_Items = $oMMC_View.ListItems() For $oMMC_Item In $oMMC_Items If $oMMC_Item.Name = $sGroup Then $oMMC_View.Select($oMMC_Item) $oMMC_View.ExecuteSelectionMenuItem('_PROPERTIES') EndIf Next $oMMC_Application.UserControl = 1 Return SetError($__g_MMC_iCOMError, 0, $__g_MMC_iCOMError = 0 ? True : False) EndFunc ;==>_MMC_GroupShowProperties Func __MMC_COMError() $__g_MMC_iCOMError = $__g_MMC_oCOMError.number ; use to check when a COM Error occurs. reset it to 0 after handling the error $__g_MMC_sCOMError = _ 'err.number: ' & $__g_MMC_iCOMError & @CRLF & _ 'err.number (hex): ' & Hex($__g_MMC_iCOMError, 8) & @CRLF & _ 'err.description: ' & $__g_MMC_oCOMError.description & @CRLF & _ 'err.windescription: ' & $__g_MMC_oCOMError.windescription & @CRLF & _ 'err.lastdllerror: ' & $__g_MMC_oCOMError.lastdllerror & @CRLF & _ 'err.scriptline: ' & $__g_MMC_oCOMError.scriptline & @CRLF & _ 'err.source: ' & $__g_MMC_oCOMError.source & @CRLF & _ 'err.helpfile: ' & $__g_MMC_oCOMError.helpfile & @CRLF & _ 'err.helpcontext: ' & $__g_MMC_oCOMError.helpcontext ConsoleWrite($__g_MMC_sCOMError & @CRLF) EndFunc ;==>__MMC_COMError ; MAIN Global $oCOMError = ObjEvent('AutoIt.Error', '__COMError') If Not _MMC_GroupShowProperties('Administrators') Then MsgBox(0, 'Error', 'COM error occurred in UDF.') Global $oMMC_Application = ObjCreate('MMC20.Application') $oMMC_Application.UndefinedAction() Func __COMError() Local $iCOMError = $oCOMError.number ; use to check when a COM Error occurs. reset it to 0 after handling the error Local $sCOMError = _ 'err.number: ' & $iCOMError & @CRLF & _ 'err.number (hex): ' & Hex($iCOMError, 8) & @CRLF & _ 'err.description: ' & $oCOMError.description & @CRLF & _ 'err.windescription: ' & $oCOMError.windescription & @CRLF & _ 'err.lastdllerror: ' & $oCOMError.lastdllerror & @CRLF & _ 'err.scriptline: ' & $oCOMError.scriptline & @CRLF & _ 'err.source: ' & $oCOMError.source & @CRLF & _ 'err.helpfile: ' & $oCOMError.helpfile & @CRLF & _ 'err.helpcontext: ' & $oCOMError.helpcontext MsgBox(0, '', '!COM error in main script') ConsoleWrite('!COM error in main script' & @CRLF) ConsoleWrite($sCOMError & @CRLF) EndFunc ;==>__COMError1 point
-
May I have some help about Recordset question?
WinMacBear reacted to GokAy for a topic
Hey, That looks like a mixture of AutoIt and VBA. You could use a variable to hold the return value. First assign it to the "all passed" value, and only change it when your fail condition is met. Also exit loop if only one instance of condition = true (TEST1 = 0 in this case) is necessary to return 0. Local $iReturn = 1 With $oADORecordset While Not .EOF If TEST1 = 0 Then $iReturn = 0 ExitLoop ; no need to continue further if condition is met Else ; Unless you need other return values, this part is unnecessary now ; $iReturn = 1 Endif WEND ENDWITH $oADORecordset.Close ; Close the recordset $oADORecordset = 0 ; Release the recordset object $oADOConnection.Close ; Close the connection $oADOConnection = 0 ; Release the connection object Return $iReturn1 point -
Hack that tells you what line# a compiled script actually crashed on...
mLipok reacted to JockoDundee for a topic
mLipok, it’s not the Autoit Error MsgBox that I object to, it’s the the data in the Error MsgBox (with compiled scripts) that’s the problem. Your example is interesting but although you eliminate the pop-up, you are still showing the stripped error line #, not the actual line# in the source file. You still need to go to the stripped file and x-ref, and the come back to the actual source file - it’s another step. You may not feel it’s a big deal, but as I explained I am writing mostly CLI apps exclusively, it is a common occurrence. Do you use ScITe to develop in? Now imagine every time you had a runtime error using SciTe that instead of the editor taking you right to the line, it just told you the line number into another file where you could see the errant line, but still had to go back to your source find it and pull it up. You could do it, but you might wonder why. Anyway, I do like the idea of the error line# being displayed on stdout, as long as it has the line# of the source file and not the stripped file. So I took the liberty of merging the AddHookApi code with some of my functions to achieve that. Here is the output that mirrors yours, with the difference that the line # is a direct reference to the source file: I made an #include called AddHookApi.au3 c using the code you provided, then I added my own code to it. It works but it’s rather sloppy, and I expect I’ll break it out further. That file looks like this: #include <WinApi.au3> #include <StringConstants.au3> #include <File.au3> #pragma compile(Console, True) Local $fhInput, $fhOutput Local $sErrorText, $sSourceFile, $sOutFileName Local $iErrLineNo, $iRefLineNo, $iLinesRead ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; AddHookApi("user32.dll", "MessageBoxW", "Intercept_MessageBoxW", "int", "hwnd;wstr;wstr;uint") Func Intercept_MessageBoxW($hWnd, $sText, $sTitle, $iType) Local $aOutput = StringRegExp($sText, '(?i)Line\s+(\d+)', $STR_REGEXPARRAYGLOBALMATCH) If @error Then Return If @ScriptName="_errormsghack.exe" Then ConsoleWrite($aOutput[0]) Exit Else $aOutput[0]=GetTrueSourceErrorLine($aOutput[0]) EndIf ConsoleWrite(@ScriptName & ' - !!! Error occured in line #' & $aOutput[0] & @CRLF) Return ; mLipok mod omnit MsgBox because of CUI=Y Local $aCall = DllCall("user32.dll", "int", "MessageBoxW", _ "hwnd", $hWnd, _ "wstr", $sText, _ "wstr", StringReplace($sTitle, "AutoIt", @ScriptName), _ "uint", $iType) If @error Or Not $aCall[0] Then Return 0 Return $aCall[0] EndFunc ;==>Intercept_MessageBoxW ; The magic is down below Func AddHookApi($sModuleName, $vFunctionName, $vNewFunction, $sRet = "", $sParams = "") Local Static $pImportDirectory, $hInstance Local Const $IMAGE_DIRECTORY_ENTRY_IMPORT = 1 If Not $pImportDirectory Then $hInstance = _WinAPI_GetModuleHandle(0) $pImportDirectory = ImageDirectoryEntryToData($hInstance, $IMAGE_DIRECTORY_ENTRY_IMPORT) If @error Then Return SetError(1, 0, 0) EndIf Local $iIsInt = IsInt($vFunctionName) Local $iRestore = Not IsString($vNewFunction) Local $tIMAGE_IMPORT_MODULE_DIRECTORY Local $pDirectoryOffset = $pImportDirectory Local $tModuleName Local $iInitialOffset, $iInitialOffset2 Local $iOffset2 Local $tBufferOffset2, $iBufferOffset2 Local $tBuffer, $tFunctionOffset, $pOld, $fMatch, $pModuleName, $pFuncName Local Const $PAGE_READWRITE = 0x04 While 1 $tIMAGE_IMPORT_MODULE_DIRECTORY = DllStructCreate("dword RVAOriginalFirstThunk;" & _ "dword TimeDateStamp;" & _ "dword ForwarderChain;" & _ "dword RVAModuleName;" & _ "dword RVAFirstThunk", _ $pDirectoryOffset) If Not DllStructGetData($tIMAGE_IMPORT_MODULE_DIRECTORY, "RVAFirstThunk") Then ExitLoop $pModuleName = $hInstance + DllStructGetData($tIMAGE_IMPORT_MODULE_DIRECTORY, "RVAModuleName") $tModuleName = DllStructCreate("char Name[" & _WinAPI_StringLenA($pModuleName) & "]", $pModuleName) If DllStructGetData($tModuleName, "Name") = $sModuleName Then ; function from this module $iInitialOffset = $hInstance + DllStructGetData($tIMAGE_IMPORT_MODULE_DIRECTORY, "RVAFirstThunk") $iInitialOffset2 = $hInstance + DllStructGetData($tIMAGE_IMPORT_MODULE_DIRECTORY, "RVAOriginalFirstThunk") If $iInitialOffset2 = $hInstance Then $iInitialOffset2 = $iInitialOffset $iOffset2 = 0 While 1 $tBufferOffset2 = DllStructCreate("dword_ptr", $iInitialOffset2 + $iOffset2) $iBufferOffset2 = DllStructGetData($tBufferOffset2, 1) If Not $iBufferOffset2 Then ExitLoop If $iIsInt Then If BitAND($iBufferOffset2, 0xFFFFFF) = $vFunctionName Then $fMatch = True ; wanted function Else $pFuncName = $hInstance + $iBufferOffset2 + 2 ; 2 is size od "word", see line below... $tBuffer = DllStructCreate("word Ordinal; char Name[" & _WinAPI_StringLenA($pFuncName) & "]", $hInstance + $iBufferOffset2) If DllStructGetData($tBuffer, "Name") == $vFunctionName Then $fMatch = True ; wanted function EndIf If $fMatch Then $tFunctionOffset = DllStructCreate("ptr", $iInitialOffset + $iOffset2) VirtualProtect(DllStructGetPtr($tFunctionOffset), DllStructGetSize($tFunctionOffset), $PAGE_READWRITE) If @error Then Return SetError(3, 0, 0) $pOld = DllStructGetData($tFunctionOffset, 1) If $iRestore Then DllStructSetData($tFunctionOffset, 1, $vNewFunction) Else DllStructSetData($tFunctionOffset, 1, DllCallbackGetPtr(DllCallbackRegister($vNewFunction, $sRet, $sParams))) EndIf Return $pOld EndIf $iOffset2 += DllStructGetSize($tBufferOffset2) WEnd ExitLoop EndIf $pDirectoryOffset += 20 ; size of $tIMAGE_IMPORT_MODULE_DIRECTORY WEnd Return SetError(4, 0, 0) EndFunc ;==>AddHookApi Func VirtualProtect($pAddress, $iSize, $iProtection) Local $aCall = DllCall("kernel32.dll", "bool", "VirtualProtect", "ptr", $pAddress, "dword_ptr", $iSize, "dword", $iProtection, "dword*", 0) If @error Or Not $aCall[0] Then Return SetError(1, 0, 0) Return 1 EndFunc ;==>VirtualProtect Func ImageDirectoryEntryToData($hInstance, $iDirectoryEntry) ; Get pointer to data Local $pPointer = $hInstance ; Start processing passed binary data. 'Reading' PE format follows. Local $tIMAGE_DOS_HEADER = DllStructCreate("char Magic[2];" & _ "word BytesOnLastPage;" & _ "word Pages;" & _ "word Relocations;" & _ "word SizeofHeader;" & _ "word MinimumExtra;" & _ "word MaximumExtra;" & _ "word SS;" & _ "word SP;" & _ "word Checksum;" & _ "word IP;" & _ "word CS;" & _ "word Relocation;" & _ "word Overlay;" & _ "char Reserved[8];" & _ "word OEMIdentifier;" & _ "word OEMInformation;" & _ "char Reserved2[20];" & _ "dword AddressOfNewExeHeader", _ $pPointer) Local $sMagic = DllStructGetData($tIMAGE_DOS_HEADER, "Magic") ; Check if it's valid format If Not ($sMagic == "MZ") Then Return SetError(1, 0, 0) ; MS-DOS header missing. Btw 'MZ' are the initials of Mark Zbikowski in case you didn't know. ; Move pointer $pPointer += DllStructGetData($tIMAGE_DOS_HEADER, "AddressOfNewExeHeader") ; move to PE file header ; In place of IMAGE_NT_SIGNATURE structure Local $tIMAGE_NT_SIGNATURE = DllStructCreate("dword Signature", $pPointer) ; Check signature If DllStructGetData($tIMAGE_NT_SIGNATURE, "Signature") <> 17744 Then ; IMAGE_NT_SIGNATURE Return SetError(2, 0, 0) ; wrong signature. For PE image should be "PE\0\0" or 17744 dword. EndIf ; Move pointer $pPointer += 4 ; size of $tIMAGE_NT_SIGNATURE structure ; In place of IMAGE_FILE_HEADER structure ; Move pointer $pPointer += 20 ; size of $tIMAGE_FILE_HEADER structure ; Determine the type Local $tMagic = DllStructCreate("word Magic;", $pPointer) Local $iMagic = DllStructGetData($tMagic, 1) Local $tIMAGE_OPTIONAL_HEADER If $iMagic = 267 Then ; x86 version ; Move pointer $pPointer += 96 ; size of $tIMAGE_OPTIONAL_HEADER ElseIf $iMagic = 523 Then ; x64 version ; Move pointer $pPointer += 112 ; size of $tIMAGE_OPTIONAL_HEADER Else Return SetError(3, 0, 0) ; unsupported module type EndIf ; Validate input by checking available number of structures that are in the module Local Const $IMAGE_NUMBEROF_DIRECTORY_ENTRIES = 16 ; predefined value that PE modules always use (AutoIt certainly) If $iDirectoryEntry > $IMAGE_NUMBEROF_DIRECTORY_ENTRIES - 1 Then Return SetError(4, 0, 0) ; invalid input ; Calculate the offset to wanted entry (every entry is 8 bytes) $pPointer += 8 * $iDirectoryEntry ; At place of correst directory entry Local $tIMAGE_DIRECTORY_ENTRY = DllStructCreate("dword VirtualAddress; dword Size", $pPointer) ; Collect data Local $pAddress = DllStructGetData($tIMAGE_DIRECTORY_ENTRY, "VirtualAddress") If $pAddress = 0 Then Return SetError(5, 0, 0) ; invalid input ; $pAddress is RVA, add it to base address Return $hInstance + $pAddress EndFunc ;==>ImageDirectoryEntryToData ;;;;;;;;;;;;;;START OF FUNCTIONS TAKEN FROM ErrMsgHack;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func GetTrueSourceErrorLine($aOut) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; $sSourceFile=@ScriptName $iErrLineNo=$aOut If CreateRefFile() Then CompileAndRunRefFile() CalculateOffset() Return $iLinesRead EndIf EndFunc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func CreateRefFile() ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Local $sLine="" , $bIncludeFound=False $sSourceFile=StringReplace($sSourceFile, ".exe", ".au3") $sOutFileName="_errormsghack" $fhInput=FileOpen($sSourceFile) $fhOutput=FileOpen($sOutFileName &".au3",2) If $fhInput=-1 Then Return False While True $sLine=FileReadLine($fhInput) If @error=-1 Then ExitLoop $sLine=StringStripWS($sLine,8) If StringLeft($sline,8)="#include" Then FileWriteLine($fhOutput, $sLine) $bIncludeFound=True ElseIf $sline="" Then Else ExitLoop EndIf WEnd If Not $bIncludeFound Then Return False FileWriteLine($fhOutput, "[[[") FileClose($fhOutput) Return True EndFunc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func CompileAndRunRefFile() ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; RunWait(@ProgramFilesDir &"\AutoIt3\Aut2Exe\Aut2exe.exe /in "& $sOutFileName &".au3 /console") Local $childId=Run(@ComSpec & " /c " & $sOutFileName &".exe", "", @SW_HIDE, $STDOUT_CHILD) ProcessWaitClose($childId) $iRefLineNo=StdOutRead($childId) FileDelete($sOutFileName &".au3") FileDelete($sOutFileName &".exe") EndFunc ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Func CalculateOffset() ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Local $iCnt=$iRefLineNo, $bInComment=False, $sLine="" $iLinesRead=0 FileSetPos($fhInput,0,0) While True $sLine=FileReadLine($fhInput) If @error=-1 Then ExitLoop $sLine=StringStripWS($sLine,8) $iLinesRead+=1 $stok=StringLeft($sLine,3) If $stok="#cs" Then $bInComment=True ElseIf $stok="#ce" Then $bInComment=False EndIf If $sLine="" Or StringLeft($sLine,1)="#" Or StringLeft($sLine,1)=";" Or StringRight($sLine, 1)="_" Or $bInComment Then Else If $iCnt=$iErrLineNo Then ExitLoop EndIf $iCnt+=1 EndIf WEnd Which leaves the AvoidErrAu3Error.au3 looking like this: #include <WinApi.au3> #include <StringConstants.au3> #include <AddHookApi.au3> _Example() Func _Example() ; mLipok example Local $aTest[0] ConsoleWrite("! " & $aTest[2] & @CRLF) EndFunc ;==>_Example Just to note I took out the Wrapper directives and added a pragma to force console compile, only because I don’t normally work thru SciTe. Thanks to both you and @trancexx for the ideas!1 point -
May I have some help about Recordset question?
WinMacBear reacted to Musashi for a topic
No, not the script you provide here . Yes.1 point -
Hack that tells you what line# a compiled script actually crashed on...
JockoDundee reacted to mLipok for a topic
I take a look again in this following awesome @trancexx example: and here you go... an CUI example with no AutoIt Erorr MsgBox: ;~ https://www.autoitscript.com/forum/topic/154081-avoid-autoit-error-message-box-in-unknown-errors/?tab=comments#comment-1111917 ;~ https://www.autoitscript.com/forum/topic/204311-hack-that-tells-you-what-line-a-compiled-script-actually-crashed-on/ #AutoIt3Wrapper_Run_Au3Stripper=Y #Au3Stripper_Parameters=/rsln /mo #AutoIt3Wrapper_Change2CUI=Y #include <WinApi.au3> #include <StringConstants.au3> ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; AddHookApi("user32.dll", "MessageBoxW", "Intercept_MessageBoxW", "int", "hwnd;wstr;wstr;uint") _Example() Func _Example() ; mLipok example Local $aTest[0] ConsoleWrite("! " & $aTest[2] & @CRLF) EndFunc ;==>_Example Func Intercept_MessageBoxW($hWnd, $sText, $sTitle, $iType) Local $aOutput = StringRegExp($sText, '(?i)Line\s+(\d+)', $STR_REGEXPARRAYGLOBALMATCH) If @error Then Return ConsoleWrite(@ScriptName & ' - !!! Error occured in line #' & $aOutput[0] & @CRLF) Return ; mLipok mod omnit MsgBox because of CUI=Y Local $aCall = DllCall("user32.dll", "int", "MessageBoxW", _ "hwnd", $hWnd, _ "wstr", $sText, _ "wstr", StringReplace($sTitle, "AutoIt", @ScriptName), _ "uint", $iType) If @error Or Not $aCall[0] Then Return 0 Return $aCall[0] EndFunc ;==>Intercept_MessageBoxW ; The magic is down below Func AddHookApi($sModuleName, $vFunctionName, $vNewFunction, $sRet = "", $sParams = "") Local Static $pImportDirectory, $hInstance Local Const $IMAGE_DIRECTORY_ENTRY_IMPORT = 1 If Not $pImportDirectory Then $hInstance = _WinAPI_GetModuleHandle(0) $pImportDirectory = ImageDirectoryEntryToData($hInstance, $IMAGE_DIRECTORY_ENTRY_IMPORT) If @error Then Return SetError(1, 0, 0) EndIf Local $iIsInt = IsInt($vFunctionName) Local $iRestore = Not IsString($vNewFunction) Local $tIMAGE_IMPORT_MODULE_DIRECTORY Local $pDirectoryOffset = $pImportDirectory Local $tModuleName Local $iInitialOffset, $iInitialOffset2 Local $iOffset2 Local $tBufferOffset2, $iBufferOffset2 Local $tBuffer, $tFunctionOffset, $pOld, $fMatch, $pModuleName, $pFuncName Local Const $PAGE_READWRITE = 0x04 While 1 $tIMAGE_IMPORT_MODULE_DIRECTORY = DllStructCreate("dword RVAOriginalFirstThunk;" & _ "dword TimeDateStamp;" & _ "dword ForwarderChain;" & _ "dword RVAModuleName;" & _ "dword RVAFirstThunk", _ $pDirectoryOffset) If Not DllStructGetData($tIMAGE_IMPORT_MODULE_DIRECTORY, "RVAFirstThunk") Then ExitLoop $pModuleName = $hInstance + DllStructGetData($tIMAGE_IMPORT_MODULE_DIRECTORY, "RVAModuleName") $tModuleName = DllStructCreate("char Name[" & _WinAPI_StringLenA($pModuleName) & "]", $pModuleName) If DllStructGetData($tModuleName, "Name") = $sModuleName Then ; function from this module $iInitialOffset = $hInstance + DllStructGetData($tIMAGE_IMPORT_MODULE_DIRECTORY, "RVAFirstThunk") $iInitialOffset2 = $hInstance + DllStructGetData($tIMAGE_IMPORT_MODULE_DIRECTORY, "RVAOriginalFirstThunk") If $iInitialOffset2 = $hInstance Then $iInitialOffset2 = $iInitialOffset $iOffset2 = 0 While 1 $tBufferOffset2 = DllStructCreate("dword_ptr", $iInitialOffset2 + $iOffset2) $iBufferOffset2 = DllStructGetData($tBufferOffset2, 1) If Not $iBufferOffset2 Then ExitLoop If $iIsInt Then If BitAND($iBufferOffset2, 0xFFFFFF) = $vFunctionName Then $fMatch = True ; wanted function Else $pFuncName = $hInstance + $iBufferOffset2 + 2 ; 2 is size od "word", see line below... $tBuffer = DllStructCreate("word Ordinal; char Name[" & _WinAPI_StringLenA($pFuncName) & "]", $hInstance + $iBufferOffset2) If DllStructGetData($tBuffer, "Name") == $vFunctionName Then $fMatch = True ; wanted function EndIf If $fMatch Then $tFunctionOffset = DllStructCreate("ptr", $iInitialOffset + $iOffset2) VirtualProtect(DllStructGetPtr($tFunctionOffset), DllStructGetSize($tFunctionOffset), $PAGE_READWRITE) If @error Then Return SetError(3, 0, 0) $pOld = DllStructGetData($tFunctionOffset, 1) If $iRestore Then DllStructSetData($tFunctionOffset, 1, $vNewFunction) Else DllStructSetData($tFunctionOffset, 1, DllCallbackGetPtr(DllCallbackRegister($vNewFunction, $sRet, $sParams))) EndIf Return $pOld EndIf $iOffset2 += DllStructGetSize($tBufferOffset2) WEnd ExitLoop EndIf $pDirectoryOffset += 20 ; size of $tIMAGE_IMPORT_MODULE_DIRECTORY WEnd Return SetError(4, 0, 0) EndFunc ;==>AddHookApi Func VirtualProtect($pAddress, $iSize, $iProtection) Local $aCall = DllCall("kernel32.dll", "bool", "VirtualProtect", "ptr", $pAddress, "dword_ptr", $iSize, "dword", $iProtection, "dword*", 0) If @error Or Not $aCall[0] Then Return SetError(1, 0, 0) Return 1 EndFunc ;==>VirtualProtect Func ImageDirectoryEntryToData($hInstance, $iDirectoryEntry) ; Get pointer to data Local $pPointer = $hInstance ; Start processing passed binary data. 'Reading' PE format follows. Local $tIMAGE_DOS_HEADER = DllStructCreate("char Magic[2];" & _ "word BytesOnLastPage;" & _ "word Pages;" & _ "word Relocations;" & _ "word SizeofHeader;" & _ "word MinimumExtra;" & _ "word MaximumExtra;" & _ "word SS;" & _ "word SP;" & _ "word Checksum;" & _ "word IP;" & _ "word CS;" & _ "word Relocation;" & _ "word Overlay;" & _ "char Reserved[8];" & _ "word OEMIdentifier;" & _ "word OEMInformation;" & _ "char Reserved2[20];" & _ "dword AddressOfNewExeHeader", _ $pPointer) Local $sMagic = DllStructGetData($tIMAGE_DOS_HEADER, "Magic") ; Check if it's valid format If Not ($sMagic == "MZ") Then Return SetError(1, 0, 0) ; MS-DOS header missing. Btw 'MZ' are the initials of Mark Zbikowski in case you didn't know. ; Move pointer $pPointer += DllStructGetData($tIMAGE_DOS_HEADER, "AddressOfNewExeHeader") ; move to PE file header ; In place of IMAGE_NT_SIGNATURE structure Local $tIMAGE_NT_SIGNATURE = DllStructCreate("dword Signature", $pPointer) ; Check signature If DllStructGetData($tIMAGE_NT_SIGNATURE, "Signature") <> 17744 Then ; IMAGE_NT_SIGNATURE Return SetError(2, 0, 0) ; wrong signature. For PE image should be "PE\0\0" or 17744 dword. EndIf ; Move pointer $pPointer += 4 ; size of $tIMAGE_NT_SIGNATURE structure ; In place of IMAGE_FILE_HEADER structure ; Move pointer $pPointer += 20 ; size of $tIMAGE_FILE_HEADER structure ; Determine the type Local $tMagic = DllStructCreate("word Magic;", $pPointer) Local $iMagic = DllStructGetData($tMagic, 1) Local $tIMAGE_OPTIONAL_HEADER If $iMagic = 267 Then ; x86 version ; Move pointer $pPointer += 96 ; size of $tIMAGE_OPTIONAL_HEADER ElseIf $iMagic = 523 Then ; x64 version ; Move pointer $pPointer += 112 ; size of $tIMAGE_OPTIONAL_HEADER Else Return SetError(3, 0, 0) ; unsupported module type EndIf ; Validate input by checking available number of structures that are in the module Local Const $IMAGE_NUMBEROF_DIRECTORY_ENTRIES = 16 ; predefined value that PE modules always use (AutoIt certainly) If $iDirectoryEntry > $IMAGE_NUMBEROF_DIRECTORY_ENTRIES - 1 Then Return SetError(4, 0, 0) ; invalid input ; Calculate the offset to wanted entry (every entry is 8 bytes) $pPointer += 8 * $iDirectoryEntry ; At place of correst directory entry Local $tIMAGE_DIRECTORY_ENTRY = DllStructCreate("dword VirtualAddress; dword Size", $pPointer) ; Collect data Local $pAddress = DllStructGetData($tIMAGE_DIRECTORY_ENTRY, "VirtualAddress") If $pAddress = 0 Then Return SetError(5, 0, 0) ; invalid input ; $pAddress is RVA, add it to base address Return $hInstance + $pAddress EndFunc ;==>ImageDirectoryEntryToData1 point -
Hi Paul, Long explanation coming Your comments can be explained, because _ArrayDisplay always uses a comparison type based on Windows API StrCmpLogical, as you can see in the help file, topic _GUICtrlListView_RegisterSortCallBack, where the 2nd parameter (= 2) means "Use Windows API StrCmpLogical" This corresponds to line #448 in ArrayDisplayInternals.au3 (version 3.3.14.5) __ArrayDisplay_RegisterSortCallBack($idListView, 2, True, "__ArrayDisplay_SortCallBack") When this 2nd parameter = 2, then the sort isn't done in a pure alphabetically (ascii) way because "Digits in the strings are considered as numerical content rather than text", as explained on the MSDN web page. A note from Wikipedia concerning this "natural sort" : Natural sort order is an ordering of strings in alphabetical order, except that multi-digit numbers are treated atomically, i.e., as if they were a single character. Natural sort order has been promoted as being more human-friendly ("natural") than the machine-oriented pure alphabetical order. It could explain why, in your very last diagram, when the 1st character in col1 is a digit (0 for all rows), then "01" means 1, "02" => 2, "03" => 3, while "0A" and "0B" equal to 0 (because their 1st 0 is not followed by a digit), which could explain why "0A" and "0B" are placed on the 1st two lines, in an ascending sort using StrCmpLogical Your other column (col0) doesn't have the same character at 1st place but a simple "1", "2", "3", "A", "B" In this case, I guess that StrCmpLogical immediately sorts the letters after the numbers when the sort is ascending, after comparing for example "3" to "A" and finding that the ascii code for "A" is higher than the ascii code for "3", which will result in an ascending sort like this : 1 - 2 - 3 - A - B So it seems that both columns have their contents treated very differently, depending on the fact that a digit is found or not... at least this is the only explanation I can find. If anyone could confirm or disprove this explanation, please do not hesitate, thanks I find it hard to solve your issue, because changing permanently the 2nd parameter in line #448 (from 2 to 0, meaning you want a pure String comparison) will solve your case... but will bring issues when you have numerals to compare. Same if you change it permanently from 2 to 1 ("String treated as number") The only (bad) way I found to sort correctly your pointers & handles (or any hex number starting with 0x) in your 1st diagram is : * Line 448 : 2nd parameter = 1 (String treated as number) * Lines 596 to 600, added a test on "0x" : If $__g_aArrayDisplay_SortInfo[8] = 1 Then ; force Treat as Number if possible If StringIsFloat($sVal1) Or StringIsInt($sVal1) Or StringLeft($sVal1, 2) = "0x" Then $sVal1 = Number($sVal1) If StringIsFloat($sVal2) Or StringIsInt($sVal2) Or StringLeft($sVal2, 2) = "0x" Then $sVal2 = Number($sVal2) EndIf Then an array like this one... Global $aSortTest[6][1] = [["0x0B"], ["0x020"], ["0x0C"], ["0x03"], ["0x01"], ["0x0A"]] ...would correctly be sorted (ascending) This is the reason why, in my CSV file editor, a choice is given to the user, before each sort (by right-clicking a header column) so the user chooses the kind of sort he wants, instead of being stuck with a "forced" way of sorting : This required of course to register the sort, do the sort, then unregister it each time the user wants to sort, no big deal. So, if this is really important to you, I guess you'll have to tweak a bit your own version of ArrayDisplayInternals.au3 Good luck1 point
-
Thanks for your commitment @caramen I appreciate that but I tried that earlier. What seems to work in my case is the batch file with the code for /f "skip=1 tokens=3" %%s in ('query user %USERNAME%') do (tscon.exe %%s /dest:console) I created a batch file and then created a desktop shortcut with that batch file since I changed the rights to run the program under the tab "advanced" (so I can run with admin rights). It kicked me out of the RDP (as it should) and now it's displaying the GUI on the disconnected RDP for the bot/program which is needed. Thanks again everyone who tried to help me! Thread can be closed @Melba231 point
-
Autoit-DD
mLipok reacted to tarretarretarre for a file
Version 1.0.0
449 downloads
About AutoIt-DD AutoIt-DD is an carbon copy of Laravels dd helper. DD stands for "Dump and DIE" and is a great tool for debugging AutoIt variables Features Get useful information about any AutoIt variable Nested Arrays and Scripting dictionaries Multi DIM arrays Great structure and colored output Example In Example.au3 you can run a fully featured example, but I also provided a print screen for you lazy people1 point -
_AutoItErrorTrap.zip
mLipok reacted to argumentum for a file
1 point -
1 point
-
_IsHex() - Checks if a string is a hexadecimal value.
pixelsearch reacted to guinness for a topic
Checks if a string is hexadecimal. Function and Example: #include <MsgBoxConstants.au3> MsgBox($MB_SYSTEMMODAL, '', '0xFFFF00: ' & _IsHex('0xFFFF00')) MsgBox($MB_SYSTEMMODAL, '', '0XGHXX190: ' & _IsHex('0XGHXX190')) ; #FUNCTION# ==================================================================================================================== ; Name ..........: _IsHex ; Description ...: Checks if a string is a hexadecimal value. ; Syntax ........: _IsHex($sString) ; Parameters ....: $sString - A hexadecimal string. ; Return values .: Success - True ; Failure - False ; Author ........: guinness ; Example .......: Yes ; =============================================================================================================================== Func _IsHex($sString) Return StringRegExp($sString, '^0x[[:xdigit:]]+$') > 0 ; Or the class [0-9A-Za-z]. EndFunc ;==>_IsHex1 point