| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
#include <common.h> |
| 23 |
#include <types.h> |
| 24 |
|
| 25 |
#include "libuna_codepage_mac_dingbats.h" |
| 26 |
#include "libuna_libcerror.h" |
| 27 |
#include "libuna_types.h" |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
const uint16_t libuna_codepage_mac_dingbats_byte_stream_to_unicode_base_0x20[ 224 ] = { |
| 33 |
0x0020, 0x2701, 0x2702, 0x2703, 0x2704, 0x260e, 0x2706, 0x2707, |
| 34 |
0x2708, 0x2709, 0x261b, 0x261e, 0x270c, 0x270d, 0x270e, 0x270f, |
| 35 |
0x2710, 0x2711, 0x2712, 0x2713, 0x2714, 0x2715, 0x2716, 0x2717, |
| 36 |
0x2718, 0x2719, 0x271a, 0x271b, 0x271c, 0x271d, 0x271e, 0x271f, |
| 37 |
0x2720, 0x2721, 0x2722, 0x2723, 0x2724, 0x2725, 0x2726, 0x2727, |
| 38 |
0x2605, 0x2729, 0x272a, 0x272b, 0x272c, 0x272d, 0x272e, 0x272f, |
| 39 |
0x2730, 0x2731, 0x2732, 0x2733, 0x2734, 0x2735, 0x2736, 0x2737, |
| 40 |
0x2738, 0x2739, 0x273a, 0x273b, 0x273c, 0x273d, 0x273e, 0x273f, |
| 41 |
0x2740, 0x2741, 0x2742, 0x2743, 0x2744, 0x2745, 0x2746, 0x2747, |
| 42 |
0x2748, 0x2749, 0x274a, 0x274b, 0x25cf, 0x274d, 0x25a0, 0x274f, |
| 43 |
0x2750, 0x2751, 0x2752, 0x25b2, 0x25bc, 0x25c6, 0x2756, 0x25d7, |
| 44 |
0x2758, 0x2759, 0x275a, 0x275b, 0x275c, 0x275d, 0x275e, 0x007f, |
| 45 |
0x2768, 0x2769, 0x276a, 0x276b, 0x276c, 0x276d, 0x276e, 0x276f, |
| 46 |
0x2770, 0x2771, 0x2772, 0x2773, 0x2774, 0x2775, 0xfffd, 0xfffd, |
| 47 |
0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, |
| 48 |
0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, 0xfffd, |
| 49 |
0xfffd, 0x2761, 0x2762, 0x2763, 0x2764, 0x2765, 0x2766, 0x2767, |
| 50 |
0x2663, 0x2666, 0x2665, 0x2660, 0x2460, 0x2461, 0x2462, 0x2463, |
| 51 |
0x2464, 0x2465, 0x2466, 0x2467, 0x2468, 0x2469, 0x2776, 0x2777, |
| 52 |
0x2778, 0x2779, 0x277a, 0x277b, 0x277c, 0x277d, 0x277e, 0x277f, |
| 53 |
0x2780, 0x2781, 0x2782, 0x2783, 0x2784, 0x2785, 0x2786, 0x2787, |
| 54 |
0x2788, 0x2789, 0x278a, 0x278b, 0x278c, 0x278d, 0x278e, 0x278f, |
| 55 |
0x2790, 0x2791, 0x2792, 0x2793, 0x2794, 0x2192, 0x2194, 0x2195, |
| 56 |
0x2798, 0x2799, 0x279a, 0x279b, 0x279c, 0x279d, 0x279e, 0x279f, |
| 57 |
0x27a0, 0x27a1, 0x27a2, 0x27a3, 0x27a4, 0x27a5, 0x27a6, 0x27a7, |
| 58 |
0x27a8, 0x27a9, 0x27aa, 0x27ab, 0x27ac, 0x27ad, 0x27ae, 0x27af, |
| 59 |
0xfffd, 0x27b1, 0x27b2, 0x27b3, 0x27b4, 0x27b5, 0x27b6, 0x27b7, |
| 60 |
0x27b8, 0x27b9, 0x27ba, 0x27bb, 0x27bc, 0x27bd, 0x27be, 0xfffd |
| 61 |
}; |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
const uint8_t libuna_codepage_mac_dingbats_unicode_to_byte_stream_base_0x2460[ 16 ] = { |
| 67 |
0xac, 0xad, 0xae, 0xaf, 0xb0, 0xb1, 0xb2, 0xb3, |
| 68 |
0xb4, 0xb5, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a, 0x1a |
| 69 |
}; |
| 70 |
|
| 71 |
const uint8_t libuna_codepage_mac_dingbats_unicode_to_byte_stream_base_0x2700[ 192 ] = { |
| 72 |
0x1a, 0x21, 0x22, 0x23, 0x24, 0x1a, 0x26, 0x27, |
| 73 |
0x28, 0x29, 0x1a, 0x1a, 0x2c, 0x2d, 0x2e, 0x2f, |
| 74 |
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, |
| 75 |
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, |
| 76 |
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, |
| 77 |
0x1a, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, |
| 78 |
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, |
| 79 |
0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, |
| 80 |
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, |
| 81 |
0x68, 0x69, 0x6a, 0x6b, 0x1a, 0x6d, 0x1a, 0x6f, |
| 82 |
0x70, 0x71, 0x72, 0x1a, 0x1a, 0x1a, 0x76, 0x1a, |
| 83 |
0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x1a, |
| 84 |
0x1a, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, |
| 85 |
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, |
| 86 |
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0xb6, 0xb7, |
| 87 |
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, |
| 88 |
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, |
| 89 |
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, |
| 90 |
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0x1a, 0x1a, 0x1a, |
| 91 |
0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, |
| 92 |
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, |
| 93 |
0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, |
| 94 |
0x1a, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, |
| 95 |
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0x1a |
| 96 |
}; |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
int libuna_codepage_mac_dingbats_copy_from_byte_stream( |
| 102 |
libuna_unicode_character_t *unicode_character, |
| 103 |
const uint8_t *byte_stream, |
| 104 |
size_t byte_stream_size, |
| 105 |
size_t *byte_stream_index, |
| 106 |
libcerror_error_t **error ) |
| 107 |
{ |
| 108 |
static char *function = "libuna_codepage_mac_dingbats_copy_from_byte_stream"; |
| 109 |
libuna_unicode_character_t safe_unicode_character = 0xfffd; |
| 110 |
size_t safe_byte_stream_index = 0; |
| 111 |
uint8_t byte_stream_character = 0; |
| 112 |
|
| 113 |
if( unicode_character == NULL ) |
| 114 |
{ |
| 115 |
libcerror_error_set( |
| 116 |
error, |
| 117 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 118 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 119 |
"%s: invalid Unicode character.", |
| 120 |
function ); |
| 121 |
|
| 122 |
return( -1 ); |
| 123 |
} |
| 124 |
if( byte_stream == NULL ) |
| 125 |
{ |
| 126 |
libcerror_error_set( |
| 127 |
error, |
| 128 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 129 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 130 |
"%s: invalid byte stream.", |
| 131 |
function ); |
| 132 |
|
| 133 |
return( -1 ); |
| 134 |
} |
| 135 |
if( byte_stream_size > (size_t) SSIZE_MAX ) |
| 136 |
{ |
| 137 |
libcerror_error_set( |
| 138 |
error, |
| 139 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 140 |
LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
| 141 |
"%s: invalid byte stream size value exceeds maximum.", |
| 142 |
function ); |
| 143 |
|
| 144 |
return( -1 ); |
| 145 |
} |
| 146 |
if( byte_stream_index == NULL ) |
| 147 |
{ |
| 148 |
libcerror_error_set( |
| 149 |
error, |
| 150 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 151 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 152 |
"%s: invalid byte stream index.", |
| 153 |
function ); |
| 154 |
|
| 155 |
return( -1 ); |
| 156 |
} |
| 157 |
safe_byte_stream_index = *byte_stream_index; |
| 158 |
|
| 159 |
if( safe_byte_stream_index >= byte_stream_size ) |
| 160 |
{ |
| 161 |
libcerror_error_set( |
| 162 |
error, |
| 163 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 164 |
LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, |
| 165 |
"%s: byte stream too small.", |
| 166 |
function ); |
| 167 |
|
| 168 |
return( -1 ); |
| 169 |
} |
| 170 |
byte_stream_character = byte_stream[ safe_byte_stream_index++ ]; |
| 171 |
|
| 172 |
if( byte_stream_character < 0x20 ) |
| 173 |
{ |
| 174 |
safe_unicode_character = byte_stream_character; |
| 175 |
} |
| 176 |
else |
| 177 |
{ |
| 178 |
byte_stream_character -= 0x20; |
| 179 |
|
| 180 |
safe_unicode_character = libuna_codepage_mac_dingbats_byte_stream_to_unicode_base_0x20[ byte_stream_character ]; |
| 181 |
} |
| 182 |
*unicode_character = safe_unicode_character; |
| 183 |
*byte_stream_index = safe_byte_stream_index; |
| 184 |
|
| 185 |
return( 1 ); |
| 186 |
} |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
int libuna_codepage_mac_dingbats_copy_to_byte_stream( |
| 192 |
libuna_unicode_character_t unicode_character, |
| 193 |
uint8_t *byte_stream, |
| 194 |
size_t byte_stream_size, |
| 195 |
size_t *byte_stream_index, |
| 196 |
libcerror_error_t **error ) |
| 197 |
{ |
| 198 |
static char *function = "libuna_codepage_mac_dingbats_copy_to_byte_stream"; |
| 199 |
size_t safe_byte_stream_index = 0; |
| 200 |
uint16_t byte_stream_value = 0x001a; |
| 201 |
|
| 202 |
if( byte_stream == NULL ) |
| 203 |
{ |
| 204 |
libcerror_error_set( |
| 205 |
error, |
| 206 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 207 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 208 |
"%s: invalid byte stream.", |
| 209 |
function ); |
| 210 |
|
| 211 |
return( -1 ); |
| 212 |
} |
| 213 |
if( byte_stream_size > (size_t) SSIZE_MAX ) |
| 214 |
{ |
| 215 |
libcerror_error_set( |
| 216 |
error, |
| 217 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 218 |
LIBCERROR_ARGUMENT_ERROR_VALUE_EXCEEDS_MAXIMUM, |
| 219 |
"%s: invalid byte stream size value exceeds maximum.", |
| 220 |
function ); |
| 221 |
|
| 222 |
return( -1 ); |
| 223 |
} |
| 224 |
if( byte_stream_index == NULL ) |
| 225 |
{ |
| 226 |
libcerror_error_set( |
| 227 |
error, |
| 228 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 229 |
LIBCERROR_ARGUMENT_ERROR_INVALID_VALUE, |
| 230 |
"%s: invalid byte stream index.", |
| 231 |
function ); |
| 232 |
|
| 233 |
return( -1 ); |
| 234 |
} |
| 235 |
safe_byte_stream_index = *byte_stream_index; |
| 236 |
|
| 237 |
if( safe_byte_stream_index >= byte_stream_size ) |
| 238 |
{ |
| 239 |
libcerror_error_set( |
| 240 |
error, |
| 241 |
LIBCERROR_ERROR_DOMAIN_ARGUMENTS, |
| 242 |
LIBCERROR_ARGUMENT_ERROR_VALUE_TOO_SMALL, |
| 243 |
"%s: byte stream too small.", |
| 244 |
function ); |
| 245 |
|
| 246 |
return( -1 ); |
| 247 |
} |
| 248 |
if( ( unicode_character <= 0x0020 ) |
| 249 |
|| ( unicode_character == 0x007f ) ) |
| 250 |
{ |
| 251 |
byte_stream_value = (uint16_t) unicode_character; |
| 252 |
} |
| 253 |
else if( ( unicode_character >= 0x2460 ) |
| 254 |
&& ( unicode_character < 0x2470 ) ) |
| 255 |
{ |
| 256 |
unicode_character -= 0x2460; |
| 257 |
|
| 258 |
byte_stream_value = libuna_codepage_mac_dingbats_unicode_to_byte_stream_base_0x2460[ unicode_character ]; |
| 259 |
} |
| 260 |
else if( ( unicode_character >= 0x2700 ) |
| 261 |
&& ( unicode_character < 0x27c0 ) ) |
| 262 |
{ |
| 263 |
unicode_character -= 0x2700; |
| 264 |
|
| 265 |
byte_stream_value = libuna_codepage_mac_dingbats_unicode_to_byte_stream_base_0x2700[ unicode_character ]; |
| 266 |
} |
| 267 |
else switch( unicode_character ) |
| 268 |
{ |
| 269 |
case 0x2192: |
| 270 |
byte_stream_value = 0xd5; |
| 271 |
break; |
| 272 |
|
| 273 |
case 0x2194: |
| 274 |
byte_stream_value = 0xd6; |
| 275 |
break; |
| 276 |
|
| 277 |
case 0x2195: |
| 278 |
byte_stream_value = 0xd7; |
| 279 |
break; |
| 280 |
|
| 281 |
case 0x25a0: |
| 282 |
byte_stream_value = 0x6e; |
| 283 |
break; |
| 284 |
|
| 285 |
case 0x25b2: |
| 286 |
byte_stream_value = 0x73; |
| 287 |
break; |
| 288 |
|
| 289 |
case 0x25bc: |
| 290 |
byte_stream_value = 0x74; |
| 291 |
break; |
| 292 |
|
| 293 |
case 0x25c6: |
| 294 |
byte_stream_value = 0x75; |
| 295 |
break; |
| 296 |
|
| 297 |
case 0x25cf: |
| 298 |
byte_stream_value = 0x6c; |
| 299 |
break; |
| 300 |
|
| 301 |
case 0x25d7: |
| 302 |
byte_stream_value = 0x77; |
| 303 |
break; |
| 304 |
|
| 305 |
case 0x2605: |
| 306 |
byte_stream_value = 0x48; |
| 307 |
break; |
| 308 |
|
| 309 |
case 0x260e: |
| 310 |
byte_stream_value = 0x25; |
| 311 |
break; |
| 312 |
|
| 313 |
case 0x261b: |
| 314 |
byte_stream_value = 0x2a; |
| 315 |
break; |
| 316 |
|
| 317 |
case 0x261e: |
| 318 |
byte_stream_value = 0x2b; |
| 319 |
break; |
| 320 |
|
| 321 |
case 0x2660: |
| 322 |
byte_stream_value = 0xab; |
| 323 |
break; |
| 324 |
|
| 325 |
case 0x2663: |
| 326 |
byte_stream_value = 0xa8; |
| 327 |
break; |
| 328 |
|
| 329 |
case 0x2665: |
| 330 |
byte_stream_value = 0xaa; |
| 331 |
break; |
| 332 |
|
| 333 |
case 0x2666: |
| 334 |
byte_stream_value = 0xa9; |
| 335 |
break; |
| 336 |
|
| 337 |
default: |
| 338 |
byte_stream_value = 0x1a; |
| 339 |
break; |
| 340 |
} |
| 341 |
byte_stream[ safe_byte_stream_index++ ] = (uint8_t) ( byte_stream_value & 0x00ff ); |
| 342 |
|
| 343 |
*byte_stream_index = safe_byte_stream_index; |
| 344 |
|
| 345 |
return( 1 ); |
| 346 |
} |
| 347 |
|