Jump to content

API Hooking in AutoIt


monoceres
 Share

Recommended Posts

@monoceres

Can you weigh in on this?

http://www.autoitscript.com/forum/index.ph...st&p=613011

I've got the same problem on Vista - the callback is not being called from a compiled script.

EDIT - last minute thought, and I was right. UPX is breaking it. Any ideas why this is? Are the function addresses and such being mangled by the runtime decompression?

Edited by wraithdu
Link to comment
Share on other sites

  • Replies 60
  • Created
  • Last Reply

Top Posters In This Topic

  • 3 weeks later...

@monoceres

I need your help, about hook back.

http://www.autoitscript.com/forum/index.ph...st&p=622307

; Add the hook and save the "handle" to the hook, we need this to change the hook later on
global $regptr = DllCallbackRegister( "_ApiHookLog" , "int" , "ptr" )
global $hook = _ApiHookAdd( "Shell32.dll" , "ShellExecuteExW" , $regptr )

;; Lets try ShellExecute something
ShellExecute( FileOpenDialog( "All files", "" , "All files (*.*)" ) )

; Change back to the original ShellExecute
_ApiHookDel( $hook )


Func _ApiHookLog( $ptr )
; SHELLEXECUTEINFO struct
    Local $SHELLEXECUTEINFO = DllStructCreate( "dword;ulong;hwnd;ptr;ptr;ptr;ptr;int;ptr;ptr;ptr;ptr;dword;ptr;ptr;" , $ptr )

    Local $wstring = DllStructCreate( "wchar[255]" , DllStructGetData( $SHELLEXECUTEINFO , 5 ) )

    Local $confirm = MsgBox( 0x1 , "Shellexecute hook" , "AutoIt tried to shellexecute: " & DllStructGetData( $wstring , 1 ) & @CRLF & "Allow this?" )

    If $confirm Then
 ;Referred <= Dim $return[4] = [ $itd , $callBackReg , $orig , $NewProcAddress ]

        DllStructSetData( $hook[0] , 1 , $hook[2] )

        DllCallbackFree( $regptr )

        $regptr = DllCallbackRegister( "_ApiHookLog" , "int" , "ptr" )

        $hook[1] = $regptr

        DllStructSetData( $hook[0] , 1 , $hook[3] )
    EndIf

    $wstring = 0
    $SHELLEXECUTEINFO = 0

    Return 0
EndFunc

Is this just a simple level, the only possible example apihook as Hook/Unhook except 'hook forwading'?

Edited by GoodMan
Link to comment
Share on other sites

You have to save the old func-pointer (getprocAddres) and then use MemoryDllCall or write your own code with CallWindowProc :)

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

For API-hooks it's not possible to use these functions.

But if you can use SetWindowsHookEx instead of API-Hook, it would be better to do so.

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

For API-hooks it's not possible to use these functions.

But if you can use SetWindowsHookEx instead of API-Hook, it would be better to do so.

This sample just shown like 'can not get back across the bridge'?

0xSOME JMP SHORT 0xHOOK

0xHOOK You can not return to 0xSOME, this is just 'JMP'. If you want to 'CallBack', fill this line by some CallBack routine.

Ok. Let's try ...

Thanks.

Link to comment
Share on other sites

  • 1 month later...

hey mate! thanks for this! Thgis is a great script for learning.. You say that you cant hook other processes addresses with just autoit code, like say if I wanted to hook an address in wow.exe while its running... and since autoit can handle anything(for the msot part) thats in a Dll, I could write a dll, in C++ that hooks a certain address and use DllCall() to call that function from the C++ dll with my autoit handler... Is this correct? because Im thinking of using a an Api hook in my telebot... Let me know... Ive taken C++ class last year mate so im sure i could make the dll... just need to know if I could use autoit to handle the functions and call them... Thanks agaion mate

*WoW Dev Projects: AFK Tele Bot development journalSimple Player Pointer Scanner + Z-Teleport*My Projects: coming soon.Check out my WoW Dev wiki for patch 3.0.9!http://www.wowdev.wikidot.com

Link to comment
Share on other sites

the dll can be injected as we already seen in another post

to make this dll communicate with other programs, see IPC.

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]
Link to comment
Share on other sites

hey mate! thanks for this! Thgis is a great script for learning.. You say that you cant hook other processes addresses with just autoit code, like say if I wanted to hook an address in wow.exe while its running... and since autoit can handle anything(for the msot part) thats in a Dll, I could write a dll, in C++ that hooks a certain address and use DllCall() to call that function from the C++ dll with my autoit handler... Is this correct? because Im thinking of using a an Api hook in my telebot... Let me know... Ive taken C++ class last year mate so im sure i could make the dll... just need to know if I could use autoit to handle the functions and call them... Thanks agaion mate

wraithdu has made a wonderful job for this in this topic:

http://www.autoitscript.com/forum/index.ph...c=87240&hl=

:)

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

hey thanks mate! That helps alot...Im doing some testing since im pretty sure theres no why for autoit to support sending packets with only autoit native code, but only through a C++ Dll or anouther power language... but Im thinking of hooking a function by its address in game to make my speed faster...The faster the speed the faster the teleport :) thanks again mate

*WoW Dev Projects: AFK Tele Bot development journalSimple Player Pointer Scanner + Z-Teleport*My Projects: coming soon.Check out my WoW Dev wiki for patch 3.0.9!http://www.wowdev.wikidot.com

Link to comment
Share on other sites

  • 8 months later...

Ok, I'm a little confused. Am I restricted to using windows API DLLs?

I have a function in a c++ dll that takes a number and returns the number * 2.

double testFunc( int testVar ) 
{
    int newTestVar = testVar*2;
 return newTestVar;
}

What I'd like to do is reroute the function to an AutoIt script, that returned the number * 4, whenever this function was called by its original process.

Is that what this UDF does, or does it only work for functions that AutoIt calls?

The pic should explain better than I can in words.

Link to comment
Share on other sites

Is the Original Program an exe? If so, then you need, to read that little faq I wrote at the beginning of this topic. API Hooking is only supported in our address space. Trying to monitor what other processes do is not possible without injecting code into that process.

It doesn't matter if you hook the dll loaded in your address space. The original application will load its own version of the dll. Unhooked. And even if it didn't processes are bound to their own address space, it's not possible to transfer control between processes. Processes are on their own.

What you're trying to achieve is pretty easy with the help of some work by trancexx, I have uploaded and described the process here, it's almost exactly what you wanna do. However Rest assured you will not be able to do this in autoit (without the machinecode voodoo as you cleverly described it). Running you code inside the application is not optional.

Hit me an pm if you're not getting it to work. I can help you further on an IM service or something.

Edited by monoceres

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

  • 6 months later...
  • 1 year later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...