Module: Objc_Obfuscator::Integrator

Included in:
CLI
Defined in:
lib/objc-obfuscator/integrator.rb

Instance Method Summary collapse

Instance Method Details

#integrate_xcode(encryption_key, project_path, podfile_path, target_name) ⇒ Object

Raises:

  • (Thor::Error)


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/objc-obfuscator/integrator.rb', line 6

def integrate_xcode(encryption_key, project_path, podfile_path, target_name)
  project = Xcodeproj::Project.open project_path

  main_target = project.targets.first

  unless target_name.empty?
    main_target = project.targets.select { |a| (a.name == target_name) }.first
  end

  raise Thor::Error, 'Cannot find the specified target' unless main_target

  phase_obf = project.new('PBXShellScriptBuildPhase')
  phase_obf.name = "Obfuscate strings"
  phase_obf.shell_path = '/bin/bash'
  phase_obf.shell_script = "  if [ -f \"$HOME/.rvm/scripts/rvm\" ];\n  then\n    source $HOME/.rvm/scripts/rvm\n    rvm rvmrc trust\n    rvm rvmrc load\n  fi\n  find ${SRCROOT} -name \"*.h\" -exec objc-obfuscator obfuscate \#{encryption_key} {} \\\\;\n  find ${SRCROOT} -name \"*.m\" -exec objc-obfuscator obfuscate \#{encryption_key} {} \\\\;\n  SCRIPT\n\n  phase_unobf = project.new('PBXShellScriptBuildPhase')\n  phase_unobf.name = \"Unobfuscate strings\"\n  phase_unobf.shell_path = '/bin/bash'\n  phase_unobf.shell_script = <<-SCRIPT\n  find ${SRCROOT} -name \"*.bak\" -exec bash -c 'mv -f \"$1\" \"${1%.bak}\"' _ {} \\\\;\n  SCRIPT\n\n  build_source_phase_idx = main_target.build_phases.index main_target.source_build_phase\n  obf_phase_idx = build_source_phase_idx\n\n  main_target.build_phases.insert obf_phase_idx, phase_obf\n\n  phase_unobf_idx = build_source_phase_idx+2\n  if(phase_unobf_idx >= main_target.build_phases.size)\n    main_target.build_phases << phase_unobf \n  else\n     main_target.build_phases.insert phase_unobf_idx, phase_unobf\n  end\n\n  project.save\n\n  if File.readlines(podfile_path).grep(/objc_obfuscator/).size == 0\n    File.open(podfile_path, 'a') {|f| f.write('pod \"FWTObfuscator\"') }\n  end\n\n  say_status :info, 'The project has been correctly update. Please run \"pod install\" to install the required pods', :blue\nend\n"