source: freewrt/target/linux/package/base-files/src/adam2patcher.c@ 475ad56

freewrt_1_0 freewrt_2_0
Last change on this file since 475ad56 was 475ad56, checked in by Waldemar Brodkorb <wbx@…>, 20 years ago

add OpenWrt trunk revision 3830.

git-svn-id: svn://www.freewrt.org/trunk/freewrt@1 afb5a338-a214-0410-bd46-81f09a774fd1

  • Property mode set to 100644
File size: 1.5 KB
Line 
1/*
2 * patcher.c - ADAM2 patcher for Netgear DG834 (and compatible)
3 *
4 * Copyright (C) 2006 Felix Fietkau
5 *
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.
10 *
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.
15 */
16
17#include <stdio.h>
18#include <stdlib.h>
19#include <stddef.h>
20#include <unistd.h>
21#include <fcntl.h>
22#include <stdint.h>
23#include <sys/mman.h>
24#include <sys/stat.h>
25#include <string.h>
26
27#include <sys/ioctl.h>
28
29int main(int argc, char **argv)
30{
31 int fd;
32 char *ptr;
33 uint32_t *i;
34
35 if (argc != 2) {
36 fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
37 exit(1);
38 }
39
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");
43 exit(1);
44 }
45
46 i = (uint32_t *) &ptr[0x3944];
47 if (*i == 0x0c000944) {
48 fprintf(stderr, "Unpatched ADAM2 detected. Patching... ");
49 *i = 0x00000000;
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");
54 } else {
55 fprintf(stderr, "Unknown ADAM2 detected. Can't patch!\n");
56 }
57
58 close(fd);
59}
Note: See TracBrowser for help on using the repository browser.