📄 tmd.c
字号:
/* * Copyright (C) 2008 dhewg, #wiidev efnet * * this file is part of wiifuse * http://wiibrew.org/index.php?title=Wiifuse * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#include <stdlib.h>#include <stdio.h>#include "global.h"#include "io.h"#include "tmd.h"// TODO// this is a WIP, recheck the data structures and parse the whole cert chainvoid tmd_load (struct image_file *image, u32 part) { struct tmd *tmd; u64 certs_size, certs_offset, tmd_size, tmd_offset; enum tmd_sig sig = SIG_UNKNOWN; u64 off; u8 buffer[64]; u16 i, s; off = image->parts[part].offset; io_read (buffer, 16, image, off + 0x2a4); tmd_size = get_be32 (buffer); tmd_offset = get_be32 (&buffer[4]) * 4llu; certs_size = get_be32 (&buffer[8]); certs_offset = get_be32 (&buffer[12]) * 4llu; off += tmd_offset; io_read (buffer, 4, image, off); off += 4; switch (get_be32 (buffer)) { case 0x00010001: sig = SIG_RSA_2048; s = 0x100; break; case 0x00010000: sig = SIG_RSA_4096; s = 0x200; break; } if (sig == SIG_UNKNOWN) return; tmd = (struct tmd *) malloc (sizeof (struct tmd)); memset (tmd, 0, sizeof (struct tmd)); tmd->sig_type = sig; image->parts[part].certs_offset = certs_offset; image->parts[part].certs_size = certs_size; image->parts[part].tmd_offset = tmd_offset; image->parts[part].tmd_size = tmd_size; // TODO omg im so lazy image->parts[part].ticket_offset = 0; image->parts[part].ticket_size = 676; image->parts[part].tmd = tmd; tmd->sig = malloc (s); io_read (tmd->sig, s, image, off); off += s; off = ROUNDUP64B (off); io_read (tmd->issuer, 0x40, image, off); off += 0x40; io_read (buffer, 26, image, off); off += 26; tmd->version = buffer[0]; tmd->ca_crl_version = buffer[1]; tmd->signer_crl_version = buffer[2]; tmd->sys_version = get_be64 (&buffer[4]); tmd->title_id = get_be64 (&buffer[12]); tmd->title_type = get_be32 (&buffer[20]); tmd->group_id = get_be16 (&buffer[24]); off += 62; io_read (buffer, 10, image, off); off += 10; tmd->access_rights = get_be32 (buffer); tmd->title_version = get_be16 (&buffer[4]); tmd->num_contents = get_be16 (&buffer[6]); tmd->boot_index = get_be16 (&buffer[8]); off += 2; if (tmd->num_contents < 1) return; tmd->contents = (struct tmd_content *) malloc (sizeof (struct tmd_content) * tmd->num_contents); LOG (2, "tmd contents: 0x%08x", tmd->num_contents); for (i = 0; i < tmd->num_contents; ++i) { io_read (buffer, 0x30, image, off); off += 0x30; tmd->contents[i].cid = get_be32 (buffer); tmd->contents[i].index = get_be16 (&buffer[4]); tmd->contents[i].type = get_be16 (&buffer[6]); tmd->contents[i].size = get_be64 (&buffer[8]); memcpy (tmd->contents[i].hash, &buffer[16], 20); LOG (2, " cid: 0x%08x index: 0x%04x type: 0x%04x " "size: 0x%016llx", tmd->contents[i].cid, tmd->contents[i].index, tmd->contents[i].type, tmd->contents[i].size); } return;}void tmd_free (struct tmd *tmd) { if (tmd == NULL) return; if (tmd->sig) free (tmd->sig); if (tmd->contents) free (tmd->contents); free (tmd);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -