Portable executable in C
I've been reading up on portable executables(Portable Executable - Wikipedia, the free encyclopedia), as they quite interest me. I would hate to have to compile my programs to work on different processors. This is in windows I am talking about. I read up a bit on Wow64, but I would like to target Windows 2000+. Alright, I'm going to use an analogy of something that interests me. On pentest forums I see malware developers saying that their malware will work on Windows 2000, xp, vista/win7 32/64bit. The only way I can imagine this can work is because they make their programs Portable executables(Like in the Wiki link). Am I correct on this one? Does anybody have any tutorials on making C programs portable? I have used Google to try and find some, but sometimes the best information doesn't always show up. I'm guessing you guys would have the best knowledge in this and could give me some references. Please and thank you. :biggrin:
Portable Executable format is portable only in the sense that the executable wrapper itself is versatile enough that it can be used in a variety of systems and architectures. The executable code inside the wrapper has to be compiled for whatever system will run it.
I'm sure you've been told this in another thread already, but I'll say it again: all the Windows systems you listed can run 32-bit x86 executables. They're not "different processors" if you stick with the 32-bit instruction set that they have in common.
You have a fundamental misunderstanding of PE's. The word 'portable' has *nothing* to do with 'portable applications'. It was originally named that because the format was robust enough to allow for all sorts of use, but in practice it is only used in Windows. So, again, forget the word portable and just say PE, it will simplify things for you ;p. Source: Author of PECompact, been writing PE manipulation utilities for 15 years.
Now, as far as Windows 2000 compatibility, Microsoft dropped that from Windows Visual Studio 2010. To achieve compatibility, you have to change the OS MajorVersion/MinorVersion settings in the PE header, *or* use VS2008 (VC9) build tools. Similarly, Microsoft dropped XP/2003 in VS2012 (VC11), so you need to use the older platform toolset (VC10) to build utilities compatible with XP. Due to this rapid abandonment of Windows 2000, XP, 2003 by Microsoft, I have dropped Windows 2000 myself. I still support XP though, and am using VC10 with VS2012 until the announced out-of-band update to VS2012 restores proper XP/2003 target support.