📄 plugmem.c
字号:
/* * Copyright (C) 1996-1998 by the Board of Trustees * of Leland Stanford Junior University. * * This file is part of the SimOS distribution. * See LICENSE file for terms of the license. * */#include <stdio.h>#include <sys/types.h>#include <sys/mman.h>#include <sys/stat.h> #include <fcntl.h> #define MAPADDR 0x60000000int main(int argc, char **argv){ char *fileName; int fd; uint offset; uint oldValue; uint newValue; void *mapAddr; void *plugAddr; if (argc != 5) { printf("Usage: %s file offset old_value new_value\n", argv[0]); exit(); } fileName = (char *)argv[1]; offset = (uint)strtoul(argv[2], NULL, 16); oldValue = (uint)strtoul(argv[3], NULL, 16); newValue = (uint)strtoul(argv[4], NULL, 16); printf("Attempting to change offset %#x from %#x to %#x\n", offset, oldValue, newValue); if ((fd = open(fileName, O_RDWR)) == -1) { printf("Can't open file\n", fileName); perror("Opening"); exit(); } if ((mapAddr = mmap((void *)MAPADDR, 4096, PROT_READ|PROT_WRITE, MAP_SHARED, fd, offset&0xfffff000)) == (void *)-1) { printf("Problem mapping %s\n", fileName); perror("Mapping"); exit(); } plugAddr = (void *)((uint)mapAddr+(offset & 0x00000fff)); printf("Current value at %#x is %#x\n", offset, *(int *)plugAddr); if (*(uint *)plugAddr != oldValue) { printf("This offset doesn't have the old value specified\n"); exit(); } *(uint *)(uint)plugAddr = (uint) newValue; printf("New value is %#x\n", *(uint *)plugAddr); close(fd); printf("You've successfully plugged, homeboy\n");}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -