Useing Perl With C to Read From Executable

N

Nori

Okay. I am working on a small operating system called MOSS (mini
operating system/shell). One of the features of this is it has a file
system of its own which apears to the host operating system as a large
file. If you would like more information you can go check out
comp.lang.c where I have described it in detail many a time. Anyway as
some of you may know C has no way to read executeable code and execute
what it has read. I have heard that perl does. What I mean is:

This is the psudo file system that is a large file

::::FILE ONE:::
this is text
::::FILE TWO:::
exicuteable code is here
::::FILE THREE:::
more text text text text

Okay. What I need is some way to go to file two and execute what is in
it. Basicly I'm looking for a way to execute programs that are in a
file togather. For instance I could also have file three contail
executable code and have it read and executed from two or three then,
and I could have the text be read from one.
Take note that this is only an example and the real file system
contains several codes dictating what type of file it is so the system
knows what to do. Thanks in advanced for any help.
Nori

P.S. If this doesn't make any sence check out comp.lang.c and read some
of my past posts.
 
M

Matt Garrish

Nori said:
Okay. I am working on a small operating system called MOSS (mini
operating system/shell). One of the features of this is it has a file
system of its own which apears to the host operating system as a large
file. If you would like more information you can go check out
comp.lang.c where I have described it in detail many a time. Anyway as
some of you may know C has no way to read executeable code and execute
what it has read. I have heard that perl does. What I mean is:

This is the psudo file system that is a large file

::::FILE ONE:::
this is text
::::FILE TWO:::
exicuteable code is here
::::FILE THREE:::
more text text text text

Have you had a look at the do and eval commands yet?

Matt
 
P

Peter J. Holzer

Nori said:
Okay. I am working on a small operating system called MOSS (mini
operating system/shell). One of the features of this is it has a file
system of its own which apears to the host operating system as a large
file. If you would like more information you can go check out
comp.lang.c where I have described it in detail many a time. Anyway
as some of you may know C has no way to read executeable code and
execute
what it has read. I have heard that perl does. What I mean is:

What do you mean by "executable code"? Maschine code for CPU? Some kind
of byte code? Source code?

In most C implementations it is trivial to load some code into memory
and execute it. Some make it a bit trickier (you have to twiddle memory
protection bits), and on some it is impossible. It really depends on the
platform. Most platforms also have a way to load shared libraries (which
really isn't anything else than "read executeable code and execute what
it has read", except that it takes care of the nasty details like
relocation).

Perl can execute Perl code via do and eval. It cannot execute machine
code directly, although a module for your platform may already exist
(almost certainly written in C).

If you are talking about some kind of byte code, you need an interpreter
for that.

hp
 
N

Nori

Let me rephrase my question. Would it be possible in a perl script to:
1. Copy Executable (binary) code from one file to another (the second
would be temp)
2. Execute that executable binary code in the second file.
3. Delete the temporary file.
 
A

Ala Qumsieh

Nori said:
Let me rephrase my question. Would it be possible in a perl script to:
1. Copy Executable (binary) code from one file to another (the second
would be temp)
2. Execute that executable binary code in the second file.
3. Delete the temporary file.

Why can't you do that directly in C? Just fork and exec. Or am I missing
something?

--Ala
 
C

Charles DeRykus

Nori said:
Let me rephrase my question. Would it be possible in a perl script to:
1. Copy Executable (binary) code from one file to another (the second
would be temp)
2. Execute that executable binary code in the second file.
3. Delete the temporary file.

It sounds as if you need to embed an executable in some large MOSS
pseudo container file. If so, uuencoding the binary content might be
a possibility. To run, you could read the uuencoded file into a string;
uudecode; and then save the output string to a temp file for subsequent
execution (possibly useful modules: Convert::UU and File::Temp). The
reason I suggest uuencoding is that mixing binary executable content
with readable text is likely very problematic. But then maybe MOSS may
be able to handle this potentially troublesome mixture without problem..
.. Sorry if this is a false lead...
 

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,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top