]> git.saurik.com Git - cycript.git/blame_incremental - libcycript.py
Instance's toPointer() should return as CFTypeRef.
[cycript.git] / libcycript.py
... / ...
CommitLineData
1#!/usr/bin/python
2
3import os
4import sqlite3
5import sys
6
7system = sys.argv[1]
8dbfile = sys.argv[2]
9nodejs = sys.argv[3]
10merges = sys.argv[4:]
11
12system = int(system)
13nodejs += '/node/lib'
14
15keys = {}
16
17while True:
18 line = sys.stdin.readline()
19 if line == "":
20 break
21 elif line == "\n":
22 continue
23 assert line[-1] == '\n'
24 line = line[0:-1]
25
26 pipe = line.index('|')
27 name = line[0:pipe]
28 line = line[pipe+1:]
29
30 quote = line.index('"')
31 flags = int(line[0:quote])
32 code = line[quote+1:-1]
33
34 key = (name, flags, code)
35 keys[key] = system
36
37for db in merges:
38 with sqlite3.connect(db) as sql:
39 c = sql.cursor()
40 for name, system, flags, code in c.execute('select name, system, flags, code from cache'):
41 key = (name, flags, code)
42 keys[key] = keys.get(key, 0) | system
43
44if os.path.exists(dbfile):
45 os.unlink(dbfile)
46
47with sqlite3.connect(dbfile) as sql:
48 c = sql.cursor()
49
50 c.execute("create table cache (name text not null, system int not null, flags int not null, code text not null, primary key (name, system))")
51 c.execute("create table module (name text not null, flags int not null, code blob not null, primary key (name))")
52
53 for name in [js[0:-3] for js in os.listdir(nodejs) if js.endswith('.js')]:
54 with open(nodejs + '/' + name + '.js', 'r') as file:
55 code = file.read()
56 c.execute("insert into module (name, flags, code) values (?, ?, ?)", [name, 0, buffer(code)])
57
58 many = []
59 for key, system in keys.items():
60 name, flags, code = key
61 many.append((name, system, flags, code))
62 c.executemany("insert into cache (name, system, flags, code) values (?, ?, ?, ?)", many)