Solved

Please help me

Posted on 1998-10-01
1
181 Views
Last Modified: 2010-04-01
I would like to find the media id of a compact disc
anyone can help???
0
Comment
Question by:Tonyleung
1 Comment
 
LVL 1

Accepted Solution

by:
roaknog earned 10 total points
ID: 1174254
#define VWIN32_DIOC_DOS_IOCTL 1

#include <windows.h>
#include <fstream.h>//for ofstream

//DECLARE SOME VARIABLES
      UINT nDrive = 4; //for cd drive d
      HANDLE hDevice;
      BOOL fResult;
      DWORD cb;
      char hexarray[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
      DWORD hfst, hscd, htrd, hfth, lfst, lscd, ltrd, lfth;

      typedef struct _midSN {
            WORD SNHighPart;
            WORD SNLowPart;
      } midSN;


      typedef struct _MID
      {
            WORD midInfoLevel;
            midSN midSerialNum;
            BYTE midVolLabel[11];
            BYTE midFileSysType[8];
      } MID, *PMID;

      MID mid;
      PMID pmid = &mid;

      typedef struct _DEVICEIOCTL_REGISTETRS
      {
            DWORD reg_EBX;
            DWORD reg_EDX;
            DWORD reg_ECX;
            DWORD reg_EAX;
            DWORD reg_EDI;
            DWORD reg_ESI;
            DWORD reg_Flags;
      } DEVIOCTL_REGISTERS, *PDEVIOCTL_REGISTERS;


void main()
      {
      DEVIOCTL_REGISTERS roakreg;
      PDEVIOCTL_REGISTERS preg = &roakreg;
      roakreg.reg_EAX = 0x440D;
      roakreg.reg_EBX = nDrive;
      roakreg.reg_ECX = 0x866;
      roakreg.reg_EDX = (DWORD)pmid;
      roakreg.reg_Flags = 0x8000;


// GET HANDLE
      hDevice = CreateFile("\\\\.\\vwin32",
            0,
            0,
            NULL,
            0,
            FILE_FLAG_DELETE_ON_CLOSE,
            NULL);

      fResult = DeviceIoControl(hDevice,
            VWIN32_DIOC_DOS_IOCTL,
            &roakreg,
            sizeof(roakreg),
            &roakreg,
            sizeof(roakreg),
            &cb,
            0);

//CLOSE HANDLE
      CloseHandle(hDevice);

//convert serial number to hex
      hfst = mid.midSerialNum.SNHighPart/4096;
      hscd = (mid.midSerialNum.SNHighPart-(hfst*4096))/256;
      htrd = (mid.midSerialNum.SNHighPart-(hfst*4096)-(hscd*256))/16;
      hfth = (mid.midSerialNum.SNHighPart-(hfst*4096)-(hscd*256)-(htrd*16));
      lfst = mid.midSerialNum.SNLowPart/4096;
      lscd = (mid.midSerialNum.SNLowPart-(lfst*4096))/256;
      ltrd = (mid.midSerialNum.SNLowPart-(lfst*4096)-(lscd*256))/16;
      lfth = (mid.midSerialNum.SNLowPart-(lfst*4096)-(lscd*256)-(ltrd*16));

//OUTPUT
      ofstream q("c:\\temp\\dioc.doc");
      q << "cb = " << cb <<
            ".\vhDevice = " << hDevice <<
            ".\v(HANDLE)INVALID_HANDLE_VALUE = " << (HANDLE)INVALID_HANDLE_VALUE <<
            ".\vfResult = " << fResult <<
            ".\vVWIN32_DIOC_DOS_IOCTL = " << VWIN32_DIOC_DOS_IOCTL <<
            ".\vnDrive = " << nDrive <<
            ".\vmid.midInfoLevel = " << mid.midInfoLevel <<
            ".\vWORD mid.midSerialNum.SNHighPart = " << mid.midSerialNum.SNHighPart <<
            ".\vWORD mid.midSerialNum.SNLowPart = " << mid.midSerialNum.SNLowPart <<
            ".\v&mid.midSerialNum.SNHighPart = " << &mid.midSerialNum.SNHighPart <<
            ".\v&mid.midSerialNum.SNLowPart = " << &mid.midSerialNum.SNLowPart <<
            ".\vhexadecimal mid.midSerialNum.SNHighPart = " << hexarray[hfst] << hexarray[hscd] << hexarray[htrd] << hexarray[hfth] <<
            ".\vhexadecimal mid.midSerialNum.SNLowPart = " << hexarray[lfst] << hexarray[lscd] << hexarray[ltrd] << hexarray[lfth] <<
            ".\vThe Serial Number is: " << hexarray[lfst] << hexarray[lscd] << hexarray[ltrd] << hexarray[lfth] << "-" << hexarray[hfst] << hexarray[hscd] << hexarray[htrd] << hexarray[hfth] <<
            ".\vmid.midVolLabel = " << mid.midVolLabel <<
            ".\vmid.midFileSysType = " << mid.midFileSysType <<
            ".\vmid->pmidInfoLevel = " << pmid->midInfoLevel <<
            ".\vmid->pmidVolLabel = " << pmid->midVolLabel <<
            ".\vmid->pmidFileSysType = " << pmid->midFileSysType <<
            ".\v(DWORD) pmid = " << (DWORD)pmid <<
            ".\vroakreg.reg_EDX = (DWORD) pmid = " << roakreg.reg_EDX  <<
            ".\vroakreg.reg_EBX = nDrive = " << roakreg.reg_EBX <<
            ".\vroakreg.reg_ECX = 0x866 = " << roakreg.reg_ECX <<
            ".\vroakreg.reg_Flags = 0x8000 = " << roakreg.reg_Flags <<
            ".\vroakreg.reg_EAX = " << roakreg.reg_EAX <<
            ".\v";

      cout << "\n     This program gets the media id of a cd at drive D:\\!\n\n     Function 440Dh of interrupt 21h is used!\n\n     The information is put into file c:\\temp\\dioc.doc!\n\n     This is not to be confused with the media in the FAT!\n\n     To get the media you could use function 1h of interrupt 25\n\n     with a boot structure, or offset 15h of a buffer!\n\n     (C) 1998 Inniea Publishing Company ROAK NOG!\n\n     ";
}
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now