Rizin
unix-like reverse engineering framework and cli tools
crc32_tablegen.c File Reference

Generate crc32_table_le.h and crc32_table_be.h. More...

#include <stdio.h>
#include "../../common/tuklib_integer.h"

Go to the source code of this file.

Functions

static void init_crc32_table (void)
 
static void print_crc32_table (void)
 
static void print_lz_table (void)
 
int main (void)
 

Variables

static uint32_t crc32_table [8][256]
 

Detailed Description

Generate crc32_table_le.h and crc32_table_be.h.

Compiling: gcc -std=c99 -o crc32_tablegen crc32_tablegen.c Add -DWORDS_BIGENDIAN to generate big endian table. Add -DLZ_HASH_TABLE to generate lz_encoder_hash_table.h (little endian).

Definition in file crc32_tablegen.c.

Function Documentation

◆ init_crc32_table()

static void init_crc32_table ( void  )
static

Definition at line 25 of file crc32_tablegen.c.

26 {
27  static const uint32_t poly32 = UINT32_C(0xEDB88320);
28 
29  for (size_t s = 0; s < 8; ++s) {
30  for (size_t b = 0; b < 256; ++b) {
31  uint32_t r = s == 0 ? b : crc32_table[s - 1][b];
32 
33  for (size_t i = 0; i < 8; ++i) {
34  if (r & 1)
35  r = (r >> 1) ^ poly32;
36  else
37  r >>= 1;
38  }
39 
40  crc32_table[s][b] = r;
41  }
42  }
43 
44 #ifdef WORDS_BIGENDIAN
45  for (size_t s = 0; s < 8; ++s)
46  for (size_t b = 0; b < 256; ++b)
48 #endif
49 
50  return;
51 }
lzma_index ** i
Definition: index.h:629
static uint32_t crc32_table[8][256]
#define r
Definition: crypto_rc6.c:12
static RzSocket * s
Definition: rtr.c:28
unsigned int uint32_t
Definition: sftypes.h:29
#define b(i)
Definition: sha256.c:42
#define UINT32_C(val)
#define bswap32(n)

References b, bswap32, crc32_table, i, r, s, and UINT32_C.

Referenced by main().

◆ main()

int main ( void  )

Definition at line 106 of file crc32_tablegen.c.

107 {
109 
110 #ifdef LZ_HASH_TABLE
111  print_lz_table();
112 #else
114 #endif
115 
116  return 0;
117 }
static void print_crc32_table(void)
static void init_crc32_table(void)
static void print_lz_table(void)

References init_crc32_table(), print_crc32_table(), and print_lz_table().

◆ print_crc32_table()

static void print_crc32_table ( void  )
static

Definition at line 55 of file crc32_tablegen.c.

56 {
57  printf("/* This file has been automatically generated by "
58  "crc32_tablegen.c. */\n\n"
59  "const uint32_t lzma_crc32_table[8][256] = {\n\t{");
60 
61  for (size_t s = 0; s < 8; ++s) {
62  for (size_t b = 0; b < 256; ++b) {
63  if ((b % 4) == 0)
64  printf("\n\t\t");
65 
66  printf("0x%08" PRIX32, crc32_table[s][b]);
67 
68  if (b != 255)
69  printf(",%s", (b+1) % 4 == 0 ? "" : " ");
70  }
71 
72  if (s == 7)
73  printf("\n\t}\n};\n");
74  else
75  printf("\n\t}, {");
76  }
77 
78  return;
79 }
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
#define PRIX32
Definition: sysdefs.h:70

References b, crc32_table, printf(), PRIX32, and s.

Referenced by main().

◆ print_lz_table()

static void print_lz_table ( void  )
static

Definition at line 83 of file crc32_tablegen.c.

84 {
85  printf("/* This file has been automatically generated by "
86  "crc32_tablegen.c. */\n\n"
87  "const uint32_t lzma_lz_hash_table[256] = {");
88 
89  for (size_t b = 0; b < 256; ++b) {
90  if ((b % 4) == 0)
91  printf("\n\t");
92 
93  printf("0x%08" PRIX32, crc32_table[0][b]);
94 
95  if (b != 255)
96  printf(",%s", (b+1) % 4 == 0 ? "" : " ");
97  }
98 
99  printf("\n};\n");
100 
101  return;
102 }

References b, crc32_table, printf(), and PRIX32.

Referenced by main().

Variable Documentation

◆ crc32_table

uint32_t crc32_table[8][256]
static

Definition at line 21 of file crc32_tablegen.c.

Referenced by init_crc32_table(), print_crc32_table(), and print_lz_table().