adam2patcher.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <stddef.h>
  19. #include <unistd.h>
  20. #include <fcntl.h>
  21. #include <stdint.h>
  22. #include <sys/mman.h>
  23. #include <sys/stat.h>
  24. #include <string.h>
  25. #include <sys/ioctl.h>
  26. int main(int argc, char **argv)
  27. {
  28. int fd;
  29. char *ptr;
  30. uint32_t *i;
  31. if (argc != 2) {
  32. fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
  33. exit(1);
  34. }
  35. if (((fd = open(argv[1], O_RDWR)) < 0)
  36. || ((ptr = mmap(0, 128 * 1024, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)) == (void *) (-1))) {
  37. fprintf(stderr, "Can't open file\n");
  38. exit(1);
  39. }
  40. i = (uint32_t *) &ptr[0x3944];
  41. if (*i == 0x0c000944) {
  42. fprintf(stderr, "Unpatched ADAM2 detected. Patching... ");
  43. *i = 0x00000000;
  44. msync(i, sizeof(*i), MS_SYNC|MS_INVALIDATE);
  45. fprintf(stderr, "done!\n");
  46. } else if (*i == 0x00000000) {
  47. fprintf(stderr, "Patched ADAM2 detected.\n");
  48. } else {
  49. fprintf(stderr, "Unknown ADAM2 detected. Can't patch!\n");
  50. }
  51. close(fd);
  52. }