VirtualBox

source: vbox/trunk/src/bldprogs/VBoxPeSetVersion.cpp@ 58029

Last change on this file since 58029 was 57898, checked in by vboxsync, 9 years ago

bldprogs: fix for cross-building with Windows as target.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.8 KB
Line 
1/* $Id: VBoxPeSetVersion.cpp 57898 2015-09-25 14:58:47Z vboxsync $ */
2/** @file
3 * IPRT - Change the OS and SubSystem version to 4.0 (VS2010 trick).
4 */
5
6/*
7 * Copyright (C) 2012-2015 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*********************************************************************************************************************************
20* Header Files *
21*********************************************************************************************************************************/
22#ifdef RT_OS_WINDOWS
23# include <Windows.h>
24#else
25# include <iprt/stdint.h>
26# include "../VBox/Runtime/include/internal/ldrPE.h"
27# include "../VBox/Runtime/include/internal/ldrMZ.h"
28#endif
29#include <stdio.h>
30#include <string.h>
31
32
33/** @todo Rewrite this so it can take options and print out error messages. */
34int main(int argc, char **argv)
35{
36 if (argc != 2)
37 return 30;
38 FILE *pFile = fopen(argv[1], "r+b");
39 if (!pFile)
40 return 1;
41 IMAGE_DOS_HEADER MzHdr;
42 if (fread(&MzHdr, sizeof(MzHdr), 1, pFile) != 1)
43 return 2;
44
45 if (fseek(pFile, MzHdr.e_lfanew, SEEK_SET) != 0)
46 return 3;
47
48 IMAGE_NT_HEADERS32 NtHdrs;
49 if (fread(&NtHdrs, sizeof(NtHdrs), 1, pFile) != 1)
50 return 4;
51 if (NtHdrs.Signature != IMAGE_NT_SIGNATURE)
52 return 5;
53 if (NtHdrs.FileHeader.Machine != IMAGE_FILE_MACHINE_I386)
54 return 6;
55 if (NtHdrs.OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR32_MAGIC)
56 return 7;
57
58 if (NtHdrs.OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR32_MAGIC)
59 return 7;
60
61 IMAGE_NT_HEADERS32 NtHdrsNew = NtHdrs;
62 if (NtHdrsNew.OptionalHeader.MajorOperatingSystemVersion > 4)
63 {
64 NtHdrsNew.OptionalHeader.MajorOperatingSystemVersion = 4;
65 NtHdrsNew.OptionalHeader.MinorOperatingSystemVersion = 0;
66 }
67 if (NtHdrsNew.OptionalHeader.MajorSubsystemVersion > 4)
68 {
69 NtHdrsNew.OptionalHeader.MajorSubsystemVersion = 4;
70 NtHdrsNew.OptionalHeader.MinorSubsystemVersion = 0;
71 }
72
73 if (memcmp(&NtHdrsNew, &NtHdrs, sizeof(NtHdrs)))
74 {
75 /** @todo calc checksum. */
76 NtHdrsNew.OptionalHeader.CheckSum = 0;
77
78 if (fseek(pFile, MzHdr.e_lfanew, SEEK_SET) != 0)
79 return 10;
80 if (fwrite(&NtHdrsNew, sizeof(NtHdrsNew), 1, pFile) != 1)
81 return 11;
82 }
83
84 if (fclose(pFile) != 0)
85 return 29;
86 return 0;
87}
88
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette