Add IDA-style asm display mode

This commit is contained in:
√(noham)²
2026-03-03 20:43:02 +01:00
parent 85e8e09249
commit 5e3598d8c4
3 changed files with 92 additions and 11 deletions

View File

@@ -1,6 +1,6 @@
{{- /* Assembly code block shortcode - supports multiple display modes */ -}}
{{- /* Parameters:
- mode: "raw" (syntax highlighted), "hex" (hex + asm), "full" (addr + hex + asm)
- mode: "raw" (syntax highlighted), "hex" (hex + asm), "full" (addr + hex + asm), "ida" (IDA-style addr + asm)
- arch: "x86" or "arm" (default: "x86")
- capitalize: "true" to uppercase hex bytes and addresses (default: "false")
*/ -}}
@@ -86,5 +86,37 @@
</div>
</div>
{{- else if eq $mode "ida" -}}
{{- /* IDA-style: section:address label | instruction (format: SECTION:ADDR label | INSTRUCTION) */ -}}
<div class="highlight">
<div class="asm-ida">
<pre tabindex="0" class="chroma"><code>{{- range split $content "\n" -}}
{{- if . -}}
<span class="asm-line">
{{- $parts := split . "|" -}}
{{- if ge (len $parts) 2 -}}
{{- /* Extract section:address and optional label */ -}}
{{- $addrPart := index $parts 0 | strings.TrimSpace -}}
{{- /* Extract instruction */ -}}
{{- $instruction := index $parts 1 | strings.TrimSpace -}}
{{- /* Optionally capitalize address */ -}}
{{- if eq $capitalize "true" -}}
{{- $addrPart = upper $addrPart -}}
{{- end -}}
{{- /* Apply syntax highlighting to instruction */ -}}
{{- $lang := cond (eq $arch "arm") "armasm" "nasm" -}}
{{- $highlighted := highlight $instruction $lang "" -}}
{{- /* Strip wrapper divs from highlighted output */ -}}
<span class="ida-address">{{ $addrPart }}</span><span class="ida-separator">|</span>{{ $highlighted | replaceRE "<div class=\"highlight\"><pre[^>]*><code[^>]*>" "" | replaceRE "</code></pre></div>" "" | safeHTML }}
{{- else -}}
{{ . }}
{{- end -}}
</span>
{{- end -}}
{{- end -}}</code></pre>
<button class="copy-code">copy</button>
</div>
</div>
{{- end -}}
</div>