/// <summary> /// Computes the checksum of a basic block. /// </summary> private static void ComputeMore( HashAlgorithm hasher, BasicBlock basicBlock, BinaryImage image) { ArraySegment <byte> code = image.GetBytes(basicBlock.Location, basicBlock.Length); int index = code.Offset; // TODO: maybe we should subclass X86Codec.Instruction to provide // rich functionalities??? foreach (Instruction instruction in basicBlock.GetInstructions(image)) { ComputeMore(hasher, code.Array, index, instruction); index += instruction.EncodedLength; } }
/// <summary> /// Decodes an instruction at the given offset, applying associated /// fix-up information if present. /// </summary> /// <returns>The decoded instruction.</returns> /// <remarks> /// When overridden, the method must guarantee that the instruction /// is contained in the image, and not into another segment. /// </remarks> /// <exception cref="ArgumentOutOfRangeException">If offset refers to /// a location outside of the image.</exception> protected virtual Instruction DecodeInstruction(Address address) { if (!image.IsAddressValid(address)) { throw new ArgumentOutOfRangeException("address"); } Instruction instruction; try { instruction = X86Codec.Decoder.Decode( image.GetBytes(address), CpuMode.RealAddressMode); } catch (Exception ex) { AddError(address, ErrorCode.InvalidInstruction, "Bad instruction: {0}", ex.Message); return(null); } MakeRelativeOperandSourceAware(instruction, address); return(instruction); }
/// <summary> /// Computes the checksum of a basic block. /// </summary> private static void ComputeMore( HashAlgorithm hasher, BasicBlock basicBlock, BinaryImage image) { ArraySegment<byte> code = image.GetBytes(basicBlock.Location, basicBlock.Length); int index = code.Offset; // TODO: maybe we should subclass X86Codec.Instruction to provide // rich functionalities??? foreach (Instruction instruction in basicBlock.GetInstructions(image)) { ComputeMore(hasher, code.Array, index, instruction); index += instruction.EncodedLength; } }