2007-12-08 23:42:33 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
/// \file arm.c
|
|
|
|
/// \brief Filter for ARM binaries
|
2009-04-13 10:27:40 +02:00
|
|
|
///
|
|
|
|
// Authors: Igor Pavlov
|
|
|
|
// Lasse Collin
|
2007-12-08 23:42:33 +01:00
|
|
|
//
|
2009-04-13 10:27:40 +02:00
|
|
|
// This file has been put into the public domain.
|
|
|
|
// You can do whatever you want with this file.
|
2007-12-08 23:42:33 +01:00
|
|
|
//
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "simple_private.h"
|
|
|
|
|
|
|
|
|
|
|
|
static size_t
|
2016-11-21 19:24:50 +01:00
|
|
|
arm_code(void *simple lzma_attribute((__unused__)),
|
2007-12-08 23:42:33 +01:00
|
|
|
uint32_t now_pos, bool is_encoder,
|
|
|
|
uint8_t *buffer, size_t size)
|
|
|
|
{
|
2009-04-15 13:13:38 +02:00
|
|
|
size_t i;
|
2007-12-08 23:42:33 +01:00
|
|
|
for (i = 0; i + 4 <= size; i += 4) {
|
|
|
|
if (buffer[i + 3] == 0xEB) {
|
2019-06-23 20:38:56 +02:00
|
|
|
uint32_t src = ((uint32_t)(buffer[i + 2]) << 16)
|
|
|
|
| ((uint32_t)(buffer[i + 1]) << 8)
|
|
|
|
| (uint32_t)(buffer[i + 0]);
|
2007-12-08 23:42:33 +01:00
|
|
|
src <<= 2;
|
|
|
|
|
|
|
|
uint32_t dest;
|
|
|
|
if (is_encoder)
|
|
|
|
dest = now_pos + (uint32_t)(i) + 8 + src;
|
|
|
|
else
|
|
|
|
dest = src - (now_pos + (uint32_t)(i) + 8);
|
|
|
|
|
|
|
|
dest >>= 2;
|
|
|
|
buffer[i + 2] = (dest >> 16);
|
|
|
|
buffer[i + 1] = (dest >> 8);
|
|
|
|
buffer[i + 0] = dest;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static lzma_ret
|
2012-07-17 17:19:59 +02:00
|
|
|
arm_coder_init(lzma_next_coder *next, const lzma_allocator *allocator,
|
2007-12-08 23:42:33 +01:00
|
|
|
const lzma_filter_info *filters, bool is_encoder)
|
|
|
|
{
|
|
|
|
return lzma_simple_coder_init(next, allocator, filters,
|
2009-07-10 10:39:38 +02:00
|
|
|
&arm_code, 0, 4, 4, is_encoder);
|
2007-12-08 23:42:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern lzma_ret
|
2012-07-17 17:19:59 +02:00
|
|
|
lzma_simple_arm_encoder_init(lzma_next_coder *next,
|
|
|
|
const lzma_allocator *allocator,
|
2007-12-08 23:42:33 +01:00
|
|
|
const lzma_filter_info *filters)
|
|
|
|
{
|
|
|
|
return arm_coder_init(next, allocator, filters, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern lzma_ret
|
2012-07-17 17:19:59 +02:00
|
|
|
lzma_simple_arm_decoder_init(lzma_next_coder *next,
|
|
|
|
const lzma_allocator *allocator,
|
2007-12-08 23:42:33 +01:00
|
|
|
const lzma_filter_info *filters)
|
|
|
|
{
|
|
|
|
return arm_coder_init(next, allocator, filters, false);
|
|
|
|
}
|