diff --git a/bindings/java/unicorn/Unicorn.java b/bindings/java/unicorn/Unicorn.java index 985a322d..9117a65f 100644 --- a/bindings/java/unicorn/Unicorn.java +++ b/bindings/java/unicorn/Unicorn.java @@ -25,12 +25,6 @@ import java.util.*; public class Unicorn implements UnicornConst, ArmConst, Arm64Const, M68kConst, SparcConst, MipsConst, X86Const { - // Scales to calculate timeout on microsecond unit - // 1 second = 1000,000 microseconds - public static final int UC_SECOND_SCALE = 1000000; - // 1 milisecond = 1000 nanoseconds - public static final int UC_MILISECOND_SCALE = 1000; - private long blockHandle = 0; private long interruptHandle = 0; private long codeHandle = 0; @@ -622,8 +616,26 @@ public class Unicorn implements UnicornConst, ArmConst, Arm64Const, M68kConst, S * * @param address Base address of the memory range * @param size Size of the memory block. + * @param perms Permissions on the memory block. A combination of UC_PROT_READ, UC_PROT_WRITE, UC_PROT_EXEC */ public native void mem_map(long address, long size, int perms) throws UnicornException; +/** + * Unmap a range of memory. + * + * @param address Base address of the memory range + * @param size Size of the memory block. + */ + public native void mem_unmap(long address, long size) throws UnicornException; + +/** + * Change permissions on a range of memory. + * + * @param address Base address of the memory range + * @param size Size of the memory block. + * @param perms New permissions on the memory block. A combination of UC_PROT_READ, UC_PROT_WRITE, UC_PROT_EXEC + */ + public native void mem_protect(long address, long size, int perms) throws UnicornException; + } diff --git a/bindings/java/unicorn_Unicorn.c b/bindings/java/unicorn_Unicorn.c index cd0428f9..8f06af08 100644 --- a/bindings/java/unicorn_Unicorn.c +++ b/bindings/java/unicorn_Unicorn.c @@ -513,3 +513,33 @@ JNIEXPORT void JNICALL Java_unicorn_Unicorn_mem_1map throwException(env, err); } } + +/* + * Class: unicorn_Unicorn + * Method: mem_unmap + * Signature: (JJ)V + */ +JNIEXPORT void JNICALL Java_unicorn_Unicorn_mem_1unmap + (JNIEnv *env, jobject self, jlong address, jlong size) { + uch handle = getHandle(env, self); + + uc_err err = uc_mem_unmap(handle, (uint64_t)address, (size_t)size); + if (err != UC_ERR_OK) { + throwException(env, err); + } +} + +/* + * Class: unicorn_Unicorn + * Method: mem_protect + * Signature: (JJI)V + */ +JNIEXPORT void JNICALL Java_unicorn_Unicorn_mem_1protect + (JNIEnv *env, jobject self, jlong address, jlong size, jint perms) { + uch handle = getHandle(env, self); + + uc_err err = uc_mem_protect(handle, (uint64_t)address, (size_t)size, (uint32_t)perms); + if (err != UC_ERR_OK) { + throwException(env, err); + } +}