3 ms·
Wow, I’m super happy to see folks interested in my little project! I was inspired to do this thanks to a challenge posted to Twitter. It was fun putting togethe
by nneonneo 6y ago
Wow, I’m super happy to see folks interested in my little project! I was inspired to do this thanks to a challenge posted to Twitter. It was fun putting together this binary and learning more than I thought I was going to learn about DOS extenders and the PE format. Happy to answer any questions!
- btilly 6y agoHow hard would it be to add support for other operating systems like OS X as well?
- jonny_eh 6y agoMy guess is that the headers would be incompatible.
- obverse 6y agoI've tried going down that rabbit hole before. The primary issue that stopped me was the different executable file formats. I never took it anywhere, but I think the way to go would be a "polyglot" script that could be interpreted by different script engines (sh/bat) that would then pick the correct executable for the given OS. This would require the user to change the file extension as well as download multiple executable files so I don't necessarily like this solution from an elegance stand point.
- sgtnoodle 6y agoI've had good success with shebangs combined with zip archives containing python code. Zip files use a footer rather than a header, and python natively supports executing scripts out of them. The beginning of the file can have a shebang, allowing it to specify the interpreter to use. The only trick is that windows doesn't support shebangs, and so you need to associate your chosen file extension with python on every system. Also, you need python installed obviously. What that gives you is a stable entry point into python code. From there, you can run whatever platform specific code you want.
- nneonneo 6y agoMost file formats have a magic number at offset 0. The magic numbers for EXE ("MZ"), OS X (0xfeedface/0xfeedfacf) and Linux ("\x7fELF") are all different, so they aren't compatible.
- viraptor 6y agoNot on windows, but that depends on the OS. On Linux the handlers are pluggable via binfmt (https://en.m.wikipedia.org/wiki/Binfmt_misc https://en.m.wikipedia.org/wiki/Binfmt_misc) and this allows for example wine and .net binaries to work transparently. (I'm not aware of it, but maybe there a similar system in windows)
- pwdisswordfish4 6y agoαcτµαlly pδrταblε εxεcµταblε https://news.ycombinator.com/item?id=24256883 https://news.ycombinator.com/item?id=24256883 https://justine.storage.googleapis.com/ape.html https://justine.storage.googleapis.com/ape.html
- wizzwizz4 6y agoThe PE magic number doesn't need to be at offset zero, which is why you can do this. Mach and ELF do need to be at offset zero, so you can't have something that's Mach and ELF at the same time. In theory, this is possible, if you can recover from COM executing the header.
- mehrdadn 6y agoDo you know of a good way (if any) to shrink the size of the DOS header as much as possible on MSVC? (Like to remove the "This program cannot be run in DOS mode" notice, and other things you don't need on Windows.)