/src/xz/src/liblzma/simple/arm.c
Line | Count | Source |
1 | | // SPDX-License-Identifier: 0BSD |
2 | | |
3 | | /////////////////////////////////////////////////////////////////////////////// |
4 | | // |
5 | | /// \file arm.c |
6 | | /// \brief Filter for ARM binaries |
7 | | /// |
8 | | // Authors: Igor Pavlov |
9 | | // Lasse Collin |
10 | | // |
11 | | /////////////////////////////////////////////////////////////////////////////// |
12 | | |
13 | | #include "simple_private.h" |
14 | | |
15 | | |
16 | | static size_t |
17 | | arm_code(void *simple lzma_attribute((__unused__)), |
18 | | uint32_t now_pos, bool is_encoder, |
19 | | uint8_t *buffer, size_t size) |
20 | 0 | { |
21 | 0 | size &= ~(size_t)3; |
22 | |
|
23 | 0 | size_t i; |
24 | 0 | for (i = 0; i < size; i += 4) { |
25 | 0 | if (buffer[i + 3] == 0xEB) { |
26 | 0 | uint32_t src = ((uint32_t)(buffer[i + 2]) << 16) |
27 | 0 | | ((uint32_t)(buffer[i + 1]) << 8) |
28 | 0 | | (uint32_t)(buffer[i + 0]); |
29 | 0 | src <<= 2; |
30 | |
|
31 | 0 | uint32_t dest; |
32 | 0 | if (is_encoder) |
33 | 0 | dest = now_pos + (uint32_t)(i) + 8 + src; |
34 | 0 | else |
35 | 0 | dest = src - (now_pos + (uint32_t)(i) + 8); |
36 | |
|
37 | 0 | dest >>= 2; |
38 | 0 | buffer[i + 2] = (dest >> 16); |
39 | 0 | buffer[i + 1] = (dest >> 8); |
40 | 0 | buffer[i + 0] = dest; |
41 | 0 | } |
42 | 0 | } |
43 | |
|
44 | 0 | return i; |
45 | 0 | } |
46 | | |
47 | | |
48 | | static lzma_ret |
49 | | arm_coder_init(lzma_next_coder *next, const lzma_allocator *allocator, |
50 | | const lzma_filter_info *filters, bool is_encoder) |
51 | 0 | { |
52 | 0 | return lzma_simple_coder_init(next, allocator, filters, |
53 | 0 | &arm_code, 0, 4, 4, is_encoder); |
54 | 0 | } |
55 | | |
56 | | |
57 | | #ifdef HAVE_ENCODER_ARM |
58 | | extern lzma_ret |
59 | | lzma_simple_arm_encoder_init(lzma_next_coder *next, |
60 | | const lzma_allocator *allocator, |
61 | | const lzma_filter_info *filters) |
62 | 0 | { |
63 | 0 | return arm_coder_init(next, allocator, filters, true); |
64 | 0 | } |
65 | | #endif |
66 | | |
67 | | |
68 | | #ifdef HAVE_DECODER_ARM |
69 | | extern lzma_ret |
70 | | lzma_simple_arm_decoder_init(lzma_next_coder *next, |
71 | | const lzma_allocator *allocator, |
72 | | const lzma_filter_info *filters) |
73 | 0 | { |
74 | | return arm_coder_init(next, allocator, filters, false); |
75 | 0 | } |
76 | | #endif |