TemplateManager API
TemplateManager API
app/managers/templateManager.py implements the template engine used to resolve snippet inclusions, evaluate whitelisted helper calls, and substitute parameters.
TemplateManager(os_, arch)
Builds OS/arch-aware paths into templates/recipes/{os}_{arch}/ and templates/snippets/{os}_{arch}/, and validates that both directories exist — otherwise it raises FileNotFoundError.
os_(str, default"win")arch(str, default"64")
Class constants:
MAX_RESOLVE_DEPTH = 10— maximum snippet nesting depthALLOWED_HELPERS— the set of helper names that may be called in templates
TemplateManager.load(name, params)
Loads a named recipe from the recipes directory, applies parameter substitution and helper evaluation, then recursively resolves snippet inclusions.
Returns the fully resolved NASM source string.
from app.managers.templateManager import TemplateManager
tm = TemplateManager(os_="posix", arch="64")
nasm = tm.load("exec", {"cmd": "id", "visible": False})
TemplateManager.render(template_code, params)
Applies the same resolution pipeline to an arbitrary ASM string rather than a named recipe file. This is the entry point used by the generate_from_template and compile_shellcode MCP tools.
nasm = tm.render("section .text\n[[EXIT_CLEAN]]\n", {})
ParamsManager
app/managers/paramsManager.py converts a params dict into a plain Python object whose attributes are the dict keys — this is the _params object referenced in templates.
from app.managers.paramsManager import ParamsManager
p = ParamsManager({"pid": 1234})
p.pid # 1234
An empty dict yields an object with no attributes; reading an unset attribute raises AttributeError at the template-evaluation site.
Constants
app/constants/shellSnipConstants.py defines the template delimiters and supported platforms:
| Constant | Value | Meaning |
|---|---|---|
TEMPLATE_PATH | <root>/templates | Root of recipe/snippet templates |
RECIPE_DIR | recipes | Recipe subdirectory under the templates root |
SNIP_DIR | snippets | Snippet subdirectory under the templates root |
SNIP_EXT | .asm | Template file extension |
SNIP_START | \[\[ | Snippet inclusion start marker |
SNIP_END | \]\] | Snippet inclusion end marker |
SNIP_PARAM | \# | Helper / parameter marker |
PARAMS_SEPARATOR | , | Separator between snippet name and its JSON params |
SUPPORTED_OS | ["win","posix","macos"] | Accepted --os values |
SUPPORTED_ARCH | ["32","64"] | Accepted architecture values |