⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 registry.java

📁 注册表的读取信息,工具文件包
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
			RegistryKey topKey, String keyName,
			String valueName, String data )
		{
		RegistryKey subKey =
			Registry.openSubKeyVerbose
				( topKey, keyName, RegistryKey.ACCESS_WRITE );

		if ( subKey == null )
			return;

		int anInt;
		try { anInt = Integer.parseInt( data ); }
		catch ( NumberFormatException ex )
			{
			System.err.println
				( "ERROR bad int: '" + ex.getMessage() + "'" );
			return;
			}

		RegDWordValue val = new RegDWordValue( subKey, valueName );
		val.setData( anInt );
		
		Registry.setValue( subKey, val );
		}
	
	private static void
	setMultiStringCommand(
			RegistryKey topKey, String keyName,
			String valueName, String data )
		{
		RegistryKey subKey =
			Registry.openSubKeyVerbose
				( topKey, keyName, RegistryKey.ACCESS_WRITE );

		if ( subKey == null )
			return;

		String[] strArray =
			Registry.splitString( data, ";" );

		RegMultiStringValue val =
			new RegMultiStringValue
				( subKey, valueName, strArray );

		Registry.setValue( subKey, val );
		}

	private static void
	setStringCommand(
			RegistryKey topKey, String keyName,
			String valueName, String data )
		{
		RegistryKey subKey =
			Registry.openSubKeyVerbose
				( topKey, keyName, RegistryKey.ACCESS_WRITE );

		if ( subKey == null )
			return;

		RegStringValue val =
			new RegStringValue( subKey, valueName, data );

		Registry.setValue( subKey, val );
		}

	private static void
	setBinaryCommand(
			RegistryKey topKey, String keyName,
			String valueName, String data )
		{
		RegistryKey subKey =
			Registry.openSubKeyVerbose
				( topKey, keyName, RegistryKey.ACCESS_WRITE );

		if ( subKey == null )
			return;

		byte[] binData = data.getBytes();

		RegBinaryValue val =
			new RegBinaryValue( subKey, valueName, binData );

		Registry.setValue( subKey, val );
		}

	private static void
	createCommand( RegistryKey topKey, String keyName )
		{
		RegistryKey		subKey;

		try {
			subKey =
				topKey.createSubKey
					( keyName, "", RegistryKey.ACCESS_WRITE );
			}
		catch ( RegistryException ex )
			{
			subKey = null;
			System.err.println
				( "ERROR creating subKey: " + ex.getMessage() );
			}

		if ( subKey != null )
			{
			try {
				subKey.flushKey();
				subKey.closeKey();
				}
			catch ( RegistryException ex )
				{
				subKey = null;
				System.err.println
					( "ERROR flushing and closing key: "
						+ ex.getMessage() );
				}
			}

		if ( subKey != null )
			{
			System.err.println
				( "SUCCEEDED "
					+ ( subKey.wasCreated()
						? "Creating" : "Opening via create" )
					+ " Key '" + keyName + "'" );
			}
		else
			{
			System.err.println
				( "FAILED Creating Key '" + keyName + "'" );
			}
		}

	private static RegistryKey
	openSubKeyVerbose( RegistryKey topKey, String keyName, int access )
		{
		RegistryKey		subKey = null;

		try { subKey = topKey.openSubKey( keyName, access ); }
		catch ( NoSuchKeyException ex )
			{
			subKey = null;
			System.err.println
				( "Key '" + keyName + "' does not exist." );
			}
		catch ( RegistryException ex )
			{
			subKey = null;
			System.err.println
				( "ERROR registry error=" + ex.getErrorCode()
					+ ", " + ex.getMessage() );
			}

		return subKey;
		}

	private static void
	setValue( RegistryKey subKey, RegistryValue value )
		{
		try {
			subKey.setValue( value );
			subKey.flushKey();
			}
		catch ( RegistryException ex )
			{
			System.err.println
				( "ERROR setting MULTI_SZ value '"
					+ value.getName() + "', " + ex.getMessage() );
			}
		}

	public static void
	dumpHexData( PrintStream out, String title, byte[] buf, int numBytes )
		{
		PrintWriter wrtr =
			new PrintWriter( new OutputStreamWriter( out ) );

		Registry.dumpHexData( wrtr, title, buf, 0, numBytes );
		}

	public static void
	dumpHexData(
			PrintWriter out, String title,
			byte[] buf, int offset, int numBytes )
		{
		int			rows, residue, i, j;
		byte[]		save_buf= new byte[ ROW_BYTES+2 ];
		char[]		hex_buf = new char[ 4 ];
		char[]		idx_buf = new char[ 8 ];
		char[]		hex_chars = new char[20];
		
		hex_chars[0] = '0';
		hex_chars[1] = '1';
		hex_chars[2] = '2';
		hex_chars[3] = '3';
		hex_chars[4] = '4';
		hex_chars[5] = '5';
		hex_chars[6] = '6';
		hex_chars[7] = '7';
		hex_chars[8] = '8';
		hex_chars[9] = '9';
		hex_chars[10] = 'A';
		hex_chars[11] = 'B';
		hex_chars[12] = 'C';
		hex_chars[13] = 'D';
		hex_chars[14] = 'E';
		hex_chars[15] = 'F';
		
		out.println( title + " - " + numBytes + " bytes." );

		rows = (numBytes + (ROW_BYTES-1)) / ROW_BYTES;
		residue = (numBytes % ROW_BYTES);

		for ( i = 0 ; i < rows ; i++ )
			{
			int hexVal = (i * ROW_BYTES);
			idx_buf[0] = hex_chars[ ((hexVal >> 12) & 15) ];
			idx_buf[1] = hex_chars[ ((hexVal >> 8) & 15) ];
			idx_buf[2] = hex_chars[ ((hexVal >> 4) & 15) ];
			idx_buf[3] = hex_chars[ (hexVal & 15) ];

			String idxStr = new String( idx_buf, 0, 4 );
			out.print( idxStr + ": " );
		
			for ( j = 0 ; j < ROW_BYTES ; j++ )
				{
				if ( i == (rows - 1) && j >= residue )
					{
					save_buf[j] = ' ';
					out.print( "   " );
					if ( j == ROW_QTR1 || j == ROW_HALF || j == ROW_QTR2 )
						out.print( ' ' );
					}
				else
					{
					save_buf[j] = buf[ offset + (i * ROW_BYTES) + j ];

					hex_buf[0] = hex_chars[ (save_buf[j] >> 4) & 0x0F ];
					hex_buf[1] = hex_chars[ save_buf[j] & 0x0F ];

					out.print( hex_buf[0] );
					out.print( hex_buf[1] );
					out.print( ' ' );

					if ( j == ROW_QTR1 || j == ROW_HALF || j == ROW_QTR2 )
						out.print( ' ' );

					if ( save_buf[j] < 0x20 || save_buf[j] > 0x7E )
						save_buf[j] = (byte) '.';
					}
				}

			String saveStr = new String( save_buf, 0, j );
			out.println( " | " + saveStr + " |" );
			}

		out.flush();
		}

	/**
	 * Split a string into a string array containing the substrings
	 * between the delimiters.
	 *
	 * NOTE This method WILL <strong>NOT</strong> return an empty
	 * token at the end of the array that is returned, if the string
	 * ends with the delimiter. If you wish to have a property string
	 * array that ends with the delimiter return an empty string at
	 * the end of the array, use <code>vectorString()</code>.
	 */

	static public String[]
	splitString( String splitStr, String delim )
		{
		int				i, count;
		String[]		result;
		StringTokenizer toker;

		toker = new StringTokenizer( splitStr, delim );

		count = toker.countTokens();

		result = new String[ count ];

		for ( i = 0 ; i < count ; ++i )
			{
			try { result[i] = toker.nextToken(); }
			catch ( NoSuchElementException ex )
				{
				result = null;
				break;
				}
			}

		return result;
		}

	public static String[]
	parseArgumentString( String argStr )
		{
		String[] result = null;

		Vector vector = Registry.parseArgumentVector( argStr );

		if ( vector != null && vector.size() > 0 )
			{
			result = new String[ vector.size() ];
			vector.copyInto( result );
			}

		return result;
		}

	public static Vector
	parseArgumentVector( String argStr )
		{
		Vector			result = new Vector();
		StringBuffer	argBuf = new StringBuffer();

		boolean backSlash = false;
		boolean matchSglQuote = false;
		boolean matchDblQuote = false;

		for ( int cIdx = 0 ; cIdx < argStr.length() ; ++cIdx )
			{
			char ch = argStr.charAt( cIdx );

			switch ( ch )
				{
				//
				// W H I T E S P A C E
				//
				case ' ':
				case '\t':
				case '\n':
				case '\r':
					if ( backSlash )
						{
						argBuf.append( ch );
						backSlash = false; 
						}
					else if ( matchSglQuote || matchDblQuote )
						{
						argBuf.append( ch );
						}
					else if ( argBuf.length() > 0 )
						{
						result.addElement( argBuf.toString() );
						argBuf.setLength( 0 );
						}
					break;

				case '\\':
					if ( backSlash )
						{
						argBuf.append( "\\" );
						}
					backSlash = ! backSlash;
					break;

				case '\'':
					if ( backSlash )
						{
						argBuf.append( "'" );
						backSlash = false; 
						}
					else if ( matchSglQuote )
						{
						result.addElement( argBuf.toString() );
						argBuf.setLength( 0 );
						matchSglQuote = false;
						}
					else if ( ! matchDblQuote )
						{
						matchSglQuote = true;
						}
					break;

				case '"':
					if ( backSlash )
						{
						argBuf.append( "\"" );
						backSlash = false; 
						}
					else if ( matchDblQuote )
						{
						result.addElement( argBuf.toString() );
						argBuf.setLength( 0 );
						matchDblQuote = false;
						}
					else if ( ! matchSglQuote )
						{
						matchDblQuote = true;
						}
					break;

				default:
					if ( backSlash )
						{
						switch ( ch )
							{
							case 'b': argBuf.append( '\b' ); break;
							case 'f': argBuf.append( '\f' ); break;
							case 'n': argBuf.append( '\n' ); break;
							case 'r': argBuf.append( '\r' ); break;
							case 't': argBuf.append( '\t' ); break;

							default:
								char ch2 = argStr.charAt( cIdx+1 );
								char ch3 = argStr.charAt( cIdx+2 );
								if ( (ch >= '0' && ch <= '7')
										&& (ch2 >= '0' && ch2 <= '7')
										&& (ch3 >= '0' && ch3 <= '7') )
									{
									int octal =
										( ( (ch - '0') * 64 )
											+ ( (ch2 - '0') * 8 )
												+ (ch3 - '0') );
									argBuf.append( (char) octal );
									cIdx += 2;
									}
								else if ( ch == '0' )
									{
									argBuf.append( '\0' );
									}
								else
									{
									argBuf.append( ch );
									}
								break;
							}
						}
					else
						{
						argBuf.append( ch );
						}

					backSlash = false;
					break;
				}
			}

		if ( argBuf.length() > 0 )
			{
			result.addElement( argBuf.toString() );
			}

		return result;
		}
	
	}




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -