📄 tmarshal.c
字号:
} else {
VariantInit(vt);
return S_OK;
}
}
case VT_I8:
case VT_UI8:
case VT_CY:
if (readit) {
hres = xbuf_get(buf,(LPBYTE)arg,8);
if (hres) ERR("Failed to read integer 8 byte\n");
}
if (debugout) TRACE_(olerelay)("%x%x",arg[0],arg[1]);
return hres;
case VT_ERROR:
case VT_BOOL:
case VT_I4:
case VT_INT:
case VT_UINT:
case VT_R4:
case VT_UI4:
if (readit) {
hres = xbuf_get(buf,(LPBYTE)arg,sizeof(DWORD));
if (hres) ERR("Failed to read integer 4 byte\n");
}
if (debugout) TRACE_(olerelay)("%x",*arg);
return hres;
case VT_I2:
case VT_UI2:
if (readit) {
DWORD x;
hres = xbuf_get(buf,(LPBYTE)&x,sizeof(DWORD));
if (hres) ERR("Failed to read integer 4 byte\n");
memcpy(arg,&x,2);
}
if (debugout) TRACE_(olerelay)("%04x",*arg & 0xffff);
return hres;
case VT_I1:
case VT_UI1:
if (readit) {
DWORD x;
hres = xbuf_get(buf,(LPBYTE)&x,sizeof(DWORD));
if (hres) ERR("Failed to read integer 4 byte\n");
memcpy(arg,&x,1);
}
if (debugout) TRACE_(olerelay)("%02x",*arg & 0xff);
return hres;
case VT_I4|VT_BYREF:
hres = S_OK;
if (alloc)
*arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DWORD));
if (readit) {
hres = xbuf_get(buf,(LPBYTE)*arg,sizeof(DWORD));
if (hres) ERR("Failed to read integer 4 byte\n");
}
if (debugout) TRACE_(olerelay)("&0x%x",*(DWORD*)*arg);
return hres;
case VT_BSTR|VT_BYREF: {
BSTR **bstr = (BSTR **)arg;
WCHAR *str;
DWORD len;
if (readit) {
hres = xbuf_get(buf,(LPBYTE)&len,sizeof(DWORD));
if (hres) {
ERR("failed to read bstr klen\n");
return hres;
}
if (len == -1) {
*bstr = CoTaskMemAlloc(sizeof(BSTR *));
**bstr = NULL;
if (debugout) TRACE_(olerelay)("<bstr NULL>");
} else {
str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(len+1)*sizeof(WCHAR));
hres = xbuf_get(buf,(LPBYTE)str,len*sizeof(WCHAR));
if (hres) {
ERR("Failed to read BSTR.\n");
return hres;
}
*bstr = CoTaskMemAlloc(sizeof(BSTR *));
**bstr = SysAllocStringLen(str,len);
if (debugout) TRACE_(olerelay)("%s",relaystr(str));
HeapFree(GetProcessHeap(),0,str);
}
} else {
*bstr = NULL;
}
return S_OK;
}
case VT_BSTR: {
WCHAR *str;
DWORD len;
if (readit) {
hres = xbuf_get(buf,(LPBYTE)&len,sizeof(DWORD));
if (hres) {
ERR("failed to read bstr klen\n");
return hres;
}
if (len == -1) {
*arg = 0;
if (debugout) TRACE_(olerelay)("<bstr NULL>");
} else {
str = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,(len+1)*sizeof(WCHAR));
hres = xbuf_get(buf,(LPBYTE)str,len*sizeof(WCHAR));
if (hres) {
ERR("Failed to read BSTR.\n");
return hres;
}
*arg = (DWORD)SysAllocStringLen(str,len);
if (debugout) TRACE_(olerelay)("%s",relaystr(str));
HeapFree(GetProcessHeap(),0,str);
}
} else {
*arg = 0;
}
return S_OK;
}
case VT_PTR: {
DWORD cookie;
BOOL derefhere = TRUE;
if (tdesc->u.lptdesc->vt == VT_USERDEFINED) {
ITypeInfo *tinfo2;
TYPEATTR *tattr;
hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.lptdesc->u.hreftype,&tinfo2);
if (hres) {
ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc->u.lptdesc->u.hreftype);
return hres;
}
ITypeInfo_GetTypeAttr(tinfo2,&tattr);
switch (tattr->typekind) {
case TKIND_ENUM: /* confirmed */
case TKIND_RECORD: /* FIXME: mostly untested */
derefhere=TRUE;
break;
case TKIND_ALIAS: /* FIXME: untested */
case TKIND_DISPATCH: /* will be done in VT_USERDEFINED case */
case TKIND_INTERFACE: /* will be done in VT_USERDEFINED case */
derefhere=FALSE;
break;
default:
FIXME("unhandled switch cases tattr->typekind %d\n", tattr->typekind);
derefhere=FALSE;
break;
}
ITypeInfo_ReleaseTypeAttr(tinfo2, tattr);
ITypeInfo_Release(tinfo2);
}
/* read it in all cases, we need to know if we have
* NULL pointer or not.
*/
hres = xbuf_get(buf,(LPBYTE)&cookie,sizeof(cookie));
if (hres) {
ERR("Failed to load pointer cookie.\n");
return hres;
}
if (cookie != 0x42424242) {
/* we read a NULL ptr from the remote side */
if (debugout) TRACE_(olerelay)("NULL");
*arg = 0;
return S_OK;
}
if (debugout) TRACE_(olerelay)("*");
if (alloc) {
/* Allocate space for the referenced struct */
if (derefhere)
*arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,_xsize(tdesc->u.lptdesc));
}
if (derefhere)
return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, (LPDWORD)*arg, buf);
else
return deserialize_param(tinfo, readit, debugout, alloc, tdesc->u.lptdesc, arg, buf);
}
case VT_UNKNOWN:
/* FIXME: UNKNOWN is unknown ..., but allocate 4 byte for it */
if (alloc)
*arg=(DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(DWORD));
hres = S_OK;
if (readit)
hres = _unmarshal_interface(buf,&IID_IUnknown,(LPUNKNOWN*)arg);
if (debugout)
TRACE_(olerelay)("unk(%p)",arg);
return hres;
case VT_DISPATCH:
hres = S_OK;
if (readit)
hres = _unmarshal_interface(buf,&IID_IDispatch,(LPUNKNOWN*)arg);
if (debugout)
TRACE_(olerelay)("idisp(%p)",arg);
return hres;
case VT_VOID:
if (debugout) TRACE_(olerelay)("<void>");
return S_OK;
case VT_USERDEFINED: {
ITypeInfo *tinfo2;
TYPEATTR *tattr;
hres = ITypeInfo_GetRefTypeInfo(tinfo,tdesc->u.hreftype,&tinfo2);
if (hres) {
ERR("Could not get typeinfo of hreftype %x for VT_USERDEFINED.\n",tdesc->u.hreftype);
return hres;
}
hres = ITypeInfo_GetTypeAttr(tinfo2,&tattr);
if (hres) {
ERR("Could not get typeattr in VT_USERDEFINED.\n");
} else {
switch (tattr->typekind) {
case TKIND_DISPATCH:
case TKIND_INTERFACE:
if (readit)
hres = _unmarshal_interface(buf,&(tattr->guid),(LPUNKNOWN*)arg);
break;
case TKIND_RECORD: {
int i;
if (alloc)
*arg = (DWORD)HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,tattr->cbSizeInstance);
if (debugout) TRACE_(olerelay)("{");
for (i=0;i<tattr->cVars;i++) {
VARDESC *vdesc;
hres = ITypeInfo2_GetVarDesc(tinfo2, i, &vdesc);
if (hres) {
ERR("Could not get vardesc of %d\n",i);
ITypeInfo_ReleaseTypeAttr(tinfo2, tattr);
ITypeInfo_Release(tinfo2);
return hres;
}
hres = deserialize_param(
tinfo2,
readit,
debugout,
alloc,
&vdesc->elemdescVar.tdesc,
(DWORD*)(((LPBYTE)*arg)+vdesc->u.oInst),
buf
);
ITypeInfo2_ReleaseVarDesc(tinfo2, vdesc);
if (debugout && (i<tattr->cVars-1)) TRACE_(olerelay)(",");
}
if (debugout) TRACE_(olerelay)("}");
break;
}
case TKIND_ALIAS:
hres = deserialize_param(tinfo2,readit,debugout,alloc,&tattr->tdescAlias,arg,buf);
break;
case TKIND_ENUM:
if (readit) {
hres = xbuf_get(buf,(LPBYTE)arg,sizeof(DWORD));
if (hres) ERR("Failed to read enum (4 byte)\n");
}
if (debugout) TRACE_(olerelay)("%x",*arg);
break;
default:
ERR("Unhandled typekind %d\n",tattr->typekind);
hres = E_FAIL;
break;
}
ITypeInfo_ReleaseTypeAttr(tinfo2, tattr);
}
if (hres)
ERR("failed to stuballoc in TKIND_RECORD.\n");
ITypeInfo_Release(tinfo2);
return hres;
}
case VT_CARRAY: {
/* arg is pointing to the start of the array. */
ARRAYDESC *adesc = tdesc->u.lpadesc;
int arrsize,i;
arrsize = 1;
if (adesc->cDims > 1) FIXME("cDims > 1 in VT_CARRAY. Does it work?\n");
for (i=0;i<adesc->cDims;i++)
arrsize *= adesc->rgbounds[i].cElements;
for (i=0;i<arrsize;i++)
deserialize_param(
tinfo,
readit,
debugout,
alloc,
&adesc->tdescElem,
(DWORD*)((LPBYTE)(arg)+i*_xsize(&adesc->tdescElem)),
buf
);
return S_OK;
}
case VT_SAFEARRAY: {
if (readit)
{
ULONG flags = MAKELONG(MSHCTX_DIFFERENTMACHINE, NDR_LOCAL_DATA_REPRESENTATION);
unsigned char *buffer;
buffer = LPSAFEARRAY_UserUnmarshal(&flags, buf->base + buf->curoff, (LPSAFEARRAY *)arg);
buf->curoff = buffer - buf->base;
}
return S_OK;
}
default:
ERR("No handler for VT type %d!\n",tdesc->vt);
return S_OK;
}
}
}
/* Retrieves a function's funcdesc, searching back into inherited interfaces. */
static HRESULT get_funcdesc(ITypeInfo *tinfo, int iMethod, ITypeInfo **tactual, const FUNCDESC **fdesc,
BSTR *iname, BSTR *fname, UINT *num)
{
HRESULT hr;
UINT i, impl_types;
UINT inherited_funcs = 0;
TYPEATTR *attr;
if (fname) *fname = NULL;
if (iname) *iname = NULL;
if (num) *num = 0;
*tactual = NULL;
hr = ITypeInfo_GetTypeAttr(tinfo, &attr);
if (FAILED(hr))
{
ERR("GetTypeAttr failed with %x\n",hr);
return hr;
}
if(attr->typekind == TKIND_DISPATCH)
{
if(attr->wTypeFlags & TYPEFLAG_FDUAL)
{
HREFTYPE href;
ITypeInfo *tinfo2;
hr = ITypeInfo_GetRefTypeOfImplType(tinfo, -1, &href);
if(FAILED(hr))
{
ERR("Cannot get interface href from dual dispinterface\n");
ITypeInfo_ReleaseTypeAttr(tinfo, attr);
return hr;
}
hr = ITypeInfo_GetRefTypeInfo(tinfo, href, &tinfo2);
if(FAILED(hr))
{
ERR("Cannot get interface from dual dispinterface\n");
ITypeInfo_ReleaseTypeAttr(tinfo, attr);
return hr;
}
hr = get_funcdesc(tinfo2, iMethod, tactual, fdesc, iname, fname, num);
ITypeInfo_Release(tinfo2);
ITypeInfo_ReleaseTypeAttr(tinfo, attr);
return hr;
}
ERR("Shouldn't be called with a non-dual dispinterface\n");
return E_FAIL;
}
impl_types = attr->cImplTypes;
ITypeInfo_ReleaseTypeAttr(tinfo, attr);
for (i = 0; i < impl_types; i++)
{
HREFTYPE href;
ITypeInfo *pSubTypeInfo;
UINT sub_funcs;
hr = ITypeInfo_GetRefTypeOfImplType(tinfo, i, &href);
if (FAILED(hr)) return hr;
hr = ITypeInfo_GetRefTypeInfo(tinfo, href, &pSubTypeInfo);
if (FAILED(hr)) return hr;
hr = get_funcdesc(pSubTypeInfo, iMethod, tactual, fdesc, iname, fname, &sub_funcs);
inherited_funcs += sub_funcs;
ITypeInfo_Release(pSubTypeInfo);
if(SUCCEEDED(hr)) return hr;
}
if(iMethod < inherited_funcs)
{
ERR("shouldn't be here\n");
return E_INVALIDARG;
}
for(i = inherited_funcs; i <= iMethod; i++)
{
hr = ITypeInfoImpl_GetInternalFuncDesc(tinfo, i - inherited_funcs, fdesc);
if(FAILED(hr))
{
if(num) *num = i;
return hr;
}
}
/* found it. We don't care about num so zero it */
if(num) *num = 0;
*tactual = tinfo;
ITypeInfo_AddRef(*tactual);
if (fname) ITypeInfo_GetDocumentation(tinfo,(*fdesc)->memid,fname,NULL,NULL,NULL);
if (iname) ITypeInfo_GetDocumentation(tinfo,-1,iname,NULL,NULL,NULL);
return S_OK;
}
static inline BOOL is_in_elem(const ELEMDESC *elem)
{
return (elem->u.paramdesc.wParamFlags & PARAMFLAG_FIN || !elem->u.paramdesc.wParamFlags);
}
static inline BOOL is_out_elem(const ELEMDESC *elem)
{
return (elem->u.paramdesc.wParamFlags & PARAMFLAG_FOUT || !elem->u.paramdesc.wParamFlags);
}
static DWORD
xCall(LPVOID retptr, int method, TMProxyImpl *tpinfo /*, args */)
{
DWORD *args = ((DWORD*)&tpinfo)+1, *xargs;
const FUNCDESC *fdesc;
HRESULT hres;
int i, relaydeb = TRACE_ON(olerelay);
marshal_state buf;
RPCOLEMESSAGE msg;
ULONG status;
BSTR fname,iname;
BSTR names[10];
UINT nrofnames;
DWORD remoteresult = 0;
ITypeInfo *tinfo;
IRpcChannelBuffer *chanbuf;
EnterCriticalSection(&tpinfo->crit);
hres = get_funcdesc(tpinfo->tinfo,method,&tinfo,&fdesc,&iname,&fname,NULL);
if (hres) {
ERR("Did not find typeinfo/funcdesc entry for method %d!\n",method);
LeaveCriticalSection(&tpinfo->crit);
return E_FAIL;
}
if (!tpinfo->chanbuf)
{
WARN("Tried to use disconnected proxy\n");
ITypeInfo_Release(tinfo);
LeaveCriticalSection(&tpinfo->crit);
return RPC_E_DISCONNECTED;
}
chanbuf = tpinfo->chanbuf;
IRpcChannelBuffer_AddRef(chanbuf);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -