plugMem.c
1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
* 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 0x60000000
int
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");
}