コード例 #1
0
        public static int EncryptMethod(
            [NotNull] SmaliMethod method,
            [NotNull] string className,
            [NotNull] Dictionary <string, SmaliMethod> methods
            )
        {
            Guard.NotNullArgument(method, nameof(method));
            Guard.NotNullArgument(className, nameof(className));
            Guard.NotNullArgument(methods, nameof(methods));

            int plusCount = 0;

            int tempRegister = method.RegistersType == SmaliMethod.RegistersTypes.Locals
                ? method.Registers.Value
                : method.Registers.Value - method.Parameters.Count;

            if (method.Registers < 15)
            {
                method.Registers++;
            }
            else
            {
                tempRegister = 14;
            }

            List <string> lines = method.Body;

            for (int j = 0; j < lines.Count; j++)
            {
                string str = lines[j];

                var matches = MessageRegex.Matches(str);

                if (matches.Count == 0)
                {
                    continue;
                }

                int resultRegister = int.Parse(matches[0].Groups[1].Value);

                string text = matches[0].Groups[2].Value;

                int plus;

                text = EncodeString(text, className, methods, tempRegister, resultRegister, out plus,
                                    method.Name == "wPdauIdcaW" && method.Parameters.Count == 2 ? "PdsjdolaSd" : null);

                lines[j] = text;

                plusCount += plus;
            }

            return(plusCount);
        }
コード例 #2
0
        private static SmaliMethod GenerateStringCall(
            [NotNull] string str,
            [NotNull] string className,
            [NotNull] string[] existingMethodNames,
            [CanBeNull] string plusName = null
            )
        {
            Guard.NotNullArgument(str, nameof(str));
            Guard.NotNullArgument(className, nameof(className));
            Guard.NotNullArgument(existingMethodNames, nameof(existingMethodNames));

            string name = GenerateRandomString();

            string nl = NewLine;

            while (existingMethodNames.Contains(name))
            {
                name = GenerateRandomString();
            }

            var method = new SmaliMethod
            {
                Name          = name,
                RegistersType = SmaliMethod.RegistersTypes.Locals,
                Registers     = 1,
                ReturnType    = "Ljava/lang/String",
                Modifers      = { "private", "static" }
            };

            if (plusName != null)
            {
                method.Body.Add(
                    $"    sget v0, {className};->{plusName}:I{nl}" +
                    $"{nl}" +
                    $"    add-int/lit8 v0, v0, 0x1{nl}" +
                    $"{nl}" +
                    $"    sput v0, {className};->{plusName}:I{nl}" +
                    $"{nl}");
            }

            method.Body.Add(
                $"    const-string v0, \"{str}\"{nl}" +
                $"{nl}" +
                $"    return-object v0");

            return(method);
        }