mirror of
https://github.com/FIX94/hbc.git
synced 2024-11-21 18:19:19 +01:00
-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:
parent
2fb61e432e
commit
4cf05be0ff
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,5 +5,6 @@
|
||||
.*.swp
|
||||
*.dSYM
|
||||
*.pyc
|
||||
*.exe
|
||||
.DS_Store
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
@ -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 $@
|
||||
|
@ -1,9 +1,11 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <ogcsys.h>
|
||||
#include <ogc/lwp_watchdog.h>
|
||||
#include <wiidrc/wiidrc.h>
|
||||
|
||||
#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;
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
../00000000
|
@ -1 +0,0 @@
|
||||
../00000001
|
@ -1 +0,0 @@
|
||||
../footer
|
@ -1 +0,0 @@
|
||||
../00000000
|
@ -1 +0,0 @@
|
||||
../00000001
|
@ -1 +0,0 @@
|
||||
../footer
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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 ]
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
||||
|
@ -1 +0,0 @@
|
||||
../Common/pywii
|
3
pywii/pywii-tools/pywii.py
Normal file
3
pywii/pywii-tools/pywii.py
Normal 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 *
|
@ -4,7 +4,7 @@ all:
|
||||
|
||||
clean distclean:
|
||||
$(MAKE) -C stub distclean
|
||||
$(MAKE) -C client clean
|
||||
$(MAKE) -C client distclean
|
||||
|
||||
install:
|
||||
$(MAKE) -C client install
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -33,6 +33,7 @@
|
||||
#ifndef _ELF_ABI_H
|
||||
#define _ELF_ABI_H
|
||||
|
||||
#include <sys/param.h>
|
||||
#include "common.h"
|
||||
|
||||
/*
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
#ifndef _LZMA_H_
|
||||
#define _LZMA_H_
|
||||
|
||||
#include <sys/param.h>
|
||||
#include "common.h"
|
||||
#include "LzmaEnc.h"
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
#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) {
|
||||
|
@ -1 +0,0 @@
|
||||
../stub/stub_dkf.c
|
@ -1 +0,0 @@
|
||||
../stub/stub_dkf_debug.c
|
@ -1 +0,0 @@
|
||||
../stub/stub_dkfc.c
|
@ -1 +0,0 @@
|
||||
../stub/stub_dkfc_debug.c
|
@ -1 +0,0 @@
|
||||
../stub/stub_mini.c
|
@ -1 +0,0 @@
|
||||
../stub/stub_mini_debug.c
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user