Skip to content

Commit

Permalink
Abort when insufficient arguments are specified, return EINVAL for
Browse files Browse the repository at this point in the history
incorrect argument errors and fixed warnings.
  • Loading branch information
sp193 committed Aug 23, 2018
1 parent af97d3c commit e914733
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 9 deletions.
2 changes: 2 additions & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,7 @@ typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;

int pack_section(const u8 * source, u8 ** dest, u32 source_size);

#endif // __COMMON_H__

17 changes: 12 additions & 5 deletions ps2-packer.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <getopt.h>
Expand Down Expand Up @@ -95,7 +96,7 @@ void printv(char * fmt, ...) {

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

psh.compressedSize = packed_size = pack_section(pdata, &packed, section_size);
#ifndef PS2_PACKER_LITE
packed_size = ppack_section(pdata, &packed, section_size);
#else
packed_size = pack_section(pdata, &packed, section_size);
#endif
psh.compressedSize = packed_size;

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

Expand Down Expand Up @@ -705,16 +711,17 @@ int main(int argc, char ** argv) {
default:
printf("Unknown option %c\n\n", c);
show_usage();
exit(-1);
exit(EINVAL);
}
}

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

if ((argc - optind) != 2) {
printf("%i files specified, I need exactly 2.\n\n", argc - optind);
printe("%i files specified, I need exactly 2.\n\n", argc - optind);
show_usage();
exit(EINVAL);
}

in_name = argv[optind++];
Expand Down Expand Up @@ -794,7 +801,7 @@ int main(int argc, char ** argv) {
#ifndef PS2_PACKER_LITE
printv("Opening packer %s.\n", packer_dll);
packer_module = open_module(packer_dll);
pack_section = get_symbol(packer_module, "pack_section");
ppack_section = get_symbol(packer_module, "pack_section");
signature = get_symbol(packer_module, "signature");
if (signature() != stub_signature) {
printe("Packer's signature and stub's signature are not matching.\n");
Expand Down
2 changes: 1 addition & 1 deletion stub/main-kmode.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int main(int argc, char ** argv) {
fast_memzero((void *)(sectionHeader->virtualAddr + sectionHeader->originalSize), sectionHeader->zeroByteSize);
compressedData += sectionHeader->compressedSize;
if (((u32) compressedData) & 3)
compressedData = (u32 *) ((((u32)compressedData) | 3) + 1);
compressedData = (u8 *) ((((u32)compressedData) | 3) + 1);
}

ee_kmode_exit();
Expand Down
2 changes: 1 addition & 1 deletion stub/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ int main(int argc, char ** argv) {
fast_memzero((void *)(sectionHeader->virtualAddr + sectionHeader->originalSize), sectionHeader->zeroByteSize);
compressedData += sectionHeader->compressedSize;
if (((u32) compressedData) & 3)
compressedData = (u32 *) ((((u32)compressedData) | 3) + 1);
compressedData = (u8 *) ((((u32)compressedData) | 3) + 1);
}

#ifdef DEBUG
Expand Down
2 changes: 1 addition & 1 deletion stub/zlib-stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void Decompress(u8 *dest, const u8 *src, u32 dst_size, u32 src_size) {
d_stream.zfree = (free_func)0;
d_stream.opaque = (voidpf)0;

d_stream.next_in = src;
d_stream.next_in = (u8*)src;
d_stream.avail_in = src_size;
d_stream.next_out = dest;
d_stream.avail_out = dst_size;
Expand Down
2 changes: 1 addition & 1 deletion zlib-packer.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int pack_section(const u8 * source, u8 ** dest, u32 source_size) {
if (deflateInit(&c_stream, 9) != Z_OK)
printe("Error during deflateInit.\n");

c_stream.next_in = source;
c_stream.next_in = (u8*)source;
c_stream.avail_in = source_size;
c_stream.next_out = packed;
c_stream.avail_out = packed_size;
Expand Down

0 comments on commit e914733

Please sign in to comment.