VirtualBox

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

Last change on this file since 43017 was 43017, checked in by vboxsync, 12 years ago

win.x86 addition signing fix.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.0 KB
Line 
1/* $Id: VBoxPeSetVersion.cpp 43017 2012-08-27 22:16:03Z vboxsync $ */
2/** @file
3 * IPRT - Change the OS and SubSystem version to 4.0 (VS2010 trick).
4 */
5
6/*
7 * Copyright (C) 2012 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 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27
28/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#include <Windows.h>
32#include <stdio.h>
33#include <string.h>
34
35
36/** @todo Rewrite this so it can take options and print out error messages. */
37int main(int argc, char **argv)
38{
39 if (argc != 2)
40 return 30;
41 FILE *pFile = fopen(argv[1], "r+b");
42 if (!pFile)
43 return 1;
44 IMAGE_DOS_HEADER MzHdr;
45 if (fread(&MzHdr, sizeof(MzHdr), 1, pFile) != 1)
46 return 2;
47
48 if (fseek(pFile, MzHdr.e_lfanew, SEEK_SET) != 0)
49 return 3;
50
51 IMAGE_NT_HEADERS32 NtHdrs;
52 if (fread(&NtHdrs, sizeof(NtHdrs), 1, pFile) != 1)
53 return 4;
54 if (NtHdrs.Signature != IMAGE_NT_SIGNATURE)
55 return 5;
56 if (NtHdrs.FileHeader.Machine != IMAGE_FILE_MACHINE_I386)
57 return 6;
58 if (NtHdrs.OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR32_MAGIC)
59 return 7;
60
61 if (NtHdrs.OptionalHeader.Magic != IMAGE_NT_OPTIONAL_HDR32_MAGIC)
62 return 7;
63
64 IMAGE_NT_HEADERS32 NtHdrsNew = NtHdrs;
65 if (NtHdrsNew.OptionalHeader.MajorOperatingSystemVersion > 4)
66 {
67 NtHdrsNew.OptionalHeader.MajorOperatingSystemVersion = 4;
68 NtHdrsNew.OptionalHeader.MinorOperatingSystemVersion = 0;
69 }
70 if (NtHdrsNew.OptionalHeader.MajorSubsystemVersion > 4)
71 {
72 NtHdrsNew.OptionalHeader.MajorSubsystemVersion = 4;
73 NtHdrsNew.OptionalHeader.MinorSubsystemVersion = 0;
74 }
75
76 if (memcmp(&NtHdrsNew, &NtHdrs, sizeof(NtHdrs)))
77 {
78 /** @todo calc checksum. */
79 NtHdrsNew.OptionalHeader.CheckSum = 0;
80
81 if (fseek(pFile, MzHdr.e_lfanew, SEEK_SET) != 0)
82 return 10;
83 if (fwrite(&NtHdrsNew, sizeof(NtHdrsNew), 1, pFile) != 1)
84 return 11;
85 }
86
87 if (fclose(pFile) != 0)
88 return 29;
89 return 0;
90}
91
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