internal string GetHandlerLabel(CatchHandler handler) { var label = string.Empty; Handlers.TryGetValue(handler, out label); return(label); }
internal void AddHandler(CatchHandler handler, string labelPrefix, ref int counter) { var label = AddTarget(-1, handler.HandlerOffset, labelPrefix, ref counter); Handlers.Add(handler, label); }
internal Method(uint id, Dex dex, BinaryReader reader, uint codeOffset) { Id = id; Dex = dex; ClassIndex = reader.ReadUInt16(); PrototypeIndex = reader.ReadUInt16(); NameIndex = reader.ReadUInt32(); Annotations = new Annotation[0]; ParameterAnnotations = new List <Annotation>(); // This method has no opcodes, must be abstract or native. // Or the method is being loaded directly from the methods list if (codeOffset != 0) { reader.BaseStream.Position = codeOffset; RegistersSize = reader.ReadUInt16(); ArgumentsSize = reader.ReadUInt16(); ReturnValuesSize = reader.ReadUInt16(); var numberOfTryItems = reader.ReadUInt16(); // Not parsing debug info /*var debugInfoOffset =*/ reader.ReadUInt32(); CodeLength = reader.ReadUInt32(); CodeOffset = reader.BaseStream.Position; // Skip the opcode block reader.BaseStream.Position += CodeLength * 2; // Skip the optional padding if ((numberOfTryItems != 0) && (CodeLength % 2 != 0)) { reader.BaseStream.Position += 2; } // Load the try blocks if (numberOfTryItems != 0) { TryCatchBlocks = new TryCatchBlock[numberOfTryItems]; var handlerOffsets = new long[numberOfTryItems]; // read Try for (int i = 0; i < numberOfTryItems; i++) { var tryCatch = new TryCatchBlock(CodeOffset); tryCatch.StartAddress = reader.ReadUInt32(); tryCatch.InstructionCount = reader.ReadUInt16(); TryCatchBlocks [i] = tryCatch; handlerOffsets[i] = reader.ReadUInt16(); } var encodedCatchHandlerListOffset = reader.BaseStream.Position; // Size of the list, could be used to confirm the DEX is properly // built. For this purpose will assume DEX files are always good Leb128.ReadUleb(reader); // read Catch blocks for (int i = 0; i < numberOfTryItems; i++) { //encoded_catch_handler if (handlerOffsets [i] > 0) { reader.BaseStream.Position = encodedCatchHandlerListOffset + handlerOffsets [i]; var handlersCount = Leb128.ReadLeb(reader); var handlers = new CatchHandler[handlersCount <= 0 ? Math.Abs(handlersCount) + 1 : handlersCount]; for (int j = 0; j < Math.Abs(handlersCount); j++) { var catchHandler = new CatchHandler(CodeOffset); catchHandler.TypeIndex = Leb128.ReadUleb(reader); catchHandler.Address = Leb128.ReadUleb(reader); handlers [j] = catchHandler; } // parse the catch all block if (handlersCount <= 0) { var catchHandler = new CatchHandler(CodeOffset); catchHandler.TypeIndex = 0; catchHandler.Address = Leb128.ReadUleb(reader); handlers [handlers.Length - 1] = catchHandler; } TryCatchBlocks [i].Handlers = handlers; } } } } }