2017-10-02 16:18:40 +00:00
|
|
|
#include "ImportsWidget.h"
|
|
|
|
#include "ui_ImportsWidget.h"
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-10-01 19:09:42 +00:00
|
|
|
#include "MainWindow.h"
|
|
|
|
#include "utils/Helpers.h"
|
2017-04-13 15:14:02 +00:00
|
|
|
|
|
|
|
#include <QTreeWidget>
|
|
|
|
#include <QPen>
|
|
|
|
#include <QPainter>
|
|
|
|
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-04-09 19:55:06 +00:00
|
|
|
void CMyDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2017-04-12 22:05:58 +00:00
|
|
|
QStyleOptionViewItem itemOption(option);
|
2017-03-29 10:18:37 +00:00
|
|
|
initStyleOption(&itemOption, index);
|
|
|
|
|
|
|
|
itemOption.rect.adjust(10, 0, 0, 0); // Make the item rectangle 10 pixels smaller from the left side.
|
|
|
|
|
|
|
|
// Draw your item content.
|
|
|
|
QApplication::style()->drawControl(QStyle::CE_ItemViewItem, &itemOption, painter, nullptr);
|
|
|
|
|
|
|
|
// And now you can draw a bottom border.
|
|
|
|
//painter->setPen(Qt::cyan);
|
|
|
|
QPen pen = painter->pen();
|
|
|
|
pen.setColor(Qt::white);
|
|
|
|
pen.setWidth(1);
|
|
|
|
painter->setPen(pen);
|
|
|
|
painter->drawLine(itemOption.rect.bottomLeft(), itemOption.rect.bottomRight());
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Imports Widget
|
|
|
|
*/
|
|
|
|
|
2018-03-16 21:46:57 +00:00
|
|
|
ImportsWidget::ImportsWidget(MainWindow *main, QAction *action) :
|
|
|
|
CutterDockWidget(main, action),
|
|
|
|
ui(new Ui::ImportsWidget)
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2017-12-02 19:15:12 +00:00
|
|
|
ui->importsTreeWidget->sortByColumn(3, Qt::AscendingOrder);
|
2017-04-13 15:14:02 +00:00
|
|
|
|
|
|
|
setScrollMode();
|
|
|
|
|
2017-11-19 12:56:10 +00:00
|
|
|
connect(Core(), SIGNAL(refreshAll()), this, SLOT(fillImports()));
|
2017-04-13 15:14:02 +00:00
|
|
|
}
|
|
|
|
|
2017-11-19 12:56:10 +00:00
|
|
|
ImportsWidget::~ImportsWidget() {}
|
2017-03-29 10:18:37 +00:00
|
|
|
|
2017-04-09 19:55:06 +00:00
|
|
|
void ImportsWidget::fillImports()
|
|
|
|
{
|
2017-04-13 15:14:02 +00:00
|
|
|
ui->importsTreeWidget->clear();
|
2017-10-09 18:08:35 +00:00
|
|
|
for (auto i : CutterCore::getInstance()->getAllImports())
|
2017-05-19 07:45:26 +00:00
|
|
|
{
|
2017-12-02 19:15:12 +00:00
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem();
|
|
|
|
item->setText(0, RAddressString(i.plt));
|
|
|
|
item->setText(1, i.type);
|
|
|
|
item->setText(2, "");
|
|
|
|
item->setText(3, i.name);
|
2017-05-19 07:45:26 +00:00
|
|
|
item->setData(0, Qt::UserRole, QVariant::fromValue(i));
|
2017-12-02 19:15:12 +00:00
|
|
|
ui->importsTreeWidget->addTopLevelItem(item);
|
2017-05-19 07:45:26 +00:00
|
|
|
}
|
2017-04-28 13:09:40 +00:00
|
|
|
|
2017-03-29 10:18:37 +00:00
|
|
|
highlightUnsafe();
|
2017-04-13 16:18:56 +00:00
|
|
|
qhelpers::adjustColumns(ui->importsTreeWidget, 0, 10);
|
2017-03-29 10:18:37 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 19:55:06 +00:00
|
|
|
void ImportsWidget::highlightUnsafe()
|
|
|
|
{
|
2017-04-12 22:12:01 +00:00
|
|
|
static const QString banned("[a-zA-Z_.]*(system|strcpy|strcpyA|strcpyW|wcscpy|_tcscpy|_mbscpy|StrCpy|StrCpyA|StrCpyW|lstrcpy|lstrcpyA|lstrcpyW" \
|
|
|
|
"|_tccpy|_mbccpy|_ftcscpy|strcat|strcatA|strcatW|wcscat|_tcscat|_mbscat|StrCat|StrCatA|StrCatW|lstrcat|lstrcatA|" \
|
|
|
|
"lstrcatW|StrCatBuff|StrCatBuffA|StrCatBuffW|StrCatChainW|_tccat|_mbccat|_ftcscat|sprintfW|sprintfA|wsprintf|wsprintfW|" \
|
|
|
|
"wsprintfA|sprintf|swprintf|_stprintf|wvsprintf|wvsprintfA|wvsprintfW|vsprintf|_vstprintf|vswprintf|strncpy|wcsncpy|" \
|
|
|
|
"_tcsncpy|_mbsncpy|_mbsnbcpy|StrCpyN|StrCpyNA|StrCpyNW|StrNCpy|strcpynA|StrNCpyA|StrNCpyW|lstrcpyn|lstrcpynA|lstrcpynW|" \
|
|
|
|
"strncat|wcsncat|_tcsncat|_mbsncat|_mbsnbcat|StrCatN|StrCatNA|StrCatNW|StrNCat|StrNCatA|StrNCatW|lstrncat|lstrcatnA|" \
|
|
|
|
"lstrcatnW|lstrcatn|gets|_getts|_gettws|IsBadWritePtr|IsBadHugeWritePtr|IsBadReadPtr|IsBadHugeReadPtr|IsBadCodePtr|" \
|
|
|
|
"IsBadStringPtr|memcpy|RtlCopyMemory|CopyMemory|wmemcpy|wnsprintf|wnsprintfA|wnsprintfW|_snwprintf|_snprintf|_sntprintf|" \
|
|
|
|
"_vsnprintf|vsnprintf|_vsnwprintf|_vsntprintf|wvnsprintf|wvnsprintfA|wvnsprintfW|strtok|_tcstok|wcstok|_mbstok|makepath|" \
|
|
|
|
"_tmakepath| _makepath|_wmakepath|_splitpath|_tsplitpath|_wsplitpath|scanf|wscanf|_tscanf|sscanf|swscanf|_stscanf|snscanf|" \
|
|
|
|
"snwscanf|_sntscanf|_itoa|_itow|_i64toa|_i64tow|_ui64toa|_ui64tot|_ui64tow|_ultoa|_ultot|_ultow|CharToOem|CharToOemA|CharToOemW|" \
|
|
|
|
"OemToChar|OemToCharA|OemToCharW|CharToOemBuffA|CharToOemBuffW|alloca|_alloca|strlen|wcslen|_mbslen|_mbstrlen|StrLen|lstrlen|" \
|
|
|
|
"ChangeWindowMessageFilter)");
|
|
|
|
|
2017-04-13 15:14:02 +00:00
|
|
|
QList<QTreeWidgetItem *> clist = ui->importsTreeWidget->findItems(banned, Qt::MatchRegExp, 4);
|
2017-04-09 19:55:06 +00:00
|
|
|
foreach (QTreeWidgetItem *item, clist)
|
2017-03-29 10:18:37 +00:00
|
|
|
{
|
2017-12-02 19:15:12 +00:00
|
|
|
item->setText(2, "Unsafe");
|
2017-03-29 10:18:37 +00:00
|
|
|
//item->setBackgroundColor(4, QColor(255, 129, 123));
|
|
|
|
//item->setForeground(4, Qt::white);
|
|
|
|
item->setForeground(4, QColor(255, 129, 123));
|
|
|
|
}
|
|
|
|
//ui->importsTreeWidget->setStyleSheet("QTreeWidget::item { padding-left:10px; padding-top: 1px; padding-bottom: 1px; border-left: 10px; }");
|
|
|
|
}
|
|
|
|
|
2017-04-13 15:14:02 +00:00
|
|
|
void ImportsWidget::setScrollMode()
|
|
|
|
{
|
|
|
|
qhelpers::setVerticalScrollMode(ui->importsTreeWidget);
|
|
|
|
}
|
2017-05-19 07:45:26 +00:00
|
|
|
|
|
|
|
void ImportsWidget::on_importsTreeWidget_itemDoubleClicked(QTreeWidgetItem *item, int /* column */)
|
|
|
|
{
|
|
|
|
ImportDescription imp = item->data(0, Qt::UserRole).value<ImportDescription>();
|
2017-10-09 18:08:35 +00:00
|
|
|
CutterCore::getInstance()->seek(imp.plt);
|
2017-05-19 07:45:26 +00:00
|
|
|
}
|