Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disassembling Simple Hello World program

I wrote this small C++ program and built it(Release)

#include<iostream>
int main(){
     std::cout<<"Hello World";
     return 0;
}

When I disassemble it, it has a lot of extra code(security cookie etc..). I believe Visual Studio is adding all those. How can I compile this program without any extra information, so that its easy to understand its disassembled code?

I know assembly is comparatively harder, but what I mean is getting a hello world asm code out of a hello world c++ program. Is this possible?

like image 631
questions Avatar asked Oct 15 '25 05:10

questions


2 Answers

You're starting with a huge code base with <iostream>. What you might want to do is avoid the use of a runtime library entirely. Try something like this:

#include <windows.h>

int main() {
    HANDLE stdout = GetStdHandle(STD_OUTPUT_HANDLE);
    WriteFile(stdout, "Hello world\n", 12, NULL, NULL);
    return 0;
}

Compile that with assembly listing turned on, and that should give you some "raw" Win32 code to start with.

like image 59
Greg Hewgill Avatar answered Oct 16 '25 20:10

Greg Hewgill


you can generate assembly output in Project Properties -> Configuration Properties -> Output Files -> Assembler Output

This will let you see the assembly for the code you wrote.

Diassembling, you are going to get a bunch of other things that are linked in.

like image 31
Keith Nicholas Avatar answered Oct 16 '25 20:10

Keith Nicholas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!