Rizin
unix-like reverse engineering framework and cli tools
diff_output.c
Go to the documentation of this file.
1 #include "diff_output.h"
2 
3 #include <stdarg.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7 
8 #include "compat.h"
9 
11  if (output->archive_names[0] != NULL) {
12  printf("--- %s\n", output->archive_names[0]);
13  printf("+++ %s\n", output->archive_names[1]);
16  }
17 }
18 
19 void diff_output_init(diff_output_t *output, int verbose, char *const archive_names[]) {
20  output->archive_names[0] = archive_names[0];
21  output->archive_names[1] = archive_names[1];
24  output->file_size = 0;
25  output->file_crc = 0;
26 }
27 
31  output->file_crc = crc;
32 }
33 
36 }
37 
38 void diff_output(diff_output_t *output, int side, const char *fmt, ...) {
39  va_list ap;
40 
41  if (!output->verbose) {
42  return;
43  }
44 
46 
47  if (output->file_name != NULL) {
50  }
51 
52  printf("%c ", side);
53  va_start(ap, fmt);
54  vprintf(fmt, ap);
55  va_end(ap);
56  printf("\n");
57 }
58 
59 void diff_output_file(diff_output_t *output, char side, const char *name, zip_uint64_t size, zip_uint32_t crc) {
60  if (!output->verbose) {
61  return;
62  }
63 
65 
66  if (size == 0 && crc == 0 && name[0] != '\0' && name[strlen(name) - 1] == '/') {
67  printf("%c directory '%s'\n", side, name);
68  }
69  else {
70  printf("%c file '%s', size %" PRIu64 ", crc %08x\n", side, name, size, crc);
71  }
72 }
73 
74 #define MAX_BYTES 64
75 void diff_output_data(diff_output_t *output, int side, const zip_uint8_t *data, zip_uint64_t data_length, const char *fmt, ...) {
76  char prefix[1024];
77  char hexdata[MAX_BYTES * 3 + 6];
78  size_t i, offset;
79  va_list ap;
80 
81  if (!output->verbose) {
82  return;
83  }
84 
85  offset = 0;
86  for (i = 0; i < data_length; i++) {
87  hexdata[offset++] = (i == 0 ? '<' : ' ');
88 
89  if (i >= MAX_BYTES) {
90  sprintf(hexdata + offset, "...");
91  break;
92  }
93  sprintf(hexdata + offset, "%02x", data[i]);
94  offset += 2;
95  }
96 
97  hexdata[offset++] = '>';
98  hexdata[offset] = '\0';
99 
100  va_start(ap, fmt);
101  vsnprintf(prefix, sizeof(prefix), fmt, ap);
102  va_end(ap);
103  prefix[sizeof(prefix) - 1] = '\0';
104 
105  diff_output(output, side, "%s, length %" PRIu64 ", data %s", prefix, data_length, hexdata);
106 }
lzma_index ** i
Definition: index.h:629
#define NULL
Definition: cris-opc.c:27
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
void diff_output_file(diff_output_t *output, char side, const char *name, zip_uint64_t size, zip_uint32_t crc)
Definition: diff_output.c:59
static void ensure_header(diff_output_t *output)
Definition: diff_output.c:10
void diff_output_data(diff_output_t *output, int side, const zip_uint8_t *data, zip_uint64_t data_length, const char *fmt,...)
Definition: diff_output.c:75
void diff_output(diff_output_t *output, int side, const char *fmt,...)
Definition: diff_output.c:38
#define MAX_BYTES
Definition: diff_output.c:74
void diff_output_end_file(diff_output_t *output)
Definition: diff_output.c:34
void diff_output_start_file(diff_output_t *output, const char *name, zip_uint64_t size, zip_uint32_t crc)
Definition: diff_output.c:28
void diff_output_init(diff_output_t *output, int verbose, char *const archive_names[])
Definition: diff_output.c:19
unsigned short prefix[65536]
Definition: gun.c:163
voidpf void uLong size
Definition: ioapi.h:138
voidpf uLong offset
Definition: ioapi.h:144
sprintf
Definition: kernel.h:365
vsnprintf
Definition: kernel.h:366
#define PRIu64
Definition: macros.h:18
const char * name
Definition: op.c:541
const char * file_name
Definition: diff_output.h:8
zip_uint64_t file_size
Definition: diff_output.h:9
zip_uint32_t file_crc
Definition: diff_output.h:10
const char * archive_names[2]
Definition: diff_output.h:7
Definition: z80asm.h:102
static int verbose
Definition: z80asm.c:73
diff_output_t output
Definition: zipcmp.c:237
uint64_t zip_uint64_t
Definition: zipconf.h:39
uint32_t zip_uint32_t
Definition: zipconf.h:37
uint8_t zip_uint8_t
Definition: zipconf.h:33