Skip to content

Commit

Permalink
[BUGFIX] Decode resource timestamp as DOS time (Issue #42)
Browse files Browse the repository at this point in the history
  • Loading branch information
hasherezade committed Nov 19, 2023
1 parent bbe0b7c commit 87a9ca4
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion pe-bear/gui/pe_models/ResourcesTreeModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,29 @@ QVariant ResourcesTreeModel::subdirsData(const QModelIndex &index, int role) con
return QVariant();
}

QString getDosDateString(const unsigned long timestamp, const QString &format)
{
if (timestamp == 0) {
return "";
}
unsigned int d = (timestamp >> 16);
unsigned short t = (unsigned short)(timestamp & 0xFFFF);
unsigned char s = ((t & 0x1F) << 1);
if (s == 60){
s--;
}

QString timeStr;
#if QT_VERSION >= 0x050000
timeStr = QString().asprintf("%04d-%02d-%02d %02d:%02d:%02d", ((d & 0xFE00) >> 9) + 1980, (d & 0x1E0) >> 5, d & 0x1F, (t & 0xF800) >> 11, (t & 0x7E0) >> 5, s);
#else
timeStr = QString().sprintf("%04d-%02d-%02d %02d:%02d:%02d", ((d & 0xFE00) >> 9) + 1980, (d & 0x1E0) >> 5, d & 0x1F, (t & 0xF800) >> 11, (t & 0x7E0) >> 5, s);
#endif

QDateTime datetime = QDateTime::fromString(timeStr,"yyyy-MM-dd HH:mm:ss");
return datetime.toString(format) + " (DOS)";
}

QVariant ResourcesTreeModel::data(const QModelIndex &index, int role) const
{
ExeNodeWrapper *wrap = dynamic_cast<ExeNodeWrapper*>(wrapper());
Expand Down Expand Up @@ -175,7 +198,7 @@ QVariant ResourcesTreeModel::data(const QModelIndex &index, int role) const
if (row == ResourceDirWrapper::TIMESTAMP && !m_PE->isReproBuild()) {
bool isOk = false;
int val = wrap->getNumValue(fId, &isOk);
return (isOk) ? getDateString(val) : QVariant();
return (isOk) ? getDosDateString(val, "dddd, dd.MM.yyyy hh:mm:ss") : QVariant();
}
}
}
Expand Down

0 comments on commit 87a9ca4

Please sign in to comment.