Author Topic: [C++] List Processes *Windows Only*  (Read 5480 times)

0 Members and 1 Guest are viewing this topic.

Offline I_Learning_I

  • Knight
  • **
  • Posts: 213
  • Reputation: +18
  • Gender: Male
  • Nor black or white, not even grey. What hat am I?
    • View Profile
    • Hacking F0r Fr33
Re: [C++] List Processes *Windows Only*
« Reply #15 on: May 31, 2011, 04:06:49 pm »
Compiled assembly code is the same, but linked libraries and executable structures are different in each OS. For example, something like
Code: [Select]
i++;
i += 2;
would be assembled into something like
Code: [Select]
inc i
add i, 2
whose opcodes are the same (it depends on the processor, not the OS.
Look for PE and ELF structures for more info. In this forum we have 2 topics about PE format.
Are you sure about that statement?
I'm asking because in the same CPU, in my home desktop, without any non-standard header I couldn't run a C++ file in Linux and Windows.
And I have read and I know that different OS, will mean different compile.
Do you mind explaining better? I'm not much into ASM.

@Tsar
Alright, thank you, I never knew of the #ifdef.

@iMorg
By using external API you're also forcing the client to have the API you used for your tool, which means it's not standalone.
Thanks for reading,
I_Learning_I


Offline Tsar

  • Peasant
  • *
  • Posts: 132
  • Reputation: +11
  • turing-recognizable
    • View Profile
Re: [C++] List Processes *Windows Only*
« Reply #16 on: May 31, 2011, 04:28:05 pm »
Are you sure about that statement?
I'm asking because in the same CPU, in my home desktop, without any non-standard header I couldn't run a C++ file in Linux and Windows.
Do you mind explaining better? I'm not much into ASM.

Do you mean you recompiled the C++ code both on Windows and Linux and it didn't run on one of them?

When you compile your code gets converted to ASM then into binary (ASM to Binary is a 1 to 1 relationship), these ASM Instructions or Binary codes tell the processor what to do, what flags to set, where to store stuff, etc. Because of this for any program to work the binary must make sense when the processor reads it. Therefore all compilers(with maybe an exception of some specialized processors) will compile using Intel's instruction set (AMD adapted Intel's instruction set which is why they are still around to day, had they not they most likely would have gone bankrupt many many years ago). The difference as to why you can't run the same executable in both Linux and Windows is because of the way libraries are linked and the general structure of the executables. Remember all normal processes are in user mode not the privileged OS mode, so in a way all processes launched are handled by the OS(not the processor directly), and because of this the two OS(s) have different exe structures and linking methods depending on how they handle it. That's my understanding anyways.

Also PROTIP: You can compile your c directly to ASM if you want to check it out,
gcc:   
Code: [Select]
gcc -g -Wall -S MyProgram.c -o MyProgram.swhere MyProgram.s is the program in assembly
« Last Edit: May 31, 2011, 04:34:55 pm by Tsar »

Offline I_Learning_I

  • Knight
  • **
  • Posts: 213
  • Reputation: +18
  • Gender: Male
  • Nor black or white, not even grey. What hat am I?
    • View Profile
    • Hacking F0r Fr33
Re: [C++] List Processes *Windows Only*
« Reply #17 on: May 31, 2011, 04:54:29 pm »
Thank you for your quick answer.
So, from what I've read it is from the OS, because the OS handles the executable files in a different way the same executable can NOT run (compiled only once) in both Windows and Linux.
That is what I had learn.

I know how to compile, that's how I tested it :P
The thing is that I compile and code every day but I don't know much of the assembly and executable behind it, I mean, I have coded ASM, but I don't know... it's different.
And I was sure my file hadn't run and was the same CPU, so when ca0s said it was because of the CPU I knew it wasn't exactly like that.
Thanks for reading,
I_Learning_I


Offline Huntondoom

  • Baron
  • ****
  • Posts: 868
  • Reputation: +20
  • Gender: Male
  • Visual C# programmer
    • View Profile
Re: [C++] List Processes *Windows Only*
« Reply #18 on: May 31, 2011, 05:06:06 pm »
External libraries are normally loaded at runtime and allow you to shorten your code by calling predefined functions rather than writing your own. So by using external APIs you are probably reducing the size of the executable and handing the size over to run time memory, unless its windows which loads all the libraries anyways so the size would be the same.

there are allot of external libraries that are used in normal process
windows is full of them
and they make today coding easier
Aslong as you are connected to the internet, you'll have no privacy

Advanced Internet Search
Clean Up!

Offline Tsar

  • Peasant
  • *
  • Posts: 132
  • Reputation: +11
  • turing-recognizable
    • View Profile
Re: [C++] List Processes *Windows Only*
« Reply #19 on: May 31, 2011, 05:10:24 pm »
I know how to compile, that's how I tested it :P
What I posted is how to compile into ASM in text rather than a binary executable so you can see the assembly instructions behind your code if your interested in that, sometimes helps give you a better perspective of what is going on in between compilation of the C code and the Binary Executable

Quote
And I was sure my file hadn't run and was the same CPU, so when ca0s said it was because of the CPU I knew it wasn't exactly like that.
Well I think what ca0s was saying that it isn't because of the CPU but instead because of the OS's way of handling things, although it may of seemed a little unclear

Online ca0s

  • VIP
  • Sir
  • *
  • Posts: 401
  • Reputation: +44
  • Gender: Male
  • ca0s@ka0labs #
    • View Profile
    • { st4ck~3rr0r }
Re: [C++] List Processes *Windows Only*
« Reply #20 on: May 31, 2011, 06:31:04 pm »
Yeh, I said that while ASM instructions are the same, executable file format is different in each OS. You cannot simply compile it in one OS and make it walk into execution in any OS. I said it earlier, look for PE / ELF structures and you will understand it better.
What a compiler does is (more or less, skipping some steps...):
1 - Check syntax.
2 - Make raw binary code.
3 - Link it with libraries, make PE/ELF/whatevertheformat file.
And profit.

Offline I_Learning_I

  • Knight
  • **
  • Posts: 213
  • Reputation: +18
  • Gender: Male
  • Nor black or white, not even grey. What hat am I?
    • View Profile
    • Hacking F0r Fr33
Re: [C++] List Processes *Windows Only*
« Reply #21 on: June 01, 2011, 12:42:01 pm »
there are allot of external libraries that are used in normal process
windows is full of them
and they make today coding easier
They keyword there is "Windows" :D

@Tsar
I just did, looks awesome :O
Each day that passes I want more to learn ASM. :P

@ca0s
I've seen a little bit yesterday, will do when I have more time, I guess I just misread what you wrote.
Thanks for reading,
I_Learning_I


 



Intern0t SoldierX py1337 SecurityOverride programisiai iExploit
Want to be here? Contact Ande, Bluechill or Kulverstukas on the forum or at IRC.