
Hunting strings in binary files
Let's suppose we want to analyze an unknown file in order to get some information about its content. In binary analysis, everything begins by looking for strings because they are the only human readable data stored there. Strings? What could go wrong? Let's see! This post will explore the ASCII Character Set only Strategy #1: contiguous alphanumeric characters We can assume that a contiguous series of alphanumeric characters is a valid string: #include <stdio.h> #include <ctype.h> void print_strings ( const char * s , int len ) { const char * end = s + len ; while ( s < end ) { if ( isalnum ( * s )) { // we found an alphanumeric character const char * start = s ; // save the start position // continue scanning until end or non-alphanumeric // character is found while ( s < end && isalnum ( * s )) s ++ ; // we found a string, calculate its length and print it int n = s - start ; printf ( "%.*s \n " , n , start ); } else // non-alphanumeric, go ahead... s ++ ; } } This code works fine bu
Continue reading on Dev.to
Opens in a new tab




