I want to take a binary file (exe, msi, dll, whatever) and be able to actually \"see\" the binary code or whatever base I\'d like (hexadecimal whatever). Figured the easiest
Here's the code to print out the bytes at 1's and 0's in C:
#include
void putbits(unsigned char byte)
{
unsigned char mask = 0x01;
for (int bit = 7; bit >= 0; bit--)
{
if ((mask << bit) & byte)
{
printf("1");
}
else
{
printf("0");
}
}
// Uncomment the following line to get each byte on it's own line.
//printf("\n");
}
int main (int argc, const char * argv[])
{
int c;
while ((c = getchar()) != EOF)
{
putbits(c);
}
return 0;
}
You can build and run it on the command line like this:
gcc main.c --std=c99 -o printer
./printer < printer > printer.txt
It will then output it's 1's and 0's to printer.txt.