Just to toot my own horn, I have creating a solution for this exact circumstance. You can have a debian archive downloaded, unpacked, built, and reinstalled with 3 simple commands.
It is a shell script called debtool and is available on GitHub via the aforementioned link. As mentioned on the GitHub page, the script requires apt, dpkg, and fakeroot. It also requires dpkg-repack if you want to manipulate packages that are currently installed and no longer available via sources.
Building debian packages from source can be cumbersome, especially on a daily driver that you don't necessarily want to muddle up with numerous build dependencies and the like.
Assuming libvirt is available via sources, run the following command:
debtool --combo libvirt
The above command just downloaded the libvirt_0.9.8_all.deb file and unpacked it into the directory libvirt_0.9.8_all.
At this point you should make all of your changes to the files in the directory. You will also likely want to bump up the package's version number (i.e. 0.9.8-custom1) located in ./libvirt_0.9.8_all/DEBIAN/control.
Now build the new debian archive by running the following command:
debtool --build ./libvirt_0.9.8_all
Your finished debian archive is now in the current directory as libvirt_0.9.8-custom1_all.deb.
You can quickly reinstall this debian archive by running
debtool --reinst ./libvirt_0.9.8-custom1_all.deb.
You can do a couple of other related things with debtool as well.
Show Available Versions
If there are several versions of a package available in the repositories, you can list them as follows:
debtool --show zsh
The above command will return the following:
zsh 5.0.5-4ubuntu1~ubuntu14.04.1 amd64
zsh 5.0.2-3ubuntu6 amd64
If you'd like to download the packages manually then you can use the
debtool --show --show-format zsh
Will return the following:
apt-get download zsh=5.0.5-4ubuntu1~ubuntu14.04.1 -a=amd64
apt-get download zsh=5.0.2-3ubuntu6 -a=amd64
Download Debian Archives
You can download the most recent version of a package as follows:
debtool --download zsh
You can download a specific version as follows:
debtool --download zsh=5.0.2-3ubuntu6
Note: You'll need to download the package manually if you require an architecture-specific package.
You can unpack a debian archive on your hard drive as follows:
debtool --unpack package.deb
You can also unpack a package that is currently installed on your system as follows. Note: requires dpkg-repack
debtool --unpack package
If you have made changes to any of the installed files, they will be incorporated as well. This is perfect if you want to work with a package that is no longer available from sources or if you want to incorporate pre-existing fixes into a 'patched' deb.