diff --git a/idaplugin/rematch/automate.py b/idaplugin/rematch/automate.py new file mode 100755 index 000000000..8ac3bd96c --- /dev/null +++ b/idaplugin/rematch/automate.py @@ -0,0 +1,41 @@ +import idaapi + +from . import actions +from . import dialogs + + +def main(): + # add file + 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) + + ############## + # 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__": + # 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/idaplugin/rematch/dialogs/__init__.py b/idaplugin/rematch/dialogs/__init__.py index 9dc111125..912530266 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 auto 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', 'auto', 'login', 'upload', 'match', + 'result', 'project', 'settings', 'serializedgraph'] diff --git a/idaplugin/rematch/dialogs/auto.py b/idaplugin/rematch/dialogs/auto.py new file mode 100755 index 000000000..35bbc876b --- /dev/null +++ b/idaplugin/rematch/dialogs/auto.py @@ -0,0 +1,36 @@ +from .. import log +from .base import BaseDialog + + +class AutoDialog(BaseDialog): + def __init__(self, calls): + # initialize super without any callbacks to avoid code review warnings + super(AutoDialog, self).__init__() + self.data_value = None + self.calls = calls + + def __call__(self, **kwargs): + super(AutoDialog, self).__init__(**kwargs) + return self + + 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': + response = self.reject_base(**kws) + elif handler == 'submit': + self.data_value = kws + response = self.submit_base() + elif handler == 'response': + response = self.response_base(**kws) + elif handler == 'exception': + 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 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()