Skip to content

Commit e914733

Browse files
committed
Abort when insufficient arguments are specified, return EINVAL for
incorrect argument errors and fixed warnings.
1 parent af97d3c commit e914733

File tree

6 files changed

+18
-9
lines changed

6 files changed

+18
-9
lines changed

common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ typedef uint8_t u8;
77
typedef uint16_t u16;
88
typedef uint32_t u32;
99

10+
int pack_section(const u8 * source, u8 ** dest, u32 source_size);
11+
1012
#endif // __COMMON_H__
1113

ps2-packer.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <stdlib.h>
2121
#include <unistd.h>
22+
#include <errno.h>
2223
#include <stdio.h>
2324
#include <string.h>
2425
#include <getopt.h>
@@ -95,7 +96,7 @@ void printv(char * fmt, ...) {
9596

9697
#ifndef PS2_PACKER_LITE
9798
typedef int (*pack_section_t)(const u8 * source, u8 ** dest, u32 source_size);
98-
pack_section_t pack_section;
99+
pack_section_t ppack_section;
99100
typedef u32 (*signature_t)();
100101
signature_t signature;
101102
#endif
@@ -563,7 +564,12 @@ void packing(FILE * out, FILE * in, u32 base, int use_asm_n2e) {
563564
remove_section_zeroes(pdata, &section_size, &psh.zeroByteSize);
564565
printv("Loaded section: %08X bytes (with %08X zeroes) based at %08X\n", psh.originalSize, psh.zeroByteSize, psh.virtualAddr);
565566

566-
psh.compressedSize = packed_size = pack_section(pdata, &packed, section_size);
567+
#ifndef PS2_PACKER_LITE
568+
packed_size = ppack_section(pdata, &packed, section_size);
569+
#else
570+
packed_size = pack_section(pdata, &packed, section_size);
571+
#endif
572+
psh.compressedSize = packed_size;
567573

568574
printv("Section packed, from %u to %u bytes, ratio = %5.2f%%\n", section_size, packed_size, 100.0 * (section_size - packed_size) / section_size);
569575

@@ -705,16 +711,17 @@ int main(int argc, char ** argv) {
705711
default:
706712
printf("Unknown option %c\n\n", c);
707713
show_usage();
708-
exit(-1);
714+
exit(EINVAL);
709715
}
710716
}
711717

712718
if (alternative)
713719
printv("Using alternative packing method.\n");
714720

715721
if ((argc - optind) != 2) {
716-
printf("%i files specified, I need exactly 2.\n\n", argc - optind);
722+
printe("%i files specified, I need exactly 2.\n\n", argc - optind);
717723
show_usage();
724+
exit(EINVAL);
718725
}
719726

720727
in_name = argv[optind++];
@@ -794,7 +801,7 @@ int main(int argc, char ** argv) {
794801
#ifndef PS2_PACKER_LITE
795802
printv("Opening packer %s.\n", packer_dll);
796803
packer_module = open_module(packer_dll);
797-
pack_section = get_symbol(packer_module, "pack_section");
804+
ppack_section = get_symbol(packer_module, "pack_section");
798805
signature = get_symbol(packer_module, "signature");
799806
if (signature() != stub_signature) {
800807
printe("Packer's signature and stub's signature are not matching.\n");

stub/main-kmode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ int main(int argc, char ** argv) {
5252
fast_memzero((void *)(sectionHeader->virtualAddr + sectionHeader->originalSize), sectionHeader->zeroByteSize);
5353
compressedData += sectionHeader->compressedSize;
5454
if (((u32) compressedData) & 3)
55-
compressedData = (u32 *) ((((u32)compressedData) | 3) + 1);
55+
compressedData = (u8 *) ((((u32)compressedData) | 3) + 1);
5656
}
5757

5858
ee_kmode_exit();

stub/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ int main(int argc, char ** argv) {
7474
fast_memzero((void *)(sectionHeader->virtualAddr + sectionHeader->originalSize), sectionHeader->zeroByteSize);
7575
compressedData += sectionHeader->compressedSize;
7676
if (((u32) compressedData) & 3)
77-
compressedData = (u32 *) ((((u32)compressedData) | 3) + 1);
77+
compressedData = (u8 *) ((((u32)compressedData) | 3) + 1);
7878
}
7979

8080
#ifdef DEBUG

stub/zlib-stub.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ void Decompress(u8 *dest, const u8 *src, u32 dst_size, u32 src_size) {
1111
d_stream.zfree = (free_func)0;
1212
d_stream.opaque = (voidpf)0;
1313

14-
d_stream.next_in = src;
14+
d_stream.next_in = (u8*)src;
1515
d_stream.avail_in = src_size;
1616
d_stream.next_out = dest;
1717
d_stream.avail_out = dst_size;

zlib-packer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ int pack_section(const u8 * source, u8 ** dest, u32 source_size) {
4646
if (deflateInit(&c_stream, 9) != Z_OK)
4747
printe("Error during deflateInit.\n");
4848

49-
c_stream.next_in = source;
49+
c_stream.next_in = (u8*)source;
5050
c_stream.avail_in = source_size;
5151
c_stream.next_out = packed;
5252
c_stream.avail_out = packed_size;

0 commit comments

Comments
 (0)