简体   繁体   English

Windows可执行文件,内部带有Linux Shell脚本

[英]Windows executable with linux shell script inside

To me, this sounds like mission impossible, but there are people who know more than me, so i thought maybe i have a chance :) 对我来说,这听起来像是不可能完成的任务,但是有些人比我更了解,所以我想也许我有机会:)

I would like to have 1 file that would execute on both - windows and linux. 我想拥有1个在Windows和Linux上都可以执行的文件。

Basically, program could be made out of 2 parts. 基本上,程序可以分为两部分。
Part 1 being the windows executable which can run on windows. 第1部分是可以在Windows上运行的Windows可执行文件。
Part 2 being the linux shell script which can run on linux. 第2部分是可以在linux上运行的linux shell脚本。

Is there a way to build the file in such a way, that linux could ignore the windows binary executable bytes and just run the shell script which is appended as text onto the binary windows executable? 有没有办法以这种方式构建文件,使得Linux可以忽略Windows二进制可执行文件字节,而只运行作为文本附加到二进制Windows可执行文件的shell脚本?

I've tried to add bytes before the windows exe, and of course windows fails to recognize the file. 我尝试在Windows exe之前添加字节,但是Windows当然无法识别该文件。 So yeah, i can't put anything before the bytes of executable, however i CAN add them at the end of file. 所以,是的,我不能在可执行文件的字节之前放置任何内容,但是我可以在文件末尾添加它们。

Then, on linux, i took the plain script 然后,在Linux上,我采用了普通脚本

#!/bin/bash
echo "Hello world?"
exit 0

and added some text before the script. 并在脚本之前添加了一些文本。 All it did was complain about non existent command, but continued to execute the file and i got the "hello world" text outputted. 它所做的只是抱怨不存在的命令,而是继续执行该文件,并且输出了“ hello world”文本。

Putting those two things together ( cat runLinuxPart.sh >> myMix.exe ) and then chmod +x myMix.exe then run it, i get The entry point method could not be loaded :( 将这两件事放在一起( cat runLinuxPart.sh >> myMix.exe ),然后chmod +x myMix.exe然后运行它,我得到The entry point method could not be loaded :(

The linux shell file is a sort of self extractor-installer. linux shell文件是一种自解压安装程序。 It hold the .tar at the end and the script on the front, so if i run the .sh on linux, it gets the .tar, extracts and does all i need. 它将.tar放在最后,将脚本放在最前面,因此,如果我在Linux上运行.sh,它将获取.tar,提取并完成我需要的所有操作。

The windows exe purpose is to connect to remote linux machine, extract .sh file from itself and upload it to linux, then run it. Windows exe的目的是连接到远程linux计算机,从其自身提取.sh文件并将其上传到linux,然后运行它。

I want to give a single self installer file to users. 我想给用户一个自助安装文件。

If this my dream is impossible i will of course be ok with 2 separate installers too 如果这个梦想不可能实现,那么我当然也可以选择2个独立的安装程序

A Linux shell script should start with #! Linux shell脚本应以#!开头#! . A Linux ELF executable should start with \\x7FELF . Linux ELF可执行文件应以\\x7FELF If a Windows executable cannot start with these bytes your dream is not possible. 如果Windows可执行文件不能以这些字节开头,那么您的梦想就不可能实现。 I believe that PE (the binary format of Windows executable) cannot start with these (but I am not sure). 我相信PE (Windows可执行文件的二进制格式)不能以此开头(但我不确定)。 Hence your universal installer single file is an impossible dream. 因此,通用安装程序单个文件是不可能实现的梦想。

On Linux, you could consider playing with binfmt_misc or shar . 在Linux上,您可以考虑使用binfmt_miscshar

Read Levine's Linkers and Loaders book, and elf(5) & execve(2) Linux man pages. 阅读Levine的Linkers and Loaders一书,以及elf(5)execve(2) Linux手册页。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM