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

Update mainwindow.cpp #6

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Update mainwindow.cpp
Finished binary info dump file feature
HoodedBlack authored Jul 3, 2023
commit ddc8a3564b1bf630e1d4a6f6acf7093484b429e1
56 changes: 56 additions & 0 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -284,13 +284,69 @@ void MainWindow::on_actionDumpFile_triggered()
QFile file2(filename);
if(file2.open(QIODevice::ReadWrite | QIODevice::Truncate | QIODevice::Text)) {
QTextStream stream(&file2);

//dump functions
QStringList funcs = disassemblyCore.getFunctionNames();
QVector<QString> baseOffsets = disassemblyCore.getBaseOffsets();
for(const auto& func : funcs) {
Function currFunc = disassemblyCore.getFunction(func);
stream << "F|"+currFunc.getName()+"|"+currFunc.getAddress()<<endl;
//write here using stream << "something" << endl;
}

// dump instructions
// regex for parsing instruction nmeumonics: [\s]+\t(...)[.]*[a-z]*
// after regexing for those, regex for: (...)[.]*[a-z]*
// use [\s][a-fA-F0-9]+[:] regex to grab address
// out of those regex matches to grab JUST the instruction mnemonic
// TO-DO AFTER IMPLEMENTING ABOVE: Make a regex to grab the instruction address on the first column of objdump output

QStringList arg;
arg << "-d" << disassemblyCore.getFileName();
QProcess *proc = new QProcess();
proc->start(ui->customBinaryLineEdit->text(), arg);
proc->waitForFinished();
QString result=proc->readAllStandardOutput();
QString line;
QTextStream stream2(&result);
while (stream2.readLineInto(&line)) {
QString address;
QString nmeumonic;
QRegularExpression addressRegex("[\\s][a-fA-F0-9]+[:]");

QRegularExpressionMatch match = addressRegex.match(line);
if(match.hasMatch()) {
QString matched = match.captured(0);
address = matched.mid(1, (matched.length()-2));
} else {
continue;
}


QRegularExpression nmeumonicRegex("[\\s]+\t(...)[.]*[a-z]*");
QRegularExpressionMatch match2 = nmeumonicRegex.match(line);
if(match2.hasMatch()) {
nmeumonic = match2.captured(0).simplified();
nmeumonic.remove("\t");
/*
QRegularExpression nmeumonicRegex2("(...)[.]*[a-z]*");
QRegularExpressionMatch match3 = nmeumonicRegex2.match(line2);
if(match3.hasMatch()) {
qDebug() << "MATCH 3 BEFORE: "<<match3.captured(0)<<endl;
nmeumonic = match3.captured(0).simplified();
nmeumonic.remove('\t');
qDebug() << "MATCH 3 AFTER: "<<nmeumonic<<endl;
} else {
continue;
}
*/
} else {
continue;
}
stream << "I|"+nmeumonic<<"|"<<address<<endl;
}


}
file2.close();
}