Esempio n. 1
0
        protected override bool checkHandlerMethod(MethodDefinition method)
        {
            if (!method.IsStatic || !method.HasBody)
                return false;

            EmbeddedAssemblyInfo info = 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;

                info = assemblyResolverInfo.find(Utils.getAssemblySimpleName(s));
                if (info != null)
                    break;
            }
            if (info == null)
                return false;

            resourceInfo = info;
            Log.v("Found embedded assemblies resource {0}", Utils.toCsharpString(info.resourceName));
            return true;
        }
Esempio n. 2
0
        public static EmbeddedAssemblyInfo create(ModuleDefinition module, string encName, string rsrcName)
        {
            var info = new EmbeddedAssemblyInfo();

            try {
                if (encName == "" || Convert.ToBase64String(Convert.FromBase64String(encName)) != encName)
                    return null;
            }
            catch (FormatException) {
                return null;
            }

            if (rsrcName.Length > 0 && rsrcName[0] == '[') {
                int i = rsrcName.IndexOf(']');
                if (i < 0)
                    return null;
                info.flags = rsrcName.Substring(1, i - 1);
                info.isTempFile = info.flags.IndexOf('t') >= 0;
                info.isCompressed = info.flags.IndexOf('z') >= 0;
                rsrcName = rsrcName.Substring(i + 1);
            }
            if (rsrcName == "")
                return null;

            info.assemblyName = Encoding.UTF8.GetString(Convert.FromBase64String(encName));
            info.resourceName = rsrcName;
            info.resource = DotNetUtils.getResource(module, rsrcName) as EmbeddedResource;
            info.simpleName = Utils.getAssemblySimpleName(info.assemblyName);

            return info;
        }
Esempio n. 3
0
        public byte[] removeDecryptedResource(EmbeddedAssemblyInfo info)
        {
            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;
        }
Esempio n. 4
0
 byte[] decryptResource(EmbeddedAssemblyInfo info)
 {
     if (info.isCompressed)
         return resourceDecrypter.decrypt(info.resource);
     else
         return info.resource.GetResourceData();
 }
Esempio n. 5
0
 public bool canDecryptResource(EmbeddedAssemblyInfo info)
 {
     if (info == null || !info.isCompressed)
         return true;
     return resourceDecrypter.CanDecrypt;
 }