importSwiftUIimportosimportDarwinstructMastgTest{staticfuncmastgTest(completion:@escaping(String)->Void){letfilename="secret.json"letsecret="secret_token"letfm=FileManager.defaultlettypes:[FileManager.SearchPathDirectory]=[.documentDirectory,.cachesDirectory,.libraryDirectory,.applicationSupportDirectory,]fortypeintypes{guardletdocDir=fm.urls(for:type,in:.userDomainMask).firstelse{continue}try?secret.write(to:docDir.appendingPathComponent(filename),atomically:false,encoding:.utf8)}completion("Successfully stored files to the storage")}}
constCONTAINER_PATH_LEN="/var/mobile/Containers/Data/Application/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/".lengthInterceptor.attach(Module.getGlobalExportByName("open"),{onEnter(args){letpath=args[0].readCString()if(path.indexOf("/var/mobile/Containers/Data/Application")!=-1&&((path.indexOf("tmp")!=CONTAINER_PATH_LEN&&path.indexOf("Library/Caches")!=CONTAINER_PATH_LEN))){console.log(`\nopen(${path})`);// Use an arrow function so that `this` remains the same as in onEnterconstprintBacktrace=(maxLines=8)=>{console.log("Backtrace:");letbacktrace=Thread.backtrace(this.context,Backtracer.ACCURATE).map(DebugSymbol.fromAddress);for(leti=0;i<Math.min(maxLines,backtrace.length);i++){console.log(backtrace[i]);}}printBacktrace();}}});
open(/var/mobile/Containers/Data/Application/976DB6BA-3AE8-483D-9CE7-0207049BB3B5/Documents/secret.json)Backtrace:0x19a8dfd68Foundation!_NSOpenFileDescriptor_Protected0x19a8cb884Foundation!_NSWriteDataToFileWithExtendedAttributes0x19a92336cFoundation!writeStringToURLOrPath0x19abeb294Foundation!StringProtocol.write(to:atomically:encoding:)0x104ab0418MASTestApp!specializedstaticMastgTest.mastgTest(completion:)0x104ab122cMASTestApp!closure#1 in closure #1 in closure #1 in ContentView.body.getter0x1a417e9e8SwiftUI!0x7199e8(0x18a8f29e8)0x1a417ece8SwiftUI!0x719ce8(0x18a8f2ce8)open(/var/mobile/Containers/Data/Application/976DB6BA-3AE8-483D-9CE7-0207049BB3B5/Library/secret.json)Backtrace:0x19a8dfd68Foundation!_NSOpenFileDescriptor_Protected0x19a8cb884Foundation!_NSWriteDataToFileWithExtendedAttributes0x19a92336cFoundation!writeStringToURLOrPath0x19abeb294Foundation!StringProtocol.write(to:atomically:encoding:)0x104ab0418MASTestApp!specializedstaticMastgTest.mastgTest(completion:)0x104ab122cMASTestApp!closure#1 in closure #1 in closure #1 in ContentView.body.getter0x1a417e9e8SwiftUI!0x7199e8(0x18a8f29e8)0x1a417ece8SwiftUI!0x719ce8(0x18a8f2ce8)open(/var/mobile/Containers/Data/Application/976DB6BA-3AE8-483D-9CE7-0207049BB3B5/Library/ApplicationSupport/secret.json)Backtrace:0x19a8dfd68Foundation!_NSOpenFileDescriptor_Protected0x19a8cb884Foundation!_NSWriteDataToFileWithExtendedAttributes0x19a92336cFoundation!writeStringToURLOrPath0x19abeb294Foundation!StringProtocol.write(to:atomically:encoding:)0x104ab0418MASTestApp!specializedstaticMastgTest.mastgTest(completion:)0x104ab122cMASTestApp!closure#1 in closure #1 in closure #1 in ContentView.body.getter0x1a417e9e8SwiftUI!0x7199e8(0x18a8f29e8)0x1a417ece8SwiftUI!0x719ce8(0x18a8f2ce8)
The output contains all calls to open including the paths of the files being accessed and backtraces. In this case the app is writing a file named secret.json to multiple locations.