Skip to content

Commit

Permalink
Introducing lite version, which doesn't require any external file
Browse files Browse the repository at this point in the history
Updating copyright dates, since this is my new year eve's update :)
Taggint as 0.4.4
  • Loading branch information
pixel committed Dec 26, 2004
1 parent 158808b commit 4d911ef
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 25 deletions.
49 changes: 39 additions & 10 deletions Makefile
Expand Up @@ -6,8 +6,9 @@ SHELL = /bin/sh
SYSTEM = $(shell uname) SYSTEM = $(shell uname)
LIBZA = /usr/lib/libz.a LIBZA = /usr/lib/libz.a
LIBUCLA = /usr/lib/libucl.a LIBUCLA = /usr/lib/libucl.a
VERSION = 0.4.3 VERSION = 0.4.4
CC = gcc CC = gcc
BIN2O = ld -r -b binary
CPPFLAGS = -O3 -Wall -I. -DVERSION=\"$(VERSION)\" -DPREFIX=\"$(PREFIX)\" CPPFLAGS = -O3 -Wall -I. -DVERSION=\"$(VERSION)\" -DPREFIX=\"$(PREFIX)\"
INSTALL = install INSTALL = install


Expand All @@ -23,7 +24,7 @@ endif


PACKERS = zlib-packer lzo-packer n2b-packer n2d-packer n2e-packer null-packer PACKERS = zlib-packer lzo-packer n2b-packer n2d-packer n2e-packer null-packer


all: ps2-packer packers stubs all: ps2-packer ps2-packer-lite packers stubs


install: all install: all
$(INSTALL) -d $(PREFIX)/bin $(INSTALL) -d $(PREFIX)/bin
Expand All @@ -37,8 +38,24 @@ install: all
ps2-packer: ps2-packer.c dlopen.c ps2-packer: ps2-packer.c dlopen.c
$(CC) $(CPPFLAGS) ps2-packer.c dlopen.c -o ps2-packer -ldl $(CC) $(CPPFLAGS) ps2-packer.c dlopen.c -o ps2-packer -ldl


stubs: ps2-packer-lite: ps2-packer.c builtin_stub_one.o builtin_stub.o
$(CC) $(CPPFLAGS) -DPS2_PACKER_LITE ps2-packer.c n2e-packer.c $(LIBUCLA) builtin_stub_one.o builtin_stub.o -o ps2-packer-lite

builtin_stub_one.o: stubs-tag.stamp
cp stub/n2e-asm-one-1d00-stub ./b_stub_one
$(BIN2O) b_stub_one -o builtin_stub_one.o
rm b_stub_one

builtin_stub.o: stubs-tag.stamp
cp stub/n2e-asm-1d00-stub ./b_stub
$(BIN2O) b_stub -o builtin_stub.o
rm b_stub

stubs: stubs-tag.stamp

stubs-tag.stamp:
$(SUBMAKE) stub $(SUBMAKE) stub
touch stubs-tag.stamp


packers: $(addsuffix $(SHAREDSUFFIX),$(PACKERS)) packers: $(addsuffix $(SHAREDSUFFIX),$(PACKERS))


Expand Down Expand Up @@ -68,8 +85,9 @@ stubs-dist:
$(SUBMAKE) stub dist $(SUBMAKE) stub dist


clean: clean:
rm -f ps2-packer ps2-packer.exe *.zip *.gz *.dll *.so *.o rm -f ps2-packer ps2-packer-lite ps2-packer.exe ps2-packer-lite.exe *.zip *.gz *.dll *.so *.o mingw-builtin_stub_one.h mingw-builtin_stub.h
$(SUBMAKE) stub clean $(SUBMAKE) stub clean
rm -f stubs-tag.stamp


rebuild: clean all rebuild: clean all


Expand All @@ -79,13 +97,22 @@ rebuild: clean all
# Everything below is for me, building the distribution packages. # Everything below is for me, building the distribution packages.
# #


mingw: ps2-packer.exe mingw-packers mingw: ps2-packer.exe ps2-packer-lite.exe mingw-packers


MINGW_LIBGCC = /usr/lib/gcc-lib/i586-mingw32msvc/2.95.3-7/libgcc.a MINGW_LIBGCC = /usr/lib/gcc-lib/i586-mingw32msvc/2.95.3-7/libgcc.a


ps2-packer.exe: ps2-packer.c dlopen.c ps2-packer.exe: ps2-packer.c dlopen.c
i586-mingw32msvc-gcc $(CPPFLAGS) ps2-packer.c dlopen.c -o ps2-packer.exe -I mingw-getopt mingw-getopt/getopt*.c i586-mingw32msvc-gcc $(CPPFLAGS) ps2-packer.c dlopen.c -o ps2-packer.exe -I mingw-getopt mingw-getopt/getopt*.c


ps2-packer-lite.exe: ps2-packer.c n2e-packer.c mingw-ucl mingw-ucl mingw-builtin_stub_one.h mingw-builtin_stub.h
i586-mingw32msvc-gcc $(CPPFLAGS) -DPS2_PACKER_LITE ps2-packer.c n2e-packer.c -o ps2-packer-lite.exe -I mingw-getopt -I mingw-ucl mingw-getopt/getopt*.c mingw-ucl/ucl.a

mingw-builtin_stub_one.h: stubs-tag.stamp
/usr/local/ps2dev/ps2sdk/bin/bin2c stub/n2e-asm-one-1d00-stub mingw-builtin_stub_one.h _binary_b_stub_one_start

mingw-builtin_stub.h: stubs-tag.stamp
/usr/local/ps2dev/ps2sdk/bin/bin2c stub/n2e-asm-1d00-stub mingw-builtin_stub.h _binary_b_stub_start

mingw-packers: $(addsuffix .dll,$(PACKERS)) mingw-packers: $(addsuffix .dll,$(PACKERS))


mingw-zlib: mingw-zlib:
Expand Down Expand Up @@ -156,17 +183,19 @@ null-packer.dll: null-packer.c dllinit.o
rm tmp.base tmp.exp tmp.def null-packer.o rm tmp.base tmp.exp tmp.def null-packer.o


dist: all mingw COPYING stubs-dist README.txt ps2-packer.c $(addsuffix .c,$(PACKERS)) dist: all mingw COPYING stubs-dist README.txt ps2-packer.c $(addsuffix .c,$(PACKERS))
strip ps2-packer $(addsuffix .so,$(PACKERS)) strip ps2-packer ps2-packer-lite $(addsuffix .so,$(PACKERS))
i586-mingw32msvc-strip ps2-packer.exe $(addsuffix .dll,$(PACKERS)) i586-mingw32msvc-strip ps2-packer.exe ps2-packer-lite.exe $(addsuffix .dll,$(PACKERS))
upx-nrv --best ps2-packer ps2-packer.exe $(addsuffix .dll,$(PACKERS)) upx-nrv --best ps2-packer ps2-packer-lite ps2-packer.exe ps2-packer-lite.exe $(addsuffix .dll,$(PACKERS))
tar cvfz ps2-packer-$(VERSION)-linux.tar.gz ps2-packer $(addsuffix .so,$(PACKERS)) COPYING stub/*stub README.txt tar cvfz ps2-packer-$(VERSION)-linux.tar.gz ps2-packer $(addsuffix .so,$(PACKERS)) COPYING stub/*stub README.txt
zip -9 ps2-packer-$(VERSION)-win32.zip ps2-packer.exe $(addsuffix .dll,$(PACKERS)) COPYING stub/*stub README.txt zip -9 ps2-packer-$(VERSION)-win32.zip ps2-packer.exe $(addsuffix .dll,$(PACKERS)) COPYING stub/*stub README.txt
tar cvfz ps2-packer-$(VERSION)-src.tar.gz *.{c,h} Makefile COPYING stub/{Makefile,crt0.s,linkfile,*.{c,h,S}} stub/ucl/*.S stub/{zlib,lzo,ucl}/{Makefile,*.{c,h}} README.txt tar cvfz ps2-packer-lite-$(VERSION)-linux.tar.gz ps2-packer-lite COPYING README.txt README-lite.txt
zip -9 ps2-packer-lite-$(VERSION)-win32.zip ps2-packer-lite.exe COPYING README.txt README-lite.txt
tar cvfz ps2-packer-$(VERSION)-src.tar.gz *.{c,h} Makefile COPYING stub/{Makefile,crt0.s,linkfile,*.{c,h,S}} stub/ucl/*.S stub/{zlib,lzo,ucl}/{Makefile,*.{c,h}} README.txt README-lite.txt


redist: clean mingw-clean dist redist: clean mingw-clean dist


release: redist release: redist
rm -f /var/www/ps2-packer/* rm -f /var/www/ps2-packer/*
cp *.gz *.zip COPYING README.txt /var/www/ps2-packer cp *.gz *.zip COPYING README.txt README-lite.txt /var/www/ps2-packer


.PHONY: mingw-zlib mingw-ucl .PHONY: mingw-zlib mingw-ucl
6 changes: 5 additions & 1 deletion README.txt
@@ -1,4 +1,4 @@
PS2-Packer version 0.4.3 PS2-Packer version 0.4.4
======================== ========================


Overview Overview
Expand Down Expand Up @@ -58,6 +58,10 @@ Changelog
fixed a multiple-section critical bug. fixed a multiple-section critical bug.
fixed a bit the asm stub code. fixed a bit the asm stub code.
tagging as 0.4.3 tagging as 0.4.3
2004/12/26: added reload option, and used branches instead of jumps in
the asm stubs.
created lite version - see README-lite.txt for informations.
tagging as 0.4.4




Todo Todo
Expand Down
2 changes: 1 addition & 1 deletion lzo-packer.c
@@ -1,6 +1,6 @@
/* /*
* PS2-Packer * PS2-Packer
* Copyright (C) 2004 Nicolas "Pixel" Noble * Copyright (C) 2004-2005 Nicolas "Pixel" Noble
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion n2b-packer.c
@@ -1,6 +1,6 @@
/* /*
* PS2-Packer * PS2-Packer
* Copyright (C) 2004 Nicolas "Pixel" Noble * Copyright (C) 2004-2005 Nicolas "Pixel" Noble
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion n2d-packer.c
@@ -1,6 +1,6 @@
/* /*
* PS2-Packer * PS2-Packer
* Copyright (C) 2004 Nicolas "Pixel" Noble * Copyright (C) 2004-2005 Nicolas "Pixel" Noble
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion n2e-packer.c
@@ -1,6 +1,6 @@
/* /*
* PS2-Packer * PS2-Packer
* Copyright (C) 2004 Nicolas "Pixel" Noble * Copyright (C) 2004-2005 Nicolas "Pixel" Noble
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion null-packer.c
@@ -1,6 +1,6 @@
/* /*
* PS2-Packer * PS2-Packer
* Copyright (C) 2004 Nicolas "Pixel" Noble * Copyright (C) 2004-2005 Nicolas "Pixel" Noble
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
Expand Down
72 changes: 64 additions & 8 deletions ps2-packer.c
@@ -1,6 +1,6 @@
/* /*
* PS2-Packer * PS2-Packer
* Copyright (C) 2004 Nicolas "Pixel" Noble * Copyright (C) 2004-2005 Nicolas "Pixel" Noble
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
Expand All @@ -23,7 +23,9 @@
#include <string.h> #include <string.h>
#include <getopt.h> #include <getopt.h>
#include <stdarg.h> #include <stdarg.h>
#ifndef PS2_PACKER_LITE
#include "dlopen.h" #include "dlopen.h"
#endif


#ifdef _WIN32 #ifdef _WIN32
#define SUFFIX ".dll" #define SUFFIX ".dll"
Expand Down Expand Up @@ -55,17 +57,21 @@ u32 reload = 0;
u8 alternative = 0; /* boolean for alternative loading method */ u8 alternative = 0; /* boolean for alternative loading method */
u32 alignment = 0x10; u32 alignment = 0x10;


int sections;

/* /*
This is the pointer in our output elf file. This is the pointer in our output elf file.
*/ */
u32 data_pointer; u32 data_pointer;


struct option long_options[] = { struct option long_options[] = {
{"help", 0, NULL, 'h'}, {"help", 0, NULL, 'h'},
{"packer", 1, NULL, 'p'},
{"base", 1, NULL, 'b'}, {"base", 1, NULL, 'b'},
{"reload", 1, NULL, 'r'}, {"reload", 1, NULL, 'r'},
#ifndef PS2_PACKER_LITE
{"packer", 1, NULL, 'p'},
{"stub", 1, NULL, 's'}, {"stub", 1, NULL, 's'},
#endif
{"align", 1, NULL, 'a'}, {"align", 1, NULL, 'a'},
{"verbose", 1, NULL, 'v'}, {"verbose", 1, NULL, 'v'},
{0, 0, NULL, 0 }, {0, 0, NULL, 0 },
Expand All @@ -90,10 +96,12 @@ void printv(char * fmt, ...) {
va_end(list); va_end(list);
} }


#ifndef PS2_PACKER_LITE
typedef int (*pack_section_t)(const u8 * source, u8 ** dest, u32 source_size); typedef int (*pack_section_t)(const u8 * source, u8 ** dest, u32 source_size);
pack_section_t pack_section; pack_section_t pack_section;
typedef u32 (*signature_t)(); typedef u32 (*signature_t)();
signature_t signature; signature_t signature;
#endif


u8 bigendian = 0; u8 bigendian = 0;
u32 ELF_MAGIC = 0x464c457f; u32 ELF_MAGIC = 0x464c457f;
Expand Down Expand Up @@ -212,21 +220,27 @@ void sanity_checks() {


void show_banner() { void show_banner() {
printf( printf(
"PS2-Packer v" VERSION " (C) 2004 Nicolas \"Pixel\" Noble\n" "PS2-Packer v" VERSION " (C) 2004-2005 Nicolas \"Pixel\" Noble\n"
"This is free software with ABSOLUTELY NO WARRANTY.\n" "This is free software with ABSOLUTELY NO WARRANTY.\n"
"\n" "\n"
); );
} }


void show_usage() { void show_usage() {
printf( printf(
"Usage: ps2-packer [-v] [-a X] [-b X] [-p X] [-s X] [-r X] <in_elf> <out_elf>\n" "Usage: ps2-packer [-v] [-a X] [-b X] "
#ifndef PS2_PACKER_LITE
"[-p X] [-s X] "
#endif
"[-r X] <in_elf> <out_elf>\n"
" -v verbose mode.\n" " -v verbose mode.\n"
" -b base sets the loading base of the compressed data. When activated\n" " -b base sets the loading base of the compressed data. When activated\n"
" it will activate the alternative packing way.\n" " it will activate the alternative packing way.\n"
#ifndef PS2_PACKER_LITE
" -p packer sets a packer name. n2e by default.\n" " -p packer sets a packer name. n2e by default.\n"
" -s stub sets another uncruncher stub. stub/n2e-asm-1d00-stub,\n" " -s stub sets another uncruncher stub. stub/n2e-asm-1d00-stub,\n"
" or stub/n2e-0088-stub when using alternative packing.\n" " or stub/n2e-0088-stub when using alternative packing.\n"
#endif
" -r reload sets a reload base of the stub. Beware, that will only works\n" " -r reload sets a reload base of the stub. Beware, that will only works\n"
" with the special asm stubs.\n" " with the special asm stubs.\n"
" -a align sets section alignment. 16 by default. Any value accepted.\n" " -a align sets section alignment. 16 by default. Any value accepted.\n"
Expand Down Expand Up @@ -310,21 +324,42 @@ int count_sections(FILE * stub) {
return r; return r;
} }


#ifdef PS2_PACKER_LITE
#ifdef __MINGW32__
#include "mingw-builtin_stub_one.h"
#include "mingw-builtin_stub.h"
#endif
extern u8 _binary_b_stub_one_start[];
extern u8 _binary_b_stub_start[];
#endif

/* Loads the stub file in memory, filling up the global variables */ /* Loads the stub file in memory, filling up the global variables */
void load_stub(FILE * stub) { void load_stub(
#ifndef PS2_PACKER_LITE
FILE * stub
#endif
) {
u8 * loadbuf, * pdata; u8 * loadbuf, * pdata;
int size; int size;
int i; int i;
elf_header_t *eh = 0; elf_header_t *eh = 0;
elf_pheader_t *eph = 0; elf_pheader_t *eph = 0;
int loaded = 0; int loaded = 0;


#ifndef PS2_PACKER_LITE
fseek(stub, 0, SEEK_END); fseek(stub, 0, SEEK_END);
size = ftell(stub); size = ftell(stub);
fseek(stub, 0, SEEK_SET); fseek(stub, 0, SEEK_SET);


loadbuf = (u8 *) malloc(size); loadbuf = (u8 *) malloc(size);
fread(loadbuf, 1, size, stub); fread(loadbuf, 1, size, stub);
#else
if (sections == 1) {
loadbuf = _binary_b_stub_one_start;
} else {
loadbuf = _binary_b_stub_start;
}
#endif


eh = (elf_header_t *)loadbuf; eh = (elf_header_t *)loadbuf;
SWAP_ELF_HEADER((*eh)); SWAP_ELF_HEADER((*eh));
Expand Down Expand Up @@ -369,7 +404,9 @@ void load_stub(FILE * stub) {
remove_section_zeroes(stub_section, &stub_size, &stub_zero); remove_section_zeroes(stub_section, &stub_size, &stub_zero);
printv("Loaded stub: %08X bytes (with %08X zeroes) based at %08X\n", stub_size, stub_zero, stub_base); printv("Loaded stub: %08X bytes (with %08X zeroes) based at %08X\n", stub_size, stub_zero, stub_base);


#ifndef PS2_PACKER_LITE
free(loadbuf); free(loadbuf);
#endif
} }


/* Write out the basic elf structures, that is, the ELF header, /* Write out the basic elf structures, that is, the ELF header,
Expand Down Expand Up @@ -605,15 +642,20 @@ int main(int argc, char ** argv) {
char c; char c;
u32 base = 0; u32 base = 0;
char buffer[BUFSIZ + 1]; char buffer[BUFSIZ + 1];
#ifndef PS2_PACKER_LITE
char * packer_name = 0; char * packer_name = 0;
char * stub_name = 0; char * stub_name = 0;
char * packer_dll = 0; char * packer_dll = 0;
#endif
char * in_name; char * in_name;
char * out_name; char * out_name;
void * packer_module = 0; void * packer_module = 0;
FILE * stub_file, * in, * out; #ifndef PS2_PACKER_LITE
FILE * stub_file;
#endif
FILE * in, * out;
u32 size_in, size_out; u32 size_in, size_out;
int sections, use_asm_n2e = 0; int use_asm_n2e = 0;
char * pwd; char * pwd;


sanity_checks(); sanity_checks();
Expand All @@ -628,7 +670,11 @@ int main(int argc, char ** argv) {


pwd = argv[0]; pwd = argv[0];


while ((c = getopt_long(argc, argv, "b:a:p:s:hvr:", long_options, NULL)) != EOF) { while ((c = getopt_long(argc, argv, "b:a:"
#ifndef PS2_PACKER_LITE
"p:s:"
#endif
"hvr:", long_options, NULL)) != EOF) {
switch (c) { switch (c) {
case 'b': case 'b':
base = strtol(optarg, NULL, 0); base = strtol(optarg, NULL, 0);
Expand All @@ -637,12 +683,14 @@ int main(int argc, char ** argv) {
case 'a': case 'a':
alignment = strtol(optarg, NULL, 0); alignment = strtol(optarg, NULL, 0);
break; break;
#ifndef PS2_PACKER_LITE
case 'p': case 'p':
packer_name = strdup(optarg); packer_name = strdup(optarg);
break; break;
case 's': case 's':
stub_name = strdup(optarg); stub_name = strdup(optarg);
break; break;
#endif
case 'r': case 'r':
reload = strtol(optarg, NULL, 0); reload = strtol(optarg, NULL, 0);
break; break;
Expand Down Expand Up @@ -679,6 +727,7 @@ int main(int argc, char ** argv) {


sections = count_sections(in); sections = count_sections(in);


#ifndef PS2_PACKER_LITE
if (!packer_name) { if (!packer_name) {
packer_name = "n2e"; packer_name = "n2e";
} }
Expand Down Expand Up @@ -724,17 +773,24 @@ int main(int argc, char ** argv) {
} }


packer_dll = strdup(buffer); packer_dll = strdup(buffer);
#endif


printf("Compressing %s...\n", in_name); printf("Compressing %s...\n", in_name);


printv("Loading stub file.\n"); printv("Loading stub file.\n");
#ifndef PS2_PACKER_LITE
load_stub(stub_file); load_stub(stub_file);
fclose(stub_file); fclose(stub_file);
#else
load_stub();
#endif


#ifndef PS2_PACKER_LITE
printv("Opening packer.\n"); printv("Opening packer.\n");
packer_module = open_module(packer_dll); packer_module = open_module(packer_dll);
pack_section = get_symbol(packer_module, "pack_section"); pack_section = get_symbol(packer_module, "pack_section");
signature = get_symbol(packer_module, "signature"); signature = get_symbol(packer_module, "signature");
#endif
if (signature() != stub_signature) { if (signature() != stub_signature) {
printe("Packer's signature and stub's signature are not matching.\n"); printe("Packer's signature and stub's signature are not matching.\n");
} }
Expand Down
2 changes: 1 addition & 1 deletion zlib-packer.c
@@ -1,6 +1,6 @@
/* /*
* PS2-Packer * PS2-Packer
* Copyright (C) 2004 Nicolas "Pixel" Noble * Copyright (C) 2004-2005 Nicolas "Pixel" Noble
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
Expand Down

0 comments on commit 4d911ef

Please sign in to comment.