GTFOBins.github.io/_includes/bin_table.html
2018-09-15 16:06:56 +02:00

99 lines
3.1 KiB
HTML

<input id="bin-search" type="text" placeholder="Search among {{ site.gtfobins | size }} binaries: <binary> +<function> ..."/>
<div id="bin-table-wrapper">
<table id="bin-table">
<thead>
<tr>
<th>Binary</th>
<th>Functions</th>
</tr>
</thead>
<tbody>
{% for file in site.gtfobins %}
<tr>
<td><a href="{{ file.url }}" class="bin-name">{% include get_bin_name path=file.path %}</a></td>
<td>{% include function_list.html bin=file %}</td>
</tr>
{% endfor %}
</tbody>
<tfoot>
<tr><td id="search-message" colspan="2">No binary matches...</td></tr>
</tfoot>
</table>
</div>
<script>
function filter(query) {
var queryArray = query.toLowerCase().trim().split(/ *\+/);
var binPattern = queryArray[0];
var functionPatterns = queryArray.splice(1);
// consistently update the URL
location.hash = query;
// filter rows
var noResults = true;
document.querySelectorAll('#bin-table tbody tr').forEach(function (row) {
var binName = row.children[0].firstElementChild.innerText.toLowerCase();
var functions = Array.from(row.children[1].firstElementChild.children)
.map(function (x) { return x.innerText })
.join('\x00').toLowerCase(); // separator
var show = (
binName.indexOf(binPattern) !== -1 &&
functionPatterns.every(function (pattern) {
return functions.indexOf(pattern) !== -1;
})
);
if (show) {
row.style.display = '';
noResults = false;
} else {
row.style.display = 'none';
}
});
// update the search message visibility
var searchMessage = document.getElementById('search-message');
searchMessage.style.display = noResults ? 'table-cell' : 'none';
}
(function () {
var searchBox = document.getElementById('bin-search');
// ensure height during filtering
var binTableWrapper = document.getElementById('bin-table-wrapper');
binTableWrapper.style.height = binTableWrapper.clientHeight + 'px';
// handle user input
searchBox.addEventListener('input', function () {
var query = searchBox.value;
filter(query);
});
// handle shortcuts
addEventListener('keydown', function (event) {
// focus search box on valid keydown
if (event.key.toLowerCase().match(/^[+a-z]$/) &&
!(event.ctrlKey || event.altKey || event.metaKey)) {
searchBox.focus();
}
// clear filter on escape
else if (event.key === 'Escape') {
searchBox.value = '';
searchBox.focus();
filter('');
}
});
// filter on load according to the URL
var query = decodeURIComponent(location.hash.slice(1));
filter(query);
if (query) {
searchBox.value = query;
searchBox.focus();
}
})();
</script>