All pastes #2110042 Raw Edit

Something

public text v1 · immutable
#2110042 ·published 2012-02-05 23:36 UTC
rendered paste body
#include <unistd.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <stdio.h>
#include <errno.h>

#define PROC "1652"
#define FROM 0x7f0c0e811000 
#define TO 0x7f0c0ea3a000
int main() {
    int fd = open("/proc/" PROC "/mem", O_RDONLY);
    int out = open("/home/mnzaki/libpng14.so.14", O_WRONLY|O_CREAT);
    ssize_t r, w;
    char buf[1024];
    unsigned long toread = TO - FROM;
    if (errno != 0) {
        perror(NULL);
        exit(0);
    }
    lseek(fd, FROM, SEEK_SET);
    while(toread > 0) {
        r = read(fd, buf, 1024);
        if (r == -1) exit(0);
        printf("read %d\n", r);
        w = 0;
        while (w != r) {
            w += write(out, buf+w, 1024-w);
            printf("wrote %d\n", w);
        }
        toread -= r;
    }
    close(fd);
    close(out);
    return 0; 
}