This commit is contained in:
parent
ec9c57b6ca
commit
79340a9197
|
|
@ -12,11 +12,11 @@ namespace mScriptableCS25;
|
|||
public class MainScriptingObject : IDisposable
|
||||
{
|
||||
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 tempPath = Path.GetTempPath();
|
||||
string tempPath = Path.GetTempPath() + @"TmpVbsScripts" + Path.DirectorySeparatorChar;
|
||||
Dictionary<string, Dictionary<string, string>>? dctCache = null;
|
||||
Dictionary<string, MdlVbsSources> dctFileCache = new(StringComparer.OrdinalIgnoreCase);
|
||||
Dictionary<string, MdlVbsSources> dctFileCache = new();//(StringComparer.OrdinalIgnoreCase);
|
||||
Random rn = new();
|
||||
List<string> lstFilesToRemove = new();
|
||||
bool removedOldScripts = false;
|
||||
|
|
@ -25,6 +25,8 @@ public class MainScriptingObject : IDisposable
|
|||
{
|
||||
if (dctCache != null)
|
||||
dctCache.Clear();
|
||||
if (dctFileCache != null)
|
||||
dctFileCache.Clear();
|
||||
}
|
||||
|
||||
public bool HadErrors { get; set; } = false;
|
||||
|
|
@ -60,10 +62,12 @@ public class MainScriptingObject : IDisposable
|
|||
}
|
||||
if (File.Exists(f))
|
||||
File.Delete(f);
|
||||
|
||||
tempPath = Path.GetDirectoryName(f);
|
||||
}
|
||||
catch
|
||||
{
|
||||
tempPath = Path.GetTempPath();
|
||||
tempPath = Path.GetTempPath() + @"TmpVbsScripts" + Path.DirectorySeparatorChar;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -71,11 +75,12 @@ public class MainScriptingObject : IDisposable
|
|||
public bool SetScriptFromFile(string VBScriptPath)
|
||||
{
|
||||
var rv = false;
|
||||
var theKey = SHA256Hash(VBScriptPath);
|
||||
|
||||
if (dctFileCache.ContainsKey(VBScriptPath))
|
||||
if (dctFileCache.ContainsKey(theKey))
|
||||
{
|
||||
scriptSource = dctFileCache[VBScriptPath].VbsScriptSource;
|
||||
dctCache = dctFileCache[VBScriptPath].CacheDict;
|
||||
scriptSource = dctFileCache[theKey].VbsScriptSource;
|
||||
dctCache = dctFileCache[theKey].CacheDict;
|
||||
rv = true;
|
||||
}
|
||||
else
|
||||
|
|
@ -93,8 +98,9 @@ public class MainScriptingObject : IDisposable
|
|||
scriptSource = sr.ReadToEnd();
|
||||
|
||||
z.VbsScriptSource = scriptSource;
|
||||
dctCache = z.CacheDict;
|
||||
dctFileCache[VBScriptPath] = z;
|
||||
z.CacheDict = new();
|
||||
dctFileCache[theKey] = z;
|
||||
dctCache = dctFileCache[theKey].CacheDict;
|
||||
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 outFile = Path.Combine(tempPath, tStamp + ".txt");
|
||||
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 retVals = string.Empty;
|
||||
var varName = string.Empty;
|
||||
|
|
@ -151,7 +158,7 @@ public class MainScriptingObject : IDisposable
|
|||
HadErrors = false;
|
||||
lstFilesToRemove.Add(outFile);
|
||||
lstFilesToRemove.Add(scriptFile);
|
||||
if (UseCache && dctCache.ContainsKey(iKey))
|
||||
if (UseCache && dctCache != null && dctCache.ContainsKey(iKey))
|
||||
toReturn = dctCache[iKey];
|
||||
else
|
||||
{
|
||||
|
|
@ -173,6 +180,9 @@ public class MainScriptingObject : IDisposable
|
|||
genCodeHeader.AppendLine("'* Revised in 2015 by KeyMotive LLC (Rich Deck) *");
|
||||
genCodeHeader.AppendLine("'* Refreshed in 2025 by KeyMotive LLC (Rich Deck)*");
|
||||
genCodeHeader.AppendLine("'*************************************************");
|
||||
genCodeHeader.AppendLine("'Non-Crypto Lookup: " + iClearValues);
|
||||
genCodeHeader.AppendLine("'Crypto Lookup: " + iKey);
|
||||
genCodeHeader.AppendLine("'*************************************************");
|
||||
|
||||
genCodeHeader.AppendLine("outFile = \"" + outFile + "\"");
|
||||
//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;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -338,6 +348,9 @@ public class MainScriptingObject : IDisposable
|
|||
return gx;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region "Crypto stuff"
|
||||
internal string SHA1Hash(string strToHash)
|
||||
{
|
||||
var rv = new StringBuilder();
|
||||
|
|
@ -356,8 +369,61 @@ public class MainScriptingObject : IDisposable
|
|||
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
|
||||
|
||||
|
||||
#region "Models and Such"
|
||||
internal class MdlVbsSources : IDisposable
|
||||
{
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@
|
|||
<TargetFramework>net9.0-windows</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<AssemblyVersion>1.2.0.8</AssemblyVersion>
|
||||
<FileVersion>1.2.0.8</FileVersion>
|
||||
<Version>1.0.0.8</Version>
|
||||
<AssemblyVersion>1.2.0.21</AssemblyVersion>
|
||||
<FileVersion>1.2.0.21</FileVersion>
|
||||
<Version>1.0.0.21</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<Target Name="PreBuild" BeforeTargets="PreBuildEvent">
|
||||
|
|
|
|||
Loading…
Reference in New Issue