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

Filter for ARM-Thumb binaries. More...

#include "simple_private.h"

Go to the source code of this file.

Functions

static size_t armthumb_code (void *simple lzma_attribute((__unused__)), uint32_t now_pos, bool is_encoder, uint8_t *buffer, size_t size)
 
static lzma_ret armthumb_coder_init (lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters, bool is_encoder)
 
lzma_ret lzma_simple_armthumb_encoder_init (lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters)
 
lzma_ret lzma_simple_armthumb_decoder_init (lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters)
 

Detailed Description

Filter for ARM-Thumb binaries.

Definition in file armthumb.c.

Function Documentation

◆ armthumb_code()

static size_t armthumb_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 armthumb.c.

21 {
22  size_t i;
23  for (i = 0; i + 4 <= size; i += 2) {
24  if ((buffer[i + 1] & 0xF8) == 0xF0
25  && (buffer[i + 3] & 0xF8) == 0xF8) {
26  uint32_t src = (((uint32_t)(buffer[i + 1]) & 7) << 19)
27  | ((uint32_t)(buffer[i + 0]) << 11)
28  | (((uint32_t)(buffer[i + 3]) & 7) << 8)
29  | (uint32_t)(buffer[i + 2]);
30 
31  src <<= 1;
32 
33  uint32_t dest;
34  if (is_encoder)
35  dest = now_pos + (uint32_t)(i) + 4 + src;
36  else
37  dest = src - (now_pos + (uint32_t)(i) + 4);
38 
39  dest >>= 1;
40  buffer[i + 1] = 0xF0 | ((dest >> 19) & 0x7);
41  buffer[i + 0] = (dest >> 11);
42  buffer[i + 3] = 0xF8 | ((dest >> 8) & 0x7);
43  buffer[i + 2] = (dest);
44  i += 2;
45  }
46  }
47 
48  return i;
49 }
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
Definition: buffer.h:15

References dest, i, and src.

Referenced by armthumb_coder_init().

◆ armthumb_coder_init()

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

Definition at line 53 of file armthumb.c.

55 {
57  &armthumb_code, 0, 4, 2, is_encoder);
58 }
static size_t armthumb_code(void *simple lzma_attribute((__unused__)), uint32_t now_pos, bool is_encoder, uint8_t *buffer, size_t size)
Definition: armthumb.c:18
const lzma_allocator * allocator
Definition: block.h:377
const lzma_filter * filters
Definition: container.h:315
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, armthumb_code(), filters, and lzma_simple_coder_init().

Referenced by lzma_simple_armthumb_decoder_init(), and lzma_simple_armthumb_encoder_init().

◆ lzma_simple_armthumb_decoder_init()

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

Definition at line 71 of file armthumb.c.

74 {
75  return armthumb_coder_init(next, allocator, filters, false);
76 }
static lzma_ret armthumb_coder_init(lzma_next_coder *next, const lzma_allocator *allocator, const lzma_filter_info *filters, bool is_encoder)
Definition: armthumb.c:53

References allocator, armthumb_coder_init(), and filters.

◆ lzma_simple_armthumb_encoder_init()

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

Definition at line 62 of file armthumb.c.

65 {
66  return armthumb_coder_init(next, allocator, filters, true);
67 }

References allocator, armthumb_coder_init(), and filters.