Enviado em 06/08/2022 - 12:33h
<stdio.h>
#define BLOCOS 16
FILE *Abre_hexdump(const char *caminho, const char *mode) {
FILE *fp;
if (!(fp = fopen(caminho, mode))){
printf("error ao abrir '%s'", caminho);
return 0;
}return fp;
}
int main(int argc, char const *argv[]){
FILE *fp_in, *fp_out;
unsigned char buf[BLOCOS];
size_t nread;
int i, c, npos;
if (argc < 2 || argc > 3){
printf("use: %s <file-in> [file-out]\n", argv[0]);
return 0;
}/* Abre o arquivo de entrada */
fp_in = Abre_hexdump(argv[1], "r");
/* Redirecionar a saída se um arquivo de saída for definido */
fp_out = (argc == 3 ? Abre_hexdump_open(argv[2], "w") : stdout);
npos = 0;
/* Exibir BLOCOS de bytes dos dados hexadecimais de cada vez */
while ((nread = fread(buf, 1, sizeof buf, fp_in)) > 1) {
fprintf(fp_out, "%04x: ", npos);
npos += BLOCOS;
/* print valores hexadecimais, exemplo 3f 62 ec f0*/
for (i = 0; i < BLOCOS; i++)
fprintf(fp_out, "%02x ", buf[i]);
/* print valores ascii ..A6..ó.j...D*/
for (i = 0; i < BLOCOS; i++) {
c = buf[i];
fprintf(fp_out, "%c", (c >= 33 && c <= 255 ? c : '.'));
}fprintf(fp_out, "\n");
}fclose(fp_in);
return 0;
}
(buf[i] >= 33 || buf[i] <=126); ou, >0x20 && <=0x7e
"%c", (c >= 33 && c <= 255 ? c : '.')
Enviado em 07/08/2022 - 03:40h
Normalmente você faria algo como o seguinte:putchar(isprint(c)? c: '.');
Enviado em 07/08/2022 - 04:22h
(isprint(buf[i])?buf[i]:'a')
(isprint(buf[i])?buf[i]:'')
Instalação do Ambiente .NET (#C) no Slackware 15.0
Kali On The Box - Colocando o Kali para rodar no Raspberry Pi
Como contribuir com a atualização de pacotes no Void Linux
Colocar dispositivo móvel Samsung em modo Download pela linha de comando
Instalando Slackware com btrfs
Debian 11 bullseye não tem terminal transparente (2)
System Halted - ao desligar o computador (7)
Instalação Fedora 36 com "\home&q... separada: Questão sobre Sist... (5)