Code programs in binary

With this tool, you will be able to code a program using pure binary. Save the ascii 1’s and 0’s in a text file and this program will take every 8 characters, convert the value to a byte, and output it to the specified file. Example usage:

I have this text file called hello.bin:

10110100 00001001
10111010 00001001 00000001
11001101 00100001
11001101 00100000
01101000 01100101 01101100 01101100 01101111 00100100

Which translates to this in assembly:

mov ah,09
mov dx,0109
int 21
int 20
db "hello$"

Just run the following command:

bincode hello.com hello.bin

Now you can run hello.com in dosbox and watch the magic happen.
Of course, you can also use it to write PE executables, ELF, images, text files, anything.

bincode.c

#include <stdio.h>
#include <stdlib.h>

void help(char* fname) {
    printf(
        "Code programs in binary - by Jakash3\n"
        "Usage: %s outfile infile"
        "Notes:\n"
        "   infile = Text file containing ascii 1's and 0's.\n"
        "            8 bits per byte, all other characters\n"
      "            and whitespace ignored.\n"
        "   outfile = Name of program to create and write to.\n",
        fname
    );
    exit(1);
}

int main(int argc, char** argv) {
    if (argc!=3) help(argv[0]);
    FILE *dst, *src;
    dst = fopen(argv[1],"wb");
    if (!dst) { printf("Could not create or truncate %s\nQuitting...",argv[1]); return 1;}
    src = fopen(argv[2],"r");
    if (!src) { printf("Could not open %s\nQuitting...",argv[2]); return 1;}
    char c, byte=0;
    int i=0, count=0;
    while (!feof(src)) {
        if (i==8) { fwrite(&byte,1,1,dst); byte=0; i=0; count++; }
        fread(&c,1,1,src);
        switch (c) {
            case '1':
                byte |= ((c=='1') << (7-i));
            case '0':
                i++;
        }
    }
    fclose(src);
    if (!fclose(dst)) 
        printf("Wrote %d bytes to %s\n",count,argv[1]);
    return 0;
}

3 thoughts on “Code programs in binary

  1. Hello Jakash3!

    I would like to get in touch with you.
    Could you please write me an email?
    I would be grateful.

    Best Regards

    r4f43ll

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: