1
1
mirror of https://github.com/wader/fq.git synced 2024-10-26 20:06:29 +03:00

caff: obfuscation key is a signed integer, add test data

The obfuscation key is actually a signed integer, and thanks to two's complement
arithmetic and sign extension, this is actually significant.
This commit is contained in:
Ronsor 2023-08-18 19:45:09 -07:00
parent 03ba71b67f
commit fa1157221b
3 changed files with 216 additions and 5 deletions

View File

@ -86,11 +86,11 @@ func decodeCAFF(d *decode.D) any {
var ci format.CAFF_In
d.ArgAs(&ci)
var obfsKey uint64
var obfsKey int64
obfsU8 := func(d *decode.D) uint64 { return d.U8() ^ (obfsKey & 0xff) }
obfsU32 := func(d *decode.D) uint64 { return d.U32() ^ (obfsKey & 0xffff_ffff) }
obfsU64 := func(d *decode.D) uint64 { return d.U64() ^ (obfsKey<<32 | obfsKey) }
obfsU8 := func(d *decode.D) uint64 { return d.U8() ^ uint64(obfsKey & 0xff) }
obfsU32 := func(d *decode.D) uint64 { return d.U32() ^ uint64(obfsKey & 0xffff_ffff) }
obfsU64 := func(d *decode.D) uint64 { return d.U64() ^ uint64(obfsKey<<32 | obfsKey) }
obfsBool := func(d *decode.D) bool { return obfsU8(d) != 0 }
// "Big Endian Base 128" - LEB128's strange sibling
@ -122,7 +122,7 @@ func decodeCAFF(d *decode.D) any {
d.FieldStruct("archive_version", decodeVersion)
d.FieldUTF8("format_id", 4)
d.FieldStruct("format_version", decodeVersion)
obfsKey = d.FieldU32("obfuscate_key")
obfsKey = d.FieldS32("obfuscate_key")
d.SeekRel(8 * 8)
d.FieldStruct("preview_image", func(d *decode.D) {

BIN
format/caff/testdata/test.cmo3 vendored Executable file

Binary file not shown.

211
format/caff/testdata/test.cmo3.fqtest vendored Normal file
View File

@ -0,0 +1,211 @@
$ fq dv test.cmo3
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.{}: test.cmo3 (caff) 0x0-0x2268.7 (8809)
0x000000|43 41 46 46 |CAFF | archive_id: "CAFF" (valid) 0x0-0x3.7 (4)
| | | archive_version{}: 0x4-0x6.7 (3)
0x000000| 00 | . | major: 0 0x4-0x4.7 (1)
0x000000| 00 | . | minor: 0 0x5-0x5.7 (1)
0x000000| 00 | . | patch: 0 0x6-0x6.7 (1)
0x000000| 2d 2d 2d 2d | ---- | format_id: "----" 0x7-0xa.7 (4)
| | | format_version{}: 0xb-0xd.7 (3)
0x000000| 00 | . | major: 0 0xb-0xb.7 (1)
0x000000| 00 | . | minor: 0 0xc-0xc.7 (1)
0x000000| 00 | . | patch: 0 0xd-0xd.7 (1)
0x000000| af de| ..| obfuscate_key: -1344390416 0xe-0x11.7 (4)
0x000010|3a f0 |:. |
0x000010| 00 00 00 00 00 00 00 00 | ........ | gap0: raw bits 0x12-0x19.7 (8)
| | | preview_image{}: 0x1a-0x2d.7 (20)
0x000010| 7f | . | image_format: "no_preview" (127) 0x1a-0x1a.7 (1)
0x000010| 7f | . | color_type: "no_preview" (127) 0x1b-0x1b.7 (1)
0x000010| 00 00| ..| width: 0 0x1e-0x1f.7 (2)
0x000020|00 00 |.. | height: 0 0x20-0x21.7 (2)
0x000020| 00 00 00 00 00 00 00 00 | ........ | start_pos: 0 0x22-0x29.7 (8)
0x000020| 00 00 00 00 | .... | file_size: 0 0x2a-0x2d.7 (4)
0x000010| 00 00 | .. | gap1: raw bits 0x1c-0x1d.7 (2)
0x000020| 00 00| ..| gap2: raw bits 0x2e-0x35.7 (8)
0x000030|00 00 00 00 00 00 |...... |
0x000030| af de 3a f4 | ..:. | file_info_map_size: 4 0x36-0x39.7 (4)
| | | file_info_list[0:4]: 0x3a-0xc0.7 (135)
| | | [0]{}: file_info 0x3a-0x52.7 (25)
0x000030| f9 99 9d 91 97 95| ......| file_path: "image.png" 0x3a-0x43.7 (10)
0x000040|de 80 9e 97 |.... |
0x000040| f0 | . | tag: "" 0x44-0x44.7 (1)
0x000040| ff ff ff ff af de 3a 39 | ......:9 | start_pos: 201 0x45-0x4c.7 (8)
0x000040| af de 3a| ..:| file_size: 96 0x4d-0x50.7 (4)
0x000050|90 |. |
0x000050| f1 | . | is_obfuscated: true 0x51-0x51.7 (1)
0x000050| e0 | . | compress_option: "raw" (16) 0x52-0x52.7 (1)
| | | [1]{}: file_info 0x5b-0x75.7 (27)
0x000050| fb 99 9d 91 97| .....| file_path: "image_0.png" 0x5b-0x66.7 (12)
0x000060|95 af c0 de 80 9e 97 |....... |
0x000060| f0 | . | tag: "" 0x67-0x67.7 (1)
0x000060| ff ff ff ff af de 3b d9| ......;.| start_pos: 297 0x68-0x6f.7 (8)
0x000070|af de 3a a3 |..:. | file_size: 83 0x70-0x73.7 (4)
0x000070| f1 | . | is_obfuscated: true 0x74-0x74.7 (1)
0x000070| e0 | . | compress_option: "raw" (16) 0x75-0x75.7 (1)
| | | [2]{}: file_info 0x7e-0x98.7 (27)
0x000070| fb 99| ..| file_path: "image_1.png" 0x7e-0x89.7 (12)
0x000080|9d 91 97 95 af c1 de 80 9e 97 |.......... |
0x000080| f0 | . | tag: "" 0x8a-0x8a.7 (1)
0x000080| ff ff ff ff af| .....| start_pos: 380 0x8b-0x92.7 (8)
0x000090|de 3b 8c |.;. |
0x000090| af de 3a bb | ..:. | file_size: 75 0x93-0x96.7 (4)
0x000090| f1 | . | is_obfuscated: true 0x97-0x97.7 (1)
0x000090| e0 | . | compress_option: "raw" (16) 0x98-0x98.7 (1)
| | | [3]{}: file_info 0xa1-0xc0.7 (32)
0x0000a0| f8 9d 91 99 9e de 88 9d 9c | ......... | file_path: "main.xml" 0xa1-0xa9.7 (9)
0x0000a0| f8 9d 91 99 9e af| ......| tag: "main_xml" 0xaa-0xb2.7 (9)
0x0000b0|88 9d 9c |... |
0x0000b0| ff ff ff ff af de 3b 37 | ......;7 | start_pos: 455 0xb3-0xba.7 (8)
0x0000b0| af de 1a 50 | ...P | file_size: 8352 0xbb-0xbe.7 (4)
0x0000b0| f1| .| is_obfuscated: true 0xbf-0xbf.7 (1)
0x0000c0|d1 |. | compress_option: "fast" (33) 0xc0-0xc0.7 (1)
0x000050| 00 00 00 00 00 00 00 00 | ........ | gap3: raw bits 0x53-0x5a.7 (8)
0x000070| 00 00 00 00 00 00 00 00 | ........ | gap4: raw bits 0x76-0x7d.7 (8)
0x000090| 00 00 00 00 00 00 00| .......| gap5: raw bits 0x99-0xa0.7 (8)
0x0000a0|00 |. |
0x0000c0| 00 00 00 00 00 00 00 00 79 a0 be b7 fd fa ea| ........y......| gap6: raw bits 0xc1-0x2266.7 (8614)
0x0000d0|fa f0 f0 f0 fd b9 b8 b4 a2 f0 f0 f0 b0 f0 f0 f0|................|
* |until 0x2266.7 (8614) | |
| | | files[0:4]: 0xc9-0x1c6.7 (254)
| | | [0]{}: file 0xc9-NA (0)
| | | file_path: "image.png" 0xc9-NA (0)
| | | file_size: 96 0xc9-NA (0)
| | | is_obfuscated: true 0xc9-NA (0)
| | | compress_option: "raw" (16) 0xc9-NA (0)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| uncompressed{}: (png) 0x0-0x5f.7 (96)
0x0000|89 50 4e 47 0d 0a 1a 0a |.PNG.... | signature: raw bits (valid) 0x0-0x7.7 (8)
| | | chunks[0:3]: 0x8-0x5f.7 (88)
| | | [0]{}: chunk 0x8-0x20.7 (25)
0x0000| 00 00 00 0d | .... | length: 13 0x8-0xb.7 (4)
0x0000| 49 48 44 52| IHDR| type: "IHDR" 0xc-0xf.7 (4)
0x0000| 49 | I | ancillary: false 0xc.3-0xc.3 (0.1)
0x0000| 48 | H | private: false 0xd.3-0xd.3 (0.1)
0x0000| 44 | D | reserved: false 0xe.3-0xe.3 (0.1)
0x0000| 52| R| safe_to_copy: true 0xf.3-0xf.3 (0.1)
0x0001|00 00 00 40 |...@ | width: 64 0x10-0x13.7 (4)
0x0001| 00 00 00 40 | ...@ | height: 64 0x14-0x17.7 (4)
0x0001| 08 | . | bit_depth: 8 0x18-0x18.7 (1)
0x0001| 06 | . | color_type: "rgba" (6) 0x19-0x19.7 (1)
0x0001| 00 | . | compression_method: "deflate" (0) 0x1a-0x1a.7 (1)
0x0001| 00 | . | filter_method: "adaptive_filtering" (0) 0x1b-0x1b.7 (1)
0x0001| 00 | . | interlace_method: "none" (0) 0x1c-0x1c.7 (1)
0x0001| aa 69 71| .iq| crc: 0xaa6971de (valid) 0x1d-0x20.7 (4)
0x0002|de |. |
| | | [1]{}: chunk 0x21-0x53.7 (51)
0x0002| 00 00 00 27 | ...' | length: 39 0x21-0x24.7 (4)
0x0002| 49 44 41 54 | IDAT | type: "IDAT" 0x25-0x28.7 (4)
0x0002| 49 | I | ancillary: false 0x25.3-0x25.3 (0.1)
0x0002| 44 | D | private: false 0x26.3-0x26.3 (0.1)
0x0002| 41 | A | reserved: false 0x27.3-0x27.3 (0.1)
0x0002| 54 | T | safe_to_copy: true 0x28.3-0x28.3 (0.1)
0x0002| 78 5e ed c1 01 0d 00| x^.....| data: raw bits 0x29-0x4f.7 (39)
0x0003|00 00 c2 a0 f7 4f 6d 0e 37 a0 00 00 00 00 00 00|.....Om.7.......|
0x0004|00 00 00 00 00 00 00 00 00 80 77 03 40 40 00 01|..........w.@@..|
0x0005|59 0a 7b 0c |Y.{. | crc: 0x590a7b0c (valid) 0x50-0x53.7 (4)
| | | [2]{}: chunk 0x54-0x5f.7 (12)
0x0005| 00 00 00 00 | .... | length: 0 0x54-0x57.7 (4)
0x0005| 49 45 4e 44 | IEND | type: "IEND" 0x58-0x5b.7 (4)
0x0005| 49 | I | ancillary: false 0x58.3-0x58.3 (0.1)
0x0005| 45 | E | private: false 0x59.3-0x59.3 (0.1)
0x0005| 4e | N | reserved: false 0x5a.3-0x5a.3 (0.1)
0x0005| 44 | D | safe_to_copy: false 0x5b.3-0x5b.3 (0.1)
0x0005| ae 42 60 82| .B`.| crc: 0xae426082 (valid) 0x5c-0x5f.7 (4)
| | | [1]{}: file 0x129-NA (0)
| | | file_path: "image_0.png" 0x129-NA (0)
| | | file_size: 83 0x129-NA (0)
| | | is_obfuscated: true 0x129-NA (0)
| | | compress_option: "raw" (16) 0x129-NA (0)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| uncompressed{}: (png) 0x0-0x52.7 (83)
0x0000|89 50 4e 47 0d 0a 1a 0a |.PNG.... | signature: raw bits (valid) 0x0-0x7.7 (8)
| | | chunks[0:3]: 0x8-0x52.7 (75)
| | | [0]{}: chunk 0x8-0x20.7 (25)
0x0000| 00 00 00 0d | .... | length: 13 0x8-0xb.7 (4)
0x0000| 49 48 44 52| IHDR| type: "IHDR" 0xc-0xf.7 (4)
0x0000| 49 | I | ancillary: false 0xc.3-0xc.3 (0.1)
0x0000| 48 | H | private: false 0xd.3-0xd.3 (0.1)
0x0000| 44 | D | reserved: false 0xe.3-0xe.3 (0.1)
0x0000| 52| R| safe_to_copy: true 0xf.3-0xf.3 (0.1)
0x0001|00 00 00 20 |... | width: 32 0x10-0x13.7 (4)
0x0001| 00 00 00 20 | ... | height: 32 0x14-0x17.7 (4)
0x0001| 08 | . | bit_depth: 8 0x18-0x18.7 (1)
0x0001| 06 | . | color_type: "rgba" (6) 0x19-0x19.7 (1)
0x0001| 00 | . | compression_method: "deflate" (0) 0x1a-0x1a.7 (1)
0x0001| 00 | . | filter_method: "adaptive_filtering" (0) 0x1b-0x1b.7 (1)
0x0001| 00 | . | interlace_method: "none" (0) 0x1c-0x1c.7 (1)
0x0001| 73 7a 7a| szz| crc: 0x737a7af4 (valid) 0x1d-0x20.7 (4)
0x0002|f4 |. |
| | | [1]{}: chunk 0x21-0x46.7 (38)
0x0002| 00 00 00 1a | .... | length: 26 0x21-0x24.7 (4)
0x0002| 49 44 41 54 | IDAT | type: "IDAT" 0x25-0x28.7 (4)
0x0002| 49 | I | ancillary: false 0x25.3-0x25.3 (0.1)
0x0002| 44 | D | private: false 0x26.3-0x26.3 (0.1)
0x0002| 41 | A | reserved: false 0x27.3-0x27.3 (0.1)
0x0002| 54 | T | safe_to_copy: true 0x28.3-0x28.3 (0.1)
0x0002| 78 5e ed c1 01 01 00| x^.....| data: raw bits 0x29-0x42.7 (26)
0x0003|00 00 82 20 ff af 6e 48 40 01 00 00 00 ef 06 10|... ..nH@.......|
0x0004|20 00 01 | .. |
0x0004| 9f 22 b8 f9 | .".. | crc: 0x9f22b8f9 (valid) 0x43-0x46.7 (4)
| | | [2]{}: chunk 0x47-0x52.7 (12)
0x0004| 00 00 00 00 | .... | length: 0 0x47-0x4a.7 (4)
0x0004| 49 45 4e 44 | IEND | type: "IEND" 0x4b-0x4e.7 (4)
0x0004| 49 | I | ancillary: false 0x4b.3-0x4b.3 (0.1)
0x0004| 45 | E | private: false 0x4c.3-0x4c.3 (0.1)
0x0004| 4e | N | reserved: false 0x4d.3-0x4d.3 (0.1)
0x0004| 44 | D | safe_to_copy: false 0x4e.3-0x4e.3 (0.1)
0x0004| ae| .| crc: 0xae426082 (valid) 0x4f-0x52.7 (4)
0x0005|42 60 82| |B`.| |
| | | [2]{}: file 0x17c-NA (0)
| | | file_path: "image_1.png" 0x17c-NA (0)
| | | file_size: 75 0x17c-NA (0)
| | | is_obfuscated: true 0x17c-NA (0)
| | | compress_option: "raw" (16) 0x17c-NA (0)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef| uncompressed{}: (png) 0x0-0x4a.7 (75)
0x0000|89 50 4e 47 0d 0a 1a 0a |.PNG.... | signature: raw bits (valid) 0x0-0x7.7 (8)
| | | chunks[0:3]: 0x8-0x4a.7 (67)
| | | [0]{}: chunk 0x8-0x20.7 (25)
0x0000| 00 00 00 0d | .... | length: 13 0x8-0xb.7 (4)
0x0000| 49 48 44 52| IHDR| type: "IHDR" 0xc-0xf.7 (4)
0x0000| 49 | I | ancillary: false 0xc.3-0xc.3 (0.1)
0x0000| 48 | H | private: false 0xd.3-0xd.3 (0.1)
0x0000| 44 | D | reserved: false 0xe.3-0xe.3 (0.1)
0x0000| 52| R| safe_to_copy: true 0xf.3-0xf.3 (0.1)
0x0001|00 00 00 10 |.... | width: 16 0x10-0x13.7 (4)
0x0001| 00 00 00 10 | .... | height: 16 0x14-0x17.7 (4)
0x0001| 08 | . | bit_depth: 8 0x18-0x18.7 (1)
0x0001| 06 | . | color_type: "rgba" (6) 0x19-0x19.7 (1)
0x0001| 00 | . | compression_method: "deflate" (0) 0x1a-0x1a.7 (1)
0x0001| 00 | . | filter_method: "adaptive_filtering" (0) 0x1b-0x1b.7 (1)
0x0001| 00 | . | interlace_method: "none" (0) 0x1c-0x1c.7 (1)
0x0001| 1f f3 ff| ...| crc: 0x1ff3ff61 (valid) 0x1d-0x20.7 (4)
0x0002|61 |a |
| | | [1]{}: chunk 0x21-0x3e.7 (30)
0x0002| 00 00 00 12 | .... | length: 18 0x21-0x24.7 (4)
0x0002| 49 44 41 54 | IDAT | type: "IDAT" 0x25-0x28.7 (4)
0x0002| 49 | I | ancillary: false 0x25.3-0x25.3 (0.1)
0x0002| 44 | D | private: false 0x26.3-0x26.3 (0.1)
0x0002| 41 | A | reserved: false 0x27.3-0x27.3 (0.1)
0x0002| 54 | T | safe_to_copy: true 0x28.3-0x28.3 (0.1)
0x0002| 78 5e 63 60 18 05 a3| x^c`...| data: raw bits 0x29-0x3a.7 (18)
0x0003|60 14 8c 02 08 00 00 04 10 00 01 |`.......... |
0x0003| 66 c1 64 0b | f.d. | crc: 0x66c1640b (valid) 0x3b-0x3e.7 (4)
| | | [2]{}: chunk 0x3f-0x4a.7 (12)
0x0003| 00| .| length: 0 0x3f-0x42.7 (4)
0x0004|00 00 00 |... |
0x0004| 49 45 4e 44 | IEND | type: "IEND" 0x43-0x46.7 (4)
0x0004| 49 | I | ancillary: false 0x43.3-0x43.3 (0.1)
0x0004| 45 | E | private: false 0x44.3-0x44.3 (0.1)
0x0004| 4e | N | reserved: false 0x45.3-0x45.3 (0.1)
0x0004| 44 | D | safe_to_copy: false 0x46.3-0x46.3 (0.1)
0x0004| ae 42 60 82| | .B`.| | crc: 0xae426082 (valid) 0x47-0x4a.7 (4)
| | | [3]{}: file 0x1c7-NA (0)
| | | file_path: "main.xml" 0x1c7-NA (0)
| | | file_size: 8352 0x1c7-NA (0)
| | | is_obfuscated: true 0x1c7-NA (0)
| | | compress_option: "fast" (33) 0x1c7-NA (0)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
0x0000|50 4b 03 04 14 00 08 08 08 00 7b 9a 12 57 00 00|PK........{..W..| compressed: raw bits 0x0-0x209f.7 (8352)
* |until 0x209f.7 (end) (8352) | |
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
0x0000|3c 3f 78 6d 6c 20 76 65 72 73 69 6f 6e 3d 22 31|<?xml version="1| uncompressed: {} (xml) 0x0-0xfcd9.7 (64730)
* |until 0xfcd9.7 (end) (64730) | |
0x002260| 62 63| | bc| | guard_bytes: raw bits (valid) 0x2267-0x2268.7 (2)