I want to know how to show C++'s application in a text-format in machine language through C++ itself.

Does any one know how to do that? Sorry if I wasn't too descriptive, I can add more.

Recommended Answers

All 21 Replies

With GCC, all you need is the -S option:

$ gcc -S my_program.cpp

It will create a file with the same name as the cpp file, but with extension .s and it contains the assembly listing (what you call machine language).

If you are not using GCC, then almost all IDEs have an option to either output the assembly listing and/or to display while in debugging mode. This is taken from an SO thread:

There are several approaches:

1.

You can normally see assembly code while debugging C++ in visual studio (and eclipse too). For this in Visual Studio put a breakpoint on code in question and when debugger hits it rigth click and find "Go To Assembly" ( or press CTRL+ALT+D )
2.

Second approach is to generate assembly listings while compiling. For this go to project settings -> C/C++ -> Output Files -> ASM List Location and fill in file name. Also select "Assembly Output" to "Assembly With Source Code".
3.

Compile the program and use any third-party debugger. You can use OllyDbg or WinDbg for this. Also you can use IDA (interactive disassembler). But this is hardcore way of doing it.

With GCC, all you need is the -S option:

$ gcc -S my_program.cpp

It will create a file with the same name as the cpp file, but with extension .s and it contains the assembly listing (what you call machine language).

If you are not using GCC, then almost all IDEs have an option to either output the assembly listing and/or to display while in debugging mode. This is taken from an SO thread:

No, I mean machine language and not Assembly programming.

No, I mean machine language and not Assembly programming.

Totally saw that one coming. :icon_rolleyes: If you want to work directly with machine language, get a hex editor. The only way to work with machine language is to directly modify the bytes of a file much the same way an assembler would.

Totally saw that one coming. :icon_rolleyes: If you want to work directly with machine language, get a hex editor. The only way to work with machine language is to directly modify the bytes of a file much the same way an assembler would.

Nope, hex is not machine language's actual working level, which is binary and EAX and other registers.

Is there any program that can input direct machine language instructions to the processor from machine language itself and have it do whatever told is what I ALSO want to know.

Nope, hex is not machine language's actual working level, which is binary and EAX and other registers.

And how do you plan on editing the binary? Magic?

And how do you plan on editing the binary? Magic?

I just told you I wanted to write raw machine code to the processor from machine language and nothing more.

Hex editors use hex, which is not machine language which machine language is technically binary.

Done with the idiot troll. Thanks for playing.

*plonk*

Done with the idiot troll. Thanks for playing.

*plonk*

I'm being serious here. Hex editors are NOT machine language and that should be obvious to you.

> I'm being serious here.
No you aren't. You are just wasting people's time.

> I'm being serious here.
No you aren't. You are just wasting people's time.

I'm not. I'm seriously waiting for an answer. It's not wasting peoples' time if they are supposedly here to help.

I'm not. I'm seriously waiting for an answer. It's not wasting peoples' time if they are supposedly here to help.

You do realize that an 'equivalent' value can be represented as a integer, octal, hexadecimal or binary...You realize that right? So you can write raw machine code with a hex editor, I do it all the time.

You do realize that an 'equivalent' value can be represented as a integer, octal, hexadecimal or binary...You realize that right?

But you obviously don't understand what raw machine language really is. That's what I want to create data from and work with and NOT editors of number systems but the REAL machine language its self.

I DON'T want to represent numbers from equivalent values that can be changed I want to do it in PURE MACHINE CODE!

But you obviously don't understand what raw machine language really is. That's what I want to create data from and work with and NOT editors of number systems but the REAL machine language its self.

I DON'T want to represent numbers from equivalent values that can be changed I want to do it in PURE MACHINE CODE!

Then find or write an editor that will display binary and go blind in the sea of 0's and 1's.

Then find or write an editor that will display binary and go blind in the sea of 0's and 1's.

Not JUST binary but the whole implementation of machine language architecture, such as registers and values that take action through the commands.

And I won't go blind... :P

commented: 010010010010000001110011011001010110010100101110 -1

To quote an earlier posting.

" *plonk* "

Nope, hex is not machine language's actual working level, which is binary and EAX and other registers.

Is there any program that can input direct machine language instructions to the processor from machine language itself and have it do whatever told is what I ALSO want to know.

well yes you can , it's called modifying code at runtime.
Did you heard the gdb debugger?

here is a tutorial with source codes.
http://www.technochakra.com/debugging-modifying-code-at-runtime/

and also ollydbg debugger also helps you to do this.In the ollydebug
if the targert code segment that is debugging haven't granted the
write access(normally default denied in modern OSes),it will clone the
executable and modify that flags and reload the process into the memory
and allow you to do it.it's used for software cracking, the subject is
called reverse engineering.I suggest you to read a the book "hackers
debugging uncovered".

And I also heard that those old NES game terminals to the some Xbox clones
are allowed to modify the code and inject arbitrary machine code by
temporary suspend the process that is running.Cool isn't it for cheating?
But if you are a starter the I recommand you to start with that old NES
simulator that allows cheat console(more similar to a debugger) where
you can play lazy and manipulate the high score table. Starting with
NES is simpler because it's instruction set is easy to learn and there are
more resources on it.


and This is completely possible , did you ever heard about class of security
vulnurabilities called "buffer overflows"?
http://en.wikipedia.org/wiki/Buffer_overflow
The basic principle of a shell code is that. Even you can modify the execution
flow of a server computer running a HTTP server if you discovered a buffer-overflow
in the software software.

Good Luck

commented: nice post, but don't waste your time with spoonlicker +1

well yes you can , it's called modifying code at runtime.
Did you heard the gdb debugger?

here is a tutorial with source codes.
http://www.technochakra.com/debugging-modifying-code-at-runtime/

and also ollydbg debugger also helps you to do this.In the ollydebug
if the targert code segment that is debugging haven't granted the
write access(normally default denied in modern OSes),it will clone the
executable and modify that flags and reload the process into the memory
and allow you to do it.it's used for software cracking, the subject is
called reverse engineering.I suggest you to read a the book "hackers
debugging uncovered".

And I also heard that those old NES game terminals to the some Xbox clones
are allowed to modify the code and inject arbitrary machine code by
temporary suspend the process that is running.Cool isn't it for cheating?
But if you are a starter the I recommand you to start with that old NES
simulator that allows cheat console(more similar to a debugger) where
you can play lazy and manipulate the high score table. Starting with
NES is simpler because it's instruction set is easy to learn and there are
more resources on it.


and This is completely possible , did you ever heard about class of security
vulnurabilities called "buffer overflows"?
http://en.wikipedia.org/wiki/Buffer_overflow
The basic principle of a shell code is that. Even you can modify the execution
flow of a server computer running a HTTP server if you discovered a buffer-overflow
in the software software.

Good Luck

Well that's a cool debugging program, although it's not exactly with I was looking for. :(

I'm guessing you want to write a program in C++, then convert it into 'Machine Code' so that it can be read by a physical device. If this is really what you want, then the above posters have already answered your questions. Use the above answers to scrape your code down into Hex format, then use this to translate it down into binary, line by line.

http://easycalculation.com/hex-converter.php

Good luck.

I'm guessing you want to write a program in C++, then convert it into 'Machine Code' so that it can be read by a physical device. If this is really what you want, then the above posters have already answered your questions. Use the above answers to scrape your code down into Hex format, then use this to translate it down into binary, line by line.

http://easycalculation.com/hex-converter.php

Good luck.

No, you got it wrong. That's not what I want to do.

Something that turns C++ code into machine code is called a "C++ compiler". How to show the machine code? Open an executable in a text editor!

Something that turns C++ code into machine code is called a "C++ compiler". How to show the machine code? Open an executable in a text editor!

I want to write the machine code and have it converted to C++. :P

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.