;{- WMI Constants
COINIT_MULTITHREAD=0
#RPC_C_AUTHN_LEVEL_CONNECT=2
#RPC_C_IMP_LEVEL_IDENTIFY=2
#EOAC_NONE=0
#RPC_C_AUTHN_WINNT=10
#RPC_C_AUTHZ_NONE=0
#RPC_C_AUTHN_LEVEL_CALL=3
#RPC_C_IMP_LEVEL_IMPERSONATE=3
#CLSCTX_INPROC_SERVER=1
#wbemFlagReturnImmediately=16
#wbemFlagForwardOnly=32
#IFlags = #wbemFlagReturnImmediately + #wbemFlagForwardOnly
#WBEM_INFINITE=$FFFFFFFF
#WMISeparator=","
;}
Procedure.l ansi2bstr(ansi.s)
Size.l = MultiByteToWideChar_(#CP_ACP, 0, ansi, -1, 0, 0)
Global Dim unicode.w(Size)
MultiByteToWideChar_(#CP_ACP, 0, ansi, Len(ansi), unicode(), Size)
ProcedureReturn SysAllocString_( @unicode())
EndProcedure
Procedure bstr2string (bstr)
Shared WMIResult.s
WMIResult.s = ""
pos = bstr
While PeekW (pos)
WMIResult = WMIResult + Chr(PeekW(pos))
pos = pos + 2
Wend
ProcedureReturn @WMIResult
EndProcedure
ProcedureDLL.s WMIC(root.s, WMICommand.s)
CoInitializeEx_(0, #COINIT_MULTITHREAD)
hres = CoInitializeSecurity_(0, -1, 0, 0, #RPC_C_AUTHN_LEVEL_CONNECT, #RPC_C_IMP_LEVEL_IDENTIFY, 0, #EOAC_NONE, 0)
If hres <> 0 : e$ = "unable to call CoInitializeSecurity" : Goto cleanup : EndIf
hres = CoCreateInstance_(?CLSID_WbemLocator, 0, #CLSCTX_INPROC_SERVER, ?IID_IWbemLocator, @loc.IWbemLocator)
If hres <> 0 : e$ = "unable to call CoCreateInstance" : Goto cleanup : EndIf
hres = loc\ConnectServer(ansi2bstr(root), 0, 0, 0, 0, 0, 0, @svc.IWbemServices)
If hres <> 0 : e$ = "unable to call IWbemLocator::ConnectServer" : loc\Release() : Goto cleanup : EndIf
hres = svc\QueryInterface(?IID_IUnknown, @pUnk.IUnknown)
hres = CoSetProxyBlanket_(svc, #RPC_C_AUTHN_WINNT, #RPC_C_AUTHZ_NONE, 0, #RPC_C_AUTHN_LEVEL_CALL, #RPC_C_IMP_LEVEL_IMPERSONATE, 0, #EOAC_NONE)
If hres <> 0 : e$ = "unable to call CoSetProxyBlanket" : svc\Release() : loc\Release() : Goto cleanup : EndIf
hres = CoSetProxyBlanket_(pUnk, #RPC_C_AUTHN_WINNT, #RPC_C_AUTHZ_NONE, 0, #RPC_C_AUTHN_LEVEL_CALL, #RPC_C_IMP_LEVEL_IMPERSONATE, 0, #EOAC_NONE)
If hres <> 0 : e$ = "unable to call CoSetProxyBlanket" : svc\Release() : loc\Release() : pUnk\Release() : Goto cleanup : EndIf
pUnk\Release()
hres=CoCreateInstance_(?CLSID_WbemRefresher,0,#CLSCTX_INPROC_SERVER,?IID_IWbemRefresher,@pRefresher.IWbemRefresher)
If hres <> 0 : e$ = "unable to call CoCreateInstance" : svc\Release() : loc\Release() : Goto cleanup : EndIf
hres=pRefresher\QueryInterface(?IID_IWbemConfigureRefresher,@pConfig.IWbemConfigureRefresher)
If hres <> 0 : e$ = "unable to QueryInterface" : svc\Release() : loc\Release() : pRefresher\Release() : Goto cleanup : EndIf
pRefresher\refresh(0)
k = CountString(WMICommand, #WMISeparator)
Global Dim wmitxt$(k)
For i = 0 To k
wmitxt$(i) = StringField(WMICommand, i + 1, #WMISeparator)
Next
hres = svc\ExecQuery(ansi2bstr("WQL"), ansi2bstr(wmitxt$(0)), #IFlags, 0, @pEnumerator.IEnumWbemClassObject)
If hres <> 0 : e$ = "unable to call IWbemServices::ExecQuery" : svc\Release() : loc\Release() : pRefresher\Release() : Goto cleanup : EndIf
hres = pEnumerator\reset()
Repeat
hres = pEnumerator\Next(#WBEM_INFINITE, 1, @pclsObj.IWbemClassObject, @uReturn)
If hres = 0
For i = 1 To k
mem = AllocateMemory(1000)
hres = pclsObj\get(ansi2bstr(wmitxt$(i)), 0, mem, 0, 0)
Type = PeekW(mem)
Select Type
Case 8
val.s = PeekS(bstr2string(PeekL(mem + ))
Case 3
val.s = Str(PeekL(mem + )
Default
val.s = ""
EndSelect
If uReturn <> 0 : If wmi$ : wmi$ = wmi$ + "|" + wmitxt$(i) + "=" + val : Else : wmi$ = wmitxt$(i) + "=" + val : EndIf : EndIf
FreeMemory(mem)
Next
pclsObj\Release()
EndIf
Until uReturn = 0
svc\Release() : loc\Release() : pEnumerator\Release() : pRefresher\Release()
cleanup :
CoUninitialize_()
If e$
ProcedureReturn "ERROR : " + e$
EndIf
ProcedureReturn wmi$
EndProcedure
DataSection
CLSID_IEnumWbemClassObject :
; 1B1CAD8C-2DAB-11D2-B604-00104B703EFD
Data.l $1B1CAD8C
Data.w $2DAB, $11D2
Data.b $B6, $04, $00, $10, $4B, $70, $3E, $FD
IID_IEnumWbemClassObject :
; 7C857801-7381-11CF-884D-00AA004B2E24
Data.l $7C857801
Data.w $7381, $11CF
Data.b $88, $4D, $00, $AA, $00, $4B, $2E, $24
CLSID_WbemLocator :
; 4590f811-1d3a-11d0-891f-00aa004b2e24
Data.l $4590F811
Data.w $1D3A, $11D0
Data.b $89, $1F, $00, $AA, $00, $4B, $2E, $24
IID_IWbemLocator :
; dc12a687-737f-11cf-884d-00aa004b2e24
Data.l $DC12A687
Data.w $737F, $11CF
Data.b $88, $4D, $00, $AA, $00, $4B, $2E, $24
IID_IUnknown :
; 00000000-0000-0000-C000-000000000046
Data.l $00000000
Data.w $0000, $0000
Data.b $C0, $00, $00, $00, $00, $00, $00, $46
IID_IWbemRefresher:
;49353c99-516b-11d1-aea6-00c04fb68820
Data.l $49353C99
Data.w $516B, $11D1
Data.b $AE, $A6, $00, $C0, $4F, $B6, $88, $20
CLSID_WbemRefresher:
;c71566f2-561E-11D1-AD87-00C04FD8FDFF
Data.l $C71566F2
Data.w $561E, $11D1
Data.b $AD,$87,$00,$C0,$4F,$D8,$FD,$FF
IID_IWbemConfigureRefresher:
;49353c92-516b-11d1-aea6-00c04fb68820
Data.l $49353C92
Data.w $516B, $11D1
Data.b $AE, $A6, $00, $C0, $4F, $B6, $88, $20
EndDataSection
ProcedureDLL.s criptage()
Define chaine$,toto.l
chaine$= WMIC("root\cimv2\Applications\MicrosoftIE", "select * from MicrosoftIE_Summary,Version,ProductID,Cipherstrength")
toto=FindString(chaine$,"Cipherstrength=",1) +15
ProcedureReturn Trim(Mid(chaine$,toto,4))
EndProcedure [/code]
After compiling with purebasic invoking criptage() generate a read error at adress 0
Purebasic PB 4?.20
Tailbite PR3 1.8.76
READ ERROR AT ADRESS 0
Moderators: gnozal, ABBKlaus, lexvictory
READ ERROR AT ADRESS 0
@KIKI,
please use code tags, its unreadable.
Btw, i found it. You should never call an exported string function from inside the library !
please use code tags, its unreadable.
Btw, i found it. You should never call an exported string function from inside the library !
Code: Select all
;{- WMI Constants
#COINIT_MULTITHREAD=0
#RPC_C_AUTHN_LEVEL_CONNECT=2
#RPC_C_IMP_LEVEL_IDENTIFY=2
#EOAC_NONE=0
#RPC_C_AUTHN_WINNT=10
#RPC_C_AUTHZ_NONE=0
#RPC_C_AUTHN_LEVEL_CALL=3
#RPC_C_IMP_LEVEL_IMPERSONATE=3
#CLSCTX_INPROC_SERVER=1
#wbemFlagReturnImmediately=16
#wbemFlagForwardOnly=32
#IFlags = #wbemFlagReturnImmediately + #wbemFlagForwardOnly
#WBEM_INFINITE=$FFFFFFFF
#WMISeparator=","
;}
Procedure.l ansi2bstr(ansi.s)
Size.l = MultiByteToWideChar_(#CP_ACP, 0, ansi, -1, 0, 0)
Global Dim unicode.w(Size)
MultiByteToWideChar_(#CP_ACP, 0, ansi, Len(ansi), unicode(), Size)
ProcedureReturn SysAllocString_( @unicode())
EndProcedure
Procedure bstr2string (bstr)
Shared WMIResult.s
WMIResult.s = ""
pos = bstr
While PeekW (pos)
WMIResult = WMIResult + Chr(PeekW(pos))
pos = pos + 2
Wend
ProcedureReturn @WMIResult
EndProcedure
Procedure.s ipf_WMIC(root.s, WMICommand.s)
CoInitializeEx_(0, #COINIT_MULTITHREAD)
hres = CoInitializeSecurity_(0, -1, 0, 0, #RPC_C_AUTHN_LEVEL_CONNECT, #RPC_C_IMP_LEVEL_IDENTIFY, 0, #EOAC_NONE, 0)
If hres <> 0 : e$ = "unable to call CoInitializeSecurity" : Goto cleanup : EndIf
hres = CoCreateInstance_(?CLSID_WbemLocator, 0, #CLSCTX_INPROC_SERVER, ?IID_IWbemLocator, @loc.IWbemLocator)
If hres <> 0 : e$ = "unable to call CoCreateInstance" : Goto cleanup : EndIf
hres = loc\ConnectServer(ansi2bstr(root), 0, 0, 0, 0, 0, 0, @svc.IWbemServices)
If hres <> 0 : e$ = "unable to call IWbemLocator::ConnectServer" : loc\Release() : Goto cleanup : EndIf
hres = svc\QueryInterface(?IID_IUnknown, @pUnk.IUnknown)
hres = CoSetProxyBlanket_(svc, #RPC_C_AUTHN_WINNT, #RPC_C_AUTHZ_NONE, 0, #RPC_C_AUTHN_LEVEL_CALL, #RPC_C_IMP_LEVEL_IMPERSONATE, 0, #EOAC_NONE)
If hres <> 0 : e$ = "unable to call CoSetProxyBlanket" : svc\Release() : loc\Release() : Goto cleanup : EndIf
hres = CoSetProxyBlanket_(pUnk, #RPC_C_AUTHN_WINNT, #RPC_C_AUTHZ_NONE, 0, #RPC_C_AUTHN_LEVEL_CALL, #RPC_C_IMP_LEVEL_IMPERSONATE, 0, #EOAC_NONE)
If hres <> 0 : e$ = "unable to call CoSetProxyBlanket" : svc\Release() : loc\Release() : pUnk\Release() : Goto cleanup : EndIf
pUnk\Release()
hres=CoCreateInstance_(?CLSID_WbemRefresher,0,#CLSCTX_INPROC_SERVER,?IID_IWbemRefresher,@pRefresher.IWbemRefresher)
If hres <> 0
e$ = "unable to call CoCreateInstance"
svc\Release()
loc\Release()
Goto cleanup
EndIf
hres=pRefresher\QueryInterface(?IID_IWbemConfigureRefresher,@pConfig.IWbemConfigureRefresher)
If hres <> 0
e$ = "unable to QueryInterface"
svc\Release()
loc\Release()
pRefresher\Release()
Goto cleanup
EndIf
pRefresher\refresh(0)
k = CountString(WMICommand, #WMISeparator)
Global Dim wmitxt$(k)
For i = 0 To k
wmitxt$(i) = StringField(WMICommand, i + 1, #WMISeparator)
Next
hres = svc\ExecQuery(ansi2bstr("WQL"), ansi2bstr(wmitxt$(0)), #IFlags, 0, @pEnumerator.IEnumWbemClassObject)
If hres <> 0
e$ = "unable to call IWbemServices::ExecQuery"
svc\Release()
loc\Release()
pRefresher\Release()
Goto cleanup
EndIf
hres = pEnumerator\reset()
Repeat
hres = pEnumerator\Next(#WBEM_INFINITE, 1, @pclsObj.IWbemClassObject, @uReturn)
If hres = 0
For i = 1 To k
mem = AllocateMemory(1000)
hres = pclsObj\get(ansi2bstr(wmitxt$(i)), 0, mem, 0, 0)
Type = PeekW(mem)
Select Type
Case 8
val.s = PeekS(bstr2string(PeekL(mem + 8)))
Case 3
val.s = Str(PeekL(mem + 8))
Default
val.s = ""
EndSelect
If uReturn <> 0
If wmi$
wmi$ = wmi$ + "|" + wmitxt$(i) + "=" + val
Else
wmi$ = wmitxt$(i) + "=" + val
EndIf
EndIf
FreeMemory(mem)
Next
pclsObj\Release()
EndIf
Until uReturn = 0
svc\Release()
loc\Release()
pEnumerator\Release()
pRefresher\Release()
cleanup:
CoUninitialize_()
If e$
ProcedureReturn "ERROR : " + e$
EndIf
ProcedureReturn wmi$
EndProcedure
ProcedureDLL.s WMIC(root.s,WMICommand.s)
ProcedureReturn ipf_WMIC(root,WMICommand)
EndProcedure
DataSection
CLSID_IEnumWbemClassObject:
; 1B1CAD8C-2DAB-11D2-B604-00104B703EFD
Data.l $1B1CAD8C
Data.w $2DAB, $11D2
Data.b $B6, $04, $00, $10, $4B, $70, $3E, $FD
IID_IEnumWbemClassObject:
; 7C857801-7381-11CF-884D-00AA004B2E24
Data.l $7C857801
Data.w $7381, $11CF
Data.b $88, $4D, $00, $AA, $00, $4B, $2E, $24
CLSID_WbemLocator:
; 4590f811-1d3a-11d0-891f-00aa004b2e24
Data.l $4590F811
Data.w $1D3A, $11D0
Data.b $89, $1F, $00, $AA, $00, $4B, $2E, $24
IID_IWbemLocator:
; dc12a687-737f-11cf-884d-00aa004b2e24
Data.l $DC12A687
Data.w $737F, $11CF
Data.b $88, $4D, $00, $AA, $00, $4B, $2E, $24
IID_IUnknown:
; 00000000-0000-0000-C000-000000000046
Data.l $00000000
Data.w $0000, $0000
Data.b $C0, $00, $00, $00, $00, $00, $00, $46
IID_IWbemRefresher:
;49353c99-516b-11d1-aea6-00c04fb68820
Data.l $49353C99
Data.w $516B, $11D1
Data.b $AE, $A6, $00, $C0, $4F, $B6, $88, $20
CLSID_WbemRefresher:
;c71566f2-561E-11D1-AD87-00C04FD8FDFF
Data.l $C71566F2
Data.w $561E, $11D1
Data.b $AD,$87,$00,$C0,$4F,$D8,$FD,$FF
IID_IWbemConfigureRefresher:
;49353c92-516b-11d1-aea6-00c04fb68820
Data.l $49353C92
Data.w $516B, $11D1
Data.b $AE, $A6, $00, $C0, $4F, $B6, $88, $20
EndDataSection
Procedure.s ipf_Criptage()
Define chaine$,toto.l
chaine$=ipf_WMIC("root\cimv2\Applications\MicrosoftIE", "select * from MicrosoftIE_Summary,Version,ProductID,Cipherstrength")
toto=FindString(chaine$,"Cipherstrength=",1)+15
ProcedureReturn Trim(Mid(chaine$,toto,4))
EndProcedure
ProcedureDLL.s Criptage()
ProcedureReturn ipf_Criptage()
EndProcedure
In the future hopefully we'll be able to do this again.ABBKlaus wrote:You should never call an exported string function from inside the library !
http://www.purebasic.fr/english/viewtop ... 751#245751Fred wrote:Actually, there could be a solution on the compiler side. TailBaite creates pblibraries with the 'ASM' flags (in the .desc), right ?Mistrel wrote:Is there an inconsistency somewhere that prevents us from calling an exported function that returns a string from within the same library? I'm assuming that the ASM output is different between a Procedure and ProcedureDLL.
Would it be possible to keep the ASM the same so that we can call these functions again with TailBite?