Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sys/mman.h>
- #include <string.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- #include <unistd.h>
- #include <stdio.h>
- #define IMG "./english.dsk"
- const off_t offset = 0x0468c00;
- #define S_OFFSET "OFFSET"
- #define SIZE 60
- int edit(char *v) {
- int fd;
- char *mem;
- struct stat s;
- off_t pa_offset, diff;
- pa_offset = offset & ~(sysconf(_SC_PAGE_SIZE) - 1);
- printf("PA_OFFSET = %d, offset = %d\n", pa_offset, offset);
- diff = offset - pa_offset;
- if ((fd = open(IMG, O_RDWR)) == -1) {
- perror("open");
- } else {
- fstat(fd, &s);
- if ((mem = mmap(NULL, SIZE + diff, PROT_READ | PROT_WRITE, MAP_SHARED, fd, pa_offset)) == MAP_FAILED) {
- perror("mmap");
- }
- memset(&mem[diff], 0, SIZE);
- memcpy(&mem[diff], v, strlen(v));
- if (msync(mem, SIZE + diff, MS_SYNC|MS_INVALIDATE)) {
- perror("msync");
- }
- if (munmap(mem, SIZE + diff)) {
- perror("munmap");
- }
- close(fd);
- }
- }
- int usage(char *v) {
- return printf("usage: %s BLAH\n", v);
- }
- int main(char c, char **v) {
- if (c < 2) return usage(v[0]);
- if (strlen(v[1]) > SIZE) {
- return(printf("Sorry, %d is too big.\n", strlen(v[1])));
- }
- printf("edit_img %s\n", v[1]);
- return (edit(v[1]));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement