#!/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 '