(clazzes: string[], clsWhitelist?: null | any, stackFilter?: null | string)
| 453 | * @param stackFilter |
| 454 | */ |
| 455 | export function traceJavaMethods_custom(clazzes: string[], clsWhitelist?: null | any, stackFilter?: null | string) { |
| 456 | |
| 457 | function match(destCls: string, curClsName: string) { |
| 458 | let mode = destCls[0]; |
| 459 | let ex = destCls.substr(2); |
| 460 | if (mode == 'E') { |
| 461 | return ex == curClsName; |
| 462 | } |
| 463 | else { |
| 464 | return curClsName.match(ex); |
| 465 | } |
| 466 | } |
| 467 | |
| 468 | function sendContent(obj: any) { |
| 469 | let str = JSON.stringify(obj); |
| 470 | let stacks = null; |
| 471 | if (null != stackFilter && str.indexOf(stackFilter) > -1) { |
| 472 | stacks = getStacks(); |
| 473 | obj['stacks'] = stacks; |
| 474 | if (false == firstdiscovery) { |
| 475 | obj['firstdiscovery'] = true; |
| 476 | firstdiscovery = true; |
| 477 | } |
| 478 | str = JSON.stringify(obj); |
| 479 | } |
| 480 | send(str); |
| 481 | } |
| 482 | |
| 483 | function getMethodDescription(clsname: string, overload: any) { |
| 484 | // @ts-ignore |
| 485 | let argumentTypes = overload.argumentTypes.map(val => val.className).toString(); |
| 486 | let desc = `${overload.returnType.className} ${clsname}#${overload.methodName}(${argumentTypes})`; |
| 487 | return desc; |
| 488 | } |
| 489 | |
| 490 | function traceJavaMethodsCore(clsname: string) { |
| 491 | const tag = 'traceJavaMethodsCore'; |
| 492 | let detail: { methods: string | any[]; white: boolean; } | null = null; |
| 493 | if (null != clsWhitelist) { |
| 494 | detail = clsWhitelist[clsname]; |
| 495 | } |
| 496 | let cls = Java.use(clsname); |
| 497 | let methods = cls.class.getDeclaredMethods(); |
| 498 | DMLog.i(tag, 'trace cls: ' + clsname + ', method size: ' + methods.length); |
| 499 | methods.forEach(function (method: any) { |
| 500 | let methodName = method.getName(); |
| 501 | // DMLog.i('traceJavaMethodsCore.methodname', methodName); |
| 502 | if (null != detail && typeof (detail) == 'object') { |
| 503 | if ((detail.methods.indexOf(methodName) > -1) != detail.white) { |
| 504 | return true; // next forEach |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | if ('invoke' == methodName) { |
| 509 | return true; // 跳过并继续执行下一个 forEach |
| 510 | } |
| 511 | let methodOverloads = cls[methodName].overloads; |
| 512 | if (null != methodOverloads) { |
no test coverage detected