3 ms·
I don't GitHub, but here are some thoughts: you only need to disable ints when you mess with cr0 and cr3 and applying patches. There are apis in the kernel for
by dmitrygr 9y ago
I don't GitHub, but here are some thoughts: you only need to disable ints when you mess with cr0 and cr3 and applying patches. There are apis in the kernel for that.
Basic block detection isn't easy. You CAN find branches in the block, and even patch them to work when you copy them elsewhere (you'll need this since most x86 branches are relative). There is provably NO 100% certain way to make sure no branch anywhere else targets those 12 bytes though.
You can use heuristics to almost-reliably guess though. If there is a "call", the instruction after it likely is a target of an indirect branch (ret). Also you'll have to disassemble the entire function (breadth first search till every traversal path hits a "ret") and see if any jumps to these 12 bytes exist. This will cover 99.99% of cases. The remaining 0.01% is VERY hard.