//+--------------------------------------------------------------------------- // // Member: CStrOut::CStrOut // // Synopsis: Allocates enough space for an out buffer. // // Arguments: [pwstr] -- The Unicode buffer to convert to when destroyed. // May be NULL. // // [cwchBuf] -- The size of the buffer in characters. // // Modifies: [this]. // //---------------------------------------------------------------------------- CStrOut::CStrOut(LPWSTR pwstr, int cwchBuf) : CConvertStr(CP_ACP) { Assert(cwchBuf >= 0); _pwstr = pwstr; _cwchBuf = cwchBuf; if(!pwstr) { _cwchBuf = 0; _pstr = NULL; return; } Assert(HIWORD64(pwstr)); // Initialize buffer in case Windows API returns an error. _ach[0] = 0; // Use preallocated buffer if big enough. if(cwchBuf*2 <= ARRAYSIZE(_ach)) { _pstr = _ach; return; } // Allocate buffer. Trace0("CStrOut: Allocating buffer for wrapped function argument.\n"); _pstr = new char[cwchBuf*2]; if(!_pstr) { // On failure, the argument will point to a zero-sized buffer initialized // to the empty string. This should cause the Windows API to fail. Trace0("CStrOut: No heap space for wrapped function argument.\n"); Assert(cwchBuf > 0); _pwstr[0] = 0; _cwchBuf = 0; _pstr = _ach; return; } Assert(HIWORD64(_pstr)); _pstr[0] = 0; }
BOOLEAN HidePortName(IN PC0C_FDOPORT_EXTENSION pDevExt) { BOOLEAN res; HANDLE hKey; NTSTATUS status; if (pDevExt->pIoPortLocal->isComClass) return TRUE; res = TRUE; status = IoOpenDeviceRegistryKey(pDevExt->pIoPortLocal->pPhDevObj, PLUGPLAY_REGKEY_DEVICE, STANDARD_RIGHTS_WRITE, &hKey); if (NT_SUCCESS(status)) { UNICODE_STRING keyName; RtlInitUnicodeString(&keyName, L"PortName"); status = ZwDeleteValueKey(hKey, &keyName); if (NT_SUCCESS(status)) { Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"Hidden PORTNAME"); } else if ((pDevExt->shown & C0C_SHOW_PORTNAME) != 0) { res = FALSE; Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"HidePortName ZwDeleteValueKey(PortName) FAIL"); } ZwClose(hKey); } else if ((pDevExt->shown & C0C_SHOW_PORTNAME) != 0) { res = FALSE; Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"HidePortName IoOpenDeviceRegistryKey(PLUGPLAY_REGKEY_DEVICE) FAIL"); } pDevExt->shown &= ~C0C_SHOW_PORTNAME; return res; }
void CDispRoot::OpenDisplayTree() { CheckReenter(); _cOpen++; Trace0("***** OpenDisplayTree call stack:\n"); if(_cOpen == 1) { // on first open, none of these flags should be set VerifyFlags(CDispFlags::s_generalFlagsNotSetInDraw, CDispFlags::s_none, TRUE); } }
VOID SetHiddenMode(IN PC0C_FDOPORT_EXTENSION pDevExt, ULONG hiddenMode) { if (hiddenMode == 0xFFFFFFFF) pDevExt->hide = (C0C_SHOW_PORTNAME|C0C_SHOW_DEVICEMAP|C0C_SHOW_WMIREG); else pDevExt->hide = (UCHAR)hiddenMode; #if ENABLE_TRACING if (pDevExt->hide) TraceMask((PC0C_COMMON_EXTENSION)pDevExt, "Enabled hidden mode ", codeNameTableShowPort, pDevExt->hide); else Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"Disabled hidden mode"); #endif /* ENABLE_TRACING */ }
//+------------------------------------------------------------------------ // // Function: ClearDDBCache() // // Synopsis: Free the cached DDD, if any. // //------------------------------------------------------------------------- void ClearDDBCache() { if(!g_OscCache._fInUse && !g_OscCache._fUseDD && g_OscCache._hbmMem!=NULL) { Trace0("DDB cache deleted\n"); if(g_OscCache._hdcMem) { if(g_OscCache._hbmOld) { SelectObject(g_OscCache._hdcMem, g_OscCache._hbmOld); } g_OscCache._hbmOld = NULL; DeleteDC(g_OscCache._hdcMem); g_OscCache._hdcMem = NULL; } DeleteObject(g_OscCache._hbmMem); g_OscCache._hbmMem = NULL; } }
//+------------------------------------------------------------------------ // // Function: ClearSurfaceCache() // // Synopsis: Free the cached DD surface, if any. // //------------------------------------------------------------------------- void ClearSurfaceCache() { // Quick test without entering critical section, then retest afterwards in case it // changes. if(!g_OscCache._fInUse && g_OscCache._fUseDD && g_OscCache._pDDSurface!=NULL) { LOCK_SECTION(g_csOscCache); if(!g_OscCache._fInUse && g_OscCache._fUseDD && g_OscCache._pDDSurface!=NULL) { Trace0("surface cache deleted\n"); if(g_OscCache._hdcMem) { SelectPalette(g_OscCache._hdcMem, (HPALETTE)GetStockObject(DEFAULT_PALETTE), TRUE); Verify(g_OscCache._pDDSurface->ReleaseDC(g_OscCache._hdcMem) == DD_OK); g_OscCache._hdcMem = NULL; } ClearInterface(&g_OscCache._pDDSurface); g_OscCache._fUseDD = FALSE; } } }
/* * Shut down a device */ static void gsclose(gsc_softc_t *sp, dev_t devno) { int i; if (sp->fp != NULL && sp->unstart) { (void) fp_ioctl(sp->fp, SCIOSTOP, (caddr_t) IDLUN(sp->tgt, sp->lun), NULL); sp->unstart = 0; } if (sp->fp) { (void) fp_close(sp->fp); sp->fp = NULL; } for (i = 0; i < MAX_UNITS; i++) { if (softinfo[i].iscfg) { Trace1(0, "gsclose: unit %d still confd", i); break; } } if (i == MAX_UNITS) { Trace0(0, "gsclose: All unconfigured now"); (void) devswdel(devno); unpincode((int (*) ()) gscdd_intr); } }
void pws_os::HexDump(unsigned char *pmemory, const int &length, const stringT &cs_prefix, const int &maxnum) { TCHAR szBuffer[256]; unsigned char *pmem; stringT cs_outbuff, cs_hexbuff, cs_charbuff; int i, j, len(length); unsigned char c; pmem = pmemory; while (len > 0) { // Show offset for this line. cs_charbuff.clear(); cs_hexbuff.clear(); Format(cs_outbuff, _T("%s: %08x *"), cs_prefix.c_str(), pmem); // Format hex portion of line and save chars for ascii portion if (len > maxnum) j = maxnum; else j = len; for (i = 0; i < j; i++) { c = *pmem++; if ((i % 4) == 0 && i != 0) cs_outbuff += _T(' '); Format(cs_hexbuff, _T("%02x"), c); cs_outbuff += cs_hexbuff; if (c >= 32 && c < 127) cs_charbuff += (TCHAR)c; else cs_charbuff += _T('.'); } j = maxnum - j; // Fill out hex portion of short lines. for (i = j; i > 0; i--) { if ((i % 4) != 0) cs_outbuff += _T(" "); else cs_outbuff += _T(" "); } // Add ASCII character portion to line. cs_outbuff += _T("* |"); cs_outbuff += cs_charbuff; // Fill out end of short lines. for (i = j; i > 0; i--) cs_outbuff += _T(' '); cs_outbuff += _T('|'); // Next line len -= maxnum; _stprintf_s(szBuffer, sizeof(szBuffer) / sizeof(TCHAR), _T("%s\n"), cs_outbuff.c_str()); Trace0(szBuffer); }; }
//+--------------------------------------------------------------------------- // // Member: CStrIn::Init // // Synopsis: Converts a LPWSTR function argument to a LPSTR. // // Arguments: [pwstr] -- The function argument. May be NULL or an atom // (HIWORD64(pwstr) == 0). // // [cwch] -- The number of characters in the string to // convert. If -1, the string is assumed to be // NULL terminated and its length is calculated. // // Modifies: [this] // //---------------------------------------------------------------------------- void CStrIn::Init(LPCWSTR pwstr, int cwch) { int cchBufReq; _cchLen = 0; // Check if string is NULL or an atom. if(HIWORD64(pwstr) == 0) { _pstr = (LPSTR) pwstr; return; } if(cwch == 0) { *_ach = '\0'; _pstr = _ach; return; } Assert(cwch==-1 || cwch>0); // Convert string to preallocated buffer, and return if successful. _cchLen = WideCharToMultiByte(_uCP, 0, pwstr, cwch, _ach, ARRAYSIZE(_ach)-1, NULL, NULL); if(_cchLen > 0) { // This is DBCS safe since byte before _cchLen is last character _ach[_cchLen] = 0; // BUGBUG DBCS REVIEW: this may not be safe if the last character // was a multibyte character... if(_ach[_cchLen-1]==0) { _cchLen--; // account for terminator } _pstr = _ach; return; } // Alloc space on heap for buffer. cchBufReq = WideCharToMultiByte(_uCP, 0, pwstr, cwch, NULL, 0, NULL, NULL); Assert(cchBufReq > 0); cchBufReq++; // may need to append NUL Trace((_T("CStrIn: Allocating buffer for argument (_uCP=%ld,cwch=%ld,pwstr=%lX,cchBufReq=%ld)\n"), _uCP, cwch, pwstr, cchBufReq)); _pstr = new char[cchBufReq]; if(!_pstr) { // On failure, the argument will point to the empty string. Trace0("CStrIn: No heap space for wrapped function argument.\n"); _ach[0] = 0; _pstr = _ach; return; } Assert(HIWORD64(_pstr)); _cchLen = WideCharToMultiByte(_uCP, 0, pwstr, cwch, _pstr, cchBufReq, NULL, NULL); // Again, make sure we're always null terminated Assert(_cchLen < cchBufReq); _pstr[_cchLen] = 0; if(0 == _pstr[_cchLen-1]) // account for terminator { _cchLen--; } }
//+------------------------------------------------------------------------ // // Member: COffScreenContext::GetDDB // // Synopsis: Create a suitable DDB or get one from the cache. // //------------------------------------------------------------------------- BOOL COffScreenContext::GetDDB(HPALETTE hpal) { LOCK_SECTION(g_csOscCache); if(!g_OscCache._fInUse) { ClearSurfaceCache(); // don't allow both DD & DDB in the cache if(g_OscCache._hbmMem != NULL) { if(_widthActual>g_OscCache._size.cx || _heightActual>g_OscCache._size.cy || _cBitsPixel!=g_OscCache._cBitsPixel) { ++g_OscCache._cMisses; ClearDDBCache(); } else { ++g_OscCache._cHits; g_OscCache._fInUse = TRUE; _hbmMem = g_OscCache._hbmMem; _hdcMem = g_OscCache._hdcMem; _widthActual = g_OscCache._size.cx; _heightActual = g_OscCache._size.cy; } } if(g_OscCache._hbmMem==NULL && _widthActual*_heightActual<=g_OscCache._areaTgt) { // use max area allowed for the cache, so we get max reuse potential // favor width over height for those wide text runs g_OscCache._size.cx = max(min(g_OscCache._areaTgt/_heightActual, g_OscCache._sizeTgt.cx), _widthActual); g_OscCache._size.cy = max(g_OscCache._areaTgt/g_OscCache._size.cx, _heightActual); if(!CreateDDB(g_OscCache._size.cx, g_OscCache._size.cy)) { return FALSE; } Trace0("DDB cache created\n"); g_OscCache._fInUse = TRUE; g_OscCache._hbmMem = _hbmMem; g_OscCache._hbmOld = _hbmOld; g_OscCache._cBitsPixel = _cBitsPixel; g_OscCache._hdcMem = _hdcMem; g_OscCache._hpal = hpal; _widthActual = g_OscCache._size.cx; _heightActual = g_OscCache._size.cy; } } else { Trace0("DDB cache in use\n"); } if(_hbmMem == NULL) { if(!CreateDDB(_widthActual, _heightActual)) { return FALSE; } } return TRUE; }
//+------------------------------------------------------------------------ // // Member: COffScreenContext::GetDDSurface // // Synopsis: Create a suitable DD surface or get one from the cache. // //------------------------------------------------------------------------- BOOL COffScreenContext::GetDDSurface(HPALETTE hpal) { HRESULT hr; LOCK_SECTION(g_csOscCache); if(!g_OscCache._fInUse) { ClearDDBCache(); // don't allow both DD & DDB in the cache if(g_OscCache._pDDSurface != NULL) { Assert(g_OscCache._fUseDD); if(_widthActual>g_OscCache._size.cx || _heightActual>g_OscCache._size.cy || _cBitsPixel!=g_OscCache._cBitsPixel || (_fUse3D&&!g_OscCache._fUse3D)) { ++g_OscCache._cMisses; ClearSurfaceCache(); } else { ++g_OscCache._cHits; g_OscCache._fInUse = TRUE; _pDDSurface = g_OscCache._pDDSurface; _pDDSurface->AddRef(); _hdcMem = g_OscCache._hdcMem; _widthActual = g_OscCache._size.cx; _heightActual = g_OscCache._size.cy; } } if(g_OscCache._pDDSurface == NULL) { // use max area allowed for the cache, so we get max reuse potential // favor width over height for those wide text runs // also adjust the max size in a growing fashion based on former allocations g_OscCache._size.cx = max(g_OscCache._size.cx, max(min(g_OscCache._areaTgt/_heightActual, g_OscCache._sizeTgt.cx), _widthActual)); g_OscCache._size.cy = max(g_OscCache._size.cy , max(g_OscCache._areaTgt/g_OscCache._size.cx, _heightActual)); if(!CreateDDSurface(g_OscCache._size.cx, g_OscCache._size.cy, hpal)) { return FALSE; } Trace0("surface cache created\n"); g_OscCache._fInUse = TRUE; g_OscCache._fUseDD = TRUE; g_OscCache._fUse3D = _fUse3D; g_OscCache._pDDSurface = _pDDSurface; g_OscCache._pDDSurface->AddRef(); // addref the global surface g_OscCache._cBitsPixel = _cBitsPixel; g_OscCache._hdcMem = _hdcMem; g_OscCache._hpal = hpal; _widthActual = g_OscCache._size.cx; _heightActual = g_OscCache._size.cy; } } else { Trace0("surface cache in use\n"); } if(_pDDSurface == NULL) { if(!CreateDDSurface(_widthActual, _heightActual, hpal)) { return FALSE; } } // reset the color table when using cache if(_cBitsPixel==8 && _pDDSurface==g_OscCache._pDDSurface && (hpal!=g_OscCache._hpal || hpal!=g_hpalHalftone)) { IDirectDrawPalette* pDDPal; PALETTEENTRY pal256[256]; long cEntries; cEntries = GetPaletteEntries(hpal, 0, 256, pal256); // get the DD palette and set entries hr = _pDDSurface->GetPalette(&pDDPal); if(SUCCEEDED(hr)) { hr = pDDPal->SetEntries(0, 0, cEntries, pal256); pDDPal->Release(); if(SUCCEEDED(hr)) { g_OscCache._hpal = hpal; } } } return TRUE; }
NTSTATUS FdoPortOpen(IN PC0C_FDOPORT_EXTENSION pDevExt) { LIST_ENTRY queueToComplete; PUCHAR pBase; ULONG size; KIRQL oldIrql; PC0C_IO_PORT pIoPort; if (InterlockedIncrement(&pDevExt->openCount) != 1) { InterlockedDecrement(&pDevExt->openCount); return STATUS_ACCESS_DENIED; } pIoPort = pDevExt->pIoPortLocal; if (pIoPort->plugInMode && !pIoPort->pIoPortRemote->isOpen) { InterlockedDecrement(&pDevExt->openCount); return STATUS_ACCESS_DENIED; } if (pIoPort->exclusiveMode) IoInvalidateDeviceRelations(pIoPort->pPhDevObj, BusRelations); switch (MmQuerySystemSize()) { case MmLargeSystem: size = 4096; pBase = (PUCHAR)C0C_ALLOCATE_POOL(NonPagedPool, size); if (pBase) break; case MmMediumSystem: size = 1024; pBase = (PUCHAR)C0C_ALLOCATE_POOL(NonPagedPool, size); if (pBase) break; case MmSmallSystem: size = 128; pBase = (PUCHAR)C0C_ALLOCATE_POOL(NonPagedPool, size); if (pBase) break; default: size = 0; pBase = NULL; } InitializeListHead(&queueToComplete); #if ENABLE_TRACING if (pIoPort->amountInWriteQueue) { NTSTATUS status; UNICODE_STRING msg; status = STATUS_SUCCESS; RtlInitUnicodeString(&msg, NULL); StrAppendStr0(&status, &msg, L"!!!WARNING!!! amountInWriteQueue = "); StrAppendNum(&status, &msg, pIoPort->amountInWriteQueue, 10); Trace0((PC0C_COMMON_EXTENSION)pDevExt, msg.Buffer); StrFree(&msg); } #endif /* ENABLE_TRACING */ KeAcquireSpinLock(pIoPort->pIoLock, &oldIrql); InitBuffer(&pIoPort->readBuf, pBase, size); pIoPort->amountInWriteQueue = 0; pIoPort->tryWrite = FALSE; pIoPort->errors = 0; pIoPort->waitMask = 0; pIoPort->eventMask = 0; RtlZeroMemory(&pIoPort->perfStats, sizeof(pIoPort->perfStats)); pIoPort->handFlow.XoffLimit = size >> 3; pIoPort->handFlow.XonLimit = size >> 1; pIoPort->pIoPortRemote->brokeIdleChars = 0; SetHandFlow(pIoPort, NULL, &queueToComplete); SetModemControl(pIoPort, C0C_MCR_OPEN, C0C_MCR_OPEN, &queueToComplete); if (pIoPort->pIoPortRemote->pWriteDelay && pIoPort->pIoPortRemote->brokeCharsProbability > 0) StartWriteDelayTimer(pIoPort->pIoPortRemote->pWriteDelay); KeReleaseSpinLock(pIoPort->pIoLock, oldIrql); pIoPort->isOpen = TRUE; if (pIoPort->pIoPortRemote->plugInMode) IoInvalidateDeviceRelations(pIoPort->pIoPortRemote->pPhDevObj, BusRelations); FdoPortCompleteQueue(&queueToComplete); return STATUS_SUCCESS; }
NTSTATUS FdoBusPnp( IN PC0C_FDOBUS_EXTENSION pDevExt, IN PIRP pIrp) { NTSTATUS status; PIO_STACK_LOCATION pIrpStack = IoGetCurrentIrpStackLocation(pIrp); ULONG minorFunction = pIrpStack->MinorFunction; PDEVICE_OBJECT pLowDevObj = pDevExt->pLowDevObj; // IRP_MN_REMOVE_DEVICE deletes *pDevExt! status = STATUS_SUCCESS; switch (minorFunction) { case IRP_MN_QUERY_DEVICE_RELATIONS: if (pIrpStack->Parameters.QueryDeviceRelations.Type == BusRelations) { ULONG countPdos, countRelations; PDEVICE_RELATIONS pRelationsPrev, pRelations; int i; countPdos = 0; for (i = 0 ; i < 2 ; i++) { if (pDevExt->childs[i].pDevExt) countPdos++; } if (!countPdos) break; pRelationsPrev = (PDEVICE_RELATIONS)pIrp->IoStatus.Information; countRelations = pRelationsPrev ? pRelationsPrev->Count : 0; pRelations = (PDEVICE_RELATIONS)C0C_ALLOCATE_POOL(PagedPool, sizeof(DEVICE_RELATIONS) + ((countPdos + countRelations - 1) * sizeof (PDEVICE_OBJECT))); if (!pRelations) { status = STATUS_INSUFFICIENT_RESOURCES; break; } if (countRelations) RtlCopyMemory(pRelations->Objects, pRelationsPrev->Objects, countRelations * sizeof (PDEVICE_OBJECT)); for (i = 0 ; i < 2 ; i++) { PC0C_PDOPORT_EXTENSION pPhDevExt; pPhDevExt = pDevExt->childs[i].pDevExt; if (pPhDevExt) { if (!pDevExt->childs[i].ioPort.pDevExt) { UNICODE_STRING portName; UNICODE_STRING portRegistryPath; RtlInitUnicodeString(&portRegistryPath, NULL); StrAppendPortParametersRegistryPath(&status, &portRegistryPath, pPhDevExt->portName); RtlInitUnicodeString(&portName, NULL); StrAppendParameterPortName(&status, &portName, portRegistryPath.Buffer); StrFree(&portRegistryPath); if (NT_SUCCESS(status) && portName.Length && _wcsicmp(C0C_PORT_NAME_COMCLASS, portName.Buffer) == 0) { pDevExt->childs[i].ioPort.isComClass = TRUE; Trace0((PC0C_COMMON_EXTENSION)pPhDevExt, L"Port class set to COM"); } else { pDevExt->childs[i].ioPort.isComClass = FALSE; Trace0((PC0C_COMMON_EXTENSION)pPhDevExt, L"Port class set to CNC"); } StrFree(&portName); status = STATUS_SUCCESS; } pRelations->Objects[countRelations++] = pPhDevExt->pDevObj; ObReferenceObject(pPhDevExt->pDevObj); } } pRelations->Count = countRelations; if (pRelationsPrev) ExFreePool(pRelationsPrev); pIrp->IoStatus.Information = (ULONG_PTR)pRelations; pIrp->IoStatus.Status = STATUS_SUCCESS; } break; case IRP_MN_REMOVE_DEVICE: RemoveFdoBus(pDevExt); pDevExt = NULL; pIrp->IoStatus.Status = STATUS_SUCCESS; break; case IRP_MN_START_DEVICE: case IRP_MN_STOP_DEVICE: case IRP_MN_QUERY_STOP_DEVICE: case IRP_MN_CANCEL_STOP_DEVICE: case IRP_MN_QUERY_REMOVE_DEVICE: case IRP_MN_CANCEL_REMOVE_DEVICE: case IRP_MN_SURPRISE_REMOVAL: pIrp->IoStatus.Status = STATUS_SUCCESS; break; } if (status == STATUS_SUCCESS) { TraceIrp("FdoBusPnp", pIrp, NULL, TRACE_FLAG_RESULTS); IoSkipCurrentIrpStackLocation(pIrp); status = IoCallDriver(pLowDevObj, pIrp); TraceCode((PC0C_COMMON_EXTENSION)pDevExt, "PNP ", codeNameTablePnp, minorFunction, &status); } else { TraceIrp("PNP", pIrp, &status, TRACE_FLAG_RESULTS); pIrp->IoStatus.Status = status; IoCompleteRequest(pIrp, IO_NO_INCREMENT); } return status; }
HRESULT CDwnDoc::SetAuthorColors(LPCTSTR pchColors, int cchColors) { if(_fGotAuthorPalette) { Trace0("Ignoring author palette\n"); RRETURN(S_OK); } Trace0("Setting author colors\n"); HRESULT hr = S_OK; if(cchColors == -1) { cchColors = _tcslen(pchColors); } LPCTSTR pch = pchColors; LPCTSTR pchTok = pchColors; LPCTSTR pchEnd = pchColors + cchColors; PALETTEENTRY ape[256]; unsigned cpe = 0; CColorValue cv; while((pch<pchEnd) && (cpe<256)) { while(*pch && isspace(*pch)) { pch++; } pchTok = pch; BOOL fParen = FALSE; while(pch<pchEnd && (fParen || !isspace(*pch))) { if(*pch == _T('(')) { if(fParen) { hr = E_INVALIDARG; goto Cleanup; } else { fParen = TRUE; } } else if(*pch == _T(')')) { if(fParen) { fParen = FALSE; } else { hr = E_INVALIDARG; goto Cleanup; } } pch++; } int iStrLen = pch - pchTok; if(iStrLen > 0) { hr = cv.FromString(pchTok, FALSE, iStrLen); if(FAILED(hr)) { goto Cleanup; } COLORREF cr = cv.GetColorRef(); ape[cpe].peRed = GetRValue(cr); ape[cpe].peGreen = GetGValue(cr); ape[cpe].peBlue = GetBValue(cr); ape[cpe].peFlags = 0; cpe++; } } if(cpe) { Assert(!_ape); _ape = (PALETTEENTRY*)MemAlloc(cpe*sizeof(PALETTEENTRY)); if(!_ape) { hr = E_OUTOFMEMORY; goto Cleanup; } memcpy(_ape, ape, cpe*sizeof(PALETTEENTRY)); _cpe = cpe; } Cleanup: Trace((SUCCEEDED(hr) ? _T("Author palette: %d colors\n") : _T("Author palette failed\n"), _cpe)); // No matter what happened, we are no longer interested in getting the palette PreventAuthorPalette(); RRETURN(hr); }
BOOLEAN HidePort(IN PC0C_FDOPORT_EXTENSION pDevExt) { BOOLEAN res; NTSTATUS status; if (!pDevExt->shown) return TRUE; res = TRUE; if ((pDevExt->shown & C0C_SHOW_WMIREG) != 0) { status = IoWMIRegistrationControl(pDevExt->pDevObj, WMIREG_ACTION_DEREGISTER); pDevExt->shown &= ~C0C_SHOW_WMIREG; if (NT_SUCCESS(status)) { Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"Hidden WMIREG"); } else { res = FALSE; Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"HidePort IoWMIRegistrationControl FAIL"); } } if (pDevExt->symbolicLinkName.Buffer && (pDevExt->shown & C0C_SHOW_INTERFACE) != 0) { status = IoSetDeviceInterfaceState(&pDevExt->symbolicLinkName, FALSE); pDevExt->shown &= ~C0C_SHOW_INTERFACE; if (NT_SUCCESS(status)) { Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"Hidden INTERFACE"); } else { res = FALSE; Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"HidePort IoSetDeviceInterfaceState FAIL"); } } if (pDevExt->ntDeviceName.Buffer && (pDevExt->shown & C0C_SHOW_DEVICEMAP) != 0) { status = RtlDeleteRegistryValue(RTL_REGISTRY_DEVICEMAP, C0C_SERIAL_DEVICEMAP, pDevExt->ntDeviceName.Buffer); pDevExt->shown &= ~C0C_SHOW_DEVICEMAP; if (NT_SUCCESS(status)) { Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"Hidden DEVICEMAP"); } else { res = FALSE; Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"HidePort RtlDeleteRegistryValue " C0C_SERIAL_DEVICEMAP L" FAIL"); } } if (pDevExt->win32DeviceName.Buffer && (pDevExt->shown & C0C_SHOW_SYMLINK) != 0) { status = IoDeleteSymbolicLink(&pDevExt->win32DeviceName); pDevExt->shown &= ~C0C_SHOW_SYMLINK; if (NT_SUCCESS(status)) { Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"Hidden SYMLINK"); } else { res = FALSE; Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"HidePort IoDeleteSymbolicLink FAIL"); } } if ((pDevExt->shown & C0C_SHOW_PORTNAME) != 0) res = (HidePortName(pDevExt) && res); pDevExt->shown &= ~C0C_SHOW_SHOWN; Trace00((PC0C_COMMON_EXTENSION)pDevExt, L"HidePort - ", res ? L"OK" : L"FAIL"); return res; }
BOOLEAN ShowPort(IN PC0C_FDOPORT_EXTENSION pDevExt) { BOOLEAN res; NTSTATUS status; if ((pDevExt->shown & C0C_SHOW_SHOWN) != 0) return TRUE; res = TRUE; if (!pDevExt->pIoPortLocal->isComClass && (pDevExt->shown & C0C_SHOW_PORTNAME) == 0 && (pDevExt->hide & C0C_SHOW_PORTNAME) == 0) { HANDLE hKey; status = IoOpenDeviceRegistryKey(pDevExt->pIoPortLocal->pPhDevObj, PLUGPLAY_REGKEY_DEVICE, STANDARD_RIGHTS_WRITE, &hKey); if (NT_SUCCESS(status)) { UNICODE_STRING keyName; RtlInitUnicodeString(&keyName, L"PortName"); status = ZwSetValueKey(hKey, &keyName, 0, REG_SZ, pDevExt->portName, (ULONG)((wcslen(pDevExt->portName) + 1) * sizeof(WCHAR))); if (NT_SUCCESS(status)) { pDevExt->shown |= C0C_SHOW_PORTNAME; Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"Shown PORTNAME"); } else { res = FALSE; Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"ShowPort ZwSetValueKey(PortName) FAIL"); } ZwClose(hKey); } else { res = FALSE; Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"ShowPort IoOpenDeviceRegistryKey(PLUGPLAY_REGKEY_DEVICE) FAIL"); } } if (pDevExt->ntDeviceName.Buffer) { if (pDevExt->win32DeviceName.Buffer && (pDevExt->shown & C0C_SHOW_SYMLINK) == 0 && (pDevExt->hide & C0C_SHOW_SYMLINK) == 0) { status = IoCreateSymbolicLink(&pDevExt->win32DeviceName, &pDevExt->ntDeviceName); if (NT_SUCCESS(status)) { pDevExt->shown |= C0C_SHOW_SYMLINK; Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"Shown SYMLINK"); } else { res = FALSE; Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"ShowPort IoCreateSymbolicLink FAIL"); } } if ((pDevExt->shown & C0C_SHOW_SYMLINK) != 0 && (pDevExt->shown & C0C_SHOW_DEVICEMAP) == 0 && (pDevExt->hide & C0C_SHOW_DEVICEMAP) == 0) { status = RtlWriteRegistryValue(RTL_REGISTRY_DEVICEMAP, C0C_SERIAL_DEVICEMAP, pDevExt->ntDeviceName.Buffer, REG_SZ, pDevExt->portName, (ULONG)((wcslen(pDevExt->portName) + 1) * sizeof(WCHAR))); if (NT_SUCCESS(status)) { pDevExt->shown |= C0C_SHOW_DEVICEMAP; Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"Shown DEVICEMAP"); } else { res = FALSE; Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"ShowPort RtlWriteRegistryValue " C0C_SERIAL_DEVICEMAP L" FAIL"); } } } if (pDevExt->symbolicLinkName.Buffer && (pDevExt->shown & C0C_SHOW_INTERFACE) == 0 && (pDevExt->hide & C0C_SHOW_INTERFACE) == 0) { status = IoSetDeviceInterfaceState(&pDevExt->symbolicLinkName, TRUE); if (NT_SUCCESS(status)) { pDevExt->shown |= C0C_SHOW_INTERFACE; Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"Shown INTERFACE"); } else { res = FALSE; Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"ShowPort IoSetDeviceInterfaceState FAIL"); } } if ((pDevExt->shown & C0C_SHOW_WMIREG) == 0 && (pDevExt->hide & C0C_SHOW_WMIREG) == 0) { status = IoWMIRegistrationControl(pDevExt->pDevObj, WMIREG_ACTION_REGISTER); if (NT_SUCCESS(status)) { pDevExt->shown |= C0C_SHOW_WMIREG; Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"Shown WMIREG"); } else { res = FALSE; Trace0((PC0C_COMMON_EXTENSION)pDevExt, L"ShowPort IoWMIRegistrationControl FAIL"); } } pDevExt->shown |= C0C_SHOW_SHOWN; Trace00((PC0C_COMMON_EXTENSION)pDevExt, L"ShowPort - ", res ? L"OK" : L"FAIL"); return res; }