flat assembler
Message board for the users of flat assembler.

Index > DOS > A binary executable which can be executed backward

Author
Thread Post new topic Reply to topic
FlierMate



Joined: 21 Jan 2021
Posts: 31
Location: Malaysia
FlierMate
I wish to share this DOS .COM executable in which the machine code is the same if reading from end to start, or from start to end.

This is my submission for a small contest.
Code:
JMP 103             EB01
RET                 C3
MOV AX, B800        B800B8
MOV ES, AX          8EC0
MOV DI, 07D0        BFD007  
MOV AX, 9090        B89090
MOV ES:[DI], AX     268905
ADD AX, 2689        058926
NOP                 90
NOP                 90
MOV AX, D007        B807D0
MOV DI, 8EC0        BFC08E
MOV AX, B800        B800B8
RET                 C3
ADD BX, BP          01EB    


Fun?
Post 27 Jan 2021, 04:11
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17942
Location: In your JS exploiting you and your system
revolution
Nice. That is a palindrome.

I think you can add any arbitrary number of "EB01C3 ... C301EB" bytes at each end to fill out the full 64k.
Post 27 Jan 2021, 05:24
View user's profile Send private message Visit poster's website Reply with quote
FlierMate



Joined: 21 Jan 2021
Posts: 31
Location: Malaysia
FlierMate
revolution wrote:
Nice. That is a palindrome.

I think you can add any arbitrary number of "EB01C3 ... C301EB" bytes at each end to fill out the full 64k.


Your idea is good, never thought of that. Smile
Post 27 Jan 2021, 06:02
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3076
Location: vpcmipstrm
bitRAKE
Technically, RETN is palindromic - from there we might ask which lengths of executables can be palindromic? 1,(34+6n ; n>=0) have been presented so far. Very Happy

Just to be pedantic we should state they must be valid for the OS and return (halt).
Post 27 Jan 2021, 18:37
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17942
Location: In your JS exploiting you and your system
revolution
If all, or most, of the code must be executed then the problem is harder.

Otherwise we can have any valid arbitrary code as the first half, and simply place the reversed bytes at the end.
Post 28 Jan 2021, 14:11
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3076
Location: vpcmipstrm
bitRAKE
That's a good point. For example,

{C3,...}{...,C3} for even lengths
{C3,...}XX{...,C3} for odd.

The length should be truncated at the point execution is returned to the OS. So, all the above would have an actual length of one.

_________________
¯\(°_o)/¯ unlicense.org
Post 29 Jan 2021, 08:36
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17942
Location: In your JS exploiting you and your system
revolution
Even simpler:

Odd: {anything}C3{reversed anything}
Even: {anything...C3}{C3...reversed anything}

Where"anything" is any valid code. Hex editor, game, etc.
Post 29 Jan 2021, 08:57
View user's profile Send private message Visit poster's website Reply with quote
FlierMate



Joined: 21 Jan 2021
Posts: 31
Location: Malaysia
FlierMate
The rules of the contest was:

Quote:

Scores will be calculated based on both the size of the executable, as well as
the percentage of bytes executed when it is run.

An easy solution would be to just have the binary end, and append the binary
backwards at the end of the original file. Because of this, in order to qualify
for entry, your binary must at a minimum execute > 50% of the bytes in your
binary, and must execute past the halfway mark in your binary as well.


The mirrored side of the code has to be executed to qualify...
Post 29 Jan 2021, 12:40
View user's profile Send private message Reply with quote
FlierMate



Joined: 21 Jan 2021
Posts: 31
Location: Malaysia
FlierMate
This is the organizer website: https://n0.lol/bggp/

The contest is called BGGP.
Post 29 Jan 2021, 12:45
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7862
Location: Kraków, Poland
Tomasz Grysztar
FlierMate wrote:
The rules of the contest was:

Quote:

Scores will be calculated based on both the size of the executable, as well as
the percentage of bytes executed when it is run.

An easy solution would be to just have the binary end, and append the binary
backwards at the end of the original file. Because of this, in order to qualify
for entry, your binary must at a minimum execute > 50% of the bytes in your
binary, and must execute past the halfway mark in your binary as well.
The mirrored side of the code has to be executed to qualify...
The rules as quoted above are easy to circumvent, with something like:
Code:
; arbitrary code A, ending with:
jmp filler

; reversed code B (never executed)

filler:
; a whole lot of NOPs, or other similarly trivially palindromic code

; arbitrary code B (should end with program termination)

; reverse of "jmp filler", and:
; reversed code A (never executed)    
Because you can put as many NOPs in the middle as you wish, it is not hard to make 50%, or even 90% of file be executed, and you can still put any code in there (into A and B portions).

And even if you were not allowed, for example, to put NOP sequences in your code, you could replace it with some other instructions that would be trivially palindromic, like a 24 24 ("and al,24h") or 1C 1C ("sbb al,1Ch"), any of the single-byte opcodes that has no disruptive effect on your program (like CLC, STC, AAA), etc. etc. You could even mix and match them to make a randomly-looking filler.

I would say it is actually a serious challenge to write good rules for such contest, as I found out myself when writing rules for my 512-byte coding contest last year. In the end organizers may need to rely on human assessment, at least to some extent.
Post 29 Jan 2021, 12:59
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.