int main(int argc, char *argv[]) { struct image_t img, indata, oudata; image_read("origin_img/6001.bmp", &img); image_read(FILE_INPUT, &indata); image_lsbr_code(&img, &indata, 1); image_write("code_img/", &img); image_read("code_img/6001.bmp", &img); image_lsbr_decode(&img, &oudata, 1); image_write("output/", &oudata); return 0; }
int main(int argc, char **argv) { if ( argc != 2 ) { fprintf(stderr, "usage: ./test-image [image-file]\n"); return 1; } const char *FILENAME_IN = argv[1]; const char *FILENAME_OUT = "wahaha.ppm"; // map an image to a column vector image_t *image = image_construct(); image_read(image, FILENAME_IN); matrix_t *x = m_initialize(image->channels * image->width * image->height, 1); m_image_read(x, 0, image); // map a column vector to an image m_image_write(x, 0, image); image_write(image, FILENAME_OUT); image_destruct(image); m_free(x); return 0; }
float *image_read_float(const char *name, int *w, int *h, int *c, int *b) { void *p = 0; float *q = 0; int i; /* Read the named file. */ if ((p = image_read(name, w, h, c, b))) { int n = (*w) * (*h) * (*c); /* If the type is already float (b == 4) then return immediately. */ if ((*b) == 4) return p; /* Otherwise, convert the file before returning. */ if ((q = (float *) malloc(n * sizeof (float)))) { if ((*b) == 1) for (i = 0; i < n; ++i) q[i] = btof(((unsigned char *) p)[i]); if ((*b) == 2) for (i = 0; i < n; ++i) q[i] = stof(((unsigned short *) p)[i]); } free(p); } return q; }
static void m2i_rename(path_t *path, cbmdirent_t *dent, uint8_t *newname) { uint16_t offset; uint8_t *ptr; set_busy_led(1); /* Locate entry in the M2I file */ offset = dent->pvt.m2i.offset; if (load_entry(path->part, offset)) { update_leds(); return; } /* Re-load the entry because load_entry modifies it */ /* Assume this never fails because load_entry was successful */ image_read(path->part, offset, ops_scratch, M2I_ENTRY_LEN); /* Copy the new filename */ ptr = ops_scratch + M2I_CBMNAME_OFFSET; memset(ptr, ' ', CBM_NAME_LENGTH); while (*newname) *ptr++ = *newname++; /* Write new entry */ image_write(path->part, offset, ops_scratch, M2I_ENTRY_LEN, 1); update_leds(); }
int main() { IMAGE *image1 = image_read("pc2.bmp"); IMAGE *image2 = myfunction(image1); image_write("UnsharpenImage.bmp",image2); system("UnsharpenImage.bmp"); return 0; }
int main() { IMAGE *image1 = image_read("pc1.bmp"); IMAGE *image2 = myfunction1(image1); image_write("Otsu.bmp",image2); system("Otsu.bmp"); IMAGE *image3 = myfunction2(image1); image_write("Adaptive.bmp",image3); system("Adaptive.bmp"); return 0; }
void LoadTextures(const char *textureName) { std::cout << "Loading Texture " << textureName << std::endl; int w, h, c, b; void *p = image_read(textureName, &w, &h, &c, &b); int i = image_internal_form(c, b); int e = image_external_form(c); int t = image_external_type(b); image_flip(w, h, c, b, p); glTexImage2D(GL_TEXTURE_2D, 0, i, w, h, 0, e, t, p); free(p); std::cout << "Done Loading Texture " << textureName << std::endl; }
char *ascii_read() { FILE *jpeg = webcam_read(); image_t *original = image_read(jpeg), *resized = image_new(opt_width, opt_height); fclose(jpeg); image_clear(resized); image_resize(original, resized); char *ascii = image_print(resized); image_destroy(original); image_destroy(resized); return ascii; }
int main(int argc, char *argv[]) { struct image_t img_1, img_2; int diff; image_read(argv[1], &img_1); if(argv[2][0] == '1') image_lsbr_rndcode(&img_1, 0.01); image_clone(&img_1, &img_2); image_plusone(&img_2); image_offset(&img_1); image_offset(&img_2); image_write("image_ideal.bmp", &img_1); image_write("image_plusone.bmp", &img_2); return 0; }
/** * load_entry - load M2I entry at offset into ops_scratch * @part : partition number * @offset: offset in M2I file to be loaded * * This function loads the M2I line at offset into ops_scratch and zero- * terminates the FAT name within. Returns 0 if successful, 1 at * end of file or 255 on error. */ static uint8_t load_entry(uint8_t part, uint16_t offset) { uint8_t i; i = image_read(part, offset, ops_scratch, M2I_ENTRY_LEN); if (i > 1) return 255; if (i == 1) /* Incomplete entry read, assuming end of file */ return 1; /* Be nice and zero-terminate the FAT filename */ i = 0; while (ops_scratch[M2I_FATNAME_OFFSET + i] != ' ' && i < M2I_FATNAME_LEN) i++; ops_scratch[M2I_FATNAME_OFFSET + i] = 0; return 0; }
extern image_t * load_image(char *skinpath, char *file) { image_params_t ip; char fn[1024]; image_t *img; url_t *u; if(!file) return NULL; snprintf(fn, 1023, "%s/%s", skinpath, file); u = url_open(fn, "r"); if(!u) return NULL; ip.pixel_type = IMAGE_COLOR_RGB | IMAGE_COLOR_ALPHA; img = image_read(u, &ip); u->close(u); return img; }
void VIDEO_IN::read_image() { std::ostringstream name_s; FILE *fin = NULL; // Calcul du nom de la prochaine image. name_s << base_name << std::setfill('0') << std::setw(2) << current_image_number << ".png"; fin = fopen(name_s.str().c_str(), "rb"); if(fin == NULL) { // Le Fichier n'existe pas, on remet l'index a zero current_image_number = 0; name_s.str(""); name_s.clear(); name_s << base_name << std::setfill('0') << std::setw(2) << current_image_number << ".png"; fin = fopen(name_s.str().c_str(), "rb"); // Problème! il n'y a aucune image avec ce nom de base if(fin == NULL) { std::cerr << name() << "(read_image): impossible d'ouvrir l'image source " << name_s.str() << endl; exit(-1); } } fclose(fin); // Lecture proprement dite de l'image PNG a l'aide de la libpng std::cout << name() << " Ouverture de l'image " << name_s.str() << endl; image_read(&image, name_s.str().c_str()); // L'image est lue et chargée en mémoire. // On vérifie quand même que l'image lue a la bonne taille (720*576) if((image.width != 720) || (image.height != 576)) { std::cerr << name() << " l'image " << name_s.str() << " n'a pas les bonnes dimensions (720*576)" << endl; exit(-1); } }
static void init_tex(struct cube *C) { void *p; int w; int h; int c; int b; int i; for (i = 0; i < 6; ++i) if ((p = image_read(names[i], &w, &h, &c, &b))) { int f = image_internal_form(c, b); int e = image_external_form(c); int t = image_external_type(b); glBindTexture(GL_TEXTURE_2D, C->tex[i]); glTexImage2D (GL_TEXTURE_2D, 0, f, w, h, 0, e, t, p); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } }
int fiasco_unpack(struct fiasco * fiasco, const char * dir) { int fd = -1; char * name = NULL; char * layout_name = NULL; struct image * image; struct image_list * image_list; uint32_t size; char cwd[256]; unsigned char buf[4096]; if ( dir ) { memset(cwd, 0, sizeof(cwd)); if ( ! getcwd(cwd, sizeof(cwd)) ) { ERROR_INFO("Cannot store current directory"); return -1; } if ( chdir(dir) < 0 ) { ERROR_INFO("Cannot change current directory to %s", dir); return -1; } } fiasco_print_info(fiasco); image_list = fiasco->first; while ( image_list ) { image = image_list->image; name = image_name_alloc_from_values(image); if ( ! name ) return -1; printf("\n"); printf("Unpacking image...\n"); image_print_info(image); if ( image->layout ) { layout_name = calloc(1, strlen(name) + strlen(".layout") + 1); if ( ! layout_name ) ALLOC_ERROR_RETURN(-1); sprintf(layout_name, "%s.layout", name); printf(" Layout file: %s\n", layout_name); } printf(" Output file: %s\n", name); if ( ! simulate ) { fd = open(name, O_RDWR|O_CREAT|O_TRUNC, 0644); if ( fd < 0 ) { ERROR_INFO("Cannot create output file %s", name); return -1; } } free(name); image_seek(image, 0); while ( 1 ) { size = image_read(image, buf, sizeof(buf)); if ( size == 0 ) break; WRITE_OR_FAIL(name, fd, buf, size); } close(fd); if ( image->layout ) { if ( ! simulate ) { fd = open(layout_name, O_RDWR|O_CREAT|O_TRUNC, 0644); if ( fd < 0 ) { ERROR_INFO("Cannot create layout file %s", layout_name); return -1; } } free(layout_name); WRITE_OR_FAIL(layout_name, fd, image->layout, (int)strlen(image->layout)); close(fd); } image_list = image_list->next; } if ( dir ) { if ( chdir(cwd) < 0 ) { ERROR_INFO("Cannot change current directory back to %s", cwd); return -1; } } printf("\nDone\n\n"); return 0; }
int fiasco_write_to_file(struct fiasco * fiasco, const char * file) { int fd = -1; int i; int device_count; uint32_t size; uint32_t length; uint16_t hash; uint8_t length8; char ** device_hwrevs_bufs; const char * str; const char * type; struct image_list * image_list; struct image * image; unsigned char buf[4096]; if ( ! fiasco ) return -1; printf("Generating Fiasco image %s...\n", file); if ( ! fiasco->first ) FIASCO_WRITE_ERROR(file, fd, "Nothing to write"); if ( fiasco->name && strlen(fiasco->name)+1 > UINT8_MAX ) FIASCO_WRITE_ERROR(file, fd, "Fiasco name string is too long"); if ( fiasco->swver && strlen(fiasco->swver)+1 > UINT8_MAX ) FIASCO_WRITE_ERROR(file, fd, "SW version string is too long"); if ( ! simulate ) { fd = open(file, O_RDWR|O_CREAT|O_TRUNC, 0644); if ( fd < 0 ) { ERROR_INFO("Cannot create file"); return -1; } } printf("Writing Fiasco header...\n"); WRITE_OR_FAIL(file, fd, "\xb4", 1); /* signature */ if ( fiasco->name[0] ) str = fiasco->name; else str = "OSSO UART+USB"; length = 4 + strlen(str) + 3; if ( fiasco->swver[0] ) length += strlen(fiasco->swver) + 3; length = htonl(length); WRITE_OR_FAIL(file, fd, &length, 4); /* FW header length */ if ( fiasco->swver[0] ) length = htonl(2); else length = htonl(1); WRITE_OR_FAIL(file, fd, &length, 4); /* FW header blocks count */ /* Fiasco name */ length8 = strlen(str)+1; WRITE_OR_FAIL(file, fd, "\xe8", 1); WRITE_OR_FAIL(file, fd, &length8, 1); WRITE_OR_FAIL(file, fd, str, length8); /* SW version */ if ( fiasco->swver[0] ) { printf("Writing SW version: %s\n", fiasco->swver); length8 = strlen(fiasco->swver)+1; WRITE_OR_FAIL(file, fd, "\x31", 1); WRITE_OR_FAIL(file, fd, &length8, 1); WRITE_OR_FAIL(file, fd, fiasco->swver, length8); }; printf("\n"); image_list = fiasco->first; while ( image_list ) { image = image_list->image; if ( ! image ) FIASCO_WRITE_ERROR(file, fd, "Empty image"); printf("Writing image...\n"); image_print_info(image); type = image_type_to_string(image->type); device_hwrevs_bufs = device_list_alloc_to_bufs(image->devices); device_count = 0; if ( device_hwrevs_bufs && device_hwrevs_bufs[0] ) for ( ; device_hwrevs_bufs[device_count]; ++device_count ); if ( ! type ) FIASCO_WRITE_ERROR(file, fd, "Unknown image type"); if ( image->version && strlen(image->version) > UINT8_MAX ) FIASCO_WRITE_ERROR(file, fd, "Image version string is too long"); if ( image->layout && strlen(image->layout) > UINT8_MAX ) FIASCO_WRITE_ERROR(file, fd, "Image layout is too long"); printf("Writing image header...\n"); /* signature */ WRITE_OR_FAIL(file, fd, "T", 1); /* number of subsections */ length8 = device_count+1; if ( image->version ) ++length8; if ( image->layout ) ++length8; WRITE_OR_FAIL(file, fd, &length8, 1); /* unknown */ WRITE_OR_FAIL(file, fd, "\x2e\x19\x01\x01\x00", 5); /* checksum */ hash = htons(image->hash); WRITE_OR_FAIL(file, fd, &hash, 2); /* image type name */ memset(buf, 0, 12); strncpy((char *)buf, type, 12); WRITE_OR_FAIL(file, fd, buf, 12); /* image size */ size = htonl(image->size); WRITE_OR_FAIL(file, fd, &size, 4); /* unknown */ WRITE_OR_FAIL(file, fd, "\x00\x00\x00\x00", 4); /* append version subsection */ if ( image->version ) { WRITE_OR_FAIL(file, fd, "1", 1); /* 1 - version */ length8 = strlen(image->version)+1; WRITE_OR_FAIL(file, fd, &length8, 1); WRITE_OR_FAIL(file, fd, image->version, length8); } /* append device & hwrevs subsection */ for ( i = 0; i < device_count; ++i ) { WRITE_OR_FAIL(file, fd, "2", 1); /* 2 - device & hwrevs */ WRITE_OR_FAIL(file, fd, &device_hwrevs_bufs[i][0], 1); WRITE_OR_FAIL(file, fd, device_hwrevs_bufs[i]+1, ((uint8_t *)(device_hwrevs_bufs[i]))[0]); } free(device_hwrevs_bufs); /* append layout subsection */ if ( image->layout ) { length8 = strlen(image->layout); WRITE_OR_FAIL(file, fd, "3", 1); /* 3 - layout */ WRITE_OR_FAIL(file, fd, &length8, 1); WRITE_OR_FAIL(file, fd, image->layout, length8); } /* dummy byte - end of all subsections */ WRITE_OR_FAIL(file, fd, "\x00", 1); printf("Writing image data...\n"); image_seek(image, 0); while ( 1 ) { size = image_read(image, buf, sizeof(buf)); if ( size == 0 ) break; WRITE_OR_FAIL(file, fd, buf, size); } image_list = image_list->next; if ( image_list ) printf("\n"); } close(fd); printf("\nDone\n\n"); return 0; }
static uint8_t m2i_getdisklabel(uint8_t part, uint8_t *label) { label[16] = 0; return image_read(part, 0, label, 16); }
int main( int argc, char *argv[]){ //set up the images Image *src; Image *myImage; //set up the modules!! Module *basket; Module *connector; Module *connector1; Line l; Point pts[2]; Module *circle; Module *hotAirBalloon; Module *teamOfBalloons; Module *scene; //pick the colors Color colors[6]; Color brown; Color blue; Color green; Color grey; //set up view stuff, and image file stuff Matrix vtm, gtm; int rows; int cols; View3D view; DrawState *ds; char filename[256]; int i, j, k, m, n; //Set the colors up color_set(&brown, 0.2, 0.1, 0.0); color_set(&blue, 0.6, 0.8, 1.0); color_set(&green, 0.1, 0.4, 0.0); color_set(&grey, 0.3, 0.3, 0.3); color_set(&colors[0], 1.0, 0.0, 0.0);//Red color_set(&colors[1],1.0, 0.5, 0.0);//orange color_set(&colors[2],1.0, 1.0, 0.1);//yellow color_set(&colors[3], 0.0, 1.0, 0.0);//green color_set(&colors[4], 0.0, 0.0, 1.0);//blue color_set(&colors[5], 0.4, 0.0, 0.8);//purple //if you want to supply a background image you can, otherwise I set a default sky blue background! if(argc>1){ printf("you supplied an image\n"); myImage = image_read(argv[1]); rows = myImage->rows; cols = myImage->cols; printf("%d %d\n", rows, cols); }else{ printf("We are giving your image a default size!\n"); rows = 500; cols = 500; myImage = image_create(rows, cols); for(m = 0; m< rows; m++){ for(n = 0; n<cols; n++){ image_setColor(myImage, m, n, blue); } } } //Loop over the scene 300 times moving the scene around!! for(k = 0; k<300; k++){ //Set up the view point_set( &(view.vrp), 150, 100, 200, 1.0); vector_set( &(view.vpn), -view.vrp.val[0], -view.vrp.val[1], -view.vrp.val[2]); vector_set( &(view.vup), 0, 1.0, 0); view.d = 20; view.du = 10; view.dv = view.du* (float)rows/cols; view.f = 0; view.b = 5; view.screenx = rows; view.screeny = cols; matrix_setView3D( &vtm, &view); matrix_identity( >m ); // basket: cube (will need 1 in hot air balloon module) basket = module_create(); module_color(basket, &brown); module_cube(basket, 1); //connectors: lines need 4 connector = module_create(); point_set3D(&pts[0],1,1,1 ); point_set3D(&pts[1],2,4.2,1); line_set(&l, pts[0], pts[1]); module_line(connector, &l); connector1 = module_create(); point_set3D(&pts[0], 1,1 , 1); point_set3D(&pts[1], 0,4.2 ,1 ); line_set(&l, pts[0], pts[1]); module_line(connector1, &l); // balloon: circles nested on top of eachother circle = module_create(); module_color(circle, &colors[0]); module_rotateX(circle, 0, 1); module_translate2D(circle, 0, 3); module_circle(circle, 1); module_color(circle, &colors[1]); module_rotateX(circle, 1, 0); module_translate2D(circle, 0, 1); module_circle(circle, 2.5); module_color(circle, &colors[2]); module_rotateX(circle, 1, 0); module_translate2D(circle, 0, 1); module_circle(circle, 3); module_color(circle, &colors[3]); module_rotateX(circle, 1, 0); module_translate2D(circle, 0, 1); module_circle(circle, 4); module_color(circle, &colors[4]); module_rotateX(circle, 1, 0); module_translate2D(circle, 0, 1); module_circle(circle, 5); module_color(circle, &colors[5]); module_rotateX(circle, 1, 0); module_translate2D(circle, 0, 1); module_circle(circle, 6); module_color(circle, &colors[0]); module_rotateX(circle, 1,0); module_translate2D(circle, 0, 1); module_circle(circle, 7); module_color(circle, &colors[1]); module_rotateX(circle, 1, 0); module_translate2D(circle, 0, 1); module_circle(circle, 7); module_color(circle, &colors[2]); module_rotateX(circle, 1, 0); module_translate2D(circle, 0,1); module_circle(circle, 7); module_color(circle, &colors[3]); module_rotateX(circle, 1, 0); module_translate2D(circle, 0, 1); module_circle(circle, 7); module_color(circle, &colors[4]); module_rotateX(circle, 1, 0); module_translate2D(circle, 0, 1); module_circle(circle, 6); module_color(circle, &colors[5]); module_rotateX(circle, 1, 0); module_translate2D(circle, 0, 1); module_circle(circle, 5); module_color(circle, &colors[0]); module_rotateX(circle, 1, 0); module_translate2D(circle, 0, 1); module_circle(circle, 4); module_color(circle, &colors[1]); module_rotateX(circle, 1, 0); module_translate2D(circle, 0, 0.5); module_circle(circle, 3); module_color(circle, &colors[2]); module_rotateX(circle, 1, 0); module_translate2D(circle, 0, 0.5); module_circle(circle, 2); //hotAirBalloon: put the above parts together hotAirBalloon = module_create(); module_module(hotAirBalloon, basket); module_module(hotAirBalloon, connector); module_translate(hotAirBalloon, -2,0 ,0 ); module_module(hotAirBalloon, connector1); module_translate(hotAirBalloon, 0, 0, -2); module_module(hotAirBalloon, connector1); module_translate(hotAirBalloon, 2, 0, 0); module_module(hotAirBalloon, connector); module_module(hotAirBalloon, circle); //make a team of balloons teamOfBalloons = module_create(); module_translate(teamOfBalloons, 0,-30,-15); module_module(teamOfBalloons, hotAirBalloon); module_translate(teamOfBalloons, 0, 0+(k*0.1),15); module_module(teamOfBalloons, hotAirBalloon); module_translate(teamOfBalloons, 0, 0+(k*0.1),15); module_module(teamOfBalloons, hotAirBalloon); //make a scene of balloons scene = module_create(); module_translate(scene, -40, 10+(k*0.1), 10); module_module(scene, teamOfBalloons); module_translate(scene, 140, 10, 55); module_module(scene, teamOfBalloons); module_translate(scene, -50, 10+(k*0.1), -40); module_module(scene, teamOfBalloons); module_translate(scene, 30, 10+(k*0.2) , -55); module_module(scene, teamOfBalloons); //set up the image src = image_create(rows, cols); //Either draw the background image you supplied or use my default background for (i = 0; i<rows; i++){ for (j = 0; j<cols; j++){ blue = image_getColor(myImage, i, j); image_setColor(src,i, j, blue); } } //set up the draw state if you want filled polygons need to use ShadeConstant instead of ShadeFrame ds = drawstate_create(); ds->shade = ShadeFrame; //draw the modules! module_draw( scene, &vtm, >m, ds, NULL, src); //put the files in the right place with the right name!! sprintf(filename, "/export/home/vedwards/Desktop/Graphics/images/hotAirBalloons3/frame-%04d.ppm", k ); printf("Writing image\n"); image_write( src, filename ); } //Clean up, delete all of the modules, images, and drawState module_delete(basket); module_delete(connector); module_delete(connector1); module_delete(circle); module_delete(hotAirBalloon); module_delete(teamOfBalloons); free(ds); image_free( src ); image_free( myImage ); return(0); }
/* * * The implementation assumes that the loadable segments are present * in the PHT sorted by their offsets, so that only forward seeks would * be necessary. */ int load_segments(struct elf_module *module, Elf_Ehdr *elf_hdr) { int i; int res = 0; char *pht = NULL; char *sht = NULL; Elf32_Phdr *cr_pht; Elf32_Shdr *cr_sht; Elf32_Addr min_addr = 0x00000000; // Min. ELF vaddr Elf32_Addr max_addr = 0x00000000; // Max. ELF vaddr Elf32_Word max_align = sizeof(void*); // Min. align of posix_memalign() Elf32_Addr min_alloc, max_alloc; // Min. and max. aligned allocables Elf32_Addr dyn_addr = 0x00000000; // Get to the PHT image_seek(elf_hdr->e_phoff, module); // Load the PHT pht = malloc(elf_hdr->e_phnum * elf_hdr->e_phentsize); if (!pht) return -1; image_read(pht, elf_hdr->e_phnum * elf_hdr->e_phentsize, module); // Compute the memory needings of the module for (i=0; i < elf_hdr->e_phnum; i++) { cr_pht = (Elf32_Phdr*)(pht + i * elf_hdr->e_phentsize); switch (cr_pht->p_type) { case PT_LOAD: if (i == 0) { min_addr = cr_pht->p_vaddr; } else { min_addr = MIN(min_addr, cr_pht->p_vaddr); } max_addr = MAX(max_addr, cr_pht->p_vaddr + cr_pht->p_memsz); max_align = MAX(max_align, cr_pht->p_align); break; case PT_DYNAMIC: dyn_addr = cr_pht->p_vaddr; break; default: // Unsupported - ignore break; } } if (max_addr - min_addr == 0) { // No loadable segments DBG_PRINT("No loadable segments found\n"); goto out; } if (dyn_addr == 0) { DBG_PRINT("No dynamic information segment found\n"); goto out; } // The minimum address that should be allocated min_alloc = min_addr - (min_addr % max_align); // The maximum address that should be allocated max_alloc = max_addr - (max_addr % max_align); if (max_addr % max_align > 0) max_alloc += max_align; if (elf_malloc(&module->module_addr, max_align, max_alloc-min_alloc) != 0) { DBG_PRINT("Could not allocate segments\n"); goto out; } module->base_addr = (Elf32_Addr)(module->module_addr) - min_alloc; module->module_size = max_alloc - min_alloc; // Zero-initialize the memory memset(module->module_addr, 0, module->module_size); for (i = 0; i < elf_hdr->e_phnum; i++) { cr_pht = (Elf32_Phdr*)(pht + i * elf_hdr->e_phentsize); if (cr_pht->p_type == PT_LOAD) { // Copy the segment at its destination if (cr_pht->p_offset < module->u.l._cr_offset) { // The segment contains data before the current offset // It can be discarded without worry - it would contain only // headers Elf32_Off aux_off = module->u.l._cr_offset - cr_pht->p_offset; if (image_read((char *)module_get_absolute(cr_pht->p_vaddr, module) + aux_off, cr_pht->p_filesz - aux_off, module) < 0) { res = -1; goto out; } } else { if (image_seek(cr_pht->p_offset, module) < 0) { res = -1; goto out; } if (image_read(module_get_absolute(cr_pht->p_vaddr, module), cr_pht->p_filesz, module) < 0) { res = -1; goto out; } } /* DBG_PRINT("Loadable segment of size 0x%08x copied from vaddr 0x%08x at 0x%08x\n", cr_pht->p_filesz, cr_pht->p_vaddr, (Elf32_Addr)module_get_absolute(cr_pht->p_vaddr, module)); */ } } // Get to the SHT image_seek(elf_hdr->e_shoff, module); // Load the SHT sht = malloc(elf_hdr->e_shnum * elf_hdr->e_shentsize); if (!sht) { res = -1; goto out; } image_read(sht, elf_hdr->e_shnum * elf_hdr->e_shentsize, module); // Setup the symtable size for (i = 0; i < elf_hdr->e_shnum; i++) { cr_sht = (Elf32_Shdr*)(sht + i * elf_hdr->e_shentsize); if (cr_sht->sh_type == SHT_DYNSYM) { module->symtable_size = cr_sht->sh_size; break; } } free(sht); // Setup dynamic segment location module->dyn_table = module_get_absolute(dyn_addr, module); /* DBG_PRINT("Base address: 0x%08x, aligned at 0x%08x\n", module->base_addr, max_align); DBG_PRINT("Module size: 0x%08x\n", module->module_size); */ out: // Free up allocated memory if (pht != NULL) free(pht); return res; }
static uint8_t m2i_getdirlabel(path_t *path, uint8_t *label) { return image_read(path->part, 0, label, 16); }