repo
stringclasses
1k values
file_url
stringlengths
96
373
file_path
stringlengths
11
294
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
6 values
commit_sha
stringclasses
1k values
retrieved_at
stringdate
2026-01-04 14:45:56
2026-01-04 18:30:23
truncated
bool
2 classes
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/uva/SolveEquation.java
uva/SolveEquation.java
/** * Let us look at a boring mathematics problem. :-) We have three different * integers, x, y and z, which satisfy the following three relations: • x + y + * z = A • xyz = B • x 2 + y 2 + z 2 = C You are asked to write a program that * solves for x, y and z for given values of A, B and C. Input The first line of * the input file gives the number of test cases N (N < 20). Each of the * following N lines gives the values of A, B and C (1 ≤ A, B, C ≤ 10000). * Output For each test case, output the corresponding values of x, y and z. If * there are many possible answers, choose the one with the least value of x. If * there is a tie, output the one with the least value of y. If there is no * solution, output the line ‘No solution.’ instead. Sample Input 2 1 2 3 6 6 14 * Sample Output No solution. 1 2 3 */ // https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2612 import java.util.Scanner; public class SolveEquation { public static void main(String[] args) { Scanner input = new Scanner(System.in); int numberOfTestCases = input.nextInt(); while (numberOfTestCases != 0) { int A = input.nextInt(); int B = input.nextInt(); int C = input.nextInt(); boolean hasSolution = false; for (int x = -22; x <= 22 && !hasSolution; x++) { if (x * x <= C) { for (int y = -100; y <= 100 && !hasSolution; y++) { if (x != y && y * y <= C && (x * x + y * y <= C)) { int z = A - x - y; if ((z != y && z != x && x * x + y * y + z * z == C) && x * y * z == B) { hasSolution = true; System.out.println(x + " " + y + " " + z); } } } } } if (!hasSolution) { System.out.println("No solution."); } numberOfTestCases--; } } }
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/uva/FactorialFrequenices.java
uva/FactorialFrequenices.java
/** * In an attempt to bolster her sagging palm-reading business, Madam Phoenix has decided to offer * several numerological treats to her customers. She has been able to convince them that the frequency * of occurrence of the digits in the decimal representation of factorials bear witness to their futures. * Unlike palm-reading, however, she can’t just conjure up these frequencies, so she has employed you to * determine these values. * (Recall that the definition of n! (that is, n factorial) is just 1 × 2 × 3 × · · · × n. As she expects to use * either the day of the week, the day of the month, or the day of the year as the value of n, you must be * able to determine the number of occurrences of each decimal digit in numbers as large as 366 factorial * (366!), which has 781 digits. * Madam Phoenix will be forever (or longer) in your debt; she might even give you a trip if you do * your job well! * Input * The input data for the program is simply a list of integers for which the digit counts are desired. All * of these input values will be less than or equal to 366 and greater than 0, except for the last integer, * which will be zero. Don’t bother to process this zero value; just stop your program at that point. * Output * The output format isn’t too critical, but you should make your program produce results that look * similar to those shown below. * Sample Input * 3 * 8 * 100 * 0 * Sample Output * 3! -- * (0) 0 (1) 0 (2) 0 (3) 0 (4) 0 * (5) 0 (6) 1 (7) 0 (8) 0 (9) 0 * 8! -- * (0) 2 (1) 0 (2) 1 (3) 1 (4) 1 * (5) 0 (6) 0 (7) 0 (8) 0 (9) 0 * 100! -- * (0) 30 (1) 15 (2) 19 (3) 10 (4) 10 * (5) 14 (6) 19 (7) 7 (8) 14 (9) 20 */ //https://uva.onlinejudge.org/index.php?option=onlinejudge&Itemid=99999999&page=show_problem&category=&problem=260 import java.math.BigInteger; import java.util.Scanner; public class FactorialFrequenices { public static void main(String[] args) { Scanner input = new Scanner(System.in); int number = input.nextInt(); while (number != 0) { BigInteger product = BigInteger.ONE; for (int i = 2; i < number + 1; i++) { product = product.multiply(BigInteger.valueOf(i)); } int[] digitCounter = new int[10]; BigInteger productValue = product; while (!productValue.equals(BigInteger.ZERO)) { digitCounter[Integer.valueOf(productValue.mod(BigInteger.TEN) .toString())]++; productValue = productValue.divide(BigInteger.TEN); } formatOutput(number, digitCounter); number = input.nextInt(); } } private static void formatOutput(int number, int[] digits) { System.out.println(number + "! --"); for (int i = 0; i < 10; i++) { if (i != 0 || i != 9 || i != 4) System.out.printf(" "); System.out.printf("(%d)%5d", i, digits[i]); if (i == 4 || i == 9) System.out.printf("\n"); } } }
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/uva/Parity.java
uva/Parity.java
/** * We define the parity of an integer n as the sum of the bits in binary representation computed modulo * two. As an example, the number 21 = 101012 has three 1s in its binary representation so it has parity * 3(mod2), or 1. * In this problem you have to calculate the parity of an integer 1 ≤ I ≤ 2147483647. * Input * Each line of the input has an integer I and the end of the input is indicated by a line where I = 0 that * should not be processed. * Output * For each integer I in the inputt you should print a line ‘The parity of B is P (mod 2).’, where B * is the binary representation of I. * Sample Input * 1 * 2 * 10 * 21 * 0 * Sample Output * The parity of 1 is 1 (mod 2). * The parity of 10 is 1 (mod 2). * The parity of 1010 is 2 (mod 2). * The parity of 10101 is 3 (mod 2). */ //https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1872 import java.util.Scanner; public class Parity { public static void main(String[] args) { while (true) { Scanner input = new Scanner(System.in); int number = input.nextInt(); if (number == 0) { break; } String binaryInString = convertToBinary(number); int count = 0; for (int i = 0; i < binaryInString.length(); i++) { if ("1".equals(binaryInString.charAt(i) + "")) { count++; } } System.out.println("The parity of " + binaryInString + " is " + count + " (mod 2)."); } } private static String convertToBinary(int number) { StringBuilder s = new StringBuilder(""); while (number != 0) { s = s.append(number % 2); number = number / 2; } return s.reverse().toString(); } }
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/uva/CoconutsRevisited.java
uva/CoconutsRevisited.java
/** * The short story titled Coconuts, by Ben Ames Williams, appeared in the Saturday Evening Post on * October 9, 1926. The story tells about five men and a monkey who were shipwrecked on an island. * They spent the first night gathering coconuts. During the night, one man woke up and decided to take * his share of the coconuts. He divided them into five piles. One coconut was left over so he gave it to * the monkey, then hid his share and went back to sleep. * Soon a second man woke up and did the same thing. After dividing the coconuts into five piles, * one coconut was left over which he gave to the monkey. He then hid his share and went back to bed. * The third, fourth, and fifth man followed exactly the same procedure. The next morning, after they * all woke up, they divided the remaining coconuts into five equal shares. This time no coconuts were * left over. * An obvious question is “how many coconuts did they originally gather?” There are an infinite * number of answers, but the lowest of these is 3,121. But that’s not our problem here. * Suppose we turn the problem around. If we know the number of coconuts that were gathered, what * is the maximum number of persons (and one monkey) that could have been shipwrecked if the same * procedure could occur? * Input * The input will consist of a sequence of integers, each representing the number of coconuts gathered by * a group of persons (and a monkey) that were shipwrecked. The sequence will be followed by a negative * number. * Output * For each number of coconuts, determine the largest number of persons who could have participated in * the procedure described above. Display the results similar to the manner shown below, in the Sample * Output. There may be no solution for some of the input cases; if so, state that observation. * Sample Input * 25 * 30 * 3121 * -1 * Sample Output * 25 coconuts, 3 people and 1 monkey * 30 coconuts, no solution * 3121 coconuts, 5 people and 1 monkey */ //https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=557 import java.util.Scanner; public class CoconutsRevisited { public static void main(String[] args) { Scanner input = new Scanner(System.in); int i, rez, j; boolean isValid; while (true) { isValid = false; int num = input.nextInt(); if (num == -1) { break; } for (i = (int) (Math.sqrt(num) + 1); i > 1; i--) { rez = num; for (j = 0; j < i && rez % i == 1; j++) { rez = rez - rez / i - 1; } if (rez % i == 0 && i == j) { isValid = true; break; } } if (isValid) { System.out.println(num + " coconuts, " + i + " people and 1 monkey"); } else { System.out.println(num + " coconuts, no solution"); } } } }
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/uva/HighSchoolPhysics.java
uva/HighSchoolPhysics.java
/** * A particle has initial velocity and acceleration. If its velocity after certain time is v then what will its * displacement be in twice of that time? * Input * The input will contain two integers in each line. Each line makes one set of input. These two integers * denote the value of v (−100 ≤ v ≤ 100) and t (0 ≤ t ≤ 200) (t means at the time the particle gains * that velocity) * Output * For each line of input print a single integer in one line denoting the displacement in double of that time. * Sample Input * 0 0 * 5 12 * Sample Output * 0 * 120 */ //https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1012 import java.util.Scanner; public class HighSchoolPhysics { public static void main(String[] args) { Scanner input = new Scanner(System.in); String line = input.nextLine(); while (!"".equals(line)) { String[] numbers = line.split(" "); int v = Integer.valueOf(numbers[0]); int t = Integer.valueOf(numbers[1]) * 2; System.out.println(v * t); line = input.nextLine(); } } }
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/uva/MischievousChildren.java
uva/MischievousChildren.java
/** * Adam’s parents put up a sign that says “CONGRATULATIONS”. The sign is so big that exactly one * letter fits on each panel. Some of Adam’s younger cousins got bored during the reception and decided * to rearrange the panels. How many unique ways can the panels be arranged (counting the original * arrangement)? * Input * The first line of input is a single non-negative integer. It indicates the number of data sets to follow. * Its value will be less than 30001. * Each data set consists of a single word, in all capital letters. * Each word will have at most 20 letters. There will be no spaces or other punctuation. * The number of arrangements will always be able to fit into an unsigned long int. Note that 12! * is the largest factorial that can fit into an unsigned long int. * Output * For each word, output the number of unique ways that the letters can be rearranged (counting the * original arrangement). Use the format shown in Sample Output, below. * Sample Input * 3 * HAPPY * WEDDING * ADAM * Sample Output * Data set 1: 60 * Data set 2: 2520 * Data set 3: 12 */ //https://uva.onlinejudge.org/index.php?option=onlinejudge&Itemid=99999999&page=show_problem&category=&problem=1279 import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class MischievousChildren { public static void main(String[] args) { Scanner input = new Scanner(System.in); int numberOfCases = input.nextInt(); int currentCase = 1; while (numberOfCases != 0) { String line = input.next(); int numberOfLetters = line.length(); Map<Character, Integer> letterCounter = new HashMap<Character, Integer>(); for (int i = 0; i < numberOfLetters; i++) { char c = line.charAt(i); if (letterCounter.containsKey(c)) { int previousOccurrences = letterCounter.get(c); letterCounter.replace(c, previousOccurrences + 1); } else { letterCounter.put(c, 1); } } String lineWithoutDuplicates = ""; for (int i = 0; i < numberOfLetters; i++) { char c = line.charAt(i); if (!lineWithoutDuplicates.contains(c + "")) { lineWithoutDuplicates = lineWithoutDuplicates + c; } } long nFactorial = computeFactorial(numberOfLetters); for (int i = 0; i < letterCounter.size(); i++) { char c = lineWithoutDuplicates.charAt(i); int numberOfOccurrences = letterCounter.get(c); if (numberOfOccurrences != 1) { long currentProduct = computeFactorial(numberOfOccurrences); nFactorial = nFactorial / currentProduct; } } System.out.println("Data set " + currentCase + ": " + nFactorial); currentCase++; numberOfCases--; } } private static long computeFactorial(int number) { long product = 1; for (int i = 2; i < number + 1; i++) { product = product * i; } return product; } }
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/uva/SimplyEmirp.java
uva/SimplyEmirp.java
/** * An integer greater than 1 is called a prime number if its only positive divisors (factors) are 1 and itself. * Prime numbers have been studied over the years by a lot of mathematicians. Applications of prime * numbers arise in Cryptography and Coding Theory among others. * Have you tried reversing a prime? For most primes, you get a composite (43 becomes 34). An * Emirp (Prime spelt backwards) is a Prime that gives you a different Prime when its digits are reversed. * For example, 17 is Emirp because 17 as well as 71 are Prime. * In this problem, you have to decide whether a number N is Non-prime or Prime or Emirp. Assume * that 1 < N < 1000000. * Interestingly, Emirps are not new to NTU students. We have been boarding 199 and 179 buses for * quite a long time! * Input * Input consists of several lines specifying values for N. * Output * For each N given in the input, output should contain one of the following: * 1. ‘N is not prime.’, if N is not a Prime number. * 2. ‘N is prime.’, if N is Prime and N is not Emirp. * 3. ‘N is emirp.’, if N is Emirp. * Sample Input * 17 * 18 * 19 * 179 * 199 * Sample Output * 17 is emirp. * 18 is not prime. * 19 is prime. * 179 is emirp. * 199 is emirp. */ //https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1176 import java.math.BigInteger; import java.util.Scanner; public class SimplyEmirp { public static void main(String[] args) { Scanner input = new Scanner(System.in); while (input.hasNext()) { String inputGiven = input.next(); BigInteger number = new BigInteger(inputGiven); if (!number.isProbablePrime(10)) { System.out.println(number + " is not prime."); } else { String numberReversedAsString = new StringBuilder( number.toString()).reverse().toString(); BigInteger numberReversed = new BigInteger( numberReversedAsString); if (numberReversed.isProbablePrime(10) && numberReversed.compareTo(number) != 0) { System.out.println(number + " is emirp."); } else { System.out.println(number + " is prime."); } } } } }
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/uva/NumberingRoads.java
uva/NumberingRoads.java
/**In my country, streets dont have names, each of them are * just given a number as name. These numbers are supposed * to be unique but that is not always the case. The local * government allocates some integers to name the roads and * in many case the number of integers allocated is less that * the total number of roads. In that case to make road * names unique some single character suffixes are used. So * roads are named as 1, 2, 3, 1A, 2B, 3C, etc. Of course the * number of suffixes is also always limited to 26 (A, B, . . . , * Z). For example if there are 4 roads and 2 different integers * are allocated for naming then some possible assignments * of names can be: * 1, 2, 1A, 2B * 1, 2, 1A, 2C * 3, 4, 3A, 4A * 1, 2, 1B, 1C * Given the number of roads (R) and the numbers of * integers allocated for naming (N), your job is to determine * minimum how many different suffixes will be required (of * all possible namings) to name the streets assuming that * no two streets can have same names. * Input * The input file can contain up to 10002 lines of inputs. Each line contains two integers R and N * (0 < N, R < 10001). Here R is the total number of streets to be named and N denotes number integers * allocated for naming. * Output * For each line of input produce one line of output. This line contains the serial of output followed by * an integer D which denotes the minimum number of suffixes required to name the streets. If it is not * possible to name all the streets print ‘impossible’ instead (without the quotes). * Sample Input * 8 5 * 100 2 * 0 0 * Sample Output * Case 1: 1 * Case 2: impossible */ //https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2823 import java.util.Scanner; public class NumberingRoads { public static void main(String[] args) { Scanner input = new Scanner(System.in); int caseNumber = 1; while (true) { int first = input.nextInt(); int second = input.nextInt(); if (first == 0 && second == 0) { break; } boolean found = false; for (int i = 0; i < 27 && !found; i++) { int sum = second + second * i; if (sum >= first) { System.out.print("Case " + caseNumber + ": " + i + "\n"); found = true; } } if (!found) { System.out.print("Case " + caseNumber + ": impossible\n"); } caseNumber = caseNumber + 1; } } }
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/uva/BrickGame.java
uva/BrickGame.java
/** * There is a village in Bangladesh, where brick game is very popular. Brick game is a team game. Each * team consists of odd number of players. Number of players must be greater than 1 but cannot be * greater than 10. Age of each player must be within 11 and 20. No two players can have the same age. * There is a captain for each team. The communication gap between two players depends on their age * difference, i.e. the communication gap is larger if the age difference is larger. Hence they select the * captain of a team in such a way so that the number of players in the team who are younger than that * captain is equal to the number of players who are older than that captain. * Ages of all members of the team are provided. You have to determine the age of the captain. * Input * Input starts with an integer T (T ≤ 100), the number of test cases. * Each of the next T lines will start with an integer N (1 < N < 11), number of team members * followed by N space separated integers representing ages of all of the members of a team. Each of these * N integers will be between 11 and 20 (inclusive). Note that, ages will be given in strictly increasing * order or strictly decreasing order. We will not mention which one is increasing and which one is * decreasing, you have to be careful enough to handle both situations. * Output * For each test case, output one line in the format ‘Case x: a’ (quotes for clarity), where x is the case * number and a is the age of the captain. * Sample Input * 2 * 5 19 17 16 14 12 * 5 12 14 16 17 18 * Sample Output * Case 1: 16 * Case 2: 16 */ //https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2986 import static java.lang.Integer.parseInt; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner; public class BrickGame { public static void main(String[] args) { Scanner input = new Scanner(System.in); int numberOfTestCases = input.nextInt(); int caseNum = 1; while (numberOfTestCases != 0) { String[] numbersString = input.nextLine().split(" "); int numberOfMembers = parseInt(numbersString[0]); List<Integer> numbers = new ArrayList<Integer>(); for (int i = 0; i < numberOfMembers + 1; i++) { numbers.add(parseInt(numbersString[i])); } Collections.sort(numbers); System.out.print("Case " + caseNum + ": " + numbers.subList(1, numbers.size()).get( numberOfMembers / 2) + "\n"); numberOfTestCases--; caseNum++; } } }
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/uva/GoogleIsFeelingLucky.java
uva/GoogleIsFeelingLucky.java
// Google is one of the most famous Internet search engines which hosts and develops a number of Internetbased // services and products. On its search engine website, an interesting button ‘I’m feeling lucky’ // attracts our eyes. This feature could allow the user skip the search result page and goes directly to the // first ranked page. Amazing! It saves a lot of time. // The question is, when one types some keywords and presses ‘I’m feeling lucky’ button, which web // page will appear? Google does a lot and comes up with excellent approaches to deal with it. In this // simplified problem, let us just consider that Google assigns every web page an integer-valued relevance. // The most related page will be chosen. If there is a tie, all the pages with the highest relevance are // possible to be chosen. // Your task is simple, given 10 web pages and their relevance. Just pick out all the possible candidates // which will be served to the user when ‘I’m feeling lucky’. // Input // The input contains multiple test cases. The number of test cases T is in the first line of the input file. // For each test case, there are 10 lines, describing the web page and the relevance. Each line contains // a character string without any blank characters denoting the URL of this web page and an integer // Vi denoting the relevance of this web page. The length of the URL is between 1 and 100 inclusively. // (1 ≤ Vi ≤ 100) // Output // For each test case, output several lines which are the URLs of the web pages which are possible to be // chosen. The order of the URLs is the same as the input. Please look at the sample output for further // information of output format. // Sample Input // 2 // www.youtube.com 1 // www.google.com 2 // www.google.com.hk 3 // www.alibaba.com 10 // www.taobao.com 5 // www.bad.com 10 // www.good.com 7 // www.fudan.edu.cn 8 // www.university.edu.cn 9 // acm.university.edu.cn 10 // www.youtube.com 1 // www.google.com 2 // www.google.com.hk 3 // www.alibaba.com 11 // www.taobao.com 5 // www.bad.com 10 // www.good.com 7 // www.fudan.edu.cn 8 // acm.university.edu.cn 9 // acm.university.edu.cn 10 // Sample Output // Case #1: // www.alibaba.com // www.bad.com // acm.university.edu.cn // Case #2: // www.alibaba.com /** * Created by kdn251 on 1/30/17. */ import java.util.*; public class GoogleIsFeelingLucky { public static void main(String args[]) { HashMap<Integer, List<String>> map = new HashMap<Integer, List<String>>(); Scanner sc = new Scanner(System.in); int testCases = sc.nextInt(); int max = Integer.MIN_VALUE; int caseCount = 1; for(int i = 0; i < testCases * 10; i++) { String website = sc.next(); int relevance = sc.nextInt(); if(i % 10 == 0 && i != 0) { List<String> allCandidates = map.get(max); System.out.println("Case #" + caseCount + ":"); caseCount++; for(String s : allCandidates) { System.out.println(s); } map = new HashMap<Integer, List<String>>(); max = Integer.MIN_VALUE; } if(map.containsKey(relevance)) { map.get(relevance).add(website); } if(!map.containsKey(relevance)) { List<String> list = new ArrayList<String>(); map.put(relevance, list); map.get(relevance).add(website); } if(relevance > max) { max = relevance; } } System.out.println("Case #" + caseCount + ":"); for(String s : map.get(max)) { System.out.println(s); } } }
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/uva/FiveHundredFactorial.java
uva/FiveHundredFactorial.java
/** * In these days you can more and more often happen to see programs which perform some useful calculations * being executed rather then trivial screen savers. Some of them check the system message queue * and in case of finding it empty (for examples somebody is editing a file and stays idle for some time) * execute its own algorithm. * As an examples we can give programs which calculate primary numbers. * One can also imagine a program which calculates a factorial of given numbers. In this case it is not * the time complexity of order O(n) which makes troubles, but the memory requirements. Considering * the fact that 500! gives 1135-digit number. No standard, neither integer nor floating, data type is * applicable here. * Your task is to write a programs which calculates a factorial of a given number. * Input * Any number of lines, each containing value n for which you should provide value of n! * Output * 2 lines for each input case. First should contain value n followed by character ‘!’. The second should * contain calculated value n!. * Assumptions: * • Value of a number n which factorial should be calculated of does not exceed 1000 (although 500! * is the name of the problem, 500 is a small limit). * • Mind that visually big number of case 4 is broken after 80 characters, but this is not the case in * the real output file. * Sample Input * 10 * 30 * 50 * 100 * Sample Output * 10! * 3628800 * 30! * 265252859812191058636308480000000 * 50! * 30414093201713378043612608166064768844377641568960512000000000000 * 100! * 93326215443944152681699238856266700490715968264381621468592963895217599993229915 * 608941463976156518286253697920827223758251185210916864000000000000000000000000 */ //https://uva.onlinejudge.org/index.php?option=onlinejudge&Itemid=99999999&page=show_problem&category=&problem=564 import java.math.BigInteger; import java.util.Scanner; public class FiveHundredFactorial { public static void main(String[] args) { Scanner input = new Scanner(System.in); while (input.hasNext()) { int number = input.nextInt(); BigInteger product = BigInteger.ONE; for (int i = 2; i < number + 1; i++) { product = product.multiply(BigInteger.valueOf(i)); } System.out.println(number + "!\n" + product); } } }
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/uva/HashmatWarriors.java
uva/HashmatWarriors.java
/** * Hashmat is a brave warrior who with his group of young soldiers moves from one place to another to * fight against his opponents. Before Fighting he just calculates one thing, the difference between his * soldier number and the opponent’s soldier number. From this difference he decides whether to fight or * not. Hashmat’s soldier number is never greater than his opponent. * Input * The input contains two numbers in every line. These two numbers in each line denotes the number * soldiers in Hashmat’s army and his opponent’s army or vice versa. The input numbers are not greater * than 232. Input is terminated by ‘End of File’. * Output * For each line of input, print the difference of number of soldiers between Hashmat’s army and his * opponent’s army. Each output should be in seperate line. * Sample Input * 10 12 * 10 14 * 100 200 * Sample Output * 2 * 4 * 100 */ //https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=996 import java.util.Scanner; public class HashmatWarriors { public static void main(String[] args) { Scanner input = new Scanner(System.in); String nextLine = input.nextLine(); while (!"".equals(nextLine)) { String[] nums = nextLine.split(" "); long firstNum = Long.valueOf(nums[0]); long secondNum = Long.valueOf(nums[1]); System.out.println(Math.abs(secondNum - firstNum)); nextLine = input.nextLine(); } } }
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/uva/WhatBaseIsThis.java
uva/WhatBaseIsThis.java
/** * In positional notation we know the position of a digit indicates the weight of that digit toward the * value of a number. For example, in the base 10 number 362 we know that 2 has the weight 100 * , 6 * has the weight 101 * , and 3 has the weight 102 * , yielding the value 3 × 102 + 6 × 101 + 2 × 100 * , or just * 300 + 60 + 2. The same mechanism is used for numbers expressed in other bases. While most people * assume the numbers they encounter everyday are expressed using base 10, we know that other bases * are possible. In particular, the number 362 in base 9 or base 14 represents a totally different value than * 362 in base 10. * For this problem your program will presented with a sequence of pairs of integers. Let’s call the * members of a pair X and Y . What your program is to do is determine the smallest base for X and the * smallest base for Y (likely different from that for X) so that X and Y represent the same value. * Consider, for example, the integers 12 and 5. Certainly these are not equal if base 10 is used for * each. But suppose 12 was a base 3 number and 5 was a base 6 number? 12 base 3 = 1 × 3 * 1 + 2 × 3 * 0 * , * or 5 base 10, and certainly 5 in any base is equal to 5 base 10. So 12 and 5 can be equal, if you select * the right bases for each of them! * Input * On each line of the input data there will be a pair of integers, X and Y , separated by one or more blanks; * leading and trailing blanks may also appear on each line, are are to be ignored. The bases associated * with X and Y will be between 1 and 36 (inclusive), and as noted above, need not be the same for X and * Y . In representing these numbers the digits 0 through 9 have their usual decimal interpretations. The * uppercase alphabetic characters A through Z represent digits with values 10 through 35, respectively. * Output * For each pair of integers in the input display a message similar to those shown in the examples shown * below. Of course if the two integers cannot be equal regardless of the assumed base for each, then print * an appropriate message; a suitable illustration is given in the examples. * Sample Input * 12 5 * 10 A * 12 34 * 123 456 * 1 2 * 10 2 * Sample Output * 12 (base 3) = 5 (base 6) * 10 (base 10) = A (base 11) * 12 (base 17) = 34 (base 5) * 123 is not equal to 456 in any base 2..36 * 1 is not equal to 2 in any base 2..36 * 10 (base 2) = 2 (base 3) */ //https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=&problem=279 import java.math.BigInteger; import java.util.Scanner; public class WhatBaseIsThis { public static void main(String[] args) { Scanner input = new Scanner(System.in); while (input.hasNext()) { String x = input.next(); String y = input.next(); boolean found = false; for (int i = 2; i < 37 && !found; i++) { BigInteger xConvertedToBase; try { xConvertedToBase = new BigInteger(x, i); } catch (Exception e) { continue; } for (int j = 2; j < 37; j++) { BigInteger yConvertedToBase; try { yConvertedToBase = new BigInteger(y, j); } catch (Exception e) { continue; } if (xConvertedToBase.equals(yConvertedToBase)) { System.out.println(x + " (base " + i + ") = " + y + " (base " + j + ")"); found = true; break; } } } if (!found) { System.out.println(x + " is not equal to " + y + " in any base 2..36"); } } } }
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/uva/Modex.java
uva/Modex.java
/** * Many well-known cryptographic operations require modular exponentiation. That is, given integers x, * y and n, compute x * y mod n. In this question, you are tasked to program an efficient way to execute * this calculation. * Input * The input consists of a line containing the number c of datasets, followed by c datasets, followed by a * line containing the number ‘0’. * Each dataset consists of a single line containing three positive integers, x, y, and n, separated by * blanks. You can assume that 1 < x, n < 2 * 15 = 32768, and 0 < y < 2 * 31 = 2147483648. * Output * The output consists of one line for each dataset. The i-th line contains a single positive integer z such * that * z = x * y mod n * for the numbers x, y, z given in the i-th input dataset. * Sample Input * 2 * 2 3 5 * 2 2147483647 13 * 0 * Sample Output * 3 * 11 */ //https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3671 import java.math.BigInteger; import java.util.Scanner; public class Modex { public static void main(String[] args) { Scanner input = new Scanner(System.in); int numberOfTestCases = input.nextInt(); while (numberOfTestCases != 0) { BigInteger x = input.nextBigInteger(); BigInteger y = input.nextBigInteger(); BigInteger n = input.nextBigInteger(); BigInteger result = x.modPow(y, n); System.out.println(result); numberOfTestCases--; } } }
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
kdn251/interviews
https://github.com/kdn251/interviews/blob/03fdcb2703ce72dc0606748733d0c13f09d41d21/uva/PseudoPrimeNumbers.java
uva/PseudoPrimeNumbers.java
/** * Fermat’s theorem states that for any * prime number p and for any integer a > 1, * a * p == a (mod p). That is, if we raise a to * the pth power and divide by p, the remainder * is a. Some (but not very many) nonprime * values of p, known as base-a pseudoprimes, * have this property for some a. * (And some, known as Carmichael Numbers, * are base-a pseudoprimes for all a.) * Given 2 < p ≤ 1, 000, 000, 000 and 1 < * a < p, determine whether or not p is a * base-a pseudoprime. * Input * Input contains several test cases followed by a line containing ‘0 0’. Each test case consists of a line * containing p and a. * Output * For each test case, output ‘yes’ if p is a base-a pseudoprime; otherwise output ‘no’. * Sample Input * 3 2 * 10 3 * 341 2 * 341 3 * 1105 2 * 1105 3 * 0 0 * Sample Output * no * no * yes * no * yes * yes */ //https://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=2262 import java.math.BigInteger; import java.util.Scanner; public class PseudoPrimeNumbers { public static void main(String[] args) { Scanner input = new Scanner(System.in); while (true) { int p = input.nextInt(); int a = input.nextInt(); if (a == 0 && p == 0) { break; } BigInteger pAsBigInteger = new BigInteger(p + ""); BigInteger aAsBigInteger = new BigInteger(a + ""); String answer = ""; if (!pAsBigInteger.isProbablePrime(10)) { BigInteger result = aAsBigInteger.modPow(pAsBigInteger, pAsBigInteger); if (result.equals(aAsBigInteger)) { answer = "yes"; } else { answer = "no"; } } else { answer = "no"; } System.out.println(answer); } } }
java
MIT
03fdcb2703ce72dc0606748733d0c13f09d41d21
2026-01-04T14:45:56.686758Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins-tools/src/test/java/jadx/plugins/tools/resolvers/github/GithubToolsTest.java
jadx-plugins-tools/src/test/java/jadx/plugins/tools/resolvers/github/GithubToolsTest.java
package jadx.plugins.tools.resolvers.github; import java.io.IOException; import java.io.InputStream; import java.time.Instant; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import mockwebserver3.MockResponse; import mockwebserver3.MockWebServer; import jadx.core.utils.files.FileUtils; import jadx.plugins.tools.resolvers.github.data.Release; import static org.assertj.core.api.Assertions.assertThat; class GithubToolsTest { private static final Logger LOG = LoggerFactory.getLogger(GithubToolsTest.class); private MockWebServer server; private GithubTools githubTools; @BeforeEach public void setup() throws IOException { server = new MockWebServer(); server.start(); String baseUrl = server.url("/").toString(); githubTools = new GithubTools(baseUrl); } @AfterEach public void close() { server.close(); } @Test public void getReleaseGood() { server.enqueue(new MockResponse.Builder() .body(loadFromResource("plugins-list-good.json")) .build()); LocationInfo pluginsList = new LocationInfo("jadx-decompiler", "jadx-plugins-list", "list"); Release release = githubTools.getRelease(pluginsList); LOG.info("Result release: {}", release); assertThat(release.getName()).isEqualTo("v15"); assertThat(release.getAssets()).hasSize(1); } @Test public void getReleaseRateLimit() { server.enqueue(new MockResponse.Builder() .code(403) .addHeader("x-ratelimit-remaining", "0") .addHeader("x-ratelimit-reset", Instant.now().plusSeconds(60 * 60).getEpochSecond()) // 1 hour from now .body("{}") .build()); LocationInfo pluginsList = new LocationInfo("jadx-decompiler", "jadx-plugins-list", "list"); Assertions.assertThatThrownBy(() -> githubTools.getRelease(pluginsList)) .hasMessageContaining("403") .hasMessageContaining("Client Error") .hasMessageContaining("rate limit reached"); } private static String loadFromResource(String resName) { try (InputStream stream = GithubToolsTest.class.getResourceAsStream("/github/" + resName)) { return FileUtils.streamToString(stream); } catch (IOException e) { throw new RuntimeException("Failed to load resource: " + resName, e); } } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins-tools/src/main/java/jadx/plugins/tools/JadxPluginsTools.java
jadx-plugins-tools/src/main/java/jadx/plugins/tools/JadxPluginsTools.java
package jadx.plugins.tools; import java.io.IOException; import java.io.Reader; import java.io.Writer; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.Optional; import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import jadx.api.plugins.JadxPlugin; import jadx.api.plugins.JadxPluginInfo; import jadx.core.Jadx; import jadx.core.plugins.versions.VerifyRequiredVersion; import jadx.core.utils.StringUtils; import jadx.core.utils.exceptions.JadxRuntimeException; import jadx.plugins.tools.data.JadxInstalledPlugins; import jadx.plugins.tools.data.JadxPluginMetadata; import jadx.plugins.tools.data.JadxPluginUpdate; import jadx.plugins.tools.resolvers.IJadxPluginResolver; import jadx.plugins.tools.resolvers.ResolversRegistry; import jadx.plugins.tools.utils.PluginUtils; import static jadx.core.utils.GsonUtils.buildGson; import static jadx.plugins.tools.utils.PluginFiles.DROPINS_DIR; import static jadx.plugins.tools.utils.PluginFiles.INSTALLED_DIR; import static jadx.plugins.tools.utils.PluginFiles.PLUGINS_JSON; public class JadxPluginsTools { private static final Logger LOG = LoggerFactory.getLogger(JadxPluginsTools.class); private static final JadxPluginsTools INSTANCE = new JadxPluginsTools(); public static JadxPluginsTools getInstance() { return INSTANCE; } private JadxPluginsTools() { } public JadxPluginMetadata install(String locationId) { IJadxPluginResolver resolver = ResolversRegistry.getResolver(locationId); Supplier<List<JadxPluginMetadata>> fetchVersions; if (resolver.hasVersion(locationId)) { fetchVersions = () -> { JadxPluginMetadata version = resolver.resolve(locationId) .orElseThrow(() -> new JadxRuntimeException("Failed to resolve plugin location: " + locationId)); return Collections.singletonList(version); }; } else { // load latest 10 version to search for compatible one fetchVersions = () -> resolver.resolveVersions(locationId, 1, 10); } List<JadxPluginMetadata> versionsMetadata; try { versionsMetadata = fetchVersions.get(); } catch (Exception e) { throw new JadxRuntimeException("Plugin info fetch failed, locationId: " + locationId, e); } if (versionsMetadata.isEmpty()) { throw new JadxRuntimeException("Plugin release not found, locationId: " + locationId); } VerifyRequiredVersion verifyRequiredVersion = new VerifyRequiredVersion(); List<String> rejectedVersions = new ArrayList<>(); for (JadxPluginMetadata pluginMetadata : versionsMetadata) { // download plugin jar and fill metadata // any download or plugin instantiation errors will stop versions check fillMetadata(pluginMetadata); if (verifyRequiredVersion.isCompatible(pluginMetadata.getRequiredJadxVersion())) { install(pluginMetadata); return pluginMetadata; } rejectedVersions.add(" version " + pluginMetadata.getVersion() + " not compatible, require: " + pluginMetadata.getRequiredJadxVersion()); } throw new JadxRuntimeException("Can't find compatible version to install" + ", current jadx version: " + verifyRequiredVersion.getJadxVersion() + "\nrejected versions:\n" + String.join("\n", rejectedVersions)); } public JadxPluginMetadata resolveMetadata(String locationId) { IJadxPluginResolver resolver = ResolversRegistry.getResolver(locationId); JadxPluginMetadata pluginMetadata = resolver.resolve(locationId) .orElseThrow(() -> new RuntimeException("Failed to resolve locationId: " + locationId)); fillMetadata(pluginMetadata); return pluginMetadata; } public List<JadxPluginMetadata> getVersionsByLocation(String locationId, int page, int perPage) { IJadxPluginResolver resolver = ResolversRegistry.getResolver(locationId); List<JadxPluginMetadata> list = resolver.resolveVersions(locationId, page, perPage); for (JadxPluginMetadata pluginMetadata : list) { fillMetadata(pluginMetadata); } return list; } public List<JadxPluginUpdate> updateAll() { JadxInstalledPlugins plugins = loadPluginsJson(); int size = plugins.getInstalled().size(); List<JadxPluginUpdate> updates = new ArrayList<>(size); List<JadxPluginMetadata> newList = new ArrayList<>(size); for (JadxPluginMetadata plugin : plugins.getInstalled()) { JadxPluginMetadata newVersion = null; try { newVersion = update(plugin); } catch (Exception e) { LOG.warn("Failed to update plugin: {}", plugin.getPluginId(), e); } if (newVersion != null) { updates.add(new JadxPluginUpdate(plugin, newVersion)); newList.add(newVersion); } else { newList.add(plugin); } } if (!updates.isEmpty()) { plugins.setUpdated(System.currentTimeMillis()); plugins.setInstalled(newList); savePluginsJson(plugins); } return updates; } public Optional<JadxPluginUpdate> update(String pluginId) { JadxInstalledPlugins plugins = loadPluginsJson(); JadxPluginMetadata plugin = plugins.getInstalled().stream() .filter(p -> p.getPluginId().equals(pluginId)) .findFirst() .orElseThrow(() -> new RuntimeException("Plugin not found: " + pluginId)); JadxPluginMetadata newVersion = update(plugin); if (newVersion == null) { return Optional.empty(); } plugins.setUpdated(System.currentTimeMillis()); plugins.getInstalled().remove(plugin); plugins.getInstalled().add(newVersion); savePluginsJson(plugins); return Optional.of(new JadxPluginUpdate(plugin, newVersion)); } public boolean uninstall(String pluginId) { JadxInstalledPlugins plugins = loadPluginsJson(); Optional<JadxPluginMetadata> found = plugins.getInstalled().stream() .filter(p -> p.getPluginId().equals(pluginId)) .findFirst(); if (found.isEmpty()) { return false; } JadxPluginMetadata plugin = found.get(); deletePluginJar(plugin); plugins.getInstalled().remove(plugin); savePluginsJson(plugins); return true; } public List<JadxPluginMetadata> getInstalled() { return loadPluginsJson().getInstalled(); } /** * Return all loadable plugins info (including installed, bundled and dropins). * <br> * For only installed plugins prefer {@link jadx.plugins.tools.JadxPluginsTools#getInstalled} * method. */ public List<JadxPluginInfo> getAllPluginsInfo() { try (JadxExternalPluginsLoader pluginsLoader = new JadxExternalPluginsLoader()) { return pluginsLoader.load().stream() .map(JadxPlugin::getPluginInfo) .collect(Collectors.toList()); } } public List<Path> getAllPluginJars() { List<Path> list = new ArrayList<>(); for (JadxPluginMetadata pluginMetadata : loadPluginsJson().getInstalled()) { list.add(INSTALLED_DIR.resolve(pluginMetadata.getJar())); } collectJarsFromDir(list, DROPINS_DIR); return list; } public List<Path> getEnabledPluginJars() { List<Path> list = new ArrayList<>(); for (JadxPluginMetadata pluginMetadata : loadPluginsJson().getInstalled()) { if (pluginMetadata.isDisabled()) { continue; } list.add(INSTALLED_DIR.resolve(pluginMetadata.getJar())); } collectJarsFromDir(list, DROPINS_DIR); return list; } /** * Disable or enable plugin * * @return true if disabled status was changed */ public boolean changeDisabledStatus(String pluginId, boolean disabled) { JadxInstalledPlugins data = loadPluginsJson(); JadxPluginMetadata plugin = data.getInstalled().stream() .filter(p -> p.getPluginId().equals(pluginId)) .findFirst() .orElseThrow(() -> new RuntimeException("Plugin not found: " + pluginId)); if (plugin.isDisabled() == disabled) { return false; } plugin.setDisabled(disabled); data.setUpdated(System.currentTimeMillis()); savePluginsJson(data); return true; } private @Nullable JadxPluginMetadata update(JadxPluginMetadata plugin) { IJadxPluginResolver resolver = ResolversRegistry.getResolver(plugin.getLocationId()); if (!resolver.isUpdateSupported()) { return null; } Optional<JadxPluginMetadata> updateOpt = resolver.resolve(plugin.getLocationId()); if (updateOpt.isEmpty()) { return null; } JadxPluginMetadata update = updateOpt.get(); if (Objects.equals(update.getVersion(), plugin.getVersion())) { return null; } fillMetadata(update); install(update); return update; } private void install(JadxPluginMetadata metadata) { String reqVersionStr = metadata.getRequiredJadxVersion(); if (!VerifyRequiredVersion.isJadxCompatible(reqVersionStr)) { throw new JadxRuntimeException("Can't install plugin, required version: \"" + reqVersionStr + '\"' + " is not compatible with current jadx version: " + Jadx.getVersion()); } String version = metadata.getVersion(); String fileName = metadata.getPluginId() + (StringUtils.notBlank(version) ? '-' + version : "") + ".jar"; Path pluginJar = INSTALLED_DIR.resolve(fileName); copyJar(Paths.get(metadata.getJar()), pluginJar); metadata.setJar(INSTALLED_DIR.relativize(pluginJar).toString()); JadxInstalledPlugins plugins = loadPluginsJson(); // remove previous version jar plugins.getInstalled().removeIf(p -> { if (p.getPluginId().equals(metadata.getPluginId())) { deletePluginJar(p); return true; } return false; }); plugins.getInstalled().add(metadata); plugins.setUpdated(System.currentTimeMillis()); savePluginsJson(plugins); } private void fillMetadata(JadxPluginMetadata metadata) { try { Path tmpJar; if (needDownload(metadata.getJar())) { tmpJar = Files.createTempFile(metadata.getName(), "plugin.jar"); PluginUtils.downloadFile(metadata.getJar(), tmpJar); metadata.setJar(tmpJar.toAbsolutePath().toString()); } else { tmpJar = Paths.get(metadata.getJar()); } fillMetadataFromJar(metadata, tmpJar); } catch (Exception e) { throw new RuntimeException("Failed to fill plugin metadata, plugin: " + metadata.getPluginId(), e); } } private void fillMetadataFromJar(JadxPluginMetadata metadata, Path jar) { try (JadxExternalPluginsLoader loader = new JadxExternalPluginsLoader()) { JadxPlugin jadxPlugin = loader.loadFromJar(jar); JadxPluginInfo pluginInfo = jadxPlugin.getPluginInfo(); metadata.setPluginId(pluginInfo.getPluginId()); metadata.setName(pluginInfo.getName()); metadata.setDescription(pluginInfo.getDescription()); metadata.setHomepage(pluginInfo.getHomepage()); metadata.setRequiredJadxVersion(pluginInfo.getRequiredJadxVersion()); } catch (NoSuchMethodError e) { throw new RuntimeException("Looks like plugin uses unknown API, try to update jadx version", e); } } private static boolean needDownload(String jar) { return jar.startsWith("https://") || jar.startsWith("http://"); } private void copyJar(Path sourceJar, Path destJar) { try { Files.copy(sourceJar, destJar, StandardCopyOption.REPLACE_EXISTING); } catch (Exception e) { throw new RuntimeException("Failed to copy plugin jar: " + sourceJar + " to: " + destJar, e); } } private void deletePluginJar(JadxPluginMetadata plugin) { try { Files.deleteIfExists(INSTALLED_DIR.resolve(plugin.getJar())); } catch (IOException e) { // ignore } } private JadxInstalledPlugins loadPluginsJson() { if (!Files.isRegularFile(PLUGINS_JSON)) { JadxInstalledPlugins plugins = new JadxInstalledPlugins(); plugins.setVersion(1); return plugins; } try (Reader reader = Files.newBufferedReader(PLUGINS_JSON, StandardCharsets.UTF_8)) { JadxInstalledPlugins data = buildGson().fromJson(reader, JadxInstalledPlugins.class); upgradePluginsData(data); return data; } catch (Exception e) { throw new RuntimeException("Failed to read file: " + PLUGINS_JSON); } } private void savePluginsJson(JadxInstalledPlugins data) { if (data.getInstalled().isEmpty()) { try { Files.deleteIfExists(PLUGINS_JSON); } catch (Exception e) { throw new RuntimeException("Failed to remove file: " + PLUGINS_JSON, e); } return; } data.getInstalled().sort(null); try (Writer writer = Files.newBufferedWriter(PLUGINS_JSON, StandardCharsets.UTF_8)) { buildGson().toJson(data, writer); } catch (Exception e) { throw new RuntimeException("Error saving file: " + PLUGINS_JSON, e); } } private void upgradePluginsData(JadxInstalledPlugins data) { if (data.getVersion() == 0) { data.setVersion(1); } } private static void collectJarsFromDir(List<Path> list, Path dir) { try (Stream<Path> files = Files.list(dir)) { files.filter(p -> p.getFileName().toString().endsWith(".jar")).forEach(list::add); } catch (IOException e) { throw new RuntimeException(e); } } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins-tools/src/main/java/jadx/plugins/tools/JadxPluginsList.java
jadx-plugins-tools/src/main/java/jadx/plugins/tools/JadxPluginsList.java
package jadx.plugins.tools; import java.io.InputStreamReader; import java.io.Reader; import java.lang.reflect.Type; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicReference; import java.util.function.Consumer; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import jadx.core.utils.files.FileUtils; import jadx.plugins.tools.data.JadxPluginListCache; import jadx.plugins.tools.data.JadxPluginListEntry; import jadx.plugins.tools.resolvers.github.GithubTools; import jadx.plugins.tools.resolvers.github.LocationInfo; import jadx.plugins.tools.resolvers.github.data.Asset; import jadx.plugins.tools.resolvers.github.data.Release; import jadx.plugins.tools.utils.PluginUtils; import jadx.zip.ZipReader; import static jadx.core.utils.GsonUtils.buildGson; import static jadx.plugins.tools.utils.PluginFiles.PLUGINS_LIST_CACHE; public class JadxPluginsList { private static final Logger LOG = LoggerFactory.getLogger(JadxPluginsList.class); private static final JadxPluginsList INSTANCE = new JadxPluginsList(); private static final Type LIST_TYPE = new TypeToken<List<JadxPluginListEntry>>() { }.getType(); private static final Type CACHE_TYPE = new TypeToken<JadxPluginListCache>() { }.getType(); public static JadxPluginsList getInstance() { return INSTANCE; } private @Nullable JadxPluginListCache loadedList; private JadxPluginsList() { } /** * List provider with update callback. * Can be called one or two times: * <br> * - Apply cached data first * <br> * - If update is available, apply data after fetch * <br> * Method call is blocking. */ public synchronized void get(Consumer<List<JadxPluginListEntry>> consumer) { if (loadedList != null) { consumer.accept(loadedList.getList()); return; } JadxPluginListCache listCache = loadCache(); if (listCache != null) { consumer.accept(listCache.getList()); loadedList = listCache; } Release release = fetchLatestRelease(); if (listCache == null || !listCache.getVersion().equals(release.getName())) { JadxPluginListCache updatedList = fetchBundle(release); saveCache(updatedList); consumer.accept(updatedList.getList()); loadedList = updatedList; } } public List<JadxPluginListEntry> get() { AtomicReference<List<JadxPluginListEntry>> holder = new AtomicReference<>(); get(holder::set); return holder.get(); } private @Nullable JadxPluginListCache loadCache() { if (!Files.isRegularFile(PLUGINS_LIST_CACHE)) { return null; } try { String jsonStr = FileUtils.readFile(PLUGINS_LIST_CACHE); return buildGson().fromJson(jsonStr, CACHE_TYPE); } catch (Exception e) { return null; } } private void saveCache(JadxPluginListCache listCache) { try { String jsonStr = buildGson().toJson(listCache, CACHE_TYPE); FileUtils.writeFile(PLUGINS_LIST_CACHE, jsonStr); } catch (Exception e) { throw new RuntimeException("Error saving file: " + PLUGINS_LIST_CACHE, e); } } private Release fetchLatestRelease() { LOG.debug("Fetching latest plugins-list release info"); LocationInfo pluginsList = new LocationInfo("jadx-decompiler", "jadx-plugins-list", "list"); Release release = GithubTools.fetchRelease(pluginsList); List<Asset> assets = release.getAssets(); if (assets.isEmpty()) { throw new RuntimeException("Release don't have assets"); } return release; } private JadxPluginListCache fetchBundle(Release release) { LOG.debug("Fetching plugins-list bundle: {}", release.getName()); try { Asset listAsset = release.getAssets().get(0); Path tmpListFile = Files.createTempFile("plugins-list", ".zip"); try { PluginUtils.downloadFile(listAsset.getDownloadUrl(), tmpListFile); JadxPluginListCache listCache = new JadxPluginListCache(); listCache.setVersion(release.getName()); listCache.setList(loadListBundle(tmpListFile)); return listCache; } finally { Files.deleteIfExists(tmpListFile); } } catch (Exception e) { throw new RuntimeException("Failed to load plugin-list bundle for release:" + release.getName(), e); } } private static List<JadxPluginListEntry> loadListBundle(Path tmpListFile) { Gson gson = buildGson(); List<JadxPluginListEntry> entries = new ArrayList<>(); new ZipReader().visitEntries(tmpListFile.toFile(), entry -> { if (entry.getName().endsWith(".json")) { try (Reader reader = new InputStreamReader(entry.getInputStream())) { entries.addAll(gson.fromJson(reader, LIST_TYPE)); } catch (Exception e) { throw new RuntimeException("Failed to read plugins list entry: " + entry.getName()); } } return null; }); return entries; } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins-tools/src/main/java/jadx/plugins/tools/JadxExternalPluginsLoader.java
jadx-plugins-tools/src/main/java/jadx/plugins/tools/JadxExternalPluginsLoader.java
package jadx.plugins.tools; import java.io.File; import java.net.URL; import java.net.URLClassLoader; import java.nio.file.Path; import java.util.ArrayList; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.ServiceLoader; import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import jadx.api.plugins.JadxPlugin; import jadx.api.plugins.loader.JadxPluginLoader; import jadx.core.utils.Utils; import jadx.core.utils.exceptions.JadxRuntimeException; public class JadxExternalPluginsLoader implements JadxPluginLoader { private static final Logger LOG = LoggerFactory.getLogger(JadxExternalPluginsLoader.class); public static final String JADX_PLUGIN_CLASSLOADER_PREFIX = "jadx-plugin:"; private final List<URLClassLoader> classLoaders = new ArrayList<>(); @Override public List<JadxPlugin> load() { close(); long start = System.currentTimeMillis(); Map<String, JadxPlugin> map = new HashMap<>(); loadFromClsLoader(map, thisClassLoader()); loadInstalledPlugins(map); List<JadxPlugin> list = new ArrayList<>(map.size()); list.addAll(map.values()); list.sort(Comparator.comparing(p -> p.getClass().getSimpleName())); if (LOG.isDebugEnabled()) { LOG.debug("Collected {} plugins in {}ms", list.size(), System.currentTimeMillis() - start); } return list; } public JadxPlugin loadFromJar(Path jar) { Map<String, JadxPlugin> map = new HashMap<>(); loadFromJar(map, jar); int loaded = map.size(); if (loaded == 0) { throw new JadxRuntimeException("No plugin found in jar: " + jar); } if (loaded > 1) { String plugins = map.values().stream().map(p -> p.getPluginInfo().getPluginId()).collect(Collectors.joining(", ")); throw new JadxRuntimeException("Expect only one plugin per jar: " + jar + ", but found: " + loaded + " - " + plugins); } return Utils.first(map.values()); } private void loadFromClsLoader(Map<String, JadxPlugin> map, ClassLoader classLoader) { ServiceLoader<JadxPlugin> serviceLoader = ServiceLoader.load(JadxPlugin.class, classLoader); for (ServiceLoader.Provider<JadxPlugin> provider : serviceLoader.stream().collect(Collectors.toList())) { Class<? extends JadxPlugin> pluginClass = provider.type(); String clsName = pluginClass.getName(); if (!map.containsKey(clsName) && pluginClass.getClassLoader() == classLoader) { map.put(clsName, provider.get()); } } } private void loadInstalledPlugins(Map<String, JadxPlugin> map) { List<Path> jars = JadxPluginsTools.getInstance().getEnabledPluginJars(); for (Path jar : jars) { loadFromJar(map, jar); } } private void loadFromJar(Map<String, JadxPlugin> map, Path jar) { try { File jarFile = jar.toFile(); String clsLoaderName = JADX_PLUGIN_CLASSLOADER_PREFIX + jarFile.getName(); URL[] urls = new URL[] { jarFile.toURI().toURL() }; URLClassLoader pluginClsLoader = new URLClassLoader(clsLoaderName, urls, thisClassLoader()); classLoaders.add(pluginClsLoader); loadFromClsLoader(map, pluginClsLoader); } catch (Exception e) { throw new JadxRuntimeException("Failed to load plugins from jar: " + jar, e); } } private static ClassLoader thisClassLoader() { return JadxExternalPluginsLoader.class.getClassLoader(); } @Override public void close() { try { for (URLClassLoader classLoader : classLoaders) { try { classLoader.close(); } catch (Exception e) { // ignore } } } finally { classLoaders.clear(); } } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins-tools/src/main/java/jadx/plugins/tools/utils/PluginUtils.java
jadx-plugins-tools/src/main/java/jadx/plugins/tools/utils/PluginUtils.java
package jadx.plugins.tools.utils; import java.io.InputStream; import java.net.URI; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.jetbrains.annotations.Nullable; public class PluginUtils { public static String removePrefix(String str, String prefix) { if (str.startsWith(prefix)) { return str.substring(prefix.length()); } return str; } public static void downloadFile(String fileUrl, Path destPath) { try (InputStream in = URI.create(fileUrl).toURL().openStream()) { Files.copy(in, destPath, StandardCopyOption.REPLACE_EXISTING); } catch (Exception e) { throw new RuntimeException("Failed to download file: " + fileUrl, e); } } private static final Pattern VERSION_LONG = Pattern.compile(".*v?(\\d+\\.\\d+\\.\\d+).*"); private static final Pattern VERSION_SHORT = Pattern.compile(".*v?(\\d+\\.\\d+).*"); public static @Nullable String extractVersion(String str) { Matcher longMatcher = VERSION_LONG.matcher(str); if (longMatcher.matches()) { return longMatcher.group(1); } Matcher shortMatcher = VERSION_SHORT.matcher(str); if (shortMatcher.matches()) { return shortMatcher.group(1); } return null; } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins-tools/src/main/java/jadx/plugins/tools/utils/PluginFiles.java
jadx-plugins-tools/src/main/java/jadx/plugins/tools/utils/PluginFiles.java
package jadx.plugins.tools.utils; import java.nio.file.Path; import jadx.commons.app.JadxCommonFiles; import static jadx.core.utils.files.FileUtils.makeDirs; public class PluginFiles { private static final Path PLUGINS_DIR = JadxCommonFiles.getConfigDir().resolve("plugins"); public static final Path PLUGINS_JSON = PLUGINS_DIR.resolve("plugins.json"); public static final Path INSTALLED_DIR = PLUGINS_DIR.resolve("installed"); public static final Path DROPINS_DIR = PLUGINS_DIR.resolve("dropins"); public static final Path PLUGINS_LIST_CACHE = JadxCommonFiles.getCacheDir().resolve("plugin-list.json"); static { makeDirs(INSTALLED_DIR); makeDirs(DROPINS_DIR); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins-tools/src/main/java/jadx/plugins/tools/data/JadxPluginMetadata.java
jadx-plugins-tools/src/main/java/jadx/plugins/tools/data/JadxPluginMetadata.java
package jadx.plugins.tools.data; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class JadxPluginMetadata implements Comparable<JadxPluginMetadata> { private String pluginId; private String name; private String description; private String homepage; private @Nullable String requiredJadxVersion; private @Nullable String version; private String locationId; private String jar; private boolean disabled; public String getPluginId() { return pluginId; } public void setPluginId(String pluginId) { this.pluginId = pluginId; } public String getName() { return name; } public void setName(String name) { this.name = name; } public @Nullable String getVersion() { return version; } public void setVersion(@Nullable String version) { this.version = version; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public String getHomepage() { return homepage; } public void setHomepage(String homepage) { this.homepage = homepage; } public @Nullable String getRequiredJadxVersion() { return requiredJadxVersion; } public void setRequiredJadxVersion(@Nullable String requiredJadxVersion) { this.requiredJadxVersion = requiredJadxVersion; } public String getLocationId() { return locationId; } public void setLocationId(String locationId) { this.locationId = locationId; } public String getJar() { return jar; } public void setJar(String jar) { this.jar = jar; } public boolean isDisabled() { return disabled; } public void setDisabled(boolean disabled) { this.disabled = disabled; } @Override public boolean equals(Object other) { if (this == other) { return true; } if (!(other instanceof JadxPluginMetadata)) { return false; } return pluginId.equals(((JadxPluginMetadata) other).pluginId); } @Override public int hashCode() { return pluginId.hashCode(); } @Override public int compareTo(@NotNull JadxPluginMetadata o) { return pluginId.compareTo(o.pluginId); } @Override public String toString() { return "JadxPluginMetadata{" + "id=" + pluginId + ", name=" + name + ", version=" + (version != null ? version : "?") + ", locationId=" + locationId + ", jar=" + jar + '}'; } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins-tools/src/main/java/jadx/plugins/tools/data/JadxPluginListCache.java
jadx-plugins-tools/src/main/java/jadx/plugins/tools/data/JadxPluginListCache.java
package jadx.plugins.tools.data; import java.util.List; public class JadxPluginListCache { private String version; private List<JadxPluginListEntry> list; public String getVersion() { return version; } public void setVersion(String version) { this.version = version; } public List<JadxPluginListEntry> getList() { return list; } public void setList(List<JadxPluginListEntry> list) { this.list = list; } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins-tools/src/main/java/jadx/plugins/tools/data/JadxInstalledPlugins.java
jadx-plugins-tools/src/main/java/jadx/plugins/tools/data/JadxInstalledPlugins.java
package jadx.plugins.tools.data; import java.util.ArrayList; import java.util.List; public class JadxInstalledPlugins { private int version; private long updated; private List<JadxPluginMetadata> installed = new ArrayList<>(); public int getVersion() { return version; } public void setVersion(int version) { this.version = version; } public long getUpdated() { return updated; } public void setUpdated(long updated) { this.updated = updated; } public List<JadxPluginMetadata> getInstalled() { return installed; } public void setInstalled(List<JadxPluginMetadata> installed) { this.installed = installed; } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins-tools/src/main/java/jadx/plugins/tools/data/JadxPluginListEntry.java
jadx-plugins-tools/src/main/java/jadx/plugins/tools/data/JadxPluginListEntry.java
package jadx.plugins.tools.data; public class JadxPluginListEntry { private String pluginId; private String locationId; private String name; private String description; private String homepage; private int revision; public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public String getHomepage() { return homepage; } public void setHomepage(String homepage) { this.homepage = homepage; } public String getLocationId() { return locationId; } public void setLocationId(String locationId) { this.locationId = locationId; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPluginId() { return pluginId; } public void setPluginId(String pluginId) { this.pluginId = pluginId; } public int getRevision() { return revision; } public void setRevision(int revision) { this.revision = revision; } @Override public String toString() { return "JadxPluginListEntry{" + "description='" + description + '\'' + ", pluginId='" + pluginId + '\'' + ", locationId='" + locationId + '\'' + ", name='" + name + '\'' + ", homepage='" + homepage + '\'' + ", revision=" + revision + '}'; } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins-tools/src/main/java/jadx/plugins/tools/data/JadxPluginUpdate.java
jadx-plugins-tools/src/main/java/jadx/plugins/tools/data/JadxPluginUpdate.java
package jadx.plugins.tools.data; public class JadxPluginUpdate { private final JadxPluginMetadata oldVersion; private final JadxPluginMetadata newVersion; public JadxPluginUpdate(JadxPluginMetadata oldVersion, JadxPluginMetadata newVersion) { this.oldVersion = oldVersion; this.newVersion = newVersion; } public JadxPluginMetadata getOld() { return oldVersion; } public JadxPluginMetadata getNew() { return newVersion; } public String getPluginId() { return newVersion.getPluginId(); } public String getOldVersion() { return oldVersion.getVersion(); } public String getNewVersion() { return newVersion.getVersion(); } @Override public String toString() { return "PluginUpdate{" + oldVersion.getPluginId() + ": " + oldVersion.getVersion() + " -> " + newVersion.getVersion() + "}"; } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins-tools/src/main/java/jadx/plugins/tools/resolvers/ResolversRegistry.java
jadx-plugins-tools/src/main/java/jadx/plugins/tools/resolvers/ResolversRegistry.java
package jadx.plugins.tools.resolvers; import java.util.HashMap; import java.util.Map; import java.util.Objects; import jadx.plugins.tools.resolvers.file.LocalFileResolver; import jadx.plugins.tools.resolvers.github.GithubReleaseResolver; public class ResolversRegistry { private static final Map<String, IJadxPluginResolver> RESOLVERS_MAP = new HashMap<>(); static { register(new LocalFileResolver()); register(new GithubReleaseResolver()); } private static void register(IJadxPluginResolver resolver) { RESOLVERS_MAP.put(resolver.id(), resolver); } public static IJadxPluginResolver getResolver(String locationId) { Objects.requireNonNull(locationId); int sep = locationId.indexOf(':'); if (sep <= 0) { throw new IllegalArgumentException("Malformed locationId: " + locationId); } return getById(locationId.substring(0, sep)); } public static IJadxPluginResolver getById(String resolverId) { IJadxPluginResolver resolver = RESOLVERS_MAP.get(resolverId); if (resolver == null) { throw new IllegalArgumentException("Unknown resolverId: " + resolverId); } return resolver; } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins-tools/src/main/java/jadx/plugins/tools/resolvers/IJadxPluginResolver.java
jadx-plugins-tools/src/main/java/jadx/plugins/tools/resolvers/IJadxPluginResolver.java
package jadx.plugins.tools.resolvers; import java.util.List; import java.util.Optional; import jadx.plugins.tools.data.JadxPluginMetadata; public interface IJadxPluginResolver { /** * Unique resolver identifier, should be same as locationId prefix */ String id(); /** * This resolver support updates and can fetch the latest version. */ boolean isUpdateSupported(); /** * Fetch the latest version plugin metadata by location */ Optional<JadxPluginMetadata> resolve(String locationId); /** * Fetch several latest versions (pageable) of plugin by locationId. * * @param page page number, starts with 1 * @param perPage result's count limit */ List<JadxPluginMetadata> resolveVersions(String locationId, int page, int perPage); /** * Check if locationId has a specified version number */ boolean hasVersion(String locationId); }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins-tools/src/main/java/jadx/plugins/tools/resolvers/file/LocalFileResolver.java
jadx-plugins-tools/src/main/java/jadx/plugins/tools/resolvers/file/LocalFileResolver.java
package jadx.plugins.tools.resolvers.file; import java.io.File; import java.util.List; import java.util.Optional; import jadx.plugins.tools.data.JadxPluginMetadata; import jadx.plugins.tools.resolvers.IJadxPluginResolver; import static jadx.plugins.tools.utils.PluginUtils.removePrefix; public class LocalFileResolver implements IJadxPluginResolver { @Override public String id() { return "file"; } @Override public boolean isUpdateSupported() { return false; } @Override public Optional<JadxPluginMetadata> resolve(String locationId) { if (!locationId.startsWith("file:") || !locationId.endsWith(".jar")) { return Optional.empty(); } File jarFile = new File(removePrefix(locationId, "file:")); if (!jarFile.isFile()) { throw new RuntimeException("File not found: " + jarFile.getAbsolutePath()); } JadxPluginMetadata metadata = new JadxPluginMetadata(); metadata.setLocationId(locationId); metadata.setJar(jarFile.getAbsolutePath()); return Optional.of(metadata); } @Override public List<JadxPluginMetadata> resolveVersions(String locationId, int page, int perPage) { if (page > 1) { // no other versions return List.of(); } // return only the current file return resolve(locationId).map(List::of).orElseGet(List::of); } @Override public boolean hasVersion(String locationId) { // no supported return false; } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins-tools/src/main/java/jadx/plugins/tools/resolvers/github/GithubReleaseResolver.java
jadx-plugins-tools/src/main/java/jadx/plugins/tools/resolvers/github/GithubReleaseResolver.java
package jadx.plugins.tools.resolvers.github; import java.util.List; import java.util.Optional; import java.util.regex.Pattern; import java.util.stream.Collectors; import jadx.core.utils.ListUtils; import jadx.plugins.tools.data.JadxPluginMetadata; import jadx.plugins.tools.resolvers.IJadxPluginResolver; import jadx.plugins.tools.resolvers.github.data.Asset; import jadx.plugins.tools.resolvers.github.data.Release; import jadx.plugins.tools.utils.PluginUtils; public class GithubReleaseResolver implements IJadxPluginResolver { private static final Pattern VERSION_PATTERN = Pattern.compile("v?\\d+\\.\\d+(\\.\\d+)?"); @Override public Optional<JadxPluginMetadata> resolve(String locationId) { LocationInfo info = parseLocation(locationId); if (info == null) { return Optional.empty(); } Release release = GithubTools.fetchRelease(info); JadxPluginMetadata metadata = buildMetadata(release, info); return Optional.of(metadata); } @Override public List<JadxPluginMetadata> resolveVersions(String locationId, int page, int perPage) { LocationInfo info = parseLocation(locationId); if (info == null) { return List.of(); } return GithubTools.fetchReleases(info, page, perPage) .stream() .map(r -> buildMetadata(r, info)) .collect(Collectors.toList()); } @Override public boolean hasVersion(String locationId) { LocationInfo locationInfo = parseLocation(locationId); return locationInfo != null && locationInfo.getVersion() != null; } private JadxPluginMetadata buildMetadata(Release release, LocationInfo info) { List<Asset> assets = release.getAssets(); String releaseVersion = PluginUtils.removePrefix(release.getName(), "v"); Asset asset = searchPluginAsset(assets, info.getArtifactPrefix(), releaseVersion); if (!asset.getName().contains(releaseVersion)) { String assetVersion = PluginUtils.extractVersion(asset.getName()); if (assetVersion != null) { releaseVersion = assetVersion; } } JadxPluginMetadata metadata = new JadxPluginMetadata(); metadata.setVersion(releaseVersion); metadata.setLocationId(buildLocationIdWithoutVersion(info)); // exclude version for later updates metadata.setJar(asset.getDownloadUrl()); return metadata; } private static LocationInfo parseLocation(String locationId) { if (!locationId.startsWith("github:")) { return null; } String[] parts = locationId.split(":"); if (parts.length < 3) { return null; } String owner = parts[1]; String project = parts[2]; String version = null; String artifactPrefix = project; if (parts.length >= 4) { String part = parts[3]; if (VERSION_PATTERN.matcher(part).matches()) { version = part; if (parts.length >= 5) { artifactPrefix = parts[4]; } } else { artifactPrefix = part; } } return new LocationInfo(owner, project, artifactPrefix, version); } private static Asset searchPluginAsset(List<Asset> assets, String artifactPrefix, String releaseVersion) { String artifactName = artifactPrefix + '-' + releaseVersion + ".jar"; Asset exactAsset = ListUtils.filterOnlyOne(assets, a -> a.getName().equals(artifactName)); if (exactAsset != null) { return exactAsset; } // search without version filter Asset foundAsset = ListUtils.filterOnlyOne(assets, a -> { String assetFileName = a.getName(); return assetFileName.startsWith(artifactPrefix) && assetFileName.endsWith(".jar"); }); if (foundAsset != null) { return foundAsset; } throw new RuntimeException("Release artifact with prefix '" + artifactPrefix + "' not found"); } private static String buildLocationIdWithoutVersion(LocationInfo info) { String baseLocation = "github:" + info.getOwner() + ':' + info.getProject(); if (info.getProject().equals(info.getArtifactPrefix())) { return baseLocation; } return baseLocation + ':' + info.getArtifactPrefix(); } @Override public String id() { return "github"; } @Override public boolean isUpdateSupported() { return true; } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins-tools/src/main/java/jadx/plugins/tools/resolvers/github/LocationInfo.java
jadx-plugins-tools/src/main/java/jadx/plugins/tools/resolvers/github/LocationInfo.java
package jadx.plugins.tools.resolvers.github; import org.jetbrains.annotations.Nullable; public class LocationInfo { private final String owner; private final String project; private final String artifactPrefix; private final @Nullable String version; public LocationInfo(String owner, String project, String artifactPrefix) { this(owner, project, artifactPrefix, null); } public LocationInfo(String owner, String project, String artifactPrefix, @Nullable String version) { this.owner = owner; this.project = project; this.artifactPrefix = artifactPrefix; this.version = version; } public String getOwner() { return owner; } public String getProject() { return project; } public String getArtifactPrefix() { return artifactPrefix; } public @Nullable String getVersion() { return version; } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins-tools/src/main/java/jadx/plugins/tools/resolvers/github/GithubTools.java
jadx-plugins-tools/src/main/java/jadx/plugins/tools/resolvers/github/GithubTools.java
package jadx.plugins.tools.resolvers.github; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.lang.reflect.Type; import java.net.HttpURLConnection; import java.net.URI; import java.nio.charset.StandardCharsets; import java.time.Instant; import java.util.List; import java.util.stream.Collectors; import com.google.gson.reflect.TypeToken; import jadx.core.utils.files.FileUtils; import jadx.plugins.tools.resolvers.github.data.Release; import static jadx.core.utils.GsonUtils.buildGson; public class GithubTools { private static final GithubTools GITHUB_INSTANCE = new GithubTools("https://api.github.com"); private static final Type RELEASE_TYPE = new TypeToken<Release>() { }.getType(); private static final Type RELEASE_LIST_TYPE = new TypeToken<List<Release>>() { }.getType(); public static Release fetchRelease(LocationInfo info) { return GITHUB_INSTANCE.getRelease(info); } public static List<Release> fetchReleases(LocationInfo info, int page, int perPage) { return GITHUB_INSTANCE.getReleases(info, page, perPage); } private final String baseUrl; GithubTools(String baseUrl) { this.baseUrl = baseUrl; } Release getRelease(LocationInfo info) { String projectUrl = baseUrl + "/repos/" + info.getOwner() + "/" + info.getProject(); String version = info.getVersion(); if (version == null) { // get latest version return get(projectUrl + "/releases/latest", RELEASE_TYPE); } // search version in other releases (by name) List<Release> releases = fetchReleases(info, 1, 50); return releases.stream() .filter(r -> r.getName().equals(version)) .findFirst() .orElseThrow(() -> new RuntimeException("Release with version: " + version + " not found." + " Available versions: " + releases.stream().map(Release::getName).collect(Collectors.joining(", ")))); } List<Release> getReleases(LocationInfo info, int page, int perPage) { String projectUrl = baseUrl + "/repos/" + info.getOwner() + "/" + info.getProject(); String requestUrl = projectUrl + "/releases?page=" + page + "&per_page=" + perPage; return get(requestUrl, RELEASE_LIST_TYPE); } private static <T> T get(String url, Type type) { HttpURLConnection con = null; try { try { con = (HttpURLConnection) URI.create(url).toURL().openConnection(); con.setRequestMethod("GET"); con.setInstanceFollowRedirects(true); int code = con.getResponseCode(); if (code != 200) { throw new RuntimeException(buildErrorDetails(con, url)); } } catch (IOException e) { throw new RuntimeException("Request failed, url: " + url, e); } try (Reader reader = new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8)) { return buildGson().fromJson(reader, type); } catch (Exception e) { throw new RuntimeException("Failed to parse response, url: " + url, e); } } finally { if (con != null) { con.disconnect(); } } } private static String buildErrorDetails(HttpURLConnection con, String url) throws IOException { String shortMsg = con.getResponseMessage(); String remainRateLimit = con.getHeaderField("X-RateLimit-Remaining"); if ("0".equals(remainRateLimit)) { String resetTimeMs = con.getHeaderField("X-RateLimit-Reset"); String timeStr = resetTimeMs != null ? "after " + Instant.ofEpochSecond(Long.parseLong(resetTimeMs)) : "in one hour"; shortMsg += " (rate limit reached, try again " + timeStr + ')'; } StringBuilder headers = new StringBuilder(); for (int i = 0;; i++) { String value = con.getHeaderField(i); if (value == null) { break; } String key = con.getHeaderFieldKey(i); if (key != null) { headers.append('\n').append(key).append(": ").append(value); } } String responseStr = getResponseString(con); return "Request failed: " + con.getResponseCode() + ' ' + shortMsg + "\nURL: " + url + "\nHeaders:" + headers + (responseStr.isEmpty() ? "" : "\nresponse:\n" + responseStr); } private static String getResponseString(HttpURLConnection con) { try (InputStream in = con.getInputStream()) { return new String(FileUtils.streamToByteArray(in), StandardCharsets.UTF_8); } catch (Exception e) { // ignore return ""; } } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins-tools/src/main/java/jadx/plugins/tools/resolvers/github/data/Asset.java
jadx-plugins-tools/src/main/java/jadx/plugins/tools/resolvers/github/data/Asset.java
package jadx.plugins.tools.resolvers.github.data; import com.google.gson.annotations.SerializedName; public class Asset { private int id; private String name; private long size; @SerializedName("browser_download_url") private String downloadUrl; @SerializedName("created_at") private String createdAt; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public long getSize() { return size; } public void setSize(long size) { this.size = size; } public String getDownloadUrl() { return downloadUrl; } public void setDownloadUrl(String downloadUrl) { this.downloadUrl = downloadUrl; } public String getCreatedAt() { return createdAt; } public void setCreatedAt(String createdAt) { this.createdAt = createdAt; } @Override public String toString() { return name + ", size: " + String.format("%.2fMB", size / 1024. / 1024.) + ", url: " + downloadUrl + ", date: " + createdAt; } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins-tools/src/main/java/jadx/plugins/tools/resolvers/github/data/Release.java
jadx-plugins-tools/src/main/java/jadx/plugins/tools/resolvers/github/data/Release.java
package jadx.plugins.tools.resolvers.github.data; import java.util.List; public class Release { private int id; private String name; private List<Asset> assets; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getId() { return id; } public void setId(int id) { this.id = id; } public List<Asset> getAssets() { return assets; } public void setAssets(List<Asset> assets) { this.assets = assets; } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(name); for (Asset asset : getAssets()) { sb.append("\n "); sb.append(asset); } return sb.toString(); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-java-convert/src/main/java/jadx/plugins/input/javaconvert/D8Converter.java
jadx-plugins/jadx-java-convert/src/main/java/jadx/plugins/input/javaconvert/D8Converter.java
package jadx.plugins.input.javaconvert; import java.nio.file.Path; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.android.tools.r8.CompilationFailedException; import com.android.tools.r8.CompilationMode; import com.android.tools.r8.D8; import com.android.tools.r8.D8Command; import com.android.tools.r8.Diagnostic; import com.android.tools.r8.DiagnosticsHandler; import com.android.tools.r8.OutputMode; public class D8Converter { private static final Logger LOG = LoggerFactory.getLogger(D8Converter.class); public static void run(Path path, Path tempDirectory, JavaConvertOptions options) throws CompilationFailedException { D8Command d8Command = D8Command.builder(new LogHandler()) .addProgramFiles(path) .setOutput(tempDirectory, OutputMode.DexIndexed) .setMode(CompilationMode.DEBUG) .setMinApiLevel(30) .setIntermediate(true) .setDisableDesugaring(!options.isD8Desugar()) .build(); D8.run(d8Command); } private static class LogHandler implements DiagnosticsHandler { @Override public void error(Diagnostic diagnostic) { LOG.error("D8 error: {}", format(diagnostic)); } @Override public void warning(Diagnostic diagnostic) { LOG.warn("D8 warning: {}", format(diagnostic)); } @Override public void info(Diagnostic diagnostic) { LOG.info("D8 info: {}", format(diagnostic)); } public static String format(Diagnostic diagnostic) { return diagnostic.getDiagnosticMessage() + ", origin: " + diagnostic.getOrigin() + ", position: " + diagnostic.getPosition(); } } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-java-convert/src/main/java/jadx/plugins/input/javaconvert/ConvertResult.java
jadx-plugins/jadx-java-convert/src/main/java/jadx/plugins/input/javaconvert/ConvertResult.java
package jadx.plugins.input.javaconvert; import java.io.Closeable; import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.Comparator; import java.util.List; import java.util.stream.Stream; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class ConvertResult implements Closeable { private static final Logger LOG = LoggerFactory.getLogger(ConvertResult.class); private final List<Path> converted = new ArrayList<>(); private final List<Path> tmpPaths = new ArrayList<>(); public List<Path> getConverted() { return converted; } public void addConvertedFiles(List<Path> paths) { converted.addAll(paths); } public void addTempPath(Path path) { tmpPaths.add(path); } public boolean isEmpty() { return converted.isEmpty(); } @Override public void close() { for (Path tmpPath : tmpPaths) { try { delete(tmpPath); } catch (Exception e) { LOG.warn("Failed to delete temp path: {}", tmpPath, e); } } } @SuppressWarnings("ResultOfMethodCallIgnored") private static void delete(Path path) throws IOException { if (Files.isRegularFile(path)) { Files.delete(path); return; } if (Files.isDirectory(path)) { try (Stream<Path> pathStream = Files.walk(path)) { pathStream .sorted(Comparator.reverseOrder()) .map(Path::toFile) .forEach(File::delete); } } } @Override public String toString() { return "ConvertResult{converted=" + converted + ", tmpPaths=" + tmpPaths + '}'; } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-java-convert/src/main/java/jadx/plugins/input/javaconvert/JavaConvertOptions.java
jadx-plugins/jadx-java-convert/src/main/java/jadx/plugins/input/javaconvert/JavaConvertOptions.java
package jadx.plugins.input.javaconvert; import jadx.api.plugins.options.impl.BasePluginOptionsBuilder; import static jadx.plugins.input.javaconvert.JavaConvertPlugin.PLUGIN_ID; public class JavaConvertOptions extends BasePluginOptionsBuilder { public enum Mode { DX, D8, BOTH } private Mode mode; private boolean d8Desugar; @Override public void registerOptions() { enumOption(PLUGIN_ID + ".mode", Mode.values(), Mode::valueOf) .description("convert mode") .defaultValue(Mode.BOTH) .setter(v -> mode = v); boolOption(PLUGIN_ID + ".d8-desugar") .description("use desugar in d8") .defaultValue(false) .setter(v -> d8Desugar = v); } public Mode getMode() { return mode; } public boolean isD8Desugar() { return d8Desugar; } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-java-convert/src/main/java/jadx/plugins/input/javaconvert/JavaConvertPlugin.java
jadx-plugins/jadx-java-convert/src/main/java/jadx/plugins/input/javaconvert/JavaConvertPlugin.java
package jadx.plugins.input.javaconvert; import java.nio.file.Path; import java.util.List; import jadx.api.plugins.JadxPlugin; import jadx.api.plugins.JadxPluginContext; import jadx.api.plugins.JadxPluginInfo; import jadx.api.plugins.JadxPluginInfoBuilder; import jadx.api.plugins.data.JadxPluginRuntimeData; import jadx.api.plugins.input.ICodeLoader; import jadx.api.plugins.input.JadxCodeInput; import jadx.api.plugins.input.data.impl.EmptyCodeLoader; import jadx.plugins.input.dex.DexInputPlugin; public class JavaConvertPlugin implements JadxPlugin, JadxCodeInput { public static final String PLUGIN_ID = "java-convert"; private final JavaConvertOptions options = new JavaConvertOptions(); private JadxPluginRuntimeData dexInput; private JavaConvertLoader loader; @Override public JadxPluginInfo getPluginInfo() { return JadxPluginInfoBuilder.pluginId(PLUGIN_ID) .name("Java Convert") .description("Convert .class, .jar and .aar files to dex") .provides("java-input") .build(); } @Override public void init(JadxPluginContext context) { context.registerOptions(options); dexInput = context.plugins().getById(DexInputPlugin.PLUGIN_ID); loader = new JavaConvertLoader(options, context); context.addCodeInput(this); } @Override public ICodeLoader loadFiles(List<Path> input) { ConvertResult result = loader.process(input); if (result.isEmpty()) { result.close(); return EmptyCodeLoader.INSTANCE; } return dexInput.loadCodeFiles(result.getConverted(), result); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-java-convert/src/main/java/jadx/plugins/input/javaconvert/DxConverter.java
jadx-plugins/jadx-java-convert/src/main/java/jadx/plugins/input/javaconvert/DxConverter.java
package jadx.plugins.input.javaconvert; import java.io.ByteArrayOutputStream; import java.nio.file.Path; import com.android.dx.command.dexer.DxContext; import com.android.dx.command.dexer.Main; public class DxConverter { private static final String CHARSET_NAME = "UTF-8"; private static class DxArgs extends com.android.dx.command.dexer.Main.Arguments { public DxArgs(DxContext context, String dexDir, String[] input) { super(context); outName = dexDir; fileNames = input; jarOutput = false; multiDex = true; optimize = true; localInfo = true; coreLibrary = true; debug = true; warnings = true; minSdkVersion = 28; } } public static void run(Path path, Path tempDirectory) { int result; String dxErrors; try (ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream errOut = new ByteArrayOutputStream()) { DxContext context = new DxContext(out, errOut); DxArgs args = new DxArgs( context, tempDirectory.toAbsolutePath().toString(), new String[] { path.toAbsolutePath().toString() }); result = new Main(context).runDx(args); dxErrors = errOut.toString(CHARSET_NAME); } catch (Exception e) { throw new RuntimeException("dx exception: " + e.getMessage(), e); } if (result != 0) { throw new RuntimeException("Java to dex conversion error, code: " + result + ", errors: " + dxErrors); } } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-java-convert/src/main/java/jadx/plugins/input/javaconvert/AsmUtils.java
jadx-plugins/jadx-java-convert/src/main/java/jadx/plugins/input/javaconvert/AsmUtils.java
package jadx.plugins.input.javaconvert; import java.io.IOException; import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; import org.objectweb.asm.ClassReader; public class AsmUtils { public static String getNameFromClassFile(Path file) throws IOException { try (InputStream in = Files.newInputStream(file)) { return getClassFullName(new ClassReader(in)); } } public static String getNameFromClassFile(byte[] content) throws IOException { return getClassFullName(new ClassReader(content)); } private static String getClassFullName(ClassReader classReader) { return classReader.getClassName(); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-java-convert/src/main/java/jadx/plugins/input/javaconvert/JavaConvertLoader.java
jadx-plugins/jadx-java-convert/src/main/java/jadx/plugins/input/javaconvert/JavaConvertLoader.java
package jadx.plugins.input.javaconvert; import java.io.IOException; import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.LinkOption; import java.nio.file.Path; import java.nio.file.PathMatcher; import java.nio.file.attribute.FileTime; import java.util.List; import java.util.Objects; import java.util.jar.JarEntry; import java.util.jar.JarOutputStream; import java.util.stream.Collectors; import java.util.stream.Stream; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import jadx.api.plugins.JadxPluginContext; import jadx.api.plugins.utils.CommonFileUtils; import jadx.api.security.IJadxSecurity; import jadx.zip.ZipReader; public class JavaConvertLoader { private static final Logger LOG = LoggerFactory.getLogger(JavaConvertLoader.class); private final JavaConvertOptions options; private final ZipReader zipReader; private final IJadxSecurity security; public JavaConvertLoader(JavaConvertOptions options, JadxPluginContext context) { this.options = options; this.zipReader = context.getZipReader(); this.security = context.getArgs().getSecurity(); } public ConvertResult process(List<Path> input) { ConvertResult result = new ConvertResult(); processJars(input, result); processAars(input, result); processClassFiles(input, result); return result; } private void processJars(List<Path> input, ConvertResult result) { PathMatcher jarMatcher = FileSystems.getDefault().getPathMatcher("glob:**.jar"); input.stream() .filter(jarMatcher::matches) .forEach(path -> { try { convertJar(result, path); } catch (Exception e) { LOG.error("Failed to convert file: {}", path.toAbsolutePath(), e); } }); } private void processClassFiles(List<Path> input, ConvertResult result) { PathMatcher jarMatcher = FileSystems.getDefault().getPathMatcher("glob:**.class"); List<Path> clsFiles = input.stream() .filter(jarMatcher::matches) .collect(Collectors.toList()); if (clsFiles.isEmpty()) { return; } try { LOG.debug("Converting class files ..."); Path jarFile = Files.createTempFile("jadx-", ".jar"); try (JarOutputStream jo = new JarOutputStream(Files.newOutputStream(jarFile))) { for (Path file : clsFiles) { String clsName = AsmUtils.getNameFromClassFile(file); if (clsName == null) { throw new IOException("Can't read class name from file: " + file); } if (!security.isValidEntryName(clsName)) { LOG.warn("Skip class with invalid name: {}", clsName); continue; } addFileToJar(jo, file, clsName + ".class"); } } result.addTempPath(jarFile); LOG.debug("Packed {} class files into jar: {}", clsFiles.size(), jarFile); convertJar(result, jarFile); } catch (Exception e) { LOG.error("Error process class files", e); } } private void processAars(List<Path> input, ConvertResult result) { PathMatcher aarMatcher = FileSystems.getDefault().getPathMatcher("glob:**.aar"); input.stream() .filter(aarMatcher::matches) .forEach(path -> zipReader.readEntries(path.toFile(), (entry, in) -> { try { String entryName = entry.getName(); if (entryName.endsWith(".jar")) { Path tempJar = CommonFileUtils.saveToTempFile(in, ".jar"); result.addTempPath(tempJar); LOG.debug("Loading jar: {} ...", entryName); convertJar(result, tempJar); } } catch (Exception e) { LOG.error("Failed to process zip entry: {}", entry, e); } })); } private void convertJar(ConvertResult result, Path path) throws Exception { if (repackAndConvertJar(result, path)) { return; } convertSimpleJar(result, path); } private boolean repackAndConvertJar(ConvertResult result, Path path) throws Exception { // check if jar needs a full repackaging Boolean repackNeeded = zipReader.visitEntries(path.toFile(), zipEntry -> { String entryName = zipEntry.getName(); if (zipEntry.isDirectory()) { if (entryName.equals("BOOT-INF/")) { return true; // Spring Boot jar } if (entryName.equals("META-INF/versions/")) { return true; // exclude duplicated classes } } if (entryName.endsWith(".jar")) { return true; // contains sub jars } if (entryName.endsWith("module-info.class")) { return true; // need to exclude module files } return null; }); if (!Objects.equals(repackNeeded, Boolean.TRUE)) { return false; } LOG.debug("Repacking jar file: {} ...", path.toAbsolutePath()); Path jarFile = Files.createTempFile("jadx-classes-", ".jar"); result.addTempPath(jarFile); try (JarOutputStream jo = new JarOutputStream(Files.newOutputStream(jarFile))) { zipReader.readEntries(path.toFile(), (entry, in) -> { try { String entryName = entry.getName(); if (entryName.endsWith(".class")) { if (entryName.endsWith("module-info.class") || entryName.startsWith("META-INF/versions/")) { LOG.debug(" exclude: {}", entryName); return; } byte[] clsFileContent = CommonFileUtils.loadBytes(in); String clsName = AsmUtils.getNameFromClassFile(clsFileContent); if (clsName == null) { throw new IOException("Can't read class name from file: " + entryName); } if (!security.isValidEntryName(clsName)) { LOG.warn("Ignore class with invalid name: {} from {}", clsName, entry); } else { addJarEntry(jo, clsName + ".class", clsFileContent, null); } } else if (entryName.endsWith(".jar")) { Path tempJar = CommonFileUtils.saveToTempFile(in, ".jar"); result.addTempPath(tempJar); convertJar(result, tempJar); } } catch (Exception e) { LOG.error("Failed to process jar entry: {} in {}", entry, path, e); } }); } convertSimpleJar(result, jarFile); return true; } private void convertSimpleJar(ConvertResult result, Path path) throws Exception { Path tempDirectory = Files.createTempDirectory("jadx-"); result.addTempPath(tempDirectory); LOG.debug("Converting to dex ..."); convert(path, tempDirectory); List<Path> dexFiles = collectFilesInDir(tempDirectory); LOG.debug("Converted {} to {} dex", path.toAbsolutePath(), dexFiles.size()); result.addConvertedFiles(dexFiles); } private void convert(Path path, Path tempDirectory) { JavaConvertOptions.Mode mode = options.getMode(); switch (mode) { case DX: try { DxConverter.run(path, tempDirectory); } catch (Throwable e) { LOG.error("DX convert failed, path: {}", path, e); } break; case D8: try { D8Converter.run(path, tempDirectory, options); } catch (Throwable e) { LOG.error("D8 convert failed, path: {}", path, e); } break; case BOTH: try { DxConverter.run(path, tempDirectory); } catch (Throwable e) { LOG.warn("DX convert failed, trying D8, path: {}", path); try { D8Converter.run(path, tempDirectory, options); } catch (Throwable ex) { LOG.error("D8 convert failed: {}", ex.getMessage()); } } break; } } private static List<Path> collectFilesInDir(Path tempDirectory) throws IOException { PathMatcher dexMatcher = FileSystems.getDefault().getPathMatcher("glob:**.dex"); try (Stream<Path> pathStream = Files.walk(tempDirectory, 1)) { return pathStream .filter(p -> Files.isRegularFile(p, LinkOption.NOFOLLOW_LINKS)) .filter(dexMatcher::matches) .collect(Collectors.toList()); } } private static void addFileToJar(JarOutputStream jar, Path source, String entryName) throws IOException { byte[] fileContent = Files.readAllBytes(source); FileTime lastModifiedTime = Files.getLastModifiedTime(source, LinkOption.NOFOLLOW_LINKS); addJarEntry(jar, entryName, fileContent, lastModifiedTime); } private static void addJarEntry(JarOutputStream jar, String entryName, byte[] content, FileTime modTime) throws IOException { JarEntry entry = new JarEntry(entryName); if (modTime != null) { entry.setTime(modTime.toMillis()); } jar.putNextEntry(entry); jar.write(content); jar.closeEntry(); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-aab-input/src/main/java/jadx/plugins/input/aab/ResTableProtoParserProvider.java
jadx-plugins/jadx-aab-input/src/main/java/jadx/plugins/input/aab/ResTableProtoParserProvider.java
package jadx.plugins.input.aab; import org.jetbrains.annotations.Nullable; import jadx.api.ResourceFile; import jadx.api.plugins.resources.IResTableParserProvider; import jadx.core.dex.nodes.RootNode; import jadx.core.xmlgen.IResTableParser; import jadx.plugins.input.aab.parsers.ResTableProtoParser; public class ResTableProtoParserProvider implements IResTableParserProvider { private RootNode root; @Override public void init(RootNode root) { this.root = root; } @Override public @Nullable IResTableParser getParser(ResourceFile resFile) { String fileName = resFile.getOriginalName(); if (!fileName.endsWith("resources.pb")) { return null; } return new ResTableProtoParser(root); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-aab-input/src/main/java/jadx/plugins/input/aab/AabInputPlugin.java
jadx-plugins/jadx-aab-input/src/main/java/jadx/plugins/input/aab/AabInputPlugin.java
package jadx.plugins.input.aab; import jadx.api.plugins.JadxPlugin; import jadx.api.plugins.JadxPluginContext; import jadx.api.plugins.JadxPluginInfo; import jadx.api.plugins.resources.IResourcesLoader; import jadx.plugins.input.aab.factories.ProtoAppDependenciesResContainerFactory; import jadx.plugins.input.aab.factories.ProtoAssetsConfigResContainerFactory; import jadx.plugins.input.aab.factories.ProtoBundleConfigResContainerFactory; import jadx.plugins.input.aab.factories.ProtoNativeConfigResContainerFactory; import jadx.plugins.input.aab.factories.ProtoTableResContainerFactory; import jadx.plugins.input.aab.factories.ProtoXmlResContainerFactory; public class AabInputPlugin implements JadxPlugin { public static final String PLUGIN_ID = "aab-input"; @Override public JadxPluginInfo getPluginInfo() { return new JadxPluginInfo( PLUGIN_ID, ".AAB Input", "Loads .AAB files."); } @Override public synchronized void init(JadxPluginContext context) { IResourcesLoader resourcesLoader = context.getResourcesLoader(); ResTableProtoParserProvider tableParserProvider = new ResTableProtoParserProvider(); resourcesLoader.addResTableParserProvider(tableParserProvider); resourcesLoader.addResContainerFactory(new ProtoTableResContainerFactory(tableParserProvider)); resourcesLoader.addResContainerFactory(new ProtoXmlResContainerFactory()); resourcesLoader.addResContainerFactory(new ProtoBundleConfigResContainerFactory()); resourcesLoader.addResContainerFactory(new ProtoAssetsConfigResContainerFactory()); resourcesLoader.addResContainerFactory(new ProtoNativeConfigResContainerFactory()); resourcesLoader.addResContainerFactory(new ProtoAppDependenciesResContainerFactory()); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-aab-input/src/main/java/jadx/plugins/input/aab/factories/ProtoAppDependenciesResContainerFactory.java
jadx-plugins/jadx-aab-input/src/main/java/jadx/plugins/input/aab/factories/ProtoAppDependenciesResContainerFactory.java
package jadx.plugins.input.aab.factories; import java.io.IOException; import java.io.InputStream; import org.jetbrains.annotations.Nullable; import com.android.bundle.AppDependenciesOuterClass; import jadx.api.ICodeInfo; import jadx.api.ResourceFile; import jadx.api.impl.SimpleCodeInfo; import jadx.api.plugins.resources.IResContainerFactory; import jadx.core.xmlgen.ResContainer; public class ProtoAppDependenciesResContainerFactory implements IResContainerFactory { @Override public @Nullable ResContainer create(ResourceFile resFile, InputStream inputStream) throws IOException { if (!resFile.getOriginalName().endsWith("BUNDLE-METADATA/com.android.tools.build.libraries/dependencies.pb")) { return null; } AppDependenciesOuterClass.AppDependencies appDependencies = AppDependenciesOuterClass.AppDependencies.parseFrom(inputStream); ICodeInfo content = new SimpleCodeInfo(appDependencies.toString()); return ResContainer.textResource(resFile.getDeobfName(), content); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-aab-input/src/main/java/jadx/plugins/input/aab/factories/ProtoBundleConfigResContainerFactory.java
jadx-plugins/jadx-aab-input/src/main/java/jadx/plugins/input/aab/factories/ProtoBundleConfigResContainerFactory.java
package jadx.plugins.input.aab.factories; import java.io.IOException; import java.io.InputStream; import org.jetbrains.annotations.Nullable; import com.android.bundle.Config.BundleConfig; import jadx.api.ICodeInfo; import jadx.api.ResourceFile; import jadx.api.impl.SimpleCodeInfo; import jadx.api.plugins.resources.IResContainerFactory; import jadx.core.xmlgen.ResContainer; public class ProtoBundleConfigResContainerFactory implements IResContainerFactory { @Override public @Nullable ResContainer create(ResourceFile resFile, InputStream inputStream) throws IOException { if (!resFile.getOriginalName().endsWith("BundleConfig.pb")) { return null; } BundleConfig bundleConfig = BundleConfig.parseFrom(inputStream); ICodeInfo content = new SimpleCodeInfo(bundleConfig.toString()); return ResContainer.textResource(resFile.getDeobfName(), content); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-aab-input/src/main/java/jadx/plugins/input/aab/factories/ProtoAssetsConfigResContainerFactory.java
jadx-plugins/jadx-aab-input/src/main/java/jadx/plugins/input/aab/factories/ProtoAssetsConfigResContainerFactory.java
package jadx.plugins.input.aab.factories; import java.io.IOException; import java.io.InputStream; import org.jetbrains.annotations.Nullable; import com.android.bundle.Files; import jadx.api.ICodeInfo; import jadx.api.ResourceFile; import jadx.api.impl.SimpleCodeInfo; import jadx.api.plugins.resources.IResContainerFactory; import jadx.core.xmlgen.ResContainer; public class ProtoAssetsConfigResContainerFactory implements IResContainerFactory { @Override public @Nullable ResContainer create(ResourceFile resFile, InputStream inputStream) throws IOException { if (!resFile.getOriginalName().endsWith("assets.pb")) { return null; } Files.Assets assetsConfig = Files.Assets.parseFrom(inputStream); ICodeInfo content = new SimpleCodeInfo(assetsConfig.toString()); return ResContainer.textResource(resFile.getDeobfName(), content); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-aab-input/src/main/java/jadx/plugins/input/aab/factories/ProtoNativeConfigResContainerFactory.java
jadx-plugins/jadx-aab-input/src/main/java/jadx/plugins/input/aab/factories/ProtoNativeConfigResContainerFactory.java
package jadx.plugins.input.aab.factories; import java.io.IOException; import java.io.InputStream; import org.jetbrains.annotations.Nullable; import com.android.bundle.Files; import jadx.api.ICodeInfo; import jadx.api.ResourceFile; import jadx.api.impl.SimpleCodeInfo; import jadx.api.plugins.resources.IResContainerFactory; import jadx.core.xmlgen.ResContainer; public class ProtoNativeConfigResContainerFactory implements IResContainerFactory { @Override public @Nullable ResContainer create(ResourceFile resFile, InputStream inputStream) throws IOException { if (!resFile.getOriginalName().endsWith("native.pb")) { return null; } Files.NativeLibraries nativeConfig = Files.NativeLibraries.parseFrom(inputStream); ICodeInfo content = new SimpleCodeInfo(nativeConfig.toString()); return ResContainer.textResource(resFile.getDeobfName(), content); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-aab-input/src/main/java/jadx/plugins/input/aab/factories/ProtoTableResContainerFactory.java
jadx-plugins/jadx-aab-input/src/main/java/jadx/plugins/input/aab/factories/ProtoTableResContainerFactory.java
package jadx.plugins.input.aab.factories; import java.io.IOException; import java.io.InputStream; import org.jetbrains.annotations.Nullable; import jadx.api.ResourceFile; import jadx.api.ResourceType; import jadx.api.plugins.resources.IResContainerFactory; import jadx.api.plugins.resources.IResTableParserProvider; import jadx.core.xmlgen.IResTableParser; import jadx.core.xmlgen.ResContainer; public class ProtoTableResContainerFactory implements IResContainerFactory { private final IResTableParserProvider provider; public ProtoTableResContainerFactory(IResTableParserProvider provider) { this.provider = provider; } @Override public @Nullable ResContainer create(ResourceFile resFile, InputStream inputStream) throws IOException { if (!resFile.getOriginalName().endsWith(".pb") || resFile.getType() != ResourceType.ARSC) { return null; } IResTableParser parser = provider.getParser(resFile); if (parser == null) { return null; } parser.decode(inputStream); return parser.decodeFiles(); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-aab-input/src/main/java/jadx/plugins/input/aab/factories/ProtoXmlResContainerFactory.java
jadx-plugins/jadx-aab-input/src/main/java/jadx/plugins/input/aab/factories/ProtoXmlResContainerFactory.java
package jadx.plugins.input.aab.factories; import java.io.IOException; import java.io.InputStream; import org.jetbrains.annotations.Nullable; import jadx.api.ICodeInfo; import jadx.api.ResourceFile; import jadx.api.ResourceType; import jadx.api.plugins.resources.IResContainerFactory; import jadx.core.dex.nodes.RootNode; import jadx.core.xmlgen.ResContainer; import jadx.plugins.input.aab.parsers.ResXmlProtoParser; import jadx.zip.IZipEntry; public class ProtoXmlResContainerFactory implements IResContainerFactory { private ResXmlProtoParser xmlParser; @Override public void init(RootNode root) { xmlParser = new ResXmlProtoParser(root); } @Override public @Nullable ResContainer create(ResourceFile resFile, InputStream inputStream) throws IOException { ResourceType type = resFile.getType(); if (type != ResourceType.XML && type != ResourceType.MANIFEST) { return null; } IZipEntry zipEntry = resFile.getZipEntry(); if (zipEntry == null) { return null; } boolean isFromAab = zipEntry.getZipFile().getPath().toLowerCase().endsWith(".aab"); if (!isFromAab) { return null; } ICodeInfo content = xmlParser.parse(inputStream); return ResContainer.textResource(resFile.getDeobfName(), content); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-aab-input/src/main/java/jadx/plugins/input/aab/parsers/ResXmlProtoParser.java
jadx-plugins/jadx-aab-input/src/main/java/jadx/plugins/input/aab/parsers/ResXmlProtoParser.java
package jadx.plugins.input.aab.parsers; import java.io.IOException; import java.io.InputStream; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Random; import java.util.Set; import com.android.aapt.Resources.XmlAttribute; import com.android.aapt.Resources.XmlElement; import com.android.aapt.Resources.XmlNamespace; import com.android.aapt.Resources.XmlNode; import jadx.api.ICodeInfo; import jadx.api.ICodeWriter; import jadx.core.dex.nodes.RootNode; import jadx.core.utils.StringUtils; import jadx.core.utils.android.AndroidResourcesMap; import jadx.core.xmlgen.XMLChar; import jadx.core.xmlgen.XmlDeobf; import jadx.core.xmlgen.XmlGenUtils; public class ResXmlProtoParser extends CommonProtoParser { private Map<String, String> nsMap; private final Map<String, String> tagAttrDeobfNames = new HashMap<>(); private ICodeWriter writer; private final RootNode rootNode; private String currentTag; private String appPackageName; private final boolean isPrettyPrint; public ResXmlProtoParser(RootNode rootNode) { this.rootNode = rootNode; this.isPrettyPrint = !rootNode.getArgs().isSkipXmlPrettyPrint(); } public synchronized ICodeInfo parse(InputStream inputStream) throws IOException { nsMap = new HashMap<>(); writer = rootNode.makeCodeWriter(); writer.add("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); decode(decodeProto(inputStream)); nsMap = null; return writer.finish(); } private void decode(XmlNode n) throws IOException { if (n.hasSource()) { writer.attachSourceLine(n.getSource().getLineNumber()); } writer.add(StringUtils.escapeXML(n.getText().trim())); if (n.hasElement()) { decode(n.getElement()); } } private void decode(XmlElement e) throws IOException { String tag = deobfClassName(e.getName()); tag = getValidTagAttributeName(tag); currentTag = tag; writer.startLine('<').add(tag); decodeNamespaces(e); decodeAttributes(e); if (e.getChildCount() > 0) { writer.add('>'); writer.incIndent(); for (int i = 0; i < e.getChildCount(); i++) { Map<String, String> oldNsMap = new HashMap<>(nsMap); decode(e.getChild(i)); nsMap = oldNsMap; } writer.decIndent(); writer.startLine("</").add(tag).add('>'); } else { writer.add(" />"); } } private void decodeNamespaces(XmlElement e) { int nsCount = e.getNamespaceDeclarationCount(); boolean newLine = nsCount != 1 && isPrettyPrint; if (nsCount > 0) { writer.add(' '); } for (int i = 0; i < nsCount; i++) { decodeNamespace(e.getNamespaceDeclaration(i), newLine, i == nsCount - 1); } } private void decodeNamespace(XmlNamespace n, boolean newLine, boolean isLastElement) { String prefix = n.getPrefix(); String uri = n.getUri(); nsMap.put(uri, prefix); writer.add("xmlns:").add(prefix).add("=\"").add(uri).add('"'); if (isLastElement) { return; } if (newLine) { writer.startLine().addIndent(); } else { writer.add(' '); } } private void decodeAttributes(XmlElement e) { int attrsCount = e.getAttributeCount(); boolean newLine = attrsCount != 1 && isPrettyPrint; if (attrsCount > 0) { writer.add(' '); if (isPrettyPrint) { writer.startLine().addIndent(); } } Set<String> attrCache = new HashSet<>(); for (int i = 0; i < attrsCount; i++) { decodeAttribute(e.getAttribute(i), attrCache, newLine, i == attrsCount - 1); } } private void decodeAttribute(XmlAttribute a, Set<String> attrCache, boolean newLine, boolean isLastElement) { String name = getAttributeFullName(a); if (XmlDeobf.isDuplicatedAttr(name, attrCache)) { return; } String value = deobfClassName(getAttributeValue(a)); writer.add(name).add("=\"").add(StringUtils.escapeXML(value)).add('\"'); memorizePackageName(name, value); if (isLastElement) { return; } if (newLine) { writer.startLine().addIndent(); } else { writer.add(' '); } } private String getAttributeFullName(XmlAttribute a) { String namespaceUri = a.getNamespaceUri(); String namespace = null; if (!namespaceUri.isEmpty()) { namespace = nsMap.get(namespaceUri); } String attrName = a.getName(); if (attrName.isEmpty()) { // some optimization tools clear the name because the Android platform doesn't need it int resId = a.getResourceId(); String str = AndroidResourcesMap.getResName(resId); if (str != null) { namespace = nsMap.get(ANDROID_NS_URL); // cut type before / int typeEnd = str.indexOf('/'); if (typeEnd != -1) { attrName = str.substring(typeEnd + 1); } else { attrName = str; } } else { attrName = "_unknown_"; } } return namespace != null ? namespace + ":" + attrName : attrName; } private String getAttributeValue(XmlAttribute a) { if (!a.getValue().isEmpty()) { return a.getValue(); } return parse(a.getCompiledItem()); } private void memorizePackageName(String attrName, String attrValue) { if ("manifest".equals(currentTag) && "package".equals(attrName)) { appPackageName = attrValue; } } private String deobfClassName(String className) { String newName = XmlDeobf.deobfClassName(rootNode, className, appPackageName); if (newName != null) { return newName; } return className; } private String getValidTagAttributeName(String originalName) { if (XMLChar.isValidName(originalName)) { return originalName; } if (tagAttrDeobfNames.containsKey(originalName)) { return tagAttrDeobfNames.get(originalName); } String generated; do { generated = generateTagAttrName(); } while (tagAttrDeobfNames.containsValue(generated)); tagAttrDeobfNames.put(originalName, generated); return generated; } private static String generateTagAttrName() { final int length = 6; Random r = new Random(); StringBuilder sb = new StringBuilder(); for (int i = 1; i <= length; i++) { sb.append((char) (r.nextInt(26) + 'a')); } return sb.toString(); } private XmlNode decodeProto(InputStream inputStream) throws IOException { return XmlNode.parseFrom(XmlGenUtils.readData(inputStream)); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-aab-input/src/main/java/jadx/plugins/input/aab/parsers/CommonProtoParser.java
jadx-plugins/jadx-aab-input/src/main/java/jadx/plugins/input/aab/parsers/CommonProtoParser.java
package jadx.plugins.input.aab.parsers; import java.util.ArrayList; import java.util.List; import com.android.aapt.ConfigurationOuterClass; import com.android.aapt.Resources; import jadx.core.xmlgen.ParserConstants; import jadx.core.xmlgen.XmlGenUtils; import jadx.core.xmlgen.entry.EntryConfig; import jadx.core.xmlgen.entry.ProtoValue; public class CommonProtoParser extends ParserConstants { protected ProtoValue parse(Resources.Style s) { List<ProtoValue> namedValues = new ArrayList<>(s.getEntryCount()); String parent = s.getParent().getName(); if (parent.isEmpty()) { parent = null; } else { parent = '@' + parent; } for (int i = 0; i < s.getEntryCount(); i++) { Resources.Style.Entry entry = s.getEntry(i); String name = entry.getKey().getName(); String value = parse(entry.getItem()); namedValues.add(new ProtoValue(value).setName(name)); } return new ProtoValue().setNamedValues(namedValues).setParent(parent); } protected ProtoValue parse(Resources.Styleable s) { List<ProtoValue> namedValues = new ArrayList<>(s.getEntryCount()); for (int i = 0; i < s.getEntryCount(); i++) { Resources.Styleable.Entry e = s.getEntry(i); namedValues.add(new ProtoValue('@' + e.getAttr().getName())); } return new ProtoValue().setNamedValues(namedValues); } protected ProtoValue parse(Resources.Array a) { List<ProtoValue> namedValues = new ArrayList<>(a.getElementCount()); for (int i = 0; i < a.getElementCount(); i++) { Resources.Array.Element e = a.getElement(i); String value = parse(e.getItem()); namedValues.add(new ProtoValue(value)); } return new ProtoValue().setNamedValues(namedValues); } protected ProtoValue parse(Resources.Attribute a) { String format = XmlGenUtils.getAttrTypeAsString(a.getFormatFlags()); List<ProtoValue> namedValues = new ArrayList<>(a.getSymbolCount()); for (int i = 0; i < a.getSymbolCount(); i++) { Resources.Attribute.Symbol s = a.getSymbol(i); int type = s.getType(); String name = s.getName().getName(); String value = String.valueOf(s.getValue()); namedValues.add(new ProtoValue(value).setName(name).setType(type)); } return new ProtoValue(format).setNamedValues(namedValues); } protected ProtoValue parse(Resources.Plural p) { List<ProtoValue> namedValues = new ArrayList<>(p.getEntryCount()); for (int i = 0; i < p.getEntryCount(); i++) { Resources.Plural.Entry e = p.getEntry(i); String name = e.getArity().name(); String value = parse(e.getItem()); namedValues.add(new ProtoValue(value).setName(name)); } return new ProtoValue().setNamedValues(namedValues); } protected ProtoValue parse(Resources.CompoundValue c) { switch (c.getValueCase()) { case STYLE: return parse(c.getStyle()); case STYLEABLE: return parse(c.getStyleable()); case ARRAY: return parse(c.getArray()); case ATTR: return parse(c.getAttr()); case PLURAL: return parse(c.getPlural()); default: return new ProtoValue("Unresolved value"); } } protected String parse(ConfigurationOuterClass.Configuration c) { char[] language = c.getLocale().toCharArray(); if (language.length == 0) { language = new char[] { '\00' }; } short mcc = (short) c.getMcc(); short mnc = (short) c.getMnc(); byte orientation = (byte) c.getOrientationValue(); short screenWidth = (short) c.getScreenWidth(); short screenHeight = (short) c.getScreenHeight(); short screenWidthDp = (short) c.getScreenWidthDp(); short screenHeightDp = (short) c.getScreenHeightDp(); short smallestScreenWidthDp = (short) c.getSmallestScreenWidthDp(); short sdkVersion = (short) c.getSdkVersion(); byte keyboard = (byte) c.getKeyboardValue(); byte touchscreen = (byte) c.getTouchscreenValue(); int density = c.getDensity(); byte screenLayout = (byte) c.getScreenLayoutLongValue(); byte colorMode = (byte) (c.getHdrValue() | c.getWideColorGamutValue()); byte screenLayout2 = (byte) (c.getLayoutDirectionValue() | c.getScreenRoundValue()); byte navigation = (byte) c.getNavigationValue(); byte inputFlags = (byte) (c.getKeysHiddenValue() | c.getNavHiddenValue()); byte grammaticalInflection = (byte) c.getGrammaticalGenderValue(); int size = c.getSerializedSize(); byte uiMode = (byte) (c.getUiModeNightValue() | c.getUiModeTypeValue()); c.getScreenLayoutSize(); // unknown field c.getProduct(); // unknown field return new EntryConfig(mcc, mnc, language, new char[] { '\00' }, orientation, touchscreen, density, keyboard, navigation, inputFlags, grammaticalInflection, screenWidth, screenHeight, sdkVersion, screenLayout, uiMode, smallestScreenWidthDp, screenWidthDp, screenHeightDp, new char[] { '\00' }, new char[] { '\00' }, screenLayout2, colorMode, false, size).getQualifiers(); } protected String parse(Resources.Item i) { if (i.hasRawStr()) { return i.getRawStr().getValue(); } if (i.hasStr()) { return i.getStr().getValue(); } if (i.hasStyledStr()) { return i.getStyledStr().getValue(); } if (i.hasPrim()) { Resources.Primitive prim = i.getPrim(); switch (prim.getOneofValueCase()) { case NULL_VALUE: return null; case INT_DECIMAL_VALUE: return String.valueOf(prim.getIntDecimalValue()); case INT_HEXADECIMAL_VALUE: return Integer.toHexString(prim.getIntHexadecimalValue()); case BOOLEAN_VALUE: return String.valueOf(prim.getBooleanValue()); case FLOAT_VALUE: return String.valueOf(prim.getFloatValue()); case COLOR_ARGB4_VALUE: return String.format("#%04x", prim.getColorArgb4Value()); case COLOR_ARGB8_VALUE: return String.format("#%08x", prim.getColorArgb8Value()); case COLOR_RGB4_VALUE: return String.format("#%03x", prim.getColorRgb4Value()); case COLOR_RGB8_VALUE: return String.format("#%06x", prim.getColorRgb8Value()); case DIMENSION_VALUE: return XmlGenUtils.decodeComplex(prim.getDimensionValue(), false); case FRACTION_VALUE: return XmlGenUtils.decodeComplex(prim.getDimensionValue(), true); case EMPTY_VALUE: default: return ""; } } if (i.hasRef()) { Resources.Reference ref = i.getRef(); String value = ref.getName(); if (value.isEmpty()) { value = "id/" + ref.getId(); } return '@' + value; } if (i.hasFile()) { return i.getFile().getPath(); } return ""; } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-aab-input/src/main/java/jadx/plugins/input/aab/parsers/ResTableProtoParser.java
jadx-plugins/jadx-aab-input/src/main/java/jadx/plugins/input/aab/parsers/ResTableProtoParser.java
package jadx.plugins.input.aab.parsers; import java.io.IOException; import java.io.InputStream; import java.util.List; import com.android.aapt.Resources.ConfigValue; import com.android.aapt.Resources.Entry; import com.android.aapt.Resources.Package; import com.android.aapt.Resources.ResourceTable; import com.android.aapt.Resources.Type; import com.android.aapt.Resources.Value; import jadx.api.ICodeInfo; import jadx.core.dex.nodes.RootNode; import jadx.core.utils.files.FileUtils; import jadx.core.xmlgen.BinaryXMLStrings; import jadx.core.xmlgen.IResTableParser; import jadx.core.xmlgen.ResContainer; import jadx.core.xmlgen.ResXmlGen; import jadx.core.xmlgen.ResourceStorage; import jadx.core.xmlgen.XmlGenUtils; import jadx.core.xmlgen.entry.ProtoValue; import jadx.core.xmlgen.entry.ResourceEntry; import jadx.core.xmlgen.entry.ValuesParser; public class ResTableProtoParser extends CommonProtoParser implements IResTableParser { private final RootNode root; private ResourceStorage resStorage; private String baseFileName = ""; public ResTableProtoParser(RootNode root) { this.root = root; } @Override public void setBaseFileName(String fileName) { this.baseFileName = fileName; } @Override public void decode(InputStream inputStream) throws IOException { resStorage = new ResourceStorage(root.getArgs().getSecurity()); ResourceTable table = ResourceTable.parseFrom(FileUtils.streamToByteArray(inputStream)); for (Package p : table.getPackageList()) { parse(p); } resStorage.finish(); } @Override public synchronized ResContainer decodeFiles() { ValuesParser vp = new ValuesParser(new BinaryXMLStrings(), resStorage.getResourcesNames()); ResXmlGen resGen = new ResXmlGen(resStorage, vp, root.initManifestAttributes()); ICodeInfo content = XmlGenUtils.makeXmlDump(root.makeCodeWriter(), resStorage); List<ResContainer> xmlFiles = resGen.makeResourcesXml(root.getArgs()); return ResContainer.resourceTable(baseFileName, xmlFiles, content); } private void parse(Package p) { String packageName = p.getPackageName(); resStorage.setAppPackage(packageName); List<Type> types = p.getTypeList(); for (Type type : types) { String typeName = type.getName(); for (Entry entry : type.getEntryList()) { int id = p.getPackageId().getId() << 24 | type.getTypeId().getId() << 16 | entry.getEntryId().getId(); String entryName = entry.getName(); for (ConfigValue configValue : entry.getConfigValueList()) { String config = parse(configValue.getConfig()); ResourceEntry resEntry = new ResourceEntry(id, packageName, typeName, entryName, config); resStorage.add(resEntry); ProtoValue protoValue; if (configValue.getValue().getValueCase() == Value.ValueCase.ITEM) { protoValue = new ProtoValue(parse(configValue.getValue().getItem())); } else { protoValue = parse(configValue.getValue().getCompoundValue()); } resEntry.setProtoValue(protoValue); } } } } @Override public ResourceStorage getResStorage() { return resStorage; } @Override public BinaryXMLStrings getStrings() { return new BinaryXMLStrings(); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/test/java/jadx/plugins/input/dex/DexInputPluginTest.java
jadx-plugins/jadx-dex-input/src/test/java/jadx/plugins/input/dex/DexInputPluginTest.java
package jadx.plugins.input.dex; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Collections; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import org.junit.jupiter.api.Test; import jadx.api.plugins.input.ICodeLoader; import jadx.api.plugins.input.data.AccessFlags; import jadx.api.plugins.input.data.AccessFlagsScope; import jadx.api.plugins.input.data.ICodeReader; import jadx.plugins.input.dex.utils.SmaliTestUtils; import static org.assertj.core.api.Assertions.assertThat; class DexInputPluginTest { @Test public void loadSampleApk() throws Exception { processFile(Paths.get(ClassLoader.getSystemResource("samples/app-with-fake-dex.apk").toURI())); } @Test public void loadHelloWorld() throws Exception { processFile(Paths.get(ClassLoader.getSystemResource("samples/hello.dex").toURI())); } @Test public void loadTestSmali() throws Exception { processFile(SmaliTestUtils.compileSmaliFromResource("samples/test.smali")); } private static void processFile(Path sample) throws IOException { System.out.println("Input file: " + sample.toAbsolutePath()); long start = System.currentTimeMillis(); List<Path> files = Collections.singletonList(sample); try (ICodeLoader result = new DexInputPlugin().loadFiles(files)) { AtomicInteger count = new AtomicInteger(); result.visitClasses(cls -> { System.out.println(); System.out.println("Class: " + cls.getType()); System.out.println("AccessFlags: " + AccessFlags.format(cls.getAccessFlags(), AccessFlagsScope.CLASS)); System.out.println("SuperType: " + cls.getSuperType()); System.out.println("Interfaces: " + cls.getInterfacesTypes()); System.out.println("Attributes: " + cls.getAttributes()); count.getAndIncrement(); cls.visitFieldsAndMethods( System.out::println, mth -> { System.out.println("---"); System.out.println(mth); ICodeReader codeReader = mth.getCodeReader(); if (codeReader != null) { codeReader.visitInstructions(insn -> { insn.decode(); System.out.println(insn); }); } System.out.println("---"); System.out.println(mth.disassembleMethod()); System.out.println("---"); }); System.out.println("----"); System.out.println(cls.getDisassembledCode()); System.out.println("----"); }); assertThat(count.get()).isGreaterThan(0); } System.out.println("Time: " + (System.currentTimeMillis() - start) + "ms"); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/test/java/jadx/plugins/input/dex/utils/SmaliTestUtils.java
jadx-plugins/jadx-dex-input/src/test/java/jadx/plugins/input/dex/utils/SmaliTestUtils.java
package jadx.plugins.input.dex.utils; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import com.android.tools.smali.smali.Smali; import com.android.tools.smali.smali.SmaliOptions; public class SmaliTestUtils { public static Path compileSmaliFromResource(String res) { try { Path input = Paths.get(ClassLoader.getSystemResource(res).toURI()); return compileSmali(input); } catch (Exception e) { throw new AssertionError("Smali assemble error", e); } } public static Path compileSmali(Path input) { try { Path tempFile = Files.createTempFile("jadx", "smali.dex"); compileSmali(tempFile, Collections.singletonList(input)); return tempFile; } catch (Exception e) { throw new AssertionError("Smali assemble error", e); } } private static void compileSmali(Path output, List<Path> inputFiles) { try { SmaliOptions options = new SmaliOptions(); options.outputDexFile = output.toAbsolutePath().toString(); List<String> inputFileNames = inputFiles.stream() .map(Path::toAbsolutePath) .map(Path::toString) .collect(Collectors.toList()); Smali.assemble(options, inputFileNames); } catch (Exception e) { throw new AssertionError("Smali assemble error", e); } } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/DexFileLoader.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/DexFileLoader.java
package jadx.plugins.input.dex; import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import jadx.api.plugins.utils.CommonFileUtils; import jadx.core.utils.files.FileUtils; import jadx.plugins.input.dex.sections.DexConsts; import jadx.plugins.input.dex.sections.DexHeaderV41; import jadx.plugins.input.dex.utils.DexCheckSum; import jadx.zip.IZipEntry; import jadx.zip.ZipContent; import jadx.zip.ZipReader; public class DexFileLoader { private static final Logger LOG = LoggerFactory.getLogger(DexFileLoader.class); // sharing between all instances (can be used in other plugins) // TODO: private static int dexUniqId = 1; private final DexInputOptions options; private ZipReader zipReader = new ZipReader(); public DexFileLoader(DexInputOptions options) { this.options = options; } public void setZipReader(ZipReader zipReader) { this.zipReader = zipReader; } public List<DexReader> collectDexFiles(List<Path> pathsList) { return pathsList.stream() .map(Path::toFile) .map(this::loadDexFromFile) .filter(list -> !list.isEmpty()) .flatMap(Collection::stream) .peek(dr -> LOG.debug("Loading dex: {}", dr)) .collect(Collectors.toList()); } private List<DexReader> loadDexFromFile(File file) { try (InputStream inputStream = new FileInputStream(file)) { return load(file, inputStream, file.getAbsolutePath()); } catch (Exception e) { LOG.error("File open error: {}", file.getAbsolutePath(), e); return Collections.emptyList(); } } private List<DexReader> load(@Nullable File file, InputStream inputStream, String fileName) throws IOException { try (InputStream in = inputStream.markSupported() ? inputStream : new BufferedInputStream(inputStream)) { byte[] magic = new byte[DexConsts.MAX_MAGIC_SIZE]; in.mark(magic.length); if (in.read(magic) != magic.length) { return Collections.emptyList(); } if (isStartWithBytes(magic, DexConsts.DEX_FILE_MAGIC)) { in.reset(); byte[] content = readAllBytes(in); return loadDexReaders(fileName, content); } if (fileName.endsWith(".dex")) { // report invalid magic in '.dex' file String hex = FileUtils.bytesToHex(magic); String str = new String(magic, StandardCharsets.US_ASCII); LOG.warn("Invalid DEX magic: 0x{}(\"{}\") in file: {}", hex, str, fileName); } if (file != null) { // allow only top level zip files if (isStartWithBytes(magic, DexConsts.ZIP_FILE_MAGIC) || CommonFileUtils.isZipFileExt(fileName)) { return collectDexFromZip(file); } } return Collections.emptyList(); } } private List<DexReader> loadFromZipEntry(byte[] content, String fileName) { if (isStartWithBytes(content, DexConsts.DEX_FILE_MAGIC) || fileName.endsWith(".dex")) { return loadDexReaders(fileName, content); } return Collections.emptyList(); } public List<DexReader> loadDexReaders(String fileName, byte[] content) { DexHeaderV41 dexHeaderV41 = DexHeaderV41.readIfPresent(content); if (dexHeaderV41 != null) { return DexHeaderV41.readSubDexOffsets(content, dexHeaderV41) .stream() .map(offset -> loadSingleDex(fileName, content, offset)) .collect(Collectors.toList()); } DexReader dexReader = loadSingleDex(fileName, content, 0); return Collections.singletonList(dexReader); } private DexReader loadSingleDex(String fileName, byte[] content, int offset) { if (options.isVerifyChecksum()) { DexCheckSum.verify(fileName, content, offset); } return new DexReader(getNextUniqId(), fileName, content, offset); } /** * Since DEX v41, several sub DEX structures can be stored inside container of a single DEX file * Use {@link DexFileLoader#loadDexReaders(String, byte[])} instead. */ @Deprecated public DexReader loadDexReader(String fileName, byte[] content) { return loadSingleDex(fileName, content, 0); } private List<DexReader> collectDexFromZip(File file) { List<DexReader> result = new ArrayList<>(); try (ZipContent zip = zipReader.open(file)) { for (IZipEntry entry : zip.getEntries()) { if (entry.isDirectory()) { continue; } try { List<DexReader> readers; if (entry.preferBytes()) { readers = loadFromZipEntry(entry.getBytes(), entry.getName()); } else { readers = load(null, entry.getInputStream(), entry.getName()); } if (!readers.isEmpty()) { result.addAll(readers); } } catch (Exception e) { LOG.error("Failed to read zip entry: {}", entry, e); } } } catch (Exception e) { LOG.error("Failed to process zip file: {}", file.getAbsolutePath(), e); } return result; } private static boolean isStartWithBytes(byte[] fileMagic, byte[] expectedBytes) { int len = expectedBytes.length; if (fileMagic.length < len) { return false; } for (int i = 0; i < len; i++) { if (fileMagic[i] != expectedBytes[i]) { return false; } } return true; } private static byte[] readAllBytes(InputStream in) throws IOException { ByteArrayOutputStream buf = new ByteArrayOutputStream(); byte[] data = new byte[8192]; while (true) { int read = in.read(data); if (read == -1) { break; } buf.write(data, 0, read); } return buf.toByteArray(); } private static synchronized int getNextUniqId() { dexUniqId++; if (dexUniqId >= 0xFFFF) { dexUniqId = 1; } return dexUniqId; } private static synchronized void resetDexUniqId() { dexUniqId = 1; } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/DexInputOptions.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/DexInputOptions.java
package jadx.plugins.input.dex; import jadx.api.plugins.options.impl.BasePluginOptionsBuilder; public class DexInputOptions extends BasePluginOptionsBuilder { private boolean verifyChecksum; @Override public void registerOptions() { boolOption(DexInputPlugin.PLUGIN_ID + ".verify-checksum") .description("verify dex file checksum before load") .defaultValue(true) .setter(v -> verifyChecksum = v); } public boolean isVerifyChecksum() { return verifyChecksum; } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/DexInputPlugin.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/DexInputPlugin.java
package jadx.plugins.input.dex; import java.io.Closeable; import java.io.InputStream; import java.nio.file.Path; import java.util.List; import java.util.stream.Collectors; import org.jetbrains.annotations.Nullable; import jadx.api.plugins.JadxPlugin; import jadx.api.plugins.JadxPluginContext; import jadx.api.plugins.JadxPluginInfo; import jadx.api.plugins.input.ICodeLoader; import jadx.api.plugins.input.data.impl.EmptyCodeLoader; import jadx.api.plugins.utils.CommonFileUtils; import jadx.plugins.input.dex.utils.IDexData; public class DexInputPlugin implements JadxPlugin { public static final String PLUGIN_ID = "dex-input"; private final DexInputOptions options = new DexInputOptions(); private final DexFileLoader loader = new DexFileLoader(options); @Override public JadxPluginInfo getPluginInfo() { return new JadxPluginInfo(PLUGIN_ID, "Dex Input", "Load .dex and .apk files"); } @Override public void init(JadxPluginContext context) { context.registerOptions(options); context.addCodeInput(this::loadFiles); loader.setZipReader(context.getZipReader()); } public ICodeLoader loadFiles(List<Path> input) { return loadFiles(input, null); } public ICodeLoader loadFiles(List<Path> inputFiles, @Nullable Closeable closeable) { List<DexReader> dexReaders = loader.collectDexFiles(inputFiles); if (dexReaders.isEmpty()) { return EmptyCodeLoader.INSTANCE; } return new DexLoadResult(dexReaders, closeable); } public ICodeLoader loadDex(byte[] content, @Nullable String fileName) { String fileLabel = fileName == null ? "input.dex" : fileName; List<DexReader> dexReaders = loader.loadDexReaders(fileLabel, content); return new DexLoadResult(dexReaders, null); } public ICodeLoader loadDexFromInputStream(InputStream in, @Nullable String fileLabel) { try { return loadDex(CommonFileUtils.loadBytes(in), fileLabel); } catch (Exception e) { throw new DexException("Failed to read input stream", e); } } public ICodeLoader loadDexData(List<IDexData> list) { List<DexReader> readers = list.stream() .flatMap(data -> loader.loadDexReaders(data.getFileName(), data.getContent()).stream()) .collect(Collectors.toList()); return new DexLoadResult(readers, null); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/DexException.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/DexException.java
package jadx.plugins.input.dex; public class DexException extends RuntimeException { private static final long serialVersionUID = -5575702801815409269L; public DexException(String message, Throwable cause) { super(message, cause); } public DexException(String message) { super(message); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/DexReader.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/DexReader.java
package jadx.plugins.input.dex; import java.nio.ByteBuffer; import java.util.function.Consumer; import jadx.api.plugins.input.data.IClassData; import jadx.plugins.input.dex.sections.DexClassData; import jadx.plugins.input.dex.sections.DexHeader; import jadx.plugins.input.dex.sections.SectionReader; import jadx.plugins.input.dex.sections.annotations.AnnotationsParser; public class DexReader { private final int uniqId; private final String inputFileName; private final ByteBuffer buf; private final DexHeader header; public DexReader(int uniqId, String inputFileName, byte[] content, int offset) { this.uniqId = uniqId; this.inputFileName = inputFileName; this.buf = ByteBuffer.wrap(content); this.header = new DexHeader(new SectionReader(this, offset)); } public void visitClasses(Consumer<IClassData> consumer) { int count = header.getClassDefsSize(); if (count == 0) { return; } int classDefsOff = header.getClassDefsOff(); SectionReader in = new SectionReader(this, classDefsOff); AnnotationsParser annotationsParser = new AnnotationsParser(in.copy(), in.copy()); DexClassData classData = new DexClassData(in, annotationsParser); for (int i = 0; i < count; i++) { consumer.accept(classData); in.shiftOffset(DexClassData.SIZE); } } public ByteBuffer getBuf() { return buf; } public DexHeader getHeader() { return header; } public String getInputFileName() { return inputFileName; } public int getUniqId() { return uniqId; } @Override public String toString() { return inputFileName; } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/DexLoadResult.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/DexLoadResult.java
package jadx.plugins.input.dex; import java.io.Closeable; import java.io.IOException; import java.util.List; import java.util.function.Consumer; import org.jetbrains.annotations.Nullable; import jadx.api.plugins.input.ICodeLoader; import jadx.api.plugins.input.data.IClassData; public class DexLoadResult implements ICodeLoader { private final List<DexReader> dexReaders; @Nullable private final Closeable closeable; public DexLoadResult(List<DexReader> dexReaders, @Nullable Closeable closeable) { this.dexReaders = dexReaders; this.closeable = closeable; } @Override public void visitClasses(Consumer<IClassData> consumer) { for (DexReader dexReader : dexReaders) { dexReader.visitClasses(consumer); } } @Override public void close() throws IOException { if (closeable != null) { closeable.close(); } } @Override public boolean isEmpty() { return dexReaders.isEmpty(); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/smali/SmaliCodeWriter.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/smali/SmaliCodeWriter.java
package jadx.plugins.input.dex.smali; import java.util.List; public class SmaliCodeWriter { public static final String NL = System.getProperty("line.separator"); public static final String INDENT_STR = " "; private final StringBuilder code = new StringBuilder(); private int indent; private String indentStr = ""; public SmaliCodeWriter startLine(String line) { startLine(); code.append(line); return this; } public SmaliCodeWriter startLine() { if (code.length() != 0) { code.append(NL); code.append(indentStr); } return this; } public SmaliCodeWriter add(Object obj) { code.append(obj); return this; } public SmaliCodeWriter add(int i) { code.append(i); return this; } public SmaliCodeWriter add(char c) { code.append(c); return this; } public SmaliCodeWriter add(String str) { code.append(str); return this; } public SmaliCodeWriter addArgs(List<String> argTypes) { for (String type : argTypes) { code.append(type); } return this; } public void incIndent() { this.indent++; buildIndent(); } public void decIndent() { this.indent--; buildIndent(); } private void buildIndent() { StringBuilder s = new StringBuilder(indent * INDENT_STR.length()); for (int i = 0; i < indent; i++) { s.append(INDENT_STR); } this.indentStr = s.toString(); } public String getCode() { return code.toString(); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/smali/InsnFormatterInfo.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/smali/InsnFormatterInfo.java
package jadx.plugins.input.dex.smali; import java.util.Objects; import org.jetbrains.annotations.Nullable; import jadx.api.plugins.input.data.IMethodData; import jadx.api.plugins.input.insns.InsnData; public class InsnFormatterInfo { private final SmaliCodeWriter codeWriter; @Nullable private IMethodData mth; @Nullable private InsnData insn; public InsnFormatterInfo(SmaliCodeWriter codeWriter, IMethodData mth) { this.codeWriter = codeWriter; this.mth = Objects.requireNonNull(mth); } public InsnFormatterInfo(SmaliCodeWriter codeWriter, InsnData insn) { this.codeWriter = codeWriter; this.insn = Objects.requireNonNull(insn); } public SmaliCodeWriter getCodeWriter() { return codeWriter; } public void setMth(IMethodData mth) { this.mth = mth; } public IMethodData getMth() { return mth; } public InsnData getInsn() { if (insn == null) { throw new NullPointerException("Instruction not set for formatter"); } return insn; } public void setInsn(InsnData insn) { this.insn = insn; } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/smali/SmaliInsnFormat.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/smali/SmaliInsnFormat.java
package jadx.plugins.input.dex.smali; import java.util.HashMap; import java.util.Map; import org.jetbrains.annotations.NotNull; import jadx.api.plugins.input.insns.InsnData; import jadx.plugins.input.dex.insns.DexOpcodes; public class SmaliInsnFormat { private static SmaliInsnFormat instance; public static synchronized SmaliInsnFormat getInstance() { SmaliInsnFormat instance = SmaliInsnFormat.instance; if (instance == null) { instance = new SmaliInsnFormat(); SmaliInsnFormat.instance = instance; } return instance; } private final Map<Integer, InsnFormatter> formatters; public SmaliInsnFormat() { formatters = registerFormatters(); } private Map<Integer, InsnFormatter> registerFormatters() { Map<Integer, InsnFormatter> map = new HashMap<>(); map.put(DexOpcodes.NOP, fi -> fi.getCodeWriter().add("nop")); map.put(DexOpcodes.SGET_OBJECT, staticFieldInsn("sget-object")); map.put(DexOpcodes.SPUT_BOOLEAN, staticFieldInsn("sput-boolean")); map.put(DexOpcodes.CONST, constInsn("const")); map.put(DexOpcodes.CONST_HIGH16, constInsn("const/high16")); map.put(DexOpcodes.CONST_STRING, stringInsn("const-string")); map.put(DexOpcodes.INVOKE_VIRTUAL, invokeInsn("invoke-virtual")); map.put(DexOpcodes.INVOKE_DIRECT, invokeInsn("invoke-direct")); map.put(DexOpcodes.INVOKE_SUPER, invokeInsn("invoke-super")); map.put(DexOpcodes.INVOKE_STATIC, invokeInsn("invoke-static")); map.put(DexOpcodes.MOVE_RESULT, oneArgsInsn("move-result")); map.put(DexOpcodes.RETURN_VOID, noArgsInsn("return-void")); map.put(DexOpcodes.GOTO, gotoInsn("goto")); map.put(DexOpcodes.GOTO_16, gotoInsn("goto-16")); map.put(DexOpcodes.MOVE, simpleInsn("move")); // TODO: complete list return map; } private InsnFormatter simpleInsn(String name) { return fi -> { SmaliCodeWriter code = fi.getCodeWriter(); code.add(name); InsnData insn = fi.getInsn(); int regsCount = insn.getRegsCount(); for (int i = 0; i < regsCount; i++) { if (i == 0) { code.add(' '); } else { code.add(", "); } code.add(regAt(fi, i)); } }; } private InsnFormatter gotoInsn(String name) { return fi -> fi.getCodeWriter().add(name).add(" :goto").add(Integer.toHexString(fi.getInsn().getTarget())); } @NotNull private InsnFormatter staticFieldInsn(String name) { return fi -> fi.getCodeWriter().add(name).add(' ').add(regAt(fi, 0)).add(", ").add(field(fi)); } @NotNull private InsnFormatter constInsn(String name) { return fi -> fi.getCodeWriter().add(name).add(' ').add(regAt(fi, 0)).add(", ").add(literal(fi)); } @NotNull private InsnFormatter stringInsn(String name) { return fi -> fi.getCodeWriter().add(name).add(' ').add(regAt(fi, 0)).add(", ").add(str(fi)); } @NotNull private InsnFormatter invokeInsn(String name) { return fi -> { SmaliCodeWriter code = fi.getCodeWriter(); code.add(name).add(' '); regsList(code, fi.getInsn()); code.add(", ").add(method(fi)); }; } private InsnFormatter oneArgsInsn(String name) { return fi -> fi.getCodeWriter().add(name).add(' ').add(regAt(fi, 0)); } private InsnFormatter noArgsInsn(String name) { return fi -> fi.getCodeWriter().add(name); } private String literal(InsnFormatterInfo fi) { return "0x" + Long.toHexString(fi.getInsn().getLiteral()); } private String str(InsnFormatterInfo fi) { return "\"" + fi.getInsn().getIndexAsString() + "\""; } private String field(InsnFormatterInfo fi) { return fi.getInsn().getIndexAsField().toString(); } private String method(InsnFormatterInfo fi) { return fi.getInsn().getIndexAsMethod().toString(); } private void regsList(SmaliCodeWriter code, InsnData insn) { int argsCount = insn.getRegsCount(); code.add('{'); for (int i = 0; i < argsCount; i++) { if (i != 0) { code.add(", "); } code.add("v").add(insn.getReg(i)); } code.add('}'); } private String regAt(InsnFormatterInfo fi, int argNum) { return "v" + fi.getInsn().getReg(argNum); } public void format(InsnFormatterInfo formatInfo) { InsnData insn = formatInfo.getInsn(); insn.decode(); int rawOpcodeUnit = insn.getRawOpcodeUnit(); int opcode = rawOpcodeUnit & 0xFF; InsnFormatter insnFormatter = formatters.get(opcode); if (insnFormatter != null) { insnFormatter.format(formatInfo); } else { formatInfo.getCodeWriter().add("# ").add(insn.getOpcode()).add(" (?0x").add(Integer.toHexString(rawOpcodeUnit)).add(')'); } } public String format(InsnData insn) { InsnFormatterInfo formatInfo = new InsnFormatterInfo(new SmaliCodeWriter(), insn); format(formatInfo); return formatInfo.getCodeWriter().getCode(); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/smali/InsnFormatter.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/smali/InsnFormatter.java
package jadx.plugins.input.dex.smali; interface InsnFormatter { void format(InsnFormatterInfo insnFormatInfo); }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/smali/SmaliPrinter.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/smali/SmaliPrinter.java
package jadx.plugins.input.dex.smali; import jadx.api.plugins.input.data.AccessFlags; import jadx.api.plugins.input.data.ICodeReader; import jadx.plugins.input.dex.sections.DexMethodData; import jadx.plugins.input.dex.sections.DexMethodRef; import static jadx.api.plugins.input.data.AccessFlagsScope.METHOD; // TODO: not finished public class SmaliPrinter { public static String printMethod(DexMethodData mth) { SmaliCodeWriter codeWriter = new SmaliCodeWriter(); codeWriter.startLine(".method "); codeWriter.add(AccessFlags.format(mth.getAccessFlags(), METHOD)); DexMethodRef methodRef = mth.getMethodRef(); methodRef.load(); codeWriter.add(methodRef.getName()); codeWriter.add('(').addArgs(methodRef.getArgTypes()).add(')'); codeWriter.add(methodRef.getReturnType()); codeWriter.incIndent(); ICodeReader codeReader = mth.getCodeReader(); if (codeReader != null) { codeWriter.startLine(".registers ").add(codeReader.getRegistersCount()); SmaliInsnFormat insnFormat = SmaliInsnFormat.getInstance(); InsnFormatterInfo formatterInfo = new InsnFormatterInfo(codeWriter, mth); codeReader.visitInstructions(insn -> { codeWriter.startLine(); formatterInfo.setInsn(insn); insnFormat.format(formatterInfo); }); codeWriter.decIndent(); } codeWriter.startLine(".end method"); return codeWriter.getCode(); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/DexConsts.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/DexConsts.java
package jadx.plugins.input.dex.sections; public class DexConsts { public static final byte[] DEX_FILE_MAGIC = { 0x64, 0x65, 0x78, 0x0a }; // 'dex\n' public static final byte[] ZIP_FILE_MAGIC = { 0x50, 0x4B, 0x03, 0x04 }; public static final int MAX_MAGIC_SIZE = 4; public static final int ENDIAN_CONSTANT = 0x12345678; public static final int NO_INDEX = -1; }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/DexAnnotationsConvert.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/DexAnnotationsConvert.java
package jadx.plugins.input.dex.sections; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.stream.Collectors; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import jadx.api.plugins.input.data.annotations.AnnotationVisibility; import jadx.api.plugins.input.data.annotations.EncodedType; import jadx.api.plugins.input.data.annotations.EncodedValue; import jadx.api.plugins.input.data.annotations.IAnnotation; import jadx.api.plugins.input.data.attributes.IJadxAttribute; import jadx.api.plugins.input.data.attributes.types.AnnotationDefaultClassAttr; import jadx.api.plugins.input.data.attributes.types.AnnotationsAttr; import jadx.api.plugins.input.data.attributes.types.ExceptionsAttr; import jadx.api.plugins.input.data.attributes.types.InnerClassesAttr; import jadx.api.plugins.input.data.attributes.types.InnerClsInfo; import jadx.api.plugins.input.data.attributes.types.MethodParametersAttr; import jadx.api.plugins.input.data.attributes.types.SignatureAttr; import jadx.api.plugins.utils.Utils; import jadx.plugins.input.dex.sections.annotations.AnnotationsUtils; public class DexAnnotationsConvert { private static final Logger LOG = LoggerFactory.getLogger(DexAnnotationsConvert.class); public static void forClass(String cls, List<IJadxAttribute> list, List<IAnnotation> annotationList) { appendAnnotations(cls, list, annotationList); } public static void forMethod(List<IJadxAttribute> list, List<IAnnotation> annotationList) { appendAnnotations(null, list, annotationList); } public static void forField(List<IJadxAttribute> list, List<IAnnotation> annotationList) { appendAnnotations(null, list, annotationList); } private static void appendAnnotations(@Nullable String cls, List<IJadxAttribute> attributes, List<IAnnotation> annotations) { if (annotations.isEmpty()) { return; } for (IAnnotation annotation : annotations) { if (annotation.getVisibility() == AnnotationVisibility.SYSTEM) { convertSystemAnnotations(cls, attributes, annotation); } } Utils.addToList(attributes, AnnotationsAttr.pack(annotations)); } @SuppressWarnings("unchecked") private static void convertSystemAnnotations(@Nullable String cls, List<IJadxAttribute> attributes, IAnnotation annotation) { switch (annotation.getAnnotationClass()) { case "Ldalvik/annotation/Signature;": attributes.add(new SignatureAttr(extractSignature(annotation))); break; case "Ldalvik/annotation/InnerClass;": try { String name = AnnotationsUtils.getValue(annotation, "name", EncodedType.ENCODED_STRING, null); int accFlags = AnnotationsUtils.getValue(annotation, "accessFlags", EncodedType.ENCODED_INT, 0); if (name != null || accFlags != 0) { InnerClsInfo innerClsInfo = new InnerClsInfo(cls, null, name, accFlags); attributes.add(new InnerClassesAttr(Collections.singletonMap(cls, innerClsInfo))); } } catch (Exception e) { LOG.warn("Failed to parse annotation: {}", annotation, e); } break; case "Ldalvik/annotation/AnnotationDefault;": EncodedValue annValue = annotation.getDefaultValue(); if (annValue != null && annValue.getType() == EncodedType.ENCODED_ANNOTATION) { IAnnotation defAnnotation = (IAnnotation) annValue.getValue(); attributes.add(new AnnotationDefaultClassAttr(defAnnotation.getValues())); } break; case "Ldalvik/annotation/Throws;": try { EncodedValue defaultValue = annotation.getDefaultValue(); if (defaultValue != null) { List<String> excs = ((List<EncodedValue>) defaultValue.getValue()) .stream() .map(ev -> ((String) ev.getValue())) .collect(Collectors.toList()); attributes.add(new ExceptionsAttr(excs)); } } catch (Exception e) { LOG.warn("Failed to convert dalvik throws annotation", e); } break; case "Ldalvik/annotation/MethodParameters;": try { List<EncodedValue> names = AnnotationsUtils.getArray(annotation, "names"); List<EncodedValue> accFlags = AnnotationsUtils.getArray(annotation, "accessFlags"); if (!names.isEmpty() && names.size() == accFlags.size()) { int size = names.size(); List<MethodParametersAttr.Info> list = new ArrayList<>(size); for (int i = 0; i < size; i++) { String name = (String) names.get(i).getValue(); int accFlag = (int) accFlags.get(i).getValue(); list.add(new MethodParametersAttr.Info(accFlag, name)); } attributes.add(new MethodParametersAttr(list)); } } catch (Exception e) { LOG.warn("Failed to parse annotation: {}", annotation, e); } break; } } @SuppressWarnings({ "unchecked", "ConstantConditions" }) private static String extractSignature(IAnnotation annotation) { List<EncodedValue> values = (List<EncodedValue>) annotation.getDefaultValue().getValue(); if (values.size() == 1) { return (String) values.get(0).getValue(); } StringBuilder sb = new StringBuilder(); for (EncodedValue part : values) { sb.append((String) part.getValue()); } return sb.toString(); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/DexHeaderV41.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/DexHeaderV41.java
package jadx.plugins.input.dex.sections; import java.util.ArrayList; import java.util.List; import org.jetbrains.annotations.Nullable; import static jadx.plugins.input.dex.utils.DataReader.readU4; public class DexHeaderV41 { public static @Nullable DexHeaderV41 readIfPresent(byte[] content) { int headerSize = readU4(content, 36); if (headerSize < 120) { return null; } int fileSize = readU4(content, 32); int containerSize = readU4(content, 112); int headerOffset = readU4(content, 116); return new DexHeaderV41(fileSize, containerSize, headerOffset); } public static List<Integer> readSubDexOffsets(byte[] content, DexHeaderV41 header) { int start = 0; int end = header.getFileSize(); int limit = Math.min(header.getContainerSize(), content.length); List<Integer> list = new ArrayList<>(); while (true) { list.add(start); start = end; if (start >= limit) { break; } int nextFileSize = readU4(content, start + 32); end = start + nextFileSize; } return list; } private final int fileSize; private final int containerSize; private final int headerOffset; public DexHeaderV41(int fileSize, int containerSize, int headerOffset) { this.fileSize = fileSize; this.containerSize = containerSize; this.headerOffset = headerOffset; } public int getFileSize() { return fileSize; } public int getContainerSize() { return containerSize; } public int getHeaderOffset() { return headerOffset; } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/DexMethodProto.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/DexMethodProto.java
package jadx.plugins.input.dex.sections; import java.util.List; import jadx.api.plugins.input.data.IMethodProto; import jadx.api.plugins.utils.Utils; public class DexMethodProto implements IMethodProto { private final List<String> argTypes; private final String returnType; public DexMethodProto(List<String> argTypes, String returnType) { this.returnType = returnType; this.argTypes = argTypes; } @Override public List<String> getArgTypes() { return argTypes; } @Override public String getReturnType() { return returnType; } @Override public boolean equals(Object other) { if (this == other) { return true; } if (!(other instanceof IMethodProto)) { return false; } IMethodProto that = (IMethodProto) other; return argTypes.equals(that.getArgTypes()) && returnType.equals(that.getReturnType()); } @Override public int hashCode() { return 31 * argTypes.hashCode() + returnType.hashCode(); } @Override public String toString() { return "(" + Utils.listToStr(argTypes) + ")" + returnType; } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/DexHeader.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/DexHeader.java
package jadx.plugins.input.dex.sections; import jadx.plugins.input.dex.DexException; public class DexHeader { private final String version; private final int classDefsSize; private final int classDefsOff; private final int stringIdsOff; private final int typeIdsOff; private final int typeIdsSize; private final int fieldIdsSize; private final int fieldIdsOff; private final int protoIdsSize; private final int protoIdsOff; private final int methodIdsOff; private final int methodIdsSize; private int callSiteOff; private int methodHandleOff; public DexHeader(SectionReader buf) { byte[] magic = buf.readByteArray(4); version = buf.readString(3); buf.skip(1); int checksum = buf.readInt(); byte[] signature = buf.readByteArray(20); int fileSize = buf.readInt(); int headerSize = buf.readInt(); int endianTag = buf.readInt(); if (endianTag != DexConsts.ENDIAN_CONSTANT) { throw new DexException("Unexpected endian tag: 0x" + Integer.toHexString(endianTag)); } int linkSize = buf.readInt(); int linkOff = buf.readInt(); int mapListOff = buf.readInt(); int stringIdsSize = buf.readInt(); stringIdsOff = buf.readInt(); typeIdsSize = buf.readInt(); typeIdsOff = buf.readInt(); protoIdsSize = buf.readInt(); protoIdsOff = buf.readInt(); fieldIdsSize = buf.readInt(); fieldIdsOff = buf.readInt(); methodIdsSize = buf.readInt(); methodIdsOff = buf.readInt(); classDefsSize = buf.readInt(); classDefsOff = buf.readInt(); int dataSize = buf.readInt(); int dataOff = buf.readInt(); readMapList(buf, mapListOff); } private void readMapList(SectionReader buf, int mapListOff) { buf.absPos(mapListOff); int size = buf.readInt(); for (int i = 0; i < size; i++) { int type = buf.readUShort(); buf.skip(6); int offset = buf.readInt(); switch (type) { case 0x0007: callSiteOff = offset; break; case 0x0008: methodHandleOff = offset; break; } } } public String getVersion() { return version; } public int getClassDefsSize() { return classDefsSize; } public int getClassDefsOff() { return classDefsOff; } public int getStringIdsOff() { return stringIdsOff; } public int getTypeIdsOff() { return typeIdsOff; } public int getTypeIdsSize() { return typeIdsSize; } public int getFieldIdsSize() { return fieldIdsSize; } public int getFieldIdsOff() { return fieldIdsOff; } public int getProtoIdsSize() { return protoIdsSize; } public int getProtoIdsOff() { return protoIdsOff; } public int getMethodIdsOff() { return methodIdsOff; } public int getMethodIdsSize() { return methodIdsSize; } public int getCallSiteOff() { return callSiteOff; } public int getMethodHandleOff() { return methodHandleOff; } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/DexClassData.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/DexClassData.java
package jadx.plugins.input.dex.sections; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.function.Consumer; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import jadx.api.plugins.input.data.IClassData; import jadx.api.plugins.input.data.IFieldData; import jadx.api.plugins.input.data.IMethodData; import jadx.api.plugins.input.data.ISeqConsumer; import jadx.api.plugins.input.data.annotations.EncodedValue; import jadx.api.plugins.input.data.annotations.IAnnotation; import jadx.api.plugins.input.data.attributes.IJadxAttribute; import jadx.api.plugins.input.data.attributes.types.SourceFileAttr; import jadx.plugins.input.dex.sections.annotations.AnnotationsParser; import jadx.plugins.input.dex.utils.SmaliUtils; public class DexClassData implements IClassData { private static final Logger LOG = LoggerFactory.getLogger(DexClassData.class); public static final int SIZE = 8 * 4; private final SectionReader in; private final AnnotationsParser annotationsParser; public DexClassData(SectionReader sectionReader, AnnotationsParser annotationsParser) { this.in = sectionReader; this.annotationsParser = annotationsParser; } @Override public IClassData copy() { return new DexClassData(in.copy(), annotationsParser.copy()); } @Override public String getType() { int typeIdx = in.pos(0).readInt(); String clsType = in.getType(typeIdx); if (clsType == null) { throw new NullPointerException("Unknown class type"); } return clsType; } @Override public int getAccessFlags() { return in.pos(4).readInt(); } @Nullable @Override public String getSuperType() { int typeIdx = in.pos(2 * 4).readInt(); return in.getType(typeIdx); } @Override public List<String> getInterfacesTypes() { int offset = in.pos(3 * 4).readInt(); if (offset == 0) { return Collections.emptyList(); } return in.absPos(offset).readTypeList(); } @Nullable private String getSourceFile() { int strIdx = in.pos(4 * 4).readInt(); return in.getString(strIdx); } @Override public String getInputFileName() { return in.getDexReader().getInputFileName(); } public int getAnnotationsOff() { return in.pos(5 * 4).readInt(); } public int getClassDataOff() { return in.pos(6 * 4).readInt(); } public int getStaticValuesOff() { return in.pos(7 * 4).readInt(); } @Override public void visitFieldsAndMethods(ISeqConsumer<IFieldData> fieldConsumer, ISeqConsumer<IMethodData> mthConsumer) { int classDataOff = getClassDataOff(); if (classDataOff == 0) { return; } SectionReader data = in.copy(classDataOff); int staticFieldsCount = data.readUleb128(); int instanceFieldsCount = data.readUleb128(); int directMthCount = data.readUleb128(); int virtualMthCount = data.readUleb128(); fieldConsumer.init(staticFieldsCount + instanceFieldsCount); mthConsumer.init(directMthCount + virtualMthCount); annotationsParser.setOffset(getAnnotationsOff()); visitFields(fieldConsumer, data, staticFieldsCount, instanceFieldsCount); visitMethods(mthConsumer, data, directMthCount, virtualMthCount); } private void visitFields(Consumer<IFieldData> fieldConsumer, SectionReader data, int staticFieldsCount, int instanceFieldsCount) { Map<Integer, Integer> annotationOffsetMap = annotationsParser.readFieldsAnnotationOffsetMap(); DexFieldData fieldData = new DexFieldData(annotationsParser); fieldData.setParentClassType(getType()); readFields(fieldConsumer, data, fieldData, staticFieldsCount, annotationOffsetMap, true); readFields(fieldConsumer, data, fieldData, instanceFieldsCount, annotationOffsetMap, false); } private void readFields(Consumer<IFieldData> fieldConsumer, SectionReader data, DexFieldData fieldData, int count, Map<Integer, Integer> annOffsetMap, boolean staticFields) { List<EncodedValue> constValues = staticFields ? getStaticFieldInitValues(data.copy()) : null; int fieldId = 0; for (int i = 0; i < count; i++) { fieldId += data.readUleb128(); int accFlags = data.readUleb128(); in.fillFieldData(fieldData, fieldId); fieldData.setAccessFlags(accFlags); fieldData.setAnnotationsOffset(getOffsetFromMap(fieldId, annOffsetMap)); fieldData.setConstValue(staticFields && i < constValues.size() ? constValues.get(i) : null); fieldConsumer.accept(fieldData); } } private void visitMethods(Consumer<IMethodData> mthConsumer, SectionReader data, int directMthCount, int virtualMthCount) { DexMethodData methodData = new DexMethodData(annotationsParser); methodData.setMethodRef(new DexMethodRef()); Map<Integer, Integer> annotationOffsetMap = annotationsParser.readMethodsAnnotationOffsetMap(); Map<Integer, Integer> paramsAnnOffsetMap = annotationsParser.readMethodParamsAnnRefOffsetMap(); readMethods(mthConsumer, data, methodData, directMthCount, annotationOffsetMap, paramsAnnOffsetMap); readMethods(mthConsumer, data, methodData, virtualMthCount, annotationOffsetMap, paramsAnnOffsetMap); } private void readMethods(Consumer<IMethodData> mthConsumer, SectionReader data, DexMethodData methodData, int count, Map<Integer, Integer> annotationOffsetMap, Map<Integer, Integer> paramsAnnOffsetMap) { DexCodeReader dexCodeReader = new DexCodeReader(in.copy()); int mthIdx = 0; for (int i = 0; i < count; i++) { mthIdx += data.readUleb128(); int accFlags = data.readUleb128(); int codeOff = data.readUleb128(); DexMethodRef methodRef = methodData.getMethodRef(); methodRef.reset(); in.initMethodRef(mthIdx, methodRef); methodData.setAccessFlags(accFlags); if (codeOff == 0) { methodData.setCodeReader(null); } else { dexCodeReader.setMthId(mthIdx); dexCodeReader.setOffset(codeOff); methodData.setCodeReader(dexCodeReader); } methodData.setAnnotationsOffset(getOffsetFromMap(mthIdx, annotationOffsetMap)); methodData.setParamAnnotationsOffset(getOffsetFromMap(mthIdx, paramsAnnOffsetMap)); mthConsumer.accept(methodData); } } private static int getOffsetFromMap(int idx, Map<Integer, Integer> annOffsetMap) { Integer offset = annOffsetMap.get(idx); return offset != null ? offset : 0; } private List<EncodedValue> getStaticFieldInitValues(SectionReader reader) { int staticValuesOff = getStaticValuesOff(); if (staticValuesOff == 0) { return Collections.emptyList(); } reader.absPos(staticValuesOff); return annotationsParser.parseEncodedArray(reader); } private List<IAnnotation> getAnnotations() { annotationsParser.setOffset(getAnnotationsOff()); return annotationsParser.readClassAnnotations(); } @Override public List<IJadxAttribute> getAttributes() { List<IJadxAttribute> list = new ArrayList<>(); String sourceFile = getSourceFile(); if (sourceFile != null && !sourceFile.isEmpty()) { list.add(new SourceFileAttr(sourceFile)); } DexAnnotationsConvert.forClass(getType(), list, getAnnotations()); return list; } public int getClassDefOffset() { return in.pos(0).getAbsPos(); } @Override public String getDisassembledCode() { byte[] dexBuf = in.getDexReader().getBuf().array(); return SmaliUtils.getSmaliCode(dexBuf, getClassDefOffset()); } @Override public String toString() { return getType(); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/DexMethodRef.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/DexMethodRef.java
package jadx.plugins.input.dex.sections; import java.util.List; import jadx.api.plugins.input.data.IMethodRef; import jadx.api.plugins.utils.Utils; import jadx.plugins.input.dex.DexReader; public class DexMethodRef implements IMethodRef { private int uniqId; private String name; private String parentClassType; private String returnType; private List<String> argTypes; // lazy loading info private int dexIdx; private SectionReader sectionReader; public void initUniqId(DexReader dexReader, int idx) { this.uniqId = (dexReader.getUniqId() & 0xFFFF) << 16 | (idx & 0xFFFF); } @Override public void load() { if (sectionReader != null) { sectionReader.loadMethodRef(this, dexIdx); sectionReader = null; } } public void setDexIdx(int dexIdx) { this.dexIdx = dexIdx; } public void setSectionReader(SectionReader sectionReader) { this.sectionReader = sectionReader; } @Override public int getUniqId() { return uniqId; } public void reset() { name = null; parentClassType = null; returnType = null; argTypes = null; } @Override public String getParentClassType() { return parentClassType; } public void setParentClassType(String parentClassType) { this.parentClassType = parentClassType; } @Override public String getName() { return name; } public void setName(String name) { this.name = name; } @Override public String getReturnType() { return returnType; } public void setReturnType(String returnType) { this.returnType = returnType; } @Override public List<String> getArgTypes() { return argTypes; } public void setArgTypes(List<String> argTypes) { this.argTypes = argTypes; } @Override public String toString() { if (name == null) { // not loaded return Integer.toHexString(uniqId); } return getParentClassType() + "->" + getName() + '(' + Utils.listToStr(getArgTypes()) + ")" + getReturnType(); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/DexCodeReader.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/DexCodeReader.java
package jadx.plugins.input.dex.sections; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Consumer; import org.jetbrains.annotations.Nullable; import jadx.api.plugins.input.data.ICatch; import jadx.api.plugins.input.data.ICodeReader; import jadx.api.plugins.input.data.IDebugInfo; import jadx.api.plugins.input.data.ITry; import jadx.api.plugins.input.data.impl.CatchData; import jadx.api.plugins.input.data.impl.TryData; import jadx.api.plugins.input.insns.InsnData; import jadx.core.utils.exceptions.InvalidDataException; import jadx.plugins.input.dex.DexException; import jadx.plugins.input.dex.insns.DexInsnData; import jadx.plugins.input.dex.insns.DexInsnFormat; import jadx.plugins.input.dex.insns.DexInsnInfo; import jadx.plugins.input.dex.sections.debuginfo.DebugInfoParser; public class DexCodeReader implements ICodeReader { private final SectionReader in; private int mthId; public DexCodeReader(SectionReader in) { this.in = in; } @Override public DexCodeReader copy() { DexCodeReader copy = new DexCodeReader(in.copy()); copy.setMthId(this.getMthId()); return copy; } public void setOffset(int offset) { this.in.setOffset(offset); } @Override public int getRegistersCount() { return in.pos(0).readUShort(); } @Override public int getArgsStartReg() { return -1; } @Override public int getUnitsCount() { return in.pos(12).readInt(); } @Override public void visitInstructions(Consumer<InsnData> insnConsumer) { DexInsnData insnData = new DexInsnData(this, in.copy()); in.pos(12); int size = in.readInt(); int offset = 0; // in code units (2 byte) while (offset < size) { int insnStart = in.getAbsPos(); int opcodeUnit = in.readUShort(); DexInsnInfo insnInfo = DexInsnInfo.get(opcodeUnit); insnData.setInsnStart(insnStart); insnData.setOffset(offset); insnData.setInsnInfo(insnInfo); insnData.setOpcodeUnit(opcodeUnit); insnData.setPayload(null); insnData.setDecoded(false); if (insnInfo != null) { DexInsnFormat format = insnInfo.getFormat(); insnData.setRegsCount(format.getRegsCount()); insnData.setLength(format.getLength()); } else { insnData.setRegsCount(0); insnData.setLength(1); } insnConsumer.accept(insnData); if (!insnData.isDecoded()) { skip(insnData); } offset += insnData.getLength(); } } public void decode(DexInsnData insn) { DexInsnFormat format = insn.getInsnInfo().getFormat(); format.decode(insn, insn.getOpcodeUnit(), insn.getCodeData().in); insn.setDecoded(true); } public void skip(DexInsnData insn) { DexInsnInfo insnInfo = insn.getInsnInfo(); if (insnInfo != null) { DexCodeReader codeReader = insn.getCodeData(); insnInfo.getFormat().skip(insn, codeReader.in); } } @Nullable @Override public IDebugInfo getDebugInfo() { int debugOff = in.pos(8).readInt(); if (debugOff == 0) { return null; } if (debugOff < 0 || debugOff > in.size()) { throw new InvalidDataException("Invalid debug info offset"); } int regsCount = getRegistersCount(); DebugInfoParser debugInfoParser = new DebugInfoParser(in, regsCount, getUnitsCount()); debugInfoParser.initMthArgs(regsCount, in.getMethodParamTypes(mthId)); return debugInfoParser.process(debugOff); } private int getTriesCount() { return in.pos(6).readUShort(); } private int getTriesOffset() { int triesCount = getTriesCount(); if (triesCount == 0) { return -1; } int insnsCount = getUnitsCount(); int padding = insnsCount % 2 == 1 ? 2 : 0; return 4 * 4 + insnsCount * 2 + padding; } @Override public List<ITry> getTries() { int triesOffset = getTriesOffset(); if (triesOffset == -1) { return Collections.emptyList(); } int triesCount = getTriesCount(); Map<Integer, ICatch> catchHandlers = getCatchHandlers(triesOffset + 8 * triesCount, in.copy()); in.pos(triesOffset); List<ITry> triesList = new ArrayList<>(triesCount); for (int i = 0; i < triesCount; i++) { int startAddr = in.readInt(); int insnsCount = in.readUShort(); int handlerOff = in.readUShort(); ICatch catchHandler = catchHandlers.get(handlerOff); if (catchHandler == null) { throw new DexException("Catch handler not found by byte offset: " + handlerOff); } triesList.add(new TryData(startAddr, startAddr + insnsCount - 1, catchHandler)); } return triesList; } private Map<Integer, ICatch> getCatchHandlers(int offset, SectionReader ext) { in.pos(offset); int byteOffsetStart = in.getAbsPos(); int size = in.readUleb128(); Map<Integer, ICatch> map = new HashMap<>(size); for (int i = 0; i < size; i++) { int byteIndex = in.getAbsPos() - byteOffsetStart; int sizeAndType = in.readSleb128(); int handlersLen = Math.abs(sizeAndType); int[] addr = new int[handlersLen]; String[] types = new String[handlersLen]; for (int h = 0; h < handlersLen; h++) { types[h] = ext.getType(in.readUleb128()); addr[h] = in.readUleb128(); } int catchAllAddr; if (sizeAndType <= 0) { catchAllAddr = in.readUleb128(); } else { catchAllAddr = -1; } map.put(byteIndex, new CatchData(addr, types, catchAllAddr)); } return map; } @Override public int getCodeOffset() { return in.getOffset(); } public void setMthId(int mthId) { this.mthId = mthId; } public int getMthId() { return mthId; } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/DexMethodData.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/DexMethodData.java
package jadx.plugins.input.dex.sections; import java.util.ArrayList; import java.util.List; import org.jetbrains.annotations.Nullable; import jadx.api.plugins.input.data.ICodeReader; import jadx.api.plugins.input.data.IMethodData; import jadx.api.plugins.input.data.annotations.IAnnotation; import jadx.api.plugins.input.data.attributes.IJadxAttribute; import jadx.api.plugins.input.data.attributes.types.AnnotationMethodParamsAttr; import jadx.api.plugins.utils.Utils; import jadx.plugins.input.dex.sections.annotations.AnnotationsParser; import jadx.plugins.input.dex.smali.SmaliPrinter; public class DexMethodData implements IMethodData { @Nullable private final AnnotationsParser annotationsParser; private DexMethodRef methodRef; private int accessFlags; private int annotationsOffset; private int paramAnnotationsOffset; @Nullable private DexCodeReader codeReader; public DexMethodData(@Nullable AnnotationsParser annotationsParser) { this.annotationsParser = annotationsParser; } @Override public DexMethodRef getMethodRef() { return methodRef; } public void setMethodRef(DexMethodRef methodRef) { this.methodRef = methodRef; } @Override public int getAccessFlags() { return accessFlags; } public void setAccessFlags(int accessFlags) { this.accessFlags = accessFlags; } @Nullable @Override public ICodeReader getCodeReader() { return codeReader; } public void setCodeReader(@Nullable DexCodeReader codeReader) { this.codeReader = codeReader; } @Override public String disassembleMethod() { return SmaliPrinter.printMethod(this); } public void setAnnotationsOffset(int annotationsOffset) { this.annotationsOffset = annotationsOffset; } public void setParamAnnotationsOffset(int paramAnnotationsOffset) { this.paramAnnotationsOffset = paramAnnotationsOffset; } private List<IAnnotation> getAnnotations() { return getAnnotationsParser().readAnnotationList(annotationsOffset); } private List<List<IAnnotation>> getParamsAnnotations() { return getAnnotationsParser().readAnnotationRefList(paramAnnotationsOffset); } @Override public List<IJadxAttribute> getAttributes() { List<IJadxAttribute> list = new ArrayList<>(); DexAnnotationsConvert.forMethod(list, getAnnotations()); Utils.addToList(list, AnnotationMethodParamsAttr.pack(getParamsAnnotations())); return list; } private AnnotationsParser getAnnotationsParser() { if (annotationsParser == null) { throw new NullPointerException("Annotation parser not initialized"); } return annotationsParser; } @Override public String toString() { return getMethodRef().toString(); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/DexFieldData.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/DexFieldData.java
package jadx.plugins.input.dex.sections; import java.util.ArrayList; import java.util.List; import org.jetbrains.annotations.Nullable; import jadx.api.plugins.input.data.IFieldData; import jadx.api.plugins.input.data.annotations.EncodedValue; import jadx.api.plugins.input.data.annotations.IAnnotation; import jadx.api.plugins.input.data.attributes.IJadxAttribute; import jadx.api.plugins.utils.Utils; import jadx.plugins.input.dex.sections.annotations.AnnotationsParser; public class DexFieldData implements IFieldData { @Nullable private final AnnotationsParser annotationsParser; private String parentClassType; private String type; private String name; private int accessFlags; private int annotationsOffset; private EncodedValue constValue; public DexFieldData(@Nullable AnnotationsParser parser) { this.annotationsParser = parser; } @Override public String getParentClassType() { return parentClassType; } public void setParentClassType(String parentClassType) { this.parentClassType = parentClassType; } @Override public String getType() { return type; } public void setType(String type) { this.type = type; } @Override public String getName() { return name; } public void setName(String name) { this.name = name; } @Override public int getAccessFlags() { return accessFlags; } public void setAccessFlags(int accessFlags) { this.accessFlags = accessFlags; } public void setAnnotationsOffset(int annotationsOffset) { this.annotationsOffset = annotationsOffset; } public void setConstValue(EncodedValue constValue) { this.constValue = constValue; } private List<IAnnotation> getAnnotations() { if (annotationsParser == null) { throw new NullPointerException("Annotation parser not initialized"); } return annotationsParser.readAnnotationList(annotationsOffset); } @Override public List<IJadxAttribute> getAttributes() { List<IJadxAttribute> list = new ArrayList<>(2); Utils.addToList(list, constValue); DexAnnotationsConvert.forField(list, getAnnotations()); return list; } @Override public String toString() { return getParentClassType() + "->" + getName() + ":" + getType(); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/SectionReader.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/SectionReader.java
package jadx.plugins.input.dex.sections; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.jetbrains.annotations.Nullable; import jadx.api.plugins.input.data.ICallSite; import jadx.api.plugins.input.data.IFieldRef; import jadx.api.plugins.input.data.IMethodHandle; import jadx.api.plugins.input.data.MethodHandleType; import jadx.api.plugins.input.data.impl.CallSite; import jadx.api.plugins.input.data.impl.FieldRefHandle; import jadx.api.plugins.input.data.impl.MethodRefHandle; import jadx.plugins.input.dex.DexReader; import jadx.plugins.input.dex.sections.annotations.EncodedValueParser; import jadx.plugins.input.dex.utils.Leb128; import jadx.plugins.input.dex.utils.MUtf8; import static jadx.plugins.input.dex.sections.DexConsts.NO_INDEX; public class SectionReader { private final ByteBuffer buf; private final DexReader dexReader; private int offset; public SectionReader(DexReader dexReader, int off) { this.dexReader = dexReader; this.offset = off; this.buf = duplicate(dexReader.getBuf(), off); } private SectionReader(SectionReader sectionReader, int off) { this(sectionReader.dexReader, off); } public SectionReader copy() { return new SectionReader(this, offset); } public SectionReader copy(int off) { return new SectionReader(this, off); } public byte[] getByteCode(int start, int len) { int pos = buf.position(); buf.position(start); byte[] bytes = readByteArray(len); buf.position(pos); return bytes; } private static ByteBuffer duplicate(ByteBuffer baseBuffer, int off) { ByteBuffer dupBuf = baseBuffer.duplicate(); dupBuf.order(ByteOrder.LITTLE_ENDIAN); dupBuf.position(off); return dupBuf; } public void setOffset(int offset) { this.offset = offset; } public int getOffset() { return offset; } public void shiftOffset(int shift) { this.offset += shift; } public SectionReader pos(int pos) { buf.position(offset + pos); return this; } public SectionReader absPos(int pos) { buf.position(pos); return this; } public int getAbsPos() { return buf.position(); } public void skip(int skip) { int pos = buf.position(); buf.position(pos + skip); } public int readInt() { return buf.getInt(); } public long readLong() { return buf.getLong(); } public byte readByte() { return buf.get(); } public int readUByte() { return buf.get() & 0xFF; } public int readUShort() { return buf.getShort() & 0xFFFF; } public int readShort() { return buf.getShort(); } public byte[] readByteArray(int len) { byte[] arr = new byte[len]; buf.get(arr); return arr; } public int[] readUShortArray(int size) { int[] arr = new int[size]; for (int i = 0; i < size; i++) { arr[i] = readUShort(); } return arr; } public String readString(int len) { return new String(readByteArray(len), StandardCharsets.US_ASCII); } private List<String> readTypeListAt(int paramsOff) { if (paramsOff == 0) { return Collections.emptyList(); } return absPos(paramsOff).readTypeList(); } public List<String> readTypeList() { int size = readInt(); if (size == 0) { return Collections.emptyList(); } int[] typeIds = readUShortArray(size); List<String> types = new ArrayList<>(size); for (int typeId : typeIds) { types.add(getType(typeId)); } return types; } @Nullable public String getType(int idx) { if (idx == NO_INDEX) { return null; } int typeIdsOff = dexReader.getHeader().getTypeIdsOff(); absPos(typeIdsOff + idx * 4); int strIdx = readInt(); return getString(strIdx); } @Nullable public String getString(int idx) { if (idx == NO_INDEX) { return null; } // TODO: make string pool cache? int stringIdsOff = dexReader.getHeader().getStringIdsOff(); absPos(stringIdsOff + idx * 4); int strOff = readInt(); absPos(strOff); return MUtf8.decode(this); } public IFieldRef getFieldRef(int idx) { DexFieldData fieldData = new DexFieldData(null); int clsTypeIdx = fillFieldData(fieldData, idx); fieldData.setParentClassType(getType(clsTypeIdx)); return fieldData; } public int fillFieldData(DexFieldData fieldData, int idx) { int fieldIdsOff = dexReader.getHeader().getFieldIdsOff(); absPos(fieldIdsOff + idx * 8); int classTypeIdx = readUShort(); int typeIdx = readUShort(); int nameIdx = readInt(); fieldData.setType(getType(typeIdx)); fieldData.setName(getString(nameIdx)); return classTypeIdx; } public DexMethodRef getMethodRef(int idx) { DexMethodRef methodRef = new DexMethodRef(); initMethodRef(idx, methodRef); return methodRef; } public ICallSite getCallSite(int idx, SectionReader ext) { int callSiteOff = dexReader.getHeader().getCallSiteOff(); absPos(callSiteOff + idx * 4); absPos(readInt()); return new CallSite(EncodedValueParser.parseEncodedArray(this, ext)); } public IMethodHandle getMethodHandle(int idx) { int methodHandleOff = dexReader.getHeader().getMethodHandleOff(); absPos(methodHandleOff + idx * 8); MethodHandleType handleType = getMethodHandleType(readUShort()); skip(2); int refId = readUShort(); if (handleType.isField()) { return new FieldRefHandle(handleType, getFieldRef(refId)); } return new MethodRefHandle(handleType, getMethodRef(refId)); } private MethodHandleType getMethodHandleType(int type) { switch (type) { case 0x00: return MethodHandleType.STATIC_PUT; case 0x01: return MethodHandleType.STATIC_GET; case 0x02: return MethodHandleType.INSTANCE_PUT; case 0x03: return MethodHandleType.INSTANCE_GET; case 0x04: return MethodHandleType.INVOKE_STATIC; case 0x05: return MethodHandleType.INVOKE_INSTANCE; case 0x06: return MethodHandleType.INVOKE_CONSTRUCTOR; case 0x07: return MethodHandleType.INVOKE_DIRECT; case 0x08: return MethodHandleType.INVOKE_INTERFACE; default: throw new IllegalArgumentException("Unknown method handle type: 0x" + Integer.toHexString(type)); } } public void initMethodRef(int idx, DexMethodRef methodRef) { methodRef.initUniqId(dexReader, idx); methodRef.setDexIdx(idx); methodRef.setSectionReader(this); } public void loadMethodRef(DexMethodRef methodRef, int idx) { DexHeader header = dexReader.getHeader(); int methodIdsOff = header.getMethodIdsOff(); absPos(methodIdsOff + idx * 8); int classTypeIdx = readUShort(); int protoIdx = readUShort(); int nameIdx = readInt(); int protoIdsOff = header.getProtoIdsOff(); absPos(protoIdsOff + protoIdx * 12); skip(4); // shortyIdx int returnTypeIdx = readInt(); int paramsOff = readInt(); List<String> argTypes = readTypeListAt(paramsOff); methodRef.setParentClassType(getType(classTypeIdx)); methodRef.setName(getString(nameIdx)); methodRef.setReturnType(getType(returnTypeIdx)); methodRef.setArgTypes(argTypes); } public DexMethodProto getMethodProto(int idx) { int protoIdsOff = dexReader.getHeader().getProtoIdsOff(); absPos(protoIdsOff + idx * 12); skip(4); // shortyIdx int returnTypeIdx = readInt(); int paramsOff = readInt(); return new DexMethodProto(readTypeListAt(paramsOff), getType(returnTypeIdx)); } public List<String> getMethodParamTypes(int idx) { DexHeader header = dexReader.getHeader(); int methodIdsOff = header.getMethodIdsOff(); absPos(methodIdsOff + idx * 8 + 2); int protoIdx = readUShort(); int protoIdsOff = header.getProtoIdsOff(); absPos(protoIdsOff + protoIdx * 12 + 8); int paramsOff = readInt(); if (paramsOff == 0) { return Collections.emptyList(); } return absPos(paramsOff).readTypeList(); } public DexReader getDexReader() { return dexReader; } public int readUleb128() { return Leb128.readUnsignedLeb128(this); } public int readUleb128p1() { return Leb128.readUnsignedLeb128(this) - 1; } public int readSleb128() { return Leb128.readSignedLeb128(this); } public int size() { return buf.capacity(); } @Override public String toString() { return "SectionReader{buf=" + buf + ", offset=" + offset + '}'; } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/annotations/AnnotationsParser.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/annotations/AnnotationsParser.java
package jadx.plugins.input.dex.sections.annotations; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import jadx.api.plugins.input.data.annotations.AnnotationVisibility; import jadx.api.plugins.input.data.annotations.EncodedValue; import jadx.api.plugins.input.data.annotations.IAnnotation; import jadx.api.plugins.input.data.annotations.JadxAnnotation; import jadx.plugins.input.dex.DexException; import jadx.plugins.input.dex.sections.SectionReader; public class AnnotationsParser { private final SectionReader in; private final SectionReader ext; private int offset; private int fieldsCount; private int methodsCount; private int paramsRefCount; public AnnotationsParser(SectionReader in, SectionReader ext) { this.in = in; this.ext = ext; } public AnnotationsParser copy() { return new AnnotationsParser(in.copy(), ext.copy()); } public void setOffset(int offset) { this.offset = offset; if (offset == 0) { this.fieldsCount = 0; this.methodsCount = 0; this.paramsRefCount = 0; } else { in.setOffset(offset); in.pos(4); this.fieldsCount = in.readInt(); this.methodsCount = in.readInt(); this.paramsRefCount = in.readInt(); } } public List<IAnnotation> readClassAnnotations() { if (offset == 0) { return Collections.emptyList(); } int classAnnotationsOffset = in.absPos(offset).readInt(); return readAnnotationList(classAnnotationsOffset); } public Map<Integer, Integer> readFieldsAnnotationOffsetMap() { if (fieldsCount == 0) { return Collections.emptyMap(); } in.pos(4 * 4); Map<Integer, Integer> map = new HashMap<>(fieldsCount); for (int i = 0; i < fieldsCount; i++) { int fieldIdx = in.readInt(); int fieldAnnOffset = in.readInt(); map.put(fieldIdx, fieldAnnOffset); } return map; } public Map<Integer, Integer> readMethodsAnnotationOffsetMap() { if (methodsCount == 0) { return Collections.emptyMap(); } in.pos(4 * 4 + fieldsCount * 2 * 4); Map<Integer, Integer> map = new HashMap<>(methodsCount); for (int i = 0; i < methodsCount; i++) { int methodIdx = in.readInt(); int methodAnnOffset = in.readInt(); map.put(methodIdx, methodAnnOffset); } return map; } public Map<Integer, Integer> readMethodParamsAnnRefOffsetMap() { if (paramsRefCount == 0) { return Collections.emptyMap(); } in.pos(4 * 4 + fieldsCount * 2 * 4 + methodsCount * 2 * 4); Map<Integer, Integer> map = new HashMap<>(paramsRefCount); for (int i = 0; i < paramsRefCount; i++) { int methodIdx = in.readInt(); int methodAnnRefOffset = in.readInt(); map.put(methodIdx, methodAnnRefOffset); } return map; } public List<IAnnotation> readAnnotationList(int offset) { if (offset == 0) { return Collections.emptyList(); } in.absPos(offset); int size = in.readInt(); if (size == 0) { return Collections.emptyList(); } List<IAnnotation> list = new ArrayList<>(size); int pos = in.getAbsPos(); for (int i = 0; i < size; i++) { in.absPos(pos + i * 4); int annOffset = in.readInt(); in.absPos(annOffset); list.add(readAnnotation(in, ext, true)); } return list; } public List<List<IAnnotation>> readAnnotationRefList(int offset) { if (offset == 0) { return Collections.emptyList(); } in.absPos(offset); int size = in.readInt(); if (size == 0) { return Collections.emptyList(); } List<List<IAnnotation>> list = new ArrayList<>(size); for (int i = 0; i < size; i++) { int refOff = in.readInt(); int pos = in.getAbsPos(); list.add(readAnnotationList(refOff)); in.absPos(pos); } return list; } public static IAnnotation readAnnotation(SectionReader in, SectionReader ext, boolean readVisibility) { AnnotationVisibility visibility = null; if (readVisibility) { int v = in.readUByte(); visibility = getVisibilityValue(v); } int typeIndex = in.readUleb128(); int size = in.readUleb128(); Map<String, EncodedValue> values = new LinkedHashMap<>(size); for (int i = 0; i < size; i++) { String name = ext.getString(in.readUleb128()); values.put(name, EncodedValueParser.parseValue(in, ext)); } String type = ext.getType(typeIndex); return new JadxAnnotation(visibility, type, values); } private static AnnotationVisibility getVisibilityValue(int value) { switch (value) { case 0: return AnnotationVisibility.BUILD; case 1: return AnnotationVisibility.RUNTIME; case 2: return AnnotationVisibility.SYSTEM; default: throw new DexException("Unknown annotation visibility value: " + value); } } public EncodedValue parseEncodedValue(SectionReader in) { return EncodedValueParser.parseValue(in, ext); } public List<EncodedValue> parseEncodedArray(SectionReader in) { return EncodedValueParser.parseEncodedArray(in, ext); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/annotations/AnnotationsUtils.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/annotations/AnnotationsUtils.java
package jadx.plugins.input.dex.sections.annotations; import java.util.Collections; import java.util.List; import org.jetbrains.annotations.Nullable; import jadx.api.plugins.input.data.annotations.EncodedType; import jadx.api.plugins.input.data.annotations.EncodedValue; import jadx.api.plugins.input.data.annotations.IAnnotation; public class AnnotationsUtils { @SuppressWarnings("unchecked") public static <T> T getValue(IAnnotation ann, String name, EncodedType type, T defValue) { if (ann == null || ann.getValues() == null || ann.getValues().isEmpty()) { return defValue; } EncodedValue encodedValue = ann.getValues().get(name); if (encodedValue == null || encodedValue.getType() != type) { return defValue; } return (T) encodedValue.getValue(); } @Nullable public static Object getValue(IAnnotation ann, String name, EncodedType type) { if (ann == null || ann.getValues() == null || ann.getValues().isEmpty()) { return null; } EncodedValue encodedValue = ann.getValues().get(name); if (encodedValue == null || encodedValue.getType() != type) { return null; } return encodedValue.getValue(); } @SuppressWarnings("unchecked") public static List<EncodedValue> getArray(IAnnotation ann, String name) { if (ann == null || ann.getValues() == null || ann.getValues().isEmpty()) { return Collections.emptyList(); } EncodedValue encodedValue = ann.getValues().get(name); if (encodedValue == null || encodedValue.getType() != EncodedType.ENCODED_ARRAY) { return Collections.emptyList(); } return (List<EncodedValue>) encodedValue.getValue(); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/annotations/EncodedValueParser.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/annotations/EncodedValueParser.java
package jadx.plugins.input.dex.sections.annotations; import java.util.ArrayList; import java.util.List; import jadx.api.plugins.input.data.annotations.EncodedType; import jadx.api.plugins.input.data.annotations.EncodedValue; import jadx.plugins.input.dex.DexException; import jadx.plugins.input.dex.sections.SectionReader; public class EncodedValueParser { private static final int ENCODED_BYTE = 0x00; private static final int ENCODED_SHORT = 0x02; private static final int ENCODED_CHAR = 0x03; private static final int ENCODED_INT = 0x04; private static final int ENCODED_LONG = 0x06; private static final int ENCODED_FLOAT = 0x10; private static final int ENCODED_DOUBLE = 0x11; private static final int ENCODED_METHOD_TYPE = 0x15; private static final int ENCODED_METHOD_HANDLE = 0x16; private static final int ENCODED_STRING = 0x17; private static final int ENCODED_TYPE = 0x18; private static final int ENCODED_FIELD = 0x19; private static final int ENCODED_ENUM = 0x1b; private static final int ENCODED_METHOD = 0x1a; private static final int ENCODED_ARRAY = 0x1c; private static final int ENCODED_ANNOTATION = 0x1d; private static final int ENCODED_NULL = 0x1e; private static final int ENCODED_BOOLEAN = 0x1f; static EncodedValue parseValue(SectionReader in, SectionReader ext) { int argAndType = in.readUByte(); int type = argAndType & 0x1F; int arg = (argAndType & 0xE0) >> 5; int size = arg + 1; switch (type) { case ENCODED_NULL: return EncodedValue.NULL; case ENCODED_BOOLEAN: return new EncodedValue(EncodedType.ENCODED_BOOLEAN, arg == 1); case ENCODED_BYTE: return new EncodedValue(EncodedType.ENCODED_BYTE, in.readByte()); case ENCODED_SHORT: return new EncodedValue(EncodedType.ENCODED_SHORT, (short) parseNumber(in, size, true)); case ENCODED_CHAR: return new EncodedValue(EncodedType.ENCODED_CHAR, (char) parseUnsignedInt(in, size)); case ENCODED_INT: return new EncodedValue(EncodedType.ENCODED_INT, (int) parseNumber(in, size, true)); case ENCODED_LONG: return new EncodedValue(EncodedType.ENCODED_LONG, parseNumber(in, size, true)); case ENCODED_FLOAT: return new EncodedValue(EncodedType.ENCODED_FLOAT, Float.intBitsToFloat((int) parseNumber(in, size, false, 4))); case ENCODED_DOUBLE: return new EncodedValue(EncodedType.ENCODED_DOUBLE, Double.longBitsToDouble(parseNumber(in, size, false, 8))); case ENCODED_STRING: return new EncodedValue(EncodedType.ENCODED_STRING, ext.getString(parseUnsignedInt(in, size))); case ENCODED_TYPE: return new EncodedValue(EncodedType.ENCODED_TYPE, ext.getType(parseUnsignedInt(in, size))); case ENCODED_FIELD: case ENCODED_ENUM: return new EncodedValue(EncodedType.ENCODED_FIELD, ext.getFieldRef(parseUnsignedInt(in, size))); case ENCODED_ARRAY: return new EncodedValue(EncodedType.ENCODED_ARRAY, parseEncodedArray(in, ext)); case ENCODED_ANNOTATION: return new EncodedValue(EncodedType.ENCODED_ANNOTATION, AnnotationsParser.readAnnotation(in, ext, false)); case ENCODED_METHOD: return new EncodedValue(EncodedType.ENCODED_METHOD, ext.getMethodRef(parseUnsignedInt(in, size))); case ENCODED_METHOD_TYPE: return new EncodedValue(EncodedType.ENCODED_METHOD_TYPE, ext.getMethodProto(parseUnsignedInt(in, size))); case ENCODED_METHOD_HANDLE: return new EncodedValue(EncodedType.ENCODED_METHOD_HANDLE, ext.getMethodHandle(parseUnsignedInt(in, size))); default: throw new DexException("Unknown encoded value type: 0x" + Integer.toHexString(type)); } } public static List<EncodedValue> parseEncodedArray(SectionReader in, SectionReader ext) { int count = in.readUleb128(); List<EncodedValue> values = new ArrayList<>(count); for (int i = 0; i < count; i++) { values.add(parseValue(in, ext)); } return values; } private static int parseUnsignedInt(SectionReader in, int byteCount) { return (int) parseNumber(in, byteCount, false, 0); } private static long parseNumber(SectionReader in, int byteCount, boolean isSignExtended) { return parseNumber(in, byteCount, isSignExtended, 0); } private static long parseNumber(SectionReader in, int byteCount, boolean isSignExtended, int fillOnRight) { long result = 0; long last = 0; for (int i = 0; i < byteCount; i++) { last = in.readUByte(); result |= last << (i * 8); } if (fillOnRight != 0) { for (int i = byteCount; i < fillOnRight; i++) { result <<= 8; } } else { if (isSignExtended && (last & 0x80) != 0) { for (int i = byteCount; i < 8; i++) { result |= (long) 0xFF << (i * 8); } } } return result; } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/debuginfo/DexLocalVar.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/debuginfo/DexLocalVar.java
package jadx.plugins.input.dex.sections.debuginfo; import org.jetbrains.annotations.Nullable; import jadx.api.plugins.input.data.ILocalVar; import jadx.api.plugins.utils.Utils; import jadx.plugins.input.dex.sections.SectionReader; public class DexLocalVar implements ILocalVar { private static final int PARAM_START_OFFSET = -1; private final int regNum; private final String name; private final String type; @Nullable private final String sign; private boolean isEnd; private int startOffset; private int endOffset; public DexLocalVar(SectionReader dex, int regNum, int nameId, int typeId, int signId) { this(regNum, dex.getString(nameId), dex.getType(typeId), dex.getString(signId)); } public DexLocalVar(int regNum, String name, String type) { this(regNum, name, type, null); } public DexLocalVar(int regNum, String name, String type, @Nullable String sign) { this.regNum = regNum; this.name = name; this.type = type; this.sign = sign; } public void start(int addr) { this.isEnd = false; this.startOffset = addr; } /** * Sets end address of local variable * * @param addr address * @return <b>true</b> if local variable was active, else <b>false</b> */ public boolean end(int addr) { if (isEnd) { return false; } this.isEnd = true; this.endOffset = addr; return true; } @Override public int getRegNum() { return regNum; } @Override public String getName() { return name; } @Override public String getType() { return type; } @Nullable @Override public String getSignature() { return sign; } @Override public int getStartOffset() { return startOffset; } public void markAsParameter() { startOffset = PARAM_START_OFFSET; } @Override public boolean isMarkedAsParameter() { return startOffset == PARAM_START_OFFSET; } @Override public int getEndOffset() { return endOffset; } public boolean isEnd() { return isEnd; } @Override public boolean equals(Object obj) { return super.equals(obj); } @Override public int hashCode() { return super.hashCode(); } @Override public String toString() { return (startOffset == -1 ? "-1 " : Utils.formatOffset(startOffset)) + '-' + (isEnd ? Utils.formatOffset(endOffset) : " ") + ": r" + regNum + " '" + name + "' " + type + (sign != null ? ", signature: " + sign : ""); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/debuginfo/DebugInfoParser.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/sections/debuginfo/DebugInfoParser.java
package jadx.plugins.input.dex.sections.debuginfo; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import org.jetbrains.annotations.Nullable; import jadx.api.plugins.input.data.ILocalVar; import jadx.api.plugins.input.data.impl.DebugInfo; import jadx.plugins.input.dex.sections.DexConsts; import jadx.plugins.input.dex.sections.SectionReader; public class DebugInfoParser { private static final int DBG_END_SEQUENCE = 0x00; private static final int DBG_ADVANCE_PC = 0x01; private static final int DBG_ADVANCE_LINE = 0x02; private static final int DBG_START_LOCAL = 0x03; private static final int DBG_START_LOCAL_EXTENDED = 0x04; private static final int DBG_END_LOCAL = 0x05; private static final int DBG_RESTART_LOCAL = 0x06; private static final int DBG_SET_PROLOGUE_END = 0x07; private static final int DBG_SET_EPILOGUE_BEGIN = 0x08; private static final int DBG_SET_FILE = 0x09; // the smallest special opcode private static final int DBG_FIRST_SPECIAL = 0x0a; // the smallest line number increment private static final int DBG_LINE_BASE = -4; // the number of line increments represented private static final int DBG_LINE_RANGE = 15; private final SectionReader in; private final SectionReader ext; private final DexLocalVar[] locals; private final int codeSize; private List<ILocalVar> resultList; private Map<Integer, Integer> linesMap; @Nullable private String sourceFile; private List<String> argTypes; private int[] argRegs; public DebugInfoParser(SectionReader in, int regsCount, int codeSize) { this.in = in; this.ext = in.copy(); this.locals = new DexLocalVar[regsCount]; this.codeSize = codeSize; } public void initMthArgs(int regsCount, List<String> argTypes) { if (argTypes.isEmpty()) { this.argTypes = Collections.emptyList(); return; } int argsCount = argTypes.size(); int[] argRegsArr = new int[argsCount]; int regNum = regsCount; for (int i = argsCount - 1; i >= 0; i--) { regNum -= getTypeLen(argTypes.get(i)); argRegsArr[i] = regNum; } this.argRegs = argRegsArr; this.argTypes = argTypes; } public static int getTypeLen(String type) { switch (type.charAt(0)) { case 'J': case 'D': return 2; default: return 1; } } public DebugInfo process(int debugOff) { in.absPos(debugOff); boolean varsInfoFound = false; resultList = new ArrayList<>(); linesMap = new HashMap<>(); int addr = 0; int line = in.readUleb128(); int paramsCount = in.readUleb128(); int argsCount = argTypes.size(); for (int i = 0; i < paramsCount; i++) { int nameId = in.readUleb128p1(); String name = ext.getString(nameId); if (name != null && i < argsCount) { DexLocalVar paramVar = new DexLocalVar(argRegs[i], name, argTypes.get(i)); startVar(paramVar, addr); paramVar.markAsParameter(); varsInfoFound = true; } } while (true) { int c = in.readUByte(); if (c == DBG_END_SEQUENCE) { break; } switch (c) { case DBG_ADVANCE_PC: { int addrInc = in.readUleb128(); addr = addrChange(addr, addrInc); break; } case DBG_ADVANCE_LINE: { line += in.readSleb128(); break; } case DBG_START_LOCAL: { int regNum = in.readUleb128(); int nameId = in.readUleb128() - 1; int type = in.readUleb128() - 1; DexLocalVar var = new DexLocalVar(ext, regNum, nameId, type, DexConsts.NO_INDEX); startVar(var, addr); varsInfoFound = true; break; } case DBG_START_LOCAL_EXTENDED: { int regNum = in.readUleb128(); int nameId = in.readUleb128p1(); int type = in.readUleb128p1(); int sign = in.readUleb128p1(); DexLocalVar var = new DexLocalVar(ext, regNum, nameId, type, sign); startVar(var, addr); varsInfoFound = true; break; } case DBG_RESTART_LOCAL: { int regNum = in.readUleb128(); restartVar(regNum, addr); varsInfoFound = true; break; } case DBG_END_LOCAL: { int regNum = in.readUleb128(); DexLocalVar var = locals[regNum]; if (var != null) { endVar(var, addr); } varsInfoFound = true; break; } case DBG_SET_PROLOGUE_END: case DBG_SET_EPILOGUE_BEGIN: { // do nothing break; } case DBG_SET_FILE: { int idx = in.readUleb128() - 1; this.sourceFile = ext.getString(idx); break; } default: { int adjustedOpCode = c - DBG_FIRST_SPECIAL; int addrInc = adjustedOpCode / DBG_LINE_RANGE; addr = addrChange(addr, addrInc); line += DBG_LINE_BASE + adjustedOpCode % DBG_LINE_RANGE; setLine(addr, line); break; } } } if (varsInfoFound) { for (DexLocalVar var : locals) { if (var != null && !var.isEnd()) { endVar(var, codeSize - 1); } } } return new DebugInfo(linesMap, resultList); } private int addrChange(int addr, int addrInc) { return Math.min(addr + addrInc, codeSize - 1); } private void setLine(int offset, int line) { linesMap.put(offset, line); } private void restartVar(int regNum, int addr) { DexLocalVar prev = locals[regNum]; if (prev != null) { endVar(prev, addr); DexLocalVar newVar = new DexLocalVar(regNum, prev.getName(), prev.getType(), prev.getSignature()); startVar(newVar, addr); } } private void startVar(DexLocalVar newVar, int addr) { int regNum = newVar.getRegNum(); DexLocalVar prev = locals[regNum]; if (prev != null) { endVar(prev, addr); } newVar.start(addr); locals[regNum] = newVar; } private void endVar(DexLocalVar var, int addr) { if (var.end(addr)) { resultList.add(var); } } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/utils/DexCheckSum.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/utils/DexCheckSum.java
package jadx.plugins.input.dex.utils; import java.util.zip.Adler32; import jadx.plugins.input.dex.DexException; public class DexCheckSum { public static void verify(String fileName, byte[] content, int offset) { if (offset + 32 + 4 > content.length) { throw new DexException("Dex file truncated, can't read file length, file: " + fileName); } int len = DataReader.readU4(content, offset + 32); if (offset + len > content.length) { throw new DexException("Dex file truncated, length in header: " + len + ", file: " + fileName); } int checksum = DataReader.readU4(content, offset + 8); Adler32 adler32 = new Adler32(); adler32.update(content, offset + 12, len - 12); int fileChecksum = (int) adler32.getValue(); if (checksum != fileChecksum) { throw new DexException(String.format("Bad dex file checksum: 0x%08x, expected: 0x%08x, file: %s", fileChecksum, checksum, fileName)); } } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/utils/MUtf8.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/utils/MUtf8.java
package jadx.plugins.input.dex.utils; import jadx.plugins.input.dex.DexException; import jadx.plugins.input.dex.sections.SectionReader; public class MUtf8 { public static String decode(SectionReader in) { int len = in.readUleb128(); char[] out = new char[len]; int k = 0; while (true) { char a = (char) (in.readUByte() & 0xff); if (a == 0) { return new String(out, 0, k); } out[k] = a; if (a < '\u0080') { k++; } else if ((a & 0xE0) == 0xC0) { int b = in.readUByte(); if ((b & 0xC0) != 0x80) { throw new DexException("Bad second byte"); } out[k] = (char) (((a & 0x1F) << 6) | (b & 0x3F)); k++; } else if ((a & 0xF0) == 0xE0) { int b = in.readUByte(); int c = in.readUByte(); if (((b & 0xC0) != 0x80) || ((c & 0xC0) != 0x80)) { throw new DexException("Bad second or third byte"); } out[k] = (char) (((a & 0x0F) << 12) | ((b & 0x3F) << 6) | (c & 0x3F)); k++; } else { throw new DexException("Bad byte"); } } } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/utils/SimpleDexData.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/utils/SimpleDexData.java
package jadx.plugins.input.dex.utils; import java.util.Objects; public class SimpleDexData implements IDexData { private final String fileName; private final byte[] content; public SimpleDexData(String fileName, byte[] content) { this.fileName = Objects.requireNonNull(fileName); this.content = Objects.requireNonNull(content); } @Override public String getFileName() { return fileName; } @Override public byte[] getContent() { return content; } @Override public String toString() { return "DexData{" + fileName + ", size=" + content.length + '}'; } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/utils/SmaliUtils.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/utils/SmaliUtils.java
package jadx.plugins.input.dex.utils; import java.io.PrintWriter; import java.io.StringWriter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.android.tools.smali.baksmali.Adaptors.ClassDefinition; import com.android.tools.smali.baksmali.BaksmaliOptions; import com.android.tools.smali.baksmali.formatter.BaksmaliWriter; import com.android.tools.smali.dexlib2.dexbacked.DexBackedClassDef; import com.android.tools.smali.dexlib2.dexbacked.DexBackedDexFile; public class SmaliUtils { private static final Logger LOG = LoggerFactory.getLogger(SmaliUtils.class); public static String getSmaliCode(byte[] dexBuf, int clsDefOffset) { StringWriter stringWriter = new StringWriter(); try { DexBackedDexFile dexFile = new DexBackedDexFile(null, dexBuf); DexBackedClassDef dexBackedClassDef = new DexBackedClassDef(dexFile, clsDefOffset, 0); ClassDefinition classDefinition = new ClassDefinition(new BaksmaliOptions(), dexBackedClassDef); classDefinition.writeTo(new BaksmaliWriter(stringWriter)); } catch (Exception e) { LOG.error("Error generating smali", e); stringWriter.append("Error generating smali code: "); stringWriter.append(e.getMessage()); stringWriter.append(System.lineSeparator()); e.printStackTrace(new PrintWriter(stringWriter, true)); } return stringWriter.toString(); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/utils/IDexData.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/utils/IDexData.java
package jadx.plugins.input.dex.utils; public interface IDexData { String getFileName(); byte[] getContent(); }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/utils/Leb128.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/utils/Leb128.java
package jadx.plugins.input.dex.utils; import jadx.plugins.input.dex.DexException; import jadx.plugins.input.dex.sections.SectionReader; public final class Leb128 { public static int readSignedLeb128(SectionReader in) { int result = 0; int cur; int count = 0; int signBits = -1; do { cur = in.readUByte(); result |= (cur & 0x7f) << (count * 7); signBits <<= 7; count++; } while (((cur & 0x80) == 0x80) && count < 5); if ((cur & 0x80) == 0x80) { throw new DexException("Invalid LEB128 sequence"); } // Sign extend if appropriate if (((signBits >> 1) & result) != 0) { result |= signBits; } return result; } public static int readUnsignedLeb128(SectionReader in) { int result = 0; int cur; int count = 0; do { cur = in.readUByte(); result |= (cur & 0x7f) << (count * 7); count++; } while (((cur & 0x80) == 0x80) && count < 5); if ((cur & 0x80) == 0x80) { throw new DexException("Invalid LEB128 sequence"); } return result; } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/utils/DataReader.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/utils/DataReader.java
package jadx.plugins.input.dex.utils; public class DataReader { public static int readU4(byte[] data, int pos) { byte b1 = data[pos++]; byte b2 = data[pos++]; byte b3 = data[pos++]; byte b4 = data[pos]; return (b4 & 0xFF) << 24 | (b3 & 0xFF) << 16 | (b2 & 0xFF) << 8 | b1 & 0xFF; } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/insns/DexOpcodes.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/insns/DexOpcodes.java
package jadx.plugins.input.dex.insns; public class DexOpcodes { public static final int NOP = 0x00; public static final int MOVE = 0x01; public static final int MOVE_FROM16 = 0x02; public static final int MOVE_16 = 0x03; public static final int MOVE_WIDE = 0x04; public static final int MOVE_WIDE_FROM16 = 0x05; public static final int MOVE_WIDE_16 = 0x06; public static final int MOVE_OBJECT = 0x07; public static final int MOVE_OBJECT_FROM16 = 0x08; public static final int MOVE_OBJECT_16 = 0x09; public static final int MOVE_RESULT = 0x0a; public static final int MOVE_RESULT_WIDE = 0x0b; public static final int MOVE_RESULT_OBJECT = 0x0c; public static final int MOVE_EXCEPTION = 0x0d; public static final int RETURN_VOID = 0x0e; public static final int RETURN = 0x0f; public static final int RETURN_WIDE = 0x10; public static final int RETURN_OBJECT = 0x11; public static final int CONST_4 = 0x12; public static final int CONST_16 = 0x13; public static final int CONST = 0x14; public static final int CONST_HIGH16 = 0x15; public static final int CONST_WIDE_16 = 0x16; public static final int CONST_WIDE_32 = 0x17; public static final int CONST_WIDE = 0x18; public static final int CONST_WIDE_HIGH16 = 0x19; public static final int CONST_STRING = 0x1a; public static final int CONST_STRING_JUMBO = 0x1b; public static final int CONST_CLASS = 0x1c; public static final int MONITOR_ENTER = 0x1d; public static final int MONITOR_EXIT = 0x1e; public static final int CHECK_CAST = 0x1f; public static final int INSTANCE_OF = 0x20; public static final int ARRAY_LENGTH = 0x21; public static final int NEW_INSTANCE = 0x22; public static final int NEW_ARRAY = 0x23; public static final int FILLED_NEW_ARRAY = 0x24; public static final int FILLED_NEW_ARRAY_RANGE = 0x25; public static final int FILL_ARRAY_DATA = 0x26; public static final int THROW = 0x27; public static final int GOTO = 0x28; public static final int GOTO_16 = 0x29; public static final int GOTO_32 = 0x2a; public static final int PACKED_SWITCH = 0x2b; public static final int SPARSE_SWITCH = 0x2c; public static final int CMPL_FLOAT = 0x2d; public static final int CMPG_FLOAT = 0x2e; public static final int CMPL_DOUBLE = 0x2f; public static final int CMPG_DOUBLE = 0x30; public static final int CMP_LONG = 0x31; public static final int IF_EQ = 0x32; public static final int IF_NE = 0x33; public static final int IF_LT = 0x34; public static final int IF_GE = 0x35; public static final int IF_GT = 0x36; public static final int IF_LE = 0x37; public static final int IF_EQZ = 0x38; public static final int IF_NEZ = 0x39; public static final int IF_LTZ = 0x3a; public static final int IF_GEZ = 0x3b; public static final int IF_GTZ = 0x3c; public static final int IF_LEZ = 0x3d; public static final int AGET = 0x44; public static final int AGET_WIDE = 0x45; public static final int AGET_OBJECT = 0x46; public static final int AGET_BOOLEAN = 0x47; public static final int AGET_BYTE = 0x48; public static final int AGET_CHAR = 0x49; public static final int AGET_SHORT = 0x4a; public static final int APUT = 0x4b; public static final int APUT_WIDE = 0x4c; public static final int APUT_OBJECT = 0x4d; public static final int APUT_BOOLEAN = 0x4e; public static final int APUT_BYTE = 0x4f; public static final int APUT_CHAR = 0x50; public static final int APUT_SHORT = 0x51; public static final int IGET = 0x52; public static final int IGET_WIDE = 0x53; public static final int IGET_OBJECT = 0x54; public static final int IGET_BOOLEAN = 0x55; public static final int IGET_BYTE = 0x56; public static final int IGET_CHAR = 0x57; public static final int IGET_SHORT = 0x58; public static final int IPUT = 0x59; public static final int IPUT_WIDE = 0x5a; public static final int IPUT_OBJECT = 0x5b; public static final int IPUT_BOOLEAN = 0x5c; public static final int IPUT_BYTE = 0x5d; public static final int IPUT_CHAR = 0x5e; public static final int IPUT_SHORT = 0x5f; public static final int SGET = 0x60; public static final int SGET_WIDE = 0x61; public static final int SGET_OBJECT = 0x62; public static final int SGET_BOOLEAN = 0x63; public static final int SGET_BYTE = 0x64; public static final int SGET_CHAR = 0x65; public static final int SGET_SHORT = 0x66; public static final int SPUT = 0x67; public static final int SPUT_WIDE = 0x68; public static final int SPUT_OBJECT = 0x69; public static final int SPUT_BOOLEAN = 0x6a; public static final int SPUT_BYTE = 0x6b; public static final int SPUT_CHAR = 0x6c; public static final int SPUT_SHORT = 0x6d; public static final int INVOKE_VIRTUAL = 0x6e; public static final int INVOKE_SUPER = 0x6f; public static final int INVOKE_DIRECT = 0x70; public static final int INVOKE_STATIC = 0x71; public static final int INVOKE_INTERFACE = 0x72; public static final int INVOKE_VIRTUAL_RANGE = 0x74; public static final int INVOKE_SUPER_RANGE = 0x75; public static final int INVOKE_DIRECT_RANGE = 0x76; public static final int INVOKE_STATIC_RANGE = 0x77; public static final int INVOKE_INTERFACE_RANGE = 0x78; public static final int NEG_INT = 0x7b; public static final int NOT_INT = 0x7c; public static final int NEG_LONG = 0x7d; public static final int NOT_LONG = 0x7e; public static final int NEG_FLOAT = 0x7f; public static final int NEG_DOUBLE = 0x80; public static final int INT_TO_LONG = 0x81; public static final int INT_TO_FLOAT = 0x82; public static final int INT_TO_DOUBLE = 0x83; public static final int LONG_TO_INT = 0x84; public static final int LONG_TO_FLOAT = 0x85; public static final int LONG_TO_DOUBLE = 0x86; public static final int FLOAT_TO_INT = 0x87; public static final int FLOAT_TO_LONG = 0x88; public static final int FLOAT_TO_DOUBLE = 0x89; public static final int DOUBLE_TO_INT = 0x8a; public static final int DOUBLE_TO_LONG = 0x8b; public static final int DOUBLE_TO_FLOAT = 0x8c; public static final int INT_TO_BYTE = 0x8d; public static final int INT_TO_CHAR = 0x8e; public static final int INT_TO_SHORT = 0x8f; public static final int ADD_INT = 0x90; public static final int SUB_INT = 0x91; public static final int MUL_INT = 0x92; public static final int DIV_INT = 0x93; public static final int REM_INT = 0x94; public static final int AND_INT = 0x95; public static final int OR_INT = 0x96; public static final int XOR_INT = 0x97; public static final int SHL_INT = 0x98; public static final int SHR_INT = 0x99; public static final int USHR_INT = 0x9a; public static final int ADD_LONG = 0x9b; public static final int SUB_LONG = 0x9c; public static final int MUL_LONG = 0x9d; public static final int DIV_LONG = 0x9e; public static final int REM_LONG = 0x9f; public static final int AND_LONG = 0xa0; public static final int OR_LONG = 0xa1; public static final int XOR_LONG = 0xa2; public static final int SHL_LONG = 0xa3; public static final int SHR_LONG = 0xa4; public static final int USHR_LONG = 0xa5; public static final int ADD_FLOAT = 0xa6; public static final int SUB_FLOAT = 0xa7; public static final int MUL_FLOAT = 0xa8; public static final int DIV_FLOAT = 0xa9; public static final int REM_FLOAT = 0xaa; public static final int ADD_DOUBLE = 0xab; public static final int SUB_DOUBLE = 0xac; public static final int MUL_DOUBLE = 0xad; public static final int DIV_DOUBLE = 0xae; public static final int REM_DOUBLE = 0xaf; public static final int ADD_INT_2ADDR = 0xb0; public static final int SUB_INT_2ADDR = 0xb1; public static final int MUL_INT_2ADDR = 0xb2; public static final int DIV_INT_2ADDR = 0xb3; public static final int REM_INT_2ADDR = 0xb4; public static final int AND_INT_2ADDR = 0xb5; public static final int OR_INT_2ADDR = 0xb6; public static final int XOR_INT_2ADDR = 0xb7; public static final int SHL_INT_2ADDR = 0xb8; public static final int SHR_INT_2ADDR = 0xb9; public static final int USHR_INT_2ADDR = 0xba; public static final int ADD_LONG_2ADDR = 0xbb; public static final int SUB_LONG_2ADDR = 0xbc; public static final int MUL_LONG_2ADDR = 0xbd; public static final int DIV_LONG_2ADDR = 0xbe; public static final int REM_LONG_2ADDR = 0xbf; public static final int AND_LONG_2ADDR = 0xc0; public static final int OR_LONG_2ADDR = 0xc1; public static final int XOR_LONG_2ADDR = 0xc2; public static final int SHL_LONG_2ADDR = 0xc3; public static final int SHR_LONG_2ADDR = 0xc4; public static final int USHR_LONG_2ADDR = 0xc5; public static final int ADD_FLOAT_2ADDR = 0xc6; public static final int SUB_FLOAT_2ADDR = 0xc7; public static final int MUL_FLOAT_2ADDR = 0xc8; public static final int DIV_FLOAT_2ADDR = 0xc9; public static final int REM_FLOAT_2ADDR = 0xca; public static final int ADD_DOUBLE_2ADDR = 0xcb; public static final int SUB_DOUBLE_2ADDR = 0xcc; public static final int MUL_DOUBLE_2ADDR = 0xcd; public static final int DIV_DOUBLE_2ADDR = 0xce; public static final int REM_DOUBLE_2ADDR = 0xcf; public static final int ADD_INT_LIT16 = 0xd0; public static final int RSUB_INT = 0xd1; public static final int MUL_INT_LIT16 = 0xd2; public static final int DIV_INT_LIT16 = 0xd3; public static final int REM_INT_LIT16 = 0xd4; public static final int AND_INT_LIT16 = 0xd5; public static final int OR_INT_LIT16 = 0xd6; public static final int XOR_INT_LIT16 = 0xd7; public static final int ADD_INT_LIT8 = 0xd8; public static final int RSUB_INT_LIT8 = 0xd9; public static final int MUL_INT_LIT8 = 0xda; public static final int DIV_INT_LIT8 = 0xdb; public static final int REM_INT_LIT8 = 0xdc; public static final int AND_INT_LIT8 = 0xdd; public static final int OR_INT_LIT8 = 0xde; public static final int XOR_INT_LIT8 = 0xdf; public static final int SHL_INT_LIT8 = 0xe0; public static final int SHR_INT_LIT8 = 0xe1; public static final int USHR_INT_LIT8 = 0xe2; public static final int INVOKE_POLYMORPHIC = 0xfa; public static final int INVOKE_POLYMORPHIC_RANGE = 0xfb; public static final int INVOKE_CUSTOM = 0xfc; public static final int INVOKE_CUSTOM_RANGE = 0xfd; public static final int CONST_METHOD_HANDLE = 0xfe; public static final int CONST_METHOD_TYPE = 0xff; // payload pseudo-instructions public static final int PACKED_SWITCH_PAYLOAD = 0x0100; public static final int SPARSE_SWITCH_PAYLOAD = 0x0200; public static final int FILL_ARRAY_DATA_PAYLOAD = 0x0300; }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/insns/DexInsnData.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/insns/DexInsnData.java
package jadx.plugins.input.dex.insns; import org.jetbrains.annotations.Nullable; import jadx.api.plugins.input.data.ICallSite; import jadx.api.plugins.input.data.IFieldRef; import jadx.api.plugins.input.data.IMethodHandle; import jadx.api.plugins.input.data.IMethodProto; import jadx.api.plugins.input.data.IMethodRef; import jadx.api.plugins.input.insns.InsnData; import jadx.api.plugins.input.insns.InsnIndexType; import jadx.api.plugins.input.insns.Opcode; import jadx.api.plugins.input.insns.custom.ICustomPayload; import jadx.plugins.input.dex.sections.DexCodeReader; import jadx.plugins.input.dex.sections.SectionReader; public class DexInsnData implements InsnData { private final DexCodeReader codeData; private final SectionReader externalReader; private final SectionReader secondExtReader; private DexInsnInfo insnInfo; private boolean decoded; private int opcodeUnit; private int length; private int insnStart; private int offset; private int[] argsReg = new int[5]; private int regsCount; private long literal; private int target; private int index; @Nullable private ICustomPayload payload; public DexInsnData(DexCodeReader codeData, SectionReader externalReader) { this.codeData = codeData; this.externalReader = externalReader; this.secondExtReader = externalReader.copy(); } @Override public void decode() { if (insnInfo != null && !decoded) { codeData.decode(this); } } @Override public int getOffset() { return offset; } @Override public int getFileOffset() { return insnStart; } @Override public Opcode getOpcode() { DexInsnInfo info = this.insnInfo; if (info == null) { return Opcode.UNKNOWN; } return info.getApiOpcode(); } @Override public String getOpcodeMnemonic() { return DexInsnMnemonics.get(opcodeUnit); } @Override public byte[] getByteCode() { return externalReader.getByteCode(insnStart, length * 2); // a unit is 2 bytes } @Override public int getRawOpcodeUnit() { return opcodeUnit; } @Override public int getRegsCount() { return regsCount; } @Override public int getReg(int argNum) { return argsReg[argNum]; } @Override public int getResultReg() { return -1; } @Override public long getLiteral() { return literal; } @Override public int getTarget() { return target; } @Override public int getIndex() { return index; } @Override public InsnIndexType getIndexType() { return insnInfo.getIndexType(); } @Override public String getIndexAsString() { return externalReader.getString(index); } @Override public String getIndexAsType() { return externalReader.getType(index); } @Override public IFieldRef getIndexAsField() { return externalReader.getFieldRef(index); } @Override public IMethodRef getIndexAsMethod() { return externalReader.getMethodRef(index); } @Override public ICallSite getIndexAsCallSite() { return externalReader.getCallSite(index, secondExtReader); } /** * Currently, protoIndex is either being stored at index or target, index for const-method-type, * target for invoke-polymorphic(/range) */ @Override public IMethodProto getIndexAsProto(int protoIndex) { return externalReader.getMethodProto(protoIndex); } @Override public IMethodHandle getIndexAsMethodHandle() { return externalReader.getMethodHandle(index); } @Nullable @Override public ICustomPayload getPayload() { return payload; } public int[] getArgsReg() { return argsReg; } public void setArgsReg(int[] argsReg) { this.argsReg = argsReg; } public void setRegsCount(int regsCount) { this.regsCount = regsCount; } public int getLength() { return length; } public void setLength(int length) { this.length = length; } public void setInsnStart(int start) { this.insnStart = start; } public void setLiteral(long literal) { this.literal = literal; } public void setTarget(int target) { this.target = target; } public void setIndex(int index) { this.index = index; } public boolean isDecoded() { return decoded; } public void setDecoded(boolean decoded) { this.decoded = decoded; } public void setOffset(int offset) { this.offset = offset; } public DexInsnInfo getInsnInfo() { return insnInfo; } public void setInsnInfo(DexInsnInfo insnInfo) { this.insnInfo = insnInfo; } public DexCodeReader getCodeData() { return codeData; } public int getOpcodeUnit() { return opcodeUnit; } public void setOpcodeUnit(int opcodeUnit) { this.opcodeUnit = opcodeUnit; } public void setPayload(ICustomPayload payload) { this.payload = payload; } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append(String.format("0x%04X", offset)); sb.append(": ").append(getOpcode()); if (insnInfo == null) { sb.append(String.format("(0x%04X)", opcodeUnit)); } else { int regsCount = getRegsCount(); if (isDecoded()) { sb.append(' '); for (int i = 0; i < regsCount; i++) { if (i != 0) { sb.append(", "); } sb.append("r").append(argsReg[i]); } } } return sb.toString(); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/insns/DexInsnFormat.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/insns/DexInsnFormat.java
package jadx.plugins.input.dex.insns; import jadx.api.plugins.input.insns.custom.impl.SwitchPayload; import jadx.plugins.input.dex.DexException; import jadx.plugins.input.dex.insns.payloads.DexArrayPayload; import jadx.plugins.input.dex.sections.SectionReader; public abstract class DexInsnFormat { public static final DexInsnFormat FORMAT_10X = new DexInsnFormat(1, 0) { @Override public void decode(DexInsnData insn, int opcodeUnit, SectionReader in) { // no op } }; public static final DexInsnFormat FORMAT_12X = new DexInsnFormat(1, 2) { @Override public void decode(DexInsnData insn, int opcodeUnit, SectionReader in) { int[] regs = insn.getArgsReg(); regs[0] = nibble2(opcodeUnit); regs[1] = nibble3(opcodeUnit); } }; public static final DexInsnFormat FORMAT_11N = new DexInsnFormat(1, 1) { @Override public void decode(DexInsnData insn, int opcodeUnit, SectionReader in) { int[] regs = insn.getArgsReg(); regs[0] = nibble2(opcodeUnit); insn.setLiteral(signedNibble3(opcodeUnit)); } }; public static final DexInsnFormat FORMAT_11X = new DexInsnFormat(1, 1) { @Override public void decode(DexInsnData insn, int opcodeUnit, SectionReader in) { int[] regs = insn.getArgsReg(); regs[0] = byte1(opcodeUnit); } }; public static final DexInsnFormat FORMAT_10T = new DexInsnFormat(1, 0) { @Override public void decode(DexInsnData insn, int opcodeUnit, SectionReader in) { insn.setTarget(insn.getOffset() + signedByte1(opcodeUnit)); } }; public static final DexInsnFormat FORMAT_20T = new DexInsnFormat(2, 0) { @Override public void decode(DexInsnData insn, int opcodeUnit, SectionReader in) { insn.setTarget(insn.getOffset() + in.readShort()); } }; public static final DexInsnFormat FORMAT_20BC = new DexInsnFormat(2, 0) { @Override public void decode(DexInsnData insn, int opcodeUnit, SectionReader in) { insn.setLiteral(byte1(opcodeUnit)); insn.setIndex(in.readUShort()); } }; public static final DexInsnFormat FORMAT_22X = new DexInsnFormat(2, 2) { @Override public void decode(DexInsnData insn, int opcodeUnit, SectionReader in) { int[] regs = insn.getArgsReg(); regs[0] = byte1(opcodeUnit); regs[1] = in.readUShort(); } }; public static final DexInsnFormat FORMAT_21T = new DexInsnFormat(2, 1) { @Override public void decode(DexInsnData insn, int opcodeUnit, SectionReader in) { int[] regs = insn.getArgsReg(); regs[0] = byte1(opcodeUnit); insn.setTarget(insn.getOffset() + in.readShort()); } }; public static final DexInsnFormat FORMAT_21S = new DexInsnFormat(2, 1) { @Override public void decode(DexInsnData insn, int opcodeUnit, SectionReader in) { int[] regs = insn.getArgsReg(); regs[0] = byte1(opcodeUnit); insn.setLiteral(in.readShort()); } }; public static final DexInsnFormat FORMAT_21H = new DexInsnFormat(2, 1) { @Override public void decode(DexInsnData insn, int opcodeUnit, SectionReader in) { int[] regs = insn.getArgsReg(); regs[0] = byte1(opcodeUnit); long literal = in.readShort(); literal <<= byte0(opcodeUnit) == DexOpcodes.CONST_HIGH16 ? 16 : 48; insn.setLiteral(literal); } }; public static final DexInsnFormat FORMAT_21C = new DexInsnFormat(2, 1) { @Override public void decode(DexInsnData insn, int opcodeUnit, SectionReader in) { int[] regs = insn.getArgsReg(); regs[0] = byte1(opcodeUnit); insn.setIndex(in.readUShort()); } }; public static final DexInsnFormat FORMAT_23X = new DexInsnFormat(2, 3) { @Override public void decode(DexInsnData insn, int opcodeUnit, SectionReader in) { int[] regs = insn.getArgsReg(); regs[0] = byte1(opcodeUnit); int next = in.readUShort(); regs[1] = byte0(next); regs[2] = byte1(next); } }; public static final DexInsnFormat FORMAT_22B = new DexInsnFormat(2, 2) { @Override public void decode(DexInsnData insn, int opcodeUnit, SectionReader in) { int[] regs = insn.getArgsReg(); regs[0] = byte1(opcodeUnit); int next = in.readUShort(); regs[1] = byte0(next); insn.setLiteral(signedByte1(next)); } }; public static final DexInsnFormat FORMAT_22T = new DexInsnFormat(2, 2) { @Override public void decode(DexInsnData insn, int opcodeUnit, SectionReader in) { int[] regs = insn.getArgsReg(); regs[0] = nibble2(opcodeUnit); regs[1] = nibble3(opcodeUnit); insn.setTarget(insn.getOffset() + in.readShort()); } }; public static final DexInsnFormat FORMAT_22S = new DexInsnFormat(2, 2) { @Override public void decode(DexInsnData insn, int opcodeUnit, SectionReader in) { int[] regs = insn.getArgsReg(); regs[0] = nibble2(opcodeUnit); regs[1] = nibble3(opcodeUnit); insn.setLiteral(in.readShort()); } }; public static final DexInsnFormat FORMAT_22C = new DexInsnFormat(2, 2) { @Override public void decode(DexInsnData insn, int opcodeUnit, SectionReader in) { int[] regs = insn.getArgsReg(); regs[0] = nibble2(opcodeUnit); regs[1] = nibble3(opcodeUnit); insn.setIndex(in.readUShort()); insn.setLiteral(0L); } }; public static final DexInsnFormat FORMAT_22CS = FORMAT_22C; public static final DexInsnFormat FORMAT_30T = new DexInsnFormat(3, 0) { @Override public void decode(DexInsnData insn, int opcodeUnit, SectionReader in) { insn.setTarget(insn.getOffset() + in.readInt()); } }; public static final DexInsnFormat FORMAT_32X = new DexInsnFormat(3, 2) { @Override public void decode(DexInsnData insn, int opcodeUnit, SectionReader in) { int[] regs = insn.getArgsReg(); regs[0] = in.readUShort(); regs[1] = in.readUShort(); } }; public static final DexInsnFormat FORMAT_31I = new DexInsnFormat(3, 1) { @Override public void decode(DexInsnData insn, int opcodeUnit, SectionReader in) { int[] regs = insn.getArgsReg(); regs[0] = byte1(opcodeUnit); insn.setLiteral(in.readInt()); } }; public static final DexInsnFormat FORMAT_31T = new DexInsnFormat(3, 1) { @Override public void decode(DexInsnData insn, int opcodeUnit, SectionReader in) { int[] regs = insn.getArgsReg(); regs[0] = byte1(opcodeUnit); insn.setTarget(insn.getOffset() + in.readInt()); } }; public static final DexInsnFormat FORMAT_31C = new DexInsnFormat(3, 1) { @Override public void decode(DexInsnData insn, int opcodeUnit, SectionReader in) { int[] regs = insn.getArgsReg(); regs[0] = byte1(opcodeUnit); insn.setIndex(in.readInt()); } }; public static final DexInsnFormat FORMAT_35C = new DexInsnFormat(3, -1) { @Override public void decode(DexInsnData insn, int opcodeUnit, SectionReader in) { readRegsList(insn, opcodeUnit, in); } }; public static final DexInsnFormat FORMAT_35MS = FORMAT_35C; public static final DexInsnFormat FORMAT_35MI = FORMAT_35C; public static final DexInsnFormat FORMAT_3RC = new DexInsnFormat(3, -1) { @Override public void decode(DexInsnData insn, int opcodeUnit, SectionReader in) { readRegsRange(insn, opcodeUnit, in); } }; public static final DexInsnFormat FORMAT_3RMS = FORMAT_3RC; public static final DexInsnFormat FORMAT_3RMI = FORMAT_3RC; public static final DexInsnFormat FORMAT_45CC = new DexInsnFormat(4, -1) { @Override public void decode(DexInsnData insn, int opcodeUnit, SectionReader in) { readRegsList(insn, opcodeUnit, in); insn.setTarget(in.readUShort()); } }; public static final DexInsnFormat FORMAT_4RCC = new DexInsnFormat(4, -1) { @Override public void decode(DexInsnData insn, int opcodeUnit, SectionReader in) { readRegsRange(insn, opcodeUnit, in); insn.setTarget(in.readUShort()); } }; public static final DexInsnFormat FORMAT_51I = new DexInsnFormat(5, 1) { @Override public void decode(DexInsnData insn, int opcodeUnit, SectionReader in) { int[] regs = insn.getArgsReg(); regs[0] = byte1(opcodeUnit); insn.setLiteral(in.readLong()); } }; public static final DexInsnFormat FORMAT_PACKED_SWITCH_PAYLOAD = new DexInsnFormat(-1, -1) { @Override public void decode(DexInsnData insn, int opcodeUnit, SectionReader in) { int size = in.readUShort(); int firstKey = in.readInt(); int[] keys = new int[size]; int[] targets = new int[size]; for (int i = 0; i < size; i++) { targets[i] = in.readInt(); keys[i] = firstKey + i; } insn.setPayload(new SwitchPayload(size, keys, targets)); insn.setLength(size * 2 + 4); } @Override public void skip(DexInsnData insn, SectionReader in) { int size = in.readUShort(); in.skip(4 + size * 4); insn.setLength(size * 2 + 4); } }; public static final DexInsnFormat FORMAT_SPARSE_SWITCH_PAYLOAD = new DexInsnFormat(-1, -1) { @Override public void decode(DexInsnData insn, int opcodeUnit, SectionReader in) { int size = in.readUShort(); int[] keys = new int[size]; for (int i = 0; i < size; i++) { keys[i] = in.readInt(); } int[] targets = new int[size]; for (int i = 0; i < size; i++) { targets[i] = in.readInt(); } insn.setPayload(new SwitchPayload(size, keys, targets)); insn.setLength(size * 4 + 2); } @Override public void skip(DexInsnData insn, SectionReader in) { int size = in.readUShort(); in.skip(size * 8); insn.setLength(size * 4 + 2); } }; public static final DexInsnFormat FORMAT_FILL_ARRAY_DATA_PAYLOAD = new DexInsnFormat(-1, -1) { @Override public void decode(DexInsnData insn, int opcodeUnit, SectionReader in) { int elemSize = in.readUShort(); int size = in.readInt(); Object data; switch (elemSize) { case 1: { data = in.readByteArray(size); if (size % 2 != 0) { in.readUByte(); } break; } case 2: { short[] array = new short[size]; for (int i = 0; i < size; i++) { array[i] = (short) in.readShort(); } data = array; break; } case 4: { int[] array = new int[size]; for (int i = 0; i < size; i++) { array[i] = in.readInt(); } data = array; break; } case 8: { long[] array = new long[size]; for (int i = 0; i < size; i++) { array[i] = in.readLong(); } data = array; break; } case 0: { data = new byte[0]; break; } default: throw new DexException("Unexpected element size in FILL_ARRAY_DATA_PAYLOAD: " + elemSize); } insn.setLength((size * elemSize + 1) / 2 + 4); insn.setPayload(new DexArrayPayload(size, elemSize, data)); } @Override public void skip(DexInsnData insn, SectionReader in) { int elemSize = in.readUShort(); int size = in.readInt(); if (elemSize == 1) { in.skip(size + size % 2); } else { in.skip(size * elemSize); } insn.setLength((size * elemSize + 1) / 2 + 4); } }; protected void readRegsList(DexInsnData insn, int opcodeUnit, SectionReader in) { int regsCount1 = nibble3(opcodeUnit); int index = in.readUShort(); int rs = in.readUShort(); int[] regs = insn.getArgsReg(); regs[0] = nibble0(rs); regs[1] = nibble1(rs); regs[2] = nibble2(rs); regs[3] = nibble3(rs); regs[4] = nibble2(opcodeUnit); insn.setRegsCount(regsCount1); insn.setIndex(index); } protected void readRegsRange(DexInsnData insn, int opcodeUnit, SectionReader in) { int regsCount = byte1(opcodeUnit); int index = in.readUShort(); int startReg = in.readUShort(); int[] regs = insn.getArgsReg(); if (regs.length < regsCount) { regs = new int[regsCount]; insn.setArgsReg(regs); } int regNum = startReg; for (int i = 0; i < regsCount; i++) { regs[i] = regNum; regNum++; } insn.setRegsCount(regsCount); insn.setIndex(index); } private final int length; private final int regsCount; protected DexInsnFormat(int length, int regsCount) { this.length = length; this.regsCount = regsCount; } public abstract void decode(DexInsnData insn, int opcodeUnit, SectionReader in); public void skip(DexInsnData insn, SectionReader in) { int len = this.length; if (len == 1) { return; } in.skip((len - 1) * 2); } public int getLength() { return length; } public int getRegsCount() { return regsCount; } private static int byte0(int value) { return value & 0xFF; } private static int byte1(int value) { return (value >> 8) & 0xFF; } private static int signedByte1(int value) { return (byte) (value >> 8); } private static int nibble0(int value) { return value & 0xF; } private static int nibble1(int value) { return (value >> 4) & 0xF; } private static int nibble2(int value) { return (value >> 8) & 0xF; } private static int nibble3(int value) { return (value >> 12) & 0xF; } private static int signedNibble3(int value) { return (((value >> 12) & 0xF) << 28) >> 28; } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/insns/DexInsnInfo.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/insns/DexInsnInfo.java
package jadx.plugins.input.dex.insns; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.jetbrains.annotations.Nullable; import jadx.api.plugins.input.insns.InsnIndexType; import jadx.api.plugins.input.insns.Opcode; public class DexInsnInfo { private static final DexInsnInfo[] INSN_INFO; private static final Map<Integer, DexInsnInfo> PAYLOAD_INFO; static { DexInsnInfo[] arr = new DexInsnInfo[0x100]; INSN_INFO = arr; register(arr, DexOpcodes.NOP, Opcode.NOP, DexInsnFormat.FORMAT_10X); register(arr, DexOpcodes.MOVE, Opcode.MOVE, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.MOVE_FROM16, Opcode.MOVE, DexInsnFormat.FORMAT_22X); register(arr, DexOpcodes.MOVE_16, Opcode.MOVE, DexInsnFormat.FORMAT_32X); register(arr, DexOpcodes.MOVE_WIDE, Opcode.MOVE_WIDE, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.MOVE_WIDE_FROM16, Opcode.MOVE_WIDE, DexInsnFormat.FORMAT_22X); register(arr, DexOpcodes.MOVE_WIDE_16, Opcode.MOVE_WIDE, DexInsnFormat.FORMAT_32X); register(arr, DexOpcodes.MOVE_OBJECT, Opcode.MOVE_OBJECT, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.MOVE_OBJECT_FROM16, Opcode.MOVE_OBJECT, DexInsnFormat.FORMAT_22X); register(arr, DexOpcodes.MOVE_OBJECT_16, Opcode.MOVE_OBJECT, DexInsnFormat.FORMAT_32X); register(arr, DexOpcodes.MOVE_RESULT, Opcode.MOVE_RESULT, DexInsnFormat.FORMAT_11X); register(arr, DexOpcodes.MOVE_RESULT_WIDE, Opcode.MOVE_RESULT, DexInsnFormat.FORMAT_11X); register(arr, DexOpcodes.MOVE_RESULT_OBJECT, Opcode.MOVE_RESULT, DexInsnFormat.FORMAT_11X); register(arr, DexOpcodes.MOVE_EXCEPTION, Opcode.MOVE_EXCEPTION, DexInsnFormat.FORMAT_11X); register(arr, DexOpcodes.RETURN_VOID, Opcode.RETURN_VOID, DexInsnFormat.FORMAT_10X); register(arr, DexOpcodes.RETURN, Opcode.RETURN, DexInsnFormat.FORMAT_11X); register(arr, DexOpcodes.RETURN_WIDE, Opcode.RETURN, DexInsnFormat.FORMAT_11X); register(arr, DexOpcodes.RETURN_OBJECT, Opcode.RETURN, DexInsnFormat.FORMAT_11X); register(arr, DexOpcodes.CONST_4, Opcode.CONST, DexInsnFormat.FORMAT_11N); register(arr, DexOpcodes.CONST_16, Opcode.CONST, DexInsnFormat.FORMAT_21S); register(arr, DexOpcodes.CONST, Opcode.CONST, DexInsnFormat.FORMAT_31I); register(arr, DexOpcodes.CONST_HIGH16, Opcode.CONST, DexInsnFormat.FORMAT_21H); register(arr, DexOpcodes.CONST_WIDE_16, Opcode.CONST_WIDE, DexInsnFormat.FORMAT_21S); register(arr, DexOpcodes.CONST_WIDE_32, Opcode.CONST_WIDE, DexInsnFormat.FORMAT_31I); register(arr, DexOpcodes.CONST_WIDE, Opcode.CONST_WIDE, DexInsnFormat.FORMAT_51I); register(arr, DexOpcodes.CONST_WIDE_HIGH16, Opcode.CONST_WIDE, DexInsnFormat.FORMAT_21H); register(arr, DexOpcodes.CONST_STRING, Opcode.CONST_STRING, DexInsnFormat.FORMAT_21C, InsnIndexType.STRING_REF); register(arr, DexOpcodes.CONST_STRING_JUMBO, Opcode.CONST_STRING, DexInsnFormat.FORMAT_31C, InsnIndexType.STRING_REF); register(arr, DexOpcodes.CONST_CLASS, Opcode.CONST_CLASS, DexInsnFormat.FORMAT_21C, InsnIndexType.TYPE_REF); register(arr, DexOpcodes.MONITOR_ENTER, Opcode.MONITOR_ENTER, DexInsnFormat.FORMAT_11X); register(arr, DexOpcodes.MONITOR_EXIT, Opcode.MONITOR_EXIT, DexInsnFormat.FORMAT_11X); register(arr, DexOpcodes.CHECK_CAST, Opcode.CHECK_CAST, DexInsnFormat.FORMAT_21C, InsnIndexType.TYPE_REF); register(arr, DexOpcodes.INSTANCE_OF, Opcode.INSTANCE_OF, DexInsnFormat.FORMAT_22C, InsnIndexType.TYPE_REF); register(arr, DexOpcodes.ARRAY_LENGTH, Opcode.ARRAY_LENGTH, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.NEW_INSTANCE, Opcode.NEW_INSTANCE, DexInsnFormat.FORMAT_21C, InsnIndexType.TYPE_REF); register(arr, DexOpcodes.NEW_ARRAY, Opcode.NEW_ARRAY, DexInsnFormat.FORMAT_22C, InsnIndexType.TYPE_REF); register(arr, DexOpcodes.FILLED_NEW_ARRAY, Opcode.FILLED_NEW_ARRAY, DexInsnFormat.FORMAT_35C, InsnIndexType.TYPE_REF); register(arr, DexOpcodes.FILLED_NEW_ARRAY_RANGE, Opcode.FILLED_NEW_ARRAY_RANGE, DexInsnFormat.FORMAT_3RC, InsnIndexType.TYPE_REF); register(arr, DexOpcodes.FILL_ARRAY_DATA, Opcode.FILL_ARRAY_DATA, DexInsnFormat.FORMAT_31T); register(arr, DexOpcodes.THROW, Opcode.THROW, DexInsnFormat.FORMAT_11X); register(arr, DexOpcodes.GOTO, Opcode.GOTO, DexInsnFormat.FORMAT_10T); register(arr, DexOpcodes.GOTO_16, Opcode.GOTO, DexInsnFormat.FORMAT_20T); register(arr, DexOpcodes.GOTO_32, Opcode.GOTO, DexInsnFormat.FORMAT_30T); register(arr, DexOpcodes.PACKED_SWITCH, Opcode.PACKED_SWITCH, DexInsnFormat.FORMAT_31T); register(arr, DexOpcodes.SPARSE_SWITCH, Opcode.SPARSE_SWITCH, DexInsnFormat.FORMAT_31T); register(arr, DexOpcodes.CMPL_FLOAT, Opcode.CMPL_FLOAT, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.CMPG_FLOAT, Opcode.CMPG_FLOAT, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.CMPL_DOUBLE, Opcode.CMPL_DOUBLE, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.CMPG_DOUBLE, Opcode.CMPG_DOUBLE, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.CMP_LONG, Opcode.CMP_LONG, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.IF_EQ, Opcode.IF_EQ, DexInsnFormat.FORMAT_22T); register(arr, DexOpcodes.IF_NE, Opcode.IF_NE, DexInsnFormat.FORMAT_22T); register(arr, DexOpcodes.IF_LT, Opcode.IF_LT, DexInsnFormat.FORMAT_22T); register(arr, DexOpcodes.IF_GE, Opcode.IF_GE, DexInsnFormat.FORMAT_22T); register(arr, DexOpcodes.IF_GT, Opcode.IF_GT, DexInsnFormat.FORMAT_22T); register(arr, DexOpcodes.IF_LE, Opcode.IF_LE, DexInsnFormat.FORMAT_22T); register(arr, DexOpcodes.IF_EQZ, Opcode.IF_EQZ, DexInsnFormat.FORMAT_21T); register(arr, DexOpcodes.IF_NEZ, Opcode.IF_NEZ, DexInsnFormat.FORMAT_21T); register(arr, DexOpcodes.IF_LTZ, Opcode.IF_LTZ, DexInsnFormat.FORMAT_21T); register(arr, DexOpcodes.IF_GEZ, Opcode.IF_GEZ, DexInsnFormat.FORMAT_21T); register(arr, DexOpcodes.IF_GTZ, Opcode.IF_GTZ, DexInsnFormat.FORMAT_21T); register(arr, DexOpcodes.IF_LEZ, Opcode.IF_LEZ, DexInsnFormat.FORMAT_21T); register(arr, DexOpcodes.AGET, Opcode.AGET, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.AGET_WIDE, Opcode.AGET_WIDE, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.AGET_OBJECT, Opcode.AGET_OBJECT, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.AGET_BOOLEAN, Opcode.AGET_BOOLEAN, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.AGET_BYTE, Opcode.AGET_BYTE, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.AGET_CHAR, Opcode.AGET_CHAR, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.AGET_SHORT, Opcode.AGET_SHORT, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.APUT, Opcode.APUT, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.APUT_WIDE, Opcode.APUT_WIDE, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.APUT_OBJECT, Opcode.APUT_OBJECT, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.APUT_BOOLEAN, Opcode.APUT_BOOLEAN, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.APUT_BYTE, Opcode.APUT_BYTE, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.APUT_CHAR, Opcode.APUT_CHAR, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.APUT_SHORT, Opcode.APUT_SHORT, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.IGET, Opcode.IGET, DexInsnFormat.FORMAT_22C, InsnIndexType.FIELD_REF); register(arr, DexOpcodes.IGET_WIDE, Opcode.IGET, DexInsnFormat.FORMAT_22C, InsnIndexType.FIELD_REF); register(arr, DexOpcodes.IGET_OBJECT, Opcode.IGET, DexInsnFormat.FORMAT_22C, InsnIndexType.FIELD_REF); register(arr, DexOpcodes.IGET_BOOLEAN, Opcode.IGET, DexInsnFormat.FORMAT_22C, InsnIndexType.FIELD_REF); register(arr, DexOpcodes.IGET_BYTE, Opcode.IGET, DexInsnFormat.FORMAT_22C, InsnIndexType.FIELD_REF); register(arr, DexOpcodes.IGET_CHAR, Opcode.IGET, DexInsnFormat.FORMAT_22C, InsnIndexType.FIELD_REF); register(arr, DexOpcodes.IGET_SHORT, Opcode.IGET, DexInsnFormat.FORMAT_22C, InsnIndexType.FIELD_REF); register(arr, DexOpcodes.IPUT, Opcode.IPUT, DexInsnFormat.FORMAT_22C, InsnIndexType.FIELD_REF); register(arr, DexOpcodes.IPUT_WIDE, Opcode.IPUT, DexInsnFormat.FORMAT_22C, InsnIndexType.FIELD_REF); register(arr, DexOpcodes.IPUT_OBJECT, Opcode.IPUT, DexInsnFormat.FORMAT_22C, InsnIndexType.FIELD_REF); register(arr, DexOpcodes.IPUT_BOOLEAN, Opcode.IPUT, DexInsnFormat.FORMAT_22C, InsnIndexType.FIELD_REF); register(arr, DexOpcodes.IPUT_BYTE, Opcode.IPUT, DexInsnFormat.FORMAT_22C, InsnIndexType.FIELD_REF); register(arr, DexOpcodes.IPUT_CHAR, Opcode.IPUT, DexInsnFormat.FORMAT_22C, InsnIndexType.FIELD_REF); register(arr, DexOpcodes.IPUT_SHORT, Opcode.IPUT, DexInsnFormat.FORMAT_22C, InsnIndexType.FIELD_REF); register(arr, DexOpcodes.SGET, Opcode.SGET, DexInsnFormat.FORMAT_21C, InsnIndexType.FIELD_REF); register(arr, DexOpcodes.SGET_WIDE, Opcode.SGET, DexInsnFormat.FORMAT_21C, InsnIndexType.FIELD_REF); register(arr, DexOpcodes.SGET_OBJECT, Opcode.SGET, DexInsnFormat.FORMAT_21C, InsnIndexType.FIELD_REF); register(arr, DexOpcodes.SGET_BOOLEAN, Opcode.SGET, DexInsnFormat.FORMAT_21C, InsnIndexType.FIELD_REF); register(arr, DexOpcodes.SGET_BYTE, Opcode.SGET, DexInsnFormat.FORMAT_21C, InsnIndexType.FIELD_REF); register(arr, DexOpcodes.SGET_CHAR, Opcode.SGET, DexInsnFormat.FORMAT_21C, InsnIndexType.FIELD_REF); register(arr, DexOpcodes.SGET_SHORT, Opcode.SGET, DexInsnFormat.FORMAT_21C, InsnIndexType.FIELD_REF); register(arr, DexOpcodes.SPUT, Opcode.SPUT, DexInsnFormat.FORMAT_21C, InsnIndexType.FIELD_REF); register(arr, DexOpcodes.SPUT_WIDE, Opcode.SPUT, DexInsnFormat.FORMAT_21C, InsnIndexType.FIELD_REF); register(arr, DexOpcodes.SPUT_OBJECT, Opcode.SPUT, DexInsnFormat.FORMAT_21C, InsnIndexType.FIELD_REF); register(arr, DexOpcodes.SPUT_BOOLEAN, Opcode.SPUT, DexInsnFormat.FORMAT_21C, InsnIndexType.FIELD_REF); register(arr, DexOpcodes.SPUT_BYTE, Opcode.SPUT, DexInsnFormat.FORMAT_21C, InsnIndexType.FIELD_REF); register(arr, DexOpcodes.SPUT_CHAR, Opcode.SPUT, DexInsnFormat.FORMAT_21C, InsnIndexType.FIELD_REF); register(arr, DexOpcodes.SPUT_SHORT, Opcode.SPUT, DexInsnFormat.FORMAT_21C, InsnIndexType.FIELD_REF); register(arr, DexOpcodes.INVOKE_VIRTUAL, Opcode.INVOKE_VIRTUAL, DexInsnFormat.FORMAT_35C, InsnIndexType.METHOD_REF); register(arr, DexOpcodes.INVOKE_SUPER, Opcode.INVOKE_SUPER, DexInsnFormat.FORMAT_35C, InsnIndexType.METHOD_REF); register(arr, DexOpcodes.INVOKE_DIRECT, Opcode.INVOKE_DIRECT, DexInsnFormat.FORMAT_35C, InsnIndexType.METHOD_REF); register(arr, DexOpcodes.INVOKE_STATIC, Opcode.INVOKE_STATIC, DexInsnFormat.FORMAT_35C, InsnIndexType.METHOD_REF); register(arr, DexOpcodes.INVOKE_INTERFACE, Opcode.INVOKE_INTERFACE, DexInsnFormat.FORMAT_35C, InsnIndexType.METHOD_REF); register(arr, DexOpcodes.INVOKE_VIRTUAL_RANGE, Opcode.INVOKE_VIRTUAL_RANGE, DexInsnFormat.FORMAT_3RC, InsnIndexType.METHOD_REF); register(arr, DexOpcodes.INVOKE_SUPER_RANGE, Opcode.INVOKE_SUPER_RANGE, DexInsnFormat.FORMAT_3RC, InsnIndexType.METHOD_REF); register(arr, DexOpcodes.INVOKE_DIRECT_RANGE, Opcode.INVOKE_DIRECT_RANGE, DexInsnFormat.FORMAT_3RC, InsnIndexType.METHOD_REF); register(arr, DexOpcodes.INVOKE_STATIC_RANGE, Opcode.INVOKE_STATIC_RANGE, DexInsnFormat.FORMAT_3RC, InsnIndexType.METHOD_REF); register(arr, DexOpcodes.INVOKE_INTERFACE_RANGE, Opcode.INVOKE_INTERFACE_RANGE, DexInsnFormat.FORMAT_3RC, InsnIndexType.METHOD_REF); register(arr, DexOpcodes.NEG_INT, Opcode.NEG_INT, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.NOT_INT, Opcode.NOT_INT, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.NEG_LONG, Opcode.NEG_LONG, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.NOT_LONG, Opcode.NOT_LONG, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.NEG_FLOAT, Opcode.NEG_FLOAT, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.NEG_DOUBLE, Opcode.NEG_DOUBLE, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.INT_TO_LONG, Opcode.INT_TO_LONG, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.INT_TO_FLOAT, Opcode.INT_TO_FLOAT, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.INT_TO_DOUBLE, Opcode.INT_TO_DOUBLE, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.LONG_TO_INT, Opcode.LONG_TO_INT, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.LONG_TO_FLOAT, Opcode.LONG_TO_FLOAT, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.LONG_TO_DOUBLE, Opcode.LONG_TO_DOUBLE, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.FLOAT_TO_INT, Opcode.FLOAT_TO_INT, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.FLOAT_TO_LONG, Opcode.FLOAT_TO_LONG, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.FLOAT_TO_DOUBLE, Opcode.FLOAT_TO_DOUBLE, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.DOUBLE_TO_INT, Opcode.DOUBLE_TO_INT, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.DOUBLE_TO_LONG, Opcode.DOUBLE_TO_LONG, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.DOUBLE_TO_FLOAT, Opcode.DOUBLE_TO_FLOAT, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.INT_TO_BYTE, Opcode.INT_TO_BYTE, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.INT_TO_CHAR, Opcode.INT_TO_CHAR, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.INT_TO_SHORT, Opcode.INT_TO_SHORT, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.ADD_INT, Opcode.ADD_INT, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.SUB_INT, Opcode.SUB_INT, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.MUL_INT, Opcode.MUL_INT, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.DIV_INT, Opcode.DIV_INT, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.REM_INT, Opcode.REM_INT, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.AND_INT, Opcode.AND_INT, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.OR_INT, Opcode.OR_INT, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.XOR_INT, Opcode.XOR_INT, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.SHL_INT, Opcode.SHL_INT, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.SHR_INT, Opcode.SHR_INT, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.USHR_INT, Opcode.USHR_INT, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.ADD_LONG, Opcode.ADD_LONG, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.SUB_LONG, Opcode.SUB_LONG, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.MUL_LONG, Opcode.MUL_LONG, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.DIV_LONG, Opcode.DIV_LONG, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.REM_LONG, Opcode.REM_LONG, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.AND_LONG, Opcode.AND_LONG, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.OR_LONG, Opcode.OR_LONG, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.XOR_LONG, Opcode.XOR_LONG, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.SHL_LONG, Opcode.SHL_LONG, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.SHR_LONG, Opcode.SHR_LONG, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.USHR_LONG, Opcode.USHR_LONG, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.ADD_FLOAT, Opcode.ADD_FLOAT, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.SUB_FLOAT, Opcode.SUB_FLOAT, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.MUL_FLOAT, Opcode.MUL_FLOAT, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.DIV_FLOAT, Opcode.DIV_FLOAT, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.REM_FLOAT, Opcode.REM_FLOAT, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.ADD_DOUBLE, Opcode.ADD_DOUBLE, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.SUB_DOUBLE, Opcode.SUB_DOUBLE, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.MUL_DOUBLE, Opcode.MUL_DOUBLE, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.DIV_DOUBLE, Opcode.DIV_DOUBLE, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.REM_DOUBLE, Opcode.REM_DOUBLE, DexInsnFormat.FORMAT_23X); register(arr, DexOpcodes.ADD_INT_2ADDR, Opcode.ADD_INT, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.SUB_INT_2ADDR, Opcode.SUB_INT, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.MUL_INT_2ADDR, Opcode.MUL_INT, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.DIV_INT_2ADDR, Opcode.DIV_INT, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.REM_INT_2ADDR, Opcode.REM_INT, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.AND_INT_2ADDR, Opcode.AND_INT, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.OR_INT_2ADDR, Opcode.OR_INT, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.XOR_INT_2ADDR, Opcode.XOR_INT, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.SHL_INT_2ADDR, Opcode.SHL_INT, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.SHR_INT_2ADDR, Opcode.SHR_INT, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.USHR_INT_2ADDR, Opcode.USHR_INT, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.ADD_LONG_2ADDR, Opcode.ADD_LONG, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.SUB_LONG_2ADDR, Opcode.SUB_LONG, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.MUL_LONG_2ADDR, Opcode.MUL_LONG, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.DIV_LONG_2ADDR, Opcode.DIV_LONG, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.REM_LONG_2ADDR, Opcode.REM_LONG, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.AND_LONG_2ADDR, Opcode.AND_LONG, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.OR_LONG_2ADDR, Opcode.OR_LONG, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.XOR_LONG_2ADDR, Opcode.XOR_LONG, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.SHL_LONG_2ADDR, Opcode.SHL_LONG, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.SHR_LONG_2ADDR, Opcode.SHR_LONG, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.USHR_LONG_2ADDR, Opcode.USHR_LONG, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.ADD_FLOAT_2ADDR, Opcode.ADD_FLOAT, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.SUB_FLOAT_2ADDR, Opcode.SUB_FLOAT, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.MUL_FLOAT_2ADDR, Opcode.MUL_FLOAT, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.DIV_FLOAT_2ADDR, Opcode.DIV_FLOAT, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.REM_FLOAT_2ADDR, Opcode.REM_FLOAT, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.ADD_DOUBLE_2ADDR, Opcode.ADD_DOUBLE, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.SUB_DOUBLE_2ADDR, Opcode.SUB_DOUBLE, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.MUL_DOUBLE_2ADDR, Opcode.MUL_DOUBLE, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.DIV_DOUBLE_2ADDR, Opcode.DIV_DOUBLE, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.REM_DOUBLE_2ADDR, Opcode.REM_DOUBLE, DexInsnFormat.FORMAT_12X); register(arr, DexOpcodes.ADD_INT_LIT16, Opcode.ADD_INT_LIT, DexInsnFormat.FORMAT_22S); register(arr, DexOpcodes.RSUB_INT, Opcode.RSUB_INT, DexInsnFormat.FORMAT_22S); register(arr, DexOpcodes.MUL_INT_LIT16, Opcode.MUL_INT_LIT, DexInsnFormat.FORMAT_22S); register(arr, DexOpcodes.DIV_INT_LIT16, Opcode.DIV_INT_LIT, DexInsnFormat.FORMAT_22S); register(arr, DexOpcodes.REM_INT_LIT16, Opcode.REM_INT_LIT, DexInsnFormat.FORMAT_22S); register(arr, DexOpcodes.AND_INT_LIT16, Opcode.AND_INT_LIT, DexInsnFormat.FORMAT_22S); register(arr, DexOpcodes.OR_INT_LIT16, Opcode.OR_INT_LIT, DexInsnFormat.FORMAT_22S); register(arr, DexOpcodes.XOR_INT_LIT16, Opcode.XOR_INT_LIT, DexInsnFormat.FORMAT_22S); register(arr, DexOpcodes.ADD_INT_LIT8, Opcode.ADD_INT_LIT, DexInsnFormat.FORMAT_22B); register(arr, DexOpcodes.RSUB_INT_LIT8, Opcode.RSUB_INT, DexInsnFormat.FORMAT_22B); register(arr, DexOpcodes.MUL_INT_LIT8, Opcode.MUL_INT_LIT, DexInsnFormat.FORMAT_22B); register(arr, DexOpcodes.DIV_INT_LIT8, Opcode.DIV_INT_LIT, DexInsnFormat.FORMAT_22B); register(arr, DexOpcodes.REM_INT_LIT8, Opcode.REM_INT_LIT, DexInsnFormat.FORMAT_22B); register(arr, DexOpcodes.AND_INT_LIT8, Opcode.AND_INT_LIT, DexInsnFormat.FORMAT_22B); register(arr, DexOpcodes.OR_INT_LIT8, Opcode.OR_INT_LIT, DexInsnFormat.FORMAT_22B); register(arr, DexOpcodes.XOR_INT_LIT8, Opcode.XOR_INT_LIT, DexInsnFormat.FORMAT_22B); register(arr, DexOpcodes.SHL_INT_LIT8, Opcode.SHL_INT_LIT, DexInsnFormat.FORMAT_22B); register(arr, DexOpcodes.SHR_INT_LIT8, Opcode.SHR_INT_LIT, DexInsnFormat.FORMAT_22B); register(arr, DexOpcodes.USHR_INT_LIT8, Opcode.USHR_INT_LIT, DexInsnFormat.FORMAT_22B); register(arr, DexOpcodes.INVOKE_POLYMORPHIC, Opcode.INVOKE_POLYMORPHIC, DexInsnFormat.FORMAT_45CC, InsnIndexType.METHOD_REF); register(arr, DexOpcodes.INVOKE_POLYMORPHIC_RANGE, Opcode.INVOKE_POLYMORPHIC_RANGE, DexInsnFormat.FORMAT_4RCC, InsnIndexType.METHOD_REF); register(arr, DexOpcodes.INVOKE_CUSTOM, Opcode.INVOKE_CUSTOM, DexInsnFormat.FORMAT_35C, InsnIndexType.CALL_SITE); register(arr, DexOpcodes.INVOKE_CUSTOM_RANGE, Opcode.INVOKE_CUSTOM_RANGE, DexInsnFormat.FORMAT_3RC, InsnIndexType.CALL_SITE); register(arr, DexOpcodes.CONST_METHOD_HANDLE, Opcode.CONST_METHOD_HANDLE, DexInsnFormat.FORMAT_21C); register(arr, DexOpcodes.CONST_METHOD_TYPE, Opcode.CONST_METHOD_TYPE, DexInsnFormat.FORMAT_21C); PAYLOAD_INFO = new ConcurrentHashMap<>(3); registerPayload(DexOpcodes.PACKED_SWITCH_PAYLOAD, Opcode.PACKED_SWITCH_PAYLOAD, DexInsnFormat.FORMAT_PACKED_SWITCH_PAYLOAD); registerPayload(DexOpcodes.SPARSE_SWITCH_PAYLOAD, Opcode.SPARSE_SWITCH_PAYLOAD, DexInsnFormat.FORMAT_SPARSE_SWITCH_PAYLOAD); registerPayload(DexOpcodes.FILL_ARRAY_DATA_PAYLOAD, Opcode.FILL_ARRAY_DATA_PAYLOAD, DexInsnFormat.FORMAT_FILL_ARRAY_DATA_PAYLOAD); } private static void register(DexInsnInfo[] arr, int opcode, Opcode apiOpcode, DexInsnFormat format) { arr[opcode] = new DexInsnInfo(opcode, apiOpcode, format, InsnIndexType.NONE); } private static void register(DexInsnInfo[] arr, int opcode, Opcode apiOpcode, DexInsnFormat format, InsnIndexType indexType) { arr[opcode] = new DexInsnInfo(opcode, apiOpcode, format, indexType); } private static void registerPayload(int opcode, Opcode apiOpcode, DexInsnFormat format) { PAYLOAD_INFO.put(opcode, new DexInsnInfo(opcode, apiOpcode, format, InsnIndexType.NONE)); } @Nullable public static DexInsnInfo get(int opcodeUnit) { int opcode = opcodeUnit & 0xFF; if (opcode == 0 && opcodeUnit != 0) { return PAYLOAD_INFO.get(opcodeUnit); } return INSN_INFO[opcode]; } private final int opcode; private final Opcode apiOpcode; private final DexInsnFormat format; private final InsnIndexType indexType; public DexInsnInfo(int opcode, Opcode apiOpcode, DexInsnFormat format, InsnIndexType indexType) { this.opcode = opcode; this.apiOpcode = apiOpcode; this.format = format; this.indexType = indexType; } public int getOpcode() { return opcode; } public Opcode getApiOpcode() { return apiOpcode; } public DexInsnFormat getFormat() { return format; } public InsnIndexType getIndexType() { return indexType; } @Override public String toString() { return String.format("0x%X :%d%d", opcode, format.getLength(), format.getRegsCount()); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/insns/DexInsnMnemonics.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/insns/DexInsnMnemonics.java
package jadx.plugins.input.dex.insns; public class DexInsnMnemonics { public static String get(int opcode) { return MNEMONICS[opcode & 0xFF]; } private static final String[] MNEMONICS = new String[] { "nop", "move", "move/from16", "move/16", "move-wide", "move-wide/from16", "move-wide/16", "move-object", "move-object/from16", "move-object/16", "move-result", "move-result-wide", "move-result-object", "move-exception", "return-void", "return", "return-wide", "return-object", "const/4", "const/16", "const", "const/high16", "const-wide/16", "const-wide/32", "const-wide", "const-wide/high16", "const-string", "const-string/jumbo", "const-class", "monitor-enter", "monitor-exit", "check-cast", "instance-of", "array-length", "new-instance", "new-array", "filled-new-array", "filled-new-array/range", "fill-array-data", "throw", "goto", "goto/16", "goto/32", "packed-switch", "sparse-switch", "cmpl-float", "cmpg-float", "cmpl-double", "cmpg-double", "cmp-long", "if-eq", "if-ne", "if-lt", "if-ge", "if-gt", "if-le", "if-eqz", "if-nez", "if-ltz", "if-gez", "if-gtz", "if-lez", "(unused)", "(unused)", "(unused)", "(unused)", "(unused)", "(unused)", "aget", "aget-wide", "aget-object", "aget-boolean", "aget-byte", "aget-char", "aget-short", "aput", "aput-wide", "aput-object", "aput-boolean", "aput-byte", "aput-char", "aput-short", "iget", "iget-wide", "iget-object", "iget-boolean", "iget-byte", "iget-char", "iget-short", "iput", "iput-wide", "iput-object", "iput-boolean", "iput-byte", "iput-char", "iput-short", "sget", "sget-wide", "sget-object", "sget-boolean", "sget-byte", "sget-char", "sget-short", "sput", "sput-wide", "sput-object", "sput-boolean", "sput-byte", "sput-char", "sput-short", "invoke-virtual", "invoke-super", "invoke-direct", "invoke-static", "invoke-interface", "(unused)", "invoke-virtual/range", "invoke-super/range", "invoke-direct/range", "invoke-static/range", "invoke-interface/range", "(unused)", "(unused)", "neg-int", "not-int", "neg-long", "not-long", "neg-float", "neg-double", "int-to-long", "int-to-float", "int-to-double", "long-to-int", "long-to-float", "long-to-double", "float-to-int", "float-to-long", "float-to-double", "double-to-int", "double-to-long", "double-to-float", "int-to-byte", "int-to-char", "int-to-short", "add-int", "sub-int", "mul-int", "div-int", "rem-int", "and-int", "or-int", "xor-int", "shl-int", "shr-int", "ushr-int", "add-long", "sub-long", "mul-long", "div-long", "rem-long", "and-long", "or-long", "xor-long", "shl-long", "shr-long", "ushr-long", "add-float", "sub-float", "mul-float", "div-float", "rem-float", "add-double", "sub-double", "mul-double", "div-double", "rem-double", "add-int/2addr", "sub-int/2addr", "mul-int/2addr", "div-int/2addr", "rem-int/2addr", "and-int/2addr", "or-int/2addr", "xor-int/2addr", "shl-int/2addr", "shr-int/2addr", "ushr-int/2addr", "add-long/2addr", "sub-long/2addr", "mul-long/2addr", "div-long/2addr", "rem-long/2addr", "and-long/2addr", "or-long/2addr", "xor-long/2addr", "shl-long/2addr", "shr-long/2addr", "ushr-long/2addr", "add-float/2addr", "sub-float/2addr", "mul-float/2addr", "div-float/2addr", "rem-float/2addr", "add-double/2addr", "sub-double/2addr", "mul-double/2addr", "div-double/2addr", "rem-double/2addr", "add-int/lit16", "rsub-int", "mul-int/lit16", "div-int/lit16", "rem-int/lit16", "and-int/lit16", "or-int/lit16", "xor-int/lit16", "add-int/lit8", "rsub-int/lit8", "mul-int/lit8", "div-int/lit8", "rem-int/lit8", "and-int/lit8", "or-int/lit8", "xor-int/lit8", "shl-int/lit8", "shr-int/lit8", "ushr-int/lit8", "(unused)", "(unused)", "(unused)", "(unused)", "(unused)", "(unused)", "(unused)", "(unused)", "(unused)", "(unused)", "(unused)", "(unused)", "(unused)", "(unused)", "(unused)", "(unused)", "(unused)", "(unused)", "(unused)", "(unused)", "(unused)", "(unused)", "(unused)", "invoke-polymorphic", "invoke-polymorphic/range", "invoke-custom", "invoke-custom/range", "const-method-handle", "const-method-type" }; }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/insns/payloads/DexArrayPayload.java
jadx-plugins/jadx-dex-input/src/main/java/jadx/plugins/input/dex/insns/payloads/DexArrayPayload.java
package jadx.plugins.input.dex.insns.payloads; import jadx.api.plugins.input.insns.custom.IArrayPayload; public class DexArrayPayload implements IArrayPayload { private final int size; private final int elemSize; private final Object data; public DexArrayPayload(int size, int elemSize, Object data) { this.size = size; this.elemSize = elemSize; this.data = data; } @Override public int getSize() { return size; } @Override public int getElementSize() { return elemSize; } @Override public Object getData() { return data; } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-smali-input/src/main/java/jadx/plugins/input/smali/SmaliInputPlugin.java
jadx-plugins/jadx-smali-input/src/main/java/jadx/plugins/input/smali/SmaliInputPlugin.java
package jadx.plugins.input.smali; import jadx.api.plugins.JadxPlugin; import jadx.api.plugins.JadxPluginContext; import jadx.api.plugins.JadxPluginInfo; import jadx.api.plugins.input.data.impl.EmptyCodeLoader; import jadx.plugins.input.dex.DexInputPlugin; public class SmaliInputPlugin implements JadxPlugin { public static final String PLUGIN_ID = "smali-input"; private final SmaliInputOptions options = new SmaliInputOptions(); @Override public JadxPluginInfo getPluginInfo() { return new JadxPluginInfo(PLUGIN_ID, "Smali Input", "Load .smali files"); } @Override public void init(JadxPluginContext context) { context.registerOptions(options); options.setThreads(context.getArgs().getThreadsCount()); DexInputPlugin dexInput = context.plugins().getInstance(DexInputPlugin.class); context.addCodeInput(input -> { SmaliConvert convert = new SmaliConvert(); if (!convert.execute(input, options)) { return EmptyCodeLoader.INSTANCE; } return dexInput.loadDexData(convert.getDexData()); }); } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-smali-input/src/main/java/jadx/plugins/input/smali/SmaliUtils.java
jadx-plugins/jadx-smali-input/src/main/java/jadx/plugins/input/smali/SmaliUtils.java
package jadx.plugins.input.smali; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; import org.antlr.runtime.CommonTokenStream; import org.antlr.runtime.RecognitionException; import org.antlr.runtime.TokenStream; import org.antlr.runtime.tree.CommonTreeNodeStream; import org.antlr.runtime.tree.TreeNodeStream; import com.android.tools.smali.dexlib2.Opcodes; import com.android.tools.smali.dexlib2.writer.builder.DexBuilder; import com.android.tools.smali.dexlib2.writer.io.MemoryDataStore; import com.android.tools.smali.smali.SmaliOptions; import com.android.tools.smali.smali.smaliFlexLexer; import com.android.tools.smali.smali.smaliParser; import com.android.tools.smali.smali.smaliTreeWalker; /** * Utility methods to assemble smali to in-memory buffer. * This implementation uses smali library internal classes. */ public class SmaliUtils { @SuppressWarnings("ExtractMethodRecommender") public static byte[] assemble(File smaliFile, SmaliOptions options) throws IOException { StringBuilder errors = new StringBuilder(); try (FileInputStream fis = new FileInputStream(smaliFile); InputStreamReader reader = new InputStreamReader(fis, StandardCharsets.UTF_8)) { smaliFlexLexer lexer = new smaliFlexLexer(reader, options.apiLevel); lexer.setSourceFile(smaliFile); CommonTokenStream tokens = new CommonTokenStream(lexer); ParserWrapper parser = new ParserWrapper(tokens, errors); parser.setVerboseErrors(options.verboseErrors); parser.setAllowOdex(options.allowOdexOpcodes); parser.setApiLevel(options.apiLevel); ParserWrapper.smali_file_return parseResult = parser.smali_file(); if (parser.getNumberOfSyntaxErrors() > 0 || lexer.getNumberOfSyntaxErrors() > 0) { throw new RuntimeException("Smali parse error: " + errors); } CommonTreeNodeStream treeStream = new CommonTreeNodeStream(parseResult.getTree()); treeStream.setTokenStream(tokens); DexBuilder dexBuilder = new DexBuilder(Opcodes.forApi(options.apiLevel)); TreeWalkerWrapper dexGen = new TreeWalkerWrapper(treeStream, errors); dexGen.setApiLevel(options.apiLevel); dexGen.setVerboseErrors(options.verboseErrors); dexGen.setDexBuilder(dexBuilder); dexGen.smali_file(); if (dexGen.getNumberOfSyntaxErrors() > 0) { throw new RuntimeException("Smali compile error: " + errors); } MemoryDataStore dataStore = new MemoryDataStore(); dexBuilder.writeTo(dataStore); return dataStore.getData(); } catch (RecognitionException e) { throw new RuntimeException("Smali process error: " + errors, e); } } private static final class ParserWrapper extends smaliParser { private final StringBuilder errors; public ParserWrapper(TokenStream input, StringBuilder errors) { super(input); this.errors = errors; } @Override public void emitErrorMessage(String msg) { errors.append('\n').append(msg); } } private static final class TreeWalkerWrapper extends smaliTreeWalker { private final StringBuilder errors; public TreeWalkerWrapper(TreeNodeStream input, StringBuilder errors) { super(input); this.errors = errors; } @Override public void emitErrorMessage(String msg) { errors.append('\n').append(msg); } } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-smali-input/src/main/java/jadx/plugins/input/smali/SmaliInputOptions.java
jadx-plugins/jadx-smali-input/src/main/java/jadx/plugins/input/smali/SmaliInputOptions.java
package jadx.plugins.input.smali; import jadx.api.plugins.options.impl.BasePluginOptionsBuilder; public class SmaliInputOptions extends BasePluginOptionsBuilder { private int apiLevel; private int threads; // use jadx global threads count option @Override public void registerOptions() { intOption(SmaliInputPlugin.PLUGIN_ID + ".api-level") .description("Android API level") .defaultValue(27) .setter(v -> apiLevel = v); } public int getApiLevel() { return apiLevel; } public int getThreads() { return threads; } public void setThreads(int threads) { this.threads = threads; } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-smali-input/src/main/java/jadx/plugins/input/smali/SmaliConvert.java
jadx-plugins/jadx-smali-input/src/main/java/jadx/plugins/input/smali/SmaliConvert.java
package jadx.plugins.input.smali; import java.nio.file.FileSystems; import java.nio.file.Path; import java.nio.file.PathMatcher; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.android.tools.smali.smali.SmaliOptions; import jadx.plugins.input.dex.utils.IDexData; import jadx.plugins.input.dex.utils.SimpleDexData; public class SmaliConvert { private static final Logger LOG = LoggerFactory.getLogger(SmaliConvert.class); private final List<IDexData> dexData = new ArrayList<>(); public boolean execute(List<Path> input, SmaliInputOptions options) { List<Path> smaliFiles = filterSmaliFiles(input); if (smaliFiles.isEmpty()) { return false; } try { compile(smaliFiles, options); } catch (Exception e) { LOG.error("Smali process error", e); } return !dexData.isEmpty(); } @SuppressWarnings("ResultOfMethodCallIgnored") private void compile(List<Path> inputFiles, SmaliInputOptions options) { SmaliOptions smaliOptions = new SmaliOptions(); smaliOptions.apiLevel = options.getApiLevel(); smaliOptions.verboseErrors = true; smaliOptions.allowOdexOpcodes = false; smaliOptions.printTokens = false; int threads = options.getThreads(); LOG.debug("Compiling smali files: {}, threads: {}", inputFiles.size(), threads); long start = System.currentTimeMillis(); if (threads == 1 || inputFiles.size() == 1) { for (Path inputFile : inputFiles) { assemble(dexData, inputFile, smaliOptions); } } else { try { ExecutorService executor = Executors.newFixedThreadPool(threads); List<IDexData> syncList = Collections.synchronizedList(dexData); for (Path inputFile : inputFiles) { executor.execute(() -> assemble(syncList, inputFile, smaliOptions)); } executor.shutdown(); executor.awaitTermination(1, TimeUnit.HOURS); dexData.sort(Comparator.comparing(IDexData::getFileName)); } catch (InterruptedException e) { LOG.error("Smali compile interrupted", e); } } if (LOG.isDebugEnabled()) { LOG.debug("Smali compile done in: {}ms", System.currentTimeMillis() - start); } } private void assemble(List<IDexData> results, Path inputFile, SmaliOptions smaliOptions) { Path path = inputFile.toAbsolutePath(); try { byte[] dexContent = SmaliUtils.assemble(path.toFile(), smaliOptions); results.add(new SimpleDexData(path.toString(), dexContent)); } catch (Exception e) { LOG.error("Failed to assemble smali file: {}", path, e); } } private List<Path> filterSmaliFiles(List<Path> input) { PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:**.smali"); return input.stream() .filter(matcher::matches) .collect(Collectors.toList()); } public List<IDexData> getDexData() { return dexData; } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-rename-mappings/src/test/java/jadx/plugins/mappings/TestInnerClassRename.java
jadx-plugins/jadx-rename-mappings/src/test/java/jadx/plugins/mappings/TestInnerClassRename.java
package jadx.plugins.mappings; import java.util.List; import org.junit.jupiter.api.Test; import jadx.api.JadxDecompiler; import jadx.api.JavaClass; import static org.assertj.core.api.Assertions.assertThat; class TestInnerClassRename extends BaseRenameMappingsTest { @Test public void test() { testResDir = "inner-cls-rename"; jadxArgs.getInputFiles().add(loadResourceFile("base.smali")); jadxArgs.getInputFiles().add(loadResourceFile("inner.smali")); jadxArgs.setUserRenamesMappingsPath(loadResourceFile("enigma.mapping").toPath()); try (JadxDecompiler jadx = new JadxDecompiler(jadxArgs)) { jadx.load(); List<JavaClass> classes = jadx.getClasses(); printClassesCode(classes); assertThat(classes).hasSize(1); JavaClass baseCls = classes.get(0); assertThat(baseCls.getName()).isEqualTo("BaseCls"); List<JavaClass> innerClasses = baseCls.getInnerClasses(); assertThat(innerClasses).hasSize(1); assertThat(innerClasses.get(0).getName()).isEqualTo("RenamedInner"); assertThat(baseCls.getCode()).contains("class RenamedInner {"); } } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false
skylot/jadx
https://github.com/skylot/jadx/blob/7bbb58863b8a80c0b862425d2701d23be40aeae8/jadx-plugins/jadx-rename-mappings/src/test/java/jadx/plugins/mappings/BaseRenameMappingsTest.java
jadx-plugins/jadx-rename-mappings/src/test/java/jadx/plugins/mappings/BaseRenameMappingsTest.java
package jadx.plugins.mappings; import java.io.File; import java.net.URL; import java.nio.file.Path; import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.io.TempDir; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import jadx.api.JadxArgs; import jadx.api.JavaClass; import jadx.api.plugins.loader.JadxBasePluginLoader; import jadx.core.plugins.files.SingleDirFilesGetter; import static org.assertj.core.api.Assertions.assertThat; public class BaseRenameMappingsTest { private static final Logger LOG = LoggerFactory.getLogger(BaseRenameMappingsTest.class); @TempDir Path testDir; Path outputDir; JadxArgs jadxArgs; String testResDir = ""; @BeforeEach public void setUp() { outputDir = testDir.resolve("output"); jadxArgs = new JadxArgs(); jadxArgs.setOutDir(outputDir.toFile()); jadxArgs.setFilesGetter(new SingleDirFilesGetter(testDir)); jadxArgs.setPluginLoader(new JadxBasePluginLoader()); } public File loadResourceFile(String fileName) { String path = testResDir + '/' + fileName; try { URL resource = getClass().getClassLoader().getResource(path); assertThat(resource).isNotNull(); return new File(resource.getFile()); } catch (Exception e) { throw new RuntimeException("Failed to load resource file: " + path, e); } } public void printClassesCode(List<JavaClass> classes) { LOG.debug("Printing code for {} classes:", classes.size()); for (JavaClass jCls : classes) { LOG.debug("Class: {}\n{}\n---\n", jCls.getFullName(), jCls.getCode()); } } }
java
Apache-2.0
7bbb58863b8a80c0b862425d2701d23be40aeae8
2026-01-04T14:45:57.033910Z
false