logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Mad Code Hook replacement

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Development
View previous topic :: View next topic  
Author Message
chaoslink



Joined: 23 Aug 2006
Posts: 37

PostPosted: Tue Aug 29, 2006 0:56    Post subject: Mad Code Hook replacement Reply with quote

This really belongs in both the Windows and Linux development forums, but I didn't want to double-post.

Last week I posted in the wish list a fairly whiney bit about portable code. This time I've begun to put my money where my mouth is.

After a search of utilities that provide the same function as Mad Code Hook, but were portable or at least exposed similar interfaces, I came up empty-handed.

However, Microsoft's Detours API particularly caught my attention. I've modified a subset of their code to compile under windows and linux and provide detour/trampoline functionality.

What all does this provide?
First, it reduces the amount of NWNX code which must be divergent between Windows and Linux platforms. My goal is to create one source tree which uses preprocessor macros to select the (minimal) divergent code. The less duplicate code, the less effort required to create new functionality and less places for error to be introduced in copying.

Second, and very importantly, it requires NO assembly code in NWNX itself (only in the detours code). This rids us of specific assembly to correctly call the original function after the hook has been executed.

I'm going to continue working on this - I will probably implement all the items I put in my wishlist post and provide my code for public consumption. Do with that what you will, but when it is ready my PW will sure be using it Very Happy
Back to top
View user's profile Send private message
chaoslink



Joined: 23 Aug 2006
Posts: 37

PostPosted: Tue Aug 29, 2006 1:08    Post subject: Reply with quote

If anyone has compiled a list of function signatures so that I can add hooking for all known (useful) functions for both windows and linux, could you please link below?

Otherwise, I'd like help in compiling such a list.
Back to top
View user's profile Send private message
chaoslink



Joined: 23 Aug 2006
Posts: 37

PostPosted: Mon Jun 25, 2007 19:54    Post subject: Reply with quote

Finally making progress on this. I've got a codebase which compiles under both windows and linux. I'm getting some runtime errors with the windows version, but I am able to hook using code pulled from Detours on both platforms. More to come when I get something releasable.
Back to top
View user's profile Send private message
Papillon
x-man


Joined: 28 Dec 2004
Posts: 1060
Location: Germany

PostPosted: Tue Jun 26, 2007 0:09    Post subject: Reply with quote

I am having troubles with my own madcodehook replacement. The problem I am having is, that I managed to load my NWNX DLL into the NWNServer process space, but I could not call any API functions in DLLMain afterwards (probably because of the loader lock the DLL loading mechanism sets up), so I can not setup DDE communications as well.

I haven't worked on this topic for a couple of weeks, so this is just from the top of my head.
_________________
Papillon


Last edited by Papillon on Tue Jun 26, 2007 0:11; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
chaoslink



Joined: 23 Aug 2006
Posts: 37

PostPosted: Tue Jun 26, 2007 0:11    Post subject: Reply with quote

I'll send you what I have once I fix the runtime errors.
Back to top
View user's profile Send private message
acaos



Joined: 08 May 2007
Posts: 153

PostPosted: Sat Jul 14, 2007 1:08    Post subject: Reply with quote

Any chance I could get a look at this code? I've been working on a couple of new plugins for NWNX2 and it would be really helpful for what I'm doing.

Thanks,
Acaos
Back to top
View user's profile Send private message
chaoslink



Joined: 23 Aug 2006
Posts: 37

PostPosted: Sat Jul 14, 2007 1:12    Post subject: Reply with quote

Sure... when I get a bit further on it, I think there may be a systemic problem with the port, but I'm not sure yet. I've been working 70+ hour weeks so it will be a bit.
Back to top
View user's profile Send private message
acaos



Joined: 08 May 2007
Posts: 153

PostPosted: Sat Jul 14, 2007 5:34    Post subject: Reply with quote

Thanks very much, I'll be looking forward to it. I'd be glad to see if I can debug it as well if you're too busy to.

I have a new plugin for NWNX2 that allows hooking combat, which means the ability to add more feats (Weapon Focus for new weapons, etc), as well as change the behavior of the system.

We're already using it on Higher Ground. Right now we're only using a couple of features, but I intend to integrate more and offer it to the community at large once it's gone through some more extensive testing.

Acaos
Back to top
View user's profile Send private message
serafim



Joined: 02 Jan 2007
Posts: 41

PostPosted: Sat Nov 03, 2007 13:00    Post subject: Reply with quote

Surfing madshi forum i found this:


http://forum.madshi.net/viewtopic.php?t=4211


revision 2.2.5.0 of hook code seems to be compatible with 64bit system and Vista too....


can someone confirm this (papillon maybe ? Very Happy)

I must reinstall os on my server so shifting to server 03 64bit may be a good improvement for me .

thanks
Back to top
View user's profile Send private message MSN Messenger
Darnah



Joined: 06 Jun 2007
Posts: 15

PostPosted: Thu Nov 08, 2007 2:22    Post subject: Reply with quote

Yes, it would be very helpful, if someone could confirm this and if someone could say, how easy it is, to replace madhook with this version. I really think, that madshi will make a frée license for this project, as said in his post here:

http://forum.madshi.net/viewtopic.php?t=4210
Back to top
View user's profile Send private message
Papillon
x-man


Joined: 28 Dec 2004
Posts: 1060
Location: Germany

PostPosted: Mon Nov 12, 2007 12:55    Post subject: Reply with quote

Could someone please try the new version ? I do not have access to a 64bit OS myself.

If there are incompabilities with the interface, I will update NWNX, of course.
_________________
Papillon
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
serafim



Joined: 02 Jan 2007
Posts: 41

PostPosted: Tue Nov 13, 2007 22:39    Post subject: Reply with quote

Unfortunately the new 2.5.5.0 version oh madChook.dll is no more freeware.

That's the readme:




Quote:
Unfortunatley madCodeHook is only available for commercial usage, anymore.
I had to drop the non-commercial edition due to constant misused by malware.

If you're a company wanting to evaluate madCodeHook, please check out the
precompiled demos. Furthermore you can build full test programs and dlls with
this evaluation version. You will need to copy "madCHook.dll" to the system32
folder, though, and you'll have to manually start the tool "mchEvaluation.exe".
Otherwise your test projects won't work. Of course with the commercial edition
you don't need "mchEvaluation.exe", anymore. Furthermore with the commercial
edition if you're using Delphi or MSVC++, you'll also not need "madCHook.dll",
either.

I'm seriously sorry for all the good freeware programmers out there, who would
have liked to use madCodeHook for their projects. But the malware writers gave
me no other choice. If you have a good and well known freeware and *are*
already using madCodeHook for some time, you may send me an eMail. If I like
your software I may eventually (or not) make a free license available to you.


maybe if u Papillon contact Madshi he can give u a free license.

thanks.
Back to top
View user's profile Send private message MSN Messenger
mckillroy



Joined: 16 May 2005
Posts: 40

PostPosted: Sat Nov 17, 2007 11:22    Post subject: Reply with quote

Madcodehook is not needed at all.

There are lots of descriptions out on how to implement DLL injection.

In the moment it appears to me, that using Microsofts Detour API is the most promising one to work under wine as well.

Once I have finished experimenting with it I'll tell here. Using the windows function "CreateRemoteThread" should also work. but I had trouble using it .. probably some mistakes on my side, and it caused trouble on wine for me.

EDIT: Just found the other thread about detours - good to see you're already on it.
_________________
/McKillroy
a.k.a Yorlik
Back to top
View user's profile Send private message
xeopherith



Joined: 14 Dec 2007
Posts: 8

PostPosted: Mon Dec 17, 2007 5:20    Post subject: Reply with quote

http://www.nwnx.org/phpBB2/viewtopic.php?t=476

mckillroy's solution is pretty close to working on my 64bit OS.

That Madchook.dll from the link above will "work" as long as you run an executable that comes with it for evaluation purposes HOWEVER, it doesn't work on my Windows Server 2003 R2 64bit edition so its useless to me.
Back to top
View user's profile Send private message
xeopherith



Joined: 14 Dec 2007
Posts: 8

PostPosted: Mon Dec 17, 2007 5:39    Post subject: Reply with quote

Read the link I posted above, the solution does work.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Development All times are GMT + 2 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


Powered by phpBB © 2001, 2005 phpBB Group