metabridge 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 849678e16e469421c068a86dc7780fd471b07d01
4
+ data.tar.gz: 1850c31c66f9564c18d13c425192342eb7e9ef29
5
+ SHA512:
6
+ metadata.gz: 634c9e84b023b40ac18c485eb4c56f7b5d22f0386123f0ac88b55f9672516a3a94b2c90abe80a27b569f9d01c52c059c3a98009f6e3cbc594822983b7a41d083
7
+ data.tar.gz: cefd6c3b11d68019fe0320fcb8380c88fa5710b7747ab00f298b26b45e3265499c8a5665a7afee1eb0298106629b2d8a882cfd35d11226c028b8e5f6df3851cd
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in metabridge.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Andrei Maxim
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ [![Code Climate](https://codeclimate.com/github/Telmate/metabridge/badges/gpa.svg)](https://codeclimate.com/github/Telmate/metabridge)
2
+ [![Test Coverage](https://codeclimate.com/github/Telmate/metabridge/badges/coverage.svg)](https://codeclimate.com/github/Telmate/metabridge/coverage)
3
+ [![Dependency Status](https://gemnasium.com/Telmate/metabridge.svg)](https://gemnasium.com/Telmate/metabridge)
4
+
5
+ # metabridge
6
+
7
+ metabridge is a tool that enables easy access to the Android Debug Brige.
8
+
9
+ ## Installation
10
+
11
+ metabridge can be installed as a command-line tool or as a Ruby gem that can be
12
+ used in other Ruby programs.
13
+
14
+ To install it for command-line use only, use the `gem` command:
15
+
16
+ $ gem install metabridge
17
+
18
+ You can also add it to your application's Gemfile:
19
+
20
+ ```ruby
21
+ gem 'metabridge'
22
+ ```
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+
29
+ ## Usage
30
+
31
+ As a command-line tool, metabridge uses the `metabridge` command. Simply run the
32
+ following command to get a list of all the available subcommands and some
33
+ examples:
34
+
35
+ ```shell
36
+ $ metabridge
37
+ ```
38
+
39
+ ## Development
40
+
41
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
42
+
43
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it ( https://github.com/Telmate/metabridge/fork )
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+ require 'rake/clean'
4
+
5
+ CLOBBER.include('**/*.gem')
6
+
7
+ Rake::TestTask.new do |t|
8
+ t.libs << 'spec'
9
+ t.pattern = "spec/**/*_spec.rb"
10
+ end
11
+
12
+ task :default => [:test]
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "metabridge"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/exe/metabridge ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'metabridge'
4
+
5
+ MetaBridge::CLI.start
@@ -0,0 +1,10 @@
1
+ require 'meta_bridge/version'
2
+
3
+ require 'meta_bridge/cli'
4
+ require 'meta_bridge/command'
5
+ require 'meta_bridge/device'
6
+
7
+ module MetaBridge
8
+ DEFAULT_PORT = 5555
9
+ DEFAULT_IFACE = 'eth1'
10
+ end
@@ -0,0 +1,30 @@
1
+ require 'meta_bridge/command'
2
+
3
+ class MetaBridge::ARP
4
+ include MetaBridge::Command
5
+
6
+ IP_REGEX = /(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b)/i
7
+ MAC_REGEX = /([0-9A-F]{2}[:-]){5}([0-9A-F]{2})/i
8
+
9
+ def connections
10
+ connections = []
11
+ run('arp -i eth1 -a') do |out|
12
+ while line = out.gets
13
+ connections << parse_arp_line(line)
14
+ end
15
+ end
16
+
17
+ connections
18
+ end
19
+
20
+ def parse_arp_line(line)
21
+ hsh = {}
22
+
23
+ line.split.each do |token|
24
+ hsh[:ip] = $1 if token =~ IP_REGEX
25
+ hsh[:mac] = token if token =~ MAC_REGEX
26
+ end
27
+
28
+ hsh
29
+ end
30
+ end
@@ -0,0 +1,44 @@
1
+ require 'meta_bridge/command'
2
+
3
+ # Wrapper class for the Android Debug Bridge (adb).
4
+ class MetaBridge::Bridge
5
+
6
+ include MetaBridge::Command
7
+
8
+ attr_accessor :device_id
9
+
10
+ def get_state
11
+ run(adb 'get-state') { |out| out.gets.strip }
12
+ end
13
+
14
+ def logcat(opts = {})
15
+ params = []
16
+ params << '-v threadtime'
17
+ params << '-d'
18
+
19
+ run(adb 'logcat', params) do |out|
20
+ while line = out.gets
21
+ puts line
22
+ end
23
+ end
24
+ end
25
+
26
+ def connect_to_device
27
+ run(adb 'connect', device_id)
28
+ end
29
+
30
+ def adb(subcommand, params = [])
31
+ connect_to_device if device_id && subcommand != 'connect'
32
+
33
+ cmd = []
34
+ params = params.respond_to?(:join) ? params.join(' ') : params.to_s
35
+
36
+ cmd << 'adb'
37
+ cmd << "-s #{device_id}" if device_id
38
+ cmd << subcommand
39
+ cmd << params.is_a?(String) ? params : params.join(' ')
40
+
41
+ cmd.join(' ')
42
+ end
43
+
44
+ end
@@ -0,0 +1,68 @@
1
+ require 'thor'
2
+ require 'meta_bridge/device'
3
+
4
+ class MetaBridge::CLI < Thor
5
+
6
+ desc 'list', 'List all the connected Android devices'
7
+ long_desc <<RAG
8
+ The list command will show all the possible tablets that might be connected to
9
+ the current AP using the ARP table. It's a different method than using plain
10
+ `adb devices` because it also shows devices without any previous connections.
11
+
12
+ The `list` command will also cycle through all the possible tablets and try to
13
+ get the state of the device using the Android Debug Bridge.
14
+
15
+ Example usage:
16
+
17
+ $ metabridge list\x5
18
+ Device found: 10.10.1.50 00:27:22:d4:d5:da\x5
19
+ Device found: 10.10.1.79 ac:22:0b:45:99:49\x5
20
+ Device found: 10.10.1.82 ac:22:0b:67:94:91\x5
21
+ RAG
22
+ def list
23
+ devices = MetaBridge::Device.all
24
+ str = []
25
+
26
+ devices.each do |device|
27
+ device_str = 'Device found: '
28
+ device_str += set_color(device.ip.ljust(16), :yellow) # 255.255.255.255
29
+ device_str += set_color(device.mac.ljust(18), :green) # aa:aa:aa:aa:aa:aa
30
+
31
+ str << device_str
32
+ end
33
+
34
+ if str.empty?
35
+ say 'No devices found'
36
+ else
37
+ say str.join("\n")
38
+ end
39
+ end
40
+
41
+ desc 'log', 'Output the logcat for a specific device'
42
+ option 'd', required: true
43
+ long_desc <<RAG
44
+ Get the output of logcat for a specific Android device using the Android
45
+ Debug Bridge. The required parameter is the device MAC address, which can be
46
+ obtained using `metabridge list`
47
+
48
+ Example usage:
49
+
50
+ $ metabridge log -d 00:27:22:d4:d5:da
51
+ <OUTPUT>
52
+
53
+ In order to save the output to a file, simply run the following command:
54
+ $ metabridge log -d 00:27:22:d4:d5:da > logcat.txt
55
+ RAG
56
+ def log
57
+ mac = options[:d]
58
+
59
+ devices = MetaBridge::Device.all
60
+ device = devices.select { |d| d.mac == mac }.first
61
+
62
+ if device
63
+ say device.log
64
+ else
65
+ say 'No device found'
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,9 @@
1
+ require 'open3'
2
+
3
+ module MetaBridge::Command
4
+ def run(cmd, &block)
5
+ Open3.popen2e(cmd) do |stdin, out, wait_thr|
6
+ yield(out, wait_thr) if block_given?
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,43 @@
1
+ require 'meta_bridge/bridge'
2
+ require 'meta_bridge/arp'
3
+
4
+ class MetaBridge::Device
5
+
6
+ DEFAULT_IP = '0.0.0.0'
7
+ DEFAULT_MAC = '00:00:00:00:00:00'
8
+ ONLINE_STATE = 'device'.freeze
9
+
10
+ attr_reader :ip
11
+ attr_reader :mac
12
+ attr_reader :port
13
+ attr_reader :bridge
14
+
15
+ class << self
16
+ def all(opts = {})
17
+ proxy = opts.delete(:proxy) || MetaBridge::ARP.new
18
+
19
+ devices = proxy.connections.map do |con|
20
+ MetaBridge::Device.new(con.merge(opts))
21
+ end
22
+
23
+ devices.select { |d| d.online? }
24
+ end
25
+ end
26
+
27
+ def initialize(hsh = {})
28
+ @ip = hsh[:ip] || MetaBridge::Device::DEFAULT_IP
29
+ @mac = hsh[:mac] || MetaBridge::Device::DEFAULT_MAC
30
+ @port = hsh[:port] || MetaBridge::DEFAULT_PORT
31
+
32
+ @bridge = hsh[:bridge] || MetaBridge::Bridge.new
33
+ @bridge.device_id = "#{ip}:#{port}"
34
+ end
35
+
36
+ def online?
37
+ bridge.get_state == ONLINE_STATE
38
+ end
39
+
40
+ def log
41
+ bridge.logcat
42
+ end
43
+ end
@@ -0,0 +1,3 @@
1
+ module MetaBridge
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'meta_bridge/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "metabridge"
8
+ spec.version = MetaBridge::VERSION
9
+ spec.version = "#{spec.version}-#{ENV['BUILD_NUMBER']}" if ENV['BUILD_NUMBER']
10
+ spec.authors = ["Andrei Maxim"]
11
+ spec.email = ["max@throwpoint.ro"]
12
+
13
+ spec.summary = %q{Get logcat output from a remote Android tablet.}
14
+ spec.description = %q{Get logcat output from a remote Android tablet using adb commands'}
15
+ spec.homepage = "https://github.com/Telmate/metabridge"
16
+ spec.license = "MIT"
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_dependency 'thor', '~> 0.19.1'
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.9"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "minitest", "~> 5.6"
28
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: metabridge
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrei Maxim
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-05-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.19.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.19.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.9'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.9'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.6'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.6'
69
+ description: Get logcat output from a remote Android tablet using adb commands'
70
+ email:
71
+ - max@throwpoint.ro
72
+ executables:
73
+ - metabridge
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - exe/metabridge
87
+ - lib/meta_bridge.rb
88
+ - lib/meta_bridge/arp.rb
89
+ - lib/meta_bridge/bridge.rb
90
+ - lib/meta_bridge/cli.rb
91
+ - lib/meta_bridge/command.rb
92
+ - lib/meta_bridge/device.rb
93
+ - lib/meta_bridge/version.rb
94
+ - metabridge.gemspec
95
+ homepage: https://github.com/Telmate/metabridge
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.4.5
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Get logcat output from a remote Android tablet.
119
+ test_files: []