Created
May 5, 2023 13:33
-
-
Save blue-devil/0aa449f8a267f5d8032d8c55f6679ca0 to your computer and use it in GitHub Desktop.
C function that prints hex dump of given memory block.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* hex_dump.c | |
* Copyright (C) 2022 Blue DeviL <[email protected]> | |
* | |
* This program is free software: you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation, either version 3 of the License, or | |
* (at your option) any later version. | |
* | |
* This program is distributed in the hope that it will be useful, | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
* GNU General Public License for more details. | |
* | |
* You should have received a copy of the GNU General Public License | |
* along with this program. If not, see <https://www.gnu.org/licenses/>. | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
void dump_mem(const void *mem_blk, unsigned long long len) | |
{ | |
char szLineFmt[] = "0x%016X\t"; | |
// char szLineFmt2[] = "0x%08X"; | |
unsigned long long i; | |
unsigned long long f32bit = 0xFFFFFFFF; | |
if (len < f32bit) | |
{ | |
strcpy(szLineFmt, "0x%08X\t"); | |
} | |
for (i = 0; i < len; i++) | |
{ | |
if (i % 8 == 0) | |
printf(" "); | |
if (i % 16 == 0) | |
{ | |
printf("\n"); | |
printf(szLineFmt, i); | |
} | |
printf("%02X ", *(unsigned char *)(mem_blk + i)); | |
} | |
printf("\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment