16,505
社区成员
发帖
与我相关
我的任务
分享
void CMakeSD::WritePasscode()
{
int file_attr = FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM;
TCHAR lpVolumeNameBuffer[MAX_SIZE];
DWORD lpVolumeSerialNumber;
DWORD lpMaximumComponentLength;
DWORD lpFileSystemFlags;
TCHAR lpFileSystemNameBuffer[MAX_SIZE];
TCHAR serial[MAX_SIZE];
TCHAR buf[BLOCK_SIZE];
GetVolumeInformation(szDrive,
lpVolumeNameBuffer,
sizeof(lpVolumeNameBuffer),
&lpVolumeSerialNumber,
&lpMaximumComponentLength,
&lpFileSystemFlags,
lpFileSystemNameBuffer,
sizeof(lpFileSystemNameBuffer));
//printf("盘的卷标:%s\n ",lpVolumeNameBuffer); //显示卷标
//printf("硬盘系列号:%08x\n",lpVolumeSerialNumber);//8位十六进制显示系列号
_stprintf(serial,_T("%08x"),lpVolumeSerialNumber);
CString szSerial(serial);
CString szName=_T("passcode");
int fd;
if ((fd = _open(szName,_O_CREAT | _O_BINARY | _O_WRONLY,_S_IWRITE))==0)
{
return ;
}
srand( (unsigned)time( NULL ) );
for (int i=0;i<BLOCK_SIZE;i++)
{
buf[i]=(TCHAR)(rand()&0xff);
}
CString szTemp(szSerial);
szTemp.Delete(4,szTemp.GetLength()-4);
memcpy(buf+0x48,szTemp,4);
szTemp=szSerial;
szTemp.Delete(0,4);
memcpy(buf+0x4dd,szTemp,4);
_write(fd,buf,sizeof(buf));
_close(fd);
}
#include <fcntl.h>
#include <sys/stat.h>
#include <io.h>
#define MAX_SIZE (0x100)
#define BLOCK_SIZE (0x100)
#define szDrive _T( "C:\\" )
void WritePasscode()
{
int file_attr = FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM;
TCHAR lpVolumeNameBuffer[MAX_SIZE];
DWORD lpVolumeSerialNumber;
DWORD lpMaximumComponentLength;
DWORD lpFileSystemFlags;
TCHAR lpFileSystemNameBuffer[MAX_SIZE];
TCHAR serial[MAX_SIZE];
TCHAR buf[BLOCK_SIZE];
GetVolumeInformation(szDrive,
lpVolumeNameBuffer,
sizeof(lpVolumeNameBuffer),
&lpVolumeSerialNumber,
&lpMaximumComponentLength,
&lpFileSystemFlags,
lpFileSystemNameBuffer,
sizeof(lpFileSystemNameBuffer));
//printf("盘的卷标:%s\n ",lpVolumeNameBuffer); //显示卷标
//printf("硬盘系列号:%08x\n",lpVolumeSerialNumber);//8位十六进制显示系列号
_stprintf(serial,_T("%08x"),lpVolumeSerialNumber);
CString szSerial(serial);
CString szName=_T("passcode");
int fd;
if ((fd = _topen(szName,_O_CREAT | _O_BINARY | _O_WRONLY,_S_IWRITE))==0)
{
return ;
}
srand( (unsigned)time( NULL ) );
for (int i=0;i<BLOCK_SIZE;i++)
{
buf[i]=(TCHAR)(rand()&0xff);
}
CString szTemp(szSerial);
szTemp.Delete(4,szTemp.GetLength()-4);
memcpy(buf+0x48,szTemp,4);
szTemp=szSerial;
szTemp.Delete(0,4);
memcpy(buf+0x4dd,szTemp,4);
_write(fd,buf,sizeof(buf));
_close(fd);
}