#

# Disarm pattern matcher file.

#

# This was originally used by me for jtool2's joker module (my kernel symbolicator). It proved

# far more scalable and extensible than hard coding the rules into jtool2, opening up the way

# for this to be used for any binary, not just the kernelcaches.

#

# jtool2 is no longer supported by me, but disarm (effectively, jtool3, I guess), meets all of 

# its predecessor's abilities, and adds many more - and so this is now a core part of it.

# 

# Syntax is intentionally kept simple:

#

# arg#|pattern|function_this_is_called_in|calling_function|Anything from this point is ignored

#

# where:

# 

#  - arg# = 0,1,2, or 3 only

#

#  - pattern = any partial but exact (from beginning) match. And, no, it can't have a '|' in it..

#  

#  - function_this_is_called_in = the containing function, NOT the calling function

#  calling_function (optional) = function whose argument this is

#

#  - The calling function = is optional, because many times you will have identified it already

#  since it gets called alot (e.g. OSKextLog, strcmp, panic etc).

#

#  # is a comment, obviously

#

# Usage is even simpler:  

# 

# JMATCHERS=/path/to/this/file disarm file  (no need to --analyze)

#

# and then use generated companion file. Using the companion file will speed up processing, since analysis

# can be at times slow.

#

# Using JMD=1 will provide matcher statistics, so you can see which matchers have grown stale

#

# Find the official manual for disarm - and a new book on Darwin and Linux/Android debugging -

# (and maybe buy the book? That not only supports me, but gets you a good reference :-)

#

# https://NewDebuggingBook.com/

# 

# LICENSE:         

# 

#          FREE TO USE (AISE, who I'm sure will find it useful ;-) 

#          **BUT** PLEASE GIVE CREDIT IF YOU FIND THIS USEFUL.

#

#          IDA's "Lumina" and other "community databases" or some productz have long been fed by jtool2 - and that's 

#          perfectly fine, but please give credit where due - and spread the word of disarm, the newosxbook.com books 

#          and tools and get other people to use/read them, and hopefully find them useful.

#

#    IDA/Ghidra/Binary Ninja/Radare/ipsw etc. - if you're reading this and thinking of incorporating similar 

#          functionality into your own engine - please do! Adhering to this matcher file format convention would

#   be greatly appreciated, since this will enable users to tap this functionality in a tool agnostic manner!

#

#          Lastly - please consider sharing your matchers, if they work for you, leaving this LICENSE comment intact.

#

# (If disarm rejects this file, please download latest version, since this license may be amended over time)

# 

# Start from here

# ----------------

#

0|%s: unsupported entry, bind: %d|_sptm_fixup|_panics_sptm|

0|Assertion failed:|_assertion_failed|_panics_sptm|

0|Security assertion|_security_assertion_failed|_

0|%s: retyping from XNU_IOMMU but not to XNU_DEFAULT|_uat_retype_out|_panics_sptm|

0|%s: UAT FW alias detected for physical page: %p|_sapt_uat_map_default_deny|_panics_sptm

0|%s: new type not XNU_IOMMU|_uat_retype_in|_panics_sptm

0|%s: State objects exhausted for IOMMU %s with ID %d|_iommu_bootstrap_alloc_instance|_panics_sptm

0|%s: [SPTM]: somehow a violation was triggered in early bo|_env_violation|_panics_sptm

0|%s: Could not get devicetree|_uat_is_enabled|_panics_sptm

0|%s: Offset into scratch page crosses pa|_copy_array_to_scratch|_panics_sptm

0|%s: tried registering the same dispatch table|_register_sptm_iommu_dispatch_table|_panics_sptm

0|%s: Error obtaining CPU node|_sptm_register_cpu|_panics_sptm

0|%s: Number of supported PAPT ranges has been exhausted|_sptm_slide_region|_panics_sptm

## ORDER MATTERS for these:

0|%s: PAPT PTE could not be reached %p|_bootstrap_unmap_page|_panics_sptm

0|%s: PAPT PTE could not be reached %p|_bootstrap_map_region|_panics_sptm

0|%s: PAPT PTE could not be reached %p|_cpu_temp_aperture_map|_panics_sptm

0|%s: PAPT PTE could not be reached %p|_cpu_temp_aperture_unmap|_panics_sptm

0|%s: Unsupported cacheattr_index %u from retype_in for incoming ty|_sptm_retype|_panics_sptm

0|%s: Shared region ID does not exist|_cpu_root_table_retype_out|_panics_sptm

0|%s: invalid cache attribute index found while updati|_papt_update_mapping|_panics_sptm

0|%s: %s at pc 0x%016llx|_panic_with_register_state|_panics_sptm

0|%s: Corrupted unmap_data, current segment grea|_uat_validate_unmap_segment|_panics_spam

0|%s: DeviceTree PAPT range not found|_sptm_init_parse_io_space|_panics_sptm

0|%s: Context ID not set despite cache flush may|_sptm_uat_unmap_continue|_panics_sptm

0|%s: unsupported TLBI flav|_sptm_broadcast_tlbi|_panics_sptm

0|%s: Not enough SK entropy|_sptm_init|_panics_sptm

0|%s: error %d looking up chosen/memory-map|_init_dt|_panics_sptm

0|%s: dart %p (%s:%u): Number of %s props|_t8110_bootstrap_preconfig_exception_sid|_panics_sptm

0|%s: Non-zero root tabl|_sptm_uat_init_state|_panics_sptm

0|%s: pmap-max-asids DT property is not |_sptm_bootstrap_late|_panics_sptm

0|%s: IOMMU "%s" bootstrap failur|_iommu_init_driver|_panics_sptm

0|%s: wrong frame type for page tables|_bootstrap_expand_page_tables|_panics_sptm

0|%s: invalid state transition - no action set for t|_dispatch_state_machine|_panics_sptm

0|%s: IOMMU %s with id %d attempted to release unexpected frame %p|_iommu_frame_release|_panics_sptm

0|%s: CTRR-C already locked|_ctrr_lock_sptm|_panics_sptm

0|%s: ANS invalidation failed with state|_sptm_nvme_unmap_pages|_panics_sptm

0|%s: seg_cnt %x is too small for unalig|_sptm_nvme_map_pages|_panics_sptm

0|%s: IOQA doesnt match the previously cached value|sptm_nvme_bar_ioqa_reg|_panics_sptm

0|NVMe|nvme_bootstrap|_iommu_bootstrap_alloc_instance|

0|%s: /chosen/lock-regs not found|_ctrr_dt_get_lock_group|_panics_sptm

0|%s: invalid flag found while updating PAPT mapping %u|_papt_update_mapping|_panics_sptm

0|%s: Unable to locate matching range for register range |_sptm_iommu_reg_base|_panics_sptm

0|%s: random-seed|_copy_and_clear_random_seed|_panics_sptm

0|%s: unsupported TLBI flavor|_sptm_broadcast_tlbi|_panics_sptm

0|%s: (range %s): Required PAPT range has no mappings.|_bootstrap_register_papt_ranges|_panics_sptm

0|%s: Invalid new type|_bootstrap_retype_papt_range|_panics_sptm

0|%s: papt_to_phys(0) encounter|_papt_to_phys|_panics_sptm

0|%s: Attempted a TLB Invalidate by ASID on a UAT|_sptm_uat_remove_ctx_id|_panics_sptm

0|%s: %d is not a valid UAT state object type when g|_sptm_uat_set_ctx_id|_panics_sptm

0|%s: %d is not a valid UAT state object type when g|_sptm_uat_get_root_table_paddr|_panics_sptm

0|%s: error %d looking up image regio|_init_get_image_region|_panics_sptm

0|%s: Parent page table has a zero refcnt|_sptm_uat_unmap_table|_panics_sptm

0|%s: Error initializing DT |_sptm_register_cpu|_panics_sptm

0|%s: dart %p (%s:%u): Flush Unlock not supported|_t8110dart_tlb_flush_unlock|_panics_sptm

0|%s: Frame has been left untyped d|_init_txm_bootstrap_complete|_panics_sptm

0|%s: dart %p (%s:%u): Per-SID|_t8110_bootstrap_sid|_panics_sptm

0|%s: dart %p (%s:%u): power down not permitted as|_sptm_t8110dart_powerdown|_panics_sptm

0|%s: dart %p (%s:%u): DART instance %u uses dual-vc-llt-workaround, but has no APF|_t8110_dart_init_instance|_panics_sptm

0|%s: dart %p (%s:%u): DART instance %u SID %u invalid translation setting|_t8110dart_verify_bypass|_panics_sptm

0|%s: dart %p (%s:%u): Invalid poller type %d|_t8110_dart_poll|_panics_sptm

0|stack check fail|_stack_chk_fail|_panics_sptm

0|%s: dart %p (%s:%u): SID %u TZ Dead Page only permitted in 3 lev|_t8110dart_validate_carveout_table|_panics_sptm

0|%s: Caller domain exceeds array dimensions %d|_sptm_register_dispatch_table|_panics_sptm

0|%s: xnu_exc_return_handler not registered|_handle_exception_action|_panics_sptm

0|%s: no matching pmap-io-filters entry found|_sptm_iofilter_protected_write|_panics_sptm

0|%s: Found non-page table frame during a page table wal|_get_ptep|_panics_sptm

0|%s: Invalid SART version %d from EDT|_sart_bootstrap|_panics_sptm

0|%s: Exceeded available number of xnu CTRR-pro|_bootstrap_alloc_frames|_panics_sptm

0|%s: Called with [num_frames] of zer|_bootstrap_retype_frames|_panics_sptm

0|%s: () No PAPT ranges have been registered|_papt_ranges_update|_panics_sptm

0|%s: Re-initializing already started CPU %d|_sptm_cpu_init|_panics_sptm

#0|%s: SAPT not bootstrapped|_sptm_uat_unmap_continue|_panics_sptm

#0|%s: SAPT not bootstrapped|_sptm_bootstrap_finalize|_panics_sptm

0|%s: Error initializing DT |_configure_late_apple_regs|_panics_sptm

0|%s: Unexpected write/exec refcount fo|_xnu_rozone_retype_out|_panics_sptm

0|%s: Type %d is not a CPU root table or XNU|_cpu_root_table_addr_to_fte|_panics_sptm

1|gfx-shared-l2-region-base|_uat_bootstrap|_iommu_bootstrap_alloc_instance

1|Starting SK...|_sptm_init|_serial_out

1|dram-base|_sptm_bootstrap_early|_DTGetProperty

1|gfx-shared-region-base||_DTLookupProperty

2|/arm-io/sgx||_DTLookupEntry|

__DATA_CONST|"TXM-ro"|SPTM_region_list

__DATA_CONST|"NVMe"|nvme_subsystem

__DATA_CONST|"uat"|uat_subsystem

__DATA_CONST|"SART"|SART_subsystem

__DATA_CONST|"t8110dart"|t8110dart_subsystem

__DATA_CONST|"CPUTRACE"|CPUTRACE_subsystem

__TEXT.__const|val=0xbb67ae856a09e667|_ccsha256_initial_state

__TEXT.__const|val=0x64656573646e6172|_randseed_magic

__TEXT.__const|val=0xcbbb9d5dc1059ed8|_ccsha384_initial_state

__TEXT.__const|val=0x428a2f98d728ae22|_sha512_K

__TEXT.__text|val=0x71374491428a2f98|K256

__TEXT.__const|"SPTM-611.0.26"|_sptm_version_string

#

# Example of an opcode matcher (These are REALLY powerful..)

#

_sptm_dispatch|opcodes:ADRP,ADD|X8=dispatch_tables

#

# Static address/symbol mappings - these will only work on sptm.t8150 from iOS 19

0xfffffff0270a37bc|_toggles_sprr_regs

0xfffffff0270a1000|vbar_gl1_initial

0xfffffff0270dc174|_sptm_dispatch

0xfffffff0270dc300|_genter_dispatch_entry

0xfffffff02709c000|vbar_gl1_final

0xfffffff0270a38ac|_initial_genter_setup

0xfffffff0270a38dc|_final_genter_setup

0xfffffff0270b05d8|_halts

0xfffffff0270a6274|_strncmp

0xfffffff0270a627c|_strnlen

0xfffffff0270a6284|_bzero

0xfffffff0270a628c|_bzero_chk

0xfffffff0270a3b60|_do_bzero

0xfffffff0270a3eb0|_do_memcpy

0xfffffff0270a529c|_vsnprintf_chk

0xfffffff0270a61b0|_do_memset

0xfffffff0270a6208|_memset_chk

0xfffffff0270a6144|_memcpy

0xfffffff0270a614c|_memcpy_chk

0xfffffff0270ab0c4|_wraps_memset

0xfffffff0270a4c5c|_write_integer

0xfffffff0270a4290|_do_strncmp

0xfffffff0270a43e0|_do_strnlen

0xfffffff0270a6264|_strcmp

0xfffffff0270a4190|_do_strcmp

#0xfffffff027091740|_dispatch_tables

0xfffffff02701cdd8|xnu_dispatch

0xfffffff02701d250|txm_dispatch

0xfffffff02701d570|sk_dispatch

0xfffffff02701d890|hibernation_dispatch

0xfffffff0270b4a6c|_txm_retype_0x5

0xfffffff027019568|sptm_page_types

0xfffffff027019768|sptm_violation_types

0xfffffff0270ccc24|_sptm_violation_type_to_string

0xfffffff0270ccbd8|_type_id_to_string

0xfffffff0270cccbc|_calls_env_violation

0xfffffff0270983d4|_sptm_do_dispatch

0xfffffff0270da00c|_iommu_frame_acquire_type

0xfffffff0270ab160|_txm_upcall_0

0xfffffff0270ab178|_txm_upcall_1

0xfffffff0270ab190|_txm_upcall_2

0xfffffff0270ab1a8|_txm_upcall_3

0xfffffff0270ab1c0|_txm_upcall_4

0xfffffff0270ab1d8|_txm_upcall_5

0xfffffff0270e2f88|_sptm_map_page

0xfffffff0270e4708|_sptm_map_table

0xfffffff0270e5188|_sptm_unmap_table

0xfffffff0270e7730|_sptm_update_region

0xfffffff0270e7fdc|_sptm_update_disjoint

0xfffffff0270e70d4|_sptm_unmap_region

0xfffffff0270e8078|_sptm_unmap_disjoint

0xfffffff0270e867c|_sptm_configure_shared_region

0xfffffff0270e8c64|_sptm_nest_region

0xfffffff0270e3cc0|_acquire_root_pt

0xfffffff0270e456c|_acquire_shared_root_pt

0xfffffff0270b0b74|_sptm_lockdown_xnu

0xfffffff0270e94c0|_sptm_unnest_region

0xfffffff0270e9b08|_sptm_configure_root

0xfffffff0270e9cdc|_sptm_switch_root

0xfffffff0270b48d0|_sptm_fixups_complete

0xfffffff0270eb220|_sptm_sign_user_pointer

0xfffffff0270eb554|_sptm_auth_user_pointer

0xfffffff0270db8e8|_sptm_register_exc_return

0xfffffff0270b15bc|_sptm_cpu_id

0xfffffff0270e80ac|_sptm_update_disjoint_multipage

0xfffffff0270ec1b8|_sptm_guest_va_to_ipa

0xfffffff0270ea6c0|_acquire_stage2_root_pt

0xfffffff027098f7c|_sptm_enter_txm

0xfffffff0270ab100|_sk_upcall_0

0xfffffff0270ab118|_sk_upcall_1

0xfffffff0270ab130|_sk_upcall_2

0xfffffff0270ab148|_sk_upcall_3

0xfffffff02709911c|_sptm_enter_sk

0xfffffff027018030|_ccsha384_di

0xfffffff027018080|_ccsha256_di

0xfffffff027004bc1|CC_DIGEST_OID_SHA256

0xfffffff027004bb5|CC_DIGEST_OID_SH384

0xfffffff0270ab0e0|_returns_ccsha256_di

0xfffffff0270ab0f0|_returns_ccsha384_di

0xfffffff0270b6688|_hibernation_key_from_dt

0xfffffff0270180d0|_uat_endpoints

0xfffffff0270a8c00|K256

0xfffffff0270aad24|_ccsha256_vng_arm_compress

0xfffffff0270a64a8|_ccdigest_final_64be

0xfffffff0270a64a0|_ccsha384_vng_arm_compress

0xfffffff0270aad2c|_ccsha512_final

0xfffffff0270a6748|_cc_related

0xfffffff0270a67a4|_cc_related2

0xfffffff0270991e0|_sk_bootstrap

0xfffffff0270990e0|_txm_bootstrap

0xfffffff0270dc05c|_action_bootstrap_txm

0xfffffff0270dc048|_action_bootstrap_sk

0xfffffff0270ce7a4|_sptm_bootstrap_tlbi

0xfffffff0270d5720|_sptm_bootstrap_finalize

0xfffffff0270d6088|_sk_types_retype_out

0xfffffff0270d62e0|_tag_frame_acquire

0xfffffff0270d6640|_xnu_subpage_user_root_tables_retype_out

0xfffffff0270d679c|_xnu_tag_storage_retype_in

0xfffffff0270d6940|_xnu_iommu_retype_out

0xfffffff02701dbe0|_page_retyping_info

0xfffffff0270d7cac|_frame_acquire

0xfffffff0270cf1a4|_bootstrap_page_related

0xfffffff0270b756c|_hib_sptm_panic_func

0xfffffff0270d9684|_io_range_get_papt

0xfffffff0270d9340|_io_range_related_important

#

# These we learn from page frames:

#

0xfffffff0270d79d4|_default_retype_in

0xfffffff0270d79dc|_default_retype

0xfffffff0270d79cc|_default_retype_out

0xfffffff0270d75d8|_cpu_root_table_retype_in

0xfffffff0270d6a9c|_xnu_iommu_retype_in

0xfffffff0270d79d4|_xnu_rozone_retype_in

0xfffffff0270d66c4|_xnu_tag_storage_retype_out

0xfffffff0270d66b8|_xnu_subpage_user_root_tables_retype_in

0xfffffff0270d64c0|_sk_types_retype_in

0xfffffff027090288|sptm_boot_args_likely

0xfffffff0270d79b8|_bzero_16K_page