Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- int main(int argc, char *argv[])
- {
- if(argc < 2)
- {
- printf("Error: you need to give me a file name to work on.\n");
- return (1);
- }
- else
- {
- FILE *infile;
- if ((infile = fopen(argv[1], "rb")))
- /* 'b' is necessary because windows is dumb and noncompliant as usual */
- {
- /* do this if the file exists: */
- fseek(infile, 0L, SEEK_END);
- long size = ftell(infile);
- fseek(infile, 0L, SEEK_SET);
- printf("size: %ld\n",size);
- if(size < 16)
- {
- printf("The file size is less than 16 bytes; this shouldn't ever happen.\nExiting.\n");
- fclose(infile);
- return (1);
- }
- /* set an output file name, in the format of origfilename_stripped.swf */
- int output;
- char outputFileName[strlen(argv[1]) + 10]; /* '_stripped' is 9 bytes, null terminator makes ten */
- size_t j=0; /* size_t is annoying. */
- int k=0; /* because size_t is unsigned I have to keep track with both signed and unsigned numbers. */
- while ( j < ( strlen(argv[1]) - 4 )) /* '.swf' is 4 chars */
- {
- outputFileName[k]=argv[1][k];
- ++j;
- ++k;
- }
- /* then append '_stripped.swf' */
- /* yes, there are better ways. but I am too lazy to try to remember them. */
- outputFileName[k]='_';
- outputFileName[k+1]='s';
- outputFileName[k+2]='t';
- outputFileName[k+3]='r';
- outputFileName[k+4]='i';
- outputFileName[k+5]='p';
- outputFileName[k+6]='p';
- outputFileName[k+7]='e';
- outputFileName[k+8]='d';
- outputFileName[k+9]='.';
- outputFileName[k+10]='s';
- outputFileName[k+11]='w';
- outputFileName[k+12]='f';
- outputFileName[k+13]='\0';
- printf("output file name: %s\n",outputFileName);
- FILE *outfile;
- outfile = fopen(outputFileName,"w+b");
- /* 'b' is necessary because windows is dumb and noncompliant as usual */
- long i=0;
- while(i < (size - (long)16))
- {
- /* start copying bytes from infile to outfile. */
- /* stops 16 bytes from the end of the input file. */
- /* this has the effect of truncating 16 bytes. */
- fputc(fgetc(infile),outfile);
- ++i;
- }
- printf("%ld\n",i);
- fclose(outfile);
- fclose(infile);
- return (0);
- }
- }
- return (0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement