public AstoriaR(DroidApp app) { runningApp = app; edw = new EnhancedDexWriter(); foreach (Class c in app.dex.GetClasses()) { if (c.Name.StartsWith(app.metadata.packageName + ".R") && c.Name.Contains("$")) { string[] name = c.Name.Split('$'); try { switch (name[1]) { case "color": SetSubClass(color, c); break; case "layout": SetSubClass(layout, c); break; } } catch { } } } }
public async Task GetAPKInfoFromLocalAppFolder() { StorageFile manifestFile = await localAppRoot.GetFileAsync("AndroidManifest.old"); StorageFile resFile = await localAppRoot.GetFileAsync("resources.arsc"); resFolder = await localAppRoot.GetFolderAsync("res"); byte[] manifestBytes = await Disassembly.Util.ReadFile(manifestFile); byte[] resBytes = await Disassembly.Util.ReadFile(resFile); ApkReader apkReader = new ApkReader(); ApkInfo appinfo = apkReader.extractInfo(manifestBytes, resBytes); metadata = appinfo; appIcon = GetAppIcon(); //dexNet dexWriter = new EnhancedDexWriter(); //dexWriter = new PlainDexWriter(); StorageFile dexFile = await localAppRoot.GetFileAsync("classes.dex"); byte[] dexBytes = await Disassembly.Util.ReadFile(dexFile); MemoryStream dexStream = new MemoryStream(dexBytes); dex = new Dex(dexStream); dexWriter.dex = dex; //dexWriter.dex.GetMethod(). var methods = dexWriter.dex.GetClasses(); foreach (Class m in methods) { Debug.WriteLine(m.ToString()); if (m.Name.Equals("com.example.ticom.myapp.MainActivity") || m.Name.Equals("com.example.ticom.myapp.MainActivity$1") || m.Name.StartsWith("com.example.ticom.myapp.R")) { TextWriter tw = new StringWriter(); dexWriter.WriteOutClass(m, ClassDisplayOptions.Fields, tw); Debug.WriteLine(tw.ToString()); foreach (Field f in m.GetFields()) { Debug.WriteLine(f.ToString()); } var meths = m.GetMethods(); foreach (Method x in meths) { //Debug.WriteLine(x.ToString()); Debug.WriteLine(dexWriter.WriteOutMethod(m, x, new Indentation())); if (x.Name.Equals("onCreate") || x.Name.Equals("<init>")) { var opcodes = x.GetInstructions(); foreach (OpCode o in opcodes) { string opCodeString = o.ToString(); Debug.WriteLine(opCodeString); if (opCodeString.Contains("meth@")) { int pos = opCodeString.IndexOf("meth@"); string methId = opCodeString.Substring(pos + 5); uint id = uint.Parse(methId); Method mx = dexWriter.dex.GetMethod(id); Debug.WriteLine("meth name: " + mx.Name + "\n"); } else if (opCodeString.Contains("type@")) { int pos = opCodeString.IndexOf("type@"); string methId = opCodeString.Substring(pos + 5); uint id = uint.Parse(methId); string mx = dexWriter.dex.GetTypeName(id); Debug.WriteLine("type name: " + mx + "\n"); } else if (opCodeString.Contains("field@")) { int pos = opCodeString.IndexOf("field@"); string methId = opCodeString.Substring(pos + 6); uint id = uint.Parse(methId); Field mx = dexWriter.dex.GetField(id); Debug.WriteLine("field info: " + mx.ToString() + "\n"); } //Debug.WriteLine("instruction: " + o.ToString() + "\n"); } } } } } //context = new AstoriaContext(); }