Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash on command line option(s) without path #116

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ endif()
set(CMAKE_CXX_FLAGS_TEST "-Ofast")
set(CMAKE_C_FLAGS_TEST "-Ofast -funroll-loops -fprefetch-loop-arrays -march=native")

set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD 17)
set(CMAKE_CXX_STANDARD 11)

set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake-modules/")
Expand Down
11 changes: 11 additions & 0 deletions include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@
#define __COMMON_H

/* Branch Prediction Hints */
#ifdef __GNUC__
#define LIKELY(x) __builtin_expect (!!(x), 1)
#define UNLIKELY(x) __builtin_expect (!!(x), 0)
#else
#define LIKELY(x) (x)
#define UNLIKELY(x) (x)
#endif

#ifdef __GNUC__
#define UNUSED(x) UNUSED_ ## x __attribute__((__unused__))
Expand All @@ -21,6 +26,12 @@
#define UNUSED_FUNCTION(x) UNUSED_ ## x
#endif

#ifdef __GNUC__
#define FORMAT_PRINTF(x, y) __attribute__((__format__(__printf__, (x), (y))))
#else
#define FORMAT_PRINTF(x, y)
#endif

#define countof(x) (sizeof(x) / sizeof((x)[0]))

#endif
2 changes: 1 addition & 1 deletion include/u-boot/partcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ typedef enum {

unsigned int dump_partinfo(const char *filename, const char *outfile);

extern char *modelname;
extern const char *modelname;
extern part_struct_type part_type;

#endif /* _PART_COMMON_H_ */
25 changes: 9 additions & 16 deletions include/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ extern "C" {
#include <stddef.h>
#include <stdlib.h>
#include <elf.h>
#include "common.h"
#include "mfile.h"

#define member_size(type, member) sizeof(((type *)0)->member)
#define err_exit(fmt, ...) \
exit(err_ret(fmt, ##__VA_ARGS__))
exit(err_ret((fmt), ##__VA_ARGS__))

#ifdef __APPLE__
typedef unsigned int uint;
Expand All @@ -29,9 +30,11 @@ char *my_basename(const char *path);
char *my_dirname(const char *path);
int count_tokens(const char *str, char token, int sz);
void getch(void);
void hexdump(void *pAddressIn, long lSize);
void hexdump(const void *pAddressIn, long lSize);
void rmrf(const char *path);
int err_ret(const char *format, ...);

/* Print message and return EXIT_FAILURE. (On Cygwin, also waits for keypress.) */
int err_ret(const char *format, ...) FORMAT_PRINTF(1, 2);

char *remove_ext(const char *mystr);
char *get_ext(const char *mystr);
Expand All @@ -43,32 +46,22 @@ void unnfsb(const char *filename, const char *extractedFile);
MFILE *is_gzip(const char *filename);
int is_jffs2(const char *filename);
int isSTRfile(const char *filename);
int isdatetime(char *datetime);
int isdatetime(const char *datetime);
int isPartPakfile(const char *filename);
int is_kernel(const char *image_file);
void extract_kernel(const char *image_file, const char *destination_file);
int asprintf_inplace(char** strp, const char* fmt, ...);
int asprintf_inplace(char **strp, const char *fmt, ...) FORMAT_PRINTF(2, 3);


#include <errno.h>
void print(int verbose, int newline, char *fn, int lineno, const char *fmt, ...);
void print(int verbose, int newline, const char *fn, int lineno, const char *fmt, ...) FORMAT_PRINTF(5, 6);
#define WHEREARG __FILE__, __LINE__
#define PRINT(...) print(0, 0 , WHEREARG, __VA_ARGS__)
#define VERBOSE(N,...) print(N, 0, WHEREARG, __VA_ARGS__)
#define VERBOSE_NN(N,...) print(N, 0, WHEREARG, __VA_ARGS__)
#define PERROR_SE(fmt, ...) print(0, 0, WHEREARG, "ERROR: " fmt " (%s)", ## __VA_ARGS__, strerror(errno))
#define PERROR(...) print(0, 1, WHEREARG, "ERROR: " __VA_ARGS__)

#if __WORDSIZE == 64
# define LX "%lx"
# define LLX LX
# define LU "%lu"
#else
# define LX "%x"
# define LLX "%llx"
# define LU "%u"
#endif

#ifdef __cplusplus
}
#endif
Expand Down
31 changes: 22 additions & 9 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
#include <mach-o/dyld.h>
#endif

static int print_usage(void);

config_opts_t config_opts;

int handle_file(char *file, config_opts_t *config_opts) {
Expand Down Expand Up @@ -214,13 +216,7 @@ int handle_file(char *file, config_opts_t *config_opts) {
int main(int argc, char *argv[]) {
printf("\nLG Electronics digital TV firmware package (EPK) extractor version 4.8 (http://openlgtv.org.ru)\n\n");
if (argc < 2) {
printf("Usage: epk2extract [-options] FILENAME\n\n");
printf("Options:\n");
printf(" -c : extract to current directory instead of source file directory\n");
printf(" -s : enable signature checking for EPK files\n");
printf(" -S : only check signature (implies -s)\n");
printf(" -n : no automatic unsquashfs\n\n");
return err_ret("");
return print_usage();
}

char *exe_dir = calloc(1, PATH_MAX);
Expand Down Expand Up @@ -279,6 +275,11 @@ int main(int argc, char *argv[]) {
}
}

if (optind == argc) {
/* no non-option args */
return print_usage();
}

#ifdef __CYGWIN__
char posix[PATH_MAX];
cygwin_conv_path(CCP_WIN_A_TO_POSIX, argv[optind], posix, PATH_MAX);
Expand All @@ -305,8 +306,20 @@ int main(int argc, char *argv[]) {

int exit_code = handle_file(input_file, &config_opts);

if (exit_code == EXIT_FAILURE)
if (exit_code == EXIT_FAILURE) {
return err_ret("Unsupported input file format: %s\n\n", input_file);
}

(void) err_ret("\nExtraction is finished.\n\n");
return EXIT_SUCCESS;
}

return !err_ret("\nExtraction is finished.\n\n");
static int print_usage(void) {
printf("Usage: epk2extract [-options] FILENAME\n\n");
printf("Options:\n");
printf(" -c : extract to current directory instead of source file directory\n");
printf(" -s : enable signature checking for EPK files\n");
printf(" -S : only check signature (implies -s)\n");
printf(" -n : no automatic unsquashfs\n\n");
return err_ret(NULL);
}
Loading
Loading