Click here to Skip to main content
15,884,388 members
Articles / Programming Languages / C++

Changing volume's serial number

Rate me:
Please Sign up or sign in to vote.
4.87/5 (75 votes)
4 Mar 20043 min read 696.8K   23.5K   123  
An article showing how to change drive's serial number
#ifndef __DISKSECTOR_02172004__INC__
#define __DISKSECTOR_02172004__INC__

#include <windows.h>

class DiskSectorRW
{
public:
  virtual bool Open(char *vol) = 0;
  virtual void Close() = 0;
  virtual bool ReadSector(DWORD sector, char *Buffer, int sectorSize = 512) = 0;
  virtual bool WriteSector(DWORD sector, char *buffer, int sectorSize = 512) = 0;
};

class DiskSectorWinNT : public DiskSectorRW
{
private:
  HANDLE m_hDisk;
public:
  bool Open(char *vol);
  void Close();
  bool ReadSector (DWORD sector, char *Buffer, int sectorSize = 512);
  bool WriteSector(DWORD sector, char *Buffer, int sectorSize = 512);
};

class DiskSectorWin9x : public DiskSectorRW
{
private:
  HANDLE m_hVmm32;
  bool m_bOpened;
  char m_chDrive;
  BYTE m_nDriveNo;
  bool m_bW9xOsr2AndAbove;
  bool m_bUseLocking;
public:
  
  DiskSectorWin9x() : m_bUseLocking(false) { }
  bool Open(char *vol);
  void Close();
  
  bool ReadSector (DWORD sector, char *Buffer, int sectorSize = 512);
  bool WriteSector(DWORD sector, char *Buffer, int sectorSize = 512);
  
  static bool LockLogicalVolume (HANDLE hVWin32, BYTE   bDriveNum, BYTE   bLockLevel, WORD wPermissions);
  static bool UnlockLogicalVolume(HANDLE hVWin32, BYTE bDriveNum);  

  static bool ReadLogicalSectors (HANDLE hDev, BYTE   bDrive, DWORD  dwStartSector, WORD wSectors, LPBYTE lpSectBuff);
  static bool WriteLogicalSectors (HANDLE hDev, BYTE   bDrive, DWORD  dwStartSector, WORD   wSectors, LPBYTE lpSectBuff);

  static bool NewReadSectors(HANDLE hDev, BYTE   bDrive, DWORD  dwStartSector, WORD   wSectors, LPBYTE lpSectBuff);
  static bool NewWriteSectors(HANDLE hDev, BYTE   bDrive, DWORD  dwStartSector, WORD   wSectors, LPBYTE lpSectBuff);

};

class DiskSector
{
private:
  DiskSectorRW *util;
public:
  DiskSector();
  ~DiskSector();
  bool Open(char *vol);
  void Close();
  bool ReadSector(DWORD sector, char *Buffer, int sectorSize = 512);
  bool WriteSector(DWORD sector, char *buffer, int sectorSize = 512);
};
#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
Elias (aka lallousx86, @0xeb) has always been interested in the making of things and their inner workings.

His computer interests include system programming, reverse engineering, writing libraries, tutorials and articles.

In his free time, and apart from researching, his favorite reading topics include: dreams, metaphysics, philosophy, psychology and any other human/mystical science.

Former employee of Microsoft and Hex-Rays (the creators of IDA Pro), was responsible about many debugger plugins, IDAPython project ownership and what not.

Elias currently works as an Anticheat engineer in Blizzard Entertainment.

Elias co-authored 2 books and authored one book:

- Practical Reverse Engineering
- The Antivirus Hacker's Handbook
- The Art of Batch Files Programming

Comments and Discussions