]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/CCode/Source/Strip/Strip.c
a7efd54936ed85265b658525fd07b80dee5e7d04
[mirror_edk2.git] / Tools / CCode / Source / Strip / Strip.c
1 /*++
2
3 Copyright (c) 2004-2006 Intel Corporation. All rights reserved
4 This program and the accompanying materials are licensed and made available
5 under the terms and conditions of the BSD License which accompanies this
6 distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12
13 Module Name:
14
15 Strip.c
16
17 Abstract:
18
19 Quick Exe2Bin equivalent.
20
21 --*/
22
23 #include <stdio.h>
24 #include <memory.h>
25 #include <string.h>
26 #include <stdlib.h>
27
28 #define UTILITY_NAME "Strip"
29 #define UTILITY_MAJOR_VERSION 1
30 #define UTILITY_MINOR_VERSION 1
31
32
33 void
34 Version(
35 void
36 )
37 /*++
38
39 Routine Description:
40
41 Print out version information for Strip.
42
43 Arguments:
44
45 None
46
47 Returns:
48
49 None
50
51 --*/
52 {
53 printf ("%s v%d.%d -EDK Utility to Convert EXE to BIN\n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION);
54 printf ("Copyright (c) 2005-2006 Intel Corporation. All rights reserved.\n");
55 }
56
57 void
58 Usage(
59 void
60 )
61 /*++
62
63 Routine Description:
64
65 Print out usage information for Strip.
66
67 Arguments:
68
69 None
70
71 Returns:
72
73 None
74
75 --*/
76 {
77 Version();
78 printf ("\nUsage: %s InputFile OutputFile\n", UTILITY_NAME);
79 }
80
81 int
82 main (
83 int argc,
84 char *argv[]
85 )
86 /*++
87
88 Routine Description:
89
90 Converts executable files to binary files.
91
92 Arguments:
93
94 argc - Number of command line arguments
95 argv[] - Array of pointers to the command line arguments
96
97 Returns:
98
99 Zero - Function completed successfully.
100 Non-zero - Function exited with errors.
101
102 --*/
103 {
104 FILE *InFile;
105 FILE *OutFile;
106 int Index;
107 int FileSize;
108 char *Buffer;
109 char *Ptrx;
110
111 if (argc == 1) {
112 Usage();
113 return -1;
114 }
115
116 if ((strcmp(argv[1], "-h") == 0) || (strcmp(argv[1], "--help") == 0) ||
117 (strcmp(argv[1], "-?") == 0) || (strcmp(argv[1], "/?") == 0)) {
118 Usage();
119 return 0;
120 }
121
122 if ((strcmp(argv[1], "-V") == 0) || (strcmp(argv[1], "--version") == 0)) {
123 Version();
124 return 0;
125 }
126
127 if (argc < 3) {
128 Usage();
129 return -1;
130 }
131
132 InFile = fopen (argv[1], "rb");
133 OutFile = fopen (argv[2], "wb");
134
135 if (!InFile) {
136 printf ("Unable to open input file, exit\n");
137 return -1;
138 }
139
140 if (OutFile == NULL) {
141 printf ("Unable to open output file, exit.\n");
142 return -1;
143 }
144
145 fseek (InFile, 0, SEEK_END);
146 FileSize = ftell (InFile);
147
148 if (FileSize < 0x200) {
149 printf ("%d is not a legal file size, exit\n", FileSize);
150 return -1;
151 }
152
153 fseek (InFile, 0, SEEK_SET);
154
155 Buffer = (char *) malloc (FileSize);
156 if (Buffer == NULL) {
157 printf ("Error: Out of resources.\n");
158 return -1;
159 }
160
161 fread (Buffer, 1, FileSize, InFile);
162
163 Ptrx = Buffer + 0x200;
164
165 Index = FileSize - 0x200;
166
167 fwrite (Ptrx, Index, 1, OutFile);
168
169 fclose (InFile);
170 fclose (OutFile);
171 free (Buffer);
172
173 return 0;
174 }