예제 #1
0
        private void ReadExceptionHandlers(BinaryReader reader, MethodDefinition mdef,
                                           InstructionReader instructionReader, ushort triesSize)
        {
            var exceptionLookup = new Dictionary <uint, List <ExceptionHandler> >();

            for (int i = 0; i < triesSize; i++)
            {
                uint startOffset   = reader.ReadUInt32();
                uint insCount      = reader.ReadUInt16();
                uint endOffset     = startOffset + insCount - 1;
                uint handlerOffset = reader.ReadUInt16();

                var ehandler = new ExceptionHandler();
                mdef.Body.Exceptions.Add(ehandler);
                if (!exceptionLookup.ContainsKey(handlerOffset))
                {
                    exceptionLookup.Add(handlerOffset, new List <ExceptionHandler>());
                }
                exceptionLookup[handlerOffset].Add(ehandler);
                ehandler.TryStart = instructionReader.Lookup[(int)startOffset];
                // The last code unit covered (inclusive) is start_addr + insn_count - 1
                ehandler.TryEnd = instructionReader.LookupLast[(int)endOffset];
            }

            long baseOffset        = reader.BaseStream.Position;
            uint catchHandlersSize = reader.ReadULEB128();

            for (int i = 0; i < catchHandlersSize; i++)
            {
                long itemoffset      = reader.BaseStream.Position - baseOffset;
                int  catchTypes      = reader.ReadSLEB128();
                bool catchAllPresent = catchTypes <= 0;
                catchTypes = Math.Abs(catchTypes);

                for (int j = 0; j < catchTypes; j++)
                {
                    uint typeIndex = reader.ReadULEB128();
                    uint offset    = reader.ReadULEB128();
                    var  @catch    = new Catch();
                    @catch.Type        = typeReferences[(int)typeIndex];
                    @catch.Instruction = instructionReader.Lookup[(int)offset];

                    // As catch handler can be used in several tries, let's clone the catch
                    foreach (ExceptionHandler ehandler in exceptionLookup[(uint)itemoffset])
                    {
                        ehandler.Catches.Add(@catch.Clone());
                    }
                }

                if (catchAllPresent)
                {
                    uint offset = reader.ReadULEB128();
                    foreach (ExceptionHandler ehandler in exceptionLookup[(uint)itemoffset])
                    {
                        ehandler.CatchAll = instructionReader.Lookup[(int)offset];
                    }
                }
            }
        }
예제 #2
0
    public virtual Differences VisitCatch(Catch catch1, Catch catch2){
      Differences differences = new Differences(catch1, catch2);
      if (catch1 == null || catch2 == null){
        if (catch1 != catch2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++;
        return differences;
      }
      Catch changes = (Catch)catch2.Clone();
      Catch deletions = (Catch)catch2.Clone();
      Catch insertions = (Catch)catch2.Clone();

      Differences diff = this.VisitBlock(catch1.Block, catch2.Block);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.Block = diff.Changes as Block;
      deletions.Block = diff.Deletions as Block;
      insertions.Block = diff.Insertions as Block;
      Debug.Assert(diff.Changes == changes.Block && diff.Deletions == deletions.Block && diff.Insertions == insertions.Block);
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      diff = this.VisitTypeNode(catch1.Type, catch2.Type);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.Type = diff.Changes as TypeNode;
      deletions.Type = diff.Deletions as TypeNode;
      insertions.Type = diff.Insertions as TypeNode;
      //Debug.Assert(diff.Changes == changes.Type && diff.Deletions == deletions.Type && diff.Insertions == insertions.Type);
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      diff = this.VisitExpression(catch1.Variable, catch2.Variable);
      if (diff == null){Debug.Assert(false); return differences;}
      changes.Variable = diff.Changes as Expression;
      deletions.Variable = diff.Deletions as Expression;
      insertions.Variable = diff.Insertions as Expression;
      Debug.Assert(diff.Changes == changes.Variable && diff.Deletions == deletions.Variable && diff.Insertions == insertions.Variable);
      differences.NumberOfDifferences += diff.NumberOfDifferences;
      differences.NumberOfSimilarities += diff.NumberOfSimilarities;

      if (differences.NumberOfDifferences == 0){
        differences.Changes = null;
        differences.Deletions = null;
        differences.Insertions = null;
      }else{
        differences.Changes = changes;
        differences.Deletions = deletions;
        differences.Insertions = insertions;
      }
      return differences;
    }
예제 #3
0
        private void ReadExceptionHandlers(BinaryReader reader, MethodDefinition mdef, InstructionReader instructionReader, ushort triesSize)
        {
            var exceptionLookup = new Dictionary<uint, List<ExceptionHandler>>();
            for (var i = 0; i < triesSize; i++)
            {
                var startOffset = reader.ReadUInt32();
                var insCount = reader.ReadUInt16();
                var endOffset = startOffset + insCount - 1;
                uint handlerOffset = reader.ReadUInt16();

                var ehandler = new ExceptionHandler();
                mdef.Body.Exceptions.Add(ehandler);
                if (!exceptionLookup.ContainsKey(handlerOffset))
                {
                    exceptionLookup.Add(handlerOffset, new List<ExceptionHandler>());
                }
                exceptionLookup[handlerOffset].Add(ehandler);
                ehandler.TryStart = instructionReader.Lookup[(int)startOffset];
                // The last code unit covered (inclusive) is start_addr + insn_count - 1
                ehandler.TryEnd = instructionReader.LookupLast[(int)endOffset];
            }

            var baseOffset = reader.BaseStream.Position;
            var catchHandlersSize = reader.ReadULEB128();
            for (var i = 0; i < catchHandlersSize; i++)
            {
                var itemoffset = reader.BaseStream.Position - baseOffset;
                var catchTypes = reader.ReadSLEB128();
                var catchAllPresent = catchTypes <= 0;
                catchTypes = Math.Abs(catchTypes);

                for (var j = 0; j < catchTypes; j++)
                {
                    var typeIndex = reader.ReadULEB128();
                    var offset = reader.ReadULEB128();
                    var @catch = new Catch
                    {
                        Type = Dex.TypeReferences[(int) typeIndex],
                        Instruction = instructionReader.Lookup[(int) offset]
                    };

                    // As catch handler can be used in several tries, let's clone the catch
                    foreach (var ehandler in exceptionLookup[(uint)itemoffset])
                        ehandler.Catches.Add(@catch.Clone());
                }

                if (!catchAllPresent)
                    continue;

                var caOffset = reader.ReadULEB128();
                foreach (var ehandler in exceptionLookup[(uint)itemoffset])
                    ehandler.CatchAll = instructionReader.Lookup[(int)caOffset];
            }
        }
예제 #4
0
 public override Statement VisitCatch(Catch Catch)
 {
     if (Catch == null) return null;
     return base.VisitCatch((Catch)Catch.Clone());
 }