-
Notifications
You must be signed in to change notification settings - Fork 91
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
Question: FormatDisassembly #21
Comments
Hey Sascha, I need more details in order to help you, for instance: why do you need to get the previous address? |
Well, maybe I have totally wrong idea how to print out the whole code formatted: medusa::Address FirstAddr = _medusa.GetDocument().GetFirstAddress();
medusa::Address LastAddr = _medusa.GetDocument().GetLastAddress();
medusa::PrintData Print;
medusa::FormatDisassembly FmtDisasm(_medusa, Print);
medusa::u32 m_FormatFlags = medusa::FormatDisassembly::ShowAddress |
medusa::FormatDisassembly::AddSpaceBeforeXref |
medusa::FormatDisassembly::Indent;
QFile assemblyFile("test.asm");
if (!assemblyFile.open(QIODevice::ReadWrite | QIODevice::Text))
return;
qDebug() << "Created file at: " << assemblyFile.fileName();
QTextStream out(&assemblyFile);
int iLineNumber = 0;
while (FirstAddr != LastAddr) {
while (!_medusa.GetDocument().GetNextAddress(FirstAddr, FirstAddr))
qDebug() << "Nothing found at " << FirstAddr.GetOffset();
FmtDisasm(FirstAddr, m_FormatFlags, 1);
std::string Line = Print.GetTexts();
out << QString::fromStdString(Line);
iLineNumber++;
if (iLineNumber == 100) {
iLineNumber = 0;
assemblyFile.flush();
}
}
assemblyFile.close(); I just created a menu item to be able to activate it after all the work is done. |
Your code looks good to me, is your code slower than medusa_text? Actually dumping disassembled text is quite long, especially here since Medusa has to re-disassemble instruction each time it's necessary. |
Well, it hasn't finished after 12 hours for the same file I have giving you a link to... So it is very slow. The file is 316.4 mb big. |
wow 12 hours, something bad happens. :p |
Well, I guess that must be true... class MemoryDisAssemblerTask : public QRunnable
{
public:
MemoryDisAssemblerTask(medusa::Medusa * medusa, medusa::Address const rAddress)
: m_pMedusa(medusa), m_Address(rAddress) {
}
void run()
{
medusa::MemoryArea const* rMemArea = m_pMedusa->GetDocument().GetMemoryArea(m_Address);
qDebug() << "Hello world from thread" << QThread::currentThread();
qDebug() << m_Address.GetOffset();
QString assemblyName = QString::fromStdString( rMemArea->GetName() ) + QString(".asm");
if (assemblyName.startsWith('.')) {
assemblyName = QString("sec_") + assemblyName;
}
QFile assemblyFile(assemblyName);
if (!assemblyFile.open(QIODevice::ReadWrite | QIODevice::Text))
return;
QTextStream out(&assemblyFile);
qDebug() << "Created file at: " << assemblyFile.fileName();
medusa::Address FirstAddr = m_Address;
int iLineNumber = 0;
std:string MemoryName = rMemArea->GetName();
medusa::PrintData Print;
medusa::FormatDisassembly FmtDisasm(*m_pMedusa, Print);
medusa::u32 m_FormatFlags = medusa::FormatDisassembly::ShowAddress |
medusa::FormatDisassembly::AddSpaceBeforeXref |
medusa::FormatDisassembly::Indent;
QString qMemoryName = QString::fromStdString(MemoryName);
medusa::TOffset EndOffset = FirstAddr.GetOffset() + rMemArea->GetSize();
qDebug() << qMemoryName << " EndOffset: " << EndOffset;
while (true) {
qDebug() << qMemoryName << FirstAddr.GetOffset();
FmtDisasm(FirstAddr, m_FormatFlags, 1);
std::string Line = Print.GetTexts();
out << QString::fromStdString(Line);
iLineNumber++;
if (iLineNumber == 1000) {
iLineNumber = 0;
assemblyFile.flush();
}
if (FirstAddr.GetOffset() == EndOffset) {
qDebug() << "We are at the end of " << qMemoryName;
break;
}
if (!m_pMedusa->GetDocument().GetNextAddress(FirstAddr, FirstAddr)) {
qDebug() << "Nothing found for " << qMemoryName;
break;
}
}
assemblyFile.flush();
assemblyFile.close();
}
private:
medusa::Address m_Address;
medusa::Medusa * m_pMedusa;
};
void MainWindow::on_actionSimpleAction_triggered()
{
_medusa.GetDocument().ForEachMemoryArea([&](medusa::MemoryArea const& rMemArea)
{
MemoryDisAssemblerTask *hello = new MemoryDisAssemblerTask(
&_medusa,
rMemArea.GetBaseAddress()
);
QThreadPool::globalInstance()->start(hello);
});
} |
It looks great, feel free to include this feature on medusa. :) |
Well, it is not yet finish since there are still some problems but I think I can fix most and than I can make a pull request |
Is it correct that only with this code, I can check where the end of the section is: if (!rMemArea->GetNextAddress(FirstAddr, FirstAddr)) {
qDebug() << "Nothing found for " << qMemoryName;
break;
} |
Actually, no since |
Well, how could I check manually if it stops correctly? |
I think it works correctly but my exe-file is about 25mb in size. And that many instructions writing down is not that fast as it seems... |
Probably not the better way, but that's what I would do: let it run several minutes (e.g. 30 minutes), and attach a debugger to see what actually happens. This method sucks but it's simple. |
I think that too because during the storing I almost only see db instructions ;) |
Hey,
I was trying to print out every single line of the disassembly with formating. It got really slow in the following method:
Now my question is if I can just switch the type of m_Cells to a deque or do I need to change something else?
The text was updated successfully, but these errors were encountered: