]>
Commit | Line | Data |
---|---|---|
95d675b5 | 1 | /*++\r |
2 | \r | |
3e99020d | 3 | Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR> \r |
4b1e1121 | 4 | This program and the accompanying materials \r |
95d675b5 | 5 | are licensed and made available under the terms and conditions of the BSD License \r |
6 | which accompanies this 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 | |
12 | Module Name:\r | |
13 | \r | |
14 | Strip.c\r | |
15 | \r | |
16 | Abstract:\r | |
17 | \r | |
18 | Quick Exe2Bin equivalent.\r | |
19 | \r | |
20 | --*/\r | |
21 | \r | |
22 | #include <stdio.h>\r | |
23 | #include <memory.h>\r | |
24 | #include <string.h>\r | |
25 | #include <malloc.h>\r | |
26 | \r | |
3e99020d LG |
27 | #define UTILITY_NAME "Strip"\r |
28 | #define UTILITY_VERSION "v1.0"\r | |
29 | \r | |
30 | static\r | |
31 | void\r | |
32 | Usage (\r | |
33 | )\r | |
34 | /*++\r | |
35 | \r | |
36 | Routine Description:\r | |
37 | \r | |
38 | Print usage information for this utility.\r | |
39 | \r | |
40 | Arguments:\r | |
41 | \r | |
42 | None.\r | |
43 | \r | |
44 | Returns:\r | |
45 | \r | |
46 | Nothing.\r | |
47 | \r | |
48 | --*/\r | |
49 | {\r | |
50 | int Index;\r | |
51 | const char *Str[] = {\r | |
52 | UTILITY_NAME" "UTILITY_VERSION" - Intel Strip Utility",\r | |
53 | " Copyright (C), 2006 - 2008 Intel Corporation",\r | |
54 | \r | |
55 | #if ( defined(UTILITY_BUILD) && defined(UTILITY_VENDOR) )\r | |
56 | " Built from "UTILITY_BUILD", project of "UTILITY_VENDOR,\r | |
57 | #endif\r | |
58 | "",\r | |
59 | "Usage:",\r | |
60 | " "UTILITY_NAME" SOURCE DEST",\r | |
61 | "Description:",\r | |
62 | " Convert executable files to binary files.",\r | |
63 | NULL\r | |
64 | };\r | |
65 | \r | |
66 | for (Index = 0; Str[Index] != NULL; Index++) {\r | |
67 | fprintf (stdout, "%s\n", Str[Index]);\r | |
68 | }\r | |
69 | }\r | |
70 | \r | |
95d675b5 | 71 | int\r |
72 | main (\r | |
73 | int argc,\r | |
74 | char *argv[]\r | |
75 | )\r | |
76 | /*++\r | |
77 | \r | |
78 | Routine Description:\r | |
79 | \r | |
80 | Converts executable files to binary files.\r | |
81 | \r | |
82 | Arguments:\r | |
83 | \r | |
84 | argc - Number of command line arguments\r | |
85 | argv[] - Array of pointers to the command line arguments\r | |
86 | \r | |
87 | Returns:\r | |
88 | \r | |
89 | Zero - Function completed successfully.\r | |
90 | Non-zero - Function exited with errors. \r | |
91 | \r | |
92 | --*/\r | |
93 | {\r | |
94 | FILE *InFile;\r | |
95 | FILE *OutFile;\r | |
96 | int Index;\r | |
97 | int FileSize;\r | |
98 | char *Buffer;\r | |
99 | char *Ptrx;\r | |
100 | \r | |
101 | if (argc < 3) {\r | |
3e99020d | 102 | Usage ();\r |
95d675b5 | 103 | return -1;\r |
104 | }\r | |
105 | \r | |
106 | InFile = fopen (argv[1], "rb");\r | |
107 | OutFile = fopen (argv[2], "wb");\r | |
108 | \r | |
109 | if (!InFile) {\r | |
110 | printf ("no file, exit\n");\r | |
111 | return -1;\r | |
112 | }\r | |
113 | \r | |
114 | if (OutFile == NULL) {\r | |
115 | printf ("Unable to open output file.\n");\r | |
116 | return -1;\r | |
117 | }\r | |
118 | \r | |
119 | fseek (InFile, 0, SEEK_END);\r | |
120 | FileSize = ftell (InFile);\r | |
121 | \r | |
122 | if (FileSize < 0x200) {\r | |
123 | printf ("%d is not a legal size, exit\n", FileSize);\r | |
124 | return -1;\r | |
125 | }\r | |
126 | \r | |
127 | fseek (InFile, 0, SEEK_SET);\r | |
128 | \r | |
129 | Buffer = malloc (FileSize);\r | |
130 | if (Buffer == NULL) {\r | |
131 | printf ("Error: Out of resources.\n");\r | |
132 | return -1;\r | |
133 | }\r | |
134 | \r | |
135 | fread (Buffer, 1, FileSize, InFile);\r | |
136 | \r | |
137 | Ptrx = Buffer + 0x200;\r | |
138 | \r | |
139 | Index = FileSize - 0x200;\r | |
140 | \r | |
141 | fwrite (Ptrx, Index, 1, OutFile);\r | |
142 | \r | |
143 | fclose (InFile);\r | |
144 | fclose (OutFile);\r | |
145 | free (Buffer);\r | |
146 | \r | |
147 | return 0;\r | |
148 | }\r |