Sha256: 7cd70a7a83f43f3a49f0f482eaad911c116a1580a59bf5fd0ba8b8d3d68bdd6b

Contents?: true

Size: 1.46 KB

Versions: 5

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

module Android
  class Dex
    class << self
      # parse uleb128(unsigned integer) data
      # @param [String] data target byte data
      # @param [Integer] offset
      # @return [Integer, Integer] parsed value and parsed byte length
      # @see http://en.wikipedia.org/wiki/LEB128
      def uleb128(data, offset=0)
        result = 0
        shift = 0
        d = data[offset...data.size]
        (0..4).each do |i|
          byte = d.getbyte(i)
          result |= ((byte & 0x7f) << shift)
          return result, i+1 if ((byte & 0x80) == 0)
          shift += 7
        end
      end
      # parse uleb128 + 1 data
      # @param [String] data target byte data
      # @param [Integer] offset
      # @return [Integer, Integer] parsed value and parsed byte length
      def uleb128p1(data, offset=0)
        ret, len = self.uleb128(data, offset)
        return (ret - 1), len
      end
      # parse sleb128(signed integer) data
      # @param [String] data target byte data
      # @param [Integer] offset
      # @return [Integer, Integer] parsed value and parsed byte length
      def sleb128(data, offset=0)
        result  = 0
        shift = 0
        d = data[offset...data.size]
        (0..4).each do |i|
          byte  = d.getbyte(i)
          result  |=((byte & 0x7F) << shift)
          return (0 == (byte & 0x40) ? result : result - (1 << (shift+7))), i+1 if ((byte & 0x80) == 0)
          shift += 7
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
android_parser-2.7.0 lib/android/dex/utils.rb
android_parser-2.7.0.beta1 lib/android/dex/utils.rb
android_parser-2.6.0 lib/android/dex/utils.rb
android_parser-2.5.1 lib/android/dex/utils.rb
android_parser-2.5.0 lib/android/dex/utils.rb