Like Tree4Likes
  • 2 Post By AndrewHunter
  • 1 Post By Fordy
  • 1 Post By CommonTater

How to call assembler

This is a discussion on How to call assembler within the C Programming forums, part of the General Programming Boards category; Look: Code: int main() { unsigned char buf[]={0xB8,0x10,0x00}; __asm { jmp buf } return 0; } I assigned assembler codes ...

  1. #1
    Registered User
    Join Date
    Jun 2011
    Posts
    50

    How to call assembler

    Look:
    Code:
    int main()
    {
        unsigned char buf[]={0xB8,0x10,0x00};
       __asm    
            {       
                jmp buf
            }                
        
        return 0;
    }
    I assigned assembler codes into array buf,and I want to call the codes,
    when I compile it,the statement jmp buf display error: illegal size for operand和illegal instruction size,
    who could help me how to call it?

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    That's going to be compiler dependent.

    But, you should also know that many OSs (eg. any version of windows since XP sp1) will include "Data Execution Prevention" and will report access violation errors on what you are trying to do. Getting code to execute instructions in memory data is a prime route for exploits and trojans so it's likely to *at least* trigger virus scanners.

  3. #3
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Quote Originally Posted by leetow2003 View Post
    Look:
    Ok, I looked. Then a little bit of me died inside. Thanks.

    Quote Originally Posted by leetow2003 View Post
    I assigned assembler codes into array buf.....
    Why on earth would you want to do that? To print them out? As CommonTater already pointed out you can not have code execution in the data section of your program. The OS will not allow it.

    Quote Originally Posted by leetow2003 View Post
    error: illegal size for operand illegal instruction size
    Because when you write assemble code do you write it to jmp and then just put in what operand you want it to jmp to? No you don't, that would be silly.

    Quote Originally Posted by leetow2003 View Post
    who could help me how to call it?
    No one will

    Just some words of advice my friend, you have been on this board for just over a month and so far all your posts have been involved with networking. Now, you ask this question about trying to run assembly code from the data section of a program. I would tread carefully and begin to explain in a lot more detail on what it is you are really trying to accomplish.

    Some acceptable questions:
    Can you explain to me how to call C funtions with inline assembly? - yes
    Can you explain to me how to access C variables for use inside my inline assembly? - yes
    Can you explain to me how to jmp around between inline assemble and my C code - yes
    ....
    Can you show me how to be a "script kiddie"? - NO
    quzah and CommonTater like this.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by AndrewHunter View Post
    Ok, I looked. Then a little bit of me died inside. Thanks.
    A++ would lol again.


    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    Quote Originally Posted by AndrewHunter View Post
    Why on earth would you want to do that? To print them out? As CommonTater already pointed out you can not have code execution in the data section of your program. The OS will not allow it.
    Actually, you can. I just tried it on a fully updated Windows XP installation with MS Security Essentials running with no complaints. There's an awful lot of hoops to jump through though to get it to do so. A simple jmp is wrong and what will the code do when its there? Can it exit? Can it terminate the process? Can it do anything meaningful? And in truth, as already mentioned, why would you want to do it?

  6. #6
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,866
    Haha...thanks for that one Fordy. I'm sure you can actually still do many things; I generally tend to go with a positive "no" on this one due to as you pointed out: "There's an awful lot of hoops to jump through though to get it to do so". Basically, my assumption is that if you know how to do it, then you won't be asking how.

    EDIT: Well, a much more informed question I should say.
    Last edited by AndrewHunter; 07-30-2011 at 08:15 PM.
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Fordy View Post
    Actually, you can. I just tried it on a fully updated Windows XP installation with MS Security Essentials running with no complaints. There's an awful lot of hoops to jump through though to get it to do so. A simple jmp is wrong and what will the code do when its there? Can it exit? Can it terminate the process? Can it do anything meaningful? And in truth, as already mentioned, why would you want to do it?
    Now take that XP Installation... go Control Panel -> System -> Performance -> Advanced -> Data Execution Prevention -> Turn on DEP for all ...

    Try that again.

    Also note that Windows can be set to boot up with DEP fully on, as well as an option on the bootstrap line...

  8. #8
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by AndrewHunter View Post
    Haha...thanks for that one Fordy. I'm sure you can actually still do many things; I generally tend to go with a positive "no" on this one due to as you pointed out: "There's an awful lot of hoops to jump through though to get it to do so". Basically, my assumption is that if you know how to do it, then you won't be asking how.

    EDIT: Well, a much more informed question I should say.
    Not to mention that DEP is a major attack vector used by trojans and malware...
    AndrewHunter likes this.

  9. #9
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,786
    Quote Originally Posted by CommonTater View Post
    Now take that XP Installation... go Control Panel -> System -> Performance -> Advanced -> Data Execution Prevention -> Turn on DEP for all ...

    Try that again.

    Also note that Windows can be set to boot up with DEP fully on, as well as an option on the bootstrap line...
    Still works with DEP set to all processes. Haven't tested this on 7 or Vista though...and I cant get hardware DEP on the virtual machine I run, only software

  10. #10
    Registered User
    Join Date
    Jan 2010
    Posts
    412
    Quote Originally Posted by Fordy View Post
    Still works with DEP set to all processes. Haven't tested this on 7 or Vista though...and I cant get hardware DEP on the virtual machine I run, only software
    Software DEP is quite limited compared to the hardware version. It only protects exception handlers on binaries built to be software DEP aware. It does not check if the memory page is marked as executable or not.

  11. #11
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,639
    I know that you want to learn. Don't use for scrpt-kiddie purposes.
    You think that smiley-face makes what you just did any less disgusting?

  12. #12
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    This thread is really suspect in my opinion.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Assembler
    By bikr692002 in forum C++ Programming
    Replies: 0
    Last Post: 02-20-2006, 07:28 AM
  2. Assembler
    By GaPe in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 02-03-2003, 12:01 PM
  3. ASM - assembler
    By johnc in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 05-29-2002, 05:32 PM
  4. Assembler to C
    By sean in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 01-28-2002, 10:07 AM
  5. How to use Assembler/BAL in C++?
    By sean in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 11-29-2001, 07:00 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21