2006-06-15 04:19:30 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include "ELFView.h"
|
|
|
|
#include "PtrMacro.h"
|
2007-02-20 21:16:34 +00:00
|
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
#include "string_cast.h"
|
2006-06-15 04:19:30 +00:00
|
|
|
|
|
|
|
using namespace Framework;
|
2007-02-20 21:16:34 +00:00
|
|
|
using namespace std;
|
|
|
|
using namespace boost;
|
2006-06-15 04:19:30 +00:00
|
|
|
|
|
|
|
CELFView::CELFView(HWND hParent) :
|
2007-02-20 21:16:34 +00:00
|
|
|
COptionWnd<CMDIChild>(hParent, _T("ELF File Viewer"))
|
2006-06-15 04:19:30 +00:00
|
|
|
{
|
|
|
|
m_pELF = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
CELFView::~CELFView()
|
|
|
|
{
|
|
|
|
Delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CELFView::Delete()
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if(m_pELF != NULL)
|
|
|
|
{
|
|
|
|
for(i = 0; i < m_pELF->m_Header.nProgHeaderCount; i++)
|
|
|
|
{
|
|
|
|
DELETEPTR(m_pProgramView[i]);
|
|
|
|
}
|
|
|
|
DELETEPTR(m_pProgramView);
|
|
|
|
|
|
|
|
for(i = 0; i < m_pELF->m_Header.nSectHeaderCount; i++)
|
|
|
|
{
|
|
|
|
DELETEPTR(m_pSectionView[i]);
|
|
|
|
}
|
|
|
|
DELETEPTR(m_pSectionView);
|
|
|
|
|
|
|
|
DELETEPTR(m_pSymbolView);
|
|
|
|
DELETEPTR(m_pHeaderView);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CELFView::SetELF(CELF* pELF)
|
|
|
|
{
|
|
|
|
HWND hCont;
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
DeleteAllOptions();
|
|
|
|
|
|
|
|
Delete();
|
|
|
|
|
|
|
|
m_pELF = pELF;
|
|
|
|
|
|
|
|
if(m_pELF == NULL) return;
|
|
|
|
|
|
|
|
hCont = GetContainer()->m_hWnd;
|
|
|
|
|
|
|
|
m_pHeaderView = new CELFHeaderView(hCont, m_pELF);
|
|
|
|
m_pSymbolView = new CELFSymbolView(hCont, m_pELF);
|
|
|
|
|
|
|
|
m_pSectionView = new CELFSectionView*[m_pELF->m_Header.nSectHeaderCount];
|
|
|
|
for(i = 0; i < m_pELF->m_Header.nSectHeaderCount; i++)
|
|
|
|
{
|
|
|
|
m_pSectionView[i] = new CELFSectionView(hCont, m_pELF, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_pProgramView = new CELFProgramView*[m_pELF->m_Header.nProgHeaderCount];
|
|
|
|
for(i = 0; i < m_pELF->m_Header.nProgHeaderCount; i++)
|
|
|
|
{
|
|
|
|
m_pProgramView[i] = new CELFProgramView(hCont, m_pELF, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
PopulateList();
|
|
|
|
|
|
|
|
GetTreeView()->SetSelection(GetTreeView()->GetRoot());
|
|
|
|
|
|
|
|
//Humm, this window is not necessarily active at this moment? Why this is here?
|
|
|
|
//GetTreeView()->SetFocus();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void CELFView::PopulateList()
|
|
|
|
{
|
|
|
|
ELFSECTIONHEADER* pSect;
|
|
|
|
HTREEITEM hItem;
|
|
|
|
const char* sName;
|
|
|
|
const char* sStrTab;
|
|
|
|
|
2007-02-20 21:16:34 +00:00
|
|
|
InsertOption(NULL, _T("Header"), m_pHeaderView->m_hWnd);
|
|
|
|
hItem = InsertOption(NULL, _T("Sections"), NULL);
|
2006-06-15 04:19:30 +00:00
|
|
|
|
|
|
|
sStrTab = (const char*)m_pELF->GetSectionData(m_pELF->m_Header.nSectHeaderStringTableIndex);
|
2007-02-20 21:16:34 +00:00
|
|
|
for(unsigned int i = 0; i < m_pELF->m_Header.nSectHeaderCount; i++)
|
2006-06-15 04:19:30 +00:00
|
|
|
{
|
2007-02-20 21:16:34 +00:00
|
|
|
tstring sDisplay;
|
|
|
|
|
|
|
|
pSect = m_pELF->GetSection(i);
|
|
|
|
|
|
|
|
if(sStrTab != NULL)
|
2006-06-15 04:19:30 +00:00
|
|
|
{
|
|
|
|
sName = sStrTab + pSect->nStringTableIndex;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sName = "";
|
|
|
|
}
|
2007-02-20 21:16:34 +00:00
|
|
|
|
|
|
|
if(strlen(sName))
|
2006-06-15 04:19:30 +00:00
|
|
|
{
|
2007-02-20 21:16:34 +00:00
|
|
|
sDisplay = string_cast<tstring>(sName);
|
2006-06-15 04:19:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-02-20 21:16:34 +00:00
|
|
|
sDisplay = _T("Section ") + lexical_cast<tstring>(i);
|
2006-06-15 04:19:30 +00:00
|
|
|
}
|
2007-02-20 21:16:34 +00:00
|
|
|
|
|
|
|
InsertOption(hItem, sDisplay.c_str(), m_pSectionView[i]->m_hWnd);
|
2006-06-15 04:19:30 +00:00
|
|
|
}
|
|
|
|
GetTreeView()->Expand(hItem, TVE_EXPAND);
|
|
|
|
|
|
|
|
if(m_pELF->m_Header.nProgHeaderCount != 0)
|
|
|
|
{
|
2007-02-20 21:16:34 +00:00
|
|
|
hItem = InsertOption(NULL, _T("Segments"), NULL);
|
2006-06-15 04:19:30 +00:00
|
|
|
|
2007-02-20 21:16:34 +00:00
|
|
|
for(unsigned int i = 0; i < m_pELF->m_Header.nProgHeaderCount; i++)
|
2006-06-15 04:19:30 +00:00
|
|
|
{
|
2007-02-20 21:16:34 +00:00
|
|
|
tstring sDisplay(_T("Segment ") + lexical_cast<tstring>(i));
|
|
|
|
InsertOption(hItem, sDisplay.c_str(), m_pProgramView[i]->m_hWnd);
|
2006-06-15 04:19:30 +00:00
|
|
|
}
|
|
|
|
GetTreeView()->Expand(hItem, TVE_EXPAND);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(m_pELF->FindSection(".strtab") && m_pELF->FindSection(".symtab"))
|
|
|
|
{
|
2007-02-20 21:16:34 +00:00
|
|
|
InsertOption(NULL, _T("Symbols"), m_pSymbolView->m_hWnd);
|
2006-06-15 04:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
long CELFView::OnSysCommand(unsigned int nCmd, LPARAM lParam)
|
|
|
|
{
|
|
|
|
switch(nCmd)
|
|
|
|
{
|
|
|
|
case SC_CLOSE:
|
|
|
|
Show(SW_HIDE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|