Advertisement
Pavle_nis

C# App1

Jan 12th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.74 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. using System.IO;
  12.  
  13. namespace Public_ID_Replacer
  14. {
  15.     public partial class Form1 : Form
  16.     {
  17.         FolderBrowserDialog folderBrowserDialog;
  18.         string path = "";
  19.         public Form1()
  20.         {
  21.             InitializeComponent();
  22.         }
  23.         private void Form1_Load(object sender, EventArgs e)
  24.         {
  25.             folderBrowserDialog = new FolderBrowserDialog();
  26.         }
  27.         private void btnApk_Click(object sender, EventArgs e)
  28.         {
  29.             getFolderDirectory(txtApk);
  30.         }
  31.  
  32.         private void btnFramework1_Click(object sender, EventArgs e)
  33.         {
  34.             getFolderDirectory(txtFramework1);
  35.         }
  36.         private void btnFramework2_Click(object sender, EventArgs e)
  37.         {
  38.             getFolderDirectory(txtFramework2);
  39.         }
  40.         private void getFolderDirectory(TextBox textBox)
  41.         {
  42.             if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
  43.             {
  44.                 path = folderBrowserDialog.SelectedPath;
  45.                 textBox.Text = path;
  46.             }
  47.         }
  48.  
  49.         private void btnReplace_Click(object sender, EventArgs e)
  50.         {
  51.             string[] apkPublicIDs = File.ReadAllLines(txtApk.Text + "/res/values/public.xml");
  52.             string[] allfiles = Directory.GetFiles(txtApk.Text + "/smali/" + readPackageName(), "*.smali*", SearchOption.AllDirectories);
  53.             string newline = "";
  54.  
  55.             foreach (var file in allfiles)
  56.             {
  57.                 FileInfo info = new FileInfo(file);
  58.  
  59.                 string[] lines = File.ReadAllLines(info.FullName);
  60.  
  61.                 for (int i = 0; i < lines.Length; i++)
  62.                 {
  63.                     if (lines[i].Contains("0x"))
  64.                     {
  65.                         newline = lines[i].Substring(lines[i].IndexOf("0x"), lines[i].Length - lines[i].IndexOf("0x"));
  66.                         if(newline.Length == 9)
  67.                         {
  68.                             newline = newline.Insert(newline.IndexOf("x") + 1, "0");
  69.                             readPortFrameworkXmlFile(newline);
  70.                         }
  71.                         else if(newline.Length == 10)
  72.                         {
  73.                             if (!apkPublicIDs.Any(str => str.Contains(newline)))
  74.                             {
  75.                                 newline = newline.Insert(newline.IndexOf("x") + 1, "0");
  76.                                 lines[i]= readPortFrameworkXmlFile(newline);
  77.                             }
  78.                         }
  79.                     }
  80.                 }
  81.  
  82.                 File.WriteAllLines(info.FullName, lines);
  83.             }
  84.         }
  85.  
  86.         private string readPortFrameworkXmlFile(string id)
  87.         {
  88.             string[] lines = File.ReadAllLines(txtFramework1.Text + "/res/values/public.xml");
  89.             string newline = "", name = "";
  90.  
  91.             foreach (string line in lines)
  92.             {
  93.                 if (line.Contains(id))
  94.                 {
  95.                     newline = line.Substring(line.IndexOf("name="), line.Length - line.IndexOf("name=") - 2);
  96.                     name = newline.Substring(newline.IndexOf("name=") + 6, newline.Length - 24);
  97.  
  98.                     return readBaseFrameworkXmlFile(name);
  99.                 }
  100.             }
  101.  
  102.             return "";
  103.         }
  104.         private string readBaseFrameworkXmlFile(string idName)
  105.         {
  106.             string[] lines = File.ReadAllLines(txtFramework2.Text + "/res/values/public.xml");
  107.             string newline = "", id = "";
  108.  
  109.             foreach (string line in lines)
  110.             {
  111.                 if (line.Contains(idName))
  112.                 {
  113.                     newline = line.Substring(line.IndexOf("id="), line.Length - line.IndexOf("id=") - 2);
  114.                     id = newline.Substring(newline.IndexOf("id=") + 4, 10);
  115.                    
  116.                     return id;
  117.                 }
  118.             }
  119.  
  120.             return "";
  121.         }
  122.         private string readPackageName()
  123.         {
  124.             string[] androidManifest = File.ReadAllLines(txtApk.Text + "/AndroidManifest.xml");
  125.             string packageName = androidManifest[0].Substring(androidManifest[0].IndexOf("package="), androidManifest[0].Length - androidManifest[0].IndexOf("package="));
  126.             packageName = packageName.Substring(packageName.IndexOf("=") + 2, packageName.Length - (packageName.IndexOf("=") + 4));
  127.             packageName = packageName.Replace(".", "/");
  128.             MessageBox.Show(packageName);
  129.  
  130.             return packageName;
  131.         }
  132.     }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement