After playing a bit with my ced I came to the conclusion that implemented DSL for editing is not enough - like it would be good to have subroutines to patch repeated/similar instructions, check that patched instruction is what I want, patch attributes/relocs etc
In other words, I need full-fledged PL. Although I've read books series "modern compiler implementation" from Andrew Appel and "crafting interpreters" I think making my own PL is overkill, so I made several XS modules to edit/patch CUBIN files for Perl. Why Perl?
- I am able to write on it almost all I want
- when I can't - I can always to develop my own module(s)
- yet I don't feel sick like from pseudo languages like python
- and it damn good and fast when you try to sketch out prototypes for things you have no idea how to make
ELF::FatBinary
for extracting/replacing CUBIN files from FatBinaries
see details here
Cubin::Ced
In essence this is wrapper around Ced - it allows you to disasm/patch SASS instructions
Currently it don't support registers tracking
See doc in POD format
Cubin::Attrs
Module to extract/patch attributes of CUBIN files + also relocs
doc in POD format
Sample
to get a taste see this script - it
- loads CUBIN file and sets up right sections
- patches special registers in dedicated subroutine patch_s2r
- then patches relocs
Note that you must setup SM_DIR env var to full directory with SASS disasm smXXX.so shared libraries
Installation
All 3 modules depend from ELFIO and base module Elf::Reader
For this reason you need patch all Makefile.PL files for path to ELFIO in INC var
Also I used dirty hack to embed full path of Elf::Reader so you need to build and install it first
Next standard process:
perl Makefile.PL
make
sudo make install
Комментариев нет:
Отправить комментарий