Example #1
0
        private SourceFile(IApkFile apk, JarFile jar, ISpySettings settings, MapFileLookup mapFile, string singleFilePath = null)
        {
            this.apk = apk;
            this.jar = jar;
            this.settings = settings;
            this.mapFile = mapFile;
            this.singleFilePath = singleFilePath;

#if DEBUG  || ENABLE_SHOW_AST
            classLoader = new AssemblyClassLoader(module.OnClassLoaded);
            var modParams = new ModuleParameters
            {
                AssemblyResolver = new AssemblyResolver(new[] { Frameworks.Instance.FirstOrDefault().Folder }, classLoader, module.OnAssemblyLoaded),
                Kind = ModuleKind.Dll
            };
            assembly = AssemblyDefinition.CreateAssembly(new AssemblyNameDefinition("spy", Version.Parse("1.0.0.0")), "main", modParams);
            classLoader.LoadAssembly(assembly);

            var dot42Assembly = modParams.AssemblyResolver.Resolve("dot42");

            // Force loading of classes
            if (jar != null)
            {
                foreach (var fileName in jar.ClassFileNames)
                {
                    OpenClass(fileName);
                }
            }
#endif
        }
Example #2
0
        private SourceFile(ApkFile apk, JarFile jar, ISpySettings settings, MapFile mapFile, string singleFilePath = null)
        {
            this.apk            = apk;
            this.jar            = jar;
            this.settings       = settings;
            this.mapFile        = mapFile;
            this.singleFilePath = singleFilePath;

#if DEBUG
            classLoader = new AssemblyClassLoader(module.OnClassLoaded);
            var modParams = new ModuleParameters
            {
                AssemblyResolver = new AssemblyResolver(new[] { Frameworks.Instance.FirstOrDefault().Folder }, classLoader, module.OnAssemblyLoaded),
                Kind             = ModuleKind.Dll
            };
            assembly = AssemblyDefinition.CreateAssembly(new AssemblyNameDefinition("spy", Version.Parse("1.0.0.0")), "main", modParams);
            classLoader.LoadAssembly(assembly);

            var dot42Assembly = modParams.AssemblyResolver.Resolve("dot42");

            // Force loading of classes
            if (jar != null)
            {
                foreach (var fileName in jar.ClassFileNames)
                {
                    OpenClass(fileName);
                }
            }
#endif
        }
Example #3
0
        /// <summary>
        /// Open a source file
        /// </summary>
        internal static SourceFile Open(string path, ISpySettings settings)
        {
            if (path.EndsWith(".apk", StringComparison.OrdinalIgnoreCase))
            {
                var mapFilePath = Path.ChangeExtension(path, ".d42map");
                var mapFile     = File.Exists(mapFilePath) ? new MapFile(mapFilePath) : null;
                var mapLookup   = mapFile == null ? null : new MapFileLookup(mapFile);
                return(new SourceFile(new ApkFileOpenOnAccessOnly(path), null, settings, mapLookup));
            }
            if (path.EndsWith(".dex", StringComparison.OrdinalIgnoreCase))
            {
                var mapFilePath  = Path.ChangeExtension(path, ".d42map");
                var mapFile      = File.Exists(mapFilePath) ? new MapFile(mapFilePath) : null;
                var tempFileName = CreateApkOnTheFly(path);
                var mapLookup    = mapFile == null ? null : new MapFileLookup(mapFile);

                return(new SourceFile(new ApkFile(tempFileName), null, settings, mapLookup));
            }
            if (path.EndsWith(".jar", StringComparison.OrdinalIgnoreCase))
            {
                return(new SourceFile(null, new JarFile(File.OpenRead(path), path, null), settings, null));
            }
            if (path.EndsWith(".bar", StringComparison.OrdinalIgnoreCase))
            {
                return(new SourceFile(null, new JarFile(File.OpenRead(path), path, null), settings, null));
            }
            if (path.EndsWith(".p12", StringComparison.OrdinalIgnoreCase))
            {
                return(new SourceFile(null, null, settings, null, path));
            }
            throw new ArgumentException("Unknown file type");
        }
Example #4
0
 /// <summary>
 /// Open a source file
 /// </summary>
 internal static SourceFile Open(string path, ISpySettings settings)
 {
     if (path.EndsWith(".apk", StringComparison.OrdinalIgnoreCase))
     {
         var mapFilePath = Path.ChangeExtension(path, ".d42map");
         var mapFile     = File.Exists(mapFilePath) ? new MapFile(mapFilePath) : null;
         return(new SourceFile(new ApkFile(path), null, settings, mapFile));
     }
     if (path.EndsWith(".jar", StringComparison.OrdinalIgnoreCase))
     {
         return(new SourceFile(null, new JarFile(File.OpenRead(path), path, null), settings, null));
     }
     if (path.EndsWith(".bar", StringComparison.OrdinalIgnoreCase))
     {
         return(new SourceFile(null, new JarFile(File.OpenRead(path), path, null), settings, null));
     }
     if (path.EndsWith(".p12", StringComparison.OrdinalIgnoreCase))
     {
         return(new SourceFile(null, null, settings, null, path));
     }
     throw new ArgumentException("Unknown file type");
 }
Example #5
0
 public static string GetBacksmaliCommand(ISpySettings settings, string dexFileName, string outputPath)
 {
     return(string.Format("{0} {1} \"{2}\" -o \"{3}\"", settings.BaksmaliCommand, settings.BaksmaliParameters, dexFileName, outputPath));
 }
Example #6
0
 public BaksmaliDisassembler(ISpySettings settings)
 {
     _settings = settings;
 }
Example #7
0
        /// <summary>
        /// Open a source file
        /// </summary>
        internal static SourceFile Open(string path, ISpySettings settings)
        {
            if (path.EndsWith(".apk", StringComparison.OrdinalIgnoreCase))
            {
                var mapFilePath = Path.ChangeExtension(path, ".d42map");
                var mapFile = File.Exists(mapFilePath) ? new MapFile(mapFilePath) : null;
                var mapLookup = mapFile == null ? null : new MapFileLookup(mapFile);
                return new SourceFile(new ApkFileOpenOnAccessOnly(path), null, settings, mapLookup);
            }
            if (path.EndsWith(".dex", StringComparison.OrdinalIgnoreCase))
            {
                var mapFilePath = Path.ChangeExtension(path, ".d42map");
                var mapFile = File.Exists(mapFilePath) ? new MapFile(mapFilePath) : null;
                var tempFileName = CreateApkOnTheFly(path);
                var mapLookup = mapFile == null ? null : new MapFileLookup(mapFile);

                return new SourceFile(new ApkFile(tempFileName), null, settings, mapLookup);
            }
            if (path.EndsWith(".jar", StringComparison.OrdinalIgnoreCase))
                return new SourceFile(null, new JarFile(File.OpenRead(path), path, null), settings, null);
            if (path.EndsWith(".bar", StringComparison.OrdinalIgnoreCase))
                return new SourceFile(null, new JarFile(File.OpenRead(path), path, null), settings, null);
            if (path.EndsWith(".p12", StringComparison.OrdinalIgnoreCase))
                return new SourceFile(null, null, settings, null, path);
            throw new ArgumentException("Unknown file type");
        }
Example #8
0
 public static string GetBacksmaliCommand(ISpySettings settings, string dexFileName, string outputPath)
 {
     return string.Format(@"{0} {1} {2} -o {3}", settings.BaksmaliCommand, settings.BaksmaliParameters, dexFileName, outputPath);
 }
Example #9
0
 public BaksmaliDisassembler(ISpySettings settings)
 {
     _settings = settings;
 }
Example #10
0
 /// <summary>
 /// Open a source file
 /// </summary>
 internal static SourceFile Open(string path, ISpySettings settings)
 {
     if (path.EndsWith(".apk", StringComparison.OrdinalIgnoreCase))
     {
         var mapFilePath = Path.ChangeExtension(path, ".d42map");
         var mapFile = File.Exists(mapFilePath) ? new MapFile(mapFilePath) : null;
         return new SourceFile(new ApkFile(path), null, settings, mapFile);
     }
     if (path.EndsWith(".jar", StringComparison.OrdinalIgnoreCase))
         return new SourceFile(null, new JarFile(File.OpenRead(path), path, null), settings, null);
     if (path.EndsWith(".bar", StringComparison.OrdinalIgnoreCase))
         return new SourceFile(null, new JarFile(File.OpenRead(path), path, null), settings, null);
     if (path.EndsWith(".p12", StringComparison.OrdinalIgnoreCase))
         return new SourceFile(null, null, settings, null, path);
     throw new ArgumentException("Unknown file type");
 }