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