Linux 上的 COFF 或 Windows 上的 ELF

发布于 2024-08-14 00:51:25 字数 99 浏览 3 评论 0原文

是否可以在 UNIX 上运行 COFF 可执行文件或在 Windows 上运行 ELF 可执行文件?要在 Windows 和 UNIX 上运行任一文件类型需要执行哪些步骤。我只是好奇。

Is it possible to run the COFF executable files on UNIX or the ELF executable files on Windows? And what would be the steps to be able to run either file type on Windows and UNIX. I'm just curious.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

浅忆 2024-08-21 00:51:25

要正确回答您的问题,有必要回顾一下 ELF、COFF 和 PE 是什么。这些二进制格式本质上只是容器,它们向操作系统提供有关如何执行文件中包含的原始 CPU 指令的指示。它们非常类似于 MKV、WMV 和 OGG 等音频/视频容器。对可执行格式的支持要么在操作系统中,要么不支持。直到最近,Microsoft Windows 一直不提供对 COFF 或 ELF 的任何支持。在 Windows 10 中,Microsoft 通过构建 Windows 内核 UserMode-Linux 兼容系统例程来提供对 ELF 的间接支持。 UserMode Linux 内核运行在 Windows 内核之上,并运行所有 ELF 二进制格式,几乎就像独立于 MS Windows 运行一样。

使用 UserMode-Linux(子内核)的替代方案是 Microsoft 以完全兼容的格式重写大部分 Linux API,他们的选择解决了另一个兼容性问题:API。 “A”代表应用程序,“I”代表接口,但是API作为接口主要只是一组可执行例程和环境假设。对文件系统和最基本的系统例程的访问由 Windows 内核提供,而其他所有内容均在 UserMode Linux 内核中提供。这样,Windows 不仅可以运行 ELF 格式的可执行文件,还可以运行已在 Linux API 上运行的最流行的 ELF 可执行文件。

相反,问题的另一半,在 Linux 上运行 PE(大多数 Microsoft Windows 可执行文件)也是可能的。有两个运行时包装库可以运行 MSIL(虚拟机应用程序)和 Win32(普通 CPU 应用程序)。由于 Linux 内核可扩展以识别某种字节格式,然后运行适当的包装程序,因此内核实际上支持 PE 和潜在的更多可执行容器格式。因此,Linux 可以在 Mono 运行时(.NET/C# 应用程序)或 WINE 运行时(Win32 C/C++)中运行某些 PE 程序。

要安装 UserMode-Linux 环境,您可以按照 微软的开发网络。总结一下:

  1. 打开开发者模式:设置|更新&安全|对于开发人员 |检查开发人员模式单选按钮
  2. 从开始菜单中,打开“打开或关闭 Windows 功能”
  3. 向下滚动并检查“Windows Subsystem for Linux (Beta)”功能
  4. 点击“确定”并重新启动(必需步骤)
  5. 重新启动后,打开 PowerShell/命令提示符并运行“Bash”,然后按照简单的提示接受 Canonical 的许可证并开始下载 Ubuntu 映像 下载
  6. 完成后,您将能够从“开始”菜单启动“Bash on Ubuntu on Windows

”请注意,此方法仅适用于 Windows 10,并且仍然仅限于文本模式控制台和 Xorg 的 Win32 端口(如 vcXsrv),用于任何图形。 Cygwin 或 MSYS2 系统无法运行 ELF 二进制文件,但可以在 Linux 系统上移植和运行通常为 ELF 二进制文件的相同应用程序。

To answer your question properly, it is relevant to review what ELF, COFF, and PE are. These binary formats are essentially just containers that give directions to the operating system about how to execute the raw CPU instructions contained in the file. They are very much like audio/video containers like MKV, WMV, and OGG. Support for the executable format is either in the operating system or not. Microsoft Windows has consistently not given any support for COFF or ELF, until recently. With Windows 10, Microsoft has provided indirect support for ELF by building into the Windows kernel UserMode-Linux compatible system routines. A UserMode Linux kernel runs on top of the Windows kernel and runs all ELF binary formats almost as if it were running independent of MS Windows.

The alternative to using the UserMode-Linux (sub-kernel) being for Microsoft to rewrite the majority of the Linux API in a completely compatible format, their choice solves one other compatibility issue: The API. "A" stands for Application and "I" for Interface, however the API as an interface is mainly just a set of executable routines and environment assumptions. Access to the filesystem and most basic system routines is provided by the Windows kernel, while everything else is provided in the UserMode Linux kernel. This way not only can Windows run ELF formatted executables, but in can run the most popular ELF executables that are already made to run on the Linux API.

The reverse, the other half of the question, running PE (most Microsoft Windows executables) on Linux is possible as well. There are two runtime wrapping libraries that can run MSIL (virtual machine application) and Win32 (normal CPU application). Because the Linux kernel is extendable to recognize a certain byte format, then run an appropriate wrapper program, in effect the kernel supports PE and potentially more executable container formats. Therefore, Linux can run some PE programs either in the mono runtime (.NET/C# applications) or in the WINE runtime (Win32 C/C++).

To install the UserMode-Linux environment you can follow instructions provided on Microsoft's Development Network. To summarize:

  1. Turn on Developer Mode: Settings | Update & Security | For Developers | Check the Developer Mode radio button
  2. From the start menu, open “Turn Windows Features on or off”
  3. Scroll down and check the “Windows Subsystem for Linux (Beta)” feature
  4. Hit okay and reboot (required step)
  5. Once rebooted, open a PowerShell/command prompt and run “Bash” and follow the simple prompts to accept Canonical’s license and kick-off the download of the Ubuntu image
  6. After download has completed, you’ll be able to start “Bash on Ubuntu on Windows” from the Start menu

Be aware this method only works on Windows 10 and is still limited to text-mode console and a Win32 port of Xorg like vcXsrv for anything graphical. Cygwin or MSYS2 systems are not able to run ELF binaries, but make it possible to port and run the same applications that are normally ELF binaries on a Linux system.

卸妝后依然美 2024-08-21 00:51:25

要实际运行可执行文件并让它们做有用的事情,您需要担心 API,而不仅仅是可执行文件格式。在安装了 WINE 的 Linux 计算机上,您可以从命令行运行 Windows .EXE 文件,它们执行与 Windows 上相同的操作。

相反的方式实际上是不可能的,但是如果您在 Windows 计算机上安装 CYGWIN,然后使用 CYGWIN 编译器从源代码重建应用程序,您将获得一个在 Windows 上运行的可执行文件,并且执行与 Linux 可执行文件相同的操作Linux。许多标准 Linux 工具已经被移植到 CYGWIN 存储库中,包括 X-Windows 和 GIMP 等工具。

To actually run executables and have them do useful stuff, you need to worry about the API, not just the executable file format. On a Linux machine with WINE installed, you can run Windows .EXE files from the command line and they do the same thing that they do on Windows.

The other way around is not really possible, however if you install CYGWIN on a Windows machine, and then rebuild the application from source with CYGWIN compilers, you will get an executable that runs on Windows and does the same thing that the Linux executable does on Linux. Lots of standard Linux tools are already ported and in the CYGWIN repository including stuff like X-Windows and GIMP.

冷︶言冷语的世界 2024-08-21 00:51:25

http://lbw.sourceforge.net/ 比线效果更好。
low 是做同样事情的另一个项目,但效果较差。

编辑: http://atratus.org/ 似乎也可以做同样的事情,而不需要 Interix/SFU 。

http://lbw.sourceforge.net/ works better than line.
low was another project for doing the same thing, but that was the less working.

EDIT: http://atratus.org/ seems to do the same as well, without the need to have Interix/SFU.

只为一人 2024-08-21 00:51:25

COFF 最初是由 UNIX(大约 System V 或附近)引入的,所以是的,某些 UNIX 可能仍然支持 COFF 格式。 Linux 已弃用它至少有一段时间了,想必大多数其他 Unices 也已弃用或彻底放弃支持。

Windows ELF 支持有点不确定——如果没有一些深奥的技巧,几乎肯定不会存在。你应该更具体地说明你想在这里做什么......

COFF was originally introduced by UNIX (around System V or thereabouts) so yes, some UNIX probably still supports COFF format. It's been deprecated by Linux at least for a while, and presumably most other Unices have also deprecated or outright dropped support.

Windows ELF support is a bit more iffy - almost certainly not there without some deep trickery. You should be more specific about what you're trying to do here...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文