Class: ModifyCode::Modify

Inherits:
Object
  • Object
show all
Defined in:
lib/core_blur/modify/modify_code.rb

Class Method Summary collapse

Class Method Details

.modify_fbObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/core_blur/modify/modify_code.rb', line 4

def self.modify_fb
  self.replace_str("Pods/FBRetainCycleDetector/FBRetainCycleDetector/Layout/Classes/FBClassStrongLayout.mm",
                  "layoutCache[currentClass] = ivars;",
                  "layoutCache[(id<NSCopying>)currentClass] = ivars;")
  self.replace_str("Pods/FBRetainCycleDetector/fishhook/fishhook.c",
                  "indirect_symbol_bindings[i] = cur->rebindings[j].replacement;",
                  "if(i < (sizeof(indirect_symbol_bindings) /sizeof(indirect_symbol_bindings[0]))) {indirect_symbol_bindings[i]=cur->rebindings[j].replacement;}")
  new_string = "#import  <objc/runtime.h>
#import <malloc/malloc.h>"
  self.replace_str("Pods/FBRetainCycleDetector/FBRetainCycleDetector/Graph/FBObjectiveCGraphElement.mm",
                  "#import <objc/runtime.h>",
                  new_string)
  new_string = "malloc_zone_t *zone = malloc_zone_from_ptr((__bridge void *)object); if (zone) { Class aCls=object_getClass(object);"
  self.replace_str("Pods/FBRetainCycleDetector/FBRetainCycleDetector/Graph/FBObjectiveCGraphElement.mm",
                  "Class aCls = object_getClass(object);",
                  new_string)
  new_string = "}
# endif"
  self.replace_str("Pods/FBRetainCycleDetector/FBRetainCycleDetector/Graph/FBObjectiveCGraphElement.mm",
                  "#endif",
                  new_string)
end

.replace_str(file_path, find, replace) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/core_blur/modify/modify_code.rb', line 26

def self.replace_str(file_path, find, replace)
  unless File.exist?(file_path)
    return
  end
  replace_string = replace
  FileUtils.chmod("+w", file_path)
  text = File.read(file_path)
  replace = text.gsub(find, replace)
  if text != replace
    File.open(file_path, "w") do |file|
      file.puts replace
    end
    file_name = File.basename(file_path)
    puts "代码替换: #{file_name} (#{find} => #{replace_string})"
  end
end