Hello,
I found these three structures in the taintrdoid source code and I want to
know :
- what is the role of each structure and how to handle exeption in
android?
- Where can I find the stored exceptions associated to a given
methode?
- Where the declared_exceptions associated to a methode are stored?
- And where the catches are stored ?
For example in the getCaughtExceptionType it has 2 for loop (what is the
role of each loop)?
*typedef struct DexTry* {
u4 startAddr; /* start address, in 16-bit code units */
u2 insnCount; /* instruction count, in 16-bit code units
*/
u2 handlerOff; /* offset in encoded handler data to
handlers */
} DexTry;
*typedef struct DexCatchHandler* {
u4 typeIdx; /* type index of the caught exception type
*/
u4 address; /* handler address */
} DexCatchHandler;
*typedef struct DexCatchIterator* {
const u1* pEncodedData;
bool catchesAll;
u4 countRemaining;
DexCatchHandler handler;
} DexCatchIterator;
/*
* For the "move-exception" instruction at "insnIdx", which must be at an
* exception handler address, determine the first common superclass of
* all exceptions that can land here. (For javac output, we're probably
* looking at multiple spans of bytecode covered by one "try" that lands
* at an exception-specific "catch", but in general the handler could be
* shared for multiple exceptions.)
*
* Returns NULL if no matching exception handler can be found, or if the
* exception is not a subclass of Throwable.
*/
*static ClassObject* getCaughtExceptionType*(const Method* meth, int
insnIdx,
VerifyError* pFailure)
{
VerifyError localFailure;
const DexCode* pCode;
DexFile* pDexFile;
ClassObject* commonSuper = NULL;
bool foundPossibleHandler = false;
u4 handlersSize;
u4 offset;
u4 i;
pDexFile = meth->clazz->pDvmDex->
pDexFile;
pCode = dvmGetMethodCode(meth);
if (pCode->triesSize != 0) {
handlersSize = dexGetHandlersSize(pCode);
offset = dexGetFirstHandlerOffset(pCode);
} else {
handlersSize = 0;
offset = 0;
}
* for (i = 0; i < handlersSize; i++) {
* DexCatchIterator iterator;
dexCatchIteratorInit(&iterator, pCode, offset);//Initialize a
DexCatchIterator to a particular handler offset
* for (;;) {*
const DexCatchHandler* handler =
dexCatchIteratorNext(&iterator);/* Get the next item from a
DexCatchIterator. Returns NULL if at end. */
if (handler == NULL) {
break;
}
if (handler->address == (u4) insnIdx) {
ClassObject* clazz;
foundPossibleHandler = true;
if (handler->typeIdx == kDexNoIndex)
clazz = gDvm.classJavaLangThrowable;
else
clazz = dvmOptResolveClass(meth->clazz,
handler->typeIdx,
&localFailure);
if (clazz == NULL) {
LOG_VFY("VFY: unable to resolve exception class %u
(%s)\n",
handler->typeIdx,
dexStringByTypeIdx(pDexFile, handler->typeIdx));
/* TODO: do we want to keep going? If we don't fail
* this we run the risk of having a non-Throwable
* introduced at runtime. However, that won't pass
* an instanceof test, so is essentially harmless. */
} else {
if (commonSuper == NULL)
commonSuper = clazz;
else
commonSuper = findCommonSuperclass(clazz,
commonSuper);//Find the first common superclass of the two classes
}
}
}
offset = dexCatchIteratorGetEndOffset(&iterator, pCode);/* Get the
handler offset just past the end of the one just iterated over.
* This ends the iteration if it wasn't already. */
}
if (commonSuper == NULL) {
/* no catch blocks, or no catches with classes we can find */
LOG_VFY_METH(meth,
"VFY: unable to find exception handler at addr 0x%x\n",
insnIdx);
*pFailure = VERIFY_ERROR_GENERIC;
} else {
// TODO: verify the class is an instance of Throwable?
}
return commonSuper;
}
thank you
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en