]> git.proxmox.com Git - mirror_edk2.git/blob - Tools/Source/TianoTools/Strip/Strip.c
567b526568751afaefe77b325291022c1f78e378
[mirror_edk2.git] / Tools / Source / TianoTools / Strip / Strip.c
1 /*++
2
3 Copyright (c) 1999 - 2002 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
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
27 int
28 main (
29 int argc,
30 char *argv[]
31 )
32 /*++
33
34 Routine Description:
35
36 Converts executable files to binary files.
37
38 Arguments:
39
40 argc - Number of command line arguments
41 argv[] - Array of pointers to the command line arguments
42
43 Returns:
44
45 Zero - Function completed successfully.
46 Non-zero - Function exited with errors.
47
48 --*/
49 {
50 FILE *InFile;
51 FILE *OutFile;
52 int Index;
53 int FileSize;
54 char *Buffer;
55 char *Ptrx;
56
57 if (argc < 3) {
58 printf ("Need more args, such as file name to convert and output name\n");
59 return -1;
60 }
61
62 InFile = fopen (argv[1], "rb");
63 OutFile = fopen (argv[2], "wb");
64
65 if (!InFile) {
66 printf ("no file, exit\n");
67 return -1;
68 }
69
70 if (OutFile == NULL) {
71 printf ("Unable to open output file.\n");
72 return -1;
73 }
74
75 fseek (InFile, 0, SEEK_END);
76 FileSize = ftell (InFile);
77
78 if (FileSize < 0x200) {
79 printf ("%d is not a legal size, exit\n", FileSize);
80 return -1;
81 }
82
83 fseek (InFile, 0, SEEK_SET);
84
85 Buffer = malloc (FileSize);
86 if (Buffer == NULL) {
87 printf ("Error: Out of resources.\n");
88 return -1;
89 }
90
91 fread (Buffer, 1, FileSize, InFile);
92
93 Ptrx = Buffer + 0x200;
94
95 Index = FileSize - 0x200;
96
97 fwrite (Ptrx, Index, 1, OutFile);
98
99 fclose (InFile);
100 fclose (OutFile);
101 free (Buffer);
102
103 return 0;
104 }