From fe39a487b4db5564036a436bfcb7cf3561889fb5 Mon Sep 17 00:00:00 2001
From: Cyrille Bagard <nocbos@gmail.com>
Date: Sun, 11 Sep 2016 20:31:34 +0200
Subject: Fixed a bug when decoding some catch-all handlers in Dex code item.

---
 ChangeLog                | 5 +++++
 src/format/dex/dex-int.c | 8 +++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index f381224..fc0f6cd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 16-09-11  Cyrille Bagard <nocbos@gmail.com>
 
+	* src/format/dex/dex-int.c:
+	Fix a bug when decoding some catch-all handlers in Dex code item.
+
+16-09-11  Cyrille Bagard <nocbos@gmail.com>
+
 	* plugins/androhelpers/try_n_catch.c:
 	* plugins/readdex/class.c:
 	Update code.
diff --git a/src/format/dex/dex-int.c b/src/format/dex/dex-int.c
index 79cdc57..b746f4d 100644
--- a/src/format/dex/dex-int.c
+++ b/src/format/dex/dex-int.c
@@ -24,6 +24,7 @@
 #include "dex-int.h"
 
 
+#include <assert.h>
 #include <malloc.h>
 
 
@@ -634,7 +635,7 @@ bool read_dex_encoded_catch_handler(const GDexFormat *format, vmpa2t *pos, encod
     }
     else handler->handlers = NULL;
 
-    if (handler->size < 0)
+    if (handler->size <= 0)
         result &= g_binary_content_read_uleb128(content, pos, &handler->catch_all_addr);
 
     else
@@ -808,10 +809,15 @@ bool read_dex_code_item(const GDexFormat *format, vmpa2t *pos, code_item *item)
 
     /* Padding ? */
     if (item->tries_size > 0 && item->insns_size % 2 == 1)
+    {
         result &= g_binary_content_read_u16(content, pos, SRE_LITTLE, &padding);
+        assert(padding == 0);
+    }
 
     if (item->tries_size > 0 && result)
     {
+        assert(get_phy_addr(pos) % 4 == 0);
+
         item->tries = (try_item *)calloc(item->tries_size, sizeof(try_item));
 
         for (i = 0; i < item->tries_size && result; i++)
-- 
cgit v0.11.2-87-g4458