Rizin
unix-like reverse engineering framework and cli tools
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Friends Macros Modules Pages
ia64.c File Reference

Filter for IA64 (Itanium) binaries. More...

#include "simple_private.h"

Go to the source code of this file.

Functions

static size_t ia64_code (void *simple lzma_attribute((__unused__)), uint32_t now_pos, bool is_encoder, uint8_t *buffer, size_t size)
 
static lzma_ret ia64_coder_init (lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters, bool is_encoder)
 
lzma_ret lzma_simple_ia64_encoder_init (lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters)
 
lzma_ret lzma_simple_ia64_decoder_init (lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters)
 

Detailed Description

Filter for IA64 (Itanium) binaries.

Definition in file ia64.c.

Function Documentation

◆ ia64_code()

static size_t ia64_code ( void *simple   lzma_attribute(__unused__),
uint32_t  now_pos,
bool  is_encoder,
uint8_t buffer,
size_t  size 
)
static

Definition at line 18 of file ia64.c.

21 {
22  static const uint32_t BRANCH_TABLE[32] = {
23  0, 0, 0, 0, 0, 0, 0, 0,
24  0, 0, 0, 0, 0, 0, 0, 0,
25  4, 4, 6, 6, 0, 0, 7, 7,
26  4, 4, 0, 0, 4, 4, 0, 0
27  };
28 
29  size_t i;
30  for (i = 0; i + 16 <= size; i += 16) {
31  const uint32_t instr_template = buffer[i] & 0x1F;
32  const uint32_t mask = BRANCH_TABLE[instr_template];
33  uint32_t bit_pos = 5;
34 
35  for (size_t slot = 0; slot < 3; ++slot, bit_pos += 41) {
36  if (((mask >> slot) & 1) == 0)
37  continue;
38 
39  const size_t byte_pos = (bit_pos >> 3);
40  const uint32_t bit_res = bit_pos & 0x7;
42 
43  for (size_t j = 0; j < 6; ++j)
44  instruction += (uint64_t)(
45  buffer[i + j + byte_pos])
46  << (8 * j);
47 
48  uint64_t inst_norm = instruction >> bit_res;
49 
50  if (((inst_norm >> 37) & 0xF) == 0x5
51  && ((inst_norm >> 9) & 0x7) == 0
52  /* && (inst_norm & 0x3F)== 0 */
53  ) {
54  uint32_t src = (uint32_t)(
55  (inst_norm >> 13) & 0xFFFFF);
56  src |= ((inst_norm >> 36) & 1) << 20;
57 
58  src <<= 4;
59 
60  uint32_t dest;
61  if (is_encoder)
62  dest = now_pos + (uint32_t)(i) + src;
63  else
64  dest = src - (now_pos + (uint32_t)(i));
65 
66  dest >>= 4;
67 
68  inst_norm &= ~((uint64_t)(0x8FFFFF) << 13);
69  inst_norm |= (uint64_t)(dest & 0xFFFFF) << 13;
70  inst_norm |= (uint64_t)(dest & 0x100000)
71  << (36 - 20);
72 
73  instruction &= (1U << bit_res) - 1;
74  instruction |= (inst_norm << bit_res);
75 
76  for (size_t j = 0; j < 6; j++)
77  buffer[i + j + byte_pos] = (uint8_t)(
79  >> (8 * j));
80  }
81  }
82  }
83 
84  return i;
85 }
#define mask()
lzma_index ** i
Definition: index.h:629
lzma_index * src
Definition: index.h:567
voidpf void uLong size
Definition: ioapi.h:138
char * dest
Definition: lz4.h:697
unsigned int uint32_t
Definition: sftypes.h:29
unsigned long uint64_t
Definition: sftypes.h:28
unsigned char uint8_t
Definition: sftypes.h:31
Definition: buffer.h:15

References dest, i, mask, and src.

Referenced by ia64_coder_init().

◆ ia64_coder_init()

static lzma_ret ia64_coder_init ( lzma_next_coder next,
const lzma_allocator allocator,
const lzma_filter_info filters,
bool  is_encoder 
)
static

Definition at line 89 of file ia64.c.

91 {
93  &ia64_code, 0, 16, 16, is_encoder);
94 }
const lzma_allocator * allocator
Definition: block.h:377
const lzma_filter * filters
Definition: container.h:315
static size_t ia64_code(void *simple lzma_attribute((__unused__)), uint32_t now_pos, bool is_encoder, uint8_t *buffer, size_t size)
Definition: ia64.c:18
lzma_ret lzma_simple_coder_init(lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters, size_t(*filter)(void *simple, uint32_t now_pos, bool is_encoder, uint8_t *buffer, size_t size), size_t simple_size, size_t unfiltered_max, uint32_t alignment, bool is_encoder)
Definition: simple_coder.c:235

References allocator, filters, ia64_code(), and lzma_simple_coder_init().

Referenced by lzma_simple_ia64_decoder_init(), and lzma_simple_ia64_encoder_init().

◆ lzma_simple_ia64_decoder_init()

lzma_ret lzma_simple_ia64_decoder_init ( lzma_next_coder next,
const lzma_allocator allocator,
const lzma_filter_info filters 
)

Definition at line 107 of file ia64.c.

110 {
111  return ia64_coder_init(next, allocator, filters, false);
112 }
static lzma_ret ia64_coder_init(lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters, bool is_encoder)
Definition: ia64.c:89

References allocator, filters, and ia64_coder_init().

◆ lzma_simple_ia64_encoder_init()

lzma_ret lzma_simple_ia64_encoder_init ( lzma_next_coder next,
const lzma_allocator allocator,
const lzma_filter_info filters 
)

Definition at line 98 of file ia64.c.

101 {
102  return ia64_coder_init(next, allocator, filters, true);
103 }

References allocator, filters, and ia64_coder_init().