BadVPN – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /** |
2 | * @file read_write_int.h |
||
3 | * @author Ambroz Bizjak <ambrop7@gmail.com> |
||
4 | * |
||
5 | * @section LICENSE |
||
6 | * |
||
7 | * Redistribution and use in source and binary forms, with or without |
||
8 | * modification, are permitted provided that the following conditions are met: |
||
9 | * 1. Redistributions of source code must retain the above copyright |
||
10 | * notice, this list of conditions and the following disclaimer. |
||
11 | * 2. Redistributions in binary form must reproduce the above copyright |
||
12 | * notice, this list of conditions and the following disclaimer in the |
||
13 | * documentation and/or other materials provided with the distribution. |
||
14 | * 3. Neither the name of the author nor the |
||
15 | * names of its contributors may be used to endorse or promote products |
||
16 | * derived from this software without specific prior written permission. |
||
17 | * |
||
18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
||
19 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
||
20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
||
21 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
||
22 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
||
23 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
||
24 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
||
25 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
||
27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
28 | */ |
||
29 | |||
30 | #ifndef BADVPN_READ_WRITE_INT_H |
||
31 | #define BADVPN_READ_WRITE_INT_H |
||
32 | |||
33 | #include <stdint.h> |
||
34 | |||
35 | static uint8_t badvpn_read_le8 (const char *c_ptr); |
||
36 | static uint16_t badvpn_read_le16 (const char *c_ptr); |
||
37 | static uint32_t badvpn_read_le32 (const char *c_ptr); |
||
38 | static uint64_t badvpn_read_le64 (const char *c_ptr); |
||
39 | |||
40 | static uint8_t badvpn_read_be8 (const char *c_ptr); |
||
41 | static uint16_t badvpn_read_be16 (const char *c_ptr); |
||
42 | static uint32_t badvpn_read_be32 (const char *c_ptr); |
||
43 | static uint64_t badvpn_read_be64 (const char *c_ptr); |
||
44 | |||
45 | static void badvpn_write_le8 (uint8_t x, char *c_ptr); |
||
46 | static void badvpn_write_le16 (uint16_t x, char *c_ptr); |
||
47 | static void badvpn_write_le32 (uint32_t x, char *c_ptr); |
||
48 | static void badvpn_write_le64 (uint64_t x, char *c_ptr); |
||
49 | |||
50 | static void badvpn_write_be8 (uint8_t x, char *c_ptr); |
||
51 | static void badvpn_write_be16 (uint16_t x, char *c_ptr); |
||
52 | static void badvpn_write_be32 (uint32_t x, char *c_ptr); |
||
53 | static void badvpn_write_be64 (uint64_t x, char *c_ptr); |
||
54 | |||
55 | static uint8_t badvpn_read_le8 (const char *c_ptr) |
||
56 | { |
||
57 | const uint8_t *ptr = (const uint8_t *)c_ptr; |
||
58 | return ((uint8_t)ptr[0] << 0); |
||
59 | } |
||
60 | |||
61 | static uint16_t badvpn_read_le16 (const char *c_ptr) |
||
62 | { |
||
63 | const uint8_t *ptr = (const uint8_t *)c_ptr; |
||
64 | return ((uint16_t)ptr[1] << 8) | ((uint16_t)ptr[0] << 0); |
||
65 | } |
||
66 | |||
67 | static uint32_t badvpn_read_le32 (const char *c_ptr) |
||
68 | { |
||
69 | const uint8_t *ptr = (const uint8_t *)c_ptr; |
||
70 | return ((uint32_t)ptr[3] << 24) | ((uint32_t)ptr[2] << 16) | |
||
71 | ((uint32_t)ptr[1] << 8) | ((uint32_t)ptr[0] << 0); |
||
72 | } |
||
73 | |||
74 | static uint64_t badvpn_read_le64 (const char *c_ptr) |
||
75 | { |
||
76 | const uint8_t *ptr = (const uint8_t *)c_ptr; |
||
77 | return ((uint64_t)ptr[7] << 56) | ((uint64_t)ptr[6] << 48) | |
||
78 | ((uint64_t)ptr[5] << 40) | ((uint64_t)ptr[4] << 32) | |
||
79 | ((uint64_t)ptr[3] << 24) | ((uint64_t)ptr[2] << 16) | |
||
80 | ((uint64_t)ptr[1] << 8) | ((uint64_t)ptr[0] << 0); |
||
81 | } |
||
82 | |||
83 | static uint8_t badvpn_read_be8 (const char *c_ptr) |
||
84 | { |
||
85 | const uint8_t *ptr = (const uint8_t *)c_ptr; |
||
86 | return ((uint8_t)ptr[0] << 0); |
||
87 | } |
||
88 | |||
89 | static uint16_t badvpn_read_be16 (const char *c_ptr) |
||
90 | { |
||
91 | const uint8_t *ptr = (const uint8_t *)c_ptr; |
||
92 | return ((uint16_t)ptr[0] << 8) | ((uint16_t)ptr[1] << 0); |
||
93 | } |
||
94 | |||
95 | static uint32_t badvpn_read_be32 (const char *c_ptr) |
||
96 | { |
||
97 | const uint8_t *ptr = (const uint8_t *)c_ptr; |
||
98 | return ((uint32_t)ptr[0] << 24) | ((uint32_t)ptr[1] << 16) | |
||
99 | ((uint32_t)ptr[2] << 8) | ((uint32_t)ptr[3] << 0); |
||
100 | } |
||
101 | |||
102 | static uint64_t badvpn_read_be64 (const char *c_ptr) |
||
103 | { |
||
104 | const uint8_t *ptr = (const uint8_t *)c_ptr; |
||
105 | return ((uint64_t)ptr[0] << 56) | ((uint64_t)ptr[1] << 48) | |
||
106 | ((uint64_t)ptr[2] << 40) | ((uint64_t)ptr[3] << 32) | |
||
107 | ((uint64_t)ptr[4] << 24) | ((uint64_t)ptr[5] << 16) | |
||
108 | ((uint64_t)ptr[6] << 8) | ((uint64_t)ptr[7] << 0); |
||
109 | } |
||
110 | |||
111 | static void badvpn_write_le8 (uint8_t x, char *c_ptr) |
||
112 | { |
||
113 | uint8_t *ptr = (uint8_t *)c_ptr; |
||
114 | ptr[0] = x >> 0; |
||
115 | } |
||
116 | |||
117 | static void badvpn_write_le16 (uint16_t x, char *c_ptr) |
||
118 | { |
||
119 | uint8_t *ptr = (uint8_t *)c_ptr; |
||
120 | ptr[1] = x >> 8; |
||
121 | ptr[0] = x >> 0; |
||
122 | } |
||
123 | |||
124 | static void badvpn_write_le32 (uint32_t x, char *c_ptr) |
||
125 | { |
||
126 | uint8_t *ptr = (uint8_t *)c_ptr; |
||
127 | ptr[3] = x >> 24; |
||
128 | ptr[2] = x >> 16; |
||
129 | ptr[1] = x >> 8; |
||
130 | ptr[0] = x >> 0; |
||
131 | } |
||
132 | |||
133 | static void badvpn_write_le64 (uint64_t x, char *c_ptr) |
||
134 | { |
||
135 | uint8_t *ptr = (uint8_t *)c_ptr; |
||
136 | ptr[7] = x >> 56; |
||
137 | ptr[6] = x >> 48; |
||
138 | ptr[5] = x >> 40; |
||
139 | ptr[4] = x >> 32; |
||
140 | ptr[3] = x >> 24; |
||
141 | ptr[2] = x >> 16; |
||
142 | ptr[1] = x >> 8; |
||
143 | ptr[0] = x >> 0; |
||
144 | } |
||
145 | |||
146 | static void badvpn_write_be8 (uint8_t x, char *c_ptr) |
||
147 | { |
||
148 | uint8_t *ptr = (uint8_t *)c_ptr; |
||
149 | ptr[0] = x >> 0; |
||
150 | } |
||
151 | |||
152 | static void badvpn_write_be16 (uint16_t x, char *c_ptr) |
||
153 | { |
||
154 | uint8_t *ptr = (uint8_t *)c_ptr; |
||
155 | ptr[0] = x >> 8; |
||
156 | ptr[1] = x >> 0; |
||
157 | } |
||
158 | |||
159 | static void badvpn_write_be32 (uint32_t x, char *c_ptr) |
||
160 | { |
||
161 | uint8_t *ptr = (uint8_t *)c_ptr; |
||
162 | ptr[0] = x >> 24; |
||
163 | ptr[1] = x >> 16; |
||
164 | ptr[2] = x >> 8; |
||
165 | ptr[3] = x >> 0; |
||
166 | } |
||
167 | |||
168 | static void badvpn_write_be64 (uint64_t x, char *c_ptr) |
||
169 | { |
||
170 | uint8_t *ptr = (uint8_t *)c_ptr; |
||
171 | ptr[0] = x >> 56; |
||
172 | ptr[1] = x >> 48; |
||
173 | ptr[2] = x >> 40; |
||
174 | ptr[3] = x >> 32; |
||
175 | ptr[4] = x >> 24; |
||
176 | ptr[5] = x >> 16; |
||
177 | ptr[6] = x >> 8; |
||
178 | ptr[7] = x >> 0; |
||
179 | } |
||
180 | |||
181 | #endif |