hekate/nyx: use zalloc where appropriate
This commit is contained in:
@@ -218,7 +218,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;
|
||||
|
||||
@@ -248,7 +248,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;
|
||||
}
|
||||
|
||||
@@ -256,7 +256,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)
|
||||
@@ -269,7 +269,7 @@ static void _hos_eks_save()
|
||||
}
|
||||
|
||||
// Get keys.
|
||||
u8 *keys = (u8 *)calloc(SZ_4K, 2);
|
||||
u8 *keys = (u8 *)zalloc(SZ_8K);
|
||||
se_get_aes_keys(keys + SZ_4K, keys, SE_KEY_128_SIZE);
|
||||
|
||||
// Set magic and personalized info.
|
||||
@@ -283,7 +283,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));
|
||||
|
||||
@@ -310,7 +310,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;
|
||||
|
||||
@@ -318,7 +318,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));
|
||||
|
||||
@@ -646,7 +646,7 @@ try_load:
|
||||
// Read the correct keyblob for older HOS versions.
|
||||
if (ctxt->pkg1_id->kb <= HOS_KB_VERSION_600)
|
||||
{
|
||||
ctxt->keyblob = (u8 *)calloc(EMMC_BLOCKSIZE, 1);
|
||||
ctxt->keyblob = (u8 *)zalloc(EMMC_BLOCKSIZE);
|
||||
emummc_storage_read(PKG1_HOS_KEYBLOBS_OFFSET / EMMC_BLOCKSIZE + ctxt->pkg1_id->kb, 1, ctxt->keyblob);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2018 naehrwert
|
||||
* Copyright (c) 2018-2021 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,
|
||||
@@ -122,27 +122,28 @@ int config_kip1patch(launch_ctxt_t *ctxt, const char *value)
|
||||
if (value == NULL)
|
||||
return 0;
|
||||
|
||||
int valueLen = strlen(value);
|
||||
if (!valueLen)
|
||||
int len = strlen(value);
|
||||
if (!len)
|
||||
return 0;
|
||||
|
||||
if (ctxt->kip1_patches == NULL)
|
||||
{
|
||||
ctxt->kip1_patches = malloc(valueLen + 1);
|
||||
memcpy(ctxt->kip1_patches, value, valueLen);
|
||||
ctxt->kip1_patches[valueLen] = 0;
|
||||
ctxt->kip1_patches = malloc(len + 1);
|
||||
memcpy(ctxt->kip1_patches, value, len);
|
||||
ctxt->kip1_patches[len] = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
char *oldAlloc = ctxt->kip1_patches;
|
||||
int oldSize = strlen(oldAlloc);
|
||||
ctxt->kip1_patches = malloc(oldSize + 1 + valueLen + 1);
|
||||
memcpy(ctxt->kip1_patches, oldAlloc, oldSize);
|
||||
free(oldAlloc);
|
||||
oldAlloc = NULL;
|
||||
ctxt->kip1_patches[oldSize++] = ',';
|
||||
memcpy(&ctxt->kip1_patches[oldSize], value, valueLen);
|
||||
ctxt->kip1_patches[oldSize + valueLen] = 0;
|
||||
char *old_addr = ctxt->kip1_patches;
|
||||
int old_len = strlen(old_addr);
|
||||
|
||||
ctxt->kip1_patches = malloc(old_len + 1 + len + 1);
|
||||
memcpy(ctxt->kip1_patches, old_addr, old_len);
|
||||
free(old_addr);
|
||||
|
||||
ctxt->kip1_patches[old_len++] = ',';
|
||||
memcpy(&ctxt->kip1_patches[old_len], value, len);
|
||||
ctxt->kip1_patches[old_len + len] = 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -220,7 +221,7 @@ static int _config_exo_user_pmu_access(launch_ctxt_t *ctxt, const char *value)
|
||||
static int _config_exo_usb3_force(launch_ctxt_t *ctxt, const char *value)
|
||||
{
|
||||
// Override key found.
|
||||
ctxt->exo_ctx.usb3_force = calloc(sizeof(bool), 1);
|
||||
ctxt->exo_ctx.usb3_force = zalloc(sizeof(bool));
|
||||
|
||||
if (*value == '1')
|
||||
{
|
||||
@@ -233,7 +234,7 @@ static int _config_exo_usb3_force(launch_ctxt_t *ctxt, const char *value)
|
||||
static int _config_exo_cal0_blanking(launch_ctxt_t *ctxt, const char *value)
|
||||
{
|
||||
// Override key found.
|
||||
ctxt->exo_ctx.cal0_blank = calloc(sizeof(bool), 1);
|
||||
ctxt->exo_ctx.cal0_blank = zalloc(sizeof(bool));
|
||||
|
||||
if (*value == '1')
|
||||
{
|
||||
@@ -246,7 +247,7 @@ static int _config_exo_cal0_blanking(launch_ctxt_t *ctxt, const char *value)
|
||||
static int _config_exo_cal0_writes_enable(launch_ctxt_t *ctxt, const char *value)
|
||||
{
|
||||
// Override key found.
|
||||
ctxt->exo_ctx.cal0_allow_writes_sys = calloc(sizeof(bool), 1);
|
||||
ctxt->exo_ctx.cal0_allow_writes_sys = zalloc(sizeof(bool));
|
||||
|
||||
if (*value == '1')
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2018 naehrwert
|
||||
* 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,
|
||||
@@ -77,7 +77,7 @@ static void parse_external_kip_patches()
|
||||
if (ini_patch_parse(&ini_kip_sections, "bootloader/patches.ini"))
|
||||
{
|
||||
// Copy ids into a new patchset.
|
||||
_kip_id_sets = calloc(sizeof(kip1_id_t), 256); // Max 256 kip ids.
|
||||
_kip_id_sets = zalloc(sizeof(kip1_id_t) * 256); // Max 256 kip ids.
|
||||
memcpy(_kip_id_sets, _kip_ids, sizeof(_kip_ids));
|
||||
|
||||
// Parse patchsets and glue them together.
|
||||
@@ -109,12 +109,12 @@ static void parse_external_kip_patches()
|
||||
{
|
||||
curr_kip->name = ini_psec->name;
|
||||
memcpy(curr_kip->hash, ini_psec->hash, 8);
|
||||
curr_kip->patchset = calloc(sizeof(kip1_patchset_t), 1);
|
||||
curr_kip->patchset = zalloc(sizeof(kip1_patchset_t));
|
||||
|
||||
_kip_id_sets_cnt++;
|
||||
}
|
||||
|
||||
kip1_patchset_t *patchsets = (kip1_patchset_t *)calloc(sizeof(kip1_patchset_t), 16); // Max 16 patchsets per kip.
|
||||
kip1_patchset_t *patchsets = (kip1_patchset_t *)zalloc(sizeof(kip1_patchset_t) * 16); // Max 16 patchsets per kip.
|
||||
|
||||
u32 curr_patchset_idx;
|
||||
for (curr_patchset_idx = 0; curr_kip->patchset[curr_patchset_idx].name != NULL; curr_patchset_idx++)
|
||||
@@ -128,7 +128,7 @@ static void parse_external_kip_patches()
|
||||
u32 curr_patch_idx = 0;
|
||||
|
||||
// Parse patches and glue them together to a patchset.
|
||||
kip1_patch_t *patches = calloc(sizeof(kip1_patch_t), 32); // Max 32 patches per set.
|
||||
kip1_patch_t *patches = zalloc(sizeof(kip1_patch_t) * 32); // Max 32 patches per set.
|
||||
LIST_FOREACH_ENTRY(ini_patchset_t, pt, &ini_psec->pts, link)
|
||||
{
|
||||
if (first_ext_patch)
|
||||
@@ -142,7 +142,7 @@ static void parse_external_kip_patches()
|
||||
// New patchset name found, create a new set.
|
||||
curr_patchset_idx++;
|
||||
curr_patch_idx = 0;
|
||||
patches = calloc(sizeof(kip1_patch_t), 32); // Max 32 patches per set.
|
||||
patches = zalloc(sizeof(kip1_patch_t) * 32); // Max 32 patches per set.
|
||||
|
||||
patchsets[curr_patchset_idx].name = pt->name;
|
||||
patchsets[curr_patchset_idx].patches = patches;
|
||||
|
||||
@@ -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,
|
||||
@@ -80,7 +80,7 @@ static ini_kip_sec_t *_ini_create_kip_section(link_t *dst, ini_kip_sec_t *ksec,
|
||||
|
||||
// Calculate total allocation size.
|
||||
u32 len = strlen(name);
|
||||
char *buf = calloc(sizeof(ini_kip_sec_t) + len + 1, 1);
|
||||
char *buf = zalloc(sizeof(ini_kip_sec_t) + len + 1);
|
||||
|
||||
ksec = (ini_kip_sec_t *)buf;
|
||||
u32 i = _find_patch_section_name(name, len, ':') + 1;
|
||||
@@ -132,7 +132,7 @@ int ini_patch_parse(link_t *dst, char *ini_path)
|
||||
u32 pos = _find_patch_section_name(lbuf, lblen, '=');
|
||||
|
||||
// Calculate total allocation size.
|
||||
char *buf = calloc(sizeof(ini_patchset_t) + strlen(&lbuf[1]) + 1, 1);
|
||||
char *buf = zalloc(sizeof(ini_patchset_t) + strlen(&lbuf[1]) + 1);
|
||||
ini_patchset_t *pt = (ini_patchset_t *)buf;
|
||||
|
||||
// Set patch name.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2018 naehrwert
|
||||
*
|
||||
* 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,
|
||||
@@ -767,7 +767,7 @@ static void _check_for_updated_bootloader()
|
||||
_launch_payload("bootloader/update.bin", true, false);
|
||||
else
|
||||
{
|
||||
u8 *buf = calloc(0x200, 1);
|
||||
u8 *buf = zalloc(0x200);
|
||||
is_ipl_updated(buf, "bootloader/update.bin", true);
|
||||
free(buf);
|
||||
}
|
||||
@@ -1236,7 +1236,7 @@ static void _check_low_battery()
|
||||
|
||||
u8 *battery_icon = malloc(0x95A); // 21x38x3
|
||||
u8 *charging_icon = malloc(0x2F4); // 21x12x3
|
||||
u8 *no_charging_icon = calloc(0x2F4, 1);
|
||||
u8 *no_charging_icon = zalloc(0x2F4);
|
||||
|
||||
memcpy(charging_icon, battery_res, 0x2F4);
|
||||
memcpy(battery_icon, battery_res + 0x2F4, 0x95A);
|
||||
|
||||
Reference in New Issue
Block a user