Copy machine code from windows executable and run on linux
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.
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.
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.
精彩评论