From a9141ed422f342f4ae584ec1182355619f85a621 Mon Sep 17 00:00:00 2001 From: Carlos Holguera Date: Mon, 2 Sep 2024 15:47:26 +0200 Subject: [PATCH] update demos to use asm for better output --- .gitignore | 4 +- .../MASTG-DEMO-0013/MASTG-DEMO-0013.md | 96 +--- .../{function.txt => function.asm} | 0 .../MASTG-DEMO-0013/{key.txt => key.asm} | 0 .../{output.txt => output.asm} | 0 demos/ios/MASVS-CRYPTO/MASTG-DEMO-0013/run.sh | 2 +- .../MASTG-DEMO-0013/sec_hardcoded_rsa.r2 | 4 +- .../MASTG-DEMO-0014/MASTG-DEMO-0014.md | 8 +- .../MASVS-CRYPTO/MASTG-DEMO-0014/MASTestApp | Bin 118608 -> 120624 bytes .../MASTG-DEMO-0014/MastgTest.swift | 30 +- .../cryptokit_hardcoded_ecdsa.r2 | 20 + .../MASTG-DEMO-0014/evaluation.txt | 6 + .../MASVS-CRYPTO/MASTG-DEMO-0014/function.asm | 513 ++++++++++++++++++ .../ios/MASVS-CRYPTO/MASTG-DEMO-0014/key.asm | 3 + .../MASVS-CRYPTO/MASTG-DEMO-0014/output.asm | 30 + .../MASVS-CRYPTO/MASTG-DEMO-0014/output.txt | 222 -------- demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/run.sh | 2 +- .../ios/MASVS-CRYPTO/MASTG-TEST-0216.md | 10 +- 18 files changed, 617 insertions(+), 333 deletions(-) rename demos/ios/MASVS-CRYPTO/MASTG-DEMO-0013/{function.txt => function.asm} (100%) rename demos/ios/MASVS-CRYPTO/MASTG-DEMO-0013/{key.txt => key.asm} (100%) rename demos/ios/MASVS-CRYPTO/MASTG-DEMO-0013/{output.txt => output.asm} (100%) create mode 100644 demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/evaluation.txt create mode 100644 demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/function.asm create mode 100644 demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/key.asm create mode 100644 demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/output.asm delete mode 100644 demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/output.txt mode change 100644 => 100755 demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/run.sh diff --git a/.gitignore b/.gitignore index b5ee583f8d..b55c20945b 100644 --- a/.gitignore +++ b/.gitignore @@ -27,4 +27,6 @@ docs/MASTG docs/MASWE docs/assets/Images OWASP_MASVS.yaml -cross_references.yaml \ No newline at end of file +cross_references.yaml +drafts/ +Payload/ \ No newline at end of file diff --git a/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0013/MASTG-DEMO-0013.md b/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0013/MASTG-DEMO-0013.md index 1e40dbdc46..5e33764958 100644 --- a/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0013/MASTG-DEMO-0013.md +++ b/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0013/MASTG-DEMO-0013.md @@ -8,7 +8,7 @@ test: MASTG-TEST-0216 ### Sample -{{ MastgTest.swift }} +{{ MastgTest.swift # function.asm }} ### Steps @@ -21,99 +21,9 @@ test: MASTG-TEST-0216 ### Observation -The output reveals the hardcoded RSA private key within the binary. This key is typically found in the DATA section of the binary, where it is loaded into memory for cryptographic operations. The presence of hardcoded keys can be identified by searching for sequences of bytes or strings corresponding to the key. +The output reveals a call to `SecKeyCreateWithData` as well as the hardcoded RSA private key within the DATA section of the binary. -{{ output.txt # function.txt # key.txt }} - -Identify where the x0 register, which holds the key data, is populated before the call to `SecKeyCreateWithData`. Trace back through the instructions to find where x0 comes from: - -```asm -│ 0x100004b74 mov x0, x20 -│ 0x100004b78 mov x1, x21 -│ 0x100004b7c bl sym.imp.SecKeyCreateWithData -``` - -Look for `ldr`, `ldp`, `adrp`, and `add` instructions, which are often used to load data from memory or set up addresses. - -```asm -│ 0x100004998 adrp x0, segment.__DATA ; 0x100010000 -│ 0x10000499c add x0, x0, 0x328 ; int64_t arg1 -``` - -This seems to be the source of the data in `x0`. Check for earlier function calls or memory loading instructions. - -In this case data is loaded from `segment.__DATA` (0x100010000), let's inspect those memory regions: - -```asm -[0x100004c84]> s 0x100010000 -[0x100010000]> px 256 -- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF -0x100010000 8100 0000 2800 0000 2800 0000 0000 0000 ....(...(....... -0x100010010 0000 0000 0000 0000 5086 0000 0000 9000 ........P....... -0x100010020 0000 0000 0000 0000 0000 0000 0000 0000 ................ -0x100010030 0000 0000 0000 0000 0000 0000 0000 0000 ................ -0x100010040 0000 0000 0000 0000 8000 0000 1000 0000 ................ -0x100010050 1000 0000 0000 0000 0000 0000 0000 0000 ................ -0x100010060 5086 0000 0000 6000 0000 0000 0000 0000 P.....`......... -0x100010070 0000 0000 0000 0000 0000 0000 0000 0000 ................ -0x100010080 0000 0000 0000 0000 0000 0000 0000 0000 ................ -0x100010090 7888 0000 0000 1000 bb00 0000 0000 7088 x.............p. -0x1000100a0 0000 0000 0000 0000 0000 0000 0000 0000 ................ -0x1000100b0 0000 0000 0000 0000 5f02 0000 0000 0000 ........_....... -0x1000100c0 be04 0000 0000 0000 3082 025b 0201 0002 ........0..[.... -0x1000100d0 8181 00bd f689 8fbd 0ce6 4f9a 97ec 301a ..........O...0. -0x1000100e0 4893 4d2a bfdf f708 154c db87 e5df b1cf H.M*.....L...... -0x1000100f0 8da2 5e2a 7d92 a8bd 30b9 10cf 96da 1025 ..^*}...0......% -``` - -RSA keys have specific patterns, especially when encoded in ASN.1/DER format. You can search for common byte patterns like 0x30 0x82 (which indicates the start of a DER sequence). You can also use r2 search capabilities to find such patterns: - -```asm -[0x100007430]> e search.from = 0x1000100a0 -[0x100007430]> e search.to = 0x1000100a0 + 0x4c8 -[0x100007430]> /x 3082 -0x1000100c8 hit4_0 3082 -``` - -There is only one hit for the 0x30 0x82 pattern within `segment.__DATA`. You can use the `px` command to print all the bytes from the RSA key. The total length of the encoded key is the length of the sequence plus the length of the initial identifier and length fields. - -The total length of the encoded key is calculated as: - -- 1 byte for 0x30 (SEQUENCE identifier) -- 1 byte for 0x82 (indicating long-form length) -- 2 bytes for 0x025b (length of the sequence) -- 603 bytes for the sequence itself - -So, the total length is: 1 + 1 + 2 + 603 = 607 bytes - -{{ key.txt }} - -Note that it seems that we could not find this address in the disassembly, but if you recall, the very first reference to `segment.__DATA` we had was: - -```asm -│ 0x100004998 adrp x0, segment.__DATA ; 0x100010000 -│ 0x10000499c add x0, x0, 0x328 ; int64_t arg1 -``` - -And this is pointing to 0x100010000 + 0x328 = 0x100010328, which is exactly after the RSA key which goes from 0x1000100c8 to 0x10001327. So, the key must be held within some data structure which must be the one being loaded into memory and then passed to `SecKeyCreateWithData`. - -The length of the actual key can be obtained from the length of the modulus (n) in the RSA key. The modulus is the first integer in the RSA key, and its length is the key size. In this case, we see `0002 8181 00bd f689 ...`. In DER the length of the modulus is encoded as `02 81 81`, where: - -- `02` is the INTEGER tag, indicating that the following bytes represent an integer (in this case, the modulus). -- the first `81` indicates that the length of the data (the modulus) is provided in the next byte. -- the second `81` indicates that the length of the modulus is 129 bytes long including the `00` byte which is added to force the integer to be positive. The key size is calculated as `(0x81 - 1) * 8 = 128 * 8 = 1024 bits`. - -If you want to decode the key you can use this website: [https://lapo.it/asn1js/](https://lapo.it/asn1js/) which is going to decode it as: - -```txt -RSAPrivateKey SEQUENCE (9 elem) - version Version INTEGER 0 - modulus INTEGER (1024 bit) 133396580715800090592469243143215418884374307199930301828108855519157… - publicExponent INTEGER 65537 -... -``` - -You can hover over the different parts of the key to see the decoded values in hex on the right side of the screen. +{{ output.asm # key.asm }} ### Evaluation diff --git a/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0013/function.txt b/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0013/function.asm similarity index 100% rename from demos/ios/MASVS-CRYPTO/MASTG-DEMO-0013/function.txt rename to demos/ios/MASVS-CRYPTO/MASTG-DEMO-0013/function.asm diff --git a/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0013/key.txt b/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0013/key.asm similarity index 100% rename from demos/ios/MASVS-CRYPTO/MASTG-DEMO-0013/key.txt rename to demos/ios/MASVS-CRYPTO/MASTG-DEMO-0013/key.asm diff --git a/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0013/output.txt b/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0013/output.asm similarity index 100% rename from demos/ios/MASVS-CRYPTO/MASTG-DEMO-0013/output.txt rename to demos/ios/MASVS-CRYPTO/MASTG-DEMO-0013/output.asm diff --git a/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0013/run.sh b/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0013/run.sh index b62cd5d124..9aaedb35d3 100755 --- a/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0013/run.sh +++ b/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0013/run.sh @@ -1 +1 @@ -r2 -q -i sec_hardcoded_rsa.r2 -A MASTestApp > output.txt \ No newline at end of file +r2 -q -i sec_hardcoded_rsa.r2 -A MASTestApp > output.asm \ No newline at end of file diff --git a/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0013/sec_hardcoded_rsa.r2 b/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0013/sec_hardcoded_rsa.r2 index 0aa0ab1423..a7bdab69e8 100644 --- a/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0013/sec_hardcoded_rsa.r2 +++ b/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0013/sec_hardcoded_rsa.r2 @@ -13,6 +13,6 @@ axt @ 0x100007904 !printf "\n" -pdf @ sym.func.10000491c > function.txt +pdf @ sym.func.10000491c > function.asm -px 607 @ 0x1000100c8 > key.txt \ No newline at end of file +px 607 @ 0x1000100c8 > key.asm \ No newline at end of file diff --git a/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/MASTG-DEMO-0014.md b/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/MASTG-DEMO-0014.md index 519545bf3e..73b0a4a868 100644 --- a/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/MASTG-DEMO-0014.md +++ b/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/MASTG-DEMO-0014.md @@ -8,22 +8,22 @@ test: MASTG-TEST-0216 ### Sample -{{ MastgTest.swift }} +{{ MastgTest.swift # function.asm }} ### Steps 1. Unzip the app package and locate the main binary file (@MASTG-TECH-0058), which in this case is `./Payload/MASTestApp.app/MASTestApp`. 2. Open the app binary with @MASTG-TOOL-0073 with the `-i` option to run this script. -{{ cryptokit_hardcoded_rsa.r2 }} +{{ cryptokit_hardcoded_ecdsa.r2 }} {{ run.sh }} ### Observation -The output reveals the hardcoded ECDSA private key within the binary. This key is typically found in the disassembled code section, where it is loaded into memory for cryptographic operations. The presence of hardcoded keys can be identified by searching for sequences of bytes or strings corresponding to the key. +The output reveals the different uses of `CryptoKit.P256.Signing.PrivateKey` functions, especially `sym.imp.CryptoKit.P256.Signing.PrivateKey.rawRepresentation` which is used to extract the raw representation of the private key. The output also reveals the hardcoded ECDSA private key within the binary's DATA section. -{{ output.txt }} +{{ output.asm # key.asm }} ### Evaluation diff --git a/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/MASTestApp b/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/MASTestApp index 13b28c76f65a400c4da992a2043f52f734b58c7b..cabd7d1fab684617265a3df6dcf5a8978a1b6189 100755 GIT binary patch delta 18104 zcmeHud013s-~WBiFfbtM$i4{!Du^rMhCVJcfDBq1iCeZHDFS9lfD3BPD6U!Lcu>qz zaZ8xWP*K!2O51FC#msDZo>0ro-ptIDF>v0`_dYXtIQ3l5d;PB8U%%^jF23ixFZX)x zGc%mp=2g4TYkgxEBVz(%>_!4^bQx_IM)}<+l%*vevhYTslqie}ESxWkQ^^At@gC9u zeYjL57y|1S$l7!rS2E6X?KQ#R$1JjTvCEfPq!@8j;8LqBJ}3Jy;zjPXUNrbkS|)3Q zUD`>@po)~5L_^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-0014/MastgTest.swift +++ b/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/MastgTest.swift @@ -6,9 +6,9 @@ struct MastgTest { // Step 1: Use a hardcoded ECDSA P-256 private key (32 bytes for P-256) in bytes let privateKeyBytes: [UInt8] = [ - 0x7c, 0x02, 0x2a, 0x7e, 0x53, 0x7e, 0x1a, 0x2d, - 0x44, 0x77, 0xd4, 0xf6, 0x20, 0x8b, 0x14, 0xdb, - 0x4e, 0x8d, 0x84, 0x19, 0xd6, 0x23, 0x5f, 0xf2, + 0x7c, 0x02, 0x2a, 0x7e, 0x53, 0x7e, 0x1a, 0x2d, + 0x44, 0x77, 0xd4, 0xf6, 0x20, 0x8b, 0x14, 0xdb, + 0x4e, 0x8d, 0x84, 0x19, 0xd6, 0x23, 0x5f, 0xf2, 0x4e, 0x4b, 0x8d, 0x18, 0xf4, 0x2c, 0x76, 0xe2 ] let privateKeyData = Data(privateKeyBytes) @@ -18,8 +18,30 @@ struct MastgTest { return } + let publicKey = privateKey.publicKey + + // Data to sign + let dataToSign = "This is a sample text".data(using: .utf8)! + + // Step 2: Sign the data with the hardcoded private key + let signature = try! privateKey.signature(for: dataToSign) + + // Convert signature to hex string for display + let signatureHex = signature.rawRepresentation.map { String(format: "%02hhx", $0) }.joined() + + // Step 3: Verify the signature with the public key + let verificationStatus = publicKey.isValidSignature(signature, for: dataToSign) + + let verificationResult = verificationStatus ? "Signature is valid." : "Signature is invalid." + let value = """ - Private Key (Hex): \(privateKeyData.map { String(format: "%02hhx", $0) }.joined()) + Original: \(String(data: dataToSign, encoding: .utf8)!) + + Public Key (Hex): \(publicKey.rawRepresentation.map { String(format: "%02hhx", $0) }.joined()) + + Signature (Hex): \(signatureHex) + + Verification: \(verificationResult) """ completion(value) diff --git a/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/cryptokit_hardcoded_ecdsa.r2 b/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/cryptokit_hardcoded_ecdsa.r2 index e69de29bb2..181ff6a7e8 100644 --- a/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/cryptokit_hardcoded_ecdsa.r2 +++ b/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/cryptokit_hardcoded_ecdsa.r2 @@ -0,0 +1,20 @@ +e asm.bytes = false +e scr.color=false + +!printf "Uses of CryptoKit.P256.Signing.PrivateKey:\n" +afl~CryptoKit.P256.Signing.PrivateKey + +!printf "\n" + +!printf "xrefs to CryptoKit.P256.Signing.PrivateKey.rawRepresentation:\n" +axt @ 0x100007388 + +!printf "\n" + +!printf "Use of CryptoKit.P256.Signing.PrivateKey.rawRepresentation:\n" + +pd-- 9 @ 0x1000048d4 + +pdf @ sym.func.1000046dc > function.asm + +px 32 @ 0x1000100c8 > key.asm \ No newline at end of file diff --git a/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/evaluation.txt b/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/evaluation.txt new file mode 100644 index 0000000000..2069b1a81e --- /dev/null +++ b/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/evaluation.txt @@ -0,0 +1,6 @@ +0x1000047b4 adrp x0, segment.__DATA ; 0x100010000 -> This instruction loads the base address of the `.data` segment into register `x0`. +0x1000047b8 add x0, x0, 0xe8 ; int64_t arg1 -> This adds an offset to the base address, pointing to a specific memory location within the `.data` segment, possibly where the hardcoded key or related data is stored. +0x1000047bc bl sym.func.100004e0c -> A function is called, with `x0` as an argument, likely using the data at the computed address (which could be the key) for further operations. +0x1000047c0 ldur x8, [x0, -8] -> This loads data from the memory location computed earlier (potentially part of the key) into register `x8`. +0x1000047c4 ldr x8, [x8, 0x40] -> Further data manipulation, loading another piece of data related to the earlier load. This could be part of the key processing. +0x1000047f0 bl sym CryptoKit.P256.Signing.PrivateKey. -> This calls the `PrivateKey` initializer, which may use the previously loaded data (potentially a hardcoded key) in its process of key creation. diff --git a/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/function.asm b/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/function.asm new file mode 100644 index 0000000000..04b2eb0424 --- /dev/null +++ b/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/function.asm @@ -0,0 +1,513 @@ + ; CALL XREF from sym.func.100005f30 @ 0x100005f68(x) +┌ 1840: sym.func.1000046dc (int64_t arg1, int64_t arg2, int64_t arg3); +│ ; arg int64_t arg1 @ x0 +│ ; arg int64_t arg2 @ x1 +│ ; arg int64_t arg3 @ x2 +│ ; var int64_t var_0h_2 @ sp+0x0 +│ ; var int64_t var_0h_10 @ sp+0x8 +│ ; var int64_t var_10h @ sp+0x10 +│ ; var int64_t var_0h_11 @ sp+0x18 +│ ; var int64_t var_20h @ sp+0x20 +│ ; var int64_t var_0h_9 @ sp+0x28 +│ ; var int64_t var_30h @ sp+0x30 +│ ; var int64_t var_0h_8 @ sp+0x38 +│ ; var int64_t var_40h @ sp+0x40 +│ ; var void *var_e8h @ sp+0x48 +│ ; var int64_t var_50h_2 @ sp+0x50 +│ ; var int64_t var_e0h @ sp+0x58 +│ ; var int64_t var_d0h @ sp+0x60 +│ ; var int64_t var_d0h_2 @ sp+0x68 +│ ; var int64_t var_0h_4 @ sp+0x70 +│ ; var int64_t var_0h_3 @ sp+0x78 +│ ; var int64_t var_0h @ sp+0x80 +│ ; var void *var_a8h @ sp+0x88 +│ ; var void *var_a0h @ sp+0x90 +│ ; var int64_t var_0h_12 @ sp+0x98 +│ ; var void *var_0h_7 @ sp+0xb0 +│ ; var void *arg0 @ sp+0xb8 +│ ; var int64_t var_0h_13 @ sp+0xc0 +│ ; var int64_t var_0h_5 @ sp+0xc8 +│ ; var int64_t var_0h_6 @ sp+0xd0 +│ ; var int64_t var_60h @ sp+0xe0 +│ ; var int64_t var_60h_2 @ sp+0xe8 +│ ; var int64_t var_10h_2 @ sp+0xf0 +│ ; var int64_t var_10h_3 @ sp+0xf8 +│ ; var int64_t var_20h_2 @ sp+0x100 +│ ; var int64_t var_20h_3 @ sp+0x108 +│ ; var int64_t var_30h_2 @ sp+0x110 +│ ; var int64_t var_30h_3 @ sp+0x118 +│ ; var int64_t var_40h_2 @ sp+0x120 +│ ; var int64_t var_40h_3 @ sp+0x128 +│ ; var int64_t var_50h @ sp+0x130 +│ ; var int64_t var_50h_3 @ sp+0x138 +│ 0x1000046dc stp x28, x27, [sp, -0x60]! +│ 0x1000046e0 stp x26, x25, [var_10h] +│ 0x1000046e4 stp x24, x23, [var_20h] +│ 0x1000046e8 stp x22, x21, [var_30h] +│ 0x1000046ec stp x20, x19, [var_40h] +│ 0x1000046f0 stp x29, x30, [var_50h_2] +│ 0x1000046f4 add x29, sp, 0x50 +│ 0x1000046f8 sub sp, sp, 0xe0 +│ 0x1000046fc stp x1, x2, [x29, -0xa8] ; arg3 +│ 0x100004700 stur x0, [x29, -0xb0] ; arg1 +│ 0x100004704 mov x0, 0 +│ 0x100004708 bl sym CryptoKit.P256.Signing.ECDSASignature...VMa ; sym.imp.CryptoKit.P256.Signing.ECDSASignature...VMa +│ 0x10000470c ldur x8, [x0, -8] +│ 0x100004710 stp x8, x0, [x29, -0xe0] +│ 0x100004714 ldr x8, [x8, 0x40] +│ 0x100004718 mov x9, x8 +│ 0x10000471c adrp x16, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000 +│ 0x100004720 ldr x16, reloc.__chkstk_darwin ; 0x10000c3b8 +│ 0x100004724 blr x16 +│ 0x100004728 mov x9, sp +│ 0x10000472c add x8, x8, 0xf +│ 0x100004730 and x8, x8, 0xfffffffffffffff0 +│ 0x100004734 sub x8, x9, x8 +│ 0x100004738 stur x8, [x29, -0xb8] +│ 0x10000473c mov sp, x8 +│ 0x100004740 mov x0, 0 +│ 0x100004744 bl sym Foundation...8EncodingVMa ; sym.imp.Foundation...8EncodingVMa +│ 0x100004748 ldur x8, [x0, -8] +│ 0x10000474c stp x8, x0, [x29, -0xd0] +│ 0x100004750 ldr x8, [x8, 0x40] +│ 0x100004754 mov x9, x8 +│ 0x100004758 adrp x16, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000 +│ 0x10000475c ldr x16, reloc.__chkstk_darwin ; 0x10000c3b8 +│ 0x100004760 blr x16 +│ 0x100004764 mov x9, sp +│ 0x100004768 add x8, x8, 0xf +│ 0x10000476c and x8, x8, 0xfffffffffffffff0 +│ 0x100004770 sub x8, x9, x8 +│ 0x100004774 stur x8, [x29, -0xc0] +│ 0x100004778 mov sp, x8 +│ 0x10000477c mov x0, 0 +│ 0x100004780 bl sym CryptoKit.P256.Signing.PublicKey...VMa ; sym.imp.CryptoKit.P256.Signing.PublicKey...VMa +│ 0x100004784 mov x27, x0 +│ 0x100004788 ldur x26, [x0, -8] +│ 0x10000478c ldr x8, [x26, 0x40] +│ 0x100004790 mov x9, x8 +│ 0x100004794 adrp x16, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000 +│ 0x100004798 ldr x16, reloc.__chkstk_darwin ; 0x10000c3b8 +│ 0x10000479c blr x16 +│ 0x1000047a0 mov x9, sp +│ 0x1000047a4 add x8, x8, 0xf +│ 0x1000047a8 and x8, x8, 0xfffffffffffffff0 +│ 0x1000047ac sub x25, x9, x8 +│ 0x1000047b0 mov sp, x25 +│ 0x1000047b4 adrp x0, segment.__DATA ; 0x100010000 +│ 0x1000047b8 add x0, x0, 0xe8 ; int64_t arg1 +│ 0x1000047bc bl sym.func.100004e0c +│ 0x1000047c0 ldur x8, [x0, -8] +│ 0x1000047c4 ldr x8, [x8, 0x40] +│ 0x1000047c8 mov x9, x8 +│ 0x1000047cc adrp x16, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000 +│ 0x1000047d0 ldr x16, reloc.__chkstk_darwin ; 0x10000c3b8 +│ 0x1000047d4 blr x16 +│ 0x1000047d8 mov x9, sp +│ 0x1000047dc add x8, x8, 0xf +│ 0x1000047e0 and x8, x8, 0xfffffffffffffff0 +│ 0x1000047e4 sub x20, x9, x8 +│ 0x1000047e8 mov sp, x20 +│ 0x1000047ec mov x0, 0 +│ 0x1000047f0 bl sym CryptoKit.P256.Signing.PrivateKey...VMa ; sym.imp.CryptoKit.P256.Signing.PrivateKey...VMa +│ 0x1000047f4 mov x23, x0 +│ 0x1000047f8 ldur x28, [x0, -8] +│ 0x1000047fc ldr x8, [x28, 0x40] +│ 0x100004800 mov x9, x8 +│ 0x100004804 adrp x16, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000 +│ 0x100004808 ldr x16, reloc.__chkstk_darwin ; 0x10000c3b8 +│ 0x10000480c blr x16 +│ 0x100004810 mov x9, sp +│ 0x100004814 add x8, x8, 0xf +│ 0x100004818 and x8, x8, 0xfffffffffffffff0 +│ 0x10000481c sub x24, x9, x8 +│ 0x100004820 mov sp, x24 +│ 0x100004824 adrp x0, segment.__DATA ; 0x100010000 +│ 0x100004828 add x0, x0, 0xf0 ; int64_t arg1 +│ 0x10000482c bl sym.func.100004e0c +│ 0x100004830 adrp x1, segment.__DATA ; 0x100010000 +│ 0x100004834 add x1, x1, 0xa8 +│ 0x100004838 bl sym.imp.swift_initStaticObject +│ 0x10000483c mov x19, x0 +│ 0x100004840 adrp x21, segment.__DATA ; 0x100010000 +│ 0x100004844 add x21, x21, 0xf8 +│ 0x100004848 mov x0, x21 ; int64_t arg1 +│ 0x10000484c bl sym.func.100004e0c +│ 0x100004850 mov x22, x0 +│ 0x100004854 stur x0, [x29, -0x68] +│ 0x100004858 adrp x0, segment.__DATA ; 0x100010000 +│ 0x10000485c add x0, x0, 0x100 ; int64_t arg1 +│ 0x100004860 adrp x2, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000 +│ 0x100004864 ldr x2, reloc.Foundation.ContiguousBytes.UInt8...szlMc ; 0x10000c368 ; int64_t arg3 +│ 0x100004868 mov x1, x21 ; int64_t arg2 +│ 0x10000486c bl sym.func.100005024 +│ 0x100004870 stur x0, [x29, -0x60] +│ 0x100004874 stur x19, [x29, -0x80] +│ 0x100004878 sub x0, x29, 0x80 ; int64_t arg1 +│ 0x10000487c mov x1, x22 ; int64_t arg2 +│ 0x100004880 bl sym.func.100004e90 +│ 0x100004884 ldr x8, [x0] +│ 0x100004888 add x0, x8, 0x20 ; int64_t arg1 +│ 0x10000488c ldr x8, [x8, 0x10] +│ 0x100004890 add x1, x0, x8 ; int64_t arg2 +│ 0x100004894 bl sym.func.100004674 +│ 0x100004898 mov x22, x0 +│ 0x10000489c mov x19, x1 +│ 0x1000048a0 sub x0, x29, 0x80 ; int64_t arg1 +│ 0x1000048a4 bl sym.func.100004eb4 +│ 0x1000048a8 stp x22, x19, [x29, -0x80] +│ 0x1000048ac mov x0, x22 ; int64_t arg2 +│ 0x1000048b0 mov x1, x19 +│ 0x1000048b4 bl sym.func.100004ed4 +│ 0x1000048b8 adrp x1, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000 +│ 0x1000048bc ldr x1, [x1, 0x38] ; 0x10000c038 +│ ; reloc.Foundation.Data...VN +│ 0x1000048c0 adrp x2, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000 +│ 0x1000048c4 ldr x2, [x2, 0x30] ; 0x10000c030 +│ ; reloc.Foundation.Data...VAA15ContiguousBytesAAWP.ContiguousBytes...WP +│ 0x1000048c8 sub x0, x29, 0x80 +│ 0x1000048cc mov x8, x20 +│ 0x1000048d0 mov x21, 0 +│ 0x1000048d4 bl sym CryptoKit.P256.Signing.PrivateKey.rawRepresentation.Foundation.ContiguousBytes...lufC ; sym.imp.CryptoKit.P256.Signing.PrivateKey.rawRepresentation.Foundation.ContiguousBytes...lufC +│ ┌─< 0x1000048d8 cbz x21, 0x100004900 +│ │ 0x1000048dc mov x0, x21 +│ │ 0x1000048e0 bl sym.imp.swift_errorRelease +│ │ 0x1000048e4 ldr x8, [x28, 0x38] +│ │ 0x1000048e8 mov x0, x20 +│ │ 0x1000048ec mov w1, 1 +│ │ 0x1000048f0 mov w2, 1 +│ │ 0x1000048f4 mov x3, x23 +│ │ 0x1000048f8 blr x8 +│ ┌──< 0x1000048fc b 0x100004940 +│ ││ ; CODE XREF from sym.func.1000046dc @ 0x1000048d8(x) +│ │└─> 0x100004900 stp x27, x24, [x29, -0xf0] +│ │ 0x100004904 stur x26, [x29, -0xf8] +│ │ 0x100004908 ldur x27, [x29, -0xb8] +│ │ 0x10000490c ldr x8, [x28, 0x38] +│ │ 0x100004910 mov x0, x20 +│ │ 0x100004914 mov w1, 0 +│ │ 0x100004918 mov w2, 1 +│ │ 0x10000491c mov x3, x23 +│ │ 0x100004920 blr x8 +│ │ 0x100004924 ldr x8, [x28, 0x30] +│ │ 0x100004928 mov x0, x20 +│ │ 0x10000492c mov w1, 1 +│ │ 0x100004930 mov x2, x23 +│ │ 0x100004934 blr x8 +│ │ 0x100004938 cmp w0, 1 +│ │┌─< 0x10000493c b.ne 0x1000049c4 +│ ││ ; CODE XREF from sym.func.1000046dc @ 0x1000048fc(x) +│ └──> 0x100004940 mov x0, x20 ; int64_t arg1 +│ │ 0x100004944 bl sym.func.100004f18 +│ │ 0x100004948 ldur x9, [x29, -0xb0] +│ │ 0x10000494c ldur x8, [x29, -0xa8] +│ │ 0x100004950 stp x9, x8, [x29, -0x80] +│ │ 0x100004954 ldur x8, [x29, -0xa0] +│ │ 0x100004958 stur x8, [x29, -0x70] +│ │ 0x10000495c mov x8, 0x13 +│ │ 0x100004960 movk x8, 0xd000, lsl 48 +│ │ 0x100004964 add x8, x8, 0xa +│ │ 0x100004968 adrp x9, 0x100007000 +│ │ 0x10000496c add x9, x9, 0xf00 ; 0x100007f00 ; "Failed to create private key." +│ │ 0x100004970 sub x9, x9, 0x20 +│ │ 0x100004974 orr x9, x9, 0x8000000000000000 +│ │ 0x100004978 stp x8, x9, [x29, -0x98] +│ │ 0x10000497c adrp x0, segment.__DATA ; 0x100010000 +│ │ 0x100004980 add x0, x0, 0x108 ; int64_t arg1 +│ │ 0x100004984 bl sym.func.100004e0c +│ │ 0x100004988 mov x1, x0 +│ │ 0x10000498c sub x0, x29, 0x98 +│ │ 0x100004990 sub x20, x29, 0x80 +│ │ 0x100004994 bl sym SwiftUI.State.wrappedValue...s ; sym.imp.SwiftUI.State.wrappedValue...s +│ │ ; CODE XREF from sym.func.1000046dc @ 0x100004db0(x) +│ ┌──> 0x100004998 mov x0, x22 ; void *arg0 +│ ╎│ 0x10000499c mov x1, x19 ; int64_t arg2 +│ ╎│ 0x1000049a0 bl sym.func.100004f58 +│ ╎│ 0x1000049a4 sub sp, x29, 0x50 +│ ╎│ 0x1000049a8 ldp x29, x30, [var_50h_2] +│ ╎│ 0x1000049ac ldp x20, x19, [var_40h] +│ ╎│ 0x1000049b0 ldp x22, x21, [var_30h] +│ ╎│ 0x1000049b4 ldp x24, x23, [var_20h] +│ ╎│ 0x1000049b8 ldp x26, x25, [var_10h] +│ ╎│ 0x1000049bc ldp x28, x27, [sp], 0x60 +│ ╎│ 0x1000049c0 ret +│ ╎│ ; CODE XREF from sym.func.1000046dc @ 0x10000493c(x) +│ ╎└─> 0x1000049c4 ldr x8, [x28, 0x20] +│ ╎ 0x1000049c8 ldur x26, [x29, -0xe8] +│ ╎ 0x1000049cc mov x0, x26 +│ ╎ 0x1000049d0 mov x1, x20 +│ ╎ 0x1000049d4 mov x2, x23 +│ ╎ 0x1000049d8 blr x8 +│ ╎ 0x1000049dc stur x25, [x29, -0x100] +│ ╎ 0x1000049e0 mov x8, x25 +│ ╎ 0x1000049e4 mov x20, x26 +│ ╎ 0x1000049e8 bl sym CryptoKit.P256.Signing.PrivateKey.public...F0AE06PublicF0Vvg.Public...F0Vvg...Vvg ; sym.imp.CryptoKit.P256.Signing.PrivateKey.public...F0AE06PublicF0Vvg.Public...F0Vvg...Vvg +│ ╎ 0x1000049ec mov x8, 0x13 +│ ╎ 0x1000049f0 movk x8, 0xd000, lsl 48 +│ ╎ 0x1000049f4 add x8, x8, 2 +│ ╎ 0x1000049f8 adrp x9, 0x100007000 +│ ╎ 0x1000049fc add x9, x9, 0xf20 ; 0x100007f20 ; "This is a sample text" +│ ╎ 0x100004a00 sub x9, x9, 0x20 +│ ╎ 0x100004a04 orr x9, x9, 0x8000000000000000 +│ ╎ 0x100004a08 stp x8, x9, [x29, -0x80] +│ ╎ 0x100004a0c ldur x25, [x29, -0xc0] +│ ╎ 0x100004a10 mov x8, x25 +│ ╎ 0x100004a14 bl sym Foundation...8EncodingV4utf8ACvgZ ; sym.imp.Foundation...8EncodingV4utf8ACvgZ +│ ╎ 0x100004a18 bl sym.func.100004f9c +│ ╎ 0x100004a1c mov x3, x0 +│ ╎ 0x100004a20 adrp x2, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000 +│ ╎ 0x100004a24 ldr x2, reloc....SSN ; 0x10000c358 +│ ╎ 0x100004a28 sub x20, x29, 0x80 +│ ╎ 0x100004a2c mov x0, x25 +│ ╎ 0x100004a30 mov w1, 0 +│ ╎ 0x100004a34 bl sym Foundation...btF ; sym.imp.Foundation...btF +│ ╎ 0x100004a38 mov x20, x0 +│ ╎ 0x100004a3c mov x24, x1 +│ ╎ 0x100004a40 ldp x8, x1, [x29, -0xd0] +│ ╎ 0x100004a44 ldr x8, [x8, 8] +│ ╎ 0x100004a48 mov x0, x25 +│ ╎ 0x100004a4c blr x8 +│ ╎ 0x100004a50 ldur x0, [x29, -0x78] ; void *arg0 +│ ╎ 0x100004a54 bl sym.imp.swift_bridgeObjectRelease ; void swift_bridgeObjectRelease(void *arg0) +│ ╎ 0x100004a58 stur x24, [x29, -0xc8] +│ ╎ 0x100004a5c lsr x8, x24, 0x3c +│ ╎ 0x100004a60 cmp x8, 0xe +│ ╎┌─< 0x100004a64 b.hi 0x100004db4 +│ ╎│ 0x100004a68 sub x8, x29, 0x10 +│ ╎│ 0x100004a6c stur x28, [x8, -0x100] +│ ╎│ 0x100004a70 sub x8, x29, 8 +│ ╎│ 0x100004a74 stur x23, [x8, -0x100] +│ ╎│ 0x100004a78 stur x20, [x29, -0xd0] +│ ╎│ 0x100004a7c ldur x8, [x29, -0xc8] +│ ╎│ 0x100004a80 stp x20, x8, [x29, -0x80] +│ ╎│ 0x100004a84 bl sym.func.100004fe0 +│ ╎│ 0x100004a88 mov x2, x0 +│ ╎│ 0x100004a8c adrp x1, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000 +│ ╎│ 0x100004a90 ldr x1, [x1, 0x38] ; 0x10000c038 +│ ╎│ ; reloc.Foundation.Data...VN +│ ╎│ 0x100004a94 sub x0, x29, 0x80 +│ ╎│ 0x100004a98 mov x28, x27 +│ ╎│ 0x100004a9c mov x27, x2 +│ ╎│ 0x100004aa0 mov x8, x28 +│ ╎│ 0x100004aa4 mov x20, x26 +│ ╎│ 0x100004aa8 bl sym CryptoKit.P256.Signing.PrivateKey.signature.for.ECDSASignature.Foundation.DataProtocol...lF ; sym.imp.CryptoKit.P256.Signing.PrivateKey.signature.for.ECDSASignature.Foundation.DataProtocol...lF +│ ┌───< 0x100004aac cbnz x21, 0x100004ddc +│ │╎│ 0x100004ab0 mov x20, x28 +│ │╎│ 0x100004ab4 bl sym CryptoKit.P256.Signing.ECDSASignature.rawRepresentation.Foundation.Data...Vvg ; sym.imp.CryptoKit.P256.Signing.ECDSASignature.rawRepresentation.Foundation.Data...Vvg +│ │╎│ 0x100004ab8 mov x20, x0 +│ │╎│ 0x100004abc mov x25, x1 +│ │╎│ 0x100004ac0 bl sym.func.100004000 +│ │╎│ 0x100004ac4 mov x26, x0 +│ │╎│ 0x100004ac8 mov x0, x20 ; void *arg0 +│ │╎│ 0x100004acc mov x1, x25 ; int64_t arg2 +│ │╎│ 0x100004ad0 bl sym.func.100004f58 +│ │╎│ 0x100004ad4 stur x26, [x29, -0x80] +│ │╎│ 0x100004ad8 adrp x20, segment.__DATA ; 0x100010000 +│ │╎│ 0x100004adc add x20, x20, 0x120 +│ │╎│ 0x100004ae0 mov x0, x20 ; int64_t arg1 +│ │╎│ 0x100004ae4 bl sym.func.100004e0c +│ │╎│ 0x100004ae8 mov x23, x0 +│ │╎│ 0x100004aec adrp x0, segment.__DATA ; 0x100010000 +│ │╎│ 0x100004af0 add x0, x0, 0x128 ; int64_t arg1 +│ │╎│ 0x100004af4 adrp x2, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000 +│ │╎│ 0x100004af8 ldr x2, reloc....SayxGSKsMc ; 0x10000c370 ; int64_t arg3 +│ │╎│ 0x100004afc mov x1, x20 ; int64_t arg2 +│ │╎│ 0x100004b00 bl sym.func.100005024 +│ │╎│ 0x100004b04 mov x3, x0 +│ │╎│ 0x100004b08 mov x25, -0x2000000000000000 +│ │╎│ 0x100004b0c sub x20, x29, 0x80 +│ │╎│ 0x100004b10 mov x0, 0 +│ │╎│ 0x100004b14 mov x1, -0x2000000000000000 +│ │╎│ 0x100004b18 sub x8, x29, 0x28 +│ │╎│ 0x100004b1c stur x23, [x8, -0x100] +│ │╎│ 0x100004b20 mov x2, x23 +│ │╎│ 0x100004b24 sub x8, x29, 0x30 +│ │╎│ 0x100004b28 stur x3, [x8, -0x100] +│ │╎│ 0x100004b2c bl sym Element...F ; sym.imp.Element...F +│ │╎│ 0x100004b30 sub x8, x29, 0x20 +│ │╎│ 0x100004b34 stur x0, [x8, -0x100] +│ │╎│ 0x100004b38 sub x8, x29, 0x18 +│ │╎│ 0x100004b3c stur x1, [x8, -0x100] +│ │╎│ 0x100004b40 mov x0, x26 ; void *arg0 +│ │╎│ 0x100004b44 bl sym.imp.swift_bridgeObjectRelease ; void swift_bridgeObjectRelease(void *arg0) +│ │╎│ 0x100004b48 ldp x23, x24, [x29, -0xd0] +│ │╎│ 0x100004b4c stp x23, x24, [x29, -0x80] +│ │╎│ 0x100004b50 adrp x2, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000 +│ │╎│ 0x100004b54 ldr x2, [x2, 0x38] ; 0x10000c038 +│ │╎│ ; reloc.Foundation.Data...VN +│ │╎│ 0x100004b58 sub x1, x29, 0x80 +│ │╎│ 0x100004b5c mov x0, x28 +│ │╎│ 0x100004b60 mov x3, x27 +│ │╎│ 0x100004b64 ldur x27, [x29, -0x100] +│ │╎│ 0x100004b68 mov x20, x27 +│ │╎│ 0x100004b6c bl sym CryptoKit.P256.Signing.PublicKey.isValidSignature.for.ECDSASignature.Foundation.DataProtocol...lF ; sym.imp.CryptoKit.P256.Signing.PublicKey.isValidSignature.for.ECDSASignature.Foundation.DataProtocol...lF +│ │╎│ 0x100004b70 mov x26, x0 +│ │╎│ 0x100004b74 stp xzr, x25, [x29, -0x80] +│ │╎│ 0x100004b78 sub x20, x29, 0x80 +│ │╎│ 0x100004b7c mov w0, 0x49 ; 'I' +│ │╎│ 0x100004b80 bl sym _StringGuts.grow...SiF ; sym.imp._StringGuts.grow...SiF +│ │╎│ 0x100004b84 ldp x8, x9, [x29, -0x80] +│ │╎│ 0x100004b88 stp x8, x9, [x29, -0x80] +│ │╎│ 0x100004b8c sub x20, x29, 0x80 +│ │╎│ 0x100004b90 mov x0, 0x724f ; 'Or' +│ │╎│ 0x100004b94 movk x0, 0x6769, lsl 16 ; 'ig' +│ │╎│ 0x100004b98 movk x0, 0x6e69, lsl 32 ; 'in' +│ │╎│ 0x100004b9c movk x0, 0x6c61, lsl 48 ; 'al' +│ │╎│ 0x100004ba0 mov x1, 0x203a ; ': ' +│ │╎│ 0x100004ba4 movk x1, 0xea00, lsl 48 +│ │╎│ 0x100004ba8 bl sym append...ySSF ; sym.imp.append...ySSF +│ │╎│ 0x100004bac ldur x20, [x29, -0xc0] +│ │╎│ 0x100004bb0 mov x8, x20 +│ │╎│ 0x100004bb4 bl sym Foundation...8EncodingV4utf8ACvgZ ; sym.imp.Foundation...8EncodingV4utf8ACvgZ +│ │╎│ 0x100004bb8 mov x0, x23 +│ │╎│ 0x100004bbc mov x1, x24 +│ │╎│ 0x100004bc0 mov x2, x20 +│ │╎│ 0x100004bc4 bl sym Foundation__String...AAE8EncodingVtcfC ; sym.imp.Foundation__String...AAE8EncodingVtcfC +│ ┌────< 0x100004bc8 cbz x1, 0x100004dc8 +│ ││╎│ 0x100004bcc mov x23, x27 +│ ││╎│ 0x100004bd0 mov x24, x1 +│ ││╎│ 0x100004bd4 adrp x8, 0x100007000 +│ ││╎│ 0x100004bd8 add x8, x8, 0xf60 ; 0x100007f60 ; "Signature is invalid." +│ ││╎│ 0x100004bdc sub x8, x8, 0x20 +│ ││╎│ 0x100004be0 orr x8, x8, 0x8000000000000000 +│ ││╎│ 0x100004be4 adrp x9, 0x100007000 +│ ││╎│ 0x100004be8 add x9, x9, 0xfe0 ; 0x100007fe0 ; "Signature is valid." +│ ││╎│ 0x100004bec sub x9, x9, 0x20 +│ ││╎│ 0x100004bf0 orr x9, x9, 0x8000000000000000 +│ ││╎│ 0x100004bf4 tst w26, 1 +│ ││╎│ 0x100004bf8 csel x26, x9, x8, ne +│ ││╎│ 0x100004bfc mov x27, 0x13 +│ ││╎│ 0x100004c00 movk x27, 0xd000, lsl 48 +│ ││╎│ 0x100004c04 add x8, x27, 2 +│ ││╎│ 0x100004c08 csel x8, x27, x8, ne +│ ││╎│ 0x100004c0c stur x8, [x29, -0xc0] +│ ││╎│ 0x100004c10 sub x20, x29, 0x80 +│ ││╎│ 0x100004c14 bl sym append...ySSF ; sym.imp.append...ySSF +│ ││╎│ 0x100004c18 mov x0, x24 ; void *arg0 +│ ││╎│ 0x100004c1c bl sym.imp.swift_bridgeObjectRelease ; void swift_bridgeObjectRelease(void *arg0) +│ ││╎│ 0x100004c20 add x0, x27, 1 +│ ││╎│ 0x100004c24 adrp x8, 0x100007000 +│ ││╎│ 0x100004c28 add x8, x8, 0xf80 ; 0x100007f80 ; "\n\nPublic Key (Hex): " +│ ││╎│ 0x100004c2c sub x8, x8, 0x20 +│ ││╎│ 0x100004c30 orr x1, x8, 0x8000000000000000 +│ ││╎│ 0x100004c34 sub x20, x29, 0x80 +│ ││╎│ 0x100004c38 bl sym append...ySSF ; sym.imp.append...ySSF +│ ││╎│ 0x100004c3c mov x20, x23 +│ ││╎│ 0x100004c40 bl sym CryptoKit.P256.Signing.PublicKey.rawRepresentation.Foundation.Data...Vvg ; sym.imp.CryptoKit.P256.Signing.PublicKey.rawRepresentation.Foundation.Data...Vvg +│ ││╎│ 0x100004c44 mov x20, x0 +│ ││╎│ 0x100004c48 mov x24, x1 +│ ││╎│ 0x100004c4c bl sym.func.100004000 +│ ││╎│ 0x100004c50 mov x21, x0 +│ ││╎│ 0x100004c54 mov x0, x20 ; void *arg0 +│ ││╎│ 0x100004c58 mov x1, x24 ; int64_t arg2 +│ ││╎│ 0x100004c5c bl sym.func.100004f58 +│ ││╎│ 0x100004c60 stur x21, [x29, -0x98] +│ ││╎│ 0x100004c64 sub x20, x29, 0x98 +│ ││╎│ 0x100004c68 mov x0, 0 +│ ││╎│ 0x100004c6c mov x1, -0x2000000000000000 +│ ││╎│ 0x100004c70 sub x8, x29, 0x28 +│ ││╎│ 0x100004c74 ldur x2, [x8, -0x100] +│ ││╎│ 0x100004c78 sub x8, x29, 0x30 +│ ││╎│ 0x100004c7c ldur x3, [x8, -0x100] +│ ││╎│ 0x100004c80 bl sym Element...F ; sym.imp.Element...F +│ ││╎│ 0x100004c84 mov x24, x0 +│ ││╎│ 0x100004c88 mov x25, x1 +│ ││╎│ 0x100004c8c mov x0, x21 ; void *arg0 +│ ││╎│ 0x100004c90 bl sym.imp.swift_bridgeObjectRelease ; void swift_bridgeObjectRelease(void *arg0) +│ ││╎│ 0x100004c94 sub x20, x29, 0x80 +│ ││╎│ 0x100004c98 mov x0, x24 +│ ││╎│ 0x100004c9c mov x1, x25 +│ ││╎│ 0x100004ca0 bl sym append...ySSF ; sym.imp.append...ySSF +│ ││╎│ 0x100004ca4 mov x0, x25 ; void *arg0 +│ ││╎│ 0x100004ca8 bl sym.imp.swift_bridgeObjectRelease ; void swift_bridgeObjectRelease(void *arg0) +│ ││╎│ 0x100004cac adrp x8, 0x100007000 +│ ││╎│ 0x100004cb0 add x8, x8, 0xfa0 ; 0x100007fa0 ; "\n\nSignature (Hex): " +│ ││╎│ 0x100004cb4 sub x8, x8, 0x20 +│ ││╎│ 0x100004cb8 orr x1, x8, 0x8000000000000000 +│ ││╎│ 0x100004cbc sub x20, x29, 0x80 +│ ││╎│ 0x100004cc0 mov x0, 0x13 +│ ││╎│ 0x100004cc4 movk x0, 0xd000, lsl 48 +│ ││╎│ 0x100004cc8 bl sym append...ySSF ; sym.imp.append...ySSF +│ ││╎│ 0x100004ccc sub x20, x29, 0x80 +│ ││╎│ 0x100004cd0 sub x8, x29, 0x20 +│ ││╎│ 0x100004cd4 ldur x0, [x8, -0x100] +│ ││╎│ 0x100004cd8 sub x8, x29, 0x18 +│ ││╎│ 0x100004cdc ldur x24, [x8, -0x100] +│ ││╎│ 0x100004ce0 mov x1, x24 +│ ││╎│ 0x100004ce4 bl sym append...ySSF ; sym.imp.append...ySSF +│ ││╎│ 0x100004ce8 sub x0, x27, 3 +│ ││╎│ 0x100004cec adrp x8, 0x100007000 +│ ││╎│ 0x100004cf0 add x8, x8, 0xfc0 ; 0x100007fc0 ; "\n\nVerification: " +│ ││╎│ 0x100004cf4 sub x8, x8, 0x20 +│ ││╎│ 0x100004cf8 orr x1, x8, 0x8000000000000000 +│ ││╎│ 0x100004cfc sub x20, x29, 0x80 +│ ││╎│ 0x100004d00 bl sym append...ySSF ; sym.imp.append...ySSF +│ ││╎│ 0x100004d04 sub x20, x29, 0x80 +│ ││╎│ 0x100004d08 ldur x0, [x29, -0xc0] +│ ││╎│ 0x100004d0c mov x1, x26 +│ ││╎│ 0x100004d10 bl sym append...ySSF ; sym.imp.append...ySSF +│ ││╎│ 0x100004d14 ldp x8, x21, [x29, -0x80] +│ ││╎│ 0x100004d18 ldur x10, [x29, -0xb0] +│ ││╎│ 0x100004d1c ldur x9, [x29, -0xa8] +│ ││╎│ 0x100004d20 stp x10, x9, [x29, -0x80] +│ ││╎│ 0x100004d24 ldur x9, [x29, -0xa0] +│ ││╎│ 0x100004d28 stur x9, [x29, -0x70] +│ ││╎│ 0x100004d2c stp x8, x21, [x29, -0x98] +│ ││╎│ 0x100004d30 mov x0, x21 ; void *arg0 +│ ││╎│ 0x100004d34 bl sym.imp.swift_bridgeObjectRetain ; void *swift_bridgeObjectRetain(void *arg0) +│ ││╎│ 0x100004d38 adrp x0, segment.__DATA ; 0x100010000 +│ ││╎│ 0x100004d3c add x0, x0, 0x108 ; int64_t arg1 +│ ││╎│ 0x100004d40 bl sym.func.100004e0c +│ ││╎│ 0x100004d44 mov x1, x0 +│ ││╎│ 0x100004d48 sub x0, x29, 0x98 +│ ││╎│ 0x100004d4c sub x20, x29, 0x80 +│ ││╎│ 0x100004d50 bl sym SwiftUI.State.wrappedValue...s ; sym.imp.SwiftUI.State.wrappedValue...s +│ ││╎│ 0x100004d54 ldp x8, x1, [x29, -0xe0] +│ ││╎│ 0x100004d58 ldr x8, [x8, 8] +│ ││╎│ 0x100004d5c mov x0, x28 +│ ││╎│ 0x100004d60 blr x8 +│ ││╎│ 0x100004d64 ldp x8, x1, [x29, -0xf8] +│ ││╎│ 0x100004d68 ldr x8, [x8, 8] +│ ││╎│ 0x100004d6c mov x0, x23 +│ ││╎│ 0x100004d70 blr x8 +│ ││╎│ 0x100004d74 sub x8, x29, 0x10 +│ ││╎│ 0x100004d78 ldur x8, [x8, -0x100] +│ ││╎│ 0x100004d7c ldr x8, [x8, 8] +│ ││╎│ 0x100004d80 ldur x0, [x29, -0xe8] +│ ││╎│ 0x100004d84 sub x9, x29, 8 +│ ││╎│ 0x100004d88 ldur x1, [x9, -0x100] +│ ││╎│ 0x100004d8c blr x8 +│ ││╎│ 0x100004d90 mov x0, x24 ; void *arg0 +│ ││╎│ 0x100004d94 bl sym.imp.swift_bridgeObjectRelease ; void swift_bridgeObjectRelease(void *arg0) +│ ││╎│ 0x100004d98 mov x0, x26 ; void *arg0 +│ ││╎│ 0x100004d9c bl sym.imp.swift_bridgeObjectRelease ; void swift_bridgeObjectRelease(void *arg0) +│ ││╎│ 0x100004da0 mov x0, x21 ; void *arg0 +│ ││╎│ 0x100004da4 bl sym.imp.swift_bridgeObjectRelease ; void swift_bridgeObjectRelease(void *arg0) +│ ││╎│ 0x100004da8 ldp x0, x1, [x29, -0xd0] ; int64_t arg2 +│ ││╎│ 0x100004dac bl sym.func.100005064 +│ ││└──< 0x100004db0 b 0x100004998 +│ ││ │ ; CODE XREF from sym.func.1000046dc @ 0x100004a64(x) +│ ││ └─> 0x100004db4 ldur x0, [x29, -0xa8] ; void *arg0 +│ ││ 0x100004db8 bl sym.imp.swift_bridgeObjectRelease ; void swift_bridgeObjectRelease(void *arg0) +│ ││ 0x100004dbc ldur x0, [x29, -0xa0] ; void *arg0 +│ ││ 0x100004dc0 bl sym.imp.swift_release ; void swift_release(void *arg0) +│ ││ 0x100004dc4 brk 1 +│ ││ ; CODE XREF from sym.func.1000046dc @ 0x100004bc8(x) +│ └────> 0x100004dc8 ldur x0, [x29, -0xa8] ; void *arg0 +│ │ 0x100004dcc bl sym.imp.swift_bridgeObjectRelease ; void swift_bridgeObjectRelease(void *arg0) +│ │ 0x100004dd0 ldur x0, [x29, -0xa0] ; void *arg0 +│ │ 0x100004dd4 bl sym.imp.swift_release ; void swift_release(void *arg0) +│ │ 0x100004dd8 brk 1 +│ │ ; CODE XREF from sym.func.1000046dc @ 0x100004aac(x) +│ └───> 0x100004ddc ldur x0, [x29, -0xa8] ; void *arg0 +│ 0x100004de0 bl sym.imp.swift_bridgeObjectRelease ; void swift_bridgeObjectRelease(void *arg0) +│ 0x100004de4 ldur x0, [x29, -0xa0] ; void *arg0 +│ 0x100004de8 bl sym.imp.swift_release ; void swift_release(void *arg0) +│ 0x100004dec adrp x1, 0x100007000 +│ 0x100004df0 add x1, x1, 0xf40 ; 0x100007f40 ; "MASTestApp/MastgTest.swift" +│ 0x100004df4 mov x0, x21 ; void *arg0 +│ 0x100004df8 mov w2, 0x1a +│ 0x100004dfc mov w3, 1 +│ 0x100004e00 mov w4, 0x1b +│ 0x100004e04 bl sym.imp.swift_unexpectedError ; void swift_unexpectedError(void *arg0) +└ 0x100004e08 brk 1 diff --git a/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/key.asm b/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/key.asm new file mode 100644 index 0000000000..e5d3c64ff4 --- /dev/null +++ b/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/key.asm @@ -0,0 +1,3 @@ +- offset - C8C9 CACB CCCD CECF D0D1 D2D3 D4D5 D6D7 89ABCDEF01234567 +0x1000100c8 7c02 2a7e 537e 1a2d 4477 d4f6 208b 14db |.*~S~.-Dw.. ... +0x1000100d8 4e8d 8419 d623 5ff2 4e4b 8d18 f42c 76e2 N....#_.NK...,v. diff --git a/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/output.asm b/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/output.asm new file mode 100644 index 0000000000..5be6139d99 --- /dev/null +++ b/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/output.asm @@ -0,0 +1,30 @@ +Uses of CryptoKit.P256.Signing.PrivateKey: +0x100007364 1 12 sym.imp.CryptoKit.P256.Signing.PrivateKey.public...F0AE06PublicF0Vvg.Public...F0Vvg...Vvg +0x100007370 1 12 sym.imp.CryptoKit.P256.Signing.PrivateKey.rawRepresentation.Foundation.ContiguousBytes...lufC +0x10000737c 1 12 sym.imp.CryptoKit.P256.Signing.PrivateKey.signature.for.ECDSASignature.Foundation.DataProtocol...lF +0x100007388 1 12 sym.imp.CryptoKit.P256.Signing.PrivateKey...VMa + +xrefs to sym.imp.CryptoKit.P256.Signing.PrivateKey...VMa: +sym.func.1000046dc 0x1000047f0 [CALL:--x] bl sym.imp.CryptoKit.P256.Signing.PrivateKey...VMa + +Use of sym.imp.CryptoKit.P256.Signing.PrivateKey: +│ 0x1000048b0 mov x1, x19 +│ 0x1000048b4 bl sym.func.100004ed4 +│ 0x1000048b8 adrp x1, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000 +│ 0x1000048bc ldr x1, [x1, 0x38] ; 0x10000c038 +│ ; reloc.Foundation.Data...VN +│ 0x1000048c0 adrp x2, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000 +│ 0x1000048c4 ldr x2, [x2, 0x30] ; 0x10000c030 +│ ; reloc.Foundation.Data...VAA15ContiguousBytesAAWP.ContiguousBytes...WP +│ 0x1000048c8 sub x0, x29, 0x80 +│ 0x1000048cc mov x8, x20 +│ 0x1000048d0 mov x21, 0 +│ 0x1000048d4 bl sym CryptoKit.P256.Signing.PrivateKey.rawRepresentation.Foundation.ContiguousBytes...lufC ; sym.imp.CryptoKit.P256.Signing.PrivateKey.rawRepresentation.Foundation.ContiguousBytes...lufC +│ ┌─< 0x1000048d8 cbz x21, 0x100004900 +│ │ 0x1000048dc mov x0, x21 +│ │ 0x1000048e0 bl sym.imp.swift_errorRelease +│ │ 0x1000048e4 ldr x8, [x28, 0x38] +│ │ 0x1000048e8 mov x0, x20 +│ │ 0x1000048ec mov w1, 1 +│ │ 0x1000048f0 mov w2, 1 +│ │ 0x1000048f4 mov x3, x23 diff --git a/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/output.txt b/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/output.txt deleted file mode 100644 index 84ee928ced..0000000000 --- a/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/output.txt +++ /dev/null @@ -1,222 +0,0 @@ -[0x10000aae0]> afl~P256.Signing.PrivateKey -0x10000aeac 1 12 sym.imp.CryptoKit.P256.Signing.PrivateKey.rawRepresentation.Foundation.ContiguousBytes...lufC -0x10000aeb8 1 12 sym.imp.CryptoKit.P256.Signing.PrivateKey...VMa - -[0x10000aae0]> axt @ 0x10000aeac -sym.func.1000086dc 0x1000087f8 [CALL:--x] bl sym.imp.CryptoKit.P256.Signing.PrivateKey.rawRepresentation.Foundation.ContiguousBytes...lufC - -[0x10000aae0]> pdf @ sym.func.1000086dc - ; CALL XREF from sym.func.100009a34 @ 0x100009a6c(x) -┌ 720: sym.func.1000086dc (int64_t arg1, int64_t arg2, int64_t arg3, int64_t arg_10h, int64_t arg_20h, int64_t arg_30h, int64_t arg_40h, int64_t arg_50h); -│ 0x1000086dc stp x28, x27, [sp, -0x60]! -│ 0x1000086e0 stp x26, x25, [var_0hx10] -│ 0x1000086e4 stp x24, x23, [var_0hx20] -│ 0x1000086e8 stp x22, x21, [var_0hx30] -│ 0x1000086ec stp x20, x19, [var_60h] -│ 0x1000086f0 stp x29, x30, [arg_50h] -│ 0x1000086f4 add x29, sp, 0x50 -│ 0x1000086f8 sub sp, sp, 0x40 -│ 0x1000086fc mov x19, x2 ; arg3 -│ 0x100008700 mov x22, x1 ; arg2 -│ 0x100008704 mov x23, x0 ; arg1 -│ 0x100008708 mov x27, 0x13 -│ 0x10000870c movk x27, 0xd000, lsl 48 -│ 0x100008710 adrp x0, segment.__DATA ; 0x100010000 -│ 0x100008714 add x0, x0, 0xe8 ; int64_t arg1 -│ 0x100008718 bl sym.func.1000089ac -│ 0x10000871c ldur x8, [x0, -8] -│ 0x100008720 ldr x8, [x8, 0x40] -│ 0x100008724 mov x9, x8 -│ 0x100008728 adrp x16, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000 -│ 0x10000872c ldr x16, reloc.__chkstk_darwin ; 0x10000c358 -│ 0x100008730 blr x16 -│ 0x100008734 mov x9, sp -│ 0x100008738 add x8, x8, 0xf -│ 0x10000873c and x8, x8, 0xfffffffffffffff0 -│ 0x100008740 sub x20, x9, x8 -│ 0x100008744 mov sp, x20 -│ 0x100008748 adrp x0, segment.__DATA ; 0x100010000 -│ 0x10000874c add x0, x0, 0xf0 ; int64_t arg1 -│ 0x100008750 bl sym.func.1000089ac -│ 0x100008754 adrp x1, segment.__DATA ; 0x100010000 -│ 0x100008758 add x1, x1, 0xa8 -│ 0x10000875c bl sym.imp.swift_initStaticObject -│ 0x100008760 mov x21, x0 -│ 0x100008764 adrp x24, segment.__DATA ; 0x100010000 -│ 0x100008768 add x24, x24, 0xf8 -│ 0x10000876c mov x0, x24 ; int64_t arg1 -│ 0x100008770 bl sym.func.1000089ac -│ 0x100008774 mov x25, x0 -│ 0x100008778 stur x0, [x29, -0x60] -│ 0x10000877c adrp x0, segment.__DATA ; 0x100010000 -│ 0x100008780 add x0, x0, 0x100 ; int64_t arg1 -│ 0x100008784 adrp x2, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000 -│ 0x100008788 ldr x2, reloc.Foundation.ContiguousBytes.UInt8...szlMc ; 0x10000c310 ; int64_t arg3 -│ 0x10000878c mov x1, x24 ; int64_t arg2 -│ 0x100008790 bl sym.func.100008b3c -│ 0x100008794 stur x0, [x29, -0x58] -│ 0x100008798 stur x21, [x29, -0x78] -│ 0x10000879c sub x0, x29, 0x78 ; int64_t arg1 -│ 0x1000087a0 mov x1, x25 ; int64_t arg2 -│ 0x1000087a4 bl sym.func.100008a30 -│ 0x1000087a8 ldr x8, [x0] -│ 0x1000087ac add x0, x8, 0x20 ; int64_t arg1 -│ 0x1000087b0 ldr x8, [x8, 0x10] -│ 0x1000087b4 add x1, x0, x8 ; int64_t arg2 -│ 0x1000087b8 bl sym.func.100008674 -│ 0x1000087bc mov x25, x0 -│ 0x1000087c0 mov x24, x1 -│ 0x1000087c4 sub x0, x29, 0x78 ; int64_t arg1 -│ 0x1000087c8 bl sym.func.100008a54 -│ 0x1000087cc stp x25, x24, [x29, -0x78] -│ 0x1000087d0 mov x0, x25 ; int64_t arg2 -│ 0x1000087d4 mov x1, x24 -│ 0x1000087d8 bl sym.func.100008a74 -│ 0x1000087dc adrp x1, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000 -│ 0x1000087e0 ldr x1, [x1, 0x30] ; 0x10000c030 -│ ; reloc.Foundation.Data...VN -│ 0x1000087e4 adrp x2, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000 -│ 0x1000087e8 ldr x2, [x2, 0x28] ; 0x10000c028 -│ ; reloc.Foundation.Data...VAA15ContiguousBytesAAWP.ContiguousBytes...WP -│ 0x1000087ec sub x0, x29, 0x78 -│ 0x1000087f0 mov x8, x20 -│ 0x1000087f4 mov x21, 0 -│ 0x1000087f8 bl sym CryptoKit.P256.Signing.PrivateKey.rawRepresentation.Foundation.ContiguousBytes...lufC ; sym.imp.CryptoKit.P256.Signing.PrivateKey.rawRepresentation.Foundation.ContiguousBytes...lufC -│ ┌─< 0x1000087fc cbz x21, 0x100008830 -│ │ 0x100008800 mov x0, x21 -│ │ 0x100008804 bl sym.imp.swift_errorRelease -│ │ 0x100008808 mov x0, 0 -│ │ 0x10000880c bl sym CryptoKit.P256.Signing.PrivateKey...VMa ; sym.imp.CryptoKit.P256.Signing.PrivateKey...VMa -│ │ 0x100008810 mov x3, x0 -│ │ 0x100008814 ldur x8, [x0, -8] -│ │ 0x100008818 ldr x8, [x8, 0x38] -│ │ 0x10000881c mov x0, x20 -│ │ 0x100008820 mov w1, 1 -│ │ 0x100008824 mov w2, 1 -│ │ 0x100008828 blr x8 -│ ┌──< 0x10000882c b 0x100008874 -│ ││ ; CODE XREF from sym.func.1000086dc @ 0x1000087fc(x) -│ │└─> 0x100008830 mov x0, 0 -│ │ 0x100008834 bl sym CryptoKit.P256.Signing.PrivateKey...VMa ; sym.imp.CryptoKit.P256.Signing.PrivateKey...VMa -│ │ 0x100008838 mov x26, x0 -│ │ 0x10000883c ldur x28, [x0, -8] -│ │ 0x100008840 ldr x8, [x28, 0x38] -│ │ 0x100008844 mov x0, x20 -│ │ 0x100008848 mov w1, 0 -│ │ 0x10000884c mov w2, 1 -│ │ 0x100008850 mov x3, x26 -│ │ 0x100008854 blr x8 -│ │ 0x100008858 ldr x8, [x28, 0x30] -│ │ 0x10000885c mov x0, x20 -│ │ 0x100008860 mov w1, 1 -│ │ 0x100008864 mov x2, x26 -│ │ 0x100008868 blr x8 -│ │ 0x10000886c cmp w0, 1 -│ │┌─< 0x100008870 b.ne 0x10000889c -│ ││ ; CODE XREF from sym.func.1000086dc @ 0x10000882c(x) -│ └──> 0x100008874 mov x0, x20 ; int64_t arg1 -│ │ 0x100008878 bl sym.func.100008ab8 -│ │ 0x10000887c stp x23, x22, [x29, -0x78] -│ │ 0x100008880 stur x19, [x29, -0x68] -│ │ 0x100008884 add x8, x27, 0xa -│ │ 0x100008888 adrp x9, 0x10000b000 -│ │ 0x10000888c add x9, x9, 0x9b0 ; 0x10000b9b0 ; "Failed to create private key." -│ │ 0x100008890 sub x9, x9, 0x20 -│ │ 0x100008894 orr x9, x9, 0x8000000000000000 -│ ┌──< 0x100008898 b 0x100008960 -│ ││ ; CODE XREF from sym.func.1000086dc @ 0x100008870(x) -│ │└─> 0x10000889c mov x0, x20 ; int64_t arg1 -│ │ 0x1000088a0 bl sym.func.100008ab8 -│ │ 0x1000088a4 mov x8, -0x2000000000000000 -│ │ 0x1000088a8 stp xzr, x8, [x29, -0x78] -│ │ 0x1000088ac sub x20, x29, 0x78 -│ │ 0x1000088b0 mov w0, 0x15 -│ │ 0x1000088b4 bl sym _StringGuts.grow...SiF ; sym.imp._StringGuts.grow...SiF -│ │ 0x1000088b8 ldur x0, [x29, -0x70] ; void *arg0 -│ │ 0x1000088bc bl sym.imp.swift_bridgeObjectRelease ; void swift_bridgeObjectRelease(void *arg0) -│ │ 0x1000088c0 adrp x8, 0x10000b000 -│ │ 0x1000088c4 add x8, x8, 0x9d0 ; 0x10000b9d0 ; "Private Key (Hex): " -│ │ 0x1000088c8 sub x8, x8, 0x20 -│ │ 0x1000088cc orr x8, x8, 0x8000000000000000 -│ │ 0x1000088d0 stp x27, x8, [x29, -0x78] -│ │ 0x1000088d4 mov x0, x25 ; int64_t arg1 -│ │ 0x1000088d8 mov x1, x24 ; int64_t arg2 -│ │ 0x1000088dc bl sym.func.100008000 -│ │ 0x1000088e0 mov x21, x0 -│ │ 0x1000088e4 stur x0, [x29, -0x90] -│ │ 0x1000088e8 adrp x20, segment.__DATA ; 0x100010000 -│ │ 0x1000088ec add x20, x20, 0x110 -│ │ 0x1000088f0 mov x0, x20 ; int64_t arg1 -│ │ 0x1000088f4 bl sym.func.1000089ac -│ │ 0x1000088f8 mov x26, x0 -│ │ 0x1000088fc adrp x0, segment.__DATA ; 0x100010000 -│ │ 0x100008900 add x0, x0, 0x118 ; int64_t arg1 -│ │ 0x100008904 adrp x2, reloc.Foundation.__DataStorage.bytes.allocator...itcfc ; 0x10000c000 -│ │ 0x100008908 ldr x2, reloc....SayxGSKsMc ; 0x10000c318 ; int64_t arg3 -│ │ 0x10000890c mov x1, x20 ; int64_t arg2 -│ │ 0x100008910 bl sym.func.100008b3c -│ │ 0x100008914 mov x3, x0 -│ │ 0x100008918 sub x20, x29, 0x90 -│ │ 0x10000891c mov x0, 0 -│ │ 0x100008920 mov x1, -0x2000000000000000 -│ │ 0x100008924 mov x2, x26 -│ │ 0x100008928 bl sym Element...F ; sym.imp.Element...F -│ │ 0x10000892c mov x26, x0 -│ │ 0x100008930 mov x27, x1 -│ │ 0x100008934 mov x0, x21 ; void *arg0 -│ │ 0x100008938 bl sym.imp.swift_bridgeObjectRelease ; void swift_bridgeObjectRelease(void *arg0) -│ │ 0x10000893c sub x20, x29, 0x78 -│ │ 0x100008940 mov x0, x26 -│ │ 0x100008944 mov x1, x27 -│ │ 0x100008948 bl sym append...ySSF ; sym.imp.append...ySSF -│ │ 0x10000894c mov x0, x27 ; void *arg0 -│ │ 0x100008950 bl sym.imp.swift_bridgeObjectRelease ; void swift_bridgeObjectRelease(void *arg0) -│ │ 0x100008954 ldp x8, x9, [x29, -0x78] -│ │ 0x100008958 stp x23, x22, [x29, -0x78] -│ │ 0x10000895c stur x19, [x29, -0x68] -│ │ ; CODE XREF from sym.func.1000086dc @ 0x100008898(x) -│ └──> 0x100008960 stp x8, x9, [x29, -0x90] -│ 0x100008964 adrp x0, segment.__DATA ; 0x100010000 -│ 0x100008968 add x0, x0, 0x108 ; int64_t arg1 -│ 0x10000896c bl sym.func.1000089ac -│ 0x100008970 mov x1, x0 -│ 0x100008974 sub x0, x29, 0x90 -│ 0x100008978 sub x20, x29, 0x78 -│ 0x10000897c bl sym SwiftUI.State.wrappedValue...s ; sym.imp.SwiftUI.State.wrappedValue...s -│ 0x100008980 mov x0, x25 ; void *arg0 -│ 0x100008984 mov x1, x24 ; int64_t arg2 -│ 0x100008988 bl sym.func.100008af8 -│ 0x10000898c sub sp, x29, 0x50 -│ 0x100008990 ldp x29, x30, [arg_50h] -│ 0x100008994 ldp x20, x19, [var_60h] -│ 0x100008998 ldp x22, x21, [var_0hx30] -│ 0x10000899c ldp x24, x23, [var_0hx20] -│ 0x1000089a0 ldp x26, x25, [var_0hx10] -│ 0x1000089a4 ldp x28, x27, [sp], 0x60 -└ 0x1000089a8 ret - - -[0x10000aae0]> px 256 @ 0x100010000 -- offset - 0 1 2 3 4 5 6 7 8 9 A B C D E F 0123456789ABCDEF -0x100010000 8100 0000 2800 0000 2800 0000 0000 0000 ....(...(....... -0x100010010 0000 0000 0000 0000 20ba 0000 0000 9000 ........ ....... -0x100010020 0000 0000 0000 0000 0000 0000 0000 0000 ................ -0x100010030 0000 0000 0000 0000 0000 0000 0000 0000 ................ -0x100010040 0000 0000 0000 0000 8000 0000 1000 0000 ................ -0x100010050 1000 0000 0000 0000 0000 0000 0000 0000 ................ -0x100010060 20ba 0000 0000 6000 0000 0000 0000 0000 .....`......... -0x100010070 0000 0000 0000 0000 0000 0000 0000 0000 ................ -0x100010080 0000 0000 0000 0000 0000 0000 0000 0000 ................ -0x100010090 c8bb 0000 0000 1000 9400 0000 0000 a083 ................ -0x1000100a0 0000 0000 0000 0000 0000 0000 0000 0000 ................ -0x1000100b0 0000 0000 0000 0000 2000 0000 0000 0000 ........ ....... -0x1000100c0 4000 0000 0000 0000 7c02 2a7e 537e 1a2d @.......|.*~S~.- -0x1000100d0 4477 d4f6 208b 14db 4e8d 8419 d623 5ff2 Dw.. ...N....#_. -0x1000100e0 4e4b 8d18 f42c 76e2 7cb0 ffff f9ff ffff NK...,v.|....... -0x1000100f0 7cb0 ffff f4ff ffff 82b0 ffff f7ff ffff |............... - - -[0x10000aae0]> px 32 @ 0x1000100c8 -- offset - C8C9 CACB CCCD CECF D0D1 D2D3 D4D5 D6D7 89ABCDEF01234567 -0x1000100c8 7c02 2a7e 537e 1a2d 4477 d4f6 208b 14db |.*~S~.-Dw.. ... -0x1000100d8 4e8d 8419 d623 5ff2 4e4b 8d18 f42c 76e2 N....#_.NK...,v. \ No newline at end of file diff --git a/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/run.sh b/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/run.sh old mode 100644 new mode 100755 index abd7676937..18d8db679d --- a/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/run.sh +++ b/demos/ios/MASVS-CRYPTO/MASTG-DEMO-0014/run.sh @@ -1 +1 @@ -r2 -q -i cryptokit_hardcoded_rsa.r2 -A MASTestApp +r2 -q -i cryptokit_hardcoded_ecdsa.r2 -A MASTestApp > output.asm diff --git a/tests-beta/ios/MASVS-CRYPTO/MASTG-TEST-0216.md b/tests-beta/ios/MASVS-CRYPTO/MASTG-TEST-0216.md index 2ab74629c6..b3e61bf72e 100644 --- a/tests-beta/ios/MASVS-CRYPTO/MASTG-TEST-0216.md +++ b/tests-beta/ios/MASVS-CRYPTO/MASTG-TEST-0216.md @@ -10,9 +10,9 @@ weakness: MASWE-0014 In this test case, we will examine iOS applications for the presence of hardcoded cryptographic keys. Hardcoded keys can be typically found in calls to cryptographic functions or stored as constants or variables within the code. In iOS, cryptographic keys are often used in the following frameworks: -- **Security Framework**: The [`SecKeyCreateWithData`](https://developer.apple.com/documentation/security/2977516-seckeycreatewithdata) function allows developers to create a cryptographic key from raw data. If developers hardcode this data within the app, it results in hardcoded cryptographic keys. -- **CommonCrypto**: The [`CCCrypt`](https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/CCCrypt.3cc.html) function is often used for symmetric encryption in iOS. Developers might mistakenly hardcode symmetric keys (like AES keys) in the app's source code. -- **CryptoKit**: Although `CryptoKit` provides higher-level abstractions for cryptographic operations, developers might still hardcode private keys or other sensitive data when using the [`P256.Signing.PrivateKey`](https://developer.apple.com/documentation/cryptokit/p256/signing/privatekey) or similar classes. +- **Security Framework**: The [`SecKeyCreateWithData`](https://developer.apple.com/documentation/security/2977516-seckeycreatewithdata) function allows developers to create a cryptographic key from raw data. +- **CommonCrypto**: The [`CCCrypt`](https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/CCCrypt.3cc.html) can be initialized with raw key data in its `key` parameter. +- **CryptoKit**: Although `CryptoKit` provides higher-level abstractions for cryptographic operations, developers might still hardcode cryptographic keys in different formats and feed it to methods like [`P256.Signing.PrivateKey.init(rawRepresentation:)`](https://developer.apple.com/documentation/cryptokit/p256/signing/privatekey/init(rawrepresentation:)) or similar. ## Steps @@ -20,11 +20,11 @@ In this test case, we will examine iOS applications for the presence of hardcode ## Observation -The output should include any instances where potential cryptographic keys are found hardcoded within the app binary. +The output should include any instances where the app uses cryptographic functions that accept raw key data. Whenever possible, the output should also try to point to the raw key data from the binary. ## Evaluation -The test fails if hardcoded cryptographic keys are found within the app binary. +The test fails if calls to cryptographic functions with hardcoded keys are found within binary. You may find the keys being directly passed as arguments to cryptographic functions (byte arrays or string literals) or stored in variables or constants within the code. Typical representations of hardcoded keys include: