⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ndr_marshall.c

📁 这是一个开放源代码的与WINNT/WIN2K/WIN2003兼容的操作系统
💻 C
📖 第 1 页 / 共 5 页
字号:
                                      PFORMAT_STRING pFormat){  unsigned long Offset = pStubMsg->Offset;  unsigned ofs, rep, count, stride, xofs;  unsigned i;  ULONG saved_buffer_length = 0;  TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);  if (pStubMsg->IgnoreEmbeddedPointers) return;  if (*pFormat != RPC_FC_PP) return;  pFormat += 2;  if (pStubMsg->PointerLength)  {    saved_buffer_length = pStubMsg->BufferLength;    pStubMsg->BufferLength = pStubMsg->PointerLength;    pStubMsg->PointerLength = 0;  }  while (pFormat[0] != RPC_FC_END) {    switch (pFormat[0]) {    default:      FIXME("unknown repeat type %d\n", pFormat[0]);    case RPC_FC_NO_REPEAT:      rep = 1;      stride = 0;      ofs = 0;      count = 1;      xofs = 0;      pFormat += 2;      break;    case RPC_FC_FIXED_REPEAT:      rep = *(const WORD*)&pFormat[2];      stride = *(const WORD*)&pFormat[4];      ofs = *(const WORD*)&pFormat[6];      count = *(const WORD*)&pFormat[8];      xofs = 0;      pFormat += 10;      break;    case RPC_FC_VARIABLE_REPEAT:      rep = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? pStubMsg->ActualCount : pStubMsg->MaxCount;      stride = *(const WORD*)&pFormat[2];      ofs = *(const WORD*)&pFormat[4];      count = *(const WORD*)&pFormat[6];      xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;      pFormat += 8;      break;    }    for (i = 0; i < rep; i++) {      PFORMAT_STRING info = pFormat;      unsigned char *membase = pMemory + ofs + (i * stride);      unsigned u;      for (u=0; u<count; u++,info+=8) {        unsigned char *memptr = membase + *(const SHORT*)&info[0];        unsigned char *saved_memory = pStubMsg->Memory;        pStubMsg->Memory = pMemory;        PointerBufferSize(pStubMsg, *(unsigned char**)memptr, info+4);        pStubMsg->Memory = saved_memory;      }    }    pFormat += 8 * count;  }  if (saved_buffer_length)  {    pStubMsg->PointerLength = pStubMsg->BufferLength;    pStubMsg->BufferLength = saved_buffer_length;  }}/*********************************************************************** *           EmbeddedPointerMemorySize [internal] */static unsigned long EmbeddedPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,                                               PFORMAT_STRING pFormat){  unsigned long Offset = pStubMsg->Offset;  unsigned char *Mark = pStubMsg->BufferMark;  unsigned ofs, rep, count, stride, xofs;  unsigned i;  TRACE("(%p,%p)\n", pStubMsg, pFormat);  if (pStubMsg->IgnoreEmbeddedPointers) return 0;  FIXME("(%p,%p): stub\n", pStubMsg, pFormat);  if (*pFormat != RPC_FC_PP) return 0;  pFormat += 2;  while (pFormat[0] != RPC_FC_END) {    switch (pFormat[0]) {    default:      FIXME("unknown repeat type %d\n", pFormat[0]);    case RPC_FC_NO_REPEAT:      rep = 1;      stride = 0;      ofs = 0;      count = 1;      xofs = 0;      pFormat += 2;      break;    case RPC_FC_FIXED_REPEAT:      rep = *(const WORD*)&pFormat[2];      stride = *(const WORD*)&pFormat[4];      ofs = *(const WORD*)&pFormat[6];      count = *(const WORD*)&pFormat[8];      xofs = 0;      pFormat += 10;      break;    case RPC_FC_VARIABLE_REPEAT:      rep = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? pStubMsg->ActualCount : pStubMsg->MaxCount;      stride = *(const WORD*)&pFormat[2];      ofs = *(const WORD*)&pFormat[4];      count = *(const WORD*)&pFormat[6];      xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;      pFormat += 8;      break;    }    /* ofs doesn't seem to matter in this context */    for (i = 0; i < rep; i++) {      PFORMAT_STRING info = pFormat;      unsigned char *bufbase = Mark + ofs + (i * stride);      unsigned u;      for (u=0; u<count; u++,info+=8) {        unsigned char *bufptr = bufbase + *(const SHORT*)&info[2];        PointerMemorySize(pStubMsg, bufptr, info+4);      }    }    pFormat += 8 * count;  }  return 0;}/*********************************************************************** *           EmbeddedPointerFree [internal] */static void EmbeddedPointerFree(PMIDL_STUB_MESSAGE pStubMsg,                                unsigned char *pMemory,                                PFORMAT_STRING pFormat){  unsigned long Offset = pStubMsg->Offset;  unsigned ofs, rep, count, stride, xofs;  unsigned i;  TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);  if (*pFormat != RPC_FC_PP) return;  pFormat += 2;  while (pFormat[0] != RPC_FC_END) {    switch (pFormat[0]) {    default:      FIXME("unknown repeat type %d\n", pFormat[0]);    case RPC_FC_NO_REPEAT:      rep = 1;      stride = 0;      ofs = 0;      count = 1;      xofs = 0;      pFormat += 2;      break;    case RPC_FC_FIXED_REPEAT:      rep = *(const WORD*)&pFormat[2];      stride = *(const WORD*)&pFormat[4];      ofs = *(const WORD*)&pFormat[6];      count = *(const WORD*)&pFormat[8];      xofs = 0;      pFormat += 10;      break;    case RPC_FC_VARIABLE_REPEAT:      rep = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? pStubMsg->ActualCount : pStubMsg->MaxCount;      stride = *(const WORD*)&pFormat[2];      ofs = *(const WORD*)&pFormat[4];      count = *(const WORD*)&pFormat[6];      xofs = (pFormat[1] == RPC_FC_VARIABLE_OFFSET) ? Offset * stride : 0;      pFormat += 8;      break;    }    for (i = 0; i < rep; i++) {      PFORMAT_STRING info = pFormat;      unsigned char *membase = pMemory + (i * stride);      unsigned u;      for (u=0; u<count; u++,info+=8) {        unsigned char *memptr = membase + *(const SHORT*)&info[0];        unsigned char *saved_memory = pStubMsg->Memory;        pStubMsg->Memory = pMemory;        PointerFree(pStubMsg, *(unsigned char**)memptr, info+4);        pStubMsg->Memory = saved_memory;      }    }    pFormat += 8 * count;  }}/*********************************************************************** *           NdrPointerMarshall [RPCRT4.@] */unsigned char * WINAPI NdrPointerMarshall(PMIDL_STUB_MESSAGE pStubMsg,                                          unsigned char *pMemory,                                          PFORMAT_STRING pFormat){  unsigned char *Buffer;  TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);  /* incremement the buffer here instead of in PointerMarshall,   * as that is used by embedded pointers which already handle the incrementing   * the buffer, and shouldn't write any additional pointer data to the wire */  if (*pFormat != RPC_FC_RP)  {    ALIGN_POINTER(pStubMsg->Buffer, 4);    Buffer = pStubMsg->Buffer;    pStubMsg->Buffer += 4;  }  else    Buffer = pStubMsg->Buffer;  PointerMarshall(pStubMsg, Buffer, pMemory, pFormat);  STD_OVERFLOW_CHECK(pStubMsg);  return NULL;}/*********************************************************************** *           NdrPointerUnmarshall [RPCRT4.@] */unsigned char * WINAPI NdrPointerUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,                                            unsigned char **ppMemory,                                            PFORMAT_STRING pFormat,                                            unsigned char fMustAlloc){  unsigned char *Buffer;  TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);  /* incremement the buffer here instead of in PointerUnmarshall,   * as that is used by embedded pointers which already handle the incrementing   * the buffer, and shouldn't read any additional pointer data from the   * buffer */  if (*pFormat != RPC_FC_RP)  {    ALIGN_POINTER(pStubMsg->Buffer, 4);    Buffer = pStubMsg->Buffer;    pStubMsg->Buffer += 4;  }  else    Buffer = pStubMsg->Buffer;  PointerUnmarshall(pStubMsg, Buffer, ppMemory, pFormat, fMustAlloc);  return NULL;}/*********************************************************************** *           NdrPointerBufferSize [RPCRT4.@] */void WINAPI NdrPointerBufferSize(PMIDL_STUB_MESSAGE pStubMsg,                                      unsigned char *pMemory,                                      PFORMAT_STRING pFormat){  TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);  /* incremement the buffer length here instead of in PointerBufferSize,   * as that is used by embedded pointers which already handle the buffer   * length, and shouldn't write anything more to the wire */  if (*pFormat != RPC_FC_RP)  {    ALIGN_LENGTH(pStubMsg->BufferLength, 4);    pStubMsg->BufferLength += 4;  }  PointerBufferSize(pStubMsg, pMemory, pFormat);}/*********************************************************************** *           NdrPointerMemorySize [RPCRT4.@] */ULONG WINAPI NdrPointerMemorySize(PMIDL_STUB_MESSAGE pStubMsg,                                  PFORMAT_STRING pFormat){  /* unsigned size = *(LPWORD)(pFormat+2); */  FIXME("(%p,%p): stub\n", pStubMsg, pFormat);  PointerMemorySize(pStubMsg, pStubMsg->Buffer, pFormat);  return 0;}/*********************************************************************** *           NdrPointerFree [RPCRT4.@] */void WINAPI NdrPointerFree(PMIDL_STUB_MESSAGE pStubMsg,                           unsigned char *pMemory,                           PFORMAT_STRING pFormat){  TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);  PointerFree(pStubMsg, pMemory, pFormat);}/*********************************************************************** *           NdrSimpleTypeMarshall [RPCRT4.@] */void WINAPI NdrSimpleTypeMarshall( PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory,                                   unsigned char FormatChar ){    NdrBaseTypeMarshall(pStubMsg, pMemory, &FormatChar);}/*********************************************************************** *           NdrSimpleTypeUnmarshall [RPCRT4.@] */void WINAPI NdrSimpleTypeUnmarshall( PMIDL_STUB_MESSAGE pStubMsg, unsigned char* pMemory,                                     unsigned char FormatChar ){    NdrBaseTypeUnmarshall(pStubMsg, &pMemory, &FormatChar, 0);}/*********************************************************************** *           NdrSimpleStructMarshall [RPCRT4.@] */unsigned char * WINAPI NdrSimpleStructMarshall(PMIDL_STUB_MESSAGE pStubMsg,                                               unsigned char *pMemory,                                               PFORMAT_STRING pFormat){  unsigned size = *(const WORD*)(pFormat+2);  TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);  ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);  memcpy(pStubMsg->Buffer, pMemory, size);  pStubMsg->BufferMark = pStubMsg->Buffer;  pStubMsg->Buffer += size;  if (pFormat[0] != RPC_FC_STRUCT)    EmbeddedPointerMarshall(pStubMsg, pMemory, pFormat+4);  STD_OVERFLOW_CHECK(pStubMsg);  return NULL;}/*********************************************************************** *           NdrSimpleStructUnmarshall [RPCRT4.@] */unsigned char * WINAPI NdrSimpleStructUnmarshall(PMIDL_STUB_MESSAGE pStubMsg,                                                 unsigned char **ppMemory,                                                 PFORMAT_STRING pFormat,                                                 unsigned char fMustAlloc){  unsigned size = *(const WORD*)(pFormat+2);  TRACE("(%p,%p,%p,%d)\n", pStubMsg, ppMemory, pFormat, fMustAlloc);  ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);  if (fMustAlloc) {    *ppMemory = NdrAllocate(pStubMsg, size);    memcpy(*ppMemory, pStubMsg->Buffer, size);  } else {    if (!pStubMsg->IsClient && !*ppMemory)      /* for servers, we just point straight into the RPC buffer */      *ppMemory = pStubMsg->Buffer;    else      /* for clients, memory should be provided by caller */      memcpy(*ppMemory, pStubMsg->Buffer, size);  }  pStubMsg->BufferMark = pStubMsg->Buffer;  pStubMsg->Buffer += size;  if (pFormat[0] != RPC_FC_STRUCT)    EmbeddedPointerUnmarshall(pStubMsg, ppMemory, pFormat+4, fMustAlloc);  return NULL;}/*********************************************************************** *           NdrSimpleStructBufferSize [RPCRT4.@] */void WINAPI NdrSimpleStructBufferSize(PMIDL_STUB_MESSAGE pStubMsg,                                      unsigned char *pMemory,                                      PFORMAT_STRING pFormat){  unsigned size = *(const WORD*)(pFormat+2);  TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);  ALIGN_LENGTH(pStubMsg->BufferLength, pFormat[1] + 1);  pStubMsg->BufferLength += size;  if (pFormat[0] != RPC_FC_STRUCT)    EmbeddedPointerBufferSize(pStubMsg, pMemory, pFormat+4);}/*********************************************************************** *           NdrSimpleStructMemorySize [RPCRT4.@] */ULONG WINAPI NdrSimpleStructMemorySize(PMIDL_STUB_MESSAGE pStubMsg,                                       PFORMAT_STRING pFormat){  unsigned short size = *(const WORD *)(pFormat+2);  TRACE("(%p,%p)\n", pStubMsg, pFormat);  ALIGN_POINTER(pStubMsg->Buffer, pFormat[1] + 1);  pStubMsg->MemorySize += size;  pStubMsg->Buffer += size;  if (pFormat[0] != RPC_FC_STRUCT)    EmbeddedPointerMemorySize(pStubMsg, pFormat+4);  return size;}/*********************************************************************** *           NdrSimpleStructFree [RPCRT4.@] */void WINAPI NdrSimpleStructFree(PMIDL_STUB_MESSAGE pStubMsg,                                unsigned char *pMemory,                                PFORMAT_STRING pFormat){  TRACE("(%p,%p,%p)\n", pStubMsg, pMemory, pFormat);  if (pFormat[0] != RPC_FC_STRUCT)    EmbeddedPointerFree(pStubMsg, pMemory, pFormat+4);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -