News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

ERROR_INVALID_ADDRESS calling QueryServiceConfig

Started by Rodol, March 22, 2006, 09:54:17 AM

Previous topic - Next topic

Rodol

Hi,

I'm trying to obtain the configuration of a service and I always obtain the same error. ERROR_INVALID_ADDRESS.The proccess is:

  Get the SCM Handler with OpenSCManager.
  Get the Service Handler with OpenService.
  Get the Service config with QueryServiceConfig, thes function alwais return 0, and the GetLastError return 1E7 (ERROR_INVALID_ADDRESS).

thank's

****************************************  CODE **************************


.data
sMachine db NULL
servicio db 'mdm',0
sOk db 'OK',0
sError db 'Bad',0
;EstructuraServicio  QUERY_SERVICE_CONFIG   <>
.data?

pServicio SC_HANDLE ?
pManejador SC_HANDLE ?
BytesNecesarios DWORD ?
hMem HANDLE  ?   ; Manejador memoria
pMem DWORD ?   ; Puntero memoria

.code
Start:
   call inicio
   invoke MessageBox,NULL,  addr sOk,addr sOk ,MB_OK
   invoke ExitProcess,0 
inicio proc   
   invoke OpenSCManager,addr sMachine,NULL,SC_MANAGER_ENUMERATE_SERVICE    mov pManejador, eax
   .if eax==0
      jmp TheEnd  ;ERROR   
   .endif
    invoke OpenService,pManejador,addr servicio,SERVICE_QUERY_CONFIG    mov pServicio,eax
   .if eax==0
      jmp TheEnd ;ERROR
   .endif
   mov BytesNecesarios,0
   invoke LocalAlloc,GMEM_FIXED,4096
   mov hMem,eax
   invoke LocalLock,hMem
   mov pMem,eax    
   INVOKE QueryServiceConfig,pServicio,pMem,4096,BytesNecesarios
    
   .if eax==0
      invoke GetLastError      ; Allways return 1E7 --> ERROR_INVALID_ADDRESS
      .if eax==ERROR_INSUFFICIENT_BUFFER
         invoke LocalUnlock,pMem
         invoke LocalFree,hMem
         invoke LocalAlloc,GMEM_FIXED,BytesNecesarios
         mov hMem,eax
         invoke LocalLock,hMem
         mov pMem,eax
         INVOKE QueryServiceConfig,pServicio,pMem,BytesNecesarios,BytesNecesarios
      .endif
   .endif
   invoke LocalUnlock,pMem
   invoke LocalFree,hMem   
   
   .if eax==0
   jmp TheEnd ;ERROR
   .endif
   jmp exithere
TheEnd:
      invoke MessageBox,NULL,  addr sError ,addr sError,MB_ICONERROR
      invoke ExitProcess,0
exithere:
   
inicio endp
   
end Start   
*******************************

MichaelW

Hello Rodol, welcome to the forum.

AFAIK the QueryServiceConfig call should be:

INVOKE QueryServiceConfig,pServicio,pMem,4096,ADDR BytesNecesarios



eschew obfuscation

Rodol