EZ-Flash USA Forum

Forum for the EZ-Flash I, II, III, IV & V Gameboy Advance & Nintendo DS USA Forum (Unofficial) Open since 2004!
It is currently Fri May 24, 2013 9:54 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
Sponsor
 Post subject: [program] EZ3 NDS skin extractor v1.0
PostPosted: Wed Nov 01, 2006 11:06 am 
Offline
 Profile

Joined: Sun Jul 23, 2006 6:19 am
Posts: 34
[Application]
EZ3 NDS skin extractor v1.0 by Suanyuan 2006/10/31

[Description]
EZ3NdsSkinExtract is a small program to extract NDS skin data files from EZ3 loader_nds.bin.

[How to run it]
Just copy the loader_nds.bin to the same folder of EZ3NdsSkinExtract.exe then run EZ3NdsSkinExtract.exe.
The NDS skin files will put to "nds" sub folder.

[Download]
http://gens32.emubase.de/Img/flash/Ez3N ... xtract.rar

:lol:

Quote:
Special thanks to Cory for his EZ4 skin injection program, I reference his program to understand the data structure of NDS skin file entry.


Quote:
/* *****************************************************
EZ3 NDS skin extracter
******************************************************
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <direct.h>

char *NDS_BIN = "nds.bin";
char *LOADER_NDS_BIN = "loader_NDS.bin";

int findNdsSkin(char *buf, long sz);
long DumpNdsBin(char *NdsBuffer, long lSize);

struct CExitDataPack
{
FILE* fptr_ezfla;
FILE* fptr_nds;
FILE* fptr_bak;
char* ezfla_buf;

CExitDataPack()
{
fptr_ezfla = NULL;
fptr_nds = NULL;
fptr_bak = NULL;
ezfla_buf = NULL;
}

~CExitDataPack()
{
if (fptr_ezfla)
fclose(fptr_ezfla);

if (fptr_nds)
fclose(fptr_nds);

if (fptr_bak)
fclose(fptr_bak);

if (ezfla_buf)
free(ezfla_buf);
}
};

struct TGbfsHeader
{
BYTE sHeader[20];
WORD wTableOff;
WORD wEntryCnt;
};

struct TGbfsEntry
{
BYTE sFile[24];
DWORD dwSize;
DWORD dwOffset;
};


int main(int argc, char* argv[])
{
FILE* fptr_ezfla = NULL;
FILE* fptr_nds = NULL;
FILE* fptr_bak = NULL;

long lSizeEzfla;
long lSizeNds;

CExitDataPack exitDataPack;

printf("EZ3NdsSkinExtract - NDS skin extractor\n");
printf("-----------------------------------\n");
printf("EZ NDS OS file : %s\n", LOADER_NDS_BIN);
printf("NDS skin-GBFS : %s\n", NDS_BIN);
printf("-----------------------------------\n");

//
// step 1: read LOADER_NDS_BIN into memory
//
if ((fptr_ezfla = fopen(LOADER_NDS_BIN, "rb")) == NULL) /* Error Check File Streams */
{
printf("Error opening %s.\n", LOADER_NDS_BIN);
printf("\npress <enter> to quit...\n");
fgetc(stdin);
return 0;
}

exitDataPack.fptr_ezfla = fptr_ezfla;

fseek(fptr_ezfla, 0, SEEK_END);
lSizeEzfla = ftell(fptr_ezfla);
rewind(fptr_ezfla);

// read LOADER_NDS_BIN into buffer
char* ezfla_buf = (char *) malloc(lSizeEzfla);
if (ezfla_buf == NULL)
{
return 0;
}

exitDataPack.ezfla_buf = ezfla_buf;

printf("reading %s into memory\n", LOADER_NDS_BIN);
fread(ezfla_buf, 1, lSizeEzfla, fptr_ezfla);

fclose(fptr_ezfla);
exitDataPack.fptr_ezfla = NULL;

//
// step 2: get data size of NDS_BIN
//
printf("Finding NDS skin offset\n");
long nds_find_offset = findNdsSkin(ezfla_buf, lSizeEzfla);
if (nds_find_offset == -1)
{
printf("\nGBFS not found in updater\n");
return 0;
}
printf("GBFS found at pos: %ld\n", nds_find_offset);

lSizeNds = lSizeEzfla - nds_find_offset;

//
// step 4: write NDS_BIN
//
if ((fptr_nds = fopen(NDS_BIN, "wb")) == NULL) // NDS GBFS skin
{
printf("Error opening %s.\n", NDS_BIN);
printf("\npress <enter> to quit...\n");
fgetc(stdin);
return 0;
}

exitDataPack.fptr_nds = fptr_nds;
fwrite(&ezfla_buf[nds_find_offset], 1, lSizeNds, fptr_nds);

// make necessary directories
mkdir("nds");

// step 6: dump NDS_BIN
DumpNdsBin(&ezfla_buf[nds_find_offset], lSizeNds);

// all done!
printf("\n\nEZ3NdsSkinExtract.exe Finished.\n");

return 0;
}

// find a string in the buffered file
// return the position the first character of string
int findNdsSkin(char *buf, long sz)
{
int pos = 0;
char text[13] = "PinEightGBFS";
while (pos < (sz-12))
{
if (buf[pos] == text[0])
{
if ((buf[pos + 1] == text[ 1]) &&
(buf[pos + 2] == text[ 2]) &&
(buf[pos + 3] == text[ 3]) &&
(buf[pos + 4] == text[ 4]) &&
(buf[pos + 5] == text[ 5]) &&
(buf[pos + 6] == text[ 6]) &&
(buf[pos + 7] == text[ 7]) &&
(buf[pos + 8] == text[ 8]) &&
(buf[pos + 9] == text[ 9]) &&
(buf[pos + 10] == text[10]) &&
(buf[pos + 11] == text[11]))
{
return pos;
}
}
pos++;
}
return -1;
}

long DumpNdsBin(char *NdsBuffer, long lSize)
{
char full_path[256];

TGbfsHeader *pGbfsHeader = (TGbfsHeader *) NdsBuffer;

DWORD dwOffset = 0;
WORD wOffset;
for (WORD i = 0; i < pGbfsHeader->wEntryCnt; i++)
{
wOffset = pGbfsHeader->wTableOff + i * sizeof(TGbfsEntry);
TGbfsEntry *pEntry = (TGbfsEntry *) &NdsBuffer[wOffset];

if ((pEntry->dwOffset + pEntry->dwSize) > lSize)
break;

dwOffset = pEntry->dwOffset + pEntry->dwSize;

sprintf(full_path, "nds\\%s", pEntry->sFile);
printf("\"%s\", pos = %d, size = %d\n", full_path, pEntry->dwOffset, pEntry->dwSize);
FILE *ofptr = fopen(full_path, "wb");
if (!ofptr)
{
printf("failed to create \"%s\"!\n", full_path);
break;
}
fwrite(&NdsBuffer[pEntry->dwOffset], 1, pEntry->dwSize, ofptr);
fclose(ofptr);
}

return dwOffset;
}


Last edited by suanyuan on Thu Nov 02, 2006 9:52 am, edited 4 times in total.

Top
 
Sponsor
 Post subject:
PostPosted: Wed Nov 01, 2006 3:56 pm 
Offline
 WWW  ICQ  YIM  Profile

Joined: Wed Feb 15, 2006 3:45 pm
Posts: 435
Location: United States of America
Fairly easy to do already. GBFSep then unGBFS.


Top
 
 Post subject:
PostPosted: Thu Nov 02, 2006 8:23 am 
Offline
 Profile

Joined: Sun Jul 23, 2006 6:19 am
Posts: 34
chuckstudios wrote:
Fairly easy to do already. GBFSep then unGBFS.


Yes, but I didn't use GBFS in my EZ3 NDS extractor. I have released my source code.


Top
 
Sponsor
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group  
Design By Poker Bandits