Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

programmers?

Name: Anonymous 2011-06-27 15:13

So eventually there will be programmers in /prog/?  Dinosaurs on the dinosaur tour?

Name: Anonymous 2011-06-27 15:58


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

#define R(L) for (;;) (L)
#define E(P) puts((P))
#define P(E) ((char *(*)(void))(E))()
#define L(R) fgets((R), sizeof (R), stdin)

int main(int ac, char **av) {
        unsigned char _[ac == 2 && atoi(av[1]) > 0 ? atoi(av[1]) : 1024];
       
        R(E(P(L(_))));
}

Name: Anonymous 2011-06-27 16:00

>>2
Error: Not all code paths return a value

Name: Anonymous 2011-06-27 16:12

THIS THREAD HAS BEEN REPLACED BY A /PROG/ CHALLENGE

WRITE A HELLO-WORLD PROGRAM FOR THE MACHINE CODE INTERPRETER GIVEN IN >>2


>>3                                
BACK TO THE IMAGEBOARDS, ``FAGGOT''.

Name: Anonymous 2011-06-27 16:25

>>4
It's not an interpreter, it's a REPL.

Name: Anonymous 2011-06-27 16:47

>>2

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

#define P(L) for (;;) (L)
#define E(P) puts((P))
#define R(E) ((char *(*)(void))(E))()
#define L(R) fgets((R), sizeof (R), stdin)

int main(int ac, char **av) {
        unsigned char _[ac == 2 && atoi(av[1]) > 0 ? atoi(av[1]) : 1024];
      
        P(E(R(L(_))));
}

wait, what?

Name: Anonymous 2011-06-27 21:26

>>2
(Obviously unportable) machine code REPL? Who would have thought!
>>4
Easy enough, here's an x86 one (should work on *nix and win32):
Assembly:

call next
szHi db "Hello World",0
next:
pop eax
retn

Assembled:
E8 0E 00 00 00 48 65 6C 6C 6F 20 57 6F 72 6C 64 21 00 00 58 C3

This would work fine, but unfortunately on some systems nulls and other characters may end up being corrupted by encoding conversion code. A better solution is to attempt to stay within readable ASCII range (or close to it), here's my second attempt:

33C0            XOR EAX,EAX
50              PUSH EAX
68 726C6421     PUSH 21646C72
68 6F20776F     PUSH 6F77206F
68 48656C6C     PUSH 6C6C6548
54              PUSH ESP
58              POP EAX
59              POP ECX
59              POP ECX
59              POP ECX
59              POP ECX
C3              RETN

Assembled:
33 C0 50 68 72 6C 64 21 68 6F 20 77 6F 68 48 65 6C 6C 54 58 59 59 59 59 C3
Much better but still not completly alphanumeric (return and the initial xor (which could be done away with)). The main challenge remains the return which could be converted into a jump, but almost all jumps that I can think of lie outside of readable ASCII range, in which case one solution would be to use self-modifying code (you're already running stuff from the stack, it will work fine) which decrypts a stub of code and runs it (in this case just the return), but if you're going to use self-modifying code, why not just use one of those automatic shellcode generators which support alphanumeric output and be done with it (one example would be ALPHA3)?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List