guFolderInspector::guFolderInspector()
{
    //первоначальна¤ инициализаци¤ (защита от дурака)
    toSearchInSubFolders = true;
    nameFilters << "*.pdf" << "*.chm" << "*.djvu";
    searchPath = qApp->applicationDirPath();
    dbFilePath = qApp->applicationDirPath() +"/"+"gu.sqlite";
    checkFromLibGen = false;
    terminate = false;
    if (QFile::exists(dbFilePath))
    {
        open(dbFilePath);\
            }
    else
    {
        open(dbFilePath);
        initDb();
    }
    libGenDb = QSqlDatabase::database("libGenDB");
    if(libGenDb.isValid())
    {
        if(!libGenDb.isOpen())
        {

            if(libGenDb.open()){checkFromLibGen = true;}
            else               {checkFromLibGen = false;}
        }
        else
        {
            checkFromLibGen = true;
        }
    }
}
示例#2
0
 void CLaunchThread::uninit()
 {
    LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__ );
    initDb(0);
    initLauncher(0);
    initRequestHandler(0);
 }
/*测试共享内存*/
VOID _db_shm_test()
{
    _DB_RET ret;
    DWORD i;
    DWORD pageNo;
    initDb(1024);
    _db_t_mem_head *pMemHead;
    DWORD *p;
    VOID *q;
    _db_t_page_common_head *pPageHead;
    pMemHead = (_db_t_mem_head *) _DB_GET_MEM_HEAD(dbHandle);

    /*检查是否有足够的内存*/
    q=malloc(1024*1024*1024);
    if(!q)
    {
        printf("mallco error\n!");
        return ;
    }
    free(q);

    for (i = 0; i < 1024 * 1024 - 1; ++i)
    {
        p = (DWORD *) ((BYTE *) (dbHandle->dbAddr) + (i << pMemHead->pageShift));
        *p = 100;
        printf("i=%d\n", i);
    }

    printf("_db_mem_test_limit first loop end! ok");
    dropDb();
    initDb(1024);
    for (i = 0; i < 0xffffffff; ++i)
    {
        printf("i=%d\n", i);
        ret = _db_mem_page_new(dbHandle, &pageNo);
        if (ret != _DB_SUCCESS)
        {
            printf("new page error : i=%d, ret=%x\n", i, ret);
            break;
        }
        pPageHead = (_db_t_page_common_head *) ((BYTE *) (dbHandle->dbAddr) + (pageNo << pMemHead->pageShift));
        pPageHead->mapLen = 100;
    }
    printf("_db_mem_test_limit ok ! i=%d\n", i);
    dropDb();
}
示例#4
0
//signatures match
void sigMatch(range range, Mem *mem, int pageSize, int dsmPages[], int *match_time) {
	int i;
	struct timeval earlier;
	struct timeval later;
	//begin match
	int osNumber = initDb();
	extern fingerprint fingerprints[FINGERPRINT_NO];
	if (gettimeofday(&earlier, NULL)) {
		perror("gettimeofday() error");
		exit(1);
	}
	int availableOs[FINGERPRINT_NO], matchCounts[FINGERPRINT_NO];
	for (i = 0; i < FINGERPRINT_NO; i++) {
		availableOs[i] = 1;
		matchCounts[i] = 0;
	}
	unsigned startVirtualAddr = range.start;
	for (; startVirtualAddr <= range.end; startVirtualAddr += 0x1000) {
		unsigned pAddr = vtop(mem->mem, mem->mem_size, mem->pgd, startVirtualAddr);
		if (pAddr == -1 || pAddr > mem->mem_size)
			continue;

		int pageIndex = pAddr / pageSize;
		if (dsmPages[pageIndex] == 1) {
			int offset = (startVirtualAddr - range.start) / 4096;
			void *startAdress = (void*) ((unsigned) mem->mem + pageIndex * pageSize);
			unsigned char md5digest[16];
			MDMem(startAdress, pageSize, md5digest);
			//	printf("%x ", vaddr); //print vaddr
			MDPrint(md5digest);
			printf("\n");
			int ret = matchByIndex(osNumber, md5digest, offset, availableOs, matchCounts);
			//			if(ret ==1)
		}
	}

	int maxIndex = -1;
	int maxMatch = 0;
	for (i = 0; i < FINGERPRINT_NO; i++) {
		if (matchCounts[i] > maxMatch) {
			maxIndex = i;
			maxMatch = matchCounts[i];
		}
	}
	if (maxMatch > 0)
		printf("Os is %s, match count is %d\n", fingerprints[maxIndex].osVersion, maxMatch);

	else
		puts("Unknown OS!");

	if (gettimeofday(&later, NULL)) {
		perror("gettimeofday() error");
		exit(1);
	}

	*match_time = timeval_diff(NULL, &later, &earlier) / 1000;
	printf("match time cost is %d milliseconds\n", *match_time);
}
void DatabaseSink::startPlayback()
{
	if(playback)
		return;

	playback = true;

	initDb();

	/// populate playback queue:

	vector<vector<string> > results = shared->db->select("SELECT * FROM "+tablename);

	/// we are done with shared.  clean up:
	delete shared;
	shared = NULL;

	if(playbackShared)
	{
		delete playbackShared;
	}

	playbackShared = new PlaybackShared(routingEngine, uuid(), playbackMultiplier);

	for(int i=0;i<results.size();i++)
	{
		if(results[i].size() < 5)
		{
			throw std::runtime_error("column mismatch in query");
		}

		DBObject* obj = new DBObject();

		obj->key = results[i][0];
		obj->value = results[i][1];
		obj->source = results[i][2];
		obj->time = boost::lexical_cast<double>(results[i][3]);

		/// TODO: figure out why sequence is broken:

//		obj->sequence = boost::lexical_cast<int>(results[i][4]);

		playbackShared->playbackQueue.push_back(obj);
	}

	g_timeout_add(0,getNextEvent,playbackShared);
}
void DatabaseSink::startDb()
{
	if(playback)
	{
		DebugOut(0)<<"ERROR: tried to start logging during playback.  Only logging or playback can be used at one time"<<endl;
		return;
	}

	if(shared)
	{
		DebugOut(0)<<"WARNING: logging already started.  doing nothing."<<endl;
		return;
	}

	initDb();

	thread = g_thread_new("dbthread", cbFunc, shared);
}
void DatabaseSink::setDatabaseFileName(string filename)
{
	databaseName = filename;

	initDb();

	vector<vector<string> > supportedStr = shared->db->select("SELECT DISTINCT key FROM "+tablename);

	for(int i=0; i < supportedStr.size(); i++)
	{
		if(!ListPlusPlus<VehicleProperty::Property>(&mSupported).contains(supportedStr[i][0]))
			mSupported.push_back(supportedStr[i][0]);
	}

	delete shared;
	shared = NULL;

	routingEngine->setSupported(mSupported, this);
}
/*测试 _db_t_object_queue 插入和弹出操作*/
VOID testQueue()
{
    _DB_RET ret;
    WORD i;
    DWORD j;
    initDb(1024);
    _db_t_object_queue queue;
    _db_t_object_handle dbObjectHandle;
    for (i = 0; i < 2; ++i)
    {
        setMem();
        _db_queue_init(dbHandle, &queue, 20, i);
        for(j=0;j<1000000;j++)
        {
            ret = _db_queue_add(dbHandle,&queue,&dbObjectHandle);
            if(ret != _DB_SUCCESS)
            {
                printf("_db_queue_add fail, ret =%x, j=%x\n", ret,j);
                break;
            }
        }
        getUsedMem();
        printf("testQueue add ok, j=%d\n", j);
        for(j=0;j<1000000;j++)
        {
           ret = _db_queue_pop(dbHandle,&queue,&dbObjectHandle);
           if(ret != _DB_SUCCESS)
           {
               printf("_db_queue_pop fail, ret =%x, j=%x\n", ret,j);
               break;
           }
        }
        getUsedMem();
        printf("testQueue pop ok! j=%d\n", j);
    }

    _db_queue_destroy(dbHandle,&queue);
    getUsedMem();

}
/*测试 _db_t_object_array 写入和读出测试*/
VOID testArray()
{
    _DB_RET ret;
    DWORD i;
    DWORD *item;
    initDb(1024);
    _db_t_object_array array;
    _db_array_init(dbHandle, sizeof(DWORD), &array);
    setMem();
    for (i = 0; i < 1000000; ++i)
    {
        printf("testArray: write  %d\n",i);
        ret = _db_array_get(dbHandle, &array, i, (VOID**)&item);
        if (ret != _DB_SUCCESS)
        {
            break;
        }
        *item = i;
    }

    printf("test read write, i=%d, ret =%x\n", i, ret);

    for (i = 0; i < 1000000; ++i)
    {
        printf("testArray: read %d\n",i);
        ret = _db_array_get(dbHandle, &array, i, (VOID**)&item);
        if (ret != _DB_SUCCESS || *item != i)
        {
            printf("%d,testArray fail, ret =0x%x, i=%d, *item=%d\n", ret, i, *item);
            break;
        }
    }
    printf("test read ok, i=%d, ret =%x\n", i, ret);
    getUsedMem();
    _db_array_destroy(dbHandle, &array);
    getUsedMem();
    dropDb();
}
示例#10
0
文件: main.cpp 项目: anyboo/SPlayer
int main(int argc, char *argv[])
{
	SetErrorMode(SEM_NOGPFAULTERRORBOX);
	SetUnhandledExceptionFilter(MyUnhandledExceptionFilter);
	SingleApplication a(argc, argv);
	
	if (a.isRunning()) {

		return 0;
	}
	
	char *pFile = NULL;
	QString strFile = "";
	if (argc >= 2)
	{
		pFile = argv[1];
		QTextCodec *textcode = QTextCodec::codecForName("GB18030");
		strFile = textcode->toUnicode(pFile);
	}
#ifndef QT_NO_DEBUG
	showMainDlgNoExcept(a, strFile);
	return 1;

/*	QString appDir = QApplication::applicationDirPath() + "/";
	if (argc <= 1 || strcmp(argv[1], "-s") != 0)
	{

		QProcess::startDetached(appDir + Verify::startExe());
		return 0;

	}*/
#else
#ifdef UKey
	showMainDlgNoExcept(a, strFile);
	return 0;
#else
	AuthorFile=QApplication::applicationDirPath() + "/AuthorFile";
	initDb();
	MD5 md5_toApply;//用于生成申请码

	unsigned char address[1024];

	memset(address, 0, 1024);
#ifndef DISKSN
	if (getLocalMac(address) > 0)
#else
	if (GetHardDriveSerialNumber((char*)address, 1024) > 0)
#endif
	{
		md5_toApply.update((const char *)address);//生成申请码
	}
	else
	{

	}

	if (!Dialog::hasKey())
	{
		Dialog w;
		w.show();
		a.exec();
		exit(0);
	}
	showMainDlgNoExcept(a, strFile);
#endif
#endif 
}
示例#11
0
struct DB *newDB(void)
{
    struct DB *db = (struct DB *)malloc(1 * sizeof(struct DB));
    initDb(db);
    return db;
}
示例#12
0
文件: bookwindow.cpp 项目: maxxant/qt
BookWindow::BookWindow()
{
    ui.setupUi(this);

    if (!QSqlDatabase::drivers().contains("QSQLITE"))
        QMessageBox::critical(this, "Unable to load database", "This demo needs the SQLITE driver");

    // initialize the database
    QSqlError err = initDb();
    if (err.type() != QSqlError::NoError) {
        showError(err);
        return;
    }

    // Create the data model
    model = new QSqlRelationalTableModel(ui.bookTable);
    model->setEditStrategy(QSqlTableModel::OnManualSubmit);
    model->setTable("books");

    // Remember the indexes of the columns
    authorIdx = model->fieldIndex("author");
    genreIdx = model->fieldIndex("genre");

    // Set the relations to the other database tables
    model->setRelation(authorIdx, QSqlRelation("authors", "id", "name"));
    model->setRelation(genreIdx, QSqlRelation("genres", "id", "name"));

    // Set the localized header captions
    model->setHeaderData(authorIdx, Qt::Horizontal, tr("Author Name"));
    model->setHeaderData(genreIdx, Qt::Horizontal, tr("Genre"));
    model->setHeaderData(model->fieldIndex("title"), Qt::Horizontal, tr("Title"));
    model->setHeaderData(model->fieldIndex("year"), Qt::Horizontal, tr("Year"));
    model->setHeaderData(model->fieldIndex("rating"), Qt::Horizontal, tr("Rating"));

    // Populate the model
    if (!model->select()) {
        showError(model->lastError());
        return;
    }

    // Set the model and hide the ID column
    ui.bookTable->setModel(model);
    ui.bookTable->setItemDelegate(new BookDelegate(ui.bookTable));
    ui.bookTable->setColumnHidden(model->fieldIndex("id"), true);
    ui.bookTable->setSelectionMode(QAbstractItemView::SingleSelection);

    // Initialize the Author combo box
    ui.authorEdit->setModel(model->relationModel(authorIdx));
    ui.authorEdit->setModelColumn(model->relationModel(authorIdx)->fieldIndex("name"));

    ui.genreEdit->setModel(model->relationModel(genreIdx));
    ui.genreEdit->setModelColumn(model->relationModel(genreIdx)->fieldIndex("name"));

    QDataWidgetMapper *mapper = new QDataWidgetMapper(this);
    mapper->setModel(model);
    mapper->setItemDelegate(new BookDelegate(this));
    mapper->addMapping(ui.titleEdit, model->fieldIndex("title"));
    mapper->addMapping(ui.yearEdit, model->fieldIndex("year"));
    mapper->addMapping(ui.authorEdit, authorIdx);
    mapper->addMapping(ui.genreEdit, genreIdx);
    mapper->addMapping(ui.ratingEdit, model->fieldIndex("rating"));

    connect(ui.bookTable->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
            mapper, SLOT(setCurrentModelIndex(QModelIndex)));

    ui.bookTable->setCurrentIndex(model->index(0, 0));
}
示例#13
0
/*表的按录号访问测试*/
VOID testSkipTupleno()
{
    _DB_RET ret;
    _db_tuple_no tupleNo, i, j, tmp;
    _db_t_object_handle objectHandle;
    DWORD loop;
    initDb(1024);
    loop = 100000;
    ret = initTable(3);
    if (_DB_SUCCESS != ret)
    {
        printf("%d, init initTable error ret= %x\n", __LINE__, ret);
        dropDb();
        return;
    }
    for (tupleNo = 0; tupleNo < loop; ++tupleNo)
    {
        ret = _db_put_tuple_by_tupleno(tranHandle, dbHandle, tableHandle, (BYTE*) record, tupleNo);
        if (ret != _DB_SUCCESS)
        {
            printf("_db_put_tuple_by_tupleno error ret= %x\n", ret);
            break;
        }
    }

    j = 0;
    ret = _db_skip_first_tupleno(dbHandle, tableHandle, &i, &objectHandle);
    while (ret == _DB_FOUND)
    {
        if (j != i)
        {
            printf("%s,%d: testSkipTupleno, skip forward error, j=%d, i=%d, ret =%x\n", __FILE__,__LINE__, j, i, ret);
            break;
        }
        ret = _db_skip_next_tupleno(dbHandle, tableHandle, i, &tmp, &objectHandle);
        i = tmp;
        ++j;
    }
    if (j == loop)
    {
        printf("_db_skip_next_tupleno ok\n");
    }

    j = i;
    ret = _db_skip_last_tupleno(dbHandle, tableHandle, &i, &objectHandle);
    while (ret == _DB_FOUND)
    {
        if (j != i)
        {
            printf("%s,%d: testSkipTupleno, skip forward error, j=%d, i=%d, ret =%x\n", __FILE__,__LINE__, j, i, ret);
            break;
        }
        ret = _db_skip_prev_tupleno(dbHandle, tableHandle, i, &tmp, &objectHandle);
        i = tmp;
        ++j;
    }
    if (j == 0)
    {
        printf("_db_skip_prev_tupleno ok\n");
    }
}
示例#14
0
/* 测试大对象 ,loop小于 500000*/
VOID testBig(WORD page, WORD field, DWORD loop)
{
    _DB_RET ret;
    _db_tuple_no tupleNo;
    DWORD mem, time;
    _db_t_object_handle objectHandle;

    initDb(page);
    ret = initTable(field);
    if (_DB_SUCCESS != ret)
    {
        printf("%d, init initTable error ret= %x\n", __LINE__, ret);
        dropDb();
        return;
    }

    /* test new */
    setClock();
    setMem();
    for (tupleNo = 0; tupleNo < loop; ++tupleNo)
    {
        ret = _db_put_tuple(tranHandle, dbHandle, tableHandle, (BYTE*) record);
        if (ret != _DB_SUCCESS)
        {
            printf("_db_put_tuple error ret= %x\n", ret);
            break;
        }
    }
    time = getUsedTimes();
    mem = getUsedMem();
    writeLog("testNew: ", page, field, tupleNo, mem >> 10, time);

    /*delete given no object */
    setClock();
    for (tupleNo = 0; tupleNo < loop; ++tupleNo)
    {
        ret = _db_delete_tuple_by_tupleno(tranHandle, dbHandle, tableHandle, tupleNo);
        if (ret != _DB_SUCCESS)
        {
            printf("_db_delete_tuple_by_tupleno= %x\n", ret);
            break;
        }
    }
    time = getUsedTimes();
    mem = getUsedMem();
    writeLog("testDelGiven: ", page, field, tupleNo, mem >> 10, time);

    /*test new given */
    setClock();
    setMem();
    for (tupleNo = 0; tupleNo < loop; ++tupleNo)
    {
        ret = _db_put_tuple_by_tupleno(tranHandle, dbHandle, tableHandle, (BYTE*) record, tupleNo);
        if (ret != _DB_SUCCESS)
        {
            printf("_db_put_tuple_by_tupleno error ret= %x\n", ret);
            break;
        }
    }
    time = getUsedTimes();
    mem = getUsedMem();
    writeLog("testNewGiven: ", page, field, tupleNo, mem >> 10, time);

    /* get given no object */
    setClock();
    for (tupleNo = 0; tupleNo < loop; ++tupleNo)
    {
        ret = _db_get_tuplehandle_by_tupleno(dbHandle, tableHandle, tupleNo, &objectHandle);
        if (ret != _DB_FOUND)
        {
            printf("_db_get_tuplehandle_by_tupleno error ret= %x, objectNo=%d\n", ret, tupleNo);
            break;
        }
    }
    time = getUsedTimes();
    writeLog("testGetGiven: ", page, field, tupleNo, mem >> 10, time);

    dropDb();
}
示例#15
0
/*按记录号操作 */
VOID testTreeGiven()
{
    _DB_RET ret;
    _db_t_object_handle objectHandle, tmpHandle;
    _db_t_pool_info dbPoolInfo;
    _db_t_mem_tree tree;
    void *pObjectAddr;
    DWORD tuple[3];
    DWORD buf[3];
    DWORD i, logicNo, count, loop;
    DWORD space;
    initDb(1024);
    _db_init_mem_tree(dbHandle, &tree, 12);
    printf("*****************************************\n");
    printf("max object num of one page: %d, shift=%d\n", tree.pageCapacity, tree.shift);
    _db_mem_get_pool_info(dbHandle, &dbPoolInfo);
    space = dbPoolInfo.free;
    count = 0;
    loop = 5000000;
    for (i = loop; i > 0; --i)
    {
        srand(i);
        tuple[0] = rand();
        srand(tuple[0]);
        tuple[1] = rand();
        srand(tuple[0]);
        tuple[2] = rand();
        ret = _db_mem_tree_new_object_byNO(dbHandle, &tree, i, &objectHandle, &pObjectAddr);
        if (_DB_SUCCESS != ret)
        {
            printf("%d, _db_mem_tree_new_object fail, objectNo=%d,ret =%d\n", __LINE__, i, ret);
            break;
        }
        ret = _db_mem_get_objectNO_byHandle(dbHandle, objectHandle, &logicNo);
        if (logicNo != i)
        {
            printf("%d, _db_mem_get_objectNO_byHandle error, objectNo= %d, logicNo=%u\n", __LINE__, i, logicNo);
            break;
        }

        ret = _db_mem_write_object(dbHandle, objectHandle, 0, (void*) tuple, tree.objectClass.objectLen);
        if (ret != _DB_SUCCESS)
        {
            printf("%d, write object error, objectNo= %d, ret=%x\n", __LINE__, i, ret);
            break;
        }

        ret = _db_mem_tree_get_object_byNO(dbHandle, &tree, logicNo, &tmpHandle);
        if (ret != _DB_FOUND || tmpHandle != objectHandle)
        {
            printf("%d, bjectNo=%d,object handle error! object=%d, tmp=%d\n", __LINE__, i, objectHandle, tmpHandle);
            break;
        }
        ret = _db_mem_read_object(dbHandle, objectHandle, 0, tree.objectClass.objectLen, (void*) buf);
        if (ret != _DB_SUCCESS || (0 != memcmp(buf, tuple, 12)))
        {
            ++count;
            printf("%8d,%8d,%8d\n", tuple[0], tuple[1], tuple[2]);
            printf("%8d,%8d,%8d\n", buf[0], buf[1], buf[2]);
            printf("**************************************\n");
        }
    }
    printf("count=%u,loop=%u\n", count, loop);
    _db_mem_get_pool_info(dbHandle, &dbPoolInfo);
    printf("used page nums=%d\n", tree.objectClass.objectQueue.itemNum);
    printf("Tree: level=%d, used=%d\n", tree.level, tree.root.usedNum);
    printf("total used page nums: %d KB\n", (space - dbPoolInfo.free) >> 10);

    for (i = 0; i < loop; i++)
    {
        ret = _db_mem_tree_delete_object_byNO(dbHandle, &tree, i);
        if (ret != _DB_SUCCESS)
        {
            printf(" test:  new given object error! delete  objectNo=%d\n", i);
            break;
        }
    }
    _db_mem_get_pool_info(dbHandle, &dbPoolInfo);
    printf("current used space: %d\n", space - dbPoolInfo.free);
    dropDb();
}
示例#16
0
/*按记录号遍历*/
VOID testTreeSkiptupleno()
{
    _DB_RET ret;
    _db_t_object_handle objectHandle;
    VOID *pObjectAddr;
    DWORD i, j, k, tmp;
    _db_t_mem_tree tree;
    initDb(1024);
    _db_init_mem_tree(dbHandle, &tree, 12);
    for (i = 100; i < 10000; i++)
    {
        ret = _db_mem_tree_new_object_byNO(dbHandle, &tree, i, &objectHandle, &pObjectAddr);
        if (ret != _DB_SUCCESS)
        {
            break;
        }
    }
    --i;
    k = 100;

    ret = _db_mem_tree_get_first_objectno(dbHandle, &tree, &j, &objectHandle);
    while (_DB_FOUND == ret)
    {
        if (j != k)
        {
            printf("%s,%d: skip forward error, j=%d, k=%d, ret =%x\n", __FILE__,__LINE__, j, k, ret);
            break;
        }
        ret = _db_mem_tree_get_next_objectno(dbHandle, &tree, j, &tmp, &objectHandle);
        j = tmp;
        ++k;
    }

    if (j == i)
    {
        printf("forward ok, i=%d\n", i);
    }
    else
    {
        printf("forward fail, j=%d, ret=%x\n", j, ret);
    }

    k = i;
    ret = _db_mem_tree_get_last_objectno(dbHandle, &tree, &j, &objectHandle);
    printf("get last objectno=%d\n", j);
    while (_DB_FOUND == ret)
    {
        if (j != k)
        {
            printf("%s,%d: skip forward error, j=%d, k=%d, ret =%x\n", __FILE__,__LINE__, j, k, ret);
            break;
        }
        ret = _db_mem_tree_get_prev_objectno(dbHandle, &tree, j, &tmp, &objectHandle);
        j = tmp;
        --k;
    }

    if (j == 100)
    {
        printf("back ok\n");
    }
    else
    {
        printf("forward fail, j=%d, ret=%x\n", j, ret);
    }
    dropDb();
}
示例#17
0
/*随机测试  概率:20% 随机插入 , 40% 按记录号删除  40% 按记录号插入*/
VOID testTreeRandom()
{
    _DB_RET ret;
    _db_t_object_handle objectHandle;
    _db_t_mem_tree tree;
    VOID *pObjectAddr;
    WORD opType;
    DWORD objectNo = 0xabcd0000;
    DWORD i, loop, sum = 0;
    loop = 100000000;

    initDb(1024);
    _db_init_mem_tree(dbHandle, &tree, 12);
    setMem();
    for (i = 0; i < loop; i++)
    {
        srand(i);
        opType = rand() % 5;
        switch (opType)
        {
            case 0:
                ret = _db_mem_tree_new_object(dbHandle, &tree, &objectHandle, &pObjectAddr);
                if (ret != _DB_SUCCESS)
                {
                    printf("%s,%d:_db_mem_tree_new_object fail,i= %d, ret =%d\n", __FILE__,__LINE__, i, ret);
                }
                ++sum;
                break;
            case 1:
            case 2:
                srand(objectNo);
                objectNo = rand() & 0x0fffffff;
                ret = _db_mem_tree_delete_object_byNO(dbHandle, &tree, objectNo);
                if (ret != _DB_SUCCESS)
                {
                    printf("%s,%d:_db_mem_tree_delete_given_no_object fail,i=%d, objectNo=%d,ret =%d\n", __FILE__,__LINE__,
                           i, objectNo, ret);
                }
                else
                {
                    --sum;
                }
                break;
            default:
                srand(objectNo);
                objectNo = rand();
                ret = _db_mem_tree_new_object_byNO(dbHandle, &tree, objectNo, &objectHandle, &pObjectAddr);
                if (ret == _DB_SUCCESS)
                {
                    ++sum;
                }
                else if (ret == _DB_E_MEM_OBJECT_EXIST)
                {
                    printf("%s,%d: object exist,i=%d, objectNo=%d \n", __FILE__,__LINE__, i, objectNo);
                }
                else
                {
                    printf("%s,%d:_db_mem_tree_new_given_no_object fail,i=%d, objectNo=%d,ret =%d\n", __FILE__,__LINE__, i,
                           objectNo, ret);
                }
        }
    }
    printf("tree.level=%d\n", tree.level);
    _db_mem_tree_destroy(dbHandle, &tree);
    dropDb();
}
示例#18
0
/*测试树 随机插入对象:插入,比对记录号,按记录号读出,比对内容*/
VOID testTreeNew()
{
    _DB_RET ret;
    _db_t_object_handle objectHandle, tmpHandle;
    _db_t_pool_info dbPoolInfo;
    _db_t_mem_tree tree;
    void *pObjectAddr;
    DWORD tuple[3];
    DWORD buf[3];
    DWORD i, logicNo, count, loop;
    DWORD space;
    initDb(1024);
    _db_init_mem_tree(dbHandle, &tree, 12);
    printf("*****************************************\n");
    printf("max object num of one page: %d, shift=%d\n", tree.pageCapacity, tree.shift);
    _db_mem_get_pool_info(dbHandle, &dbPoolInfo);
    space = dbPoolInfo.free;
    count = 0;
    loop = 1000000;
    for (i = 0; i < loop; i++)
    {
        srand(i);
        tuple[0] = rand();
        srand(tuple[0]);
        tuple[1] = rand();
        srand(tuple[0]);
        tuple[2] = rand();
        /*生成一个新对象*/
        ret = _db_mem_tree_new_object(dbHandle, &tree, &objectHandle, &pObjectAddr);
        if (_DB_SUCCESS != ret)
        {
            printf("%s,%d:_db_mem_tree_new_object fail,i=%d,ret =%d\n", __FILE__,__LINE__, i, ret);
            break;
        }
        /*获取对象的记录号*/
        ret = _db_mem_get_objectNO_byHandle(dbHandle, objectHandle, &logicNo);
        if (logicNo != i)
        {
            printf("%s, %d, get object error:i= %d, logicNo=%u\n", __FILE__,__LINE__, i, logicNo);
            break;
        }

        /*写入数据*/
        ret = _db_mem_write_object(dbHandle, objectHandle, 0, (void*) tuple, tree.objectClass.objectLen);
        if (ret != _DB_SUCCESS)
        {
            printf("%d, _db_mem_write_object error. ret =%x", __LINE__, ret);
            break;
        }

        /*根据记录号获取记录*/
        ret = _db_mem_tree_get_object_byNO(dbHandle, &tree, logicNo, &tmpHandle);
        if (ret != _DB_FOUND || tmpHandle != objectHandle)
        {
            printf("%d, objectNo=%d, get object handle error! object=%d, tmp=%d\n", __LINE__, i, objectHandle,
                   tmpHandle);
            break;
        }

        /*读出数据验证*/
        ret = _db_mem_read_object(dbHandle, objectHandle, 0, tree.objectClass.objectLen, (void*) buf);
        if (ret != _DB_SUCCESS || (0 != memcmp(buf, tuple, 12)))
        {
            ++count;
            printf("**************************************\n");
            printf("%8d,%8d,%8d\n", tuple[0], tuple[1], tuple[2]);
            printf("%8d,%8d,%8d\n", buf[0], buf[1], buf[2]);
            printf("**************************************\n");
        }
    }
    _db_mem_get_pool_info(dbHandle, &dbPoolInfo);
    printf("*****************************************\n");
    printf("error read count=%u,loop=%u\n", count, loop);
    printf("max object num of one page: %d, shift=%d\n", tree.pageCapacity, tree.shift);
    printf("used data page nums=%d\n", tree.objectClass.objectQueue.itemNum);
    printf("Tree: level=%d, rootpage used=%d\n", tree.level, tree.root.usedNum);
    printf("total used page nums: %d KB\n", (space - dbPoolInfo.free) >> 10);
    printf("******************************************\n");

    printf("test Drop..\n");
    _db_mem_tree_destroy(dbHandle, &tree);
    _db_mem_get_pool_info(dbHandle, &dbPoolInfo);
    printf("total used page nums after drop: %d KB\n", (space - dbPoolInfo.free) >> 10);
    dropDb();
}
示例#19
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    w[0][0]=4.04;
    w[0][1]=0.78;
    w[0][2]=0.46;
    w[0][3]=0.42;
    w[0][4]=0.41;
    w[0][5]=0.32;

    w[1][0]=15.14;
    w[1][1]=0.92;
    w[1][2]=0.53;
    w[1][3]=0.26;
    w[1][4]=0.14;
    w[1][5]=0.07;

    w[2][0]=22.62;
    w[2][1]=0.40;
    w[2][2]=0.63;
    w[2][3]=0.25;
    w[2][4]=0.15;
    w[2][5]=0.38;




    w[0][0]=10.04;
    w[0][1]=7.78;
    w[0][2]=5.46;
    w[0][3]=3.42;
    w[0][4]=3.41;
    w[0][5]=3.32;

    w[1][0]=10.14;
    w[1][1]=7.92;
    w[1][2]=5.53;
    w[1][3]=3.26;
    w[1][4]=3.14;
    w[1][5]=2.07;

    w[2][0]=20.62;
    w[2][1]=10.40;
    w[2][2]=5.63;
    w[2][3]=2.25;
    w[2][4]=2.15;
    w[2][5]=1.38;
    w0=0.3;
    k=128;

    ui->setupUi(this);
    ui->widget_2->setMouseTracking(true);
    ui->widget_2->setCursor(QCursor(Qt::CrossCursor));

    if(!QDir("cache").exists())
    {
        QDir dir;
        dir.mkdir("cache");
    }



    if (!QSqlDatabase::drivers().contains("QSQLITE"))
        QMessageBox::critical(this, "Unable to load database", "It needs the SQLITE driver");
    QSqlError err = initDb();
    if (err.type() != QSqlError::NoError) {
        showError(err);
        return;
    }
}
示例#20
0
/* determine version of OS by mem
 * 1.To get signature of multiply versions of os, which is the md5 of kernel code
 * 2.Compared by a decision tree.
 * 3.Done!*/
void determineOsVersion(Mem * mem)
{
    int i;
    int pageSize = 4 * 1024;    //4k
    int totalPageNumber = mem->mem_size / (4 * 1024);   //assume that every page has 4k

    unsigned codePageNo = 0;
    //record when two page have different page index and the same sharp
    int calledPages[totalPageNumber];
    int dsmPages[totalPageNumber];
    //record virtual address
    unsigned virtualAddrs[totalPageNumber];
    for (i = 0; i < totalPageNumber; i++) {
        calledPages[i] = 0;
        dsmPages[i] = 0;
        virtualAddrs[i] = 0;
    }

    //start address
    unsigned startVirtualAddr = KERNEL_START_ADDRESS;

    //with dissemble or not
    int withDissemble = 1;

    int cr3PageIndex = 0;
    unsigned cr3Pages[20];
    for (i = 0; i < 20; i++) {
        cr3Pages[i] = 0;
    }

    struct timeval earlier;
    struct timeval later;
    if (gettimeofday(&earlier, NULL)) {
        perror("gettimeofday() error");
        exit(1);
    }
    //generate step 1 clusters
    clusters[0].end = 0;
    int pre_rw = -1;            //read or write
    int pre_us = -1;            //use or system
    int pre_g = -1;             //global, no move out of TLB
    int pre_ps = -1;            //page size
    unsigned cluster_index = 0;
    newstart = 1;

    unsigned vAddr = startVirtualAddr;
    for (; vAddr > KERNEL_START_ADDRESS - 1; vAddr += 0x1000) {
        //printf("startvirtual %x:\n",startVirtualAddr);

        int rw = 0;             //read or write
        int us = 0;             //use or system
        int g = 0;              //global, no move out of TLB
        int ps = 0;             //page size 4M or 4k
        unsigned pAddr =
            vtopPageProperty(mem->mem, mem->mem_size, mem->pgd, vAddr, &rw,
                             &us, &g, &ps);

        //if PHYSICAL ADDRESS is not VALID, then start a new cluster
        if (pAddr < 0 || pAddr > mem->mem_size || us != 0 || g != 256) {
            if (newstart == 0) {
                clusters[cluster_index].end = vAddr - 1;
                //printf("err address end is %x %x\n", vAddr, ranges[range_index].end);
                newstart = 1;
            }
            continue;
        }
        //if any property changes, then start a new cluster
        if (rw != pre_rw || us != pre_us || g != pre_g || ps != pre_ps) {
            if (newstart == 0) {
                clusters[cluster_index].end = vAddr - 1;
                //printf("property change end is %x %x\n", vAddr, ranges[range_index].end);
                newstart = 1;
            }
        }
        //update pre properties
        pre_rw = rw;
        pre_us = us;
        pre_g = g;
        pre_ps = ps;

        //collect pages  with continuous properties;
        if (newstart) {
            clusters[++cluster_index].start = vAddr;
            clusters[cluster_index].end = vAddr + pageSize - 1;
            newstart = 0;
        } else
            clusters[cluster_index].end = vAddr + pageSize - 1;
    }

    if (gettimeofday(&later, NULL)) {
        perror("gettimeofday() error");
        exit(1);
    }
    printf("step1, cluster: %d,time cost is %d milliseconds\n",
           cluster_index, timeval_diff(NULL, &later, &earlier) / 1000);

    //step2. kernel code page clusters with cr3
    if (gettimeofday(&earlier, NULL)) {
        perror("gettimeofday() error");
        exit(1);
    }

    unsigned startVirtual = startVirtualAddr;
    for (; startVirtual > startVirtualAddr - 1; startVirtual += 0x1000) {
        //      for (; startVirtual < 0x818f0000; startVirtual += 0x1000) {
        unsigned vAddr = startVirtual;

        int rw = 0;             //read or write
        int us = 0;             //use or system
        int g = 0;              //global(no move out of TLB) or not global
        int ps = 0;             //page size
        unsigned pAddr =
            vtopPageProperty(mem->mem, mem->mem_size, mem->pgd, vAddr, &rw,
                             &us, &g, &ps);

        // IS PHYSICAL ADDRESS VALID?
        if (pAddr == -1 || pAddr > mem->mem_size)
            continue;

        //collect pages which are system access, and global pages
        if (us == 0 && g == 256) {
//                      printf("r only page %x\n", vAddr);
            if (find_kernel(mem, vAddr, pageSize) == 0) {
                //record kernel address
                cr3Pages[cr3PageIndex++] = vAddr;
                printf("kernel start at %x\n", vAddr);
            }
        }
    }

    if (gettimeofday(&later, NULL)) {
        perror("gettimeofday() error");
        exit(1);
    }
    printf("step2 time cost is %d milliseconds\n",
           timeval_diff(NULL, &later, &earlier) / 1000);

    //step 3. clusters
    if (gettimeofday(&earlier, NULL)) {
        perror("gettimeofday() error");
        exit(1);
    }
    int cr3PagesNo = 0;
    ranges[0].end = 0;
    newstart = 1;
    for (i = 1; i <= cluster_index; i++) {
//:w            printf("%x %x\n", clusters[i].start, clusters[i].end);
        if (containKernelAddres(clusters[i], cr3Pages) == -1) {
            continue;
        }
        cr3PagesNo++;
        unsigned vAddr = clusters[i].start;
        //      printf("%x %x\n", clusters[i].start, clusters[i].end);
        newstart = 1;
        for (; vAddr < clusters[i].end; vAddr += 0x1000) {
            unsigned pAddr =
                vtop(mem->mem, mem->mem_size, mem->pgd, vAddr);
            if (vAddr == out_pc)
                code_init(mem, vAddr, pageSize, dsmPages, virtualAddrs, 1,
                          calledPages, &codePageNo);
            else
                code_init(mem, vAddr, pageSize, dsmPages, virtualAddrs, 0,
                          calledPages, &codePageNo);
        }
        ranges[range_index].end = clusters[i].end;
    }
    if (gettimeofday(&later, NULL)) {
        perror("gettimeofday() error");
        exit(1);
    }
    printf("step2, cluster: %d\n", cr3PagesNo);

    printf("step3, cluster: %d,time cost is %d milliseconds\n",
           range_index, timeval_diff(NULL, &later, &earlier) / 1000);

    //3.find the kernel core code page cluster, and print it
    int osNumber = initDb();

    if (gettimeofday(&earlier, NULL)) {
        perror("gettimeofday() error");
        exit(1);
    }

    int max_len = 0, max_index = 0;
    for (i = 1; i <= range_index; i++) {
//              printf("start:%x, end:%x: len:%x kernel\n", ranges[i].start, ranges[i].end, ranges[i].len);
        if (ranges[i].len > max_len) {
            max_index = i;
            max_len = ranges[i].len;
        }
    }

    //4.print md5 of pages that can be disassembled
    int availableOs[FINGERPRINT_NO], matchCounts[FINGERPRINT_NO];
    for (i = 0; i < FINGERPRINT_NO; i++) {
        availableOs[i] = 1;
        matchCounts[i] = 0;
    }
    startVirtualAddr = ranges[max_index].start;
    unsigned disasPageNo = 0;
    unsigned totalPageNo = 0;
    for (; startVirtualAddr <= ranges[max_index].end;
         startVirtualAddr += 0x1000) {
        totalPageNo++;
        unsigned pAddr =
            vtop(mem->mem, mem->mem_size, mem->pgd, startVirtualAddr);
        if (pAddr == -1 || pAddr > mem->mem_size)
            continue;
        int pageIndex = pAddr / pageSize;
        if (dsmPages[pageIndex] == 1) {
            int offset =
                (startVirtualAddr - ranges[max_index].start) / 4096;
            void *startAdress =
                (void *) ((unsigned) mem->mem + pageIndex * pageSize);
            unsigned char md5digest[16];
            MDMem(startAdress, pageSize, md5digest);
            //      printf("%x ", vaddr); //print vaddr
            MDPrint(md5digest);
            printf("\n");

            //search hash table
            int ret =
                matchByIndex(osNumber, md5digest, offset, availableOs,
                             matchCounts);

//                      genMd5WithOffset(startAdress, pageSize, startVirtualAddr, offset);
            disasPageNo++;
        }
    }

    if (gettimeofday(&later, NULL)) {
        perror("gettimeofday() error");
        exit(1);
    }
    printf("step4.time cost is %d milliseconds\n",
           timeval_diff(NULL, &later, &earlier) / 1000);

    int maxIndex = -1;
    int maxMatch = 0;
    for (i = 0; i < FINGERPRINT_NO; i++) {
        if (matchCounts[i] > maxMatch) {
            maxIndex = i;
            maxMatch = matchCounts[i];
        }
    }
    if (maxMatch > 0)
        printf("Os is %s, match count is %d\n",
               fingerprints[maxIndex].osVersion, maxMatch);
    else
        puts("Unknown OS!");

    return;
}
示例#21
0
/* determine version of OS by mem
 * 1.To get signature of multiply versions of os, which is the md5 of kernel code
 * 2.scan all pages of input memory, generate the md5 checksum of one page, compare to all the signature,
 * 	 if they are match, output the version of the os.
 * 3.Done!
 * 4.abandoned*/
void determineOsVersion2(Mem * mem)
{
    //get signature
    int osNumber = initDb();

    int pageSize = 4 * 1024;    //4k
    int totalPageNumber = mem->mem_size / (4 * 1024);   //assume that every page has 4k

    //record when two page have different page index and the same sharp
    int calledPages[totalPageNumber];
    int dsmPages[totalPageNumber];
    //record virtual address
    int i;
    unsigned virtualAddrs[totalPageNumber];
    for (i = 0; i < totalPageNumber; i++) {
        calledPages[i] = 0;
        dsmPages[i] = 0;
        virtualAddrs[i] = 0;
    }

    //start address
    unsigned start_vaddr = KERNEL_START_ADDRESS;
    unsigned vaddr = start_vaddr;
    int matchCount = 0;
    int matchPageIndex = 0;
    int availableOs[FINGERPRINT_NO];
    for (i = 0; i < FINGERPRINT_NO; i++)
        availableOs[i] = 1;
    for (; vaddr > start_vaddr - 1; vaddr += 0x1000) {
        int rw = 0, us = 0, g = 0, ps = 0;      //page size 4M or 4k
        unsigned pAddr =
            vtopPageProperty(mem->mem, mem->mem_size, mem->pgd, vaddr, &rw,
                             &us, &g, &ps);
        if (pAddr == -1 || pAddr > mem->mem_size)
            continue;
        int pageIndex = pAddr / pageSize;

        if (us == 0 && g == 256
            && is_code_page(mem, vaddr, pageSize, virtualAddrs) == 0) {
            page_init(mem, pageIndex, pageSize, dsmPages, 0, vaddr,
                      calledPages);
            if (dsmPages[pageIndex] != 1)
                continue;

            void *startAdress =
                (void *) ((unsigned) mem->mem + pageIndex * pageSize);
            unsigned char md5digest[16];
            MDMem(startAdress, pageSize, md5digest);
            MDPrint(md5digest);
            printf("\n");

            //search hash table
            int ret =
                match(osNumber, md5digest, &matchPageIndex, availableOs);
            while (ret == 2) {
                matchPageIndex++;
                ret =
                    match(osNumber, md5digest, &matchPageIndex,
                          availableOs);
            }
            if (ret >= 0) {
                matchPageIndex++;
                matchCount++;
                if (ret == 1)
                    break;
            }

        }

    }


    if (matchCount == 0)
        puts("Unknown OS!");
    printf("match Count:%d\n", matchCount);
}