author : xingjun.xyf
 *  contact file time desc import { DMLog } from "./dmlog" ; import { AntiIOS } from "./ios/AntiIOS" ; export namespace FCiOS { export const anti = AntiIOS ; export let nil = ObjC . available ? new ObjC . Object ( ptr ( "0x0" ) ) : null ; export function getFuncAddr ( pattern ) { var tag = 'getFuncAddr' ; let targets = FCiOS . findAllByPattern ( pattern ) ; var targetAddr = NULL ; targets . forEach ( function ( target ) { DMLog . d ( tag , 'target.name: ' + target . name + ', target.address: ' + target . address ) ; targetAddr = target . address ; return false ; } ) ; return targetAddr ; } export function findAllByPattern ( pattern ) { var tag = 'findAllByPattern' ; var type = ( pattern . indexOf ( " " ) === - 1 ) ? "module" : "objc" ; DMLog . d ( tag , 'getFuncAddr type: ' + type ) ; var res = new ApiResolver ( type ) ; DMLog . d ( tag , 'getFuncAddr ApiResolver: ' + JSON . stringify ( res ) ) ; var matches = res . enumerateMatches ( pattern ) ; DMLog . d ( tag , 'getFuncAddr matches: ' + JSON . stringify ( matches ) ) ; var targets = uniqBy ( matches , JSON . stringify ) ; return targets ; } export function uniqBy ( array , key ) { var seen = { } ; return array . filter ( function ( item ) { var k = key ( item ) ; return seen . hasOwnProperty ( k ) ? false : ( seen [ k ] = true ) ; } ) ; } export function showStacks ( thiz ) { DMLog . i ( 'showStacks' , '\tBacktrace:\n\t' + Thread . backtrace ( thiz . context , Backtracer . ACCURATE ) . map ( DebugSymbol . fromAddress ) . join ( '\n\t' ) ) ; } export function dump_ui ( ) { try { var current_window = ObjC . classes . UIWindow . keyWindow ( ) ; return current_window . recursiveDescription ( ) . toString ( ) ; } catch ( e ) { return e ; } } /**
     * trace openURL
     */ export function trace_url ( ) { var openURL = ObjC . classes . UIApplication [ "- openURL:" ] ; Interceptor . attach ( openURL . implementation , { onEnter : function ( args ) { var myNSURL = new ObjC . Object ( args [ 2 ] ) ; var myJSURL = myNSURL . absoluteString ( ) . toString ( ) ; DMLog . d ( 'openURL' , "Launching URL: " + myJSURL ) ; } } ) ; } export function trace_NSLog ( ) { const NSLog_ptr = Module . findExportByName ( "Foundation" , "NSLog" ) ; DMLog . i ( 'NSLog_ptr' , 'addr: ' + NSLog_ptr ) ; if ( NSLog_ptr ) { Interceptor . attach ( NSLog_ptr , { onEnter : function ( args ) { DMLog . d ( 'NSLog' , new ObjC . Object ( args [ 0 ] ) . toString ( ) ) ; } } ) ; } const NSLogv_ptr = Module . findExportByName ( "Foundation" , "NSLogv" ) ; DMLog . i ( 'NSLogv_ptr' , 'addr: ' + NSLogv_ptr ) ; if ( NSLogv_ptr ) { Interceptor . attach ( NSLogv_ptr , { onEnter : function ( args ) { DMLog . d ( 'NSLogv' , new ObjC . Object ( args [ 0 ] ) . toString ( ) ) ; } } ) ; } } param val export function newString ( val ) { try { return ObjC . classes . NSString . stringWithString_ ( val ) ; } catch ( e ) { return val ; } } export function getClassName ( id ) { return new ObjC . Object ( id ) . $className ; } export function printNSDictionary ( id ) { var dict = new ObjC . Object ( id ) ; var enumerator = dict . keyEnumerator ( ) ; var key ; while ( ( key = enumerator . nextObject ( ) ) !== null ) { var value = dict . objectForKey_ ( key ) ; DMLog . d ( 'printNSDictionary' , "key: " + key + ", val: " + value ) ; } } export function justTouch ( pattern ) { let tgtarr ; tgtarr = FCiOS . findAllByPattern ( pattern ) ; tgtarr . forEach ( function ( target ) { DMLog . d ( 'justTouch' , `${ target . name } attach ed` ) ; Interceptor . attach ( target . address , { onEnter : function ( args ) { DMLog . d ( 'justTouch' , `==== name: ${ target . name } onEnter ====` ) ; } } ) ; } ) ; } }