Skip to content

Commit

Permalink
Don't free the workbuf until it's actually all done being used. Added…
Browse files Browse the repository at this point in the history
… code for checking the AM_ImportTwlBackup retval which was missing. Updated the version.
  • Loading branch information
yellows8 committed Nov 2, 2016
1 parent cafcaa9 commit b3d7eaa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ SOURCES := source
DATA := data
INCLUDES := include

VERSION := v1.0
VERSION := v1.1

APP_TITLE := 3ds_dsiwarehax_installer $(VERSION)
APP_DESCRIPTION := Tool for installing dsiwarehax on 3DS.
Expand Down
22 changes: 17 additions & 5 deletions source/3ds_dsiwarehax_installer.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ Result restore_amtext(u8 *tmpbuf, u32 tmpbuf_size, u32 ampxi_funcoffset)

Result install_dsiwarehax(int *reboot_required, dsiware_entry *ent, u8 *savebuf, u32 public_size, u32 banner_size, u32 private_size)
{
Result ret=0;
Result ret=0, ret2=0;
u8 *tmpbuf = NULL;
u32 tmpbuf_size = 0x1000;
u8 *workbuf = NULL;
Expand Down Expand Up @@ -546,19 +546,18 @@ Result install_dsiwarehax(int *reboot_required, dsiware_entry *ent, u8 *savebuf,
memcpy(&workbuf_header[tmpoffset>>2], &savebuf[0x200000], private_size);
}

ret = AM_ImportTwlBackup(filehandle, 11, workbuf, workbuf_size);
ret2 = AM_ImportTwlBackup(filehandle, 11, workbuf, workbuf_size);
if(R_FAILED(ret2))printf("AM_ImportTwlBackup failed: 0x%08x.\n", (unsigned int)ret2);

FSFILE_Close(filehandle);

memset(workbuf, 0, workbuf_size);
free(workbuf);

printf("Restoring AM-module .text...\n");

ret = svcMapProcessMemory(amproc, 0x0f000000, 0x14000);
if(R_FAILED(ret))
{
free(tmpbuf);
free(workbuf);
svcCloseHandle(amproc);
return ret;
}
Expand All @@ -568,13 +567,22 @@ Result install_dsiwarehax(int *reboot_required, dsiware_entry *ent, u8 *savebuf,
free(tmpbuf);
if(R_FAILED(ret))
{
free(workbuf);
svcCloseHandle(amproc);
return ret;
}

ret = svcUnmapProcessMemory(amproc, 0x0f000000, 0x14000);
svcCloseHandle(amproc);

if(R_FAILED(ret2))
{
printf("Aborting since AM_ImportTwlBackup failed...\n");
free(workbuf);
svcCloseHandle(amproc);
return ret2;
}

if(ret==0 && workbuf_header[0] & 0x124)
{
printf("Writing the original input import data to SD...\n");
Expand Down Expand Up @@ -621,6 +629,7 @@ Result install_dsiwarehax(int *reboot_required, dsiware_entry *ent, u8 *savebuf,
if(R_FAILED(ret))
{
free(tmpbuf);
free(workbuf);
return ret;
}

Expand Down Expand Up @@ -658,6 +667,9 @@ Result install_dsiwarehax(int *reboot_required, dsiware_entry *ent, u8 *savebuf,
ampxiExit();
}

memset(workbuf, 0, workbuf_size);
free(workbuf);

return ret;
}

Expand Down

0 comments on commit b3d7eaa

Please sign in to comment.