194 try: |
194 try: |
195 query = QSqlQuery(db) |
195 query = QSqlQuery(db) |
196 query.prepare( |
196 query.prepare( |
197 queryStr.format(",".join(["?"] * len(hashValues)))) |
197 queryStr.format(",".join(["?"] * len(hashValues)))) |
198 for hashValue in hashValues: |
198 for hashValue in hashValues: |
199 query.addBindValue(QByteArray(hashValue), |
199 query.addBindValue( |
200 QSql.In | QSql.Binary) |
200 QByteArray(hashValue), |
|
201 QSql.ParamTypeFlag.In | QSql.ParamTypeFlag.Binary) |
201 |
202 |
202 query.exec() |
203 query.exec() |
203 |
204 |
204 while query.next(): # __IGNORE_WARNING_M523__ |
205 while query.next(): # __IGNORE_WARNING_M523__ |
205 threatType = query.value(0) |
206 threatType = query.value(0) |
207 threatEntryType = query.value(2) |
208 threatEntryType = query.value(2) |
208 hasExpired = bool(query.value(3)) |
209 hasExpired = bool(query.value(3)) |
209 threatList = ThreatList(threatType, platformType, |
210 threatList = ThreatList(threatType, platformType, |
210 threatEntryType) |
211 threatEntryType) |
211 output.append((threatList, hasExpired)) |
212 output.append((threatList, hasExpired)) |
212 QCoreApplication.processEvents(QEventLoop.AllEvents, |
213 QCoreApplication.processEvents( |
213 self.maxProcessEventsTime) |
214 QEventLoop.ProcessEventsFlag.AllEvents, |
|
215 self.maxProcessEventsTime) |
214 del query |
216 del query |
215 finally: |
217 finally: |
216 db.commit() |
218 db.commit() |
217 |
219 |
218 return output |
220 return output |
253 threatEntryType = query.value(3) |
255 threatEntryType = query.value(3) |
254 negativeCacheExpired = bool(query.value(4)) |
256 negativeCacheExpired = bool(query.value(4)) |
255 threatList = ThreatList(threatType, platformType, |
257 threatList = ThreatList(threatType, platformType, |
256 threatEntryType) |
258 threatEntryType) |
257 output.append((threatList, fullHash, negativeCacheExpired)) |
259 output.append((threatList, fullHash, negativeCacheExpired)) |
258 QCoreApplication.processEvents(QEventLoop.AllEvents, |
260 QCoreApplication.processEvents( |
259 self.maxProcessEventsTime) |
261 QEventLoop.ProcessEventsFlag.AllEvents, |
|
262 self.maxProcessEventsTime) |
260 del query |
263 del query |
261 finally: |
264 finally: |
262 db.commit() |
265 db.commit() |
263 |
266 |
264 return output |
267 return output |
297 if db.isOpen(): |
300 if db.isOpen(): |
298 db.transaction() |
301 db.transaction() |
299 try: |
302 try: |
300 query = QSqlQuery(db) |
303 query = QSqlQuery(db) |
301 query.prepare(insertQueryStr) |
304 query.prepare(insertQueryStr) |
302 query.addBindValue(QByteArray(hashValue), |
305 query.addBindValue( |
303 QSql.In | QSql.Binary) |
306 QByteArray(hashValue), |
|
307 QSql.ParamTypeFlag.In | QSql.ParamTypeFlag.Binary) |
304 query.addBindValue(threatList.threatType) |
308 query.addBindValue(threatList.threatType) |
305 query.addBindValue(threatList.platformType) |
309 query.addBindValue(threatList.platformType) |
306 query.addBindValue(threatList.threatEntryType) |
310 query.addBindValue(threatList.threatEntryType) |
307 query.addBindValue(malwareThreatType) |
311 query.addBindValue(malwareThreatType) |
308 query.exec() |
312 query.exec() |
309 del query |
313 del query |
310 |
314 |
311 query = QSqlQuery(db) |
315 query = QSqlQuery(db) |
312 query.prepare(updateQueryStr) |
316 query.prepare(updateQueryStr) |
313 query.addBindValue(QByteArray(hashValue), |
317 query.addBindValue( |
314 QSql.In | QSql.Binary) |
318 QByteArray(hashValue), |
|
319 QSql.ParamTypeFlag.In | QSql.ParamTypeFlag.Binary) |
315 query.addBindValue(threatList.threatType) |
320 query.addBindValue(threatList.threatType) |
316 query.addBindValue(threatList.platformType) |
321 query.addBindValue(threatList.platformType) |
317 query.addBindValue(threatList.threatEntryType) |
322 query.addBindValue(threatList.threatEntryType) |
318 query.exec() |
323 query.exec() |
319 del query |
324 del query |
398 if db.isOpen(): |
403 if db.isOpen(): |
399 db.transaction() |
404 db.transaction() |
400 try: |
405 try: |
401 query = QSqlQuery(db) |
406 query = QSqlQuery(db) |
402 query.prepare(queryStr) |
407 query.prepare(queryStr) |
403 query.addBindValue(QByteArray(hashPrefix), |
408 query.addBindValue( |
404 QSql.In | QSql.Binary) |
409 QByteArray(hashPrefix), |
|
410 QSql.ParamTypeFlag.In | QSql.ParamTypeFlag.Binary) |
405 query.addBindValue(threatList.threatType) |
411 query.addBindValue(threatList.threatType) |
406 query.addBindValue(threatList.platformType) |
412 query.addBindValue(threatList.platformType) |
407 query.addBindValue(threatList.threatEntryType) |
413 query.addBindValue(threatList.threatEntryType) |
408 query.exec() |
414 query.exec() |
409 del query |
415 del query |
438 threatEntryType = query.value(2) |
444 threatEntryType = query.value(2) |
439 clientState = query.value(3) |
445 clientState = query.value(3) |
440 threatList = ThreatList(threatType, platformType, |
446 threatList = ThreatList(threatType, platformType, |
441 threatEntryType) |
447 threatEntryType) |
442 output.append((threatList, clientState)) |
448 output.append((threatList, clientState)) |
443 QCoreApplication.processEvents(QEventLoop.AllEvents, |
449 QCoreApplication.processEvents( |
444 self.maxProcessEventsTime) |
450 QEventLoop.ProcessEventsFlag.AllEvents, |
|
451 self.maxProcessEventsTime) |
445 del query |
452 del query |
446 finally: |
453 finally: |
447 db.commit() |
454 db.commit() |
448 |
455 |
449 return output |
456 return output |
548 checksum = None |
555 checksum = None |
549 |
556 |
550 db = QSqlDatabase.database(self.__connectionName) |
557 db = QSqlDatabase.database(self.__connectionName) |
551 if db.isOpen(): |
558 if db.isOpen(): |
552 db.transaction() |
559 db.transaction() |
553 sha256Hash = QCryptographicHash(QCryptographicHash.Sha256) |
560 sha256Hash = QCryptographicHash( |
|
561 QCryptographicHash.Algorithm.Sha256) |
554 try: |
562 try: |
555 query = QSqlQuery(db) |
563 query = QSqlQuery(db) |
556 query.prepare(queryStr) |
564 query.prepare(queryStr) |
557 query.addBindValue(threatList.threatType) |
565 query.addBindValue(threatList.threatType) |
558 query.addBindValue(threatList.platformType) |
566 query.addBindValue(threatList.platformType) |
560 |
568 |
561 query.exec() |
569 query.exec() |
562 |
570 |
563 while query.next(): # __IGNORE_WARNING_M523__ |
571 while query.next(): # __IGNORE_WARNING_M523__ |
564 sha256Hash.addData(query.value(0)) |
572 sha256Hash.addData(query.value(0)) |
565 QCoreApplication.processEvents(QEventLoop.AllEvents, |
573 QCoreApplication.processEvents( |
566 self.maxProcessEventsTime) |
574 QEventLoop.ProcessEventsFlag.AllEvents, |
|
575 self.maxProcessEventsTime) |
567 del query |
576 del query |
568 finally: |
577 finally: |
569 db.commit() |
578 db.commit() |
570 |
579 |
571 checksum = bytes(sha256Hash.result()) |
580 checksum = bytes(sha256Hash.result()) |
593 db.transaction() |
602 db.transaction() |
594 try: |
603 try: |
595 for prefix in prefixes: |
604 for prefix in prefixes: |
596 query = QSqlQuery(db) |
605 query = QSqlQuery(db) |
597 query.prepare(queryStr) |
606 query.prepare(queryStr) |
598 query.addBindValue(QByteArray(prefix), |
607 query.addBindValue( |
599 QSql.In | QSql.Binary) |
608 QByteArray(prefix), |
|
609 QSql.ParamTypeFlag.In | QSql.ParamTypeFlag.Binary) |
600 query.addBindValue(prefix[:4].hex()) |
610 query.addBindValue(prefix[:4].hex()) |
601 query.addBindValue(threatList.threatType) |
611 query.addBindValue(threatList.threatType) |
602 query.addBindValue(threatList.platformType) |
612 query.addBindValue(threatList.platformType) |
603 query.addBindValue(threatList.threatEntryType) |
613 query.addBindValue(threatList.threatEntryType) |
604 query.exec() |
614 query.exec() |
605 del query |
615 del query |
606 QCoreApplication.processEvents(QEventLoop.AllEvents, |
616 QCoreApplication.processEvents( |
607 self.maxProcessEventsTime) |
617 QEventLoop.ProcessEventsFlag.AllEvents, |
|
618 self.maxProcessEventsTime) |
608 finally: |
619 finally: |
609 db.commit() |
620 db.commit() |
610 |
621 |
611 def getHashPrefixValuesToRemove(self, threatList, indexes): |
622 def getHashPrefixValuesToRemove(self, threatList, indexes): |
612 """ |
623 """ |
644 while query.next(): # __IGNORE_WARNING_M523__ |
655 while query.next(): # __IGNORE_WARNING_M523__ |
645 if index in indexes: |
656 if index in indexes: |
646 prefix = bytes(query.value(0)) |
657 prefix = bytes(query.value(0)) |
647 output.append(prefix) |
658 output.append(prefix) |
648 index += 1 |
659 index += 1 |
649 QCoreApplication.processEvents(QEventLoop.AllEvents, |
660 QCoreApplication.processEvents( |
650 self.maxProcessEventsTime) |
661 QEventLoop.ProcessEventsFlag.AllEvents, |
|
662 self.maxProcessEventsTime) |
651 del query |
663 del query |
652 finally: |
664 finally: |
653 db.commit() |
665 db.commit() |
654 |
666 |
655 return output |
667 return output |
690 ) |
702 ) |
691 query.addBindValue(threatList.threatType) |
703 query.addBindValue(threatList.threatType) |
692 query.addBindValue(threatList.platformType) |
704 query.addBindValue(threatList.platformType) |
693 query.addBindValue(threatList.threatEntryType) |
705 query.addBindValue(threatList.threatEntryType) |
694 for prefix in removeBatch: |
706 for prefix in removeBatch: |
695 query.addBindValue(QByteArray(prefix), |
707 query.addBindValue( |
696 QSql.In | QSql.Binary) |
708 QByteArray(prefix), |
|
709 QSql.ParamTypeFlag.In | |
|
710 QSql.ParamTypeFlag.Binary) |
697 query.exec() |
711 query.exec() |
698 del query |
712 del query |
699 QCoreApplication.processEvents( |
713 QCoreApplication.processEvents( |
700 QEventLoop.AllEvents, self.maxProcessEventsTime) |
714 QEventLoop.ProcessEventsFlag.AllEvents, |
|
715 self.maxProcessEventsTime) |
701 finally: |
716 finally: |
702 db.commit() |
717 db.commit() |
703 |
718 |
704 # |
719 # |
705 # eflag: noqa = S608 |
720 # eflag: noqa = S608 |