Copy machine code from windows executable and run on linux

≯℡__Kan透↙ 提交于 2019-12-11 08:46:56

问题


I copy the machine code of a function on Windows.

For example:

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

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?)

P.S. The question regards to a distributed system question.


回答1:


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.

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.




回答2:


There is a wine program (and project) which is not an emulator. It will take exe file from windows and run it in the linux directly. Most used WinAPI will be translated to linux and to X11 graphic system.

If you want just to run exe files from windows under linux - this will be the answer. If you want know how to do this, you can read sources of Wine and/or documentation of wine and/or articles about wine and its design. Or ask authors of the wine in mailing list.



来源:https://stackoverflow.com/questions/7296410/copy-machine-code-from-windows-executable-and-run-on-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!