From e84c5c529a32f9d092f4e732696c78ff46993abf Mon Sep 17 00:00:00 2001 From: Nir Izraeli Date: Thu, 16 Mar 2017 21:25:03 +0200 Subject: [PATCH 1/8] [WIP] add automatic multiple gui-less idb upload Signed-off-by: Nir Izraeli --- idaplugin/rematch/autoupload.py | 37 ++++++++++++++++++++++++++++++ tests/idaplugin/test_autoupload.py | 7 ++++++ 2 files changed, 44 insertions(+) create mode 100755 idaplugin/rematch/autoupload.py create mode 100644 tests/idaplugin/test_autoupload.py diff --git a/idaplugin/rematch/autoupload.py b/idaplugin/rematch/autoupload.py new file mode 100755 index 000000000..8f5a3b381 --- /dev/null +++ b/idaplugin/rematch/autoupload.py @@ -0,0 +1,37 @@ +import idc +import idaapi + +from . import network +from . import actions + + +class AddFileSilentUI(actions.base.Action): + pass + + +class MatchSilentUI(actions.base.Action): + pass + + +def main(): + # add file + actions.project.AddFileAction(AddFileSilentUI) + description = "Automatically collected / uploaded by autoupload.py" + ############## + + # upload data + actions.match.MatchAction(MatchSilentUI) + + +if __name__ == "__main__": + # action = str(idc.ARGV[1]) + # task_id = int(idc.ARGV[2]) + # owner_id = int(idc.ARGV[3]) + + # wait until autoanalysis is done, if needed + idaapi.autoWait() + + main() + + # and exit the IDA instance + idaapi.qexit(0) diff --git a/tests/idaplugin/test_autoupload.py b/tests/idaplugin/test_autoupload.py new file mode 100644 index 000000000..c5e68dcbc --- /dev/null +++ b/tests/idaplugin/test_autoupload.py @@ -0,0 +1,7 @@ +import idaplugin + + +def test_main(idapro_app): + del idapro_app + + idaplugin.rematch.autoupload.main() From 04e7aa41faf021b2d272fe1d10ebc3a1b497effe Mon Sep 17 00:00:00 2001 From: Nir Izraeli Date: Wed, 10 May 2017 10:51:08 +0300 Subject: [PATCH 2/8] make silent ui configurable builder Signed-off-by: Nir Izraeli --- idaplugin/rematch/autoupload.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/idaplugin/rematch/autoupload.py b/idaplugin/rematch/autoupload.py index 8f5a3b381..a1408fa6f 100755 --- a/idaplugin/rematch/autoupload.py +++ b/idaplugin/rematch/autoupload.py @@ -1,26 +1,34 @@ -import idc import idaapi -from . import network from . import actions -class AddFileSilentUI(actions.base.Action): - pass +def silent_ui(calls): + def silent(reject_handler=None, submit_handler=None, response_handler=None, + exception_handler=None): + for handler, kwargs in calls: + if handler == 'reject': + reject_handler(**kwargs) + elif handler == 'submit': + submit_handler(**kwargs) + elif handler == 'response': + response_handler(**kwargs) + elif handler == 'exception': + exception_handler(**kwargs) - -class MatchSilentUI(actions.base.Action): - pass + return silent def main(): # add file - actions.project.AddFileAction(AddFileSilentUI) + add_file_silent = silent_ui([['submit', {}], + ['response', {}]]) + actions.project.AddFileAction(add_file_silent) description = "Automatically collected / uploaded by autoupload.py" ############## # upload data - actions.match.MatchAction(MatchSilentUI) + #actions.match.MatchAction(MatchSilentUI) if __name__ == "__main__": From 788993ca4fe4b5e8725844924eef84d095e1b99c Mon Sep 17 00:00:00 2001 From: Nir Izraeli Date: Fri, 12 May 2017 01:07:43 +0300 Subject: [PATCH 3/8] activate add file action in autoupload Signed-off-by: Nir Izraeli --- idaplugin/rematch/autoupload.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/idaplugin/rematch/autoupload.py b/idaplugin/rematch/autoupload.py index a1408fa6f..709e77669 100755 --- a/idaplugin/rematch/autoupload.py +++ b/idaplugin/rematch/autoupload.py @@ -19,12 +19,17 @@ def silent(reject_handler=None, submit_handler=None, response_handler=None, return silent +class AddFileDialog(dialogs.silent.SilentDialog): + calls = [['submit', {}], + ['response', {}]] + + def main(): # add file add_file_silent = silent_ui([['submit', {}], ['response', {}]]) - actions.project.AddFileAction(add_file_silent) - description = "Automatically collected / uploaded by autoupload.py" + actions.project.AddFileAction(add_file_silent).activate() + #description = "Automatically collected / uploaded by autoupload.py" ############## # upload data From e87b92cb7c118973874b195cdcf2dff81be64908 Mon Sep 17 00:00:00 2001 From: Nir Izraeli Date: Wed, 24 May 2017 19:17:35 -0700 Subject: [PATCH 4/8] Rebase fixes Signed-off-by: Nir Izraeli --- idaplugin/rematch/autoupload.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/idaplugin/rematch/autoupload.py b/idaplugin/rematch/autoupload.py index 709e77669..4da1d001f 100755 --- a/idaplugin/rematch/autoupload.py +++ b/idaplugin/rematch/autoupload.py @@ -1,6 +1,7 @@ import idaapi from . import actions +from . import dialogs def silent_ui(calls): @@ -29,11 +30,7 @@ def main(): add_file_silent = silent_ui([['submit', {}], ['response', {}]]) actions.project.AddFileAction(add_file_silent).activate() - #description = "Automatically collected / uploaded by autoupload.py" - ############## - - # upload data - #actions.match.MatchAction(MatchSilentUI) + # description = "Automatically collected / uploaded by autoupload.py" if __name__ == "__main__": From 162930d980deb289f1b6e4837221bea75f009c08 Mon Sep 17 00:00:00 2001 From: Nir Izraeli Date: Thu, 25 May 2017 17:04:48 -0700 Subject: [PATCH 5/8] Add silent dialog and use it in autoupload Signed-off-by: Nir Izraeli --- idaplugin/rematch/autoupload.py | 33 +++++++-------------------- idaplugin/rematch/dialogs/__init__.py | 5 ++-- idaplugin/rematch/dialogs/silent.py | 28 +++++++++++++++++++++++ 3 files changed, 39 insertions(+), 27 deletions(-) create mode 100755 idaplugin/rematch/dialogs/silent.py diff --git a/idaplugin/rematch/autoupload.py b/idaplugin/rematch/autoupload.py index 4da1d001f..13241991d 100755 --- a/idaplugin/rematch/autoupload.py +++ b/idaplugin/rematch/autoupload.py @@ -4,33 +4,16 @@ from . import dialogs -def silent_ui(calls): - def silent(reject_handler=None, submit_handler=None, response_handler=None, - exception_handler=None): - for handler, kwargs in calls: - if handler == 'reject': - reject_handler(**kwargs) - elif handler == 'submit': - submit_handler(**kwargs) - elif handler == 'response': - response_handler(**kwargs) - elif handler == 'exception': - exception_handler(**kwargs) - - return silent - - -class AddFileDialog(dialogs.silent.SilentDialog): - calls = [['submit', {}], - ['response', {}]] - - def main(): # add file - add_file_silent = silent_ui([['submit', {}], - ['response', {}]]) - actions.project.AddFileAction(add_file_silent).activate() - # description = "Automatically collected / uploaded by autoupload.py" + add_file_silent = dialogs.silent.SilentDialog([['submit', {}], + ['response', {}]]) + actions.project.AddFileAction(add_file_silent).activate(None) + description = "Automatically collected / uploaded by autoupload.py" + ############## + + # upload data + # actions.match.MatchAction(MatchSilentUI) if __name__ == "__main__": diff --git a/idaplugin/rematch/dialogs/__init__.py b/idaplugin/rematch/dialogs/__init__.py index 9dc111125..d39ac5375 100755 --- a/idaplugin/rematch/dialogs/__init__.py +++ b/idaplugin/rematch/dialogs/__init__.py @@ -1,6 +1,7 @@ from . import base from . import widgets from . import gui +from . import silent from . import login from . import upload from . import match @@ -9,5 +10,5 @@ from . import settings from . import serializedgraph -__all__ = ['base', 'widgets', 'gui', 'login', 'upload', 'match', 'result', - 'project', 'settings', 'serializedgraph'] +__all__ = ['base', 'widgets', 'gui', 'silent', 'login', 'upload', 'match', + 'result', 'project', 'settings', 'serializedgraph'] diff --git a/idaplugin/rematch/dialogs/silent.py b/idaplugin/rematch/dialogs/silent.py new file mode 100755 index 000000000..944a19b12 --- /dev/null +++ b/idaplugin/rematch/dialogs/silent.py @@ -0,0 +1,28 @@ +from .base import BaseDialog + + +class SilentDialog(BaseDialog): + def __init__(self, calls): + # initialize super without any callbacks to avoid code review warnings + super(SilentDialog, self).__init__() + self.data_value = None + self.calls = calls + + def __call__(self, **kwargs): + super(SilentDialog, self).__init__(**kwargs) + return self + + def show(self): + for handler, kws in self.calls: + if handler == 'reject': + self.reject_base(**kws) + elif handler == 'submit': + self.data_value = kws + self.submit_base() + elif handler == 'response': + self.response_base(**kws) + elif handler == 'exception': + self.exception_base(**kws) + + def data(self): + return self.data_value From 91ca55c55e4a64587602a297fa170e046e44906b Mon Sep 17 00:00:00 2001 From: Nir Izraeli Date: Fri, 2 Jun 2017 00:48:34 -0700 Subject: [PATCH 6/8] Add some logging in silent dialog Signed-off-by: Nir Izraeli --- idaplugin/rematch/dialogs/silent.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/idaplugin/rematch/dialogs/silent.py b/idaplugin/rematch/dialogs/silent.py index 944a19b12..8cd662343 100755 --- a/idaplugin/rematch/dialogs/silent.py +++ b/idaplugin/rematch/dialogs/silent.py @@ -1,3 +1,4 @@ +from .. import log from .base import BaseDialog @@ -14,15 +15,22 @@ def __call__(self, **kwargs): def show(self): for handler, kws in self.calls: + response = None + log('silent_dialog').info("dispatching silent dialog action %s: %s", + handler, kws) if handler == 'reject': - self.reject_base(**kws) + response = self.reject_base(**kws) elif handler == 'submit': self.data_value = kws - self.submit_base() + response = self.submit_base() elif handler == 'response': - self.response_base(**kws) + response = self.response_base(**kws) elif handler == 'exception': - self.exception_base(**kws) + response = self.exception_base(**kws) + else: + log('silent_dialog').error("failed resolving handler") + + log('silent_dialog').info("response: %s", response) def data(self): return self.data_value From 1c00b4306d0292afddb31e668229e55950909863 Mon Sep 17 00:00:00 2001 From: Nir Izraeli Date: Sat, 27 May 2017 18:04:17 -0700 Subject: [PATCH 7/8] Advancemant of functional autoupload.py Signed-off-by: Nir Izraeli --- idaplugin/rematch/autoupload.py | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/idaplugin/rematch/autoupload.py b/idaplugin/rematch/autoupload.py index 13241991d..32313209e 100755 --- a/idaplugin/rematch/autoupload.py +++ b/idaplugin/rematch/autoupload.py @@ -1,19 +1,34 @@ import idaapi -from . import actions -from . import dialogs +try: + import rematch.actions as actions + import rematch.dialogs as dialogs +except ImportError: + from . import actions + from . import dialogs def main(): # add file - add_file_silent = dialogs.silent.SilentDialog([['submit', {}], - ['response', {}]]) - actions.project.AddFileAction(add_file_silent).activate(None) description = "Automatically collected / uploaded by autoupload.py" - ############## + calls = [('submit', {'project': -1, 'name': "filename", 'md5hash': "hash", + 'description': description, 'shareidb': True})] + add_file_silent = dialogs.silent.SilentDialog(calls) + actions.project.AddFileAction(add_file_silent).activate(None) - # upload data - # actions.match.MatchAction(MatchSilentUI) + ############## + # skipped: add a project for file + calls = [('submit', {'name': "proj_name", 'description': description, + 'private': False, 'bind_current': True})] + add_file_silent = dialogs.silent.SilentDialog(calls) + + # upload data and start matching + calls = [('submit', {'source': 'idb', 'source_single': None, + 'source_range': None, 'target': 'db', + 'target_project': None, 'target_file': None, + 'matchers': None})] + match_silent = dialogs.silent.SilentDialog(calls) + actions.match.MatchAction(match_silent).activate(None) if __name__ == "__main__": From ed723092a8338669f4f60bdd302c3f89eb075fe1 Mon Sep 17 00:00:00 2001 From: Nir Izraeli Date: Wed, 21 Nov 2018 21:59:28 -0800 Subject: [PATCH 8/8] rename silent to auto --- idaplugin/rematch/{autoupload.py => automate.py} | 8 ++------ idaplugin/rematch/dialogs/__init__.py | 4 ++-- idaplugin/rematch/dialogs/{silent.py => auto.py} | 6 +++--- 3 files changed, 7 insertions(+), 11 deletions(-) rename idaplugin/rematch/{autoupload.py => automate.py} (89%) rename idaplugin/rematch/dialogs/{silent.py => auto.py} (88%) diff --git a/idaplugin/rematch/autoupload.py b/idaplugin/rematch/automate.py similarity index 89% rename from idaplugin/rematch/autoupload.py rename to idaplugin/rematch/automate.py index 32313209e..8ac3bd96c 100755 --- a/idaplugin/rematch/autoupload.py +++ b/idaplugin/rematch/automate.py @@ -1,11 +1,7 @@ import idaapi -try: - import rematch.actions as actions - import rematch.dialogs as dialogs -except ImportError: - from . import actions - from . import dialogs +from . import actions +from . import dialogs def main(): diff --git a/idaplugin/rematch/dialogs/__init__.py b/idaplugin/rematch/dialogs/__init__.py index d39ac5375..912530266 100755 --- a/idaplugin/rematch/dialogs/__init__.py +++ b/idaplugin/rematch/dialogs/__init__.py @@ -1,7 +1,7 @@ from . import base from . import widgets from . import gui -from . import silent +from . import auto from . import login from . import upload from . import match @@ -10,5 +10,5 @@ from . import settings from . import serializedgraph -__all__ = ['base', 'widgets', 'gui', 'silent', 'login', 'upload', 'match', +__all__ = ['base', 'widgets', 'gui', 'auto', 'login', 'upload', 'match', 'result', 'project', 'settings', 'serializedgraph'] diff --git a/idaplugin/rematch/dialogs/silent.py b/idaplugin/rematch/dialogs/auto.py similarity index 88% rename from idaplugin/rematch/dialogs/silent.py rename to idaplugin/rematch/dialogs/auto.py index 8cd662343..35bbc876b 100755 --- a/idaplugin/rematch/dialogs/silent.py +++ b/idaplugin/rematch/dialogs/auto.py @@ -2,15 +2,15 @@ from .base import BaseDialog -class SilentDialog(BaseDialog): +class AutoDialog(BaseDialog): def __init__(self, calls): # initialize super without any callbacks to avoid code review warnings - super(SilentDialog, self).__init__() + super(AutoDialog, self).__init__() self.data_value = None self.calls = calls def __call__(self, **kwargs): - super(SilentDialog, self).__init__(**kwargs) + super(AutoDialog, self).__init__(**kwargs) return self def show(self):