Rizin
unix-like reverse engineering framework and cli tools
diff_output.c File Reference
#include "diff_output.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "compat.h"

Go to the source code of this file.

Macros

#define MAX_BYTES   64
 

Functions

static void ensure_header (diff_output_t *output)
 
void diff_output_init (diff_output_t *output, int verbose, char *const archive_names[])
 
void diff_output_start_file (diff_output_t *output, const char *name, zip_uint64_t size, zip_uint32_t crc)
 
void diff_output_end_file (diff_output_t *output)
 
void diff_output (diff_output_t *output, int side, const char *fmt,...)
 
void diff_output_file (diff_output_t *output, char side, const char *name, zip_uint64_t size, zip_uint32_t crc)
 
void diff_output_data (diff_output_t *output, int side, const zip_uint8_t *data, zip_uint64_t data_length, const char *fmt,...)
 

Macro Definition Documentation

◆ MAX_BYTES

#define MAX_BYTES   64

Definition at line 74 of file diff_output.c.

Function Documentation

◆ diff_output()

void diff_output ( diff_output_t output,
int  side,
const char *  fmt,
  ... 
)

Definition at line 38 of file diff_output.c.

38  {
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 }
#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
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
diff_output_t output
Definition: zipcmp.c:237

References diff_output_file(), ensure_header(), diff_output_t::file_crc, diff_output_t::file_name, diff_output_t::file_size, NULL, output, printf(), and diff_output_t::verbose.

Referenced by diff_output_data(), and entry_paranoia_checks().

◆ diff_output_data()

void diff_output_data ( diff_output_t output,
int  side,
const zip_uint8_t data,
zip_uint64_t  data_length,
const char *  fmt,
  ... 
)

Definition at line 75 of file diff_output.c.

75  {
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
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
unsigned short prefix[65536]
Definition: gun.c:163
voidpf uLong offset
Definition: ioapi.h:144
sprintf
Definition: kernel.h:365
vsnprintf
Definition: kernel.h:366
#define PRIu64
Definition: macros.h:18

References diff_output(), i, MAX_BYTES, output, prefix, PRIu64, sprintf, diff_output_t::verbose, and vsnprintf.

Referenced by compare_zip(), ef_print(), and entry_paranoia_checks().

◆ diff_output_end_file()

void diff_output_end_file ( diff_output_t output)

Definition at line 34 of file diff_output.c.

34  {
36 }

References diff_output_t::file_name, NULL, and output.

Referenced by compare_list().

◆ diff_output_file()

void diff_output_file ( diff_output_t output,
char  side,
const char *  name,
zip_uint64_t  size,
zip_uint32_t  crc 
)

Definition at line 59 of file diff_output.c.

59  {
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 }
voidpf void uLong size
Definition: ioapi.h:138
Definition: z80asm.h:102

References ensure_header(), output, printf(), PRIu64, and diff_output_t::verbose.

Referenced by diff_output(), and entry_print().

◆ diff_output_init()

void diff_output_init ( diff_output_t output,
int  verbose,
char *const  archive_names[] 
)

Definition at line 19 of file diff_output.c.

19  {
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 }
const char * archive_names[2]
Definition: diff_output.h:7
static int verbose
Definition: z80asm.c:73

References diff_output_t::archive_names, diff_output_t::file_crc, diff_output_t::file_name, diff_output_t::file_size, NULL, output, verbose, and diff_output_t::verbose.

Referenced by compare_zip().

◆ diff_output_start_file()

void diff_output_start_file ( diff_output_t output,
const char *  name,
zip_uint64_t  size,
zip_uint32_t  crc 
)

Definition at line 28 of file diff_output.c.

28  {
31  output->file_crc = crc;
32 }
const char * name
Definition: op.c:541

References diff_output_t::file_crc, diff_output_t::file_name, diff_output_t::file_size, name, and output.

Referenced by entry_start_file().

◆ ensure_header()

static void ensure_header ( diff_output_t output)
static

Definition at line 10 of file diff_output.c.

10  {
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 }

References diff_output_t::archive_names, NULL, output, and printf().

Referenced by diff_output(), and diff_output_file().