Mercurial > vba-linux
diff src/win32/7zip/7z/C/Bra.c @ 1:f9f4f1b99eed
importing src directory
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Sat, 03 Mar 2012 10:31:27 -0600 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/win32/7zip/7z/C/Bra.c Sat Mar 03 10:31:27 2012 -0600 1.3 @@ -0,0 +1,133 @@ 1.4 +/* Bra.c -- Converters for RISC code 1.5 +2008-10-04 : Igor Pavlov : Public domain */ 1.6 + 1.7 +#include "Bra.h" 1.8 + 1.9 +SizeT ARM_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) 1.10 +{ 1.11 + SizeT i; 1.12 + if (size < 4) 1.13 + return 0; 1.14 + size -= 4; 1.15 + ip += 8; 1.16 + for (i = 0; i <= size; i += 4) 1.17 + { 1.18 + if (data[i + 3] == 0xEB) 1.19 + { 1.20 + UInt32 dest; 1.21 + UInt32 src = ((UInt32)data[i + 2] << 16) | ((UInt32)data[i + 1] << 8) | (data[i + 0]); 1.22 + src <<= 2; 1.23 + if (encoding) 1.24 + dest = ip + (UInt32)i + src; 1.25 + else 1.26 + dest = src - (ip + (UInt32)i); 1.27 + dest >>= 2; 1.28 + data[i + 2] = (Byte)(dest >> 16); 1.29 + data[i + 1] = (Byte)(dest >> 8); 1.30 + data[i + 0] = (Byte)dest; 1.31 + } 1.32 + } 1.33 + return i; 1.34 +} 1.35 + 1.36 +SizeT ARMT_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) 1.37 +{ 1.38 + SizeT i; 1.39 + if (size < 4) 1.40 + return 0; 1.41 + size -= 4; 1.42 + ip += 4; 1.43 + for (i = 0; i <= size; i += 2) 1.44 + { 1.45 + if ((data[i + 1] & 0xF8) == 0xF0 && 1.46 + (data[i + 3] & 0xF8) == 0xF8) 1.47 + { 1.48 + UInt32 dest; 1.49 + UInt32 src = 1.50 + (((UInt32)data[i + 1] & 0x7) << 19) | 1.51 + ((UInt32)data[i + 0] << 11) | 1.52 + (((UInt32)data[i + 3] & 0x7) << 8) | 1.53 + (data[i + 2]); 1.54 + 1.55 + src <<= 1; 1.56 + if (encoding) 1.57 + dest = ip + (UInt32)i + src; 1.58 + else 1.59 + dest = src - (ip + (UInt32)i); 1.60 + dest >>= 1; 1.61 + 1.62 + data[i + 1] = (Byte)(0xF0 | ((dest >> 19) & 0x7)); 1.63 + data[i + 0] = (Byte)(dest >> 11); 1.64 + data[i + 3] = (Byte)(0xF8 | ((dest >> 8) & 0x7)); 1.65 + data[i + 2] = (Byte)dest; 1.66 + i += 2; 1.67 + } 1.68 + } 1.69 + return i; 1.70 +} 1.71 + 1.72 +SizeT PPC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) 1.73 +{ 1.74 + SizeT i; 1.75 + if (size < 4) 1.76 + return 0; 1.77 + size -= 4; 1.78 + for (i = 0; i <= size; i += 4) 1.79 + { 1.80 + if ((data[i] >> 2) == 0x12 && (data[i + 3] & 3) == 1) 1.81 + { 1.82 + UInt32 src = ((UInt32)(data[i + 0] & 3) << 24) | 1.83 + ((UInt32)data[i + 1] << 16) | 1.84 + ((UInt32)data[i + 2] << 8) | 1.85 + ((UInt32)data[i + 3] & (~3)); 1.86 + 1.87 + UInt32 dest; 1.88 + if (encoding) 1.89 + dest = ip + (UInt32)i + src; 1.90 + else 1.91 + dest = src - (ip + (UInt32)i); 1.92 + data[i + 0] = (Byte)(0x48 | ((dest >> 24) & 0x3)); 1.93 + data[i + 1] = (Byte)(dest >> 16); 1.94 + data[i + 2] = (Byte)(dest >> 8); 1.95 + data[i + 3] &= 0x3; 1.96 + data[i + 3] |= dest; 1.97 + } 1.98 + } 1.99 + return i; 1.100 +} 1.101 + 1.102 +SizeT SPARC_Convert(Byte *data, SizeT size, UInt32 ip, int encoding) 1.103 +{ 1.104 + UInt32 i; 1.105 + if (size < 4) 1.106 + return 0; 1.107 + size -= 4; 1.108 + for (i = 0; i <= size; i += 4) 1.109 + { 1.110 + if (data[i] == 0x40 && (data[i + 1] & 0xC0) == 0x00 || 1.111 + data[i] == 0x7F && (data[i + 1] & 0xC0) == 0xC0) 1.112 + { 1.113 + UInt32 src = 1.114 + ((UInt32)data[i + 0] << 24) | 1.115 + ((UInt32)data[i + 1] << 16) | 1.116 + ((UInt32)data[i + 2] << 8) | 1.117 + ((UInt32)data[i + 3]); 1.118 + UInt32 dest; 1.119 + 1.120 + src <<= 2; 1.121 + if (encoding) 1.122 + dest = ip + i + src; 1.123 + else 1.124 + dest = src - (ip + i); 1.125 + dest >>= 2; 1.126 + 1.127 + dest = (((0 - ((dest >> 22) & 1)) << 22) & 0x3FFFFFFF) | (dest & 0x3FFFFF) | 0x40000000; 1.128 + 1.129 + data[i + 0] = (Byte)(dest >> 24); 1.130 + data[i + 1] = (Byte)(dest >> 16); 1.131 + data[i + 2] = (Byte)(dest >> 8); 1.132 + data[i + 3] = (Byte)dest; 1.133 + } 1.134 + } 1.135 + return i; 1.136 +}