从Windows可执行文件复制机器代码并在Linux上运行 [英] Copy machine code from windows executable and run on linux

查看:365
本文介绍了从Windows可执行文件复制机器代码并在Linux上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows上复制函数的机器码。

I copy the machine code of a function on Windows.

例如:

void func()
{
    printf("hello");
}

在上面的例子中,我将复制 func )的十六进制代码段数据和 printf()的十六进制代码数据加上其他依赖和数据,并重新链接到运行linux ,是否可以在linux机器上运行代码,如果正确重新链接?

In the above case, I would copy func()'s hex code segment data and printf()'s hex code data plus other dependencies and data and relinked it on a differnt machine running linux, would it be possible to run the code on a linux machine if properly relinked?

如果是这样,会有一个许可问题? (是合法吗?)

And if so would it there be a licensing problem? (Is it legal?)

推荐答案

这是一个非常模糊/不可回答的问题,但这将是非常困难的,如果不是不可能。你有一些困难需要解决。即,可执行格式(Linux上的ELF,Windows上的PE),系统/编译器之间的调用约定等。

This is a pretty vague/unanswerable question, but this would be extremely difficult, if not impossible. You have a number of difficulties which would need addressed. Namely, the executable format (ELF on Linux, vs PE on windows), the calling conventions between systems/compilers, etc.

我能想到的最大的问题是Linux和Windows之间的文件处理极为不同。你最好的打赌不会是复制printf(),而是将该调用重定向到Windows实现,因为在所有的库函数工作之后,对控制台的低级写入是非常不同的。

The biggest issue I can think of, is that the file handling between Linux and Windows is extremely different. Your best bet would not be to copy printf(), but to redirect that call to the windows implementation, because after all of the library function work, the low-level write to the console is very different.

这篇关于从Windows可执行文件复制机器代码并在Linux上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆