public void ReadManifestTest(string path) { using (Stream stream = File.OpenRead(path)) { AndroidXmlReader reader = new AndroidXmlReader(stream); reader.MoveToContent(); XDocument document = XDocument.Load(reader); } }
public void ReadManifestTest() { using (Stream stream = File.OpenRead(@"ApiDemos.AndroidManifest.xml")) { AndroidXmlReader reader = new AndroidXmlReader(stream); reader.MoveToContent(); XDocument document = XDocument.Load(reader); } }
public async Task <UIElement> RenderXmlFile(StorageFile sf) { using (MemoryStream stream = new MemoryStream(await Disassembly.Util.ReadFile(sf))) { AndroidXmlReader reader = new AndroidXmlReader(stream); reader.MoveToContent(); XDocument document = XDocument.Load(reader); //string p1nspace = "{http://schemas.android.com/apk/res/android}"; foreach (XElement xe in document.Elements()) { //Should only be 1 element return(await RenderObject(xe)); } throw new Exception("Invalid XML File"); //decoded = document.ToString(); } }
public async Task Install() { StorageFile dexFile = await localAppRoot.GetFileAsync("classes.dex"); byte[] dexBytes = await Disassembly.Util.ReadFile(dexFile); MemoryStream dexStream = new MemoryStream(dexBytes); dex = new Dex(dexStream); AstoriaR res = new AstoriaR(this); //StaticApkParser parser = new StaticApkParser(localAppRoot); //Find every binary .xml and convert it to human-readable xml so it can be parsed easily //crashes on Win10Mobile //foreach (StorageFile sf in await localAppRoot.GetFilesAsync(Windows.Storage.Search.CommonFileQuery.OrderByName)) string[] filePaths = Directory.GetFiles(localAppRoot.Path, "*.xml", SearchOption.AllDirectories); List <StorageFile> files = await GetFilesFromPaths(filePaths); foreach (StorageFile sf in files) { if (sf.FileType.Equals(".xml")) { //byte[] sfBytes = await Disassembly.Util.ReadFile(sf); try //TODO: IF manifest, create mainfest.OLD { if (sf.Name.Equals("AndroidManifest.xml")) { //Create binary copy of old manifest with .old extension await sf.CopyAsync(localAppRoot, "AndroidManifest.old", NameCollisionOption.ReplaceExisting); //Continue decoding it. } //AXMLPrinter printer = new AXMLPrinter(); //printer.main(sf); //APKManifest man = new APKManifest(); //string decoded = man.ReadManifestFileIntoXml(sfBytes); //string decoded = await parser.transBinaryXml(sf); string decoded; //using (Stream stream = File.OpenRead(sf.Path)) using (MemoryStream stream = new MemoryStream(await Disassembly.Util.ReadFile(sf))) { AndroidXmlReader reader = new AndroidXmlReader(stream); reader.MoveToContent(); XDocument document = XDocument.Load(reader); decoded = document.ToString(); //hack for android xml if (decoded.Contains("@layout/content_main")) { decoded.Replace("@layout/content_main", res.layout.get("content_main").ToString()); } } //Debug.WriteLine(decoded); //string decoded = Disassembly.Manifest.ManifestDecompressor.DecompressAXML(sfBytes); //Inflated XML *should* always be larger than the binary one, so we shouldn't have to clear the file first (could be a future bug though.) await Windows.Storage.FileIO.WriteTextAsync(sf, decoded); Debug.WriteLine($"Converted file: {sf.Name}"); } catch { //Non-binary xml file found. Debug.WriteLine("Exception: Non-binary xml file found."); } } } //Remove copied APK to save on disk space await apkFile.DeleteAsync(); }