-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)
This commit is contained in:
FIX94 2017-10-08 01:59:33 +02:00
parent 2fb61e432e
commit 4cf05be0ff
No known key found for this signature in database
GPG Key ID: CE39016A19D8EADA
38 changed files with 154 additions and 91 deletions

1
.gitignore vendored
View File

@ -5,5 +5,6 @@
.*.swp .*.swp
*.dSYM *.dSYM
*.pyc *.pyc
*.exe
.DS_Store .DS_Store

View File

@ -374,10 +374,10 @@ for i in col.Instances:
col.render() col.render()
brldata = brlyt.Pack() brldata = brlyt.Pack()
open(sys.argv[1],"w").write(brldata) open(sys.argv[1],"wb").write(brldata)
bradata = brlan.Pack(loopStart) bradata = brlan.Pack(loopStart)
open(sys.argv[2],"w").write(bradata) open(sys.argv[2],"wb").write(bradata)
bradata = brlan.Pack(loopStart, loopEnd) bradata = brlan.Pack(loopStart, loopEnd)
open(sys.argv[3],"w").write(bradata) open(sys.argv[3],"wb").write(bradata)

View File

@ -111,7 +111,7 @@ brlyt.RootPane.Add(tit)
brldata = brlyt.Pack() brldata = brlyt.Pack()
open(sys.argv[1],"w").write(brldata) open(sys.argv[1],"wb").write(brldata)
brlan = Brlan() 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: for a,b,c in brlan.Anim['waveb'][Brlan.A_COORD][Brlan.C_X].Triplets:
print a,b,c print a,b,c
open(sys.argv[2],"w").write(bradata) open(sys.argv[2],"wb").write(bradata)

View File

@ -10,7 +10,7 @@ mkbns$(EXE): mkbns.c
$(CC) $(CFLAGS) -o mkbns mkbns.c -lm $(CC) $(CFLAGS) -o mkbns mkbns.c -lm
png2tpl$(EXE): png2tpl.c png2tpl$(EXE): png2tpl.c
$(CC) $(CFLAGS) -o png2tpl png2tpl.c -lpng $(CC) $(CFLAGS) -o png2tpl png2tpl.c -lpng -lz
lz77$(EXE): lz77.c lz77$(EXE): lz77.c
$(CC) $(CFLAGS) -o lz77 lz77.c $(CC) $(CFLAGS) -o lz77 lz77.c

View File

@ -1,12 +1,12 @@
import md5, sys, struct import md5, sys, struct
data= open(sys.argv[1]).read() data= open(sys.argv[1],"rb").read()
digest = md5.new(data).digest() digest = md5.new(data).digest()
hdr = struct.pack(">4sI8x","IMD5",len(data)) hdr = struct.pack(">4sI8x","IMD5",len(data))
f2 = open(sys.argv[2],"w") f2 = open(sys.argv[2],"wb")
f2.write(hdr) f2.write(hdr)
f2.write(digest) f2.write(digest)
f2.write(data) f2.write(data)

View File

@ -2,11 +2,11 @@ import os, sys, struct, md5
output, datafile, iconarc, bannerarc, soundbns, namesfile = sys.argv[1:] output, datafile, iconarc, bannerarc, soundbns, namesfile = sys.argv[1:]
data = open(datafile,"r").read() data = open(datafile,"rb").read()
names={} names={}
for i in open(namesfile,"r"): for i in open(namesfile,"rb"):
a,b = i.split("=") a,b = i.split("=")
while b[-1] == "\n": while b[-1] == "\n":
b = b[:-1] b = b[:-1]
@ -34,9 +34,9 @@ imet += "\x00"*(0x600 - len(imet))
imet = imet[:-16] + md5.new(imet).digest() 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(imet)
f.write(data) f.write(data)

View File

@ -247,22 +247,24 @@ int LZ_Compress( unsigned char *in, unsigned char *out,
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int in, out, size; FILE *in, *out;
struct stat buf; int insize, size;
unsigned char *uncompressed, *compressed; unsigned char *uncompressed, *compressed;
if (argc == 3) { if (argc == 3) {
in = open(argv[1], O_RDONLY); in = fopen(argv[1], "rb");
out = creat(argv[2], 0600); out = fopen(argv[2], "wb");
fstat(in, &buf); fseek(in,0,SEEK_END);
uncompressed = malloc(buf.st_size); insize = ftell(in);
read(in, uncompressed, buf.st_size); fseek(in,0,SEEK_SET);
close(in); uncompressed = malloc(insize);
compressed = malloc(buf.st_size*2); fread(uncompressed, 1, insize, in);
size = LZ_Compress(uncompressed, compressed, buf.st_size); fclose(in);
write(out, "LZ77", 4); compressed = malloc(insize*2);
write(out, compressed, size); size = LZ_Compress(uncompressed, compressed, insize);
close(out); fwrite("LZ77", 1, 4, out);
fwrite(compressed, 1, size, out);
fclose(out);
free(compressed); free(compressed);
free(uncompressed); free(uncompressed);
return 0; return 0;

View File

@ -203,6 +203,7 @@ void repack_adpcm(int idx, int16_t *table, uint8_t *data, int16_t *inbuf)
uint8_t testdata[8]; uint8_t testdata[8];
int16_t tlsamps[2]; int16_t tlsamps[2];
int16_t blsamps[2]; int16_t blsamps[2];
blsamps[0] = 0, blsamps[1] = 0;
float error; float error;
float besterror = 99999999.0f; float besterror = 99999999.0f;
for(tblidx = 0; tblidx < 8; tblidx++) { for(tblidx = 0; tblidx < 8; tblidx++) {
@ -242,15 +243,15 @@ int main(int argc, char **argv)
if(argc > 4 && (atoi(argv[3]) == 1)) if(argc > 4 && (atoi(argv[3]) == 1))
separated_loop = 1; separated_loop = 1;
f = fopen(argv[1],"r"); f = fopen(argv[1],"rb");
fo = fopen(argv[2],"w"); fo = fopen(argv[2],"wb");
fseek(f,0,SEEK_END); fseek(f,0,SEEK_END);
samples = ftell(f)/(sizeof(uint16_t)*2); samples = ftell(f)/(sizeof(uint16_t)*2);
if(separated_loop) { if(separated_loop) {
f2 = fopen(argv[4],"r"); f2 = fopen(argv[4],"rb");
fseek(f2,0,SEEK_END); fseek(f2,0,SEEK_END);
loop_pt = samples; loop_pt = samples;
samples += ftell(f2)/(sizeof(uint16_t)*2); samples += ftell(f2)/(sizeof(uint16_t)*2);

View File

@ -33,7 +33,7 @@ DIR_LIBS = \
$(DEVKITPRO)/libogc/lib/wii \ $(DEVKITPRO)/libogc/lib/wii \
$(DEVKITPRO)/portlibs/ppc/lib $(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 MACHDEP = -g -DGEKKO -mrvl -mcpu=750 -meabi -mhard-float
CFLAGS = $(MACHDEP) -Os -Wall -DBASE_ADDR=$(BASE_ADDR) $(DIR_INCLUDES:%=-I%) CFLAGS = $(MACHDEP) -Os -Wall -DBASE_ADDR=$(BASE_ADDR) $(DIR_INCLUDES:%=-I%)
@ -117,6 +117,10 @@ $(TARGET_CHAN).elf: $(TARGET_APP)_nopax.elf
@echo $(@F) @echo $(@F)
@$(WIIPAX) -s dkfailchannel $< $@ @$(WIIPAX) -s dkfailchannel $< $@
$(TARGET_CHAN).dol: $(TARGET_CHAN).elf $(ELF2DOL)
@echo $(@F)
@$(ELF2DOL) $< $@
$(DIR_BUILD)/$(TARGET_STUB)_bin.o: $(TARGET_STUB).bin $(DIR_BUILD)/$(TARGET_STUB)_bin.o: $(TARGET_STUB).bin
@echo $(@F) @echo $(@F)
@$(BIN2S) -a 32 $< | $(AS) -o $@ @$(BIN2S) -a 32 $< | $(AS) -o $@

View File

@ -1,9 +1,11 @@
#include <stdio.h> #include <stdio.h>
#include <math.h> #include <math.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <ogcsys.h> #include <ogcsys.h>
#include <ogc/lwp_watchdog.h> #include <ogc/lwp_watchdog.h>
#include <wiidrc/wiidrc.h>
#include "../config.h" #include "../config.h"
@ -16,6 +18,13 @@ WPADData *wpads[WPAD_MAX_WIIMOTES];
static int rumbling = 0; static int rumbling = 0;
void controls_init (void) { 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; int i;
i = WPAD_Init (); i = WPAD_Init ();
@ -99,6 +108,39 @@ static u32 wpad_button_transform(WPADData *wd, u32 btns) {
return (btns&0xffff) << 16; 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) { void controls_scan (u32 *down, u32 *held, u32 *up) {
u32 bd, bh, bu; u32 bd, bh, bu;
int i; int i;
@ -158,6 +200,14 @@ void controls_scan (u32 *down, u32 *held, u32 *up) {
WPAD_Rumble(pointer_owner, 1); 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) if (down)
*down = bd; *down = bd;

View File

@ -11,10 +11,16 @@ all: channel_retail.wad
dpki: channel_dpki.wad dpki: channel_dpki.wad
channel_retail.wad: retail/cetk retail/tmd 00000000 00000001 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 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 00000000: ../banner/channel.imet
@cat footer $< > $@ @cat footer $< > $@
@ -24,27 +30,28 @@ channel_dpki.wad: dpki/cetk dpki/tmd 00000000 00000001
retail/cetk: cetk.template retail/cetk: cetk.template
@cp $< $@ @cp $< $@
@$(TOOLS)/tikfix.py $@ @python2 $(TOOLS)/tikfix.py $@
dpki/cetk: retail/cetk 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 retail/tmd: tmd.template 00000000 00000001
@cp $< $@ @cp $< $@
@$(TOOLS)/tmdupdatecr.py $@ $(CURDIR) @python2 $(TOOLS)/tmdupdatecr.py $@ $(CURDIR)
@$(TOOLS)/tmdvers.py $@ $(INSTALLER_VER_MAJOR) $(INSTALLER_VER_MINOR) @python2 $(TOOLS)/tmdvers.py $@ $(INSTALLER_VER_MAJOR) $(INSTALLER_VER_MINOR)
dpki/tmd: retail/tmd dpki/tmd: retail/tmd
@$(TOOLS)/dpkisign.py -tmd $< $@ $(CERTS) $(DPKI_ISSUER_TMD) @python2 $(TOOLS)/dpkisign.py -tmd $< $@ $(CERTS) $(DPKI_ISSUER_TMD)
check: all dpki check: all dpki
@echo ===== RETAIL ===== @echo ===== RETAIL =====
@$(TOOLS)/tikinfo.py retail/cetk retail/certs @python2 $(TOOLS)/tikinfo.py retail/cetk retail/certs
@$(TOOLS)/tmdinfo.py retail/tmd retail/certs @python2 $(TOOLS)/tmdinfo.py retail/tmd retail/certs
@echo ===== DPKI ===== @echo ===== DPKI =====
@$(TOOLS)/tikinfo.py -dpki dpki/cetk dpki/certs @python2 $(TOOLS)/tikinfo.py -dpki dpki/cetk dpki/certs
@$(TOOLS)/tmdinfo.py -dpki dpki/tmd dpki/certs @python2 $(TOOLS)/tmdinfo.py -dpki dpki/tmd dpki/certs
clean: 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

View File

@ -1 +0,0 @@
../00000000

View File

@ -1 +0,0 @@
../00000001

View File

@ -1 +0,0 @@
../footer

View File

@ -1 +0,0 @@
../00000000

View File

@ -1 +0,0 @@
../00000001

View File

@ -1 +0,0 @@
../footer

View File

@ -1,7 +1,7 @@
CFLAGS += -Wall -Wextra -Os -g -pipe CFLAGS += -Wall -Wextra -Os -g -pipe
ifeq ($(WIN32), 1) ifeq ($(WIN32), 1)
PREFIX ?= i586-mingw32msvc- #PREFIX ?= i586-mingw32msvc-
BIN_EXT = .exe BIN_EXT = .exe
CFLAGS += -Iwin32/include CFLAGS += -Iwin32/include
LDFLAGS += -Lwin32/lib -lws2_32 -lz LDFLAGS += -Lwin32/lib -lws2_32 -lz

View File

@ -408,7 +408,7 @@ int main (int argc, char **argv) {
fsize = st.st_size; fsize = st.st_size;
if (fsize < 64 || fsize > 20 * 1024 * 1024) { if (fsize < 64) {
close (fd); close (fd);
fprintf (stderr, "error: invalid file size\n"); fprintf (stderr, "error: invalid file size\n");
exit (EXIT_FAILURE); exit (EXIT_FAILURE);

View File

@ -19,7 +19,7 @@ except ImportError:
from Crypto.Hash import SHA from Crypto.Hash import SHA
from Crypto.PublicKey import RSA from Crypto.PublicKey import RSA
from Crypto.Util.number import bytes_to_long, long_to_bytes 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 import ec
@ -32,7 +32,7 @@ sigtypes = [ "RSA-4096", "RSA-2048", "EC-DSA" ]
def load_rsa_key(issuer): def load_rsa_key(issuer):
print "Loading private key for %s" % issuer print "Loading private key for %s" % issuer
path = os.path.join(os.environ["HOME"], ".wii", "dpki", issuer + ".pem") 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 ] signkeyfuncs = [ load_rsa_key, load_rsa_key, None ]

View File

@ -3,9 +3,9 @@ import sys
import re import re
import pywii as wii import pywii as wii
hash = wii.SHA.new(open(sys.argv[2]).read()).digest().encode("hex") hash = wii.SHA.new(open(sys.argv[2],"rb").read()).digest().encode("hex")
f = open(sys.argv[1], "r") f = open(sys.argv[1], "rb")
data = f.read() data = f.read()
f.close() f.close()
data = re.sub('@SHA1SUM@', hash, data) data = re.sub('@SHA1SUM@', hash, data)
open(sys.argv[3], "w").write(data) open(sys.argv[3], "wb").write(data)

View File

@ -20,7 +20,7 @@ else:
print "EYOUFAILIT" print "EYOUFAILIT"
sys.exit(1) sys.exit(1)
certs, certlist = pywii.parse_certs(open(certfile).read()) certs, certlist = pywii.parse_certs(open(certfile,"rb").read())
signed.update_issuer(issuer) signed.update_issuer(issuer)

View File

@ -1 +0,0 @@
../Common/pywii

View File

@ -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 *

View File

@ -4,7 +4,7 @@ all:
clean distclean: clean distclean:
$(MAKE) -C stub distclean $(MAKE) -C stub distclean
$(MAKE) -C client clean $(MAKE) -C client distclean
install: install:
$(MAKE) -C client install $(MAKE) -C client install

View File

@ -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) static SRes LzmaEnc_Alloc(CLzmaEnc *p, UInt32 keepWindowSize, ISzAlloc *alloc, ISzAlloc *allocBig)
{ {
UInt32 beforeSize = kNumOpts; UInt32 beforeSize = kNumOpts;
Bool btMode;
if (!RangeEnc_Alloc(&p->rc, alloc)) if (!RangeEnc_Alloc(&p->rc, alloc))
return SZ_ERROR_MEM; return SZ_ERROR_MEM;
btMode = (p->matchFinderBase.btMode != 0);
#ifdef COMPRESS_MF_MT #ifdef COMPRESS_MF_MT
Bool btMode = (p->matchFinderBase.btMode != 0);
p->mtMode = (p->multiThread && !p->fastMode && btMode); p->mtMode = (p->multiThread && !p->fastMode && btMode);
#endif #endif

View File

@ -12,3 +12,5 @@ include ../../common.mk
install: all install: all
install -m 755 $(TARGET) $(WIIDEV)/bin 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

View File

@ -33,6 +33,7 @@
#ifndef _ELF_ABI_H #ifndef _ELF_ABI_H
#define _ELF_ABI_H #define _ELF_ABI_H
#include <sys/param.h>
#include "common.h" #include "common.h"
/* /*

View File

@ -4,6 +4,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <sys/param.h>
#include "common.h" #include "common.h"
#include "lzma.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) { void lzma_write(const char *filename, const lzma_t *lzma) {
int fd; FILE *fd;
int i; int i;
fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0755); fd = fopen(filename, "wb");
if (fd < 0) if (fd == NULL)
perrordie("Could not open file"); 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"); perrordie("Could not write to file");
u64 size = lzma->len_in; u64 size = lzma->len_in;
for (i = 0; i < 8; ++i) { for (i = 0; i < 8; ++i) {
u8 j = size & 0xff; u8 j = size & 0xff;
size >>= 8; size >>= 8;
if (write(fd, &j, 1) != 1) if (fwrite(&j, 1, 1, fd) != 1)
perrordie("Could not write to file"); 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"); perrordie("Could not write to file");
close(fd); fclose(fd);
} }

View File

@ -1,6 +1,7 @@
#ifndef _LZMA_H_ #ifndef _LZMA_H_
#define _LZMA_H_ #define _LZMA_H_
#include <sys/param.h>
#include "common.h" #include "common.h"
#include "LzmaEnc.h" #include "LzmaEnc.h"

View File

@ -6,6 +6,7 @@
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/param.h>
#include "common.h" #include "common.h"
#include "lzma.h" #include "lzma.h"
@ -83,51 +84,53 @@ static elf_t *read_stub(const char *name) {
} }
static elf_t *read_elf(const char *filename) { static elf_t *read_elf(const char *filename) {
int fd; FILE *f;
struct stat st; size_t len;
elf_t *elf; elf_t *elf;
printf("Reading %s\n", filename); printf("Reading %s\n", filename);
fd = open(filename, O_RDONLY); f = fopen(filename, "rb");
if (fd < 0) if (f == NULL)
perrordie("Could not open ELF file"); die("Could not open ELF file");
if (fstat(fd, &st)) fseek(f,0,SEEK_END);
perrordie("Could not stat ELF file"); 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"); die("File too short for ELF");
elf = (elf_t *) calloc(1, sizeof(elf_t)); elf = (elf_t *) calloc(1, sizeof(elf_t));
if (!elf) if (!elf)
die("Error allocating %u bytes", (u32) sizeof(elf_t)); die("Error allocating %u bytes", (u32) sizeof(elf_t));
elf->len = st.st_size; elf->len = len;
elf->data = (u8 *) malloc(elf->len); elf->data = (u8 *) malloc(elf->len);
printf("elf->len is %u bytes\n", elf->len);
if (!elf->data) if (!elf->data)
die("Error allocating %u bytes", elf->len); die("Error allocating %u bytes", elf->len);
if (read(fd, elf->data, elf->len) != elf->len) if ((u32)fread(elf->data, 1, elf->len, f) != elf->len)
perrordie("Could not read from file"); die("Could not read from file");
close(fd); fclose(f);
return elf; return elf;
} }
static void write_elf(const char *filename, const elf_t *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); f = fopen(filename, "wb");
if (fd < 0) if (f == NULL)
perrordie("Could not open ELF file"); die("Could not open ELF file");
if (write(fd, elf->data, elf->len) != elf->len) if ((u32)fwrite(elf->data, 1, elf->len, f) != elf->len)
perrordie("Could not write ELF file"); die("Could not write ELF file");
close(fd); fclose(f);
} }
static void free_elf(elf_t *elf) { static void free_elf(elf_t *elf) {

View File

@ -1 +0,0 @@
../stub/stub_dkf.c

View File

@ -1 +0,0 @@
../stub/stub_dkf_debug.c

View File

@ -1 +0,0 @@
../stub/stub_dkfc.c

View File

@ -1 +0,0 @@
../stub/stub_dkfc_debug.c

View File

@ -1 +0,0 @@
../stub/stub_mini.c

View File

@ -1 +0,0 @@
../stub/stub_mini_debug.c

View File

@ -43,6 +43,7 @@ all: xxd
xxd: $(TARGET) xxd: $(TARGET)
@echo " XXD $^" @echo " XXD $^"
@xxd -i $(TARGET) > $(subst .elf,.c,$(TARGET)) @xxd -i $(TARGET) > $(subst .elf,.c,$(TARGET))
@cp -f $(subst .elf,.c,$(TARGET)) ../client
distclean: clean distclean: clean
rm -f stub_*.elf stub_*.c rm -f stub_*.elf stub_*.c