change the field lookup to a field dump, and the inline method lookup to an inline method dump

git-svn-id: https://smali.googlecode.com/svn/trunk@444 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
JesusFreke@JesusFreke.com 2009-09-08 23:05:53 +00:00
parent 6fa95185b7
commit e6e9569227

View File

@ -285,7 +285,7 @@ int loadAllClasses(DvmDex* pDvmDex)
return true; return true;
} }
Field *lookupField(char *classType, int offset) int dumpFields(char *classType, FILE *clientOut)
{ {
ClassObject *clazz; ClassObject *clazz;
if (classType[0] == '[') if (classType[0] == '[')
@ -294,44 +294,54 @@ Field *lookupField(char *classType, int offset)
clazz = dvmFindSystemClassNoInit(classType); clazz = dvmFindSystemClassNoInit(classType);
if (clazz == NULL) if (clazz == NULL)
return NULL; 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);
if (pField->byteOffset == offset)
return &pField->field;
}
clazz = clazz->super; clazz = clazz->super;
} while (clazz != NULL); } while (clazz != NULL);
return NULL; return 1;
} }
Method *lookupInlineMethod(int index) int dumpInlineMethods(FILE *clientOut)
{ {
const InlineOperation *inlineTable = dvmGetInlineOpsTable(); const InlineOperation *inlineTable = dvmGetInlineOpsTable();
int count = dvmGetInlineOpsTableLength(); int count = dvmGetInlineOpsTableLength();
if (index >= count) int i;
return NULL; for (i=0; i<count; i++) {
const InlineOperation *inlineOp = &inlineTable[i];
const InlineOperation *inlineOp = &inlineTable[index];
ClassObject *clazz = dvmFindSystemClassNoInit(inlineOp->classDescriptor); ClassObject *clazz = dvmFindSystemClassNoInit(inlineOp->classDescriptor);
if (clazz == NULL) if (clazz == NULL)
return NULL; return 0;
char *methodType;
Method *method = dvmFindDirectMethodByDescriptor(clazz, inlineOp->methodName, inlineOp->methodSignature); Method *method = dvmFindDirectMethodByDescriptor(clazz, inlineOp->methodName, inlineOp->methodSignature);
if (method != NULL) if (method == NULL)
return method; {
method = dvmFindVirtualMethodByDescriptor(clazz, inlineOp->methodName, inlineOp->methodSignature); method = dvmFindVirtualMethodByDescriptor(clazz, inlineOp->methodName, inlineOp->methodSignature);
return method; methodType = "virtual";
} else {
if (dvmIsStaticMethod(method))
methodType = "static";
else
methodType = "direct";
}
if (method == NULL)
return 0;
fprintf(clientOut, "inline: %s %s->%s%s\n", methodType, method->clazz->descriptor, method->name, dexProtoGetMethodDescriptor(&method->prototype, &stringCache));
}
return 1;
} }
int dumpVirtualMethods(char *classType, FILE *clientOut) int dumpVirtualMethods(char *classType, FILE *clientOut)
@ -371,27 +381,6 @@ int dumpVirtualMethods(char *classType, FILE *clientOut)
return 1; return 1;
} }
Method *lookupSuperMethod(char *classType, int index, ClassObject **clazz)
{
if (classType[0] == '[')
*clazz = dvmFindArrayClass(classType, NULL);
else
*clazz = dvmFindSystemClassNoInit(classType);
if (*clazz == NULL)
return NULL;
*clazz = (*clazz)->super;
if (*clazz == NULL)
return NULL;
if (index >= (*clazz)->vtableCount)
return NULL;
Method *method = (*clazz)->vtable[index];
return method;
}
ClassObject *lookupSuperclass(char *classType) ClassObject *lookupSuperclass(char *classType)
{ {
ClassObject *clazz = dvmFindSystemClassNoInit(classType); ClassObject *clazz = dvmFindSystemClassNoInit(classType);
@ -563,71 +552,27 @@ int main(int argc, char* const argv[])
break; break;
} }
char *offsetStr = strtok(NULL, " "); if (!dumpFields(classType, clientOut))
if (offsetStr == NULL)
{ {
fprintf(clientOut, "err: no offset for field lookup\n"); fprintf(clientOut, "err: error while dumping fields\n");
fflush(clientOut); fflush(clientOut);
break; break;
} }
char *end; fprintf(clientOut, "done\n");
int offset = strtol(offsetStr, &end, 10);
if (*end != '\0')
{
fprintf(clientOut, "err: offset not a valid number for field lookup\n");
fflush(clientOut);
break;
}
Field *field = lookupField(classType, offset);
if (field == NULL)
{
fprintf(clientOut, "err: field not found\n");
fflush(clientOut);
break;
}
fprintf(clientOut, "field: %s->%s:%s\n", classType, field->name, field->signature);
fflush(clientOut); fflush(clientOut);
break; break;
} }
case 'I': case 'I':
{ {
char *indexStr = strtok(NULL, " "); if (!dumpInlineMethods(clientOut))
if (indexStr == NULL)
{
fprintf(clientOut, "err: no index for inline method lookup\n");
fflush(clientOut);
break;
}
char *end;
int index = strtol(indexStr, &end, 10);
if (*end != '\0')
{
fprintf(clientOut, "err: index not a valid number for inline method lookup\n");
fflush(clientOut);
break;
}
Method *method = lookupInlineMethod(index);
if (method == NULL)
{ {
fprintf(clientOut, "err: inline method not found\n"); fprintf(clientOut, "err: inline method not found\n");
fflush(clientOut); fflush(clientOut);
break; break;
} }
char *methodType; fprintf(clientOut, "done\n");
if (dvmIsStaticMethod(method))
methodType = "static";
else if (dvmIsDirectMethod(method))
methodType = "direct";
else
methodType = "virtual";
fprintf(clientOut, "%s method: %s->%s%s\n", methodType, method->clazz->descriptor, method->name, dexProtoGetMethodDescriptor(&method->prototype, &stringCache));
fflush(clientOut); fflush(clientOut);
break; break;
} }
@ -651,46 +596,6 @@ int main(int argc, char* const argv[])
fflush(clientOut); fflush(clientOut);
break; break;
} }
case 'S':
{
char *classType = strtok(NULL, " ");
if (classType == NULL)
{
fprintf(clientOut, "err: no classType for super method lookup\n");
fflush(clientOut);
break;
}
char *indexStr = strtok(NULL, " ");
if (indexStr == NULL)
{
fprintf(clientOut, "err: no vtable index for super method lookup\n");
fflush(clientOut);
break;
}
char *end;
int index = strtol(indexStr, &end, 10);
if (*end != '\0')
{
fprintf(clientOut, "err: vtable index not a valid number for super method lookup\n");
fflush(clientOut);
break;
}
ClassObject *clazz;
Method *method = lookupSuperMethod(classType, index, &clazz);
if (method == NULL)
{
fprintf(clientOut, "err: method not found\n");
fflush(clientOut);
break;
}
fprintf(clientOut, "method: %s->%s%s\n", clazz->descriptor, method->name, dexProtoGetMethodDescriptor(&method->prototype, &stringCache));
fflush(clientOut);
break;
}
case 'P': case 'P':
{ {
char *classType = strtok(NULL, " "); char *classType = strtok(NULL, " ");