ReactOS 0.4.15-dev-7924-g5949c20
tools.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Spooler Router
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Miscellaneous tool functions
5 * COPYRIGHT: Copyright 2015-2017 Colin Finck (colin@reactos.org)
6 */
7
8#include "precomp.h"
9
10
39PackStrings(PCWSTR* pSource, PBYTE pDest, const DWORD* DestOffsets, PBYTE pEnd)
40{
41 DWORD cbString;
42 ULONG_PTR StringAddress;
43
44 // Loop until we reach an element with offset set to MAXDWORD.
45 while (*DestOffsets != MAXDWORD)
46 {
47 StringAddress = 0;
48
49 if (*pSource)
50 {
51 // Determine the length of the source string.
52 cbString = (wcslen(*pSource) + 1) * sizeof(WCHAR);
53
54 // Copy it before the last string.
55 pEnd -= cbString;
56 StringAddress = (ULONG_PTR)pEnd;
57 CopyMemory(pEnd, *pSource, cbString);
58 }
59
60 // Copy the address of the copied string to the location given by the offset.
61 CopyMemory(&pDest[*DestOffsets], &StringAddress, sizeof(ULONG_PTR));
62
63 // Advance to the next source string and destination offset.
64 pSource++;
65 DestOffsets++;
66 }
67
68 // pEnd is now at the last string we copied. Return this value as a pointer to the beginning of all strings in the output buffer.
69 return pEnd;
70}
PBYTE WINAPI PackStrings(PCWSTR *pSource, PBYTE pDest, const DWORD *DestOffsets, PBYTE pEnd)
Definition: tools.c:39
#define ULONG_PTR
Definition: config.h:101
unsigned long DWORD
Definition: ntddk_ex.h:95
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define MAXDWORD
BYTE * PBYTE
Definition: pedump.c:66
const uint16_t * PCWSTR
Definition: typedefs.h:57
uint32_t ULONG_PTR
Definition: typedefs.h:65
#define CopyMemory
Definition: winbase.h:1710
#define WINAPI
Definition: msvc.h:6
__wchar_t WCHAR
Definition: xmlstorage.h:180