static bool HandleBranching(string opcodeStr, int offset, MetaMidRepresentationOperationFactory operationFactory, Instruction instruction) { #region Branching if (instruction.OpCode == OpCodes.Leave || instruction.OpCode == OpCodes.Leave_S ) { //TODO: ignore flow commands for exceptions //operationFactory.LeaveTo(offset); return(true); } if (instruction.OpCode == OpCodes.Endfinally ) { //TODO: ignore flow commands for exceptions return(true); } if (instruction.OpCode == OpCodes.Brtrue_S || instruction.OpCode == OpCodes.Brtrue) { operationFactory.BranchIfTrue(offset); return(true); } if (instruction.OpCode == OpCodes.Br_S || instruction.OpCode == OpCodes.Br) { operationFactory.AlwaysBranch(offset); return(true); } if (instruction.OpCode == OpCodes.Brfalse || instruction.OpCode == OpCodes.Brfalse_S) { operationFactory.BranchIfFalse(offset); return(true); } if (opcodeStr == OpcodeBranchNames.Beq || opcodeStr == OpcodeBranchNames.BeqS) { operationFactory.BranchIfEqual(offset); return(true); } if (opcodeStr == OpcodeBranchNames.BgeUn || opcodeStr == OpcodeBranchNames.BgeUnS) //Todo: Fix this cannot treat unsigned as signed { operationFactory.BranchIfGreaterOrEqual(offset); return(true); } if (opcodeStr == OpcodeBranchNames.Bge || opcodeStr == OpcodeBranchNames.BgeS) { operationFactory.BranchIfGreaterOrEqual(offset); return(true); } if (opcodeStr == OpcodeBranchNames.BgtUn || opcodeStr == OpcodeBranchNames.BgtUnS) //Todo: Fix this cannot treat unsigned as signed { operationFactory.BranchIfGreater(offset); return(true); } if (opcodeStr == OpcodeBranchNames.Bgt || opcodeStr == OpcodeBranchNames.BgtS) { operationFactory.BranchIfGreater(offset); return(true); } if (opcodeStr == OpcodeBranchNames.Ble || opcodeStr == OpcodeBranchNames.BleS) { operationFactory.BranchIfLessOrEqual(offset); return(true); } if (opcodeStr == OpcodeBranchNames.BleUn || opcodeStr == OpcodeBranchNames.BleUnS) //Todo: Fix this cannot treat unsigned as signed { operationFactory.BranchIfLessOrEqual(offset); return(true); } if (opcodeStr == OpcodeBranchNames.BltUn || opcodeStr == OpcodeBranchNames.BltUnS) //Todo: Fix this cannot treat unsigned as signed { operationFactory.BranchIfLess(offset); return(true); } if (opcodeStr == OpcodeBranchNames.Blt || opcodeStr == OpcodeBranchNames.BltS) { operationFactory.BranchIfLess(offset); return(true); } if (opcodeStr == OpcodeBranchNames.Bne || opcodeStr == OpcodeBranchNames.BneUn || opcodeStr == OpcodeBranchNames.BneUnS || opcodeStr == OpcodeBranchNames.BneS) { operationFactory.BranchIfNotEqual(offset); return(true); } #endregion return(false); }
private static bool HandleBranching(string opcodeStr, int offset, MetaMidRepresentationOperationFactory operationFactory) { #region Branching if (opcodeStr == OpcodeBranchNames.Leave || opcodeStr == OpcodeBranchNames.LeaveS ) { operationFactory.AlwaysBranch(offset); operationFactory.LeaveTo(offset); operationFactory.ClearStack(); return(true); } if (opcodeStr == OpcodeBranchNames.BrTrueS || opcodeStr == OpcodeBranchNames.BrTrue || opcodeStr == OpcodeBranchNames.BrInstS || opcodeStr == OpcodeBranchNames.BrInst) { operationFactory.BranchIfTrue(offset); return(true); } if (opcodeStr == OpcodeBranchNames.BrFalseS || opcodeStr == OpcodeBranchNames.BrFalse || opcodeStr == OpcodeBranchNames.BrNullS || opcodeStr == OpcodeBranchNames.BrNull || opcodeStr == OpcodeBranchNames.BrZeroS || opcodeStr == OpcodeBranchNames.BrZero) { operationFactory.BranchIfFalse(offset); return(true); } if (opcodeStr == OpcodeBranchNames.Beq || opcodeStr == OpcodeBranchNames.BeqS) { operationFactory.BranchIfEqual(offset); return(true); } if (opcodeStr == OpcodeBranchNames.BgeUn || opcodeStr == OpcodeBranchNames.BgeUnS) //Todo: Fix this cannot treat unsigned as signed { operationFactory.BranchIfGreaterOrEqual(offset); return(true); } if (opcodeStr == OpcodeBranchNames.Bge || opcodeStr == OpcodeBranchNames.BgeS) { operationFactory.BranchIfGreaterOrEqual(offset); return(true); } if (opcodeStr == OpcodeBranchNames.BgtUn || opcodeStr == OpcodeBranchNames.BgtUnS) //Todo: Fix this cannot treat unsigned as signed { operationFactory.BranchIfGreater(offset); return(true); } if (opcodeStr == OpcodeBranchNames.Bgt || opcodeStr == OpcodeBranchNames.BgtS) { operationFactory.BranchIfGreater(offset); return(true); } if (opcodeStr == OpcodeBranchNames.Ble || opcodeStr == OpcodeBranchNames.BleS) { operationFactory.BranchIfLessOrEqual(offset); return(true); } if (opcodeStr == OpcodeBranchNames.BleUn || opcodeStr == OpcodeBranchNames.BleUnS) //Todo: Fix this cannot treat unsigned as signed { operationFactory.BranchIfLessOrEqual(offset); return(true); } if (opcodeStr == OpcodeBranchNames.BltUn || opcodeStr == OpcodeBranchNames.BltUnS) //Todo: Fix this cannot treat unsigned as signed { operationFactory.BranchIfLess(offset); return(true); } if (opcodeStr == OpcodeBranchNames.Blt || opcodeStr == OpcodeBranchNames.BltS) { operationFactory.BranchIfLess(offset); return(true); } if (opcodeStr == OpcodeBranchNames.Bne || opcodeStr == OpcodeBranchNames.BneUn || opcodeStr == OpcodeBranchNames.BneUnS || opcodeStr == OpcodeBranchNames.BneS) { operationFactory.BranchIfNotEqual(offset); return(true); } if (opcodeStr == OpcodeBranchNames.BrS || opcodeStr == OpcodeBranchNames.Br) { operationFactory.AlwaysBranch(offset); return(true); } #endregion return(false); }