1

デバイスパスをファイルパスに変換したい。

プロセスIDでプロセス名を取得したいので、このコードを使用しています

PsLookupProcessByProcessId(processId,&pEProcess);
ObOpenObjectByPointer(pEProcess,
                      OBJ_KERNEL_HANDLE,
                      NULL,
                      0,
                      NULL,
                      KernelMode,
                      &hProcess);
ObDereferenceObject (pEProcess);

nts = ZwQueryInformationProcess (hProcess,27,0,0,&ulSize);

しかし、それは次のようにパスを提供します\Device\hardDiskVolume1\windows\system32\taskmgr.exe

しかし、私はこれをプレーンなファイル名にしたいC:\windows\system32\taskmgr.exe

4

2 に答える 2

1

Dr. Dobb の記事 ( Jim Conyngham によるNT ハンドルからパスへの変換) に、ハンドルから DOS パス名を取得する方法を説明した記事があります: のリストを参照してくださいGetFileNameFromHandleNT()

あなたの場合、既にデバイス パスがあるため、handle-to-memory-map-to-get-device-path を実行するコードの最初の部分は必要ありません。

于 2011-06-21T09:44:39.660 に答える
1
// From device file name to DOS filename
BOOL GetFsFileName( LPCTSTR lpDeviceFileName, CString& fsFileName )
{
    BOOL rc = FALSE;

    TCHAR lpDeviceName[0x1000];
    TCHAR lpDrive[3] = _T("A:");

    // Iterating through the drive letters
    for ( TCHAR actDrive = _T('A'); actDrive <= _T('Z'); actDrive++ )
    {
        lpDrive[0] = actDrive;

        // Query the device for the drive letter
        if ( QueryDosDevice( lpDrive, lpDeviceName, 0x1000 ) != 0 )
        {
            // Network drive?
            if ( _tcsnicmp( _T("\\Device\\LanmanRedirector\\"), lpDeviceName, 25 ) == 0 )
            {
                //Mapped network drive 

                char cDriveLetter;
                DWORD dwParam;

                TCHAR lpSharedName[0x1000];

                if ( _stscanf(  lpDeviceName, 
                                _T("\\Device\\LanmanRedirector\\;%c:%d\\%s"), 
                                &cDriveLetter, 
                                &dwParam, 
                                lpSharedName ) != 3 )
                        continue;

                _tcscpy( lpDeviceName, _T("\\Device\\LanmanRedirector\\") );
                _tcscat( lpDeviceName, lpSharedName );
            }

            // Is this the drive letter we are looking for?
            if ( _tcsnicmp( lpDeviceName, lpDeviceFileName, _tcslen( lpDeviceName ) ) == 0 )
            {
                fsFileName = lpDrive;
                fsFileName += (LPCTSTR)( lpDeviceFileName + _tcslen( lpDeviceName ) );

                rc = TRUE;

                break;
            }
        }
    }

    return rc;
}
于 2013-09-08T05:56:49.640 に答える