(funcname, filename, directory)
| 110 | return {'os': osys, 'arch': arch} |
| 111 | |
| 112 | def make_function(funcname, filename, directory): |
| 113 | import functools |
| 114 | import inspect |
| 115 | path = os.path.join(directory, filename) |
| 116 | template = lookup_template(path) |
| 117 | |
| 118 | local_ctx = get_context_from_dirpath(directory) |
| 119 | |
| 120 | def res(*args, **kwargs): |
| 121 | with render_global.go_inside() as was_inside: |
| 122 | with context.local(**local_ctx): |
| 123 | lines = template.render(*args, **kwargs).split('\n') |
| 124 | for i, line in enumerate(lines): |
| 125 | def islabelchar(c): |
| 126 | return c.isalnum() or c == '.' or c == '_' |
| 127 | if ':' in line and islabelchar(line.lstrip()[0]): |
| 128 | line = line.lstrip() |
| 129 | elif line.startswith(' '): |
| 130 | line = ' ' + line.lstrip() |
| 131 | lines[i] = line |
| 132 | while lines and not lines[-1]: lines.pop() |
| 133 | while lines and not lines[0]: lines.pop(0) |
| 134 | s = '\n'.join(lines) |
| 135 | while '\n\n\n' in s: |
| 136 | s = s.replace('\n\n\n', '\n\n') |
| 137 | |
| 138 | if was_inside: |
| 139 | return s |
| 140 | else: |
| 141 | return s + '\n' |
| 142 | |
| 143 | # Setting _relpath is a slight hack only used to get better documentation |
| 144 | res._relpath = path |
| 145 | res.__module__ = 'pwnlib.shellcraft.' + os.path.dirname(path).replace('/','.') |
| 146 | res.__name__ = res.__qualname__ = funcname |
| 147 | res.__doc__ = inspect.cleandoc(template.module.__doc__ or '') |
| 148 | if hasattr(inspect, 'signature'): |
| 149 | sig = inspect.signature(template.module.render_body) |
| 150 | sig = sig.replace(parameters=list(sig.parameters.values())[1:-1]) |
| 151 | res.__signature__ = sig |
| 152 | |
| 153 | @functools.wraps(res) |
| 154 | def function(*a): |
| 155 | return sys.modules[res.__module__].function(res.__name__, res, *a) |
| 156 | @functools.wraps(res) |
| 157 | def call(*a): |
| 158 | return sys.modules[res.__module__].call(res.__name__, *a) |
| 159 | |
| 160 | res.function = function |
| 161 | res.call = call |
| 162 | |
| 163 | return res |
nothing calls this directly
no test coverage detected