From 2b69cdd166ea6e9548b7315a6a824aa371e5c88f Mon Sep 17 00:00:00 2001 From: GaryOderNichts <12049776+GaryOderNichts@users.noreply.github.com> Date: Sat, 1 Apr 2023 22:54:44 +0200 Subject: [PATCH] rsa: Use IOS_HeapRealloc for Mini-GMP --- ios_mcp/imports.ld | 1 + ios_mcp/source/imports.h | 1 + ios_mcp/source/rsa.c | 17 ++++------------- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/ios_mcp/imports.ld b/ios_mcp/imports.ld index b2f0316..6d5feef 100644 --- a/ios_mcp/imports.ld +++ b/ios_mcp/imports.ld @@ -35,6 +35,7 @@ PROVIDE(IOS_ReadOTP = 0x050568fc); PROVIDE(IOS_HeapAlloc = 0x05056924); PROVIDE(IOS_HeapAllocAligned = 0x0505692c); PROVIDE(IOS_HeapFree = 0x05056934); +PROVIDE(IOS_HeapRealloc = 0x05056944); PROVIDE(IOS_Open = 0x05056984); PROVIDE(IOS_Close = 0x0505698c); diff --git a/ios_mcp/source/imports.h b/ios_mcp/source/imports.h index 7163d42..c00dcfc 100644 --- a/ios_mcp/source/imports.h +++ b/ios_mcp/source/imports.h @@ -92,6 +92,7 @@ int IOS_ReadOTP(int index, void* buffer, uint32_t size); void* IOS_HeapAlloc(uint32_t heap, uint32_t size); void* IOS_HeapAllocAligned(uint32_t heap, uint32_t size, uint32_t alignment); void IOS_HeapFree(uint32_t heap, void* ptr); +void* IOS_HeapRealloc(uint32_t heap, void* ptr, uint32_t size); int IOS_Open(const char* device, int mode); int IOS_Close(int fd); diff --git a/ios_mcp/source/rsa.c b/ios_mcp/source/rsa.c index 03ea2cf..50517a5 100644 --- a/ios_mcp/source/rsa.c +++ b/ios_mcp/source/rsa.c @@ -46,27 +46,18 @@ static const uint32_t rsa_pubexp = 0x10001; static void *ios_gmp_alloc(size_t size) { - return IOS_HeapAlloc(CROSS_PROCESS_HEAP_ID, size); + return IOS_HeapAlloc(LOCAL_PROCESS_HEAP_ID, size); } static void *ios_gmp_realloc(void *buf, size_t old_size, size_t new_size) { - void *newbuf = IOS_HeapAlloc(CROSS_PROCESS_HEAP_ID, new_size); - if (!newbuf) - return NULL; - - // Copy the existing buffer into the new buffer. - size_t to_copy = (old_size < new_size ? old_size : new_size); - if (to_copy > 0) { - memcpy(newbuf, buf, to_copy); - } - IOS_HeapFree(CROSS_PROCESS_HEAP_ID, buf); - return newbuf; + ((void)old_size); + return IOS_HeapRealloc(LOCAL_PROCESS_HEAP_ID, buf, new_size); } static void ios_gmp_free(void *p, size_t unused_size) { ((void)unused_size); - IOS_HeapFree(CROSS_PROCESS_HEAP_ID, p); + IOS_HeapFree(LOCAL_PROCESS_HEAP_ID, p); } /**