Homebrew Question about libc in the 3ds. (Also, NTR plugin creation)

ZiggyDeer

Active Member
OP
Newcomer
Joined
Dec 20, 2014
Messages
41
Trophies
0
Location
USA
Website
ziggydev.xyz
XP
304
Country
United States
Hello,

I'm creating a pokegen NTR plugin, and I'm using the template someone gave out (I don't remember who). Here is the important code:
Code:
int inject() {
    FILE *pokemon_ekx;
    long size;
    char* buffer;
    size_t result;

    pokemon_ekx = fopen("../../pokemon.ekx", "rb");

    fseek(pokemon_ekx, 0, SEEK_END);
    size = ftell(pokemon_ekx);

    long pokemon_array[size];
  
    if (pokemon_ekx == NULL)
        return 1;

    buffer = (char*) malloc(sizeof(char) * size);
    if (buffer == NULL)
        return 1;

    result = fread(buffer, 1, size, pokemon_ekx);
    if (result != size)
        return 1;

    // Credit to YoshiOG1 for finding this address
    WRITEU16(0x08C9E134 , buffer);
    fclose(pokemon_ekx);
    free(buffer);
    return 0;
}

I know, I know, it's pretty primitive. In the future, I plan to add a file selection, but that's beyond my abilities as of now.

When I try to build the cheat.plg file, it throws a bunch of weird errors while linking:
Code:
lib\\libc.a(lib_a-fopen.o): In function `_fopen_r':
(.text+0x44): undefined reference to `_open_r'
lib\\libc.a(lib_a-freer.o): In function `_malloc_trim_r':
(.text+0x48): undefined reference to `_sbrk_r'
lib\\libc.a(lib_a-freer.o): In function `_malloc_trim_r':
(.text+0x78): undefined reference to `_sbrk_r'
lib\\libc.a(lib_a-freer.o): In function `_malloc_trim_r':
(.text+0xc0): undefined reference to `_sbrk_r'
lib\\libc.a(lib_a-fseeko.o): In function `_fseeko_r':
(.text+0x2f4): undefined reference to `_fstat_r'
lib\\libc.a(lib_a-fseeko.o): In function `_fseeko_r':
(.text+0x3f8): undefined reference to `_fstat_r'
lib\\libc.a(lib_a-makebuf.o): In function `__smakebuf_r':
(.text+0x30): undefined reference to `_fstat_r'
lib\\libc.a(lib_a-makebuf.o): In function `__smakebuf_r':
(.text+0x124): undefined reference to `_isatty_r'
lib\\libc.a(lib_a-mallocr.o): In function `_malloc_r':
(.text+0x2e0): undefined reference to `_sbrk_r'
lib\\libc.a(lib_a-mallocr.o): In function `_malloc_r':
(.text+0x358): undefined reference to `_sbrk_r'
lib\\libc.a(lib_a-stdio.o): In function `__sread':
(.text+0xc): undefined reference to `_read_r'
lib\\libc.a(lib_a-stdio.o): In function `__swrite':
(.text+0x68): undefined reference to `_lseek_r'
lib\\libc.a(lib_a-stdio.o): In function `__swrite':
(.text+0x88): undefined reference to `_write_r'
lib\\libc.a(lib_a-stdio.o): In function `__sseek':
(.text+0xa0): undefined reference to `_lseek_r'
lib\\libc.a(lib_a-stdio.o): In function `__sclose':
(.text+0xcc): undefined reference to `_close_r'
arm-none-eabi-ld: error: required section '.rel.plt' not found in the linker script
arm-none-eabi-ld: final link failed: Invalid operation

My question is, does the libc/libgcc included with the template have support for file functions, and if so, what am I doing wrong? If anyone actually knows this convoluted question, please feel free to respond.

Thanks!
 
Last edited by ZiggyDeer,

Coto

-
Member
Joined
Jun 4, 2010
Messages
2,979
Trophies
2
XP
2,565
Country
Chile
not directly related but @
Code:
fseek(pokemon_ekx,0, SEEK_END);
size = ftell(pokemon_ekx);
you should right after:
Code:
fseek(pokemon_ekx,0,SEEK_SET); //set file handle at zero pos
otherwise you will read exactly from end of file (out of bounds)
 

ZiggyDeer

Active Member
OP
Newcomer
Joined
Dec 20, 2014
Messages
41
Trophies
0
Location
USA
Website
ziggydev.xyz
XP
304
Country
United States
not directly related but @
Code:
fseek(pokemon_ekx,0, SEEK_END);
size = ftell(pokemon_ekx);
you should right after:
Code:
fseek(pokemon_ekx,0,SEEK_SET); //set file handle at zero pos
otherwise you will read exactly from end of file (out of bounds)

Thanks, I will update that in my source.

Also, I read here that some Embedded ARM devices do not have support for fopen(), fread(), etc, and instead have to use the open() and read() syscalls.

I will try those, and will reply with the results.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    Veho @ Veho: Firefox users be like "look at what they have to do to mimic a fraction of our power."