/* * QueryDos program * 01.05.26 : Makoto NARA(Mc.N) * * See follow this. * - Pop Open a Privileged Set of APIs with Windows NT Kernel Mode Drivers * [http://www.microsoft.com/msj/defaultframe.asp?page=/msj/0398/driver.htm] * - INFO: Understanding Device Names and Symbolic Links (Q235128) * [http://support.microsoft.com/support/kb/articles/Q235/1/28.ASP] */ /* * Copyright (c) 2001 Makoto NARA(Mc.N) All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY Makoto NARA(Mc.N) ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #define MAX_BUFFER 65535 #include #include int main() { PBYTE pAll, pSym; PBYTE pList; DWORD dwLen, dwRet, dwCount; HANDLE hHandle; BYTE bBuf[1024]; DWORD dw; // Alloc memory pAll = LocalAlloc (LPTR, MAX_BUFFER); pSym = LocalAlloc (LPTR, MAX_BUFFER); if( (pAll==NULL) || (pSym==NULL) ){ printf("Error : Invalid memory allocation[%d]\n", GetLastError() ); return -1; } // Get list of all existing MS-DOS device names dwLen = QueryDosDevice( NULL, pAll, MAX_BUFFER ); if( dwLen == 0 ){ printf( "Error : QueryDosDevice()[%d]\n", GetLastError() ); return -2; } dwCount = 0; for(;;){ pList = pAll+dwCount; // CreateFile check wsprintf( bBuf, "\\\\.\\%s", pList ); hHandle = CreateFile(bBuf,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ | FILE_SHARE_WRITE,NULL,OPEN_EXISTING,0,NULL); if( hHandle != INVALID_HANDLE_VALUE ){ printf("%s\tYES\t", pList); CloseHandle(hHandle); }else{ printf("%s\tNO[%d]\t", pList, GetLastError() ); } // Symbolic parameter list dwRet = QueryDosDevice( pList, pSym, MAX_BUFFER ); if( dwRet != 0 ){ dw = 0; while( dw+1 < dwRet ){ if( *(pSym+dw) != '\0'){ dw++; continue;} if( *(pSym+dw+1) == '\0' ){ break; } *(pSym+dw) = ','; dw++; } *(pSym+dwRet) = '\0'; printf("%s", pSym); } printf("\n"); // counting while( dwCount+1 < dwLen ){ if( *(pAll+dwCount) != '\0'){ dwCount++; continue;} break; } if( !(dwCount+1