Mirror of CollapseOS
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

46 рядки
1.2KB

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <fcntl.h>
  4. #include <unistd.h>
  5. #include "common.h"
  6. /* Read specified number of bytes at specified memory address through a BASIC
  7. * remote shell and dump it to stdout.
  8. */
  9. int main(int argc, char **argv)
  10. {
  11. if (argc != 4) {
  12. fprintf(stderr, "Usage: ./memdump device memptr bytecount\n");
  13. return 1;
  14. }
  15. unsigned int memptr = strtol(argv[2], NULL, 16);
  16. unsigned int bytecount = strtol(argv[3], NULL, 16);
  17. fprintf(stderr, "memptr: 0x%04x bytecount: 0x%04x.\n", memptr, bytecount);
  18. if (memptr+bytecount > 0xffff) {
  19. fprintf(stderr, "memptr+bytecount out of range.\n");
  20. return 1;
  21. }
  22. if (!bytecount) {
  23. // nothing to spit
  24. return 0;
  25. }
  26. int fd = open(argv[1], O_RDWR|O_NOCTTY);
  27. char s[0x30];
  28. sprintf(s, "m=0x%04x", memptr);
  29. sendcmdp(fd, s);
  30. sprintf(s, "while m<0x%04x peek m:puth a:m=m+1", memptr+bytecount);
  31. sendcmd(fd, s);
  32. for (int i=0; i<bytecount; i++) {
  33. read(fd, s, 2); // read hex pair
  34. s[2] = 0; // null terminate
  35. unsigned char c = strtol(s, NULL, 16);
  36. putchar(c);
  37. }
  38. read(fd, s, 2); // read prompt
  39. return 0;
  40. }