From 4cf05be0ffe3479837265c8bb81b57f0f1f895c7 Mon Sep 17 00:00:00 2001 From: FIX94 Date: Sun, 8 Oct 2017 01:59:33 +0200 Subject: [PATCH] -changed a bunch to make it compile on windows (MSYS2) -added wiiu gamepad compatibility when booting from wii vc with patched fw.img using libwiidrc -removed upper file limit from wiiload (useful when used with wiiu homebrew launcher) --- .gitignore | 1 + channel/banner/banner/mkbanner.py | 6 ++-- channel/banner/icon/mkicon.py | 4 +-- channel/banner/tools/Makefile | 2 +- channel/banner/tools/addimd5.py | 4 +-- channel/banner/tools/join-imet.py | 8 ++--- channel/banner/tools/lz77.c | 28 ++++++++-------- channel/banner/tools/mkbns.c | 7 ++-- channel/channelapp/Makefile | 6 +++- channel/channelapp/source/controls.c | 50 ++++++++++++++++++++++++++++ channel/title/Makefile | 31 ++++++++++------- channel/title/dpki/00000000 | 1 - channel/title/dpki/00000001 | 1 - channel/title/dpki/footer | 1 - channel/title/retail/00000000 | 1 - channel/title/retail/00000001 | 1 - channel/title/retail/footer | 1 - channel/wiiload/Makefile | 2 +- channel/wiiload/main.c | 2 +- pywii/Common/pywii/wii.py | 4 +-- pywii/pywii-tools/addhash.py | 6 ++-- pywii/pywii-tools/dpkisign.py | 2 +- pywii/pywii-tools/pywii | 1 - pywii/pywii-tools/pywii.py | 3 ++ wiipax/Makefile | 2 +- wiipax/client/LzmaEnc.c | 3 +- wiipax/client/Makefile | 2 ++ wiipax/client/elf_abi.h | 1 + wiipax/client/lzma.c | 15 +++++---- wiipax/client/lzma.h | 1 + wiipax/client/main.c | 41 ++++++++++++----------- wiipax/client/stub_dkf.c | 1 - wiipax/client/stub_dkf_debug.c | 1 - wiipax/client/stub_dkfc.c | 1 - wiipax/client/stub_dkfc_debug.c | 1 - wiipax/client/stub_mini.c | 1 - wiipax/client/stub_mini_debug.c | 1 - wiipax/stub/Makefile | 1 + 38 files changed, 154 insertions(+), 91 deletions(-) delete mode 120000 channel/title/dpki/00000000 delete mode 120000 channel/title/dpki/00000001 delete mode 120000 channel/title/dpki/footer delete mode 120000 channel/title/retail/00000000 delete mode 120000 channel/title/retail/00000001 delete mode 120000 channel/title/retail/footer delete mode 120000 pywii/pywii-tools/pywii create mode 100644 pywii/pywii-tools/pywii.py delete mode 120000 wiipax/client/stub_dkf.c delete mode 120000 wiipax/client/stub_dkf_debug.c delete mode 120000 wiipax/client/stub_dkfc.c delete mode 120000 wiipax/client/stub_dkfc_debug.c delete mode 120000 wiipax/client/stub_mini.c delete mode 120000 wiipax/client/stub_mini_debug.c diff --git a/.gitignore b/.gitignore index 460a56d..9370b09 100644 --- a/.gitignore +++ b/.gitignore @@ -5,5 +5,6 @@ .*.swp *.dSYM *.pyc +*.exe .DS_Store diff --git a/channel/banner/banner/mkbanner.py b/channel/banner/banner/mkbanner.py index bea4316..dc74f90 100644 --- a/channel/banner/banner/mkbanner.py +++ b/channel/banner/banner/mkbanner.py @@ -374,10 +374,10 @@ for i in col.Instances: col.render() brldata = brlyt.Pack() -open(sys.argv[1],"w").write(brldata) +open(sys.argv[1],"wb").write(brldata) bradata = brlan.Pack(loopStart) -open(sys.argv[2],"w").write(bradata) +open(sys.argv[2],"wb").write(bradata) bradata = brlan.Pack(loopStart, loopEnd) -open(sys.argv[3],"w").write(bradata) +open(sys.argv[3],"wb").write(bradata) diff --git a/channel/banner/icon/mkicon.py b/channel/banner/icon/mkicon.py index 07ca2c0..3e8823f 100644 --- a/channel/banner/icon/mkicon.py +++ b/channel/banner/icon/mkicon.py @@ -111,7 +111,7 @@ brlyt.RootPane.Add(tit) brldata = brlyt.Pack() -open(sys.argv[1],"w").write(brldata) +open(sys.argv[1],"wb").write(brldata) brlan = Brlan() @@ -179,4 +179,4 @@ bradata = brlan.Pack(60*16) for a,b,c in brlan.Anim['waveb'][Brlan.A_COORD][Brlan.C_X].Triplets: print a,b,c -open(sys.argv[2],"w").write(bradata) +open(sys.argv[2],"wb").write(bradata) diff --git a/channel/banner/tools/Makefile b/channel/banner/tools/Makefile index f42bd79..86c7fc1 100644 --- a/channel/banner/tools/Makefile +++ b/channel/banner/tools/Makefile @@ -10,7 +10,7 @@ mkbns$(EXE): mkbns.c $(CC) $(CFLAGS) -o mkbns mkbns.c -lm png2tpl$(EXE): png2tpl.c - $(CC) $(CFLAGS) -o png2tpl png2tpl.c -lpng + $(CC) $(CFLAGS) -o png2tpl png2tpl.c -lpng -lz lz77$(EXE): lz77.c $(CC) $(CFLAGS) -o lz77 lz77.c diff --git a/channel/banner/tools/addimd5.py b/channel/banner/tools/addimd5.py index a33a271..3868a27 100644 --- a/channel/banner/tools/addimd5.py +++ b/channel/banner/tools/addimd5.py @@ -1,12 +1,12 @@ import md5, sys, struct -data= open(sys.argv[1]).read() +data= open(sys.argv[1],"rb").read() digest = md5.new(data).digest() hdr = struct.pack(">4sI8x","IMD5",len(data)) -f2 = open(sys.argv[2],"w") +f2 = open(sys.argv[2],"wb") f2.write(hdr) f2.write(digest) f2.write(data) diff --git a/channel/banner/tools/join-imet.py b/channel/banner/tools/join-imet.py index 31f19a5..8aae457 100644 --- a/channel/banner/tools/join-imet.py +++ b/channel/banner/tools/join-imet.py @@ -2,11 +2,11 @@ import os, sys, struct, md5 output, datafile, iconarc, bannerarc, soundbns, namesfile = sys.argv[1:] -data = open(datafile,"r").read() +data = open(datafile,"rb").read() names={} -for i in open(namesfile,"r"): +for i in open(namesfile,"rb"): a,b = i.split("=") while b[-1] == "\n": b = b[:-1] @@ -34,9 +34,9 @@ imet += "\x00"*(0x600 - len(imet)) imet = imet[:-16] + md5.new(imet).digest() -open(output,"w").write(imet) +open(output,"wb").write(imet) -f = open(sys.argv[1],"w") +f = open(sys.argv[1],"wb") f.write(imet) f.write(data) diff --git a/channel/banner/tools/lz77.c b/channel/banner/tools/lz77.c index 0620b23..af3ebc1 100644 --- a/channel/banner/tools/lz77.c +++ b/channel/banner/tools/lz77.c @@ -247,22 +247,24 @@ int LZ_Compress( unsigned char *in, unsigned char *out, int main(int argc, char *argv[]) { - int in, out, size; - struct stat buf; + FILE *in, *out; + int insize, size; unsigned char *uncompressed, *compressed; if (argc == 3) { - in = open(argv[1], O_RDONLY); - out = creat(argv[2], 0600); - fstat(in, &buf); - uncompressed = malloc(buf.st_size); - read(in, uncompressed, buf.st_size); - close(in); - compressed = malloc(buf.st_size*2); - size = LZ_Compress(uncompressed, compressed, buf.st_size); - write(out, "LZ77", 4); - write(out, compressed, size); - close(out); + in = fopen(argv[1], "rb"); + out = fopen(argv[2], "wb"); + fseek(in,0,SEEK_END); + insize = ftell(in); + fseek(in,0,SEEK_SET); + uncompressed = malloc(insize); + fread(uncompressed, 1, insize, in); + fclose(in); + compressed = malloc(insize*2); + size = LZ_Compress(uncompressed, compressed, insize); + fwrite("LZ77", 1, 4, out); + fwrite(compressed, 1, size, out); + fclose(out); free(compressed); free(uncompressed); return 0; diff --git a/channel/banner/tools/mkbns.c b/channel/banner/tools/mkbns.c index ae15ccc..5c14175 100644 --- a/channel/banner/tools/mkbns.c +++ b/channel/banner/tools/mkbns.c @@ -203,6 +203,7 @@ void repack_adpcm(int idx, int16_t *table, uint8_t *data, int16_t *inbuf) uint8_t testdata[8]; int16_t tlsamps[2]; int16_t blsamps[2]; + blsamps[0] = 0, blsamps[1] = 0; float error; float besterror = 99999999.0f; for(tblidx = 0; tblidx < 8; tblidx++) { @@ -242,15 +243,15 @@ int main(int argc, char **argv) if(argc > 4 && (atoi(argv[3]) == 1)) separated_loop = 1; - f = fopen(argv[1],"r"); - fo = fopen(argv[2],"w"); + f = fopen(argv[1],"rb"); + fo = fopen(argv[2],"wb"); fseek(f,0,SEEK_END); samples = ftell(f)/(sizeof(uint16_t)*2); if(separated_loop) { - f2 = fopen(argv[4],"r"); + f2 = fopen(argv[4],"rb"); fseek(f2,0,SEEK_END); loop_pt = samples; samples += ftell(f2)/(sizeof(uint16_t)*2); diff --git a/channel/channelapp/Makefile b/channel/channelapp/Makefile index 50ce009..7490a39 100644 --- a/channel/channelapp/Makefile +++ b/channel/channelapp/Makefile @@ -33,7 +33,7 @@ DIR_LIBS = \ $(DEVKITPRO)/libogc/lib/wii \ $(DEVKITPRO)/portlibs/ppc/lib -LIBS = fat wiiuse bte mxml png15 z ogc m db freetype +LIBS = fat wiiuse bte wiidrc mxml png15 z ogc m db freetype MACHDEP = -g -DGEKKO -mrvl -mcpu=750 -meabi -mhard-float CFLAGS = $(MACHDEP) -Os -Wall -DBASE_ADDR=$(BASE_ADDR) $(DIR_INCLUDES:%=-I%) @@ -117,6 +117,10 @@ $(TARGET_CHAN).elf: $(TARGET_APP)_nopax.elf @echo $(@F) @$(WIIPAX) -s dkfailchannel $< $@ +$(TARGET_CHAN).dol: $(TARGET_CHAN).elf $(ELF2DOL) + @echo $(@F) + @$(ELF2DOL) $< $@ + $(DIR_BUILD)/$(TARGET_STUB)_bin.o: $(TARGET_STUB).bin @echo $(@F) @$(BIN2S) -a 32 $< | $(AS) -o $@ diff --git a/channel/channelapp/source/controls.c b/channel/channelapp/source/controls.c index e3f18eb..3e7c890 100644 --- a/channel/channelapp/source/controls.c +++ b/channel/channelapp/source/controls.c @@ -1,9 +1,11 @@ #include #include #include +#include #include #include +#include #include "../config.h" @@ -16,6 +18,13 @@ WPADData *wpads[WPAD_MAX_WIIMOTES]; static int rumbling = 0; void controls_init (void) { + WiiDRC_Init (); + if(WiiDRC_Inited() && WiiDRC_Connected()) + { //Wii VC cannot go back to this channel + memset((u32 *) 0x80001800, 0, 0x1800); + DCFlushRange((u32 *) 0x80001800, 0x1800); + } + int i; i = WPAD_Init (); @@ -99,6 +108,39 @@ static u32 wpad_button_transform(WPADData *wd, u32 btns) { return (btns&0xffff) << 16; } +static u32 wiidrc_to_wpad(u32 btns) { + u32 ret = 0; + + if(btns & WIIDRC_BUTTON_LEFT) + ret |= WPAD_BUTTON_LEFT; + if(btns & WIIDRC_BUTTON_RIGHT) + ret |= WPAD_BUTTON_RIGHT; + if(btns & WIIDRC_BUTTON_UP) + ret |= WPAD_BUTTON_UP; + if(btns & WIIDRC_BUTTON_DOWN) + ret |= WPAD_BUTTON_DOWN; + if(btns & WIIDRC_BUTTON_A) + ret |= WPAD_BUTTON_A; + if(btns & WIIDRC_BUTTON_B) + ret |= WPAD_BUTTON_B; + if(btns & WIIDRC_BUTTON_X) + ret |= WPAD_BUTTON_1; + if(btns & WIIDRC_BUTTON_Y) + ret |= WPAD_BUTTON_2; + if((btns & WIIDRC_BUTTON_ZL) || (btns & WIIDRC_BUTTON_MINUS)) + ret |= WPAD_BUTTON_MINUS; + if((btns & WIIDRC_BUTTON_ZR) || (btns & WIIDRC_BUTTON_PLUS)) + ret |= WPAD_BUTTON_PLUS; + if(btns & WIIDRC_BUTTON_HOME) + ret |= WPAD_BUTTON_HOME; + if(btns & WIIDRC_BUTTON_L) + ret |= PADW_BUTTON_NET_INIT; + if(btns & WIIDRC_BUTTON_R) + ret |= PADW_BUTTON_SCREENSHOT; + + return (ret&0xffff) << 16; +} + void controls_scan (u32 *down, u32 *held, u32 *up) { u32 bd, bh, bu; int i; @@ -158,6 +200,14 @@ void controls_scan (u32 *down, u32 *held, u32 *up) { WPAD_Rumble(pointer_owner, 1); } + if(WiiDRC_Inited() && WiiDRC_Connected()) + { + WiiDRC_ScanPads(); + bd |= wiidrc_to_wpad(WiiDRC_ButtonsDown()); + bh |= wiidrc_to_wpad(WiiDRC_ButtonsHeld()); + bu |= wiidrc_to_wpad(WiiDRC_ButtonsUp()); + } + if (down) *down = bd; diff --git a/channel/title/Makefile b/channel/title/Makefile index f1a17fc..ea78694 100644 --- a/channel/title/Makefile +++ b/channel/title/Makefile @@ -11,10 +11,16 @@ all: channel_retail.wad dpki: channel_dpki.wad channel_retail.wad: retail/cetk retail/tmd 00000000 00000001 - @$(TOOLS)/wadpack.py $@ retail/ + @cp -f 00000000 retail + @cp -f 00000001 retail + @cp -f footer retail + @python2 $(TOOLS)/wadpack.py $@ retail/ channel_dpki.wad: dpki/cetk dpki/tmd 00000000 00000001 - @$(TOOLS)/wadpack.py -dpki $@ dpki/ + @cp -f 00000000 retail + @cp -f 00000001 retail + @cp -f footer retail + @python2 $(TOOLS)/wadpack.py -dpki $@ dpki/ 00000000: ../banner/channel.imet @cat footer $< > $@ @@ -24,27 +30,28 @@ channel_dpki.wad: dpki/cetk dpki/tmd 00000000 00000001 retail/cetk: cetk.template @cp $< $@ - @$(TOOLS)/tikfix.py $@ + @python2 $(TOOLS)/tikfix.py $@ dpki/cetk: retail/cetk - @$(TOOLS)/dpkisign.py -cetk $< $@ $(CERTS) $(DPKI_ISSUER_TIK) + @python2 $(TOOLS)/dpkisign.py -cetk $< $@ $(CERTS) $(DPKI_ISSUER_TIK) retail/tmd: tmd.template 00000000 00000001 @cp $< $@ - @$(TOOLS)/tmdupdatecr.py $@ $(CURDIR) - @$(TOOLS)/tmdvers.py $@ $(INSTALLER_VER_MAJOR) $(INSTALLER_VER_MINOR) + @python2 $(TOOLS)/tmdupdatecr.py $@ $(CURDIR) + @python2 $(TOOLS)/tmdvers.py $@ $(INSTALLER_VER_MAJOR) $(INSTALLER_VER_MINOR) dpki/tmd: retail/tmd - @$(TOOLS)/dpkisign.py -tmd $< $@ $(CERTS) $(DPKI_ISSUER_TMD) + @python2 $(TOOLS)/dpkisign.py -tmd $< $@ $(CERTS) $(DPKI_ISSUER_TMD) check: all dpki @echo ===== RETAIL ===== - @$(TOOLS)/tikinfo.py retail/cetk retail/certs - @$(TOOLS)/tmdinfo.py retail/tmd retail/certs + @python2 $(TOOLS)/tikinfo.py retail/cetk retail/certs + @python2 $(TOOLS)/tmdinfo.py retail/tmd retail/certs @echo ===== DPKI ===== - @$(TOOLS)/tikinfo.py -dpki dpki/cetk dpki/certs - @$(TOOLS)/tmdinfo.py -dpki dpki/tmd dpki/certs + @python2 $(TOOLS)/tikinfo.py -dpki dpki/cetk dpki/certs + @python2 $(TOOLS)/tmdinfo.py -dpki dpki/tmd dpki/certs clean: - rm -f retail/cetk dpki/cetk retail/tmd retail/tmd 00000000 00000001 channel_retail.wad channel_dpki.wad + rm -f retail/cetk dpki/cetk retail/tmd dpki/tmd retail/footer dpki/footer retail/00000000 retail/00000001 \ + dpki/00000000 dpki/00000001 channel_retail.wad channel_dpki.wad diff --git a/channel/title/dpki/00000000 b/channel/title/dpki/00000000 deleted file mode 120000 index 763d8d7..0000000 --- a/channel/title/dpki/00000000 +++ /dev/null @@ -1 +0,0 @@ -../00000000 \ No newline at end of file diff --git a/channel/title/dpki/00000001 b/channel/title/dpki/00000001 deleted file mode 120000 index 2a48551..0000000 --- a/channel/title/dpki/00000001 +++ /dev/null @@ -1 +0,0 @@ -../00000001 \ No newline at end of file diff --git a/channel/title/dpki/footer b/channel/title/dpki/footer deleted file mode 120000 index 74c13ec..0000000 --- a/channel/title/dpki/footer +++ /dev/null @@ -1 +0,0 @@ -../footer \ No newline at end of file diff --git a/channel/title/retail/00000000 b/channel/title/retail/00000000 deleted file mode 120000 index 763d8d7..0000000 --- a/channel/title/retail/00000000 +++ /dev/null @@ -1 +0,0 @@ -../00000000 \ No newline at end of file diff --git a/channel/title/retail/00000001 b/channel/title/retail/00000001 deleted file mode 120000 index 2a48551..0000000 --- a/channel/title/retail/00000001 +++ /dev/null @@ -1 +0,0 @@ -../00000001 \ No newline at end of file diff --git a/channel/title/retail/footer b/channel/title/retail/footer deleted file mode 120000 index 74c13ec..0000000 --- a/channel/title/retail/footer +++ /dev/null @@ -1 +0,0 @@ -../footer \ No newline at end of file diff --git a/channel/wiiload/Makefile b/channel/wiiload/Makefile index 4eda0e0..ee68b98 100644 --- a/channel/wiiload/Makefile +++ b/channel/wiiload/Makefile @@ -1,7 +1,7 @@ CFLAGS += -Wall -Wextra -Os -g -pipe ifeq ($(WIN32), 1) -PREFIX ?= i586-mingw32msvc- +#PREFIX ?= i586-mingw32msvc- BIN_EXT = .exe CFLAGS += -Iwin32/include LDFLAGS += -Lwin32/lib -lws2_32 -lz diff --git a/channel/wiiload/main.c b/channel/wiiload/main.c index f28199a..6eccf7e 100644 --- a/channel/wiiload/main.c +++ b/channel/wiiload/main.c @@ -408,7 +408,7 @@ int main (int argc, char **argv) { fsize = st.st_size; - if (fsize < 64 || fsize > 20 * 1024 * 1024) { + if (fsize < 64) { close (fd); fprintf (stderr, "error: invalid file size\n"); exit (EXIT_FAILURE); diff --git a/pywii/Common/pywii/wii.py b/pywii/Common/pywii/wii.py index 4ef701a..adde719 100644 --- a/pywii/Common/pywii/wii.py +++ b/pywii/Common/pywii/wii.py @@ -19,7 +19,7 @@ except ImportError: from Crypto.Hash import SHA from Crypto.PublicKey import RSA from Crypto.Util.number import bytes_to_long, long_to_bytes - from Crypto.Signature import pkcs1_15 + from Crypto.Signature import PKCS1_v1_5 import ec @@ -32,7 +32,7 @@ sigtypes = [ "RSA-4096", "RSA-2048", "EC-DSA" ] def load_rsa_key(issuer): print "Loading private key for %s" % issuer path = os.path.join(os.environ["HOME"], ".wii", "dpki", issuer + ".pem") - return RSA.importKey(open(path, "r").read()) + return RSA.importKey(open(path, "rb").read()) signkeyfuncs = [ load_rsa_key, load_rsa_key, None ] diff --git a/pywii/pywii-tools/addhash.py b/pywii/pywii-tools/addhash.py index 52de600..4273140 100755 --- a/pywii/pywii-tools/addhash.py +++ b/pywii/pywii-tools/addhash.py @@ -3,9 +3,9 @@ import sys import re import pywii as wii -hash = wii.SHA.new(open(sys.argv[2]).read()).digest().encode("hex") -f = open(sys.argv[1], "r") +hash = wii.SHA.new(open(sys.argv[2],"rb").read()).digest().encode("hex") +f = open(sys.argv[1], "rb") data = f.read() f.close() data = re.sub('@SHA1SUM@', hash, data) -open(sys.argv[3], "w").write(data) +open(sys.argv[3], "wb").write(data) diff --git a/pywii/pywii-tools/dpkisign.py b/pywii/pywii-tools/dpkisign.py index d8de458..0fe7e65 100755 --- a/pywii/pywii-tools/dpkisign.py +++ b/pywii/pywii-tools/dpkisign.py @@ -20,7 +20,7 @@ else: print "EYOUFAILIT" sys.exit(1) -certs, certlist = pywii.parse_certs(open(certfile).read()) +certs, certlist = pywii.parse_certs(open(certfile,"rb").read()) signed.update_issuer(issuer) diff --git a/pywii/pywii-tools/pywii b/pywii/pywii-tools/pywii deleted file mode 120000 index 51fbba6..0000000 --- a/pywii/pywii-tools/pywii +++ /dev/null @@ -1 +0,0 @@ -../Common/pywii \ No newline at end of file diff --git a/pywii/pywii-tools/pywii.py b/pywii/pywii-tools/pywii.py new file mode 100644 index 0000000..c0fb1d3 --- /dev/null +++ b/pywii/pywii-tools/pywii.py @@ -0,0 +1,3 @@ +import os.path, sys +sys.path.append(os.path.join(os.path.dirname(os.path.realpath(__file__)), '../Common/pywii')) +from wii import * \ No newline at end of file diff --git a/wiipax/Makefile b/wiipax/Makefile index 6d69506..9fe0ed1 100644 --- a/wiipax/Makefile +++ b/wiipax/Makefile @@ -4,7 +4,7 @@ all: clean distclean: $(MAKE) -C stub distclean - $(MAKE) -C client clean + $(MAKE) -C client distclean install: $(MAKE) -C client install diff --git a/wiipax/client/LzmaEnc.c b/wiipax/client/LzmaEnc.c index 529fd98..a383be4 100644 --- a/wiipax/client/LzmaEnc.c +++ b/wiipax/client/LzmaEnc.c @@ -1919,11 +1919,10 @@ static SRes LzmaEnc_CodeOneBlock(CLzmaEnc *p, Bool useLimits, UInt32 maxPackSize static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig) { UInt32 beforeSize = kNumOpts; - Bool btMode; if (!RangeEnc_Alloc(&p->rc, alloc)) return SZ_ERROR_MEM; - btMode = (p->matchFinderBase.btMode != 0); #ifdef COMPRESS_MF_MT + Bool btMode = (p->matchFinderBase.btMode != 0); p->mtMode = (p->multiThread && !p->fastMode && btMode); #endif diff --git a/wiipax/client/Makefile b/wiipax/client/Makefile index 1f3ecfc..21b526b 100644 --- a/wiipax/client/Makefile +++ b/wiipax/client/Makefile @@ -12,3 +12,5 @@ include ../../common.mk install: all install -m 755 $(TARGET) $(WIIDEV)/bin +distclean: clean + rm -f stub_dkf.c stub_dkf_debug.c stub_dkfc.c stub_dkfc_debug.c stub_mini.c stub_mini_debug.c diff --git a/wiipax/client/elf_abi.h b/wiipax/client/elf_abi.h index 379355c..e210d91 100644 --- a/wiipax/client/elf_abi.h +++ b/wiipax/client/elf_abi.h @@ -33,6 +33,7 @@ #ifndef _ELF_ABI_H #define _ELF_ABI_H +#include #include "common.h" /* diff --git a/wiipax/client/lzma.c b/wiipax/client/lzma.c index 183b17b..15efdee 100644 --- a/wiipax/client/lzma.c +++ b/wiipax/client/lzma.c @@ -4,6 +4,7 @@ #include #include #include +#include #include "common.h" #include "lzma.h" @@ -97,27 +98,27 @@ void lzma_decode(const lzma_t *lzma, u8 *dst) { } void lzma_write(const char *filename, const lzma_t *lzma) { - int fd; + FILE *fd; int i; - fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0755); - if (fd < 0) + fd = fopen(filename, "wb"); + if (fd == NULL) perrordie("Could not open file"); - if (write(fd, lzma->props, LZMA_PROPS_SIZE) != LZMA_PROPS_SIZE) + if (fwrite(lzma->props, 1, LZMA_PROPS_SIZE, fd) != LZMA_PROPS_SIZE) perrordie("Could not write to file"); u64 size = lzma->len_in; for (i = 0; i < 8; ++i) { u8 j = size & 0xff; size >>= 8; - if (write(fd, &j, 1) != 1) + if (fwrite(&j, 1, 1, fd) != 1) perrordie("Could not write to file"); } - if (write(fd, lzma->data, lzma->len_out) != lzma->len_out) + if (fwrite(lzma->data, 1, lzma->len_out, fd) != lzma->len_out) perrordie("Could not write to file"); - close(fd); + fclose(fd); } diff --git a/wiipax/client/lzma.h b/wiipax/client/lzma.h index d8badf0..1e37f33 100644 --- a/wiipax/client/lzma.h +++ b/wiipax/client/lzma.h @@ -1,6 +1,7 @@ #ifndef _LZMA_H_ #define _LZMA_H_ +#include #include "common.h" #include "LzmaEnc.h" diff --git a/wiipax/client/main.c b/wiipax/client/main.c index 0cd231d..1ab7ed9 100644 --- a/wiipax/client/main.c +++ b/wiipax/client/main.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "common.h" #include "lzma.h" @@ -83,51 +84,53 @@ static elf_t *read_stub(const char *name) { } static elf_t *read_elf(const char *filename) { - int fd; - struct stat st; + FILE *f; + size_t len; elf_t *elf; printf("Reading %s\n", filename); - fd = open(filename, O_RDONLY); - if (fd < 0) - perrordie("Could not open ELF file"); + f = fopen(filename, "rb"); + if (f == NULL) + die("Could not open ELF file"); - if (fstat(fd, &st)) - perrordie("Could not stat ELF file"); + fseek(f,0,SEEK_END); + len = ftell(f); + fseek(f,0,SEEK_SET); - if ((u32) st.st_size < sizeof(Elf32_Ehdr)) + if ((u32) len < sizeof(Elf32_Ehdr)) die("File too short for ELF"); elf = (elf_t *) calloc(1, sizeof(elf_t)); if (!elf) die("Error allocating %u bytes", (u32) sizeof(elf_t)); - elf->len = st.st_size; + elf->len = len; elf->data = (u8 *) malloc(elf->len); + printf("elf->len is %u bytes\n", elf->len); if (!elf->data) die("Error allocating %u bytes", elf->len); - if (read(fd, elf->data, elf->len) != elf->len) - perrordie("Could not read from file"); + if ((u32)fread(elf->data, 1, elf->len, f) != elf->len) + die("Could not read from file"); - close(fd); + fclose(f); return elf; } static void write_elf(const char *filename, const elf_t *elf) { - int fd; + FILE *f; - fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0755); - if (fd < 0) - perrordie("Could not open ELF file"); + f = fopen(filename, "wb"); + if (f == NULL) + die("Could not open ELF file"); - if (write(fd, elf->data, elf->len) != elf->len) - perrordie("Could not write ELF file"); + if ((u32)fwrite(elf->data, 1, elf->len, f) != elf->len) + die("Could not write ELF file"); - close(fd); + fclose(f); } static void free_elf(elf_t *elf) { diff --git a/wiipax/client/stub_dkf.c b/wiipax/client/stub_dkf.c deleted file mode 120000 index 846981f..0000000 --- a/wiipax/client/stub_dkf.c +++ /dev/null @@ -1 +0,0 @@ -../stub/stub_dkf.c \ No newline at end of file diff --git a/wiipax/client/stub_dkf_debug.c b/wiipax/client/stub_dkf_debug.c deleted file mode 120000 index c992edb..0000000 --- a/wiipax/client/stub_dkf_debug.c +++ /dev/null @@ -1 +0,0 @@ -../stub/stub_dkf_debug.c \ No newline at end of file diff --git a/wiipax/client/stub_dkfc.c b/wiipax/client/stub_dkfc.c deleted file mode 120000 index 71be34f..0000000 --- a/wiipax/client/stub_dkfc.c +++ /dev/null @@ -1 +0,0 @@ -../stub/stub_dkfc.c \ No newline at end of file diff --git a/wiipax/client/stub_dkfc_debug.c b/wiipax/client/stub_dkfc_debug.c deleted file mode 120000 index e6ebaf3..0000000 --- a/wiipax/client/stub_dkfc_debug.c +++ /dev/null @@ -1 +0,0 @@ -../stub/stub_dkfc_debug.c \ No newline at end of file diff --git a/wiipax/client/stub_mini.c b/wiipax/client/stub_mini.c deleted file mode 120000 index 08525f3..0000000 --- a/wiipax/client/stub_mini.c +++ /dev/null @@ -1 +0,0 @@ -../stub/stub_mini.c \ No newline at end of file diff --git a/wiipax/client/stub_mini_debug.c b/wiipax/client/stub_mini_debug.c deleted file mode 120000 index d313e13..0000000 --- a/wiipax/client/stub_mini_debug.c +++ /dev/null @@ -1 +0,0 @@ -../stub/stub_mini_debug.c \ No newline at end of file diff --git a/wiipax/stub/Makefile b/wiipax/stub/Makefile index 2aa6340..fdad228 100644 --- a/wiipax/stub/Makefile +++ b/wiipax/stub/Makefile @@ -43,6 +43,7 @@ all: xxd xxd: $(TARGET) @echo " XXD $^" @xxd -i $(TARGET) > $(subst .elf,.c,$(TARGET)) + @cp -f $(subst .elf,.c,$(TARGET)) ../client distclean: clean rm -f stub_*.elf stub_*.c