# Copyright 1999-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$

EAPI=6

PYTHON_COMPAT=( python2_7 )

inherit eutils python-single-r1

DESCRIPTION="BDF allows to patch executable binaries with user desired shellcode"
HOMEPAGE="https://github.com/secretsquirrel/the-backdoor-factory"
SRC_URI="https://github.com/secretsquirrel/the-backdoor-factory/archive/${PV}.tar.gz -> ${P}.tar.gz"

LICENSE="BSD-4"
SLOT="0"
KEYWORDS="~x86 ~amd64"
IUSE=""

DEPEND=""
RDEPEND="${DEPEND}
	>=dev-python/capstone-python-3.0
	app-exploits/osslsigncode
	dev-python/pefile"

src_prepare(){
	epatch "${FILESDIR}"/pebin.patch
	rm -r osslsigncode
	rm {update.sh,install.sh}
	cp "${FILESDIR}"/certs/* ./certs/
	eapply_user
}

src_compile() {
	cd ./aPLib/example/
	gcc -c -I../lib/elf -m32 -Wall -O2 -s -o appack.o appack.c -v
	gcc -m32 -Wall -O2 -s -o appack appack.o ../lib/elf/aplib.a -v
	cd ../..
}

src_install() {
	insinto /usr/share/${PN}
	doins -r "${S}"/*

	dobin ./aPLib/example/appack

	python_fix_shebang "${ED}"/usr/share/${PN}

	fperms +x /usr/share/${PN}/backdoor.py
	dosym /usr/share/${PN}/backdoor.py /usr/bin/${PN}
}