Skip to content

Commit

Permalink
bug fixes and format fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
chame1eon committed Aug 30, 2019
1 parent fab4051 commit 8488bfc
Show file tree
Hide file tree
Showing 9 changed files with 579 additions and 560 deletions.
18 changes: 18 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"presets": [
[
"@babel/preset-env",
{
"loose": true
}
]
],
"plugins": [
[
"@babel/plugin-transform-runtime",
{
"corejs": 2
}
]
]
}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# jnitrace Change Log

## 2.2.1
- Sorted the alignment of the backtraces so they are right justified
- Fixed a bug when tracing Release<ArrayType>Elements where all types were assumed to be the size of a pointer
- Upgraded eslint-package to patch security vulnerability
- Stopped trying to kill Frida session if it was already dead

## 2.2.0
- Changed backtrace output to include debug symbols, where possible

Expand Down
41 changes: 26 additions & 15 deletions jnitrace/jnitrace.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __init__(self, _config, _buffer_output):
self._is_64b = False

def _print_thread_id(self, thread_id):
print("{}{:15s}/* TID {:d} */{}".format(
print("{}{:16s}/* TID {:d} */{}".format(
Fore.WHITE,
self._color_manager.get_current_color(),
thread_id,
Expand Down Expand Up @@ -279,8 +279,8 @@ def _calculate_backtrace_lengths(self, backtrace):

if b_t_len > max_len:
max_len = b_t_len
if len(b_t["symbol"]["name"]) > max_name:
max_name = len(b_t["symbol"]["name"])
if len(symbol_name) > max_name:
max_name = len(symbol_name)

return max_len, max_name, size

Expand Down Expand Up @@ -488,6 +488,24 @@ def _parse_args():

return args

def _finish(args, device, pid, scripts):
print('Stopping application (name={}, pid={})...'.format(
args.target,
pid
), end="")
try:
if args.append:
scripts["append"].unload()
scripts["script"].unload()
if args.prepend:
scripts["prepend"].unload()

device.kill(pid)
except frida.InvalidOperationError:
pass
finally:
print("stopped.")

def main():
"""
Main function to process command arguments and to inject Frida.
Expand Down Expand Up @@ -516,16 +534,19 @@ def main():
pid = device.get_process(args.target).pid

session = device.attach(pid)
scripts = {}

if args.prepend:
prepend = session.create_script(args.prepend.read(), runtime="v8")
prepend.on("message", _custom_script_on_message)
prepend.load()
args.prepend.close()
scripts["prepend"] = prepend

script = session.create_script(jscode, runtime="v8")
script.on("message", formatter.on_message)
script.load()
scripts["script"] = script

script.post({
"type": "config",
Expand All @@ -547,6 +568,7 @@ def main():
append.on("message", _custom_script_on_message)
append.load()
args.append.close()
scripts["append"] = append

if args.inject_method == "spawn":
device.resume(pid)
Expand All @@ -564,18 +586,7 @@ def main():
json.dump(formatter.get_output(), args.output, indent=4)
args.output.close()

if args.append:
append.unload()
script.unload()
if args.prepend:
prepend.unload()

print('Stopping application (name={}, pid={})...'.format(
args.target,
pid
), end="")
device.kill(pid)
print("stopped.")
_finish(args, device, pid, scripts)

if __name__ == '__main__':
main()
6 changes: 3 additions & 3 deletions jnitrace/src/data/java_vm.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
{
"name": "reserved0",
"args": [],
"ret": ""
"ret": "void"
},
{
"name": "reserved1",
"args": [],
"ret": ""
"ret": "void"
},
{
"name": "reserved2",
"args": [],
"ret": ""
"ret": "void"
},
{
"name": "DestroyJavaVM",
Expand Down
8 changes: 4 additions & 4 deletions jnitrace/src/data/jni_env.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@
{
"name": "reserved0",
"args": [],
"ret": ""
"ret": "void"
},
{
"name": "reserved1",
"args": [],
"ret": ""
"ret": "void"
},
{
"name": "reserved2",
"args": [],
"ret": ""
"ret": "void"
},
{
"name": "reserved3",
"args": [],
"ret": ""
"ret": "void"
},
{
"name": "GetVersion",
Expand Down
2 changes: 1 addition & 1 deletion jnitrace/src/transport/data_transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ class DataTransport {
const BUFFER_PTR_INDEX = 2;
const SKIP_ENV_INDEX = 1;

const byteArrayArg = data.method.args[BYTE_ARRAY_INDEX];
const byteArrayArg = data.method.args[BUFFER_PTR_INDEX];
const type = byteArrayArg.slice(TYPE_NAME_START, TYPE_NAME_END);
const nType = Types.convertNativeJTypeToFridaType(type);
const size = Types.sizeOf(nType);
Expand Down
Loading

0 comments on commit 8488bfc

Please sign in to comment.