Find the answer to your Linux question:
Results 1 to 4 of 4
hey everyone, I am trying to develop a simple raw file system driver (which will read from the given sectors of hdd) but having a little problems. Let's say I ...
  1. #1
    Just Joined!
    Join Date
    Jan 2010
    Posts
    9

    Dumping Executable's Image

    hey everyone,

    I am trying to develop a simple raw file system driver (which will read from the given sectors of hdd) but having a little problems.

    Let's say I have a single application like ;

    main(){
    printf("yea!!\n");
    return 0;
    }

    once I execute it it will take place in memory and exit after a short while.What I would like to do is take snapshot of it while it is in memory so that I can later save that image and load the specified sector from my raw driver to memory and execute the code.Is there such a tool for dumping the executables image from memory ?

    I hope I could express what I wanted to.
    I couldn't find anything related to this so I would appreciate sugesstions!

    Cheers!

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    I do not know of an existing utility to do this, but I think I know how you could do it.

    Every currently-running process has a space in the proc filesystem, located under /proc. So if you launch your process, you can find it under /proc/PID, where PID is that process's PID, obviously.

    The /proc/PID/mem file allows you to read the memory of a running process. It works just like a file: open() it, lseek() to the position you want, and read().

    Using this, you should be able to write a program to dump a process's memory.
    DISTRO=Arch
    Registered Linux User #388732

  3. #3
    Just Joined!
    Join Date
    Jan 2010
    Posts
    9
    Quote Originally Posted by Cabhan View Post
    I do not know of an existing utility to do this, but I think I know how you could do it.

    Every currently-running process has a space in the proc filesystem, located under /proc. So if you launch your process, you can find it under /proc/PID, where PID is that process's PID, obviously.

    The /proc/PID/mem file allows you to read the memory of a running process. It works just like a file: open() it, lseek() to the position you want, and read().

    Using this, you should be able to write a program to dump a process's memory.
    On ubuntu I try to cat /proc/PID/mem but cat returns 'no such process' also trying to copy to a different location doesn't work as well.

    On the other hand, I want to dump the whole executable image to a file (note that I will load the executable to memory from direct disc access), isn't proc/PID is about memory map (like variables and etc) of the executable ?

  4. #4
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    You need to replace "PID" with the process ID of the process that you want to dump.

    And dumping /proc/PID/mem will dump all of memory, which includes the executable. It will also include the stack, which includes most variables.

    If you only want the executable itself, why are you getting it from memory? When you compile an application, you will obtain an executable file: this is the executable. There may be formatting in it that you don't need (ELF headers, etc.), but by playing with gcc and ld options, you can change the output to a format that you need.
    DISTRO=Arch
    Registered Linux User #388732

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...