summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2010-06-20 20:47:17 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2010-06-20 20:47:17 (GMT)
commitdad83b556250a85a9b2ccf68e5fb6f4df7dca1f4 (patch)
tree81f90d9966d712d006aa639d90874627ccd6970b /src/common
parent0d7908e0c8282050ebbcc8a7c18fafd13152a36e (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-xsrc/common/endianness.c59
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;
}