Thread: How can I make binary compatible code?

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    69

    Question How can I make binary compatible code?

    Well... How do malware developers do it? How do they compile a single executable that can run on all machines and all Windows versions?

    I'm talking about this:
    Binary code compatibility - Wikipedia, the free encyclopedia
    Computer compatibility - Wikipedia, the free encyclopedia

    Thanks.

    NOTE: this is in-relation to one of my previous threads (not so important, but I'll note this):
    How come C can be cross-processor/architecture, but ASM can't?

  2. #2
    Registered User
    Join Date
    Mar 2009
    Posts
    344
    You'll need to ask the right question - do you want to run on all machines or just on all Windows machines? Those are two very different goals.

  3. #3
    Registered User
    Join Date
    May 2012
    Posts
    1,066
    Quote Originally Posted by inu11byte View Post
    Well... How do malware developers do it? How do they compile a single executable that can run on all machines and all Windows versions?
    They don't compile a single executable as far as I know. They usually trick you to download a Java-applet which can determine which platform you use and then load the platform-specific part in the background.

    But you can't use for example a binary for the Windows platform on Linux or Mac (disregarding any emulator/virtual machine in between).

    See also Cross-platform - Wikipedia, the free encyclopedia (Subsection "Binary software")
    Bye, Andreas

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Pick any windows program you can download off the net (I dunno, let's say WinZip)

    System Requirements:
    Microsoft Windows 7, Windows Vista, or Windows XP
    No mention of 32 or 64 bit
    No mention of Intel / AMD / Cyrix (or whoever else makes x86 compatible processors).
    The average end user doesn't care, they just want a single download that's easy to identify.

    Now, if you're a Mac user, you would want the "WinZip Mac Edition". Because it's a different OS, the interface calls to the OS, the file system and the GUI are going to be different. There is likely to be a lot of COMMON C (or C++) code, but it will be compiled with a Mac specific compiler, producing Mac specific code.

    > Well... How do malware developers do it?
    This is the second thread you've started where you seem to be more interested in what the dark side of the force is up to.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Dec 2011
    Posts
    69
    Quote Originally Posted by KCfromNC View Post
    You'll need to ask the right question - do you want to run on all machines or just on all Windows machines? Those are two very different goals.
    Sorry, I should have been more clear; I want my executable to run on all Windows machines.

  6. #6
    Registered User claudiu's Avatar
    Join Date
    Feb 2010
    Location
    London, United Kingdom
    Posts
    2,094
    Quote Originally Posted by inu11byte View Post
    Sorry, I should have been more clear; I want my executable to run on all Windows machines.
    1)You sound like you are up to no good.

    2)You probably can't write code that works on any machine yet you want to write some hackbarf to steal your girlfriend's email password or some stupid thing like that.

    3)This is not a C question in the first place, it's just a waste of our time.

    4)Please desist!
    1. Get rid of gets(). Never ever ever use it again. Replace it with fgets() and use that instead.
    2. Get rid of void main and replace it with int main(void) and return 0 at the end of the function.
    3. Get rid of conio.h and other antiquated DOS crap headers.
    4. Don't cast the return value of malloc, even if you always always always make sure that stdlib.h is included.

  7. #7
    Registered User
    Join Date
    Mar 2009
    Posts
    344
    Quote Originally Posted by inu11byte View Post
    Sorry, I should have been more clear; I want my executable to run on all Windows machines.
    All versions? How far back do you want to go? Windows 1.0? Windows 95?

  8. #8
    Registered User
    Join Date
    Dec 2011
    Posts
    69
    Quote Originally Posted by KCfromNC View Post
    All versions? How far back do you want to go? Windows 1.0? Windows 95?
    No, no, no. Windows 2000 at the very furthest back that I'd every target.
    Reason: WinAPI functions wont work too far back and there's no point really targeting anything that's before XP.

    Quote Originally Posted by claudiu View Post
    1)You sound like you are up to no good.

    2)You probably can't write code that works on any machine yet you want to write some hackbarf to steal your girlfriend's email password or some stupid thing like that.

    3)This is not a C question in the first place, it's just a waste of our time.

    4)Please desist!
    1. I'm always up to no good.
    2. I can write basic C code, extremely basic ASM, and web development languages, such as XHTML, PHP, Jquery, and Javascript. My mentions of botnets was just a mere example, I don't wish to code any malware in the near future.
    3. It relates to C. I want to know how I can do this in C.
    4. Don't be an .............., especially when you offer no help.
    Last edited by inu11byte; 08-09-2012 at 01:22 AM.

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    So make sure that any Win32 API function you call lists in the Requirements section that the Minimum supported client is Windows XP.

    If the function was introduced in say Vista, then don't call it - it's that simple.

    And make sure you DON'T fiddle about with the compiler code generation options - just leave it targeted at a generic pentium (or whatever the base processor is). Don't go round ticking feature specific boxes like "sse" or anything else that would limit the range of processors on which it will run.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  10. #10
    Registered User
    Join Date
    Dec 2011
    Posts
    69
    Quote Originally Posted by Salem View Post
    So make sure that any Win32 API function you call lists in the Requirements section that the Minimum supported client is Windows XP.

    If the function was introduced in say Vista, then don't call it - it's that simple.

    And make sure you DON'T fiddle about with the compiler code generation options - just leave it targeted at a generic pentium (or whatever the base processor is). Don't go round ticking feature specific boxes like "sse" or anything else that would limit the range of processors on which it will run.
    Thank you very much, this was a prefect reply. So, as long as I check processor specific options, my code should run on all Windows machines? If I make a simple hello world program, it will run regardless of the processor? Sorry if I sound like an idiot asking all of these questions, I just want to understand the architecture and the language so I can utilize it to its full extent.

  11. #11
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    No! Re-read it! You DON'T want to check any processor specific options! Also, check the requirements list for any Win32API function that you use, to make sure it's compatible with the Windows versions you want your program to run on.

    Also, there are work arounds, for example, say you want to do *something* with files, so you need the list of files in the directory you're in. You could use an API to get that list of files, OR you could get it by using a system call with "dir *.* > filelist.txt", and direct the output to a file called filelist.txt, then read the file. Since "dir" and redirected output has been a feature since *forever*, it's bound to be compatible with ALL DOS and Windows systems.

  12. #12
    Registered User
    Join Date
    Dec 2011
    Posts
    69
    My bad, I didn't proof read my post before posting it. I was meaning 'So, as long as I don't check processor specific options, my code should run on all Windows machines? Sorry for the seemingly stupid post.

  13. #13
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by inu11byte View Post
    My bad, I didn't proof read my post before posting it. I was meaning 'So, as long as I don't check processor specific options, my code should run on all Windows machines? Sorry for the seemingly stupid post.
    No, you have to obey all the rules that were stated!!

    Running any binary machine code on ALL Windows machines, is LIKELY impossible!!!!!!

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

  14. #14
    Registered User
    Join Date
    Mar 2010
    Posts
    583
    Win32 programs build with MSVC 2010 will not run on XP SP1 or 2000. If you really want to be able to run on those platforms, you'll need to get older runtime library. I think MSVC 2008 is still easy to get off Microsoft's website. I think code compiled with 2008 should work fine on later versions. If it doesn't, I think there are ways of specifying compatibility options in the program.

    I think 32-bit x86 would give you the most chance of binary compatibility. 64-bit x88 machines are capable of running 32-bit apps. It wouldn't run on an Intel Itanium (IA64) machine (completely incompatible) but I think they're pretty rare.

    Watch out for DLLs - consider if you need to distribute any.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Generate Assembly code and Binary code also
    By Hannibal2010 in forum C Programming
    Replies: 16
    Last Post: 07-07-2011, 05:43 AM
  2. Gray Code to Binary Code Conversion!
    By JKrakauer in forum C++ Programming
    Replies: 2
    Last Post: 03-15-2011, 03:49 AM
  3. C Code for converting generic to binary code
    By vanilla in forum C Programming
    Replies: 5
    Last Post: 11-05-2009, 03:34 AM
  4. Is agp 4 compatible with agp 8?
    By the dead tree in forum Tech Board
    Replies: 4
    Last Post: 03-20-2005, 04:26 PM
  5. Replies: 12
    Last Post: 09-02-2002, 08:04 PM