Created
August 8, 2025 01:54
-
-
Save iximeow/a18b5d6aeb0b9219d496e293640a1db5 to your computer and use it in GitHub Desktop.
arguably the most annoying gdb script i've ever written
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # written directly in conjunction with the following asm, | |
| # | |
| # ``` | |
| # bits 64 | |
| # | |
| # d: | |
| # dq 0x0303030302020202 | |
| # dq 0x0202020201010101 | |
| # | |
| # global _start | |
| #_start: | |
| # mov eax, 1 | |
| # mov ecx, 0 | |
| # cpuid | |
| # | |
| # movups xmm3, [d] | |
| # movups xmm4, [d] | |
| # pclmulqdq xmm3, xmm4, 0x11 | |
| # mov rax, 60 | |
| # pextrq rdi, xmm3, 1 | |
| # syscall | |
| # ``` | |
| # | |
| # assembled and linked like | |
| # | |
| # nasm -f elf64 -o pclmulqdq.o pclmulqdq.s | |
| # ld -o pclmulqdq pclmulqdq.o | |
| # | |
| # this can be run like | |
| # | |
| # gdb --batch-silent --command dbgscript -q --args taskset -ac 4 ./pclmulqdq | |
| # | |
| # to show that hiding the pclmulqdq bit in cpuid doesn't relate to the ability | |
| # to actually execute that instruction. | |
| # | |
| # the MSR side of things looks something like | |
| # | |
| # ``` | |
| # > sudo rdmsr -x --processor 4 0xc0011004 | |
| # 7ed8320b178bfbff | |
| # > sudo wrmsr --processor 4 0xc0011004 0x7ed83209178bfbff | |
| # > sudo rdmsr -x --processor 4 0xc0011004 | |
| # 7ed83209178bfbff | |
| # ``` | |
| set pagination off | |
| set breakpoint pending on | |
| set verbose off | |
| b _start | |
| r | |
| c | |
| set logging file /dev/stderr | |
| set logging off | |
| set $g=$pc | |
| define hook-stop | |
| set logging on | |
| x/i $g | |
| set $g=$pc | |
| set logging off | |
| end | |
| si | |
| si | |
| set logging on | |
| printf "# cpuid leaf: 0x%x\n", $rax | |
| set logging off | |
| si | |
| set logging on | |
| printf "# leaf 1 ecx: 0x%08x\n", $ecx | |
| printf "# - bit 2 (pclmulqdq): %x\n", ($ecx & 2) | |
| set logging off | |
| si | |
| si | |
| si | |
| si | |
| si | |
| define hook-stop | |
| end | |
| set logging on | |
| x/i $pc | |
| si | |
| printf "# exit code: %d\n", $_exitcode | |
| q |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment