コード例 #1
0
        public ResourceListDialog(object valueInfo, bool IsAdd)
            : this()
        {
            Logger.Log("ResourceListDialog, Inside Constructor", Logger.RegistryViewerLoglevel);

            if (valueInfo is SubKeyValueInfo)
                this.ValueInfo = valueInfo as SubKeyValueInfo;
            else
                this.regValueInfo = valueInfo as RegistryValueInfo;

            SetInputData();
        }
コード例 #2
0
        public DWORDValueEditorDialog(object valueInfo, bool bIsAdd)
            : this()
        {
            if (valueInfo is SubKeyValueInfo)
                this.ValueInfo = valueInfo as SubKeyValueInfo;
            else
                this.regValueInfo = valueInfo as RegistryValueInfo;

            this.txtValuename.ReadOnly = !bIsAdd;
            this.bIsAdd = bIsAdd;

            SetInputData();
        }
コード例 #3
0
        public StringEditorDialog(object valueInfo, bool IsAdd)
            : this()
        {
            if (valueInfo is SubKeyValueInfo)
                this.ValueInfo = valueInfo as SubKeyValueInfo;
            else
                this.regValueInfo = valueInfo as RegistryValueInfo;

            this.txtValueName.ReadOnly = !IsAdd;
            this.bIsAdd = IsAdd;

            SetInputData();
        }
コード例 #4
0
        public MultiStringValueEditorDialog(object valueInfo, bool IsAdd, RegistryViewerPlugin _plugin)
            : this()
        {
            if (valueInfo is SubKeyValueInfo)
                this.ValueInfo = valueInfo as SubKeyValueInfo;
            else
                this.regValueInfo = valueInfo as RegistryValueInfo;

            this.txtValuename.ReadOnly = !IsAdd;
            this.bIsAdd = IsAdd;
            this.plugin = _plugin;

            SetInputData();
        }
コード例 #5
0
        public static void GetValueKind(RegistryValueInfo valueInfo, string sType)
        {
            string[] splits = sType.Split(':');
            switch (splits[0])
            {
            case "hex":
                valueInfo.pType = (ulong)RegistryApi.REG_BINARY;
                break;

            case "dword":
                valueInfo.pType = (ulong)RegistryApi.REG_DWORD;
                break;

            case "qword":
                valueInfo.pType = (ulong)LWRegistryValueKind.REG_QUADWORD;
                break;

            case "":
                valueInfo.pType = (ulong)RegistryApi.REG_SZ;
                break;

            case "hex(7)":
                valueInfo.pType = (ulong)RegistryApi.REG_MULTI_SZ;
                break;

            case "hex(2)":
                valueInfo.pType = (ulong)RegistryApi.REG_EXPAND_SZ;
                break;

            case "hex(8)":
                valueInfo.pType = (ulong)RegistryApi.REG_RESOURCE_LIST;
                break;

            case "hex(9)":
                valueInfo.pType = (ulong)RegistryApi.REG_RESOURCE_REQUIREMENTS_LIST;
                break;

            default:
                valueInfo.pType = (ulong)RegistryApi.REG_SZ;
                break;
            }
        }
コード例 #6
0
        public static object GetFormatSpecificData(RegistryValueInfo valueInfo)
        {
            object sData = null;

            switch (valueInfo.pType)
            {
                case (ulong)RegistryApi.REG_BINARY:
                case (ulong)RegistryApi.REG_RESOURCE_LIST:
                case (ulong)RegistryApi.REG_UNKNOWN:
                case (ulong)RegistryApi.REG_FULL_RESOURCE_DESCRIPTOR:
                case (ulong)RegistryApi.REG_RESOURCE_REQUIREMENTS_LIST:
                    byte[] byts = valueInfo.bDataBuf as byte[];
                    Array.Resize<byte>(ref byts, (int)valueInfo.pcData);
                    sData = GetBinaryData(byts);
                    break;

                case (ulong)RegistryApi.REG_EXPAND_SZ:
                    string sTemp = new UnicodeEncoding().GetString(valueInfo.bDataBuf as byte[]);
                    byte[] eByts = new UnicodeEncoding().GetBytes(sTemp + "\n");
                    List<byte> bytList = new List<byte>();
                    foreach (byte byt in eByts)
                    {
                        if (byt == 10 || byt == 13)
                            bytList.Add((byte)00);
                        else
                        {
                            bytList.Add(byt);
                            bytList.Add((byte)00);
                        }
                    }
                    eByts = new byte[bytList.Count];
                    bytList.CopyTo(eByts);
                    sData = GetBinaryData(eByts);
                    break;

                case (ulong)RegistryApi.REG_MULTI_SZ:
                    string[] sArry = new UnicodeEncoding().GetString(valueInfo.bDataBuf as byte[]).Split('\n');
                    StringBuilder sTempArry = new StringBuilder();
                    List<byte> mBytList = new List<byte>();
                    foreach (string value in sArry)
                    {
                        sTempArry.Append(value);
                        sTempArry.Append("\r\n");
                    }
                    byte[] mByts = new UnicodeEncoding().GetBytes(sTempArry.ToString());
                    foreach (byte byt in mByts)
                    {
                        if (byt == 10 || byt == 13)
                            mBytList.Add((byte)00);
                        else
                        {
                            mBytList.Add(byt);
                            mBytList.Add((byte)00);
                        }
                    }
                    mByts = new byte[mBytList.Count];
                    mBytList.CopyTo(mByts);
                    sData = GetBinaryData(mByts);
                    break;

                case (ulong)RegistryApi.REG_DWORD:
                    sData = String.Format("{0:X2}", BitConverter.ToUInt32(valueInfo.bDataBuf as byte[], 0)).PadLeft(8, '0');
                    break;

                case (ulong)RegistryApi.REG_PLAIN_TEXT:
                case (ulong)RegistryApi.REG_SZ:
                    sData = new UnicodeEncoding().GetString(valueInfo.bDataBuf as byte[]);
                    sData = string.Concat("\"", sData, "\"");
                    break;

                case (ulong)RegistryApi.REG_QWORD:
                    //sData = RegistryUtils.DecimalToBase(Convert.ToInt32(new ASCIIEncoding().GetString(valueInfo.bDataBuf as byte[])), 16).PadLeft(16, '0');
                    sData = String.Format("{0:X2}", BitConverter.ToUInt64(valueInfo.bDataBuf as byte[], 0)).PadLeft(16, '0');
                    sData = string.Concat("\"", sData, "\"");
                    break;

                default:
                    break;
            }
            return sData;
        }
コード例 #7
0
        public static void GetValueData(RegistryValueInfo valueInfo, string sData)
        {
            UnicodeEncoding encoder = new UnicodeEncoding();
            string[] splits = sData.Split(':');

            try
            {

                switch (valueInfo.pType)
                {
                    case (ulong)RegistryApi.REG_SZ:
                    case (ulong)RegistryApi.REG_EXPAND_SZ:
                    case (ulong)RegistryApi.REG_PLAIN_TEXT:
                        if (!String.IsNullOrEmpty(splits[0]))
                        {
                            byte[] sByts = encoder.GetBytes(splits[0].Substring(1));
                            Array.Resize<byte>(ref sByts, sByts.Length - 1);
                            valueInfo.bDataBuf = sByts;
                        }
                        else
                            valueInfo.bDataBuf = new byte[] { 0 };
                        break;

                    case (ulong)RegistryApi.REG_DWORD:
                        uint dValue = UInt32.Parse(splits[1], System.Globalization.NumberStyles.HexNumber);
                        byte[] dwDataArry = BitConverter.GetBytes(dValue);
                        valueInfo.bDataBuf = dwDataArry;
                        break;

                    case (ulong)RegistryApi.REG_QWORD:
                        ulong qValue = UInt64.Parse(splits[1], System.Globalization.NumberStyles.HexNumber);
                        byte[] qwDataArry = BitConverter.GetBytes(qValue);
                        valueInfo.bDataBuf = qwDataArry;
                        break;

                    case (ulong)RegistryApi.REG_MULTI_SZ:
                        string[] sDataArray = splits[2].Split(',');
                        List<byte> bytlist = new List<byte>();
                        for (int idx = 0; idx < sDataArray.Length; idx += 2)
                            bytlist.Add(Convert.ToByte(sDataArray[idx], 16));
                        byte[] mbyts = new byte[bytlist.Count];
                        bytlist.CopyTo(mbyts);
                        valueInfo.bDataBuf = encoder.GetString(mbyts).Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries);
                        RegistryInteropWrapper.RegModifyKeyValue(valueInfo, out mbyts);
                        valueInfo.bDataBuf = mbyts;
                        break;

                    default:
                        string[] sDataArry = splits[2].Split(',');
                        if (sDataArry != null)
                        {
                            byte[] byts = new byte[sDataArry.Length];
                            for (int idx = 0; idx < sDataArry.Length; idx++)
                            {
                                if (!String.IsNullOrEmpty(sDataArry[idx]))
                                    byts[idx] = Convert.ToByte(sDataArry[idx], 16);
                            }
                            valueInfo.bDataBuf = byts;
                        }
                        break;
                }
            }
            catch (Exception ex)
            {
                Logger.LogException("GetValueData() for the value " + valueInfo.pValueName, ex);
            }
        }
コード例 #8
0
        public static void GetValueKind(RegistryValueInfo valueInfo, string sType)
        {
            string[] splits = sType.Split(':');
            switch (splits[0])
            {
                case "hex":
                    valueInfo.pType = (ulong)RegistryApi.REG_BINARY;
                    break;

                case "dword":
                    valueInfo.pType = (ulong)RegistryApi.REG_DWORD;
                    break;

                case "qword":
                    valueInfo.pType = (ulong)LWRegistryValueKind.REG_QUADWORD;
                    break;

                case "":
                    valueInfo.pType = (ulong)RegistryApi.REG_SZ;
                    break;

                case "hex(7)":
                    valueInfo.pType = (ulong)RegistryApi.REG_MULTI_SZ;
                    break;

                case "hex(2)":
                    valueInfo.pType = (ulong)RegistryApi.REG_EXPAND_SZ;
                    break;

                case "hex(8)":
                    valueInfo.pType = (ulong)RegistryApi.REG_RESOURCE_LIST;
                    break;

                case "hex(9)":
                    valueInfo.pType = (ulong)RegistryApi.REG_RESOURCE_REQUIREMENTS_LIST;
                    break;

                default:
                    valueInfo.pType = (ulong)RegistryApi.REG_SZ;
                    break;
            }
        }
コード例 #9
0
        public void On_MenuClick(object sender, EventArgs e)
        {
            MenuItem mi = sender as MenuItem;
            LACTreeNode node = mi.Tag as LACTreeNode;

            //Since both are having the different set up proreties each. made two seperate objects.
            //For windows supported registry
            SubKeyValueInfo valueInfo = null;
            SubKeyInfo keyInfo = null;

            //For linux supported registry
            RegistryEnumKeyInfo regKeyInfo = null;
            RegistryValueInfo regValueInfo = null;

            if (mi != null)
            {
				if(mi.Text.Trim().Equals("&Refresh"))
				{
					 treeNode.IsModified = true;
                     treeNode.sc.ShowControl(treeNode);
                     return;
				}
				else if(mi.Text.Trim().Equals("&Help"))
				{
                     ProcessStartInfo psi = new ProcessStartInfo();
                     psi.UseShellExecute = true;
                     psi.FileName = CommonResources.GetString("LAC_Help");
                     psi.Verb = "open";
                     psi.WindowStyle = ProcessWindowStyle.Normal;
                     Process.Start(psi);
                     return;
				}
				else
				{
	                if (Configurations.currentPlatform == LikewiseTargetPlatform.Windows)
	                {
	                    keyInfo = node == null ? null : node.Tag as SubKeyInfo;
	                    valueInfo = node == null ? mi.Tag as SubKeyValueInfo : null;
	                }
	                else
					{
		                regKeyInfo = node == null ? null : node.Tag as RegistryEnumKeyInfo;
		                regValueInfo = node == null ? mi.Tag as RegistryValueInfo : null;
                        node = node == null ? treeNode : node;

                        if(!treeNode.Text.Trim().Equals(Properties.Resources.HKEY_THIS_MACHINE, StringComparison.InvariantCultureIgnoreCase))
                        {
			                if (regKeyInfo != null)
			                {
			                    RegistryInteropWrapper.ApiRegOpenKeyExW(plugin.handle.Handle,
			                                           plugin.pRootHandle,
			                                           regKeyInfo.sKeyname,
			                                           out regKeyInfo.pKey);
		                    }
							else  if (regValueInfo != null)
		                    {
                                RegistryEnumKeyInfo subKeyInfo = treeNode.Tag as RegistryEnumKeyInfo;
		                        RegistryInteropWrapper.ApiRegOpenKeyExW(plugin.handle.Handle,
	                                               plugin.pRootHandle,
                                                   subKeyInfo.sKeyname,
	                                               out regValueInfo.pParentKey);
							}
						}
						else
						{
							if(regKeyInfo != null)
								regKeyInfo.pKey = plugin.pRootHandle;
							else if(regValueInfo != null)
								regValueInfo.pParentKey = plugin.pRootHandle;
						}
					}
				}

                switch (mi.Text.Trim())
                {
					//Modify
                    case "Modify":
                        if (Configurations.currentPlatform == LikewiseTargetPlatform.Windows)
                        {
                            valueInfo = mi.Tag is SubKeyValueInfo ? mi.Tag as SubKeyValueInfo : lvRegistryPage.SelectedItems[0].Tag as SubKeyValueInfo;
                            if (valueInfo != null)
                            {
                                DoEditorWork(valueInfo, false, (ulong)valueInfo.RegDataType);
                            }
                        }
                        else if (regValueInfo != null)
                        {
                            DoEditorWork(regValueInfo, false, regValueInfo.pType);
                        }

                        break;

                    //Modify Binary Data
                    case "Modify Binary Data":
                        valueInfo = mi.Tag is SubKeyValueInfo ? mi.Tag as SubKeyValueInfo : lvRegistryPage.SelectedItems[0].Tag as SubKeyValueInfo;
                        if (valueInfo != null)
                        {
                            SubKeyValueInfo tempValueInfo = new SubKeyValueInfo();
                            tempValueInfo.hKey = valueInfo.hKey;
                            tempValueInfo.RegDataType = LWRegistryValueKind.REG_BINARY;
                            tempValueInfo.sData = valueInfo.sData;
                            tempValueInfo.sDataBuf = valueInfo.sDataBuf;
                            tempValueInfo.sParentKey = valueInfo.sParentKey;
                            tempValueInfo.sValue = valueInfo.sValue;
                            DoEditorWork(tempValueInfo, false, (ulong)tempValueInfo.RegDataType);
                        }
                        else if (regValueInfo != null)
                            DoEditorWork(regValueInfo, false, (ulong)RegistryApi.REG_BINARY);
                        break;

                    //Delete
                    case "&Delete":
                        if (Configurations.currentPlatform == LikewiseTargetPlatform.Windows)
                        {
                            if (keyInfo != null) Do_DeleteKey(keyInfo, node);
                            else if (valueInfo != null) Do_DeleteKeyValue(valueInfo);
                        }
                        else
                        {
                            if (regKeyInfo != null) Do_DeleteKey(regKeyInfo, node);
                            else if (regValueInfo != null) Do_DeleteKeyValue(regValueInfo);
                        }
						break;

                    //Rename
                    case "&Rename":
                        if (Configurations.currentPlatform == LikewiseTargetPlatform.Windows)
                        {
                            if (keyInfo != null) Do_RenameKey(keyInfo, node);
                            else if (valueInfo != null) Do_RenameKeyValue(valueInfo, treeNode);
                        }
                        else
                        {
                            if (regKeyInfo != null) Do_RenameKey(regKeyInfo, node);
                            else if (regValueInfo != null) Do_RenameKeyValue(regValueInfo, treeNode);
                        }
						break;

                    //Key
                    case "Key":
                        if (Configurations.currentPlatform == LikewiseTargetPlatform.Windows)
                            Do_CreateKey(keyInfo, node);
                        else
                            Do_CreateKey(regKeyInfo, node);
                        break;

                    //&Import...
                    case "&Import...":
                        Do_ImportRegistry();
                        break;

                    //&Export...
                    case "&Export...":
                        Do_ExportRegistry();
                        break;

                    //String Value
                    case "String Value":
                        if (keyInfo != null)
                        {
                            valueInfo = new SubKeyValueInfo();
                            valueInfo.hKey = keyInfo.hKey;
                            valueInfo.IsDefaultValue = false;
                            valueInfo.RegDataType = LWRegistryValueKind.REG_SZ;
                            valueInfo.sParentKey = keyInfo.sSubKey;
                            DoEditorWork(valueInfo, true, (ulong)valueInfo.RegDataType);
                        }
                        else if (regKeyInfo != null)
                        {
                            regValueInfo = new RegistryValueInfo();
                            regValueInfo.pType = (ulong)RegistryApi.REG_SZ;
                            regValueInfo.pParentKey = regKeyInfo.pKey;
                            DoEditorWork(regValueInfo, true, regValueInfo.pType);
                        }
                        break;

                    //DWORD Value
                    case "DWORD Value":
                        if (keyInfo != null)
                        {
                            valueInfo = new SubKeyValueInfo();
                            valueInfo.hKey = keyInfo.hKey;
                            valueInfo.IsDefaultValue = false;
                            valueInfo.RegDataType = LWRegistryValueKind.REG_DWORD;
                            valueInfo.sParentKey = keyInfo.sSubKey;
                            DoEditorWork(valueInfo, true, (ulong)valueInfo.RegDataType);
                        }
                        else if (regKeyInfo != null)
                        {
                            regValueInfo = new RegistryValueInfo();
                            regValueInfo.pType = (ulong)RegistryApi.REG_DWORD;
                            regValueInfo.pParentKey = regKeyInfo.pKey;
                            DoEditorWork(regValueInfo, true, regValueInfo.pType);
                        }
                        break;

                    //Binary Value
                    case "Binary Value":
                        if (keyInfo != null)
                        {
                            valueInfo = new SubKeyValueInfo();
                            valueInfo.hKey = keyInfo.hKey;
                            valueInfo.IsDefaultValue = false;
                            valueInfo.RegDataType = LWRegistryValueKind.REG_BINARY;
                            valueInfo.sParentKey = keyInfo.sSubKey;
                            DoEditorWork(valueInfo, true, (ulong)valueInfo.RegDataType);
                        }
                        else if (regKeyInfo != null)
                        {
                            regValueInfo = new RegistryValueInfo();
                            regValueInfo.pType = (ulong)RegistryApi.REG_BINARY;
                            regValueInfo.pParentKey = regKeyInfo.pKey;
                            DoEditorWork(regValueInfo, true, regValueInfo.pType);
                        }
                        break;

                    //Multi-String Value
                    case "Multi-String Value":
                        if (keyInfo != null)
                        {
                            valueInfo = new SubKeyValueInfo();
                            valueInfo.hKey = keyInfo.hKey;
                            valueInfo.IsDefaultValue = false;
                            valueInfo.RegDataType = LWRegistryValueKind.REG_MULTI_SZ;
                            valueInfo.sParentKey = keyInfo.sSubKey;
                            DoEditorWork(valueInfo, true, (ulong)valueInfo.RegDataType);
                        }
                        else if (regKeyInfo != null)
                        {
                            regValueInfo = new RegistryValueInfo();
                            regValueInfo.pType = (ulong)RegistryApi.REG_MULTI_SZ;
                            regValueInfo.pParentKey = regKeyInfo.pKey;
                            DoEditorWork(regValueInfo, true, regValueInfo.pType);
                        }
                        break;

                    //Expandable String Value
                    case "Expandable String Value":
                        if (keyInfo != null)
                        {
                            valueInfo = new SubKeyValueInfo();
                            valueInfo.hKey = keyInfo.hKey;
                            valueInfo.IsDefaultValue = false;
                            valueInfo.RegDataType = LWRegistryValueKind.REG_EXPAND_SZ;
                            valueInfo.sParentKey = keyInfo.sSubKey;
                            DoEditorWork(valueInfo, true, (ulong)valueInfo.RegDataType);
                        }
                        else if (regKeyInfo != null)
                        {
                            regValueInfo = new RegistryValueInfo();
                            regValueInfo.pType = (ulong)RegistryApi.REG_EXPAND_SZ;
                            regValueInfo.pParentKey = regKeyInfo.pKey;
                            DoEditorWork(regValueInfo, true, regValueInfo.pType);
                        }
                        break;

                    default:
                        break;
                }
            }
        }
コード例 #10
0
        private void Do_RecursiveImportKey(StreamReader reader)
        {
            HKEY hKey = HKEY.HEKY_CURRENT_USER;
            RegistryKey sSubKey = null;
            List<LACTreeNode> KeyNodes = new List<LACTreeNode>();
            Hostinfo hn = ctx as Hostinfo;
            IntPtr pRootKey = IntPtr.Zero;
            LACTreeNode pluginNode = plugin.GetPlugInNode();

            if (pluginNode.Nodes.Count != 0 && Configurations.currentPlatform != LikewiseTargetPlatform.Windows)
            {
                Do_CloseRegKeyHandles(pluginNode.Nodes[1] as LACTreeNode);
                pluginNode.Nodes[1].Nodes.Clear();
            }

            while (!reader.EndOfStream)
            {
                string currentLine = reader.ReadLine();
                if (currentLine != null && currentLine.StartsWith("["))
                {
                    hKey = HKEY.HEKY_CURRENT_USER;
                    sSubKey = null;
                    LACTreeNode KeyNode = null;

                    string[] splits = currentLine.Split('\\');
                    if (splits != null && splits.Length != 0)
                    {
                        if (pRootKey != IntPtr.Zero)
                            RegistryInteropWrapper.ApiRegCloseKey(plugin.handle.Handle, pRootKey);

                        foreach (string sName in splits)
                        {
                            string sKeyName = sName.EndsWith("]") ? sName.Substring(0, sName.Length - 1) : sName;
                            sKeyName = sKeyName.StartsWith("[") ? sKeyName.Substring(1) : sKeyName;

                            //Check for the Win defined the HKEY
                            if (sName.StartsWith("["))
                            {
                                Icon ic = Properties.Resources.Reports;

                                if (Configurations.currentPlatform == LikewiseTargetPlatform.Windows)
                                {
                                    switch (sKeyName.Trim().ToUpper())
                                    {
                                        case "HKEY_CLASSES_ROOT":
                                            hKey = HKEY.HKEY_CLASSES_ROOT;
                                            KeyNode = Manage.CreateIconNode(Properties.Resources.HKEY_CLASSES_ROOT,
                                                                             ic,
                                                                             typeof(RegistryViewerClassesPage),
                                                                             plugin);
                                            KeyNode.Tag = HKEY.HKEY_CLASSES_ROOT;
                                            KeyNodes.Add(KeyNode);
                                            break;

                                        case "HKEY_CURRENT_CONFIG":
                                            hKey = HKEY.HKEY_CURRENT_CONFIG;
                                            KeyNode = Manage.CreateIconNode(Properties.Resources.HKEY_CURRENT_CONFIG,
                                                                             ic,
                                                                             typeof(RegistryViewerConfigPage),
                                                                             plugin);
                                            KeyNode.Tag = HKEY.HKEY_CURRENT_CONFIG;
                                            KeyNodes.Add(KeyNode);
                                            break;

                                        case "HKEY_CURRENT_USER":
                                            hKey = HKEY.HEKY_CURRENT_USER;
                                            KeyNode = Manage.CreateIconNode(Properties.Resources.HKEY_CURRENT_USER,
                                                                             ic,
                                                                             typeof(RegistryViewerUserPage),
                                                                             plugin);
                                            KeyNode.Tag = HKEY.HEKY_CURRENT_USER;
                                            KeyNodes.Add(KeyNode);
                                            break;

                                        case "HKEY_LOCAL_MACHINE":
                                            hKey = HKEY.HKEY_LOCAL_MACHINE;
                                            KeyNode = Manage.CreateIconNode(Properties.Resources.HKEY_LOCAL_MACHINE,
                                                                             ic,
                                                                             typeof(RegistryViewerMachinePage),
                                                                             plugin);
                                            KeyNode.Tag = HKEY.HKEY_LOCAL_MACHINE;
                                            KeyNodes.Add(KeyNode);
                                            break;

                                        case "HKEY_USERS":
                                            hKey = HKEY.HKEY_USERS;
                                            KeyNode = Manage.CreateIconNode(Properties.Resources.HKEY_USERS,
                                                                             ic,
                                                                             typeof(RegistryViewerUsersPage),
                                                                             plugin);
                                            KeyNode.Tag = HKEY.HKEY_USERS;
                                            KeyNodes.Add(KeyNode);
                                            break;
                                    }
                                    RegistryInteropWrapperWindows.Win32RegOpenRemoteBaseKey(hKey,
                                          out sSubKey);
                                }
                                else
                                {
                                    plugin.RegRootKeySelected = Properties.Resources.HKEY_LIKEWISE_IMPORT;
                                    hKey = HKEY.HKEY_LIKEWISE;
                                    KeyNode = Manage.CreateIconNode(Properties.Resources.HKEY_LIKEWISE_IMPORT,
                                                                     ic,
                                                                     typeof(RegistryViewerLikewisePage),
                                                                     plugin);
                                    KeyNode.Tag = HKEY.HKEY_LIKEWISE;
                                    KeyNodes.Add(KeyNode);

                                    if (pluginNode.Nodes[1].Tag != null && pluginNode.Nodes[1].Tag is RegistryEnumKeyInfo)
                                    {
                                        RegistryEnumKeyInfo rootKeyInfo = pluginNode.Nodes[1].Tag as RegistryEnumKeyInfo;
                                        if (rootKeyInfo.pKey != IntPtr.Zero)
                                            pRootKey = rootKeyInfo.pKey;
                                        else
                                            RegistryInteropWrapper.ApiRegOpenKeyExW(plugin.handle.Handle,
                                                                                    IntPtr.Zero,
                                                                                    plugin.RegRootKeySelected,
                                                                                    out pRootKey);
                                    }
                                    else
                                    {
                                        RegistryInteropWrapper.ApiRegOpenKeyExW(plugin.handle.Handle,
                                                                                IntPtr.Zero,
                                                                                plugin.RegRootKeySelected,
                                                                                out pRootKey);
                                    }
                                    //Create the keys under Likewise_Import
                                    if (!sKeyName.Trim().ToUpper().Equals(plugin.RegRootKeySelected))
                                        RegistryInteropWrapper.ApiRegOpenKeyExW(plugin.handle.Handle, pRootKey,
                                            sKeyName, out pRootKey);
                                }
                            }
                            else if (sSubKey != null)
                            {
                                sSubKey = RegistryInteropWrapperWindows.Win32CreateSubKey(sSubKey, sKeyName);
                            }
                            else if (pRootKey != IntPtr.Zero)
                            {
                                IntPtr pSubKey = IntPtr.Zero;
                                RegistryInteropWrapper.ApiRegOpenKeyExW(plugin.handle.Handle, pRootKey, sKeyName, out pSubKey);
                                RegistryInteropWrapper.ApiRegCloseKey(plugin.handle.Handle, pRootKey);
                                pRootKey = pSubKey;
                            }
                        }
                    }
                }
                else if (currentLine != null && currentLine.Contains("="))
                {
                    string[] splits = currentLine.Split('=');
                    if (splits != null && splits.Length != 0)
                    {
                        if (Configurations.currentPlatform == LikewiseTargetPlatform.Windows)
                        {
                            SubKeyValueInfo valueInfo = new SubKeyValueInfo();
                            valueInfo.hKey = hKey;
                            valueInfo.IsDefaultValue = false;

                            if (splits[0].StartsWith("\""))
                                valueInfo.sValue = splits[0].Substring(1, splits[0].Length - 2);
                            else if (splits[0].Equals("@"))
                                valueInfo.sValue = "";
                            else
                                valueInfo.sValue = splits[0];

                            valueInfo.sParentKey = sSubKey;
                            valueInfo.hKey = hKey;
                            RegistryHelper.GetValueKind(valueInfo, splits[1]);

                            if ((valueInfo.RegDataType == LWRegistryValueKind.REG_BINARY) ||
                              (valueInfo.RegDataType == LWRegistryValueKind.REG_MULTI_SZ) ||
                              (valueInfo.RegDataType == LWRegistryValueKind.REG_EXPAND_SZ) ||
                              (valueInfo.RegDataType == LWRegistryValueKind.REG_RESOURCE_LIST))
                            {
                                while (!reader.EndOfStream && currentLine.Contains(@"\"))
                                {
                                    splits[1] += currentLine;
                                    currentLine = reader.ReadLine();
                                }
                                splits[1] += currentLine;
                                splits[1] = splits[1].Replace('\\', ',');
                                splits[1] = splits[1].Replace(" ", "");
                                splits[1] = splits[1].EndsWith(",") ? splits[1].Substring(0, splits[1].Length - 1) : splits[1];
                            }

                            RegistryHelper.GetValueData(valueInfo, splits[1]);
                            RegistryInteropWrapperWindows.Win32AddSubKeyValue(valueInfo);
                        }
                        else
                        {
                            RegistryValueInfo regValueInfo = new RegistryValueInfo();
                            regValueInfo.pParentKey = pRootKey;

                            if (splits[0].StartsWith("\""))
                                regValueInfo.pValueName = splits[0].Substring(1, splits[0].Length - 2);
                            else
                                regValueInfo.pValueName = splits[0];

                            RegistryHelper.GetValueKind(regValueInfo, splits[1]);

                            if ((regValueInfo.pType == (ulong)RegistryApi.REG_BINARY) ||
                             (regValueInfo.pType == (ulong)RegistryApi.REG_MULTI_SZ) ||
                             (regValueInfo.pType == (ulong)RegistryApi.REG_EXPAND_SZ) ||
                             (regValueInfo.pType == (ulong)RegistryApi.REG_RESOURCE_LIST) ||
                             (regValueInfo.pType == (ulong)RegistryApi.REG_RESOURCE_REQUIREMENTS_LIST) ||
                             (regValueInfo.pType == (ulong)RegistryApi.REG_FULL_RESOURCE_DESCRIPTOR))
                            {
                                while (!reader.EndOfStream && currentLine.Contains(@"\"))
                                {
                                    splits[1] += currentLine;
                                    currentLine = reader.ReadLine();
                                }
                                splits[1] += currentLine;
                                splits[1] = splits[1].Replace('\\', ',');
                                splits[1] = splits[1].Replace(" ", "");
                                splits[1] = splits[1].EndsWith(",") ? splits[1].Substring(0, splits[1].Length - 1) : splits[1];
                            }

                            RegistryHelper.GetValueData(regValueInfo, splits[1]);
                            RegistryInteropWrapper.ApiRegSetValueEx(plugin.handle.Handle,
                                                   regValueInfo.pParentKey,
                                                   regValueInfo.pValueName,
                                                   (uint)regValueInfo.pType,
                                                    regValueInfo.bDataBuf as byte[]);
                        }
                    }
                }
            }
        }
コード例 #11
0
        public static object GetFormatSpecificData(RegistryValueInfo valueInfo)
        {
            object sData = null;

            switch (valueInfo.pType)
            {
            case (ulong)RegistryApi.REG_BINARY:
            case (ulong)RegistryApi.REG_RESOURCE_LIST:
            case (ulong)RegistryApi.REG_UNKNOWN:
            case (ulong)RegistryApi.REG_FULL_RESOURCE_DESCRIPTOR:
            case (ulong)RegistryApi.REG_RESOURCE_REQUIREMENTS_LIST:
                byte[] byts = valueInfo.bDataBuf as byte[];
                Array.Resize <byte>(ref byts, (int)valueInfo.pcData);
                sData = GetBinaryData(byts);
                break;

            case (ulong)RegistryApi.REG_EXPAND_SZ:
                string      sTemp   = new UnicodeEncoding().GetString(valueInfo.bDataBuf as byte[]);
                byte[]      eByts   = new UnicodeEncoding().GetBytes(sTemp + "\n");
                List <byte> bytList = new List <byte>();
                foreach (byte byt in eByts)
                {
                    if (byt == 10 || byt == 13)
                    {
                        bytList.Add((byte)00);
                    }
                    else
                    {
                        bytList.Add(byt);
                        bytList.Add((byte)00);
                    }
                }
                eByts = new byte[bytList.Count];
                bytList.CopyTo(eByts);
                sData = GetBinaryData(eByts);
                break;

            case (ulong)RegistryApi.REG_MULTI_SZ:
                string[]      sArry     = new UnicodeEncoding().GetString(valueInfo.bDataBuf as byte[]).Split('\n');
                StringBuilder sTempArry = new StringBuilder();
                List <byte>   mBytList  = new List <byte>();
                foreach (string value in sArry)
                {
                    sTempArry.Append(value);
                    sTempArry.Append("\r\n");
                }
                byte[] mByts = new UnicodeEncoding().GetBytes(sTempArry.ToString());
                foreach (byte byt in mByts)
                {
                    if (byt == 10 || byt == 13)
                    {
                        mBytList.Add((byte)00);
                    }
                    else
                    {
                        mBytList.Add(byt);
                        mBytList.Add((byte)00);
                    }
                }
                mByts = new byte[mBytList.Count];
                mBytList.CopyTo(mByts);
                sData = GetBinaryData(mByts);
                break;

            case (ulong)RegistryApi.REG_DWORD:
                sData = String.Format("{0:X2}", BitConverter.ToUInt32(valueInfo.bDataBuf as byte[], 0)).PadLeft(8, '0');
                break;

            case (ulong)RegistryApi.REG_PLAIN_TEXT:
            case (ulong)RegistryApi.REG_SZ:
                sData = new UnicodeEncoding().GetString(valueInfo.bDataBuf as byte[]);
                sData = string.Concat("\"", sData, "\"");
                break;

            case (ulong)RegistryApi.REG_QWORD:
                //sData = RegistryUtils.DecimalToBase(Convert.ToInt32(new ASCIIEncoding().GetString(valueInfo.bDataBuf as byte[])), 16).PadLeft(16, '0');
                sData = String.Format("{0:X2}", BitConverter.ToUInt64(valueInfo.bDataBuf as byte[], 0)).PadLeft(16, '0');
                sData = string.Concat("\"", sData, "\"");
                break;

            default:
                break;
            }
            return(sData);
        }
コード例 #12
0
        public static void GetValueData(RegistryValueInfo valueInfo, string sData)
        {
            UnicodeEncoding encoder = new UnicodeEncoding();

            string[] splits = sData.Split(':');

            try
            {
                switch (valueInfo.pType)
                {
                case (ulong)RegistryApi.REG_SZ:
                case (ulong)RegistryApi.REG_EXPAND_SZ:
                case (ulong)RegistryApi.REG_PLAIN_TEXT:
                    if (!String.IsNullOrEmpty(splits[0]))
                    {
                        byte[] sByts = encoder.GetBytes(splits[0].Substring(1));
                        Array.Resize <byte>(ref sByts, sByts.Length - 1);
                        valueInfo.bDataBuf = sByts;
                    }
                    else
                    {
                        valueInfo.bDataBuf = new byte[] { 0 }
                    };
                    break;

                case (ulong)RegistryApi.REG_DWORD:
                    uint   dValue     = UInt32.Parse(splits[1], System.Globalization.NumberStyles.HexNumber);
                    byte[] dwDataArry = BitConverter.GetBytes(dValue);
                    valueInfo.bDataBuf = dwDataArry;
                    break;

                case (ulong)RegistryApi.REG_QWORD:
                    ulong  qValue     = UInt64.Parse(splits[1], System.Globalization.NumberStyles.HexNumber);
                    byte[] qwDataArry = BitConverter.GetBytes(qValue);
                    valueInfo.bDataBuf = qwDataArry;
                    break;

                case (ulong)RegistryApi.REG_MULTI_SZ:
                    string[]    sDataArray = splits[2].Split(',');
                    List <byte> bytlist    = new List <byte>();
                    for (int idx = 0; idx < sDataArray.Length; idx += 2)
                    {
                        bytlist.Add(Convert.ToByte(sDataArray[idx], 16));
                    }
                    byte[] mbyts = new byte[bytlist.Count];
                    bytlist.CopyTo(mbyts);
                    valueInfo.bDataBuf = encoder.GetString(mbyts).Split(new char[] { '\0' }, StringSplitOptions.RemoveEmptyEntries);
                    RegistryInteropWrapper.RegModifyKeyValue(valueInfo, out mbyts);
                    valueInfo.bDataBuf = mbyts;
                    break;

                default:
                    string[] sDataArry = splits[2].Split(',');
                    if (sDataArry != null)
                    {
                        byte[] byts = new byte[sDataArry.Length];
                        for (int idx = 0; idx < sDataArry.Length; idx++)
                        {
                            if (!String.IsNullOrEmpty(sDataArry[idx]))
                            {
                                byts[idx] = Convert.ToByte(sDataArry[idx], 16);
                            }
                        }
                        valueInfo.bDataBuf = byts;
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                Logger.LogException("GetValueData() for the value " + valueInfo.pValueName, ex);
            }
        }