hekate/nyx: use zalloc where appropriate

This commit is contained in:
CTCaer
2024-03-27 09:16:06 +02:00
parent d687b53249
commit 4effaab241
12 changed files with 68 additions and 196 deletions

View File

@@ -1,7 +1,7 @@
/*
* Copyright (c) 2018 naehrwert
* Copyright (c) 2018 Rajko Stojadinovic
* Copyright (c) 2018-2022 CTCaer
* Copyright (c) 2018-2024 CTCaer
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
@@ -40,7 +40,7 @@ extern char *emmcsn_path_impl(char *path, char *sub_dir, char *filename, sdmmc_s
static void _get_valid_partition(u32 *sector_start, u32 *sector_size, u32 *part_idx, bool backup)
{
sd_mount();
mbr_t *mbr = (mbr_t *)calloc(sizeof(mbr_t), 1);
mbr_t *mbr = (mbr_t *)zalloc(sizeof(mbr_t));
sdmmc_storage_read(&sd_storage, 0, 1, mbr);
*part_idx = 0;
@@ -90,7 +90,7 @@ static void _get_valid_partition(u32 *sector_start, u32 *sector_size, u32 *part_
// Get emuMMC GPP size.
if (backup && *part_idx && *sector_size)
{
gpt_t *gpt = (gpt_t *)calloc(sizeof(gpt_t), 1);
gpt_t *gpt = (gpt_t *)zalloc(sizeof(gpt_t));
sdmmc_storage_read(&sd_storage, *sector_start + 0x4001, 1, gpt);
u32 new_size = gpt->header.alt_lba + 1;

View File

@@ -1,7 +1,7 @@
/*
* Copyright (c) 2018 naehrwert
* Copyright (c) 2018 Rajko Stojadinovic
* Copyright (c) 2018-2023 CTCaer
* Copyright (c) 2018-2024 CTCaer
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
@@ -705,7 +705,7 @@ static int _dump_emummc_raw_part(emmc_tool_gui_t *gui, int active_part, int part
// Read MBR, GPT and backup GPT.
mbr_t mbr;
gpt_t *gpt = calloc(1, sizeof(gpt_t));
gpt_t *gpt = zalloc(sizeof(gpt_t));
gpt_header_t gpt_hdr_backup;
sdmmc_storage_read(&emmc_storage, 0, 1, &mbr);
sdmmc_storage_read(&emmc_storage, 1, sizeof(gpt_t) >> 9, gpt);

View File

@@ -1,6 +1,6 @@
/*
* Copyright (c) 2018 naehrwert
* Copyright (c) 2018-2023 CTCaer
* Copyright (c) 2018-2024 CTCaer
* Copyright (c) 2018 balika011
*
* This program is free software; you can redistribute it and/or modify it
@@ -1107,7 +1107,7 @@ static lv_res_t _create_mbox_emmc_sandisk_report(lv_obj_t * btn)
lv_mbox_set_text(mbox, "#C7EA46 Sandisk Device Report#");
u8 *buf = calloc(EMMC_BLOCKSIZE, 1);
u8 *buf = zalloc(EMMC_BLOCKSIZE);
char *txt_buf = (char *)malloc(SZ_32K);
char *txt_buf2 = (char *)malloc(SZ_32K);
txt_buf[0] = 0;

View File

@@ -1145,10 +1145,10 @@ static lv_res_t _create_window_dump_pk12_tool(lv_obj_t *btn)
char path[128];
u8 kb = 0;
u8 *pkg1 = (u8 *)calloc(1, SZ_256K);
u8 *warmboot = (u8 *)calloc(1, SZ_256K);
u8 *secmon = (u8 *)calloc(1, SZ_256K);
u8 *loader = (u8 *)calloc(1, SZ_256K);
u8 *pkg1 = (u8 *)zalloc(SZ_256K);
u8 *warmboot = (u8 *)zalloc(SZ_256K);
u8 *secmon = (u8 *)zalloc(SZ_256K);
u8 *loader = (u8 *)zalloc(SZ_256K);
u8 *pkg2 = NULL;
char *txt_buf = (char *)malloc(SZ_16K);
@@ -1207,7 +1207,7 @@ static lv_res_t _create_window_dump_pk12_tool(lv_obj_t *btn)
tsec_ctxt.pkg11_off = pkg1_id->pkg11_off;
// Read keyblob.
u8 *keyblob = (u8 *)calloc(EMMC_BLOCKSIZE, 1);
u8 *keyblob = (u8 *)zalloc(EMMC_BLOCKSIZE);
sdmmc_storage_read(&emmc_storage, HOS_KEYBLOBS_OFFSET / EMMC_BLOCKSIZE + kb, 1, keyblob);
// Decrypt.

View File

@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2022 CTCaer
* Copyright (c) 2019-2024 CTCaer
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
@@ -345,7 +345,7 @@ static void _prepare_and_flash_mbr_gpt()
if (part_info.and_size)
{
gpt_t *gpt = calloc(1, sizeof(gpt_t));
gpt_t *gpt = zalloc(sizeof(gpt_t));
gpt_header_t gpt_hdr_backup = { 0 };
// Set GPT protective partition in MBR.
@@ -768,7 +768,7 @@ exit:
static u32 _get_available_l4t_partition()
{
mbr_t mbr = { 0 };
gpt_t *gpt = calloc(1, sizeof(gpt_t));
gpt_t *gpt = zalloc(sizeof(gpt_t));
memset(&l4t_flash_ctxt, 0, sizeof(l4t_flasher_ctxt_t));
@@ -815,7 +815,7 @@ static u32 _get_available_l4t_partition()
static bool _get_available_android_partition()
{
gpt_t *gpt = calloc(1, sizeof(gpt_t));
gpt_t *gpt = zalloc(sizeof(gpt_t));
// Read main GPT.
sdmmc_storage_read(&sd_storage, 1, sizeof(gpt_t) >> 9, gpt);
@@ -1007,7 +1007,7 @@ static lv_res_t _action_flash_android_data(lv_obj_t * btns, const char * txt)
// Flash Android components.
char path[128];
gpt_t *gpt = calloc(1, sizeof(gpt_t));
gpt_t *gpt = zalloc(sizeof(gpt_t));
char *txt_buf = malloc(SZ_4K);
lv_obj_t *dark_bg = lv_obj_create(lv_scr_act(), NULL);
@@ -1077,7 +1077,7 @@ static lv_res_t _action_flash_android_data(lv_obj_t * btns, const char * txt)
if (file_size % 0x200)
{
file_size = ALIGN(file_size, 0x200);
u8 *buf_tmp = calloc(file_size, 1);
u8 *buf_tmp = zalloc(file_size);
memcpy(buf_tmp, buf, file_size);
free(buf);
buf = buf_tmp;
@@ -1141,7 +1141,7 @@ boot_img_not_found:
if (file_size % 0x200)
{
file_size = ALIGN(file_size, 0x200);
u8 *buf_tmp = calloc(file_size, 1);
u8 *buf_tmp = zalloc(file_size);
memcpy(buf_tmp, buf, file_size);
free(buf);
buf = buf_tmp;
@@ -1203,7 +1203,7 @@ recovery_not_found:
if (file_size % 0x200)
{
file_size = ALIGN(file_size, 0x200);
u8 *buf_tmp = calloc(file_size, 1);
u8 *buf_tmp = zalloc(file_size);
memcpy(buf_tmp, buf, file_size);
free(buf);
buf = buf_tmp;
@@ -2228,7 +2228,7 @@ static lv_res_t _action_fix_mbr(lv_obj_t *btn)
lv_label_set_recolor(lbl_status, true);
mbr_t mbr[2] = { 0 };
gpt_t *gpt = calloc(1, sizeof(gpt_t));
gpt_t *gpt = zalloc(sizeof(gpt_t));
gpt_header_t gpt_hdr_backup = { 0 };
bool has_mbr_attributes = false;
@@ -2279,7 +2279,7 @@ static lv_res_t _action_fix_mbr(lv_obj_t *btn)
LIST_INIT(gpt_parsed);
for (u32 i = 0; i < gpt->header.num_part_ents; i++)
{
emmc_part_t *part = (emmc_part_t *)calloc(sizeof(emmc_part_t), 1);
emmc_part_t *part = (emmc_part_t *)zalloc(sizeof(emmc_part_t));
if (gpt->entries[i].lba_start < gpt->header.first_use_lba)
continue;

View File

@@ -210,7 +210,7 @@ static void _hos_eks_get()
if (!h_cfg.eks)
{
// Read EKS blob.
u8 *mbr = calloc(SD_BLOCKSIZE, 1);
u8 *mbr = zalloc(SD_BLOCKSIZE);
if (!hos_eks_rw_try(mbr, false))
goto out;
@@ -240,7 +240,7 @@ static void _hos_eks_save()
bool new_eks = false;
if (!h_cfg.eks)
{
h_cfg.eks = calloc(SD_BLOCKSIZE, 1);
h_cfg.eks = zalloc(SD_BLOCKSIZE);
new_eks = true;
}
@@ -248,7 +248,7 @@ static void _hos_eks_save()
if (h_cfg.eks->enabled != HOS_EKS_TSEC_VER)
{
// Read EKS blob.
u8 *mbr = calloc(SD_BLOCKSIZE, 1);
u8 *mbr = zalloc(SD_BLOCKSIZE);
if (!hos_eks_rw_try(mbr, false))
{
if (new_eks)
@@ -261,7 +261,7 @@ static void _hos_eks_save()
}
// Get keys.
u8 *keys = (u8 *)calloc(SZ_4K, 2);
u8 *keys = (u8 *)calloc(2, SZ_4K);
se_get_aes_keys(keys + SZ_4K, keys, SE_KEY_128_SIZE);
// Set magic and personalized info.
@@ -275,7 +275,7 @@ static void _hos_eks_save()
memcpy(h_cfg.eks->troot_dev, keys + 11 * SE_KEY_128_SIZE, SE_KEY_128_SIZE);
// Encrypt EKS blob.
u8 *eks = calloc(SD_BLOCKSIZE, 1);
u8 *eks = zalloc(SD_BLOCKSIZE);
memcpy(eks, h_cfg.eks, sizeof(hos_eks_mbr_t));
se_aes_crypt_ecb(14, ENCRYPT, eks, sizeof(hos_eks_mbr_t), eks, sizeof(hos_eks_mbr_t));
@@ -302,7 +302,7 @@ void hos_eks_clear(u32 kb)
if (h_cfg.eks->enabled)
{
// Read EKS blob.
u8 *mbr = calloc(SD_BLOCKSIZE, 1);
u8 *mbr = zalloc(SD_BLOCKSIZE);
if (!hos_eks_rw_try(mbr, false))
goto out;
@@ -310,7 +310,7 @@ void hos_eks_clear(u32 kb)
h_cfg.eks->enabled = 0;
// Encrypt EKS blob.
u8 *eks = calloc(SD_BLOCKSIZE, 1);
u8 *eks = zalloc(SD_BLOCKSIZE);
memcpy(eks, h_cfg.eks, sizeof(hos_eks_mbr_t));
se_aes_crypt_ecb(14, ENCRYPT, eks, sizeof(hos_eks_mbr_t), eks, sizeof(hos_eks_mbr_t));