Add new OSS License
[mirror_edk2.git] / Tools / Source / TianoTools / Strip / Strip.c
1 /*++
2
3 Copyright (c) 2004-2006 Intel Corporation. All rights reserved
4 This software and associated documentation (if any) is furnished
5 under a license and may only be used or copied in accordance
6 with the terms of the license. Except as permitted by such
7 license, no part of this software or documentation may be
8 reproduced, stored in a retrieval system, or transmitted in any
9 form or by any means without the express written consent of
10 Intel Corporation.
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
26 int
27 main (
28 int argc,
29 char *argv[]
30 )
31 /*++
32
33 Routine Description:
34
35 Converts executable files to binary files.
36
37 Arguments:
38
39 argc - Number of command line arguments
40 argv[] - Array of pointers to the command line arguments
41
42 Returns:
43
44 Zero - Function completed successfully.
45 Non-zero - Function exited with errors.
46
47 --*/
48 {
49 FILE *InFile;
50 FILE *OutFile;
51 int Index;
52 int FileSize;
53 char *Buffer;
54 char *Ptrx;
55
56 if (argc < 3) {
57 printf ("Need more args, such as file name to convert and output name\n");
58 return -1;
59 }
60
61 InFile = fopen (argv[1], "rb");
62 OutFile = fopen (argv[2], "wb");
63
64 if (!InFile) {
65 printf ("no file, exit\n");
66 return -1;
67 }
68
69 if (OutFile == NULL) {
70 printf ("Unable to open output file.\n");
71 return -1;
72 }
73
74 fseek (InFile, 0, SEEK_END);
75 FileSize = ftell (InFile);
76
77 if (FileSize < 0x200) {
78 printf ("%d is not a legal size, exit\n", FileSize);
79 return -1;
80 }
81
82 fseek (InFile, 0, SEEK_SET);
83
84 Buffer = (char *) malloc (FileSize);
85 if (Buffer == NULL) {
86 printf ("Error: Out of resources.\n");
87 return -1;
88 }
89
90 fread (Buffer, 1, FileSize, InFile);
91
92 Ptrx = Buffer + 0x200;
93
94 Index = FileSize - 0x200;
95
96 fwrite (Ptrx, Index, 1, OutFile);
97
98 fclose (InFile);
99 fclose (OutFile);
100 free (Buffer);
101
102 return 0;
103 }