VirtualBox

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

Last change on this file since 62193 was 58741, checked in by vboxsync, 9 years ago

VBoxPeSetVersion.cpp: Use our pecoff.h and mz.h instead of Windows.h and IPRT internal headers.

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