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 
 
Thoughts on 64-bit
Goto page 1, 2  Next
 
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows development
View previous topic :: View next topic  
Author Message
addicted2rpg



Joined: 01 Aug 2008
Posts: 106

PostPosted: Sat May 16, 2009 0:13    Post subject: Thoughts on 64-bit Reply with quote

I've been "out of the loop" due to having upgraded computer to XP64 which has basically ended my NWNX projects career =-)

However, I discovered this little gem on madshi.net

madshi wrote:

madCodeHook does support hooking APIs inside of a 32bit process just fine, regardless of which OS we are talking about, or which bitdepth the OS has. The limiting factor is DLL injection: The current official madCodeHook version can inject DLLs into all running 32bit processes, but automatic injection into newly created 32bit processes on a 64bit OS does not work.


In nwserver.cpp, the hook is established as:
Code:

   CreateProcessEx("nwserver.exe", cl, NULL, NULL,FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, si, pi, "nwnx-module.dll");


Based on what Madshi tells us, this will not work, and is indeed true -- it does not -- on my XP64 box. However, perhaps with some modification, maybe I can return to the NWN community once again.

I suppose the matter at hand is figuring out how to start the server first, and attaching second, and if that moves things around in memory how to compensate the existing hook set and scan codes.

Hmmmmm, much to dwell on. These are my thoughts on 64-bit. Smile
Back to top
View user's profile Send private message
Zebranky



Joined: 04 Jun 2006
Posts: 415

PostPosted: Sat May 16, 2009 1:34    Post subject: Reply with quote

Personally, I just keep a 32-bit VM around (two, actually -- one WinXP, one Linux) and use that for my NWNX stuff. It has the added benefit of being able to use Wireshark and other such tools with far less background noise.
_________________
Win32 SVN builds: http://www.mercuric.net/nwn/nwnx/

<Fluffy-Kooshy> NWNx plugin is to this as nuclear warheads are to getting rid of fire ants.

<ThriWork> whenever I hear nwn extender, I think what does NWN need a penis extender for?
Back to top
View user's profile Send private message Visit poster's website
addicted2rpg



Joined: 01 Aug 2008
Posts: 106

PostPosted: Sun May 17, 2009 1:02    Post subject: Reply with quote

Great idea. I still have the original media from my XP32. I'll have to give it a try.

You using "VMWare" or some other emulation solution tool?
Back to top
View user's profile Send private message
virusman



Joined: 30 Jan 2005
Posts: 1020
Location: Russia

PostPosted: Sun May 17, 2009 1:21    Post subject: Reply with quote

VMWare (Server and Player are free) or VirtualBox (free, open-source).
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Zebranky



Joined: 04 Jun 2006
Posts: 415

PostPosted: Sun May 17, 2009 20:33    Post subject: Reply with quote

VMWare, aye, though I've been considering switching to VirtualBox for the whole free software thing.
_________________
Win32 SVN builds: http://www.mercuric.net/nwn/nwnx/

<Fluffy-Kooshy> NWNx plugin is to this as nuclear warheads are to getting rid of fire ants.

<ThriWork> whenever I hear nwn extender, I think what does NWN need a penis extender for?
Back to top
View user's profile Send private message Visit poster's website
addicted2rpg



Joined: 01 Aug 2008
Posts: 106

PostPosted: Mon May 18, 2009 4:02    Post subject: Reply with quote

SUCCESS!!!!!!!!

I think the emulator ideas are awesome and probably a lot more profound than my long-way approach.

But... I read your responses a little too late and had set work on the problem. Fortunately, my labors have prevailed.

It turns out, even with the MySQL 64-bit ODBC/Connector, the 32-bit version of NWNX2 and nwserver work just fine.


In nwserver.cpp in the NWNX2 folder,
Change:
Code:


void StartServerProcess(LPTSTR cl, STARTUPINFO* si, PROCESS_INFORMATION* pi)
{
     CreateProcessEx("nwserver.exe", cl, NULL, NULL,FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, si, pi, "nwnx-module.dll");
}


To:

Code:

void StartServerProcess(LPTSTR cl, STARTUPINFO* si, PROCESS_INFORMATION* pi)
{


   
   CreateProcess("nwserver.exe", cl, sec, sec, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, si, pi);

   InjectLibrary((DWORD) pi->hProcess, "nwnx-module.dll");   

}


Recompile, and your done. You do not need to update to the latest madHook libs -- the old one and the old DLL work just fine.

All my plugins work, ODBC works, even leto works.... I really didn't have to change anything else.

So there you have it, 64-bit compat NWNX2. And to be honest, I thought it would be a lot more complex. I'm still wondering if its too good to be true.

So in my case, I'll be passing on the emulators, but thanks for the tips guys. I should have tried those first than do all this.
Back to top
View user's profile Send private message
addicted2rpg



Joined: 01 Aug 2008
Posts: 106

PostPosted: Mon May 18, 2009 6:22    Post subject: Reply with quote

Fyi, it does seem a little racey. Sometimes it doesn't inject, but I just check if the return val on InjectLibrary is FALSE and try again.. seems to work that way. Of course, since I don't run a large PW, can't make any claims to how stable it is over time, but once the dll injection takes I think (knock on wood) it should be alright.
Back to top
View user's profile Send private message
Zebranky



Joined: 04 Jun 2006
Posts: 415

PostPosted: Tue May 19, 2009 5:00    Post subject: Reply with quote

Awesome! Haven't tested it myself, but I can see that working. Good to know!
_________________
Win32 SVN builds: http://www.mercuric.net/nwn/nwnx/

<Fluffy-Kooshy> NWNx plugin is to this as nuclear warheads are to getting rid of fire ants.

<ThriWork> whenever I hear nwn extender, I think what does NWN need a penis extender for?
Back to top
View user's profile Send private message Visit poster's website
Baaleos



Joined: 02 Sep 2007
Posts: 830

PostPosted: Tue May 19, 2009 13:46    Post subject: Does this work? Reply with quote

Hey does this actually work?

If so, can someone provide a binary/executable download?

My situation is that I have a Winxp64 bit desktop, and a x86 Dedicated Server situated across the Irish Sea. Lol

So, any time I want to test a new NWNx functionality/script, I've always had to upload to my dedicated server, and then connect.


But if this can indeed get nwnx working on xp64 bit, it would solve alot of my headaches.
Back to top
View user's profile Send private message
addicted2rpg



Joined: 01 Aug 2008
Posts: 106

PostPosted: Tue May 19, 2009 23:03    Post subject: Reply with quote

Yes and no. Its pretty squirrely. What I mean by squirelly is sometimes the Inject will fail. When it succeeds, I haven't noticed any instability. Even more confusing, is if you shutdown the server and let the process-watchdog restart it, subsequent restarts (originating from the process-watch dog) won't inject.

You got to exit both the watchdog and the server and start the NWNX2.exe all over again to get a proper "try" at injecting with the code as I have it above. I'd say it almost alternates, like "every other time" it injects successfully, or around 50%.

I have mediated on the idea of calling a deliberately failing UnInjectLibrary call first just to see if there is any residue I don't know about that needs cleaning up from the last one. It might help, even if there is no library to UnInject.

I have developed code to determine if an inject worked (mainly by checking for the presence of nwnx.log after the log rotate).

I have a 32-bit box next to me so I've sort of moved over to that now, but it seems I'm not the only one interested; perhaps I should pursue this development more.

I could send you a binary, but like I said, it wouldn't be worth a damn. Although as a developer it wouldn't be bad since you could just restart it. The catch-22 is if you want to run a "real" NWN server.

I'll play around with it a little more, see if I can come up with a way to get it to inject 100% of the time. I'll also ask around on madshi.net to see if those guys can reveal anything helpful.
Back to top
View user's profile Send private message
addicted2rpg



Joined: 01 Aug 2008
Posts: 106

PostPosted: Wed May 20, 2009 4:42    Post subject: Reply with quote

This one is for you Baaleos -
http://metafocus.net/~cs60/NWNX2.rar

source included per gnu public license.

This is in no way a "release" - its more like something I scrapped together between compiles. It has the Uninject idea being applied at the moment, and god only knows how useful/useless that is Razz So far, I've got a few runs successful in a "row" so I'm optimistic, but, yeah, we'll see. Smile Anyway, as far as I am aware, that is closest as your gonna get running NWNX natively (that is, without emulation) on XP64 until further discovery.


"Key Code"-
Code:

// Fire up the server using normal windows API.
   CreateProcess("nwserver.exe", cl,  NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS, NULL, NULL, si, pi);

// Uninject call fails - nothing has been injected yet!; this is by design and is a workaround to scrub the XP64 kernel.
   UninjectLibrary((DWORD) pi->hProcess, "nwnx-module.dll");

//Proceed with normal injection
   InjectLibrary((DWORD) pi->hProcess, "nwnx-module.dll");
Back to top
View user's profile Send private message
Disco



Joined: 06 Dec 2006
Posts: 152

PostPosted: Fri May 22, 2009 17:45    Post subject: Reply with quote

We run NWNX2 on a 64-bit XP server. Magnumman posted about this before.

MagnumMan wrote:
Amia (www.amiaworld.net) is running on x86-64. We're using a pre-release madCHook which allows us to run on x86-64, along with NWNX2 32-bit, nwserver 32-bit, and mysql 64-bit. madshi said that this support would come in the next official release in an email I have stored from May 2006. In any case I know it is possible since we're doing it, perhaps a donation to madshi would be in order - I certainly made one.


MagnumMan wrote:
Why don't you just ask madshi for the 64-bit compabitle madCHook.DLL? Amia is running on Win64 with it just fine...


I am not sure how he got the pre-release version, but I can tell you it has been running fine for us for years now.
Back to top
View user's profile Send private message
addicted2rpg



Joined: 01 Aug 2008
Posts: 106

PostPosted: Mon Jun 01, 2009 9:46    Post subject: Reply with quote

I remember reading about madshi's prelease but I hadn't worked up the gall to ask him for it since he mentions its for "special customers" and I am by no means a customer. I have a feeling that donating probably helps qualify you as a "special customer."

It would be neat to get this madCHook into the NWNX distro, but that would be somewhat contingent on him giving it to us....... and I really don't want to provoke him smuggling it / discovering what extent we are actually protected by the GPL Wink It'd be poor ettiquette and distasteful anyway.

Well, for everyone else, it seems my workaround above works fine as far as I can tell (and there is still the emulator workaround). Still, its good to know the pre-release is stable and well-tested by Amia.
Back to top
View user's profile Send private message
Gryphyn



Joined: 20 Jan 2005
Posts: 431

PostPosted: Mon Jun 01, 2009 9:52    Post subject: Reply with quote

addicted2rpg wrote:
I remember reading about madshi's prelease but I hadn't worked up the gall to ask him for it since he mentions its for "special customers" and I am by no means a customer. I have a feeling that donating probably helps qualify you as a "special customer."

It would be neat to get this madCHook into the NWNX distro, but that would be somewhat contingent on him giving it to us....... and I really don't want to provoke him smuggling it / discovering what extent we are actually protected by the GPL Wink It'd be poor ettiquette and distasteful anyway.

Well, for everyone else, it seems my workaround above works fine as far as I can tell (and there is still the emulator workaround). Still, its good to know the pre-release is stable and well-tested by Amia.

There may be a 'free' alternative - a little more advanced than just 'Detours'
EasyHook - The reinvention of Windows API Hooking
It's due for an update in the next month or two...

Cheers
Gryphyn
Back to top
View user's profile Send private message
maddogfargo



Joined: 03 Nov 2009
Posts: 49

PostPosted: Tue Nov 03, 2009 23:36    Post subject: Reply with quote

Gryphyn wrote:
addicted2rpg wrote:
I remember reading about madshi's prelease but I hadn't worked up the gall to ask him for it since he mentions its for "special customers" and I am by no means a customer. I have a feeling that donating probably helps qualify you as a "special customer."

It would be neat to get this madCHook into the NWNX distro, but that would be somewhat contingent on him giving it to us....... and I really don't want to provoke him smuggling it / discovering what extent we are actually protected by the GPL Wink It'd be poor ettiquette and distasteful anyway.

Well, for everyone else, it seems my workaround above works fine as far as I can tell (and there is still the emulator workaround). Still, its good to know the pre-release is stable and well-tested by Amia.

There may be a 'free' alternative - a little more advanced than just 'Detours'
EasyHook - The reinvention of Windows API Hooking
It's due for an update in the next month or two...

Cheers
Gryphyn


Anyone know if this or the pre-release madchook mentioned earlier resolve issues with NWNX2 32bit plugin DLLs not working on XP64?
_________________
* illegible scribble *
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Windows development All times are GMT + 2 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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