public bool ProcessIndirectControlTransfer(Address addrSwitch, RtlTransfer xfer) { List <Address> vector; ImageMapVectorTable imgVector; Expression swExp; UserIndirectJump indJump; var listener = scanner.Services.RequireService <DecompilerEventListener>(); if (program.User.IndirectJumps.TryGetValue(addrSwitch, out indJump)) { vector = indJump.Table.Addresses; swExp = this.frame.EnsureIdentifier(indJump.IndexRegister); imgVector = indJump.Table; } else { var bw = new Backwalker <Block, Instruction>(new BackwalkerHost(this), xfer, eval); if (!bw.CanBackwalk()) { return(false); } var bwops = bw.BackWalk(blockCur); if (bwops == null || bwops.Count == 0) { return(false); //$REVIEW: warn? } Identifier idIndex = bw.Index != null ? blockCur.Procedure.Frame.EnsureRegister(bw.Index) : null; VectorBuilder builder = new VectorBuilder(scanner.Services, program, new DirectedGraphImpl <object>()); if (bw.VectorAddress == null) { return(false); } vector = builder.BuildAux(bw, addrSwitch, state); if (vector.Count == 0) { var rdr = program.CreateImageReader(bw.VectorAddress); if (!rdr.IsValid) { return(false); } // Can't determine the size of the table, but surely it has one entry? var addrEntry = arch.ReadCodeAddress(bw.Stride, rdr, state); string msg; if (this.program.SegmentMap.IsValidAddress(addrEntry)) { vector.Add(addrEntry); msg = "Can't determine size of jump vector; probing only one entry."; } else { // Nope, not even that. msg = "No valid entries could be found in jump vector."; } var nav = listener.CreateJumpTableNavigator(program, addrSwitch, bw.VectorAddress, bw.Stride); listener.Warn(nav, msg); if (vector.Count == 0) { return(false); } } imgVector = new ImageMapVectorTable( bw.VectorAddress, vector.ToArray(), builder.TableByteSize); swExp = idIndex; if (idIndex == null || idIndex.Name == "None") { swExp = bw.IndexExpression; } } ScanVectorTargets(xfer, vector); if (xfer is RtlGoto) { var blockSource = scanner.FindContainingBlock(ric.Address); blockCur = blockSource; foreach (Address addr in vector) { var dest = scanner.FindContainingBlock(addr); Debug.Assert(dest != null, "The block at address " + addr + "should have been enqueued."); blockSource.Procedure.ControlGraph.AddEdge(blockSource, dest); } if (swExp == null) { scanner.Warn(addrSwitch, "Unable to determine index variable for indirect jump."); Emit(new ReturnInstruction()); blockSource.Procedure.ControlGraph.AddEdge( blockSource, blockSource.Procedure.ExitBlock); } else { Emit(new SwitchInstruction(swExp, blockCur.Procedure.ControlGraph.Successors(blockCur).ToArray())); } } if (imgVector.Size > 0) { program.ImageMap.AddItemWithSize(imgVector.Address, imgVector); } else { program.ImageMap.AddItem(imgVector.Address, imgVector); } return(true); }
public bool ProcessIndirectControlTransfer(Address addrSwitch, RtlTransfer xfer) { var bw = new Backwalker(new BackwalkerHost(this), xfer, eval); if (!bw.CanBackwalk()) { return(false); } var bwops = bw.BackWalk(blockCur); if (bwops == null || bwops.Count == 0) { return(false); //$REVIEW: warn? } var idIndex = blockCur.Procedure.Frame.EnsureRegister(bw.Index); VectorBuilder builder = new VectorBuilder(scanner, program, new DirectedGraphImpl <object>()); if (bw.VectorAddress == null) { return(false); } List <Address> vector = builder.BuildAux(bw, addrSwitch, state); if (vector.Count == 0) { var addrNext = bw.VectorAddress + bw.Stride; var rdr = scanner.CreateReader(bw.VectorAddress); if (!rdr.IsValid) { return(false); } // Can't determine the size of the table, but surely it has one entry? var addrEntry = arch.ReadCodeAddress(bw.Stride, rdr, state); if (this.program.Image.IsValidAddress(addrEntry)) { vector.Add(addrEntry); scanner.Warn(addrSwitch, "Can't determine size of jump vector; probing only one entry."); } else { // Nope, not even that. scanner.Warn(addrSwitch, "No valid entries could be found in jump vector."); } } //$TODO: mark the vector ScanVectorTargets(xfer, vector); if (xfer is RtlGoto) { var blockSource = scanner.FindContainingBlock(ric.Address); blockCur = blockSource; foreach (Address addr in vector) { var dest = scanner.FindContainingBlock(addr); Debug.Assert(dest != null, "The block at address " + addr + "should have been enqueued."); blockSource.Procedure.ControlGraph.AddEdge(blockSource, dest); } Expression swExp = idIndex; if (idIndex.Name == "None") { swExp = bw.IndexExpression; } if (swExp == null) { throw new NotImplementedException(); } Emit(new SwitchInstruction(swExp, blockCur.Procedure.ControlGraph.Successors(blockCur).ToArray())); } //vectorUses[wi.addrFrom] = new VectorUse(wi.Address, builder.IndexRegister); program.ImageMap.AddItem(bw.VectorAddress, new ImageMapVectorTable(xfer is RtlCall, vector.ToArray(), builder.TableByteSize)); return(true); }