.sh and .bat should self-extract an executable stub for the supported platforms #15

Open
opened 2018-07-28 23:25:56 +01:00 by SuzanneSoy · 0 comments
SuzanneSoy commented 2018-07-28 23:25:56 +01:00 (Migrated from github.com)

printf (which is I think part of the POSIX standard) should make it relatively easy to produce a binary stub.

For MS-DOS, things are not that easy since not all characters can be printed to a file. The following post lists some possibilities (using debug, which is not present on all systems, producing a VBScript, using echo (can't handle all characters), set /p (/p option not present on older systems) or other built-in commands). I think the best solution would be to use echo to create a very small binary stub (a .COM and/or .EXE) which is capable of sending to STDOUT or to a file the rest of the binary data, based on a (e.g.) base64 output. The extraction would then proceed in three stages:

  • extract the short stub, which is hand-crafted to only contain characters that can be printed (hoping that NULL or other problematic characters will never be needed in any header or opcode, which might be difficult on ARM versions of Windows, but those should usually have other tools available like VBS, PowerShell or other).
  • run the short .COM or .EXE stub, passing it some base64 (or other base) data, that it writes to a second .COM or .EXE file
  • run the second .COM or .EXE file, which reads back from the original os.bat to produce the final result.exe (and delete all intermediate files subsequently)

https://www.experts-exchange.com/questions/26372121/DOS-Batch-file-to-write-Binary.html

There might be a solution using a fixed header that can be printed by MS-DOS echo, followed by binary data that matches the entire os.bat file. The extraction would then consist in printing a tiny header, and using copy header.txt+os.bat result.exe to concatenate them.

`printf` (which is I think part of the POSIX standard) should make it relatively easy to produce a binary stub. For MS-DOS, things are not that easy since not all characters can be printed to a file. The following post lists some possibilities (using `debug`, which is not present on all systems, producing a VBScript, using `echo` (can't handle all characters), `set /p` (`/p` option not present on older systems) or other built-in commands). I think the best solution would be to use `echo` to create a very small binary stub (a `.COM` and/or `.EXE`) which is capable of sending to STDOUT or to a file the rest of the binary data, based on a (e.g.) base64 output. The extraction would then proceed in three stages: * extract the short stub, which is hand-crafted to only contain characters that can be printed (hoping that NULL or other problematic characters will never be needed in any header or opcode, which might be difficult on ARM versions of Windows, but those should usually have other tools available like VBS, PowerShell or other). * run the short `.COM` or `.EXE` stub, passing it some base64 (or other base) data, that it writes to a second `.COM` or `.EXE` file * run the second `.COM` or `.EXE` file, which reads back from the original `os.bat` to produce the final `result.exe` (and delete all intermediate files subsequently) https://www.experts-exchange.com/questions/26372121/DOS-Batch-file-to-write-Binary.html There might be a solution using a fixed header that can be printed by MS-DOS `echo`, followed by binary data that matches the entire `os.bat` file. The extraction would then consist in printing a tiny header, and using `copy header.txt+os.bat result.exe` to concatenate them.
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: suzanne.soy/os-test-framework#15
No description provided.