void *gf_mem_realloc_tracker(void *ptr, size_t size, const char *filename, int line) { void *ptr_g; int size_prev; if (!ptr) { gf_memory_log(GF_MEMORY_DEBUG, "[MemTracker] realloc() from a null pointer: calling malloc() instead\n"); return gf_mem_malloc_tracker(size, filename, line); } /*a) The return value is NULL if the size is zero and the buffer argument is not NULL. In this case, the original block is freed.*/ if (!size) { gf_memory_log(GF_MEMORY_DEBUG, "[MemTracker] realloc() with a null size: calling free() instead\n"); gf_mem_free_tracker(ptr, filename, line); return NULL; } size_prev = unregister_address(ptr, filename, line); ptr_g = REALLOC(ptr, size); if (!ptr_g) { /*b) The return value is NULL if there is not enough available memory to expand the block to the given size. In this case, the original block is unchanged.*/ gf_memory_log(GF_MEMORY_ERROR, "[MemTracker] realloc() has returned a NULL pointer\n"); register_address(ptr, size_prev, filename, line); assert(0); } else { register_address(ptr_g, size, filename, line); // gf_memory_log(GF_MEMORY_DEBUG, "[MemTracker] realloc %3d (instead of %3d) bytes at %p (instead of %p)\n", size, size_prev, ptr_g, ptr); gf_memory_log(GF_MEMORY_DEBUG, "[MemTracker] realloc %3d (instead of %3d) bytes at %p\n", size, size_prev, ptr_g); gf_memory_log(GF_MEMORY_DEBUG, " file %s at line %d\n" , filename, line); } return ptr_g; }
// Write out the R-Type instruction void rtype_instruction(char *instruction, char *rs, char *rt, char *rd, int shamt, FILE *Out) { // Set the instruction bits char *opcode = "000000"; char *rdBin = "00000"; if (strcmp(rd, "00000") != 0) rdBin = register_address(rd); char *rsBin = "00000"; if (strcmp(rs, "00000") != 0) rsBin = register_address(rs); char *rtBin = "00000"; if (strcmp(rt, "00000") != 0) rtBin = register_address(rt); char *func = NULL; char shamtBin[6]; // Convert shamt to binary and put in shamtBin as a char* getBin(shamt, shamtBin, 5); size_t i; for (i = 0; rMap[i].name != NULL; i++) { if (strcmp(instruction, rMap[i].name) == 0) { func = rMap[i].function; } } if(RADIX == 16) { char buf[40]; sprintf(buf,"%s%s%s%s%s%s", opcode, rsBin, rtBin, rdBin, shamtBin, func); int hex = getDec(buf); // Print out the instruction to the file fprintf(Out, "%08X,\n",hex); } else { fprintf(Out, "%s%s%s%s%s%s,\n", opcode, rsBin, rtBin, rdBin, shamtBin, func); } }
void *gf_mem_malloc_tracker(size_t size, const char *filename, int line) { void *ptr = MALLOC(size); if (!ptr) { gf_memory_log(GF_MEMORY_ERROR, "[MemTracker] malloc() has returned a NULL pointer\n"); assert(0); } else { register_address(ptr, size, filename, line); } gf_memory_log(GF_MEMORY_DEBUG, "[MemTracker] malloc %3d bytes at %p\n in file %s at line %d\n", size, ptr, filename, line); return ptr; }
void *gf_mem_calloc_tracker(size_t num, size_t size_of, char *filename, int line) { size_t size = num*size_of; void *ptr = CALLOC(num, size_of); if (!ptr) { gf_memory_log(GF_MEMORY_ERROR, "[MemTracker] calloc() has returned a NULL pointer\n"); assert(0); } else { register_address(ptr, size, filename, line); } gf_memory_log(GF_MEMORY_DEBUG, "[MemTracker] calloc %3d bytes at 0x%08X\n in file %s at line %d\n", size, ptr, filename, line); return ptr; }
bool get_address(void) { printf("Try without fb_mem_exploit fist...\n\n"); set_fb_mem_exploit_enable(false); if (!setup_variables()) { printf("\n\n"); printf("Try again with fb_mem_exploit...\n\n"); set_fb_mem_exploit_enable(true); if (!setup_variables()) { printf("Failed to setup variables.\n"); return false; } } register_address(); return true; }