[USETUP][SETUPLIB] Move all the code that retrieves the version resources from PE...
authorHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Sun, 21 May 2017 23:41:04 +0000 (23:41 +0000)
committerHermès Bélusca-Maïto <hermes.belusca-maito@reactos.org>
Thu, 31 May 2018 16:00:58 +0000 (18:00 +0200)
Remove also some commented headers in precomp.h.

svn path=/branches/setup_improvements/; revision=74618

base/setup/lib/CMakeLists.txt
base/setup/lib/ntverrsrc.c [new file with mode: 0644]
base/setup/lib/ntverrsrc.h [new file with mode: 0644]
base/setup/lib/precomp.h
base/setup/lib/setuplib.h
base/setup/usetup/osdetect.c

index e44b2f7..258a14b 100644 (file)
@@ -2,6 +2,7 @@
 list(APPEND SOURCE
     fsutil.c
     genlist.c
+    ntverrsrc.c
     partlist.c
     precomp.h)
 
diff --git a/base/setup/lib/ntverrsrc.c b/base/setup/lib/ntverrsrc.c
new file mode 100644 (file)
index 0000000..e788e12
--- /dev/null
@@ -0,0 +1,193 @@
+/*
+ * PROJECT:     ReactOS Setup Library
+ * LICENSE:     GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
+ * PURPOSE:     NT Version Resource Management API
+ * COPYRIGHT:   Copyright 2017-2018 Hermes Belusca-Maito
+ *
+ * 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 */
diff --git a/base/setup/lib/ntverrsrc.h b/base/setup/lib/ntverrsrc.h
new file mode 100644 (file)
index 0000000..9ef5b00
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * PROJECT:     ReactOS Setup Library
+ * LICENSE:     GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
+ * PURPOSE:     NT Version Resource Management API
+ * COPYRIGHT:   Copyright 2017-2018 Hermes Belusca-Maito
+ */
+
+#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 */
index 1f84862..ea82da4 100644 (file)
 /* 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"
index f9ed75e..6a44524 100644 (file)
@@ -27,6 +27,7 @@ extern HANDLE ProcessHeap;
 
 #include "errorcode.h"
 #include "linklist.h"
+#include "ntverrsrc.h"
 #include "fsutil.h"
 #include "genlist.h"
 #include "partlist.h"
index 60fd7ef..23f1dee 100644 (file)
@@ -8,9 +8,6 @@
 
 #include "usetup.h"
 
-#include <ndk/ldrtypes.h>
-#include <ndk/ldrfuncs.h>
-
 // HACK!
 #include <strsafe.h>
 
@@ -26,183 +23,6 @@ extern PPARTLIST PartitionList;
 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 ****************************************************************/
 
 #if 0