2 * patcher.c - ADAM2 patcher for Netgear DG834 (and compatible)
4 * Copyright (C) 2006 Felix Fietkau
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
27 #include <sys/ioctl.h>
29 int main(int argc, char **argv)
36 fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
40 if (((fd = open(argv[1], O_RDWR)) < 0)
41 || ((ptr = mmap(0, 128 * 1024, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)) == (void *) (-1))) {
42 fprintf(stderr, "Can't open file\n");
46 i = (uint32_t *) &ptr[0x3944];
47 if (*i == 0x0c000944) {
48 fprintf(stderr, "Unpatched ADAM2 detected. Patching... ");
50 msync(i, sizeof(*i), MS_SYNC|MS_INVALIDATE);
51 fprintf(stderr, "done!\n");
52 } else if (*i == 0x00000000) {
53 fprintf(stderr, "Patched ADAM2 detected.\n");
55 fprintf(stderr, "Unknown ADAM2 detected. Can't patch!\n");