Skip to content
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
6 changes: 5 additions & 1 deletion pkg2zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,11 @@ int main(int argc, char* argv[])

if (type != PKG_TYPE_VITA_PATCH && zrif_arg != NULL)
{
zrif_decode(zrif_arg, rif, rif_size);
if (str_endswith(zrif_arg, ".bin")) {
rif_load(zrif_arg, rif, rif_size);
} else {
zrif_decode(zrif_arg, rif, rif_size);
}
const char* rif_contentid = (char*)rif + (type == PKG_TYPE_VITA_PSM ? 0x50 : 0x10);
if (strncmp(rif_contentid, content, 0x30) != 0)
{
Expand Down
11 changes: 11 additions & 0 deletions pkg2zip_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include <stdint.h>
#include <stddef.h>
#include <string.h>
#include <stdbool.h>

#if defined(_MSC_VER)
# define NORETURN __declspec(noreturn)
Expand Down Expand Up @@ -116,3 +118,12 @@ static inline void set64be(uint8_t* bytes, uint64_t x)
bytes[6] = (uint8_t)(x >> 8);
bytes[7] = (uint8_t)x;
}

static inline bool str_endswith(const char* str, const char* suffix) {
const size_t suffix_len = strlen(suffix);
const size_t str_len = strlen(str);
if (str_len < suffix_len) return false;

const char *str_end = str + (str_len - suffix_len);
return strcmp(str_end, suffix) == 0;
}
7 changes: 7 additions & 0 deletions pkg2zip_zrif.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "puff.h"

#include <assert.h>
#include <stdio.h>
#include <string.h>

#define ADLER32_MOD 65521
Expand Down Expand Up @@ -173,3 +174,9 @@ void zrif_decode(const char* str, uint8_t* rif, uint32_t rif_size)

memcpy(rif, out, rif_size);
}

void rif_load(const char* str, uint8_t* rif, uint32_t rif_size) {
FILE *file = fopen(str, "rb");
fread(rif, rif_size, 1, file);
fclose(file);
}
1 change: 1 addition & 0 deletions pkg2zip_zrif.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
#include <stdint.h>

void zrif_decode(const char* str, uint8_t* rif, uint32_t rif_size);
void rif_load(const char* str, uint8_t* rif, uint32_t rif_size);