forked from BGDonLINE/PegasusHVNC
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathEmbeddedAssembly.cs
73 lines (70 loc) · 1.78 KB
/
EmbeddedAssembly.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Security.Cryptography;
public class EmbeddedAssembly
{
private static Dictionary<string, Assembly> dic;
public static void Load(string embeddedResource, string fileName)
{
if (dic == null)
{
dic = new Dictionary<string, Assembly>();
}
byte[] array = null;
using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(embeddedResource))
{
if (stream == null)
{
throw new Exception(embeddedResource + " is not found in Embedded Resources.");
}
array = new byte[(int)stream.Length];
stream.Read(array, 0, (int)stream.Length);
try
{
Assembly assembly = Assembly.Load(array);
dic.Add(assembly.FullName, assembly);
return;
}
catch
{
}
}
bool flag = false;
string path = "";
using (SHA1CryptoServiceProvider sHA1CryptoServiceProvider = new SHA1CryptoServiceProvider())
{
string text = BitConverter.ToString(sHA1CryptoServiceProvider.ComputeHash(array)).Replace("-", string.Empty);
path = Path.GetTempPath() + fileName;
if (File.Exists(path))
{
byte[] buffer = File.ReadAllBytes(path);
string text2 = BitConverter.ToString(sHA1CryptoServiceProvider.ComputeHash(buffer)).Replace("-", string.Empty);
flag = text == text2;
}
else
{
flag = false;
}
}
if (!flag)
{
File.WriteAllBytes(path, array);
}
Assembly assembly2 = Assembly.LoadFile(path);
dic.Add(assembly2.FullName, assembly2);
}
public static Assembly Get(string assemblyFullName)
{
if (dic == null || dic.Count == 0)
{
return null;
}
if (!dic.ContainsKey(assemblyFullName))
{
return null;
}
return dic[assemblyFullName];
}
}