|
| 1 | +#pragma author gunjambi |
| 2 | +#pragma description "New" ASCII CPIO |
| 3 | +#pragma magic [ 30 37 30 37 30 31 ] @ 0x00 |
| 4 | + |
| 5 | +import std.time; |
| 6 | +import std.string; |
| 7 | + |
| 8 | +namespace new_ascii { |
| 9 | + fn format_hex_time(str value) { |
| 10 | + return std::time::format(std::time::to_utc(std::string::parse_int(value, 16))); |
| 11 | + }; |
| 12 | + fn parse_hex(str field) { |
| 13 | + return std::string::parse_int(field, 16); |
| 14 | + }; |
| 15 | + |
| 16 | + struct Cpio { |
| 17 | + char c_magic[6]; |
| 18 | + if (c_magic != "070701") { |
| 19 | + std::error("Invalid CPIO Magic!"); |
| 20 | + } |
| 21 | + |
| 22 | + char c_ino[8] [[format("new_ascii::parse_hex"), transform("new_ascii::parse_hex")]]; |
| 23 | + char c_mode[8]; |
| 24 | + char c_uid[8] [[format("new_ascii::parse_hex"), transform("new_ascii::parse_hex")]]; |
| 25 | + char c_gid[8] [[format("new_ascii::parse_hex"), transform("new_ascii::parse_hex")]]; |
| 26 | + char c_nlink[8] [[format("new_ascii::parse_hex"), transform("new_ascii::parse_hex")]]; |
| 27 | + char c_mtime[8] [[format("new_ascii::format_hex_time")]]; |
| 28 | + char c_filesize[8] [[format("new_ascii::parse_hex"), transform("new_ascii::parse_hex")]]; |
| 29 | + char c_devmajor[8] [[format("new_ascii::parse_hex"), transform("new_ascii::parse_hex")]]; |
| 30 | + char c_devminor[8] [[format("new_ascii::parse_hex"), transform("new_ascii::parse_hex")]]; |
| 31 | + char c_rdevmajor[8] [[format("new_ascii::parse_hex"), transform("new_ascii::parse_hex")]]; |
| 32 | + char c_rdevminor[8] [[format("new_ascii::parse_hex"), transform("new_ascii::parse_hex")]]; |
| 33 | + char c_namesize[8] [[format("new_ascii::parse_hex"), transform("new_ascii::parse_hex")]]; |
| 34 | + char c_check[8] [[format("new_ascii::parse_hex"), transform("new_ascii::parse_hex")]]; |
| 35 | + |
| 36 | + char filename[c_namesize - 1]; |
| 37 | + padding[1]; |
| 38 | + if (filename == "TRAILER!!!") |
| 39 | + break; |
| 40 | + padding[(4 - ((6 + c_namesize) % 4)) % 4]; |
| 41 | + |
| 42 | + u8 data[c_filesize]; |
| 43 | + padding[(4 - (c_filesize % 4)) % 4]; |
| 44 | + }; |
| 45 | +} |
| 46 | +new_ascii::Cpio cpio[while(true)] @ 0x00; |
0 commit comments