From d960166a4efe39f4598648a5ea011c22c281c63e Mon Sep 17 00:00:00 2001 From: Michaelangel007 Date: Thu, 19 Apr 2018 08:41:55 -0700 Subject: [PATCH] Add dump fragment --- Makefile | 5 ++++ dump_frag.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 Makefile create mode 100644 dump_frag.c diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..4db6d75 --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +all: dump_frag + +dump_frag: dump_frag.c + gcc -o $@ $< + diff --git a/dump_frag.c b/dump_frag.c new file mode 100644 index 0000000..538fee9 --- /dev/null +++ b/dump_frag.c @@ -0,0 +1,79 @@ +// Includes + #include // printf() + #include // malloc() + +// Util + + size_t FileSize( FILE *file ) + { + if( !file ) + return 0; + + // Yes, this is insecure + // and we should use stat() + // but that isn't available under Windows + fseek( file, 0, SEEK_END ); + size_t size = ftell( file ); + fseek( file, 0, SEEK_SET ); + + return size; + } + +// Main + + int main() + { + const char *name = "gumball.fragment.1.1800"; + FILE *in = fopen( name, "rb" ); + + if( in ) + { + size_t size = FileSize( in ); + +//printf( "Size: %lld\n", size ); + + if( size ) + { + char *buffer = (char*) malloc( size ); + + int i; + int n = (int) size; + char c; + + size_t read = fread( buffer, 1, size, in ); + + if( read != size ) + printf( "ERROR: Only read %lld / %lld bytes\n", read, size ); + + for( i = 0; i < n; i++ ) + { + c = buffer[ i ] & 0x7F; + + if( c == 0x0D ) + { + printf( "\n" ); + + c = buffer[ ++i ]; + if( (c == 0x13) || (c == 0x0B) ) + printf( "\t" ); + else + printf( " " ); + } + else + if( c < 0x20 ) + ; + else + printf( "%c", c ); + } + + free( buffer ); + } + + fclose( in ); + } + else + printf( "ERROR: Couldn't open: '%s'\n", name ); + + return 0; + } +