/** * Rewinds the iterator to the first value. */ public function rewind() { // reset pointer and count $this->pointer = 0; $this->count = 0; // create empty variants to store out params $this->valueNames = new \VARIANT(); $this->valueTypes = new \VARIANT(); // attempt to enumerate values $errorCode = $this->handle->enumValues($this->registryKey->getHive(), $this->registryKey->getQualifiedName(), $this->valueNames, $this->valueTypes); // make sure the enum isn't empty if ($errorCode === 0 && variant_get_type($this->valueNames) & VT_ARRAY && variant_get_type($this->valueTypes) & VT_ARRAY) { // store the number of values $this->count = count($this->valueNames); } }
function Win32RegistryIterator(COM $o_Win32Registry, $i_HiveKey, $s_RootKey) { static $i_Depth = -1; static $a_RegTypes = array(1 => 'REG_SZ (1)', 2 => 'REG_EXPAND_SZ (2)', 3 => 'REG_BINARY (3)', 4 => 'REG_DWORD (4)', 7 => 'REG_MULTI_SZ (7)', 10 => 'REG_RESOURCE_REQUIREMENT_LIST (10)'); $a_Keys = new VARIANT(); $a_Names = new VARIANT(); $a_Types = new VARIANT(); $i_EnumKeyState = $o_Win32Registry->EnumKey($i_HiveKey, $s_RootKey, $a_Keys); $i_EnumValuesState = $o_Win32Registry->EnumValues($i_HiveKey, $s_RootKey, $a_Names, $a_Types); if (VT_NULL !== variant_get_type($a_Keys)) { foreach ($a_Keys as $i_Key => $s_Key) { echo '[', $s_Key, ']', PHP_EOL; Win32RegistryIterator($o_Win32Registry, $i_HiveKey, $s_RootKey . '\\' . $s_Key); } } if (VT_NULL !== variant_get_type($a_Names)) { $a_ExtractedTypes = array(); foreach ($a_Types as $i_Type) { $a_ExtractedTypes[] = $i_Type; } foreach ($a_Names as $i_Name => $s_Name) { $m_RegValue = new VARIANT(); echo $i_Name, ' => ', '' === $s_Name ? '(Default)' : $s_Name, ' of type ', $a_RegTypes[$a_ExtractedTypes[$i_Name]], ' with a value of '; switch ($a_ExtractedTypes[$i_Name]) { case 1: // REG_SZ $o_Win32Registry->GetStringValue($i_HiveKey, $s_RootKey, $s_Name, $m_RegValue); echo '"', $m_RegValue, '"'; break; case 2: // REG_EXPAND_SZ $o_Win32Registry->GetExpandedStringValue($i_HiveKey, $s_RootKey, $s_Name, $m_RegValue); echo '"', $m_RegValue, '"'; break; case 3: // REG_BINARY // REG_BINARY case 10: // REG_RESOURCE_REQUIREMENT_LIST $o_Win32Registry->GetBinaryValue($i_HiveKey, $s_RootKey, $s_Name, $m_RegValue); if (VT_NULL !== variant_get_type($m_RegValue)) { foreach ($m_RegValue as $i_RegValue) { echo str_pad(dechex($i_RegValue), 2, '0', STR_PAD_LEFT), ' '; } } break; case 4: // REG_DWORD $o_Win32Registry->GetDWORDValue($i_HiveKey, $s_RootKey, $s_Name, $m_RegValue); echo '0x', str_pad(dechex($m_RegValue), 8, '0', STR_PAD_LEFT), ' (', $m_RegValue, ')'; break; case 7: // REG_MUTLI_SZ $o_Win32Registry->GetMultiStringValue($i_HiveKey, $s_RootKey, $s_Name, $m_RegValue); if (VT_NULL !== variant_get_type($m_RegValue)) { try { foreach ($m_RegValue as $s_RegValue) { echo PHP_EOL, $s_RegValue; } } catch (com_exception $e) { // As yet, I cannot determine if the $m_RegValue is empty for a REG_MULTI_SZ, // so catch the exception and test that instead. if (-2147352565 !== $e->getCode()) { throw $e; } } } break; } echo PHP_EOL; } } }
public function EnumValues($root, $keypath = "", $value_names_only = true) { $keypath = self::NormalizeKey($keypath); $values = new \VARIANT(); $value_types = new \VARIANT(); $status = $this->WmiInstance->EnumValues($root, $keypath, $values, $value_types); $this->SetLastError($status); if (variant_get_type($values) == VT_NULL) { return array(); } else { $found_values = array(); $found_types = array(); foreach ($values as $value) { $found_values[] = $value; } if ($value_names_only) { $result = $found_values; } else { foreach ($value_types as $value_type) { $found_types[] = $value_type; } $result = array_combine($found_values, $found_types); } return $result; } }
private function EnumValues($hKeyId, $subKey, &$valueList) { $valueNames = new VARIANT(); $valueTypes = new VARIANT(); if ($this->RegistryObject->EnumValues($hKeyId, $subKey, $valueNames, $valueTypes) != 0) { return FALSE; } $valueList = array(); if (variant_get_type($valueNames) == (VT_VARIANT | VT_ARRAY)) { for ($i = 0, $cnt = count($valueNames); $i < $cnt; $i++) { $valueList[] = array(strval($valueNames[$i]), intval($valueTypes[$i])); } } else { if ($this->GetStringValue($hKeyId, $subKey, '') != NULL) { $valueList[] = array('', self::REG_SZ); } else { if ($this->GetDWORDValue($hKeyId, $subKey, '') != NULL) { $valueList[] = array('', self::REG_DWORD); } else { if ($this->GetExpandedStringValue($hKeyId, $subKey, '') != NULL) { $valueList[] = array('', self::REG_EXPAND_SZ); } else { if ($this->GetBinaryValue($hKeyId, $subKey, '') != NULL) { $valueList[] = array('', self::REG_BINARY); } else { if ($this->GetMultiStringValue($hKeyId, $subKey, '') != NULL) { $valueList[] = array('', self::REG_MULTI_SZ); } } } } } } return TRUE; }
/** * Rewinds the iterator to the first key. */ public function rewind() { // reset pointer and count $this->pointer = 0; $this->count = 0; // create an empty variant to store subkey names $this->subKeyNames = new \VARIANT(); // attempt to enumerate subkeys $errorCode = $this->handle->enumKey($this->registryKey->getHive(), $this->registryKey->getQualifiedName(), $this->subKeyNames); // make sure the enum isn't empty if ($errorCode === 0 && variant_get_type($this->subKeyNames) & VT_ARRAY) { // store the number of subkeys $this->count = count($this->subKeyNames); } }
$name_spaces[$objClass->Path_->Class] = array(); // }; } } uksort($name_spaces, 'strnatcasecmp'); echo "<WMI_Output>\r\n"; foreach ($name_spaces as $class => $value) { echo " <Namespace Name=\"" . $class . "\">\r\n"; $obj = new COM('winmgmts://' . STR_COMPUTER . '\\root\\SecurityCenter' . ':' . $class); foreach ($obj->Properties_() as $objClassProperty) { echo " <Property Name=\"" . $objClassProperty->Name . "\">\r\n"; if ($objClassProperty->IsArray == true) { echo " <Qualifier Name=\"IsArray\">true</Qualifier>\r\n"; } foreach ($objClassProperty->Qualifiers_ as $objClassPropQual) { if (@variant_get_type($objClassPropQual->Value) == VT_VARIANT + VT_ARRAY) { echo " <Qualifier Name=\"" . $objClassPropQual->Name . "\">"; $objClassPropQualVal = ""; foreach ($objClassPropQual->Value as $value) { $objClassPropQualVal .= $value . ", "; } echo substr($objClassPropQualVal, 0, -2) . "</Qualifier>\r\n"; } else { echo " <Qualifier Name=\"" . $objClassPropQual->Name . "\">" . $objClassPropQual->Value . "</Qualifier>\r\n"; } } echo " </Property>\r\n"; } echo " </Namespace>\r\n"; } echo "</WMI_Output>";
/** * Helper. Recursively goes through the properties * of a VARIANT object $o of class $classname. * $islist should be TRUE if $o is a collection/list * and provides `Count` and Item() * * @return array of properties */ function populate($o, $classname, $islist = false) { if (!is_array($this->api)) { return false; } $count = $islist ? $o->Count : 1; $populateme = array(); for ($i = 0; $i < $count; $i++) { $item = $islist ? $o->Item($i) : $o; $populateme[$i] = array(); foreach ($this->api[$classname] as $prop => $value) { // skip restricted properties in the basic (free) HTTPWatch edition if ($classname === 'Entry') { if ($item->isRestrictedURL && $this->paidproperties[$prop]) { continue; } } else { if ($this->hasRestrictions() && $this->paidproperties[$prop]) { continue; } } if (is_array($value)) { $populateme[$i][$prop] = $this->populate($item->{$prop}, $value[0], true); } else { if (is_string($value)) { $populateme[$i][$prop] = $this->populate($item->{$prop}, $value, false); } else { if ($value === 1) { $val = $item->{$prop}; if (gettype($val) === "object") { $type = variant_get_type($val); if ($type === 8209) { $val = $this->getStream($val); } if ($type === VT_DATE) { $val = variant_date_to_timestamp($val); } } $populateme[$i][$prop] = $val; } } } } } return $islist ? $populateme : $populateme[0]; }
private function GetValueType($hKey, $subKey, $valueName) { $valueType = -1; $valueNames = new VARIANT(); $valueTypes = new VARIANT(); $result = -1; $result = $this->RegObject->EnumValues($hKey, $subKey, $valueNames, $valueTypes); if ($result != 0) { return $valueType; } if (variant_get_type($valueNames) == (VT_VARIANT | VT_ARRAY)) { foreach ($valueNames as $index => $_valueName) { if ($_valueName == $valueName) { $valueType = intval($valueTypes[$index]); } } } return $valueType; }
/** * Gets the value data of a named key value. * * @param string $name The name of the value. * @param int $type The value type of the value. * * @return mixed The value data of the value. */ public function getValue($name, $type = null) { // create a variant to store the key value data $valueData = new \VARIANT(); // auto detect type // not recommended - see getValueType() for details if (!$type) { $type = $this->getValueType($name); } $normalizedValue = null; $errorCode = 0; // get the value data type switch ($type) { // string type case self::TYPE_SZ: // get the data of the value $errorCode = $this->handle->getStringValue($this->hive, $this->name, $name, $valueData); $normalizedValue = (string) $valueData; break; // expanded string type // expanded string type case self::TYPE_EXPAND_SZ: // get the data of the value $errorCode = $this->handle->getExpandedStringValue($this->hive, $this->name, $name, $valueData); $normalizedValue = (string) $valueData; break; // binary type // binary type case self::TYPE_BINARY: // get the data of the value $errorCode = $this->handle->getBinaryValue($this->hive, $this->name, $name, $valueData); $binaryString = ''; // enumerate over each byte if (variant_get_type($valueData) & VT_ARRAY) { foreach ($valueData as $byte) { // add the byte code to the byte string $binaryString .= chr((int) $byte); } } $normalizedValue = $binaryString; break; // int type // int type case self::TYPE_DWORD: // get the data of the value $errorCode = $this->handle->getDWORDValue($this->hive, $this->name, $name, $valueData); $normalizedValue = (int) $valueData; break; // big-int type // big-int type case self::TYPE_QWORD: // get the data of the value $errorCode = $this->handle->getQWORDValue($this->hive, $this->name, $name, $valueData); $normalizedValue = (string) $valueData; break; // string array type // string array type case self::TYPE_MULTI_SZ: // get the data of the value $errorCode = $this->handle->getMultiStringValue($this->hive, $this->name, $name, $valueData); $stringArray = array(); // enumerate over each sub string if (variant_get_type($valueData) & VT_ARRAY) { foreach ($valueData as $subValueData) { $stringArray[] = (string) $subValueData; } } $normalizedValue = $stringArray; break; } // check for successful read if ($errorCode !== 0) { throw new OperationFailedException("Failed to read value \"{$name}\"."); } return $normalizedValue; }
function Win32RegistryIterator(COM $o_Win32Registry, $i_HiveKey, $s_RootKey) { static $i_Depth = -1; static $a_RegTypes = array(1 => 'REG_SZ (1)', 2 => 'REG_EXPAND_SZ (2)', 3 => 'REG_BINARY (3)', 4 => 'REG_DWORD (4)', 7 => 'REG_MULTI_SZ (7)', 10 => 'REG_RESOURCE_REQUIREMENT_LIST (10)'); $return = array(); $a_Keys = new VARIANT(); $a_Names = new VARIANT(); $a_Types = new VARIANT(); $i_EnumKeyState = $o_Win32Registry->EnumKey($i_HiveKey, $s_RootKey, $a_Keys); $i_EnumValuesState = $o_Win32Registry->EnumValues($i_HiveKey, $s_RootKey, $a_Names, $a_Types); if (VT_NULL !== variant_get_type($a_Keys)) { foreach ($a_Keys as $i_Key => $s_Key) { $return[$s_Key] = Win32RegistryIterator($o_Win32Registry, $i_HiveKey, $s_RootKey . '\\' . $s_Key); } } if (VT_NULL !== variant_get_type($a_Names)) { $a_ExtractedTypes = array(); foreach ($a_Types as $i_Type) { $a_ExtractedTypes[] = $i_Type; } foreach ($a_Names as $i_Name => $s_Name) { $m_RegValue = new VARIANT(); switch ($a_ExtractedTypes[$i_Name]) { case 1: // REG_SZ $o_Win32Registry->GetStringValue($i_HiveKey, $s_RootKey, $s_Name, $m_RegValue); break; case 2: // REG_EXPAND_SZ $o_Win32Registry->GetExpandedStringValue($i_HiveKey, $s_RootKey, $s_Name, $m_RegValue); break; case 3: // REG_BINARY // REG_BINARY case 10: // REG_RESOURCE_REQUIREMENT_LIST $o_Win32Registry->GetBinaryValue($i_HiveKey, $s_RootKey, $s_Name, $m_RegValue); if (VT_NULL !== variant_get_type($m_RegValue)) { $tempval = ""; foreach ($m_RegValue as $i_RegValue) { $tempval .= str_pad(dechex($i_RegValue), 2, '0', STR_PAD_LEFT) . ' '; } $m_RegValue = $tempval; } break; case 4: // REG_DWORD $o_Win32Registry->GetDWORDValue($i_HiveKey, $s_RootKey, $s_Name, $m_RegValue); $m_RegValue = '0x' . str_pad(dechex($m_RegValue), 8, '0', STR_PAD_LEFT) . ' (' . $m_RegValue . ')'; break; case 7: // REG_MUTLI_SZ $o_Win32Registry->GetMultiStringValue($i_HiveKey, $s_RootKey, $s_Name, $m_RegValue); if (VT_NULL !== variant_get_type($m_RegValue)) { try { $tempval = ""; foreach ($m_RegValue as $s_RegValue) { $tempval .= $s_RegValue; } $m_RegValue = $tempval; } catch (com_exception $e) { // As yet, I cannot determine if the $m_RegValue is empty for a REG_MULTI_SZ, // so catch the exception and test that instead. if (-2147352565 !== $e->getCode()) { throw $e; } } } break; } if ('' === $s_Name) { $key = '(Default)'; } else { $key = $s_Name; } $return[$key] = array('type' => $a_RegTypes[$a_ExtractedTypes[$i_Name]], 'value' => (string) $m_RegValue); } } return $return; }