Is it possible to load an executable binary (8k) into memory using mmap()
function ant then executing the binary program in memory.
I tried something like this in C and it only seemed to load the binary into
memory. I then tried the exec family to execute the binary but nothing
happened.Maybe in assmebler there is a better method ?
here is the source:
#include <unistd.h>
#include <stdio.h>
#include <ctype.h>
#include <fcntl.h>
#include <string.h>
#include <malloc.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <signal.h>
#include </usr/include/sys/types.h>
#include </usr/include/sys/stat.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
// gcc -o example1 example1.c
void err_quit(char *msg);
int main(int argc,char *argv[])
{
int fdin;
char *src,**dh;
struct stat statbuf;
off_t len;
if (( fdin = open("prog1",O_RDONLY)) < 0) //prog1 binary executable file
err_quit("open failed");
if ((fstat(fdin,&statbuf)) < 0)
err_quit("fstat failed");
len = statbuf.st_size;
if ((src = mmap(0, len,PROT_EXEC,MAP_SHARED,fdin,0)) == (void *)-1)
err_quit("mmap failed");
if (! fork())
{
int rt;
rt = execve(src,src,0);
sleep(2);
}
sleep(4);
close(fdin);
munmap(src,len);
exit(0);
}
void err_quit(char *msg)
{
perror(msg);
exit(EXIT_FAILURE);
}
Im using Fedora 3 ,PC: 1MB ram , 3.2 Ghz pentuim.
Any suggestions ?
[EMAIL PROTECTED]
_________________________________________________________________
Upgrade to MSN Hotmail Plus - your e-mail, your way!
http://join.msn.com/?pgmarket=en-xe&DI=1054&XAPID=1816
-
To unsubscribe from this list: send the line "unsubscribe linux-assembly" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at http://vger.kernel.org/majordomo-info.html