Author: hbelusca
Date: Sun May 21 23:41:04 2017
New Revision: 74618
URL:
http://svn.reactos.org/svn/reactos?rev=74618&view=rev
Log:
[USETUP]: Move all the code that retrieves the version resources from PE executable, out
of osdetect.c, and place it in its own module inside the setuplib.
Remove also some commented headers in precomp.h.
Added:
branches/setup_improvements/base/setup/lib/ntverrsrc.c (with props)
branches/setup_improvements/base/setup/lib/ntverrsrc.h (with props)
Modified:
branches/setup_improvements/base/setup/lib/CMakeLists.txt
branches/setup_improvements/base/setup/lib/precomp.h
branches/setup_improvements/base/setup/lib/setuplib.h
branches/setup_improvements/base/setup/usetup/osdetect.c
Modified: branches/setup_improvements/base/setup/lib/CMakeLists.txt
URL:
http://svn.reactos.org/svn/reactos/branches/setup_improvements/base/setup/l…
==============================================================================
--- branches/setup_improvements/base/setup/lib/CMakeLists.txt [iso-8859-1] (original)
+++ branches/setup_improvements/base/setup/lib/CMakeLists.txt [iso-8859-1] Sun May 21
23:41:04 2017
@@ -2,6 +2,7 @@
list(APPEND SOURCE
fsutil.c
genlist.c
+ ntverrsrc.c
partlist.c
precomp.h)
Added: branches/setup_improvements/base/setup/lib/ntverrsrc.c
URL:
http://svn.reactos.org/svn/reactos/branches/setup_improvements/base/setup/l…
==============================================================================
--- branches/setup_improvements/base/setup/lib/ntverrsrc.c (added)
+++ branches/setup_improvements/base/setup/lib/ntverrsrc.c [iso-8859-1] Sun May 21
23:41:04 2017
@@ -0,0 +1,194 @@
+/*
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS text-mode setup
+ * FILE: base/setup/lib/ntverrsrc.c
+ * PURPOSE: NT Version Resource Management API
+ * PROGRAMMER: Hermes Belusca-Maito (hermes.belusca(a)sfr.fr)
+ *
+ * NOTE 1: Adapted from Wine-synced dll/win32/version DLL.
+ * NOTE 2: We only deal with 32-bit PE executables.
+ */
+
+/* INCLUDES *****************************************************************/
+
+#include "precomp.h"
+#include <ndk/ldrtypes.h>
+#include <ndk/ldrfuncs.h>
+
+#include "ntverrsrc.h"
+
+#define NDEBUG
+#include <debug.h>
+
+
+/* FUNCTIONS ****************************************************************/
+
+NTSTATUS
+NtGetVersionResource(
+ IN PVOID BaseAddress,
+ OUT PVOID* Resource,
+ OUT PULONG ResourceSize OPTIONAL)
+{
+// #define RT_VERSION MAKEINTRESOURCE(16) // See winuser.h
+#define VS_VERSION_INFO 1 // See psdk/verrsrc.h
+#define VS_FILE_INFO RT_VERSION
+
+ NTSTATUS Status;
+ LDR_RESOURCE_INFO ResourceInfo;
+ PIMAGE_RESOURCE_DATA_ENTRY ResourceDataEntry;
+ PVOID Data = NULL;
+ ULONG Size = 0;
+
+ /* Try to find the resource */
+ ResourceInfo.Type = 16; // RT_VERSION;
+ ResourceInfo.Name = VS_VERSION_INFO; // MAKEINTRESOURCEW(VS_VERSION_INFO);
+ ResourceInfo.Language = 0; // Don't care about the language
+
+ Status = LdrFindResource_U(BaseAddress,
+ &ResourceInfo,
+ RESOURCE_DATA_LEVEL,
+ &ResourceDataEntry);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("NtGetVersionResource: Version resource not found, Status
0x%08lx\n", Status);
+ return Status;
+ }
+
+ /* Access the resource */
+ Status = LdrAccessResource(BaseAddress,
+ ResourceDataEntry,
+ &Data,
+ &Size);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("NtGetVersionResource: Cannot access Version resource, Status
0x%08lx\n", Status);
+ return Status;
+ }
+
+ *Resource = Data;
+ if (ResourceSize) *ResourceSize = Size;
+
+ return STATUS_SUCCESS;
+}
+
+/* NOTE: the xxx_STRUCT16 version differs by storing strings in ANSI, not in UNICODE */
+typedef struct _VS_VERSION_INFO_STRUCT32
+{
+ WORD wLength;
+ WORD wValueLength;
+ WORD wType; /* 1:Text, 0:Binary */
+ WCHAR szKey[1];
+#if 0 /* variable length structure */
+ /* DWORD aligned */
+ BYTE Value[];
+ /* DWORD aligned */
+ VS_VERSION_INFO_STRUCT32 Children[];
+#endif
+} VS_VERSION_INFO_STRUCT32, *PVS_VERSION_INFO_STRUCT32;
+typedef const VS_VERSION_INFO_STRUCT32 *PCVS_VERSION_INFO_STRUCT32;
+
+#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 ) \
+ (PCVS_VERSION_INFO_STRUCT32)( VersionInfo32_Value( ver ) + \
+ ( ( (ver)->wValueLength * \
+ ((ver)->wType? 2 : 1) + 3 ) & ~3 ) )
+
+#define VersionInfo32_Next( ver ) \
+ (PVS_VERSION_INFO_STRUCT32)( (ULONG_PTR)ver + (((ver)->wLength + 3) & ~3) )
+
+static PCVS_VERSION_INFO_STRUCT32
+VersionInfo32_FindChild(
+ IN PCVS_VERSION_INFO_STRUCT32 info,
+ IN PCWSTR szKey,
+ IN UINT cbKey)
+{
+ PCVS_VERSION_INFO_STRUCT32 child = VersionInfo32_Children(info);
+
+ while ((ULONG_PTR)child < (ULONG_PTR)info + info->wLength)
+ {
+ if (!_wcsnicmp(child->szKey, szKey, cbKey) &&
!child->szKey[cbKey])
+ return child;
+
+ if (child->wLength == 0) return NULL;
+ child = VersionInfo32_Next(child);
+ }
+
+ return NULL;
+}
+
+static NTSTATUS
+VersionInfo32_QueryValue(
+ IN PCVS_VERSION_INFO_STRUCT32 info,
+ IN PCWSTR lpSubBlock,
+ OUT PVOID* lplpBuffer,
+ OUT PUINT puLen OPTIONAL,
+ OUT BOOL* pbText OPTIONAL)
+{
+ PCWSTR lpNextSlash;
+
+ DPRINT("lpSubBlock : (%S)\n", lpSubBlock);
+
+ while (*lpSubBlock)
+ {
+ /* Find next path component */
+ for (lpNextSlash = lpSubBlock; *lpNextSlash; lpNextSlash++)
+ {
+ if (*lpNextSlash == '\\')
+ break;
+ }
+
+ /* Skip empty components */
+ if (lpNextSlash == lpSubBlock)
+ {
+ lpSubBlock++;
+ continue;
+ }
+
+ /* We have a non-empty component: search info for key */
+ info = VersionInfo32_FindChild(info, lpSubBlock, lpNextSlash - lpSubBlock);
+ if (!info)
+ {
+ if (puLen) *puLen = 0;
+ return STATUS_RESOURCE_TYPE_NOT_FOUND;
+ }
+
+ /* Skip path component */
+ lpSubBlock = lpNextSlash;
+ }
+
+ /* Return value */
+ *lplpBuffer = (PVOID)VersionInfo32_Value(info);
+ if (puLen)
+ *puLen = info->wValueLength;
+ if (pbText)
+ *pbText = info->wType;
+
+ return STATUS_SUCCESS;
+}
+
+NTSTATUS
+NtVerQueryValue(
+ IN const VOID* pBlock,
+ IN PCWSTR lpSubBlock,
+ OUT PVOID* lplpBuffer,
+ OUT PUINT puLen)
+{
+ PCVS_VERSION_INFO_STRUCT32 info = pBlock;
+
+ DPRINT("%s (%p, %S, %p, %p)\n", __FUNCTION__, pBlock, lpSubBlock,
lplpBuffer, puLen);
+
+ if (!pBlock)
+ return FALSE;
+
+ if (!lpSubBlock || !*lpSubBlock)
+ lpSubBlock = L"\\";
+
+ return VersionInfo32_QueryValue(info, lpSubBlock, lplpBuffer, puLen, NULL);
+}
+
+/* EOF */
Propchange: branches/setup_improvements/base/setup/lib/ntverrsrc.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: branches/setup_improvements/base/setup/lib/ntverrsrc.h
URL:
http://svn.reactos.org/svn/reactos/branches/setup_improvements/base/setup/l…
==============================================================================
--- branches/setup_improvements/base/setup/lib/ntverrsrc.h (added)
+++ branches/setup_improvements/base/setup/lib/ntverrsrc.h [iso-8859-1] Sun May 21
23:41:04 2017
@@ -0,0 +1,24 @@
+/*
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS text-mode setup
+ * FILE: base/setup/lib/ntverrsrc.h
+ * PURPOSE: NT Version Resource Management API
+ * PROGRAMMER: Hermes Belusca-Maito (hermes.belusca(a)sfr.fr)
+ */
+
+#pragma once
+
+NTSTATUS
+NtGetVersionResource(
+ IN PVOID BaseAddress,
+ OUT PVOID* Resource,
+ OUT PULONG ResourceSize OPTIONAL);
+
+NTSTATUS
+NtVerQueryValue(
+ IN const VOID* pBlock,
+ IN PCWSTR lpSubBlock,
+ OUT PVOID* lplpBuffer,
+ OUT PUINT puLen);
+
+/* EOF */
Propchange: branches/setup_improvements/base/setup/lib/ntverrsrc.h
------------------------------------------------------------------------------
svn:eol-style = native
Modified: branches/setup_improvements/base/setup/lib/precomp.h
URL:
http://svn.reactos.org/svn/reactos/branches/setup_improvements/base/setup/l…
==============================================================================
--- branches/setup_improvements/base/setup/lib/precomp.h [iso-8859-1] (original)
+++ branches/setup_improvements/base/setup/lib/precomp.h [iso-8859-1] Sun May 21 23:41:04
2017
@@ -33,11 +33,6 @@
/* Filesystem headers */
#include <reactos/rosioctl.h> // For extra partition IDs
-/** For FileSystems **/
-// #include <fslib/vfatlib.h>
-// #include <fslib/ext2lib.h>
-// // #include <fslib/ntfslib.h>
-
//
///* Internal Headers */
//#include "interface/consup.h"
Modified: branches/setup_improvements/base/setup/lib/setuplib.h
URL:
http://svn.reactos.org/svn/reactos/branches/setup_improvements/base/setup/l…
==============================================================================
--- branches/setup_improvements/base/setup/lib/setuplib.h [iso-8859-1] (original)
+++ branches/setup_improvements/base/setup/lib/setuplib.h [iso-8859-1] Sun May 21 23:41:04
2017
@@ -28,6 +28,7 @@
#include "errorcode.h"
#include "linklist.h"
+#include "ntverrsrc.h"
#include "fsutil.h"
#include "genlist.h"
#include "partlist.h"
Modified: branches/setup_improvements/base/setup/usetup/osdetect.c
URL:
http://svn.reactos.org/svn/reactos/branches/setup_improvements/base/setup/u…
==============================================================================
--- branches/setup_improvements/base/setup/usetup/osdetect.c [iso-8859-1] (original)
+++ branches/setup_improvements/base/setup/usetup/osdetect.c [iso-8859-1] Sun May 21
23:41:04 2017
@@ -9,9 +9,6 @@
#include "usetup.h"
-#include <ndk/ldrtypes.h>
-#include <ndk/ldrfuncs.h>
-
#define NDEBUG
#include <debug.h>
@@ -22,183 +19,6 @@
/* Language-independent Vendor strings */
static const PCWSTR KnownVendors[] = { L"ReactOS", L"Microsoft" };
-
-
-/* VERSION RESOURCE API ******************************************************/
-
-/*
- * NT-oriented version resource management, adapted from dll/win32/version.
- * We only deal with 32-bit PE executables.
- */
-
-NTSTATUS
-NtGetVersionResource(
- IN PVOID BaseAddress,
- OUT PVOID* Resource,
- OUT PULONG ResourceSize OPTIONAL)
-{
-// #define RT_VERSION MAKEINTRESOURCE(16) // See winuser.h
-#define VS_VERSION_INFO 1 // See psdk/verrsrc.h
-#define VS_FILE_INFO RT_VERSION
-
- NTSTATUS Status;
- LDR_RESOURCE_INFO ResourceInfo;
- PIMAGE_RESOURCE_DATA_ENTRY ResourceDataEntry;
- PVOID Data = NULL;
- ULONG Size = 0;
-
- /* Try to find the resource */
- ResourceInfo.Type = 16; // RT_VERSION;
- ResourceInfo.Name = VS_VERSION_INFO; // MAKEINTRESOURCEW(VS_VERSION_INFO);
- ResourceInfo.Language = 0; // Don't care about the language
-
- Status = LdrFindResource_U(BaseAddress,
- &ResourceInfo,
- RESOURCE_DATA_LEVEL,
- &ResourceDataEntry);
- if (!NT_SUCCESS(Status))
- {
- DPRINT1("NtGetVersionResource: Version resource not found, Status
0x%08lx\n", Status);
- return Status;
- }
-
- /* Access the resource */
- Status = LdrAccessResource(BaseAddress,
- ResourceDataEntry,
- &Data,
- &Size);
- if (!NT_SUCCESS(Status))
- {
- DPRINT1("NtGetVersionResource: Cannot access Version resource, Status
0x%08lx\n", Status);
- return Status;
- }
-
- *Resource = Data;
- if (ResourceSize) *ResourceSize = Size;
-
- return STATUS_SUCCESS;
-}
-
-/* NOTE: the xxx_STRUCT16 version differs by storing strings in ANSI, not in UNICODE */
-typedef struct _VS_VERSION_INFO_STRUCT32
-{
- WORD wLength;
- WORD wValueLength;
- WORD wType; /* 1:Text, 0:Binary */
- WCHAR szKey[1];
-#if 0 /* variable length structure */
- /* DWORD aligned */
- BYTE Value[];
- /* DWORD aligned */
- VS_VERSION_INFO_STRUCT32 Children[];
-#endif
-} VS_VERSION_INFO_STRUCT32, *PVS_VERSION_INFO_STRUCT32;
-typedef const VS_VERSION_INFO_STRUCT32 *PCVS_VERSION_INFO_STRUCT32;
-
-#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 ) \
- (PCVS_VERSION_INFO_STRUCT32)( VersionInfo32_Value( ver ) + \
- ( ( (ver)->wValueLength * \
- ((ver)->wType? 2 : 1) + 3 ) & ~3 ) )
-
-#define VersionInfo32_Next( ver ) \
- (PVS_VERSION_INFO_STRUCT32)( (ULONG_PTR)ver + (((ver)->wLength + 3) & ~3) )
-
-static PCVS_VERSION_INFO_STRUCT32
-VersionInfo32_FindChild(
- IN PCVS_VERSION_INFO_STRUCT32 info,
- IN PCWSTR szKey,
- IN UINT cbKey)
-{
- PCVS_VERSION_INFO_STRUCT32 child = VersionInfo32_Children(info);
-
- while ((ULONG_PTR)child < (ULONG_PTR)info + info->wLength)
- {
- if (!_wcsnicmp(child->szKey, szKey, cbKey) &&
!child->szKey[cbKey])
- return child;
-
- if (child->wLength == 0) return NULL;
- child = VersionInfo32_Next(child);
- }
-
- return NULL;
-}
-
-static NTSTATUS
-VersionInfo32_QueryValue(
- IN PCVS_VERSION_INFO_STRUCT32 info,
- IN PCWSTR lpSubBlock,
- OUT PVOID* lplpBuffer,
- OUT PUINT puLen OPTIONAL,
- OUT BOOL* pbText OPTIONAL)
-{
- PCWSTR lpNextSlash;
-
- DPRINT("lpSubBlock : (%S)\n", lpSubBlock);
-
- while (*lpSubBlock)
- {
- /* Find next path component */
- for (lpNextSlash = lpSubBlock; *lpNextSlash; lpNextSlash++)
- {
- if (*lpNextSlash == '\\')
- break;
- }
-
- /* Skip empty components */
- if (lpNextSlash == lpSubBlock)
- {
- lpSubBlock++;
- continue;
- }
-
- /* We have a non-empty component: search info for key */
- info = VersionInfo32_FindChild(info, lpSubBlock, lpNextSlash - lpSubBlock);
- if (!info)
- {
- if (puLen) *puLen = 0;
- return STATUS_RESOURCE_TYPE_NOT_FOUND;
- }
-
- /* Skip path component */
- lpSubBlock = lpNextSlash;
- }
-
- /* Return value */
- *lplpBuffer = (PVOID)VersionInfo32_Value(info);
- if (puLen)
- *puLen = info->wValueLength;
- if (pbText)
- *pbText = info->wType;
-
- return STATUS_SUCCESS;
-}
-
-NTSTATUS
-NtVerQueryValue(
- IN const VOID* pBlock,
- IN PCWSTR lpSubBlock,
- OUT PVOID* lplpBuffer,
- OUT PUINT puLen)
-{
- PCVS_VERSION_INFO_STRUCT32 info = pBlock;
-
- DPRINT("%s (%p, %S, %p, %p)\n", __FUNCTION__, pBlock, lpSubBlock,
lplpBuffer, puLen);
-
- if (!pBlock)
- return FALSE;
-
- if (!lpSubBlock || !*lpSubBlock)
- lpSubBlock = L"\\";
-
- return VersionInfo32_QueryValue(info, lpSubBlock, lplpBuffer, puLen, NULL);
-}
-
/* FUNCTIONS ****************************************************************/