├── .classpath ├── .gitattributes ├── .gitignore ├── .project ├── LICENSE ├── README.md ├── lib └── asm-v7.jar └── src ├── by └── radioegor146 │ ├── CachedFieldInfo.java │ ├── CachedMethodInfo.java │ ├── Main.java │ └── NativeObfuscator.java ├── ru └── gravit │ └── launchserver │ └── asm │ ├── ClassMetadataReader.java │ └── SafeClassWriter.java └── sources ├── CMakeLists.txt ├── android ├── CMakeLists.txt ├── jvmti.h └── native_jvm_output.cpp ├── cppsnippets.properties ├── native_jvm.cpp ├── native_jvm.hpp ├── native_jvm_output.cpp ├── native_jvm_output.hpp ├── string_pool.cpp └── string_pool.hpp /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.* linguist-language=Java 2 | 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .settings/ 2 | bin/ 3 | test/ 4 | native-obfuscator.jar 5 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | native-obfuscator 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.jdt.core.javanature 16 | 17 | 18 | -------------------------------------------------------------------------------- /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 | # native-obfuscator plus 2 | Java .class to .cpp converter for use with JNI 3 | 4 | ### Usage 5 | java -jar native-obfuscator.jar [libraries dir] 6 | java -jar native-obfuscator.jar classes.jar classes true libDir 7 | 8 | ### Support 9 | Android Jar (inside .class) 10 | Jar 11 | 12 | ### Credits 13 | native-obfuscator: radioegor146 14 | 15 | ### License 16 | ASM: https://asm.ow2.io/license.html 17 | -------------------------------------------------------------------------------- /lib/asm-v7.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/qtfreet00/native-obfuscator/1892efb6e7d42a220a3bb0f14a96df4dc8707986/lib/asm-v7.jar -------------------------------------------------------------------------------- /src/by/radioegor146/CachedFieldInfo.java: -------------------------------------------------------------------------------- 1 | package by.radioegor146; 2 | 3 | import java.util.Objects; 4 | 5 | public class CachedFieldInfo { 6 | public String clazz; 7 | public String name; 8 | public String desc; 9 | public boolean isStatic; 10 | 11 | public CachedFieldInfo(String clazz, String name, String desc, boolean isStatic) { 12 | this.clazz = clazz; 13 | this.name = name; 14 | this.desc = desc; 15 | this.isStatic = isStatic; 16 | } 17 | 18 | @Override 19 | public boolean equals(Object obj) { 20 | if (this == obj) { 21 | return true; 22 | } 23 | if (obj == null) { 24 | return false; 25 | } 26 | if (getClass() != obj.getClass()) { 27 | return false; 28 | } 29 | final CachedFieldInfo other = (CachedFieldInfo) obj; 30 | if (!Objects.equals(this.clazz, other.clazz)) { 31 | return false; 32 | } 33 | if (!Objects.equals(this.name, other.name)) { 34 | return false; 35 | } 36 | if (!Objects.equals(this.desc, other.desc)) { 37 | return false; 38 | } 39 | return Objects.equals(this.isStatic, other.isStatic); 40 | } 41 | 42 | @Override 43 | public int hashCode() { 44 | int hash = 7; 45 | hash = 97 * hash + Objects.hashCode(this.clazz); 46 | hash = 97 * hash + Objects.hashCode(this.name); 47 | hash = 97 * hash + Objects.hashCode(this.desc); 48 | hash = 97 * hash + Objects.hashCode(this.isStatic); 49 | return hash; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/by/radioegor146/CachedMethodInfo.java: -------------------------------------------------------------------------------- 1 | package by.radioegor146; 2 | 3 | import java.util.Objects; 4 | 5 | public class CachedMethodInfo { 6 | public String clazz; 7 | public String name; 8 | public String desc; 9 | public boolean isStatic; 10 | 11 | public CachedMethodInfo(String clazz, String name, String desc, boolean isStatic) { 12 | this.clazz = clazz; 13 | this.name = name; 14 | this.desc = desc; 15 | this.isStatic = isStatic; 16 | } 17 | 18 | @Override 19 | public boolean equals(Object obj) { 20 | if (this == obj) { 21 | return true; 22 | } 23 | if (obj == null) { 24 | return false; 25 | } 26 | if (getClass() != obj.getClass()) { 27 | return false; 28 | } 29 | final CachedMethodInfo other = (CachedMethodInfo) obj; 30 | if (!Objects.equals(this.clazz, other.clazz)) { 31 | return false; 32 | } 33 | if (!Objects.equals(this.name, other.name)) { 34 | return false; 35 | } 36 | if (!Objects.equals(this.desc, other.desc)) { 37 | return false; 38 | } 39 | return Objects.equals(this.isStatic, other.isStatic); 40 | } 41 | 42 | @Override 43 | public int hashCode() { 44 | int hash = 7; 45 | hash = 97 * hash + Objects.hashCode(this.clazz); 46 | hash = 97 * hash + Objects.hashCode(this.name); 47 | hash = 97 * hash + Objects.hashCode(this.desc); 48 | hash = 97 * hash + Objects.hashCode(this.isStatic); 49 | return hash; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/by/radioegor146/Main.java: -------------------------------------------------------------------------------- 1 | package by.radioegor146; 2 | 3 | import java.io.IOException; 4 | import java.nio.file.FileVisitOption; 5 | import java.nio.file.FileVisitResult; 6 | import java.nio.file.Files; 7 | import java.nio.file.Path; 8 | import java.nio.file.Paths; 9 | import java.nio.file.SimpleFileVisitor; 10 | import java.nio.file.attribute.BasicFileAttributes; 11 | import java.util.ArrayList; 12 | import java.util.Collections; 13 | import java.util.List; 14 | import java.util.Objects; 15 | 16 | public class Main { 17 | 18 | private static final String VERSION = "1.7b+"; 19 | 20 | public static void main(String[] args) throws IOException { 21 | System.out.println("native-obfuscator v" + VERSION); 22 | if (args.length < 3) { 23 | System.err.println("java -jar native-obfuscator.jar [libraries dir]"); 24 | System.err.println("java -jar native-obfuscator.jar classes.jar classes true androidLibDir"); 25 | return; 26 | } 27 | System.out.println("Android "+ args[2]); 28 | String libsDir = args.length < 4 ? null : args[3]; 29 | List libs = new ArrayList<>(); 30 | if (libsDir != null) 31 | Files.walkFileTree(Paths.get(libsDir), Collections.singleton(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new SimpleFileVisitor() { 32 | @Override 33 | public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) 34 | throws IOException 35 | { 36 | Objects.requireNonNull(file); 37 | Objects.requireNonNull(attrs); 38 | if (file.toString().endsWith(".jar") || file.toString().endsWith(".zip")) { 39 | libs.add(file); 40 | System.out.println("library " + file.getFileName()); 41 | } 42 | return super.visitFile(file, attrs); 43 | } 44 | }); 45 | NativeObfuscator instance = new NativeObfuscator(); 46 | instance.process(Paths.get(args[0]), Paths.get(args[1]), libs, Boolean.valueOf(args[2])); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/by/radioegor146/NativeObfuscator.java: -------------------------------------------------------------------------------- 1 | package by.radioegor146; 2 | 3 | import java.io.BufferedWriter; 4 | import java.io.ByteArrayOutputStream; 5 | import java.io.File; 6 | import java.io.FileOutputStream; 7 | import java.io.IOException; 8 | import java.io.InputStream; 9 | import java.io.OutputStream; 10 | import java.io.OutputStreamWriter; 11 | import java.lang.reflect.Field; 12 | import java.nio.charset.StandardCharsets; 13 | import java.nio.file.Files; 14 | import java.nio.file.Path; 15 | import java.nio.file.StandardOpenOption; 16 | import java.util.ArrayList; 17 | import java.util.Arrays; 18 | import java.util.HashMap; 19 | import java.util.List; 20 | import java.util.Map; 21 | import java.util.Properties; 22 | import java.util.Random; 23 | import java.util.TreeMap; 24 | import java.util.jar.Attributes.Name; 25 | import java.util.jar.JarEntry; 26 | import java.util.jar.JarFile; 27 | import java.util.jar.Manifest; 28 | import java.util.regex.Matcher; 29 | import java.util.regex.Pattern; 30 | import java.util.stream.Collectors; 31 | import java.util.stream.IntStream; 32 | import java.util.stream.Stream; 33 | import java.util.zip.ZipEntry; 34 | import java.util.zip.ZipOutputStream; 35 | 36 | import org.objectweb.asm.*; 37 | import org.objectweb.asm.tree.AbstractInsnNode; 38 | import org.objectweb.asm.tree.ClassNode; 39 | import org.objectweb.asm.tree.FieldInsnNode; 40 | import org.objectweb.asm.tree.FrameNode; 41 | import org.objectweb.asm.tree.IincInsnNode; 42 | import org.objectweb.asm.tree.InsnList; 43 | import org.objectweb.asm.tree.InsnNode; 44 | import org.objectweb.asm.tree.IntInsnNode; 45 | import org.objectweb.asm.tree.InvokeDynamicInsnNode; 46 | import org.objectweb.asm.tree.JumpInsnNode; 47 | import org.objectweb.asm.tree.LabelNode; 48 | import org.objectweb.asm.tree.LdcInsnNode; 49 | import org.objectweb.asm.tree.LineNumberNode; 50 | import org.objectweb.asm.tree.LookupSwitchInsnNode; 51 | import org.objectweb.asm.tree.MethodInsnNode; 52 | import org.objectweb.asm.tree.MethodNode; 53 | import org.objectweb.asm.tree.MultiANewArrayInsnNode; 54 | import org.objectweb.asm.tree.TableSwitchInsnNode; 55 | import org.objectweb.asm.tree.TryCatchBlockNode; 56 | import org.objectweb.asm.tree.TypeInsnNode; 57 | import org.objectweb.asm.tree.VarInsnNode; 58 | import ru.gravit.launchserver.asm.ClassMetadataReader; 59 | import ru.gravit.launchserver.asm.SafeClassWriter; 60 | 61 | public class NativeObfuscator { 62 | 63 | private static final Pattern PATTERN = Pattern.compile("([^a-zA-Z_0-9])"); 64 | private static final Map INSTRUCTIONS = new HashMap<>(); 65 | private static final Properties CPP_SNIPPETS = new Properties(); 66 | private static final String[] CPP_TYPES = { "void", // 0 67 | "jboolean", // 1 68 | "jchar", // 2 69 | "jbyte", // 3 70 | "jshort", // 4 71 | "jint", // 5 72 | "jfloat", // 6 73 | "jlong", // 7 74 | "jdouble", // 8 75 | "jarray", // 9 76 | "jobject", // 10 77 | "jobject" // 11 78 | }; 79 | 80 | private static final String[] JAVA_DESCRIPTORS = { "V", // 0 81 | "Z", // 1 82 | "C", // 2 83 | "B", // 3 84 | "S", // 4 85 | "I", // 5 86 | "F", // 6 87 | "J", // 7 88 | "D", // 8 89 | "Ljava/lang/Object;", // 9 90 | "Ljava/lang/Object;", // 10 91 | "Ljava/lang/Object;" // 11 92 | }; 93 | 94 | private static final int[] TYPE_TO_STACK = { 1, 1, 1, 1, 1, 1, 1, 2, 2, 0, 0, 0 }; 95 | 96 | private static final int[] STACK_TO_STACK = { 1, 1, 1, 2, 2, 0, 0, 0, 0 }; 97 | 98 | static { 99 | try { 100 | for (Field f : Opcodes.class.getFields()) 101 | INSTRUCTIONS.put((int) f.get(null), f.getName()); 102 | CPP_SNIPPETS.load( 103 | NativeObfuscator.class.getClassLoader().getResourceAsStream("sources/cppsnippets.properties")); 104 | } catch (IllegalArgumentException | IllegalAccessException | IOException ex) { 105 | throw new RuntimeException(ex); 106 | } 107 | } 108 | 109 | private String escapeCppNameString(String value) { 110 | Matcher m = PATTERN.matcher(value); 111 | StringBuffer sb = new StringBuffer(value.length()); 112 | while (m.find()) 113 | m.appendReplacement(sb, String.valueOf((int) m.group(1).charAt(0))); 114 | m.appendTail(sb); 115 | String output = sb.toString(); 116 | if (output.length() > 0 && (output.charAt(0) >= '0' && output.charAt(0) <= '9')) 117 | output = "_" + output; 118 | return output; 119 | } 120 | 121 | private Map createMap(Object... parts) { 122 | HashMap tokens = new HashMap<>(); 123 | for (int i = 0; i < parts.length; i += 2) { 124 | tokens.put(parts[i].toString(), parts[i + 1].toString()); 125 | } 126 | return tokens; 127 | } 128 | 129 | private String dynamicFormat(String string, Map tokens) { 130 | String patternString = "\\$(" 131 | + String.join("|", tokens.keySet().stream().map(x -> unicodify(x)).collect(Collectors.toList())) + ")"; 132 | Pattern pattern = Pattern.compile(patternString); 133 | Matcher matcher = pattern.matcher(string); 134 | 135 | StringBuffer sb = new StringBuffer(); 136 | while (matcher.find()) { 137 | matcher.appendReplacement(sb, Matcher.quoteReplacement(tokens.get(matcher.group(1)))); 138 | } 139 | matcher.appendTail(sb); 140 | 141 | return sb.toString(); 142 | } 143 | 144 | private String dynamicRawFormat(String string, Map tokens) { 145 | if (tokens.isEmpty()) 146 | return string; 147 | String patternString = "(" 148 | + String.join("|", tokens.keySet().stream().map(x -> unicodify(x)).collect(Collectors.toList())) + ")"; 149 | Pattern pattern = Pattern.compile(patternString); 150 | Matcher matcher = pattern.matcher(string); 151 | 152 | StringBuffer sb = new StringBuffer(); 153 | while (matcher.find()) { 154 | matcher.appendReplacement(sb, Matcher.quoteReplacement(tokens.get(matcher.group(1)))); 155 | } 156 | matcher.appendTail(sb); 157 | 158 | return sb.toString(); 159 | } 160 | 161 | private final HashMap stringPool = new HashMap<>(); 162 | private final HashMap cachedClasses = new HashMap<>(); 163 | private final HashMap cachedMethods = new HashMap<>(); 164 | private final HashMap cachedFields = new HashMap<>(); 165 | private StringBuilder ifaceStaticNativeMethodsSb = new StringBuilder(); 166 | private StringBuilder nativeMethodsSb = new StringBuilder(); 167 | private Map invokeDynamics = new HashMap<>(); 168 | 169 | private int currentLength = 0; 170 | 171 | private String getStringPooledString(String value) { 172 | if (!stringPool.containsKey(value)) { 173 | stringPool.put(value, currentLength); 174 | currentLength += value.getBytes(StandardCharsets.UTF_8).length + 1; 175 | } 176 | return "((char *)(string_pool + " + stringPool.get(value) + "LL))"; 177 | } 178 | 179 | private String getCachedClassPointer(String name) { 180 | if (!cachedClasses.containsKey(name)) 181 | cachedClasses.put(name, cachedClasses.size()); 182 | return "(cclasses[" + cachedClasses.get(name) + "])"; 183 | } 184 | 185 | private String getCachedMethodPointer(String clazz, String name, String desc, boolean isStatic) { 186 | if (!cachedMethods.containsKey(new CachedMethodInfo(clazz, name, desc, isStatic))) 187 | cachedMethods.put(new CachedMethodInfo(clazz, name, desc, isStatic), cachedMethods.size()); 188 | return "(cmethods[" + cachedMethods.get(new CachedMethodInfo(clazz, name, desc, isStatic)) + "].load())"; 189 | } 190 | 191 | private String getCachedFieldPointer(String clazz, String name, String desc, boolean isStatic) { 192 | if (!cachedFields.containsKey(new CachedFieldInfo(clazz, name, desc, isStatic))) 193 | cachedFields.put(new CachedFieldInfo(clazz, name, desc, isStatic), cachedFields.size()); 194 | return "(cfields[" + cachedFields.get(new CachedFieldInfo(clazz, name, desc, isStatic)) + "].load())"; 195 | } 196 | 197 | private int getCachedMethodId(String clazz, String name, String desc, boolean isStatic) { 198 | if (!cachedMethods.containsKey(new CachedMethodInfo(clazz, name, desc, isStatic))) 199 | cachedMethods.put(new CachedMethodInfo(clazz, name, desc, isStatic), cachedMethods.size()); 200 | return cachedMethods.get(new CachedMethodInfo(clazz, name, desc, isStatic)); 201 | } 202 | 203 | private int getCachedFieldId(String clazz, String name, String desc, boolean isStatic) { 204 | if (!cachedFields.containsKey(new CachedFieldInfo(clazz, name, desc, isStatic))) 205 | cachedFields.put(new CachedFieldInfo(clazz, name, desc, isStatic), cachedFields.size()); 206 | return cachedFields.get(new CachedFieldInfo(clazz, name, desc, isStatic)); 207 | } 208 | 209 | private String unicodify(String string) { 210 | StringBuilder result = new StringBuilder(); 211 | for (char c : string.toCharArray()) { 212 | result.append("\\u").append(String.format("%04x", (int) c)); 213 | } 214 | return result.toString(); 215 | } 216 | 217 | private String dynamicStringPoolFormat(String key, Map tokens) { 218 | String value = CPP_SNIPPETS.getProperty(key); 219 | if (value == null) 220 | throw new RuntimeException(key + " not found"); 221 | String[] stringVars = CPP_SNIPPETS.getProperty(key + "_S_VARS") == null 222 | || CPP_SNIPPETS.getProperty(key + "_S_VARS").equals("") ? new String[0] 223 | : CPP_SNIPPETS.getProperty(key + "_S_VARS").split(","); 224 | HashMap vars = new HashMap<>(); 225 | for (String var : stringVars) { 226 | if (var.startsWith("#")) { 227 | vars.put(var, CPP_SNIPPETS.getProperty(key + "_S_CONST_" + var.substring(1))); 228 | } else if (var.startsWith("$")) { 229 | vars.put(var, tokens.get(var.substring(1))); 230 | } else { 231 | throw new RuntimeException("Unknown format modifier: " + var); 232 | } 233 | } 234 | vars.entrySet().stream().filter((var) -> (var.getValue() == null)).forEachOrdered((var) -> { 235 | throw new RuntimeException(key + " - " + var.getKey() + " is null"); 236 | }); 237 | HashMap replaceTokens = new HashMap<>(); 238 | vars.entrySet().forEach((var) -> { 239 | replaceTokens.put(var.getKey(), getStringPooledString(var.getValue())); 240 | }); 241 | tokens.entrySet().forEach((var) -> { 242 | if (!replaceTokens.containsKey("$" + var.getKey())) 243 | replaceTokens.put("$" + var.getKey(), var.getValue()); 244 | }); 245 | return dynamicRawFormat(value, replaceTokens); 246 | } 247 | 248 | private final List readyIfaceStaticClasses = new ArrayList<>(); 249 | private ClassNode currentIfaceStaticClass; 250 | 251 | @SuppressWarnings("unchecked") 252 | static Stream reverse(Stream input) { 253 | Object[] temp = input.toArray(); 254 | return (Stream) IntStream.range(0, temp.length).mapToObj(i -> temp[temp.length - i - 1]); 255 | } 256 | 257 | private void setupNewIfaceStaticClass(Boolean forAndroid) { 258 | if (currentIfaceStaticClass != null && currentIfaceStaticClass.methods.size() > 0) 259 | readyIfaceStaticClasses.add(currentIfaceStaticClass); 260 | currentIfaceStaticClass = new ClassNode(); 261 | currentIfaceStaticClass.sourceFile = "synthetic"; 262 | currentIfaceStaticClass.name = "native" + nativeDirId + "/interfacestatic/Methods" 263 | + readyIfaceStaticClasses.size(); 264 | if (forAndroid) { // Android 265 | currentIfaceStaticClass.version = 50; 266 | } else { 267 | currentIfaceStaticClass.version = 52; 268 | } 269 | currentIfaceStaticClass.superName = "java/lang/Object"; 270 | currentIfaceStaticClass.access = Opcodes.ACC_PUBLIC; 271 | } 272 | 273 | private String visitMethod(ClassNode classNode, MethodNode methodNode, int index) { 274 | if (((methodNode.access & Opcodes.ACC_ABSTRACT) > 0) || ((methodNode.access & Opcodes.ACC_NATIVE) > 0)) 275 | return ""; 276 | if (methodNode.name.equals("")) 277 | return ""; 278 | StringBuilder outputSb = new StringBuilder("// "); 279 | outputSb.append(methodNode.name).append(methodNode.desc).append("\n"); 280 | String methodName = ""; 281 | MethodNode proxifiedResult; 282 | switch (methodNode.name) { 283 | case "": 284 | proxifiedResult = new MethodNode(Opcodes.ASM7, 285 | Opcodes.ACC_NATIVE | Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL | Opcodes.ACC_SYNTHETIC, 286 | "native_special_init" + index, methodNode.desc, methodNode.signature, new String[0]); 287 | classNode.methods.add(proxifiedResult); 288 | methodName += "native_special_init"; 289 | break; 290 | case "": 291 | proxifiedResult = new MethodNode(Opcodes.ASM7, 292 | Opcodes.ACC_NATIVE | Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC | Opcodes.ACC_SYNTHETIC, 293 | "native_special_clinit" + index, methodNode.desc, methodNode.signature, new String[0]); 294 | classNode.methods.add(proxifiedResult); 295 | methodName += "native_special_clinit"; 296 | break; 297 | default: 298 | proxifiedResult = methodNode; 299 | methodNode.access |= Opcodes.ACC_NATIVE; 300 | methodName += "native_" + methodNode.name; 301 | break; 302 | } 303 | methodName += index; 304 | methodName = "__ngen_" + methodName.replace("/", "_"); 305 | methodName = escapeCppNameString(methodName); 306 | 307 | int returnTypeSort = Type.getReturnType(methodNode.desc).getSort(); 308 | Type[] args = Type.getArgumentTypes(methodNode.desc); 309 | MethodNode nativeMethod = null; 310 | if ((classNode.access & Opcodes.ACC_INTERFACE) > 0) { 311 | if (currentIfaceStaticClass.methods.size() > 16384) { 312 | throw new RuntimeException("too many static interface methods"); 313 | } 314 | StringBuilder resultProcType = new StringBuilder("("); 315 | for (Type t : args) 316 | resultProcType.append(JAVA_DESCRIPTORS[t.getSort()]); 317 | resultProcType.append(")").append(JAVA_DESCRIPTORS[returnTypeSort]); 318 | String outerJavaMethodName = "iface_static_" + currentClassId + "_" + index; 319 | nativeMethod = new MethodNode(Opcodes.ASM7, 320 | Opcodes.ACC_NATIVE | Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_SYNTHETIC, 321 | outerJavaMethodName, resultProcType.toString(), null, new String[0]); 322 | currentIfaceStaticClass.methods.add(nativeMethod); 323 | ifaceStaticNativeMethodsSb.append(" { (char *)") 324 | .append(getStringPooledString(outerJavaMethodName)).append(", (char *)") 325 | .append(getStringPooledString(resultProcType.toString())).append(", (void *)&").append(methodName) 326 | .append(" },\n"); 327 | } else 328 | nativeMethodsSb.append(" { (char *)").append(getStringPooledString(proxifiedResult.name)) 329 | .append(", (char *)").append(getStringPooledString(methodNode.desc)).append(", (void *)&") 330 | .append(methodName).append(" },\n"); 331 | outputSb.append(CPP_TYPES[returnTypeSort]).append(" ").append("JNICALL").append(" ").append(methodName) 332 | .append("(").append("JNIEnv *env").append(", ") 333 | .append(((methodNode.access & Opcodes.ACC_STATIC) > 0) ? "jclass clazz" : "jobject obj"); 334 | if (args.length > 0) 335 | outputSb.append(", "); 336 | for (int i = 0; i < args.length; i++) 337 | outputSb.append(CPP_TYPES[args[i].getSort()]).append(" ").append("arg").append(i) 338 | .append(i == args.length - 1 ? "" : ", "); 339 | outputSb.append(") {").append("\n"); 340 | if (methodNode.maxStack > 0) 341 | outputSb.append(" ").append("utils::jvm_stack<").append(methodNode.maxStack).append("> cstack;") 342 | .append("\n"); 343 | if (methodNode.maxLocals > 0) 344 | outputSb.append(" ").append("utils::local_vars<").append(methodNode.maxLocals).append("> clocals;") 345 | .append("\n"); 346 | outputSb.append(" ").append("std::unordered_set refs;").append("\n"); 347 | outputSb.append("\n"); 348 | int localIndex = 0; 349 | if (((methodNode.access & Opcodes.ACC_STATIC) == 0)) { 350 | outputSb.append(" ").append( 351 | dynamicStringPoolFormat("LOCAL_LOAD_ARG_" + 9, createMap("index", localIndex, "arg", "obj"))) 352 | .append("\n"); 353 | localIndex++; 354 | } 355 | for (int i = 0; i < args.length; i++) { 356 | outputSb.append(" ").append(dynamicStringPoolFormat("LOCAL_LOAD_ARG_" + args[i].getSort(), 357 | createMap("index", localIndex, "arg", "arg" + i))).append("\n"); 358 | localIndex += args[i].getSize(); 359 | } 360 | outputSb.append("\n"); 361 | List currentTryCatches = new ArrayList<>(); 362 | int currentLine = -1; 363 | int invokeSpecialId = -1; 364 | List currentStack = new ArrayList<>(); 365 | List currentLocals = new ArrayList<>(); 366 | if ((methodNode.access & Opcodes.ACC_STATIC) == 0) 367 | currentLocals.add(TYPE_TO_STACK[Type.OBJECT]); 368 | for (Type localArg : args) 369 | currentLocals.add(TYPE_TO_STACK[localArg.getSort()]); 370 | for (int insnIndex = 0; insnIndex < methodNode.instructions.size(); insnIndex++) { 371 | if (methodNode.name.equals("") && invokeSpecialId < 0) { 372 | if (methodNode.instructions.get(insnIndex).getOpcode() == Opcodes.INVOKESPECIAL) { 373 | invokeSpecialId = insnIndex; 374 | } 375 | continue; 376 | } 377 | AbstractInsnNode insnNode = methodNode.instructions.get(insnIndex); 378 | switch (insnNode.getType()) { 379 | case AbstractInsnNode.LABEL: 380 | outputSb.append(((LabelNode) insnNode).getLabel()).append(": ;").append("\n"); 381 | reverse(methodNode.tryCatchBlocks.stream().filter((node) -> (node.start.equals(insnNode)))) 382 | .forEachOrdered(currentTryCatches::add); 383 | methodNode.tryCatchBlocks.stream().filter((node) -> (node.end.equals(insnNode))) 384 | .forEachOrdered(currentTryCatches::remove); 385 | break; 386 | case AbstractInsnNode.LINE: 387 | outputSb.append(" ").append("// Line ").append(((LineNumberNode) insnNode).line).append(":") 388 | .append("\n"); 389 | currentLine = ((LineNumberNode) insnNode).line; 390 | break; 391 | case AbstractInsnNode.FRAME: 392 | FrameNode frameNode = (FrameNode) insnNode; 393 | switch (frameNode.type) { 394 | case Opcodes.F_APPEND: 395 | for (Object local : frameNode.local) { 396 | if (local instanceof String) 397 | currentLocals.add(TYPE_TO_STACK[Type.OBJECT]); 398 | else if (local instanceof LabelNode) 399 | currentLocals.add(TYPE_TO_STACK[Type.OBJECT]); 400 | else 401 | currentLocals.add(STACK_TO_STACK[(int) local]); 402 | } 403 | break; 404 | case Opcodes.F_CHOP: 405 | for (int i = 0; i < frameNode.local.size(); i++) 406 | currentLocals.remove(currentLocals.size() - 1); 407 | currentStack.clear(); 408 | break; 409 | case Opcodes.F_NEW: 410 | case Opcodes.F_FULL: 411 | currentLocals.clear(); 412 | currentStack.clear(); 413 | for (Object local : frameNode.local) { 414 | if (local instanceof String) 415 | currentLocals.add(TYPE_TO_STACK[Type.OBJECT]); 416 | else if (local instanceof LabelNode) 417 | currentLocals.add(TYPE_TO_STACK[Type.OBJECT]); 418 | else 419 | currentLocals.add(STACK_TO_STACK[(int) local]); 420 | } 421 | for (Object stack : frameNode.stack) { 422 | if (stack instanceof String) 423 | currentStack.add(TYPE_TO_STACK[Type.OBJECT]); 424 | else if (stack instanceof LabelNode) 425 | currentStack.add(TYPE_TO_STACK[Type.OBJECT]); 426 | else 427 | currentStack.add(STACK_TO_STACK[(int) stack]); 428 | } 429 | break; 430 | case Opcodes.F_SAME: 431 | break; 432 | case Opcodes.F_SAME1: 433 | if (frameNode.stack.get(0) instanceof String) 434 | currentStack.add(TYPE_TO_STACK[Type.OBJECT]); 435 | else if (frameNode.stack.get(0) instanceof LabelNode) 436 | currentStack.add(TYPE_TO_STACK[Type.OBJECT]); 437 | else 438 | currentStack.add(STACK_TO_STACK[(int) frameNode.stack.get(0)]); 439 | break; 440 | } 441 | if (currentStack.stream().anyMatch(x -> x == 0)) { 442 | int currentSp = 0; 443 | outputSb.append(" "); 444 | for (int type : currentStack) { 445 | if (type == 0) 446 | outputSb.append("refs.erase(cstack.refs[" + currentSp + "]); "); 447 | currentSp += Math.max(1, type); 448 | } 449 | outputSb.append("\n"); 450 | } 451 | if (currentLocals.stream().anyMatch(x -> x == 0)) { 452 | int currentLp = 0; 453 | outputSb.append(" "); 454 | for (int type : currentLocals) { 455 | if (type == 0) 456 | outputSb.append("refs.erase(clocals.refs[" + currentLp + "]); "); 457 | currentLp += Math.max(1, type); 458 | } 459 | outputSb.append("\n"); 460 | } 461 | outputSb.append(" utils::clear_refs(env, refs);\n"); 462 | break; 463 | default: 464 | StringBuilder tryCatch = new StringBuilder("\n"); 465 | if (currentTryCatches.size() > 0) { 466 | tryCatch.append(" ").append(dynamicStringPoolFormat("TRYCATCH_START", createMap())).append("\n"); 467 | for (int i = currentTryCatches.size() - 1; i >= 0; i--) { 468 | TryCatchBlockNode tryCatchBlock = currentTryCatches.get(i); 469 | if (tryCatchBlock.type == null) { 470 | tryCatch.append(" ") 471 | .append(dynamicStringPoolFormat("TRYCATCH_ANY_L", 472 | createMap("rettype", CPP_TYPES[returnTypeSort], "handler_block", 473 | tryCatchBlock.handler.getLabel().toString()))) 474 | .append("\n"); 475 | break; 476 | } else { 477 | tryCatch.append(" ") 478 | .append(dynamicStringPoolFormat("TRYCATCH_CHECK", 479 | createMap("rettype", CPP_TYPES[returnTypeSort], "exception_class_ptr", 480 | getCachedClassPointer(tryCatchBlock.type), "handler_block", 481 | tryCatchBlock.handler.getLabel().toString()))) 482 | .append("\n"); 483 | } 484 | } 485 | tryCatch.append(" ").append( 486 | dynamicStringPoolFormat("TRYCATCH_END", createMap("rettype", CPP_TYPES[returnTypeSort]))); 487 | } else 488 | tryCatch.append(" ").append( 489 | dynamicStringPoolFormat("TRYCATCH_EMPTY", createMap("rettype", CPP_TYPES[returnTypeSort]))); 490 | outputSb.append(" "); 491 | String insnName = INSTRUCTIONS.getOrDefault(insnNode.getOpcode(), "NOTFOUND"); 492 | HashMap props = new HashMap<>(); 493 | props.put("line", String.valueOf(currentLine)); 494 | props.put("trycatchhandler", tryCatch.toString()); 495 | props.put("rettype", CPP_TYPES[returnTypeSort]); 496 | String trimmedTryCatchBlock = tryCatch.toString().trim().replace("\n", " "); 497 | if (insnNode instanceof FieldInsnNode) { 498 | insnName += "_" + Type.getType(((FieldInsnNode) insnNode).desc).getSort(); 499 | if (insnNode.getOpcode() == Opcodes.GETSTATIC || insnNode.getOpcode() == Opcodes.PUTSTATIC) 500 | props.put("class_ptr", getCachedClassPointer(((FieldInsnNode) insnNode).owner)); 501 | int fieldId = getCachedFieldId(((FieldInsnNode) insnNode).owner, ((FieldInsnNode) insnNode).name, 502 | ((FieldInsnNode) insnNode).desc, 503 | insnNode.getOpcode() == Opcodes.GETSTATIC || insnNode.getOpcode() == Opcodes.PUTSTATIC); 504 | outputSb.append("if (!cfields[").append(fieldId).append("].load()) { cfields[").append(fieldId) 505 | .append("].store(env->Get") 506 | .append((insnNode.getOpcode() == Opcodes.GETSTATIC 507 | || insnNode.getOpcode() == Opcodes.PUTSTATIC) ? "Static" : "") 508 | .append("FieldID(").append(getCachedClassPointer(((FieldInsnNode) insnNode).owner)) 509 | .append(", ").append(getStringPooledString(((FieldInsnNode) insnNode).name)).append(", ") 510 | .append(getStringPooledString(((FieldInsnNode) insnNode).desc)).append(")); ") 511 | .append(trimmedTryCatchBlock).append(" } "); 512 | props.put("fieldid", getCachedFieldPointer(((FieldInsnNode) insnNode).owner, 513 | ((FieldInsnNode) insnNode).name, ((FieldInsnNode) insnNode).desc, 514 | insnNode.getOpcode() == Opcodes.GETSTATIC || insnNode.getOpcode() == Opcodes.PUTSTATIC)); 515 | } 516 | if (insnNode instanceof IincInsnNode) { 517 | props.put("incr", String.valueOf(((IincInsnNode) insnNode).incr)); 518 | props.put("var", String.valueOf(((IincInsnNode) insnNode).var)); 519 | } 520 | if (insnNode instanceof IntInsnNode) { 521 | props.put("operand", String.valueOf(((IntInsnNode) insnNode).operand)); 522 | if (insnNode.getOpcode() == Opcodes.NEWARRAY) { 523 | insnName += "_" + ((IntInsnNode) insnNode).operand; 524 | } 525 | } 526 | if (insnNode instanceof InvokeDynamicInsnNode) { 527 | String indyMethodName = "invokedynamic$" + methodNode.name + "$" + invokeDynamics.size(); 528 | invokeDynamics.put(indyMethodName, (InvokeDynamicInsnNode) insnNode); 529 | Type returnType = Type.getReturnType(((InvokeDynamicInsnNode) insnNode).desc); 530 | Type[] argTypes = Type.getArgumentTypes(((InvokeDynamicInsnNode) insnNode).desc); 531 | insnName = "INVOKESTATIC_" + returnType.getSort(); 532 | StringBuilder argsBuilder = new StringBuilder(); 533 | List argOffsets = new ArrayList<>(); 534 | List argSorts = new ArrayList<>(); 535 | int stackOffset = -1; 536 | for (Type argType : argTypes) { 537 | int currentOffset = stackOffset; 538 | stackOffset -= argType.getSize(); 539 | argOffsets.add(currentOffset); 540 | argSorts.add(argType.getSort()); 541 | } 542 | for (int i = 0; i < argOffsets.size(); i++) 543 | argsBuilder.append(", ").append(dynamicStringPoolFormat("INVOKE_ARG_" + argSorts.get(i), 544 | createMap("index", String.valueOf(argOffsets.get(i))))); 545 | outputSb.append(dynamicStringPoolFormat("INVOKE_POPCNT", 546 | createMap("count", String.valueOf(-stackOffset - 1)))).append(" "); 547 | props.put("class_ptr", getCachedClassPointer(classNode.name)); 548 | int methodId = getCachedMethodId(classNode.name, indyMethodName, 549 | ((InvokeDynamicInsnNode) insnNode).desc, true); 550 | outputSb.append("if (!cmethods[").append(methodId).append("].load()) { cmethods[").append(methodId) 551 | .append("].store(env->GetStaticMethodID(").append(getCachedClassPointer(classNode.name)) 552 | .append(", ").append(getStringPooledString(indyMethodName)).append(", ") 553 | .append(getStringPooledString(((InvokeDynamicInsnNode) insnNode).desc)).append(")); ") 554 | .append(trimmedTryCatchBlock).append(" } "); 555 | props.put("methodid", getCachedMethodPointer(classNode.name, indyMethodName, 556 | ((InvokeDynamicInsnNode) insnNode).desc, true)); 557 | props.put("args", argsBuilder.toString()); 558 | } 559 | if (insnNode instanceof JumpInsnNode) { 560 | props.put("label", String.valueOf(((JumpInsnNode) insnNode).label.getLabel())); 561 | } 562 | if (insnNode instanceof LdcInsnNode) { 563 | Object cst = ((LdcInsnNode) insnNode).cst; 564 | if (cst instanceof java.lang.String) { 565 | insnName += "_STRING"; 566 | props.put("cst", String.valueOf(((LdcInsnNode) insnNode).cst)); 567 | } else if (cst instanceof java.lang.Integer) { 568 | insnName += "_INT"; 569 | props.put("cst", String.valueOf(((LdcInsnNode) insnNode).cst)); 570 | } else if (cst instanceof java.lang.Long) { 571 | insnName += "_LONG"; 572 | props.put("cst", String.valueOf(((LdcInsnNode) insnNode).cst)); 573 | } else if (cst instanceof java.lang.Float) { 574 | insnName += "_FLOAT"; 575 | props.put("cst", String.valueOf(((LdcInsnNode) insnNode).cst)); 576 | float cstVal = (float) cst; 577 | if (cst.toString().equals("NaN")) 578 | props.put("cst", "NAN"); 579 | else if (cstVal == Float.POSITIVE_INFINITY) 580 | props.put("cst", "HUGE_VALF"); 581 | else if (cstVal == Float.NEGATIVE_INFINITY) 582 | props.put("cst", "-HUGE_VALF"); 583 | } else if (cst instanceof java.lang.Double) { 584 | insnName += "_DOUBLE"; 585 | props.put("cst", String.valueOf(((LdcInsnNode) insnNode).cst)); 586 | double cstVal = (double) cst; 587 | if (cst.toString().equals("NaN")) 588 | props.put("cst", "NAN"); 589 | else if (cstVal == Double.POSITIVE_INFINITY) 590 | props.put("cst", "HUGE_VAL"); 591 | else if (cstVal == Double.NEGATIVE_INFINITY) 592 | props.put("cst", "-HUGE_VAL"); 593 | } else if (cst instanceof org.objectweb.asm.Type) { 594 | insnName += "_CLASS"; 595 | props.put("cst_ptr", getCachedClassPointer(((LdcInsnNode) insnNode).cst.toString())); 596 | } else { 597 | throw new UnsupportedOperationException(); 598 | } 599 | } 600 | if (insnNode instanceof LookupSwitchInsnNode) { 601 | outputSb.append(dynamicStringPoolFormat("LOOKUPSWITCH_START", createMap())).append("\n"); 602 | for (int switchIndex = 0; switchIndex < ((LookupSwitchInsnNode) insnNode).labels 603 | .size(); switchIndex++) 604 | outputSb.append(" ").append(" ") 605 | .append(dynamicStringPoolFormat("LOOKUPSWITCH_PART", createMap("key", 606 | String.valueOf(((LookupSwitchInsnNode) insnNode).keys.get(switchIndex)), 607 | "label", 608 | String.valueOf( 609 | ((LookupSwitchInsnNode) insnNode).labels.get(switchIndex).getLabel())))) 610 | .append("\n"); 611 | outputSb.append(" ").append(" ") 612 | .append(dynamicStringPoolFormat("LOOKUPSWITCH_DEFAULT", 613 | createMap("label", 614 | String.valueOf(((LookupSwitchInsnNode) insnNode).dflt.getLabel())))) 615 | .append("\n"); 616 | outputSb.append(" ").append(dynamicStringPoolFormat("LOOKUPSWITCH_END", createMap())) 617 | .append("\n"); 618 | continue; 619 | } 620 | if (insnNode instanceof MethodInsnNode) { 621 | Type returnType = Type.getReturnType(((MethodInsnNode) insnNode).desc); 622 | Type[] argTypes = Type.getArgumentTypes(((MethodInsnNode) insnNode).desc); 623 | insnName += "_" + returnType.getSort(); 624 | StringBuilder argsBuilder = new StringBuilder(); 625 | List argOffsets = new ArrayList<>(); 626 | List argSorts = new ArrayList<>(); 627 | int stackOffset = -1; 628 | for (Type argType : argTypes) { 629 | int currentOffset = stackOffset; 630 | stackOffset -= argType.getSize(); 631 | argOffsets.add(currentOffset); 632 | argSorts.add(argType.getSort()); 633 | } 634 | if (insnNode.getOpcode() == Opcodes.INVOKEINTERFACE || insnNode.getOpcode() == Opcodes.INVOKESPECIAL 635 | || insnNode.getOpcode() == Opcodes.INVOKEVIRTUAL) { 636 | for (int i = 0; i < argOffsets.size(); i++) 637 | argsBuilder.append(", ").append(dynamicStringPoolFormat("INVOKE_ARG_" + argSorts.get(i), 638 | createMap("index", String.valueOf(argOffsets.get(i) - 1)))); 639 | if (stackOffset != 0) 640 | outputSb.append(dynamicStringPoolFormat("INVOKE_POPCNT", 641 | createMap("count", String.valueOf(-stackOffset)))).append(" "); 642 | if (insnNode.getOpcode() == Opcodes.INVOKESPECIAL) 643 | props.put("class_ptr", getCachedClassPointer(((MethodInsnNode) insnNode).owner)); 644 | int methodId = getCachedMethodId(((MethodInsnNode) insnNode).owner, 645 | ((MethodInsnNode) insnNode).name, ((MethodInsnNode) insnNode).desc, false); 646 | outputSb.append("if (!cmethods[").append(methodId).append("].load()) { cmethods[") 647 | .append(methodId).append("].store(env->GetMethodID(") 648 | .append(getCachedClassPointer(((MethodInsnNode) insnNode).owner)).append(", ") 649 | .append(getStringPooledString(((MethodInsnNode) insnNode).name)).append(", ") 650 | .append(getStringPooledString(((MethodInsnNode) insnNode).desc)).append(")); ") 651 | .append(trimmedTryCatchBlock).append(" } "); 652 | props.put("methodid", getCachedMethodPointer(((MethodInsnNode) insnNode).owner, 653 | ((MethodInsnNode) insnNode).name, ((MethodInsnNode) insnNode).desc, false)); 654 | props.put("object_offset", "-1"); 655 | props.put("args", argsBuilder.toString()); 656 | } else { 657 | for (int i = 0; i < argOffsets.size(); i++) 658 | argsBuilder.append(", ").append(dynamicStringPoolFormat("INVOKE_ARG_" + argSorts.get(i), 659 | createMap("index", String.valueOf(argOffsets.get(i))))); 660 | if (-stackOffset - 1 != 0) 661 | outputSb.append(dynamicStringPoolFormat("INVOKE_POPCNT", 662 | createMap("count", String.valueOf(-stackOffset - 1)))).append(" "); 663 | props.put("class_ptr", getCachedClassPointer(((MethodInsnNode) insnNode).owner)); 664 | int methodId = getCachedMethodId(((MethodInsnNode) insnNode).owner, 665 | ((MethodInsnNode) insnNode).name, ((MethodInsnNode) insnNode).desc, true); 666 | outputSb.append("if (!cmethods[").append(methodId).append("].load()) { cmethods[") 667 | .append(methodId).append("].store(env->GetStaticMethodID(") 668 | .append(getCachedClassPointer(((MethodInsnNode) insnNode).owner)).append(", ") 669 | .append(getStringPooledString(((MethodInsnNode) insnNode).name)).append(", ") 670 | .append(getStringPooledString(((MethodInsnNode) insnNode).desc)).append(")); ") 671 | .append(trimmedTryCatchBlock).append(" } "); 672 | props.put("methodid", getCachedMethodPointer(((MethodInsnNode) insnNode).owner, 673 | ((MethodInsnNode) insnNode).name, ((MethodInsnNode) insnNode).desc, true)); 674 | props.put("args", argsBuilder.toString()); 675 | } 676 | } 677 | if (insnNode instanceof MultiANewArrayInsnNode) { 678 | props.put("count", String.valueOf(((MultiANewArrayInsnNode) insnNode).dims)); 679 | props.put("desc", ((MultiANewArrayInsnNode) insnNode).desc); 680 | } 681 | if (insnNode instanceof TableSwitchInsnNode) { 682 | outputSb.append(dynamicStringPoolFormat("TABLESWITCH_START", createMap())).append("\n"); 683 | for (int switchIndex = 0; switchIndex < ((TableSwitchInsnNode) insnNode).labels 684 | .size(); switchIndex++) 685 | outputSb.append(" ").append(" ") 686 | .append(dynamicStringPoolFormat("TABLESWITCH_PART", createMap("index", 687 | String.valueOf(((TableSwitchInsnNode) insnNode).min + switchIndex), "label", 688 | String.valueOf( 689 | ((TableSwitchInsnNode) insnNode).labels.get(switchIndex).getLabel())))) 690 | .append("\n"); 691 | outputSb.append(" ").append(" ") 692 | .append(dynamicStringPoolFormat("TABLESWITCH_DEFAULT", 693 | createMap("label", 694 | String.valueOf(((TableSwitchInsnNode) insnNode).dflt.getLabel())))) 695 | .append("\n"); 696 | outputSb.append(" ").append(dynamicStringPoolFormat("TABLESWITCH_END", createMap())) 697 | .append("\n"); 698 | continue; 699 | } 700 | if (insnNode instanceof TypeInsnNode) { 701 | props.put("desc", (((TypeInsnNode) insnNode).desc)); 702 | props.put("desc_ptr", getCachedClassPointer(((TypeInsnNode) insnNode).desc)); 703 | } 704 | if (insnNode instanceof VarInsnNode) { 705 | props.put("var", String.valueOf(((VarInsnNode) insnNode).var)); 706 | } 707 | String cppCode = CPP_SNIPPETS.getProperty(insnName); 708 | if (cppCode == null) { 709 | throw new RuntimeException("insn not found: " + insnName); 710 | } else { 711 | cppCode = dynamicStringPoolFormat(insnName, props); 712 | outputSb.append(cppCode); 713 | } 714 | outputSb.append("\n"); 715 | break; 716 | } 717 | } 718 | outputSb.append(" return (").append(CPP_TYPES[returnTypeSort]).append(") 0;\n"); 719 | outputSb.append("}\n\n"); 720 | 721 | methodNode.localVariables.clear(); 722 | methodNode.tryCatchBlocks.clear(); 723 | 724 | switch (methodNode.name) { 725 | case "": { 726 | InsnList list = new InsnList(); 727 | for (int i = 0; i <= invokeSpecialId; i++) 728 | list.add(methodNode.instructions.get(i)); 729 | list.add(new VarInsnNode(Opcodes.ALOAD, 0)); 730 | int localVarsPosition = 1; 731 | for (Type arg : args) { 732 | list.add(new VarInsnNode(arg.getOpcode(Opcodes.ILOAD), localVarsPosition)); 733 | localVarsPosition += arg.getSize(); 734 | } 735 | list.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, classNode.name, "native_special_init" + index, 736 | methodNode.desc)); 737 | list.add(new InsnNode(Opcodes.RETURN)); 738 | methodNode.instructions = list; 739 | } 740 | break; 741 | case "": 742 | methodNode.instructions.clear(); 743 | methodNode.instructions.add(new LdcInsnNode((int) currentClassId)); 744 | methodNode.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "native" + nativeDirId + "/Loader", 745 | "registerNativesForClass", "(I)V")); 746 | methodNode.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, classNode.name, 747 | "native_special_clinit" + index, methodNode.desc)); 748 | if ((classNode.access & Opcodes.ACC_INTERFACE) > 0) { 749 | proxifiedResult.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, currentIfaceStaticClass.name, 750 | nativeMethod.name, nativeMethod.desc)); 751 | proxifiedResult.instructions.add(new InsnNode(Opcodes.RETURN)); 752 | } 753 | methodNode.instructions.add(new InsnNode(Opcodes.RETURN)); 754 | break; 755 | default: 756 | methodNode.instructions.clear(); 757 | if ((classNode.access & Opcodes.ACC_INTERFACE) > 0) { 758 | InsnList list = new InsnList(); 759 | for (int i = 0; i <= invokeSpecialId; i++) 760 | list.add(methodNode.instructions.get(i)); 761 | int localVarsPosition = 0; 762 | for (Type arg : args) { 763 | list.add(new VarInsnNode(arg.getOpcode(Opcodes.ILOAD), localVarsPosition)); 764 | localVarsPosition += arg.getSize(); 765 | } 766 | methodNode.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, currentIfaceStaticClass.name, 767 | nativeMethod.name, nativeMethod.desc)); 768 | methodNode.instructions 769 | .add(new InsnNode(Type.getReturnType(methodNode.desc).getOpcode(Opcodes.IRETURN))); 770 | } 771 | break; 772 | } 773 | 774 | return outputSb.toString(); 775 | } 776 | 777 | private void processIndy(ClassNode classNode, String methodName, InvokeDynamicInsnNode indy) { 778 | MethodNode indyWrapper = new MethodNode(Opcodes.ASM7, 779 | Opcodes.ACC_PRIVATE | Opcodes.ACC_FINAL | Opcodes.ACC_SYNTHETIC | Opcodes.ACC_STATIC, methodName, 780 | indy.desc, null, new String[0]); 781 | int localVarsPosition = 0; 782 | for (Type arg : Type.getArgumentTypes(indy.desc)) { 783 | indyWrapper.instructions.add(new VarInsnNode(arg.getOpcode(Opcodes.ILOAD), localVarsPosition)); 784 | localVarsPosition += arg.getSize(); 785 | } 786 | indyWrapper.instructions.add(new InvokeDynamicInsnNode(indy.name, indy.desc, indy.bsm, indy.bsmArgs)); 787 | indyWrapper.instructions.add(new InsnNode(Opcodes.ARETURN)); 788 | classNode.methods.add(indyWrapper); 789 | } 790 | 791 | private String writeStreamToString(InputStream stream) throws IOException { 792 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 793 | transfer(stream, baos); 794 | return new String(baos.toByteArray(), StandardCharsets.UTF_8); 795 | } 796 | 797 | private void writeStreamToFile(InputStream stream, Path path) throws IOException { 798 | byte[] buffer = new byte[4096]; 799 | int bytesRead; 800 | try (OutputStream outputStream = Files.newOutputStream(path, StandardOpenOption.CREATE, 801 | StandardOpenOption.TRUNCATE_EXISTING)) { 802 | while ((bytesRead = stream.read(buffer)) != -1) { 803 | outputStream.write(buffer, 0, bytesRead); 804 | } 805 | } 806 | } 807 | 808 | private String getGetterForType(String desc) { 809 | if (desc.startsWith("[")) 810 | return "env->FindClass(" + getStringPooledString(desc) + ")"; 811 | if (desc.endsWith(";")) 812 | desc = desc.substring(1, desc.length() - 1); 813 | return "utils::find_class_wo_static(env, " + getStringPooledString(desc.replace("/", ".")) + ")"; 814 | } 815 | 816 | private int currentClassId; 817 | private int nativeDirId = 0; 818 | 819 | public void process(Path inputJar, Path outputDir, List libs, Boolean forAndroid) throws IOException { 820 | libs.add(inputJar); 821 | ClassMetadataReader metadataReader = new ClassMetadataReader(libs.stream().map(x -> { 822 | try { 823 | return new JarFile(inputJar.toFile()); 824 | } catch (IOException ex) { 825 | return null; 826 | } 827 | }).collect(Collectors.toList())); 828 | final File jar = inputJar.toAbsolutePath().toFile(); 829 | Files.createDirectories(outputDir); 830 | Files.createDirectories(outputDir.resolve("cpp")); 831 | Files.createDirectories(outputDir.resolve("cpp").resolve("output")); 832 | try (InputStream in = NativeObfuscator.class.getClassLoader().getResourceAsStream("sources/native_jvm.cpp")) { 833 | writeStreamToFile(in, outputDir.resolve("cpp").resolve("native_jvm.cpp")); 834 | } 835 | try (InputStream in = NativeObfuscator.class.getClassLoader().getResourceAsStream("sources/native_jvm.hpp")) { 836 | writeStreamToFile(in, outputDir.resolve("cpp").resolve("native_jvm.hpp")); 837 | } 838 | try (InputStream in = NativeObfuscator.class.getClassLoader() 839 | .getResourceAsStream("sources/native_jvm_output.hpp")) { 840 | writeStreamToFile(in, outputDir.resolve("cpp").resolve("native_jvm_output.hpp")); 841 | } 842 | try (InputStream in = NativeObfuscator.class.getClassLoader().getResourceAsStream("sources/string_pool.hpp")) { 843 | writeStreamToFile(in, outputDir.resolve("cpp").resolve("string_pool.hpp")); 844 | } 845 | 846 | if (forAndroid) { // Android 847 | try (InputStream in = NativeObfuscator.class.getClassLoader() 848 | .getResourceAsStream("sources/android/jvmti.h")) { 849 | writeStreamToFile(in, outputDir.resolve("cpp").resolve("jvmti.h")); 850 | } 851 | } 852 | StringBuilder outputHeaderSb = new StringBuilder(); 853 | StringBuilder outputHeaderIncludesSb = new StringBuilder(); 854 | List cmakeClassFiles = new ArrayList<>(); 855 | List cmakeMainFiles = new ArrayList<>(); 856 | cmakeMainFiles.add("native_jvm.hpp"); 857 | cmakeMainFiles.add("native_jvm.cpp"); 858 | cmakeMainFiles.add("native_jvm_output.hpp"); 859 | cmakeMainFiles.add("native_jvm_output.cpp"); 860 | cmakeMainFiles.add("string_pool.hpp"); 861 | cmakeMainFiles.add("string_pool.cpp"); 862 | String projectName = "native_jvm_classes_" + inputJar.getFileName().toString().replaceAll("[$#\\.\\s\\/]", "_") 863 | + "_" + Math.abs(new Random().nextLong()); 864 | try (final JarFile f = new JarFile(jar); 865 | final ZipOutputStream out = new ZipOutputStream(Files.newOutputStream(outputDir.resolve(jar.getName()), 866 | StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING))) { 867 | System.out.println("Processing " + jar + "..."); 868 | 869 | while (true) { 870 | final int currentNativeDirId = nativeDirId; 871 | if (!f.stream().anyMatch(x -> x.getName().startsWith("native" + currentNativeDirId))) 872 | break; 873 | nativeDirId++; 874 | } 875 | 876 | f.stream().forEach(e -> { 877 | try { 878 | if (e.getName().equals(JarFile.MANIFEST_NAME)) 879 | return; 880 | if (!e.getName().endsWith(".class")) { 881 | writeEntry(f, out, e); 882 | return; 883 | } 884 | 885 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 886 | try (InputStream in = f.getInputStream(e)) { 887 | transfer(in, baos); 888 | } 889 | byte[] src = baos.toByteArray(); 890 | if (byteArrayToInt(Arrays.copyOfRange(src, 0, 4)) != 0xCAFEBABE) { 891 | writeEntry(out, e.getName(), src); 892 | return; 893 | } 894 | nativeMethodsSb = new StringBuilder(); 895 | ifaceStaticNativeMethodsSb = new StringBuilder(); 896 | invokeDynamics = new HashMap<>(); 897 | ClassReader classReader = new ClassReader(src); 898 | ClassNode classNode = new ClassNode(Opcodes.ASM7); 899 | classReader.accept(classNode, 0); 900 | if (classNode.methods.stream() 901 | .filter(x -> (x.access & (Opcodes.ACC_ABSTRACT | Opcodes.ACC_NATIVE)) == 0 902 | && !x.name.equals("")) 903 | .count() == 0) { 904 | System.out.println("Skipping " + classNode.name); 905 | writeEntry(out, e.getName(), src); 906 | return; 907 | } 908 | System.out.println("Processing " + classNode.name); 909 | if (!classNode.methods.stream().anyMatch(x -> x.name.equals(""))) 910 | classNode.methods.add(new MethodNode(Opcodes.ASM7, Opcodes.ACC_STATIC, "", "()V", null, 911 | new String[0])); 912 | setupNewIfaceStaticClass(forAndroid); 913 | cachedClasses.clear(); 914 | cachedMethods.clear(); 915 | cachedFields.clear(); 916 | try (BufferedWriter outputCppFile = new BufferedWriter( 917 | new OutputStreamWriter(new FileOutputStream(outputDir.resolve("cpp").resolve("output") 918 | .resolve(escapeCppNameString(classNode.name.replace('/', '_')).concat(".cpp")) 919 | .toFile()), StandardCharsets.UTF_8)); 920 | BufferedWriter outputHppFile = new BufferedWriter(new OutputStreamWriter( 921 | new FileOutputStream(outputDir.resolve("cpp").resolve("output").resolve( 922 | escapeCppNameString(classNode.name.replace('/', '_')).concat(".hpp")) 923 | .toFile()), 924 | StandardCharsets.UTF_8))) { 925 | StringBuilder insnsSb = new StringBuilder(); 926 | classNode.sourceFile = escapeCppNameString(classNode.name.replace('/', '_')) + ".cpp"; 927 | for (int i = 0; i < classNode.methods.size(); i++) 928 | insnsSb.append(visitMethod(classNode, classNode.methods.get(i), i).replace("\n", "\n ")); 929 | if ((classNode.access & Opcodes.ACC_INTERFACE) > 0) 930 | for (int i = 0; i < classNode.methods.size(); i++) 931 | classNode.methods.get(i).access &= ~Opcodes.ACC_NATIVE; 932 | invokeDynamics.forEach((key, value) -> processIndy(classNode, key, value)); 933 | classNode.version = 52; 934 | ClassWriter classWriter = new SafeClassWriter(metadataReader, 935 | Opcodes.ASM7 | ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); 936 | classNode.accept(classWriter); 937 | writeEntry(out, e.getName(), classWriter.toByteArray()); 938 | 939 | outputCppFile.append("#include \"../native_jvm.hpp\"\n"); 940 | outputHppFile.append("#include \"../native_jvm.hpp\"\n"); 941 | outputCppFile.append("#include \"../string_pool.hpp\"\n"); 942 | outputCppFile.append("#include \"") 943 | .append(escapeCppNameString(classNode.name.replace('/', '_')).concat(".hpp")) 944 | .append("\"\n"); 945 | cmakeClassFiles.add("output/" + escapeCppNameString(classNode.name.replace('/', '_')) + ".hpp"); 946 | cmakeClassFiles.add("output/" + escapeCppNameString(classNode.name.replace('/', '_')) + ".cpp"); 947 | outputHeaderIncludesSb.append("#include \"output/") 948 | .append(escapeCppNameString(classNode.name.replace('/', '_')).concat(".hpp")) 949 | .append("\"\n"); 950 | outputCppFile.append("\n"); 951 | outputCppFile.append("// ").append(classNode.name).append("\n"); 952 | outputCppFile.append("namespace native_jvm::classes::__ngen_") 953 | .append(escapeCppNameString(classNode.name.replace("/", "_"))).append(" {\n\n"); 954 | outputCppFile.append(" char *string_pool;\n\n"); 955 | if (cachedClasses.size() > 0) 956 | outputCppFile.append(" jclass cclasses[" + cachedClasses.size() + "];\n"); 957 | if (cachedMethods.size() > 0) 958 | outputCppFile 959 | .append(" std::atomic cmethods[" + cachedMethods.size() + "];\n"); 960 | if (cachedFields.size() > 0) 961 | outputCppFile.append(" std::atomic cfields[" + cachedFields.size() + "];\n"); 962 | outputCppFile.append("\n"); 963 | outputHppFile.append("\n"); 964 | outputHppFile.append("#ifndef ").append( 965 | escapeCppNameString(classNode.name.replace('/', '_')).concat("_hpp").toUpperCase()) 966 | .append("_GUARD\n"); 967 | outputHppFile.append("\n"); 968 | outputHppFile.append("#define ").append( 969 | escapeCppNameString(classNode.name.replace('/', '_')).concat("_hpp").toUpperCase()) 970 | .append("_GUARD\n"); 971 | outputHppFile.append("\n"); 972 | outputHppFile.append("// ").append(classNode.name).append("\n"); 973 | outputHppFile.append("namespace native_jvm::classes::__ngen_") 974 | .append(escapeCppNameString(classNode.name.replace("/", "_"))).append(" {\n\n"); 975 | outputCppFile.append(" "); 976 | outputCppFile.append(insnsSb); 977 | outputCppFile.append("\n"); 978 | outputCppFile.append(" void __ngen_register_methods(JNIEnv *env, jvmtiEnv *jvmti_env) {\n"); 979 | outputHppFile.append(" void __ngen_register_methods(JNIEnv *env, jvmtiEnv *jvmti_env);\n"); 980 | outputCppFile.append(" string_pool = string_pool::get_pool();\n\n"); 981 | 982 | for (Map.Entry clazz : cachedClasses.entrySet()) 983 | outputCppFile.append(" if (jclass clazz = ").append(getGetterForType(clazz.getKey())) 984 | .append(") { cclasses[" + clazz.getValue() 985 | + "] = (jclass) env->NewGlobalRef(clazz); env->DeleteLocalRef(clazz); }\n"); 986 | if (!cachedClasses.isEmpty()) 987 | outputCppFile.append("\n"); 988 | 989 | if (nativeMethodsSb.length() > 0) { 990 | outputCppFile.append(" JNINativeMethod __ngen_methods[] = {\n"); 991 | outputCppFile.append(nativeMethodsSb); 992 | outputCppFile.append(" };\n\n"); 993 | outputCppFile.append(" jclass clazz = ").append(getGetterForType(classNode.name)) 994 | .append(";\n"); 995 | outputCppFile.append( 996 | " if (clazz) env->RegisterNatives(clazz, __ngen_methods, sizeof(__ngen_methods) / sizeof(__ngen_methods[0]));\n"); 997 | outputCppFile.append( 998 | " if (env->ExceptionCheck()) { fprintf(stderr, \"Exception occured while registering native_jvm for %s\\n\", ") 999 | .append(getStringPooledString(classNode.name.replace("/", "."))) 1000 | .append("); fflush(stderr); env->ExceptionDescribe(); env->ExceptionClear(); }\n"); 1001 | outputCppFile.append("\n"); 1002 | } 1003 | if (ifaceStaticNativeMethodsSb.length() > 0) { 1004 | outputCppFile.append(" JNINativeMethod __ngen_static_iface_methods[] = {\n"); 1005 | outputCppFile.append(ifaceStaticNativeMethodsSb); 1006 | outputCppFile.append(" };\n\n"); 1007 | outputCppFile.append(" jclass clazz = utils::find_class_wo_static(env, ") 1008 | .append(getStringPooledString(currentIfaceStaticClass.name.replace("/", "."))) 1009 | .append(");\n"); 1010 | outputCppFile.append( 1011 | " if (clazz) env->RegisterNatives(clazz, __ngen_static_iface_methods, sizeof(__ngen_static_iface_methods) / sizeof(__ngen_static_iface_methods[0]));\n"); 1012 | outputCppFile.append( 1013 | " if (env->ExceptionCheck()) { fprintf(stderr, \"Exception occured while registering native_jvm for %s\\n\", ") 1014 | .append(getStringPooledString(classNode.name.replace("/", "."))) 1015 | .append("); fflush(stderr); env->ExceptionDescribe(); env->ExceptionClear(); }\n"); 1016 | } 1017 | outputCppFile.append(" }\n"); 1018 | outputCppFile.append("}"); 1019 | outputHppFile.append("}\n\n#endif"); 1020 | outputHeaderSb.append(" reg_methods[").append(currentClassId) 1021 | .append("] = &(native_jvm::classes::__ngen_") 1022 | .append(escapeCppNameString(classNode.name.replace("/", "_"))) 1023 | .append("::__ngen_register_methods);\n"); 1024 | } 1025 | currentClassId++; 1026 | } catch (IOException e1) { 1027 | e1.printStackTrace(System.err); 1028 | } 1029 | }); 1030 | Manifest mf = f.getManifest(); 1031 | setupNewIfaceStaticClass(forAndroid); 1032 | for (ClassNode ifaceStaticClass : readyIfaceStaticClasses) { 1033 | ClassWriter classWriter = new SafeClassWriter(metadataReader, 1034 | Opcodes.ASM7 | ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); 1035 | ifaceStaticClass.accept(classWriter); 1036 | writeEntry(out, ifaceStaticClass.name + ".class", classWriter.toByteArray()); 1037 | } 1038 | ClassNode loaderClass = new ClassNode(); 1039 | loaderClass.sourceFile = "synthetic"; 1040 | loaderClass.name = "native" + nativeDirId + "/Loader"; 1041 | if (forAndroid) { // Android 1042 | loaderClass.version = 50; 1043 | } else { 1044 | loaderClass.version = 52; 1045 | } 1046 | 1047 | loaderClass.superName = "java/lang/Object"; 1048 | loaderClass.access = Opcodes.ACC_PUBLIC; 1049 | 1050 | if (forAndroid) { // Android 1051 | MethodNode mainMethod = new MethodNode(Opcodes.ASM7, Opcodes.ACC_STATIC, "", "()V", null, null); 1052 | mainMethod.instructions.add(new LdcInsnNode(projectName)); 1053 | mainMethod.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/System", "loadLibrary", 1054 | "(Ljava/lang/String;)V")); 1055 | mainMethod.instructions.add(new InsnNode(Opcodes.RETURN)); 1056 | loaderClass.methods.add(mainMethod); 1057 | } 1058 | 1059 | MethodNode registerNativesForClassMethod = new MethodNode(Opcodes.ASM7, 1060 | Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_NATIVE, "registerNativesForClass", "(I)V", 1061 | null, new String[0]); 1062 | loaderClass.methods.add(registerNativesForClassMethod); 1063 | ClassWriter classWriter = new SafeClassWriter(metadataReader, 1064 | Opcodes.ASM7 | ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES); 1065 | loaderClass.accept(classWriter); 1066 | writeEntry(out, "native" + nativeDirId + "/Loader.class", classWriter.toByteArray()); 1067 | System.out.println("Jar file ready!"); 1068 | if (!forAndroid) { // Android 1069 | String mainClass = (String) mf.getMainAttributes().get(Name.MAIN_CLASS); 1070 | if (mainClass != null) { 1071 | System.out.println("Creating bootstrap classes..."); 1072 | mf.getMainAttributes().put(Name.MAIN_CLASS, "native" + nativeDirId + "/Bootstrap"); 1073 | ClassNode bootstrapClass = new ClassNode(Opcodes.ASM7); 1074 | bootstrapClass.sourceFile = "synthetic"; 1075 | bootstrapClass.name = "native" + nativeDirId + "/Bootstrap"; 1076 | bootstrapClass.version = 52; 1077 | bootstrapClass.superName = "java/lang/Object"; 1078 | bootstrapClass.access = Opcodes.ACC_PUBLIC; 1079 | MethodNode mainMethod = new MethodNode(Opcodes.ASM7, Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC, 1080 | "main", "([Ljava/lang/String;)V", null, new String[0]); 1081 | mainMethod.instructions.add(new LdcInsnNode(projectName)); 1082 | mainMethod.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "java/lang/System", 1083 | "loadLibrary", "(Ljava/lang/String;)V")); 1084 | mainMethod.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); 1085 | mainMethod.instructions.add(new MethodInsnNode(Opcodes.INVOKESTATIC, mainClass.replace(".", "/"), 1086 | "main", "([Ljava/lang/String;)V")); 1087 | mainMethod.instructions.add(new InsnNode(Opcodes.RETURN)); 1088 | bootstrapClass.methods.add(mainMethod); 1089 | bootstrapClass.accept(classWriter); 1090 | writeEntry(out, "native" + nativeDirId + "/Bootstrap.class", classWriter.toByteArray()); 1091 | System.out.println("Created!"); 1092 | } else { 1093 | System.out.println("Main-Class not found - no bootstrap classes!"); 1094 | } 1095 | out.putNextEntry(new ZipEntry(JarFile.MANIFEST_NAME)); 1096 | mf.write(out); 1097 | } 1098 | out.closeEntry(); 1099 | metadataReader.close(); 1100 | } 1101 | 1102 | TreeMap stringPoolSorted = new TreeMap<>(); 1103 | stringPool.entrySet().forEach((string) -> { 1104 | stringPoolSorted.put(string.getValue(), string.getKey()); 1105 | }); 1106 | List stringPoolResult = new ArrayList<>(); 1107 | stringPoolSorted.entrySet().forEach((string) -> { 1108 | for (byte b : string.getValue().getBytes(StandardCharsets.UTF_8)) 1109 | stringPoolResult.add(b); 1110 | stringPoolResult.add((byte) 0); 1111 | }); 1112 | try (InputStream in = NativeObfuscator.class.getClassLoader().getResourceAsStream("sources/string_pool.cpp")) { 1113 | StringBuilder spValue = new StringBuilder("{ "); 1114 | for (int i = 0; i < stringPoolResult.size(); i++) 1115 | spValue.append(stringPoolResult.get(i)).append(i == stringPoolResult.size() - 1 ? "" : ", "); 1116 | spValue.append(" }"); 1117 | Files.write(outputDir.resolve("cpp").resolve("string_pool.cpp"), 1118 | dynamicFormat(writeStreamToString(in), 1119 | createMap("size", stringPoolResult.size() + "LL", "value", spValue.toString())) 1120 | .getBytes(StandardCharsets.UTF_8), 1121 | StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); 1122 | } 1123 | 1124 | if (!forAndroid) { 1125 | try (InputStream in = NativeObfuscator.class.getClassLoader() 1126 | .getResourceAsStream("sources/native_jvm_output.cpp")) { 1127 | Files.write(outputDir.resolve("cpp").resolve("native_jvm_output.cpp"), 1128 | dynamicFormat(writeStreamToString(in), 1129 | createMap("register_code", outputHeaderSb, "includes", outputHeaderIncludesSb, 1130 | "native_dir_id", nativeDirId, "class_count", currentClassId)) 1131 | .getBytes(StandardCharsets.UTF_8), 1132 | StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); 1133 | } 1134 | 1135 | try (InputStream in = NativeObfuscator.class.getClassLoader() 1136 | .getResourceAsStream("sources/CMakeLists.txt")) { 1137 | Files.write(outputDir.resolve("cpp").resolve("CMakeLists.txt"), 1138 | dynamicFormat(writeStreamToString(in), 1139 | createMap("classfiles", String.join(" ", cmakeClassFiles), "mainfiles", 1140 | String.join(" ", cmakeMainFiles), "projectname", projectName)) 1141 | .getBytes(StandardCharsets.UTF_8), 1142 | StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); 1143 | } 1144 | } else { // Android 1145 | try (InputStream in = NativeObfuscator.class.getClassLoader() 1146 | .getResourceAsStream("sources/android/native_jvm_output.cpp")) { 1147 | Files.write(outputDir.resolve("cpp").resolve("native_jvm_output.cpp"), 1148 | dynamicFormat(writeStreamToString(in), 1149 | createMap("register_code", outputHeaderSb, "includes", outputHeaderIncludesSb, 1150 | "native_dir_id", nativeDirId, "class_count", currentClassId)) 1151 | .getBytes(StandardCharsets.UTF_8), 1152 | StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); 1153 | } 1154 | 1155 | try (InputStream in = NativeObfuscator.class.getClassLoader() 1156 | .getResourceAsStream("sources/android/CMakeLists.txt")) { 1157 | Files.write(outputDir.resolve("cpp").resolve("CMakeLists.txt"), 1158 | dynamicFormat(writeStreamToString(in), 1159 | createMap("classfiles", String.join(" ", cmakeClassFiles), "mainfiles", 1160 | String.join(" ", cmakeMainFiles), "projectname", projectName)) 1161 | .getBytes(StandardCharsets.UTF_8), 1162 | StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING); 1163 | } 1164 | } 1165 | } 1166 | 1167 | private static void writeEntry(JarFile f, ZipOutputStream out, JarEntry e) throws IOException { 1168 | out.putNextEntry(new JarEntry(e.getName())); 1169 | try (InputStream in = f.getInputStream(e)) { 1170 | transfer(in, out); 1171 | } 1172 | out.closeEntry(); 1173 | } 1174 | 1175 | private static void writeEntry(ZipOutputStream out, String entryName, byte[] data) throws IOException { 1176 | out.putNextEntry(new JarEntry(entryName)); 1177 | out.write(data, 0, data.length); 1178 | out.closeEntry(); 1179 | } 1180 | 1181 | private static void transfer(InputStream in, OutputStream out) throws IOException { 1182 | byte[] buffer = new byte[4096]; 1183 | for (int r = in.read(buffer, 0, 4096); r != -1; r = in.read(buffer, 0, 4096)) { 1184 | out.write(buffer, 0, r); 1185 | } 1186 | } 1187 | 1188 | private static int byteArrayToInt(byte[] b) { 1189 | if (b.length == 4) { 1190 | return b[0] << 24 | (b[1] & 0xff) << 16 | (b[2] & 0xff) << 8 | (b[3] & 0xff); 1191 | } else if (b.length == 2) { 1192 | return (b[0] & 0xff) << 8 | (b[1] & 0xff); 1193 | } 1194 | 1195 | return 0; 1196 | } 1197 | } 1198 | -------------------------------------------------------------------------------- /src/ru/gravit/launchserver/asm/ClassMetadataReader.java: -------------------------------------------------------------------------------- 1 | package ru.gravit.launchserver.asm; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | import org.objectweb.asm.ClassReader; 5 | import org.objectweb.asm.ClassVisitor; 6 | import org.objectweb.asm.Opcodes; 7 | 8 | import java.io.IOException; 9 | import java.io.InputStream; 10 | import java.util.ArrayList; 11 | import java.util.Collections; 12 | import java.util.List; 13 | import java.util.jar.JarFile; 14 | 15 | public class ClassMetadataReader { 16 | private class CheckSuperClassVisitor extends ClassVisitor { 17 | 18 | String superClassName; 19 | 20 | public CheckSuperClassVisitor() { 21 | super(Opcodes.ASM7); 22 | } 23 | 24 | @Override 25 | public void visit(int version, int access, String name, String signature, String superName, 26 | String[] interfaces) { 27 | superClassName = superName; 28 | } 29 | } 30 | 31 | private final List classPath; 32 | 33 | public ClassMetadataReader(List classPath) { 34 | this.classPath = classPath; 35 | } 36 | 37 | public List getCp() { 38 | return classPath; 39 | } 40 | 41 | public ClassMetadataReader() { 42 | this.classPath = new ArrayList<>(); 43 | } 44 | 45 | public void acceptVisitor(byte[] classData, ClassVisitor visitor) { 46 | new ClassReader(classData).accept(visitor, 0); 47 | } 48 | 49 | public void acceptVisitor(String className, ClassVisitor visitor) throws IOException, ClassNotFoundException { 50 | acceptVisitor(getClassData(className), visitor); 51 | } 52 | 53 | private static byte[] read(InputStream input) throws IOException { 54 | try (ByteArrayOutputStream output = new ByteArrayOutputStream()) { 55 | byte[] buffer = new byte[4096]; 56 | for (int length = input.read(buffer); length >= 0; length = input.read(buffer)) { 57 | output.write(buffer, 0, length); 58 | } 59 | return output.toByteArray(); 60 | } 61 | } 62 | 63 | public byte[] getClassData(String className) throws IOException, ClassNotFoundException { 64 | for (JarFile file : classPath) { 65 | if (file.getEntry(className + ".class") == null) 66 | continue; 67 | try (InputStream in = file.getInputStream(file.getEntry(className + ".class"))) { 68 | return read(in); 69 | } 70 | } 71 | throw new ClassNotFoundException(className); 72 | } 73 | 74 | public String getSuperClass(String type) { 75 | if (type.equals("java/lang/Object")) return null; 76 | try { 77 | return getSuperClassASM(type); 78 | } catch (IOException | ClassNotFoundException e) { 79 | return "java/lang/Object"; 80 | } 81 | } 82 | 83 | protected String getSuperClassASM(String type) throws IOException, ClassNotFoundException { 84 | CheckSuperClassVisitor cv = new CheckSuperClassVisitor(); 85 | acceptVisitor(type, cv); 86 | return cv.superClassName; 87 | } 88 | 89 | public ArrayList getSuperClasses(String type) { 90 | ArrayList superclasses = new ArrayList<>(1); 91 | superclasses.add(type); 92 | while ((type = getSuperClass(type)) != null) 93 | superclasses.add(type); 94 | Collections.reverse(superclasses); 95 | return superclasses; 96 | } 97 | 98 | public void close() { 99 | classPath.forEach((file) -> { 100 | try { 101 | file.close(); 102 | } catch (IOException ex) { 103 | 104 | } 105 | }); 106 | } 107 | } -------------------------------------------------------------------------------- /src/ru/gravit/launchserver/asm/SafeClassWriter.java: -------------------------------------------------------------------------------- 1 | package ru.gravit.launchserver.asm; 2 | 3 | import org.objectweb.asm.ClassReader; 4 | import org.objectweb.asm.ClassWriter; 5 | 6 | import java.util.ArrayList; 7 | 8 | public class SafeClassWriter extends ClassWriter { 9 | 10 | private final ClassMetadataReader classMetadataReader; 11 | 12 | public SafeClassWriter(ClassMetadataReader classMetadataReader, int flags) { 13 | super(flags); 14 | this.classMetadataReader = classMetadataReader; 15 | } 16 | 17 | public SafeClassWriter(ClassReader classReader, ClassMetadataReader classMetadataReader, int flags) { 18 | super(classReader, flags); 19 | this.classMetadataReader = classMetadataReader; 20 | } 21 | 22 | @Override 23 | protected String getCommonSuperClass(String type1, String type2) { 24 | ArrayList superClasses1 = classMetadataReader.getSuperClasses(type1); 25 | ArrayList superClasses2 = classMetadataReader.getSuperClasses(type2); 26 | int size = Math.min(superClasses1.size(), superClasses2.size()); 27 | int i = 0; 28 | while (i < size && superClasses1.get(i).equals(superClasses2.get(i))) 29 | i++; 30 | if (i == 0) 31 | return "java/lang/Object"; 32 | else 33 | return superClasses1.get(i - 1); 34 | } 35 | 36 | } -------------------------------------------------------------------------------- /src/sources/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.8) 2 | project($projectname) 3 | set(CMAKE_CXX_STANDARD 17) 4 | 5 | set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY build/lib) 6 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY build/lib) 7 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY build/lib) 8 | 9 | if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") 10 | if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 6.0) 11 | message(FATAL_ERROR "GCC version must be at least 6.0!") 12 | endif() 13 | elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") 14 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY build/lib) 15 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG build/lib) 16 | set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE build/lib) 17 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY build/lib) 18 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG build/lib) 19 | set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE build/lib) 20 | set(CMAKE_CXX_FLAGS /MP8) 21 | set(CMAKE_CXX_FLAGS /wd4102) 22 | set(CMAKE_CXX_FLAGS /EHsc) 23 | else() 24 | message(FATAL_ERROR "You are using an unsupported compiler! Compilation has only been tested with MSVC and GCC.") 25 | endif() 26 | 27 | find_package(JNI REQUIRED) 28 | include_directories(${JNI_INCLUDE_DIRS}) 29 | 30 | set(CLASS_FILES $classfiles) 31 | set(MAIN_FILES $mainfiles) 32 | add_library($projectname SHARED ${CLASS_FILES} ${MAIN_FILES}) 33 | -------------------------------------------------------------------------------- /src/sources/android/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # For more information about using CMake with Android Studio, read the 2 | # documentation: https://d.android.com/studio/projects/add-native-code.html 3 | 4 | # Sets the minimum version of CMake required to build the native library. 5 | 6 | cmake_minimum_required(VERSION 3.8) 7 | 8 | set(CMAKE_CXX_STANDARD 17) 9 | 10 | set(CLASS_FILES $classfiles) 11 | set(MAIN_FILES $mainfiles) 12 | add_library($projectname SHARED ${CLASS_FILES} ${MAIN_FILES}) 13 | -------------------------------------------------------------------------------- /src/sources/android/native_jvm_output.cpp: -------------------------------------------------------------------------------- 1 | #include "native_jvm.hpp" 2 | #include "native_jvm_output.hpp" 3 | 4 | $includes 5 | 6 | namespace native_jvm { 7 | 8 | typedef void (* reg_method)(JNIEnv *,jvmtiEnv *); 9 | 10 | reg_method reg_methods[$class_count]; 11 | 12 | void register_for_class(JNIEnv *env, jclass, jint id) { 13 | jvmtiEnv *jvmti_env = nullptr; 14 | JavaVM *vm = nullptr; 15 | env->GetJavaVM(&vm); 16 | vm->GetEnv((void **)&jvmti_env, JVMTI_VERSION); 17 | 18 | reg_methods[id](env, jvmti_env); 19 | } 20 | 21 | void prepare_lib(JNIEnv *env, jvmtiEnv *jvmti_env) { 22 | utils::init_utils(env); 23 | if (env->ExceptionCheck()) 24 | return; 25 | 26 | $register_code 27 | 28 | char method_name[] = "registerNativesForClass"; 29 | char method_desc[] = "(I)V"; 30 | JNINativeMethod loader_methods[] = { 31 | { (char *) method_name, (char *) method_desc, (void *)®ister_for_class } 32 | }; 33 | env->RegisterNatives(env->FindClass("native$native_dir_id/Loader"), loader_methods, 1); 34 | } 35 | } 36 | 37 | extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { 38 | JNIEnv *env = nullptr; 39 | jvmtiEnv *jvmti_env = nullptr; 40 | vm->GetEnv((void **)&env, JNI_VERSION_1_6); 41 | vm->GetEnv((void **)&jvmti_env, JVMTI_VERSION); 42 | native_jvm::prepare_lib(env, jvmti_env); 43 | return JNI_VERSION_1_6; 44 | } -------------------------------------------------------------------------------- /src/sources/cppsnippets.properties: -------------------------------------------------------------------------------- 1 | LOCAL_LOAD_ARG_1=clocals.set($index, $arg); 2 | LOCAL_LOAD_ARG_2=clocals.set($index, $arg); 3 | LOCAL_LOAD_ARG_3=clocals.set($index, $arg); 4 | LOCAL_LOAD_ARG_4=clocals.set($index, $arg); 5 | LOCAL_LOAD_ARG_5=clocals.set($index, $arg); 6 | LOCAL_LOAD_ARG_6=clocals.set($index, utils::cfi($arg)); 7 | LOCAL_LOAD_ARG_7=clocals.set2($index, $arg); 8 | LOCAL_LOAD_ARG_8=clocals.set2($index, utils::cdl($arg)); 9 | LOCAL_LOAD_ARG_9=clocals.setref($index, $arg); refs.insert(clocals.getref($index)); 10 | LOCAL_LOAD_ARG_10=clocals.setref($index, $arg); refs.insert(clocals.getref($index)); 11 | LOCAL_LOAD_ARG_11=clocals.setref($index, $arg); refs.insert(clocals.getref($index)); 12 | 13 | NOP=; 14 | ACONST_NULL=cstack.pushref(nullptr); 15 | ICONST_M1=cstack.push(-1); 16 | ICONST_0=cstack.push(0); 17 | ICONST_1=cstack.push(1); 18 | ICONST_2=cstack.push(2); 19 | ICONST_3=cstack.push(3); 20 | ICONST_4=cstack.push(4); 21 | ICONST_5=cstack.push(5); 22 | LCONST_0=cstack.push2(0); 23 | LCONST_1=cstack.push2(1); 24 | FCONST_0=cstack.push(utils::cfi(0.0f)); 25 | FCONST_1=cstack.push(utils::cfi(1.0f)); 26 | FCONST_2=cstack.push(utils::cfi(2.0f)); 27 | DCONST_0=cstack.push2(utils::cdl(0.0)); 28 | DCONST_1=cstack.push2(utils::cdl(1.0)); 29 | BIPUSH=cstack.push($operand); 30 | SIPUSH=cstack.push($operand); 31 | LDC_STRING=cstack.pushref(env->NewStringUTF($cst)); refs.insert(cstack.fetchref(0)); $trycatchhandler 32 | LDC_STRING_S_VARS=$cst 33 | LDC_INT=cstack.push($cst); 34 | LDC_FLOAT=cstack.push(utils::cfi($cst)); 35 | LDC_LONG=cstack.push2($cst); 36 | LDC_DOUBLE=cstack.push2(utils::cdl($cst)); 37 | LDC_CLASS=cstack.pushref($cst_ptr); 38 | ILOAD=cstack.push(clocals.get($var)); 39 | LLOAD=cstack.push2(clocals.get2($var)); 40 | FLOAD=cstack.push(clocals.get($var)); 41 | DLOAD=cstack.push2(clocals.get2($var)); 42 | ALOAD=cstack.pushref(clocals.getref($var)); refs.insert(cstack.fetchref(0)); 43 | IALOAD=if (cstack.fetchref(1) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else { env->GetIntArrayRegion((jintArray) cstack.fetchref(1), cstack.fetch(0), 1, (jint *) cstack.getptr(1)); cstack.popcnt(1); } $trycatchhandler 44 | IALOAD_S_VARS=#NPE,#ERROR_DESC 45 | IALOAD_S_CONST_NPE=java/lang/NullPointerException 46 | IALOAD_S_CONST_ERROR_DESC=IALOAD npe 47 | LALOAD=if (cstack.fetchref(1) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else { env->GetLongArrayRegion((jlongArray) cstack.fetchref(1), cstack.fetch(0), 1, (jlong *) cstack.getptr2(0)); } $trycatchhandler 48 | LALOAD_S_VARS=#NPE,#ERROR_DESC 49 | LALOAD_S_CONST_NPE=java/lang/NullPointerException 50 | LALOAD_S_CONST_ERROR_DESC=LALOAD npe 51 | FALOAD=if (cstack.fetchref(1) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else { env->GetFloatArrayRegion((jfloatArray) cstack.fetchref(1), cstack.fetch(0), 1, (jfloat *) cstack.getptr(1)); cstack.popcnt(1); } $trycatchhandler 52 | FALOAD_S_VARS=#NPE,#ERROR_DESC 53 | FALOAD_S_CONST_NPE=java/lang/NullPointerException 54 | FALOAD_S_CONST_ERROR_DESC=FALOAD npe 55 | DALOAD=if (cstack.fetchref(1) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else { env->GetDoubleArrayRegion((jdoubleArray) cstack.fetchref(1), cstack.fetch(0), 1, (jdouble *) cstack.getptr2(0)); } $trycatchhandler 56 | DALOAD_S_VARS=#NPE,#ERROR_DESC 57 | DALOAD_S_CONST_NPE=java/lang/NullPointerException 58 | DALOAD_S_CONST_ERROR_DESC=DALOAD npe 59 | AALOAD=if (cstack.fetchref(1) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else { cstack.setref(1, env->GetObjectArrayElement((jobjectArray) cstack.fetchref(1), cstack.fetch(0))); cstack.popcnt(1); refs.insert(cstack.fetchref(0)); } $trycatchhandler 60 | AALOAD_S_VARS=#NPE,#ERROR_DESC 61 | AALOAD_S_CONST_NPE=java/lang/NullPointerException 62 | AALOAD_S_CONST_ERROR_DESC=AALOAD npe 63 | BALOAD=if (cstack.fetchref(1) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else { cstack.set(1, utils::baload(env, (jarray) cstack.fetchref(1), cstack.fetch(0))); cstack.popcnt(1); } $trycatchhandler 64 | BALOAD_S_VARS=#NPE,#ERROR_DESC 65 | BALOAD_S_CONST_NPE=java/lang/NullPointerException 66 | BALOAD_S_CONST_ERROR_DESC=BALOAD npe 67 | CALOAD=if (cstack.fetchref(1) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else { env->GetCharArrayRegion((jcharArray) cstack.fetchref(1), cstack.fetch(0), 1, (jchar *) cstack.getptr(1)); cstack.set(1, cstack.fetch(1) & 0xffff); cstack.popcnt(1); } $trycatchhandler 68 | CALOAD_S_VARS=#NPE,#ERROR_DESC 69 | CALOAD_S_CONST_NPE=java/lang/NullPointerException 70 | CALOAD_S_CONST_ERROR_DESC=CALOAD npe 71 | SALOAD=if (cstack.fetchref(1) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else { env->GetShortArrayRegion((jshortArray) cstack.fetchref(1), cstack.fetch(0), 1, (jshort *) cstack.getptr(1)); cstack.set(1, cstack.fetch(1) & 0xffff); cstack.popcnt(1); } $trycatchhandler 72 | SALOAD_S_VARS=#NPE,#ERROR_DESC 73 | SALOAD_S_CONST_NPE=java/lang/NullPointerException 74 | SALOAD_S_CONST_ERROR_DESC=SALOAD npe 75 | ISTORE=clocals.set($var, cstack.pop()); 76 | LSTORE=clocals.set2($var, cstack.pop2()); 77 | FSTORE=clocals.set($var, cstack.pop()); 78 | DSTORE=clocals.set2($var, cstack.pop2()); 79 | ASTORE=clocals.setref($var, cstack.popref()); refs.insert(clocals.getref($var)); 80 | IASTORE=if (cstack.fetchref(2) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else { env->SetIntArrayRegion((jintArray) cstack.fetchref(2), cstack.fetch(1), 1, (jint *) cstack.getptr(0)); cstack.popcnt(3); } $trycatchhandler 81 | IASTORE_S_VARS=#NPE,#ERROR_DESC 82 | IASTORE_S_CONST_NPE=java/lang/NullPointerException 83 | IASTORE_S_CONST_ERROR_DESC=IASTORE npe 84 | LASTORE=if (cstack.fetchref(3) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else { env->SetLongArrayRegion((jlongArray) cstack.fetchref(3), cstack.fetch(2), 1, (jlong *) cstack.getptr2(0)); cstack.popcnt(4); } $trycatchhandler 85 | LASTORE_S_VARS=#NPE,#ERROR_DESC 86 | LASTORE_S_CONST_NPE=java/lang/NullPointerException 87 | LASTORE_S_CONST_ERROR_DESC=LASTORE npe 88 | FASTORE=if (cstack.fetchref(2) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else { env->SetFloatArrayRegion((jfloatArray) cstack.fetchref(2), cstack.fetch(1), 1, (jfloat *) cstack.getptr(0)); cstack.popcnt(3); } $trycatchhandler 89 | FASTORE_S_VARS=#NPE,#ERROR_DESC 90 | FASTORE_S_CONST_NPE=java/lang/NullPointerException 91 | FASTORE_S_CONST_ERROR_DESC=FASTORE npe 92 | DASTORE=if (cstack.fetchref(3) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else { env->SetDoubleArrayRegion((jdoubleArray) cstack.fetchref(3), cstack.fetch(2), 1, (jdouble *) cstack.getptr2(0)); cstack.popcnt(4); } $trycatchhandler 93 | DASTORE_S_VARS=#NPE,#ERROR_DESC 94 | DASTORE_S_CONST_NPE=java/lang/NullPointerException 95 | DASTORE_S_CONST_ERROR_DESC=DASTORE npe 96 | AASTORE=if (cstack.fetchref(2) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else { env->SetObjectArrayElement((jobjectArray) cstack.fetchref(2), cstack.fetch(1), cstack.fetchref(0)); cstack.popcnt(3); } $trycatchhandler 97 | AASTORE_S_VARS=#NPE,#ERROR_DESC 98 | AASTORE_S_CONST_NPE=java/lang/NullPointerException 99 | AASTORE_S_CONST_ERROR_DESC=AASTORE npe 100 | BASTORE=if (cstack.fetchref(2) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else { utils::bastore(env, (jarray) cstack.fetchref(2), cstack.fetch(1), cstack.fetch(0)); cstack.popcnt(3); } $trycatchhandler 101 | BASTORE_S_VARS=#NPE,#ERROR_DESC 102 | BASTORE_S_CONST_NPE=java/lang/NullPointerException 103 | BASTORE_S_CONST_ERROR_DESC=BASTORE npe 104 | CASTORE=if (cstack.fetchref(2) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else { env->SetCharArrayRegion((jcharArray) cstack.fetchref(2), cstack.fetch(1), 1, (jchar *) cstack.getptr(0)); cstack.popcnt(3); } $trycatchhandler 105 | CASTORE_S_VARS=#NPE,#ERROR_DESC 106 | CASTORE_S_CONST_NPE=java/lang/NullPointerException 107 | CASTORE_S_CONST_ERROR_DESC=CASTORE npe 108 | SASTORE=if (cstack.fetchref(2) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else { env->SetShortArrayRegion((jshortArray) cstack.fetchref(2), cstack.fetch(1), 1, (jshort *) cstack.getptr(0)); cstack.popcnt(3); } $trycatchhandler 109 | SASTORE_S_VARS=#NPE,#ERROR_DESC 110 | SASTORE_S_CONST_NPE=java/lang/NullPointerException 111 | SASTORE_S_CONST_ERROR_DESC=SASTORE npe 112 | POP=cstack.pop(); 113 | POP2=cstack.pop2(); 114 | DUP=memmove(&cstack.data[cstack.sptr - 0], &cstack.data[cstack.sptr - 1], 1 * sizeof(cstack.data[0])); memmove(&cstack.data[cstack.sptr - 1], &cstack.data[cstack.sptr], 1 * sizeof(cstack.data[0])); \n memmove(&cstack.refs[cstack.sptr - 0], &cstack.refs[cstack.sptr - 1], 1 * sizeof(cstack.refs[0])); memmove(&cstack.refs[cstack.sptr - 1], &cstack.refs[cstack.sptr], 1 * sizeof(cstack.refs[0]));\n cstack.sptr++; 115 | DUP_X1=memmove(&cstack.data[cstack.sptr - 1], &cstack.data[cstack.sptr - 2], 2 * sizeof(cstack.data[0])); memmove(&cstack.data[cstack.sptr - 2], &cstack.data[cstack.sptr], 1 * sizeof(cstack.data[0])); \n memmove(&cstack.refs[cstack.sptr - 1], &cstack.refs[cstack.sptr - 2], 2 * sizeof(cstack.refs[0])); memmove(&cstack.refs[cstack.sptr - 2], &cstack.refs[cstack.sptr], 1 * sizeof(cstack.refs[0]));\n cstack.sptr++; 116 | DUP_X2=memmove(&cstack.data[cstack.sptr - 2], &cstack.data[cstack.sptr - 3], 3 * sizeof(cstack.data[0])); memmove(&cstack.data[cstack.sptr - 3], &cstack.data[cstack.sptr], 1 * sizeof(cstack.data[0])); \n memmove(&cstack.refs[cstack.sptr - 2], &cstack.refs[cstack.sptr - 3], 3 * sizeof(cstack.refs[0])); memmove(&cstack.refs[cstack.sptr - 3], &cstack.refs[cstack.sptr], 1 * sizeof(cstack.refs[0]));\n cstack.sptr++; 117 | DUP2=memmove(&cstack.data[cstack.sptr - 0], &cstack.data[cstack.sptr - 2], 2 * sizeof(cstack.data[0])); memmove(&cstack.data[cstack.sptr - 2], &cstack.data[cstack.sptr], 2 * sizeof(cstack.data[0])); \n memmove(&cstack.refs[cstack.sptr - 0], &cstack.refs[cstack.sptr - 2], 2 * sizeof(cstack.refs[0])); memmove(&cstack.refs[cstack.sptr - 2], &cstack.refs[cstack.sptr], 2 * sizeof(cstack.refs[0]));\n cstack.sptr += 2; 118 | DUP2_X1=memmove(&cstack.data[cstack.sptr - 1], &cstack.data[cstack.sptr - 3], 3 * sizeof(cstack.data[0])); memmove(&cstack.data[cstack.sptr - 3], &cstack.data[cstack.sptr], 2 * sizeof(cstack.data[0]));\n memmove(&cstack.refs[cstack.sptr - 1], &cstack.refs[cstack.sptr - 3], 3 * sizeof(cstack.refs[0])); memmove(&cstack.refs[cstack.sptr - 3], &cstack.refs[cstack.sptr], 2 * sizeof(cstack.refs[0]));\n cstack.sptr += 2; 119 | DUP2_X2=memmove(&cstack.data[cstack.sptr - 2], &cstack.data[cstack.sptr - 4], 4 * sizeof(cstack.data[0])); memmove(&cstack.data[cstack.sptr - 4], &cstack.data[cstack.sptr], 2 * sizeof(cstack.data[0]));\n memmove(&cstack.refs[cstack.sptr - 2], &cstack.refs[cstack.sptr - 4], 4 * sizeof(cstack.refs[0])); memmove(&cstack.refs[cstack.sptr - 4], &cstack.refs[cstack.sptr], 2 * sizeof(cstack.refs[0]));\n cstack.sptr += 2; 120 | SWAP={ jint temp = cstack.fetch(0); cstack.set(0, cstack.get(1)); cstack.set(1, temp); } 121 | IADD=cstack.set(1, cstack.fetch(1) + cstack.fetch(0)); cstack.popcnt(1); 122 | LADD=cstack.set2(1, cstack.fetch2(1) + cstack.fetch2(0)); cstack.popcnt(2); 123 | FADD=cstack.set(1, utils::cfi(utils::cif(cstack.fetch(1)) + utils::cif(cstack.fetch(0)))); cstack.popcnt(1); 124 | DADD=cstack.set2(1, utils::cdl(utils::cld(cstack.fetch2(1)) + utils::cld(cstack.fetch2(0)))); cstack.popcnt(2); 125 | ISUB=cstack.set(1, cstack.fetch(1) - cstack.fetch(0)); cstack.popcnt(1); 126 | LSUB=cstack.set2(1, cstack.fetch2(1) - cstack.fetch2(0)); cstack.popcnt(2); 127 | FSUB=cstack.set(1, utils::cfi(utils::cif(cstack.fetch(1)) - utils::cif(cstack.fetch(0)))); cstack.popcnt(1); 128 | DSUB=cstack.set2(1, utils::cdl(utils::cld(cstack.fetch2(1)) - utils::cld(cstack.fetch2(0)))); cstack.popcnt(2); 129 | IMUL=cstack.set(1, cstack.fetch(1) * cstack.fetch(0)); cstack.popcnt(1); 130 | LMUL=cstack.set2(1, cstack.fetch2(1) * cstack.fetch2(0)); cstack.popcnt(2); 131 | FMUL=cstack.set(1, utils::cfi(utils::cif(cstack.fetch(1)) * utils::cif(cstack.fetch(0)))); cstack.popcnt(1); 132 | DMUL=cstack.set2(1, utils::cdl(utils::cld(cstack.fetch2(1)) * utils::cld(cstack.fetch2(0)))); cstack.popcnt(2); 133 | IDIV=if (cstack.fetch(0) == 0) utils::throw_re(env, #AE, #ERROR_DESC, $line); else { cstack.set(1, cstack.fetch(1) / cstack.fetch(0)); cstack.popcnt(1); } $trycatchhandler 134 | IDIV_S_VARS=#AE,#ERROR_DESC 135 | IDIV_S_CONST_AE=java/lang/ArithmeticException 136 | IDIV_S_CONST_ERROR_DESC=IDIV / by 0 137 | LDIV=if (cstack.fetch2(0) == 0) utils::throw_re(env, #AE, #ERROR_DESC, $line); else { cstack.set2(1, cstack.fetch2(1) / cstack.fetch2(0)); cstack.popcnt(2); } $trycatchhandler 138 | LDIV_S_VARS=#AE,#ERROR_DESC 139 | LDIV_S_CONST_AE=java/lang/ArithmeticException 140 | LDIV_S_CONST_ERROR_DESC=LDIV / by 0 141 | FDIV=cstack.set(1, utils::cfi(utils::cif(cstack.fetch(1)) / utils::cif(cstack.fetch(0)))); cstack.popcnt(1); 142 | DDIV=cstack.set2(1, utils::cdl(utils::cld(cstack.fetch2(1)) / utils::cld(cstack.fetch2(0)))); cstack.popcnt(2); 143 | IREM=if (cstack.fetch(0) == 0) utils::throw_re(env, #AE, #ERROR_DESC, $line); else { cstack.set(1, cstack.fetch(1) % cstack.fetch(0)); cstack.popcnt(1); } $trycatchhandler 144 | IREM_S_VARS=#AE,#ERROR_DESC 145 | IREM_S_CONST_AE=java/lang/ArithmeticException 146 | IREM_S_CONST_ERROR_DESC=IREM % by 0 147 | LREM=if (cstack.fetch2(0) == 0) utils::throw_re(env, #AE, #ERROR_DESC, $line); else { cstack.set2(1, cstack.fetch2(1) % cstack.fetch2(0)); cstack.popcnt(2); } $trycatchhandler 148 | LREM_S_VARS=#AE,#ERROR_DESC 149 | LREM_S_CONST_AE=java/lang/ArithmeticException 150 | LREM_S_CONST_ERROR_DESC=LREM % by 0 151 | FREM=cstack.set(1, utils::cfi(std::fmod(utils::cif(cstack.fetch(1)), utils::cif(cstack.fetch(0))))); cstack.popcnt(1); 152 | DREM=cstack.set2(1, utils::cdl(std::fmod(utils::cld(cstack.fetch2(1)), utils::cld(cstack.fetch2(0))))); cstack.popcnt(2); 153 | INEG=cstack.set(0, -cstack.fetch(0)); 154 | LNEG=cstack.set2(0, -cstack.fetch2(0)); 155 | FNEG=cstack.set(0, utils::cfi(-utils::cif(cstack.fetch(0)))); 156 | DNEG=cstack.set2(0, utils::cdl(-utils::cld(cstack.fetch2(0)))); 157 | ISHL=cstack.set(1, cstack.fetch(1) * (1 << (0x1f & cstack.fetch(0)))); cstack.popcnt(1); 158 | LSHL=cstack.set2raw(2, cstack.fetch2raw(2) * (1LL << (0x1f & cstack.fetch(0)))); cstack.popcnt(1); 159 | ISHR=cstack.set(1, cstack.fetch(1) / (1 << (0x1f & cstack.fetch(0)))); cstack.popcnt(1); 160 | LSHR=cstack.set2raw(2, cstack.fetch2raw(2) / (1LL << (0x1f & cstack.fetch(0)))); cstack.popcnt(1); 161 | IUSHR=cstack.set(1, (jint) (((uint32_t) cstack.fetch(1)) >> ((uint32_t) cstack.fetch(0)))); cstack.popcnt(1); 162 | LUSHR=cstack.set2raw(2, (jlong) (((uint64_t) cstack.fetch2raw(2)) >> ((uint64_t) cstack.fetch(0)))); cstack.popcnt(1); 163 | IAND=cstack.set(1, cstack.fetch(1) & cstack.fetch(0)); cstack.popcnt(1); 164 | LAND=cstack.set2(1, cstack.fetch2(1) & cstack.fetch2(0)); cstack.popcnt(2); 165 | IOR=cstack.set(1, cstack.fetch(1) | cstack.fetch(0)); cstack.popcnt(1); 166 | LOR=cstack.set2(1, cstack.fetch2(1) | cstack.fetch2(0)); cstack.popcnt(2); 167 | IXOR=cstack.set(1, cstack.fetch(1) ^ cstack.fetch(0)); cstack.popcnt(1); 168 | LXOR=cstack.set2(1, cstack.fetch2(1) ^ cstack.fetch2(0)); cstack.popcnt(2); 169 | IINC=clocals.set($var, clocals.get($var) + $incr); 170 | I2L=cstack.push2((jlong) cstack.pop()); 171 | I2F=cstack.push(utils::cfi((jfloat) cstack.pop())); 172 | I2D=cstack.push2(utils::cdl((jdouble) cstack.pop())); 173 | L2I=cstack.push((jint) cstack.pop2()); 174 | L2F=cstack.push(utils::cfi((jfloat) cstack.pop2())); 175 | L2D=cstack.push2(utils::cdl((jdouble) cstack.pop2())); 176 | 177 | F2I=cstack.push(utils::cast_fi(utils::cif(cstack.pop()))); 178 | F2L=cstack.push2(utils::cast_fl(utils::cif(cstack.pop()))); 179 | 180 | F2D=cstack.push2(utils::cdl((jdouble) utils::cif(cstack.pop()))); 181 | 182 | D2I=cstack.push(utils::cast_di(utils::cld(cstack.pop2()))); 183 | D2L=cstack.push2(utils::cast_dl(utils::cld(cstack.pop2()))); 184 | 185 | D2F=cstack.push(utils::cfi((jfloat) utils::cld(cstack.pop2()))); 186 | I2B=cstack.push((jbyte) (cstack.pop() & 0xff)); 187 | I2C=cstack.push((jchar) (cstack.pop() & 0xffff)); 188 | I2S=cstack.push((jshort) (cstack.pop() & 0xffff)); 189 | LCMP=cstack.set(3, (cstack.fetch2(1) == cstack.fetch2(0)) ? 0 : (cstack.fetch2(1) < cstack.fetch2(0) ? -1 : 1)); cstack.popcnt(3); 190 | FCMPL={ jfloat value2 = utils::cif(cstack.pop()); jfloat value1 = utils::cif(cstack.pop()); cstack.push(value1 > value2 ? 1 : ((value1 == value2) ? 0 : ((value1 < value2) ? -1 : -1))); } 191 | FCMPG={ jfloat value2 = utils::cif(cstack.pop()); jfloat value1 = utils::cif(cstack.pop()); cstack.push(value1 > value2 ? 1 : ((value1 == value2) ? 0 : ((value1 < value2) ? -1 : 1))); } 192 | DCMPL={ jdouble value2 = utils::cld(cstack.pop2()); jdouble value1 = utils::cld(cstack.pop2()); cstack.push(value1 > value2 ? 1 : ((value1 == value2) ? 0 : ((value1 < value2) ? -1 : -1))); } 193 | DCMPG={ jdouble value2 = utils::cld(cstack.pop2()); jdouble value1 = utils::cld(cstack.pop2()); cstack.push(value1 > value2 ? 1 : ((value1 == value2) ? 0 : ((value1 < value2) ? -1 : 1))); } 194 | IFEQ=if (cstack.pop() == 0) goto $label; 195 | IFNE=if (cstack.pop() != 0) goto $label; 196 | IFLT=if (cstack.pop() < 0) goto $label; 197 | IFLE=if (cstack.pop() <= 0) goto $label; 198 | IFGT=if (cstack.pop() > 0) goto $label; 199 | IFGE=if (cstack.pop() >= 0) goto $label; 200 | IF_ICMPEQ=if (cstack.pop() == cstack.pop()) goto $label; 201 | IF_ICMPNE=if (cstack.pop() != cstack.pop()) goto $label; 202 | IF_ICMPLT=if (cstack.pop() > cstack.pop()) goto $label; 203 | IF_ICMPLE=if (cstack.pop() >= cstack.pop()) goto $label; 204 | IF_ICMPGT=if (cstack.pop() < cstack.pop()) goto $label; 205 | IF_ICMPGE=if (cstack.pop() <= cstack.pop()) goto $label; 206 | IF_ACMPEQ=if (env->IsSameObject(cstack.popref(), cstack.popref())) goto $label; 207 | IF_ACMPNE=if (!env->IsSameObject(cstack.popref(), cstack.popref())) goto $label; 208 | GOTO=goto $label; 209 | IRETURN=return ($rettype) cstack.pop(); 210 | LRETURN=return ($rettype) cstack.pop2(); 211 | FRETURN=return ($rettype) utils::cif(cstack.pop()); 212 | DRETURN=return ($rettype) utils::cld(cstack.pop2()); 213 | ARETURN=return ($rettype) cstack.popref(); 214 | RETURN=return; 215 | NEW=if (jobject obj = env->AllocObject($desc_ptr)) { cstack.pushref(obj); refs.insert(cstack.fetchref(0)); } $trycatchhandler 216 | ANEWARRAY=if (cstack.fetch(0) < 0) utils::throw_re(env, #NASE, #ERROR_DESC, $line); else { cstack.pushref(env->NewObjectArray(cstack.pop(), $desc_ptr, nullptr)); refs.insert(cstack.fetchref(0)); } $trycatchhandler 217 | ANEWARRAY_S_VARS=#NASE,#ERROR_DESC 218 | ANEWARRAY_S_CONST_NASE=java/lang/NegativeArraySizeException 219 | ANEWARRAY_S_CONST_ERROR_DESC=ANEWARRAY array size < 0 220 | ARRAYLENGTH=if (cstack.fetchref(0) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else cstack.push(env->GetArrayLength((jarray) cstack.popref())); $trycatchhandler 221 | ARRAYLENGTH_S_VARS=#NPE,#ERROR_DESC 222 | ARRAYLENGTH_S_CONST_NPE=java/lang/NullPointerException 223 | ARRAYLENGTH_S_CONST_ERROR_DESC=ARRAYLENGTH npe 224 | ATHROW=if (cstack.fetchref(0) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else { jthrowable exception = (jthrowable) cstack.popref(); env->Throw(exception); cstack.clear(); cstack.pushref(exception); refs.insert(cstack.fetchref(0)); } $trycatchhandler 225 | ATHROW_S_VARS=#NPE,#ERROR_DESC 226 | ATHROW_S_CONST_NPE=java/lang/NullPointerException 227 | ATHROW_S_CONST_ERROR_DESC=ATHROW npe 228 | INSTANCEOF=cstack.push(cstack.fetchref(0) == nullptr ? cstack.popref() != nullptr : env->IsInstanceOf(cstack.popref(), $desc_ptr)); 229 | MONITORENTER=if (cstack.fetchref(0) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else env->MonitorEnter(cstack.popref()); $trycatchhandler 230 | MONITORENTER_S_VARS=#NPE,#ERROR_DESC 231 | MONITORENTER_S_CONST_NPE=java/lang/NullPointerException 232 | MONITORENTER_S_CONST_ERROR_DESC=MONITORENTER npe 233 | MONITOREXIT=if (cstack.fetchref(0) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else env->MonitorExit(cstack.popref()); $trycatchhandler 234 | MONITOREXIT_S_VARS=#NPE,#ERROR_DESC 235 | MONITOREXIT_S_CONST_NPE=java/lang/NullPointerException 236 | MONITOREXIT_S_CONST_ERROR_DESC=MONITORENTER npe 237 | IFNULL=if (cstack.popref() == nullptr) goto $label; 238 | IFNONNULL=if (cstack.popref() != nullptr) goto $label; 239 | TABLESWITCH_START=switch (cstack.pop()) { 240 | TABLESWITCH_PART= case $index: goto $label; break; 241 | TABLESWITCH_DEFAULT= default: goto $label; break; 242 | TABLESWITCH_END=} 243 | LOOKUPSWITCH_START=switch (cstack.pop()) { 244 | LOOKUPSWITCH_PART= case $key: goto $label; break; 245 | LOOKUPSWITCH_DEFAULT= default: goto $label; break; 246 | LOOKUPSWITCH_END=} 247 | TRYCATCH_START=if (env->ExceptionCheck()) { cstack.clear(); jthrowable exception = env->ExceptionOccurred(); env->ExceptionClear(); cstack.pushref(exception); refs.insert(cstack.fetchref(0)); 248 | TRYCATCH_CHECK=if (env->IsInstanceOf(exception, $exception_class_ptr)) { goto $handler_block; } 249 | TRYCATCH_ANY_L=goto $handler_block; 250 | TRYCATCH_END=env->Throw(exception); return ($rettype) 0; } 251 | TRYCATCH_EMPTY=if (env->ExceptionCheck()) { return ($rettype) 0; } 252 | 253 | GETSTATIC_1=cstack.push(env->GetStaticBooleanField($class_ptr, $fieldid)); $trycatchhandler 254 | GETSTATIC_2=cstack.push(env->GetStaticCharField($class_ptr, $fieldid)); $trycatchhandler 255 | GETSTATIC_3=cstack.push(env->GetStaticByteField($class_ptr, $fieldid)); $trycatchhandler 256 | GETSTATIC_4=cstack.push(env->GetStaticShortField($class_ptr, $fieldid)); $trycatchhandler 257 | GETSTATIC_5=cstack.push(env->GetStaticIntField($class_ptr, $fieldid)); $trycatchhandler 258 | GETSTATIC_6=cstack.push(utils::cfi(env->GetStaticFloatField($class_ptr, $fieldid))); $trycatchhandler 259 | GETSTATIC_7=cstack.push2(env->GetStaticLongField($class_ptr, $fieldid)); $trycatchhandler 260 | GETSTATIC_8=cstack.push2(utils::cdl(env->GetStaticDoubleField($class_ptr, $fieldid))); $trycatchhandler 261 | GETSTATIC_9=cstack.pushref(env->GetStaticObjectField($class_ptr, $fieldid)); refs.insert(cstack.fetchref(0)); $trycatchhandler 262 | GETSTATIC_10=cstack.pushref(env->GetStaticObjectField($class_ptr, $fieldid)); refs.insert(cstack.fetchref(0)); $trycatchhandler 263 | GETSTATIC_11=cstack.pushref(env->GetStaticObjectField($class_ptr, $fieldid)); refs.insert(cstack.fetchref(0)); $trycatchhandler 264 | 265 | GETFIELD_1=if (cstack.fetchref(0) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else cstack.push(env->GetBooleanField(cstack.popref(), $fieldid)); $trycatchhandler 266 | GETFIELD_1_S_VARS=#NPE,#ERROR_DESC 267 | GETFIELD_1_S_CONST_NPE=java/lang/NullPointerException 268 | GETFIELD_1_S_CONST_ERROR_DESC=GETFIELD Boolean npe 269 | GETFIELD_2=if (cstack.fetchref(0) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else cstack.push(env->GetCharField(cstack.popref(), $fieldid)); $trycatchhandler 270 | GETFIELD_2_S_VARS=#NPE,#ERROR_DESC 271 | GETFIELD_2_S_CONST_NPE=java/lang/NullPointerException 272 | GETFIELD_2_S_CONST_ERROR_DESC=GETFIELD Char npe 273 | GETFIELD_3=if (cstack.fetchref(0) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else cstack.push(env->GetByteField(cstack.popref(), $fieldid)); $trycatchhandler 274 | GETFIELD_3_S_VARS=#NPE,#ERROR_DESC 275 | GETFIELD_3_S_CONST_NPE=java/lang/NullPointerException 276 | GETFIELD_3_S_CONST_ERROR_DESC=GETFIELD Byte npe 277 | GETFIELD_4=if (cstack.fetchref(0) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else cstack.push(env->GetShortField(cstack.popref(), $fieldid)); $trycatchhandler 278 | GETFIELD_4_S_VARS=#NPE,#ERROR_DESC 279 | GETFIELD_4_S_CONST_NPE=java/lang/NullPointerException 280 | GETFIELD_4_S_CONST_ERROR_DESC=GETFIELD Short npe 281 | GETFIELD_5=if (cstack.fetchref(0) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else cstack.push(env->GetIntField(cstack.popref(), $fieldid)); $trycatchhandler 282 | GETFIELD_5_S_VARS=#NPE,#ERROR_DESC 283 | GETFIELD_5_S_CONST_NPE=java/lang/NullPointerException 284 | GETFIELD_5_S_CONST_ERROR_DESC=GETFIELD Int npe 285 | GETFIELD_6=if (cstack.fetchref(0) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else cstack.push(utils::cfi(env->GetFloatField(cstack.popref(), $fieldid))); $trycatchhandler 286 | GETFIELD_6_S_VARS=#NPE,#ERROR_DESC 287 | GETFIELD_6_S_CONST_NPE=java/lang/NullPointerException 288 | GETFIELD_6_S_CONST_ERROR_DESC=GETFIELD Float npe 289 | GETFIELD_7=if (cstack.fetchref(0) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else cstack.push2(env->GetLongField(cstack.popref(), $fieldid)); $trycatchhandler 290 | GETFIELD_7_S_VARS=#NPE,#ERROR_DESC 291 | GETFIELD_7_S_CONST_NPE=java/lang/NullPointerException 292 | GETFIELD_7_S_CONST_ERROR_DESC=GETFIELD Long npe 293 | GETFIELD_8=if (cstack.fetchref(0) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else cstack.push2(utils::cdl(env->GetDoubleField(cstack.popref(), $fieldid))); $trycatchhandler 294 | GETFIELD_8_S_VARS=#NPE,#ERROR_DESC 295 | GETFIELD_8_S_CONST_NPE=java/lang/NullPointerException 296 | GETFIELD_8_S_CONST_ERROR_DESC=GETFIELD Double npe 297 | GETFIELD_9=if (cstack.fetchref(0) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else { cstack.pushref(env->GetObjectField(cstack.popref(), $fieldid)); refs.insert(cstack.fetchref(0)); } $trycatchhandler 298 | GETFIELD_9_S_VARS=#NPE,#ERROR_DESC 299 | GETFIELD_9_S_CONST_NPE=java/lang/NullPointerException 300 | GETFIELD_9_S_CONST_ERROR_DESC=GETFIELD Object npe 301 | GETFIELD_10=if (cstack.fetchref(0) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else { cstack.pushref(env->GetObjectField(cstack.popref(), $fieldid)); refs.insert(cstack.fetchref(0)); } $trycatchhandler 302 | GETFIELD_10_S_VARS=#NPE,#ERROR_DESC 303 | GETFIELD_10_S_CONST_NPE=java/lang/NullPointerException 304 | GETFIELD_10_S_CONST_ERROR_DESC=GETFIELD Object npe 305 | GETFIELD_11=if (cstack.fetchref(0) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else { cstack.pushref(env->GetObjectField(cstack.popref(), $fieldid)); refs.insert(cstack.fetchref(0)); } $trycatchhandler 306 | GETFIELD_11_S_VARS=#NPE,#ERROR_DESC 307 | GETFIELD_11_S_CONST_NPE=java/lang/NullPointerException 308 | GETFIELD_11_S_CONST_ERROR_DESC=GETFIELD Object npe 309 | 310 | PUTSTATIC_1=env->SetStaticBooleanField($class_ptr, $fieldid, (jboolean) cstack.pop()); $trycatchhandler 311 | PUTSTATIC_2=env->SetStaticCharField($class_ptr, $fieldid, (jchar) cstack.pop()); $trycatchhandler 312 | PUTSTATIC_3=env->SetStaticByteField($class_ptr, $fieldid, (jbyte) cstack.pop()); $trycatchhandler 313 | PUTSTATIC_4=env->SetStaticShortField($class_ptr, $fieldid, (jshort) cstack.pop()); $trycatchhandler 314 | PUTSTATIC_5=env->SetStaticIntField($class_ptr, $fieldid, (jint) cstack.pop()); $trycatchhandler 315 | PUTSTATIC_6=env->SetStaticFloatField($class_ptr, $fieldid, (jfloat) utils::cif(cstack.pop())); $trycatchhandler 316 | PUTSTATIC_7=env->SetStaticLongField($class_ptr, $fieldid, (jlong) cstack.pop2()); $trycatchhandler 317 | PUTSTATIC_8=env->SetStaticDoubleField($class_ptr, $fieldid, (jdouble) utils::cld(cstack.pop2())); $trycatchhandler 318 | PUTSTATIC_9=env->SetStaticObjectField($class_ptr, $fieldid, (jobject) cstack.popref()); $trycatchhandler 319 | PUTSTATIC_10=env->SetStaticObjectField($class_ptr, $fieldid, (jobject) cstack.popref()); $trycatchhandler 320 | PUTSTATIC_11=env->SetStaticObjectField($class_ptr, $fieldid, (jobject) cstack.popref()); $trycatchhandler 321 | 322 | PUTFIELD_1=if (cstack.fetchref(1) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else env->SetBooleanField(cstack.fetchref(1), $fieldid, (jboolean) cstack.fetch(0)); cstack.popcnt(2); $trycatchhandler 323 | PUTFIELD_1_S_VARS=#NPE,#ERROR_DESC 324 | PUTFIELD_1_S_CONST_NPE=java/lang/NullPointerException 325 | PUTFIELD_1_S_CONST_ERROR_DESC=PUTFIELD Boolean npe 326 | PUTFIELD_2=if (cstack.fetchref(1) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else env->SetCharField(cstack.fetchref(1), $fieldid, (jchar) cstack.fetch(0)); cstack.popcnt(2); $trycatchhandler 327 | PUTFIELD_2_S_VARS=#NPE,#ERROR_DESC 328 | PUTFIELD_2_S_CONST_NPE=java/lang/NullPointerException 329 | PUTFIELD_2_S_CONST_ERROR_DESC=PUTFIELD Char npe 330 | PUTFIELD_3=if (cstack.fetchref(1) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else env->SetByteField(cstack.fetchref(1), $fieldid, (jbyte) cstack.fetch(0)); cstack.popcnt(2); $trycatchhandler 331 | PUTFIELD_3_S_VARS=#NPE,#ERROR_DESC 332 | PUTFIELD_3_S_CONST_NPE=java/lang/NullPointerException 333 | PUTFIELD_3_S_CONST_ERROR_DESC=PUTFIELD Byte npe 334 | PUTFIELD_4=if (cstack.fetchref(1) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else env->SetShortField(cstack.fetchref(1), $fieldid, (jshort) cstack.fetch(0)); cstack.popcnt(2); $trycatchhandler 335 | PUTFIELD_4_S_VARS=#NPE,#ERROR_DESC 336 | PUTFIELD_4_S_CONST_NPE=java/lang/NullPointerException 337 | PUTFIELD_4_S_CONST_ERROR_DESC=PUTFIELD Short npe 338 | PUTFIELD_5=if (cstack.fetchref(1) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else env->SetIntField(cstack.fetchref(1), $fieldid, (jint) cstack.fetch(0)); cstack.popcnt(2); $trycatchhandler 339 | PUTFIELD_5_S_VARS=#NPE,#ERROR_DESC 340 | PUTFIELD_5_S_CONST_NPE=java/lang/NullPointerException 341 | PUTFIELD_5_S_CONST_ERROR_DESC=PUTFIELD Int npe 342 | PUTFIELD_6=if (cstack.fetchref(1) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else env->SetFloatField(cstack.fetchref(1), $fieldid, (jfloat) utils::cif(cstack.fetch(0))); cstack.popcnt(2); $trycatchhandler 343 | PUTFIELD_6_S_VARS=#NPE,#ERROR_DESC 344 | PUTFIELD_6_S_CONST_NPE=java/lang/NullPointerException 345 | PUTFIELD_6_S_CONST_ERROR_DESC=PUTFIELD Float npe 346 | PUTFIELD_7=if (cstack.fetchref(2) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else env->SetLongField(cstack.fetchref(2), $fieldid, (jlong) cstack.fetch2(0)); cstack.popcnt(3); $trycatchhandler 347 | PUTFIELD_7_S_VARS=#NPE,#ERROR_DESC 348 | PUTFIELD_7_S_CONST_NPE=java/lang/NullPointerException 349 | PUTFIELD_7_S_CONST_ERROR_DESC=PUTFIELD Long npe 350 | PUTFIELD_8=if (cstack.fetchref(2) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else env->SetDoubleField(cstack.fetchref(2), $fieldid, (jdouble) utils::cld(cstack.fetch2(0))); cstack.popcnt(3); $trycatchhandler 351 | PUTFIELD_8_S_VARS=#NPE,#ERROR_DESC 352 | PUTFIELD_8_S_CONST_NPE=java/lang/NullPointerException 353 | PUTFIELD_8_S_CONST_ERROR_DESC=PUTFIELD Double npe 354 | PUTFIELD_9=if (cstack.fetchref(1) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else env->SetObjectField(cstack.fetchref(1), $fieldid, (jobject) cstack.fetchref(0)); cstack.popcnt(2); $trycatchhandler 355 | PUTFIELD_9_S_VARS=#NPE,#ERROR_DESC 356 | PUTFIELD_9_S_CONST_NPE=java/lang/NullPointerException 357 | PUTFIELD_9_S_CONST_ERROR_DESC=PUTFIELD Object npe 358 | PUTFIELD_10=if (cstack.fetchref(1) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else env->SetObjectField(cstack.fetchref(1), $fieldid, (jobject) cstack.fetchref(0)); cstack.popcnt(2); $trycatchhandler 359 | PUTFIELD_10_S_VARS=#NPE,#ERROR_DESC 360 | PUTFIELD_10_S_CONST_NPE=java/lang/NullPointerException 361 | PUTFIELD_10_S_CONST_ERROR_DESC=PUTFIELD Object npe 362 | PUTFIELD_11=if (cstack.fetchref(1) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else env->SetObjectField(cstack.fetchref(1), $fieldid, (jobject) cstack.fetchref(0)); cstack.popcnt(2); $trycatchhandler 363 | PUTFIELD_11_S_VARS=#NPE,#ERROR_DESC 364 | PUTFIELD_11_S_CONST_NPE=java/lang/NullPointerException 365 | PUTFIELD_11_S_CONST_ERROR_DESC=PUTFIELD Object npe 366 | 367 | NEWARRAY_4=if (cstack.fetch(0) < 0) utils::throw_re(env, #NASE, #ERROR_DESC, $line); else { cstack.pushref(env->NewBooleanArray(cstack.pop())); refs.insert(cstack.fetchref(0)); } $trycatchhandler 368 | NEWARRAY_4_S_VARS=#NASE,#ERROR_DESC 369 | NEWARRAY_4_S_CONST_NASE=java/lang/NegativeArraySizeException 370 | NEWARRAY_4_S_CONST_ERROR_DESC=NEWARRAY Boolean array size < 0 371 | NEWARRAY_5=if (cstack.fetch(0) < 0) utils::throw_re(env, #NASE, #ERROR_DESC, $line); else { cstack.pushref(env->NewCharArray(cstack.pop())); refs.insert(cstack.fetchref(0)); } $trycatchhandler 372 | NEWARRAY_5_S_VARS=#NASE,#ERROR_DESC 373 | NEWARRAY_5_S_CONST_NASE=java/lang/NegativeArraySizeException 374 | NEWARRAY_5_S_CONST_ERROR_DESC=NEWARRAY Char array size < 0 375 | NEWARRAY_6=if (cstack.fetch(0) < 0) utils::throw_re(env, #NASE, #ERROR_DESC, $line); else { cstack.pushref(env->NewFloatArray(cstack.pop())); refs.insert(cstack.fetchref(0)); } $trycatchhandler 376 | NEWARRAY_6_S_VARS=#NASE,#ERROR_DESC 377 | NEWARRAY_6_S_CONST_NASE=java/lang/NegativeArraySizeException 378 | NEWARRAY_6_S_CONST_ERROR_DESC=NEWARRAY Float array size < 0 379 | NEWARRAY_7=if (cstack.fetch(0) < 0) utils::throw_re(env, #NASE, #ERROR_DESC, $line); else { cstack.pushref(env->NewDoubleArray(cstack.pop())); refs.insert(cstack.fetchref(0)); } $trycatchhandler 380 | NEWARRAY_7_S_VARS=#NASE,#ERROR_DESC 381 | NEWARRAY_7_S_CONST_NASE=java/lang/NegativeArraySizeException 382 | NEWARRAY_7_S_CONST_ERROR_DESC=NEWARRAY Double array size < 0 383 | NEWARRAY_8=if (cstack.fetch(0) < 0) utils::throw_re(env, #NASE, #ERROR_DESC, $line); else { cstack.pushref(env->NewByteArray(cstack.pop())); refs.insert(cstack.fetchref(0)); } $trycatchhandler 384 | NEWARRAY_8_S_VARS=#NASE,#ERROR_DESC 385 | NEWARRAY_8_S_CONST_NASE=java/lang/NegativeArraySizeException 386 | NEWARRAY_8_S_CONST_ERROR_DESC=NEWARRAY Byte array size < 0 387 | NEWARRAY_9=if (cstack.fetch(0) < 0) utils::throw_re(env, #NASE, #ERROR_DESC, $line); else { cstack.pushref(env->NewShortArray(cstack.pop())); refs.insert(cstack.fetchref(0)); } $trycatchhandler 388 | NEWARRAY_9_S_VARS=#NASE,#ERROR_DESC 389 | NEWARRAY_9_S_CONST_NASE=java/lang/NegativeArraySizeException 390 | NEWARRAY_9_S_CONST_ERROR_DESC=NEWARRAY Short array size < 0 391 | NEWARRAY_10=if (cstack.fetch(0) < 0) utils::throw_re(env, #NASE, #ERROR_DESC, $line); else { cstack.pushref(env->NewIntArray(cstack.pop())); refs.insert(cstack.fetchref(0)); } $trycatchhandler 392 | NEWARRAY_10_S_VARS=#NASE,#ERROR_DESC 393 | NEWARRAY_10_S_CONST_NASE=java/lang/NegativeArraySizeException 394 | NEWARRAY_10_S_CONST_ERROR_DESC=NEWARRAY Int array size < 0 395 | NEWARRAY_11=if (cstack.fetch(0) < 0) utils::throw_re(env, #NASE, #ERROR_DESC, $line); else { cstack.pushref(env->NewLongArray(cstack.pop())); refs.insert(cstack.fetchref(0)); } $trycatchhandler 396 | NEWARRAY_11_S_VARS=#NASE,#ERROR_DESC 397 | NEWARRAY_11_S_CONST_NASE=java/lang/NegativeArraySizeException 398 | NEWARRAY_11_S_CONST_ERROR_DESC=NEWARRAY Long array size < 0 399 | 400 | INVOKE_POPCNT=cstack.popcnt($count); 401 | 402 | INVOKE_ARG_1=(jboolean) cstack.fetch($index) 403 | INVOKE_ARG_2=(jchar) cstack.fetch($index) 404 | INVOKE_ARG_3=(jbyte) cstack.fetch($index) 405 | INVOKE_ARG_4=(jshort) cstack.fetch($index) 406 | INVOKE_ARG_5=(jint) cstack.fetch($index) 407 | INVOKE_ARG_6=(jfloat) utils::cif(cstack.fetch($index)) 408 | INVOKE_ARG_7=(jlong) cstack.fetch2raw($index) 409 | INVOKE_ARG_8=(jdouble) utils::cld(cstack.fetch2raw($index)) 410 | INVOKE_ARG_9=(jarray) cstack.fetchref($index) 411 | INVOKE_ARG_10=(jobject) cstack.fetchref($index) 412 | INVOKE_ARG_11=(jobject) cstack.fetchref($index) 413 | 414 | INVOKESPECIAL_0=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else env->CallNonvirtualVoidMethod(cstack.fetchref($object_offset), $class_ptr, $methodid$args); $trycatchhandler 415 | INVOKESPECIAL_0_S_VARS=#NPE,#ERROR_DESC 416 | INVOKESPECIAL_0_S_CONST_NPE=java/lang/NullPointerException 417 | INVOKESPECIAL_0_S_CONST_ERROR_DESC=INVOKESPECIAL Void npe 418 | INVOKESPECIAL_1=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else cstack.push(env->CallNonvirtualBooleanMethod(cstack.fetchref($object_offset), $class_ptr, $methodid$args)); $trycatchhandler 419 | INVOKESPECIAL_1_S_VARS=#NPE,#ERROR_DESC 420 | INVOKESPECIAL_1_S_CONST_NPE=java/lang/NullPointerException 421 | INVOKESPECIAL_1_S_CONST_ERROR_DESC=INVOKESPECIAL Boolean npe 422 | INVOKESPECIAL_2=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else cstack.push(env->CallNonvirtualCharMethod(cstack.fetchref($object_offset), $class_ptr, $methodid$args)); $trycatchhandler 423 | INVOKESPECIAL_2_S_VARS=#NPE,#ERROR_DESC 424 | INVOKESPECIAL_2_S_CONST_NPE=java/lang/NullPointerException 425 | INVOKESPECIAL_2_S_CONST_ERROR_DESC=INVOKESPECIAL Char npe 426 | INVOKESPECIAL_3=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else cstack.push(env->CallNonvirtualByteMethod(cstack.fetchref($object_offset), $class_ptr, $methodid$args)); $trycatchhandler 427 | INVOKESPECIAL_3_S_VARS=#NPE,#ERROR_DESC 428 | INVOKESPECIAL_3_S_CONST_NPE=java/lang/NullPointerException 429 | INVOKESPECIAL_3_S_CONST_ERROR_DESC=INVOKESPECIAL Bye npe 430 | INVOKESPECIAL_4=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else cstack.push(env->CallNonvirtualShortMethod(cstack.fetchref($object_offset), $class_ptr, $methodid$args)); $trycatchhandler 431 | INVOKESPECIAL_4_S_VARS=#NPE,#ERROR_DESC 432 | INVOKESPECIAL_4_S_CONST_NPE=java/lang/NullPointerException 433 | INVOKESPECIAL_4_S_CONST_ERROR_DESC=INVOKESPECIAL Short npe 434 | INVOKESPECIAL_5=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else cstack.push(env->CallNonvirtualIntMethod(cstack.fetchref($object_offset), $class_ptr, $methodid$args)); $trycatchhandler 435 | INVOKESPECIAL_5_S_VARS=#NPE,#ERROR_DESC 436 | INVOKESPECIAL_5_S_CONST_NPE=java/lang/NullPointerException 437 | INVOKESPECIAL_5_S_CONST_ERROR_DESC=INVOKESPECIAL Int npe 438 | INVOKESPECIAL_6=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else cstack.push(utils::cfi(env->CallNonvirtualFloatMethod(cstack.fetchref($object_offset), $class_ptr, $methodid$args))); $trycatchhandler 439 | INVOKESPECIAL_6_S_VARS=#NPE,#ERROR_DESC 440 | INVOKESPECIAL_6_S_CONST_NPE=java/lang/NullPointerException 441 | INVOKESPECIAL_6_S_CONST_ERROR_DESC=INVOKESPECIAL Float npe 442 | INVOKESPECIAL_7=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else cstack.push2(env->CallNonvirtualLongMethod(cstack.fetchref($object_offset), $class_ptr, $methodid$args)); $trycatchhandler 443 | INVOKESPECIAL_7_S_VARS=#NPE,#ERROR_DESC 444 | INVOKESPECIAL_7_S_CONST_NPE=java/lang/NullPointerException 445 | INVOKESPECIAL_7_S_CONST_ERROR_DESC=INVOKESPECIAL Long npe 446 | INVOKESPECIAL_8=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else cstack.push2(utils::cdl(env->CallNonvirtualDoubleMethod(cstack.fetchref($object_offset), $class_ptr, $methodid$args))); $trycatchhandler 447 | INVOKESPECIAL_8_S_VARS=#NPE,#ERROR_DESC 448 | INVOKESPECIAL_8_S_CONST_NPE=java/lang/NullPointerException 449 | INVOKESPECIAL_8_S_CONST_ERROR_DESC=INVOKESPECIAL Double npe 450 | INVOKESPECIAL_9=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else { cstack.pushref(env->CallNonvirtualObjectMethod(cstack.fetchref($object_offset), $class_ptr, $methodid$args)); refs.insert(cstack.fetchref(0)); } $trycatchhandler 451 | INVOKESPECIAL_9_S_VARS=#NPE,#ERROR_DESC 452 | INVOKESPECIAL_9_S_CONST_NPE=java/lang/NullPointerException 453 | INVOKESPECIAL_9_S_CONST_ERROR_DESC=INVOKESPECIAL Object npe 454 | INVOKESPECIAL_10=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else { cstack.pushref(env->CallNonvirtualObjectMethod(cstack.fetchref($object_offset), $class_ptr, $methodid$args)); refs.insert(cstack.fetchref(0)); } $trycatchhandler 455 | INVOKESPECIAL_10_S_VARS=#NPE,#ERROR_DESC 456 | INVOKESPECIAL_10_S_CONST_NPE=java/lang/NullPointerException 457 | INVOKESPECIAL_10_S_CONST_ERROR_DESC=INVOKESPECIAL Object npe 458 | INVOKESPECIAL_11=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else { cstack.pushref(env->CallNonvirtualObjectMethod(cstack.fetchref($object_offset), $class_ptr, $methodid$args)); refs.insert(cstack.fetchref(0)); } $trycatchhandler 459 | INVOKESPECIAL_11_S_VARS=#NPE,#ERROR_DESC 460 | INVOKESPECIAL_11_S_CONST_NPE=java/lang/NullPointerException 461 | INVOKESPECIAL_11_S_CONST_ERROR_DESC=INVOKESPECIAL Object npe 462 | 463 | INVOKEINTERFACE_0=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else env->CallVoidMethod(cstack.fetchref($object_offset), $methodid$args); $trycatchhandler 464 | INVOKEINTERFACE_0_S_VARS=#NPE,#ERROR_DESC 465 | INVOKEINTERFACE_0_S_CONST_NPE=java/lang/NullPointerException 466 | INVOKEINTERFACE_0_S_CONST_ERROR_DESC=INVOKEINTERFACE Void npe 467 | INVOKEINTERFACE_1=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else cstack.push(env->CallBooleanMethod(cstack.fetchref($object_offset), $methodid$args)); $trycatchhandler 468 | INVOKEINTERFACE_1_S_VARS=#NPE,#ERROR_DESC 469 | INVOKEINTERFACE_1_S_CONST_NPE=java/lang/NullPointerException 470 | INVOKEINTERFACE_1_S_CONST_ERROR_DESC=INVOKEINTERFACE Boolean npe 471 | INVOKEINTERFACE_2=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else cstack.push(env->CallCharMethod(cstack.fetchref($object_offset), $methodid$args)); $trycatchhandler 472 | INVOKEINTERFACE_2_S_VARS=#NPE,#ERROR_DESC 473 | INVOKEINTERFACE_2_S_CONST_NPE=java/lang/NullPointerException 474 | INVOKEINTERFACE_2_S_CONST_ERROR_DESC=INVOKEINTERFACE Char npe 475 | INVOKEINTERFACE_3=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else cstack.push(env->CallByteMethod(cstack.fetchref($object_offset), $methodid$args)); $trycatchhandler 476 | INVOKEINTERFACE_3_S_VARS=#NPE,#ERROR_DESC 477 | INVOKEINTERFACE_3_S_CONST_NPE=java/lang/NullPointerException 478 | INVOKEINTERFACE_3_S_CONST_ERROR_DESC=INVOKEINTERFACE Bye npe 479 | INVOKEINTERFACE_4=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else cstack.push(env->CallShortMethod(cstack.fetchref($object_offset), $methodid$args)); $trycatchhandler 480 | INVOKEINTERFACE_4_S_VARS=#NPE,#ERROR_DESC 481 | INVOKEINTERFACE_4_S_CONST_NPE=java/lang/NullPointerException 482 | INVOKEINTERFACE_4_S_CONST_ERROR_DESC=INVOKEINTERFACE Short npe 483 | INVOKEINTERFACE_5=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else cstack.push(env->CallIntMethod(cstack.fetchref($object_offset), $methodid$args)); $trycatchhandler 484 | INVOKEINTERFACE_5_S_VARS=#NPE,#ERROR_DESC 485 | INVOKEINTERFACE_5_S_CONST_NPE=java/lang/NullPointerException 486 | INVOKEINTERFACE_5_S_CONST_ERROR_DESC=INVOKEINTERFACE Int npe 487 | INVOKEINTERFACE_6=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else cstack.push(utils::cfi(env->CallFloatMethod(cstack.fetchref($object_offset), $methodid$args))); $trycatchhandler 488 | INVOKEINTERFACE_6_S_VARS=#NPE,#ERROR_DESC 489 | INVOKEINTERFACE_6_S_CONST_NPE=java/lang/NullPointerException 490 | INVOKEINTERFACE_6_S_CONST_ERROR_DESC=INVOKEINTERFACE Float npe 491 | INVOKEINTERFACE_7=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else cstack.push2(env->CallLongMethod(cstack.fetchref($object_offset), $methodid$args)); $trycatchhandler 492 | INVOKEINTERFACE_7_S_VARS=#NPE,#ERROR_DESC 493 | INVOKEINTERFACE_7_S_CONST_NPE=java/lang/NullPointerException 494 | INVOKEINTERFACE_7_S_CONST_ERROR_DESC=INVOKEINTERFACE Long npe 495 | INVOKEINTERFACE_8=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else cstack.push2(utils::cdl(env->CallDoubleMethod(cstack.fetchref($object_offset), $methodid$args))); $trycatchhandler 496 | INVOKEINTERFACE_8_S_VARS=#NPE,#ERROR_DESC 497 | INVOKEINTERFACE_8_S_CONST_NPE=java/lang/NullPointerException 498 | INVOKEINTERFACE_8_S_CONST_ERROR_DESC=INVOKEINTERFACE Double npe 499 | INVOKEINTERFACE_9=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else { cstack.pushref(env->CallObjectMethod(cstack.fetchref($object_offset), $methodid$args)); refs.insert(cstack.fetchref(0)); } $trycatchhandler 500 | INVOKEINTERFACE_9_S_VARS=#NPE,#ERROR_DESC 501 | INVOKEINTERFACE_9_S_CONST_NPE=java/lang/NullPointerException 502 | INVOKEINTERFACE_9_S_CONST_ERROR_DESC=INVOKEINTERFACE Object npe 503 | INVOKEINTERFACE_10=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else { cstack.pushref(env->CallObjectMethod(cstack.fetchref($object_offset), $methodid$args)); refs.insert(cstack.fetchref(0)); } $trycatchhandler 504 | INVOKEINTERFACE_10_S_VARS=#NPE,#ERROR_DESC 505 | INVOKEINTERFACE_10_S_CONST_NPE=java/lang/NullPointerException 506 | INVOKEINTERFACE_10_S_CONST_ERROR_DESC=INVOKEINTERFACE Object npe 507 | INVOKEINTERFACE_11=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else { cstack.pushref(env->CallObjectMethod(cstack.fetchref($object_offset), $methodid$args)); refs.insert(cstack.fetchref(0)); } $trycatchhandler 508 | INVOKEINTERFACE_11_S_VARS=#NPE,#ERROR_DESC 509 | INVOKEINTERFACE_11_S_CONST_NPE=java/lang/NullPointerException 510 | INVOKEINTERFACE_11_S_CONST_ERROR_DESC=INVOKEINTERFACE Object npe 511 | 512 | INVOKEVIRTUAL_0=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else env->CallVoidMethod(cstack.fetchref($object_offset), $methodid$args); $trycatchhandler 513 | INVOKEVIRTUAL_0_S_VARS=#NPE,#ERROR_DESC 514 | INVOKEVIRTUAL_0_S_CONST_NPE=java/lang/NullPointerException 515 | INVOKEVIRTUAL_0_S_CONST_ERROR_DESC=INVOKEVIRTUAL Void npe 516 | INVOKEVIRTUAL_1=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else cstack.push(env->CallBooleanMethod(cstack.fetchref($object_offset), $methodid$args)); $trycatchhandler 517 | INVOKEVIRTUAL_1_S_VARS=#NPE,#ERROR_DESC 518 | INVOKEVIRTUAL_1_S_CONST_NPE=java/lang/NullPointerException 519 | INVOKEVIRTUAL_1_S_CONST_ERROR_DESC=INVOKEVIRTUAL Boolean npe 520 | INVOKEVIRTUAL_2=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else cstack.push(env->CallCharMethod(cstack.fetchref($object_offset), $methodid$args)); $trycatchhandler 521 | INVOKEVIRTUAL_2_S_VARS=#NPE,#ERROR_DESC 522 | INVOKEVIRTUAL_2_S_CONST_NPE=java/lang/NullPointerException 523 | INVOKEVIRTUAL_2_S_CONST_ERROR_DESC=INVOKEVIRTUAL Char npe 524 | INVOKEVIRTUAL_3=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else cstack.push(env->CallByteMethod(cstack.fetchref($object_offset), $methodid$args)); $trycatchhandler 525 | INVOKEVIRTUAL_3_S_VARS=#NPE,#ERROR_DESC 526 | INVOKEVIRTUAL_3_S_CONST_NPE=java/lang/NullPointerException 527 | INVOKEVIRTUAL_3_S_CONST_ERROR_DESC=INVOKEVIRTUAL Bye npe 528 | INVOKEVIRTUAL_4=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else cstack.push(env->CallShortMethod(cstack.fetchref($object_offset), $methodid$args)); $trycatchhandler 529 | INVOKEVIRTUAL_4_S_VARS=#NPE,#ERROR_DESC 530 | INVOKEVIRTUAL_4_S_CONST_NPE=java/lang/NullPointerException 531 | INVOKEVIRTUAL_4_S_CONST_ERROR_DESC=INVOKEVIRTUAL Short npe 532 | INVOKEVIRTUAL_5=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else cstack.push(env->CallIntMethod(cstack.fetchref($object_offset), $methodid$args)); $trycatchhandler 533 | INVOKEVIRTUAL_5_S_VARS=#NPE,#ERROR_DESC 534 | INVOKEVIRTUAL_5_S_CONST_NPE=java/lang/NullPointerException 535 | INVOKEVIRTUAL_5_S_CONST_ERROR_DESC=INVOKEVIRTUAL Int npe 536 | INVOKEVIRTUAL_6=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else cstack.push(utils::cfi(env->CallFloatMethod(cstack.fetchref($object_offset), $methodid$args))); $trycatchhandler 537 | INVOKEVIRTUAL_6_S_VARS=#NPE,#ERROR_DESC 538 | INVOKEVIRTUAL_6_S_CONST_NPE=java/lang/NullPointerException 539 | INVOKEVIRTUAL_6_S_CONST_ERROR_DESC=INVOKEVIRTUAL Float npe 540 | INVOKEVIRTUAL_7=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else cstack.push2(env->CallLongMethod(cstack.fetchref($object_offset), $methodid$args)); $trycatchhandler 541 | INVOKEVIRTUAL_7_S_VARS=#NPE,#ERROR_DESC 542 | INVOKEVIRTUAL_7_S_CONST_NPE=java/lang/NullPointerException 543 | INVOKEVIRTUAL_7_S_CONST_ERROR_DESC=INVOKEVIRTUAL Long npe 544 | INVOKEVIRTUAL_8=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else cstack.push2(utils::cdl(env->CallDoubleMethod(cstack.fetchref($object_offset), $methodid$args))); $trycatchhandler 545 | INVOKEVIRTUAL_8_S_VARS=#NPE,#ERROR_DESC 546 | INVOKEVIRTUAL_8_S_CONST_NPE=java/lang/NullPointerException 547 | INVOKEVIRTUAL_8_S_CONST_ERROR_DESC=INVOKEVIRTUAL Double npe 548 | INVOKEVIRTUAL_9=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else { cstack.pushref(env->CallObjectMethod(cstack.fetchref($object_offset), $methodid$args)); refs.insert(cstack.fetchref(0)); } $trycatchhandler 549 | INVOKEVIRTUAL_9_S_VARS=#NPE,#ERROR_DESC 550 | INVOKEVIRTUAL_9_S_CONST_NPE=java/lang/NullPointerException 551 | INVOKEVIRTUAL_9_S_CONST_ERROR_DESC=INVOKEVIRTUAL Object npe 552 | INVOKEVIRTUAL_10=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else { cstack.pushref(env->CallObjectMethod(cstack.fetchref($object_offset), $methodid$args)); refs.insert(cstack.fetchref(0)); } $trycatchhandler 553 | INVOKEVIRTUAL_10_S_VARS=#NPE,#ERROR_DESC 554 | INVOKEVIRTUAL_10_S_CONST_NPE=java/lang/NullPointerException 555 | INVOKEVIRTUAL_10_S_CONST_ERROR_DESC=INVOKEVIRTUAL Object npe 556 | INVOKEVIRTUAL_11=if (cstack.fetchref($object_offset) == nullptr) utils::throw_re(env, #NPE, #ERROR_DESC, $line); else { cstack.pushref(env->CallObjectMethod(cstack.fetchref($object_offset), $methodid$args)); refs.insert(cstack.fetchref(0)); } $trycatchhandler 557 | INVOKEVIRTUAL_11_S_VARS=#NPE,#ERROR_DESC 558 | INVOKEVIRTUAL_11_S_CONST_NPE=java/lang/NullPointerException 559 | INVOKEVIRTUAL_11_S_CONST_ERROR_DESC=INVOKEVIRTUAL Object npe 560 | 561 | INVOKESTATIC_0=env->CallStaticVoidMethod($class_ptr, $methodid$args); $trycatchhandler 562 | INVOKESTATIC_1=cstack.push(env->CallStaticBooleanMethod($class_ptr, $methodid$args)); $trycatchhandler 563 | INVOKESTATIC_2=cstack.push(env->CallStaticCharMethod($class_ptr, $methodid$args)); $trycatchhandler 564 | INVOKESTATIC_3=cstack.push(env->CallStaticByteMethod($class_ptr, $methodid$args)); $trycatchhandler 565 | INVOKESTATIC_4=cstack.push(env->CallStaticShortMethod($class_ptr, $methodid$args)); $trycatchhandler 566 | INVOKESTATIC_5=cstack.push(env->CallStaticIntMethod($class_ptr, $methodid$args)); $trycatchhandler 567 | INVOKESTATIC_6=cstack.push(utils::cfi(env->CallStaticFloatMethod($class_ptr, $methodid$args))); $trycatchhandler 568 | INVOKESTATIC_7=cstack.push2(env->CallStaticLongMethod($class_ptr, $methodid$args)); $trycatchhandler 569 | INVOKESTATIC_8=cstack.push2(utils::cdl(env->CallStaticDoubleMethod($class_ptr, $methodid$args))); $trycatchhandler 570 | INVOKESTATIC_9=cstack.pushref(env->CallStaticObjectMethod($class_ptr, $methodid$args)); refs.insert(cstack.fetchref(0)); $trycatchhandler 571 | INVOKESTATIC_10=cstack.pushref(env->CallStaticObjectMethod($class_ptr, $methodid$args)); refs.insert(cstack.fetchref(0)); $trycatchhandler 572 | INVOKESTATIC_11=cstack.pushref(env->CallStaticObjectMethod($class_ptr, $methodid$args)); refs.insert(cstack.fetchref(0)); $trycatchhandler 573 | 574 | MULTIANEWARRAY=cstack.popcnt($count); cstack.pushref(utils::create_multidim_array(env, $count, cstack.data + cstack.sptr, $desc, $line)); refs.insert(cstack.fetchref(0)); $trycatchhandler 575 | MULTIANEWARRAY_S_VARS=$desc 576 | CHECKCAST=if (cstack.fetchref(0) != nullptr && !env->IsAssignableFrom(env->GetObjectClass(cstack.fetchref(0)), $desc_ptr)) { utils::throw_re(env, #CCE, (std::string(#ERROR_DESC) + std::string($desc)).c_str(), $line); cstack.clear(); cstack.pushref(env->ExceptionOccurred()); refs.insert(cstack.fetchref(0)); } $trycatchhandler 577 | CHECKCAST_S_VARS=#CCE,#ERROR_DESC,$desc 578 | CHECKCAST_S_CONST_CCE=java/lang/ClassCastException 579 | CHECKCAST_S_CONST_ERROR_DESC=cannot cast to 580 | -------------------------------------------------------------------------------- /src/sources/native_jvm.cpp: -------------------------------------------------------------------------------- 1 | #include "native_jvm.hpp" 2 | #include 3 | 4 | namespace native_jvm::utils { 5 | 6 | union __fi_conv { 7 | jfloat m_jfloat; 8 | jint m_jint; 9 | }; 10 | 11 | jint cfi(jfloat f) { 12 | __fi_conv fi; 13 | fi.m_jfloat = f; 14 | return fi.m_jint; 15 | } 16 | 17 | jfloat cif(jint i) { 18 | __fi_conv fi; 19 | fi.m_jint = i; 20 | return fi.m_jfloat; 21 | } 22 | 23 | 24 | union __dl_conv { 25 | jdouble m_jdouble; 26 | jlong m_jlong; 27 | }; 28 | 29 | jlong cdl(jdouble d) { 30 | __dl_conv dl; 31 | dl.m_jdouble = d; 32 | return dl.m_jlong; 33 | } 34 | 35 | jdouble cld(jlong l) { 36 | __dl_conv dl; 37 | dl.m_jlong = l; 38 | return dl.m_jdouble; 39 | } 40 | 41 | jclass boolean_array_class; 42 | 43 | void init_utils(JNIEnv *env) { 44 | jclass clazz = env->FindClass("[Z"); 45 | if (env->ExceptionCheck()) 46 | return; 47 | boolean_array_class = (jclass) env->NewGlobalRef(clazz); 48 | env->DeleteLocalRef(clazz); 49 | } 50 | 51 | jobjectArray create_multidim_array(JNIEnv *env, jint count, jint *sizes, const char *class_name, int line) { 52 | if (count == 0) 53 | return nullptr; 54 | if (*sizes < 0) { 55 | throw_re(env, "java/lang/NegativeArraySizeException", "MULTIANEWARRAY size < 0", line); 56 | return nullptr; 57 | } 58 | jobjectArray result_array = nullptr; 59 | if (jclass clazz = env->FindClass((std::string(count, '[') + std::string(class_name)).c_str())) { 60 | result_array = env->NewObjectArray(*sizes, clazz, nullptr); 61 | env->DeleteLocalRef(clazz); 62 | } 63 | else 64 | return nullptr; 65 | for (jint i = 0; i < *sizes; i++) { 66 | jobjectArray inner_array = create_multidim_array(env, count - 1, sizes + 1, class_name, line); 67 | if (env->ExceptionCheck()) 68 | return nullptr; 69 | env->SetObjectArrayElement(result_array, i, inner_array); 70 | if (env->ExceptionCheck()) 71 | return nullptr; 72 | env->DeleteLocalRef(inner_array); 73 | } 74 | return result_array; 75 | } 76 | 77 | jclass find_class_wo_static(JNIEnv *env, const char *class_name) { 78 | jclass thread_class = env->FindClass("java/lang/Thread"); 79 | if (env->ExceptionCheck()) 80 | return nullptr; 81 | jmethodID current_thread_method = env->GetStaticMethodID(thread_class, "currentThread", "()Ljava/lang/Thread;"); 82 | if (env->ExceptionCheck()) 83 | return nullptr; 84 | jobject current_thread = env->CallStaticObjectMethod( 85 | thread_class, 86 | current_thread_method 87 | ); 88 | if (env->ExceptionCheck()) 89 | return nullptr; 90 | jmethodID get_context_classloader_method = env->GetMethodID(thread_class, "getContextClassLoader", "()Ljava/lang/ClassLoader;"); 91 | jobject classloader = env->CallObjectMethod( 92 | current_thread, 93 | get_context_classloader_method 94 | ); 95 | if (env->ExceptionCheck()) 96 | return nullptr; 97 | jclass classloader_class = env->FindClass("java/lang/ClassLoader"); 98 | if (env->ExceptionCheck()) 99 | return nullptr; 100 | jstring class_name_string = env->NewStringUTF(class_name); 101 | env->DeleteLocalRef(current_thread); 102 | if (env->ExceptionCheck()) 103 | return nullptr; 104 | jmethodID load_class_method = env->GetMethodID(classloader_class, "loadClass", "(Ljava/lang/String;)Ljava/lang/Class;"); 105 | if (env->ExceptionCheck()) 106 | return nullptr; 107 | jclass clazz = (jclass) env->CallObjectMethod( 108 | classloader, 109 | load_class_method, 110 | class_name_string 111 | ); 112 | if (env->ExceptionCheck()) 113 | return nullptr; 114 | env->DeleteLocalRef(classloader); 115 | env->DeleteLocalRef(classloader_class); 116 | env->DeleteLocalRef(class_name_string); 117 | return clazz; 118 | } 119 | 120 | void throw_re(JNIEnv *env, const char *exception_class, const char *error, int line) { 121 | jclass exception_class_ptr = env->FindClass(exception_class); 122 | if (!exception_class_ptr) 123 | return; 124 | env->ThrowNew(exception_class_ptr, ("\"" + std::string(error) + "\" on " + std::to_string(line)).c_str()); 125 | env->DeleteLocalRef(exception_class_ptr); 126 | } 127 | 128 | void bastore(JNIEnv *env, jarray array, jint index, jint value) { 129 | if (env->IsInstanceOf(array, boolean_array_class)) 130 | env->SetBooleanArrayRegion((jbooleanArray) array, index, 1, (jboolean*) (&value)); 131 | else 132 | env->SetByteArrayRegion((jbyteArray) array, index, 1, (jbyte*) (&value)); 133 | } 134 | 135 | jbyte baload(JNIEnv *env, jarray array, jint index) { 136 | jbyte ret_value; 137 | if (env->IsInstanceOf(array, boolean_array_class)) 138 | env->GetBooleanArrayRegion((jbooleanArray) array, index, 1, (jboolean*) (&ret_value)); 139 | else 140 | env->GetByteArrayRegion((jbyteArray) array, index, 1, (jbyte*) (&ret_value)); 141 | return ret_value; 142 | } 143 | 144 | 145 | jlong cast_dl(jdouble value) { 146 | if (std::isnan(value)) 147 | return 0; 148 | int exponent; 149 | std::frexp(value, &exponent); 150 | if (std::isfinite(value) && exponent <= 63) 151 | return (jlong) value; 152 | return std::signbit(value) ? std::numeric_limits::min() : std::numeric_limits::max(); 153 | } 154 | 155 | jlong cast_fl(jfloat value) { 156 | if (std::isnan(value)) 157 | return 0; 158 | int exponent; 159 | std::frexp(value, &exponent); 160 | if (std::isfinite(value) && exponent <= 63) 161 | return (jlong) value; 162 | return std::signbit(value) ? std::numeric_limits::min() : std::numeric_limits::max(); 163 | } 164 | 165 | jint cast_di(jdouble value) { 166 | if (std::isnan(value)) 167 | return 0; 168 | int exponent; 169 | std::frexp(value, &exponent); 170 | if (std::isfinite(value) && exponent <= 31) 171 | return (jlong) value; 172 | return std::signbit(value) ? std::numeric_limits::min() : std::numeric_limits::max(); 173 | } 174 | 175 | jint cast_fi(jfloat value) { 176 | if (std::isnan(value)) 177 | return 0; 178 | int exponent; 179 | std::frexp(value, &exponent); 180 | if (std::isfinite(value) && exponent <= 31) 181 | return (jlong) value; 182 | return std::signbit(value) ? std::numeric_limits::min() : std::numeric_limits::max(); 183 | } 184 | 185 | void clear_refs(JNIEnv *env, std::unordered_set &refs) { 186 | for (jobject ref : refs) 187 | if (env->GetObjectRefType(ref) == JNILocalRefType) 188 | env->DeleteLocalRef(ref); 189 | refs.clear(); 190 | } 191 | } -------------------------------------------------------------------------------- /src/sources/native_jvm.hpp: -------------------------------------------------------------------------------- 1 | #include "jni.h" 2 | #include "jvmti.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #ifndef NATIVE_JVM_HPP_GUARD 11 | 12 | #define NATIVE_JVM_HPP_GUARD 13 | 14 | namespace native_jvm::utils { 15 | 16 | template 17 | struct jvm_stack { 18 | jobject refs[2 * N]; 19 | jint data[2 * N]; 20 | jint sptr = 0; 21 | 22 | void push2(jlong value) { 23 | *(jlong *)(&data[sptr]) = value; 24 | sptr += 2; 25 | } 26 | 27 | jlong pop2() { 28 | sptr -= 2; 29 | return *(jlong *)(&data[sptr]); 30 | } 31 | 32 | void push(jint value) { 33 | data[sptr] = value; 34 | sptr++; 35 | } 36 | 37 | jint pop() { 38 | sptr--; 39 | return data[sptr]; 40 | } 41 | 42 | void pushref(jobject value) { 43 | refs[sptr] = value; 44 | sptr++; 45 | } 46 | 47 | jobject popref() { 48 | sptr--; 49 | return refs[sptr]; 50 | } 51 | 52 | void popcnt(int cnt) { 53 | sptr -= cnt; 54 | } 55 | 56 | jint fetch(int sd) { 57 | return data[sptr - sd - 1]; 58 | } 59 | 60 | jlong fetch2(int sd) { 61 | return *(jlong *)(&data[sptr - 2 * sd - 2]); 62 | } 63 | 64 | jlong fetch2raw(int sd) { 65 | return *(jlong *)(&data[sptr - sd - 1]); 66 | } 67 | 68 | jobject fetchref(int sd) { 69 | return refs[sptr - sd - 1]; 70 | } 71 | 72 | void set(int sd, jint value) { 73 | data[sptr - sd - 1] = value; 74 | } 75 | 76 | void set2(int sd, jlong value) { 77 | *(jlong *)(&data[sptr - 2 * sd - 2]) = value; 78 | } 79 | 80 | void set2raw(int sd, jlong value) { 81 | *(jlong *)(&data[sptr - sd - 1]) = value; 82 | } 83 | 84 | void setref(int sd, jobject value) { 85 | refs[sptr - sd - 1] = value; 86 | } 87 | 88 | jint *getptr(int sd) { 89 | return data + (sptr - sd - 1); 90 | } 91 | 92 | jlong *getptr2(int sd) { 93 | return (jlong *)(data + (sptr - 2 * sd - 2)); 94 | } 95 | 96 | void clear() { 97 | sptr = 0; 98 | } 99 | }; 100 | 101 | template 102 | struct local_vars { 103 | jobject refs[N]; 104 | jint data[N]; 105 | 106 | jlong get2(jint index) { 107 | return *(jlong *)(&data[index]); 108 | } 109 | 110 | void set2(jint index, jlong value) { 111 | *(jlong *)(&data[index]) = value; 112 | } 113 | 114 | jint get(jint index) { 115 | return data[index]; 116 | } 117 | 118 | void set(jint index, jint value) { 119 | data[index] = value; 120 | } 121 | 122 | jobject getref(jint index) { 123 | return refs[index]; 124 | } 125 | 126 | void setref(jint index, jobject ref) { 127 | refs[index] = ref; 128 | } 129 | }; 130 | 131 | jint cfi(jfloat f); 132 | jfloat cif(jint f); 133 | jlong cdl(jdouble f); 134 | jdouble cld(jlong f); 135 | 136 | void init_utils(JNIEnv *env); 137 | 138 | jobjectArray create_multidim_array(JNIEnv *env, jint count, jint *sizes, const char *class_name, int line); 139 | 140 | jclass find_class_wo_static(JNIEnv *env, const char *class_name); 141 | 142 | void throw_re(JNIEnv *env, const char *exception_class, const char *error, int line); 143 | 144 | void bastore(JNIEnv *env, jarray array, jint index, jint value); 145 | jbyte baload(JNIEnv *env, jarray array, jint index); 146 | 147 | jlong cast_dl(jdouble value); 148 | jlong cast_fl(jfloat value); 149 | jint cast_di(jdouble value); 150 | jint cast_fi(jfloat value); 151 | 152 | void clear_refs(JNIEnv *env, std::unordered_set &refs); 153 | } 154 | 155 | #endif -------------------------------------------------------------------------------- /src/sources/native_jvm_output.cpp: -------------------------------------------------------------------------------- 1 | #include "native_jvm.hpp" 2 | #include "native_jvm_output.hpp" 3 | 4 | $includes 5 | 6 | namespace native_jvm { 7 | 8 | typedef void (* reg_method)(JNIEnv *,jvmtiEnv *); 9 | 10 | reg_method reg_methods[$class_count]; 11 | 12 | void register_for_class(JNIEnv *env, jclass, jint id) { 13 | jvmtiEnv *jvmti_env = nullptr; 14 | JavaVM *vm = nullptr; 15 | env->GetJavaVM(&vm); 16 | vm->GetEnv((void **)&jvmti_env, JVMTI_VERSION); 17 | 18 | reg_methods[id](env, jvmti_env); 19 | } 20 | 21 | void prepare_lib(JNIEnv *env, jvmtiEnv *jvmti_env) { 22 | utils::init_utils(env); 23 | if (env->ExceptionCheck()) 24 | return; 25 | 26 | $register_code 27 | 28 | char method_name[] = "registerNativesForClass"; 29 | char method_desc[] = "(I)V"; 30 | JNINativeMethod loader_methods[] = { 31 | { (char *) method_name, (char *) method_desc, (void *)®ister_for_class } 32 | }; 33 | env->RegisterNatives(env->FindClass("native$native_dir_id/Loader"), loader_methods, 1); 34 | } 35 | } 36 | 37 | extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { 38 | JNIEnv *env = nullptr; 39 | jvmtiEnv *jvmti_env = nullptr; 40 | vm->GetEnv((void **)&env, JNI_VERSION_1_8); 41 | vm->GetEnv((void **)&jvmti_env, JVMTI_VERSION); 42 | native_jvm::prepare_lib(env, jvmti_env); 43 | return JNI_VERSION_1_8; 44 | } -------------------------------------------------------------------------------- /src/sources/native_jvm_output.hpp: -------------------------------------------------------------------------------- 1 | #include "native_jvm.hpp" 2 | 3 | #ifndef NATIVE_JVM_OUTPUT_HPP_GUARD 4 | 5 | #define NATIVE_JVM_OUTPUT_HPP_GUARD 6 | 7 | namespace native_jvm { 8 | void prepare_lib(JNIEnv *env, jvmtiEnv *jvmti_env); 9 | } 10 | 11 | #endif -------------------------------------------------------------------------------- /src/sources/string_pool.cpp: -------------------------------------------------------------------------------- 1 | #include "string_pool.hpp" 2 | 3 | namespace native_jvm::string_pool { 4 | static char pool[$size] = $value; 5 | 6 | char *get_pool() { 7 | return pool; 8 | } 9 | } -------------------------------------------------------------------------------- /src/sources/string_pool.hpp: -------------------------------------------------------------------------------- 1 | #ifndef STRING_POOL_HPP_GUARD 2 | 3 | #define STRING_POOL_HPP_GUARD 4 | 5 | namespace native_jvm::string_pool { 6 | char *get_pool(); 7 | } 8 | 9 | #endif --------------------------------------------------------------------------------