//Utility function to perform hexdumps in the default format of the bsd hexdump utility //(C) 2017 Jeroen Domburg //This file is public domain where possible or CC0-licensed where not. //CC0: https://creativecommons.org/share-your-work/public-domain/cc0/ #include #include #include void hexdumpFrom(void *mem, int len, int adrStart) { uint8_t *data=(uint8_t*)mem; int pos=0; while (pos=len) break; //Print if printable if (isprint((int)data[pos+i])) { printf("%c", data[pos+i]); } else { printf("."); } } printf("|\n"); pos+=16; } printf("%08x\n", adrStart+len); } void hexdump(void *mem, int len) { hexdumpFrom(mem, len, 0); } //Uncomment the following line and compile 'gcc -o hexdump hexdump.c' to create a barebones hexdump utility that //reads stdin and dumps the hex content of it to stdout //#define TESTCASE #ifdef TESTCASE #include int main(int argc, char **argv) { char buff[1024]; int adr=0; if (argc>1) adr=strtol(argv[1], NULL, 0); int i=0; int ch; while ((ch=getchar())!=EOF) buff[i++]=ch; hexdumpFrom(buff, i, adr); } #endif