ReactOS 0.4.15-dev-7961-gdcf9eb0
ntverrsrc.c File Reference
#include "precomp.h"
#include <ndk/ldrtypes.h>
#include <ndk/ldrfuncs.h>
#include "ntverrsrc.h"
#include <debug.h>
Include dependency graph for ntverrsrc.c:

Go to the source code of this file.

Classes

struct  _VS_VERSION_INFO_STRUCT32
 

Macros

#define NDEBUG
 
#define VS_VERSION_INFO   1
 
#define VS_FILE_INFO   RT_VERSION
 
#define DWORD_ALIGN(base, ptr)    ( (ULONG_PTR)(base) + ((((ULONG_PTR)(ptr) - (ULONG_PTR)(base)) + 3) & ~3) )
 
#define VersionInfo32_Value(ver)    DWORD_ALIGN( (ver), (ver)->szKey + wcslen((ver)->szKey) + 1 )
 
#define VersionInfo32_Children(ver)
 
#define VersionInfo32_Next(ver)    (PVS_VERSION_INFO_STRUCT32)( (ULONG_PTR)ver + (((ver)->wLength + 3) & ~3) )
 

Typedefs

typedef struct _VS_VERSION_INFO_STRUCT32 VS_VERSION_INFO_STRUCT32
 
typedef struct _VS_VERSION_INFO_STRUCT32PVS_VERSION_INFO_STRUCT32
 
typedef const VS_VERSION_INFO_STRUCT32PCVS_VERSION_INFO_STRUCT32
 

Functions

NTSTATUS NtGetVersionResource (IN PVOID BaseAddress, OUT PVOID *Resource, OUT PULONG ResourceSize OPTIONAL)
 
static PCVS_VERSION_INFO_STRUCT32 VersionInfo32_FindChild (IN PCVS_VERSION_INFO_STRUCT32 info, IN PCWSTR szKey, IN UINT cchKey)
 
static NTSTATUS VersionInfo32_QueryValue (IN PCVS_VERSION_INFO_STRUCT32 info, IN PCWSTR lpSubBlock, OUT PVOID *lplpBuffer, OUT PUINT puLen OPTIONAL, OUT BOOL *pbText OPTIONAL)
 
NTSTATUS NtVerQueryValue (IN const VOID *pBlock, IN PCWSTR lpSubBlock, OUT PVOID *lplpBuffer, OUT PUINT puLen)
 

Macro Definition Documentation

◆ DWORD_ALIGN

#define DWORD_ALIGN (   base,
  ptr 
)     ( (ULONG_PTR)(base) + ((((ULONG_PTR)(ptr) - (ULONG_PTR)(base)) + 3) & ~3) )

Definition at line 89 of file ntverrsrc.c.

◆ NDEBUG

#define NDEBUG

Definition at line 19 of file ntverrsrc.c.

◆ VersionInfo32_Children

#define VersionInfo32_Children (   ver)
Value:
( ( (ver)->wValueLength * \
((ver)->wType? 2 : 1) + 3 ) & ~3 ) )
const VS_VERSION_INFO_STRUCT32 * PCVS_VERSION_INFO_STRUCT32
Definition: ntverrsrc.c:87
#define VersionInfo32_Value(ver)
Definition: ntverrsrc.c:92

Definition at line 95 of file ntverrsrc.c.

◆ VersionInfo32_Next

#define VersionInfo32_Next (   ver)     (PVS_VERSION_INFO_STRUCT32)( (ULONG_PTR)ver + (((ver)->wLength + 3) & ~3) )

Definition at line 100 of file ntverrsrc.c.

◆ VersionInfo32_Value

#define VersionInfo32_Value (   ver)     DWORD_ALIGN( (ver), (ver)->szKey + wcslen((ver)->szKey) + 1 )

Definition at line 92 of file ntverrsrc.c.

◆ VS_FILE_INFO

#define VS_FILE_INFO   RT_VERSION

◆ VS_VERSION_INFO

#define VS_VERSION_INFO   1

Typedef Documentation

◆ PCVS_VERSION_INFO_STRUCT32

◆ PVS_VERSION_INFO_STRUCT32

◆ VS_VERSION_INFO_STRUCT32

Function Documentation

◆ NtGetVersionResource()

NTSTATUS NtGetVersionResource ( IN PVOID  BaseAddress,
OUT PVOID Resource,
OUT PULONG ResourceSize  OPTIONAL 
)

Definition at line 26 of file ntverrsrc.c.

30{
31// #define RT_VERSION MAKEINTRESOURCE(16) // See winuser.h
32#define VS_VERSION_INFO 1 // See psdk/verrsrc.h
33#define VS_FILE_INFO RT_VERSION
34
36 LDR_RESOURCE_INFO ResourceInfo;
37 PIMAGE_RESOURCE_DATA_ENTRY ResourceDataEntry;
38 PVOID Data = NULL;
39 ULONG Size = 0;
40
41 /* Try to find the resource */
42 ResourceInfo.Type = 16; // RT_VERSION;
43 ResourceInfo.Name = VS_VERSION_INFO; // MAKEINTRESOURCEW(VS_VERSION_INFO);
44 ResourceInfo.Language = 0; // Don't care about the language
45
47 &ResourceInfo,
49 &ResourceDataEntry);
50 if (!NT_SUCCESS(Status))
51 {
52 DPRINT1("NtGetVersionResource: Version resource not found, Status 0x%08lx\n", Status);
53 return Status;
54 }
55
56 /* Access the resource */
58 ResourceDataEntry,
59 &Data,
60 &Size);
61 if (!NT_SUCCESS(Status))
62 {
63 DPRINT1("NtGetVersionResource: Cannot access Version resource, Status 0x%08lx\n", Status);
64 return Status;
65 }
66
67 *Resource = Data;
68 if (ResourceSize) *ResourceSize = Size;
69
70 return STATUS_SUCCESS;
71}
LONG NTSTATUS
Definition: precomp.h:26
#define DPRINT1
Definition: precomp.h:8
_Acquires_exclusive_lock_ Resource _Acquires_shared_lock_ Resource _Inout_ PERESOURCE Resource
Definition: cdprocs.h:843
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:25
NTSTATUS NTAPI LdrAccessResource(_In_ PVOID BaseAddress, _In_ PIMAGE_RESOURCE_DATA_ENTRY ResourceDataEntry, _Out_opt_ PVOID *Resource, _Out_opt_ PULONG Size)
NTSTATUS NTAPI LdrFindResource_U(_In_ PVOID BaseAddress, _In_ PLDR_RESOURCE_INFO ResourceInfo, _In_ ULONG Level, _Out_ PIMAGE_RESOURCE_DATA_ENTRY *ResourceDataEntry)
#define RESOURCE_DATA_LEVEL
Definition: ldrtypes.h:33
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define VS_VERSION_INFO
#define STATUS_SUCCESS
Definition: shellext.h:65
Definition: pedump.c:458
ULONG_PTR Language
Definition: ldrtypes.h:183
ULONG_PTR Name
Definition: ldrtypes.h:182
ULONG_PTR Type
Definition: ldrtypes.h:181
uint32_t ULONG
Definition: typedefs.h:59
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533

Referenced by CheckForValidPEAndVendor().

◆ NtVerQueryValue()

NTSTATUS NtVerQueryValue ( IN const VOID pBlock,
IN PCWSTR  lpSubBlock,
OUT PVOID lplpBuffer,
OUT PUINT  puLen 
)

Definition at line 174 of file ntverrsrc.c.

179{
181
182 DPRINT("%s (%p, %S, %p, %p)\n", __FUNCTION__, pBlock, lpSubBlock, lplpBuffer, puLen);
183
184 if (!pBlock)
185 return FALSE;
186
187 if (!lpSubBlock || !*lpSubBlock)
188 lpSubBlock = L"\\";
189
190 return VersionInfo32_QueryValue(info, lpSubBlock, lplpBuffer, puLen, NULL);
191}
#define FALSE
Definition: types.h:117
#define __FUNCTION__
Definition: types.h:116
#define L(x)
Definition: ntvdm.h:50
static NTSTATUS VersionInfo32_QueryValue(IN PCVS_VERSION_INFO_STRUCT32 info, IN PCWSTR lpSubBlock, OUT PVOID *lplpBuffer, OUT PUINT puLen OPTIONAL, OUT BOOL *pbText OPTIONAL)
Definition: ntverrsrc.c:124
#define DPRINT
Definition: sndvol32.h:71

Referenced by CheckForValidPEAndVendor().

◆ VersionInfo32_FindChild()

static PCVS_VERSION_INFO_STRUCT32 VersionInfo32_FindChild ( IN PCVS_VERSION_INFO_STRUCT32  info,
IN PCWSTR  szKey,
IN UINT  cchKey 
)
static

Definition at line 104 of file ntverrsrc.c.

108{
110
111 while ((ULONG_PTR)child < (ULONG_PTR)info + info->wLength)
112 {
113 if (!_wcsnicmp(child->szKey, szKey, cchKey) && !child->szKey[cchKey])
114 return child;
115
116 if (child->wLength == 0) return NULL;
118 }
119
120 return NULL;
121}
static HWND child
Definition: cursoricon.c:298
#define VersionInfo32_Next(ver)
Definition: ntverrsrc.c:100
#define VersionInfo32_Children(ver)
Definition: ntverrsrc.c:95
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
uint32_t ULONG_PTR
Definition: typedefs.h:65

Referenced by VersionInfo32_QueryValue().

◆ VersionInfo32_QueryValue()

static NTSTATUS VersionInfo32_QueryValue ( IN PCVS_VERSION_INFO_STRUCT32  info,
IN PCWSTR  lpSubBlock,
OUT PVOID lplpBuffer,
OUT PUINT puLen  OPTIONAL,
OUT BOOL *pbText  OPTIONAL 
)
static

Definition at line 124 of file ntverrsrc.c.

130{
131 PCWSTR lpNextSlash;
132
133 DPRINT("lpSubBlock : (%S)\n", lpSubBlock);
134
135 while (*lpSubBlock)
136 {
137 /* Find next path component */
138 for (lpNextSlash = lpSubBlock; *lpNextSlash; lpNextSlash++)
139 {
140 if (*lpNextSlash == '\\')
141 break;
142 }
143
144 /* Skip empty components */
145 if (lpNextSlash == lpSubBlock)
146 {
147 lpSubBlock++;
148 continue;
149 }
150
151 /* We have a non-empty component: search info for key */
152 info = VersionInfo32_FindChild(info, lpSubBlock, lpNextSlash - lpSubBlock);
153 if (!info)
154 {
155 if (puLen) *puLen = 0;
157 }
158
159 /* Skip path component */
160 lpSubBlock = lpNextSlash;
161 }
162
163 /* Return value */
164 *lplpBuffer = (PVOID)VersionInfo32_Value(info);
165 if (puLen)
166 *puLen = info->wValueLength;
167 if (pbText)
168 *pbText = info->wType;
169
170 return STATUS_SUCCESS;
171}
#define STATUS_RESOURCE_TYPE_NOT_FOUND
Definition: ntstatus.h:374
static PCVS_VERSION_INFO_STRUCT32 VersionInfo32_FindChild(IN PCVS_VERSION_INFO_STRUCT32 info, IN PCWSTR szKey, IN UINT cchKey)
Definition: ntverrsrc.c:104
const uint16_t * PCWSTR
Definition: typedefs.h:57
void * PVOID
Definition: typedefs.h:50

Referenced by NtVerQueryValue().