📄 convertdlg.cpp
字号:
// convertDlg.cpp : implementation file
//
#include "stdafx.h"
#include "convert.h"
#include "convertDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define FILESIZE 1024*128
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CConvertDlg dialog
CConvertDlg::CConvertDlg(CWnd* pParent /*=NULL*/)
: CDialog(CConvertDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CConvertDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CConvertDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CConvertDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CConvertDlg, CDialog)
//{{AFX_MSG_MAP(CConvertDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_OPEN, OnOpen)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CConvertDlg message handlers
BOOL CConvertDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CConvertDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CConvertDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CConvertDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CConvertDlg::OnOpen()
{
// TODO: Add your control notification handler code here
CFileDialog dlg(true, NULL, NULL, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, NULL, NULL );
dlg.DoModal();
my_filename=dlg.GetFileName();
CString filename;
filename="12.txt";
lpszPathName=dlg.GetPathName();
CFile filedes;
CFileException fedes;
CFile file;
CFileException fe;
int Max_Limit=4096*1024;
lpBuf = new CHAR[Max_Limit];
lpDes = new BYTE[Max_Limit];
int i=0;
count=0;
int len;
int BlockSize=1024;
bool bFlag;
////////文件信息
struct FileHeader s_fileheader;
struct OpHeader s_opheader;
struct Section s_section;
struct Relocation s_relocation;
// 打开文件
if (!file.Open(lpszPathName, CFile::modeRead | CFile::shareDenyWrite, &fe))
{
// 失败
//ReportSaveLoadException(lpszPathName, &fe,
// FALSE, AFX_IDP_FAILED_TO_OPEN_DOC);
// 返回FALSE
return ;
}
if (!filedes.Open(filename, CFile::modeCreate |CFile::modeReadWrite, &fe))// CFile::modeNoTruncate
{
// 失败
//ReportSaveLoadException(lpszPathName, &fe,
// FALSE, AFX_IDP_FAILED_TO_OPEN_DOC);
AfxMessageBox("error");
// 返回FALSE
return ;
}
//read file header
file.Read(&s_fileheader,22);
//read option file header
if(s_fileheader.op_header_size>0)
file.Read(&s_opheader,28);
//read section header
struct Section * pSection=new Section[s_fileheader.section_num];
struct Section * pSecHeader=pSection;
BYTE bBuff[FILESIZE];
memset(bBuff,(int)0,FILESIZE);
filedes.Write(bBuff,FILESIZE);
int iCopyTable[1024];
memset(iCopyTable,0,1024);
int iTableCount=0;
for(i=0;i<s_fileheader.section_num;i++)
{
file.Read(&s_section,48);
*pSecHeader=(s_section);
pSecHeader++;
}
pSecHeader=pSection;
for(i=0;i<s_fileheader.section_num;i++)
{
s_section=*pSecHeader;
pSecHeader++;
if(FlagAnalysis(s_section))
bFlag=SectionProcess(s_section);
else
bFlag=0;
if(bFlag)
{
file.Seek(s_section.p_data,CFile::begin);
file.Read(bBuff,s_section.size);
filedes.Seek(s_section.virtual_addr-0x01400000,CFile::begin);
filedes.Write(bBuff,s_section.size);
iCopyTable[iTableCount++]=s_section.size;
iCopyTable[iTableCount++]=s_section.virtual_addr;
iCopyTable[iTableCount++]=s_section.addr;
}
}
filedes.Seek(0x00018000,CFile::begin);
filedes.Write(iCopyTable,iTableCount*4);
//because filedes has initialed with 0,the end of copy_table need not be set with 0
/*int acc=0;
BYTE tempB,tempA,temp,aaa;
temp=tempA=tempB=0;
aaa=0;
while(1)
{
len=file.Read(lpBuf,BlockSize);
for(i=0;i<len;i++)
{
if(LookUp((lpBuf[i]))<16)
{
if(acc==0)
{
temp=LookUp((lpBuf[i]));
lpDes[count++]=temp;//LookUp((lpBuf[i]));
aaa=lpDes[count-1];
acc++;
continue;
}
if(acc==1)
{
lpDes[count-1]*=16;
tempA=lpDes[count-1];
lpDes[count-1]+=LookUp((lpBuf[i]));
tempB=lpDes[count-1];
acc++;
continue;
}
if(acc==2)
{
temp=LookUp((lpBuf[i]));
lpDes[count++]=temp;//LookUp((lpBuf[i]));
aaa=lpDes[count-1];
acc++;
continue;
}
if(acc==3)
{
lpDes[count-1]*=16;
tempA=lpDes[count-1];
lpDes[count-1]+=LookUp((lpBuf[i]));
tempB=lpDes[count-1];
temp=lpDes[count-1];
lpDes[count-1]=lpDes[count-2];
lpDes[count-2]=temp;
acc=0;
}
}
}
if(count>Max_Limit-BlockSize*3)
{
filedes.Write(lpDes,count);
count=0;
}
if(len<16)
{
filedes.Write(lpDes,count);
delete []lpBuf;
delete []lpDes;
return;
}
}*/
delete []pSection;
return;
}
BYTE CConvertDlg::LookUp(CHAR dec)
{
switch(dec)
{
case '1': return 1;
case '2': return 2;
case '3': return 3;
case '4': return 4;
case '5': return 5;
case '6': return 6;
case '7': return 7;
case '8': return 8;
case '9': return 9;
case '0': return 0;
case 'A': return 10;
case 'B': return 11;
case 'C': return 12;
case 'D': return 13;
case 'E': return 14;
case 'F': return 15;
case 'a': return 10;
case 'b': return 11;
case 'c': return 12;
case 'd': return 13;
case 'e': return 14;
case 'f': return 15;
default: return 100 ;
}
}
bool CConvertDlg::FlagAnalysis(struct Section ss)
{
UINT flag;
flag=ss.flag;
flag=flag&(0x80);
if(flag==0)
return 1;
else
return 0;
}
bool CConvertDlg::SectionProcess(struct Section ss)
{
UINT addr;
UINT vir_addr;
addr=ss.addr;
vir_addr=ss.virtual_addr;
if((vir_addr>=0x01400000) && (vir_addr<= 0x014fffff) && (addr!=vir_addr) )
return 1;
else
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -