Mirror of CollapseOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 line
859B

  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 in active blkdev at active offset.
  7. */
  8. int main(int argc, char **argv)
  9. {
  10. if (argc != 3) {
  11. fprintf(stderr, "Usage: ./memdump device bytecount\n");
  12. return 1;
  13. }
  14. unsigned int bytecount = strtol(argv[2], NULL, 16);
  15. if (!bytecount) {
  16. // nothing to spit
  17. return 0;
  18. }
  19. int fd = open(argv[1], O_RDWR|O_NOCTTY);
  20. char s[0x30];
  21. sendcmdp(fd, "i=0");
  22. sprintf(s, "while i<0x%04x getb:puth a:i=i+1", bytecount);
  23. sendcmd(fd, s);
  24. for (int i=0; i<bytecount; i++) {
  25. read(fd, s, 2); // read hex pair
  26. s[2] = 0; // null terminate
  27. unsigned char c = strtol(s, NULL, 16);
  28. putchar(c);
  29. }
  30. read(fd, s, 2); // read prompt
  31. return 0;
  32. }