public static List<MethodSigInfo> Read(BinaryReader reader) { if (reader.ReadInt32() != 1) throw new InvalidDataException(); int numHandlers = reader.ReadInt32(); var list = new List<MethodSigInfo>(numHandlers); for (int i = 0; i < numHandlers; i++) { var typeCode = (HandlerTypeCode)reader.ReadInt32(); int numBlocks = reader.ReadInt32(); var blocks = new List<BlockSigInfo>(numBlocks); for (int j = 0; j < numBlocks; j++) { int numTargets = reader.ReadInt32(); var targets = new List<int>(numTargets); for (int k = 0; k < numTargets; k++) targets.Add(reader.ReadInt32()); var numHashes = reader.ReadInt32(); var hashes = new List<BlockElementHash>(numHashes); for (int k = 0; k < numHashes; k++) hashes.Add((BlockElementHash)reader.ReadInt32()); var block = new BlockSigInfo(hashes, targets); block.HasFallThrough = reader.ReadBoolean(); block.EndsInRet = reader.ReadBoolean(); blocks.Add(block); } list.Add(new MethodSigInfo(blocks, typeCode)); } return list; }
public List <BlockSigInfo> Create(MethodDef method) { blocks = new Blocks(method); var allBlocks = blocks.MethodBlocks.GetAllBlocks(); var blockInfos = new List <BlockSigInfo>(allBlocks.Count); foreach (var block in allBlocks) { var blockInfo = new BlockSigInfo(); blockInfo.HasFallThrough = block.FallThrough != null; blockInfo.EndsInRet = block.LastInstr.OpCode.Code == Code.Ret; blockInfos.Add(blockInfo); var instrs = block.Instructions; for (int i = 0; i < instrs.Count; i++) { var info = CalculateHash(instrs, ref i); if (info != null) { blockInfo.Hashes.Add(info.Value); } } } for (int i = 0; i < blockInfos.Count; i++) { var block = allBlocks[i]; var blockInfo = blockInfos[i]; if (block.FallThrough != null) { blockInfo.Targets.Add(allBlocks.IndexOf(block.FallThrough)); } if (block.Targets != null) { foreach (var target in block.Targets) { blockInfo.Targets.Add(allBlocks.IndexOf(target)); } } } return(blockInfos); }
public static List <MethodSigInfo> Read(BinaryReader reader) { if (reader.ReadInt32() != 1) { throw new InvalidDataException(); } int numHandlers = reader.ReadInt32(); var list = new List <MethodSigInfo>(numHandlers); for (int i = 0; i < numHandlers; i++) { var typeCode = (HandlerTypeCode)reader.ReadInt32(); int numBlocks = reader.ReadInt32(); var blocks = new List <BlockSigInfo>(numBlocks); for (int j = 0; j < numBlocks; j++) { int numTargets = reader.ReadInt32(); var targets = new List <int>(numTargets); for (int k = 0; k < numTargets; k++) { targets.Add(reader.ReadInt32()); } var numHashes = reader.ReadInt32(); var hashes = new List <BlockElementHash>(numHashes); for (int k = 0; k < numHashes; k++) { hashes.Add((BlockElementHash)reader.ReadInt32()); } var block = new BlockSigInfo(hashes, targets) { HasFallThrough = reader.ReadBoolean(), EndsInRet = reader.ReadBoolean(), }; blocks.Add(block); } list.Add(new MethodSigInfo(blocks, typeCode)); } return(list); }
public List<BlockSigInfo> Create(MethodDef method) { blocks = new Blocks(method); var allBlocks = blocks.MethodBlocks.GetAllBlocks(); var blockInfos = new List<BlockSigInfo>(allBlocks.Count); foreach (var block in allBlocks) { var blockInfo = new BlockSigInfo(); blockInfo.HasFallThrough = block.FallThrough != null; blockInfo.EndsInRet = block.LastInstr.OpCode.Code == Code.Ret; blockInfos.Add(blockInfo); var instrs = block.Instructions; for (int i = 0; i < instrs.Count; i++) { var info = CalculateHash(instrs, ref i); if (info != null) blockInfo.Hashes.Add(info.Value); } } for (int i = 0; i < blockInfos.Count; i++) { var block = allBlocks[i]; var blockInfo = blockInfos[i]; if (block.FallThrough != null) blockInfo.Targets.Add(allBlocks.IndexOf(block.FallThrough)); if (block.Targets != null) { foreach (var target in block.Targets) blockInfo.Targets.Add(allBlocks.IndexOf(target)); } } return blockInfos; }