ubyte4 GmUifSourceEntry::ReadEntry (const char * pBuffer) { const char * pBase = pBuffer; pBuffer += CharsToUByte4 (pBuffer, &Signature); CheckSignature (SG_UIF_SOURCE_ENTRY, Signature); pBuffer += CharsToUByte4 (pBuffer, &Flags); pBuffer += CharsToUByte2 (pBuffer, &SourceType); pBuffer += CharsToUByte2 (pBuffer, &SourceNameLen); pBuffer += CharsToUByte2 (pBuffer, &SourceBlockNum); pBuffer += CharsToUByte2 (pBuffer, &SourceExtLen); pBuffer += CharsToUByte8 (pBuffer, &DataOffset); SourceName.assign (pBuffer, SourceNameLen); pBuffer += SourceNameLen; for (ubyte2 index = 0; index < SourceBlockNum; ++index) { ubyte4 Data; pBuffer += CharsToUByte4 (pBuffer, &Data); SourceBlocks.push_back (Data); } vcExtendData.assign (pBuffer, pBuffer + SourceExtLen); pBuffer += SourceExtLen; assert ((GetSize () == (ubyte4) (pBuffer - pBase))); return (ubyte4) (pBuffer - pBase); }
ubyte4 GmLeafEntry::ReadEntry (const char * pBuffer) { const char * pBase = pBuffer; pBuffer += CharsToUByte4 (pBuffer, &Signature); CheckSignature (SG_UIF_LEAF_NODE_ENTRY, Signature); pBuffer += CharsToUByte4 (pBuffer, &Flags); pBuffer += CharsToUByte4 (pBuffer, &Attribute); pBuffer += CharsToUByte4 (pBuffer, &StartDataSet); pBuffer += CharsToUByte8 (pBuffer, &StartOffset); pBuffer += CharsToUByte8 (pBuffer, &FileSize); pBuffer += CharsToUByte8 (pBuffer, &CompressSize); pBuffer += CharsToUByte8 (pBuffer, &CreateTime); pBuffer += CharsToUByte8 (pBuffer, &ModifyTime); pBuffer += CharsToUByte8 (pBuffer, &AccessTime); pBuffer += CharsToUByte8 (pBuffer, &Extent); pBuffer += CharsToUByte2 (pBuffer, &LeafNameLen); pBuffer += CharsToUByte2 (pBuffer, &LeafExtLen); LeafName.assign (pBuffer, LeafNameLen); pBuffer += LeafNameLen; vcExtendData.assign (pBuffer, pBuffer + LeafExtLen); pBuffer += LeafExtLen; assert ((GetSize () == (ubyte4) (pBuffer - pBase))); return (ubyte4) (pBuffer - pBase); }
bool CMasternodeBroadcast::CheckOutpoint(int& nDos) { // we are a masternode with the same outpoint (i.e. already activated) and this mnb is ours (matches our Masternode privkey) // so nothing to do here for us if (fMasternodeMode && outpoint == activeMasternode.outpoint && pubKeyMasternode == activeMasternode.pubKeyMasternode) { return false; } AssertLockHeld(cs_main); int nHeight; CollateralStatus err = CheckCollateral(outpoint, pubKeyCollateralAddress, nHeight); if (err == COLLATERAL_UTXO_NOT_FOUND) { LogPrint(MCLog::MN, "CMasternodeBroadcast::CheckOutpoint -- Failed to find Masternode UTXO, masternode=%s\n", outpoint.ToStringShort()); return false; } if (err == COLLATERAL_INVALID_AMOUNT) { LogPrint(MCLog::MN, "CMasternodeBroadcast::CheckOutpoint -- Masternode UTXO should have 1000 DASH, masternode=%s\n", outpoint.ToStringShort()); nDos = 33; return false; } if (err == COLLATERAL_INVALID_PUBKEY) { LogPrint(MCLog::MN, "CMasternodeBroadcast::CheckOutpoint -- Masternode UTXO should match pubKeyCollateralAddress, masternode=%s\n", outpoint.ToStringShort()); nDos = 33; return false; } if (chainActive.Height() - nHeight + 1 < Params().GetConsensus().nMasternodeMinimumConfirmations) { LogPrintf("CMasternodeBroadcast::CheckOutpoint -- Masternode UTXO must have at least %d confirmations, masternode=%s\n", Params().GetConsensus().nMasternodeMinimumConfirmations, outpoint.ToStringShort()); // UTXO is legit but has not enough confirmations. // Maybe we miss few blocks, let this mnb be checked again later. mnodeman.mapSeenMasternodeBroadcast.erase(GetHash()); return false; } LogPrint(MCLog::MN, "CMasternodeBroadcast::CheckOutpoint -- Masternode UTXO verified\n"); // Verify that sig time is legit, should be at least not earlier than the timestamp of the block // at which collateral became nMasternodeMinimumConfirmations blocks deep. // NOTE: this is not accurate because block timestamp is NOT guaranteed to be 100% correct one. CBlockIndex* pRequiredConfIndex = chainActive[nHeight + Params().GetConsensus().nMasternodeMinimumConfirmations - 1]; // block where tx got nMasternodeMinimumConfirmations if (pRequiredConfIndex->GetBlockTime() > sigTime) { LogPrintf("CMasternodeBroadcast::CheckOutpoint -- Bad sigTime %d (%d conf block is at %d) for Masternode %s %s\n", sigTime, Params().GetConsensus().nMasternodeMinimumConfirmations, pRequiredConfIndex->GetBlockTime(), outpoint.ToStringShort(), addr.ToString()); return false; } if (!CheckSignature(nDos)) { LogPrintf("CMasternodeBroadcast::CheckOutpoint -- CheckSignature() failed, masternode=%s\n", outpoint.ToStringShort()); return false; } // remember the block hash when collateral for this masternode had minimum required confirmations nCollateralMinConfBlockHash = pRequiredConfIndex->GetBlockHash(); return true; }
bool CGovernanceVote::IsValid(bool fSignatureCheck) const { if(nTime > GetAdjustedTime() + (60*60)) { LogPrint("gobject", "CGovernanceVote::IsValid -- vote is too far ahead of current time - %s - nTime %lli - Max Time %lli\n", GetHash().ToString(), nTime, GetAdjustedTime() + (60*60)); return false; } // support up to MAX_SUPPORTED_VOTE_SIGNAL, can be extended if(nVoteSignal > MAX_SUPPORTED_VOTE_SIGNAL) { LogPrint("gobject", "CGovernanceVote::IsValid -- Client attempted to vote on invalid signal(%d) - %s\n", nVoteSignal, GetHash().ToString()); return false; } // 0=none, 1=yes, 2=no, 3=abstain. Beyond that reject votes if(nVoteOutcome > 3) { LogPrint("gobject", "CGovernanceVote::IsValid -- Client attempted to vote on invalid outcome(%d) - %s\n", nVoteSignal, GetHash().ToString()); return false; } masternode_info_t infoMn; if(!mnodeman.GetMasternodeInfo(masternodeOutpoint, infoMn)) { LogPrint("gobject", "CGovernanceVote::IsValid -- Unknown Masternode - %s\n", masternodeOutpoint.ToStringShort()); return false; } if(!fSignatureCheck) return true; return CheckSignature(infoMn.pubKeyMasternode); }
ubyte4 GmUifRootEntry::ReadEntry (const char * pBuffer) { const char * pBase = pBuffer; pBuffer += CharsToUByte4 (pBuffer, &Signature); CheckSignature (SG_UIF_ROOT_ENTRY, Signature); pBuffer += CharsToUByte2 (pBuffer, &EntryType); ////-1 means this entry is removed. pBuffer += CharsToUByte2 (pBuffer, &EntryDataType); pBuffer += CharsToUByte2 (pBuffer, &SourceNum); pBuffer += CharsToUByte2 (pBuffer, &DataSetNum); pBuffer += CharsToUByte2 (pBuffer, &ExtendDataLen); //64k is maximum; pBuffer += CharsToUByte2 (pBuffer, &TraverseMtd); pBuffer += CharsToUByte4 (pBuffer, &SourceDataLen); pBuffer += CharsToUByte4 (pBuffer, &DataSetDataLen); pBuffer += CharsToUByte4 (pBuffer, &Flags); pBuffer += CharsToUByte8 (pBuffer, &EntryTime); pBuffer += CharsToUByte8 (pBuffer, &DataOffset); pBuffer += CharsToUByte8 (pBuffer, &SourceOffset); pBuffer += CharsToUByte8 (pBuffer, &DataSetOffset); pBuffer += CharsToUByte8 (pBuffer, &ExtendDataOffset); memcpy (&Reserved, pBuffer, RESERVED_CHARS); pBuffer += RESERVED_CHARS; assert ((GetSize () == (ubyte4) (pBuffer - pBase))); return (ubyte4) (pBuffer - pBase); }
int32 FChunkCacheWorker::ProcessQueue() { SCOPE_CYCLE_COUNTER( STAT_FChunkCacheWorker_ProcessQueue ); // Add the queue to the active requests list { FScopeLock LockQueue(&QueueLock); ActiveRequests.Append(RequestQueue); RequestQueue.Empty(); } // Keep track how many request have been process this loop int32 ProcessedRequests = ActiveRequests.Num(); for (int32 RequestIndex = 0; RequestIndex < ActiveRequests.Num(); ++RequestIndex) { FChunkRequest& Request = *ActiveRequests[RequestIndex]; if (Request.RefCount.GetValue() == 0) { // ChunkRequest is no longer used by anything. Add it to the free requests lists // and release the associated buffer. ReleaseBuffer(Request.Index); ActiveRequests.RemoveAt(RequestIndex--); FreeChunkRequests.Push(&Request); } else if (Request.Buffer == NULL) { // See if the requested chunk is already cached. FChunkBuffer* CachedBuffer = GetCachedChunkBuffer(Request.Index); if (!CachedBuffer) { // This chunk is not cached. Get a free buffer if possible. CachedBuffer = GetFreeBuffer(); if (!!CachedBuffer) { // Load and verify. CachedBuffer->ChunkIndex = Request.Index; Request.Buffer = CachedBuffer; CheckSignature(Request); } } else { Request.Buffer = CachedBuffer; } if (!!CachedBuffer) { check(Request.Buffer == CachedBuffer); // Chunk is cached and trusted. We no longer need the request handle on this thread. // Let the other thread know the chunk is ready to read. Request.RefCount.Decrement(); Request.IsTrusted.Increment(); } } } return ProcessedRequests; }
bool CMasternodeBroadcast::Update(CMasternode* pmn, int& nDos, CConnman& connman) { nDos = 0; AssertLockHeld(cs_main); if (pmn->sigTime == sigTime && !fRecovery) { // mapSeenMasternodeBroadcast in CMasternodeMan::CheckMnbAndUpdateMasternodeList should filter legit duplicates // but this still can happen if we just started, which is ok, just do nothing here. return false; } // this broadcast is older than the one that we already have - it's bad and should never happen // unless someone is doing something fishy if (pmn->sigTime > sigTime) { LogPrint(MCLog::MN, "CMasternodeBroadcast::Update -- Bad sigTime %d (existing broadcast is at %d) for Masternode %s %s\n", sigTime, pmn->sigTime, outpoint.ToStringShort(), addr.ToString()); return false; } pmn->Check(); // masternode is banned by PoSe if (pmn->IsPoSeBanned()) { LogPrint(MCLog::MN, "CMasternodeBroadcast::Update -- Banned by PoSe, masternode=%s\n", outpoint.ToStringShort()); return false; } // IsVnAssociatedWithPubkey is validated once in CheckOutpoint, after that they just need to match if (pmn->pubKeyCollateralAddress != pubKeyCollateralAddress) { LogPrint(MCLog::MN, "CMasternodeBroadcast::Update -- Got mismatched pubKeyCollateralAddress and outpoint\n"); nDos = 33; return false; } if (!CheckSignature(nDos)) { LogPrint(MCLog::MN, "CMasternodeBroadcast::Update -- CheckSignature() failed, masternode=%s\n", outpoint.ToStringShort()); return false; } // if ther was no masternode broadcast recently or if it matches our Masternode privkey... if (!pmn->IsBroadcastedWithin(MASTERNODE_MIN_MNB_SECONDS) || (fMasternodeMode && pubKeyMasternode == activeMasternode.pubKeyMasternode)) { // take the newest entry LogPrint(MCLog::MN, "CMasternodeBroadcast::Update -- Got UPDATED Masternode entry: addr=%s\n", addr.ToString()); if (pmn->UpdateFromNewBroadcast(*this, connman)) { pmn->Check(); Relay(connman); } masternodeSync.BumpAssetLastTime("CMasternodeBroadcast::Update"); } return true; }
/** * Checks if the file already exists */ bool CheckFileExists( const std::string &filename, const Signature crc) { Trace("Checking file exists: " << filename); const vfs::Path outputPath = GetOutputPath(filename); vfs::FileStats stats = vfs::Stat(outputPath); if (!stats.m_exists) { return false; } return CheckSignature(outputPath, crc); }
BOOL DestroyDriveInfo( IN LPDRIVE_INFO DriveInfo ) /*++ Routine Description: Destroys a DRIVE_INFO object by freeing it, only after making sure it is valid Arguments: LPDRIVE_INFO - Supplies a pointer to a DRIVE_INFO object. Return Value: BOOL - Returns TRUE if the DRIVE_OBJECT is succesfully destroyed --*/ { BOOL Success; DbgPointerAssert( DriveInfo ); DbgAssert( CheckSignature( DriveInfo )); if(( DriveInfo == NULL ) || ( !CheckSignature( DriveInfo ))) { return FALSE; } // // Delete the DRIVE_INFO object itself. // Success = FreeObject( DriveInfo ); DbgAssert( Success ); return TRUE; }
/** * Downloads a single file from the specified server. */ bool GetOneFile( const launcher::Settings &settings, const std::string &filename, const Signature crc) { Trace("Attempting to download " << filename); core::net::NetClient client(core::net::eConnectionMode::TCP_ASYNC); std::string hostName; for (auto server = settings.get_patch_server_begin(); server != settings.get_patch_server_end(); ++server) { client.start(settings.get_patch_server(0)); if (client.valid()) { hostName = wrappers::net::http::Uri(server->get_dns_name()).getHost(); break; } } if (!client.valid()) { Log(LL::Error) << "Unable to connect to any servers." << std::endl; return false; } wrappers::net::http::HttpHeader header = wrappers::net::http::HttpHeader::Builder() .setRequestType(wrappers::net::http::HttpHeader::eRequestType::HTTP_REQUEST_GET) .setRequestPath(std::string("/") + settings.get_server_patch_dir() + filename) .addHeader("host", hostName) .build(); if (!header.valid()) { return false; } client.send(header.asBlob()); const vfs::Path outputPath = GetOutputPath(filename); vfs::ofstream outfile(outputPath, std::ios::binary | std::ios::out); if (!outfile.is_open()) { Log(LL::Error) << "Unable to open file: " << outputPath.str() << std::endl; return false; } wrappers::net::http::HttpFileHandler fileHandler(outfile); while (client.valid() && !fileHandler.done()) { client.update(fileHandler); core::thread::thisthread::yield(); } client.stop(); outfile.flush(); if (!fileHandler.success()) { return false; } return CheckSignature(outputPath, crc); }
// Get the CA which signed the certificate X *FindCaSignedX(LIST *o, X *x) { X *ret; // Validate arguments if (o == NULL || x == NULL) { return NULL; } ret = NULL; LockList(o); { UINT i; for (i = 0;i < LIST_NUM(o);i++) { X *ca = LIST_DATA(o, i); if (CheckXDateNow(ca)) { if (CompareName(ca->subject_name, x->issuer_name)) { K *k = GetKFromX(ca); if (k != NULL) { if (CheckSignature(x, k)) { ret = CloneX(ca); } FreeK(k); } } else if (CompareX(ca, x)) { ret = CloneX(ca); } } if (ret != NULL) { break; } } } UnlockList(o); return ret; }
ubyte4 GmDataSetEntry::ReadEntry (const char * pBuffer) { const char * pBase = pBuffer; pBuffer += CharsToUByte4 (pBuffer, &Signature); CheckSignature (SG_DATASET_ENTRY, Signature); pBuffer += CharsToUByte4 (pBuffer, &Flags); pBuffer += CharsToUByte2 (pBuffer, &RefCount); pBuffer += CharsToUByte2 (pBuffer, &SetNameLen); pBuffer += CharsToUByte2 (pBuffer, &SetExtLen); SetName.assign (pBuffer, SetNameLen); pBuffer += SetNameLen; vcExtendData.assign (pBuffer, pBuffer + SetExtLen); pBuffer += SetExtLen; assert (((ubyte4)(pBuffer - pBase) == GetSize ())); return (ubyte4) (pBuffer - pBase); }
/* virtual */ bool WMAPResource::Load(Archive* archive, uint32 key) { if (!Resource::Load(archive, key)) return false; if (!CheckSignature(WMAP_SIGNATURE)) return false; if (!CheckVersion(WMAP_VERSION_1)) return false; fData->ReadAt(8, fCount); fData->ReadAt(12, fOffset); // TODO: Handle the case where there are more than one. fData->ReadAt(fOffset, fWorldMapEntry); fIcons = gResManager->GetBAM(fWorldMapEntry.map_icons_bam); for (uint32 c = 0; c < fWorldMapEntry.areaentries_count; c++) { area_entry areaEntry; if (GetAreaEntry(c, areaEntry)) { fData->ReadAt( fWorldMapEntry.areaentries_offset + c * sizeof(area_entry), areaEntry); AreaEntry* entry = new AreaEntry(areaEntry); /*std::cout << "Area " << areaEntry.area; std::cout << ", short: " << areaEntry.shortname; std::cout << ", long: " << areaEntry.name; std::cout << ", tooltip: " << areaEntry.tooltip_ref; std::cout << ", loading " << areaEntry.loading_mos; std::cout << std::endl; */ entry->fIcon = const_cast<Bitmap*>(fIcons->FrameForCycle(areaEntry.icons_bam_sequence, 0)); entry->fPosition.x = (int16)areaEntry.x; entry->fPosition.y = (int16)areaEntry.y; fAreaEntries.push_back(entry); } } return true; }
/* virtual */ bool ITMResource::Load(Archive *archive, uint32 key) { if (!Resource::Load(archive, key)) return false; if (!CheckSignature(ITM_SIGNATURE)) return false; if (!CheckVersion(ITM_VERSION_1)) return false; fData->ReadAt(8, fHeader); std::cout << "Name: " << IDTable::ObjectAt(fHeader.name_identified) << std::endl; return true; }
void WEDResource::_Load() { if (!CheckSignature("WED ")) throw -1; if (!CheckVersion("V1.3")) throw -1; fData->ReadAt(8, fNumOverlays); fData->ReadAt(12, fNumTiledObjects); fData->ReadAt(16, fOverlaysOffset); fData->ReadAt(20, f2ndHeaderOffset); fData->ReadAt(24, fTiledObjectsOffset); fData->ReadAt(28, fTiledObjectsTileCellsOffset); _LoadPolygons(); }
AJ_Status AJ_LookupMessageId(AJ_Message* msg, uint8_t* secure) { uint8_t oIndex = 0; for (oIndex = 0; oIndex < ArraySize(objectLists); ++oIndex) { uint8_t pIndex = 0; const AJ_Object* obj = objectLists[oIndex]; if (!obj) { continue; } while (obj->path) { /* * Match the object path. The wildcard entry is for interfaces that are automatically * defined for all objects; specifically to support the introspection and ping methods. */ if (!(obj->flags & AJ_OBJ_FLAG_DISABLED) && ((obj->path[0] == '*') || (strcmp(obj->path, msg->objPath) == 0))) { uint8_t iIndex; AJ_InterfaceDescription desc = FindInterface(obj->interfaces, msg->iface, &iIndex); if (desc) { uint8_t mIndex = 0; *secure = SecurityApplies(*desc, obj, objectLists[oIndex]); /* * Skip the interface name and iterate over the members of the interface */ while (*(++desc)) { if (MatchMember(*desc, msg)) { msg->msgId = (oIndex << 24) | (pIndex << 16) | (iIndex << 8) | mIndex; AJ_InfoPrintf(("Identified message %x\n", msg->msgId)); return CheckSignature(*desc, msg); } ++mIndex; } } } ++pIndex; ++obj; } } AJ_ErrPrintf(("LookupMessageId(): AJ_ERR_NO_MATCH\n")); return AJ_ERR_NO_MATCH; }
// Get the root certificate that signed the specified certificate from the list X *GetIssuerFromList(LIST *cert_list, X *cert) { UINT i; X *ret = NULL; // Validate arguments if (cert_list == NULL || cert == NULL) { return NULL; } for (i = 0;i < LIST_NUM(cert_list);i++) { X *x = LIST_DATA(cert_list, i); // Name comparison if (CheckXDateNow(x)) { if (CompareName(x->subject_name, cert->issuer_name)) { // Get the public key of the root certificate K *k = GetKFromX(x); if (k != NULL) { // Check the signature if (CheckSignature(cert, k)) { ret = x; } FreeK(k); } } } if (CompareX(x, cert)) { // Complete identical ret = x; } } return ret; }
ubyte4 GmUifDirEntry::ReadEntry (const char * pBuffer) { const char * pBase = pBuffer; pBuffer += CharsToUByte4 (pBuffer, &Signature); CheckSignature (SG_UIF_DIR_NODE_ENTRY, Signature); pBuffer += CharsToUByte4 (pBuffer, &Flags); pBuffer += CharsToUByte4 (pBuffer, &Attribute); pBuffer += CharsToUByte8 (pBuffer, &CreateTime); pBuffer += CharsToUByte8 (pBuffer, &ModifyTime); pBuffer += CharsToUByte8 (pBuffer, &AccessTime); pBuffer += CharsToUByte2 (pBuffer, &DirNameLen); pBuffer += CharsToUByte2 (pBuffer, &ExtLen); DirName.assign (pBuffer, DirNameLen); pBuffer += DirNameLen; vcExtendData.assign (pBuffer, pBuffer + ExtLen); pBuffer += ExtLen; assert ((GetSize () == (ubyte4) (pBuffer - pBase))); return (ubyte4) (pBuffer - pBase); }
bool CTxLockVote::IsValid(CNode* pnode, CConnman& connman) const { if(!mnodeman.Has(outpointMasternode)) { LogPrint("instantsend", "CTxLockVote::IsValid -- Unknown masternode %s\n", outpointMasternode.ToStringShort()); mnodeman.AskForMN(pnode, outpointMasternode, connman); return false; } Coin coin; if(!GetUTXOCoin(outpoint, coin)) { LogPrint("instantsend", "CTxLockVote::IsValid -- Failed to find UTXO %s\n", outpoint.ToStringShort()); return false; } int nLockInputHeight = coin.nHeight + Params().GetConsensus().nInstantSendConfirmationsRequired - 2; int nRank; if(!mnodeman.GetMasternodeRank(outpointMasternode, nRank, nLockInputHeight, MIN_INSTANTSEND_PROTO_VERSION)) { //can be caused by past versions trying to vote with an invalid protocol LogPrint("instantsend", "CTxLockVote::IsValid -- Can't calculate rank for masternode %s\n", outpointMasternode.ToStringShort()); return false; } LogPrint("instantsend", "CTxLockVote::IsValid -- Masternode %s, rank=%d\n", outpointMasternode.ToStringShort(), nRank); int nSignaturesTotal = COutPointLock::SIGNATURES_TOTAL; if(nRank > nSignaturesTotal) { LogPrint("instantsend", "CTxLockVote::IsValid -- Masternode %s is not in the top %d (%d), vote hash=%s\n", outpointMasternode.ToStringShort(), nSignaturesTotal, nRank, GetHash().ToString()); return false; } if(!CheckSignature()) { LogPrintf("CTxLockVote::IsValid -- Signature invalid\n"); return false; } return true; }
BOOL FilesystemDetailsDlgProc( IN HWND hWnd, IN UINT message, IN WPARAM wParam, IN LPARAM lParam ) /*++ Routine Description: DriveDetailsDlgProc supports the display of the drives detail dialog which displays information about a logical drive, including, label, serial number, file system information and a host of space statistics. Arguments: Standard DLGPROC entry. Return Value: BOOL - Depending on input message and processing options. --*/ { BOOL Success; HICON hIcon; switch( message ) { case WM_INITDIALOG: { int i; TCHAR szBuffer[ MAX_PATH ]; LPDRIVE_INFO DriveInfo; VALUE_ID_MAP FSFlags[ ] = { FS_CASE_IS_PRESERVED, IDC_TEXT_CASE_IS_PRESERVED, FS_CASE_SENSITIVE, IDC_TEXT_CASE_SENSITIVE, FS_UNICODE_STORED_ON_DISK, IDC_TEXT_UNICODE_STORED_ON_DISK, FS_FILE_COMPRESSION, IDC_TEXT_FILE_COMPRESSION, FS_PERSISTENT_ACLS, IDC_TEXT_PERSISTENT_ACLS }; // // Retrieve and validate the DRIVE_INFO object. // DriveInfo = (LPDRIVE_INFO) ( ( LPPROPSHEETPAGE ) lParam)->lParam ; DbgPointerAssert( DriveInfo ); DbgAssert( CheckSignature( DriveInfo )); DbgAssert( DriveInfo->ValidDetails ); if( ( DriveInfo == NULL ) || ( ! CheckSignature( DriveInfo )) || ( ! DriveInfo->ValidDetails )) { EndDialog( hWnd, 0 ); return FALSE; } // // If the drive is remote, display its connection name in the title. // if( DriveInfo->DriveType == DRIVE_REMOTE ) { SetDlgItemText( hWnd, IDC_DRIVE_NAME, DriveInfo->RemoteNameBuffer ); } // // Set the appropriate Icon // hIcon = GetIcon (GetDriveImage(DriveInfo->DriveType), 32); if (hIcon) { hIcon = (HICON)SendDlgItemMessage(hWnd, IDC_DRIVE_ICON, STM_SETICON, (WPARAM)hIcon, 0L); if (hIcon) DestroyIcon(hIcon); } // // Fill in drive label // SetDlgItemText( hWnd, IDC_DRIVE_LABEL, DriveInfo->VolumeNameBuffer ); // // Fill in serial number // wsprintf( szBuffer, L"%X - %X", HIWORD( DriveInfo->VolumeSerialNumber ), LOWORD( DriveInfo->VolumeSerialNumber )); SetDlgItemText( hWnd, IDC_DRIVE_SERIAL_NUMBER, szBuffer ); // // Display the file system information. // SetDlgItemText( hWnd, IDC_FILESYSTEM_NAME, DriveInfo->FileSystemNameBuffer ); SetDlgItemText( hWnd, IDC_EDIT_FS_MAX_COMPONENT, FormatBigInteger( DriveInfo->MaximumComponentLength, FALSE ) ); for( i = 0; i < NumberOfEntries( FSFlags ); i++ ) { Success = EnableControl( hWnd, FSFlags[ i ].Id, DriveInfo->FileSystemFlags & FSFlags[ i ].Value ); DbgAssert( Success ); } return TRUE; } } return FALSE; }
bool CGovernanceObject::IsValidLocally(std::string& strError, bool& fMissingMasternode, bool& fMissingConfirmations, bool fCheckCollateral) const { fMissingMasternode = false; fMissingConfirmations = false; if (fUnparsable) { strError = "Object data unparseable"; return false; } switch (nObjectType) { case GOVERNANCE_OBJECT_PROPOSAL: { CProposalValidator validator(GetDataAsHexString(), true); // Note: It's ok to have expired proposals // they are going to be cleared by CGovernanceManager::UpdateCachesAndClean() // TODO: should they be tagged as "expired" to skip vote downloading? if (!validator.Validate(false)) { strError = strprintf("Invalid proposal data, error messages: %s", validator.GetErrorMessages()); return false; } if (fCheckCollateral && !IsCollateralValid(strError, fMissingConfirmations)) { strError = "Invalid proposal collateral"; return false; } return true; } case GOVERNANCE_OBJECT_TRIGGER: { if (!fCheckCollateral) { // nothing else we can check here (yet?) return true; } auto mnList = deterministicMNManager->GetListAtChainTip(); std::string strOutpoint = masternodeOutpoint.ToStringShort(); auto dmn = mnList.GetMNByCollateral(masternodeOutpoint); if (!dmn) { strError = "Failed to find Masternode by UTXO, missing masternode=" + strOutpoint; return false; } if (!mnList.IsMNValid(dmn)) { if (mnList.IsMNPoSeBanned(dmn)) { strError = "Masternode is POSE_BANNED, masternode=" + strOutpoint; } else { strError = "Masternode is invalid for unknown reason, masternode=" + strOutpoint; } return false; } // Check that we have a valid MN signature if (!CheckSignature(dmn->pdmnState->pubKeyOperator)) { strError = "Invalid masternode signature for: " + strOutpoint + ", pubkey = " + dmn->pdmnState->pubKeyOperator.ToString(); return false; } return true; } default: { strError = strprintf("Invalid object type %d", nObjectType); return false; } } }
BOOL DisplayServiceProc(LPDISPLAY_SERVICE ServiceObject) /*++ Routine Description: DisplayServiceProc displays the details about the supplied service/device. Arguments: Standard PROC entry. Return Value: BOOL - Depending on input message and processing options. --*/ { BOOL Success; LPDISPLAY_SERVICE DisplayService; LPQUERY_SERVICE_CONFIG SvcConfig; LPTSTR Dependent; DWORD Count; TCHAR Buffer[ MAX_PATH ]; // // Retrieve and validate the DISPLAY_SERVICE object. // DisplayService= ( LPDISPLAY_SERVICE ) ServiceObject; DbgPointerAssert( DisplayService ); DbgAssert( CheckSignature( DisplayService )); if( ( DisplayService == NULL ) || ( ! CheckSignature( DisplayService ))) { return FALSE; } // // Display the name and state of the service/device, separated by a // colon, as the window title. // PrintToFile((LPCTSTR)DisplayService->Ess->lpDisplayName,IDC_SERVICE_TITLE,TRUE); PrintDwordToFile(DisplayService->Ess->ServiceStatus.dwCurrentState,IDC_CURRENT_STATE); // // Create a configuration status for this device/service. // SvcConfig = ConstructSvcConfig( DisplayService->hSvc, DisplayService->Ess ); DbgPointerAssert( SvcConfig ); if( SvcConfig == NULL ) { return FALSE; } // // Display the service/device's type, start type, error control, // and start name. // //defined in D:\NT\PUBLIC\SDK\INC\winsvc.h //typedef struct _QUERY_SERVICE_CONFIGA { //DWORD dwServiceType; //DWORD dwStartType; //DWORD dwErrorControl; //LPSTR lpBinaryPathName; //LPSTR lpLoadOrderGroup; //DWORD dwTagId; //LPSTR lpDependencies; //LPSTR lpServiceStartName; //LPSTR lpDisplayName; //} QUERY_SERVICE_CONFIGA, *LPQUERY_SERVICE_CONFIGA; PrintDwordToFile((DWORD) SvcConfig->dwServiceType ,IDC_EDIT_SERVICE_TYPE); PrintDwordToFile((DWORD) SvcConfig->dwStartType ,IDC_EDIT_START_TYPE); PrintDwordToFile((DWORD) SvcConfig->dwErrorControl ,IDC_EDIT_ERROR_CONTROL); PrintToFile((LPCTSTR)SvcConfig->lpServiceStartName, IDC_EDIT_START_NAME,TRUE); // // If the service/device has a binary path name display it. // if( SvcConfig->lpBinaryPathName != NULL ) { TCHAR Buffer2[ MAX_PATH ]; LPTSTR PathName; // // If the binary path name's prefix is '\\SystemRoot' replace // this with '%SystemRoot%' and expand the environment // variable to the real system root. This is needed because // services/devices that are started by the I/O system do not // use the environment variable form in their name. // if( _tcsnicmp( SvcConfig->lpBinaryPathName, TEXT( "\\SystemRoot" ), 11 ) == 0 ) { PrintToFile((LPCTSTR)&SvcConfig->lpBinaryPathName[11],IDC_SYSTEM_ROOT,TRUE);//test to see if we need to remove the following Count = ExpandEnvironmentStrings( Buffer, Buffer2, sizeof( Buffer2 ) ); DbgAssert(( Count != 0 ) && ( Count <= sizeof( Buffer2 ))); PathName = Buffer2; PrintToFile((LPCTSTR) Buffer2,IDC_EDIT_PATHNAME,TRUE); } else { PathName = SvcConfig->lpBinaryPathName; PrintToFile((LPCTSTR) SvcConfig->lpBinaryPathName,IDC_EDIT_PATHNAME,TRUE); } }//endif // // Display the name of the order group. // PrintToFile((LPCTSTR) SvcConfig->lpLoadOrderGroup,IDC_EDIT_GROUP,TRUE); // // Traverse the list of dependencies and display them in their // appropriate group. // Dependent = SvcConfig->lpDependencies; while(( Dependent != NULL ) && ( Dependent[ 0 ] != TEXT( '\0' ))) { UINT ListId; LONG Index; LPTSTR Name; // // If the dependent has the prefix SC_GROUP_IDENTIFIER then // display it in the group dependency list otherwise display it // in the service dependency list. // if( Dependent[ 0 ] == SC_GROUP_IDENTIFIER ) { ListId = IDC_LIST_GROUP_DEPEND; Name = &Dependent[ 1 ]; } else { ListId = IDC_LIST_SERVICE_DEPEND; Name = Dependent; } PrintToFile((LPCTSTR) Name,IDC_NAME,TRUE); // // Get the next dependent from the list of NUL terminated // strings (the list itself is further NUL terminated). // Dependent += _tcslen( Dependent ) + 1; }//end while // // Destroy the QUERY_SERVICE_CONFIG structure. // Success = DestroySvcConfig( SvcConfig ); DbgAssert( Success ); return TRUE; }
BOOL GeneralDriveDetailsDlgProc( IN HWND hWnd, IN UINT message, IN WPARAM wParam, IN LPARAM lParam ) /*++ Routine Description: GeneralDriveDetailsDlgProc supports the display of the General information tab of the Drive Details Property Dialog. Arguments: Standard DLGPROC entry. Return Value: BOOL - Depending on input message and processing options. --*/ { BOOL Success; LARGE_INTEGER LargeInt; HANDLE hIcon; switch( message ) { case WM_INITDIALOG: { int i; TCHAR szBuffer[ MAX_PATH ]; LPDRIVE_INFO DriveInfo; // // Retrieve and validate the DRIVE_INFO object. // DriveInfo = (LPDRIVE_INFO) ( ( LPPROPSHEETPAGE ) lParam)->lParam ; DbgPointerAssert( DriveInfo ); DbgAssert( CheckSignature( DriveInfo )); DbgAssert( DriveInfo->ValidDetails ); if( ( DriveInfo == NULL ) || ( ! CheckSignature( DriveInfo )) || ( ! DriveInfo->ValidDetails )) { EndDialog( hWnd, 0 ); return FALSE; } // // If the drive is remote, display its connection name in the title. // if( DriveInfo->DriveType == DRIVE_REMOTE ) { SetDlgItemText( hWnd, IDC_DRIVE_NAME, DriveInfo->RemoteNameBuffer ); } // // Set the appropriate Icon // hIcon = GetIcon (GetDriveImage(DriveInfo->DriveType), 32); if ( hIcon ) { hIcon = (HICON)SendDlgItemMessage(hWnd, IDC_DRIVE_ICON, STM_SETICON, (WPARAM)hIcon, 0L); if (hIcon) DestroyIcon(hIcon); } // // Fill in drive label // SetDlgItemText( hWnd, IDC_DRIVE_LABEL, DriveInfo->VolumeNameBuffer ); // // Fill in serial number // wsprintf( szBuffer, L"%X - %X", HIWORD( DriveInfo->VolumeSerialNumber ), LOWORD( DriveInfo->VolumeSerialNumber )); SetDlgItemText( hWnd, IDC_DRIVE_SERIAL_NUMBER, szBuffer ); // // Display the space statistics. // SetDlgItemText( hWnd, IDC_SECTORS_PER_CLUSTER, FormatBigInteger( DriveInfo->SectorsPerCluster, FALSE ) ); SetDlgItemText( hWnd, IDC_BYTES_PER_SECTOR, FormatBigInteger( DriveInfo->BytesPerSector, FALSE ) ); SetDlgItemText( hWnd, IDC_FREE_CLUSTERS, FormatBigInteger( DriveInfo->FreeClusters, FALSE ) ); SetDlgItemText( hWnd, IDC_USED_CLUSTERS, FormatBigInteger( DriveInfo->Clusters - DriveInfo->FreeClusters, FALSE ) ); SetDlgItemText( hWnd, IDC_TOTAL_CLUSTERS, FormatBigInteger( DriveInfo->Clusters, FALSE ) ); // // Use LargeInteger routines for large drives ( > 4G ) // LargeInt.QuadPart = UInt32x32To64( DriveInfo->FreeClusters, (DriveInfo->SectorsPerCluster * DriveInfo->BytesPerSector) ); SetDlgItemText( hWnd, IDC_FREE_BYTES, FormatLargeInteger( &LargeInt, FALSE ) ); LargeInt.QuadPart = UInt32x32To64( (DriveInfo->Clusters - DriveInfo->FreeClusters), (DriveInfo->SectorsPerCluster * DriveInfo->BytesPerSector) ); SetDlgItemText( hWnd, IDC_USED_BYTES, FormatLargeInteger( &LargeInt, FALSE ) ); LargeInt.QuadPart = UInt32x32To64( DriveInfo->Clusters, (DriveInfo->SectorsPerCluster * DriveInfo->BytesPerSector) ); SetDlgItemText( hWnd, IDC_TOTAL_BYTES, FormatLargeInteger( &LargeInt, FALSE ) ); return TRUE; } case WM_COMMAND: { switch( LOWORD( wParam )) { case IDOK: case IDCANCEL: EndDialog( hWnd, 1 ); return TRUE; } break; } } return( FALSE ); }
BOOL PortResourceProc( LPSYSTEM_RESOURCES PortObject, int Translation) /*++ Routine Description: PortResourceProc supports the display of port resources for each device/driver in the system. Arguments: Standard PROC entry. Return Value: BOOL - Depending on input message and processing options. --*/ { BOOL Success; static LPSYSTEM_RESOURCES SystemResourceLists; DWORD Widths[ ] = { 22, 10, ( DWORD ) -1 }; LPRESOURCE_DESCRIPTOR ResourceDescriptor; TCHAR StartBuffer[ MAX_PATH ]; TCHAR LengthBuffer[ MAX_PATH ]; // // Retrieve and validate the system resource lists. // SystemResourceLists = ( LPSYSTEM_RESOURCES ) PortObject; DbgPointerAssert( SystemResourceLists ); DbgAssert( CheckSignature( SystemResourceLists )); if( ( ! SystemResourceLists ) || ( ! CheckSignature( SystemResourceLists ))) { return FALSE; } ResourceDescriptor = SystemResourceLists[ Translation ].PortHead; DbgPointerAssert( ResourceDescriptor ); DbgAssert( CheckSignature( ResourceDescriptor )); if( ( ! ResourceDescriptor ) || ( ! CheckSignature( ResourceDescriptor ))) { return FALSE; } // // Walk the resource descriptor list, formatting the appropriate // values and adding the CLB_ROW to the Clb. // while( ResourceDescriptor ) { DbgAssert( ResourceDescriptor->CmResourceDescriptor.Type == CmResourceTypePort ); PrintDwordToFile(ResourceDescriptor->CmResourceDescriptor.u.Port.Start.LowPart,IDC_PORT_START_LOWPART); //take out for now scottsu //PrintDwordToFile(ResourceDescriptor->CmResourceDescriptor.u.Port.Start,IDC_PORT_START); PrintDwordToFile(ResourceDescriptor->CmResourceDescriptor.u.Port.Length,IDC_PORT_LENGTH); PrintToFile((LPCTSTR) ResourceDescriptor->Owner->Name,IDC_PORT_NAME,TRUE); PrintToFile((LPCTSTR)TEXT("\n"),IDC_SPACE,TRUE); // // Get the next resource descriptor. // ResourceDescriptor = ResourceDescriptor->NextSame; } return TRUE; }
BOOL FreeDriveInfoStructures( HWND hWnd ) /*++ Routine Description: Walks the tree in the tree view window, freeing DRIVE_INFO objects. Arguments: hWnd - tab window handle Return Value: BOOL true if successful --*/ { HWND hWndTree = GetDlgItem(hWnd, IDC_TV_DRIVE_LIST); TV_ITEM tvi; TV_ITEM tviChild; LPDRIVE_INFO lpdi; tvi.mask = tviChild.mask = TVIF_HANDLE | TVIF_PARAM; tvi.hItem = TreeView_GetRoot( hWndTree ); tvi.hItem = TreeView_GetChild( hWndTree, tvi.hItem); // // Walk the TreeView, freeing memory associated with the tvis.item.lParam // while( tvi.hItem ){ if ( TreeView_GetItem(hWndTree, &tvi) ){ // // If we have found a pointer to a DRIVE_INFO, free it // lpdi = (LPDRIVE_INFO) tvi.lParam; if( ( lpdi != NULL ) && ( CheckSignature( lpdi ) ) ){ FreeObject( lpdi ); } } // // Check the children as well // tviChild.hItem = TreeView_GetChild( hWndTree, tvi.hItem); while( tviChild.hItem ) { if ( TreeView_GetItem(hWndTree, &tviChild) ){ // // If we have found a pointer to a DRIVE_INFO, free it // lpdi = (LPDRIVE_INFO) tviChild.lParam; if( ( lpdi != NULL ) && ( CheckSignature( lpdi ) ) ){ FreeObject( lpdi ); } } tviChild.hItem = TreeView_GetNextSibling(hWndTree, tviChild.hItem); } // // Get next tree item // tvi.hItem = TreeView_GetNextSibling(hWndTree, tvi.hItem); } return(TRUE); }
BOOL InterruptResourceProc(LPSYSTEM_RESOURCES InterruptObject, int Translation) /*++ Routine Description: InterruptResourceProc supports the display of interrupt resources for each device/driver in the system. Arguments: Standard DLGPROC entry. Return Value: BOOL - Depending on input message and processing options. --*/ { BOOL Success; static LPSYSTEM_RESOURCES SystemResourceLists; DWORD Widths[ ] = { 5, 5, 16, ( DWORD ) -1 }; LPRESOURCE_DESCRIPTOR ResourceDescriptor; TCHAR VectorBuffer[ MAX_PATH ]; TCHAR LevelBuffer[ MAX_PATH ]; TCHAR AffinityBuffer[ MAX_PATH ]; // // Retrieve and validate the system resource lists. // SystemResourceLists = ( LPSYSTEM_RESOURCES ) InterruptObject; DbgPointerAssert( SystemResourceLists ); DbgAssert( CheckSignature( SystemResourceLists )); if( ( ! SystemResourceLists ) || ( ! CheckSignature( SystemResourceLists ))) { return FALSE; } ResourceDescriptor = SystemResourceLists[ Translation ].InterruptHead; DbgPointerAssert( ResourceDescriptor ); DbgAssert( CheckSignature( ResourceDescriptor )); if( ( ! ResourceDescriptor ) || ( ! CheckSignature( ResourceDescriptor ))) { return FALSE; } // // Walk the resource descriptor list, formatting the appropriate // values and adding the CLB_ROW to the Clb. // while( ResourceDescriptor ) { DbgAssert( ResourceDescriptor->CmResourceDescriptor.Type == CmResourceTypeInterrupt ); PrintDwordToFile(ResourceDescriptor->CmResourceDescriptor.u.Interrupt.Vector,IDC_INTERRUPT_VECTOR); PrintDwordToFile(ResourceDescriptor->CmResourceDescriptor.u.Interrupt.Level,IDC_INTERRUPT_LEVEL); PrintDwordToFile(ResourceDescriptor->CmResourceDescriptor.u.Interrupt.Affinity,IDC_INTERRUPT_AFFINITY); PrintToFile((LPCTSTR) ResourceDescriptor->Owner->Name,IDC_INTERRUPT_NAME,TRUE); PrintToFile((LPCTSTR)TEXT("\n"),IDC_SPACE,TRUE); // // Get the next resource descriptor. // ResourceDescriptor = ResourceDescriptor->NextSame; } return TRUE; }
BOOL ClbSetColumnWidths( IN HWND hWnd, IN int ControlId, IN LPDWORD Widths ) /*++ Routine Description: ClbSetColumnWidths sets the width of each column based on the supplied widths in characters. Note that the column on the far right extends to the edge of the Clb. Arguments: hWnd - Supplies the window handle for the parent window. ControlId - Supplies the control id for this Clb for the supplied hWnd. Widths - Supplies an array of widths, one less then the number of columns, in characters. Return Value: BOOL - Returns TRUE if the widths were successfully adjusted. --*/ { BOOL Success; DWORD Columns; LPCLB_INFO ClbInfo; HWND hWndClb; LONG CharWidth; LONG CharHeight; DWORD i; LPLONG WidthsInPixels; LONG TotalPixels; HDC hDCClientHeader; HD_ITEM hdi; UINT iRight; // // Validate arguments. // DbgHandleAssert( hWnd ); DbgPointerAssert( Widths ); // // Retrieve information for this ColumnListBox. // hWndClb = GetDlgItem( hWnd, ControlId ); DbgHandleAssert( hWndClb ); ClbInfo = RestoreClbInfo( hWndClb ); DbgPointerAssert( ClbInfo ); DbgAssert( CheckSignature( ClbInfo )); // // Get thd HDC for the header. // hDCClientHeader = GetDC( ClbInfo->hWndHeader ); DbgHandleAssert( hDCClientHeader ); // // Get the width of a character. // Success = GetCharMetrics( hDCClientHeader, &CharWidth, &CharHeight ); DbgAssert( Success ); // // Release the DC for the header. // Success = ReleaseDC( ClbInfo->hWndHeader, hDCClientHeader ); DbgAssert( Success ); // // Allocate an array of pixel widths, one for each column. // WidthsInPixels = AllocateObject( LONG, ClbInfo->Columns ); DbgPointerAssert( WidthsInPixels ); // // Compute the width of each column (not including the rightmost) in pixels, // and the total number of pixels used by these columns. // TotalPixels = 0; for( i = 0; i < ClbInfo->Columns - 1; i++ ) { WidthsInPixels[ i ] = Widths[ i ] * CharWidth; TotalPixels += WidthsInPixels[ i ]; } // // The caller did not specify the width of the rightmost column. // if( Widths[ i ] == -1 ) { RECT Rect; // // Set the width of the rightmost column to the remainder of the width // of the header window. // Success = GetClientRect( ClbInfo->hWndHeader, &Rect ); DbgAssert( Success ); WidthsInPixels[ i ] = ( Rect.right - Rect.left ) - TotalPixels; } else { // // Set the width of the rightmost column to the value supplied // by the caller. // WidthsInPixels[ i ] = Widths[ i ] * CharWidth; } // // Tell the header window the width of each column. // hdi.mask = HDI_WIDTH; for( i = 0; i < ClbInfo->Columns - 1; i++ ) { hdi.cxy = WidthsInPixels[i]; Success = Header_SetItem(ClbInfo->hWndHeader, i, &hdi); DbgAssert( Success ); } // // Calc the array of right edges. // iRight = 0; for( i = 0; i < ClbInfo->Columns - 1; i++ ) { iRight += WidthsInPixels[i]; ClbInfo->Right[i] = iRight; } // // Free the array of pixel widths. // Success = FreeObject( WidthsInPixels ); DbgAssert( Success ); return TRUE; }
BOOL ClbAddData( IN HWND hWnd, IN int ControlId, IN LPCLB_ROW ClbRow ) /*++ Routine Description: ClbAddData adds a new row of data to the Clb control's List Box. Arguments: hWnd - Supplies the window handle for the parent window. ControlId - Supplies the control id for this Clb for the supplied hWnd. ClbRow - Supplies a pointer to a CLB_ROW object which contains user define per row data along with an array of CLB_STRINGs. Return Value: BOOL - Returns TRUE if the data was successfully added. --*/ { LPCLB_INFO ClbInfo; LRESULT LbErr; DWORD i; HWND hWndClb; LPCLB_ROW TempRow; // // Validate arguments. // DbgHandleAssert( hWnd ); DbgPointerAssert( ClbRow ); // // Retrieve information for this ColumnListBox. // hWndClb = GetDlgItem( hWnd, ControlId ); DbgHandleAssert( hWndClb ); ClbInfo = RestoreClbInfo( hWndClb ); DbgPointerAssert( ClbInfo ); DbgAssert( CheckSignature( ClbInfo )); // // Validate the count of strings. // DbgAssert( ClbRow->Count == ClbInfo->Columns ); // // Capture the CLB_ROW object. // TempRow = AllocateObject( CLB_ROW, 1 ); DbgPointerAssert( TempRow ); CopyMemory( TempRow, ClbRow, sizeof( CLB_ROW) ); // // Capture the strings. // TempRow->Strings = AllocateObject( CLB_STRING, ClbInfo->Columns ); DbgPointerAssert( TempRow->Strings ); for( i = 0; i < ClbInfo->Columns; i++ ) { // // Copy the header. // CopyMemory( &TempRow->Strings[ i ], &ClbRow->Strings[ i ], sizeof( CLB_STRING ) ); // // Copy the string. // TempRow->Strings[ i ].String = _wcsdup( ClbRow->Strings[ i ].String ); } // // Store the CLB_ROW object in the listbox. // LbErr = SendMessage( ClbInfo->hWndListBox, LB_ADDSTRING, 0, ( LPARAM ) TempRow ); DbgAssert(( LbErr != LB_ERR ) && ( LbErr != LB_ERRSPACE )); return TRUE; }
LRESULT ClbWndProc( IN HWND hWnd, IN UINT message, IN WPARAM wParam, IN LPARAM lParam ) /*++ Routine Description: This function is the window procedure for the Clb custom control. Arguments: Standard window procedure parameters. Return Value: LRESULT - dependent on the supplied message. --*/ { BOOL Success; LPCLB_INFO ClbInfo; if( message == WM_NCCREATE ) { LONG Long; // // Save the original styles. // Long = SetWindowLong( hWnd, GWL_USERDATA, (( LPCREATESTRUCT ) lParam )->style ); DbgAssert( Long == 0 ); // // Get rid of any styles that are uninteresting to the Clb. // SetWindowLong( hWnd, GWL_STYLE, (( LPCREATESTRUCT ) lParam )->style & CLBS_CLB ); return TRUE; } if( message == WM_CREATE ) { // // Assert that there is no prior per window information associated // with this Clb. // DbgAssert( RestoreClbInfo( hWnd ) == NULL ); // // Restore the original styles. // (( LPCREATESTRUCT ) lParam )->style = GetWindowLong( hWnd, GWL_USERDATA ); // // Allocate a CLB_INFO object for this Clb and initialize the Clb // relevant fields. // ClbInfo = AllocateObject( CLB_INFO, 1 ); DbgPointerAssert( ClbInfo ); // // Set the number of columns to zero so that remainder of creation // understands the state of the Clb. // ClbInfo->Columns = 0; // // Create the header portion of the Clb. // Success = CreateHeader( hWnd, ClbInfo, ( LPCREATESTRUCT ) lParam ); DbgAssert( Success ); // // Create the list box portion of the Clb. // Success = CreateListBox( hWnd, ClbInfo, ( LPCREATESTRUCT ) lParam ); DbgAssert( Success ); // // Adjust the column number, widths based on the heading text. // Success = AdjustClbHeadings( hWnd, ClbInfo, (( LPCREATESTRUCT ) lParam )->lpszName ); DbgAssert( Success ); // // Everything was succesfully created so set the Clb's signature // and save it away as part of the per window data. // SetSignature( ClbInfo ); SaveClbInfo( ClbInfo ); return 0; } // // Get the ClbInfo object for this Clb and make sure that its already // been created i.e. WM_CREATE was already executed and thereby initialized // and saved a ClbInfo object. // ClbInfo = RestoreClbInfo( hWnd ); if( ClbInfo != NULL ) { // // Validate that this really is a ClbInfo object. // DbgAssert( CheckSignature( ClbInfo )); switch( message ) { case WM_DESTROY: { // // Delete the font used in the list box. // Success = DeleteObject( ClbInfo->hFontListBox ); DbgAssert( Success ); // // Delete the array of right habd edges. // Success = FreeObject( ClbInfo->Right ); DbgAssert( Success ); // // Delete the CLB_INFO object for this window. // Success = FreeObject( ClbInfo ); DbgAssert( Success ); SaveClbInfo ( ClbInfo ); return 0; } case WM_PAINT: { PAINTSTRUCT ps; RECT Rect; POINT Points[ 2 ]; HDC hDC; HPEN hPen; hDC = BeginPaint( hWnd, &ps ); DbgAssert( hDC == ps.hdc ); Success = GetClientRect( hWnd, &Rect ); DbgAssert( Success ); Points[ 0 ].x = 0; Points[ 0 ].y = ClbInfo->HeaderHeight + 1; Points[ 1 ].x = Rect.right - Rect.left; Points[ 1 ].y = ClbInfo->HeaderHeight + 1; hPen = GetStockObject( BLACK_PEN ); DbgHandleAssert( hPen ); hPen = SelectObject( hDC, hPen ); Success = Polyline( hDC, Points, NumberOfEntries( Points )); DbgAssert( Success ); hPen = SelectObject( hDC, hPen ); Success = DeleteObject( hPen ); DbgAssert( Success ); Success = EndPaint( hWnd, &ps ); DbgAssert( Success ); return 0; } case WM_COMMAND: switch( LOWORD( wParam )) { case ID_LISTBOX: switch( HIWORD( wParam )) { case LBN_DBLCLK: case LBN_KILLFOCUS: case LBN_SELCHANGE: { // // These messages come to ClbWndProc because it is the parent // of the list box, but they are really intended for the parent // of the Clb. // HWND hWndParent; // // Forward the message to the Clb's parent if it has a parent. // hWndParent = GetParent( hWnd ); DbgHandleAssert( hWndParent ); if( hWndParent != NULL ) { // // Replace the control id and handle with the Clb's. // LOWORD( wParam ) = GetDlgCtrlID( hWnd ); DbgAssert( LOWORD( wParam ) != 0 ); lParam = ( LPARAM ) hWnd; // // Forward the message... // return SendMessage( hWndParent, message, wParam, lParam ); } } } break; } break; // // Forward to listbox. // case LB_GETCURSEL: case LB_SETCURSEL: case LB_FINDSTRING: case LB_GETITEMDATA: case LB_RESETCONTENT: case WM_CHAR: case WM_GETDLGCODE: case WM_KILLFOCUS: return SendMessage( ClbInfo->hWndListBox, message, wParam, lParam ); case WM_SETFOCUS: { SetFocus( ClbInfo->hWndListBox ); return 0; } case WM_COMPAREITEM: { // // This message comes to ClbWndProc because it is the parent // of the list box, but is really intended for the parent // of the Clb. // HWND hWndParent; // // Forward the message to the Clb's parent if it has a parent. // hWndParent = GetParent( hWnd ); DbgHandleAssert( hWndParent ); if( hWndParent != NULL ) { int ControlId; LPCOMPAREITEMSTRUCT lpcis; lpcis = ( LPCOMPAREITEMSTRUCT ) lParam; ControlId = GetDlgCtrlID( hWnd ); DbgAssert( ControlId != 0 ); // // Modify the COMPAREITEMSTRUCT so that it refers to the Clb. // lpcis->CtlID = ControlId; lpcis->hwndItem = hWnd; // // Forward the message... // return SendMessage( hWndParent, message, ( WPARAM ) ControlId, lParam ); } break; } case WM_DELETEITEM: { LPDELETEITEMSTRUCT lpditms; LPCLB_ROW ClbRow; DWORD i; DbgAssert( wParam == ID_LISTBOX ); // // Retrieve the pointer to the DELETEITEMSTRUCT. // lpditms = ( LPDELETEITEMSTRUCT ) lParam; DbgAssert(( lpditms->CtlType == ODT_LISTBOX ) &&( lpditms->CtlID == ID_LISTBOX )); // // If there is no data, just return. // if( lpditms->itemData == 0 ) { return TRUE; } // // Retrieve the CLB_ROW object for this row. // ClbRow = ( LPCLB_ROW ) lpditms->itemData; // // For each column delete the string. // for( i = 0; i < ClbInfo->Columns; i++ ) { // // Strings were copied with _tcsdup so they must be // freed with free( ). // free( ClbRow->Strings[ i ].String ); } // // Free the CLB_STRING object. // Success = FreeObject( ClbRow->Strings ); DbgAssert( Success ); // // Free the CLB_ROW object. // Success = FreeObject( ClbRow ); DbgAssert( Success ); return TRUE; } case WM_DRAWITEM: { LPDRAWITEMSTRUCT lpdis; BOOL DrawFocus; DbgAssert( wParam == ID_LISTBOX ); // // Retrieve the pointer to the DRAWITEMSTRUCT. // lpdis = ( LPDRAWITEMSTRUCT ) lParam; DbgAssert(( lpdis->CtlType == ODT_LISTBOX ) &&( lpdis->CtlID == ID_LISTBOX )); // // If there is no data, just return. // if( lpdis->itemData == 0 ) { return TRUE; } if( lpdis->itemAction & ( ODA_DRAWENTIRE | ODA_SELECT )) { DWORD i; LPCLB_ROW ClbRow; COLORREF TextColor; COLORREF BkColor; // // Retrieve the CLB_ROW object for this row. // ClbRow = ( LPCLB_ROW ) lpdis->itemData; // // If the item is selected, set the selection colors. // if( lpdis->itemState & ODS_SELECTED ) { BkColor = COLOR_HIGHLIGHT; TextColor = COLOR_HIGHLIGHTTEXT; } else { BkColor = COLOR_WINDOW; TextColor = COLOR_WINDOWTEXT; } BkColor = GetSysColor( BkColor ); TextColor = GetSysColor( TextColor ); BkColor = SetBkColor( lpdis->hDC, BkColor ); DbgAssert( BkColor != CLR_INVALID ); TextColor = SetTextColor( lpdis->hDC, TextColor ); DbgAssert( TextColor != CLR_INVALID ); // // For each column display the text. // for( i = 0; i < ClbInfo->Columns; i++ ) { RECT ClipOpaqueRect; int x; int Left; UINT GdiErr; // // Depending on the format, adjust the alignment reference // point (x) and the clipping rectangles left edge so that // there are five pixels between each column. // switch( ClbRow->Strings[ i ].Format ) { case CLB_LEFT: if( i == 0 ) { x = 2; } else { x = ClbInfo->Right[ i - 1 ] + 2; } Left = x - 2; break; case CLB_RIGHT: if( i == 0 ) { Left = 0; } else { Left = ClbInfo->Right[ i - 1 ]; } x = ClbInfo->Right[ i ] - 3; break; default: DbgAssert( FALSE ); } // // Set the format for this column. // GdiErr = SetTextAlign( lpdis->hDC, ClbRow->Strings[ i ].Format | TA_TOP ); DbgAssert( GdiErr != GDI_ERROR ); // // Clip each string to its column width less two pixels // (for asthetics). // Success = SetRect( &ClipOpaqueRect, Left, lpdis->rcItem.top, ClbInfo->Right[ i ], lpdis->rcItem.bottom ); DbgAssert( Success ); Success = ExtTextOut( lpdis->hDC, x, lpdis->rcItem.top, ETO_CLIPPED | ETO_OPAQUE, &ClipOpaqueRect, ClbRow->Strings[ i ].String, ClbRow->Strings[ i ].Length, NULL ); DbgAssert( Success ); // // If the item has the focus, draw the focus rectangle. // DrawFocus = lpdis->itemState & ODS_FOCUS; } } else { // // If the Clb has the focus, display a focus rectangle // around the selected item. // DrawFocus = lpdis->itemAction & ODA_FOCUS; } // // If needed, toggle the focus rectangle. // if( DrawFocus ) { Success = DrawFocusRect( lpdis->hDC, &lpdis->rcItem ); DbgAssert( Success ); } return TRUE; } case WM_NOTIFY: { HD_NOTIFY * lpNot; HD_ITEM *pHDI; lpNot = (HD_NOTIFY *)lParam; pHDI = lpNot->pitem; switch( lpNot->hdr.code) { static DRAW_ERASE_LINE DrawEraseLine; static HPEN hPen; static HDC hDCClientListBox; HD_ITEM hdi; UINT iRight; UINT i; RECT ClientRectHeader; case HDN_BEGINTRACK: { RECT ClientRectListBox; // // Get thd HDC for the list box. // hDCClientListBox = GetDC( ClbInfo->hWndListBox ); DbgHandleAssert( hDCClientListBox ); // // Create the pen used to display the drag position and // select it into the in list box client area DC. Also set // the ROP2 code so that drawing with the pen twice in the // same place will erase it. This is what allows the // line to drag. // hPen = CreatePen( PS_DOT, 1, RGB( 255, 255, 255 )); DbgHandleAssert( hPen ); hPen = SelectObject( hDCClientListBox, hPen ); SetROP2( hDCClientListBox, R2_XORPEN ); // // Set up the DRAW_ERASE_LINE structure so that the drag line is // drawn from the top to the bottom of the list box at the // current drag position. // Success = GetClientRect( ClbInfo->hWndListBox, &ClientRectListBox ); DbgAssert( Success ); // // Draw the initial drag line from the top to the bottom // of the list box equivalent with the header edge grabbed // by the user. // DrawEraseLine.Draw.Src.x = ClbInfo->Right[ pHDI->cxy ]; DrawEraseLine.Draw.Src.y = 0; DrawEraseLine.Draw.Dst.x = ClbInfo->Right[ pHDI->cxy ]; DrawEraseLine.Draw.Dst.y = ClientRectListBox.bottom - ClientRectListBox.top; Success = DrawLine( hDCClientListBox, &DrawEraseLine ); DbgAssert( Success ); return 0; } case HDN_TRACK: { //DWORD Columns; // // Get new drag position. // iRight = 0; hdi.mask = HDI_WIDTH; for( i = 0; i < ClbInfo->Columns - 1; i++ ) { if (i != (UINT)lpNot->iItem) { Header_GetItem(ClbInfo->hWndHeader, i, &hdi); } else { hdi.cxy = pHDI->cxy; } iRight += hdi.cxy; ClbInfo->Right[i] = iRight; } GetClientRect( ClbInfo->hWndHeader, &ClientRectHeader ); ClbInfo->Right[i] = ClientRectHeader.right; // // Erase the old line and draw the new one at the new // drag position. // Success = RedrawVerticalLine( hDCClientListBox, ClbInfo->Right[lpNot->iItem], &DrawEraseLine ); DbgAssert( Success ); return 0; } case HDN_ENDTRACK: // // Replace the old pen and delete the one created // during HBN_BEGINDRAG. // hPen = SelectObject( hDCClientListBox, hPen ); Success = DeleteObject( hPen ); DbgAssert( Success ); // // Release the DC for the list box. // Success = ReleaseDC( ClbInfo->hWndListBox, hDCClientListBox ); DbgAssert( Success ); Success = RedrawWindow( hWnd, NULL, NULL, RDW_ERASE | RDW_INVALIDATE | RDW_UPDATENOW | RDW_ALLCHILDREN ); DbgAssert( Success ); return 0; } break; } case WM_SETTEXT: // // Adjust the column number and widths based on the heading text. // Success = AdjustClbHeadings( hWnd, ClbInfo, ( LPCWSTR ) lParam ); DbgAssert( Success ); return Success; case WM_SIZE: { HDWP hDWP; LONG Width; LONG Height; LONG Style; LONG VScrollWidth; Width = LOWORD( lParam ); Height = HIWORD( lParam ); hDWP = BeginDeferWindowPos( 2 ); DbgHandleAssert( hDWP ); // // Retrieve the list box's styles. // Style = GetWindowLong( ClbInfo->hWndListBox, GWL_STYLE ); // // If the list box has a vertical scroll bar compute its // width so that the header window's width can be adjusted // appropriately. // VScrollWidth = ( Style & WS_VSCROLL ) ? GetSystemMetrics( SM_CXVSCROLL ) + ( GetSystemMetrics( SM_CXBORDER ) * 2 ) : 0; // // Size the header window to the width of the Clb and its // default / original height. // hDWP = DeferWindowPos( hDWP, ClbInfo->hWndHeader, NULL, 0, 0, Width - VScrollWidth, ClbInfo->HeaderHeight, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER ); DbgHandleAssert( hDWP ); // // If the list box has a vertical scroll bar, bump the width // and height by two so that its border overwrites the Clb // border. This eliminates a double border (and a gap) between // the right and bottom edges of the scroll bar and the Clb. // if( Style & WS_VSCROLL ) { Height += 2; Width += 2; } // // Size the list box so that it is the size of the Clb less // the height of the header window less the height of the // border. // hDWP = DeferWindowPos( hDWP, ClbInfo->hWndListBox, NULL, 0, 0, Width, Height - ClbInfo->HeaderHeight - 3, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER ); DbgHandleAssert( hDWP ); Success = EndDeferWindowPos( hDWP ); DbgAssert( Success ); break; } } } return DefWindowProc( hWnd, message, wParam, lParam ); }
BOOL MemoryResourceProc( LPSYSTEM_RESOURCES MemoryObject,int Translation) /*++ Routine Description: MemoryResourceProc supports the display of memory resources for each device/driver in the system. Arguments: Standard PROC entry. Return Value: BOOL - Depending on input message and processing options. --*/ { BOOL Success; static LPSYSTEM_RESOURCES SystemResourceLists; LPCOMPAREITEMSTRUCT lpcis; LPRESOURCE_DESCRIPTOR ResourceDescriptor; TCHAR StartBuffer[ MAX_PATH ]; TCHAR LengthBuffer[ MAX_PATH ]; // // Retrieve and validate the system resource lists. // SystemResourceLists = ( LPSYSTEM_RESOURCES ) MemoryObject; DbgPointerAssert( SystemResourceLists ); DbgAssert( CheckSignature( SystemResourceLists )); if( ( ! SystemResourceLists ) || ( ! CheckSignature( SystemResourceLists ))) { return FALSE; } lpcis = ( LPCOMPAREITEMSTRUCT ) MemoryObject; ResourceDescriptor = SystemResourceLists[ Translation ].MemoryHead; DbgPointerAssert( ResourceDescriptor ); DbgAssert( CheckSignature( ResourceDescriptor )); if( ( ! ResourceDescriptor ) || ( ! CheckSignature( ResourceDescriptor ))) { return FALSE; } // // Initialize the constants in the CLB_ROW object. // // // Walk the resource descriptor list, formatting the appropriate // values and adding the CLB_ROW to the Clb. // while( ResourceDescriptor ) { DbgAssert( ResourceDescriptor->CmResourceDescriptor.Type == CmResourceTypeMemory ); PrintHexToFile((DWORD) &ResourceDescriptor->CmResourceDescriptor.u.Memory.Start,IDC_MEMORY_START); //( LPVOID ) PrintDwordToFile(ResourceDescriptor->CmResourceDescriptor.u.Memory.Length,IDC_MEMORY_LENGTH); PrintToFile((LPCTSTR) ResourceDescriptor->Owner->Name,IDC_MEMORY_NAME,TRUE); PrintToFile((LPCTSTR)TEXT("\n"),IDC_SPACE,TRUE); // // Get the next resource descriptor. // ResourceDescriptor = ResourceDescriptor->NextSame; } return TRUE; }