2019-12-11 02:33:29 +11:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
/* Read specified number of bytes in active blkdev at active offset.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
if (argc != 3) {
|
|
|
|
fprintf(stderr, "Usage: ./memdump device bytecount\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
unsigned int bytecount = strtol(argv[2], NULL, 16);
|
|
|
|
if (!bytecount) {
|
|
|
|
// nothing to spit
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int fd = open(argv[1], O_RDWR|O_NOCTTY);
|
2019-12-13 04:04:56 +11:00
|
|
|
char s[0x30];
|
|
|
|
sendcmdp(fd, "i=0");
|
|
|
|
sprintf(s, "while i<0x%04x getb:puth a:i=i+1", bytecount);
|
|
|
|
sendcmd(fd, s);
|
|
|
|
|
2019-12-11 02:33:29 +11:00
|
|
|
for (int i=0; i<bytecount; i++) {
|
|
|
|
read(fd, s, 2); // read hex pair
|
|
|
|
s[2] = 0; // null terminate
|
|
|
|
unsigned char c = strtol(s, NULL, 16);
|
|
|
|
putchar(c);
|
|
|
|
}
|
2019-12-13 04:04:56 +11:00
|
|
|
read(fd, s, 2); // read prompt
|
2019-12-11 02:33:29 +11:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|