ReactOS 0.4.15-dev-7958-gcd0bb1a
fxtelemetry.cpp File Reference
#include "fxsupportpch.hpp"
#include "fxldr.h"
#include <ntstrsafe.h>
Include dependency graph for fxtelemetry.cpp:

Go to the source code of this file.

Functions

VOID GetNameFromPath (_In_ PCUNICODE_STRING Path, _Out_ PUNICODE_STRING Name)
 

Function Documentation

◆ GetNameFromPath()

VOID GetNameFromPath ( _In_ PCUNICODE_STRING  Path,
_Out_ PUNICODE_STRING  Name 
)

Definition at line 54 of file fxtelemetry.cpp.

78{
79 BOOLEAN foundSlash;
80
81 ASSERT(Path != NULL);
82
83 //
84 // Ideally a check of Path->Length == 0 would be sufficient except that
85 // PreFAST thinks that Length can be odd, so it thinks Length == 1 is possible.
86 // Comparing Length < sizeof(WCHAR) satisfies PreFAST and keeps the logic
87 // at runtime correct.
88 //
89 if (Path->Length < sizeof(WCHAR)) {
91 return;
92 }
93
94 //
95 // Initialize Name to point to the last WCHAR of the buffer and we will work
96 // our way backwards to the beginning of the string or a \
97 //
98
99 Name->Buffer = WDF_PTR_ADD_OFFSET_TYPE(Path->Buffer,
100 Path->Length - sizeof(WCHAR),
101 PWCH);
102 Name->Length = sizeof(WCHAR);
103 foundSlash = FALSE;
104
105 while (Name->Buffer >= Path->Buffer) {
106 if (*Name->Buffer == L'\\') {
107 //
108 // Skip the \ in the buffer moving forward a character and adjusting
109 // the length
110 //
111 foundSlash = TRUE;
112 Name->Buffer++;
113 Name->Length -= sizeof(WCHAR);
114 break;
115 }
116
117 //
118 // Move backwards in the string
119 //
120 Name->Buffer--;
121 Name->Length += sizeof(WCHAR);
122 }
123
124 if (foundSlash && Name->Length == 0) {
125 //
126 // Handle the case where a slash was found and it is the only character
127 //
128 Name->Buffer = NULL;
129 }
130 else if (foundSlash == FALSE) {
131 //
132 // Handle the case where no slash was found. In this case, Name->Buffer
133 // points to one WCHAR before the beginning of the string.
134 //
135 Name->Length -= sizeof(WCHAR);
136 Name->Buffer++;
137 }
138
139 //
140 // Need to set MaximumLength to the same value as Length so that the struct
141 // format is valid.
142 //
143 Name->MaximumLength = Name->Length;
144}
unsigned char BOOLEAN
PRTL_UNICODE_STRING_BUFFER Path
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ASSERT(a)
Definition: mode.c:44
WCHAR * PWCH
Definition: ntbasedef.h:410
#define L(x)
Definition: ntvdm.h:50
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
#define WDF_PTR_ADD_OFFSET_TYPE(_ptr, _offset, _type)
Definition: wdfcore.h:141
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by FxLibraryCommonRegisterClient(), and GetImageName().