CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    May 2010
    Posts
    11

    Creating a binary

    Hey, i need to create an executable somehow, preferably by using its hexcode, how would i possibly do that in c++ ?
    Lets say i take the hexcode of notepad.exe, how would i be able to create it?

  2. #2
    Join Date
    Apr 2009
    Posts
    598

    Re: Creating a binary

    Open a file in binary mode, with fopen() and "wb" flag. Write data in your file with fwrite(). Close your file with fclose().

    Then you will ask yourself what data shall I write inside the file. Then, you will discover it is easier to use a compiler and a linker.

    If you want to create a virus, then don't.

  3. #3
    Join Date
    May 2010
    Posts
    11

    Re: Creating a binary

    I know how to write to a file... i just dont know what to write in there.
    If i write the hexcode in it, it doesnt work.
    And lol at the writing a virus part, yes every person on the internet whos asking for help is trying to write a virus.
    Stereotypical bullcrap.

  4. #4
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Creating a binary

    The old .com image executable is the closest you'll get to that and I don't even know if modern OS's support it anymore.

  5. #5
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: Creating a binary

    If i write the hexcode in it, it doesnt work.
    I'd like to ask what is the "hexcode" you mentioned already twice here?
    Best regards,
    Igor

  6. #6
    Join Date
    Oct 2006
    Location
    Sweden
    Posts
    3,654

    Re: Creating a binary

    I would expect the com format to be supported in all OS's that support 16-bit exe's. After all, it's not that much that differ between them especially not compared with a tiny model exe.

    As olivthill indicated, there's a lot of stuff you have to write into that file to get it to be executable. You could start off by googling on details of the PE header for instance. All that stuff has to be written into the file and then there's the actual program...
    Debugging is twice as hard as writing the code in the first place.
    Therefore, if you write the code as cleverly as possible, you are, by
    definition, not smart enough to debug it.
    - Brian W. Kernighan

    To enhance your chance's of getting an answer be sure to read
    http://www.codeguru.com/forum/announ...nouncementid=6
    and http://www.codeguru.com/forum/showthread.php?t=366302 before posting

    Refresh your memory on formatting tags here
    http://www.codeguru.com/forum/misc.php?do=bbcode

    Get your free MS compiler here
    https://visualstudio.microsoft.com/vs

  7. #7
    Join Date
    May 2010
    Posts
    11

    Re: Creating a binary

    Quote Originally Posted by Igor Vartanov View Post
    I'd like to ask what is the "hexcode" you mentioned already twice here?
    Well what i did was, i made a simple program

    Code:
    #include <iostream>
    #include <conio.h>
    
    int main()
    {
    	std::cout << "watever" << std::endl;
    	_getch();
    }
    opened it up in hex editor
    http://paste2.org/followup/888430
    and tried to paste it to a txt which did not work as expected.
    So i googled for hex to binary which only made converters pop up which was expected so i came here..

    Any suggestions how i could get that to work?

  8. #8
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: Creating a binary

    Okay, what I see from your description is: you have a text (program code in C++), you convert the text to another text with hexadecimal notation, you write that what you finally get to a file... and expect the file working like executable binary???

    Man, you have a lot of things to know about how C++ program text becomes executable module. Try to get some reading on compiling and linking.

    Any suggestions how i could get that to work?
    First, you install some C++ compiler, then you build your program, like this (VC++ sample):
    Code:
    cl.exe mycoolprogram.cpp /link /out:coolprog.exe
    Last edited by Igor Vartanov; June 23rd, 2010 at 01:11 AM.
    Best regards,
    Igor

  9. #9
    Join Date
    Dec 2007
    Posts
    69

    Re: Creating a binary

    I think that what he's trying to do is to convert a text file which contains an executable binary in hexadecimal code to a executable binary (like the one he put on paste2.org).

    Open the input and the output files (remember that for the output file you'll need to set binary mode), then just read each pair of characters from the input, convert from hex string to a byte, and write it to the output.

    Anyway, I'm not sure about why would he want to do that.

  10. #10
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,633

    Re: Creating a binary

    Oh, yes, now I see I was wrong. Sorry.
    Best regards,
    Igor

  11. #11
    Join Date
    May 2010
    Posts
    11

    Re: Creating a binary

    Quote Originally Posted by GameZelda View Post
    I think that what he's trying to do is to convert a text file which contains an executable binary in hexadecimal code to a executable binary (like the one he put on paste2.org).

    Open the input and the output files (remember that for the output file you'll need to set binary mode), then just read each pair of characters from the input, convert from hex string to a byte, and write it to the output.

    Anyway, I'm not sure about why would he want to do that.
    Thanks!
    Thats exactly what i needed, and thanks to the others for trying to understand me

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured