#!/usr/bin/perl ############################################################ ############################################################ # name: Registry Conversion Utility # author: Ian Hickson (Hixie the Pixie) # license: GPL # description: Converts REGEDIT4 output to REG.EXE input. ############################################################ # Initialise System use lib ('../utils'); $output::mediaPath = '../../../media/'; $output::appName = 'Registry Data Conversion Utility'; $output::appStyle = 'style/default.css'; $output::authorContact = 'http://www.bath.ac.uk/%7Epy8ieh/'; $output::authorEmail = 'py8ieh=website=cgi=development=buncs=regconv@bath.ac.uk'; $output::authorName = 'Ian Hickson'; require 'inputRoutines.pl'; # get cookies, parameters require 'outputRoutines.pl'; # so that we can output stuff ############################################################ $regkeys{'HKEY_CURRENT_CONFIG'} = 'HKCC'; $regkeys{'HKEY_CLASSES_ROOT'} = 'HKCR'; $regkeys{'HKEY_CURRENT_USER'} = 'HKCU'; $regkeys{'HKEY_DYN_DATA'} = 'HKDD'; $regkeys{'HKEY_USERS'} = 'HKU'; $regkeys{'HKEY_LOCAL_MACHINE'} = 'HKLM'; $x = 'http://www.bath.ac.uk/%7Epy8ieh/cgid/development/buncs/' if $param::debug; my(@input); if ($param::filename) { &output::outputDebug(); print "Sorry, the file upload feature doesn't work yet.\n\n\n\n"; while (<$param::filename>) { print; } } else { @input = split(/\r\n/, $param::input); } my(@output, $regpath); if (@input > 0) { # great, now we have to parse it. foreach $newline (@input) { $newline =~ s/^ *([^ ]+.*[^ ]+) *$/$1/go; $line .= $newline; if ($line =~ /\\$/) { chop $line; next; } if ($line eq 'REGEDIT4') { push @output, "; Converted from a REGEDIT4 input file."; } elsif ($line =~ /^\[([^\\]+)\\(.+)\]$/) { # key $b = $1; @x = &process($2, 1); $a = $x[0]; $qa = $x[1]; push @output, "-ADDKEY $qa\\".$regkeys{$b}."\\$a$qa $qa\\".$regkeys{$b}."\\$a\\$qa"; } elsif ($line =~ /^@="(.*)"$/) { # default value @x = &process($1); $a = $x[0]; $qa = $x[1]; push @output, qq!-SET ""=$qa$a$qa!; } elsif ($line =~ /^"(.*[^\\])"="(.*)"$/) { # simple value $b = $2; @x = &process($1); $a = $x[0]; $qa = $x[1]; @x = &process($b); $b = $x[0]; $qb = $x[1]; push @output, qq!-SET $qa$a$qa=$qb$b$qb!; } elsif ($line =~ /^"(.*[^\\])"=dword:([0-9a-f]+)$/) { # dword value (hex) $b = $2; @x = &process($1, 1); $a = $x[0]; $qa = $x[1]; push @output, qq!-SET REG_DWORD $qa$a$qa="0x$b"!; } elsif ($line =~ /^"(.*[^\\])"=hex:([0-9a-f,]+)$/) { # hex value ($b = $2) =~ s/,//go; @x = &process($1, 1); $a = $x[0]; $qa = $x[1]; push @output, qq!-SET REG_DWORD $qa$a$qa="0x$b"!; } elsif ($line eq '') { # blank line push @output, q!!; } else { # gunk push @output, qq!; XXX did not grok "$line"!; } $line = ''; } } $output = &output::escapeHTML(join("\r\n", @output)); &output::cleanParam(1, 'input', 'filename'); ## GENERATE OUTPUT ######################################### &output::printHTMLHeader(); print '

This program converts REGEDIT data files into the format used by the REG.EXE program.

'; if (@output > 0) { print '

Here is the converted output:

'; print '

'; print '

'.length($param::input).' characters parsed in '.($#input+1).' line'. (($#input == 0) ? '' : 's') .'. Total output was '.length($output).' characters in '.($#output+1).' line'. (($#output == 0) ? '' : 's') .'.

'; } print '

Enter your REGEDIT4 input below. This is the format of the output files created when exporting from the Microsoft Registry Editor program. Alternatively, give the path of a file on your machine which contains stuff to convert. (If you provide both, the file will be used and the contents of the text box below will be ignored.)

File to convert: '. ($param::allowFiles ? '' : '[use the button below to enable file uploads]') . '

'; if ($x) { print '

To switch back to normal, non-debug mode, use this button:

'."\n".&output::getContinueHiddenFields('debug').'

'; } else { print '

If you want the script to return the results using the "cgid" debug mode, use this button:

'."\n".&output::getContinueHiddenFields('debug').'

'; } if ($param::allowFiles) { print '

To disable the uploading of files (might solve problems with the script) use this button:

'."\n".&output::getContinueHiddenFields('allowFiles').'

'; } else { print '

To enable the uploading of files (warning -- this is buggy!) use this button:

'."\n".&output::getContinueHiddenFields('allowFiles').'

'; } print '
'; &output::printHTMLFooter(); ############################################################ sub process { my($a, $b) = @_; if (!defined($b)) { $a =~ s/\\(.)/$1/go; } if ($a =~ '"') { if ($a =~ "'") { $q = 'XXX PROBLEM ON THIS LINE -- REG.EXE CANNOT COPE WITH STRINGS CONTAINING BOTH " AND \' SO THIS LINE WILL NOT WORK!!! XXX'; } else { $q = "'"; } } else { $q = '"'; } return ($a, $q); } ############################################################