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