Monday, March 28, 2016
Saturday, March 12, 2016
Using Gradle to disassembles classes into bytecode format in a java project
apply plugin: 'java'import groovy.io.FileType repositories { mavenCentral() } dependencies { testCompile 'junit:junit:4.12' testCompile 'org.mockito:mockito-core:1.10.8' } task generateBytecode { dependsOn compileJava doLast { readClassFiles() } } private void readClassFiles() { def list = [] File srcDir = sourceSets.main.output.classesDir if (srcDir != null) { // iterate through all files in the build/classes directory srcDir.eachFileRecurse(FileType.FILES) { file -> boolean b = checkIfIsClassFile(file) if (b) { // add the file to the list if it is an class file list << file } } println 'starts generating bytecode files ... ' list.each { generateByteCodeFiles(it) } } } private boolean checkIfIsClassFile(File file) { String regex = ".*\\.class" String filename = file.getName() boolean b = filename.matches(regex); b } def generateByteCodeFiles(File file) { //execute command and get the command line output as a String def stdout = new ByteArrayOutputStream() exec { // javap -v -p -s -sysinfo -constants Subclass\$InnerClass.class commandLine "javap", "-private", "-v", "-s", file; standardOutput = stdout } String resultString = stdout.toString(); createFile(resultString, file); } def createFile(String result, File classFile) { String fname = classFile.name; // remove file name extension int pos = fname.lastIndexOf("."); if (pos > 0) { fname = fname.substring(0, pos); } // create txt files to save the result fname = fname + ".txt" File textFile = new File(project.getBuildDir().toString() + "/bytecode/" + fname); textFile.getParentFile().mkdirs(); textFile.createNewFile(); println textFile // write the output String into the file FileWriter fileWriter = new FileWriter(textFile); fileWriter.write(result); fileWriter.flush(); fileWriter.close(); }
ClassLoaders in Android SDK
~/Library/Android$ find . -name *ClassLoader*
./sdk/docs/reference/android/os/Parcelable.ClassLoaderCreator.html
./sdk/docs/reference/dalvik/system/BaseDexClassLoader.html
./sdk/docs/reference/dalvik/system/DexClassLoader.html
./sdk/docs/reference/dalvik/system/PathClassLoader.html
./sdk/docs/reference/java/lang/ClassLoader.html
./sdk/docs/reference/java/net/URLClassLoader.html
./sdk/docs/reference/java/security/SecureClassLoader.html
./sdk/sources/android-15/android/core/ClassLoaderTest.java
./sdk/sources/android-15/java/lang/ClassLoader.java
./sdk/sources/android-15/java/lang/VMClassLoader.java
./sdk/sources/android-15/java/net/URLClassLoader.java
./sdk/sources/android-15/java/security/SecureClassLoader.java
./sdk/sources/android-15/junit/runner/TestCaseClassLoader.java
./sdk/sources/android-17/java/lang/ClassLoader.java
./sdk/sources/android-17/java/lang/VMClassLoader.java
./sdk/sources/android-17/java/net/URLClassLoader.java
./sdk/sources/android-17/java/security/SecureClassLoader.java
./sdk/sources/android-17/junit/runner/TestCaseClassLoader.java
./sdk/sources/android-19/java/lang/ClassLoader.java
./sdk/sources/android-19/java/lang/VMClassLoader.java
./sdk/sources/android-19/java/net/URLClassLoader.java
./sdk/sources/android-19/java/security/SecureClassLoader.java
./sdk/sources/android-19/junit/runner/TestCaseClassLoader.java
./sdk/sources/android-20/java/lang/ClassLoader.java
./sdk/sources/android-20/java/lang/VMClassLoader.java
./sdk/sources/android-20/java/net/URLClassLoader.java
./sdk/sources/android-20/java/security/SecureClassLoader.java
./sdk/sources/android-20/junit/runner/TestCaseClassLoader.java
./sdk/sources/android-20/org/apache/harmony/tests/java/lang/ClassLoaderTest.java
./sdk/sources/android-22/java/lang/ClassLoader.java
./sdk/sources/android-22/java/lang/VMClassLoader.java
./sdk/sources/android-22/java/net/URLClassLoader.java
./sdk/sources/android-22/java/security/SecureClassLoader.java
./sdk/sources/android-22/junit/runner/TestCaseClassLoader.java
./sdk/sources/android-22/org/apache/harmony/tests/java/lang/ClassLoaderTest.java
./sdk/sources/android-23/com/android/layoutlib/bridge/intensive/setup/ModuleClassLoader.java
./sdk/sources/android-23/java/lang/ClassLoader.java
./sdk/sources/android-23/java/lang/VMClassLoader.java
./sdk/sources/android-23/java/net/URLClassLoader.java
./sdk/sources/android-23/java/security/SecureClassLoader.java
./sdk/sources/android-23/junit/runner/TestCaseClassLoader.java
./sdk/sources/android-23/org/apache/harmony/tests/java/lang/ClassLoaderTest.java
Subscribe to:
Posts (Atom)