static int retrieve_addons_libraries(struct dl_phdr_info *info, size_t size, void *data) { char process[260]; char library[32]; strncpy(process, info->dlpi_name, strlen(info->dlpi_name)); if (strstr(process, "addons")) { size_t length = strlen(process); size_t i = length; while (process[--i] != '.') {}; process[i] = '\0'; while (process[--i] != '/') {}; char *pLibrary = strcpy(library, &process[i + 1]); char *ptr = strstr(pLibrary, "_i386"); if (ptr) { library[ptr - pLibrary] = '\0'; } G_GameLibraries.Others.insert(library, new GameLibraryAny(*create_library((void *)info->dlpi_addr))); } return 0; }
LibraryForModule* Rage::insert_library(void* contained_address, char* name) { Library* library = create_library(contained_address,name); if(!library) return NULL; Global::librariesManager.add(name,library); return library; }
void retrieve_addons_libraries() // IM THE KING OF EXAMPLE COPYPASTING! { HMODULE hMods[1024]; HANDLE hProcess; DWORD cbNeeded; unsigned int i; hProcess = GetCurrentProcess(); if (hProcess == NULL) // IS NOT POSSIBLE! return; if (EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded)) { TCHAR process[MAX_PATH]; char library[32]; for (i = 0; i < (cbNeeded / sizeof(HMODULE)); ++i) { if (GetModuleFileNameEx(hProcess, hMods[i], process, sizeof(process) / sizeof(TCHAR))) { _MODULEINFO info; GetModuleInformation(hProcess, hMods[i], &info, sizeof(info)); if (strstr(process, "addons")) { size_t length = strlen(process); size_t i = length; while (process[--i] != '.') {}; process[i] = '\0'; while (process[--i] != '\\') {}; strcpy(library, &process[i + 1]); G_GameLibraries.Others.insert(library, new GameLibraryAny(*create_library((void *)info.lpBaseOfDll))); } } } } }
/* * Main */ int main(int argc, char **argv) { FILE *libfp, *tmpfp, *modfp = NULL; struct stat finfo; struct rdlm_hdr hdr; char buf[MAXMODNAMELEN], *p = NULL; char c; int i; progname = argv[0]; _argv = argv; if (argc < 2) { usage(); exit(1); } /* Check whether some modifiers were specified */ for (i = 1; i < strlen(argv[1]); i++) { switch (c = argv[1][i]) { case 'c': options.createok = true; break; case 'f': options.usefname = true; break; case 'l': options.align = true; break; case 'o': options.odate = true; break; case 'u': options.fresh = true; break; case 'v': options.verbose++; break; case 'V': show_version(); exit(0); default: if (strchr(commands, c) == NULL) error_exit(2, false, "invalid command or modifier '%c'", c); } } if (argc < 3) error_exit(2, false, "missing library name"); /* Process the command */ if (argv[1][0] == '-') argv[1]++; switch (c = argv[1][0]) { case 'a': /* add a module */ if (argc < 4 || (!options.usefname && argc != 5)) error_exit(2, false, "invalid number of arguments"); /* Check if a library already exists. If not - create it */ if (access(argv[2], F_OK) < 0) { if (!options.createok) fprintf(stderr, "creating library %s\n", argv[2]); create_library(argv[2]); } libfp = fopen(argv[2], "ab"); if (!libfp) error_exit(1, true, "could not open '%s'", argv[2]); if (!options.usefname) add_module(libfp, argv[4], argv[3]); else for (i = 3; i < argc; i++) add_module(libfp, argv[i], argv[i]); fclose(libfp); break; case 'n': /* create library */ create_library(argv[2]); break; case 'x': /* extract module(s) */ if (!options.usefname) argc--; if (argc < 4) error_exit(2, false, "required parameter missing"); p = options.usefname ? argv[3] : argv[4]; case 't': /* list library contents */ libfp = fopen(argv[2], "rb"); if (!libfp) error_exit(1, true, "could not open '%s'\n", argv[2]); /* Read library header */ if (fread(&hdr, 1, sizeof(hdr), libfp) != sizeof(hdr) || hdr.magic != RDLAMAG) error_exit(1, false, "invalid library format"); /* Walk through the library looking for requested module */ while (!feof(libfp)) { /* Read module header */ i = fread(&hdr, 1, sizeof(hdr), libfp); if (feof(libfp)) break; if (i != sizeof(hdr) || hdr.magic != RDLMMAG) error_exit(1, false, "invalid module header"); /* Read module name */ i = hdr.hdrsize - sizeof(hdr); if (i > sizeof(buf) || fread(buf, 1, i, libfp) != i) error_exit(1, false, "invalid module name"); if (c == 'x') { /* Check against desired name */ if (!strcmp(buf, argv[3])) { if (options.verbose) fprintf(stderr, "extracting module %s to file %s\n", buf, p); modfp = fopen(p, "wb"); if (!modfp) error_exit(1, true, "could not open '%s'", p); } } else { printf("%-40s ", buf); if (options.verbose) { printf("%ld bytes", hdr.size); } putchar('\n'); } copybytes(libfp, modfp, hdr.size); if (modfp) break; } fclose(libfp); if (modfp) fclose(modfp); else if (c == 'x') error_exit(1, false, "module '%s' not found in '%s'", argv[3], argv[2]); break; case 'r': /* replace module(s) */ argc--; if (stat(argv[4], &finfo) < 0) error_exit(1, true, "could not stat '%s'", argv[4]); case 'd': /* delete module(s) */ if (argc < 4) error_exit(2, false, "required parameter missing"); libfp = fopen(argv[2], "rb"); if (!libfp) error_exit(1, true, "could not open '%s'", argv[2]); /* Copy the library into a temporary file */ tmpfp = tmpfile(); if (!tmpfp) error_exit(1, true, "could not open temporary file"); stat(argv[2], &finfo); copybytes(libfp, tmpfp, finfo.st_size); rewind(tmpfp); freopen(argv[2], "wb", libfp); /* Read library header and write it to a new file */ if (fread(&hdr, 1, sizeof(hdr), tmpfp) != sizeof(hdr) || hdr.magic != RDLAMAG) error_exit(1, false, "invalid library format"); put_header(&hdr, libfp, NULL); /* Walk through the library looking for requested module */ while (!feof(tmpfp)) { /* Read module header */ if (fread(&hdr, 1, sizeof(hdr), tmpfp) != sizeof(hdr) || hdr.magic != RDLMMAG) error_exit(1, false, "invalid module header"); /* Read module name */ i = hdr.hdrsize - sizeof(hdr); if (i > sizeof(buf) || fread(buf, 1, i, tmpfp) != i) error_exit(1, false, "invalid module name"); /* Check against desired name */ if (!strcmp(buf, argv[3]) && (c == 'd' || !options.odate || finfo.st_mtime <= hdr.date)) { if (options.verbose) fprintf(stderr, "deleting module %s\n", buf); fseek(tmpfp, hdr.size, SEEK_CUR); break; } else { put_header(&hdr, libfp, buf); copybytes(tmpfp, libfp, hdr.size); } } if (c == 'r') { /* Copy new module into library */ p = options.usefname ? argv[4] : argv[3]; add_module(libfp, argv[4], p); } /* Copy rest of library if any */ while (!feof(tmpfp)) { if ((i = fgetc(tmpfp)) == EOF) break; if (fputc(i, libfp) == EOF) error_exit(1, false, "write error"); } fclose(libfp); fclose(tmpfp); break; default: error_exit(2, false, "invalid command '%c'\n", c); } return 0; }