Tutorial Getting the address of a library

noobexploiter

Platinian
Original poster
Apr 29, 2022
6
6
3
34
Philippines
When obtaining the address of a library, i commonly see people, searching for the library in the memory map of the game. Take octowolves template for example Hooking-Template-With-Mod-Menu/Utils.h at master · Octowolve/Hooking-Template-With-Mod-Menu
C++:
DWORD findLibrary(const char *library) {
    char filename[0xFF] = {0},
            buffer[1024] = {0};
    FILE *fp = NULL;
    DWORD address = 0;

    //sprintf( filename, "/proc/self/maps"); Buffer Overflow warning. shit is depreceated
    snprintf(filename, sizeof(filename) ,"/proc/self/maps");

    fp = fopen( filename, "rt" );
    if( fp == NULL ){
        perror("fopen");
        goto done;
    }

    while( fgets( buffer, sizeof(buffer), fp ) ) {
        if( strstr( buffer, library ) ){
            address = (DWORD)strtoul( buffer, NULL, 16 );
            goto done;
        }
    }

    done:

    if(fp){
        fclose(fp);
    }

    return address;
}
It opens the /proc/self/maps and search for the library using strstr. The problem with this, is not all the time, libraries are mapped as they are named. For example, farmville,
unknown.png

In its maps, the libil2cpp.so is named split_config.arm64_v8a.apk , so obviously, the strstr will not find it. Instead, i came up with my own implementation
C++:
DWORD addr;
int callback(struct dl_phdr_info *info, size_t size, void *data){
    if(strstr(info->dlpi_name, static_cast<const char* const>(data))){
        addr = info->dlpi_addr;
    }
    return 0;
}

DWORD get_libBase(const char* libName) {
    dl_iterate_phdr(callback, (void*)libName);
    return addr;
}
It uses dl_iterate_phdr to loop through all libraries loaded, on each library found, it will call the callback function. In the callback function, if the name of the library matches what we are looking for, it will assign the addr parameter to the address of that library, and it returns the addr paramter.
You can use it like
C++:
DWORD libil2cpp = get_libBase("libil2cpp.so");
 

noobexploiter

Platinian
Original poster
Apr 29, 2022
6
6
3
34
Philippines
What if you just unsplit the apk?

Farmville 2 example:


No more split_config.arm64_v8a.apk lol
That could also work, but you cant expect everyone to have the unsplit version of the game, for example on bug bounties, triagers will not blindly install an apk you gave to them. So having an exploit that works both on split and unsplit version of the game is better
 

Hiyall360

Awesome Active Platinian
Jan 14, 2018
132
3,944
193
Mr.Pringlez
That could also work, but you cant expect everyone to have the unsplit version of the game, for example on bug bounties, triagers will not blindly install an apk you gave to them. So having an exploit that works both on split and unsplit version of the game is better
And that's what APKCombo is for (popular reputable source for Android apks that get them directly from Google Play)

1652244265864.png


All you do is choose the Architecture and you've got yourself a non-split APK. It's actually quite well known.

Nice tutorial though :D
 

noobexploiter

Platinian
Original poster
Apr 29, 2022
6
6
3
34
Philippines
And that's what APKCombo is for (popular reputable source for Android apks that get them directly from Google Play)

View attachment 411724

All you do is choose the Architecture and you've got yourself a non-split APK. It's actually quite well known.

Nice tutorial though :D
That is cool, but like i said, having an exploit that works both on split and non split apk is better