2 * Copyright (C) 2008 dhewg, #wiidev efnet
4 * some functions are taken from
5 * http://git.infradead.org/?p=users/segher/wii.git
6 * Copyright 2007,2008 Segher Boessenkool <segher@kernel.crashing.org>
7 * 21:14:49 <@segher> i'll happily grant you to license the whole as v3, btw
9 * this file is part of wiifuse
10 * http://wiibrew.org/index.php?title=Wiifuse
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 u16
get_be16 (const u8
*p
) {
32 return (p
[0] << 8) | p
[1];
35 u32
get_be32 (const u8
*p
) {
36 return (p
[0] << 24) | (p
[1] << 16) | (p
[2] << 8) | p
[3];
39 u64
get_be64 (const u8
*p
) {
40 return ((u64
) get_be32 (p
) << 32) | get_be32 (p
+ 4);
43 void put_be16 (u8
*p
, const u16 value
) {
44 p
[0] = (value
>> 8) & 0xff;
48 void put_be32 (u8
*p
, const u32 value
) {
49 p
[0] = (value
>> 24) & 0xff;
50 p
[1] = (value
>> 16) & 0xff;
51 p
[2] = (value
>> 8) & 0xff;
55 void put_be64 (u8
*p
, const u64 value
) {
56 put_be32 (p
, (value
>> 32) & 0xffffffff);
57 put_be32 (p
+ 4, value
& 0xffffffff);
60 size_t g_strnlen (const char *s
, size_t size
) {
63 for (i
= 0; i
< size
; ++i
)
70 u32
get_dol_size (const u8
*header
) {
75 // iterate through the 7 code segments
76 for (i
= 0; i
< 7; ++i
) {
77 offset
= get_be32 (&header
[i
* 4]);
78 size
= get_be32 (&header
[0x90 + i
* 4]);
79 if (offset
+ size
> max
)
83 // iterate through the 11 data segments
84 for (i
= 0; i
< 11; ++i
) {
85 offset
= get_be32 (&header
[0x1c + i
* 4]);
86 size
= get_be32 (&header
[0xac + i
* 4]);
87 if (offset
+ size
> max
)