Skip to content

Commit

Permalink
add monitoring limit
Browse files Browse the repository at this point in the history
  • Loading branch information
yzygitzh committed Aug 4, 2017
1 parent 7d2aee8 commit 983a244
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
5 changes: 3 additions & 2 deletions dsm_patcher/scripts/dsm_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ def run(config_json_path):

if trace_method_id not in result_dict[package_name][device_id]:
result_dict[package_name][device_id][trace_method_id] = []
reverse_stack_trace = [] + thread_stack_trace[tid]
reverse_stack_trace.reverse()
#reverse_stack_trace = [] + thread_stack_trace[tid]
#reverse_stack_trace.reverse()
reverse_stack_trace = []
result_dict[package_name][device_id][trace_method_id].append({
"returnValue": monitor_item["returnValue"],
"paraList": para_types,
Expand Down
4 changes: 2 additions & 2 deletions dsm_patcher/scripts/jdwp.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ def parse_return_value(self, return_value):
basic_parser = {
"Z": lambda x: ("boolean", struct.unpack(">?", x)[0]),
"B": lambda x: ("byte", chr(struct.unpack(">B", x)[0])),
"C": lambda x: ("char", unicode(x)),
"C": lambda x: ("char", x.encode("utf8", "ignore")),
"S": lambda x: ("short", struct.unpack(">h", x)[0]),
"I": lambda x: ("int", struct.unpack(">i", x)[0]),
"J": lambda x: ("long", struct.unpack(">q", x)[0]),
Expand All @@ -390,7 +390,7 @@ def parse_return_value(self, return_value):
ident, code, data = self.StringReference_Value(str_id)
str_len = struct.unpack(">I", data[:4])[0]
str_data = struct.unpack(">%ds" % str_len, data[4:])[0]
return (str_type, str_data)
return (str_type, str_data.decode("utf8", "ignore").encode("utf8"))
else:
return basic_parser[return_value[0]](return_value[1:])

Expand Down
7 changes: 5 additions & 2 deletions dsm_patcher/scripts/trace_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def monitor_func(device_id, apk_path_list, droidbot_out_dir,
if thread_info[matched_idx] is not None:
matched_methods = get_monitoring_methods(thread_info[matched_idx])
monitoring_methods = monitoring_methods.union(matched_methods)
monitoring_methods_list.append(sorted(list(monitoring_methods)))
monitoring_methods_list.append(monitoring_methods)

# intialize ADB
adb = ADBConnection(device_id)
Expand Down Expand Up @@ -118,7 +118,10 @@ def monitor_func(device_id, apk_path_list, droidbot_out_dir,
for event_id in event_ids:
jdwp_helper.EventRequest_Clear(event_id[0], event_id[1])

trace_result.append(jdwp_helper.parse_cmd_packets(jdwp.get_cmd_packets()))
parsed_result = jdwp_helper.parse_cmd_packets(jdwp.get_cmd_packets())
#print monitoring_methods
#print parsed_result[0]
trace_result.append([x for x in parsed_result if x["classMethodName"] in monitoring_methods])

with open("%s/%s.json" % (full_output_dir, comparator_result_labels[event_idx]), "w") as trace_result_file:
json.dump({
Expand Down
13 changes: 5 additions & 8 deletions dsm_patcher/scripts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,23 @@ def java_shorty2full(short_sig):
idx += 1
return fields[0], parsed_paras

def java_full4jdwp(shorty_sig):
class_method, parsed_paras = java_shorty2full(shorty_sig)
return "%s(%s)" % (class_method, ",".join(parsed_paras[:-1]))

def java_full4dsm(shorty_sig):
class_method, parsed_paras = java_shorty2full(shorty_sig)
return class_method, parsed_paras[:-1], parsed_paras[-1]

def get_monitoring_methods(trace_item_list):
ret_list = []
method_filter = set([")Z", ")B", ")C", ")S", ")I", ")J"])
method_filter = set(["Z", "B", "C", "S", "I", "J", "Ljava/lang/String;"])

for trace_item in trace_item_list:
fields = trace_item.split()
sig_end = fields[1][-len(")X"):]
sig = fields[1]
sig_end = sig[sig.rfind(")") + 1:]
if sig_end in method_filter:
ret_list.append(java_full4jdwp(trace_item))
ret_list.append(fields[0])
return set(ret_list)

def extract_method_classes(methods_list):
return sorted(list(set([
".".join(x.split("(")[0].split(".")[:-1]) for x in methods_list
".".join(x.split(".")[:-1]) for x in methods_list
])))

0 comments on commit 983a244

Please sign in to comment.