2008-11-17 18:29:00 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2008-03-05 09:52:00 -05:00
|
|
|
//
|
|
|
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
|
|
//
|
2008-11-17 18:29:00 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
2008-03-05 09:52:00 -05:00
|
|
|
|
|
|
|
namespace ManifestReader
|
|
|
|
{
|
|
|
|
using System;
|
|
|
|
using System.IO;
|
|
|
|
using System.Collections;
|
|
|
|
using System.Xml;
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
|
|
public abstract class ManifestParser
|
|
|
|
{
|
|
|
|
public ManifestParser()
|
|
|
|
{
|
|
|
|
// do nothing for now
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Hashtable registryConflictTable = new Hashtable();
|
|
|
|
public static Hashtable provideFileTable = new Hashtable();
|
|
|
|
public static Hashtable requiresFileTable = new Hashtable();
|
|
|
|
public static Hashtable appFileTable = new Hashtable();
|
|
|
|
public static Hashtable appRegistryTable = new Hashtable();
|
|
|
|
public static Hashtable nameTable = new Hashtable();
|
|
|
|
public static Hashtable fileTypeTable = new Hashtable();
|
|
|
|
public static Hashtable customActionsTable = new Hashtable();
|
|
|
|
public static void addEntry(string path, string val, string appName)
|
|
|
|
{
|
|
|
|
if (!registryConflictTable.ContainsKey(path))
|
|
|
|
{
|
|
|
|
registryConflictTable[path] = new ArrayList();
|
|
|
|
}
|
|
|
|
Pair tempP = new Pair(val, appName);
|
|
|
|
((ArrayList)(registryConflictTable[path])).Add(tempP);
|
|
|
|
|
|
|
|
// also compute all the prefixes and put them in the appRegistryTable
|
2008-11-17 18:29:00 -05:00
|
|
|
if (!appRegistryTable.ContainsKey(appName)) {
|
2008-03-05 09:52:00 -05:00
|
|
|
appRegistryTable[appName] = new Hashtable();
|
|
|
|
}
|
|
|
|
string prefix = "";
|
|
|
|
string[] pathElts = path.Split(new char[] {'\\'}, 40);
|
2008-11-17 18:29:00 -05:00
|
|
|
for (int i = 0; i < pathElts.Length; i++) {
|
2008-03-05 09:52:00 -05:00
|
|
|
prefix += "\\" + pathElts[i];
|
2008-11-17 18:29:00 -05:00
|
|
|
if (!((Hashtable)appRegistryTable[appName]).ContainsKey(prefix)) {
|
2008-03-05 09:52:00 -05:00
|
|
|
((Hashtable)appRegistryTable[appName])[prefix] = 1;
|
|
|
|
}
|
2008-11-17 18:29:00 -05:00
|
|
|
else {
|
2008-03-05 09:52:00 -05:00
|
|
|
((Hashtable)appRegistryTable[appName])[prefix] = (int)((Hashtable)appRegistryTable[appName])[prefix] + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void addCustomAction(string appName)
|
|
|
|
{
|
|
|
|
if (!customActionsTable.ContainsKey(appName))
|
|
|
|
{
|
|
|
|
customActionsTable[appName] = 0;
|
|
|
|
}
|
|
|
|
customActionsTable[appName] = (int)customActionsTable[appName] + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void addProvidesFile(string path, string filename, string appName)
|
|
|
|
{
|
|
|
|
|
|
|
|
string file = path + "\\" + filename;
|
|
|
|
if (path.Equals("\\"))
|
|
|
|
{
|
|
|
|
file = "\\" + filename;
|
|
|
|
}
|
|
|
|
// grab off the suffix and put it in the file extension table
|
|
|
|
string[] fileComponents = filename.Split(new char[] {'.'}, 50);
|
|
|
|
string extension = fileComponents[fileComponents.Length - 1].ToLower();
|
|
|
|
if (fileComponents.Length > 1)
|
|
|
|
{
|
|
|
|
// then we probably have a real file extension (there's at least on '.')
|
|
|
|
if (!fileTypeTable.ContainsKey(appName))
|
|
|
|
{
|
|
|
|
// this hash maps file types to the count for this manifest
|
|
|
|
fileTypeTable[appName] = new Hashtable();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!((Hashtable)fileTypeTable[appName]).ContainsKey(extension))
|
|
|
|
{
|
|
|
|
((Hashtable)fileTypeTable[appName])[extension] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
((Hashtable)fileTypeTable[appName])[extension] = (int)((Hashtable)fileTypeTable[appName])[extension] + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!provideFileTable.ContainsKey(file))
|
|
|
|
{
|
|
|
|
provideFileTable[file] = new ArrayList();
|
|
|
|
}
|
|
|
|
((ArrayList)provideFileTable[file]).Add(appName);
|
|
|
|
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
if (!appFileTable.ContainsKey(appName)) {
|
2008-03-05 09:52:00 -05:00
|
|
|
appFileTable[appName] = new Hashtable();
|
|
|
|
}
|
|
|
|
|
2008-11-17 18:29:00 -05:00
|
|
|
if (!((Hashtable)appFileTable[appName]).ContainsKey(file)) {
|
2008-03-05 09:52:00 -05:00
|
|
|
((Hashtable)appFileTable[appName])[file] = 1;
|
|
|
|
}
|
2008-11-17 18:29:00 -05:00
|
|
|
else {
|
2008-03-05 09:52:00 -05:00
|
|
|
((Hashtable)appFileTable[appName])[file] = (int)((Hashtable)appFileTable[appName])[file] + 1;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void addRequiresFile(string path, string filename, string appName)
|
|
|
|
{
|
|
|
|
string file = path + "\\" + filename;
|
|
|
|
|
|
|
|
if (!requiresFileTable.ContainsKey(file))
|
|
|
|
{
|
|
|
|
// I don't care if I end up adding it twice: I'll sort it out in the end
|
|
|
|
requiresFileTable[file] = new ArrayList();
|
|
|
|
}
|
|
|
|
((ArrayList)requiresFileTable[file]).Add(appName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void setName(string appPathName, string appTrueName)
|
|
|
|
{
|
|
|
|
nameTable[appPathName] = appTrueName;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract Hashtable Parse(string appName, string file, Hashtable elementTranslator);
|
|
|
|
|
|
|
|
protected bool isCodeSuffix(string suffix)
|
|
|
|
{
|
|
|
|
return suffix.Equals("exe") ||
|
|
|
|
suffix.Equals("dll") ||
|
|
|
|
suffix.Equals("com") ||
|
|
|
|
suffix.Equals("bin") ||
|
|
|
|
suffix.Equals("ocx") ||
|
|
|
|
suffix.Equals("sys");
|
|
|
|
}
|
|
|
|
|
|
|
|
protected bool isImageSuffix(string suffix)
|
|
|
|
{
|
|
|
|
return suffix.Equals("avi") ||
|
|
|
|
suffix.Equals("bmp") ||
|
|
|
|
suffix.Equals("gif") ||
|
|
|
|
suffix.Equals("tif") ||
|
|
|
|
suffix.Equals("xbm") ||
|
|
|
|
suffix.Equals("jpg") ||
|
|
|
|
suffix.Equals("ico");
|
|
|
|
}
|
|
|
|
|
|
|
|
protected bool isFontSuffix(string suffix)
|
|
|
|
{
|
|
|
|
return suffix.Equals("ttf") ||
|
|
|
|
suffix.Equals("fon");
|
|
|
|
}
|
|
|
|
|
|
|
|
protected string getCodeType(string suffix)
|
|
|
|
{
|
|
|
|
if (suffix.Equals("exe") ||
|
|
|
|
suffix.Equals("com"))
|
|
|
|
{
|
|
|
|
return "Code NonLinked";
|
|
|
|
}
|
|
|
|
else if (suffix.Equals("ocx") ||
|
|
|
|
suffix.Equals("sys"))
|
|
|
|
{
|
|
|
|
return "Code Linked Dynamic";
|
|
|
|
}
|
|
|
|
// despite the name, if it's a DLL, we can't tell
|
2008-11-17 18:29:00 -05:00
|
|
|
else if (suffix.Equals("dll")) {
|
2008-03-05 09:52:00 -05:00
|
|
|
return "Code";
|
|
|
|
}
|
|
|
|
return "Code";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// grab the Hashtable that will give us the paths for Manifest elements
|
|
|
|
public static Hashtable GetManifestHashtable(string filename)
|
|
|
|
{
|
|
|
|
StreamReader ios = new StreamReader(filename);
|
|
|
|
Hashtable outTable = new Hashtable();
|
|
|
|
string curLine;
|
2008-11-17 18:29:00 -05:00
|
|
|
while ((curLine = ios.ReadLine()) != null)
|
2008-03-05 09:52:00 -05:00
|
|
|
{
|
|
|
|
// take the first word, and leave the rest
|
|
|
|
int firstSpaceIndex = curLine.IndexOf(' ');
|
|
|
|
string first = curLine.Substring(0, firstSpaceIndex);
|
|
|
|
//"Got first = ***{0}***", first);
|
|
|
|
string rest = curLine.Substring(firstSpaceIndex + 1);
|
|
|
|
//"Got rest = ***{0}***", rest);
|
|
|
|
outTable[first] = rest;
|
|
|
|
}
|
|
|
|
return outTable;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected string parseRegistry(string fullpath, string val, string file)
|
|
|
|
{
|
|
|
|
// just add this Registry entry to the Hashtable
|
|
|
|
ManifestParser.addEntry(fullpath, val, file);
|
|
|
|
|
|
|
|
// split off the first two elements from the path
|
|
|
|
string[] components = fullpath.Split(new char[] {'\\'}, 10);
|
|
|
|
string rootname = components[0];
|
|
|
|
string toplevelname = components[1];
|
|
|
|
if (rootname.Equals("HKCR"))
|
|
|
|
{
|
|
|
|
if (toplevelname.Equals("CLSID") ||
|
|
|
|
toplevelname.Equals("Interface"))
|
|
|
|
{
|
|
|
|
return "Code NonLinked";
|
|
|
|
}
|
|
|
|
}
|
2008-11-17 18:29:00 -05:00
|
|
|
else if (rootname.Equals("HKCU")) {
|
2008-03-05 09:52:00 -05:00
|
|
|
if (toplevelname.Equals("Printers"))
|
|
|
|
{
|
|
|
|
return "Code NonLinked";
|
|
|
|
}
|
|
|
|
}
|
2008-11-17 18:29:00 -05:00
|
|
|
else if (rootname.Equals("HKLM")) {
|
2008-03-05 09:52:00 -05:00
|
|
|
if (toplevelname.Equals("HARDWARE"))
|
|
|
|
{
|
|
|
|
return "Hardware";
|
|
|
|
}
|
2008-11-17 18:29:00 -05:00
|
|
|
else if (toplevelname.Equals("SYSTEM")) {
|
2008-03-05 09:52:00 -05:00
|
|
|
return "Data Config Settings Permanent";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "Data Config Settings";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|