show unpacking progress in percents

This commit is contained in:
Martins Mozeiko
2017-11-16 21:29:54 -08:00
parent 5a86f84196
commit 1206d40166
4 changed files with 42 additions and 7 deletions
+10 -6
View File
@@ -506,22 +506,22 @@ int main(int argc, char* argv[])
else if (type == PKG_TYPE_VITA_DLC)
{
snprintf(root, sizeof(root), "%s [%.9s] [%s] [DLC-%s]%s", title, id, get_region(id), id2, ext);
sys_output("[*] unpacking DLC\n");
sys_output("[*] unpacking Vita DLC\n");
}
else if (type == PKG_TYPE_VITA_PATCH)
{
snprintf(root, sizeof(root), "%s [%.9s] [%s] [PATCH] [v%s]%s", title, id, get_region(id), pkg_version, ext);
sys_output("[*] unpacking PATCH\n");
sys_output("[*] unpacking Vita PATCH\n");
}
else if (type == PKG_TYPE_VITA_PSM)
{
snprintf(root, sizeof(root), "%.9s [%s]%s", id, get_region(id), ext);
sys_output("[*] unpacking PSM\n");
sys_output("[*] unpacking Vita PSM\n");
}
else if (type == PKG_TYPE_VITA_APP)
{
snprintf(root, sizeof(root), "%s [%.9s] [%s]%s", title, id, get_region(id), ext);
sys_output("[*] unpacking APP\n");
sys_output("[*] unpacking Vita APP\n");
}
else
{
@@ -606,11 +606,12 @@ int main(int argc, char* argv[])
sys_error("ERROR: unsupported type\n");
}
sys_output("[*] decrypting...\n");
char path[1024];
int sce_sys_package_created = 0;
sys_output_progress_init(pkg_size);
for (uint32_t item_index = 0; item_index < item_count; item_index++)
{
uint8_t item[32];
@@ -654,7 +655,7 @@ int main(int argc, char* argv[])
aes128_ctr_xor(item_key, iv, name_offset / 16, (uint8_t*)name, name_size);
name[name_size] = 0;
sys_output("[%u/%u] %s\n", item_index + 1, item_count, name);
// sys_output("[%u/%u] %s\n", item_index + 1, item_count, name);
if (flags == 4 || flags == 18)
{
@@ -751,6 +752,7 @@ int main(int argc, char* argv[])
{
uint8_t PKG_ALIGN(16) buffer[1 << 16];
uint32_t size = (uint32_t)min64(data_size, sizeof(buffer));
sys_output_progress(enc_offset + offset);
sys_read(pkg, enc_offset + offset, buffer, size);
if (decrypt)
@@ -766,6 +768,8 @@ int main(int argc, char* argv[])
}
}
sys_output("[*] unpacking completed\n");
if (type == PKG_TYPE_VITA_APP || type == PKG_TYPE_VITA_DLC || type == PKG_TYPE_VITA_PATCH)
{
if (!sce_sys_package_created)
+1
View File
@@ -417,6 +417,7 @@ void unpack_psp_eboot(const char* path, const aes128_key* pkg_key, const uint8_t
uint8_t PKG_ALIGN(16) data[16 * ISO_SECTOR_SIZE];
uint64_t abs_offset = item_offset + psar_offset + block_offset;
sys_output_progress(enc_offset + abs_offset);
sys_read(pkg, enc_offset + abs_offset, data, block_size);
aes128_ctr_xor(pkg_key, pkg_iv, abs_offset / 16, data, block_size);
+28 -1
View File
@@ -38,7 +38,7 @@ void sys_output(const char* msg, ...)
int wcount = MultiByteToWideChar(CP_UTF8, 0, buffer, -1, wbuffer, sizeof(buffer));
DWORD written;
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), wbuffer, wcount, &written, NULL);
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), wbuffer, wcount - 1, &written, NULL);
return;
}
fputs(buffer, stdout);
@@ -161,8 +161,11 @@ void sys_write(sys_file file, uint64_t offset, const void* buffer, uint32_t size
#include <unistd.h>
#include <sys/stat.h>
static int gStdoutRedirected;
void sys_output_init(void)
{
gStdoutRedirected = !isatty(STDOUT_FILENO);
}
void sys_output(const char* msg, ...)
@@ -303,3 +306,27 @@ void sys_vstrncat(char* dst, size_t n, const char* format, ...)
strncat(dst, temp, n - strlen(dst) - 1);
}
static uint64_t out_size;
static uint32_t out_next;
void sys_output_progress_init(uint64_t size)
{
out_size = size;
out_next = 0;
}
void sys_output_progress(uint64_t progress)
{
if (gStdoutRedirected)
{
return;
}
uint32_t now = (uint32_t)(progress * 100 / out_size);
if (now >= out_next)
{
sys_output("[*] unpacking... %u%%\r", now);
out_next = now + 1;
}
}
+3
View File
@@ -7,6 +7,9 @@ void sys_output_init(void);
void sys_output(const char* msg, ...);
void NORETURN sys_error(const char* msg, ...);
void sys_output_progress_init(uint64_t size);
void sys_output_progress(uint64_t progress);
typedef void* sys_file;
void sys_mkdir(const char* path);