Shoutbox

[?] GetProcAddress and LoadLibraryW - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: [?] GetProcAddress and LoadLibraryW (/showthread.php?tid=97329)

[?] GetProcAddress and LoadLibraryW by SmokingCookie on 04-09-2011 at 07:17 PM

Wow I've been away for a LOOOOOOOONG time man :|

Anyways, I'm having trouble getting GetProcAddress to do what I want. I've managed to have it return a valid (and the right) address value for the ordinal value associated with LoadLibraryW, but it won't work for the string "LoadLibraryW". My code:

JS code:
var GetModuleHandle = function(ModuleName) {
    Print("Getting module handle for " + ModuleName);
    return Interop.Call("Kernel32.dll","GetModuleHandleW",ModuleName);
}

var GetProcAddress = function(hModule,ProcName) {
    Print("Getting procedure address for " + ProcName);
    return Interop.Call("Kernel32.dll","GetProcAddress",hModule,ProcName);
}

This code does return a valid hModule, but the procedure address is zero/NULL for the "LoadLibraryW" string. I've checked the ordinal value on Vista x64 SP2; it's not the same as the XP one. That's why I want this to work with the procedure name, rather than its ordinal value.

I've read the remarks in the MSDN article on GetProcAddress - that's why I came up with the ordinal value thing - but I can't figure out what I'm doing wrong. So, could anyone please help me with this issue?

FTR, I'm on Windows XP x86 SP 3.
RE: [?] GetProcAddress and LoadLibraryW by Eljay on 04-09-2011 at 07:56 PM

GetProcAddress doesn't take a unicode string :P

js code:
function Print(s){Debug.Trace(s);}

var GetModuleHandle = function(ModuleName) {
    Print("Getting module handle for " + ModuleName);
    return Interop.Call("Kernel32.dll","GetModuleHandleW",ModuleName);
}

var GetProcAddress = function(hModule,ProcName) {
    Print("Getting procedure address for " + ProcName);
    var DataBloc = Interop.Allocate(ProcName.length + 1);
    DataBloc.WriteString(0, ProcName, false);
    return Interop.Call("Kernel32.dll","GetProcAddress",hModule,DataBloc);
}

var a = GetModuleHandle("kernel32.dll");
Debug.Trace(a);
var b = GetProcAddress(a, "LoadLibraryW");
Debug.Trace(b);

RE: [?] GetProcAddress and LoadLibraryW by SmokingCookie on 04-10-2011 at 08:25 AM

Got it working, thanks :D