Skip to content

Instantly share code, notes, and snippets.

@knot126
Created March 29, 2026 19:20
Show Gist options
  • Select an option

  • Save knot126/987da23f5adce52f7e8d3d5b9e7d7d08 to your computer and use it in GitHub Desktop.

Select an option

Save knot126/987da23f5adce52f7e8d3d5b9e7d7d08 to your computer and use it in GitHub Desktop.
/**
* Find starts of LaunchController::decideLaunchMode and
* AccountList::anyAccountIsValid (for prism launcher 11.x)
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <elf.h>
typedef struct Data {
union {
void *pointer;
size_t offset;
};
size_t size;
} Data;
int read_file(const char *path, Data *info_out) {
/**
* Read a file into a buffer
*/
FILE *f = fopen(path, "rb");
if (!f) {
return 0;
}
struct stat file_status;
if (fstat(fileno(f), &file_status)) {
fclose(f);
return 0;
}
void *buffer = malloc(file_status.st_size);
if (!buffer) {
fclose(f);
return 0;
}
if (fread(buffer, file_status.st_size, 1, f) != 1) {
fclose(f);
free(buffer);
return 0;
}
info_out->pointer = buffer;
info_out->size = file_status.st_size;
return 1;
}
int main(int argc, char *argv[]) {
if (argc < 2) {
fprintf(stderr, "Usage: %s <elf file>\n", argv[0]);
return 127;
}
Data elf_data;
if (!read_file(argv[1], &elf_data)) {
fprintf(stderr, "Could not load file %s\n", argv[1]);
return 1;
}
// Main ELF header
Elf64_Ehdr *header = elf_data.pointer;
// Section headers
Elf64_Shdr *shdrs = elf_data.pointer + header->e_shoff;
// String table location
const char *shstrtab = elf_data.pointer + shdrs[header->e_shstrndx].sh_offset;
// Let's find the symbol table
Elf64_Sym *symbols = NULL;
size_t num_symbols = 0;
const char *strtab = NULL;
for (size_t i = 0; i < header->e_shnum; i++) {
if (!strcmp(shstrtab + shdrs[i].sh_name, ".symtab")) {
symbols = elf_data.pointer + shdrs[i].sh_offset;
num_symbols = shdrs[i].sh_size / shdrs[i].sh_entsize;
}
else if (!strcmp(shstrtab + shdrs[i].sh_name, ".strtab")) {
strtab = elf_data.pointer + shdrs[i].sh_offset;
}
}
if (!symbols) {
fprintf(stderr, "Could not find .symtab section\n");
return 1;
}
// print symbol names
for (size_t i = 0; i < num_symbols; i++) {
const char *name = strtab + symbols[i].st_name;
Elf64_Shdr *section = &shdrs[symbols[i].st_shndx];
if (( (strstr(name, "AccountList") && strstr(name, "anyAccountIsValid"))
|| (strstr(name, "LaunchController") && strstr(name, "decideLaunchMode")))
&& (!strstr(name, ".cold"))) {
printf("[%zu] name=%s shndx=%d value=%p\n", i, name, symbols[i].st_shndx, symbols[i].st_value);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment