The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Slugsnack on May 17, 2009, 01:09:23 AM

Title: RegGetValue not working ?
Post by: Slugsnack on May 17, 2009, 01:09:23 AM
MASM does not let me use this function so I tried to use it via GetProcAddress/GetModuleHandle.  GetModuleHandle correctly returns the base of advapi32.dll but then GetProcAddress returns null with error ERROR_PROC_NOT_FOUND.  Any clue what's happened ?!  I'm on Server 2008 SP2 so that function should exist..
Title: Re: RegGetValue not working ?
Post by: MichaelW on May 17, 2009, 01:23:58 AM
Did you try RegGetValueA or RegGetValueW?
Title: Re: RegGetValue not working ?
Post by: Slugsnack on May 17, 2009, 01:35:17 AM
oh crap yeah that was it.  is there anyway i can use it without this method though ?  the proto can be easily added to the inc file, not sure what can be done with the lib file though :/
Title: Re: RegGetValue not working ?
Post by: Tedd on May 17, 2009, 08:01:09 PM
Use RegQueryValueEx :wink
(Paired with RegSetValueEx)
Title: Re: RegGetValue not working ?
Post by: Slugsnack on May 18, 2009, 12:46:14 AM
using that now since i guess reggetvalue doesn't work with winxp, etc. at least from what i read
Title: Re: RegGetValue not working ?
Post by: ecube on May 18, 2009, 03:51:36 AM
to load dynamic you can

.data
Advapi32 byte 'advapi32.dll',0
RegGetValueAx byte 'RegGetValueA',0

.data?
RegGetValueAm dd ?

.code
start:
invoke LoadLibrary,addr Advapi32
.if eax
    invoke GetProcAddress,eax,addr RegGetValueAx
   .if eax
       mov RegGetValueAm,eax
       etc...
       push arg2
       push arg1
       call RegGetValueAm
   .endif
.endif

invoke ExitProcess,0
end start


or better

this attempts to get a handle to the dll you want and if it's already loaded then it gets the proc address, if the dll isn't
loaded then it loads it and then gets the proc addr.

returns 0 on error, otherwise the func addr

LoadLib proto :DWORD,:DWORD

.code
LoadLib proc iDll,iFunc
invoke GetModuleHandle, iDll
.if eax==NULL
  invoke LoadLibrary,iDll
  .if eax==NULL
     ret
.endif
.endif
   invoke GetProcAddress,eax,iFunc

ret
LoadLib endp
Title: Re: RegGetValue not working ?
Post by: UtillMasm on May 18, 2009, 04:01:33 AM
post a tester, we can run it on our XPs. and see what's happed.