From 4297ba431019a9cc73b8bcf2161817b93062a0dc Mon Sep 17 00:00:00 2001 From: Chris Eagle Date: Thu, 24 Sep 2015 09:41:49 -0700 Subject: [PATCH] additional update to handle new hooking macros --- bindings/java/unicorn/MemHook.java | 27 +++++++++++++++++++ bindings/java/unicorn/Unicorn.java | 42 ++++++++++++++++++++++-------- 2 files changed, 58 insertions(+), 11 deletions(-) create mode 100755 bindings/java/unicorn/MemHook.java mode change 100644 => 100755 bindings/java/unicorn/Unicorn.java diff --git a/bindings/java/unicorn/MemHook.java b/bindings/java/unicorn/MemHook.java new file mode 100755 index 00000000..9f1a1889 --- /dev/null +++ b/bindings/java/unicorn/MemHook.java @@ -0,0 +1,27 @@ +/* + +Java bindings for the Unicorn Emulator Engine + +Copyright(c) 2015 Chris Eagle + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +version 2 as published by the Free Software Foundation. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +*/ + +package unicorn; + +public interface MemHook extends ReadHook,WriteHook { + +} + diff --git a/bindings/java/unicorn/Unicorn.java b/bindings/java/unicorn/Unicorn.java old mode 100644 new mode 100755 index c9ed1436..9abfeb60 --- a/bindings/java/unicorn/Unicorn.java +++ b/bindings/java/unicorn/Unicorn.java @@ -519,6 +519,21 @@ public class Unicorn implements UnicornConst, ArmConst, Arm64Const, M68kConst, S writeList.add(new Tuple(callback, user_data)); } +/** + * Hook registration for UC_HOOK_MEM_WRITE | UC_HOOK_MEM_WRITE hooks. The registered callback function will be + * invoked whenever a memory write or read is performed within the address range begin <= addr <= end. For + * the special case in which begin > end, the callback will be invoked for ALL memory writes. + * + * @param callback Implementation of a MemHook interface + * @param begin Start address of memory range + * @param end End address of memory range + * @param user_data User data to be passed to the callback function each time the event is triggered + */ + public void hook_add(MemHook callback, long begin, long end, Object user_data) throws UnicornException { + hook_add((ReadHook)callback, begin, end, user_data); + hook_add((WriteHook)callback, begin, end, user_data); + } + /** * Hook registration for UC_HOOK_MEM_XXX_INVALID and UC_HOOK_MEM_XXX_PROT hooks. * The registered callback function will be invoked whenever a read or write is @@ -529,18 +544,23 @@ public class Unicorn implements UnicornConst, ArmConst, Arm64Const, M68kConst, S * @param user_data User data to be passed to the callback function each time the event is triggered */ public void hook_add(EventMemHook callback, int type, Object user_data) throws UnicornException { - Long handle = eventMemHandles.get(type); - if (handle == null) { - eventMemHandles.put(type, registerHook(eng, type)); + //test all of the EventMem related bits in type + for (Integer htype : eventMemMap.keySet()) { + if ((type & htype) != 0) { //the 'htype' bit is set in type + Long handle = eventMemHandles.get(htype); + if (handle == null) { + eventMemHandles.put(htype, registerHook(eng, htype)); + } + int cbType = eventMemMap.get(htype); + ArrayList flist = eventMemLists.get(cbType); + if (flist == null) { + flist = new ArrayList(); + allLists.add(flist); + eventMemLists.put(cbType, flist); + } + flist.add(new Tuple(callback, user_data)); + } } - int cbType = eventMemMap.get(type); - ArrayList flist = eventMemLists.get(cbType); - if (flist == null) { - flist = new ArrayList(); - allLists.add(flist); - eventMemLists.put(cbType, flist); - } - flist.add(new Tuple(callback, user_data)); } /**