use spaces instead of tabs in deodexerant

git-svn-id: https://smali.googlecode.com/svn/trunk@570 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
JesusFreke@JesusFreke.com 2010-01-24 00:54:48 +00:00
parent d27ca7f7a6
commit 41d8cd7df2

View File

@ -294,21 +294,21 @@ int dumpFields(char *classType, FILE *clientOut)
{ {
ClassObject *clazz; ClassObject *clazz;
if (classType[0] == '[') if (classType[0] == '[')
clazz = dvmFindArrayClass(classType, NULL); clazz = dvmFindArrayClass(classType, NULL);
else else
clazz = dvmFindSystemClassNoInit(classType); clazz = dvmFindSystemClassNoInit(classType);
if (clazz == NULL) if (clazz == NULL)
return 0; return 0;
int i; int i;
do do
{ {
InstField *pField = clazz->ifields; InstField *pField = clazz->ifields;
for (i=0; i<clazz->ifieldCount; i++, pField++) for (i=0; i<clazz->ifieldCount; i++, pField++)
fprintf(clientOut, "field: %d %s:%s\n", pField->byteOffset, pField->field.name, pField->field.signature); fprintf(clientOut, "field: %d %s:%s\n", pField->byteOffset, pField->field.name, pField->field.signature);
clazz = clazz->super; clazz = clazz->super;
} while (clazz != NULL); } while (clazz != NULL);
return 1; return 1;
@ -321,29 +321,29 @@ int dumpInlineMethods(FILE *clientOut)
int i; int i;
for (i=0; i<count; i++) { for (i=0; i<count; i++) {
const InlineOperation *inlineOp = &inlineTable[i]; const InlineOperation *inlineOp = &inlineTable[i];
ClassObject *clazz = dvmFindSystemClassNoInit(inlineOp->classDescriptor); ClassObject *clazz = dvmFindSystemClassNoInit(inlineOp->classDescriptor);
if (clazz == NULL) if (clazz == NULL)
return 0; return 0;
char *methodType; char *methodType;
Method *method = dvmFindDirectMethodByDescriptor(clazz, inlineOp->methodName, inlineOp->methodSignature); Method *method = dvmFindDirectMethodByDescriptor(clazz, inlineOp->methodName, inlineOp->methodSignature);
if (method == NULL) if (method == NULL)
{ {
method = dvmFindVirtualMethodByDescriptor(clazz, inlineOp->methodName, inlineOp->methodSignature); method = dvmFindVirtualMethodByDescriptor(clazz, inlineOp->methodName, inlineOp->methodSignature);
methodType = "virtual"; methodType = "virtual";
} else { } else {
if (dvmIsStaticMethod(method)) if (dvmIsStaticMethod(method))
methodType = "static"; methodType = "static";
else else
methodType = "direct"; methodType = "direct";
} }
if (method == NULL) if (method == NULL)
return 0; return 0;
fprintf(clientOut, "inline: %s %s->%s%s\n", methodType, method->clazz->descriptor, method->name, dexProtoGetMethodDescriptor(&method->prototype, &stringCache)); fprintf(clientOut, "inline: %s %s->%s%s\n", methodType, method->clazz->descriptor, method->name, dexProtoGetMethodDescriptor(&method->prototype, &stringCache));
} }
return 1; return 1;
@ -353,35 +353,35 @@ int dumpVirtualMethods(char *classType, FILE *clientOut)
{ {
ClassObject *clazz; ClassObject *clazz;
if (classType[0] == '[') if (classType[0] == '[')
clazz = dvmFindArrayClass(classType, NULL); clazz = dvmFindArrayClass(classType, NULL);
else else
clazz = dvmFindSystemClassNoInit(classType); clazz = dvmFindSystemClassNoInit(classType);
if (clazz == NULL) if (clazz == NULL)
{ {
fprintf(clientOut, "err: could not find class %s\n", classType); fprintf(clientOut, "err: could not find class %s\n", classType);
return 0; return 0;
} }
//interface classes don't have virtual methods, by definition. But it's possible //interface classes don't have virtual methods, by definition. But it's possible
//to call virtual methods defined on the Object class via an interface type //to call virtual methods defined on the Object class via an interface type
if (dvmIsInterfaceClass(clazz)) if (dvmIsInterfaceClass(clazz))
{ {
clazz = dvmFindSystemClassNoInit("Ljava/lang/Object;"); clazz = dvmFindSystemClassNoInit("Ljava/lang/Object;");
if (clazz == NULL) if (clazz == NULL)
{ {
fprintf(clientOut, "err: could not find class %s\n", classType); fprintf(clientOut, "err: could not find class %s\n", classType);
return 0; return 0;
} }
} }
int i; int i;
for (i=0; i<clazz->vtableCount; i++) for (i=0; i<clazz->vtableCount; i++)
{ {
Method *method = clazz->vtable[i]; Method *method = clazz->vtable[i];
fprintf(clientOut, "vtable: %s%s\n", method->name, fprintf(clientOut, "vtable: %s%s\n", method->name,
dexProtoGetMethodDescriptor(&method->prototype, &stringCache)); dexProtoGetMethodDescriptor(&method->prototype, &stringCache));
} }
return 1; return 1;
} }
@ -391,7 +391,7 @@ ClassObject *lookupSuperclass(char *classType)
ClassObject *clazz = dvmFindSystemClassNoInit(classType); ClassObject *clazz = dvmFindSystemClassNoInit(classType);
if (clazz == NULL) if (clazz == NULL)
return NULL; return NULL;
return clazz->super; return clazz->super;
} }
@ -410,7 +410,7 @@ int main(int argc, char* const argv[])
if (argc != 3) { if (argc != 3) {
fprintf(stderr, "deodexerant %s (Android %s)\n", VERSION, ANDROID_VERSION); fprintf(stderr, "deodexerant %s (Android %s)\n", VERSION, ANDROID_VERSION);
fprintf(stderr, "usage: deodexerant <odex_file> <port>\n"); fprintf(stderr, "usage: deodexerant <odex_file> <port>\n");
return 1; return 1;
} }
@ -419,8 +419,8 @@ int main(int argc, char* const argv[])
struct stat inputInfo; struct stat inputInfo;
if (stat(inputFileName, &inputInfo) != 0) { if (stat(inputFileName, &inputInfo) != 0) {
fprintf(stderr, "could not stat '%s' : %s\n", inputFileName, strerror(errno)); fprintf(stderr, "could not stat '%s' : %s\n", inputFileName, strerror(errno));
return 1; return 1;
} }
int odexFd = open(inputFileName, O_RDONLY); int odexFd = open(inputFileName, O_RDONLY);
@ -433,8 +433,8 @@ int main(int argc, char* const argv[])
int socketFd = socket(AF_INET, SOCK_STREAM, 0); int socketFd = socket(AF_INET, SOCK_STREAM, 0);
if (socketFd < 0) if (socketFd < 0)
{ {
fprintf(stderr, "Unable to open socket\n"); fprintf(stderr, "Unable to open socket\n");
return 1; return 1;
} }
struct sockaddr_in serverAddress, clientAddress; struct sockaddr_in serverAddress, clientAddress;
@ -444,8 +444,8 @@ int main(int argc, char* const argv[])
serverAddress.sin_port = htons(port); serverAddress.sin_port = htons(port);
if (bind(socketFd, (struct sockaddr *)&serverAddress, sizeof(serverAddress)) < 0) if (bind(socketFd, (struct sockaddr *)&serverAddress, sizeof(serverAddress)) < 0)
{ {
fprintf(stderr, "Unable to bind socket\n"); fprintf(stderr, "Unable to bind socket\n");
return 1; return 1;
} }
const char* bcp = getenv("BOOTCLASSPATH"); const char* bcp = getenv("BOOTCLASSPATH");
@ -473,10 +473,10 @@ int main(int argc, char* const argv[])
bool success; bool success;
void* mapAddr; void* mapAddr;
mapAddr = mmap(NULL, inputInfo.st_size, PROT_READ, mapAddr = mmap(NULL, inputInfo.st_size, PROT_READ,
MAP_PRIVATE, odexFd, 0); MAP_PRIVATE, odexFd, 0);
if (mapAddr == MAP_FAILED) { if (mapAddr == MAP_FAILED) {
fprintf(stderr, "unable to mmap DEX cache: %s\n", strerror(errno)); fprintf(stderr, "unable to mmap DEX cache: %s\n", strerror(errno));
return 1; return 1;
} }
if (dvmDexFileOpenPartial(mapAddr + *((int *)(mapAddr+8)), *((int *)(mapAddr+12)), &pDvmDex) != 0) { if (dvmDexFileOpenPartial(mapAddr + *((int *)(mapAddr+8)), *((int *)(mapAddr+12)), &pDvmDex) != 0) {
@ -487,7 +487,7 @@ int main(int argc, char* const argv[])
pClassLookup = dexCreateClassLookup(pDvmDex->pDexFile); pClassLookup = dexCreateClassLookup(pDvmDex->pDexFile);
if (pClassLookup == NULL) if (pClassLookup == NULL)
{ {
fprintf(stderr, "unable to create class lookup\n"); fprintf(stderr, "unable to create class lookup\n");
return 1; return 1;
} }
@ -495,7 +495,7 @@ int main(int argc, char* const argv[])
if (!loadAllClasses(pDvmDex)) if (!loadAllClasses(pDvmDex))
{ {
fprintf(stderr, "error while loading classes\n"); fprintf(stderr, "error while loading classes\n");
return 1; return 1;
} }
@ -508,22 +508,22 @@ int main(int argc, char* const argv[])
int clientFd = accept(socketFd, (struct sockaddr *) &clientAddress, &clientSocketLength); int clientFd = accept(socketFd, (struct sockaddr *) &clientAddress, &clientSocketLength);
if (clientFd < 0) if (clientFd < 0)
{ {
fprintf(stderr, "Unable to accept incomming connection\n"); fprintf(stderr, "Unable to accept incomming connection\n");
return 1; return 1;
} }
FILE *clientIn = fdopen(clientFd, "r"); FILE *clientIn = fdopen(clientFd, "r");
if (clientIn == 0) if (clientIn == 0)
{ {
fprintf(stderr, "Unable to fdopen socket to get input stream\n"); fprintf(stderr, "Unable to fdopen socket to get input stream\n");
return 1; return 1;
} }
FILE *clientOut = fdopen(dup(clientFd), "w"); FILE *clientOut = fdopen(dup(clientFd), "w");
if (clientOut == 0) if (clientOut == 0)
{ {
fprintf(stderr, "Unable to fdopen socket to get output stream\n"); fprintf(stderr, "Unable to fdopen socket to get output stream\n");
return 1; return 1;
} }
char *command = NULL; char *command = NULL;
@ -531,156 +531,156 @@ int main(int argc, char* const argv[])
dexStringCacheInit(&stringCache); dexStringCacheInit(&stringCache);
while ((command = fgetln(clientIn, &len)) != NULL) { while ((command = fgetln(clientIn, &len)) != NULL) {
while (len > 0 && (command[len-1] == '\r' || command[len-1] == '\n')) while (len > 0 && (command[len-1] == '\r' || command[len-1] == '\n'))
len--; len--;
char *buf = malloc(len+1); char *buf = malloc(len+1);
memcpy(buf, command, len); memcpy(buf, command, len);
buf[len] = 0; buf[len] = 0;
//printf("%s\n", buf); //printf("%s\n", buf);
char *cmd = strtok(buf, " "); char *cmd = strtok(buf, " ");
if (cmd == NULL) { if (cmd == NULL) {
fprintf(clientOut, "err: error interpreting command\n"); fprintf(clientOut, "err: error interpreting command\n");
fflush(clientOut); fflush(clientOut);
continue; continue;
} }
switch (cmd[0]) switch (cmd[0])
{ {
case 'F' : case 'F' :
{ {
char *classType = strtok(NULL, " "); char *classType = strtok(NULL, " ");
if (classType == NULL) if (classType == NULL)
{ {
fprintf(clientOut, "err: no classType for field lookup\n"); fprintf(clientOut, "err: no classType for field lookup\n");
fflush(clientOut); fflush(clientOut);
break; break;
} }
if (!dumpFields(classType, clientOut)) if (!dumpFields(classType, clientOut))
{ {
fprintf(clientOut, "err: error while dumping fields\n"); fprintf(clientOut, "err: error while dumping fields\n");
fflush(clientOut); fflush(clientOut);
break; break;
} }
fprintf(clientOut, "done\n"); fprintf(clientOut, "done\n");
fflush(clientOut); fflush(clientOut);
break; break;
} }
case 'I': case 'I':
{ {
if (!dumpInlineMethods(clientOut)) if (!dumpInlineMethods(clientOut))
{ {
fprintf(clientOut, "err: inline method not found\n"); fprintf(clientOut, "err: inline method not found\n");
fflush(clientOut); fflush(clientOut);
break; break;
} }
fprintf(clientOut, "done\n"); fprintf(clientOut, "done\n");
fflush(clientOut); fflush(clientOut);
break; break;
} }
case 'V': case 'V':
{ {
char *classType = strtok(NULL, " "); char *classType = strtok(NULL, " ");
if (classType == NULL) if (classType == NULL)
{ {
fprintf(clientOut, "err: no classType for vtable dump\n"); fprintf(clientOut, "err: no classType for vtable dump\n");
fflush(clientOut); fflush(clientOut);
break; break;
} }
if (!dumpVirtualMethods(classType, clientOut)) { if (!dumpVirtualMethods(classType, clientOut)) {
fprintf(clientOut, "err: error encountered while dumping virtual methods\n"); fprintf(clientOut, "err: error encountered while dumping virtual methods\n");
fflush(clientOut); fflush(clientOut);
break; break;
} }
fprintf(clientOut, "done\n"); fprintf(clientOut, "done\n");
fflush(clientOut); fflush(clientOut);
break; break;
} }
case 'P': case 'P':
{ {
char *classType = strtok(NULL, " "); char *classType = strtok(NULL, " ");
if (classType == NULL) if (classType == NULL)
{ {
fprintf(clientOut, "err: no classType for superclass lookup\n"); fprintf(clientOut, "err: no classType for superclass lookup\n");
fflush(clientOut); fflush(clientOut);
break; break;
} }
ClassObject *clazz = lookupSuperclass(classType); ClassObject *clazz = lookupSuperclass(classType);
if (clazz == NULL) if (clazz == NULL)
{ {
fprintf(clientOut, "class: \n"); fprintf(clientOut, "class: \n");
fflush(clientOut); fflush(clientOut);
break; break;
} }
fprintf(clientOut, "class: %s\n", clazz->descriptor); fprintf(clientOut, "class: %s\n", clazz->descriptor);
fflush(clientOut); fflush(clientOut);
break; break;
} }
case 'C': case 'C':
{ {
char *classType1 = strtok(NULL, " "); char *classType1 = strtok(NULL, " ");
if (classType1 == NULL) if (classType1 == NULL)
{ {
fprintf(clientOut, "err: no classType for common superclass lookup\n"); fprintf(clientOut, "err: no classType for common superclass lookup\n");
fflush(clientOut); fflush(clientOut);
break; break;
} }
ClassObject *clazz1; ClassObject *clazz1;
if (classType1[0] == '[') if (classType1[0] == '[')
clazz1 = dvmFindArrayClass(classType1, NULL); clazz1 = dvmFindArrayClass(classType1, NULL);
else else
clazz1 = dvmFindSystemClassNoInit(classType1); clazz1 = dvmFindSystemClassNoInit(classType1);
if (clazz1 == NULL) if (clazz1 == NULL)
{ {
fprintf(clientOut, "err: class %s could not be found for common superclass lookup. This can be caused if a library the odex depends on is not in the BOOTCLASSPATH environment variable\n", classType1); fprintf(clientOut, "err: class %s could not be found for common superclass lookup. This can be caused if a library the odex depends on is not in the BOOTCLASSPATH environment variable\n", classType1);
fflush(clientOut); fflush(clientOut);
break; break;
} }
char *classType2 = strtok(NULL, " "); char *classType2 = strtok(NULL, " ");
if (classType2 == NULL) if (classType2 == NULL)
{ {
fprintf(clientOut, "err: no classType for common superclass lookup\n"); fprintf(clientOut, "err: no classType for common superclass lookup\n");
fflush(clientOut); fflush(clientOut);
break; break;
} }
ClassObject *clazz2; ClassObject *clazz2;
if (classType2[0] == '[') if (classType2[0] == '[')
clazz2 = dvmFindArrayClass(classType2, NULL); clazz2 = dvmFindArrayClass(classType2, NULL);
else else
clazz2 = dvmFindSystemClassNoInit(classType2); clazz2 = dvmFindSystemClassNoInit(classType2);
if (clazz2 == NULL) if (clazz2 == NULL)
{ {
fprintf(clientOut, "err: class %s could not be found for common superclass lookup\n", classType2); fprintf(clientOut, "err: class %s could not be found for common superclass lookup\n", classType2);
fflush(clientOut); fflush(clientOut);
break; break;
} }
ClassObject *clazz = findCommonSuperclass(clazz1, clazz2); ClassObject *clazz = findCommonSuperclass(clazz1, clazz2);
fprintf(clientOut, "class: %s\n", clazz->descriptor); fprintf(clientOut, "class: %s\n", clazz->descriptor);
fflush(clientOut); fflush(clientOut);
break; break;
} }
default: default:
fprintf(clientOut, "err: not a valid command\n"); fprintf(clientOut, "err: not a valid command\n");
fflush(clientOut); fflush(clientOut);
} }
/*gettimeofday(&tv, NULL); /*gettimeofday(&tv, NULL);
printf("end %07d\n", tv.tv_usec);*/ printf("end %07d\n", tv.tv_usec);*/
} }