Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.IO;
- namespace Public_ID_Replacer
- {
- public partial class Form1 : Form
- {
- FolderBrowserDialog folderBrowserDialog;
- string path = "";
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- folderBrowserDialog = new FolderBrowserDialog();
- }
- private void btnApk_Click(object sender, EventArgs e)
- {
- getFolderDirectory(txtApk);
- }
- private void btnFramework1_Click(object sender, EventArgs e)
- {
- getFolderDirectory(txtFramework1);
- }
- private void btnFramework2_Click(object sender, EventArgs e)
- {
- getFolderDirectory(txtFramework2);
- }
- private void getFolderDirectory(TextBox textBox)
- {
- if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
- {
- path = folderBrowserDialog.SelectedPath;
- textBox.Text = path;
- }
- }
- private void btnReplace_Click(object sender, EventArgs e)
- {
- string[] apkPublicIDs = File.ReadAllLines(txtApk.Text + "/res/values/public.xml");
- string[] allfiles = Directory.GetFiles(txtApk.Text + "/smali/" + readPackageName(), "*.smali*", SearchOption.AllDirectories);
- string newline = "";
- foreach (var file in allfiles)
- {
- FileInfo info = new FileInfo(file);
- string[] lines = File.ReadAllLines(info.FullName);
- for (int i = 0; i < lines.Length; i++)
- {
- if (lines[i].Contains("0x"))
- {
- newline = lines[i].Substring(lines[i].IndexOf("0x"), lines[i].Length - lines[i].IndexOf("0x"));
- if(newline.Length == 9)
- {
- newline = newline.Insert(newline.IndexOf("x") + 1, "0");
- readPortFrameworkXmlFile(newline);
- }
- else if(newline.Length == 10)
- {
- if (!apkPublicIDs.Any(str => str.Contains(newline)))
- {
- newline = newline.Insert(newline.IndexOf("x") + 1, "0");
- lines[i]= readPortFrameworkXmlFile(newline);
- }
- }
- }
- }
- File.WriteAllLines(info.FullName, lines);
- }
- }
- private string readPortFrameworkXmlFile(string id)
- {
- string[] lines = File.ReadAllLines(txtFramework1.Text + "/res/values/public.xml");
- string newline = "", name = "";
- foreach (string line in lines)
- {
- if (line.Contains(id))
- {
- newline = line.Substring(line.IndexOf("name="), line.Length - line.IndexOf("name=") - 2);
- name = newline.Substring(newline.IndexOf("name=") + 6, newline.Length - 24);
- return readBaseFrameworkXmlFile(name);
- }
- }
- return "";
- }
- private string readBaseFrameworkXmlFile(string idName)
- {
- string[] lines = File.ReadAllLines(txtFramework2.Text + "/res/values/public.xml");
- string newline = "", id = "";
- foreach (string line in lines)
- {
- if (line.Contains(idName))
- {
- newline = line.Substring(line.IndexOf("id="), line.Length - line.IndexOf("id=") - 2);
- id = newline.Substring(newline.IndexOf("id=") + 4, 10);
- return id;
- }
- }
- return "";
- }
- private string readPackageName()
- {
- string[] androidManifest = File.ReadAllLines(txtApk.Text + "/AndroidManifest.xml");
- string packageName = androidManifest[0].Substring(androidManifest[0].IndexOf("package="), androidManifest[0].Length - androidManifest[0].IndexOf("package="));
- packageName = packageName.Substring(packageName.IndexOf("=") + 2, packageName.Length - (packageName.IndexOf("=") + 4));
- packageName = packageName.Replace(".", "/");
- MessageBox.Show(packageName);
- return packageName;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement