lifting-bits / remill

Library for lifting machine code to LLVM bitcode
Apache License 2.0
1.22k stars 143 forks source link

Fix bug in rendering actual PC from NEXT_PC with thumb preffix/suffix instructions #661

Closed 2over12 closed 1 year ago

2over12 commented 1 year ago

Since we group preffix suffix instructions using the current instruction size to work out the mode was buggy https://github.com/lifting-bits/remill/blob/b677387f6f7507193ddd4e3c9a2ec8bc2da94fc0/lib/Arch/Sleigh/Thumb2Arch.cpp#L48

instead this passes down the decoding context to figure out where PC should be

2over12 commented 1 year ago

There's an additional issue here in how we compute the patch expressions for sleigh files. We assume we can compute the address of inst_next given the value in PC, but we do it using inst_last, in reality regardless of the instruction size this should be -4 on thumb and -8 on arm which requires determining what mode, this will require another macro

2over12 commented 1 year ago

replacing all context reg references with a known constant is too naive, we need to just assign the entry value then lift the register like normal. A better way to do this is to allocate the local context reg as a pointer, store the assumed constant, then lift

2over12 commented 1 year ago

Should really integrate TestLifting.cpp from ARM and PPC but Im pressed for time at the moment.