CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Opcodes in C++

  1. #1
    Join Date
    Jan 2012
    Posts
    1

    Opcodes in C++

    How can you manually input opcodes in C++?
    Like 8B is MOV ans so forth. (Compiler having trouble with Asm)

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Opcodes in C++

    Watch out for the magic words "inline assembler". In case you're using MS Visual C++: http://msdn.microsoft.com/en-us/library/4ks26t93.aspx
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  3. #3
    Join Date
    Aug 2008
    Posts
    902

    Re: Opcodes in C++

    I suppose you could do something like this:

    Code:
    int main()
    {
    	const char* code = "\x90\x90\x90\x90";
    	void (*foo)(void) = (void (*)(void))code;
    	foo();
    }
    But I wouldn't advise it. There's also no need to go to such lengths since most compilers support inline assembly which is more useful.

  4. #4
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Opcodes in C++

    Quote Originally Posted by Chris_F View Post
    I suppose you could do something like this:

    [...]
    In principle, yes (ignoring the fact that your machine code lacks the RET instruction, causing it to lead to a certain crash ). However exactly this is what DEP is meant to prevent, so it probably won't work on the majority of today's systems.
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

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