Commit 1bb0e66f authored by Sylvain St.Germain's avatar Sylvain St.Germain Committed by Alexandre Julliard

Added command line tool to access the registry.

parent 0dd1b5b2
......@@ -4643,6 +4643,7 @@ programs/avitools/Makefile
programs/notepad/Makefile
programs/progman/Makefile
programs/regtest/Makefile
programs/regapi/Makefile
programs/view/Makefile
programs/winhelp/Makefile
programs/winver/Makefile
......@@ -4806,6 +4807,7 @@ programs/avitools/Makefile
programs/notepad/Makefile
programs/progman/Makefile
programs/regtest/Makefile
programs/regapi/Makefile
programs/view/Makefile
programs/winhelp/Makefile
programs/winver/Makefile
......
......@@ -668,6 +668,7 @@ programs/avitools/Makefile
programs/notepad/Makefile
programs/progman/Makefile
programs/regtest/Makefile
programs/regapi/Makefile
programs/view/Makefile
programs/winhelp/Makefile
programs/winver/Makefile
......
......@@ -5,6 +5,7 @@ SUBDIRS = \
control \
notepad \
progman \
regapi \
regtest \
view \
winhelp \
......
DEFS = -DWINELIB
TOPSRCDIR = @top_srcdir@
TOPOBJDIR = ../..
SRCDIR = @srcdir@
VPATH = @srcdir@
MODULE = none
PROGRAMS = regapi
ALL_LIBS = $(WINELIB) $(X_LIBS) $(XLIB) $(LIBS)
RCFLAGS = -w32 -h
WRCEXTRA = -A -p $*
C_SRCS = \
regapi.c
all: $(PROGRAMS)
depend::
@MAKE_RULES@
regapi: $(OBJS)
$(CC) -o regapi $(OBJS) $(LDOPTIONS) $(ALL_LIBS)
install: dummy
$(INSTALL_PROGRAM) regapi $(bindir)/regapi
uninstall: dummy
$(RM) $(bindir)/regapi
dummy:
### Dependencies:
Registry Command Line API Tool
------------------------------
This progam is intended to fill a particular need. I needed to make the
wine registry look like it would have been if my application would have
been installed by its installation program. Since this was not possible I
took the following approach.
1 - Use regedit to export my full Windows registry before I install my
application.
2 - Use regedit to export my full Windows registry after I had install my
application.
3 - Generate the differences between the two image. What I obtain from the
diff is what I need to apply to the wine registry.
Obvisouly the process is not that straight forward to solve, first,
you don't get the diff between two Windows regedit exported .reg file by
doing a simple diff. What I had to do is a little more complex, but not
that much...
(Assuming that the registry picture files are
named ./before.reg and ./after.reg)
1 - Parse the before.reg and after.reg file into regFixer.pl, in order to
obtain lines in the form [HKEY\Sub1\Sub2\...\Subn]"Value"="Data"
(where "Data" can be prefixed by the type identifyer : hex:, hex(0000000?)
or dword:)
2 - Generate the diff between the before.reg.fix and after.reg.fix
into app.diff
Now we have a app.reg file that contain what has been done by installing the
application. To this we extract the part's that we are interested in using
grep (and fix it with sed) and put that into app.added by example
( let say we keep the added values only ).
At this point we know which registry entry to add to the wine registry. It
only remains to take the format we have and reset it into a format similar
to the one we get from regedit.
I say "similar" because there is a tiny difference between Windows regedit
export format and the format actualy required by the tool.
The problem with this (and it is not a big one) is that regedit export long
data streams onto many lines, and since I dont have tons of time I setup
another Perl script (regRestorer.pl) that fixes this (this could easily
be done in C obviously) (left as excercise ;-) ).
So, once you parsed app.added into regRestorer.pl you get a app.reg ready to
process by regapi.
So, this package comes with a few pieces:
regFixer.pl - Will convert the export of regedit
into something "diff-able"
regRestorer.pl - Will convert "cleaned" diff file into
something "regapi-able"
regSet - Will do the procedure explained herein
for the added key only.
FAQ
---
Quick Start Guide
-----------------
1 - Get a snapshot of your windows registry in before.reg, (regedit/export)
2 - Install you're application,
3 - Get a snapshot of your windows registry in after.reg.
4 - Invoke ./regSet.sh before.reg after.reg
Adding key I have in a regedit export file (nothing to diff with...)
------------------------------------------
1 - Invoke ./regSet.sh /dev/null myRegistry.reg
regapi help
-----------
1 - regapi has some sort of "man page like" help in it, simply invoke it
without any arguments.
Hope this is of any use to you.
Sylvain St-Germain.
#!/usr/bin/perl
# This script takes as STDIN an output from the Registry
# (export from regedit.exe) and prefixes every subkey-value
# pair by their hkey,key data member
#
# Copyright 1999 Sylvain St-Germain
#
${prefix} = "";
${line} = "";
LINE: while(<>) {
chomp; # Get rid of 0x0a
chop; # Get rid of 0x0d
next LINE if(/^$/); # This is an empty line
if( /^\[/ ) {
${prefix} = ${_}; # assign the prefix for the forthcomming section
next LINE;
}
s/\\\\/\\/g; # Still some more substitutions... To fix paths...
s/^ //; # Get rid of the stupid two spaces at the begining
# they are there in the case of a multi-line thing
if (/\\$/) { # The line ends with '\', it means it is a multi
s/\\$//; # line thing, remove it.
${line} = "${line}${_}";# Add the current line to the line to output
next LINE; # process the next line
}
${line} = "${line}${_}"; # Set line to the multi line thing+the current line
print "${prefix}${line}\n";
${line} = ""; # start over...
}
#!/usr/bin/perl
# This script takes as STDIN an output from the regFixer.pl
# and reformat the file as if it would have been exported from the registry
#
# Note: the output file is not exactly the one we get when exporting from
# regedit, the tiny difference is that multilines (which were
# single-linized by regFixer.pl) values are not re-multi-linized by
# this script.
#
# Copyright 1999 Sylvain St-Germain
#
${newkey} = "";
${key} = "";
${data} = "";
# I do not validate the integrity of the file, I am assuming that
# the input file comes from the output of regFixer.pl, therefore things
# should be ok, if they are not, investigate and send me an email...
LINE: while(<>) {
chomp; # get rid of new line
next LINE if(/^$/); # This is an empty line
(${key}, ${data}, ${rest})= split /]/,$_ ; # Extract the values from the line
${key} = "${key}]"; # put the ']' back there...
if (${rest} ne "") # concat we had more than 1 ']'
{ # on the line
${data} = "${data}]${rest}";
}
if (${key} eq ${newkey})
{
print "${data}\n";
}
else
{
${newkey} = ${key}; # assign it
print "\n";
print "${key}\n";
print "${data}\n";
}
}
#!/bin/bash
# This script is the receipe to generate the key that have to be created like
# if an applicaiton was installed by its installer. It processes using a
# registry based on the picture of the registry before the application is
# installed and the picture of the registry after the application is installed.
#
# Copyright 1999 Sylvain St-Germain
#
if [ $# -ne 2 ]; then
echo "$0 Usage: "
echo " You must provide 2 arguments."
echo " 1 - Registry output before the application's installation."
echo " 2 - Registry output after the application's installation."
echo
exit 1
fi
echo "Assuming that $1 is the \"before\" file..."
echo "Assuming that $2 is the \"after\" file..."
#
# do not attempt to regFix.pl /dev/null ...
#
echo "Fixing exported registry files..."
if [ $1 != "/dev/null" ]; then
cat $1 | ./regFixer.pl > $1.fix
fi
cat $2 | ./regFixer.pl > $2.fix
#
# diff accordingly depending on /dev/null
#
echo "Diffing..."
if [ $1 != "/dev/null" ]; then
diff $1.fix $2.fix > $2.diff
else
diff /dev/null $2.fix > $2.diff
fi
#
# Keep only added lines
#
echo "Grepping keys to add and generating cleaned fixed registry file."
cat $2.diff | grep '^> ' | sed -e 's/^> //' > $2.toAdd
#
# Restore the file format to the regedit export 'like' format
#
echo "Restoring key's in the regedit export format..."
cat $2.toAdd | ./regRestorer.pl > $2.toAdd.final
echo "Cleaning..."
rm $1.fix $2.fix >/dev/null 2>&1
rm $2.diff >/dev/null 2>&1
rm $2.toAdd >/dev/null 2>&1
mv $2.toAdd.final $2.toAdd
echo "Operation completed, result file is $2.toAdd"
exit 0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment