VirtualBox

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

Last change on this file since 57698 was 57353, checked in by vboxsync, 9 years ago

scm: Added fixing of flower boxes marking sections in C/C++ source file, like 'Header Files' and 'Defined Constants And Macros'. Applied it to the bldprogs.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.7 KB
Line 
1/* $Id: VBoxPeSetVersion.cpp 57353 2015-08-14 14:31:09Z 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#include <Windows.h>
23#include <stdio.h>
24#include <string.h>
25
26
27/** @todo Rewrite this so it can take options and print out error messages. */
28int main(int argc, char **argv)
29{
30 if (argc != 2)
31 return 30;
32 FILE *pFile = fopen(argv[1], "r+b");
33 if (!pFile)
34 return 1;
35 IMAGE_DOS_HEADER MzHdr;
36 if (fread(&MzHdr, sizeof(MzHdr), 1, pFile) != 1)
37 return 2;
38
39 if (fseek(pFile, MzHdr.e_lfanew, SEEK_SET) != 0)
40 return 3;
41
42 IMAGE_NT_HEADERS32 NtHdrs;
43 if (fread(&NtHdrs, sizeof(NtHdrs), 1, pFile) != 1)
44 return 4;
45 if (NtHdrs.Signature != IMAGE_NT_SIGNATURE)
46 return 5;
47 if (NtHdrs.FileHeader.Machine != IMAGE_FILE_MACHINE_I386)
48 return 6;
49 if (NtHdrs.OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR32_MAGIC)
50 return 7;
51
52 if (NtHdrs.OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR32_MAGIC)
53 return 7;
54
55 IMAGE_NT_HEADERS32 NtHdrsNew = NtHdrs;
56 if (NtHdrsNew.OptionalHeader.MajorOperatingSystemVersion > 4)
57 {
58 NtHdrsNew.OptionalHeader.MajorOperatingSystemVersion = 4;
59 NtHdrsNew.OptionalHeader.MinorOperatingSystemVersion = 0;
60 }
61 if (NtHdrsNew.OptionalHeader.MajorSubsystemVersion > 4)
62 {
63 NtHdrsNew.OptionalHeader.MajorSubsystemVersion = 4;
64 NtHdrsNew.OptionalHeader.MinorSubsystemVersion = 0;
65 }
66
67 if (memcmp(&NtHdrsNew, &NtHdrs, sizeof(NtHdrs)))
68 {
69 /** @todo calc checksum. */
70 NtHdrsNew.OptionalHeader.CheckSum = 0;
71
72 if (fseek(pFile, MzHdr.e_lfanew, SEEK_SET) != 0)
73 return 10;
74 if (fwrite(&NtHdrsNew, sizeof(NtHdrsNew), 1, pFile) != 1)
75 return 11;
76 }
77
78 if (fclose(pFile) != 0)
79 return 29;
80 return 0;
81}
82
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