Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Question| Interrupt Hooking

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Zerith
Master Cheater
Reputation: 1

Joined: 07 Oct 2007
Posts: 468

PostPosted: Fri Jan 30, 2009 8:36 am    Post subject: Question| Interrupt Hooking Reply with quote

Hello, i'm trying to hook interrupts, and for some reason it doesn't work.
Here's my code:
http://pastebin.com/m33877ede

Output:
Code:

MyKbdRoutine: 0xF8ABC4C0
Original: int15_entry: 0x80543A50
New:      int15_entry: 0xF8ABC4C0
Unhooked: int15_entry: 0x80543A50
Unhooking Successful!


The original handler is being overwritten with my function according to the output.
I tried pressing keys but nothing was outputted.

so i tried to change KEYBOARD_INT to 21 (For int 21h), and i got 0x0000000 as it's handler.

Why am i getting an invalid address for INT 21 handler?
Is there a problem with my code?

Thank you for your help.
Why am i getting an invalid address when changing to 21?
Back to top
View user's profile Send private message MSN Messenger
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Fri Jan 30, 2009 6:57 pm    Post subject: Reply with quote

So... why are you calling any sort of Windows API inside an interrupt handler again? Death wish?
Back to top
View user's profile Send private message
Zerith
Master Cheater
Reputation: 1

Joined: 07 Oct 2007
Posts: 468

PostPosted: Sat Jan 31, 2009 12:01 am    Post subject: Reply with quote

Flyte wrote:
So... why are you calling any sort of Windows API inside an interrupt handler again? Death wish?


That though is irrelevant, since my handler isn't even being called.
I think i am getting the wrong address of the real handler, any suggestions?
Back to top
View user's profile Send private message MSN Messenger
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Sat Jan 31, 2009 12:08 am    Post subject: Reply with quote

Zerith wrote:
Flyte wrote:
So... why are you calling any sort of Windows API inside an interrupt handler again? Death wish?


That though is irrelevant, since my handler isn't even being called.
I think i am getting the wrong address of the real handler, any suggestions?


I bet you are running it on a multi-core processor. Wink

Oh, and I said that because in your code you commented that you BSOD'd when you called in yourself. My previous post is why.
Back to top
View user's profile Send private message
Zerith
Master Cheater
Reputation: 1

Joined: 07 Oct 2007
Posts: 468

PostPosted: Sat Jan 31, 2009 12:10 am    Post subject: Reply with quote

Flyte wrote:
Zerith wrote:
Flyte wrote:
So... why are you calling any sort of Windows API inside an interrupt handler again? Death wish?


That though is irrelevant, since my handler isn't even being called.
I think i am getting the wrong address of the real handler, any suggestions?


I bet you are running it on a multi-core processor. Wink

Oh, and I said that because in your code you commented that you BSOD'd when you called in yourself. My previous post is why.


Ahh, i know you need to hook both IDTs for a multi-core processor, but i have one processor.
sadly that isn't the problem.
Alright, i'll try removing the dbgprint and calling it. i'll come back with results in a minute.
Back to top
View user's profile Send private message MSN Messenger
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Sat Jan 31, 2009 12:16 am    Post subject: Reply with quote

Also, you didn't fix the stack after you were done. Assuming that when you declare a variable in a function with the __declspec(naked) attribute only allocates it and doesn't fix the stack itself. I've actually never checked (always done everything in ASM in naked functions).
Back to top
View user's profile Send private message
Zerith
Master Cheater
Reputation: 1

Joined: 07 Oct 2007
Posts: 468

PostPosted: Sat Jan 31, 2009 12:24 am    Post subject: Reply with quote

Alright, i tried removing everything but the jmp to the original handler.
I called INT 15, and crashed. Confused
Back to top
View user's profile Send private message MSN Messenger
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Sat Jan 31, 2009 12:47 am    Post subject: Reply with quote

Zerith wrote:
Alright, i tried removing everything but the jmp to the original handler.
I called INT 15, and crashed. Confused


Well, I don't have a DDK installed on this machine, so I can't do any testing with it. However, if memory serves me correctly:

Code:
#pragma pack(1)
typedef struct
{
     WORD LowOffset;
     WORD selector;
     BYTE unused_lo;
     unsigned char unused_hi:5;
     unsigned char DPL:2;
     unsigned char P:1;
     WORD HiOffset;
} IDTENTRY;
#pragma pack()


Should be:

Code:
typedef struct {
  WORD    Low;     
  WORD    Selector;       
  WORD    Garbage;
  WORD    T:5;
  WORD    DPL:2;
  WORD    P:1;
  WORD    High;   
} IDTENTRY;
Back to top
View user's profile Send private message
Zerith
Master Cheater
Reputation: 1

Joined: 07 Oct 2007
Posts: 468

PostPosted: Sat Jan 31, 2009 12:52 am    Post subject: Reply with quote

Hmm no, as i have seen a couple of times on the net, the struct is as i declared it.

Like in:
http://www.viralpatel.net/taj/tutorial/idt.php
Back to top
View user's profile Send private message MSN Messenger
BanMe
Master Cheater
Reputation: 0

Joined: 29 Nov 2005
Posts: 375
Location: Farmington NH, USA

PostPosted: Sat Jan 31, 2009 10:09 am    Post subject: Reply with quote

DbgPrint is exported by the kernel no need to worry about that api....
you should keep the DbgPrints and at Key Locations where you think bsod is happening use KeDelayExecutionThread to see where it actualy gets to.
my thought being is the crash is that you are installing the handler the wrong way..(i went over your code, and it should be entirely workable) (hopefully)

Regards BanMe
Back to top
View user's profile Send private message MSN Messenger
Zerith
Master Cheater
Reputation: 1

Joined: 07 Oct 2007
Posts: 468

PostPosted: Sat Jan 31, 2009 10:39 am    Post subject: Reply with quote

I'm crashing when calling INT 15, if i remove that line i get no BSODs.

But nothing calls my handler.
Back to top
View user's profile Send private message MSN Messenger
BanMe
Master Cheater
Reputation: 0

Joined: 29 Nov 2005
Posts: 375
Location: Farmington NH, USA

PostPosted: Sat Jan 31, 2009 11:23 am    Post subject: Reply with quote

try just __asm int15;
instead of far jmping to the handler address Smile
Back to top
View user's profile Send private message MSN Messenger
Zerith
Master Cheater
Reputation: 1

Joined: 07 Oct 2007
Posts: 468

PostPosted: Sat Jan 31, 2009 11:31 am    Post subject: Reply with quote

BanMe wrote:
try just __asm int15;
instead of far jmping to the handler address Smile


You didn't read my post and obviously not my code either.
I did try using INT 15. and crashed.
Back to top
View user's profile Send private message MSN Messenger
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Sat Jan 31, 2009 2:31 pm    Post subject: Reply with quote

Zerith wrote:
Hmm no, as i have seen a couple of times on the net, the struct is as i declared it.

Like in:
http://www.viralpatel.net/taj/tutorial/idt.php


I'm quite sure this is the correct structure (small difference from the one I posted above).

Code:
typedef struct {
  WORD    Low;     
  WORD    Selector;       
  WORD    Garbage:8;
  WORD    T:5;
  WORD    DPL:2;
  WORD    P:1;
  WORD    High;   
} IDTENTRY;


Honestly, whoever wrote the other structure must of been on drugs. It makes no sense to have unused_lo be 8 bits, and unused_hi be 5. My structure may be wrong, as I'm working off of memory, but I doubt it (it shouldn't make any difference in the long run, as they are both the same size; it's just for clarity purposes).

I'm also sure that you don't need to deal with hi/lo words in the IDTINFO struct, this should be sufficient:

Code:
typedef struct {
   WORD IDTLimit;
   DWORD IDTBase;
} IDTINFO;


Again, I may wrong since I'm working off of memory, but as usual I doubt it. Razz
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites