Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Load multilingual function #35

Merged
merged 4 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"ranges": "cpp"
}
}
3,081 changes: 3,081 additions & 0 deletions Language/PE-bear.ts

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions Language/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# How to load a language file
Current version
Rename the Language file to PELanguage.qm and put it in the language folder.
Folder example
```
Language
PELanguage.qm
pebear.exe
```
# How to translate
Download the language file, use QT linguist to load and select the language to be translated, and click Publish to generate qm file after translation.
# reference data
* https://doc.qt.io/qt-5/qtlinguist-index.html
* https://doc.qt.io/qt-5/linguist-translators.html
Binary file added Language/zh_cn PELanguage.qm
Binary file not shown.
52 changes: 26 additions & 26 deletions pe-bear/DisasmView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ void DisasmTreeView::onFollowOffset(offset_t offset, Executable::addr_type aT)
hndl->setDisplayed(false, raw);

} catch (CustomException e) {
this->lastErrorString = "Address: "+ QString::number(offset, 16) +" is invalid:\n" + e.what();
QMessageBox::warning(0, "Warning!", this->lastErrorString );
this->lastErrorString = tr("Address: ")+ QString::number(offset, 16) + tr(" is invalid:") + "\n" + e.what();
QMessageBox::warning(0, tr("Warning!"), this->lastErrorString );
}
}

Expand Down Expand Up @@ -262,7 +262,7 @@ void DisasmTreeView::pasteToSelected()

QModelIndexList list = this->uniqOffsets(model->selectedIndexes());
if (!this->isIndexListContinuous(list)) {
QMessageBox::warning(0, "Warning!", "Select continuous area!");
QMessageBox::warning(0, tr("Warning!"), tr("Select continuous area!"));
return;
}
if (list.size() == 0) return;
Expand All @@ -287,21 +287,21 @@ void DisasmTreeView::initMenu()
{
QMenu *menu = &defaultMenu;;

QAction *copySelAction = new QAction("Copy", menu);
QAction *copySelAction = new QAction(tr("Copy"), menu);
copySelAction->setShortcut(Qt::CTRL + Qt::Key_C);

menu->addAction(copySelAction);
connect(copySelAction, SIGNAL(triggered()), this, SLOT(copySelected()));

QAction *pasteSelAction = new QAction("Paste to selected", menu);
QAction *pasteSelAction = new QAction(tr("Paste to selected"), menu);
pasteSelAction->setShortcut(Qt::CTRL + Qt::Key_V);
menu->addAction(pasteSelAction);
connect(pasteSelAction, SIGNAL(triggered()), this, SLOT(pasteToSelected()));

QMenu *followMenu = new QMenu("Follow", menu);
QMenu *followMenu = new QMenu(tr("Follow"), menu);
menu->addMenu(followMenu);

OffsetDependentAction* followRvaAction = new OffsetDependentAction(Executable::RVA, "Selection RVA:\t", followMenu);
OffsetDependentAction* followRvaAction = new OffsetDependentAction(Executable::RVA, tr("Selection RVA:") + "\t", followMenu);
followMenu->addAction(followRvaAction);
connect(this, SIGNAL(currentRvaChanged(offset_t)), followRvaAction, SLOT(onOffsetChanged(offset_t)) );
connect(followRvaAction, SIGNAL(triggered(offset_t, Executable::addr_type)), this, SLOT(onFollowOffset(offset_t, Executable::addr_type)));
Expand Down Expand Up @@ -335,7 +335,7 @@ void DisasmTreeView::initMenu()

//set EP at offset:
QPixmap epIco(":/icons/arrow-right.ico");
OffsetDependentAction* setEpAction = new OffsetDependentAction(Executable::RVA, "Set EP =", menu);
OffsetDependentAction* setEpAction = new OffsetDependentAction(Executable::RVA, tr("Set EP ="), menu);
setEpAction->setIcon(epIco);
menu->addAction(setEpAction);
connect(this, SIGNAL(currentRvaChanged(offset_t)), setEpAction, SLOT(onOffsetChanged(offset_t)) );
Expand All @@ -347,23 +347,23 @@ void DisasmTreeView::initHeaderMenu()
QMenu &hdrMenu = vHdr.defaultMenu;
//------------

QMenu *hdrSettings = new QMenu("Settings", &hdrMenu);
QMenu *hdrSettings = new QMenu(tr("Settings"), &hdrMenu);
hdrMenu.addSeparator();
hdrMenu.addMenu(hdrSettings);

imgBaseA = hdrSettings->addAction("RVA -> VA");
imgBaseA->setCheckable(true);
imgBaseA->setToolTip("Add ImageBase");
imgBaseA->setToolTip(tr("Add ImageBase"));
imgBaseA->setChecked(false);

/*Bitmode setting actions */
QActionGroup *group = new QActionGroup(this);
group->setExclusive(true);
QMenu* bitModeSubmenu = hdrSettings->addMenu("&Bit mode");
QMenu* bitModeSubmenu = hdrSettings->addMenu(tr("&Bit mode"));
const int MODES_NUM = 4;
QAction *actions[MODES_NUM];

actions[0] = group->addAction("Automatic");
actions[0] = group->addAction(tr("Automatic"));
actions[0]->setData(0);

for (int i = 1; i < MODES_NUM; i++) {
Expand Down Expand Up @@ -723,9 +723,9 @@ QVariant DisasmModel::horizHeader(int section, int role) const
if (role != Qt::DisplayRole) return QVariant();

switch (section) {
case HEX_COL: return " Hex ";
case DISASM_COL: return " Disasm ";
case HINT_COL: return " Hint ";
case HEX_COL: return tr(" Hex ");
case DISASM_COL: return tr(" Disasm ");
case HINT_COL: return tr(" Hint ");
}
return QVariant();
}
Expand All @@ -751,12 +751,12 @@ QVariant DisasmModel::verticHeader(int section, int role) const
offset_t rva = this->getRvaAt(y);

if (rva == INVALID_ADDR) {
if (role == Qt::DisplayRole) return "<invalid>";
if (role == Qt::DisplayRole) return tr("<invalid>");
if (role == Qt::ToolTipRole) {
const offset_t raw = this->getRawAt(y);
return "Not mapped. Raw = 0x" + QString::number(raw, 16);
return tr("Not mapped. Raw = 0x") + QString::number(raw, 16);
}
if (role == Qt::ForegroundRole) return QColor("red");
if (role == Qt::ForegroundRole) return QColor(tr("red"));
}

//rva valid
Expand All @@ -768,22 +768,22 @@ QVariant DisasmModel::verticHeader(int section, int role) const
}

if (role == Qt::ToolTipRole) {
return QString::number(rva, 16).toUpper() +"\nRight click to follow";
return QString::number(rva, 16).toUpper() +"\n"+ tr("Right click to follow");
}

if (!myDisasm.isRvaContnuous(y)) {
if (role == Qt::ForegroundRole) return QColor("magenta");
if (role == Qt::ForegroundRole) return QColor(tr("magenta"));
}

DWORD ep = m_PE->getEntryPoint();
size_t disChunk = myDisasm.getChunkSize(y);

if (ep >= rva && ep < (rva + disChunk)) {
if (role == Qt::ForegroundRole) return QColor("cyan");
if (role == Qt::ToolTipRole) return "Entry Point = " + QString::number(ep, 16).toUpper();
if (role == Qt::ForegroundRole) return QColor(tr("cyan"));
if (role == Qt::ToolTipRole) return tr("Entry Point = ") + QString::number(ep, 16).toUpper();
}
// normal color
if (role == Qt::ForegroundRole) return QColor("white");
if (role == Qt::ForegroundRole) return QColor(tr("white"));

return QVariant();
}
Expand Down Expand Up @@ -1098,7 +1098,7 @@ QVariant DisasmModel::data(const QModelIndex &index, int role) const

if (role == Qt::ToolTipRole) {
if (tRva >= imgSize) {
return "RVA out of ImageSize: 0x" + QString::number(imgSize, 16);
return tr("RVA out of ImageSize: 0x") + QString::number(imgSize, 16);
}
if (lval < 0) {
return "$- 0x" + QString::number(~lval + 1, 16);
Expand All @@ -1108,7 +1108,7 @@ QVariant DisasmModel::data(const QModelIndex &index, int role) const
}

if (role == Qt::ToolTipRole && x == DISASM_COL) {
QString s = "Click arrow icon to follow (RVA: " + QString::number(tRva, 16).toUpper() + ")";
QString s = tr("Click arrow icon to follow (RVA: ") + QString::number(tRva, 16).toUpper() + ")";
return s;
}
}
Expand All @@ -1128,7 +1128,7 @@ QVariant DisasmModel::data(const QModelIndex &index, int role) const
}
}
if (role == Qt::ToolTipRole && x == HEX_COL) {
return "Double-click to edit";
return tr("Double-click to edit");
}
if (x == HEX_COL) {
if (role == Qt::DisplayRole || role == Qt::ToolTipRole || role == Qt::EditRole) {
Expand Down
4 changes: 2 additions & 2 deletions pe-bear/HexCompareView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ MenuHeader::MenuHeader(QWidget *parent)
this->setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customMenuEvent(QPoint)) );

this->copyAction = new QAction("Copy the offset", this);
this->copyAction = new QAction(tr("Copy the offset"), this);
connect(copyAction, SIGNAL(triggered()), this, SLOT(copyOffset()));

this->defaultMenu.addAction(copyAction);
Expand Down Expand Up @@ -46,7 +46,7 @@ void MenuHeader::mousePressEvent(QMouseEvent *event)
if (isOk) {
selectedOffset = offset;
}
copyAction->setText("Copy the offset: " + QString::number(selectedOffset, 16).toUpper());
copyAction->setText(tr("Copy the offset: ") + QString::number(selectedOffset, 16).toUpper());
}
QHeaderView::mousePressEvent(event);
}
Expand Down
4 changes: 2 additions & 2 deletions pe-bear/HexDumpModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ QVariant HexDumpModel::headerData(int section, Qt::Orientation orientation, int
return QString::number(offset, 16).toUpper();
}
if ( role == Qt::ToolTipRole) {
return QString::number(offset, 16).toUpper() +"\nRight click to follow.";
return QString::number(offset, 16).toUpper() +"\n"+ tr("Right click to follow.");
}
}

Expand Down Expand Up @@ -163,7 +163,7 @@ QVariant HexDumpModel::data(const QModelIndex &index, int role) const
return settings.myFont;
}
if (role == Qt::ToolTipRole) {
return "Double-click to edit";
return tr("Double-click to edit");
}
if (role == Qt::ForegroundRole) {
bool isActiveArea = this->myPeHndl->isInActiveArea(offset);
Expand Down
30 changes: 15 additions & 15 deletions pe-bear/HexView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void HexTableView::initHeaderMenu()
{
if (!vHdr) return;
QMenu &hdrMenu = vHdr->defaultMenu;
QMenu *naviSubMenu = hdrMenu.addMenu("Navigation");
QMenu *naviSubMenu = hdrMenu.addMenu(tr("Navigation"));

QString pageSize = QString::number(PREVIEW_SIZE, 16);

Expand All @@ -161,7 +161,7 @@ void HexTableView::initHeaderMenu()
connect(pgDn, SIGNAL(triggered()), this, SLOT(setPageDown()));
naviSubMenu->addAction(pgDn);

back = new QAction("Back to offset", &hdrMenu);
back = new QAction(tr("Back to offset"), &hdrMenu);
back->setShortcut(Qt::Key_B);
connect(back, SIGNAL(triggered()), this, SLOT(undoOffset()));
naviSubMenu->addAction(back);
Expand All @@ -172,29 +172,29 @@ void HexTableView::initMenu()
QMenu* menu = &defaultMenu;
//QMenu* editSubmenu = menu.addMenu("&Selection");

QAction *copySelAction = new QAction("Copy", menu);
QAction *copySelAction = new QAction(tr("Copy"), menu);
copySelAction->setShortcut(Qt::CTRL + Qt::Key_C);

menu->addAction(copySelAction);
connect(copySelAction, SIGNAL(triggered()), this, SLOT(copySelected()));

QAction *pasteSelAction = new QAction("Paste to selected", menu);
QAction *pasteSelAction = new QAction(tr("Paste to selected"), menu);
pasteSelAction->setShortcut(Qt::CTRL + Qt::Key_V);
menu->addAction(pasteSelAction);
connect(pasteSelAction, SIGNAL(triggered()), this, SLOT(pasteToSelected()));

QMenu* fillSubmenu = menu->addMenu("Fill selected");
QMenu* fillSubmenu = menu->addMenu(tr("Fill selected"));

QAction *clearSelAction = new QAction("Clear", fillSubmenu);
QAction *clearSelAction = new QAction(tr("Clear"), fillSubmenu);
clearSelAction->setShortcut(Qt::Key_Delete);
fillSubmenu->addAction(clearSelAction);
connect(clearSelAction, SIGNAL(triggered()), this, SLOT(clearSelected()));

QAction *fillSelAction = new QAction("NOP", fillSubmenu);
QAction *fillSelAction = new QAction(tr("NOP"), fillSubmenu);
fillSubmenu->addAction(fillSelAction);
connect(fillSelAction, SIGNAL(triggered()), this, SLOT(fillSelected()));

undo = new QAction("Undo", menu);
undo = new QAction(tr("Undo"), menu);
undo->setShortcut(Qt::CTRL + Qt::Key_Z);
connect(undo, SIGNAL(triggered()), this, SLOT(undoLastModification()));
}
Expand Down Expand Up @@ -309,7 +309,7 @@ void HexTableView::pasteToSelected()
if (bufSize == 0) return;

if (!isIndexListContinuous(list)) {
QMessageBox::warning(0, "Warning!", "Select continuous area!");
QMessageBox::warning(0, tr("Warning!"), tr("Select continuous area!"));
return;
}
offset_t first = hexModel->contentOffsetAt(list.at(0));
Expand All @@ -325,7 +325,7 @@ void HexTableView::pasteToSelected()

bool success = hexModel->myPeHndl->substBlock(first, clipSize, buf);
if (success == false) {
QMessageBox::warning(0, "Error!", "Modification in this area in unacceptable!\n(Causes format corruption)");
QMessageBox::warning(0, tr("Error!"), tr("Modification in this area in unacceptable!")+"\n"+tr("(Causes format corruption)"));
return;
}
}
Expand All @@ -340,15 +340,15 @@ void HexTableView::fillSelected()
if (size == 0) return;

if (!isIndexListContinuous(list)) {
QMessageBox::warning(0,"Warning!", "Select continuous area!");
QMessageBox::warning(0, tr("Warning!"), tr("Select continuous area!"));
return;
}

offset_t first = hexModel->contentOffsetAt(list.at(0));
if (first == INVALID_ADDR) return;

if (hexModel->myPeHndl->fillBlock(first, size, 0x90) == false) {
QMessageBox::warning(0, "Error!", "Modification in this area in unacceptable!\n(Causes format corruption)");
QMessageBox::warning(0, tr("Error!"), tr("Modification in this area in unacceptable!")+"\n"+ tr("(Causes format corruption)"));
return;
}
}
Expand All @@ -364,14 +364,14 @@ void HexTableView::clearSelected()
if (size == 0) return;

if (!isIndexListContinuous(list)) {
QMessageBox::warning(0,"Warning!", "Select continuous area!");
QMessageBox::warning(0, tr("Warning!"), tr("Select continuous area!"));
return;
}
offset_t first = hexModel->contentOffsetAt(list.at(0));
if (first == INVALID_ADDR) return;

if (hexModel->myPeHndl->fillBlock(first, size, 0) == false) {
QMessageBox::warning(0, "Error!", "Modification in this area in unacceptable!\n(Causes format corruption)");
QMessageBox::warning(0, tr("Error!"), tr("Modification in this area in unacceptable!")+"\n"+ tr("(Causes format corruption)"));
return;
}
}
Expand Down Expand Up @@ -405,7 +405,7 @@ void HexTableView::updateUndoAction()
if (!hexModel) return;
if (hexModel->myPeHndl->prevOffsets.size() > 0) {
this->back->setEnabled(true);
this->back->setText("Back to: 0x" + QString::number(hexModel->myPeHndl->prevOffsets.top(), 16).toUpper());
this->back->setText(tr("Back to: 0x") + QString::number(hexModel->myPeHndl->prevOffsets.top(), 16).toUpper());
} else {
this->back->setEnabled(false);
}
Expand Down
6 changes: 3 additions & 3 deletions pe-bear/OffsetHeader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ OffsetHeader::OffsetHeader(QWidget *parent)
this->setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(customMenuEvent(QPoint)) );

this->followAction = new QAction("Follow the offset", this);
this->followAction = new QAction(tr("Follow the offset"), this);
connect(followAction, SIGNAL(triggered()), this, SLOT(followOffset()));

this->copyAction = new QAction("Copy the offset", this);
this->copyAction = new QAction(tr("Copy the offset"), this);
connect(copyAction, SIGNAL(triggered()), this, SLOT(copyOffset()));

this->defaultMenu.addAction(followAction);
Expand All @@ -32,7 +32,7 @@ void OffsetHeader::customMenuEvent(QPoint p)
if (!hexModel) return;

if (selectedOffset == INVALID_ADDR) {
followAction->setText("Invalid offset");
followAction->setText(tr("Invalid offset"));
followAction->setEnabled(false);

} else {
Expand Down
Loading