⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 io.c

📁 WiiFuse is a FUSE filesystem module for Linux and Mac OS X. It will let you mount a Wii disc ISO an
💻 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 <stdio.h>#include "io.h"int io_read (void *ptr, size_t size, struct image_file *image, u64 offset) {        size_t bytes;        if (fseeko (image->fp, offset, SEEK_SET)) {                perror ("io_seek");                return -1;        }        bytes = fread (ptr, 1, size, image->fp);        if (bytes != size)                perror ("io_read");        return bytes;}int decrypt_block (struct image_file *image, u32 part, u32 block) {        if (block == image->parts[part].cached_block)                return 0;        LOG (3, "decrypting part/block %u/%08x", part, block);        if (io_read (image->parts[part].dec_buffer, 0x8000, image,                     image->parts[part].offset +                     image->parts[part].data_offset + 0x8000ull * block)            != 0x8000) {                perror ("decrypt read");                return -1;        }        AES_cbc_encrypt (&image->parts[part].dec_buffer[0x400],                         image->parts[part].cache, 0x7c00,                         &image->parts[part].key,                         &image->parts[part].dec_buffer[0x3d0], 0);        image->parts[part].cached_block = block;        return 0;}size_t io_read_part (void *ptr, size_t size, struct image_file *image,                     u32 part, u64 offset) {        u32 block = offset / 0x7c00;        u32 cache_offset = offset % 0x7c00;        u32 cache_size;        void *dst = ptr;        if (!image->parts[part].is_encrypted)                return io_read (ptr, size, image,                                image->parts[part].offset + offset);        while (size) {                if (decrypt_block (image, part, block))                        return dst - ptr;                cache_size = size;                if (cache_size + cache_offset > 0x7c00)                        cache_size = 0x7c00 - cache_offset;                memcpy (dst, image->parts[part].cache + cache_offset,                        cache_size);                dst += cache_size;                size -= cache_size;                cache_offset = 0;                block++;        }        return dst - ptr;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -