-
Notifications
You must be signed in to change notification settings - Fork 2
Python development
libwrc comes with Python-bindings named pywrc.
Below are examples how use pywrc. They assume you have a working version of pywrc on your system. To build pywrc see Building.
To be able to use pywrc in your Python scripts add the following import:
import pywrc
The get_version() module function can be used to retrieve the version of the pywrc.
pywrc.get_version()
This will return a textual string (Unicode) that contains the libwrc version. Since pywrc is a wrapper around libwrc it does not have a separate version.
import pyexe
import pywrc
exe_file = pyexe.file()
exe_file.open("cmd.exe")
exe_section = exe_file.get_section_by_name('.rsrc')
wrc_stream = pywrc.stream()
wrc_stream.set_virtual_address(exe_section.virtual_address)
wrc_stream.open_file_object(exe_section)
wrc_stream.close()
exe_file.close()
Note that the explicit calls to close are not required.
A pywrc.resource is the base object for the different resources stored in a PE/COFF executable stream.
The number of resources can be retrieved by either calling the get_number_of_resources() function, e.g.
number_of_resources = wrc_stream.get_number_of_resources()
or reading the number_of_resources property:
number_of_resources = wrc_stream.number_of_resources
A resource can be retrieved by index:
wrc_resource = wrc_stream.get_resource(0)
The function will return the most specific item object type. This will either be pywrc.item, pywrc.manifest, pywrc.message_table, pywrc.string. Where pywrc.resource is the base type for the other resource types.
A resource can be retrieved by its numeric identifier:
RESOURCE_IDENTIFIER_MESSAGE_TABLE = 0x0b
wrc_resource = wrc_stream.get_resource(RESOURCE_IDENTIFIER_MESSAGE_TABLE)
import pywrc
help(pywrc)
help(pywrc.stream)
help(pywrc.resource)
help(pywrc.manifest)
help(pywrc.message_table)
help(pywrc.string)