Skip to content

Commit

Permalink
Bug fix to check the this CpuContext before using it
Browse files Browse the repository at this point in the history
  • Loading branch information
chame1eon committed Jul 30, 2019
1 parent 6f2c27d commit 2029441
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# jnitrace Change Log

## 1.3.3
- Bug fix - Checked whether the this context exists before using it

## 1.3.2
- Bug fix - Use Process.findRangeByAddress instead of Process.findModuleByAddress for checking the validity of the stack pointer

Expand Down
8 changes: 6 additions & 2 deletions jnitrace/src/jni/jni_env_interceptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,13 @@ JNIEnvInterceptor.prototype.createJNIIntercept = function(id, methodAddr) {

var nativeFunction = new NativeFunction(methodAddr, fridaRet, fridaArgs);
var nativeCallback = new NativeCallback(function() {
var threadId = this.threadId;
var threadId = Process.getCurrentThreadId();
var localArgs = [].slice.call(arguments);
var jniEnv = self.threads.getJNIEnv(threadId);
var context = null;
if (this) {
context = this.context;
}

localArgs[0] = jniEnv;

Expand All @@ -62,7 +66,7 @@ JNIEnvInterceptor.prototype.createJNIIntercept = function(id, methodAddr) {
}
}

self.transport.trace(method, localArgs, ret, this.context, add);
self.transport.trace(method, localArgs, ret, context, add);

if (method.name === "GetMethodID" ||
method.name === "GetStaticMethodID") {
Expand Down
2 changes: 1 addition & 1 deletion jnitrace/src/transport/trace_transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ TraceTransport.prototype.trace = function(method, args, ret, context, add) {

// verify that a backtrace is possible.
// sometimes the NativeCallback provides erroneous CpuContexts
if (Process.findModuleByAddress(context.pc) &&
if (context && Process.findModuleByAddress(context.pc) &&
Process.findRangeByAddress(context.sp)) {
var bt = Thread.backtrace(context, Backtracer.FUZZY);

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setup(
name='jnitrace',
version='1.3.2',
version='1.3.3',
description='A tool for tracing use of the JNI in Android apps',
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down

0 comments on commit 2029441

Please sign in to comment.