Yeah, I was looking for an alternative way of figuring that out, e.g. when you only have the pointer itself but not the code. It looks like region type (in vmmap) is a good indicator:
// C:
const char data[] = { ... } // __TEXT
char data[] = {...} // __DATA
// Swift:
var data = (42, 24, ... ) // __DATA
Changing the above Swift's "var data" to "let" doesn't place the bytes in a readonly memory unlike what happens in C.
let bytes: (B, B, B, B, B, B, B, B, B, B, B, B, B, B, B, B) = (
0x86, 0x73, 0xF1, 0xDE, 0x63, 0x19, 0x50, 0x27, 0x66, 0x39, 0x72, 0x04, 0x58, 0x29, 0x32, 0x46
)
let f = findBytes() // this searches app memory for the above byte pattern
let ptr = UnsafeMutablePointer<UInt8>(bitPattern: f)!
print(String(bytes.2, radix: 0x10)) // f1
ptr[2] = 0x42 // no crash here compared to C
print(String(bytes.2, radix: 0x10)) // 42