{% load analysis_tags %}

<style type="text/css">
.signature {
    padding: 5px;
    padding-left: 10px;
    margin-bottom: 5px;
}

.signature-process {
    background-color: #d9edf7;
    font-weight: bold;
}

.sign-key {
    font-weight: bold;
}
</style>
<section id="signatures">
    <h4><span class="glyphicon glyphicon-qrcode" aria-hidden="true"></span> Signatures</h4>
    {% for signature in analysis.signatures %}
        <a style="text-decoration: none;" href="#signature_{{signature.name}}" data-toggle="collapse">
        <div class="alert {% if signature.severity <= 1 %}alert-info{% elif signature.severity == 2 %}alert-warning{% else %}alert-danger{% endif %} signature">
        {{signature.description}}
        {% if signature.marks %}
            {% if signature.marks|length == 1 %}
            (1 event)
            {% elif signature.markcount == signature.marks|length %}
            ({{ signature.marks|length }} events)
            {% elif signature.markcount %}
            ({{ signature.marks|length }} out of {{ signature.markcount }} events)
            {% else %}
            ({{ signature.marks|length }} events)
            {% endif %}
        {% endif %}
        </div></a>

        <div id="signature_{{signature.name}}" class="collapse">
            <table class="table table-bordered" style="table-layout: fixed;">
                {% for mark in signature.marks|sigsort %}
                    {% if mark.type == "call" %}
                    {% if mark.first %}
                        {# Close up the non-API call table #}
                        {% if not forloop.first %}
                        </table>
                        <table class="table table-bordered" style="table-layout: fixed;">
                        {% endif %}

                        <thead>
                            <tr>
                                <th width="15%">Time &amp; API</th>
                                <th width="65%">Arguments</th>
                                <th width="5%">Status</th>
                                <th width="10%">Return</th>
                                <th width="5%">Repeated</th>
                            </tr>
                        </thead>
                    {% endif %}
                    <tr>
                        {% include "analysis/behavior/_api_call.html" with call=mark.call pid=mark.pid cid=mark.cid %}
                    </tr>
                    {% elif mark.type == "ioc" %}
                    <tr>
                        <td>{{ mark.category }}</td>
                        <td>{{ mark.ioc }}</td>
                        {% if mark.description %}
                        <td>{{ mark.description }}</td>
                        {% endif %}
                    </tr>
                    {% elif mark.type == "generic" %}
                    <tr>
                        {% for key, value in mark.items %}
                            {% if key != "type" %}
                                <td colspan="1">{{ key }}</td>
                                <td colspan="4">{{ value }}</td>
                            {% endif %}
                        {% endfor %}
                    </tr>
                    {% endif %}
                {% endfor %}
            </table>
        </div>
    {% endfor %}
    {% if not analysis.signatures %}
        <p>No signatures</p>
    {% endif %}
</section>
