Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

[IMP] send batch of names/comments instead of 1 by 1 #192

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 33 additions & 22 deletions polichombr/views/api_idaactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,23 @@ def api_post_sample_comments(sid):
data = request.json
if "address" not in list(data.keys()) or "comment" not in list(data.keys()):
abort(400, "Missing comment or address arguments")
address = data['address']
comment = data['comment']
data = request.json
addresses = data['address']
comments = data['comment']
user_id = current_user.id
current_app.logger.debug(
"Getting a new comment for sample %d : %s@0x%x",
sid,
comment,
address)
action_id = api.idacontrol.add_comment(address, comment, user_id)
result = api.samplecontrol.add_idaaction(sid, action_id)
return jsonify({'result': result})
results = []
for i in range(len(addresses)) :
address = addresses[i]
comment = comments[i]
current_app.logger.debug(
"Getting a new comment for sample %d : %s@0x%x",
sid,
comment,
address)
action_id = api.idacontrol.add_comment(address, comment, user_id)
result = api.samplecontrol.add_idaaction(sid, action_id)
results.append(result)
return jsonify({'result': results})


@apiview.route('/samples/<int:sid>/names/', methods=['GET'])
Expand All @@ -140,21 +146,26 @@ def api_post_sample_names(sid):
@arg name the name
"""
data = request.json
addr = data['address']
name = data['name']
addresses = data['address']
names = data['name']
user_id = current_user.id
current_app.logger.debug(
"Getting a new name for sample %d : %s@0x%x",
sid,
name,
addr)
action_id = api.idacontrol.add_name(addr, name, user_id)
result = api.samplecontrol.add_idaaction(sid, action_id)
if result is True:
api.samplecontrol.rename_func_from_action(sid, addr, name)
results = []
for i in range(len(addresses)) :
name = names[i]
addr = addresses[i]
current_app.logger.debug(
"Getting a new name for sample %d : %s@0x%x",
sid,
name,
addr)
action_id = api.idacontrol.add_name(addr, name, user_id)
result = api.samplecontrol.add_idaaction(sid, action_id)
results.append(result)
if result is True:
api.samplecontrol.rename_func_from_action(sid, addr, name)
# we don't care if the function is renamed for a global name,
# so if the name is created return True anyway
return jsonify({'result': result})
return jsonify({'result': results})


@apiview.route('/samples/<int:sid>/types/', methods=['POST'])
Expand Down
41 changes: 41 additions & 0 deletions skelenox_plugin/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,26 @@ def push_comment(self, address=0, comment=None):
logger.error("Cannot send comment %s ( 0x%x )", comment, address)
return res["result"]

def push_comments(self, addresses=0, comments=None):
"""
Push a standard comment
"""
if comments is None or addresses == 0:
return False
data = {'address':[], 'comment':[]}
for address in addresses :
data['address'].append(address)
for comment in comments :
data['comment'].append(comment)
endpoint = self.prepare_endpoint('comments')
res = self.poli_post(endpoint, data)
if res["result"]:
logger.debug(
"Comments sent")
else:
logger.error("Cannot send comments")
return res["result"]

def push_type(self, address, mtype=None):
"""
Push defined types, parsed with prepare_parse_type
Expand Down Expand Up @@ -342,6 +362,27 @@ def push_name(self, address=0, name=None):
logger.error("failed to send name %s", name)
return True

def push_names(self, addresses=0, names=None):
"""
Send a define name, be it func or area
"""
if names is None:
return False

data = {'address':[], 'name':[]}
for address in addresses :
data['address'].append(address)
for name in names :
data['name'].append(name)
#data = list(map(lambda x, y: {'address':x, 'name':y}, addresses, names))
endpoint = self.prepare_endpoint('names')
res = self.poli_post(endpoint, data)
if res["result"]:
logger.debug("sent names")
else:
logger.error("failed to send names")
return True

def create_struct(self, struct_name):
"""
Create a structure in the database
Expand Down
14 changes: 12 additions & 2 deletions skelenox_plugin/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,28 @@ def send_names(self):
Used to send all the names to the server.
Usecase: Previously analyzed IDB
"""
addresses = []
names = []
for head in idautils.Names():
if not idaapi.has_dummy_name(idaapi.get_flags(head[0])):
self.skel_conn.push_name(head[0], head[1])
addresses.append(head[0])
names.append(head[1])
if len(names) > 0:
self.skel_conn.push_names(addresses, names)

def send_comments(self):
"""
Initial sync of comments
"""
comments = []
heads = []
for head in idautils.Heads():
cmt = SkelUtils.get_comment(head)
if cmt:
self.skel_conn.push_comment(head, cmt)
heads.append(head)
comments.append(cmt)
if len(comments) > 0:
self.skel_conn.push_comments(heads, comments)

def run(self):
"""
Expand Down
6 changes: 3 additions & 3 deletions skelenox_plugin/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def area_cmt_changed(self, *args):
Function comments are Area comments
"""
cb, area, cmt, rpt = args
self.skel_conn.push_comment(area.startEA, cmt)
self.skel_conn.push_comments([area.startEA], [cmt])

return ida_idp.IDB_Hooks.area_cmt_changed(self, *args)

Expand All @@ -51,7 +51,7 @@ def renamed(self, *args):
auto = idaapi.has_auto_name(idaapi.get_flags(ea))
dummy = idaapi.has_dummy_name(idaapi.get_flags(ea))
if not dummy and not auto:
self.skel_conn.push_name(ea, new_name)
self.skel_conn.push_names([ea], [new_name])
else:
logger.warning("ea outside program...")

Expand All @@ -66,7 +66,7 @@ def cmt_changed(self, *args):
addr, rpt)
cmt = idc.get_cmt(addr, rpt)
if not SkelUtils.filter_coms_blacklist(cmt):
self.skel_conn.push_comment(addr, cmt)
self.skel_conn.push_comments([addr], [cmt])
return ida_idp.IDB_Hooks.cmt_changed(self, *args)

def gen_regvar_def(self, *args):
Expand Down