Remove deodexerant and related functionality

git-svn-id: https://smali.googlecode.com/svn/trunk@797 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
JesusFreke@JesusFreke.com
2010-12-21 17:33:20 +00:00
parent b3ba356d94
commit b9a19bf3f1
7 changed files with 0 additions and 1211 deletions

View File

@ -1212,79 +1212,4 @@ public class ClassPath {
return null;
}
}
public static void validateAgainstDeodexerant(String host, int port, int skipClasses) {
Deodexerant deodexerant = new Deodexerant(host, port);
int count = 0;
try {
String[] inlineMethods = deodexerant.getInlineMethods();
(new DeodexUtil(null)).checkInlineMethods(inlineMethods);
} catch (Exception ex) {
throw ExceptionWithContext.withContext(ex, "Error while checking inline methods");
}
try {
for (ClassDef classDef: theClassPath.classDefs.values()) {
if (count < skipClasses) {
count++;
continue;
}
if ((count%1000)==0) {
System.out.println(count);
}
if (classDef instanceof UnresolvedClassDef || classDef instanceof ArrayClassDef ||
classDef instanceof PrimitiveClassDef) {
continue;
}
String[] vtable = deodexerant.getVirtualMethods(classDef.classType);
if (vtable.length != classDef.vtable.length) {
throw new ValidationException(String.format("virtual table size mismatch for class %s",
classDef.classType));
}
for (int i=0; i<classDef.vtable.length; i++) {
if (!classDef.vtable[i].equals(vtable[i])) {
throw new ValidationException(String.format("virtual method mismatch for class %s at index %d",
classDef.classType, i));
}
}
String[] fields = deodexerant.getInstanceFields(classDef.classType);
if (fields.length != classDef.instanceFields.size()) {
throw new ValidationException(String.format("field count mismatch for class %s",
classDef.classType));
}
for (int i=0; i<classDef.instanceFields.size(); i++) {
String[] fieldValues = fields[i].split(" ");
if (fieldValues.length != 2) {
throw new ValidationException("Could not parse field");
}
int fieldOffset = Integer.parseInt(fieldValues[0]);
String field = classDef.instanceFields.get(fieldOffset);
if (field == null) {
throw new ValidationException("Could not find a field at the given offset");
}
if (!field.equals(fieldValues[1])) {
throw new ValidationException(String.format("field offset mismatch for class %s at index %d",
classDef.classType, i));
}
}
count++;
}
} catch (Exception ex) {
throw ExceptionWithContext.withContext(ex, String.format("Error while checking class #%d", count));
}
}
}

View File

@ -288,49 +288,6 @@ public class DeodexUtil {
return null;
}
/**
* Compare the inline methods that we have against the given set of inline methods from deodexerant.
* We want to make sure that each inline method in inlineMethods matches the method we have at the same
* index. We may have more inline methods than we are given in inlineMethods - this shouldn't be a problem.
* Newer versions of dalvik add additional inline methods, but (so far) have changed any existing ones.
*
* If anything doesn't look right, we just throw an exception
* @param inlineMethods the inline methods from deodexerant
*/
protected void checkInlineMethods(String[] inlineMethods) {
if (inlineMethods.length > this.inlineMethods.length) {
throw new ValidationException("Inline method count mismatch");
}
for (int i=0; i<inlineMethods.length; i++) {
String inlineMethod = inlineMethods[i];
int methodType;
if (inlineMethod.startsWith("static")) {
methodType = Static;
inlineMethod = inlineMethod.substring(7);
} else if (inlineMethod.startsWith("direct")) {
methodType = Direct;
inlineMethod = inlineMethod.substring(7);
} else if (inlineMethod.startsWith("virtual")) {
methodType = Virtual;
inlineMethod = inlineMethod.substring(8);
} else {
throw new ValidationException("Could not parse inline method");
}
if (!inlineMethod.equals(this.inlineMethods[i].getMethodString())) {
throw new ValidationException(String.format("Inline method mismatch. %s vs. %s", inlineMethod,
this.inlineMethods[i].getMethodString()));
}
if (methodType != this.inlineMethods[i].methodType) {
throw new ValidationException(String.format("Inline method type mismatch. %d vs. %d", methodType,
this.inlineMethods[i].methodType));
}
}
}
public class InlineMethod {
public final int methodType;
public final String classType;

View File

@ -1,138 +0,0 @@
/*
* [The "BSD licence"]
* Copyright (c) 2010 Ben Gruver (JesusFreke)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jf.dexlib.Code.Analysis;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.ArrayList;
/**
* This class handles communication with the deodexerant helper binary,
* as well as caching the results of any deodexerant lookups
*/
public class Deodexerant {
private final String host;
private final int port;
private Socket socket = null;
private PrintWriter out = null;
private BufferedReader in = null;
public Deodexerant(String host, int port) {
this.host = host;
this.port = port;
}
public String[] getInlineMethods() {
return sendMultilineCommand("I");
}
public String[] getVirtualMethods(String classType) {
return sendMultilineCommand(String.format("V %s", classType));
}
public String[] getInstanceFields(String classType) {
return sendMultilineCommand(String.format("F %s", classType));
}
private String sendCommand(String cmd) {
try {
connectIfNeeded();
out.println(cmd);
out.flush();
String response = in.readLine();
if (response.startsWith("err")) {
String error = response.substring(5);
throw new RuntimeException(error);
}
return response;
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
//The command is still just a single line, but we're expecting a multi-line
//response. The repsonse is considered finished when a line starting with "err"
//or with "done" is encountered
private String[] sendMultilineCommand(String cmd) {
try {
connectIfNeeded();
out.println(cmd);
out.flush();
ArrayList<String> responseLines = new ArrayList<String>();
String response = in.readLine();
if (response == null) {
throw new RuntimeException("Error talking to deodexerant");
}
while (!response.startsWith("done"))
{
if (response.startsWith("err")) {
throw new RuntimeException(response.substring(5));
}
int pos = response.indexOf(':') + 1;
responseLines.add(response.substring(pos+1));
response = in.readLine();
}
String[] lines = new String[responseLines.size()];
for (int i=0; i<lines.length; i++) {
lines[i] = responseLines.get(i);
}
return lines;
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
private void connectIfNeeded() {
try {
if (socket != null) {
return;
}
socket = new Socket(host, port);
out = new PrintWriter(socket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
}