本文整理汇总了C#中Mono.Cecil.EmbeddedResource类的典型用法代码示例。如果您正苦于以下问题:C# EmbeddedResource类的具体用法?C# EmbeddedResource怎么用?C# EmbeddedResource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EmbeddedResource类属于Mono.Cecil命名空间,在下文中一共展示了EmbeddedResource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: decrypt
public byte[] decrypt(EmbeddedResource resource)
{
if (!CanDecrypt)
throw new ApplicationException("Can't decrypt resources");
var encryptedData = resource.GetResourceData();
return decrypt(encryptedData);
}
示例2: checkHandlerMethod
protected override bool checkHandlerMethod(MethodDefinition method)
{
if (!method.IsStatic || !method.HasBody)
return false;
EmbeddedResource resource = null;
var instructions = method.Body.Instructions;
for (int i = 0; i < instructions.Count; i++) {
var instrs = DotNetUtils.getInstructions(instructions, i, OpCodes.Ldstr, OpCodes.Call);
if (instrs == null)
continue;
var s = instrs[0].Operand as string;
var calledMethod = instrs[1].Operand as MethodReference;
if (s == null || calledMethod == null)
continue;
resource = DotNetUtils.getResource(module, SA_Utils.getAssemblySimpleName(s)) as EmbeddedResource;
if (resource != null)
break;
}
if (resource == null)
return false;
embeddedAssembliesResource = resource;
Log.v("Found embedded assemblies resource {0}", Utils.toCsharpString(embeddedAssembliesResource.Name));
return true;
}
示例3: canDecryptResource
public bool canDecryptResource(EmbeddedResource resource)
{
var info = getEmbeddedAssemblyInfo(resource);
if (info == null || !info.isCompressed)
return true;
return resourceDecrypter.CanDecrypt;
}
示例4: Embedd
void Embedd(string fullPath)
{
logger.LogMessage(string.Format("\tEmbedding '{0}'", fullPath));
var fileStream = File.OpenRead(fullPath);
streams.Add(fileStream);
var resource = new EmbeddedResource("costura." + Path.GetFileName(fullPath).ToLowerInvariant(), ManifestResourceAttributes.Private, fileStream);
moduleReader.Module.Resources.Add(resource);
}
示例5: Process
public void Process(EmbeddedResource embeddedResource, ResourceWriter resourceWriter)
{
if (_bamlStreams.Count == 0)
return;
WriteCollectedBamlStreams(resourceWriter);
PatchGenericThemesBaml(resourceWriter);
}
示例6: Csvm
public Csvm(IDeobfuscatorContext deobfuscatorContext, ModuleDefinition module, Csvm oldOne)
{
this.deobfuscatorContext = deobfuscatorContext;
this.module = module;
if (oldOne.resource != null)
this.resource = (EmbeddedResource)module.Resources[oldOne.module.Resources.IndexOf(oldOne.resource)];
if (oldOne.vmAssemblyReference != null)
this.vmAssemblyReference = module.AssemblyReferences[oldOne.module.AssemblyReferences.IndexOf(oldOne.vmAssemblyReference)];
}
示例7: VisitEmbeddedResource
public override void VisitEmbeddedResource(EmbeddedResource res)
{
// TODO: Description?
IResourceWriter resourceWriter = module.Builder.DefineResource(res.Name, "",
(System.Reflection.ResourceAttributes)res.Flags);
resourceWriter.AddResource(res.Name, res.Data);
resourceWriter.Generate();
}
示例8: AddResourceFile
/// <summary>
/// Adds infromation about embedded resource file in Mono.Cecil format into list.
/// </summary>
/// <param name="item">Embedded resouce file information in Mono.Cecil format.</param>
/// <param name="count">Number of recource items in this resouce file.</param>
public void AddResourceFile(
EmbeddedResource item,
UInt32 count)
{
var correctFileName = Path.ChangeExtension(item.Name, ".tinyresources");
var nameStringId = _context.StringTable.GetOrCreateStringId(correctFileName);
_resouces.Add(new Tuple<UInt16, UInt32>(nameStringId, count));
}
示例9: Embed
private string Embed(string prefix, string fullPath, bool compress)
{
var resourceName = String.Format("{0}{1}", prefix, Path.GetFileName(fullPath).ToLowerInvariant());
if (ModuleDefinition.Resources.Any(x => x.Name == resourceName))
{
LogInfo(string.Format("\tSkipping '{0}' because it is already embedded", fullPath));
return resourceName;
}
if (compress)
{
resourceName = String.Format("{0}{1}.zip", prefix, Path.GetFileName(fullPath).ToLowerInvariant());
}
LogInfo(string.Format("\tEmbedding '{0}'", fullPath));
var checksum = CalculateChecksum(fullPath);
var cacheFile = Path.Combine(cachePath, String.Format("{0}.{1}", checksum, resourceName));
var memoryStream = new MemoryStream();
if (File.Exists(cacheFile))
{
using (var fileStream = File.Open(cacheFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
fileStream.CopyTo(memoryStream);
}
}
else
{
using (var cacheFileStream = File.Open(cacheFile, FileMode.CreateNew, FileAccess.Write, FileShare.Read))
{
using (var fileStream = File.Open(fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
if (compress)
{
using (var compressedStream = new DeflateStream(memoryStream, CompressionMode.Compress, true))
{
fileStream.CopyTo(compressedStream);
}
}
else
{
fileStream.CopyTo(memoryStream);
}
}
memoryStream.Position = 0;
memoryStream.CopyTo(cacheFileStream);
}
}
memoryStream.Position = 0;
streams.Add(memoryStream);
var resource = new EmbeddedResource(resourceName, ManifestResourceAttributes.Private, memoryStream);
ModuleDefinition.Resources.Add(resource);
return resourceName;
}
示例10: RelativeBasedOnNamespace
public void RelativeBasedOnNamespace()
{
var expected = new EmbeddedResource("AssemblyName.Namespace1.ResourceName", ManifestResourceAttributes.Public, (Stream) null);
var definition = ModuleDefinition.CreateModule("AssemblyName", ModuleKind.Dll);
definition.Resources.Add(expected);
var moduleWeaver = new ModuleWeaver
{
ModuleDefinition = definition
};
var actual = moduleWeaver.FindResource("ResourceName", "AssemblyName.Namespace1", null, null);
Assert.AreEqual(expected, actual);
}
示例11: RelativeBasedOnDirUpTwoLevelsMultipleNamespaces
public void RelativeBasedOnDirUpTwoLevelsMultipleNamespaces()
{
var expected = new EmbeddedResource("AssemblyName.ResourceName", ManifestResourceAttributes.Public, (Stream) null);
var definition = ModuleDefinition.CreateModule("AssemblyName", ModuleKind.Dll);
definition.Resources.Add(expected);
var moduleWeaver = new ModuleWeaver
{
ModuleDefinition = definition
};
var actual = moduleWeaver.FindResource(@"..\..\ResourceName", "BadPrefix", @"Namespace1\Namespace2", null);
Assert.AreEqual(expected, actual);
}
示例12: Main
static void Main(string[] args)
{
// TODO: Smarter handling of command line parameters if there ever are additional ones
if (args.Length < 4 || args.Length == 5 || args.Length > 6)
{
Console.Error.WriteLine("Expected arguments: <Assembly-Path> <New-Assembly-Path> <Resource-Name> <Resource-Path> [-snk <Strong-Name-Key-Path>]");
Environment.Exit(1);
}
else if (args.Length == 6 && args[4] != "-snk")
{
Console.Error.WriteLine("Available options are:");
Console.Error.WriteLine("\t-snk: Path to strong name key file (.snk).");
Environment.Exit(1);
}
var assemblyPath = args[0];
var newAssemblyPath = args[1];
var resourceName = args[2];
var resourcePath = args[3];
var snkPath = args.Length == 6 ? args[5] : null;
var assemblyDef = AssemblyDefinition.ReadAssembly(assemblyPath);
Console.WriteLine("Loaded assembly " + assemblyDef);
// TODO: Support other modules than MainModule
var resources = assemblyDef.MainModule.Resources;
var selectedResource = resources.FirstOrDefault(x => x.Name == resourceName);
if (selectedResource != null)
{
var newResource = new EmbeddedResource(resourceName, selectedResource.Attributes, File.ReadAllBytes(resourcePath));
resources.Remove(selectedResource);
resources.Add(newResource);
if (snkPath == null)
assemblyDef.Write(newAssemblyPath);
else
{
Console.WriteLine("Using strong name key file " + snkPath);
assemblyDef.Write(newAssemblyPath, new WriterParameters() { StrongNameKeyPair = new StrongNameKeyPair(File.ReadAllBytes(snkPath)) });
}
Console.WriteLine("Replaced embedded resource " + resourceName + " successfully!");
}
else
{
Console.Error.WriteLine("Could not find a resource with name " + resourceName);
Console.Error.WriteLine("Available resources: " + String.Join(", ", resources.Select(x => x.Name).DefaultIfEmpty("<none>")));
}
}
示例13: removeDecryptedResource
public byte[] removeDecryptedResource(EmbeddedResource resource)
{
if (resource == null)
return null;
var info = getEmbeddedAssemblyInfo(resource);
if (info == null)
return null;
var data = decryptResource(info);
if (!assemblyResolverInfo.EmbeddedAssemblyInfos.Remove(info))
throw new ApplicationException(string.Format("Could not remove resource {0}", Utils.toCsharpString(info.resourceName)));
return data;
}
示例14: initialize
public void initialize()
{
if (resolveHandler == null)
return;
if (isV3) {
simpleDeobfuscator.deobfuscate(resolveHandler);
simpleDeobfuscator.decryptStrings(resolveHandler, deob);
resource = DeobUtils.getEmbeddedResourceFromCodeStrings(module, resolveHandler);
if (resource == null) {
Log.w("Could not find resource of encrypted resources");
return;
}
}
}
示例15: decryptResource
byte[] decryptResource(EmbeddedResource resource)
{
using (var rsrcStream = resource.GetResourceStream()) {
using (var reader = new BinaryReader(rsrcStream)) {
var key = reader.ReadString();
var data = reader.ReadBytes((int)(rsrcStream.Length - rsrcStream.Position));
var cryptoTransform = new DESCryptoServiceProvider {
Key = Encoding.ASCII.GetBytes(key),
IV = Encoding.ASCII.GetBytes(key),
}.CreateDecryptor();
var memStream = new MemoryStream(data);
using (var reader2 = new BinaryReader(new CryptoStream(memStream, cryptoTransform, CryptoStreamMode.Read))) {
return reader2.ReadBytes((int)memStream.Length);
}
}
}
}