// IROM_Fusing_ToolDlg.cpp : implementation file
//
#include <afx.h>
#include "stdafx.h"
#include "IROM_Fusing_Tool.h"
#include "IROM_Fusing_ToolDlg.h"
#include <WinIoCtl.h>
#include "shlwapi.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
#define EFUSE_RESEVED_SECTOR (2)
//#define SDHC_SHIFT_SECTOR (1024) // it's for SDHC card
#define SDHC_SHIFT_SECTOR (0) // it's for some SD/MMC cards that don't need any sector shift.
#define VOLUMEDISKSIZE (sizeof(VOLUME_DISK_EXTENTS))
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
// CIROM_Fusing_ToolDlg dialog
CIROM_Fusing_ToolDlg::CIROM_Fusing_ToolDlg(CWnd* pParent /*=NULL*/)
: CDialog(CIROM_Fusing_ToolDlg::IDD, pParent)
, m_strCombo(_T(""))
, m_dwDriveNumber(0)
, m_strDriveSize(_T(""))
, m_strFilePath(_T(""))
, m_dwTotalSector(0)
, m_pbWriteBuffer(NULL)
, m_dwStartWriteSector(0)
, m_strFromSector(_T(""))
, m_strToSector(_T(""))
, m_strTargetDrive(_T(""))
, m_nPhysicalNumber(0)
{
m_hIcon = AfxGetApp()->LoadIcon(IDI_ICON5);
}
void CIROM_Fusing_ToolDlg::DoDataExchange(CDataExchange* pDX)
{
// DDX_CBString(pDX, IDC_COMBO2, m_strCombo);
DDX_Text(pDX, IDC_EDIT1, m_strFilePath);
DDX_Text(pDX, IDC_EDIT7, m_strFilePath2);
DDX_Control(pDX, IDC_COMBO3, m_combox);
DDX_Control(pDX, IDC_EDIT1, m_string);
DDX_Control(pDX, IDC_EDIT5, m_report);
DDX_Control(pDX, IDC_EDIT6, m_drive);
DDX_Control(pDX, IDC_EDIT7, m_Path2);
DDX_Control(pDX, IDC_BUTTON3, m_Button2);
}
BEGIN_MESSAGE_MAP(CIROM_Fusing_ToolDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_EN_CHANGE(IDC_EDIT3, &CIROM_Fusing_ToolDlg::OnEnChangeEdit3)
ON_BN_CLICKED(ID_BUTTON_START, &CIROM_Fusing_ToolDlg::OnBnClickedButtonStart)
ON_EN_CHANGE(IDC_EDIT_SIZE, &CIROM_Fusing_ToolDlg::OnEnChangeEditSize)
ON_BN_CLICKED(IDC_BUTTON_BROWSE, &CIROM_Fusing_ToolDlg::OnBnClickedButtonBrowse)
// ON_BN_CLICKED(IDC_BUTTON1, &CIROM_Fusing_ToolDlg::OnBnClickedButton1)
ON_BN_CLICKED(IDC_BUTTON2, &CIROM_Fusing_ToolDlg::OnStart)
ON_CBN_SELCHANGE(IDC_COMBO3, &CIROM_Fusing_ToolDlg::OnCbnSelchangeCombo3)
ON_BN_CLICKED(IDC_BUTTON3, &CIROM_Fusing_ToolDlg::OnBnClickedButton3)
END_MESSAGE_MAP()
// CIROM_Fusing_ToolDlg message handlers
BOOL CIROM_Fusing_ToolDlg::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
m_combox.InsertString(0,_T("icool 210"));
m_combox.InsertString(1,_T("icool 2416"));
m_combox.InsertString(2,_T("icool 6410"));
m_combox.InsertString(3,_T("icool 4418"));
m_combox.SetCurSel(0);
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CIROM_Fusing_ToolDlg::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 CIROM_Fusing_ToolDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<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 function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CIROM_Fusing_ToolDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CIROM_Fusing_ToolDlg::OnEnChangeEdit3()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CIROM_Fusing_ToolDlg::OnCbnSelchangeComboDriveName()
{
}
int cal=0;
void CIROM_Fusing_ToolDlg::OnBnClickedButtonStart()
{
/*BOOL bRet = FALSE;
CFileFind finder;
bool bFound = finder.FindFile(m_strFilePath+_T("*"), 0);
while(bFound) // 递归拷贝
{
bFound = finder.FindNextFile();
if( finder.GetFileName() == "." || finder.GetFileName() == ".." )
continue;
CString strSubSrcPath = finder.GetFilePath();
CString strSubDespath = strSubSrcPath;
strSubDespath.Replace(m_strFilePath,m_strFilePath+_T("\\1"));
MessageBox(finder.GetFileTitle());
MessageBox(strSubDespath);
// if( finder.IsDirectory() )
// bRet = CopyDirectory(strSubSrcPath, strSubDespath, FALSE); // 递归拷贝文件夹
// else
bRet = CopyFile(strSubSrcPath, strSubDespath, FALSE); // 拷贝文件
if ( !bRet )
break;
}
finder.Close();
//MessageBox(TEXT("烧写完成"),TEXT("NOTICE"),NULL);
*/
//char szTemp[105]=;
// = new char[256]; //=(char *)m_strFilePath.GetBuffer(0);;
char szTemp[100];// =(char *)m_strFilePath.GetBuffer(0);
//strcpy(szTemp, (LPCTSTR)m_strFilePath);
// memset( szTemp, 0, sizeof(m_strFilePath) );
// strcpy(szTemp,(LPCSTR)m_strFilePath,m_strFilePath.GetAllocLength());
//sprintf(szTemp,"%s",m_strFilePath);
//memcpy(szTemp,(LPCSTR)m_strFilePath,m_strFilePath.GetAllocLength());
//strcpy( szTemp, (LPSTR)(LPCSTR)m_strFilePath.GetBuffer(m_strFilePath.GetLength()) );
// char szTemp1[256]="copy \"";//+szTemp;
// int i;
// char a[10];
//for (i=0;i<4;i++) a[i]=szTemp[i];
//strcpy(szTemp1,a);
CString cs;
///cs.Format(_T("%s"),szSelected);
//cs.Format(_T("%d%c%c%c%c%c%c"),sizeof(szSelected),szSelected[0],szSelected[1],szSelected[2],szSelected[3],szSelected[4],szSelected[5]);
//MessageBox(cs);
//char *buf="copy \"+"C:\\test.dll\";
char tmp[100];
char mm[100];
// mm=(char *) szSelected;
int nLen = wcslen(szSelected)+1;
WideCharToMultiByte(CP_ACP, 0, szSelected, nLen, mm,
2*nLen, NULL, NULL);
//="E:";
strcpy(sd , (LPSTR)(LPCTSTR)a);
strcat(sd,(":\\bin\\"));
// "copy \"C:\\Documents and Settings\\Administrator\\桌面\\test.dll\" C:\\"
sprintf(tmp, "copy %s\\*.prj %s", mm,sd);
// cs.Format(_T("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c"),mm[0],mm[1],mm[2],mm[3],mm[4],mm[5],tmp[6],tmp[7],tmp[8],tmp[9],tmp[10],tmp[11],tmp[12],tmp[13],tmp[14],tmp[15],tmp[16],tmp[17]);
//MessageBox(a);
CString strFolderPath(sd);//=sd;
//strFolderPath.Format(_T("%c"),sd);
// MessageBox(strFolderPath);
// 判断路径是否存在
if (!PathIsDirectory(strFolderPath) )
{
// CString strMsg;
// strMsg.Format ("指定路径\"%s\"不存在,是否创建?", strFolderPath);
// if (AfxMessageBox(strMsg, MB_YESNO) == IDYES)
{
if (!CreateDirectory(strFolderPath, NULL ) )
{
// strMsg.Format ("创建路径\"%s\"失败!是否继续?", m_strFolderPath);
// if (AfxMessageBox(strMsg, MB_YESNO) == IDYES)
// return;
}
}
}
// MessageBox(cs);
//system("copy C:\\test.dll C:\\1\\");
system(tmp);
CFile file;
CString filepath,filename,s;
filepath=_T("c:\\"); //文件位置
filename="Upadate.txt"; //文件名
filename=strFolderPath+filename; //文件路径
file.Open(filename,CFile::modeCreate|CFile::modeWrite);//建立文件
// s="Hello Motor!";
// file.Write(s,strlen(s)); //把字符串s写入文件
file.Close(); //关闭文件
// system("copy \"C:\\*.prj\" E:\\bin\\");
m_report.SetWindowTextW(TEXT("Write Succed\r\n"));
//m_report.SetDlgItemTextW(1,TEXT("Write Succed"));
return ;
}
int CIROM_Fusing_ToolDlg::ChangeStringDriveNameToDriveNumber(void)
{
DWORD dwReturnValue = TRUE;
UpdateData(TRUE);
m_strCombo="F";
if ( m_strCombo == "D")
m_dwDriveNumber = 3; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "E")
m_dwDriveNumber = 4; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "F")
m_dwDriveNumber = 5; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "G")
m_dwDriveNumber = 6; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "H")
m_dwDriveNumber = 7; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "I")
m_dwDriveNumber = 8; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "J")
m_dwDriveNumber = 9; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "K")
m_dwDriveNumber = 10; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "L")
m_dwDriveNumber = 11; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "M")
m_dwDriveNumber = 12; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "N")
m_dwDriveNumber = 13; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "O")
m_dwDriveNumber = 14; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "P")
m_dwDriveNumber = 15; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "Q")
m_dwDriveNumber = 16; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "R")
m_dwDriveNumber = 17; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "S")
m_dwDriveNumber = 18; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "T")
m_dwDriveNumber = 19; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "U")
m_dwDriveNumber = 20; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "V")
m_dwDriveNumber = 21; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "W")
m_dwDriveNumber = 22; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "X")
m_dwDriveNumber = 23; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "Y")
m_dwDriveNumber = 24; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "Z")
m_dwDriveNumber = 25; // driver number [0=A, 1=B, 2=C, 3=D ....]
else
dwReturnValue = FALSE;
return dwReturnValue;
}
char * CIROM_Fusing_ToolDlg::ReadSector(int startsector, int numberofsectors)
{
// All msdos data structures must be packed on a 1 byte boundary
#pragma pack (1)
struct
{
DWORD StartingSector ;
WORD NumberOfSectors ;
DWORD pBuffer;
}ControlBlock;
#pragma pack ()
#pragma pack (1)
typedef struct _DIOC_REGISTERS
{
DWORD reg_EBX;
DWORD reg_EDX;
DWORD reg_ECX;
DWORD reg_EAX;
DWORD reg_EDI;
DWORD reg_ESI;
DWORD reg_Flags;
} DIOC_REGISTERS ;
#pragma pack ()
char* buffer = (char*)malloc (512*numberofsectors);
HANDLE hDevice ;
DIOC_REGISTERS reg ;
BOOL fResult ;
DWORD cb ;
// Creating handle to vwin32.vxd (win 9x)
hDevice = CreateFile ( TEXT("\\\\.\\vwin32"),
0,
0,
NULL,
0,
FILE_FLAG_DELETE_ON_CLOSE,
NULL );
if ( hDevice == INVALID_HANDLE_VALUE )
{
// win NT/2K/XP code
HANDLE hDevice;
DWORD bytesread;
wchar_t _devicename[] = TEXT("\\\\.\\A:");
_devicename[4] += m_dwDriveNumber;
// Creating a handle to disk drive using CreateFile () function ..
hDevice = CreateFile(_devicename,
GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL);
if (hDevice == INVALID_HANDLE_VALUE)
{
free(buffer);
buffer = NULL;
goto finish;
}
// Setting the pointer to point to the start of the sector we want to read ..
SetFilePointer (hDevice, (startsector*512), NULL, FILE_BEGIN);
if (!ReadFile (hDevice, buffer, 512*numberofsectors, &bytesread, NULL) )
{
free(buffer);
buffer = NULL;
goto finish;
}
}
else
{
// code for win 95/98
ControlBlock.StartingSector = (DWORD)startsector;
ControlBlock.NumberOfSectors = (WORD)numberofsectors ;
ControlBlock.pBuffer = (DWORD)buffer ;
//-----------------------------------------------------------
// SI contains read/write mode flags
// SI=0h for read and SI=1h for write
// CX must be equal to ffffh for
// int 21h's 7305h extention
// DS:BX -> base addr of the
// control block structure
// DL must contain the drive number
// (01h=A:, 02h=B: etc)
//-----------------------------------------------------------
reg.reg_ESI = 0x00 ;
reg.reg_ECX = -1 ;
reg.reg_EBX = (DWORD)(&ControlBlock);
reg.reg_EDX = m_dwDriveNumber+1;
reg.reg_EAX = 0x7305 ;
// 6 == VWIN32_DIOC_DOS_DRIVEINFO
fResult = DeviceIoControl ( hDevice,
6,
&(reg),
sizeof (reg),
&(reg),
sizeof (reg),
&cb,
0);
if (!fResult || (reg.reg_Flags & 0x0001)) return NULL;
}
finish:
CloseHandle(hDevice);
return buffer;
}
void CIROM_Fusing_ToolDlg::OnEnChangeEditSize()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CIROM_Fusing_ToolDlg::OnBnClickedButtonBrowse()
{
// CFileDialog dlgFileOpen(TRUE,TEXT("*.*"),NULL,OFN_FILEMUSTEXIST,
// TEXT("Image(*.*)|*.*||"),NULL);
// if (dlgFileOpen.DoModal() == IDOK)
// {
// m_strFilePath = dlgFileOpen.GetPathName();
// UpdateData(FALSE);
// }
CString m_strFileOut = _T("");
//用来存放文件夹路径
BROWSEINFO bi;
LPITEMIDLIST pidl;
bi.hwndOwner = this->m_hWnd;
bi.pidlRoot = NULL;
bi.pszDisplayName = szSelected;
bi.lpszTitle = _T("选择输出文件路径");
bi.ulFlags = BIF_RETURNONLYFSDIRS;
bi.lpfn = NULL;
bi.lParam = NULL;
bi.iImage = NULL;
if((pidl = SHBrowseForFolder(&bi)) != NULL)
{
if(SUCCEEDED(SHGetPathFromIDList(pidl, szSelected))) //得到文件夹的全路径,不要的话,只得本文件夹名
{ SetDlgItemText(IDC_EDIT1, szSelected);
m_strFilePath =szSelected;
}
}
}
int CIROM_Fusing_ToolDlg::GetTotalSector(void)
{
struct _DISK_GEOMETRY_EX
{ DISK_GEOMETRY Geometry;
LARGE_INTEGER DiskSize;
UCHAR Data[1];
} DiskEX;
wchar_t temp2[20];
HANDLE hDevice;
DWORD bytesReturned;
DWORD totalSector = 0;
DWORD bRet;
wchar_t _devicename[] = TEXT("\\\\.\\A:");
_devicename[4] += m_dwDriveNumber;
// Creating a handle to disk drive using CreateFile () function ..
hDevice = CreateFile(_devicename,
GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL);
if (hDevice == INVALID_HANDLE_VALUE)
return FALSE;
bRet = DeviceIoControl(
hDevice, // handle to device
IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, // dwIoControlCode
NULL, // lpInBuffer
0, // nInBufferSize
(LPVOID) &DiskEX, // output buffer
sizeof(DiskEX), // size of output buffer
(LPDWORD) &bytesReturned , // number of bytes returned
NULL // OVERLAPPED structure
);
if (bRet == 0)
{
return FALSE;
}
if ( DiskEX.DiskSize.HighPart != 0 )
{
totalSector = ((DiskEX.DiskSize.HighPart) << 23);
}
totalSector |= (DiskEX.DiskSize.LowPart >> 9);
swprintf(temp2,20,L"%d sectors",totalSector);
m_strDriveSize = temp2;
UpdateData(FALSE);
m_dwTotalSector = totalSector;
return TRUE;
}
int CIROM_Fusing_ToolDlg::WriteSector(int startsector, int numberofsectors, char *buffer)
{
wchar_t temp2[20];
LARGE_INTEGER startbytes;
CString StringTemp;
// All msdos data structures must be packed on a 1 byte boundary
#pragma pack (1)
struct
{
DWORD StartingSector ;
WORD NumberOfSectors ;
DWORD pBuffer;
}ControlBlock;
#pragma pack ()
#pragma pack (1)
typedef struct _DIOC_REGISTERS
{
DWORD reg_EBX;
DWORD reg_EDX;
DWORD reg_ECX;
DWORD reg_EAX;
DWORD reg_EDI;
DWORD reg_ESI;
DWORD reg_Flags;
} DIOC_REGISTERS ;
#pragma pack ()
HANDLE hDevice ;
DIOC_REGISTERS reg ;
BOOL fResult ;
DWORD cb ;
// Creating handle to vwin32.vxd (win 9x)
/*hDevice = CreateFile ( TEXT("\\\\.\\vwin32"),
0,
0,
NULL,
0,
FILE_FLAG_DELETE_ON_CLOSE,
NULL );*/
if ( 1 )
{
// win NT/2K/XP code
//HANDLE hDevice;
DWORD byteswrite;
wchar_t _devicename[30];
if (m_nPhysicalNumber == 0 )
return FALSE;
//m_nPhysicalNumber=6;
swprintf(_devicename,30,TEXT("\\\\.\\PhysicalDrive%d"), m_nPhysicalNumber);
//MessageBox(_devicename);
// Creating a handle to disk drive using CreateFile () function ..
hDevice = CreateFile(_devicename,
GENERIC_READ | GENERIC_WRITE , FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING,0 , NULL);
if (hDevice == INVALID_HANDLE_VALUE)
{
// MessageBox(_T("INVALID_HANDLE_VALUE"));
return FALSE;
}
startbytes.LowPart = ((startsector&0x7fffff) << 9);
if (startsector&0xff800000)
startbytes.HighPart = ((startsector&0xff800000)>>23);
else
startbytes.HighPart = 0;
// Setting the pointer to point to the start of the sector we want to read ..
SetFilePointerEx (hDevice, startbytes, NULL, FILE_BEGIN);
//SetFilePointer (hDevice, ((startsector&0x7fffff) << 9), NULL, FILE_BEGIN);
if (!WriteFile (hDevice, buffer, 512*numberofsectors, &byteswrite, NULL) )
return FALSE;
if (byteswrite != (512*numberofsectors))
{
swprintf(temp2,20,L"%d sectors",byteswrite);
StringTemp = temp2;
MessageBox((TEXT("Only copy ")+StringTemp),TEXT("ERROR"),NULL);
return FALSE;
}
}
else
{
// code for win 95/98
ControlBlock.StartingSector = (DWORD)startsector;
ControlBlock.NumberOfSectors = (WORD)numberofsectors ;
ControlBlock.pBuffer = (DWORD)buffer ;
//-----------------------------------------------------------
// SI contains read/write mode flags
// SI=0h for read and SI=1h for write
// CX must be equal to ffffh for
// int 21h's 7305h extention
// DS:BX -> base addr of the
// control block structure
// DL must contain the drive number
// (01h=A:, 02h=B: etc)
//-----------------------------------------------------------
reg.reg_ESI = 0x00 ;
reg.reg_ECX = -1 ;
reg.reg_EBX = (DWORD)(&ControlBlock);
reg.reg_EDX = m_dwDriveNumber+1;
reg.reg_EAX = 0x7305 ;
// 6 == VWIN32_DIOC_DOS_DRIVEINFO
fResult = DeviceIoControl ( hDevice,
6,
&(reg),
sizeof (reg),
&(reg),
sizeof (reg),
&cb,
0);
if (!fResult || (reg.reg_Flags & 0x0001)) return FALSE;
}
CloseHandle(hDevice);
return TRUE;
}
void CIROM_Fusing_ToolDlg::InitMemberVariables(void)
{
m_dwDriveNumber = 0x100;
m_dwStartWriteSector = 0x0;
m_dwTotalSector = 0;
if (m_pbWriteBuffer != NULL)
{
free(m_pbWriteBuffer);
m_pbWriteBuffer = NULL;
}
m_strCombo.Empty();
m_strDriveSize.Empty();
m_strFilePath.Empty();
m_fileImageFile.Close();
}
int CIROM_Fusing_ToolDlg::GetPhysicalDriveNumber( char cDriveName )
{
HANDLE hDevice;
DWORD dwOut;
BOOL bRet;
wchar_t vcDriveName[ 40 ];
VOLUME_DISK_EXTENTS* pstVolumeData;
int iDiskNumber;
// alloc memory
pstVolumeData = ( VOLUME_DISK_EXTENTS * ) malloc( VOLUMEDISKSIZE );
if( pstVolumeData == NULL )
{
return -1;
}
//
swprintf( vcDriveName,7,TEXT("\\\\?\\%c:"), cDriveName );
// Open Device
hDevice = CreateFile( vcDriveName, GENERIC_READ, FILE_SHARE_READ |
FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL );
if( hDevice == INVALID_HANDLE_VALUE )
{
return -1;
}
// Call Device Io Control
bRet = DeviceIoControl( hDevice, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS,
NULL, 0, pstVolumeData, VOLUMEDISKSIZE, &dwOut, NULL );
if( bRet == FALSE )
{
free( pstVolumeData );
return -1;
}
CloseHandle( hDevice );
// Disk number is lower than 1 is failed.
if( pstVolumeData->NumberOfDiskExtents < 1 )
{
free( pstVolumeData );
return -1;
}
iDiskNumber = pstVolumeData->Extents[ 0 ].DiskNumber;
free( pstVolumeData );
return iDiskNumber;
}
int CIROM_Fusing_ToolDlg::GetSettingFromINIFile(void)
{
HANDLE hFile;
wchar_t buffer[1024];
// wchar_t filename[868];
// wchar_t drivename;
// wchar_t temp2[868];
DWORD bytesread;
hFile = CreateFile( TEXT("irom.ini"), GENERIC_READ, FILE_SHARE_READ |
FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL );
if (hFile == INVALID_HANDLE_VALUE)
{
if (!CreateINIFile())
{
CloseHandle(hFile);
return FALSE;
}
hFile = CreateFile( TEXT("irom.ini"), GENERIC_READ, FILE_SHARE_READ |
FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL );
if (hFile == INVALID_HANDLE_VALUE)
{
CloseHandle(hFile);
return FALSE;
}
}
if(!ReadFile (hFile, buffer, 1024 * sizeof(wchar_t), &bytesread, NULL))
{
CloseHandle(hFile);
return FALSE;
}
if ( buffer[0] != 0xaa ||
buffer[1] != 0xbb ||
buffer[2] != 0xcc ||
buffer[3] != 0xdd ||
buffer[4] != 0xee )
{
CloseHandle(hFile);
return FALSE;
}
if ( buffer[6] == TEXT('\0'))
{
return FALSE;
}
return TRUE;
}
int CIROM_Fusing_ToolDlg::CreateINIFile(void)
{
wchar_t buffer[1024] = {TEXT('\0'),};
DWORD byteswrite;
HANDLE hFile;
buffer[0] = 0xaa;
buffer[1] = 0xbb;
buffer[2] = 0xcc;
buffer[3] = 0xdd;
buffer[4] = 0xff;
hFile = CreateFile( TEXT("irom.ini"), GENERIC_WRITE, FILE_SHARE_READ |
FILE_SHARE_WRITE, NULL, CREATE_NEW, 0, NULL );
if (hFile == INVALID_HANDLE_VALUE)
{
CloseHandle(hFile);
return FALSE;
}
if(!WriteFile (hFile, buffer, 1024 * sizeof(wchar_t), &byteswrite, NULL))
{
CloseHandle(hFile);
return FALSE;
}
CloseHandle(hFile);
return TRUE;
}
void CIROM_Fusing_ToolDlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
HANDLE hPtoken = NULL ;
//INTER_GetExplorerToken( &hPtoken ) ;
PROCESS_INFORMATION pi;
STARTUPINFO si = { sizeof(STARTUPINFO),NULL,_T(""),NULL,0,0,0,0,0,0,0,STARTF_USESHOWWINDOW,0,0,NULL,0,0,0};
si.wShowWindow = SW_SHOW;
si.lpDesktop = NULL;
ZeroMemory( &pi, sizeof(pi) );
CreateProcessAsUser( hPtoken ,_T("E:\\1\\IROM_Fusing_Tool_src\Release\\IROM_Fusing_Tool.exe"),NULL ,
NULL,NULL,FALSE , NORMAL_PRIORITY_CLASS| CREATE_NEW_CONSOLE ,NULL,NULL,&si,&pi ) ;
Sleep(1000);
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}
void CIROM_Fusing_ToolDlg::OnStart()
{
// TODO: 在此添加控件通知处理程序代码
int i,ii,iii;
char ab='D';
int m_panfu;
CString cs;
for( m_panfu=3;m_panfu<25;m_panfu++)
{
b.Format(_T("%c:\\"),ab);
ii=GetDriveType(b);
if(ii==2)
{
break;
}
ab++;
}
m_dwDriveNumber=m_panfu;
// MessageBox(b);
if ( m_panfu == 3)
a = "D"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu ==4 )
a = "E"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 5)
a = "F"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 6)
a = "G"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu ==7)
a = "H"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 8)
a = "I"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 9)
a = "J"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 10)
a = "K";// driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 11)
a = "L";// driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 12)
a = "M"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 13)
a = "N"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 14)
a = "O";// driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 15)
a = "P"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 16)
a = "Q"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 17)
a = "R"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 18)
a = "S"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 19)
a = "T"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 20)
a = "U"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 21)
a = "V"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 22)
a = "W"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 23)
a = "X"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 24)
a = "Y"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 25)
a = "Z";// driver number [0=A, 1=B, 2=C, 3=D ....]
else
a = "";
cs.Format(_T("%c",m_panfu));
m_drive.SetWindowTextW(b.Left(3));
}
void CIROM_Fusing_ToolDlg::OnCbnSelchangeCombo3()
{
CString strcurent;
m_combox.GetLBText(m_combox.GetCurSel(),strcurent);
if(strcurent==(_T("icool 4418")))
{
// TODO: 在此添加控件通知处理程序代码
GetDlgItem(IDC_EDIT7)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_BUTTON3)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_Nboot)->ShowWindow(SW_SHOW);
}
else
{
GetDlgItem(IDC_EDIT7)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_BUTTON3)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_Nboot)->ShowWindow(SW_HIDE);
}
}
void CIROM_Fusing_ToolDlg::OnBnClickedButton3()
{
// TODO: 在此添加控件通知处理程序代码
CFileDialog dlgFileOpen(TRUE,TEXT("*.*"),NULL,OFN_FILEMUSTEXIST,
TEXT("Image(*.*)|*.*||"),NULL);
if (dlgFileOpen.DoModal() == IDOK)
{
m_strFilePath2 = dlgFileOpen.GetPathName();
UpdateData(FALSE);
}
}
//
#include <afx.h>
#include "stdafx.h"
#include "IROM_Fusing_Tool.h"
#include "IROM_Fusing_ToolDlg.h"
#include <WinIoCtl.h>
#include "shlwapi.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
#define EFUSE_RESEVED_SECTOR (2)
//#define SDHC_SHIFT_SECTOR (1024) // it's for SDHC card
#define SDHC_SHIFT_SECTOR (0) // it's for some SD/MMC cards that don't need any sector shift.
#define VOLUMEDISKSIZE (sizeof(VOLUME_DISK_EXTENTS))
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
enum { IDD = IDD_ABOUTBOX };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
// Implementation
protected:
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
// CIROM_Fusing_ToolDlg dialog
CIROM_Fusing_ToolDlg::CIROM_Fusing_ToolDlg(CWnd* pParent /*=NULL*/)
: CDialog(CIROM_Fusing_ToolDlg::IDD, pParent)
, m_strCombo(_T(""))
, m_dwDriveNumber(0)
, m_strDriveSize(_T(""))
, m_strFilePath(_T(""))
, m_dwTotalSector(0)
, m_pbWriteBuffer(NULL)
, m_dwStartWriteSector(0)
, m_strFromSector(_T(""))
, m_strToSector(_T(""))
, m_strTargetDrive(_T(""))
, m_nPhysicalNumber(0)
{
m_hIcon = AfxGetApp()->LoadIcon(IDI_ICON5);
}
void CIROM_Fusing_ToolDlg::DoDataExchange(CDataExchange* pDX)
{
// DDX_CBString(pDX, IDC_COMBO2, m_strCombo);
DDX_Text(pDX, IDC_EDIT1, m_strFilePath);
DDX_Text(pDX, IDC_EDIT7, m_strFilePath2);
DDX_Control(pDX, IDC_COMBO3, m_combox);
DDX_Control(pDX, IDC_EDIT1, m_string);
DDX_Control(pDX, IDC_EDIT5, m_report);
DDX_Control(pDX, IDC_EDIT6, m_drive);
DDX_Control(pDX, IDC_EDIT7, m_Path2);
DDX_Control(pDX, IDC_BUTTON3, m_Button2);
}
BEGIN_MESSAGE_MAP(CIROM_Fusing_ToolDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
//}}AFX_MSG_MAP
ON_EN_CHANGE(IDC_EDIT3, &CIROM_Fusing_ToolDlg::OnEnChangeEdit3)
ON_BN_CLICKED(ID_BUTTON_START, &CIROM_Fusing_ToolDlg::OnBnClickedButtonStart)
ON_EN_CHANGE(IDC_EDIT_SIZE, &CIROM_Fusing_ToolDlg::OnEnChangeEditSize)
ON_BN_CLICKED(IDC_BUTTON_BROWSE, &CIROM_Fusing_ToolDlg::OnBnClickedButtonBrowse)
// ON_BN_CLICKED(IDC_BUTTON1, &CIROM_Fusing_ToolDlg::OnBnClickedButton1)
ON_BN_CLICKED(IDC_BUTTON2, &CIROM_Fusing_ToolDlg::OnStart)
ON_CBN_SELCHANGE(IDC_COMBO3, &CIROM_Fusing_ToolDlg::OnCbnSelchangeCombo3)
ON_BN_CLICKED(IDC_BUTTON3, &CIROM_Fusing_ToolDlg::OnBnClickedButton3)
END_MESSAGE_MAP()
// CIROM_Fusing_ToolDlg message handlers
BOOL CIROM_Fusing_ToolDlg::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
m_combox.InsertString(0,_T("icool 210"));
m_combox.InsertString(1,_T("icool 2416"));
m_combox.InsertString(2,_T("icool 6410"));
m_combox.InsertString(3,_T("icool 4418"));
m_combox.SetCurSel(0);
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CIROM_Fusing_ToolDlg::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 CIROM_Fusing_ToolDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, reinterpret_cast<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 function to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CIROM_Fusing_ToolDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CIROM_Fusing_ToolDlg::OnEnChangeEdit3()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CIROM_Fusing_ToolDlg::OnCbnSelchangeComboDriveName()
{
}
int cal=0;
void CIROM_Fusing_ToolDlg::OnBnClickedButtonStart()
{
/*BOOL bRet = FALSE;
CFileFind finder;
bool bFound = finder.FindFile(m_strFilePath+_T("*"), 0);
while(bFound) // 递归拷贝
{
bFound = finder.FindNextFile();
if( finder.GetFileName() == "." || finder.GetFileName() == ".." )
continue;
CString strSubSrcPath = finder.GetFilePath();
CString strSubDespath = strSubSrcPath;
strSubDespath.Replace(m_strFilePath,m_strFilePath+_T("\\1"));
MessageBox(finder.GetFileTitle());
MessageBox(strSubDespath);
// if( finder.IsDirectory() )
// bRet = CopyDirectory(strSubSrcPath, strSubDespath, FALSE); // 递归拷贝文件夹
// else
bRet = CopyFile(strSubSrcPath, strSubDespath, FALSE); // 拷贝文件
if ( !bRet )
break;
}
finder.Close();
//MessageBox(TEXT("烧写完成"),TEXT("NOTICE"),NULL);
*/
//char szTemp[105]=;
// = new char[256]; //=(char *)m_strFilePath.GetBuffer(0);;
char szTemp[100];// =(char *)m_strFilePath.GetBuffer(0);
//strcpy(szTemp, (LPCTSTR)m_strFilePath);
// memset( szTemp, 0, sizeof(m_strFilePath) );
// strcpy(szTemp,(LPCSTR)m_strFilePath,m_strFilePath.GetAllocLength());
//sprintf(szTemp,"%s",m_strFilePath);
//memcpy(szTemp,(LPCSTR)m_strFilePath,m_strFilePath.GetAllocLength());
//strcpy( szTemp, (LPSTR)(LPCSTR)m_strFilePath.GetBuffer(m_strFilePath.GetLength()) );
// char szTemp1[256]="copy \"";//+szTemp;
// int i;
// char a[10];
//for (i=0;i<4;i++) a[i]=szTemp[i];
//strcpy(szTemp1,a);
CString cs;
///cs.Format(_T("%s"),szSelected);
//cs.Format(_T("%d%c%c%c%c%c%c"),sizeof(szSelected),szSelected[0],szSelected[1],szSelected[2],szSelected[3],szSelected[4],szSelected[5]);
//MessageBox(cs);
//char *buf="copy \"+"C:\\test.dll\";
char tmp[100];
char mm[100];
// mm=(char *) szSelected;
int nLen = wcslen(szSelected)+1;
WideCharToMultiByte(CP_ACP, 0, szSelected, nLen, mm,
2*nLen, NULL, NULL);
//="E:";
strcpy(sd , (LPSTR)(LPCTSTR)a);
strcat(sd,(":\\bin\\"));
// "copy \"C:\\Documents and Settings\\Administrator\\桌面\\test.dll\" C:\\"
sprintf(tmp, "copy %s\\*.prj %s", mm,sd);
// cs.Format(_T("%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c"),mm[0],mm[1],mm[2],mm[3],mm[4],mm[5],tmp[6],tmp[7],tmp[8],tmp[9],tmp[10],tmp[11],tmp[12],tmp[13],tmp[14],tmp[15],tmp[16],tmp[17]);
//MessageBox(a);
CString strFolderPath(sd);//=sd;
//strFolderPath.Format(_T("%c"),sd);
// MessageBox(strFolderPath);
// 判断路径是否存在
if (!PathIsDirectory(strFolderPath) )
{
// CString strMsg;
// strMsg.Format ("指定路径\"%s\"不存在,是否创建?", strFolderPath);
// if (AfxMessageBox(strMsg, MB_YESNO) == IDYES)
{
if (!CreateDirectory(strFolderPath, NULL ) )
{
// strMsg.Format ("创建路径\"%s\"失败!是否继续?", m_strFolderPath);
// if (AfxMessageBox(strMsg, MB_YESNO) == IDYES)
// return;
}
}
}
// MessageBox(cs);
//system("copy C:\\test.dll C:\\1\\");
system(tmp);
CFile file;
CString filepath,filename,s;
filepath=_T("c:\\"); //文件位置
filename="Upadate.txt"; //文件名
filename=strFolderPath+filename; //文件路径
file.Open(filename,CFile::modeCreate|CFile::modeWrite);//建立文件
// s="Hello Motor!";
// file.Write(s,strlen(s)); //把字符串s写入文件
file.Close(); //关闭文件
// system("copy \"C:\\*.prj\" E:\\bin\\");
m_report.SetWindowTextW(TEXT("Write Succed\r\n"));
//m_report.SetDlgItemTextW(1,TEXT("Write Succed"));
return ;
}
int CIROM_Fusing_ToolDlg::ChangeStringDriveNameToDriveNumber(void)
{
DWORD dwReturnValue = TRUE;
UpdateData(TRUE);
m_strCombo="F";
if ( m_strCombo == "D")
m_dwDriveNumber = 3; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "E")
m_dwDriveNumber = 4; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "F")
m_dwDriveNumber = 5; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "G")
m_dwDriveNumber = 6; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "H")
m_dwDriveNumber = 7; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "I")
m_dwDriveNumber = 8; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "J")
m_dwDriveNumber = 9; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "K")
m_dwDriveNumber = 10; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "L")
m_dwDriveNumber = 11; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "M")
m_dwDriveNumber = 12; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "N")
m_dwDriveNumber = 13; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "O")
m_dwDriveNumber = 14; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "P")
m_dwDriveNumber = 15; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "Q")
m_dwDriveNumber = 16; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "R")
m_dwDriveNumber = 17; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "S")
m_dwDriveNumber = 18; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "T")
m_dwDriveNumber = 19; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "U")
m_dwDriveNumber = 20; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "V")
m_dwDriveNumber = 21; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "W")
m_dwDriveNumber = 22; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "X")
m_dwDriveNumber = 23; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "Y")
m_dwDriveNumber = 24; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_strCombo == "Z")
m_dwDriveNumber = 25; // driver number [0=A, 1=B, 2=C, 3=D ....]
else
dwReturnValue = FALSE;
return dwReturnValue;
}
char * CIROM_Fusing_ToolDlg::ReadSector(int startsector, int numberofsectors)
{
// All msdos data structures must be packed on a 1 byte boundary
#pragma pack (1)
struct
{
DWORD StartingSector ;
WORD NumberOfSectors ;
DWORD pBuffer;
}ControlBlock;
#pragma pack ()
#pragma pack (1)
typedef struct _DIOC_REGISTERS
{
DWORD reg_EBX;
DWORD reg_EDX;
DWORD reg_ECX;
DWORD reg_EAX;
DWORD reg_EDI;
DWORD reg_ESI;
DWORD reg_Flags;
} DIOC_REGISTERS ;
#pragma pack ()
char* buffer = (char*)malloc (512*numberofsectors);
HANDLE hDevice ;
DIOC_REGISTERS reg ;
BOOL fResult ;
DWORD cb ;
// Creating handle to vwin32.vxd (win 9x)
hDevice = CreateFile ( TEXT("\\\\.\\vwin32"),
0,
0,
NULL,
0,
FILE_FLAG_DELETE_ON_CLOSE,
NULL );
if ( hDevice == INVALID_HANDLE_VALUE )
{
// win NT/2K/XP code
HANDLE hDevice;
DWORD bytesread;
wchar_t _devicename[] = TEXT("\\\\.\\A:");
_devicename[4] += m_dwDriveNumber;
// Creating a handle to disk drive using CreateFile () function ..
hDevice = CreateFile(_devicename,
GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL);
if (hDevice == INVALID_HANDLE_VALUE)
{
free(buffer);
buffer = NULL;
goto finish;
}
// Setting the pointer to point to the start of the sector we want to read ..
SetFilePointer (hDevice, (startsector*512), NULL, FILE_BEGIN);
if (!ReadFile (hDevice, buffer, 512*numberofsectors, &bytesread, NULL) )
{
free(buffer);
buffer = NULL;
goto finish;
}
}
else
{
// code for win 95/98
ControlBlock.StartingSector = (DWORD)startsector;
ControlBlock.NumberOfSectors = (WORD)numberofsectors ;
ControlBlock.pBuffer = (DWORD)buffer ;
//-----------------------------------------------------------
// SI contains read/write mode flags
// SI=0h for read and SI=1h for write
// CX must be equal to ffffh for
// int 21h's 7305h extention
// DS:BX -> base addr of the
// control block structure
// DL must contain the drive number
// (01h=A:, 02h=B: etc)
//-----------------------------------------------------------
reg.reg_ESI = 0x00 ;
reg.reg_ECX = -1 ;
reg.reg_EBX = (DWORD)(&ControlBlock);
reg.reg_EDX = m_dwDriveNumber+1;
reg.reg_EAX = 0x7305 ;
// 6 == VWIN32_DIOC_DOS_DRIVEINFO
fResult = DeviceIoControl ( hDevice,
6,
&(reg),
sizeof (reg),
&(reg),
sizeof (reg),
&cb,
0);
if (!fResult || (reg.reg_Flags & 0x0001)) return NULL;
}
finish:
CloseHandle(hDevice);
return buffer;
}
void CIROM_Fusing_ToolDlg::OnEnChangeEditSize()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
}
void CIROM_Fusing_ToolDlg::OnBnClickedButtonBrowse()
{
// CFileDialog dlgFileOpen(TRUE,TEXT("*.*"),NULL,OFN_FILEMUSTEXIST,
// TEXT("Image(*.*)|*.*||"),NULL);
// if (dlgFileOpen.DoModal() == IDOK)
// {
// m_strFilePath = dlgFileOpen.GetPathName();
// UpdateData(FALSE);
// }
CString m_strFileOut = _T("");
//用来存放文件夹路径
BROWSEINFO bi;
LPITEMIDLIST pidl;
bi.hwndOwner = this->m_hWnd;
bi.pidlRoot = NULL;
bi.pszDisplayName = szSelected;
bi.lpszTitle = _T("选择输出文件路径");
bi.ulFlags = BIF_RETURNONLYFSDIRS;
bi.lpfn = NULL;
bi.lParam = NULL;
bi.iImage = NULL;
if((pidl = SHBrowseForFolder(&bi)) != NULL)
{
if(SUCCEEDED(SHGetPathFromIDList(pidl, szSelected))) //得到文件夹的全路径,不要的话,只得本文件夹名
{ SetDlgItemText(IDC_EDIT1, szSelected);
m_strFilePath =szSelected;
}
}
}
int CIROM_Fusing_ToolDlg::GetTotalSector(void)
{
struct _DISK_GEOMETRY_EX
{ DISK_GEOMETRY Geometry;
LARGE_INTEGER DiskSize;
UCHAR Data[1];
} DiskEX;
wchar_t temp2[20];
HANDLE hDevice;
DWORD bytesReturned;
DWORD totalSector = 0;
DWORD bRet;
wchar_t _devicename[] = TEXT("\\\\.\\A:");
_devicename[4] += m_dwDriveNumber;
// Creating a handle to disk drive using CreateFile () function ..
hDevice = CreateFile(_devicename,
GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING, 0, NULL);
if (hDevice == INVALID_HANDLE_VALUE)
return FALSE;
bRet = DeviceIoControl(
hDevice, // handle to device
IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, // dwIoControlCode
NULL, // lpInBuffer
0, // nInBufferSize
(LPVOID) &DiskEX, // output buffer
sizeof(DiskEX), // size of output buffer
(LPDWORD) &bytesReturned , // number of bytes returned
NULL // OVERLAPPED structure
);
if (bRet == 0)
{
return FALSE;
}
if ( DiskEX.DiskSize.HighPart != 0 )
{
totalSector = ((DiskEX.DiskSize.HighPart) << 23);
}
totalSector |= (DiskEX.DiskSize.LowPart >> 9);
swprintf(temp2,20,L"%d sectors",totalSector);
m_strDriveSize = temp2;
UpdateData(FALSE);
m_dwTotalSector = totalSector;
return TRUE;
}
int CIROM_Fusing_ToolDlg::WriteSector(int startsector, int numberofsectors, char *buffer)
{
wchar_t temp2[20];
LARGE_INTEGER startbytes;
CString StringTemp;
// All msdos data structures must be packed on a 1 byte boundary
#pragma pack (1)
struct
{
DWORD StartingSector ;
WORD NumberOfSectors ;
DWORD pBuffer;
}ControlBlock;
#pragma pack ()
#pragma pack (1)
typedef struct _DIOC_REGISTERS
{
DWORD reg_EBX;
DWORD reg_EDX;
DWORD reg_ECX;
DWORD reg_EAX;
DWORD reg_EDI;
DWORD reg_ESI;
DWORD reg_Flags;
} DIOC_REGISTERS ;
#pragma pack ()
HANDLE hDevice ;
DIOC_REGISTERS reg ;
BOOL fResult ;
DWORD cb ;
// Creating handle to vwin32.vxd (win 9x)
/*hDevice = CreateFile ( TEXT("\\\\.\\vwin32"),
0,
0,
NULL,
0,
FILE_FLAG_DELETE_ON_CLOSE,
NULL );*/
if ( 1 )
{
// win NT/2K/XP code
//HANDLE hDevice;
DWORD byteswrite;
wchar_t _devicename[30];
if (m_nPhysicalNumber == 0 )
return FALSE;
//m_nPhysicalNumber=6;
swprintf(_devicename,30,TEXT("\\\\.\\PhysicalDrive%d"), m_nPhysicalNumber);
//MessageBox(_devicename);
// Creating a handle to disk drive using CreateFile () function ..
hDevice = CreateFile(_devicename,
GENERIC_READ | GENERIC_WRITE , FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING,0 , NULL);
if (hDevice == INVALID_HANDLE_VALUE)
{
// MessageBox(_T("INVALID_HANDLE_VALUE"));
return FALSE;
}
startbytes.LowPart = ((startsector&0x7fffff) << 9);
if (startsector&0xff800000)
startbytes.HighPart = ((startsector&0xff800000)>>23);
else
startbytes.HighPart = 0;
// Setting the pointer to point to the start of the sector we want to read ..
SetFilePointerEx (hDevice, startbytes, NULL, FILE_BEGIN);
//SetFilePointer (hDevice, ((startsector&0x7fffff) << 9), NULL, FILE_BEGIN);
if (!WriteFile (hDevice, buffer, 512*numberofsectors, &byteswrite, NULL) )
return FALSE;
if (byteswrite != (512*numberofsectors))
{
swprintf(temp2,20,L"%d sectors",byteswrite);
StringTemp = temp2;
MessageBox((TEXT("Only copy ")+StringTemp),TEXT("ERROR"),NULL);
return FALSE;
}
}
else
{
// code for win 95/98
ControlBlock.StartingSector = (DWORD)startsector;
ControlBlock.NumberOfSectors = (WORD)numberofsectors ;
ControlBlock.pBuffer = (DWORD)buffer ;
//-----------------------------------------------------------
// SI contains read/write mode flags
// SI=0h for read and SI=1h for write
// CX must be equal to ffffh for
// int 21h's 7305h extention
// DS:BX -> base addr of the
// control block structure
// DL must contain the drive number
// (01h=A:, 02h=B: etc)
//-----------------------------------------------------------
reg.reg_ESI = 0x00 ;
reg.reg_ECX = -1 ;
reg.reg_EBX = (DWORD)(&ControlBlock);
reg.reg_EDX = m_dwDriveNumber+1;
reg.reg_EAX = 0x7305 ;
// 6 == VWIN32_DIOC_DOS_DRIVEINFO
fResult = DeviceIoControl ( hDevice,
6,
&(reg),
sizeof (reg),
&(reg),
sizeof (reg),
&cb,
0);
if (!fResult || (reg.reg_Flags & 0x0001)) return FALSE;
}
CloseHandle(hDevice);
return TRUE;
}
void CIROM_Fusing_ToolDlg::InitMemberVariables(void)
{
m_dwDriveNumber = 0x100;
m_dwStartWriteSector = 0x0;
m_dwTotalSector = 0;
if (m_pbWriteBuffer != NULL)
{
free(m_pbWriteBuffer);
m_pbWriteBuffer = NULL;
}
m_strCombo.Empty();
m_strDriveSize.Empty();
m_strFilePath.Empty();
m_fileImageFile.Close();
}
int CIROM_Fusing_ToolDlg::GetPhysicalDriveNumber( char cDriveName )
{
HANDLE hDevice;
DWORD dwOut;
BOOL bRet;
wchar_t vcDriveName[ 40 ];
VOLUME_DISK_EXTENTS* pstVolumeData;
int iDiskNumber;
// alloc memory
pstVolumeData = ( VOLUME_DISK_EXTENTS * ) malloc( VOLUMEDISKSIZE );
if( pstVolumeData == NULL )
{
return -1;
}
//
swprintf( vcDriveName,7,TEXT("\\\\?\\%c:"), cDriveName );
// Open Device
hDevice = CreateFile( vcDriveName, GENERIC_READ, FILE_SHARE_READ |
FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL );
if( hDevice == INVALID_HANDLE_VALUE )
{
return -1;
}
// Call Device Io Control
bRet = DeviceIoControl( hDevice, IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS,
NULL, 0, pstVolumeData, VOLUMEDISKSIZE, &dwOut, NULL );
if( bRet == FALSE )
{
free( pstVolumeData );
return -1;
}
CloseHandle( hDevice );
// Disk number is lower than 1 is failed.
if( pstVolumeData->NumberOfDiskExtents < 1 )
{
free( pstVolumeData );
return -1;
}
iDiskNumber = pstVolumeData->Extents[ 0 ].DiskNumber;
free( pstVolumeData );
return iDiskNumber;
}
int CIROM_Fusing_ToolDlg::GetSettingFromINIFile(void)
{
HANDLE hFile;
wchar_t buffer[1024];
// wchar_t filename[868];
// wchar_t drivename;
// wchar_t temp2[868];
DWORD bytesread;
hFile = CreateFile( TEXT("irom.ini"), GENERIC_READ, FILE_SHARE_READ |
FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL );
if (hFile == INVALID_HANDLE_VALUE)
{
if (!CreateINIFile())
{
CloseHandle(hFile);
return FALSE;
}
hFile = CreateFile( TEXT("irom.ini"), GENERIC_READ, FILE_SHARE_READ |
FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL );
if (hFile == INVALID_HANDLE_VALUE)
{
CloseHandle(hFile);
return FALSE;
}
}
if(!ReadFile (hFile, buffer, 1024 * sizeof(wchar_t), &bytesread, NULL))
{
CloseHandle(hFile);
return FALSE;
}
if ( buffer[0] != 0xaa ||
buffer[1] != 0xbb ||
buffer[2] != 0xcc ||
buffer[3] != 0xdd ||
buffer[4] != 0xee )
{
CloseHandle(hFile);
return FALSE;
}
if ( buffer[6] == TEXT('\0'))
{
return FALSE;
}
return TRUE;
}
int CIROM_Fusing_ToolDlg::CreateINIFile(void)
{
wchar_t buffer[1024] = {TEXT('\0'),};
DWORD byteswrite;
HANDLE hFile;
buffer[0] = 0xaa;
buffer[1] = 0xbb;
buffer[2] = 0xcc;
buffer[3] = 0xdd;
buffer[4] = 0xff;
hFile = CreateFile( TEXT("irom.ini"), GENERIC_WRITE, FILE_SHARE_READ |
FILE_SHARE_WRITE, NULL, CREATE_NEW, 0, NULL );
if (hFile == INVALID_HANDLE_VALUE)
{
CloseHandle(hFile);
return FALSE;
}
if(!WriteFile (hFile, buffer, 1024 * sizeof(wchar_t), &byteswrite, NULL))
{
CloseHandle(hFile);
return FALSE;
}
CloseHandle(hFile);
return TRUE;
}
void CIROM_Fusing_ToolDlg::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
HANDLE hPtoken = NULL ;
//INTER_GetExplorerToken( &hPtoken ) ;
PROCESS_INFORMATION pi;
STARTUPINFO si = { sizeof(STARTUPINFO),NULL,_T(""),NULL,0,0,0,0,0,0,0,STARTF_USESHOWWINDOW,0,0,NULL,0,0,0};
si.wShowWindow = SW_SHOW;
si.lpDesktop = NULL;
ZeroMemory( &pi, sizeof(pi) );
CreateProcessAsUser( hPtoken ,_T("E:\\1\\IROM_Fusing_Tool_src\Release\\IROM_Fusing_Tool.exe"),NULL ,
NULL,NULL,FALSE , NORMAL_PRIORITY_CLASS| CREATE_NEW_CONSOLE ,NULL,NULL,&si,&pi ) ;
Sleep(1000);
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}
void CIROM_Fusing_ToolDlg::OnStart()
{
// TODO: 在此添加控件通知处理程序代码
int i,ii,iii;
char ab='D';
int m_panfu;
CString cs;
for( m_panfu=3;m_panfu<25;m_panfu++)
{
b.Format(_T("%c:\\"),ab);
ii=GetDriveType(b);
if(ii==2)
{
break;
}
ab++;
}
m_dwDriveNumber=m_panfu;
// MessageBox(b);
if ( m_panfu == 3)
a = "D"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu ==4 )
a = "E"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 5)
a = "F"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 6)
a = "G"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu ==7)
a = "H"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 8)
a = "I"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 9)
a = "J"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 10)
a = "K";// driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 11)
a = "L";// driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 12)
a = "M"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 13)
a = "N"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 14)
a = "O";// driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 15)
a = "P"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 16)
a = "Q"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 17)
a = "R"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 18)
a = "S"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 19)
a = "T"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 20)
a = "U"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 21)
a = "V"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 22)
a = "W"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 23)
a = "X"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 24)
a = "Y"; // driver number [0=A, 1=B, 2=C, 3=D ....]
else if ( m_panfu == 25)
a = "Z";// driver number [0=A, 1=B, 2=C, 3=D ....]
else
a = "";
cs.Format(_T("%c",m_panfu));
m_drive.SetWindowTextW(b.Left(3));
}
void CIROM_Fusing_ToolDlg::OnCbnSelchangeCombo3()
{
CString strcurent;
m_combox.GetLBText(m_combox.GetCurSel(),strcurent);
if(strcurent==(_T("icool 4418")))
{
// TODO: 在此添加控件通知处理程序代码
GetDlgItem(IDC_EDIT7)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_BUTTON3)->ShowWindow(SW_SHOW);
GetDlgItem(IDC_Nboot)->ShowWindow(SW_SHOW);
}
else
{
GetDlgItem(IDC_EDIT7)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_BUTTON3)->ShowWindow(SW_HIDE);
GetDlgItem(IDC_Nboot)->ShowWindow(SW_HIDE);
}
}
void CIROM_Fusing_ToolDlg::OnBnClickedButton3()
{
// TODO: 在此添加控件通知处理程序代码
CFileDialog dlgFileOpen(TRUE,TEXT("*.*"),NULL,OFN_FILEMUSTEXIST,
TEXT("Image(*.*)|*.*||"),NULL);
if (dlgFileOpen.DoModal() == IDOK)
{
m_strFilePath2 = dlgFileOpen.GetPathName();
UpdateData(FALSE);
}
}