about summary refs log tree commit diff stats
path: root/miasm2/jitter/jitload.py
diff options
context:
space:
mode:
authorPierre LALET <pierre.lalet@cea.fr>2015-02-16 14:06:18 +0100
committerPierre LALET <pierre.lalet@cea.fr>2015-02-17 12:47:33 +0100
commit773a0e9a43163d84a619496863c3136e63eafc16 (patch)
treedabb6a64a8832c83c2dbf8374efe9ae71c9b3545 /miasm2/jitter/jitload.py
parent779cacc9a71dcdfdf4318f9a2a596b36ec184989 (diff)
downloadmiasm-773a0e9a43163d84a619496863c3136e63eafc16.tar.gz
miasm-773a0e9a43163d84a619496863c3136e63eafc16.zip
Add a function decorator to use named arguments in .func_args_stdcall() methods
Diffstat (limited to 'miasm2/jitter/jitload.py')
-rw-r--r--miasm2/jitter/jitload.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/miasm2/jitter/jitload.py b/miasm2/jitter/jitload.py
index 525cda09..defc139a 100644
--- a/miasm2/jitter/jitload.py
+++ b/miasm2/jitter/jitload.py
@@ -1,12 +1,14 @@
 #!/usr/bin/env python
 
+import logging
+from functools import wraps
+from collections import Sequence, namedtuple
+
 from miasm2.jitter.csts import *
 from miasm2.core.utils import *
 from miasm2.core.bin_stream import bin_stream_vm
 from miasm2.ir.ir2C import init_arch_C
 
-import logging
-
 log = logging.getLogger('jitload.py')
 hnd = logging.StreamHandler()
 hnd.setFormatter(logging.Formatter("[%(levelname)s]: %(message)s"))
@@ -28,6 +30,21 @@ try:
 except ImportError:
     log.error('cannot import jit python')
 
+def named_arguments(func):
+    """Function decorator to allow the use of .func_args_stdcall()
+    methods with either the number of arguments or the list of the
+    argument names.
+
+    @func: function
+    """
+    @wraps(func)
+    def newfunc(self, args):
+        if isinstance(args, Sequence):
+            ret_ad, arg_vals = func(self, len(args))
+            return ret_ad, namedtuple("args", args)(*arg_vals)
+        else:
+            return func(self, args)
+    return newfunc
 
 class CallbackHandler(object):