from optparse import OptionParser

class PayloadInjector:
    def logo(self=None):
        return """
  _________            .__    .___.___            __               __           ____    _______   
 /   _____/ ________ __|__| __| _/|   | ____     |__| ____   _____/  |_  ___  _/_   |   \   _  \  
 \_____  \ / ____/  |  \  |/ __ | |   |/    \    |  |/ __ \_/ ___\   __\ \  \/ /|   |   /  /_\  \ 
 /        < <_|  |  |  /  / /_/ | |   |   |  \   |  \  ___/\  \___|  |    \   / |   |   \  \_/   \\
/_______  /\__   |____/|__\____ | |___|___|  /\__|  |\___  >\___  >__|     \_/  |___| /\ \_____  /
        \/    |__|             \/          \/\______|    \/     \/                    \/       \/ 
File Payload Injector by DrSquid"""
    def __init__(self, injectfile, payloadfile):
        print(self.logo())
        self.payloadfile = payloadfile
        self.injectfile = injectfile
    def obtain_payload(self):
        file = open(self.payloadfile,"r")
        payload = file.read()
        file.close()
        return payload
    def inject(self):
        self.payload = self.obtain_payload()
        self.inject_file_open = open(self.injectfile,"r")
        self.injectfile_content = self.inject_file_open.read()
        self.inject_file_open.close()
        self.new_inject_file = open(self.injectfile,"w")
        self.new_inject_file.write(self.payload+"\n")
        self.new_inject_file.write(self.injectfile_content)
        self.new_inject_file.close()
        print(f"[+] Payload from file '{self.payloadfile}' has been injected into file '{self.injectfile}'.")
class OptionParse:
    def __init__(self):
        self.parse_args()
    def usage(self):
        print(PayloadInjector.logo())
        print("""
[+] Option-Parsing Information:
[+] --pL, --payload   - Specify the payload file.
[+] --iF, --inject    - Specify the file being injected.
[+] Note: These parameters are required.""")
    def parse_args(self):
        opt = OptionParser()
        opt.add_option("--pL","--payload", dest="payload")
        opt.add_option("--iF","--inject",dest="inject")
        arg, opts = opt.parse_args()
        if arg.payload is None or arg.inject is None:
            self.usage()
        else:
            payloadfile = arg.payload
            injectfile = arg.inject
            payloadinject = PayloadInjector(injectfile, payloadfile)
            payloadinject.inject()
optionparse = OptionParse()