0

So I have the following challenge: I receive binary file. When opened in notepad++, first line says:

This program is developed with specific programming language. Opcodes: 0x3F byte - gotox byte, 0x40 byte - gotoy byte, 0x2400 - print ' ', 0x2401 - print ','

Iv'e never done anything like that but I would like to know how to crack this question. Basicaly the binary file is a function, I need to recompile it and extract the output.

My idea was opening the file with C in binary format, and reading each byte. But I'm not sure how to exactly do it.. what should be the procedure. Read each byte and then what?

Thank you for any help :)

EDIT: Thanks to clbx I made some real progress, But I'm stuck at the end! This is my simple C code:

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

void gotoxy(int x, int y)
{
    printf("%c[%d;%df", 0x1B, y, x);
}

int main(int argc, char const *argv[])
{
    FILE *fp = fopen("elbitsystems.elbit", "rb");
    unsigned char byte, x, y, print_code;
    while (fread(&byte, 1, 1, fp) != 0)
    {
        switch (byte)
        {
        case 0x3F: // gotox byte
            fread(&x, 1, 1, fp);
            break;
        case 0x40: // gotoy byte
            fread(&y, 1, 1, fp);
            break;
        case 0x24: // print
            fread(&print_code, 1, 1, fp);
            if (print_code == 1)
            {
                gotoxy(x, y);
                printf(",");
            }
            break;
        default:
            break;
        }
    }
    fclose(fp);
    printf("\n");
    return 0;
}

And this is the output I get: enter image description here

I can really see the answer ("Sysco..?" But some of it is messed up and I dont know how. I found the gotoxy() function on line and it seems to work.. but not quite. I tried not using it and instead created 2d array size 255,255 and wrote it to a text file after while loop, result was the same as picture above. Any idea what I can do? I feel so close to the finish.. and don't know what to do haha. THANKS!!

Gal Birka
  • 581
  • 6
  • 16

2 Answers2

0

Each Opcode is an instruction, the byte given determines what the program should do.

Looks like you have only 4 opcodes, makes it pretty easy:

0x3F byte - gotox byte,

0x40 byte - gotoy byte,

0x2400 - print ' ',

0x2401 - print ','

You're on the right track, open the file and read byte by byte. When you get a byte(s) that you know (0x3F, 0x40, 0x2400, 0x2401), execute its correleated function (goto x, goto y, print ' ', print '.'

clbx
  • 154
  • 2
  • 15
  • So I run in while loop (for each byte) and check if currentByte== one of the opcodes. If it is not, I ignore and continue to next byte. If it is 0x24, I check if next byte is 0x00 or 0x01 and print accordingly, but I dont quite understand what goto x and y is.. Lets say currentByte is 0x3F (goto x) and next byte is 0x30.. what should I do? – Gal Birka Jan 07 '21 at 20:06
  • goto generally means go to a point in memory. So if you had the instruction ``goto x`` then you should read your next value from x and the one after that and so on as for what x and y are, thats something specific to your problem. Other than that it sounds like you have it figured out, you should give it a shot. – clbx Jan 07 '21 at 20:10
  • Thank you for your help, I really made some progress! I edited my main post, can you take a look and see if you have any idea how to finish this? Thanks again friend – Gal Birka Jan 07 '21 at 21:43
0

I tryed to solve this challange also, you did nice job on it! notice that in the middle of the file there is more opcode char. "2=%, 4=,, 16=#, 32=(, 64=/, 128=*" add them to your code and you will succsesfully finish this challange!

jonathan
  • 269
  • 1
  • 7
  • I think this is for printing, I chage your case 0x24 print "%" when print_code is 2 and "," when 4 and its look like it is finished – jonathan Jan 09 '21 at 13:47