Module: FiltSymbols

Defined in:
lib/codeobscure/filtsymbols.rb

Constant Summary collapse

@@db =
nil
@@filt_db_path =
"#{File.expand_path '../../..', __FILE__}/filtSymbols"
@@table_name =
"symbols"
@@key_words =
["interface","NSInteger","BOOL","Class","free","M_PI_2","abort","change","top","bottom","NSUIntegerMax","intoString","readonly"]

Class Method Summary collapse

Class Method Details

.createTableObject



16
17
18
19
20
21
# File 'lib/codeobscure/filtsymbols.rb', line 16

def self.createTable  
  open_db
  if @@db 
    @@db.execute "create table if not exists #{@@table_name}(src text,PRIMARY KEY (src));" 
  end
end

.insertValue(line) ⇒ Object



23
24
25
26
# File 'lib/codeobscure/filtsymbols.rb', line 23

def self.insertValue(line)  
  open_db
  @@db.execute "insert or ignore into #{@@table_name} values('#{line}');"
end

.loadFiltSymbols(path) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/codeobscure/filtsymbols.rb', line 37

def self.loadFiltSymbols(path) 

  @@db = SQLite3::Database.new(@@filt_db_path)
  createTable
  
  funclist_path = FuncList.genFuncList path , "all" , false

  puts "处理中,可能需要一段时间,耐心等候...".colorize(:yellow)
  symbol_file = File.open(funclist_path).read
  symbol_file.each_line do |line|
    line_content = line.rstrip.split(":").last
    insertValue line_content  
  end

  @@key_words.each do |word|
    insertValue word
  end

  if File.exist? funclist_path  
    `rm -f '#{funclist_path}'`
  end

end

.loadStrictMode(path) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/codeobscure/filtsymbols.rb', line 62

def self.loadStrictMode(path) 
  file_pathes = []
  file_pathes += `find #{path} -name "*.h" -d`.split "\n"
  file_pathes += `find #{path} -name "*.m" -d`.split "\n"
  
  file_pathes.each do |file_path|
    content = File.read file_path
    FuncList.loadStrictSymbols content
  end
  
end

.open_dbObject



10
11
12
13
14
# File 'lib/codeobscure/filtsymbols.rb', line 10

def self.open_db 
  if @@db.nil? || @@db.closed? 
    @@db = SQLite3::Database.new(@@filt_db_path)
  end
end

.query(line) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/codeobscure/filtsymbols.rb', line 28

def self.query(line) 
  open_db
  results = []
  @@db.execute "select * from #{@@table_name} where src='#{line}';" do |row|
    results << row
  end
  results
end