Rizin
unix-like reverse engineering framework and cli tools
stream_flags_encoder.c
Go to the documentation of this file.
1 //
5 //
6 // Author: Lasse Collin
7 //
8 // This file has been put into the public domain.
9 // You can do whatever you want with this file.
10 //
12 
13 #include "stream_flags_common.h"
14 
15 
16 static bool
18 {
19  if ((unsigned int)(options->check) > LZMA_CHECK_ID_MAX)
20  return true;
21 
22  out[0] = 0x00;
23  out[1] = options->check;
24 
25  return false;
26 }
27 
28 
30 lzma_stream_header_encode(const lzma_stream_flags *options, uint8_t *out)
31 {
34 
35  if (options->version != 0)
36  return LZMA_OPTIONS_ERROR;
37 
38  // Magic
40 
41  // Stream Flags
43  return LZMA_PROG_ERROR;
44 
45  // CRC32 of the Stream Header
46  const uint32_t crc = lzma_crc32(out + sizeof(lzma_header_magic),
48 
50  crc);
51 
52  return LZMA_OK;
53 }
54 
55 
56 extern LZMA_API(lzma_ret)
57 lzma_stream_footer_encode(const lzma_stream_flags *options, uint8_t *out)
58 {
61 
62  if (options->version != 0)
63  return LZMA_OPTIONS_ERROR;
64 
65  // Backward Size
67  return LZMA_PROG_ERROR;
68 
69  write32le(out + 4, options->backward_size / 4 - 1);
70 
71  // Stream Flags
72  if (stream_flags_encode(options, out + 2 * 4))
73  return LZMA_PROG_ERROR;
74 
75  // CRC32
76  const uint32_t crc = lzma_crc32(
77  out + 4, 4 + LZMA_STREAM_FLAGS_SIZE, 0);
78 
79  write32le(out, crc);
80 
81  // Magic
84 
85  return LZMA_OK;
86 }
#define LZMA_CHECK_ID_MAX
Maximum valid Check ID.
Definition: check.h:68
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static const char struct stat static buf struct stat static buf static vhangup int options
Definition: sflib.h:145
assert(limit<=UINT32_MAX/2)
unsigned int uint32_t
Definition: sftypes.h:29
unsigned char uint8_t
Definition: sftypes.h:31
#define LZMA_STREAM_HEADER_SIZE
Size of Stream Header and Stream Footer.
Definition: stream_flags.h:27
const uint8_t lzma_header_magic[6]
const uint8_t lzma_footer_magic[2]
Common stuff for Stream flags coders.
static bool is_backward_size_valid(const lzma_stream_flags *options)
#define LZMA_STREAM_FLAGS_SIZE
Size of the Stream Flags field.
LZMA_API(lzma_ret)
static bool stream_flags_encode(const lzma_stream_flags *options, uint8_t *out)
Options for encoding/decoding Stream Header and Stream Footer.
Definition: stream_flags.h:33
#define write32le(buf, num)
lzma_ret
Return values used by several functions in liblzma.
Definition: base.h:57
@ LZMA_PROG_ERROR
Programming error.
Definition: base.h:218
@ LZMA_OPTIONS_ERROR
Invalid or unsupported options.
Definition: base.h:160
@ LZMA_OK
Operation completed successfully.
Definition: base.h:58