News for hackers. Stuff that matters.
Re:Manually Creating an ELF Executable by sdegutis on Monday January 27, 2014 @12:17PM (#7131574)
Awesome. My wife and kids asked me if you can write computer programs using just 1s and 0s and I told them that assembly was the lowest you could use, apparently mistakenly. Gonna have to try this out!
Re:Manually Creating an ELF Executable by adestefan on Monday January 27, 2014 @08:04PM (#7134574)
Here's the DOS COM version. Copy this into HELLO.COM with a hex editor of your choice. It will run in dosbox (that's what I tested on) and should run in Windows COMMAND.COM on a 32-bit system.

  b409ba0d01cd21b44cb05dcd2148454c4c4f20574f524c442124
Here's the breakdown:

  b409    MOV AH, 09h    ; OUTPUT string
  ba0d01  MOV DX, 010Dh  ; address of output buffer (remember we're loaded into 0100h)
  cd21    INT 21h

  b44c    MOV AH, 4Ch    ; TERMINATE with return code
  b05d    MOV AL, 5Dh    ; return code
  cd21    INT 21h

  48454c4c4f20574f524c442124 "HELLO WORLD$" ; DOS strings are $ terminated
Back in the day we used to do this with the DEBUG.COM command. It's actually not that bad to do this. The thing that sucks is hand assembling and going back to fixup your addresses. It starts to get hairy if you need to flip around the CS and DS registers to shift in different segments.

As an exercise for the reader use the RET instruction instead of doing the return code stuff. If you want to really get into you you can look up how to read from the console and then display that string back to the user.

Re:Manually Creating an ELF Executable by drv on Monday January 27, 2014 @09:03PM (#7134836)
You can cheat a little bit and use RET rather than INT 21h to save a few bytes.

The way this works is pretty clever - the COM loader places an INT 20h instruction (the old-style terminate function) at offset 0 in the PSP (the 100h-byte-long structure loaded right before the contents of the COM file). The loader also sets up the word above the initial stack pointer to 0 so that a RET will return to address 0 and execute the INT 20h.

Re:Manually Creating an ELF Executable by adestefan on Monday January 27, 2014 @09:06PM (#7134850)
And the RET saves you one byte over the INT 20h. Oh what a different world we live in now.
Re:Manually Creating an ELF Executable by e12e on Monday January 27, 2014 @08:30PM (#7134694)
Wasn't there a Phrack Magazine article on typing in software from memory using debug.com? COM-files are funny. I seem to recall "echo d > restart.com" (or possibly "D") would give you a quick way to reboot a 3.11 machine (probably due to some crash or other, I never investigated why it worked - but a couple of other random characters would usually end up with a freeze...
Re:Manually Creating an ELF Executable by ajross on Monday January 27, 2014 @01:32PM (#7132126)
Of course you can, though on a modern system it's no longer possible to get code into the system by toggling electrical switches, which was the way computers were bootstrapped way back in the day.

But hand assembly isn't so far away from our experience. Woz famously wrote the original Apple ][ ROM by hand, including the BASIC interpreter (itself written in a "SWEET16" bytecode for which he hand-assembled the interpreter). I don't know what the tooling looked like for that; surely he wasn't hand-toggling this thing in every time. Presumably the monitor and casette interface were written first...

Re:Manually Creating an ELF Executable by jsolson on Monday January 27, 2014 @07:06PM (#7134304)
> Of course you can, though on a modern system it's no longer possible to get code into the system by toggling electrical switches, which was the way computers were bootstrapped way back in the day.

Challenge accepted.

Re:Manually Creating an ELF Executable by adestefan on Monday January 27, 2014 @03:20PM (#7132916)
The easiest way to do this is to actually build a COM file and run it in a 32-bit version of Windows. COM has no header information at all and just starts running the x86 instructions after loading the file to 0100h.
Re:Manually Creating an ELF Executable by spacey on Tuesday January 28, 2014 @04:46AM (#7136242)
Even more impressive than this hello world and with 29 byte just 3 byte bigger:

  b013cd10c52f0f3197b18cb38cfe018009804b75f881c74001e2f0ebe9
I made this in 2001 and used it once in a job interview, I asked for access to a computer running XP, opened cmd.exe and debug.exe, entered the asm code (rdtsc is not supported by debug.exe but i remembered the 0f31 opcode) and blew someones mind.
Re:Manually Creating an ELF Executable by deeepinit on Monday January 27, 2014 @12:57PM (#7131859)
Assembly opcodes are 0's && 1's.
Re:Manually Creating an ELF Executable by sdegutis on Monday January 27, 2014 @12:59PM (#7131874)
Sure but that's not nearly as magical as writing literal numbers in a file and running it.