#include <windows.h>
#include <stdio.h>
#include <iostream>
using namespace std;
short ReadSect
(const char *_dsk, char *&_buff, unsigned int _nsect )
{
DWORD dwRead;
HANDLE hDisk=CreateFile(_dsk,GENERIC_READ,0,0,OPEN_EXISTING,0,0);
if(hDisk==INVALID_HANDLE_VALUE) {
CloseHandle(hDisk);
printf("Read fail\n");
return 1;
}
SetFilePointer(hDisk,_nsect*512,0,FILE_BEGIN); for (int f=0;f<512;f++)
printf("%c" ,_buff[0]);
printf("\n");
ReadFile(hDisk,_buff,512,&dwRead,0); CloseHandle(hDisk);
return 0;
}
short WriteSect
(const char *_tdsk, char *&_buff, unsigned int _nsect )
{
DWORD dwWrite;
HANDLE tDisk=CreateFile(_tdsk,GENERIC_WRITE,0,0,OPEN_EXISTING,0,0);
if(tDisk==INVALID_HANDLE_VALUE) { printf("write fail\n");
GetLastError();
CloseHandle(tDisk);
return 1;
}
SetFilePointer(tDisk,_nsect*512,0,FILE_BEGIN); printf("%x\n",_buff[0]);
WriteFile(tDisk,_buff,512,&dwWrite,0); CloseHandle(tDisk);
printf("HURRRRRRRRRRRRReyyyyyyyy!!!!!!!!!\n");
return 0;
}
int main()
{
char * drv="\\\\.\\C:";
char *dsk="\\\\.\\PhysicalDrive2";
char *tdsk="\\\\.\\PhysicalDrive1";
int sector=5;
char *buffer=new char[512];
ReadSect(dsk,buffer,sector);
WriteSect(tdsk,buffer,sector);
printf("%d",sector);
getchar();
}
[EDIT: Code formatting; removed all caps from title]