Exemple #1
0
    def next_step(self):
        out_path = os.path.join(
            os.path.dirname(self.db_path),
            os.path.splitext(os.path.basename(self.db_path))[0] + '.txt')
        print(out_path)

        preprocess.preprocess_db(self.db_path)
        train.train(self.db_path, out_path, fileid=True)
        explore.explore(self.db_path)
        self.preprocessed = True
Exemple #2
0
def process_sample_file(db_path, sample_path, first_only=False):
    db = sqlite3.connect(db_path)
    c = db.cursor()

    with open(sample_path) as infile:
        sample = infile.read()

    i = 0
    tail = 0
    offset = len('__kernel void ')
    while True:
        print('\r\033[Kkernel', i, end='')
        sys.stdout.flush()

        # Find the starting index of the next kernel.
        tail = sample.find('__kernel void ', tail)

        # If we didn't find another kernel, stop.
        if tail == -1:
            break

        # Find the end index of this kernel.
        head = clutil.get_cl_kernel_end_idx(sample, start_idx=tail,
                                            max_len=MAX_KERNEL_LEN)

        # Look for other ends
        end = sample.find('__kernel void ',
                          tail + offset, tail + offset + MAX_KERNEL_LEN)
        head = min(end, head) if end != -1 else head

        kernel = sample[tail:head]
        id = smith.checksum_str(kernel)
        c.execute('INSERT OR IGNORE INTO ContentFiles VALUES(?,?)',
                  (id,kernel))
        tail = head
        i += 1
        if first_only:
            break
    print()
    db.commit()
    c.close()
    explore.explore(db_path)