injection-helper 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/injection +52 -0
- data/lib/injection.rb +129 -0
- metadata +52 -0
    
        data/bin/injection
    ADDED
    
    | @@ -0,0 +1,52 @@ | |
| 1 | 
            +
            #!/usr/bin/env ruby
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'injection'
         | 
| 4 | 
            +
            require 'optparse'
         | 
| 5 | 
            +
             | 
| 6 | 
            +
            class OptionsParser
         | 
| 7 | 
            +
             | 
| 8 | 
            +
              def self.parse(args)
         | 
| 9 | 
            +
                options = {}
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                opt_parser = OptionParser.new do |opts|
         | 
| 12 | 
            +
                  opts.banner = 'Usage: injection COMMAND [options]'
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                  opts.separator ''
         | 
| 15 | 
            +
                  opts.separator 'Use "patch", "revert", "refresh", "mute", "unmute" as a COMMAND'
         | 
| 16 | 
            +
                  opts.separator ''
         | 
| 17 | 
            +
                  opts.on_tail('-h', '--help', 'Show this message') do
         | 
| 18 | 
            +
                    puts opts
         | 
| 19 | 
            +
                    exit
         | 
| 20 | 
            +
                  end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                end
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                opt_parser.parse!(args)
         | 
| 25 | 
            +
                options
         | 
| 26 | 
            +
              end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
            end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
             | 
| 31 | 
            +
            arg = ARGV[0]
         | 
| 32 | 
            +
            options = OptionsParser.parse(ARGV)
         | 
| 33 | 
            +
             | 
| 34 | 
            +
            case arg
         | 
| 35 | 
            +
              when 'revert'
         | 
| 36 | 
            +
                injection = Injection.new
         | 
| 37 | 
            +
                injection.revert
         | 
| 38 | 
            +
              when 'patch'
         | 
| 39 | 
            +
                injection = Injection.new
         | 
| 40 | 
            +
                injection.patch
         | 
| 41 | 
            +
              when 'refresh'
         | 
| 42 | 
            +
                  injection = Injection.new
         | 
| 43 | 
            +
                  injection.refresh
         | 
| 44 | 
            +
              when 'mute'
         | 
| 45 | 
            +
                  injection = Injection.new
         | 
| 46 | 
            +
                  injection.mute_all
         | 
| 47 | 
            +
              when 'unmute'
         | 
| 48 | 
            +
                  injection = Injection.new
         | 
| 49 | 
            +
                  injection.unmute_all
         | 
| 50 | 
            +
              else
         | 
| 51 | 
            +
                OptionsParser.parse(["-h"])
         | 
| 52 | 
            +
            end
         | 
    
        data/lib/injection.rb
    ADDED
    
    | @@ -0,0 +1,129 @@ | |
| 1 | 
            +
            require 'socket'
         | 
| 2 | 
            +
            require 'securerandom'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            class Injection
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              def initialize
         | 
| 7 | 
            +
                home = Dir.home
         | 
| 8 | 
            +
                @resources = home + '/Library/Application Support/Developer/Shared/Xcode/Plug-ins/InjectionPlugin.xcplugin/Contents/Resources/'
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                project_files = Dir.glob('./*.xcodeproj')
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                if project_files.size != 1
         | 
| 13 | 
            +
                  raise 'Zero or more than one project file found in current path. Make sure you run this script in XCode project directory '
         | 
| 14 | 
            +
                end
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                @project_file = project_files[0]
         | 
| 17 | 
            +
              end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              def revert
         | 
| 20 | 
            +
                self.execute_command('revertProject.pl')
         | 
| 21 | 
            +
              end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              def patch
         | 
| 24 | 
            +
                self.execute_command('patchProject.pl')
         | 
| 25 | 
            +
              end
         | 
| 26 | 
            +
             | 
| 27 | 
            +
              def refresh
         | 
| 28 | 
            +
                self.revert
         | 
| 29 | 
            +
                self.patch
         | 
| 30 | 
            +
              end
         | 
| 31 | 
            +
             | 
| 32 | 
            +
              def my_first_public_ipv4
         | 
| 33 | 
            +
                Socket.ip_address_list.detect { |intf| intf.ipv4? and !intf.ipv4_loopback? and !intf.ipv4_multicast? }.ip_address
         | 
| 34 | 
            +
              end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
              def execute_command(script_name)
         | 
| 37 | 
            +
                ip = self.my_first_public_ipv4
         | 
| 38 | 
            +
                puts "ip: #{ip}"
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                backup_suffix = SecureRandom.hex
         | 
| 41 | 
            +
                mute_script 'common.pm', backup_suffix
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                command = "\"#{@resources}#{script_name}\"  \"#{@resources}\" \"#{@project_file}\" \"\" \"\" i386 0 20 0 \"127.0.0.1 #{ip}\" 31444"
         | 
| 44 | 
            +
                system(command)
         | 
| 45 | 
            +
             | 
| 46 | 
            +
                unmute_script 'common.pm', backup_suffix
         | 
| 47 | 
            +
              end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
              def mute_script(script_name, backup_suffix = '')
         | 
| 50 | 
            +
                path = "#{@resources}#{script_name}"
         | 
| 51 | 
            +
                bak_path = "#{path}_bak#{backup_suffix}"
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                if File.exist?(bak_path)
         | 
| 54 | 
            +
                  return
         | 
| 55 | 
            +
                end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                system("cp \"#{path}\" \"#{bak_path}\"")
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                puts "path: #{path}"
         | 
| 60 | 
            +
                text = File.read(path)
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                muting_definitions[script_name].each { |line|
         | 
| 63 | 
            +
                  line.each { |to_replace, replacement|
         | 
| 64 | 
            +
                    puts "to_replace: #{to_replace}"
         | 
| 65 | 
            +
                    puts "replacement: #{replacement}"
         | 
| 66 | 
            +
                    text.gsub! to_replace, replacement
         | 
| 67 | 
            +
                  }
         | 
| 68 | 
            +
             | 
| 69 | 
            +
                }
         | 
| 70 | 
            +
                File.open(path, 'w') { |file| file.puts text }
         | 
| 71 | 
            +
             | 
| 72 | 
            +
              end
         | 
| 73 | 
            +
             | 
| 74 | 
            +
              def unmute_script(script_name, backup_suffix = '')
         | 
| 75 | 
            +
                path = "#{@resources}#{script_name}"
         | 
| 76 | 
            +
                bak_path = "#{path}_bak#{backup_suffix}"
         | 
| 77 | 
            +
             | 
| 78 | 
            +
                system("cp \"#{bak_path}\" \"#{path}\"")
         | 
| 79 | 
            +
                system("rm \"#{bak_path}\" ")
         | 
| 80 | 
            +
              end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
              def convert_file(script_name, reverse)
         | 
| 83 | 
            +
                path = "#{@resources}#{script_name}"
         | 
| 84 | 
            +
                bak_path = "#{path}_bak"
         | 
| 85 | 
            +
             | 
| 86 | 
            +
                system("cp \"#{path}\" \"#{bak_path}\"")
         | 
| 87 | 
            +
             | 
| 88 | 
            +
                puts "path: #{path}"
         | 
| 89 | 
            +
                text = File.read(path)
         | 
| 90 | 
            +
             | 
| 91 | 
            +
                muting_definitions[script_name].each { |line|
         | 
| 92 | 
            +
                  line.each { |to_replace, replacement|
         | 
| 93 | 
            +
                    puts "to_replace: #{to_replace}"
         | 
| 94 | 
            +
                    puts "replacement: #{replacement}"
         | 
| 95 | 
            +
                    text.gsub! to_replace, replacement
         | 
| 96 | 
            +
                  }
         | 
| 97 | 
            +
             | 
| 98 | 
            +
                }
         | 
| 99 | 
            +
                File.open(path, 'w') { |file| file.puts text }
         | 
| 100 | 
            +
              end
         | 
| 101 | 
            +
             | 
| 102 | 
            +
              def mute_all
         | 
| 103 | 
            +
             | 
| 104 | 
            +
                muting_definitions.each { |key, value|
         | 
| 105 | 
            +
                  mute_script key
         | 
| 106 | 
            +
                }
         | 
| 107 | 
            +
             | 
| 108 | 
            +
              end
         | 
| 109 | 
            +
             | 
| 110 | 
            +
              def unmute_all
         | 
| 111 | 
            +
             | 
| 112 | 
            +
                muting_definitions.each { |key, value|
         | 
| 113 | 
            +
                  unmute_script key
         | 
| 114 | 
            +
                }
         | 
| 115 | 
            +
             | 
| 116 | 
            +
              end
         | 
| 117 | 
            +
             | 
| 118 | 
            +
              def muting_definitions
         | 
| 119 | 
            +
                {'BundleInjection.h' => [{
         | 
| 120 | 
            +
                                             '[alert show];' => '/* REDACTED */'
         | 
| 121 | 
            +
                                         }],
         | 
| 122 | 
            +
                 'common.pm' => [{
         | 
| 123 | 
            +
                                     'system "open \'$file\'";' => '# REDACTED ";'
         | 
| 124 | 
            +
                                 }],
         | 
| 125 | 
            +
                }
         | 
| 126 | 
            +
              end
         | 
| 127 | 
            +
             | 
| 128 | 
            +
            end
         | 
| 129 | 
            +
             | 
    
        metadata
    ADDED
    
    | @@ -0,0 +1,52 @@ | |
| 1 | 
            +
            --- !ruby/object:Gem::Specification
         | 
| 2 | 
            +
            name: injection-helper
         | 
| 3 | 
            +
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            +
              version: 0.0.1
         | 
| 5 | 
            +
              prerelease: 
         | 
| 6 | 
            +
            platform: ruby
         | 
| 7 | 
            +
            authors:
         | 
| 8 | 
            +
            - Michal Lukasiewicz
         | 
| 9 | 
            +
            autorequire: 
         | 
| 10 | 
            +
            bindir: bin
         | 
| 11 | 
            +
            cert_chain: []
         | 
| 12 | 
            +
            date: 2014-11-07 00:00:00.000000000 Z
         | 
| 13 | 
            +
            dependencies: []
         | 
| 14 | 
            +
            description: ! 'It lets you patch your project for XCode injection directly from command
         | 
| 15 | 
            +
              line rather than
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              using option in Xcode or AppCode menu, which generates a lot of alerts'
         | 
| 18 | 
            +
            email: michal.lukasiewicz@brightinventions.pl
         | 
| 19 | 
            +
            executables:
         | 
| 20 | 
            +
            - injection
         | 
| 21 | 
            +
            extensions: []
         | 
| 22 | 
            +
            extra_rdoc_files: []
         | 
| 23 | 
            +
            files:
         | 
| 24 | 
            +
            - lib/injection.rb
         | 
| 25 | 
            +
            - bin/injection
         | 
| 26 | 
            +
            homepage: https://github.com/bright/injection
         | 
| 27 | 
            +
            licenses:
         | 
| 28 | 
            +
            - MIT
         | 
| 29 | 
            +
            post_install_message: 
         | 
| 30 | 
            +
            rdoc_options: []
         | 
| 31 | 
            +
            require_paths:
         | 
| 32 | 
            +
            - lib
         | 
| 33 | 
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         | 
| 34 | 
            +
              none: false
         | 
| 35 | 
            +
              requirements:
         | 
| 36 | 
            +
              - - ! '>='
         | 
| 37 | 
            +
                - !ruby/object:Gem::Version
         | 
| 38 | 
            +
                  version: '0'
         | 
| 39 | 
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         | 
| 40 | 
            +
              none: false
         | 
| 41 | 
            +
              requirements:
         | 
| 42 | 
            +
              - - ! '>='
         | 
| 43 | 
            +
                - !ruby/object:Gem::Version
         | 
| 44 | 
            +
                  version: '0'
         | 
| 45 | 
            +
            requirements: []
         | 
| 46 | 
            +
            rubyforge_project: 
         | 
| 47 | 
            +
            rubygems_version: 1.8.24
         | 
| 48 | 
            +
            signing_key: 
         | 
| 49 | 
            +
            specification_version: 3
         | 
| 50 | 
            +
            summary: simple command line utility for patching project for InjectionForXcode and
         | 
| 51 | 
            +
              reverting it
         | 
| 52 | 
            +
            test_files: []
         |