diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2010-06-20 20:47:17 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2010-06-20 20:47:17 (GMT) |
commit | dad83b556250a85a9b2ccf68e5fb6f4df7dca1f4 (patch) | |
tree | 81f90d9966d712d006aa639d90874627ccd6970b /src/common | |
parent | 0d7908e0c8282050ebbcc8a7c18fafd13152a36e (diff) |
Supported more Dalvik opcodes.
git-svn-id: svn://svn.gna.org/svn/chrysalide/trunk@169 abbe820e-26c8-41b2-8c08-b7b2b41f8b0a
Diffstat (limited to 'src/common')
-rwxr-xr-x | src/common/endianness.c | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/src/common/endianness.c b/src/common/endianness.c index 3a2a653..5a14e1c 100755 --- a/src/common/endianness.c +++ b/src/common/endianness.c @@ -257,7 +257,64 @@ bool read_u32(uint32_t *target, const bin_t *data, off_t *pos, off_t len, Source bool read_u64(uint64_t *target, const bin_t *data, off_t *pos, off_t len, SourceEndian endian) { + if (*pos < 0) return false; + if ((len - *pos) < 8) return false; + + switch (endian) + { + case SRE_LITTLE: + +#if __BYTE_ORDER == __LITTLE_ENDIAN + + *target = (uint64_t)data[*pos] | (uint64_t)data[*pos + 1] << 8; + *target |= (uint64_t)data[*pos + 2] << 16 | (uint64_t)data[*pos + 3] << 24; + *target |= (uint64_t)data[*pos + 4] << 32 | (uint64_t)data[*pos + 5] << 40; + *target |= (uint64_t)data[*pos + 6] << 48 | (uint64_t)data[*pos + 7] << 56; + +#elif __BYTE_ORDER == __BIG_ENDIAN + + *target = (uint64_t)data[*pos + 7] | (uint64_t)data[*pos + 6] << 8; + *target |= (uint64_t)data[*pos + 5] << 16 | (uint64_t)data[*pos + 4] << 24; + *target |= (uint64_t)data[*pos + 3] << 32 | (uint64_t)data[*pos + 2] << 40; + *target |= (uint64_t)data[*pos + 1] << 48 | (uint64_t)data[*pos] << 56; + +#else + +# error "TODO : PDP !" + +#endif + + break; + + case SRE_BIG: + +#if __BYTE_ORDER == __LITTLE_ENDIAN + + *target = (uint64_t)data[*pos + 7] | (uint64_t)data[*pos + 6] << 8; + *target |= (uint64_t)data[*pos + 5] << 16 | (uint64_t)data[*pos + 4] << 24; + *target |= (uint64_t)data[*pos + 3] << 32 | (uint64_t)data[*pos + 2] << 40; + *target |= (uint64_t)data[*pos + 1] << 48 | (uint64_t)data[*pos] << 56; + +#elif __BYTE_ORDER == __BIG_ENDIAN + + *target = (uint64_t)data[*pos] | (uint64_t)data[*pos + 1] << 8; + *target |= (uint64_t)data[*pos + 2] << 16 | (uint64_t)data[*pos + 3] << 24; + *target |= (uint64_t)data[*pos + 4] << 32 | (uint64_t)data[*pos + 5] << 40; + *target |= (uint64_t)data[*pos + 6] << 48 | (uint64_t)data[*pos + 7] << 56; + +#else + +# error "TODO : PDP !" + +#endif + + break; - return false; + + } + + *pos += 8; + + return true; } |