Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include-once
- ; #INDEX# =======================================================================================================================
- ; Title .........: AutoIt SEH
- ; AutoIt Version : 3.3.12.0 (x86)
- ; Description ...: Enables compiled script to gain control when events that normally terminate program execution occur.
- ; Version .......: 0.3.3 (beta)
- ; Author(s) .....: Firex
- ; Dll(s) ........: Kernel32.dll
- ; ===============================================================================================================================
- ; #CURRENT# =====================================================================================================================
- ; __TRY
- ; __ENDTRY
- ; ===============================================================================================================================
- ; #VARIABLES# ===================================================================================================================
- Global $__Au3SehCb[2]
- Global $__Au3SehBak[9]
- Global $SEH_INCLUDES_LENGTH
- ; ===============================================================================================================================
- ; #EXAMPLE# =====================================================================================================================
- ;~#Include <SEH.au3>
- ;~
- ;~__TRY() ;Default: "__EXCEPT"
- ;~ MsgBox( 0, 'SEH - Example', 'Init' )
- ;~ For $Idx = 1 To 5 Step 1
- ;~ If Random( 0, 1, 1 ) Then
- ;~ $PlsError[1] = $PlsError[2]
- ;~ Else
- ;~ Local $PlsError[-1] = [[]] ;goto not work for this type of error, i will fix it
- ;~ EndIf
- ;~ Next
- ;~ If 1 == 0 Then
- ;~ MsgBox( 0, 'SEH - Example', 'Goto?' ) ;11 line
- ;~ EndIf
- ;~__ENDTRY()
- ;~
- ;~Func __EXCEPT( $pwErr, $pwScriptLine, $iLine )
- ;~ MsgBox( 0, '', _
- ;~ '$iLine=' & $iLine - $SEH_INCLUDES_LENGTH & @LF & _
- ;~ '$pScriptLine=' & __wCharArray( $pwScriptLine ) & @LF & _
- ;~ '$pErrMsg=' & __wCharArray( $pwErr ) )
- ;~ ; ---
- ;~ Return $SEH_INCLUDES_LENGTH + 11 ;[goto 11 line]
- ;~ ;Change to:
- ;~ ;RET==0 : [ignore]
- ;~ ;RET<<0 : [terminate]
- ;~ ;RET>>0 : [goto_line]
- ;~EndFunc
- ;~
- ;~Func __wCharArray( $pwStr )
- ;~ Local $aRes, $tStr
- ;~ ; ---
- ;~ $aRes = DllCall("kernel32.dll", "int", "lstrlenW", "ptr", $pwStr)
- ;~ If @Error Or Not $aRes[0] Then _
- ;~ Return ''
- ;~
- ;~ $tStr = DllStructCreate( "wchar[" & $aRes[0] & "]", $pwStr )
- ;~ If @Error Then _
- ;~ Return ''
- ;~ ; ---
- ;~ Return DllStructGetData( $tStr, 1 )
- ;~EndFunc
- ; ===============================================================================================================================
- ; #FUNCTION# ====================================================================================================================
- ; Author ........: Firex
- ; Modified.......:
- ; ===============================================================================================================================
- Func __TRY( $sFunc = '__EXCEPT' )
- If Not IsDeclared( "__Au3SehCb" ) Then _
- Global $__Au3SehCb[2]
- If ( Not $__Au3SehCb[0] ) <> ( $sFunc <> '' ) Then _
- Return SetError( -1 )
- ; *
- Local $aLib[2][9][3] = [ [ [1] ], _ ;* - ptr32
- [ _
- [ '0_3.3.12.0', 0x0004CD69, 0x0004CDD5 ], _
- [ '#A_', '0BA2FBFF', '927FFBFF' ], _ ;__GetScriptLineByNum
- [ 0x00, '0x743C' ], _
- [ 0x20, '0xEB1C' ], _
- [ 0x1E, '0x8B97F400000052E8#A_5250FF75BCB8*FFD083F8007C11744189EA8B12837A0C0075F8894208EB3231C04080BF1C010000008987FC00000074088B45080500F0FF7F8D4DDCE9C8FDFFFF' ] _
- ] _
- ], _
- $Ver, $Vkp, $Const, $sDyn, $aRes, $hModule, $pOffset, $bVkp_Cur, $iVkp_Sz, $tPatch
- ; ---
- $aRes = DllCall( "kernel32.dll", "handle", "GetModuleHandle", "ptr", 0 )
- If @Error Or Not $aRes[0] Then Return SetError( -2 )
- $hModule = $aRes[0]
- For $Ver = 1 To $aLib[0][0][0] Step 1
- If ( @AutoItX64 & "_" & @AutoItVersion ) <> $aLib[$Ver][0][0] Then _
- ContinueLoop
- ; *
- $pOffset = $hModule + Ptr( $aLib[$Ver][0][1+@Compiled] )
- If Not $__Au3SehCb[0] Then
- $__Au3SehCb[0] = DllCallbackRegister( $sFunc, 'int', 'ptr;ptr;ulong' )
- If Not $__Au3SehCb[0] Then _
- Return SetError( -3 )
- ; -
- $__Au3SehCb[1] = Hex( Binary( DllCallbackGetPtr( $__Au3SehCb[0] ) ) )
- $__Au3SehCb[1] = StringLeft( $__Au3SehCb[1], 8 ) ;Fix for x64 (qdword=4 byte)
- If Not IsDeclared( '__Au3SehBak' ) Then _
- Global $__Au3SehBak[9]
- Else
- $__Au3SehCb[1] = 0
- EndIf
- For $Vkp = 1 To 8 Step 1
- $sDyn = $aLib[$Ver][$Vkp][0]
- Select ;Preproc vkp
- Case $sDyn == ''
- If Not $__Au3SehCb[1] Then
- DllCallbackFree( $__Au3SehCb[0] )
- $__Au3SehCb[0] = 0
- EndIf
- ExitLoop
- Case IsString( $sDyn )
- For $Const = $Vkp To 8 Step 1
- If $aLib[$Ver][$Const][1] == '' Then _
- ExitLoop
- ; -
- $aLib[$Ver][$Const][1] = StringReplace( $aLib[$Ver][$Const][1], $sDyn, $aLib[$Ver][$Vkp][1+@Compiled] )
- Next
- ContinueLoop
- EndSelect
- ; -
- $pOffset += Ptr( $sDyn )
- $bVkp_Cur = $aLib[$Ver][$Vkp][1]
- $iVkp_Sz = BinaryLen( StringReplace( $bVkp_Cur, '*', '00000000' ) )
- ; < Replace opcode region
- $aRes = DllCall( "kernel32.dll", "bool", "VirtualProtect", "ptr", $pOffset, "ulong", $iVkp_Sz, "dword", 0x40, "dword*", "" )
- If @Error Or Not $aRes[0] Then _
- ExitLoop 2
- $tPatch = DllStructCreate( "byte Code[" & $iVkp_Sz & "]", $pOffset )
- If $__Au3SehCb[1] Then
- If Not $__Au3SehBak[$Vkp] Then _
- $__Au3SehBak[$Vkp] = DllStructGetData( $tPatch, 'Code' ) ;Save opcode
- ; -
- DllStructSetData( $tPatch, 'Code', StringReplace( $bVkp_Cur, '*', $__Au3SehCb[1] ) )
- Else
- DllStructSetData( $tPatch, 'Code', $__Au3SehBak[$Vkp] ) ;Restore opcode
- EndIf
- DllCall( "kernel32.dll", "bool", "VirtualProtect", "ptr", $pOffset, "ulong", $iVkp_Sz, "dword", $aRes[4], "ptr", 0 )
- ; < Replace opcode endregion
- Next
- ; -
- Return True
- Next
- ; ---
- Return False
- EndFunc
- ; #FUNCTION# ====================================================================================================================
- ; Author ........: Firex
- ; Modified.......:
- ; ===============================================================================================================================
- Func __ENDTRY()
- Return __TRY('')
- EndFunc
- ; #INTERLAN_USE_ONLY# ====================================================================================================================
- ; Description ...: Calculate real line number
- ; ========================================================================================================================================
- Func __SEH_InternalCb( $pwErr, $pwScriptLine, $iLine )
- If Not IsDeclared( 'SEH_INCLUDES_LENGTH' ) Then _
- Global $SEH_INCLUDES_LENGTH
- $SEH_INCLUDES_LENGTH = $iLine + 4
- Return 0
- EndFunc
- Func __SEH_GetIncludesLength()
- If __TRY( '__SEH_InternalCb' ) Then
- SEH_GetError
- __ENDTRY()
- EndIf
- EndFunc
- __SEH_GetIncludesLength()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement