insn_get_immediate(9)
β¨ insn_get_immediate β¨
okay bestie, welcome to the kernel API manual for insn_get_immediate π
this one lives in the insn(9) family of pages, and it's genuinely so useful β let's get into it π«Ά
πΈ NAME πΈ
insn_get_immediate β get the immediate in an instruction π
β¨ SYNOPSIS β¨
int insn_get_immediate (struct insn *insn );
π ARGUMENTS π
insnβ thestruct insnthat's holding your instruction π
π¦ DESCRIPTION π¦
So here's the vibe: if it's necessary, this bad boy first collects the instruction up to and including the displacement bytes β¨ lowkey an important detail, don't skip it.
Basically? Most of the immediates are sign-expanded β that's just how it is, no cap π
And if you want the unsigned value, you can compute it by bit masking with this iconic little expression:
((1 << (nbytes * 8)) - 1)
that's literally it, she ate π
π₯ RETURN π₯
0β on success π< 0β on error π
π SEE ALSO π
This one's part of a whole friend group, iykyk β go check out the Kernel file ./tools/arch/x86/lib/insn.c and also, like, all of these:
insn_init(9)insn_get_prefixes(9)insn_get_opcode(9)insn_get_modrm(9)insn_rip_relative(9)insn_get_sib(9)insn_get_displacement(9)insn_get_length(9)insn_decode(9)
mwah π this page is brought to you by ./tools/arch/x86/lib, dated October 2026, and it's the insn_get_immediate(9) kernel API manual β go read the whole squad, they're all iconic π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms