This commit is contained in:
parent
ec9c57b6ca
commit
79340a9197
|
|
@ -12,11 +12,11 @@ namespace mScriptableCS25;
|
||||||
public class MainScriptingObject : IDisposable
|
public class MainScriptingObject : IDisposable
|
||||||
{
|
{
|
||||||
SortedDictionary<string, string> scrInp1 = new(StringComparer.OrdinalIgnoreCase);
|
SortedDictionary<string, string> scrInp1 = new(StringComparer.OrdinalIgnoreCase);
|
||||||
SortedDictionary<string, string> scrInp2 = new(StringComparer.OrdinalIgnoreCase); //This will have the STRIPUNPRINTABLES applied to it
|
SortedDictionary<string, string> scrInp2 = new(StringComparer.OrdinalIgnoreCase); //This will have the STRIPUNPRINTABLES applied to it (so we can cache it)
|
||||||
string scriptSource = string.Empty;
|
string scriptSource = string.Empty;
|
||||||
string tempPath = Path.GetTempPath();
|
string tempPath = Path.GetTempPath() + @"TmpVbsScripts" + Path.DirectorySeparatorChar;
|
||||||
Dictionary<string, Dictionary<string, string>>? dctCache = null;
|
Dictionary<string, Dictionary<string, string>>? dctCache = null;
|
||||||
Dictionary<string, MdlVbsSources> dctFileCache = new(StringComparer.OrdinalIgnoreCase);
|
Dictionary<string, MdlVbsSources> dctFileCache = new();//(StringComparer.OrdinalIgnoreCase);
|
||||||
Random rn = new();
|
Random rn = new();
|
||||||
List<string> lstFilesToRemove = new();
|
List<string> lstFilesToRemove = new();
|
||||||
bool removedOldScripts = false;
|
bool removedOldScripts = false;
|
||||||
|
|
@ -25,6 +25,8 @@ public class MainScriptingObject : IDisposable
|
||||||
{
|
{
|
||||||
if (dctCache != null)
|
if (dctCache != null)
|
||||||
dctCache.Clear();
|
dctCache.Clear();
|
||||||
|
if (dctFileCache != null)
|
||||||
|
dctFileCache.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HadErrors { get; set; } = false;
|
public bool HadErrors { get; set; } = false;
|
||||||
|
|
@ -60,10 +62,12 @@ public class MainScriptingObject : IDisposable
|
||||||
}
|
}
|
||||||
if (File.Exists(f))
|
if (File.Exists(f))
|
||||||
File.Delete(f);
|
File.Delete(f);
|
||||||
|
|
||||||
|
tempPath = Path.GetDirectoryName(f);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
tempPath = Path.GetTempPath();
|
tempPath = Path.GetTempPath() + @"TmpVbsScripts" + Path.DirectorySeparatorChar;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -71,11 +75,12 @@ public class MainScriptingObject : IDisposable
|
||||||
public bool SetScriptFromFile(string VBScriptPath)
|
public bool SetScriptFromFile(string VBScriptPath)
|
||||||
{
|
{
|
||||||
var rv = false;
|
var rv = false;
|
||||||
|
var theKey = SHA256Hash(VBScriptPath);
|
||||||
|
|
||||||
if (dctFileCache.ContainsKey(VBScriptPath))
|
if (dctFileCache.ContainsKey(theKey))
|
||||||
{
|
{
|
||||||
scriptSource = dctFileCache[VBScriptPath].VbsScriptSource;
|
scriptSource = dctFileCache[theKey].VbsScriptSource;
|
||||||
dctCache = dctFileCache[VBScriptPath].CacheDict;
|
dctCache = dctFileCache[theKey].CacheDict;
|
||||||
rv = true;
|
rv = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -93,8 +98,9 @@ public class MainScriptingObject : IDisposable
|
||||||
scriptSource = sr.ReadToEnd();
|
scriptSource = sr.ReadToEnd();
|
||||||
|
|
||||||
z.VbsScriptSource = scriptSource;
|
z.VbsScriptSource = scriptSource;
|
||||||
dctCache = z.CacheDict;
|
z.CacheDict = new();
|
||||||
dctFileCache[VBScriptPath] = z;
|
dctFileCache[theKey] = z;
|
||||||
|
dctCache = dctFileCache[theKey].CacheDict;
|
||||||
rv = true;
|
rv = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -142,7 +148,8 @@ public class MainScriptingObject : IDisposable
|
||||||
var tStamp = string.Format("TmpVbsScript-{0:yyyyMMddHHmmssfff}-{1}", DateTime.Now, Guid.NewGuid().ToString("N").Substring(0, 12));
|
var tStamp = string.Format("TmpVbsScript-{0:yyyyMMddHHmmssfff}-{1}", DateTime.Now, Guid.NewGuid().ToString("N").Substring(0, 12));
|
||||||
var outFile = Path.Combine(tempPath, tStamp + ".txt");
|
var outFile = Path.Combine(tempPath, tStamp + ".txt");
|
||||||
var scriptFile = Path.Combine(tempPath, tStamp + ".vbs");
|
var scriptFile = Path.Combine(tempPath, tStamp + ".vbs");
|
||||||
var iKey = SHA1Hash(string.Join('\t', scrInp2.ToArray()));
|
var iClearValues = string.Join('\t', scrInp2.ToArray());
|
||||||
|
var iKey = SHA256Hash(iClearValues);
|
||||||
var toReturn = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
var toReturn = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||||
var retVals = string.Empty;
|
var retVals = string.Empty;
|
||||||
var varName = string.Empty;
|
var varName = string.Empty;
|
||||||
|
|
@ -151,7 +158,7 @@ public class MainScriptingObject : IDisposable
|
||||||
HadErrors = false;
|
HadErrors = false;
|
||||||
lstFilesToRemove.Add(outFile);
|
lstFilesToRemove.Add(outFile);
|
||||||
lstFilesToRemove.Add(scriptFile);
|
lstFilesToRemove.Add(scriptFile);
|
||||||
if (UseCache && dctCache.ContainsKey(iKey))
|
if (UseCache && dctCache != null && dctCache.ContainsKey(iKey))
|
||||||
toReturn = dctCache[iKey];
|
toReturn = dctCache[iKey];
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -173,6 +180,9 @@ public class MainScriptingObject : IDisposable
|
||||||
genCodeHeader.AppendLine("'* Revised in 2015 by KeyMotive LLC (Rich Deck) *");
|
genCodeHeader.AppendLine("'* Revised in 2015 by KeyMotive LLC (Rich Deck) *");
|
||||||
genCodeHeader.AppendLine("'* Refreshed in 2025 by KeyMotive LLC (Rich Deck)*");
|
genCodeHeader.AppendLine("'* Refreshed in 2025 by KeyMotive LLC (Rich Deck)*");
|
||||||
genCodeHeader.AppendLine("'*************************************************");
|
genCodeHeader.AppendLine("'*************************************************");
|
||||||
|
genCodeHeader.AppendLine("'Non-Crypto Lookup: " + iClearValues);
|
||||||
|
genCodeHeader.AppendLine("'Crypto Lookup: " + iKey);
|
||||||
|
genCodeHeader.AppendLine("'*************************************************");
|
||||||
|
|
||||||
genCodeHeader.AppendLine("outFile = \"" + outFile + "\"");
|
genCodeHeader.AppendLine("outFile = \"" + outFile + "\"");
|
||||||
//get our file I/O initialized. This assumes we have write
|
//get our file I/O initialized. This assumes we have write
|
||||||
|
|
@ -277,7 +287,7 @@ public class MainScriptingObject : IDisposable
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (UseCache)
|
if (UseCache && dctCache != null)
|
||||||
dctCache[iKey] = toReturn;
|
dctCache[iKey] = toReturn;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
@ -338,6 +348,9 @@ public class MainScriptingObject : IDisposable
|
||||||
return gx;
|
return gx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region "Crypto stuff"
|
||||||
internal string SHA1Hash(string strToHash)
|
internal string SHA1Hash(string strToHash)
|
||||||
{
|
{
|
||||||
var rv = new StringBuilder();
|
var rv = new StringBuilder();
|
||||||
|
|
@ -356,8 +369,61 @@ public class MainScriptingObject : IDisposable
|
||||||
return rv.ToString();
|
return rv.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal string SHA256Hash(string strToHash)
|
||||||
|
{
|
||||||
|
var rv = new StringBuilder();
|
||||||
|
|
||||||
|
using (var sha = SHA256.Create())
|
||||||
|
{
|
||||||
|
byte[] bytes = Encoding.UTF8.GetBytes(strToHash);
|
||||||
|
byte[] hash = sha.ComputeHash(bytes);
|
||||||
|
|
||||||
|
foreach (byte x in hash)
|
||||||
|
{
|
||||||
|
rv.AppendFormat("{0:x2}", x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rv.ToString();
|
||||||
|
}
|
||||||
|
internal string SHA384Hash(string strToHash)
|
||||||
|
{
|
||||||
|
var rv = new StringBuilder();
|
||||||
|
|
||||||
|
using (var sha = SHA384.Create())
|
||||||
|
{
|
||||||
|
byte[] bytes = Encoding.UTF8.GetBytes(strToHash);
|
||||||
|
byte[] hash = sha.ComputeHash(bytes);
|
||||||
|
|
||||||
|
foreach (byte x in hash)
|
||||||
|
{
|
||||||
|
rv.AppendFormat("{0:x2}", x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rv.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
internal string SHA512Hash(string strToHash)
|
||||||
|
{
|
||||||
|
var rv = new StringBuilder();
|
||||||
|
|
||||||
|
using (var sha = SHA512.Create())
|
||||||
|
{
|
||||||
|
byte[] bytes = Encoding.UTF8.GetBytes(strToHash);
|
||||||
|
byte[] hash = sha.ComputeHash(bytes);
|
||||||
|
|
||||||
|
foreach (byte x in hash)
|
||||||
|
{
|
||||||
|
rv.AppendFormat("{0:x2}", x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return rv.ToString();
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
#region "Models and Such"
|
#region "Models and Such"
|
||||||
internal class MdlVbsSources : IDisposable
|
internal class MdlVbsSources : IDisposable
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -4,9 +4,9 @@
|
||||||
<TargetFramework>net9.0-windows</TargetFramework>
|
<TargetFramework>net9.0-windows</TargetFramework>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<AssemblyVersion>1.2.0.8</AssemblyVersion>
|
<AssemblyVersion>1.2.0.21</AssemblyVersion>
|
||||||
<FileVersion>1.2.0.8</FileVersion>
|
<FileVersion>1.2.0.21</FileVersion>
|
||||||
<Version>1.0.0.8</Version>
|
<Version>1.0.0.21</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
|
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue