|
|
|
@ -10,6 +10,15 @@ |
|
|
|
#include "afxdialogex.h" |
|
|
|
|
|
|
|
#include <iostream> |
|
|
|
#include <fstream> |
|
|
|
#include <cstdlib> |
|
|
|
#include <iomanip> |
|
|
|
|
|
|
|
|
|
|
|
#include <iostream> |
|
|
|
#include "intelhex.h" |
|
|
|
#include "elfio.hpp" |
|
|
|
#include "elfio_dump.hpp" |
|
|
|
|
|
|
|
#ifdef _DEBUG |
|
|
|
#define new DEBUG_NEW |
|
|
|
@ -96,6 +105,8 @@ BEGIN_MESSAGE_MAP(CIncSourceTestDlgDlg, CDialogEx) |
|
|
|
ON_WM_PAINT() |
|
|
|
ON_WM_QUERYDRAGICON() |
|
|
|
ON_BN_CLICKED(IDC_BUTTON_OPEN, &CIncSourceTestDlgDlg::OnBnClickedButtonOpen) |
|
|
|
ON_BN_CLICKED(IDC_BUTTON_ELF, &CIncSourceTestDlgDlg::OnBnClickedButtonElf) |
|
|
|
ON_BN_CLICKED(IDC_BUTTON_HEX, &CIncSourceTestDlgDlg::OnBnClickedButtonHex) |
|
|
|
END_MESSAGE_MAP() |
|
|
|
|
|
|
|
|
|
|
|
@ -587,4 +598,135 @@ void CIncSourceTestDlgDlg::AddLogString(std::string strMessage) |
|
|
|
message_w.assign(strMessage.begin(), strMessage.end()); |
|
|
|
|
|
|
|
pListBox->AddString(message_w.c_str()); |
|
|
|
} |
|
|
|
} |
|
|
|
void CIncSourceTestDlgDlg::OnBnClickedButtonElf() |
|
|
|
{ |
|
|
|
// TODO: 여기에 컨트롤 알림 처리기 코드를 추가합니다.
|
|
|
|
TCHAR hexExt[] = _T("*.elf"); |
|
|
|
TCHAR hexBaseFilter[] = _T("ELF file(*.ELF) | *.elf;*.ELF | 모든파일(*.*) | *.* ||"); |
|
|
|
CFileDialog dlg(TRUE, hexExt, NULL, OFN_HIDEREADONLY, hexBaseFilter); |
|
|
|
|
|
|
|
if (dlg.DoModal() == IDOK) { |
|
|
|
|
|
|
|
std::wstring strPath = dlg.GetPathName().GetBuffer(); |
|
|
|
|
|
|
|
std::string strHexPath; |
|
|
|
|
|
|
|
strHexPath.assign(strPath.begin(), strPath.end()); |
|
|
|
|
|
|
|
ELFIO::elfio reader; |
|
|
|
if (reader.load(strHexPath.c_str())) { |
|
|
|
// Print ELF file properties
|
|
|
|
std::cout << "ELF file class : "; |
|
|
|
|
|
|
|
if (reader.get_class() == ELFIO::ELFCLASS32) { |
|
|
|
std::cout << "ELF32" << std::endl; |
|
|
|
AddLogString(string_format("ELF file class : ELF32")); |
|
|
|
} |
|
|
|
else { |
|
|
|
std::cout << "ELF64" << std::endl; |
|
|
|
AddLogString(string_format("ELF file class : ELF64")); |
|
|
|
} |
|
|
|
|
|
|
|
std::cout << "ELF file encoding : "; |
|
|
|
if (reader.get_encoding() == ELFIO::ELFDATA2LSB) { |
|
|
|
std::cout << "Little endian" << std::endl; |
|
|
|
AddLogString(string_format("ELF file encoding : Little endian")); |
|
|
|
} |
|
|
|
else { |
|
|
|
std::cout << "Big endian" << std::endl; |
|
|
|
AddLogString(string_format("ELF file encoding : Big endian")); |
|
|
|
} |
|
|
|
|
|
|
|
// Print ELF file sections info
|
|
|
|
ELFIO::Elf_Half sec_num = reader.sections.size(); |
|
|
|
std::cout << "Number of sections: " << sec_num << std::endl; |
|
|
|
AddLogString(string_format("Number of sections: %d", sec_num)); |
|
|
|
for (int i = 0; i < sec_num; ++i) { |
|
|
|
ELFIO::section* psec = reader.sections[i]; |
|
|
|
std::cout << " [" << i << "] " << psec->get_name() << "\t" |
|
|
|
<< psec->get_size() << std::endl; |
|
|
|
|
|
|
|
AddLogString(string_format(" [%d] %s [%d]", i, psec->get_name(), psec->get_size())); |
|
|
|
|
|
|
|
// Access to section's data
|
|
|
|
// const char* p = reader.sections[i]->get_data()
|
|
|
|
} |
|
|
|
|
|
|
|
// Print ELF file segments info
|
|
|
|
ELFIO::Elf_Half seg_num = reader.segments.size(); |
|
|
|
std::cout << "Number of segments: " << seg_num << std::endl; |
|
|
|
AddLogString(string_format("Number of segments: %d", seg_num)); |
|
|
|
for (int i = 0; i < seg_num; ++i) { |
|
|
|
const ELFIO::segment* pseg = reader.segments[i]; |
|
|
|
std::cout << " [" << i << "] 0x" << std::hex << pseg->get_flags() |
|
|
|
<< "\t0x" << pseg->get_virtual_address() << "\t0x" |
|
|
|
<< pseg->get_file_size() << "\t0x" << pseg->get_memory_size() |
|
|
|
<< std::endl; |
|
|
|
|
|
|
|
AddLogString(string_format(" [%d] 0x%X 0x%X [%d]", i, pseg->get_flags(), pseg->get_virtual_address(), pseg->get_memory_size())); |
|
|
|
// Access to segments's data
|
|
|
|
// const char* p = reader.segments[i]->get_data()
|
|
|
|
} |
|
|
|
|
|
|
|
for (int i = 0; i < sec_num; ++i) { |
|
|
|
ELFIO::section* psec = reader.sections[i]; |
|
|
|
// Check section type
|
|
|
|
if (psec->get_type() == ELFIO::SHT_SYMTAB) { |
|
|
|
const ELFIO::symbol_section_accessor symbols(reader, psec); |
|
|
|
for (unsigned int j = 0; j < symbols.get_symbols_num(); ++j) { |
|
|
|
std::string name; |
|
|
|
ELFIO::Elf64_Addr value; |
|
|
|
ELFIO::Elf_Xword size; |
|
|
|
unsigned char bind; |
|
|
|
unsigned char type; |
|
|
|
ELFIO::Elf_Half section_index; |
|
|
|
unsigned char other; |
|
|
|
|
|
|
|
// Read symbol properties
|
|
|
|
symbols.get_symbol(j, name, value, size, bind, type, |
|
|
|
section_index, other); |
|
|
|
std::cout << j << " " << name << " " << value << std::endl; |
|
|
|
|
|
|
|
if (type == 1) |
|
|
|
AddLogString(string_format("[%d][%d] %s 0x%X %d type=%d bind=%d section_index=0x%X other=%d",i, j, name.c_str(), value, size, type, bind, section_index, other)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void CIncSourceTestDlgDlg::OnBnClickedButtonHex() |
|
|
|
{ |
|
|
|
// TODO: 여기에 컨트롤 알림 처리기 코드를 추가합니다.
|
|
|
|
|
|
|
|
|
|
|
|
TCHAR hexExt[] = _T("*.hex"); |
|
|
|
TCHAR hexBaseFilter[] = _T("HEX file(*.HEX) | *.hex;*.HEX | 모든파일(*.*) | *.* ||"); |
|
|
|
CFileDialog dlg(TRUE, hexExt, NULL, OFN_HIDEREADONLY, hexBaseFilter); |
|
|
|
|
|
|
|
if (dlg.DoModal() == IDOK) { |
|
|
|
|
|
|
|
std::wstring strPath = dlg.GetPathName().GetBuffer(); |
|
|
|
|
|
|
|
std::string strHexPath; |
|
|
|
|
|
|
|
strHexPath.assign(strPath.begin(), strPath.end()); |
|
|
|
|
|
|
|
intelhex::hex_data ithex; |
|
|
|
|
|
|
|
ithex.load(strHexPath.c_str()); |
|
|
|
|
|
|
|
intelhex::hex_data::iterator iter = ithex.begin(); |
|
|
|
|
|
|
|
for (; iter != ithex.end(); iter++) { |
|
|
|
(*iter).second; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|