Jumping to machine code

D

Derek Fountain

I have a string in my Perl which contains the machine code for a short
program I want to run. I want Perl to jump to it. It's the last thing my
script will do, so I don't care about returning safely, etc. Ideally the
Perl will just exit neatly, but I really don't mind. I just need that
machine code to execute. I'm on Win32, but a cross platform method would be
good.

How can I do that?
 
A

Andrew Bryson

Derek Fountain said:
I have a string in my Perl which contains the machine code for a short
program I want to run. I want Perl to jump to it. It's the last thing my
script will do, so I don't care about returning safely, etc. Ideally the
Perl will just exit neatly, but I really don't mind. I just need that
machine code to execute. I'm on Win32, but a cross platform method would
be
good.

How can I do that?

Have you considered putting the machine code into a .com file and just
running it with system() ?

Andrew
 
D

Derek Fountain

Andrew said:
Have you considered putting the machine code into a .com file and just
running it with system() ?

Yes, but the application doesn't easily allow disk access, plus I need
speed. Is that all a .com file is - no headers or other confusing stuff I
would need to generate?
 
J

John

Derek said:
Yes, but the application doesn't easily allow disk access, plus I need
speed. Is that all a .com file is - no headers or other confusing stuff I
would need to generate?

First, there is no such thing as "cross platform machine code."

Second, a Perl script must do an awful lot of disk access to get
started, so what's the problem?

Third, if you are so concerned about speed, WTF are you doing running it
from within Perl?

Fourth, this sounds like an attempt at injecting a virus in Perl code.

Could you please tell us what this marvelous piece of machine code is
going to do, and given that Perl is SOOO slow compared to machine code,
what benefit you think you're going to get from this approach?
 
L

Lukas Mai

Derek Fountain schrob:
I have a string in my Perl which contains the machine code for a short
program I want to run. I want Perl to jump to it. It's the last thing my
script will do, so I don't care about returning safely, etc. Ideally the
Perl will just exit neatly, but I really don't mind. I just need that
machine code to execute. I'm on Win32, but a cross platform method would be
good.
How can I do that?

You could use Inline::ASM or Inline::C with something like:
void execute(char *code) {
((void (*)(void))code)();
}

HTH, Lukas
 
D

Derek Fountain

First, there is no such thing as "cross platform machine code."

I know that, but I can put the right flavour of machine code into the string
dynamically.
Second, a Perl script must do an awful lot of disk access to get
started, so what's the problem?

Perl scripts start with a lot of disk *reading*, I don't have easy write
access.
Third, if you are so concerned about speed, WTF are you doing running it
from within Perl?

The usual balance of convenience and speed; writing a file to disk might tip
the balance the wrong way.
Fourth, this sounds like an attempt at injecting a virus in Perl code.

It might sound like it, but no. Close though, I'm working with the
metasploit framework and want to test some payloads.
Could you please tell us what this marvelous piece of machine code is
going to do, and given that Perl is SOOO slow compared to machine code,
what benefit you think you're going to get from this approach?

Since your attitude is that of an idiot, and you clearly have no intention
of helping me with my genuine, legitimate problem, no.
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top