├── .github
└── ISSUE_TEMPLATE
│ └── bug_report.md
├── LICENSE
├── README.md
├── pom.xml
├── src
└── main
│ └── java
│ ├── apc
│ ├── AndroidProjectCreator.java
│ ├── ArgumentManager.java
│ ├── ArgumentParser.java
│ ├── FileManager.java
│ └── RepositoryManager.java
│ ├── command
│ ├── Assembler.java
│ ├── CompactInstaller.java
│ ├── Decompiler.java
│ ├── Installer.java
│ └── Updater.java
│ ├── enumeration
│ ├── Action.java
│ └── DecompilerType.java
│ ├── library
│ ├── Constants.java
│ ├── ProjectInfos.java
│ ├── Repositories.java
│ └── Tools.java
│ └── model
│ ├── ArgumentPackage.java
│ ├── Command.java
│ ├── ProjectInfo.java
│ ├── Repository.java
│ └── Tool.java
└── target
└── AndroidProjectCreator-1.5.2-stable-jar-with-dependencies.jar
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Describe the bug**
11 | A clear and concise description of what the bug is.
12 |
13 | **To Reproduce**
14 | Steps to reproduce the behavior:
15 | 1. Go to '...'
16 | 2. Click on '....'
17 | 3. Scroll down to '....'
18 | 4. See error
19 |
20 | **Expected behavior**
21 | A clear and concise description of what you expected to happen.
22 |
23 | **Screenshots**
24 | If applicable, add screenshots to help explain your problem.
25 |
26 | **Desktop (please complete the following information):**
27 | - OS: [e.g. iOS]
28 | - Browser [e.g. chrome, safari]
29 | - Version [e.g. 22]
30 | - Java version
31 |
32 | **Additional context**
33 | Add any other context about the problem here.
34 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AndroidProjectCreator
2 | Convert an APK to an Android Studio Project using multiple open-source tools. Tools that are unavailable are mirrored using repositories on my own Github account (copyright remains with the original creators, those repositories only serve as a mirror).
3 |
4 | For more information, refer to [this](https://maxkersten.nl/projects/androidprojectcreator/) page on my website. If you've got any questions, please contact me on Twitter [@Libranalysis](https://twitter.com/Libranalysis)!
5 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 | libra
5 | AndroidProjectCreator
6 | 1.5.2-stable
7 | jar
8 |
9 | UTF-8
10 | 1.8
11 | 1.8
12 |
13 |
14 |
15 | central
16 | Central Repository
17 | https://repo.maven.apache.org/maven2
18 | default
19 |
20 | false
21 |
22 |
23 | never
24 |
25 |
26 |
27 |
28 |
29 | central
30 | Central Repository
31 | https://repo.maven.apache.org/maven2
32 | default
33 |
34 | false
35 |
36 |
37 |
38 |
39 |
40 | org.eclipse.jgit
41 | org.eclipse.jgit
42 | 5.1.1.201809181055-r
43 | jar
44 |
45 |
46 | net.lingala.zip4j
47 | zip4j
48 | 1.3.3
49 |
50 |
51 | org.apache.logging.log4j
52 | log4j-api
53 | 2.17.1
54 |
55 |
56 | org.apache.logging.log4j
57 | log4j-core
58 | 2.17.1
59 |
60 |
61 | org.apache.logging.log4j
62 | log4j-slf4j-impl
63 | 2.16.0
64 |
65 |
66 |
67 |
68 |
69 | maven-assembly-plugin
70 |
71 |
72 |
73 | apc.AndroidProjectCreator
74 |
75 |
76 |
77 | jar-with-dependencies
78 |
79 |
80 |
81 |
82 |
83 |
84 |
--------------------------------------------------------------------------------
/src/main/java/apc/AndroidProjectCreator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Max 'Libra' Kersten
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 | package apc;
18 |
19 | import enumeration.Action;
20 | import enumeration.DecompilerType;
21 | import java.io.File;
22 | import library.Constants;
23 | import model.ArgumentPackage;
24 |
25 | /**
26 | * This class serves as a front for a possible GUI. The 'ArgumentManager' class
27 | * contains all functions.
28 | *
29 | * @author Max 'Libra' Kersten
30 | */
31 | public class AndroidProjectCreator {
32 |
33 | /**
34 | * @param args the command line arguments
35 | */
36 | public static void main(String[] args) {
37 | /**
38 | * Build this project with: mvn clean compile assembly:single
39 | *
40 | * Ubuntu 18.04 settings (make sure JAVA_HOME is set to the JDK): sudo
41 | * apt-get install openjdk-8-jre openjdk-8-jdk maven
42 | *
43 | * Windows: Install Java 8 JRE, Java 8 JDK Maven and set the JAVA_HOME
44 | * system environment variable to the JDK
45 | *
46 | * MacOS: install Java 8 JRE, Java 8 JDK and use brew to install maven
47 | */
48 | boolean debugging = false;
49 | if (debugging) {
50 | installTest();
51 | //updateTest();
52 | //decompileTest(DecompilerType.FERNFLOWER);
53 | System.exit(0);
54 | }
55 |
56 | //Instantiate the ArgumentParser for later use
57 | ArgumentParser argumentParser = new ArgumentParser();
58 | //Instantiate the ArgumentManager for later use
59 | ArgumentManager argumentManager = new ArgumentManager();
60 | //Show the version information
61 | argumentManager.showVersion();
62 | //Set the action, if there is an error, the Action.ERROR value is provided. This is all handled within the setArguments function
63 | ArgumentPackage argumentPackage = argumentParser.setArguments(args);
64 | //If incorrect or unknown parameters are provided, APC provides feedback to the user and then terminates.
65 | if (argumentPackage.getAction() == Action.ERROR) {
66 | handleAction(argumentManager, args);
67 | }
68 | //Executes the action based on the return value of the setArguments function
69 | argumentManager.execute(argumentPackage);
70 | }
71 |
72 | /**
73 | * A method which is used during debugging to avoid mistakes in the code
74 | */
75 | private static void installTest() {
76 | ArgumentManager manager = new ArgumentManager();
77 | manager.showVersion();
78 | String[] args = new String[1];
79 | args[0] = "-install";
80 | ArgumentParser argumentParser = new ArgumentParser();
81 | ArgumentPackage argumentPackage = argumentParser.setArguments(args);
82 | manager.execute(argumentPackage);
83 | }
84 |
85 | /**
86 | * A method which is used during debugging to avoid mistakes in the code
87 | */
88 | private static void updateTest() {
89 | ArgumentManager manager = new ArgumentManager();
90 | manager.showVersion();
91 | String[] args = new String[1];
92 | args[0] = "-update";
93 | ArgumentParser argumentParser = new ArgumentParser();
94 | ArgumentPackage argumentPackage = argumentParser.setArguments(args);
95 | manager.execute(argumentPackage);
96 | }
97 |
98 | /**
99 | * A method which is used during debugging to avoid mistakes in the code
100 | *
101 | * @param decompiler the decompiler that should be used
102 | */
103 | private static void decompileTest(DecompilerType decompiler) {
104 | ArgumentManager manager = new ArgumentManager();
105 | manager.showVersion();
106 | String[] args;
107 | if (decompiler == DecompilerType.JEB3) {
108 | args = new String[5];
109 | } else {
110 | args = new String[4];
111 | }
112 | args[0] = "-decompile";
113 | args[1] = decompiler.toString().toLowerCase();
114 | //Mac is excluded from the tests
115 | if (Constants.isLinux()) {
116 | args[2] = "/home/libra/Documents/apc-test/apk/challenge1_release.apk";
117 | } else if (Constants.isWindows()) {
118 | args[2] = "C:\\Users\\Libra\\Downloads\\ap k.apk";
119 | }
120 | args[3] = "./test-output-guid-" + java.util.UUID.randomUUID();
121 | if (decompiler == DecompilerType.JEB3) {
122 | args[4] = "/home/libra/Downloads/jeb-pro";
123 | }
124 | ArgumentParser argumentParser = new ArgumentParser();
125 | ArgumentPackage argumentPackage = argumentParser.setArguments(args);
126 | manager.execute(argumentPackage);
127 | }
128 |
129 | //TODO refactor this method into the argument parser
130 | private static void handleAction(ArgumentManager manager, String[] args) {
131 | //If no arguments are given, the general usage information should be given
132 | if (args.length == 0 || args.length == 1) {
133 | manager.showUsage();
134 | System.exit(1);
135 | } else if (args.length > 4) {
136 | //Since there is no option to support more than four arguments, this should be fixed first
137 | System.out.println("\tAndroidProjectCreator does not support more than four arguments!");
138 | } else {
139 | //Obtain the provided arguments in a String-object for later use
140 | String arguments = "";
141 | //Concatenate the arguments behind one another
142 | for (int i = 0; i < args.length; i++) {
143 | arguments += args[i] + " ";
144 | }
145 | //Notify the user of the error
146 | System.out.println("[+]The provided input has not been recognised by AndroidProjectCreator, the provided arguments are given below.\n");
147 | //Display the received arguments back to the user
148 | System.out.println("\t" + arguments + "\n");
149 | //Loop through all of the arguments to display additional information
150 | for (int i = 0; i < args.length; i++) {
151 | switch (i) {
152 | case 0:
153 | //The first argument, in any case, is the requested method
154 | System.out.println("\tThe requested method is:\t\t" + args[0]);
155 | System.out.println("");
156 | /**
157 | * If this point is reached, either the "-decompile"
158 | * method is called (since it requires more arguments
159 | * than 1) or a non-existing method is called
160 | *
161 | */
162 | if (args[0].equalsIgnoreCase("-decompile")) {
163 | System.out.println("\tThe embedded decompilers that are included are:");
164 | for (DecompilerType decompilerType : DecompilerType.values()) {
165 | if (decompilerType.toString().equalsIgnoreCase("apktool") || decompilerType.toString().equalsIgnoreCase("dex2jar")) {
166 | continue;
167 | }
168 | System.out.println("\t\t" + decompilerType);
169 | }
170 | } else {
171 | System.out.println("\tThe available methods are:");
172 | for (Action method : Action.values()) {
173 | if (method.toString().equalsIgnoreCase("error")) {
174 | System.out.println("\t\t-HELP");
175 | continue;
176 | }
177 | System.out.println("\t\t-" + method);
178 | }
179 | }
180 | break;
181 | case 1:
182 | //If the decompile method is requested, the second argument is the requested decompiler
183 | if (args[0].equalsIgnoreCase("-decompile")) {
184 | System.out.println("\tThe requested decompiler is:\t\t" + args[1]);
185 | } else {
186 | //Notify the user that too many arguments are passed
187 | System.out.println("\tOnly the \"-DECOMPILE\" option supports more than one argument!");
188 | }
189 | break;
190 | case 2:
191 | //If decompilation was chosen, the location of the APK file should also be provided
192 | if (args[0].equalsIgnoreCase("-decompile")) {
193 | //The location itself is shown
194 | System.out.println("\tThe provided APK location is:\t\t" + args[2]);
195 | File apk = new File(args[2]);
196 | //At first, a check is done to see if the APK file actually exists, if this isn't the case, the user is notified
197 | if (!apk.exists()) {
198 | System.out.println("\t\tThe APK file does not exist!");
199 | } else if (apk.exists() && apk.isFile()) { //If the file exists and is a file, the user is provided this information
200 | System.out.println("\t\tThe APK file exists and is a file!");
201 | } else if (apk.exists() && apk.isDirectory()) { //If the file is actually an existing folder, the user should know
202 | System.out.println("\t\tThe APK file is not a file, but a folder!");
203 | }
204 | }
205 | break;
206 | default:
207 | //The last argument of the decompilation method is the output location, this cannot be checked as it is made at the end of the decompilation process
208 | break;
209 | }
210 | }
211 | //Close APC with the 'unsuccessful' message, hence the '1' as parameter, instead of 0
212 | System.exit(1);
213 | }
214 | }
215 | }
216 |
--------------------------------------------------------------------------------
/src/main/java/apc/ArgumentManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Max 'Libra' Kersten
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 | package apc;
18 |
19 | import command.Assembler;
20 | import command.CompactInstaller;
21 | import command.Installer;
22 | import command.Decompiler;
23 | import command.Updater;
24 | import enumeration.DecompilerType;
25 | import java.io.File;
26 | import java.io.IOException;
27 | import library.Constants;
28 | import model.ArgumentPackage;
29 |
30 | /**
31 | * Handles everything regarding the flow of the AndroidProjectCreator, based on
32 | * the input provided by the user. The main function of this class is to
33 | * delegate functionality to one of the classes in the "command" package. All
34 | * exceptions (with a couple of exceptions which have their own documentation)
35 | * are handled in the passArguments
function.
36 | *
37 | * @author Max 'Libra' Kersten
38 | */
39 | public class ArgumentManager {
40 |
41 | /**
42 | * The action, as defined by the setArguments
function, will be
43 | * executed.
44 | *
45 | * @param arguments the provided arguments
46 | */
47 | public void execute(ArgumentPackage arguments) {
48 | try {
49 | /**
50 | * Since there was no error, the remaining options for the enum are
51 | * handled below. Exceptions that occur during the actions that are
52 | * defined within the enum, are caught in a single try-catch
53 | * structure to aggregate all exceptions at one place. This improves
54 | * the exception handling usability and maintainability and provides
55 | * more information to the user.
56 | */
57 | switch (arguments.getAction()) {
58 | case INSTALL:
59 | /**
60 | * Clone the repositories, build the projects and save them
61 | * in the Constants.LIBRARY_FOLDER_NAME folder
62 | */
63 | Installer installer = new Installer();
64 | installer.install();
65 | //Usage is shown after the installation has successfully been completed
66 | showUsage();
67 | break;
68 | case COMPACT_INSTALL:
69 | /**
70 | * Clones all tools into the library folder from a Github
71 | * repository that is occasionally updated. All tools on
72 | * that repository are precompiled, meaning one only has to
73 | * download the files, resulting in a compacter installation
74 | * in both disk space and time.
75 | */
76 | CompactInstaller compactInstaller = new CompactInstaller();
77 | compactInstaller.install();
78 | break;
79 | case UPDATE:
80 | /**
81 | * Updating the library is done by pulling the repository
82 | * from the selected branch, rebuilding the tool and
83 | * replacing it in the correct library folder.
84 | */
85 | Updater updater = new Updater();
86 | updater.update();
87 | break;
88 | case DECOMPILE:
89 | //Decompile the APK into the parts required for the assembler
90 | Decompiler decompiler = new Decompiler(arguments);
91 | decompiler.decompile();
92 | //Assemble the taken manifest and source files together with the Android Studio project
93 | Assembler assembler = new Assembler(arguments.getOutputLocation());
94 | assembler.assemble();
95 | break;
96 | default:
97 | //Something went wrong since this case shouldnt be reachable, show the usage and exit
98 | showUsage();
99 | System.exit(1);
100 | break;
101 | }
102 | } catch (Exception ex) {
103 | cleanOnError(arguments.getOutputLocation());
104 | showError(ex);
105 | System.exit(1);
106 | }
107 | }
108 |
109 | /**
110 | * If an error occurs, the output location and the temp folder within the
111 | * library need to be cleaned. This method does exactly that.
112 | */
113 | private void cleanOnError(File outputLocation) {
114 | try {
115 | FileManager fileManager = new FileManager();
116 | //If something goes wrong during the installation or update, the outputLocation variable is equal to null
117 | if (outputLocation != null) {
118 | fileManager.delete(outputLocation);
119 | }
120 | fileManager.delete(new File(Constants.TEMP_LIBRARY_FOLDER));
121 | } catch (IOException ex) {
122 | System.out.println("[+]Something went wrong during the removal of " + outputLocation.getAbsolutePath());
123 | }
124 | }
125 |
126 | /**
127 | * Shows the usage information to the user
128 | */
129 | public void showUsage() {
130 | StringBuilder usage = new StringBuilder();
131 | usage.append("[+]AndroidProjectCreator has multiple modes, all of which are explained below, together with the required parameters.\n");
132 | usage.append("\t-install\n");
133 | usage.append("\t\tThis option requires an internet connection as it clones multiple repositories from Git.\n");
134 | usage.append("\t\tAfter the repositories have been downloaded, the projects will be compiled. \n");
135 | usage.append("\t\tThen, the compiled repositories are saved in a folder named \"Library\" in the folder where the JAR resides.\n");
136 | usage.append("\t\tThe repositories are then deleted from the disk.\n");
137 | usage.append("\t\tCurrently, the following tools are embedded:\n");
138 | for (DecompilerType decompilerType : DecompilerType.values()) {
139 | usage.append("\t\t\t" + decompilerType + "\n");
140 | }
141 | usage.append("\t-compactInstall\n");
142 | usage.append("\t\tDownloads precompiled instances of the tools that are listed at \"-install\" from a repository that is mainted by me.\n");
143 | usage.append("\t\tThis is faster than installing it yourself, but the the \"-update\" will not work. Tools will also be a bit older.\n");
144 | usage.append("\t-update\n");
145 | usage.append("\t\tUpdating the library folder is equal to reinstalling the library using the -install function.\n");
146 | usage.append("\t-decompile\n");
147 | usage.append("\t\tUsing this function, more parameters are required.\n");
148 | usage.append("\t\tThe name of the decompiler needs to be specified, using one of the following embedded decompilers:\n");
149 | usage.append("\t\t\tCFR, FERNFLOWER, JADX, JDCMD, JEB3 and PROCYON\n");
150 | usage.append("\t\tAdditionally, the location of the APK and the output location for the Android Project are required.\n");
151 | usage.append("\t\tSample usage to decompile an APK:\n");
152 | if (Constants.isWindows()) {
153 | usage.append("\t\t\t java -jar AndroidProjectCreator.jar -decompile FERNFLOWER path\\to\\the.apk output\\path\n");
154 | } else {
155 | usage.append("\t\t\tjava -jar ./AndroidProjectCreator.jar -decompile FERNFLOWER /path/to/the.apk /output/path/\n");
156 | }
157 | usage.append("\t\tNote that one should provide the path to the JEB3 folder as a fifth argument if JEB3 is chosen to decompile the code.\n ");
158 | System.out.println(usage.toString());
159 | }
160 |
161 | /**
162 | * Displays the given error message with an introduction
163 | */
164 | private void showError(Exception ex) {
165 | System.out.println("\n\n[+]An error has occurred, therefore AndroidProjectCreator has shut down. The error message is given below.");
166 | System.out.println("");
167 | System.out.println(ex.getMessage());
168 | System.out.println("");
169 | System.out.println("[+]For additional details, see the stack traces of the used tools above.");
170 | }
171 |
172 | /**
173 | * Display the version information
174 | */
175 | public void showVersion() {
176 | String versionNumber = "1.5.2-stable";
177 | StringBuilder version = new StringBuilder();
178 | version.append("[+]AndroidProjectCreator " + versionNumber + " [developed by Max 'Libra' Kersten or @Libranalysis on Twitter]\n");
179 | System.out.println(version.toString());
180 | }
181 | }
182 |
--------------------------------------------------------------------------------
/src/main/java/apc/ArgumentParser.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Max 'Libra' Kersten
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 | package apc;
18 |
19 | import enumeration.Action;
20 | import enumeration.DecompilerType;
21 | import java.io.File;
22 | import java.nio.file.Paths;
23 | import model.ArgumentPackage;
24 |
25 | /**
26 | * This class handles the parsing of the received arguments via the CLI
27 | *
28 | * @author Max 'Libra' Kersten
29 | */
30 | public class ArgumentParser {
31 |
32 | /**
33 | * Extracts the arguments from the provided String array and saves them into
34 | * their respective fields in this class
35 | *
36 | * CLI usage:
37 | * java -jar AndroidProjectCreator.jar -decompile [name] /path/to/app.apk /path/to/output/to
38 | *
39 | * In case JEB3 is used, the JEB3 folder should be given as a fifth
40 | * argument, as can be seen in the example below: *
41 | * java -jar AndroidProjectCreator.jar -decompile [name] /path/to/app.apk /path/to/output/to /path/to/jeb/folder
42 | *
43 | * Possible decompilers: JDCmd (uses JD-Core, also used in JD-GUI), JADX,
44 | * Fernflower, CFR, ProCyon and JEB3
45 | *
46 | * @param args the string array containing the user defined input
47 | * @return if all variables were set, the requested action is returned as an
48 | * enum value. If one or more variables were not set successfully, the
49 | * enum's value equals Action.ERROR.
50 | */
51 | public ArgumentPackage setArguments(String[] args) {
52 | //Check if the amount of provided arguments equals one, which is also equal to the installation command. Note that both strings are converted to a lowercase variant.
53 | if (args.length == 1 && "-install".toLowerCase().equals(args[0].toLowerCase())) {
54 | return new ArgumentPackage(Action.INSTALL);
55 | //Check if the update command is provided (if it is not the installation command).
56 | } else if (args.length == 1 && "-update".toLowerCase().equals(args[0].toLowerCase())) {
57 | return new ArgumentPackage(Action.UPDATE);
58 | //Check if the amount of arguments equals 4 or 5, of which the first equals to the decompile command.
59 | } else if ((args.length == 4 || args.length == 5) && "-decompile".toLowerCase().equals(args[0].toLowerCase())) {
60 | return parseDecompile(args);
61 | //Check if the compact install argument is provided
62 | } else if (args.length == 1 && "-compactInstall".toLowerCase().equals(args[0].toLowerCase())) {
63 | return new ArgumentPackage(Action.COMPACT_INSTALL);
64 | }
65 | //Return error if something went wrong
66 | return new ArgumentPackage(Action.ERROR);
67 | }
68 |
69 | /**
70 | * Obtain an argument package to decompile a given APK with a given
71 | * decompiler. If JEB3 isn't chosen as the decompiler, requesting the JEB3
72 | * folder from the package will return null.
73 | *
74 | * @param args the arguments that the user provided
75 | * @return the argument package which contains all required information for
76 | * the argument manager
77 | */
78 | private ArgumentPackage parseDecompile(String[] args) {
79 | DecompilerType decompilerType;
80 | File apk;
81 | File outputLocation;
82 | File jeb3Folder;
83 | ArgumentPackage argumentPackage;
84 | //Set the decompiler type
85 | String decompilerString = args[1];
86 | if (decompilerString.equalsIgnoreCase(DecompilerType.FERNFLOWER.toString())) {
87 | decompilerType = DecompilerType.FERNFLOWER;
88 | } else if (decompilerString.equalsIgnoreCase(DecompilerType.JADX.toString())) {
89 | decompilerType = DecompilerType.JADX;
90 | } else if (decompilerString.equalsIgnoreCase(DecompilerType.JDCMD.toString())) {
91 | decompilerType = DecompilerType.JDCMD;
92 | } else if (decompilerString.equalsIgnoreCase(DecompilerType.CFR.toString())) {
93 | decompilerType = DecompilerType.CFR;
94 | } else if (decompilerString.equalsIgnoreCase(DecompilerType.PROCYON.toString())) {
95 | decompilerType = DecompilerType.PROCYON;
96 | } else if (decompilerString.equalsIgnoreCase(DecompilerType.JEB3.toString())) {
97 | decompilerType = DecompilerType.JEB3;
98 | } else {
99 | return new ArgumentPackage(Action.ERROR);
100 | }
101 | //Sets the path to the APK
102 | apk = Paths.get(args[2]).toFile();
103 | //Sanity checks on the APK
104 | if (!apk.exists() || apk.isDirectory()) {
105 | return new ArgumentPackage(Action.ERROR);
106 | }
107 | //Set the location where the output should be written to
108 | outputLocation = Paths.get(args[3]).toFile();
109 | //Make sure the output location exists completely, thus all parent folders are also created if need be
110 | if (!outputLocation.exists()) {
111 | outputLocation.mkdirs();
112 | }
113 | //Detect if JEB is used
114 | if (args.length == 4) {
115 | argumentPackage = new ArgumentPackage(decompilerType, apk, outputLocation);
116 | return argumentPackage;
117 | } else if (args.length == 5) {
118 | jeb3Folder = Paths.get(args[4]).toFile();
119 | //Check if the JEB folder exists and is a directory (instead of a file)
120 | if (jeb3Folder.exists() && jeb3Folder.isDirectory()) {
121 | argumentPackage = new ArgumentPackage(apk, outputLocation, jeb3Folder);
122 | return argumentPackage;
123 | }
124 | }
125 | //In case this code is reached, something went wrong and thus the error package is returned
126 | return new ArgumentPackage(Action.ERROR);
127 | }
128 | }
129 |
--------------------------------------------------------------------------------
/src/main/java/apc/FileManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Max 'Libra' Kersten
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 | package apc;
18 |
19 | import java.io.File;
20 | import java.io.IOException;
21 | import java.nio.file.Files;
22 | import java.nio.file.Paths;
23 | import net.lingala.zip4j.core.ZipFile;
24 | import net.lingala.zip4j.exception.ZipException;
25 |
26 | /**
27 | * Contains all functions which handle files, such as removing and copying files
28 | *
29 | * @author Max 'Libra' Kersten
30 | */
31 | public class FileManager {
32 |
33 | /**
34 | * Works on both ZIP and APK archives
35 | *
36 | * @param source ZIP or APK file location
37 | * @param destination place to extract all files to
38 | * @throws ZipException if the file is not a ZIP archive
39 | * @throws IOException if the source file cannot be found
40 | */
41 | public void extractArchive(String source, String destination) throws ZipException, IOException {
42 | //Checke if the source folder exists
43 | if (!new File(source).exists()) {
44 | throw new IOException("The source file does not exist");
45 | }
46 | try {
47 | ZipFile zipFile = new ZipFile(source);
48 | zipFile.extractAll(destination);
49 | } catch (ZipException e) {
50 | //A message is already provided
51 | throw new ZipException(e.getMessage());
52 | }
53 | }
54 |
55 | /**
56 | * Deletes a folder, including all sub directories.
57 | *
58 | * Code taken from Erickson (from
59 | * "https://stackoverflow.com/questions/779519/delete-directories-recursively-in-java").
60 | * Code altered by Max 'Libra' Kersten.
61 | *
62 | * @param file the file to delete
63 | * @throws IOException the exception when a file could not be deleted
64 | */
65 | public void delete(File file) throws IOException {
66 | //Check if the file does not exist
67 | if (!file.exists()) {
68 | //The file that should be deleted, does not exist
69 | return;
70 | }
71 | if (file.isDirectory()) {
72 | for (File currentFile : file.listFiles()) {
73 | delete(currentFile);
74 | }
75 | }
76 | try {
77 | Files.delete(Paths.get(file.getAbsolutePath()));
78 | } catch (Exception e) {
79 | throw new IOException("Failed to delete file: " + file);
80 | }
81 | }
82 |
83 | /**
84 | * Removes all files and subfolders from the provided folder, excluding the
85 | * ".git" folder.
86 | *
87 | * Code taken from Erickson (from
88 | * "https://stackoverflow.com/questions/779519/delete-directories-recursively-in-java").
89 | * Code altered by Max 'Libra' Kersten.
90 | *
91 | * @param folder the folder to remove files from
92 | * @throws IOException if an error occurs upon deleting the file
93 | */
94 | public void emptyFolder(File folder) throws IOException {
95 | //Check if the file does not exist
96 | if (!folder.exists()) {
97 | //A newly created folder is also an empty folder
98 | folder.mkdirs();
99 | return;
100 | }
101 |
102 | if (folder.isDirectory()) {
103 | for (File currentFile : folder.listFiles()) {
104 | //Exclude the .git folder to avoid errors on Windows
105 | if (!currentFile.getName().endsWith(".git")) {
106 | delete(currentFile);
107 | }
108 | }
109 | }
110 | }
111 |
112 | /**
113 | * Copies a folder (including all the sub folders) to the given destination.
114 | *
115 | * Originally taken from pwipo
116 | * (https://stackoverflow.com/questions/29076439/java-8-copy-directory-recursively/34254130)
117 | *
118 | * @param src the file to be copied
119 | * @param dest the place to copy the src
file to
120 | * @throws IOException if the destination is not a folder or if the copying
121 | * of the files failed
122 | */
123 | public void copyFolder(File src, File dest) throws IOException {
124 | if (src == null || dest == null) {
125 | return;
126 | }
127 | if (!src.isDirectory()) {
128 | return;
129 | }
130 | if (dest.exists()) {
131 | if (!dest.isDirectory()) {
132 | throw new IOException("The destination is not a folder: " + dest.getAbsolutePath());
133 | }
134 | } else {
135 | dest.mkdirs();
136 | }
137 |
138 | if (src.listFiles() == null || src.listFiles().length == 0) {
139 | return;
140 | }
141 |
142 | for (File file : src.listFiles()) {
143 | File fileDest = new File(dest, file.getName());
144 | if (file.isDirectory()) {
145 | copyFolder(file, fileDest);
146 | } else {
147 | if (fileDest.exists()) {
148 | continue;
149 | }
150 | try {
151 | Files.copy(file.toPath(), fileDest.toPath());
152 | } catch (IOException ex) {
153 | throw new IOException("Something went wrong when trying to copy the file \"" + file.getAbsolutePath() + "\"! It might not exist or you might not have the correct permissions to write a file to the destination (\"" + fileDest.getAbsolutePath() + "\").");
154 | }
155 | }
156 | }
157 | }
158 | }
159 |
--------------------------------------------------------------------------------
/src/main/java/apc/RepositoryManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Max 'Libra' Kersten
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 | package apc;
18 |
19 | import enumeration.DecompilerType;
20 | import java.io.File;
21 | import java.io.IOException;
22 | import java.util.ArrayList;
23 | import java.util.List;
24 | import library.Constants;
25 | import model.Repository;
26 | import model.Tool;
27 | import net.lingala.zip4j.exception.ZipException;
28 |
29 | /**
30 | * Handles everything regarding repositories, such as cloning and updating
31 | *
32 | * @author Max 'Libra' Kersten
33 | */
34 | public class RepositoryManager {
35 |
36 | /**
37 | * The file manager that is used within this class
38 | */
39 | private FileManager fileManager;
40 |
41 | /**
42 | * This class handles everything regarding repositories, such as cloning and
43 | * updating
44 | */
45 | public RepositoryManager() {
46 | fileManager = new FileManager();
47 | }
48 |
49 | /**
50 | * Removes the repository directory (as specified by the constant
51 | * Constants.REPOSITORY_FOLDER
)
52 | *
53 | * @throws IOException when the repository cannot be removed
54 | */
55 | public void removeRepositoryFolder() throws IOException {
56 | File reposDirectory = new File(Constants.REPOSITORY_FOLDER);
57 | if (reposDirectory.exists() && reposDirectory.isDirectory()) {
58 | fileManager.delete(reposDirectory);
59 | }
60 | }
61 |
62 | /**
63 | * Clones all repositories that are provided
64 | *
65 | * @param repositoryList the repositories to be cloned
66 | *
67 | * @throws IOException if the cloning of a repository fails
68 | */
69 | public void cloneRepositories(List repositoryList) throws IOException {
70 | for (Repository repository : repositoryList) {
71 | System.out.println("[+]Started cloning " + repository.getName());
72 | repository.cloneRepository();
73 | System.out.println("[+]Finished cloning " + repository.getName());
74 | }
75 | }
76 |
77 | /**
78 | * Updates all repositories that are given using.
79 | *
80 | * @param repositoryList the repositories to be updated
81 | * @throws IOException if an IO operation returns an error
82 | */
83 | public void updateRepositories(List repositoryList) throws IOException {
84 | for (Repository repository : repositoryList) {
85 | System.out.println("[+]Started updating " + repository.getName());
86 | repository.updateRepository();
87 | System.out.println("[+]Succesfully updated " + repository.getName());
88 | }
89 | }
90 |
91 | /**
92 | * Builds each project that is provided
93 | *
94 | * @param tools the tools to be build
95 | * @throws IOException if the building process went wrong
96 | * @throws InterruptedException if the thread was somehow interrupted
97 | */
98 | public void buildRepositories(List tools) throws IOException, InterruptedException {
99 | for (Tool tool : tools) {
100 | try {
101 | if (tool.getRepository().getName().equalsIgnoreCase("androidproject")
102 | || tool.getRepository().getName().equalsIgnoreCase(DecompilerType.PROCYON.toString())
103 | || tool.getRepository().getName().equalsIgnoreCase(DecompilerType.JEB3.toString())
104 | || tool.getRepository().getName().equalsIgnoreCase(DecompilerType.JDCMD.toString())) {
105 | continue;
106 | }
107 | System.out.println("[+]Starting to build " + tool.getRepository().getName());
108 | tool.getProjectInfo().getBuildCommand().execute();
109 | System.out.println("[+]Finished building " + tool.getRepository().getName());
110 | } catch (IOException ex) {
111 | throw new IOException("Something went wrong when building " + tool.getRepository().getName());
112 | }
113 | }
114 | }
115 |
116 | /**
117 | * Empty the folders of each repository before the content is placed in it.
118 | * This is required during the update process
119 | *
120 | * @param tools the tools which will be emptied
121 | * @throws IOException is an IO error occurs
122 | */
123 | public void emptyLibraryFolders(List tools) throws IOException {
124 | for (Tool tool : tools) {
125 | fileManager.emptyFolder(new File(Constants.LIBRARY_FOLDER + "/" + tool.getRepository().getName()));
126 | }
127 | }
128 |
129 | /**
130 | * Extracts the output of the builds to the library (as is defined in
131 | * Constants.getLibraryFolderName()
132 | *
133 | * @param tools the tools to be extracted
134 | */
135 | public void extractBuilds(List tools) {
136 | for (Tool tool : tools) {
137 | try {
138 | /**
139 | * Since the Android Studio Project repository, CFR mirror,
140 | * Procyon mirror and JEB3 CLI Android Decompiler script only
141 | * consist of a single file, it does not need to be extracted.
142 | */
143 | if (tool.getRepository().getName().equalsIgnoreCase("androidproject")) {
144 | fileManager.copyFolder(new File(Constants.ANDROIDPROJECT_REPOSITORY_FOLDER), new File(Constants.ANDROIDPROJECT_LIBRARY_FOLDER));
145 | continue;
146 | } else if (tool.getRepository().getName().equalsIgnoreCase(DecompilerType.CFR.toString())) {
147 | fileManager.copyFolder(tool.getProjectInfo().getBuildOutputFolder(), new File(Constants.CFR_LIBRARY_FOLDER));
148 | continue;
149 | } else if (tool.getRepository().getName().equalsIgnoreCase(DecompilerType.PROCYON.toString())) {
150 | fileManager.copyFolder(new File(Constants.PROCYON_REPOSITORY_FOLDER), new File(Constants.PROCYON_LIBRARY_FOLDER));
151 | continue;
152 | } else if (tool.getRepository().getName().equalsIgnoreCase(DecompilerType.JEB3.toString())) {
153 | fileManager.copyFolder(new File(Constants.JEB3_CLI_ANDROID_SCRIPT_REPOSITORY_FOLDER), new File(Constants.JEB3_CLI_ANDROID_SCRIPT_LIBRARY_FOLDER));
154 | continue;
155 | } else if (tool.getRepository().getName().equalsIgnoreCase(DecompilerType.JDCMD.toString())) {
156 | fileManager.copyFolder(new File(Constants.JDCMD_REPOSITORY_FOLDER), new File(Constants.JDCMD_LIBRARY_FOLDER));
157 | continue;
158 | }
159 | System.out.println("[+]Extracting " + tool.getRepository().getName());
160 | File buildOutputFolder = tool.getProjectInfo().getBuildOutputFolder();
161 | String partialArchiveName = tool.getProjectInfo().getPartialOutputName();
162 | //Loop through the output directory of the build
163 | for (File currentFile : buildOutputFolder.listFiles()) {
164 | //If this file contains the partial name, then it is treated as being the build output
165 | if (currentFile.getName().toLowerCase().contains(partialArchiveName.toLowerCase()) && partialArchiveName.toLowerCase().endsWith(".zip")) {
166 | File outputLocation = new File(buildOutputFolder.getAbsolutePath() + "/" + Constants.BUILD_OUTPUT);
167 | System.out.println("[+]Extracting to " + outputLocation.getAbsolutePath());
168 | outputLocation.mkdir();
169 | fileManager.extractArchive(currentFile.getAbsolutePath(), outputLocation.getAbsolutePath());
170 | //Copy extracted files to the lib folder, where only the builds reside
171 | if (tool.getRepository().getName().equalsIgnoreCase(DecompilerType.DEX2JAR.toString())) {
172 | fileManager.copyFolder(outputLocation.listFiles()[0], new File(Constants.DEX2JAR_LIBRARY_FOLDER));
173 | } else {
174 | fileManager.copyFolder(outputLocation, new File(Constants.LIBRARY_FOLDER + "/" + tool.getRepository().getName()));;
175 | }
176 | } else if (currentFile.getName().toLowerCase().contains(partialArchiveName.toLowerCase()) && partialArchiveName.toLowerCase().endsWith(".jar")) {
177 | fileManager.copyFolder(buildOutputFolder, new File(Constants.LIBRARY_FOLDER + "/" + tool.getRepository().getName()));
178 | }
179 | }
180 | System.out.println("[+]Finished extracting " + tool.getRepository().getName());
181 |
182 | } catch (IOException | ZipException ex) {
183 | System.err.println("Something went wrong during the extraction of the build of " + tool.getRepository().getName() + ":\n" + ex.getMessage());
184 | ex.printStackTrace();
185 | }
186 | }
187 | }
188 |
189 | /**
190 | * Verify if all required folders are present (every enum value in
191 | * DecompilerType). Define which ones are missing and add those in the error
192 | * message. Reason for this method is the fact that the child process which
193 | * is launched in the command, launches another child to execute the
194 | * process. The error code is hard to retrieve, so this method was chosen
195 | * instead.
196 | *
197 | * @throws Exception if one or more tools fail to install
198 | */
199 | public void verifyInstallation() throws Exception {
200 | //Create a list in which all of the results go
201 | List missingTools = new ArrayList<>();
202 |
203 | //Create an object for each folder
204 | File androidProjectFolder = new File(Constants.ANDROIDPROJECT_LIBRARY_FOLDER);
205 | File apkToolFolder = new File(Constants.APKTOOL_LIBRARY_FOLDER);
206 | File dex2jarFolder = new File(Constants.DEX2JAR_LIBRARY_FOLDER);
207 | File fernflowerFolder = new File(Constants.FERNFLOWER_LIBRARY_FOLDER);
208 | //Since the JadX folder is set to the "bin" folder within the "jadx" folder, the last four characters need to be removed in order for the name-printing to work
209 | File jadxFolder = new File(new String(Constants.JADX_LIBRARY_FOLDER).substring(0, Constants.JADX_LIBRARY_FOLDER.length() - 4));
210 | File jdcmdFolder = new File(Constants.JDCMD_LIBRARY_FOLDER);
211 | File crfFolder = new File(Constants.CFR_LIBRARY_FOLDER);
212 | File procyonFolder = new File(Constants.PROCYON_LIBRARY_FOLDER);
213 | File jeb3Script = new File(Constants.JEB3_CLI_ANDROID_SCRIPT_LIBRARY_FOLDER);
214 |
215 | //Add all folders in a list
216 | List folders = new ArrayList<>();
217 | folders.add(androidProjectFolder);
218 | folders.add(apkToolFolder);
219 | folders.add(dex2jarFolder);
220 | folders.add(fernflowerFolder);
221 | folders.add(jadxFolder);
222 | folders.add(jdcmdFolder);
223 | folders.add(crfFolder);
224 | folders.add(procyonFolder);
225 | folders.add(jeb3Script);
226 |
227 | //Check each of the folders in the folders list
228 | for (File folder : folders) {
229 | //If it does not exist or is not a folder, then something went wrong
230 | if (folder.exists() == false || folder.isDirectory() == false) {
231 | //Add the missing tool to the list
232 | missingTools.add(folder.getName());
233 | }
234 | }
235 |
236 | //If the list contains 1 or more elements, an exception is thrown to notify the user
237 | if (missingTools.size() > 0) {
238 | StringBuilder message = new StringBuilder();
239 | message.append("\tThe following tools failed to install correctly:\n");
240 | for (String missingTool : missingTools) {
241 | message.append("\t\t" + missingTool.toUpperCase() + "\n");
242 | }
243 | message.append("\tSee the output log above for more details. Verify that you have installed the correct dependencies before you try again.");
244 | throw new Exception(message.toString());
245 | }
246 | }
247 | }
248 |
--------------------------------------------------------------------------------
/src/main/java/command/Assembler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Max 'Libra' Kersten
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 | package command;
18 |
19 | import apc.FileManager;
20 | import java.io.File;
21 | import java.io.FileInputStream;
22 | import java.io.FileNotFoundException;
23 | import java.io.FileOutputStream;
24 | import java.io.IOException;
25 | import java.io.InputStream;
26 | import java.io.OutputStream;
27 | import library.Constants;
28 | import net.lingala.zip4j.exception.ZipException;
29 |
30 | /**
31 | * The assembler class contains all functions required to create the Android
32 | * Studio project using the output of the decompiler class and the Android
33 | * Studio ZIP archive from the
34 | * Constants.ANDROIDPROJECT_LIBRARY_FOLDER
35 | *
36 | * @author Max 'Libra' Kersten
37 | */
38 | public class Assembler {
39 |
40 | /**
41 | * The location to place the filled Android Studio project
42 | */
43 | private final File outputLocation;
44 |
45 | /**
46 | * The file manager that is used to perform actions on files
47 | */
48 | private final FileManager fileManager;
49 |
50 | /**
51 | * The assembler class contains all functions required to create the Android
52 | * Studio project using the output of the decompiler class and the Android
53 | * Studio ZIP archive from the
54 | * Constants.ANDROIDPROJECT_LIBRARY_FOLDER
55 | *
56 | * @param outputLocation the location where the filled Android Studio
57 | * project should be placed
58 | */
59 | public Assembler(File outputLocation) {
60 | this.outputLocation = outputLocation;
61 | fileManager = new FileManager();
62 | }
63 |
64 | /**
65 | * The public function which contains all function calls to the private
66 | * methods which assemble the Android Studio project
67 | *
68 | * @throws IOException if something goes wrong with the file handling
69 | * @throws ZipException if an archive cannot be extracted
70 | * @throws FileNotFoundException if a file cannot be found (such as the
71 | * AndroidManifest file)
72 | */
73 | public void assemble() throws IOException, ZipException, FileNotFoundException {
74 | //Copy and extract the template zip
75 | prepareTemplateProject();
76 | //Copy the decoded and decompiled files to the template project
77 | copyManifest();
78 | copyResources();
79 | copyJavaCode();
80 | copyNativeLibraries();
81 | copySmaliFiles();
82 | copyAssets();
83 | //Copy the template project from the temporary location to the desired output location
84 | copyTemplateToOutputFolder();
85 | //TODO ZIP template project to the desired output location (if the zip flag is used)
86 | //Remove temporary files
87 | cleanup();
88 | }
89 |
90 | /**
91 | * Extracts the template archive file into the temporary folder (which is
92 | * located in ./Library/temp, in which the working directory is the one in
93 | * which the APK resides)
94 | *
95 | * @throws ZipException if an archive cannot be extracted
96 | */
97 | private void prepareTemplateProject() throws ZipException, IOException {
98 | try {
99 | //Read file
100 | System.out.println("[+]Reading Android Studio template project");
101 | //Create temp folder
102 | File tempFile = new File(Constants.TEMP_LIBRARY_FOLDER);
103 | tempFile.mkdir();
104 | System.out.println("[+]Writing template to a temporary folder (" + Constants.TEMP_TEMPLATE_FOLDER + ")");
105 | String androidStudioZipFileName = "/ap.zip";
106 | File targetFile = new File(Constants.ANDROIDPROJECT_LIBRARY_FOLDER + androidStudioZipFileName);
107 | File destinationFile = new File(Constants.TEMP_TEMPLATE_FOLDER);
108 | //Extract file
109 | System.out.println("[+]Extracting Android Studio template project");
110 | fileManager.extractArchive(targetFile.getAbsolutePath(), destinationFile.getAbsolutePath());
111 | System.out.println("[+]Template extraction finished");
112 | } catch (ZipException ex) {
113 | throw new ZipException("An error occurred when trying to extract the template project. Reinstall AndroidProjectCreator using the \"-install\" flag and try again.");
114 | }
115 | }
116 |
117 | /**
118 | * Copies the resources from the APK into the template project in the
119 | * temporary folder
120 | *
121 | * @throws IOException if the resources cannot be copied
122 | */
123 | private void copyResources() throws IOException {
124 | try {
125 | //Get the teporary resource folder location
126 | File tempResourcesFolder = new File(Constants.TEMP_RESOURCES_FOLDER);
127 | //Copy the template resource folder
128 | File templateResourceFolder = new File(Constants.TEMP_TEMPLATE_RESOURCES_FOLDER);
129 | System.out.println("[+]Copying resources from the APK to the Android Studio project");
130 | //Copy the files
131 | fileManager.copyFolder(tempResourcesFolder, templateResourceFolder);
132 | System.out.println("[+]Copying resources complete");
133 | } catch (IOException ex) {
134 | throw new IOException("Something went wrong when trying to copy the resources");
135 | }
136 | }
137 |
138 | /**
139 | * Copy the AndroidManifest.xml from the temporary folder to the template
140 | * project
141 | *
142 | * @throws FileNotFoundException if the manifest file cannot be found
143 | * @throws IOException if the manifest file cannot be copied
144 | */
145 | private void copyManifest() throws FileNotFoundException, IOException {
146 | try {
147 | //The manifest
148 | File tempManifest = new File(Constants.TEMP_MANIFEST_FILE);
149 | //Create file located in the Android Project
150 | File templateManifest = new File(Constants.TEMP_TEMPLATE_MANIFEST_FILE);
151 | //Copy the xml file
152 | System.out.println("[+]Copying the AndroidManifest.xml from the APK to the Android Studio project");
153 | templateManifest.createNewFile();
154 | InputStream input = null;
155 | OutputStream output = null;
156 | input = new FileInputStream(tempManifest);
157 | output = new FileOutputStream(templateManifest);
158 | byte[] buf = new byte[1024];
159 | int bytesRead;
160 | while ((bytesRead = input.read(buf)) > 0) {
161 | output.write(buf, 0, bytesRead);
162 | }
163 | input.close();
164 | output.close();
165 | System.out.println("[+]AndroidManifest.xml successfully copied");
166 | } catch (FileNotFoundException ex) {
167 | throw new FileNotFoundException("The manifest could not be found!");
168 | } catch (IOException ex) {
169 | throw new IOException("Something went wrong when copying the AndroidManifest.xml file to the template project.");
170 | }
171 | }
172 |
173 | /**
174 | * Copy the decompiled Java code from the output location of the decompiler
175 | * to the template project
176 | *
177 | * @throws IOException if something goes wrong during the copying of the
178 | * decompiled Java code
179 | */
180 | private void copyJavaCode() throws IOException {
181 | try {
182 | System.out.println("[+]Copying the decompiled Java source code from the APK to the Android Studio project");
183 | File sourceLocation = new File(Constants.TEMP_SOURCES_FOLDER);
184 | File sourceDest = new File(Constants.TEMP_TEMPLATE_SOURCE);
185 | fileManager.copyFolder(sourceLocation, sourceDest);
186 | System.out.println("[+]Source code successfully copied");
187 | } catch (IOException ex) {
188 | throw new IOException("An error occurred when the decompiled Java code was copied to the template project!");
189 | }
190 | }
191 |
192 | /**
193 | * Copies the native libraries from the APK to the template project. APKTool
194 | * only creates the lib folder, if there are libraries to extract from the
195 | * APK, hence the check. If it is not found, it is skipped
196 | *
197 | * @throws IOException when something goes wrong during the copying of the
198 | * libraries
199 | */
200 | private void copyNativeLibraries() throws IOException {
201 | try {
202 | System.out.println("[+]Looking for native libraries");
203 | File apkLibraryFolder = new File(Constants.TEMP_LIB_FOLDER);
204 | if (apkLibraryFolder.exists() && apkLibraryFolder.isDirectory()) {
205 | System.out.println("[+]Native libraries found!");
206 | System.out.println("[+]Copying native lbraries to the template project");
207 | File templateLibraryFolder = new File(Constants.TEMP_TEMPLATE_LIBS_FOLDER);
208 | templateLibraryFolder.mkdir();
209 | fileManager.copyFolder(apkLibraryFolder, templateLibraryFolder);
210 | System.out.println("[+]Native libraries succesfully copied!");
211 | return;
212 | }
213 | System.out.println("[+]No native libraries found, skipping this step.");
214 | } catch (IOException e) {
215 | throw new IOException("Something went wrong when copying the native libraries from the APK to the template project.");
216 | }
217 |
218 | }
219 |
220 | /**
221 | * Copy the SMALI files into the template project's resources folder
222 | *
223 | * @throws IOException when the copying fails
224 | */
225 | private void copySmaliFiles() throws IOException {
226 | try {
227 | System.out.println("[+]Looking for SMALI files");
228 | File apkSmaliFolder = new File(Constants.TEMP_SMALI_FOLDER);
229 | if (apkSmaliFolder.exists() && apkSmaliFolder.isDirectory()) {
230 | System.out.println("[+]SMALI files found!");
231 | System.out.println("[+]Copying the SMALI files to the template project");
232 | File templateSmaliFolder = new File(Constants.TEMP_TEMPLATE_SMALI_FOLDER);
233 | templateSmaliFolder.mkdir();
234 | fileManager.copyFolder(apkSmaliFolder, templateSmaliFolder);
235 | System.out.println("[+]SMALI files succesfully copied!");
236 | return;
237 | }
238 | System.out.println("[+]No SMALI files found, skipping this step.");
239 | } catch (IOException e) {
240 | throw new IOException("Something went wrong when copying the SMALI files from the APK to the template project.");
241 | }
242 | }
243 |
244 | /**
245 | * Copies assets from the APK to the resource folder of the template project
246 | *
247 | * @throws IOException
248 | */
249 | private void copyAssets() throws IOException {
250 | try {
251 | System.out.println("[+]Looking for assets");
252 | File apkAssetFolder = new File(Constants.TEMP_ASSET_FOLDER);
253 | if (apkAssetFolder.exists() && apkAssetFolder.isDirectory()) {
254 | System.out.println("[+]Assets found!");
255 | System.out.println("[+]Copying assets to the template project");
256 | File templateAssetFolder = new File(Constants.TEMP_TEMPLATE_ASSET_FOLDER);
257 | templateAssetFolder.mkdir();
258 | fileManager.copyFolder(apkAssetFolder, templateAssetFolder);
259 | System.out.println("[+]Assets succesfully copied!");
260 | return;
261 | }
262 | System.out.println("[+]No assets found, skipping this step.");
263 | } catch (IOException e) {
264 | throw new IOException("Something went wrong when copying assets from the APK to the template project.");
265 | }
266 | }
267 |
268 | /**
269 | * Copies the template project to the desired output location
270 | *
271 | * @throws IOException if there is an error during the copying of the
272 | * template project to the desired output location
273 | */
274 | private void copyTemplateToOutputFolder() throws IOException {
275 | try {
276 | System.out.println("[+]Copying temp folder to output folder");
277 | File tempProject = new File(Constants.TEMP_TEMPLATE_FOLDER);
278 | //Make sure the output location (and its parents) exists
279 | outputLocation.mkdirs();
280 | fileManager.copyFolder(tempProject, outputLocation);
281 | System.out.println("[+]Output folder succesfully populated!");
282 | } catch (IOException ex) {
283 | throw new IOException("Unable to copy the temporary project (\"" + new File(Constants.TEMP_TEMPLATE_FOLDER).getAbsolutePath() + "\") to the desired output location (\"" + outputLocation.getAbsolutePath() + "\").");
284 | }
285 | }
286 |
287 | /**
288 | * Removes the temporary folder within the library's temporary folder
289 | *
290 | * @throws IOException if something goes wrong during the deletion of the
291 | * file(s) and/or folder(s)
292 | */
293 | private void cleanup() throws IOException {
294 | try {
295 | System.out.println("[+]Cleaning the temporary files folder");
296 | fileManager.delete(new File(Constants.TEMP_LIBRARY_FOLDER));
297 | System.out.println("[+]Cleanup complete");
298 | } catch (IOException ex) {
299 | throw new IOException("An error occurred during the removal of the temporary files");
300 | }
301 | }
302 | }
303 |
--------------------------------------------------------------------------------
/src/main/java/command/CompactInstaller.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2020 Max 'Libra' Kersten
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 | package command;
18 |
19 | import apc.RepositoryManager;
20 | import java.io.File;
21 | import java.io.IOException;
22 | import java.util.ArrayList;
23 | import java.util.List;
24 | import library.Constants;
25 | import model.Repository;
26 |
27 | /**
28 | * Handles the compact installation of all required tools for
29 | * AndroidProjectCreator.
30 | *
31 | * @author Max 'Libra' Kersten
32 | */
33 | public class CompactInstaller {
34 |
35 | /**
36 | * Performs the compact installation of the required tools by cloning a
37 | * repository directly into the library folder
38 | */
39 | public void install() throws IOException, InterruptedException, Exception {
40 | System.out.println("[+]Starting the installation");
41 | RepositoryManager repositoryManager = new RepositoryManager();
42 | System.out.println("[+]Starting cloning the repositories");
43 | List repository = new ArrayList<>();
44 | String name = "CompactInstall version 1.1 (dated 11-05-2021)";
45 | String url = "https://github.com/thisislibra/apc-compact.git";
46 | File directory = new File(Constants.LIBRARY_FOLDER);
47 | String branch = "11-05-2021";
48 | repository.add(new Repository(name, url, directory, branch));
49 | repositoryManager.cloneRepositories(repository);
50 | System.out.println("[+]Cloning finished");
51 | System.out.println("[+]Verifying the toolset");
52 | repositoryManager.verifyInstallation();
53 | System.out.println("[+]Verification succesful!");
54 | System.out.println("[+]Installation complete!");
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/command/Decompiler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Max 'Libra' Kersten
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 | package command;
18 |
19 | import apc.FileManager;
20 | import enumeration.DecompilerType;
21 | import java.io.File;
22 | import java.io.IOException;
23 | import library.Constants;
24 | import library.ProjectInfos;
25 | import model.ArgumentPackage;
26 | import model.Command;
27 | import net.lingala.zip4j.exception.ZipException;
28 |
29 | /**
30 | * This class handles the decompilation of the APK with the embedded tools and
31 | * the flags for the command line interfaces that are provided.
32 | *
33 | * @author Max 'Libra' Kersten
34 | */
35 | public class Decompiler {
36 |
37 | private final ArgumentPackage argumentPackage;
38 |
39 | public Decompiler(ArgumentPackage argumentPackage) {
40 | this.argumentPackage = argumentPackage;
41 | }
42 |
43 | /**
44 | * Decompiles the APK with the requested tool
45 | *
46 | * @throws IOException if the file handling goes wrong
47 | * @throws InterruptedException if the command execution is interrupted
48 | * @throws ZipException if an archive cannot be extracted (i.e. it is not a
49 | * ZIP archive)
50 | */
51 | public void decompile() throws IOException, InterruptedException, ZipException {
52 | //Declare local variables
53 | boolean isWindows = Constants.isWindows();
54 | String command;
55 | File workingDirectory;
56 |
57 | //Decode the APK with APKTool
58 | File apkOutput = new File(Constants.TEMP_LIBRARY_FOLDER);
59 | System.out.println("[+]Decompiling the APK to a temporary location (" + apkOutput.getAbsolutePath() + ")");
60 | apkOutput.mkdirs();
61 | /**
62 | * First the 'd' is provided to enable 'decoding'.
63 | *
64 | * The '-f' command is used to remove the destination folder if it
65 | * already exists.
66 | *
67 | * The '-s' command is used to keep the classes.dex file (instead of
68 | * decompiling it to smali code). This speeds up the process of decoding
69 | * the APK. Additionally, the classes.dex file is used by the
70 | * decompilers. Without the '-s' flag, the classes.dex file is not
71 | * present in the decoded output
72 | *
73 | * The '-o' command requires one more parameter behind it. This
74 | * specifies the output directory
75 | *
76 | * The '-m' command stands for "match-original" which matches files as
77 | * close as possible to original ones, but prevents the ability to
78 | * rebuild. This is irrelevant for APC users, since the decompiled Java
79 | * code isn't buildable in most cases
80 | *
81 | * The '-k' command allows broken resources to be decoded although the
82 | * project will then not be compilable. This is not a problem, since the
83 | * output of APC isn't fully buildable anyway.
84 | */
85 | System.out.println("[+]Calling APKTool to decompile the AndroidManifest.xml and the application resources");
86 | if (isWindows) {
87 | command = "java -jar apktool-cli-all.jar";
88 | } else {
89 | command = "java -jar ./apktool-cli-all.jar";
90 | }
91 | //Append the flags and the file paths to the commands. These are the same on any platform due to the Java runtime
92 | command += " d -f -s -m -k -o " + encapsulate(new File(Constants.TEMP_LIBRARY_FOLDER + "/apktool").getAbsolutePath()) + " " + encapsulate(argumentPackage.getApk().getAbsolutePath());
93 |
94 | workingDirectory = new File(Constants.APKTOOL_LIBRARY_FOLDER);
95 | executeCommand(DecompilerType.APKTOOL, command, workingDirectory);
96 |
97 | /**
98 | * Use APKTool again for the SMALI files, cant be done at once because
99 | * one either gets the 'classes.dex' file or the .smali files
100 | *
101 | * The flag '--no-assets' avoids the decoding of assets in the APK,
102 | * which are already extracted in the previous call of APKTool.
103 | *
104 | * The '--no-res' avoids the decoding of resources, which is also done
105 | * in the previous call of APKTool.
106 | *
107 | */
108 | System.out.println("[+]Calling APKTool to obtain the SMALI code");
109 | if (isWindows) {
110 | command = "java -jar apktool-cli-all.jar";
111 | } else {
112 | command = "java -jar ./apktool-cli-all.jar";
113 | }
114 | //Append the flags and the file paths to the commands. These are the same on any platform due to the Java runtime
115 | command += " d -f --no-assets --no-res -m -o " + encapsulate(new File(Constants.TEMP_LIBRARY_FOLDER + "/apktool-smali").getAbsolutePath()) + " " + encapsulate(argumentPackage.getApk().getAbsolutePath());
116 |
117 | workingDirectory = new File(Constants.APKTOOL_LIBRARY_FOLDER);
118 | executeCommand(DecompilerType.APKTOOL, command, workingDirectory);
119 |
120 | //TODO before the combine functionality is added, add a temporary "copy all classes[n].dex files to the template project's assets folder" method
121 | //TODO Combine classes[N].dex files into classes.dex to decompile every part of the binary, should be optional since it can exceed 64k functions. Use /Users/[name]/Library/Android/sdk/build-tools/28.0.2/lib/dx.jar com.android.dx.merge.DexMerger output.dex part1.dex part2.dex
122 | //Source for code: https://stackoverflow.com/questions/11257378/is-there-a-way-to-merge-two-or-more-dex-files-into-one-dex-file-using-scala
123 | /**
124 | * JADX can decompile an APK directly, therefore its more efficient to
125 | * skip this step if the JADX decompiler has been selected.
126 | */
127 | if (argumentPackage.getDecompilerType().equals(DecompilerType.JADX) == false) {
128 | //Convert the classes.dex to a JAR file for later use
129 | /**
130 | * Convert the classes.dex to a JAR (use the "sh" in front since the
131 | * script is not executable by default)
132 | *
133 | * The '-n' is used to ignore exceptions that are thrown by dex2jar
134 | *
135 | * The '-f' is used to forcefully overwrite existing files on the
136 | * destination location
137 | *
138 | * The '-o' is used to define the output location
139 | */
140 | if (isWindows) {
141 | command = "d2j-dex2jar.bat";
142 | } else {
143 | //Add extra shell here to avoid the need to chmod +x the shell script
144 | command = "sh ./d2j-dex2jar.sh";
145 | }
146 | //Append the flags and the file paths to the commands. These are the same on any platform due to the Java runtime
147 | command += " -n -f -o " + encapsulate(new File(Constants.TEMP_CONVERTED_JAR).getAbsolutePath()) + " " + encapsulate(new File(Constants.TEMP_LIBRARY_FOLDER + "/apktool/classes.dex").getAbsolutePath());
148 | workingDirectory = new File(Constants.DEX2JAR_LIBRARY_FOLDER);
149 | executeCommand(DecompilerType.DEX2JAR, command, workingDirectory);
150 | }
151 |
152 | //Ensure that the output directory for the source code exists
153 | new File(Constants.TEMP_SOURCES_FOLDER).mkdir();
154 |
155 | //Handle each decompiler with different commands
156 | switch (argumentPackage.getDecompilerType()) {
157 | case FERNFLOWER:
158 | //TODO implement rename option
159 | //use -ren=1 for rename
160 | if (isWindows) {
161 | command = "java -jar fernflower.jar";
162 | } else {
163 | command = "java -jar ./fernflower.jar";
164 | }
165 | //Append the flags and the file paths to the commands. These are the same on any platform due to the Java runtime
166 | command += " " + encapsulate(new File(Constants.TEMP_CONVERTED_JAR).getAbsolutePath()) + " " + encapsulate(new File(Constants.TEMP_SOURCES_FOLDER).getAbsolutePath());
167 | workingDirectory = new File(Constants.FERNFLOWER_LIBRARY_FOLDER);
168 | break;
169 | case JADX:
170 | /**
171 | * -d sets output dir
172 | *
173 | * -r avoids resources (got these with APKTool already)
174 | *
175 | * --escape-unicode to escape unicode characters
176 | *
177 | * --deobf to enable deobfuscation
178 | *
179 | * --deobf-min minimum length of the new names
180 | *
181 | * --deobf-max maximum length of the new names
182 | */
183 | //TODO implement deobfuscation parameters
184 | if (isWindows) {
185 | command = "jadx.bat";
186 | } else {
187 | //Add extra shell here to avoid the need to chmod +x the shell script
188 | command = "sh ./jadx";
189 | }
190 | //Append the flags and the file paths to the commands. These are the same on any platform due to the Java runtime
191 | command += " -r --escape-unicode -d " + encapsulate(new File(Constants.TEMP_LIBRARY_FOLDER).getAbsolutePath()) + " " + encapsulate(argumentPackage.getApk().getAbsolutePath());
192 | workingDirectory = new File(Constants.JADX_LIBRARY_FOLDER);
193 | break;
194 | case JDCMD:
195 | /**
196 | *
197 | * '-od' specifies the output directory
198 | */
199 | if (isWindows) {
200 | command = "java -jar jd-cli.jar";
201 | } else {
202 | command = "java -jar ./jd-cli.jar";
203 | }
204 | //Append the flags and the file paths to the commands. These are the same on any platform due to the Java runtime
205 | command += " -od " + encapsulate(new File(Constants.TEMP_SOURCES_FOLDER).getAbsolutePath()) + " " + encapsulate(new File(Constants.TEMP_CONVERTED_JAR).getAbsolutePath());
206 | workingDirectory = new File(Constants.JDCMD_LIBRARY_FOLDER);
207 | break;
208 | case CFR:
209 | //The file name of the CFR decompiler JAR, which contains the version number
210 | String cfrFileName = "";
211 | //Get the folder where the build is located
212 | File cfrLibraryFolder = new File(Constants.CFR_LIBRARY_FOLDER);
213 | //Iterate through all files in the folder to find the correct JAR
214 | for (File file : cfrLibraryFolder.listFiles()) {
215 | //Even though only files are listed, this measure is added as an additional security layer
216 | if (file.isDirectory()) {
217 | continue;
218 | }
219 | //If the name of the iterated file in the build output directory contains the partial output name of CFR, the name is taken
220 | //Both are in lower case to avoid errors when the casing is changed in the build output
221 | if (file.getName().toLowerCase().contains(ProjectInfos.getCfr().getPartialOutputName().toLowerCase())) {
222 | cfrFileName = file.getName();
223 | }
224 | }
225 | /**
226 | * --outputdir [the output directory]
227 | *
228 | * --aexagg true To remove nested exception handles which have
229 | * the same semantics
230 | *
231 | */
232 | if (isWindows) {
233 | command = "java -jar " + cfrFileName;
234 | } else {
235 | command = "java -jar " + cfrFileName;
236 | }
237 | //Append the flags and the file paths to the commands. These are the same on any platform due to the Java runtime
238 | command += " " + encapsulate(new File(Constants.TEMP_CONVERTED_JAR).getAbsolutePath()) + " --aexagg true --outputdir " + encapsulate(new File(Constants.TEMP_SOURCES_FOLDER).getAbsolutePath());
239 | workingDirectory = new File(Constants.CFR_LIBRARY_FOLDER);
240 | break;
241 | case PROCYON:
242 | /**
243 | * -ci collapses multiple imports from the same package into a
244 | * wildcard import
245 | *
246 | * -eml for eager loading
247 | *
248 | * -o [dir] for output
249 | */
250 | if (isWindows) {
251 | command = "java -jar procyon-decompiler-0.5.30.jar";
252 | } else {
253 | command = "java -jar ./procyon-decompiler-0.5.30.jar";
254 | }
255 | //Append the flags and the file paths to the commands. These are the same on any platform due to the Java runtime
256 | command += " -ci -eml --jar-file " + encapsulate(new File(Constants.TEMP_CONVERTED_JAR).getAbsolutePath()) + " -o " + encapsulate(new File(Constants.TEMP_SOURCES_FOLDER).getAbsolutePath());
257 | workingDirectory = new File(Constants.PROCYON_LIBRARY_FOLDER);
258 | break;
259 | case JEB3:
260 | /**
261 | * No parameters are required besides the path to the file and
262 | * the output directory (in that order)
263 | *
264 | * JEB decompile command:
265 | *
266 | * java -jar ./jeb.jar --srv2=DecompileAndroid.py -- FILE
267 | * OUTPUT_DIR
268 | */
269 | if (isWindows) {
270 | command = "java -jar bin/app/jeb.jar";
271 | } else {
272 | command = "java -jar ./bin/app/jeb.jar";
273 | }
274 | command += " --srv2 --script=" + encapsulate(new File(Constants.JEB3_CLI_ANDROID_SCRIPT_LIBRARY_FOLDER + "/DecompileAndroid.py").getAbsolutePath()) + " -- " + encapsulate(argumentPackage.getApk().getAbsolutePath()) + " " + encapsulate(new File(Constants.TEMP_SOURCES_FOLDER).getAbsolutePath());
275 | workingDirectory = argumentPackage.getJeb3Folder();
276 | }
277 | executeCommand(argumentPackage.getDecompilerType(), command, workingDirectory);
278 | }
279 |
280 | /**
281 | * Executes the command based on the previously entered command within the
282 | * given working directory
283 | *
284 | * @param name the name of the tool that is executed
285 | * @param commandString the command that is executed
286 | * @param workingDirectory the working directory in which the command is
287 | * executed
288 | * @throws IOException if something goes wrong with file handling
289 | * @throws InterruptedException if the command is interrupted, although this
290 | * should never happen
291 | * @throws ZipException if an archive cannot be extracted
292 | */
293 | private void executeCommand(DecompilerType name, String commandString, File workingDirectory) throws IOException, InterruptedException, ZipException {
294 | Command command = new Command(commandString, workingDirectory);
295 | FileManager fileManager = new FileManager();
296 | System.out.println("[+]Decompling JAR with " + name);
297 | try {
298 | command.execute();
299 | switch (name) {
300 | case FERNFLOWER:
301 | fileManager.extractArchive(new File(Constants.TEMP_SOURCES_FOLDER + "/output.jar").getAbsolutePath(), new File(Constants.TEMP_SOURCES_FOLDER).getAbsolutePath());
302 | fileManager.delete(new File(Constants.TEMP_SOURCES_FOLDER + "/output.jar"));
303 | break;
304 | case JEB3:
305 | /**
306 | * If the JEB3 output folder exists, copy the contents to
307 | * the TEMP_SOURCES_FOLDER and remove the JEB3 output
308 | * folder. This way, the rest file handling can stay the
309 | * same.
310 | */
311 | File sourceLocation = new File(Constants.TEMP_SOURCES_FOLDER);
312 | File jeb3Output = new File(sourceLocation.getAbsolutePath() + "/Bytecode_decompiled");
313 | if (jeb3Output.exists() && jeb3Output.isDirectory()) {
314 | for (File currentFileObject : sourceLocation.listFiles()) {
315 | fileManager.copyFolder(currentFileObject, sourceLocation);
316 | }
317 | fileManager.delete(jeb3Output);
318 | }
319 | break;
320 | case JADX:
321 | File source = new File(Constants.TEMP_SOURCES_FOLDER);
322 | File jadxOutput = new File(source.getAbsolutePath() + "/sources");
323 | if (jadxOutput.exists() && jadxOutput.isDirectory()) {
324 | for (File currentFileObject : source.listFiles()) {
325 | fileManager.copyFolder(currentFileObject, source);
326 | }
327 | fileManager.delete(jadxOutput);
328 | }
329 | break;
330 | default:
331 | break;
332 | }
333 | System.out.println("[+]Decompilation finished");
334 | } catch (IOException ex) {
335 | throw new IOException("Something went wrong with the I/O during the decompilation. Check the permissions of the output directory and try again.");
336 | }
337 | }
338 |
339 | /**
340 | * Encapsulates the given string between quotes
341 | *
342 | * @param value the string to encapsulate
343 | * @return the encapsulated string
344 | */
345 | private String encapsulate(String value) {
346 | return "\"" + value + "\"";
347 | }
348 | }
349 |
--------------------------------------------------------------------------------
/src/main/java/command/Installer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Max 'Libra' Kersten
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 | package command;
18 |
19 | import apc.RepositoryManager;
20 | import java.io.IOException;
21 | import library.Repositories;
22 | import library.Tools;
23 |
24 | /**
25 | * Handles the installation of all tools
26 | *
27 | * @author Max 'Libra' Kersten
28 | */
29 | public class Installer {
30 |
31 | /**
32 | * Clones all the git repositories in a sub folder of
33 | * Constants.getLibraryFolderName()
(named "repos") in the
34 | * current directory. Then, all projects are built to ensure the latest
35 | * version is used. The outcome of the builds is either a ZIP or a JAR file.
36 | * A ZIP file will first be extracted. The tools are then copied into the
37 | * Constants.getLibraryFolderName()
folder within their own
38 | * subdirectory.
39 | */
40 | public void install() throws IOException, Exception {
41 | System.out.println("[+]Starting the installation");
42 | RepositoryManager repositoryManager = new RepositoryManager();
43 | System.out.println("[+]Starting cloning the repositories");
44 | repositoryManager.cloneRepositories(Repositories.getAll());
45 | System.out.println("[+]Cloning finished");
46 | System.out.println("[+]Starting to build all repositories");
47 | repositoryManager.buildRepositories(Tools.getTools());
48 | System.out.println("[+]All projects have been built");
49 | System.out.println("[+]Starting to extract the builds to the library");
50 | repositoryManager.extractBuilds(Tools.getTools());
51 | System.out.println("[+]Extraction complete");
52 | System.out.println("[+]Verifying the toolset");
53 | repositoryManager.verifyInstallation();
54 | System.out.println("[+]Verification succesful!");
55 | System.out.println("[+]Installation complete!");
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/main/java/command/Updater.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Max 'Libra' Kersten
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 | package command;
18 |
19 | import apc.RepositoryManager;
20 | import java.io.IOException;
21 | import library.Repositories;
22 | import library.Tools;
23 |
24 | /**
25 | * Handles the repositories to update and rebuild them
26 | *
27 | * @author Max 'Libra' Kersten
28 | */
29 | public class Updater {
30 |
31 | public void update() throws IOException, Exception {
32 | System.out.println("[+]Starting the update");
33 | RepositoryManager repositoryManager = new RepositoryManager();
34 | System.out.println("[+]Starting updating the repositories");
35 | repositoryManager.updateRepositories(Repositories.getAll());
36 | System.out.println("[+]Updating finished");
37 | System.out.println("[+]Starting to build all repositories");
38 | repositoryManager.buildRepositories(Tools.getTools());
39 | System.out.println("[+]All projects have been built");
40 | System.out.println("[+]Removing tools from the library");
41 | repositoryManager.emptyLibraryFolders(Tools.getTools());
42 | System.out.println("[+]Succesfully removed tools from the library");
43 | System.out.println("[+]Starting to extract the builds to the library");
44 | repositoryManager.extractBuilds(Tools.getTools());
45 | System.out.println("[+]Extraction complete");
46 | System.out.println("[+]Verifying the toolset");
47 | repositoryManager.verifyInstallation();
48 | System.out.println("[+]Verification succesful!");
49 | System.out.println("[+]Update complete!");
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/main/java/enumeration/Action.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Max 'Libra' Kersten
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 | package enumeration;
18 |
19 | /**
20 | * The action as specified by the user
21 | *
22 | * @author Max 'Libra' Kersten
23 | */
24 | public enum Action {
25 | INSTALL,
26 | COMPACT_INSTALL,
27 | UPDATE,
28 | DECOMPILE,
29 | ERROR
30 | }
31 |
--------------------------------------------------------------------------------
/src/main/java/enumeration/DecompilerType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Max 'Libra' Kersten
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 | package enumeration;
18 |
19 | /**
20 | * Enumeration used to list the decompilers that are included
21 | *
22 | * @author Max 'Libra' Kersten
23 | */
24 | public enum DecompilerType {
25 | APKTOOL,
26 | CFR,
27 | DEX2JAR,
28 | FERNFLOWER,
29 | JADX,
30 | JDCMD,
31 | JEB3,
32 | PROCYON
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/library/Constants.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Max 'Libra' Kersten
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 | package library;
18 |
19 | import apc.AndroidProjectCreator;
20 | import java.io.File;
21 | import java.net.URISyntaxException;
22 | import java.util.UUID;
23 |
24 | /**
25 | * Within this class, constant values are declared. To keep an overview and
26 | * allow changes in the program without altering multiple classes and various
27 | * variables, the variables are stored in one static class.
28 | *
29 | * An example of an advantage would be a change in the location of the library
30 | * folder. In this class, the field LIBRARY_FOLDER_NAME
is contains
31 | * the name of this folder. Changing it, will change the name within the whole
32 | * program, without any additional changes.
33 | *
34 | * @author Max 'Libra' Kersten
35 | */
36 | public class Constants {
37 |
38 | /**
39 | * Determines if the current operating system is Windows.
40 | *
41 | * @return true if the operating system is Windows, false if it is not.
42 | */
43 | public static boolean isWindows() {
44 | //If the os.name property of the Dalvik VM contains "windows", the system is Windows based
45 | if (System.getProperty("os.name").toLowerCase().contains("windows")) {
46 | return true;
47 | }
48 | return false;
49 | }
50 |
51 | /**
52 | * Determines if the current operating system is a Linux distribution.
53 | *
54 | * @return true if the operating system is a Linux distribution, false if it
55 | * is not.
56 | */
57 | public static boolean isLinux() {
58 | //If the os.name property of the Dalvik VM contains "linux", the system is a Linux distribution
59 | if (System.getProperty("os.name").toLowerCase().contains("linux")) {
60 | return true;
61 | }
62 | return false;
63 | }
64 |
65 | /**
66 | * Determines if the current operating system is a MacOS based operating
67 | * system
68 | *
69 | * @return true if the host is running MacOS, false if not
70 | */
71 | public static boolean isMac() {
72 | //If the os.name property of the Dalvik VM contains "mac os", the system is a MacOS distribution
73 | if (System.getProperty("os.name").toLowerCase().contains("mac os")) {
74 | return true;
75 | }
76 | return false;
77 | }
78 |
79 | /**
80 | * Obtain the base location of this instance of APC
81 | *
82 | * @return the folder in which the JAR resides
83 | */
84 | public static final String getProgramBase() {
85 | try {
86 | return new File(AndroidProjectCreator.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()).getParentFile().getAbsolutePath();
87 | } catch (URISyntaxException ex) {
88 | //Since this is a constant which is used in nearly every other constant, it may not fail. This is therefore also disconnected from the main error handling try-catch clause, which is located in the ArgumentManager.
89 | System.out.println("[+]An error occurred upon requesting the location of this JAR. Please make sure the permissions are correctly set and try again.");
90 | System.exit(1);
91 | //Unreachable code to avoid compiler issues
92 | return null;
93 | }
94 | }
95 |
96 | /**
97 | * The name of the library folder, which resides in the same folder as this
98 | * JAR
99 | */
100 | private static final String LIBRARY_FOLDER_NAME = "/library";
101 |
102 | /**
103 | * Gets the complete path of the library folder, which resides in the same
104 | * directory as this JAR resides in.
105 | */
106 | public static final String LIBRARY_FOLDER = getProgramBase() + LIBRARY_FOLDER_NAME;
107 |
108 | /**
109 | * The name of the build output
110 | */
111 | public static final String BUILD_OUTPUT = "buildOutput";
112 |
113 | /**
114 | * The temporary folder, which is used during the decompilation process.
115 | * This folder is unique during each execution of the program using the Java
116 | * UUID functionality. After the execution is done (during the cleaning),
117 | * the folder is removed but the folder named "temp" still exists, since
118 | * multiple instances of AndroidProjectCreator can run at the same time.
119 | */
120 | public static final String TEMP_LIBRARY_FOLDER = LIBRARY_FOLDER + "/temp" + "/" + UUID.randomUUID().toString();
121 |
122 | /**
123 | * The location of JAR, which was created by convertingthe classes.dex with
124 | * Dex2Jar and placed within the temporary library folder.
125 | */
126 | public static final String TEMP_CONVERTED_JAR = TEMP_LIBRARY_FOLDER + "/output.jar";
127 |
128 | /**
129 | * The location of the template project, which is used until the assembly
130 | * process is completed. After that, it is copied to the user-specified
131 | * output location and deleted
132 | */
133 | public static final String TEMP_TEMPLATE_FOLDER = TEMP_LIBRARY_FOLDER + "/ap";
134 |
135 | /**
136 | * The main folder within the source part of the template project. This
137 | * variable is used multiple times and only used within the Constants class.
138 | */
139 | private static final String TEMP_TEMPLATE_APP_SOURCE_MAIN_FOLDER = TEMP_TEMPLATE_FOLDER + "/app/src/main";
140 |
141 | /**
142 | * The location of the source code within the template project
143 | */
144 | public static final String TEMP_TEMPLATE_SOURCE = TEMP_TEMPLATE_APP_SOURCE_MAIN_FOLDER + "/java";
145 |
146 | /**
147 | * The location of the AndroidManifest file within the template project
148 | */
149 | public static final String TEMP_TEMPLATE_MANIFEST_FILE = TEMP_TEMPLATE_APP_SOURCE_MAIN_FOLDER + "/AndroidManifest.xml";
150 |
151 | /**
152 | * The location of the resources folder within the template project
153 | */
154 | public static final String TEMP_TEMPLATE_RESOURCES_FOLDER = TEMP_TEMPLATE_APP_SOURCE_MAIN_FOLDER + "/res";
155 |
156 | /**
157 | * The location of the assets within the resources folder of the template
158 | * project
159 | */
160 | public static final String TEMP_TEMPLATE_ASSET_FOLDER = TEMP_TEMPLATE_RESOURCES_FOLDER + "/assets";
161 |
162 | /**
163 | * The location of the SMALI folder within the resources folder of the
164 | * template project
165 | */
166 | public static final String TEMP_TEMPLATE_SMALI_FOLDER = TEMP_TEMPLATE_SOURCE + "/smali";
167 |
168 | /**
169 | * The location of the libraries within the template project
170 | */
171 | public static final String TEMP_TEMPLATE_LIBS_FOLDER = TEMP_TEMPLATE_SOURCE + "/libraries";
172 |
173 | /**
174 | * The temporary folder used to store the decompiled source code
175 | */
176 | public static final String TEMP_SOURCES_FOLDER = TEMP_LIBRARY_FOLDER + "/sources";
177 |
178 | /**
179 | * The location of the resources folder within the temporary folder
180 | */
181 | public static final String TEMP_RESOURCES_FOLDER = TEMP_LIBRARY_FOLDER + "/apktool/res";
182 |
183 | /**
184 | * The location of the manifest file in the temporary folder
185 | */
186 | public static final String TEMP_MANIFEST_FILE = TEMP_LIBRARY_FOLDER + "/apktool/AndroidManifest.xml";
187 |
188 | /**
189 | * The location of the libraries in the temporary folder
190 | */
191 | public static final String TEMP_LIB_FOLDER = TEMP_LIBRARY_FOLDER + "/apktool/lib";
192 |
193 | /**
194 | * The location of the Smali files in the temporary folder
195 | */
196 | public static final String TEMP_SMALI_FOLDER = TEMP_LIBRARY_FOLDER + "/apktool-smali/smali";
197 |
198 | /**
199 | * The location of the assets in the temporary folder
200 | */
201 | public static final String TEMP_ASSET_FOLDER = TEMP_LIBRARY_FOLDER + "/apktool/assets";
202 | /**
203 | * The location of APKTool within the library
204 | */
205 | public static final String APKTOOL_LIBRARY_FOLDER = LIBRARY_FOLDER + "/apktool";
206 |
207 | /**
208 | * The location of Dex2Jar within the library
209 | */
210 | public static final String DEX2JAR_LIBRARY_FOLDER = LIBRARY_FOLDER + "/dex2jar";
211 |
212 | /**
213 | * The location of Fernflower within the library
214 | */
215 | public static final String FERNFLOWER_LIBRARY_FOLDER = LIBRARY_FOLDER + "/fernflower";
216 |
217 | /**
218 | * The location of JadX within the library
219 | */
220 | public static final String JADX_LIBRARY_FOLDER = LIBRARY_FOLDER + "/jadx/bin";
221 |
222 | /**
223 | * The location of JD-CMD within the library
224 | */
225 | public static final String JDCMD_LIBRARY_FOLDER = LIBRARY_FOLDER + "/jdcmd";
226 |
227 | /**
228 | * The location of the Android Studio template project within the library
229 | */
230 | public static final String ANDROIDPROJECT_LIBRARY_FOLDER = LIBRARY_FOLDER + "/androidproject";
231 |
232 | /**
233 | * The location of the JEB3 CLI Android Decompiler script within the library
234 | */
235 | public static final String JEB3_CLI_ANDROID_SCRIPT_LIBRARY_FOLDER = LIBRARY_FOLDER + "/jeb3";
236 | /**
237 | * The location of CFR within the library
238 | */
239 | public static final String CFR_LIBRARY_FOLDER = LIBRARY_FOLDER + "/cfr";
240 |
241 | /**
242 | * The location of Procyon within the library
243 | */
244 | public static final String PROCYON_LIBRARY_FOLDER = LIBRARY_FOLDER + "/procyon";
245 | /**
246 | * The repository folder contains all cloned repositories during the
247 | * installation
248 | */
249 | public static final String REPOSITORY_FOLDER = LIBRARY_FOLDER + "/repos";
250 |
251 | /**
252 | * The location of the Dex2Jar repository on the disk
253 | */
254 | public static final String DEX2JAR_REPOSITORY_FOLDER = REPOSITORY_FOLDER + "/dex2jar";
255 |
256 | /**
257 | * The location of the JadX repository on the disk
258 | */
259 | public static final String JADX_REPOSITORY_FOLDER = REPOSITORY_FOLDER + "/jadx";
260 |
261 | /**
262 | * The location of the JD-CMD repository on the disk
263 | */
264 | public static final String JDCMD_REPOSITORY_FOLDER = REPOSITORY_FOLDER + "/jdcmd";
265 |
266 | /**
267 | * The location of the Fernflower repository on the disk
268 | */
269 | public static final String FERNFLOWER_REPOSITORY_FOLDER = REPOSITORY_FOLDER + "/fernflower";
270 |
271 | /**
272 | * The location of the APKTool repository on the disk
273 | */
274 | public static final String APKTOOL_REPOSITORY_FOLDER = REPOSITORY_FOLDER + "/apktool";
275 |
276 | /**
277 | * The location of the JEB3 CLI Android Decompiler script repository
278 | */
279 | public static final String JEB3_CLI_ANDROID_SCRIPT_REPOSITORY_FOLDER = REPOSITORY_FOLDER + "/jeb3";
280 |
281 | /**
282 | * The location of the Android Studio template repository on the disk
283 | */
284 | public static final String ANDROIDPROJECT_REPOSITORY_FOLDER = REPOSITORY_FOLDER + "/androidproject";
285 |
286 | /**
287 | * The location of the pre-built CFR decompiler repository on the disk
288 | */
289 | public static final String CFR_REPOSITORY_FOLDER = REPOSITORY_FOLDER + "/cfr";
290 |
291 | /**
292 | * The location of the pre-built ProCyon decompiler on the disk
293 | */
294 | public static final String PROCYON_REPOSITORY_FOLDER = REPOSITORY_FOLDER + "/procyon";
295 | }
296 |
--------------------------------------------------------------------------------
/src/main/java/library/ProjectInfos.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Max 'Libra' Kersten
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 | package library;
18 |
19 | import java.io.File;
20 | import java.util.ArrayList;
21 | import java.util.List;
22 | import model.Command;
23 | import model.ProjectInfo;
24 |
25 | /**
26 | * All ProjectInfo objects are created in this class. To obtain information
27 | * about a specific project, one has to call that specific function. To obtain
28 | * all ProjectInfo objects in a list, use the getAll
function.
29 | *
30 | * @author Max 'Libra' Kersten
31 | */
32 | public class ProjectInfos {
33 |
34 | /**
35 | * Get all the ProjectInfo objects in a list
36 | *
37 | * @return all embedded ProjectInfo objects in a list
38 | */
39 | public static List getAll() {
40 | List projectInfos = new ArrayList<>();
41 | projectInfos.add(getApkTool());
42 | projectInfos.add(getCfr());
43 | projectInfos.add(getDex2Jar());
44 | projectInfos.add(getFernflower());
45 | projectInfos.add(getJadX());
46 | projectInfos.add(getJdCmd());
47 | return projectInfos;
48 | }
49 |
50 | /**
51 | * Get the project information regarding Cfr
52 | *
53 | * @return Cfr project information
54 | */
55 | public static ProjectInfo getCfr() {
56 | String compileCommand;
57 | //The terminal commands in Windows differ from the ones on MacOS and Linux distributions
58 | if (!Constants.isWindows()) {
59 | compileCommand = "mvn clean package";
60 | } else {
61 | compileCommand = "mvn clean package";
62 | }
63 | File directory = new File(Constants.CFR_REPOSITORY_FOLDER);
64 | //Set the information required to find the build, extract and copy it to the proper directory
65 | Command buildCommand = new Command(compileCommand, directory); //Gradle project
66 | File buildOutputFolder = new File(Constants.CFR_REPOSITORY_FOLDER + "/target");
67 | String partialOutputName = "-SNAPSHOT.jar";
68 | return new ProjectInfo(buildCommand, buildOutputFolder, partialOutputName);
69 | }
70 |
71 | /**
72 | * Get the project information regarding Dex2Jar
73 | *
74 | * @return Dex2Jar project information
75 | */
76 | public static ProjectInfo getDex2Jar() {
77 | String compileCommand;
78 | //The terminal commands in Windows differ from the ones on MacOS and Linux distributions
79 | if (!Constants.isWindows()) {
80 | compileCommand = "./gradlew clean distZip";
81 | } else {
82 | compileCommand = "gradlew.bat clean distZip";
83 | }
84 | File directory = new File(Constants.DEX2JAR_REPOSITORY_FOLDER);
85 | //Set the information required to find the build, extract and copy it to the proper directory
86 | Command buildCommand = new Command(compileCommand, directory); //Gradle project
87 | File buildOutputFolder = new File(Constants.DEX2JAR_REPOSITORY_FOLDER + "/dex-tools/build/distributions");
88 | String partialOutputName = "-SNAPSHOT.zip";
89 | return new ProjectInfo(buildCommand, buildOutputFolder, partialOutputName);
90 | }
91 |
92 | /**
93 | * Get the project information regarding JadX
94 | *
95 | * @return JadX project information
96 | */
97 | public static ProjectInfo getJadX() {
98 | String compileCommand;
99 | //The terminal commands in Windows differ from the ones on MacOS and Linux distributions
100 | if (!Constants.isWindows()) {
101 | compileCommand = "./gradlew dist";
102 | } else {
103 | compileCommand = "gradlew.bat dist";
104 | }
105 | File directory = new File(Constants.JADX_REPOSITORY_FOLDER);
106 | //Set the information required to find the build, extract and copy it to the proper directory
107 | Command buildCommand = new Command(compileCommand, directory);
108 | File buildOutputFolder = new File(Constants.JADX_REPOSITORY_FOLDER + "/build");
109 | String partialOutputName = "jadx-dev.zip";
110 | return new ProjectInfo(buildCommand, buildOutputFolder, partialOutputName);
111 | }
112 |
113 | /**
114 | * Get the project information regarding JD-CMD
115 | *
116 | * @return JD-CMD project information
117 | */
118 | public static ProjectInfo getJdCmd() {
119 | String compileCommand;
120 | if (!Constants.isWindows()) {
121 | compileCommand = "mvn package";
122 | } else {
123 | compileCommand = "mvn package";
124 | }
125 | File directory = new File(Constants.JDCMD_REPOSITORY_FOLDER);
126 | Command buildCommand = new Command(compileCommand, directory);
127 | File buildOutputFolder = new File(Constants.JDCMD_REPOSITORY_FOLDER);
128 | String partialOutputName = "-SNAPSHOT-dist.zip";
129 | return new ProjectInfo(buildCommand, buildOutputFolder, partialOutputName);
130 | }
131 |
132 | /**
133 | * Get the project information regarding Fernflower
134 | *
135 | * @return Fernflower project information
136 | */
137 | public static ProjectInfo getFernflower() {
138 | String compileCommand;
139 | if (!Constants.isWindows()) {
140 | compileCommand = "./gradlew jar";
141 | } else {
142 | compileCommand = "gradlew.bat jar";
143 | }
144 | File directory = new File(Constants.FERNFLOWER_REPOSITORY_FOLDER);
145 | Command buildCommand = new Command(compileCommand, directory);
146 | File buildOutputFolder = new File(Constants.FERNFLOWER_REPOSITORY_FOLDER + "/build/libs");
147 | String partialOutputName = "fernflower.jar";
148 | return new ProjectInfo(buildCommand, buildOutputFolder, partialOutputName);
149 | }
150 |
151 | /**
152 | * Get the project information regarding APKTool
153 | *
154 | * @return APKTool project information
155 | */
156 | public static ProjectInfo getApkTool() {
157 | String compileCommand;
158 | if (!Constants.isWindows()) {
159 | compileCommand = "./gradlew build shadowJar";
160 | } else {
161 | compileCommand = "gradlew.bat build shadowJar";
162 | }
163 | File directory = new File(Constants.APKTOOL_REPOSITORY_FOLDER);
164 | Command buildCommand = new Command(compileCommand, directory);
165 | File buildOutputFolder = new File(Constants.APKTOOL_REPOSITORY_FOLDER + "/brut.apktool/apktool-cli/build/libs");
166 | String partialOutputName = "apktool-cli-all.jar";
167 | return new ProjectInfo(buildCommand, buildOutputFolder, partialOutputName);
168 | }
169 | }
170 |
--------------------------------------------------------------------------------
/src/main/java/library/Repositories.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Max 'Libra'
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 | package library;
18 |
19 | import enumeration.DecompilerType;
20 | import java.io.File;
21 | import java.util.ArrayList;
22 | import java.util.List;
23 | import model.Repository;
24 |
25 | /**
26 | * All repositories are created in this class. To obtain a specific repository,
27 | * one has to call that specific function. To obtain all repositories in a list,
28 | * use the getAll
function.
29 | *
30 | * @author Max 'Libra' Kersten
31 | */
32 | public class Repositories {
33 |
34 | /**
35 | * Get all repositories that are included within this project
36 | *
37 | * @return all repositories in a list
38 | */
39 | public static List getAll() {
40 | List repositories = new ArrayList<>();
41 | repositories.add(getAndroidProject());
42 | repositories.add(getApkTool());
43 | repositories.add(getCfr());
44 | repositories.add(getDex2Jar());
45 | repositories.add(getFernflower());
46 | repositories.add(getJadX());
47 | repositories.add(getJdCmd());
48 | repositories.add(getJeb3AndroidDecompilerScript());
49 | repositories.add(getProcyon());
50 | return repositories;
51 | }
52 |
53 | /**
54 | * Get the Dex2Jar repository
55 | *
56 | * @return the Dex2Jar repository
57 | */
58 | public static Repository getDex2Jar() {
59 | //Set the information for the repository
60 | String name = DecompilerType.DEX2JAR.toString().toLowerCase();
61 | String url = "https://github.com/pxb1988/dex2jar.git";
62 | File directory = new File(Constants.DEX2JAR_REPOSITORY_FOLDER);
63 | String branch = "2.x";
64 | return new Repository(name, url, directory, branch);
65 | }
66 |
67 | /**
68 | * Get the JadX repository
69 | *
70 | * @return the JadX repository
71 | */
72 | public static Repository getJadX() {
73 | //Set the information for the repository
74 | String name = DecompilerType.JADX.toString().toLowerCase();
75 | String url = "https://github.com/skylot/jadx.git";
76 | File directory = new File(Constants.JADX_REPOSITORY_FOLDER);
77 | String branch = "master";
78 |
79 | return new Repository(name, url, directory, branch);
80 | }
81 |
82 | /**
83 | * Get the JD-CMD repository
84 | *
85 | * @return the JD-CMD repository
86 | */
87 | public static Repository getJdCmd() {
88 | String name = DecompilerType.JDCMD.toString().toLowerCase();
89 | //String url = "https://github.com/kwart/jd-cmd.git";
90 | String url = "https://github.com/ThisIsLibra/jdcmd.git";
91 | File directory = new File(Constants.JDCMD_REPOSITORY_FOLDER);
92 | String branch = "main";
93 | return new Repository(name, url, directory, branch);
94 | }
95 |
96 | /**
97 | * Get the Fernflower repository
98 | *
99 | * @return the Fernflower repository
100 | */
101 | public static Repository getFernflower() {
102 | String name = DecompilerType.FERNFLOWER.toString().toLowerCase();
103 | String url = "https://github.com/fesh0r/fernflower.git";
104 | File directory = new File(Constants.FERNFLOWER_REPOSITORY_FOLDER);
105 | String branch = "master";
106 | return new Repository(name, url, directory, branch);
107 | }
108 |
109 | /**
110 | * Get the APKTool repository
111 | *
112 | * @return the APKTool repository
113 | */
114 | public static Repository getApkTool() {
115 | String name = DecompilerType.APKTOOL.toString().toLowerCase();
116 | String url = "https://github.com/iBotPeaches/Apktool.git";
117 | File directory = new File(Constants.APKTOOL_REPOSITORY_FOLDER);
118 | String branch = "master";
119 | return new Repository(name, url, directory, branch);
120 | }
121 |
122 | /**
123 | * Get the Android Studio template project
124 | *
125 | * @return the Android Studio template project
126 | */
127 | public static Repository getAndroidProject() {
128 | String name = "androidproject";
129 | //String name = "androidstudioproject";
130 | String url = "https://github.com/ThisIsLibra/AndroidStudioProject.git";
131 | File directory = new File(Constants.ANDROIDPROJECT_REPOSITORY_FOLDER);
132 | String branch = "main";
133 | return new Repository(name, url, directory, branch);
134 | }
135 |
136 | /**
137 | * Get the pre-built CFR decompiler
138 | *
139 | * @return the pre-built CFR decompiler
140 | */
141 | public static Repository getCfr() {
142 | String name = DecompilerType.CFR.toString().toLowerCase();
143 | String url = "https://github.com/leibnitz27/cfr.git";
144 | File directory = new File(Constants.CFR_REPOSITORY_FOLDER);
145 | String branch = "master";
146 | return new Repository(name, url, directory, branch);
147 | }
148 |
149 | /**
150 | * Get the pre-built Procyon decompiler
151 | *
152 | * @return the pre-built Procyon decompiler
153 | */
154 | public static Repository getProcyon() {
155 | String name = DecompilerType.PROCYON.toString().toLowerCase();
156 | String url = "https://github.com/ThisIsLibra/procyon-decompiler.git";
157 | File directory = new File(Constants.PROCYON_REPOSITORY_FOLDER);
158 | String branch = "apc-1.1";
159 | return new Repository(name, url, directory, branch);
160 | }
161 |
162 | /**
163 | * Get the script to decompile an Android Package (APK) with JEB3
164 | *
165 | * @return the repository with the JEB3 script
166 | */
167 | public static Repository getJeb3AndroidDecompilerScript() {
168 | String name = DecompilerType.JEB3.toString().toLowerCase();
169 | String url = "https://github.com/ThisIsLibra/jeb3-cli-android-decompiler.git";
170 | File directory = new File(Constants.JEB3_CLI_ANDROID_SCRIPT_REPOSITORY_FOLDER);
171 | String branch = "main";
172 | return new Repository(name, url, directory, branch);
173 | }
174 | }
175 |
--------------------------------------------------------------------------------
/src/main/java/library/Tools.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Max 'Libra' Kersten
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 | package library;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 | import model.Tool;
22 |
23 | /**
24 | * All tools that are included in this project can be found in this class. A
25 | * tool consists of two parts. The Repository and the ProjectInfo, both of which
26 | * contain information that is required during the cloning and building.
27 | *
28 | * @author Max 'Libra' Kersten
29 | */
30 | public class Tools {
31 |
32 | /**
33 | * Get all tools that are included in this project
34 | *
35 | * @return a list of all tools
36 | */
37 | public static List getTools() {
38 | List tools = new ArrayList<>();
39 | tools.add(getAndroidStudioProject());
40 | tools.add(getApkTool());
41 | tools.add(getCfr());
42 | tools.add(getDex2Jar());
43 | tools.add(getJadX());
44 | tools.add(getJdCmd());
45 | tools.add(getJeb3AndroidDecompilerScript());
46 | tools.add(getFernflower());
47 | tools.add(getProcyon());
48 | return tools;
49 | }
50 |
51 | /**
52 | * The Dex2Jar tool
53 | *
54 | * @return the Dex2Jar tool object
55 | */
56 | private static Tool getDex2Jar() {
57 | return new Tool(Repositories.getDex2Jar(), ProjectInfos.getDex2Jar());
58 | }
59 |
60 | /**
61 | * The JadX tool
62 | *
63 | * @return the JadX tool object
64 | */
65 | private static Tool getJadX() {
66 | return new Tool(Repositories.getJadX(), ProjectInfos.getJadX());
67 | }
68 |
69 | /**
70 | * The JD-CMD tool
71 | *
72 | * @return the JD-CMD tool object
73 | */
74 | private static Tool getJdCmd() {
75 | return new Tool(Repositories.getJdCmd(), ProjectInfos.getJdCmd());
76 | }
77 |
78 | /**
79 | * The Fernflower tool
80 | *
81 | * @return the Fernflower tool object
82 | */
83 | private static Tool getFernflower() {
84 | return new Tool(Repositories.getFernflower(), ProjectInfos.getFernflower());
85 | }
86 |
87 | /**
88 | * The APKTool tool
89 | *
90 | * @return the APKTool tool object
91 | */
92 | private static Tool getApkTool() {
93 | return new Tool(Repositories.getApkTool(), ProjectInfos.getApkTool());
94 | }
95 |
96 | /**
97 | * The Android Studio template project
98 | *
99 | * @return the Android Studio template tool object
100 | */
101 | private static Tool getAndroidStudioProject() {
102 | return new Tool(Repositories.getAndroidProject(), null);
103 | }
104 |
105 | /**
106 | * The pre-built CFR decompiler tool
107 | *
108 | * @return the pre-built CFR decompiler tool object
109 | */
110 | private static Tool getCfr() {
111 | return new Tool(Repositories.getCfr(), ProjectInfos.getCfr());
112 | }
113 |
114 | /**
115 | * The pre-built Procyon decompiler tool
116 | *
117 | * @return the pre-built Procyon decompiler tool object
118 | */
119 | private static Tool getProcyon() {
120 | return new Tool(Repositories.getProcyon(), null);
121 | }
122 |
123 | /**
124 | * The JEB3 Android decompiler script
125 | *
126 | * @return the tool object containing the repository
127 | */
128 | private static Tool getJeb3AndroidDecompilerScript() {
129 | return new Tool(Repositories.getJeb3AndroidDecompilerScript(), null);
130 | }
131 | }
132 |
--------------------------------------------------------------------------------
/src/main/java/model/ArgumentPackage.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Max 'Libra' Kersten
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 | package model;
18 |
19 | import enumeration.Action;
20 | import enumeration.DecompilerType;
21 | import java.io.File;
22 |
23 | /**
24 | * The ArgumentPackage class is used as a single object to be shared between the
25 | * ArgumentParser and the ArgumentManager. Depending on the decompiler, some
26 | * values may be null within this class, which is fine since they're not
27 | * required.
28 | *
29 | * @author Max 'Libra' Kersten
30 | */
31 | public class ArgumentPackage {
32 |
33 | private DecompilerType decompilerType;
34 | private File apk;
35 | private File outputLocation;
36 | private File jeb3Folder;
37 | private Action action;
38 |
39 | /**
40 | * This constructor is used when an action requires no parameters, such as
41 | * INSTALL, UPDATE or ERROR
42 | *
43 | * @param action the action to be set
44 | */
45 | public ArgumentPackage(Action action) {
46 | this.action = action;
47 | }
48 |
49 | /**
50 | * This constructor is used to save the requested decompiler, the APK file
51 | * and the output location for the Android Studio Project. Note that the
52 | * action within this object is set to DECOMPILE by default.
53 | *
54 | * @param decompilerType the requested decompiler
55 | * @param apk the APK to be decompiled
56 | * @param outputLocation the output location for the Android Studio project
57 | */
58 | public ArgumentPackage(DecompilerType decompilerType, File apk, File outputLocation) {
59 | this.action = Action.DECOMPILE;
60 | this.decompilerType = decompilerType;
61 | this.apk = apk;
62 | this.outputLocation = outputLocation;
63 | }
64 |
65 | /**
66 | * This constructor is to be used when the specified decompiler is JEB3. The
67 | * action is set to DECOMPILE and the decompiler type to JEB3 by default.
68 | *
69 | * @param apk the APK to decompile
70 | * @param outputLocation the output location of the Android Studio project
71 | * @param jeb3Folder the folder in which JEB3 is installed, i.e.
72 | * /path/to/jeb3-pro
73 | */
74 | public ArgumentPackage(File apk, File outputLocation, File jeb3Folder) {
75 | this.action = Action.DECOMPILE;
76 | this.decompilerType = DecompilerType.JEB3;
77 | this.apk = apk;
78 | this.outputLocation = outputLocation;
79 | this.jeb3Folder = jeb3Folder;
80 | }
81 |
82 | /**
83 | * Get the action that was set by the ArgumentParser
84 | *
85 | * @return the action to execute
86 | */
87 | public Action getAction() {
88 | return action;
89 | }
90 |
91 | /**
92 | * The decompiler type that was set by the ArgumentParser
93 | *
94 | * @return the requested decompiler
95 | */
96 | public DecompilerType getDecompilerType() {
97 | return decompilerType;
98 | }
99 |
100 | /**
101 | * The APK file object that was set by the ArgumentParser
102 | *
103 | * @return the APK file object
104 | */
105 | public File getApk() {
106 | return apk;
107 | }
108 |
109 | /**
110 | * The output location of the Android Studio Project
111 | *
112 | * @return the output location file object
113 | */
114 | public File getOutputLocation() {
115 | return outputLocation;
116 | }
117 |
118 | /**
119 | * The file object of the JEB3 folder
120 | *
121 | * @return the JEB3 folder object
122 | */
123 | public File getJeb3Folder() {
124 | return jeb3Folder;
125 | }
126 |
127 | }
128 |
--------------------------------------------------------------------------------
/src/main/java/model/Command.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Max 'Libra' Kersten
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 | package model;
18 |
19 | import java.io.File;
20 | import java.io.IOException;
21 | import java.io.InputStream;
22 | import java.io.*;
23 | import java.util.logging.Level;
24 | import java.util.logging.Logger;
25 | import library.Constants;
26 |
27 | /**
28 | * Execute a command line command on any platform (Windows, MacOS and Linux
29 | * distributions) and receive the results back. The results are shown through
30 | * the default output stream of this application.
31 | *
32 | * @author Max 'Libra' Kersten
33 | */
34 | public class Command {
35 |
36 | /**
37 | * The directory in which the command is executed
38 | */
39 | private final File workingDirectory;
40 |
41 | /**
42 | * The command which is to be executed
43 | */
44 | private final String command;
45 |
46 | /**
47 | * Create an instance of the command class, which builds a Gradle project
48 | *
49 | * @param command the command which is required to compile the project
50 | * @param workingDirectory the directory where the project resides
51 | */
52 | public Command(String command, File workingDirectory) {
53 | this.command = command;
54 | this.workingDirectory = workingDirectory;
55 | }
56 |
57 | /**
58 | * Executes the command based on the previously provided information
59 | *
60 | * Original code taken from Pepe (edited by tvanfosson) from
61 | * https://stackoverflow.com/a/5437863 Code altered by Max 'Libra' Kersten
62 | *
63 | * @throws IOException if something within the file handling goes wrong
64 | */
65 | public void execute() throws IOException {
66 | try {
67 | String[] processName = new String[1];
68 | if (Constants.isWindows()) {
69 | processName[0] = "cmd";
70 | } else {
71 | processName[0] = "sh";
72 | }
73 | Process p = Runtime.getRuntime().exec(processName, null, workingDirectory);
74 | new Thread(new SyncPipe(p.getErrorStream(), System.err)).start();
75 | new Thread(new SyncPipe(p.getInputStream(), System.out)).start();
76 | PrintWriter stdin = new PrintWriter(p.getOutputStream());
77 | //Enter commands for the shell here
78 | stdin.println(command);
79 | stdin.close();
80 | p.waitFor();
81 | //New line to avoid the next line to be printed on the same line as the one which ends the command
82 | System.out.println("");
83 | } catch (IOException | InterruptedException ex) {
84 | throw new IOException("The working directory (" + workingDirectory.getAbsolutePath() + ") can not be found or the command (" + command + ") can not be found!");
85 | }
86 | }
87 | }
88 |
89 | /**
90 | * Code used to execute commands and read the output stream back to another
91 | * stream, in this case, the standard output stream.
92 | *
93 | * The original code is taken from Pepe (and was edited by tvanfosson) from
94 | * https://stackoverflow.com/a/5437863
95 | *
96 | * @author Pepe and tvanfosson
97 | */
98 | class SyncPipe implements Runnable {
99 |
100 | public SyncPipe(InputStream istrm, OutputStream ostrm) {
101 | istrm_ = istrm;
102 | ostrm_ = ostrm;
103 | }
104 |
105 | public void run() {
106 | final byte[] buffer = new byte[1024];
107 | try {
108 | for (int length = 0; (length = istrm_.read(buffer)) != -1;) {
109 |
110 | ostrm_.write(buffer, 0, length);
111 | }
112 | } catch (IOException ex) {
113 | Logger.getLogger(SyncPipe.class.getName()).log(Level.SEVERE, null, ex);
114 | }
115 | }
116 | private final OutputStream ostrm_;
117 | private final InputStream istrm_;
118 | }
119 |
--------------------------------------------------------------------------------
/src/main/java/model/ProjectInfo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Max 'Libra' Kersten
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 | package model;
18 |
19 | import java.io.File;
20 |
21 | /**
22 | * The ProjectInfo class contains additional information for a repository
23 | *
24 | * @author Max 'Libra' Kersten
25 | */
26 | public class ProjectInfo {
27 |
28 | /**
29 | * The command to build the project
30 | */
31 | private Command buildCommand;
32 |
33 | /**
34 | * The folder in which the output of the build is put, as described by the
35 | * programmer who created the original project (a.k.a. tool)
36 | */
37 | private final File buildOutputFolder;
38 |
39 | /**
40 | * In some cases, the version number is in the name of the build output, so
41 | * only the partial name can be used. If the full name is known, it can be
42 | * used here as well.
43 | */
44 | private final String partialOutputName;
45 |
46 | /**
47 | * Create an object with information about a repository
48 | *
49 | * @param buildCommand The command to build the project
50 | * @param buildOutputFolder The folder in which the output of the build is
51 | * put, as described by the programmer who created the original project
52 | * (a.k.a. tool)
53 | * @param partialOutputName In some cases, the version number is in the name
54 | * of the build output, so only the partial name can be used. If the full
55 | * name is known, it can be used here as well.
56 | */
57 | public ProjectInfo(Command buildCommand, File buildOutputFolder, String partialOutputName) {
58 | this.buildOutputFolder = buildOutputFolder;
59 | this.buildCommand = buildCommand;
60 | this.partialOutputName = partialOutputName;
61 | }
62 |
63 | /**
64 | * Get the command which is used to build the repository
65 | *
66 | * @return the build command
67 | */
68 | public Command getBuildCommand() {
69 | return buildCommand;
70 | }
71 |
72 | /**
73 | * Get the location where the building process places its output
74 | *
75 | * @return the output folder of the build
76 | */
77 | public File getBuildOutputFolder() {
78 | return buildOutputFolder;
79 | }
80 |
81 | /**
82 | * In some cases, the version number is in the name of the build output, so
83 | * only the partial name can be used. If the full name is known, it can be
84 | * used here as well.
85 | *
86 | * @return the (partial) output name
87 | */
88 | public String getPartialOutputName() {
89 | return partialOutputName;
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/src/main/java/model/Repository.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Max 'Libra' Kersten
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 | package model;
18 |
19 | import java.io.File;
20 | import java.io.IOException;
21 | import java.io.PrintWriter;
22 | import static java.util.Collections.singleton;
23 | import org.eclipse.jgit.api.Git;
24 | import org.eclipse.jgit.api.errors.GitAPIException;
25 | import org.eclipse.jgit.lib.TextProgressMonitor;
26 |
27 | /**
28 | * The repository from which a tool is cloned
29 | *
30 | * @author Max 'Libra' Kersten
31 | */
32 | public class Repository {
33 |
34 | /**
35 | * The name of the repository
36 | */
37 | private final String name;
38 |
39 | /**
40 | * The URL of the repository
41 | */
42 | private final String url;
43 |
44 | /**
45 | * The local directory in which the cloned repository should be saved
46 | */
47 | private final File directory;
48 |
49 | /**
50 | * The branch in the repository which should be used
51 | */
52 | private final String branch;
53 |
54 | /**
55 | * Create a repository object which can be used to clone the repository with
56 | * the provided information
57 | *
58 | * @param name The name of the repository
59 | * @param url The URL of the repository
60 | * @param directory The local directory in which the cloned repository
61 | * should be saved
62 | * @param branch The branch in the repository which should be used
63 | */
64 | public Repository(String name, String url, File directory, String branch) {
65 | this.name = name;
66 | this.url = url;
67 | this.directory = directory;
68 | this.branch = branch;
69 | }
70 |
71 | /**
72 | * Gets the name of the repository
73 | *
74 | * @return
75 | */
76 | public String getName() {
77 | return name;
78 | }
79 |
80 | /**
81 | * Function to clone the repository
82 | *
83 | * @throws IOException if something goes wrong, this exception is thrown
84 | */
85 | public void cloneRepository() throws IOException {
86 | try {
87 | Git.cloneRepository()
88 | .setProgressMonitor(new TextProgressMonitor(new PrintWriter(System.out)))
89 | .setURI(url)
90 | .setDirectory(directory)
91 | .setBranchesToClone(singleton(branch))
92 | .setBranch(branch)
93 | .call();
94 |
95 | } catch (GitAPIException ex) {
96 | //Because the GitAPIException is abstract and cannot be instantiated, another (similar) exception is used
97 | throw new IOException("[+]There was an error cloing " + name + ". Verify your internet connection and the permissions of the folder!");
98 | }
99 | }
100 |
101 | /**
102 | * Updates the current repository
103 | *
104 | * @throws IOException if the Git pull goes wrong of if the directory cannot
105 | * be found
106 | */
107 | public void updateRepository() throws IOException {
108 | try {
109 | Git git = Git.open(directory);
110 | if (git.pull().setRemoteBranchName(branch).call().isSuccessful()) {
111 | System.out.println("[+]Git pull succesful for " + name);
112 | }
113 | } catch (GitAPIException ex) {
114 | //Because the GitAPIException is abstract and cannot be instantiated, another (similar) exception is used
115 | throw new IOException("Git pull failed, AndroidProjectCreator will now exit");
116 | } catch (IOException ex) {
117 | throw new IOException("Repository directory not found, reinstall AndroidProjectCreator and check your permissions in this folder. AndroidProjectCreator will now exit.");
118 | }
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/src/main/java/model/Tool.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2018 Max 'Libra' Kersten
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 | package model;
18 |
19 | /**
20 | * A tool is a wrapper for a Repository object and a ProjectInfo object, as long
21 | * as both contain information about the same repository and project.
22 | *
23 | * @author Max 'Libra' Kersten
24 | */
25 | public class Tool {
26 |
27 | /**
28 | * The repository of this tool
29 | */
30 | private Repository repository;
31 |
32 | /**
33 | * The project info of this tool
34 | */
35 | private ProjectInfo projectInfo;
36 |
37 | /**
38 | * A tool consists of a repository (which is cloned) and the project info
39 | * (how to build the tool from the repository)
40 | *
41 | * @param repository the repository
42 | * @param projectInfo additional information about the repository
43 | */
44 | public Tool(Repository repository, ProjectInfo projectInfo) {
45 | this.repository = repository;
46 | this.projectInfo = projectInfo;
47 | }
48 |
49 | /**
50 | * Gets the repository of this tool
51 | *
52 | * @return the repository
53 | */
54 | public Repository getRepository() {
55 | return repository;
56 | }
57 |
58 | /**
59 | * Gets the project info of this tool
60 | *
61 | * @return the project info
62 | */
63 | public ProjectInfo getProjectInfo() {
64 | return projectInfo;
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/target/AndroidProjectCreator-1.5.2-stable-jar-with-dependencies.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/ThisIsLibra/AndroidProjectCreator/6d99c5d7690c9a44fd67fdb3895c1d21a17b7bf3/target/AndroidProjectCreator-1.5.2-stable-jar-with-dependencies.jar
--------------------------------------------------------------------------------