An unusual question...

Discussion in 'Python' started by Guest, Apr 17, 2011.

  1. Guest

    Guest Guest

    Hi coders...

    Before I start I don`t expect an easy answer
    except "No it can`t be done!".

    I have not tried it yet, I`m only asking for opinions ATM.
    (Except on the classic AMIGA and it DOES work for that!)

    I only want it to work in Linux/?IX. Windblows does
    not interest me at all.

    OK here we go...

    I can easily place a machine code, PURE binary,
    routine into Python.

    I can also find out where it is EXACTLY just as
    easily so this is not my problem.

    The problem is calling it!

    If I wrote an Assembly(/Assembler) routine to call
    this binary code using say the JMP instruction or
    using PUSH absolute value and RET, and, call these
    "Jump" using:-

    os.system("/full//path/to/Jump <address_of_binary_in_ascii>")

    can I expect a "segmentation error" OR because the
    "Jump" command is already inside the Python terminal
    would this be considered inside Python`s working memory
    from the MMUs point of view?

    TIA...



    --
    73...

    Bazza, G0LCU...

    Team AMIGA...

    http://homepages.tesco.net/wisecracker/

    http://main.aminet.net/search?readme=wisecracker

    http://mikeos.berlios.de/
     
    Guest, Apr 17, 2011
    #1
    1. Advertising

  2. On Sun, 17 Apr 2011 13:15:01 +0100, wisecracker wrote:

    > OK here we go...
    >
    > I can easily place a machine code, PURE binary, routine into Python.


    What do you mean by "into Python"? Do you mean patching the Python
    compiler? Injecting code into the runtime interpreter? Storing a bunch of
    bytes in memory?

    What machine code, for which CPU?


    > I can also find out where it is EXACTLY just as easily so this is not my
    > problem.


    And how would you do that?


    > The problem is calling it!
    >
    > If I wrote an Assembly(/Assembler) routine to call this binary code
    > using say the JMP instruction or using PUSH absolute value and RET, and,
    > call these "Jump" using:-
    >
    > os.system("/full//path/to/Jump <address_of_binary_in_ascii>")
    >
    > can I expect a "segmentation error"


    Almost certainly.

    Sorry to be cynical, but if you have to ask these questions, you almost
    certainly don't have the skill to successfully pull it off.

    Reading your questions is a bit like hearing somebody saying "I have a
    Swiss Army Knife. If I poke around here in somebody's chest, can I do a
    heart transplant, or do you think they might die?"




    > OR because the "Jump" command is
    > already inside the Python terminal would this be considered inside
    > Python`s working memory from the MMUs point of view?


    I don't know. That depends on what you mean by "into Python".



    --
    Steven
     
    Steven D'Aprano, Apr 17, 2011
    #2
    1. Advertising

  3. Guest

    sturlamolden Guest

    On Apr 17, 2:15 pm, <> wrote:

    > I can also find out where it is EXACTLY just as
    > easily so this is not my problem.
    >
    > The problem is calling it!


    You'll need to mmap or valloc a page-alligned memory
    buffer (for which the size must be a multiple of the system
    page size), and call mprotect to make it executable.
    Copy your binary code into this buffer. Then you will
    need to do some magic with ctypes, Cython or C to call
    it; i.e. cast or memcpy the address of the excutable buffer
    into a function pointer, and dereference/call the function
    pointer. If that sounds gibberish, see Steven's comment
    about heart transplants.

    Sturla
     
    sturlamolden, Apr 17, 2011
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Neo Geshel
    Replies:
    2
    Views:
    358
    Flinky Wisty Pomm
    Feb 14, 2006
  2. earthwormgaz

    Unusual scope question

    earthwormgaz, Apr 26, 2007, in forum: C++
    Replies:
    3
    Views:
    296
    Salt_Peter
    Apr 26, 2007
  3. Jukka K. Korpela

    Re: Unusual Validation Question

    Jukka K. Korpela, Aug 27, 2010, in forum: HTML
    Replies:
    3
    Views:
    504
    Jukka K. Korpela
    Aug 28, 2010
  4. Guest

    Re: An unusual question...

    Guest, Apr 18, 2011, in forum: Python
    Replies:
    3
    Views:
    202
    Grant Edwards
    Apr 18, 2011
  5. Colin Colin
    Replies:
    2
    Views:
    119
    Colin Colin
    Apr 5, 2004
Loading...

Share This Page