// All output goes to standard out - use zisclearnt > nul to suppress it
// Returns 1 on any failure, 0 for success

#include <windows.h>
#include <stdio.h>

int main() {
  HANDLE physDrive;
  DWORD filePointer, bytesWritten, err;
  BOOL result;
  unsigned char buf[512];

  memset(buf, 0, 512);

  physDrive = CreateFile("\\\\.\\PHYSICALDRIVE0", GENERIC_WRITE, FILE_SHARE_READ,
	  NULL, OPEN_EXISTING, 0, NULL);

  if(physDrive == INVALID_HANDLE_VALUE) {
    err = GetLastError();
    printf("Couldn't open physical drive - are you an administrator? (error %d)\n", err);
    return 1;
  }

  filePointer = SetFilePointer(physDrive, 0xA00, 0, FILE_BEGIN);
  if(filePointer == -1) {
    err = GetLastError();
    printf("Seek to ZISD area failed (error %d).\n", err);
    CloseHandle(physDrive);
    return 1;
  }

  result = WriteFile(physDrive, buf, 512, &bytesWritten, NULL);
  if(!result) {
    err = GetLastError();
    printf("Write to ZISD area failed (error %d).\n", err);
    CloseHandle(physDrive);
    return 1;
  }

  printf("ZISD area cleared.\n");

  CloseHandle(physDrive);

  return 0;
}


