바이너리 코드 실행

바이너리 코드 실행

바이너리 코드가 있고 이를 실행하고 싶습니다.

01001000 01100101 01101100 01101100 01101111 00100000 01010111 01101111 01110010 01101100 01100100

"application/x-executable" 파일을 생성하고 데비안에서 실행하는 방법은 무엇입니까?

답변1

이것은 실행 파일이 아닌 "Hello World"의 ASCII로 인코딩된 바이너리 표현일 뿐이므로 실행할 방법이 없습니다.

답변2

실제로 실행 가능한 코드는 아닙니다. 이는 8비트 ASCII의 이진 문자열 콘텐츠 "Hello World"일 뿐입니다.

프로그램을 요청했으므로 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

8개의 0과 1로 구성된 11개의 시퀀스가 ​​다음 값을 갖는 바이트라고 가정합니다.

72 101 108 108 111 32 87 111 114 108 100

이는 예를 들어 MOS Technology 6502와 같은 8비트 프로세서 또는 Inmos T800과 같은 32비트 프로세서의 프로그램을 쉽게 나타낼 수 있지만 AFAIK는 Debian을 실행하는 프로세서에서는 작동하지 않습니다(T800은 유사하게 실행될 수 있음). 유닉스).

이 값을 ASCII 문자 표현으로 변환하면 11자 문자열 "Hello World"가 생성됩니다. 그러나 이 문자열은 프로그램이 아닙니다. 그러한 문자열을 생성하는 프로그램을 찾고 있다면 다음 C 프로그램을 컴파일하여 시작할 수 있습니다.

#include <stdio.h>

int main()
{
    puts("Hello World");
}

답변4

바이너리 인코딩을 디코딩하는 방법이 필요한 경우 다음을 사용할 수 있습니다.

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

관련 정보