OWASP O2 Platform Blog

O2 Script Sequence: Creating a Windows Registry Viewer

When I was writing the script to Add sites to IE’s trusted zone I found that I needed to have a quick look at the registry. Since opening up RegEdit seemed like too much work, I decided to quickly add a Registry Viewer to O2 (you can find the published version of this script on your local Scripts folder at /O2_Scripts/Utils/Windows/Util – Registry Viewer.h2)

Here is how I created this script:

Step 1: Open a “Quick Development GUI’ window

panel.clear();
var textBox = panel.add_TextBox(true);
textBox.set_Text("hello world");

Step 2:

panel.clear();
RegistryKey currentUserKey = Registry.CurrentUser;
return currentUserKey;
//using Microsoft.Win32

Step 3:

panel.clear();
var subKeys = panel.add_TreeView();
RegistryKey currentUserKey = Registry.CurrentUser;
subKeys.add_Nodes(currentUserKey.GetSubKeyNames());return "ok";
//using Microsoft.Win32

Step 4:

panel.clear();
var subKeys = panel.add_TreeView();
RegistryKey currentUserKey = Registry.CurrentUser;subKeys.add_Nodes(currentUserKey.GetSubKeyNames());
return currentUserKey.OpenSubKey(currentUserKey.GetSubKeyNames()[0]);
return "ok";
//using Microsoft.Win32

Step 5:

panel.clear();
var subKeys = panel.add_TreeView();
subKeys.beforeExpand<RegistryKey>(
    (currentKey) => {
                        var currentNode = subKeys.selected();
                        currentNode.clear();
                       
                        "current key {0}".info(currentKey);
                      });
RegistryKey currentUserKey = Registry.CurrentUser;
subKeys.add_Node(Registry.CurrentUser.Name, Registry.CurrentUser ,true);
 
subKeys.add_Nodes(currentUserKey.GetSubKeyNames());
return currentUserKey.OpenSubKey(currentUserKey.GetSubKeyNames()[0]);
return "ok";
//using Microsoft.Win32

Step 6:

panel.clear();
var subKeys = panel.add_TreeView();
subKeys.beforeExpand<RegistryKey>(
    (currentKey) => {
                        var currentNode = subKeys.selected();
                        currentNode.clear();
                        foreach(var keyName in currentKey.GetSubKeyNames())
                            currentNode.add_Node(keyName, currentKey.OpenSubKey(keyName));
                        "current key {0}".info(currentKey);
                      });
RegistryKey currentUserKey = Registry.CurrentUser;
subKeys.add_Node(Registry.CurrentUser.Name, Registry.CurrentUser ,true);
 
subKeys.add_Nodes(currentUserKey.GetSubKeyNames());
return currentUserKey.OpenSubKey(currentUserKey.GetSubKeyNames()[0]);
return "ok";
//using Microsoft.Win32

Step 7:

panel.clear();
var subKeys = panel.add_TreeView();
subKeys.beforeExpand<RegistryKey>(
    (currentKey) => {
                        var currentNode = subKeys.selected();
                        currentNode.clear();
                        foreach(var keyName in currentKey.GetSubKeyNames())
                        {
                            var subKey = currentKey.OpenSubKey(keyName);
                            currentNode.add_Node(subKey.Name.remove(currentKey.Name+"\\"), subKey, subKey.GetSubKeyNames().size()>0);
                        }
                        "current key {0}".info(currentKey);
                      });
RegistryKey currentUserKey = Registry.CurrentUser;
subKeys.add_Node(Registry.CurrentUser.Name, Registry.CurrentUser ,true);
 return currentUserKey.OpenSubKey(currentUserKey.GetSubKeyNames()[0]);
return "ok";
//using Microsoft.Win32

Step 8:

panel.clear();
var registryKeys = panel.add_TreeView();
registryKeys.beforeExpand<RegistryKey>(
    (currentKey) => {
                        var currentNode = registryKeys.selected();
                        currentNode.clear();
                        foreach(var keyName in currentKey.GetSubKeyNames())
                        {
                            var subKey = currentKey.OpenSubKey(keyName);
                            currentNode.add_Node(subKey.Name.remove(currentKey.Name+"\\"), subKey, subKey.GetSubKeyNames().size()>0);
                        }
                        "current key {0}".info(currentKey);
                      });
var currentUserKey = Registry.CurrentUser;
registryKeys.add_Node(Registry.CurrentUser.Name, Registry.CurrentUser ,true);
 
return currentUserKey.GetValueNames();registryKeys.expand();
return "ok";
//using Microsoft.Win32

Step 9:

panel.clear();
var tableList = panel.add_TableList();
var registryKeys = tableList.insert_Left<Panel>(200).add_TreeView();
//var registryKeys = panel.add_TreeView();
registryKeys.beforeExpand<RegistryKey>(
    (currentKey) => {
                        var currentNode = registryKeys.selected();
                        currentNode.clear();
                        foreach(var keyName in currentKey.GetSubKeyNames())
                        {
                            var subKey = currentKey.OpenSubKey(keyName);
                            currentNode.add_Node(subKey.Name.remove(currentKey.Name+"\\"), subKey, subKey.GetSubKeyNames().size()>0);
                        }
                        "current key {0}".info(currentKey);
                      });
var currentUserKey = Registry.CurrentUser;
registryKeys.add_Node(Registry.CurrentUser.Name, Registry.CurrentUser ,true);
 
return currentUserKey.GetValueNames();registryKeys.expand();
return "ok";
//using Microsoft.Win32

Step 10:

panel.clear();
var tableList = panel.add_TableList();
var registryKeys = tableList.insert_Left<Panel>(200).add_TreeView();
//var registryKeys = panel.add_TreeView();
registryKeys.beforeExpand<RegistryKey>(
    (currentKey) => {
                        var currentNode = registryKeys.selected();
                        currentNode.clear();
                        foreach(var keyName in currentKey.GetSubKeyNames())
                        {
                            var subKey = currentKey.OpenSubKey(keyName);
                            currentNode.add_Node(subKey.Name.remove(currentKey.Name+"\\"), subKey, subKey.GetSubKeyNames().size()>0);
                        }
                        "current key {0}".info(currentKey);
                      });
registryKeys.afterSelect<RegistryKey>(                 
    (currentKey)=>{
                     tableList.clearTable();
                     tableList.add_Columns("Name");
                    
                  });
var currentUserKey = Registry.CurrentUser;
registryKeys.add_Node(Registry.CurrentUser.Name, Registry.CurrentUser ,true);
 
return currentUserKey.GetValueNames();registryKeys.expand();
return "ok";
//using Microsoft.Win32

Step 11:

panel.clear();
var tableList = panel.add_TableList();
var registryKeys = tableList.insert_Left<Panel>(200).add_TreeView();
//var registryKeys = panel.add_TreeView();
registryKeys.beforeExpand<RegistryKey>(
    (currentKey) => {
                        var currentNode = registryKeys.selected();
                        currentNode.clear();
                        foreach(var keyName in currentKey.GetSubKeyNames())
                        {
                            var subKey = currentKey.OpenSubKey(keyName);
                            currentNode.add_Node(subKey.Name.remove(currentKey.Name+"\\"), subKey, subKey.GetSubKeyNames().size()>0);
                        }
                        "current key {0}".info(currentKey);
                      });
registryKeys.afterSelect<RegistryKey>(                 
    (currentKey)=>{
                     tableList.clearTable();
                     tableList.add_Columns("Name"); 
                     foreach(var name in currentKey.GetValueNames())
                         tableList.add_Row(name);
                  });
var currentUserKey = Registry.CurrentUser;
registryKeys.add_Node(Registry.CurrentUser.Name, Registry.CurrentUser ,true);registryKeys.expand();
registryKeys.selectFirst();
return "ok";
//using Microsoft.Win32

Step 12:

panel.clear();
var tableList = panel.add_TableList();
var registryKeys = tableList.insert_Left<Panel>(200).add_TreeView();
//var registryKeys = panel.add_TreeView();
registryKeys.beforeExpand<RegistryKey>(
    (currentKey) => {
                        var currentNode = registryKeys.selected();
                        currentNode.clear();
                        foreach(var keyName in currentKey.GetSubKeyNames())
                        {
                            var subKey = currentKey.OpenSubKey(keyName);
                            currentNode.add_Node(subKey.Name.remove(currentKey.Name+"\\"), subKey, subKey.GetSubKeyNames().size()>0);
                        }
                        "current key {0}".info(currentKey);
                      });
registryKeys.afterSelect<RegistryKey>(                 
    (currentKey)=>{
                     tableList.clearTable();
                                         
                     tableList.add_Columns("Name", "Type", "Value"); 
                     foreach(var name in currentKey.GetValueNames())
                     {
                         var value = currentKey.GetValue(name);
                         tableList.add_Row(name, currentKey.GetValue(name).typeName());
                     }
                  });
var currentUserKey = Registry.CurrentUser;
registryKeys.add_Node(Registry.CurrentUser.Name, Registry.CurrentUser ,true);registryKeys.expand();
registryKeys.selectFirst();
return "ok";
//using Microsoft.Win32

Step 13:

panel.clear();
var tableList = panel.add_TableList();
var registryKeys = tableList.insert_Left<Panel>(200).add_TreeView();
//var registryKeys = panel.add_TreeView();
registryKeys.beforeExpand<RegistryKey>(
    (currentKey) => {
                        var currentNode = registryKeys.selected();
                        currentNode.clear();
                        foreach(var keyName in currentKey.GetSubKeyNames())
                        {
                            var subKey = currentKey.OpenSubKey(keyName);
                            currentNode.add_Node(subKey.Name.remove(currentKey.Name+"\\"), subKey, subKey.GetSubKeyNames().size()>0);
                        }
                        "current key {0}".info(currentKey);
                      });
registryKeys.afterSelect<RegistryKey>(                 
    (currentKey)=>{
                     tableList.clearTable();
                                         
                     tableList.add_Columns("Name", "Type", "Value"); 
                     foreach(var name in currentKey.GetValueNames())
                     {
                         var value = currentKey.GetValue(name);
                         tableList.add_Row(name, value.typeName(),value.str());
                     }
                     tableList.makeColumnWidthMatchCellWidth();
                  });
var currentUserKey = Registry.CurrentUser;
registryKeys.add_Node(Registry.CurrentUser.Name, Registry.CurrentUser ,true);registryKeys.expand();
registryKeys.selectFirst();
return "ok";
//using Microsoft.Win32

Step 14:

panel.clear();
var tableList = panel.add_TableList("Registy Values of Selected Key");
var registryKeys = tableList.insert_Left<Panel>(200).add_TreeView();
//var registryKeys = panel.add_TreeView();
registryKeys.beforeExpand<RegistryKey>(
    (currentKey) => {
                        var currentNode = registryKeys.selected();
                        currentNode.clear();
                        foreach(var keyName in currentKey.GetSubKeyNames())
                        {
                            var subKey = currentKey.OpenSubKey(keyName);
                            currentNode.add_Node(subKey.Name.remove(currentKey.Name+"\\"), subKey, subKey.GetSubKeyNames().size()>0);
                        }
                        "current key {0}".info(currentKey);
                      });
registryKeys.afterSelect<RegistryKey>(                 
    (currentKey)=>{
                     tableList.clearTable();
                                         
                     tableList.add_Columns("Name", "Type", "Value"); 
                     foreach(var name in currentKey.GetValueNames())
                     {
                         var value = currentKey.GetValue(name);
                         tableList.add_Row(name, value.typeName(),value.str());
                     }
                     tableList.makeColumnWidthMatchCellWidth();
                  });
//registryKeys.add_Node(Registry.ClassesRoot.Name, Registry.ClassesRoot ,true);  // this is quite resource intensive
registryKeys.add_Node(Registry.CurrentConfig.Name, Registry.CurrentConfig ,true);
registryKeys.add_Node(Registry.CurrentUser.Name, Registry.CurrentUser ,true);
registryKeys.add_Node(Registry.LocalMachine.Name, Registry.LocalMachine ,true);
registryKeys.add_Node(Registry.Users.Name, Registry.Users ,true);registryKeys.expand();
registryKeys.selectFirst();
return "ok";
//using Microsoft.Win32

Step 15:

//panel.clear();
var topPanel =  O2Gui.open<Panel>("Registry Viewer", 600,400);
var tableList = topPanel.add_TableList("Registy Values of Selected Key");
var registryKeys = tableList.insert_Left<Panel>(200).add_TreeView();
//var registryKeys = panel.add_TreeView();
registryKeys.beforeExpand<RegistryKey>(
    (currentKey) => {
                        var currentNode = registryKeys.selected();
                        currentNode.clear();
                        foreach(var keyName in currentKey.GetSubKeyNames())
                        {
                            var subKey = currentKey.OpenSubKey(keyName);
                            currentNode.add_Node(subKey.Name.remove(currentKey.Name+"\\"), subKey, subKey.GetSubKeyNames().size()>0);
                        }
                        "current key {0}".info(currentKey);
                      });
registryKeys.afterSelect<RegistryKey>(                 
    (currentKey)=>{
                     tableList.clearTable();
                                         
                     tableList.add_Columns("Name", "Type", "Value"); 
                     foreach(var name in currentKey.GetValueNames())
                     {
                         var value = currentKey.GetValue(name);
                         tableList.add_Row(name, value.typeName(),value.str());
                     }
                     tableList.makeColumnWidthMatchCellWidth();
                  });
//registryKeys.add_Node(Registry.ClassesRoot.Name, Registry.ClassesRoot ,true);  // this is quite resource intensive
//registryKeys.add_Node(Registry.CurrentConfig.Name, Registry.CurrentConfig ,true);
registryKeys.add_Node(Registry.CurrentUser.Name, Registry.CurrentUser ,true);
//registryKeys.add_Node(Registry.LocalMachine.Name, Registry.LocalMachine ,true);
//registryKeys.add_Node(Registry.Users.Name, Registry.Users ,true);registryKeys.expand();
registryKeys.selectFirst();
return "ok";
//using Microsoft.Win32

Step 16:

This is what it looks like when executed

 

March 4, 2011 - Posted by | Windows Tools

1 Comment »

  1. […] the APIs added here and the Registry Viewer added here, this next script shows a little tool that can be used to add sites directly into IE’s […]

    Pingback by O2 Util: Add sites to IE trusted zone « O2Platform.com for Developers | March 4, 2011 | Reply


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: