2

I have a binary code and I want to run it.

01001000 01100101 01101100 01101100 01101111 00100000 01010111 01101111 01110010 01101100 01100100

How can I create a file "application/x-executable" and execute it on Debian?

  • 1
    Regardless of the sensibility of the specific binary presented it would be edifying for some master of assembler to post a commented template by which an arbitrary array of binary (e.g. a DB field prior to assembly) could be pointed at by the IP register and executed. – Theophrastus May 13 '16 at 15:51
  • 1
    It looks like, one of the answers to this question provides a way to execute machine code directly: stackoverflow.com/a/25483473/1470293 – Xantix May 14 '16 at 0:24
  • If you want to run that as if it were machine code, you could write an emulator for your cpu. – Liam May 14 '16 at 7:37
20

That's just the binary representation of the ascii encoding of "Hello World", not an executable, there's no way to execute that.

  • but compilers do not write in binary code? – Gab May 13 '16 at 16:54
  • 3
    @Gab All compiler output of binary (for the meaning of “compiler” that you're used to), but all that is binary is not compiler output. Analogy: English is written using Latin letters, but “jijdasjkdnsuidhu” is not an English word. – Gilles May 13 '16 at 22:11
  • @Gab: Expanding on Gilles comment: a normal assembly program is a list of instructions and arguments (which may be values or names of registers). They'll typically look something like mov eax, 0fa, and this is what's compiled more directly down to binary. Look up e.g. x86 hello world online to see an assembly hello world. – Jules May 14 '16 at 5:29
  • 2
    @Gab Everything is binary - depending on what you mean by "binary". – immibis May 14 '16 at 5:35
3

That is actually not executable code. It's simply the binary string content "Hello World" in 8bit ASCII.

Since you ask for a program, you could do something like this in C:

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


char *bin2str(char *binStr) {
        int len;
        int i = 0; // input cursor
        int j = 0; // binary cursor used to allow spaces in the input
        static char str[256]; // keep it simple and limit the length

        len = strlen(binStr); // avoid recounting every time

        if (len > 256 * 8 - 1) { // impose the limit
                fprintf(stderr, "Error!  Input string too long\n");
                exit(2);
        }

        for (i = 0; i < len; i ++) {
                switch(binStr[i]) {
                        case ' ':
                                continue;
                                break;

                        case '0':
                        case '1':
                                break;  // valid :)

                        default:
                                fprintf(stderr, "Encountered an invalid binary number ('%c') at offset %d!\nAborting\n", binStr[i], i);
                                exit(3);
                }


                if (j % 8 == 0) {
                        str[j / 8] = 0; // initialize char
                }

                if (binStr[i] == '1') {
                        str[j / 8] |= 1 << (7 - (j % 8));
                }

                j ++;
        }

        str[i / 8] = '\0'; // null terminate string

        return str;
}


int main(int argc, char *argv[]) {
        if (argc != 2) {
                fprintf(stderr, "Usage:\t%s binary string\n", argv[0]);
                exit(1);
        }

        printf("Conversion output: \n%s\n", bin2str(argv[1]));

        return 0;
}
3

Assuming the eleven sequences of eight zeros and ones are bytes, those bytes have the values:

72 101 108 108 111 32 87 111 114 108 100

This could easily represent a program, e.g., for an 8-bit processor like the MOS Technology 6502 or a 32-bit processor like the Inmos T800, but AFAIK not for any processor running Debian (the T800 can run a Unix alike).

Converting the values to their ASCII character representation gets you the 11-character string "Hello World". That string, however, is not a program. If you are looking for a program that generates such a string, you might want to start with compiling the following C program:

#include <stdio.h>

int main()
{
    puts("Hello World");
}
  • 2
    According to muppetlabs.com/~breadbox/software/tiny/teensy.html An ELF binary needs to be at least 45 bytes (and that page shows how to reach that), so you're right as far as Linux versions of Debian go (I don't know if Debian with other kernels can execute other formats). – Henrik May 13 '16 at 15:56
  • @Henrik IIRC not even the Unix derivative that I ran on my Transputer could have executables that small, even though the opcodes were 8 bit because of header information. – Anthon May 13 '16 at 16:05
  • What does "run a Unix alike" mean? – JDługosz May 14 '16 at 14:24
  • @JDługosz It runs Helios, which has, similar to Linux, a Unix like system interface, but it is not Unix. – Anthon May 15 '16 at 4:48
  • Is "unix alike" a common term of jargon? I didn't know how to parse it as English before your clarification. – JDługosz May 15 '16 at 10:21
2

If you're asking for a way to decode that binary encoding, you could use

 perl -ape '$_=pack "(B8)*", @F'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.