https://github.com/d3dave/cough
Write COFF object files from Python
https://github.com/d3dave/cough
build coff development obj pe python python-3 python3
Last synced: about 2 months ago
JSON representation
Write COFF object files from Python
- Host: GitHub
- URL: https://github.com/d3dave/cough
- Owner: d3dave
- License: mit
- Created: 2017-06-03T12:47:52.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2023-01-12T13:48:21.000Z (over 3 years ago)
- Last Synced: 2026-01-06T23:20:12.956Z (4 months ago)
- Topics: build, coff, development, obj, pe, python, python-3, python3
- Language: Python
- Size: 25.4 KB
- Stars: 14
- Watchers: 2
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
cough
=====
A library for building COFF object files.
Tutorial
--------
Start with the ObjectModule class:
module = ObjectModule()
Now, let's create a '.text' section:
section = Section(b'.text', SectionFlags.MEM_EXECUTE)
Add a bit of code:
section.data = b'\x29\xC0\xC3' # return 0
section.size_of_raw_data = len(section.data)
Good enough, let's add it to our module:
module.sections.append(section)
To make use of that bit of code, we are going to need an exported symbol:
main = SymbolRecord(b'main', section_number=1, storage_class=StorageClass.EXTERNAL)
Set the value to the offset in the section:
main.value = 0
And add it to our module:
module.symbols.append(main)
That's enough, let's write our module to a file:
with open('test.obj', 'wb') as obj_file:
obj_file.write(module.get_buffer())