TACIXAT / portable-executable-library

Automatically exported from code.google.com/p/portable-executable-library
23 stars 22 forks source link

How to add a resource into a new PE file? #4

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago

Hello, I'm a beginner, my English is not good.I now have a good pe generated 
files. I want to fill it to add a zip package. . I'm running on linux. I hope 
to get your help?

email  460457528@qq.com

Original issue reported on code.google.com by 460457...@qq.com on 23 Aug 2013 at 4:16

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
//Create PE image from file stream
pe_base image(pe_factory::create_pe(pe_file));

//Get Resource Manager
resource_directory root(get_resources(image));
pe_resource_manager res(root);

//Change the name of the old resource section (Not Sure if this is neccesary)
image.section_from_directory(pe_win::image_directory_entry_resource).set_name("o
ldres");

//Add the resource by providing data, a root name, resource id, language, ...
res.add_resource(<-Some Binary Data Here->, L"BIN", 205, 1033,0,0);

//Create new resource section and add it to the image
section new_resources;
new_resources.get_raw_data().resize(1);
new_resources.set_name(".rsrc");
new_resources.readable(true);
section& attached_section = image.add_section(new_resources);

//Rebuild the resources
rebuild_resources(image, root, attached_section);

//Build the new executable by providing file stream to write new PE to
rebuild_pe(image, new_pe_file);

Original comment by Damian.D...@gmail.com on 28 Nov 2013 at 10:14