An unusual question...

G

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/
 
S

Steven D'Aprano

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".
 
S

sturlamolden

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top