├── .github └── workflows │ └── maven.yml ├── .gitignore ├── LICENSE ├── README.md ├── pom.xml └── src └── main └── java └── de └── mas └── wiiu └── jnus └── fuse_wiiu ├── Main.java ├── RootFuseFS.java ├── Settings.java ├── implementation ├── FSFuseContainer.java ├── FSTDataProviderContainer.java ├── GroupFuseContainer.java ├── GroupFuseContainerDefault.java ├── LocalBackupNUSTitleContainer.java ├── LocalNUSTitleContainer.java ├── MultipleFSTDataProviderFuseContainer.java ├── MultipleFSTDataProviderRecursiveFuseContainer.java ├── NUSTitleEncryptedFuseContainer.java ├── RemoteLocalBackupNUSTitleContainer.java ├── WUDToWUDContainer.java ├── WoomyNUSTitleContainer.java └── loader │ ├── WUDFSTDataProviderLoader.java │ └── WumadFSTDataProviderLoader.java ├── interfaces ├── FSTDataProviderLoader.java ├── FuseContainer.java └── FuseDirectory.java └── utils ├── FuseContainerWrapper.java ├── TicketUtils.java └── WUDUtils.java /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | # This workflow will build a Java project with Maven 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven 3 | 4 | name: Java CI with Maven 5 | 6 | on: 7 | push: 8 | branches: [ master ] 9 | pull_request: 10 | branches: [ master ] 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v2 19 | - name: Set up JDK 1.8 20 | uses: actions/setup-java@v1 21 | with: 22 | java-version: 1.8 23 | - name: Build with Maven 24 | run: mvn -B package --file pom.xml 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .classpath 2 | common.key 3 | .project 4 | *.jar 5 | *.key 6 | .settings/ 7 | target/ 8 | .idea/ 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # fuse-wiiu 2 | fuse-wiiu is an easy way to extract data from Wii U titles in various formats. 3 | It's compatible to: 4 | - Title in the installable format (.tmd, .app, .h3 etc.) 5 | - Multiple versions of a title in the installable format (.tmd, .app, .h3 etc.) 6 | - Wii U disc images (WUD, WUX and splitted WUD), including kiosk discs and .wumad files. 7 | 8 | fuse-wiiu requires Java 8 and fuse implementation thats compatible to you OS and CPU architecture. 9 | # Setup 10 | Before fuse-wiiu can be used the following steps are required. 11 | 12 | ## Fuse 13 | 14 | ### Linux 15 | 16 | [`libfuse`](https://github.com/libfuse/libfuse) needs to be installed. 17 | 18 | **Ubuntu** 19 | ```bash 20 | sudo apt-get install libfuse-dev 21 | ``` 22 | 23 | ### MacOS 24 | 25 | [`osxfuse`](https://osxfuse.github.io) needs to be installed. 26 | 27 | ```bash 28 | brew cask install osxfuse 29 | ``` 30 | 31 | ### Windows 32 | 33 | [`winfsp`](https://github.com/billziss-gh/winfsp) needs to be installed. 34 | ```batch 35 | choco install winfsp 36 | ``` 37 | 38 | ## Keys (optional) 39 | To decrypt the titles, some keys are required. 40 | 41 | The retail common key is expected in either `~/.wiiu/common.key` or `./common.key` in binary. It's also possible to provide it via an command line argument `-commonkey` with the key as hex-string. 42 | 43 | The dev common key optional for most titles but is expected in either `~/.wiiu/devcommon.key` or `./devcommon.key` in binary. It's also possible to provide it via an command line argument `-devcommonkey` with the key as hex-string. 44 | 45 | It's possible to provide the disc keys (for decrypting WUD/WUX) or titles keys (to decrypt tmd+app) in a seperate folder. This step is optional 46 | Disc keys are expected in `~/.wiiu/discKeys`, and should have the same basename as the WUD/WUX. Example: If a `mygame.wux` is found, a `mygame.key` will be searched in folder next the `.wux`. If it doesn't exist, it'll try to load `~/.wiiu/discKeys/mygame.key`. The `.key` is expected to contain the disc key in binary. 47 | 48 | If a installable title doesn't provide a `title.tik`, it's possible to provide the needed title key in the folder `~/.wiiu/titleKeys`. Corresponding to the title id, a `TITLEID.key` is expected which contains the key in binary. Example: if the title `000500101004B100` doesn't have a `title.tik`, wiiu-fuse will try to load a `000500101004B100.key` from `~/.wiiu/titleKeys`. 49 | 50 | More information can be found in "Supported formats". 51 | # Usage 52 | fuse-wiiu will be started from the command line and requires Java 8 and a fuse implementation (see Setup). 53 | 54 | ## Input path 55 | The most imported argument in the `-in` argument which defines the input path. In most cases this will be a folder, but it's also possible to choose a WUD/WUX directly. If a folder was chosen as input, it will be mirrored to the mounpath, but normal files be hidden. Directories will still be as expected, and whenever a support titles can be mounted, it will be emulated as directory with the prefix `[EMULATED] `. More information about the behavious on different fileformats can be found on "Supported formats". 56 | 57 | ## Mount path 58 | The mountpath will be set via the `-mountpath` argument and will set the target of fuse-wiiu. This can be almost any path (and a drive on Windows). 59 | Just make sure: 60 | - The path doesn't exist - but the parent path (if existing) DOES exist. 61 | - (unix) The user can only mount on a mountpoint for which he has write permission 62 | - (unitx) The mountpoint must not be a sticky directory which isn't owned by the user (like /tmp usually is) 63 | 64 | **Example Windows:** 65 | To mount the folder `H:/WiiU` to `Q:/` you would use something like this: 66 | `java "-Dfile.encoding=UTF-8" -jar wiiu-fuse.jar -in H:/WiiU -mountpath Q` 67 | 68 | To mount the folder `H:/WiiU` to `C:/mounted` you would use something like this: 69 | `java "-Dfile.encoding=UTF-8" -jar wiiu-fuse.jar -in H:/WiiU -mountpath C:/mounted` 70 | **Note: You may need to force Java to use the UTF-8 charset. Quoting the VM argument is need by Powershell** 71 | 72 | **Example Unix:** 73 | To mount the home folder to `~/test` you use something like this: 74 | `java -jar wiiu-fuse.jar -in ~ -mountpath ~/test` 75 | 76 | 77 | ## Optional arguments. 78 | - `-commonkey [KEY AS HEX STRING]` The Wii U retail common key. If not provided, the key will be tried to be read from ~/.wiiu/common.key` or `./common.key`. The argument has priority. 79 | - `-devcommonkey [KEY AS HEX STRING]` The Wii U dev common key. If not provided, the key will be tried to be read from ~/.wiiu/devcommon.key` or `./devcommon.key`. The argument has priority. 80 | - `-disckeypath [path]` Override the path where disc keys will be tried to be loaded from. 81 | - `-titlekeypath [path]` Override the path where titles keys will be tried to be loaded from. 82 | 83 | ## Forcing the UTF-8 charset to the JVM 84 | `java "-Dfile.encoding=UTF-8" -jar wiiu-fuse.jar` or java -Dfile.encoding=UTF-8 -jar wiiu-fuse.jar`. 85 | 86 | # Supported formats 87 | It's possible to use any directory as input, `fuse-wiiu` will scan will useable formats and mount them on request. If a directory wasn't used for ~5 minutes, it will be unmounted, but automatically remounted on the next access. 88 | 89 | If a supported format is found and successfully mounted, a support starting with `[EMULATED] ` will be emulated, which will give you access to the files. The actual content and file layout may differ from format to format. 90 | 91 | ## Wii U disc images - WUD/WUX/Wumad 92 | Images of Wii U discs are saved `.wud` (or `.wux` if compressed, or `game_partX.wud` when dumped on FAT32). Every .wux, .wud or .wumad will be emulated as up to three different directories (for image names `game.wux`). 93 | 94 | - [EMULATED] game.wux 95 | - This directory is the "normal" representation of a Wii U disc image. It'll have one subfolder for each partition. The `GM`-Partitions will be mounted and decrypted directly in the common `code, content and meta` format. The `SI` contain the ticket and tmd for `GM` partitions. All other partitions give you files in the "installable" format (tmd,app,tik). 96 | - [EMULATED] [EXTRA] game.wux 97 | - In this directory you can find some extra data (or data in a different presentation) of the disc. This includes: 98 | - The `GM` partitions in the "installable" format. (Folders with the prefix `[ENCRYPTED] `) 99 | - Mounted and decrypted titles from all partitions. (Folder with the prefix `[DECRYPTED] [PARTITIONNAME]`) 100 | - This includes titles from the non-`GM` partitions (like updates), and installable titles from the decrypted `GM` partitions (titles from kiosk discs). 101 | - [EMULATED] [WUD] game.wux (Only for WUX and splitted WUD) 102 | - In this directory you can access Wii U disc image as the orginal WUD. 103 | 104 | Expected file layout: 105 | ``` 106 | game.wux (or game.wud) 107 | (game.key) 108 | ``` 109 | 110 | For all discs (except kiosk discs and .wumad), a file containing the disc key is required. This has be either in a `.key` in the same folder as the wux/wud or in `~/.wiiu/disckeypath` (with the same basename e.g `game.wux` -> `game.key`). 111 | 112 | Multiple WUD/WUX in the same directory are possible, they won't be mounted until you open them. 113 | 114 | ## Installable format (tmd/h3/app) 115 | 116 | Expected file layout: 117 | ``` 118 | - title.tmd 119 | - 0000000X.app 120 | - 0000000X.h3 121 | - (title.tik) 122 | ``` 123 | 124 | The `title.tik` is optional. If no ticket was found, a file `[titleID].key` (where `[titleID]` is the titleID of the .tmd)containing the key in binary (16 bytes) is expected in `~/.wiiu/titlekeypath` (default `~/.wiiu/titleKeys`). 125 | 126 | ## Extended installable format (tmd/h3/app) with multiple versions. 127 | It's possible to have to mount multiple versions of an installable title. In this case, all `.app` files are expected in the root, and a `tmd.[VERSION]` for each tmd of a version. 128 | 129 | Expected file layout: 130 | ``` 131 | - tmd.0 132 | - tmd.16 133 | - tmd.48 134 | - 0000000X.app 135 | - 0000000X.h3 136 | - (title.tik) 137 | ``` 138 | 139 | The `title.tik` is optional. If no ticket was found, a file `[titleID].key` (where `[titleID]` is the titleID of the .tmd)containing the key in binary (16 bytes) is expected in `~/.wiiu/titlekeypath` (default `~/.wiiu/titleKeys`). 140 | 141 | ## NUS installable format (tmd/h3/app) with multiple versions. 142 | It's possible to have to mount multiple versions of an installable title. In this case, all content files are expected to have no extension in the root directory. A `tmd.[VERSION]` for each tmd of a version is expected. 143 | 144 | Expected file layout: 145 | ``` 146 | - tmd.0 147 | - tmd.16 148 | - tmd.48 149 | - 0000000X 150 | - 0000000X.h3 151 | - (cetk) 152 | ``` 153 | 154 | The `cetk` is optional. If no ticket was found, a file `[titleID].key` (where `[titleID]` is the titleID of the .tmd) containing the key in binary (16 bytes) is expected in `~/.wiiu/titlekeypath` (default `~/.wiiu/titleKeys`). 155 | 156 | 157 | # Used libraries 158 | 159 | - [jnr-fuse](https://github.com/SerCeMan/jnr-fuse) 160 | - [lombok](https://projectlombok.org/) (install it to your IDE) 161 | - [JNUSLib](https://github.com/Maschell/JNUSLib) 162 | - [commons-cli](https://commons.apache.org/proper/commons-cli/)- -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 4 | 4.0.0 5 | 6 | de.mas.wiiu.jnus 7 | fuse-wiiu 8 | 0.4 9 | jar 10 | 11 | fuse-wiiu 12 | http://maven.apache.org 13 | 14 | UTF-8 15 | 16 | 17 | 18 | 19 | normal-build 20 | 21 | true 22 | 23 | 24 | ./target 25 | 26 | 27 | 28 | ci-build 29 | 30 | 31 | ci-build 32 | true 33 | 34 | 35 | 36 | ./ci 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | maven-compiler-plugin 45 | 3.7.0 46 | 47 | 1.8 48 | 1.8 49 | 50 | 51 | 52 | maven-assembly-plugin 53 | 54 | 55 | make-assembly 56 | 57 | 58 | 59 | de.mas.wiiu.jnus.fuse_wiiu.Main 60 | 61 | 62 | 63 | jar-with-dependencies 64 | 65 | 66 | ${jar_dir} 67 | fuse-wiiu-${project.version}-nightly 68 | 69 | package 70 | 71 | attached 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | central 82 | bintray 83 | http://jcenter.bintray.com 84 | 85 | 86 | jitpack.io 87 | https://jitpack.io 88 | 89 | 90 | 91 | 92 | 93 | com.github.Maschell 94 | JNUSLib 95 | 822cf2d 96 | 97 | 98 | org.projectlombok 99 | lombok 100 | 1.16.18 101 | 102 | 103 | com.github.serceman 104 | jnr-fuse 105 | 0.5.3 106 | 107 | 108 | commons-cli 109 | commons-cli 110 | 1.4 111 | 112 | 113 | org.slf4j 114 | slf4j-api 115 | 1.7.5 116 | 117 | 118 | org.slf4j 119 | slf4j-log4j12 120 | 1.7.5 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /src/main/java/de/mas/wiiu/jnus/fuse_wiiu/Main.java: -------------------------------------------------------------------------------- 1 | package de.mas.wiiu.jnus.fuse_wiiu; 2 | 3 | import de.mas.wiiu.jnus.fuse_wiiu.implementation.GroupFuseContainer; 4 | import de.mas.wiiu.jnus.fuse_wiiu.implementation.GroupFuseContainerDefault; 5 | import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FuseContainer; 6 | import de.mas.wiiu.jnus.fuse_wiiu.utils.FuseContainerWrapper; 7 | import de.mas.wiiu.jnus.utils.HashUtil; 8 | import de.mas.wiiu.jnus.utils.Utils; 9 | import org.apache.commons.cli.*; 10 | 11 | import java.io.File; 12 | import java.io.IOException; 13 | import java.nio.charset.Charset; 14 | import java.nio.file.Files; 15 | import java.util.Arrays; 16 | import java.util.Map; 17 | import java.util.Map.Entry; 18 | import java.util.Optional; 19 | 20 | public class Main { 21 | private static final String DEV_COMMON_KEY = "devcommon.key"; 22 | private static final String COMMON_KEY = "common.key"; 23 | private final static String OPTION_HELP = "help"; 24 | private final static String OPTION_MOUNTPATH = "mountpath"; 25 | private final static String OPTION_INPUT = "in"; 26 | private final static String OPTION_DISCKEYS = "disckeypath"; 27 | private final static String OPTION_TITLEKEYS = "titlekeypath"; 28 | private static final String OPTION_COMMON_KEY = "commonkey"; 29 | private static final String OPTION_DEV_COMMON_KEY = "devcommonkey"; 30 | private static final String HOMEPATH = System.getProperty("user.home") + File.separator + ".wiiu"; 31 | private static final String DISC_KEY_PATH = "discKeys"; 32 | private static final String TITLE_KEY_PATH = "titleKeys"; 33 | 34 | private static Optional readKey(File file) { 35 | if (file.isFile()) { 36 | byte[] key; 37 | try { 38 | key = Files.readAllBytes(file.toPath()); 39 | if (key != null && key.length == 16) { 40 | return Optional.of(key); 41 | } 42 | } catch (IOException e) { 43 | } 44 | } 45 | return Optional.empty(); 46 | } 47 | 48 | private static void checkKeysForFolder(File folder) { 49 | if (folder.exists()) { 50 | File commonkeyFile = new File(folder.getAbsolutePath() + File.separator + COMMON_KEY); 51 | File commonkeyDevFile = new File(folder.getAbsolutePath() + File.separator + DEV_COMMON_KEY); 52 | 53 | if (commonkeyFile.exists()) { 54 | readKey(commonkeyFile).ifPresent(key -> Settings.retailCommonKey = key); 55 | } 56 | 57 | if (commonkeyDevFile.exists()) { 58 | readKey(commonkeyDevFile).ifPresent(key -> Settings.devCommonKey = key); 59 | } 60 | } 61 | } 62 | 63 | public static void main(String[] args) throws Exception { 64 | if (!Charset.defaultCharset().toString().equals("UTF-8")) { 65 | System.err.println("This application needs to be started with the \"UTF-8\" charset."); 66 | System.out.println("Use the jvm argument \"-Dfile.encoding=UTF-8\"."); 67 | System.exit(-1); 68 | } 69 | File homewiiufolder = new File(HOMEPATH); 70 | 71 | checkKeysForFolder(homewiiufolder); 72 | checkKeysForFolder(new File(".")); 73 | 74 | Options options = getOptions(); 75 | 76 | if (args.length == 0) { 77 | showHelp(options); 78 | return; 79 | } 80 | 81 | Settings.disckeyPath = new File(HOMEPATH + File.separator + DISC_KEY_PATH); 82 | Settings.titlekeyPath = new File(HOMEPATH + File.separator + TITLE_KEY_PATH); 83 | 84 | CommandLineParser parser = new DefaultParser(); 85 | CommandLine cmd = null; 86 | 87 | String mountPath = ""; 88 | 89 | cmd = parser.parse(options, args); 90 | 91 | String inputPath = ""; 92 | 93 | if (cmd.hasOption(OPTION_MOUNTPATH)) { 94 | mountPath = cmd.getOptionValue(OPTION_MOUNTPATH); 95 | } 96 | 97 | if (cmd.hasOption(OPTION_INPUT)) { 98 | inputPath = cmd.getOptionValue(OPTION_INPUT); 99 | } 100 | 101 | if (cmd.hasOption(OPTION_COMMON_KEY)) { 102 | String commonKey = cmd.getOptionValue(OPTION_COMMON_KEY); 103 | byte[] key = Utils.StringToByteArray(commonKey); 104 | if (key != null && key.length == 0x10) { 105 | Settings.retailCommonKey = key; 106 | System.out.println("Common key was set from command line."); 107 | } 108 | } 109 | 110 | if (cmd.hasOption(OPTION_DEV_COMMON_KEY)) { 111 | String devCommonKey = cmd.getOptionValue(OPTION_DEV_COMMON_KEY); 112 | byte[] key = Utils.StringToByteArray(devCommonKey); 113 | if (key != null && key.length == 0x10) { 114 | Settings.devCommonKey = key; 115 | System.out.println("Dev common key was set from command line."); 116 | } 117 | } 118 | 119 | if (cmd.hasOption(OPTION_DISCKEYS)) { 120 | Settings.disckeyPath = new File(cmd.getOptionValue(OPTION_DISCKEYS)); 121 | } 122 | 123 | if (cmd.hasOption(OPTION_TITLEKEYS)) { 124 | Settings.titlekeyPath = new File(cmd.getOptionValue(OPTION_TITLEKEYS)); 125 | } 126 | 127 | File mount = new File(mountPath); 128 | File mountparent = mount.getParentFile(); 129 | if (mountparent != null && !mountparent.exists()) { 130 | System.err.println("Mounting to " + mount + " is not possible." + mountparent + " does not exist"); 131 | return; 132 | } else if (mount.exists() && System.getProperty("os.name").contains("Windows")) { 133 | System.err.println("Mounting to " + mount + " is not possible. It's already mounted or in use"); 134 | return; 135 | } 136 | 137 | if (!Arrays.equals(HashUtil.hashSHA1(Settings.retailCommonKey), Settings.retailCommonKeyHash)) { 138 | System.err.println("WARNING: Retail common key is not as expected"); 139 | } else { 140 | System.out.println("retail common key is okay"); 141 | } 142 | 143 | if (!Arrays.equals(HashUtil.hashSHA1(Settings.devCommonKey), Settings.devCommonKeyHash)) { 144 | System.err.println("WARNING: Dev common key is not as expected"); 145 | } else { 146 | System.out.println("dev common key is okay"); 147 | } 148 | 149 | System.out.println("disc key path is: " + Settings.disckeyPath.getAbsolutePath()); 150 | System.out.println("title key path is: " + Settings.titlekeyPath.getAbsolutePath()); 151 | 152 | GroupFuseContainer root = new GroupFuseContainerDefault(Optional.empty()); 153 | 154 | File input = new File(inputPath); 155 | Map containers = FuseContainerWrapper.createFuseContainer(Optional.of(root), input); 156 | for (Entry c : containers.entrySet()) { 157 | String name = c.getKey(); 158 | if (name.isEmpty()) { 159 | name = input.getAbsolutePath().replaceAll("[\\\\/:*?\"<>|]", ""); 160 | } 161 | root.addFuseContainer(name, c.getValue()); 162 | } 163 | 164 | RootFuseFS stub = new RootFuseFS(root); 165 | try { 166 | System.out.println("Mounting " + new File(inputPath).getAbsolutePath() + " to " + mount.getAbsolutePath()); 167 | stub.mount(mount.toPath(), true, false); 168 | } finally { 169 | stub.umount(); 170 | } 171 | } 172 | 173 | private static Options getOptions() { 174 | Options options = new Options(); 175 | options.addOption(Option.builder(OPTION_MOUNTPATH).required().hasArg() 176 | .desc("The target mount path.").build()); 177 | options.addOption(Option.builder(OPTION_INPUT).required().hasArg().desc("input path").build()); 178 | options.addOption(Option.builder(OPTION_DISCKEYS).optionalArg(true).hasArg() 179 | .desc("Path of .key files used to decrypt WUD/WUX. If not set \"" + HOMEPATH + File.separator + DISC_KEY_PATH + "\" will be used.").build()); 180 | options.addOption(Option.builder(OPTION_TITLEKEYS).optionalArg(true).hasArg() 181 | .desc("Path of [TITLTEID].key files used to decrypt encrypted titles (.app,.tmd etc.). If not set \"" + HOMEPATH + File.separator 182 | + TITLE_KEY_PATH + "\" will be used.") 183 | .build()); 184 | options.addOption(Option.builder(OPTION_COMMON_KEY).optionalArg(true).hasArg() 185 | .desc("Wii U retail common key as binary string. Will be used even if a key is specified in \"" + HOMEPATH + File.separator + COMMON_KEY 186 | + "\" or \"" + HOMEPATH + File.separator + COMMON_KEY + "\"") 187 | .build()); 188 | options.addOption(Option.builder(OPTION_DEV_COMMON_KEY).optionalArg(true).hasArg() 189 | .desc("Wii U dev common key as binary string. Will be used even if a key is specified in \"" + HOMEPATH + File.separator + DEV_COMMON_KEY 190 | + "\" or \"" + HOMEPATH + File.separator + DEV_COMMON_KEY + "\"") 191 | .build()); 192 | 193 | options.addOption(OPTION_HELP, false, "shows this text"); 194 | 195 | return options; 196 | } 197 | 198 | private static void showHelp(Options options) { 199 | HelpFormatter formatter = new HelpFormatter(); 200 | formatter.setWidth(100); 201 | formatter.printHelp(" ", options); 202 | } 203 | 204 | } 205 | -------------------------------------------------------------------------------- /src/main/java/de/mas/wiiu/jnus/fuse_wiiu/RootFuseFS.java: -------------------------------------------------------------------------------- 1 | package de.mas.wiiu.jnus.fuse_wiiu; 2 | 3 | import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FuseContainer; 4 | import jnr.ffi.Pointer; 5 | import jnr.ffi.types.off_t; 6 | import jnr.ffi.types.size_t; 7 | import ru.serce.jnrfuse.FuseFillDir; 8 | import ru.serce.jnrfuse.FuseStubFS; 9 | import ru.serce.jnrfuse.struct.FileStat; 10 | import ru.serce.jnrfuse.struct.FuseFileInfo; 11 | 12 | public class RootFuseFS extends FuseStubFS { 13 | 14 | private final FuseContainer root; 15 | 16 | public RootFuseFS(FuseContainer root) { 17 | this.root = root; 18 | } 19 | 20 | @Override 21 | public int getattr(String path, FileStat stat) { 22 | int res = root.getattr(path, stat); 23 | // System.out.println("getattr " + res + " for " + path); 24 | return res; 25 | } 26 | 27 | @Override 28 | public int open(String path, FuseFileInfo fi) { 29 | int res = root.open(path, fi); 30 | // System.out.println("readdir " + res + " for " + path); 31 | return res; 32 | } 33 | 34 | @Override 35 | public int readdir(String path, Pointer buf, FuseFillDir filter, @off_t long offset, FuseFileInfo fi) { 36 | int res = root.readdir(path, buf, filter, offset, fi); 37 | // System.out.println("readdir " + res + " for " + path); 38 | return res; 39 | } 40 | 41 | @Override 42 | public int read(String path, Pointer buf, @size_t long size, @off_t long offset, FuseFileInfo fi) { 43 | int res = root.read(path, buf, size, offset, fi); 44 | // System.out.println("read " + res + " for " + path); 45 | return res; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/de/mas/wiiu/jnus/fuse_wiiu/Settings.java: -------------------------------------------------------------------------------- 1 | package de.mas.wiiu.jnus.fuse_wiiu; 2 | 3 | import de.mas.wiiu.jnus.utils.Utils; 4 | 5 | import java.io.File; 6 | 7 | public class Settings { 8 | public static final byte[] retailCommonKeyHash = Utils.StringToByteArray("6A0B87FC98B306AE3366F0E0A88D0B06A2813313"); 9 | public static final byte[] devCommonKeyHash = Utils.StringToByteArray("E191BFDB1232537D7DADEAD81F2A48FD6F188E02"); 10 | public static File disckeyPath = null; 11 | public static File titlekeyPath = null; 12 | public static byte[] retailCommonKey = new byte[16]; 13 | public static byte[] devCommonKey = new byte[16]; 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/FSFuseContainer.java: -------------------------------------------------------------------------------- 1 | package de.mas.wiiu.jnus.fuse_wiiu.implementation; 2 | 3 | import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FuseContainer; 4 | import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FuseDirectory; 5 | import de.mas.wiiu.jnus.fuse_wiiu.utils.FuseContainerWrapper; 6 | import lombok.val; 7 | 8 | import java.io.File; 9 | import java.util.*; 10 | import java.util.Map.Entry; 11 | 12 | /** 13 | * Representation of a directory on the OS filesystem. For every children of this directory the FuseContainerWrapper is used to create children if needed. 14 | * 15 | * @author Maschell 16 | * 17 | */ 18 | public class FSFuseContainer extends GroupFuseContainer { 19 | private final File curDir; 20 | private final Timer timer = new Timer(); 21 | 22 | public FSFuseContainer(Optional parent, File input) { 23 | super(parent); 24 | this.curDir = input; 25 | 26 | // Check every 5 minutes if the children of this directory have been accessed in the last 5 minutes. 27 | timer.schedule(new TimerTask() { 28 | public void run() { 29 | removeUnused(5 * 60 * 1000); 30 | } 31 | }, 5 * 60 * 1000, 5 * 60 * 1000); 32 | 33 | } 34 | 35 | @Override 36 | public void deinit() { 37 | // Stop the timers so this can be collected by the GC. 38 | timer.cancel(); 39 | timer.purge(); 40 | } 41 | 42 | Map> existingFiles = new HashMap<>(); 43 | 44 | /** 45 | * Add FuseContainer for the children of this directory, but only if they are missing. 46 | */ 47 | private void updateFolder() { 48 | for (File f : curDir.listFiles()) { 49 | Collection t = existingFiles.get(f); 50 | if (t != null && !t.isEmpty()) { 51 | boolean missing = false; 52 | for (String cur : t) { 53 | if (!hasFuseContainer(cur)) { 54 | missing = true; 55 | break; 56 | } 57 | } 58 | if (missing) { 59 | for (String cur : t) { 60 | removeFuseContainer(cur); 61 | } 62 | existingFiles.remove(f); 63 | } else { 64 | continue; 65 | } 66 | } 67 | 68 | val fuseContainers = FuseContainerWrapper.createFuseContainer(Optional.of(this), f); 69 | 70 | for (Entry e : fuseContainers.entrySet()) { 71 | addFuseContainer(e.getKey(), e.getValue()); 72 | } 73 | existingFiles.put(f, fuseContainers.keySet()); 74 | } 75 | } 76 | 77 | @Override 78 | protected void doInit() { 79 | updateFolder(); 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/FSTDataProviderContainer.java: -------------------------------------------------------------------------------- 1 | package de.mas.wiiu.jnus.fuse_wiiu.implementation; 2 | 3 | import de.mas.wiiu.jnus.entities.FST.nodeentry.DirectoryEntry; 4 | import de.mas.wiiu.jnus.entities.FST.nodeentry.FileEntry; 5 | import de.mas.wiiu.jnus.entities.FST.nodeentry.NodeEntry; 6 | import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FuseContainer; 7 | import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FuseDirectory; 8 | import de.mas.wiiu.jnus.interfaces.FSTDataProvider; 9 | import de.mas.wiiu.jnus.utils.FSTUtils; 10 | import jnr.ffi.Pointer; 11 | import lombok.Getter; 12 | import ru.serce.jnrfuse.ErrorCodes; 13 | import ru.serce.jnrfuse.FuseFillDir; 14 | import ru.serce.jnrfuse.struct.FileStat; 15 | import ru.serce.jnrfuse.struct.FuseFileInfo; 16 | 17 | import java.util.Optional; 18 | import java.util.function.Supplier; 19 | 20 | /** 21 | * FuseContainer implementation based on a FSTDataProvider. 22 | * 23 | * @author Maschell 24 | * 25 | */ 26 | public class FSTDataProviderContainer implements FuseContainer { 27 | private final Optional parent; 28 | @Getter(lazy = true) private final FSTDataProvider dataProvider = dataProviderSupplier.get(); 29 | private final Supplier dataProviderSupplier; 30 | 31 | public FSTDataProviderContainer(Optional parent, FSTDataProvider dp) { 32 | this(parent, () -> dp); 33 | } 34 | 35 | public FSTDataProviderContainer(Optional parent, Supplier dp) { 36 | this.parent = parent; 37 | this.dataProviderSupplier = dp; 38 | } 39 | 40 | @Override 41 | public Optional getParent() { 42 | return parent; 43 | } 44 | 45 | @Override 46 | public int open(String path, FuseFileInfo fi) { 47 | Optional entryOpt = FSTUtils.getFSTEntryByFullPath(getDataProvider().getRoot(), path); 48 | if (entryOpt.isPresent()) { 49 | if (entryOpt.get().isDirectory()) { 50 | return -ErrorCodes.EISDIR(); 51 | } else if (!entryOpt.get().isLink()) { 52 | return 0; 53 | } 54 | } 55 | return -ErrorCodes.ENOENT(); 56 | } 57 | 58 | @Override 59 | public int getattr(String path, FileStat stat) { 60 | if (path.equals("/")) { 61 | stat.st_mode.set(FileStat.S_IFDIR | 0755); 62 | stat.st_nlink.set(2); 63 | return 0; 64 | } 65 | Optional entryOpt = FSTUtils.getFSTEntryByFullPath(getDataProvider().getRoot(), path); 66 | 67 | int res = 0; 68 | if (entryOpt.isPresent()) { 69 | NodeEntry entry = entryOpt.get(); 70 | if (entry.isDirectory()) { 71 | stat.st_mode.set(FileStat.S_IFDIR | 0755); 72 | stat.st_nlink.set(2); 73 | } else { 74 | stat.st_mode.set(FileStat.S_IFREG | FileStat.ALL_READ); 75 | stat.st_nlink.set(1); 76 | stat.st_size.set(((FileEntry) entry).getSize()); 77 | } 78 | } else { 79 | System.out.println("error for " + path); 80 | return -ErrorCodes.ENOENT(); 81 | } 82 | return res; 83 | } 84 | 85 | @Override 86 | public int readdir(String path, Pointer buf, FuseFillDir filter, long offset, FuseFileInfo fi) { 87 | DirectoryEntry entry = getDataProvider().getRoot(); 88 | 89 | if (!path.equals("/")) { 90 | Optional entryOpt = FSTUtils.getFileEntryDir(entry, path); 91 | if (!entryOpt.isPresent()) { 92 | return -ErrorCodes.ENOENT(); 93 | } 94 | entry = entryOpt.get(); 95 | } 96 | 97 | filter.apply(buf, ".", null, 0); 98 | filter.apply(buf, "..", null, 0); 99 | 100 | for (NodeEntry e : entry.getChildren()) { 101 | if (!e.isLink()) { 102 | filter.apply(buf, e.getName(), null, 0); 103 | } 104 | } 105 | return 0; 106 | } 107 | 108 | @Override 109 | public int read(String path, Pointer buf, long size, long offset, FuseFileInfo fi) { 110 | Optional entryopt = FSTUtils.getFSTEntryByFullPath(getDataProvider().getRoot(), path); 111 | if (entryopt.isPresent() && !entryopt.get().isLink() && entryopt.get().isFile()) { 112 | 113 | FileEntry entry = (FileEntry) entryopt.get(); 114 | 115 | if (offset >= entry.getSize()) { 116 | return 0; 117 | } 118 | if (offset + size > entry.getSize()) { 119 | size = entry.getSize() - offset; 120 | } 121 | 122 | if (size > Integer.MAX_VALUE) { 123 | System.err.println("Request read size was too big."); 124 | return -ErrorCodes.EIO(); 125 | } 126 | 127 | try { 128 | byte[] data; 129 | if (offset % 16 > 0) { 130 | // make sure the offset is aligned to 0x10; 131 | // in worst case we read 15 additional bytes- 132 | long newOffset = (offset / 16) * 16; 133 | int diff = (int) (offset - newOffset); 134 | data = getDataProvider().readFile(entry, newOffset, size + diff); 135 | 136 | buf.put(0, data, diff, data.length - diff); 137 | 138 | return (int) (data.length > size ? size : data.length); 139 | } else { 140 | data = getDataProvider().readFile(entry, offset, size); 141 | buf.put(0, data, 0, data.length); 142 | return data.length; 143 | } 144 | } catch (Exception e) { 145 | e.printStackTrace(); 146 | return -ErrorCodes.ENOENT(); 147 | } 148 | } else { 149 | System.out.println("Path not found:" + path); 150 | return -ErrorCodes.ENOENT(); 151 | } 152 | } 153 | 154 | @Override 155 | public void init() { 156 | } 157 | 158 | @Override 159 | public void deinit() { 160 | } 161 | 162 | } 163 | -------------------------------------------------------------------------------- /src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/GroupFuseContainer.java: -------------------------------------------------------------------------------- 1 | package de.mas.wiiu.jnus.fuse_wiiu.implementation; 2 | 3 | import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FuseContainer; 4 | import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FuseDirectory; 5 | import jnr.ffi.Pointer; 6 | import jnr.ffi.types.off_t; 7 | import jnr.ffi.types.size_t; 8 | import ru.serce.jnrfuse.ErrorCodes; 9 | import ru.serce.jnrfuse.FuseFillDir; 10 | import ru.serce.jnrfuse.struct.FileStat; 11 | import ru.serce.jnrfuse.struct.FuseFileInfo; 12 | 13 | import java.util.HashMap; 14 | import java.util.Map; 15 | import java.util.Map.Entry; 16 | import java.util.Optional; 17 | import java.util.function.BiFunction; 18 | import java.util.stream.Collectors; 19 | 20 | /** 21 | * Implementation of an FuseContainer which can hold serveral FuseContainers emulated as directories. 22 | * 23 | * @author Maschell 24 | */ 25 | public abstract class GroupFuseContainer implements FuseContainer { 26 | private final Map containerMap = new HashMap<>(); 27 | private final Map lastAccess = new HashMap<>(); 28 | private final Optional parent; 29 | 30 | public GroupFuseContainer(Optional parent) { 31 | this.parent = parent; 32 | } 33 | 34 | /** 35 | * Removing old container from the list that haven't been updated in a given time frame. 36 | * 37 | * @param duration 38 | * @return Number of elements that have been removed. 39 | */ 40 | protected int removeUnused(long duration) { 41 | int count = 0; 42 | for (Entry cur : lastAccess.entrySet().stream().filter(e -> System.currentTimeMillis() - e.getValue() > duration) 43 | .collect(Collectors.toList())) { 44 | lastAccess.remove(cur.getKey()); 45 | containerMap.remove(cur.getKey()).deinit(); 46 | System.out.println("Unmounting " + cur.getKey()); 47 | count++; 48 | } 49 | if (count > 0) { 50 | synchronized (initDone) { 51 | initDone = false; 52 | } 53 | } 54 | return count; 55 | } 56 | 57 | /** 58 | * 59 | * @param path 60 | * @param func 61 | * @param defaultValue 62 | * @return 63 | */ 64 | private int doForContainer(String path, BiFunction func, int defaultValue) { 65 | path.replace("\\", "/"); 66 | path = path.substring(1); 67 | String[] parts = path.split("/"); 68 | 69 | FuseContainer container = containerMap.get(parts[0]); 70 | 71 | if (container != null) { 72 | lastAccess.put(parts[0], System.currentTimeMillis()); 73 | 74 | container.init(); 75 | 76 | String newPath = path.substring(parts[0].length()); 77 | if (newPath.length() == 0) { 78 | newPath = "/"; 79 | } 80 | return func.apply(newPath, container); 81 | } 82 | return defaultValue; 83 | } 84 | 85 | @Override 86 | public int getattr(String path, FileStat stat) { 87 | path.replace("\\", "/"); 88 | if (path.equals("/")) { 89 | stat.st_mode.set(FileStat.S_IFDIR | 0755); 90 | stat.st_nlink.set(2); 91 | return 0; 92 | } 93 | if (path.split("/").length == 2) { 94 | for (String container : containerMap.keySet()) { 95 | if (container.equals(path.split("/")[1])) { 96 | stat.st_mode.set(FileStat.S_IFDIR | 0755); 97 | stat.st_nlink.set(2); 98 | return 0; 99 | } 100 | } 101 | } 102 | 103 | return doForContainer(path, (newPath, container) -> container.getattr(newPath, stat), -ErrorCodes.ENOENT()); 104 | } 105 | 106 | @Override 107 | public int readdir(String path, Pointer buf, FuseFillDir filter, @off_t long offset, FuseFileInfo fi) { 108 | path.replace("\\", "/"); 109 | if (path.equals("/")) { 110 | filter.apply(buf, ".", null, 0); 111 | if (getParent().isPresent()) { 112 | filter.apply(buf, "..", null, 0); 113 | } 114 | for (String container : containerMap.keySet()) { 115 | filter.apply(buf, container, null, 0); 116 | } 117 | return 0; 118 | } 119 | 120 | return doForContainer(path, (newPath, container) -> container.readdir(newPath, buf, filter, offset, fi), 0); 121 | } 122 | 123 | @Override 124 | public int read(String path, Pointer buf, @size_t long size, @off_t long offset, FuseFileInfo fi) { 125 | path.replace("\\", "/"); 126 | if (path.length() <= 1) { 127 | return -ErrorCodes.EISDIR(); 128 | } 129 | 130 | return doForContainer(path, (newPath, container) -> container.read(newPath, buf, size, offset, fi), 0); 131 | } 132 | 133 | @Override 134 | public int open(String path, FuseFileInfo fi) { 135 | path.replace("\\", "/"); 136 | if (path.length() <= 1) { 137 | return -ErrorCodes.EISDIR(); 138 | } 139 | 140 | return doForContainer(path, (newPath, container) -> container.open(newPath, fi), 0); 141 | } 142 | 143 | @Override 144 | public Optional getParent() { 145 | return parent; 146 | } 147 | 148 | public FuseContainer addFuseContainer(String name, FuseContainer container) { 149 | return containerMap.put(name, container); 150 | } 151 | 152 | public void clearFuseContainer() { 153 | containerMap.clear(); 154 | } 155 | 156 | public FuseContainer getFuseContainer(String name) { 157 | return containerMap.get(name); 158 | } 159 | 160 | public boolean hasFuseContainer(String name) { 161 | return containerMap.containsKey(name); 162 | } 163 | 164 | public FuseContainer removeFuseContainer(String name) { 165 | return containerMap.remove(name); 166 | } 167 | 168 | private Boolean initDone = false; 169 | 170 | @Override 171 | public void init() { 172 | synchronized (initDone) { 173 | if (!initDone) { 174 | doInit(); 175 | initDone = true; 176 | } 177 | } 178 | } 179 | 180 | /** 181 | * This function is used to add FuseContainers to this GroupFuseContainer and can be called because of two reason. 1. The GroupFuseContainer is access for 182 | * the first time and the list FuseContainers in this group need to be added to the map using "addFuseContainer". 2. Some of the children have been removed 183 | * (due to inactivity). In this case the functions should add them again. So it needs to either add the missing one (check by hasFuseContainer), or 184 | * completely wipe and start over. 185 | */ 186 | abstract protected void doInit(); 187 | 188 | @Override 189 | public void deinit() { 190 | // 191 | } 192 | 193 | } 194 | -------------------------------------------------------------------------------- /src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/GroupFuseContainerDefault.java: -------------------------------------------------------------------------------- 1 | package de.mas.wiiu.jnus.fuse_wiiu.implementation; 2 | 3 | import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FuseDirectory; 4 | 5 | import java.util.Optional; 6 | 7 | /** 8 | * Default GroupFuseContainer implementation 9 | * 10 | * @author Maschell 11 | */ 12 | public class GroupFuseContainerDefault extends GroupFuseContainer { 13 | 14 | public GroupFuseContainerDefault(Optional parent) { 15 | super(parent); 16 | } 17 | 18 | @Override 19 | protected void doInit() { 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/LocalBackupNUSTitleContainer.java: -------------------------------------------------------------------------------- 1 | package de.mas.wiiu.jnus.fuse_wiiu.implementation; 2 | 3 | import de.mas.wiiu.jnus.NUSTitle; 4 | import de.mas.wiiu.jnus.NUSTitleLoaderLocalBackup; 5 | import de.mas.wiiu.jnus.entities.Ticket; 6 | import de.mas.wiiu.jnus.fuse_wiiu.Settings; 7 | import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FuseDirectory; 8 | import de.mas.wiiu.jnus.fuse_wiiu.utils.TicketUtils; 9 | import de.mas.wiiu.jnus.implementations.FSTDataProviderNUSTitle; 10 | import de.mas.wiiu.jnus.utils.Utils; 11 | 12 | import java.io.File; 13 | import java.io.IOException; 14 | import java.util.Optional; 15 | 16 | public class LocalBackupNUSTitleContainer extends GroupFuseContainer { 17 | 18 | private File folder; 19 | 20 | public LocalBackupNUSTitleContainer(Optional parent, File folder) { 21 | super(parent); 22 | this.folder = folder; 23 | } 24 | 25 | @Override 26 | protected void doInit() { 27 | File[] wud = folder.listFiles(f -> f.getName().startsWith("tmd.")); 28 | for (File versionF : wud) { 29 | short version = Short.parseShort(versionF.getName().substring(4)); 30 | this.addFuseContainer(String.format("v%d", version), new FSTDataProviderContainer(Optional.of(this), () -> { 31 | long titleID = Utils.StringToLong(folder.getName()); 32 | NUSTitle t = null; 33 | Optional ticketOpt = TicketUtils.getTicket(folder, Settings.titlekeyPath, titleID, Settings.retailCommonKey); 34 | if (!ticketOpt.isPresent()) { 35 | return null; 36 | } 37 | Ticket ticket = ticketOpt.get(); 38 | try { 39 | t = NUSTitleLoaderLocalBackup.loadNUSTitle(folder.getAbsolutePath(), version, ticket); 40 | } catch (Exception e) { 41 | // Try dev ticket 42 | ticket = Ticket.createTicket(ticket.getEncryptedKey(), titleID, Settings.devCommonKey); 43 | try { 44 | t = NUSTitleLoaderLocalBackup.loadNUSTitle(folder.getAbsolutePath(), version, ticket); 45 | } catch (Exception e1) { 46 | e.printStackTrace(); 47 | e1.printStackTrace(); 48 | } 49 | } 50 | try { 51 | return new FSTDataProviderNUSTitle(t); 52 | } catch (IOException e) { 53 | e.printStackTrace(); 54 | return null; 55 | } 56 | })); 57 | } 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/LocalNUSTitleContainer.java: -------------------------------------------------------------------------------- 1 | package de.mas.wiiu.jnus.fuse_wiiu.implementation; 2 | 3 | import de.mas.wiiu.jnus.NUSTitle; 4 | import de.mas.wiiu.jnus.NUSTitleLoaderLocal; 5 | import de.mas.wiiu.jnus.entities.TMD.TitleMetaData; 6 | import de.mas.wiiu.jnus.entities.Ticket; 7 | import de.mas.wiiu.jnus.fuse_wiiu.Settings; 8 | import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FuseDirectory; 9 | import de.mas.wiiu.jnus.fuse_wiiu.utils.TicketUtils; 10 | import de.mas.wiiu.jnus.implementations.FSTDataProviderNUSTitle; 11 | 12 | import java.io.File; 13 | import java.io.IOException; 14 | import java.text.ParseException; 15 | import java.util.Optional; 16 | 17 | public class LocalNUSTitleContainer extends GroupFuseContainer { 18 | 19 | private File folder; 20 | 21 | public LocalNUSTitleContainer(Optional parent, File folder) { 22 | super(parent); 23 | this.folder = folder; 24 | } 25 | 26 | @Override 27 | protected void doInit() { 28 | long titleID = 0; 29 | short version = 0; 30 | try { 31 | TitleMetaData tmd = TitleMetaData.parseTMD(new File(folder.getAbsoluteFile() + File.separator + "title.tmd")); 32 | titleID = tmd.getTitleID(); 33 | version = tmd.getTitleVersion(); 34 | } catch (IOException | ParseException e2) { 35 | return; 36 | } 37 | 38 | long titleIDcpy = titleID; 39 | 40 | this.addFuseContainer(String.format("v%d", version), new FSTDataProviderContainer(Optional.of(this), () -> { 41 | NUSTitle t = null; 42 | 43 | Optional ticketOpt = TicketUtils.getTicket(folder, Settings.titlekeyPath, titleIDcpy, Settings.retailCommonKey); 44 | if (!ticketOpt.isPresent()) { 45 | return null; 46 | } 47 | Ticket ticket = ticketOpt.get(); 48 | 49 | try { 50 | t = NUSTitleLoaderLocal.loadNUSTitle(folder.getAbsolutePath(), ticket); 51 | } catch (Exception e) { 52 | ticket = Ticket.createTicket(ticket.getEncryptedKey(), titleIDcpy, Settings.devCommonKey); 53 | try { 54 | t = NUSTitleLoaderLocal.loadNUSTitle(folder.getAbsolutePath(), ticket); 55 | } catch (Exception e1) { 56 | e.printStackTrace(); 57 | e1.printStackTrace(); 58 | } 59 | } 60 | 61 | try { 62 | return new FSTDataProviderNUSTitle(t); 63 | } catch (IOException e) { 64 | e.printStackTrace(); 65 | return null; 66 | } 67 | })); 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/MultipleFSTDataProviderFuseContainer.java: -------------------------------------------------------------------------------- 1 | package de.mas.wiiu.jnus.fuse_wiiu.implementation; 2 | 3 | import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FSTDataProviderLoader; 4 | import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FuseDirectory; 5 | import de.mas.wiiu.jnus.interfaces.FSTDataProvider; 6 | import lombok.val; 7 | 8 | import java.io.File; 9 | import java.util.List; 10 | import java.util.Optional; 11 | 12 | public class MultipleFSTDataProviderFuseContainer extends GroupFuseContainer { 13 | private final File file; 14 | private final FSTDataProviderLoader loader; 15 | private int i = 0; 16 | 17 | public MultipleFSTDataProviderFuseContainer(Optional parent, File file, FSTDataProviderLoader loader) { 18 | super(parent); 19 | this.file = file; 20 | this.loader = loader; 21 | } 22 | 23 | @Override 24 | protected void doInit() { 25 | Optional infoOpt = loader.loadInfo(file); 26 | if (infoOpt.isPresent()) { 27 | parseContents(loader.getDataProvider(infoOpt.get())); 28 | } else { 29 | System.err.println("Failed to parse " + file.getAbsolutePath()); 30 | } 31 | } 32 | 33 | void parseContents(List dps) { 34 | for (val dp : dps) { 35 | this.addFuseContainer(dp.getName() + "_" + (++i), new FSTDataProviderContainer(getParent(), dp)); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/MultipleFSTDataProviderRecursiveFuseContainer.java: -------------------------------------------------------------------------------- 1 | package de.mas.wiiu.jnus.fuse_wiiu.implementation; 2 | 3 | import de.mas.wiiu.jnus.NUSTitleLoaderFST; 4 | import de.mas.wiiu.jnus.entities.FST.nodeentry.DirectoryEntry; 5 | import de.mas.wiiu.jnus.entities.FST.nodeentry.FileEntry; 6 | import de.mas.wiiu.jnus.fuse_wiiu.Settings; 7 | import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FSTDataProviderLoader; 8 | import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FuseDirectory; 9 | import de.mas.wiiu.jnus.implementations.FSTDataProviderNUSTitle; 10 | import de.mas.wiiu.jnus.interfaces.FSTDataProvider; 11 | import de.mas.wiiu.jnus.interfaces.HasNUSTitle; 12 | import de.mas.wiiu.jnus.utils.FSTUtils; 13 | 14 | import java.io.File; 15 | import java.io.IOException; 16 | import java.text.ParseException; 17 | import java.util.List; 18 | import java.util.Optional; 19 | 20 | public class MultipleFSTDataProviderRecursiveFuseContainer extends MultipleFSTDataProviderFuseContainer { 21 | public MultipleFSTDataProviderRecursiveFuseContainer(Optional parent, File input, FSTDataProviderLoader loader) { 22 | super(parent, input, loader); 23 | } 24 | 25 | @Override 26 | void parseContents(List dps) { 27 | try { 28 | for (FSTDataProvider dp : dps) { 29 | for (FileEntry tmd : FSTUtils.getFSTEntriesByRegEx(dp.getRoot(), ".*tmd")) { 30 | DirectoryEntry parent = tmd.getParent(); 31 | if (parent.getFileChildren().stream().filter(f -> f.getName().endsWith(".app")).findAny().isPresent()) { 32 | FSTDataProvider fdp = null; 33 | 34 | try { 35 | fdp = new FSTDataProviderNUSTitle(NUSTitleLoaderFST.loadNUSTitle(dp, parent, Settings.retailCommonKey)); 36 | } catch (IOException | ParseException e) { 37 | try { 38 | fdp = new FSTDataProviderNUSTitle(NUSTitleLoaderFST.loadNUSTitle(dp, parent, Settings.devCommonKey)); 39 | } catch (Exception e1) { 40 | System.out.println("Ignoring " + parent.getName() + " :" + e1.getClass().getName() + " " + e1.getMessage()); 41 | continue; 42 | } 43 | } catch (Exception e) { 44 | System.out.println("Ignoring " + parent.getName() + " :" + e.getClass().getName() + " " + e.getMessage()); 45 | continue; 46 | } 47 | 48 | FSTDataProvider fdpCpy = fdp; 49 | 50 | this.addFuseContainer("[DECRYPTED] [" + dp.getName() + "] " + parent.getName(), new FSTDataProviderContainer(getParent(), fdpCpy)); 51 | } 52 | } 53 | 54 | if (dp instanceof HasNUSTitle) { 55 | try { 56 | this.addFuseContainer("[ENCRYPTED] " + dp.getName(), new NUSTitleEncryptedFuseContainer(getParent(), ((HasNUSTitle) dp).getNUSTitle())); 57 | } catch (Exception e) { 58 | e.printStackTrace(); 59 | } 60 | } 61 | 62 | } 63 | } catch (Exception e) { 64 | e.printStackTrace(); 65 | } 66 | 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/NUSTitleEncryptedFuseContainer.java: -------------------------------------------------------------------------------- 1 | package de.mas.wiiu.jnus.fuse_wiiu.implementation; 2 | 3 | import de.mas.wiiu.jnus.NUSTitle; 4 | import de.mas.wiiu.jnus.entities.TMD.Content; 5 | import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FuseContainer; 6 | import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FuseDirectory; 7 | import jnr.ffi.Pointer; 8 | import ru.serce.jnrfuse.ErrorCodes; 9 | import ru.serce.jnrfuse.FuseFillDir; 10 | import ru.serce.jnrfuse.struct.FileStat; 11 | import ru.serce.jnrfuse.struct.FuseFileInfo; 12 | 13 | import java.io.IOException; 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | import java.util.Optional; 17 | import java.util.function.Supplier; 18 | 19 | public class NUSTitleEncryptedFuseContainer implements FuseContainer { 20 | private final Optional parent; 21 | private final NUSTitle title; 22 | 23 | public NUSTitleEncryptedFuseContainer(Optional parent, NUSTitle t) { 24 | this.parent = parent; 25 | this.title = t; 26 | } 27 | 28 | @Override 29 | public Optional getParent() { 30 | return parent; 31 | } 32 | 33 | private Optional getContentForPath(String path) { 34 | if (!path.endsWith(".app") || path.length() != 12) { 35 | return Optional.empty(); 36 | } 37 | 38 | try { 39 | int contentID = Integer.parseInt(path.substring(0, 8), 16); 40 | Content c = title.getTMD().getContentByID(contentID); 41 | if (c != null) { 42 | return Optional.of(c); 43 | } 44 | } catch (NumberFormatException e) { 45 | } 46 | return Optional.empty(); 47 | } 48 | 49 | @SuppressWarnings("unused") 50 | private Optional getH3ForPath(String path) { 51 | if (!path.endsWith(".h3") || path.length() != 11) { 52 | return Optional.empty(); 53 | } 54 | return getContentForPath(path.substring(0, 8) + ".app").flatMap(c -> { 55 | if (c.isHashed()) { 56 | try { 57 | Optional hash = title.getDataProcessor().getDataProvider().getContentH3Hash(c); 58 | return hash; 59 | } catch (IOException e) { 60 | } 61 | } 62 | return Optional.empty(); 63 | }); 64 | } 65 | 66 | private Optional getTMDforPath(String path) { 67 | return getFileforPath(path, "title.tmd", () -> { 68 | try { 69 | return title.getDataProcessor().getDataProvider().getRawTMD(); 70 | } catch (IOException e) { 71 | return Optional.empty(); 72 | } 73 | }); 74 | } 75 | 76 | private Optional getTicketforPath(String path) { 77 | return getFileforPath(path, "title.tik", () -> { 78 | try { 79 | return title.getDataProcessor().getDataProvider().getRawTicket(); 80 | } catch (IOException e) { 81 | return Optional.empty(); 82 | } 83 | }); 84 | } 85 | 86 | private Optional getCertforPath(String path) { 87 | return getFileforPath(path, "title.cert", () -> { 88 | try { 89 | return title.getDataProcessor().getDataProvider().getRawCert(); 90 | } catch (IOException e) { 91 | return Optional.empty(); 92 | } 93 | }); 94 | } 95 | 96 | private Optional getFileforPath(String path, String expected, Supplier> func) { 97 | if (!path.equals(expected)) { 98 | return Optional.empty(); 99 | } 100 | 101 | return func.get(); 102 | } 103 | 104 | @Override 105 | public int open(String path, FuseFileInfo fi) { 106 | if (path.equals("/")) { 107 | return -ErrorCodes.EISDIR(); 108 | } 109 | return getattr(path, null); 110 | } 111 | 112 | @Override 113 | public int getattr(String path, FileStat stat) { 114 | if (path.equals("/")) { 115 | stat.st_mode.set(FileStat.S_IFDIR | 0755); 116 | stat.st_nlink.set(2); 117 | return 0; 118 | } 119 | 120 | path = path.substring(1); 121 | 122 | Optional coOptional = getContentForPath(path); 123 | if (coOptional.isPresent()) { 124 | if (stat != null) { 125 | stat.st_mode.set(FileStat.S_IFREG | FileStat.ALL_READ); 126 | stat.st_nlink.set(1); 127 | stat.st_size.set(coOptional.get().getEncryptedFileSize()); 128 | } 129 | return 0; 130 | } else { 131 | Optional h3Data = getH3ForPath(path); 132 | if (h3Data.isPresent()) { 133 | if (stat != null) { 134 | stat.st_mode.set(FileStat.S_IFREG | FileStat.ALL_READ); 135 | stat.st_nlink.set(1); 136 | stat.st_size.set(h3Data.get().length); 137 | } 138 | return 0; 139 | } 140 | } 141 | 142 | List>> functions = new ArrayList<>(); 143 | 144 | String pathcopy = path; 145 | 146 | functions.add(() -> getTMDforPath(pathcopy)); 147 | functions.add(() -> getTicketforPath(pathcopy)); 148 | functions.add(() -> getCertforPath(pathcopy)); 149 | 150 | for (Supplier> func : functions) { 151 | Optional data = func.get(); 152 | if (data.isPresent()) { 153 | if (stat != null) { 154 | stat.st_mode.set(FileStat.S_IFREG | FileStat.ALL_READ); 155 | stat.st_nlink.set(1); 156 | stat.st_size.set(data.get().length); 157 | } 158 | return 0; 159 | } 160 | } 161 | 162 | return -ErrorCodes.ENOENT(); 163 | } 164 | 165 | @Override 166 | public int readdir(String path, Pointer buf, FuseFillDir filter, long offset, FuseFileInfo fi) { 167 | filter.apply(buf, ".", null, 0); 168 | if (getParent().isPresent()) { 169 | filter.apply(buf, "..", null, 0); 170 | } 171 | 172 | for (Content e : title.getTMD().getAllContents().values()) { 173 | filter.apply(buf, e.getFilename(), null, 0); 174 | if (e.isHashed()) { 175 | filter.apply(buf, String.format("%08X.h3", e.getID()), null, 0); 176 | } 177 | } 178 | 179 | if (getTMDforPath("title.tmd").isPresent()) { 180 | filter.apply(buf, "title.tmd", null, 0); 181 | } 182 | 183 | if (getTicketforPath("title.tik").isPresent()) { 184 | filter.apply(buf, "title.tik", null, 0); 185 | } 186 | 187 | if (getCertforPath("title.cert").isPresent()) { 188 | filter.apply(buf, "title.cert", null, 0); 189 | } 190 | 191 | return 0; 192 | } 193 | 194 | @Override 195 | public int read(String path, Pointer buf, long size, long offset, FuseFileInfo fi) { 196 | if (path.equals("/")) { 197 | return -ErrorCodes.EISDIR(); 198 | } 199 | 200 | if(size > Integer.MAX_VALUE) { 201 | System.err.println("Request read size was too big."); 202 | return -ErrorCodes.EIO(); 203 | } 204 | 205 | path = path.substring(1); 206 | 207 | Optional coOptional = getContentForPath(path); 208 | if (coOptional.isPresent()) { 209 | Content c = coOptional.get(); 210 | if (offset >= c.getEncryptedFileSize()) { 211 | return -ErrorCodes.EIO(); 212 | } 213 | if (offset + size > c.getEncryptedFileSize()) { 214 | size = c.getEncryptedFileSize() - offset; 215 | } 216 | 217 | byte[] data; 218 | try { 219 | data = title.getDataProcessor().readContent(c, offset, (int) size); 220 | buf.put(0, data, 0, data.length); 221 | return data.length; 222 | } catch (Exception e) { 223 | e.printStackTrace(); 224 | return -ErrorCodes.ENOENT(); 225 | } 226 | } else { 227 | Optional h3Data = getH3ForPath(path); 228 | if (h3Data.isPresent()) { 229 | byte[] hash = h3Data.get(); 230 | 231 | if (offset >= hash.length) { 232 | return -ErrorCodes.EIO(); 233 | } 234 | if (offset + size > hash.length) { 235 | size = hash.length - offset; 236 | } 237 | 238 | buf.put(0, hash, (int) offset, (int) size); 239 | return (int) size; 240 | } 241 | } 242 | 243 | // Check if the tmd ticket or cert are request. 244 | List>> functions = new ArrayList<>(); 245 | String pathcopy = path; 246 | functions.add(() -> getTMDforPath(pathcopy)); 247 | functions.add(() -> getTicketforPath(pathcopy)); 248 | functions.add(() -> getCertforPath(pathcopy)); 249 | for (Supplier> func : functions) { 250 | Optional dataOpt = func.get(); 251 | if (dataOpt.isPresent()) { 252 | byte[] data = dataOpt.get(); 253 | if (data == null || data.length == 0) { 254 | return -ErrorCodes.ENOENT(); 255 | } 256 | if (offset >= data.length) { 257 | return -ErrorCodes.ENOENT(); 258 | } 259 | if (offset + size > data.length) { 260 | size = data.length - offset; 261 | } 262 | buf.put(0, data, (int) offset, (int) size); 263 | return (int) size; 264 | } 265 | } 266 | 267 | return 0; 268 | } 269 | 270 | @Override 271 | public void init() { 272 | } 273 | 274 | @Override 275 | public void deinit() { 276 | } 277 | 278 | } 279 | -------------------------------------------------------------------------------- /src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/RemoteLocalBackupNUSTitleContainer.java: -------------------------------------------------------------------------------- 1 | package de.mas.wiiu.jnus.fuse_wiiu.implementation; 2 | 3 | import de.mas.wiiu.jnus.NUSTitle; 4 | import de.mas.wiiu.jnus.NUSTitleLoaderRemoteLocal; 5 | import de.mas.wiiu.jnus.entities.Ticket; 6 | import de.mas.wiiu.jnus.fuse_wiiu.Settings; 7 | import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FuseDirectory; 8 | import de.mas.wiiu.jnus.fuse_wiiu.utils.TicketUtils; 9 | import de.mas.wiiu.jnus.implementations.FSTDataProviderNUSTitle; 10 | import de.mas.wiiu.jnus.utils.Utils; 11 | 12 | import java.io.File; 13 | import java.io.IOException; 14 | import java.util.Optional; 15 | 16 | public class RemoteLocalBackupNUSTitleContainer extends GroupFuseContainer { 17 | 18 | private File folder; 19 | 20 | public RemoteLocalBackupNUSTitleContainer(Optional parent, File folder) { 21 | super(parent); 22 | this.folder = folder; 23 | } 24 | 25 | @Override 26 | protected void doInit() { 27 | File[] wud = folder.listFiles(f -> f.getName().startsWith("tmd.")); 28 | for (File versionF : wud) { 29 | short version = Short.parseShort(versionF.getName().substring(4)); 30 | this.addFuseContainer(String.format("v%d", version), new FSTDataProviderContainer(Optional.of(this), () -> { 31 | long titleID = Utils.StringToLong(folder.getName()); 32 | NUSTitle t = null; 33 | Optional ticketOpt = TicketUtils.getTicket(folder, Settings.titlekeyPath, titleID, Settings.retailCommonKey); 34 | System.out.println(ticketOpt); 35 | if (!ticketOpt.isPresent()) { 36 | 37 | return null; 38 | } 39 | Ticket ticket = ticketOpt.get(); 40 | try { 41 | t = NUSTitleLoaderRemoteLocal.loadNUSTitle(folder.getAbsolutePath(), version, ticket); 42 | } catch (Exception e) { 43 | // Try dev ticket 44 | ticket = Ticket.createTicket(ticket.getEncryptedKey(), titleID, Settings.devCommonKey); 45 | try { 46 | t = NUSTitleLoaderRemoteLocal.loadNUSTitle(folder.getAbsolutePath(), version, ticket); 47 | } catch (Exception e1) { 48 | e.printStackTrace(); 49 | e1.printStackTrace(); 50 | } 51 | } 52 | try { 53 | return new FSTDataProviderNUSTitle(t); 54 | } catch (IOException e) { 55 | e.printStackTrace(); 56 | return null; 57 | } 58 | })); 59 | } 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/WUDToWUDContainer.java: -------------------------------------------------------------------------------- 1 | package de.mas.wiiu.jnus.fuse_wiiu.implementation; 2 | 3 | import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FuseContainer; 4 | import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FuseDirectory; 5 | import de.mas.wiiu.jnus.fuse_wiiu.utils.WUDUtils; 6 | import de.mas.wiiu.jnus.implementations.wud.WUDImage; 7 | import de.mas.wiiu.jnus.implementations.wud.WiiUDisc; 8 | import jnr.ffi.Pointer; 9 | import ru.serce.jnrfuse.ErrorCodes; 10 | import ru.serce.jnrfuse.FuseFillDir; 11 | import ru.serce.jnrfuse.struct.FileStat; 12 | import ru.serce.jnrfuse.struct.FuseFileInfo; 13 | 14 | import java.io.File; 15 | import java.io.IOException; 16 | import java.util.Optional; 17 | 18 | public class WUDToWUDContainer implements FuseContainer { 19 | private final String filename; 20 | private final Optional wudInfo; 21 | private final Optional parent; 22 | 23 | public WUDToWUDContainer(Optional parent, File c) { 24 | this.wudInfo = WUDUtils.loadWUDInfo(c); 25 | this.parent = parent; 26 | this.filename = c.getName().replace("_part1.", ".").replace(".wux", ".wud"); 27 | } 28 | 29 | @Override 30 | public Optional getParent() { 31 | return parent; 32 | } 33 | 34 | @Override 35 | public int getattr(String path, FileStat stat) { 36 | if (path.equals("/")) { 37 | stat.st_mode.set(FileStat.S_IFDIR | 0755); 38 | stat.st_nlink.set(2); 39 | return 0; 40 | } 41 | 42 | if (path.equals("/" + filename)) { 43 | if (stat != null) { 44 | stat.st_mode.set(FileStat.S_IFREG | FileStat.ALL_READ); 45 | stat.st_nlink.set(1); 46 | stat.st_size.set(WUDImage.WUD_FILESIZE); 47 | } 48 | return 0; 49 | } 50 | 51 | return -ErrorCodes.ENOENT(); 52 | } 53 | 54 | @Override 55 | public int open(String path, FuseFileInfo fi) { 56 | if (path.equals("/")) { 57 | return -ErrorCodes.EISDIR(); 58 | } 59 | return getattr(path, null); 60 | } 61 | 62 | @Override 63 | public int readdir(String path, Pointer buf, FuseFillDir filter, long offset, FuseFileInfo fi) { 64 | filter.apply(buf, ".", null, 0); 65 | if (getParent().isPresent()) { 66 | filter.apply(buf, "..", null, 0); 67 | } 68 | 69 | if (wudInfo.isPresent()) { 70 | filter.apply(buf, filename, null, 0); 71 | } 72 | return 0; 73 | } 74 | 75 | @Override 76 | public int read(String path, Pointer buf, long size, long offset, FuseFileInfo fi) { 77 | if (path.equals("/")) { 78 | return -ErrorCodes.EISDIR(); 79 | } 80 | 81 | if (!path.equals("/" + filename)) { 82 | return -ErrorCodes.ENOENT(); 83 | } 84 | 85 | if (offset >= WUDImage.WUD_FILESIZE) { 86 | return -ErrorCodes.ENOENT(); 87 | } 88 | if (offset + size > WUDImage.WUD_FILESIZE) { 89 | size = WUDImage.WUD_FILESIZE - offset; 90 | } 91 | 92 | try { 93 | byte[] data; 94 | data = wudInfo.get().getReader().get().readEncryptedToByteArray(offset, 0, size); 95 | buf.put(0, data, 0, data.length); 96 | return data.length; 97 | } catch (IOException e) { 98 | e.printStackTrace(); 99 | return -ErrorCodes.ENOENT(); 100 | } 101 | } 102 | 103 | @Override 104 | public void init() { 105 | // Not used 106 | } 107 | 108 | @Override 109 | public void deinit() { 110 | // Not used 111 | } 112 | 113 | } 114 | -------------------------------------------------------------------------------- /src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/WoomyNUSTitleContainer.java: -------------------------------------------------------------------------------- 1 | package de.mas.wiiu.jnus.fuse_wiiu.implementation; 2 | 3 | import de.mas.wiiu.jnus.NUSTitleLoaderWoomy; 4 | import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FuseDirectory; 5 | import de.mas.wiiu.jnus.implementations.FSTDataProviderNUSTitle; 6 | 7 | import java.io.File; 8 | import java.util.Optional; 9 | 10 | public class WoomyNUSTitleContainer extends GroupFuseContainer { 11 | private final File file; 12 | 13 | public WoomyNUSTitleContainer(Optional parent, File file) { 14 | super(parent); 15 | this.file = file; 16 | } 17 | 18 | @Override 19 | protected void doInit() { 20 | this.addFuseContainer(file.getName(), new FSTDataProviderContainer(Optional.of(this), () -> { 21 | try { 22 | return new FSTDataProviderNUSTitle(NUSTitleLoaderWoomy.loadNUSTitle(file.getAbsolutePath())); 23 | } catch (Exception e1) { 24 | e1.printStackTrace(); 25 | return null; 26 | } 27 | })); 28 | 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/loader/WUDFSTDataProviderLoader.java: -------------------------------------------------------------------------------- 1 | package de.mas.wiiu.jnus.fuse_wiiu.implementation.loader; 2 | 3 | import de.mas.wiiu.jnus.WUDLoader; 4 | import de.mas.wiiu.jnus.fuse_wiiu.Settings; 5 | import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FSTDataProviderLoader; 6 | import de.mas.wiiu.jnus.fuse_wiiu.utils.WUDUtils; 7 | import de.mas.wiiu.jnus.implementations.wud.WiiUDisc; 8 | import de.mas.wiiu.jnus.interfaces.FSTDataProvider; 9 | import lombok.Getter; 10 | 11 | import java.io.File; 12 | import java.io.IOException; 13 | import java.text.ParseException; 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | import java.util.Optional; 17 | 18 | public class WUDFSTDataProviderLoader implements FSTDataProviderLoader { 19 | @Getter 20 | private static final WUDFSTDataProviderLoader instance = new WUDFSTDataProviderLoader(); 21 | 22 | private WUDFSTDataProviderLoader() { 23 | } 24 | 25 | @Override 26 | public List getDataProvider(WiiUDisc info) { 27 | List dps = new ArrayList<>(); 28 | try { 29 | dps = WUDLoader.getPartitonsAsFSTDataProvider(info, Settings.retailCommonKey); 30 | } catch (Exception e) { 31 | try { 32 | dps = WUDLoader.getPartitonsAsFSTDataProvider(info, Settings.devCommonKey); 33 | } catch (IOException | ParseException e1) { 34 | return dps; 35 | } 36 | } 37 | return dps; 38 | } 39 | 40 | @Override 41 | public Optional loadInfo(File input) { 42 | return WUDUtils.loadWUDInfo(input); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/de/mas/wiiu/jnus/fuse_wiiu/implementation/loader/WumadFSTDataProviderLoader.java: -------------------------------------------------------------------------------- 1 | package de.mas.wiiu.jnus.fuse_wiiu.implementation.loader; 2 | 3 | import de.mas.wiiu.jnus.WumadLoader; 4 | import de.mas.wiiu.jnus.fuse_wiiu.Settings; 5 | import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FSTDataProviderLoader; 6 | import de.mas.wiiu.jnus.implementations.wud.wumad.WumadInfo; 7 | import de.mas.wiiu.jnus.interfaces.FSTDataProvider; 8 | import lombok.Getter; 9 | 10 | import java.io.File; 11 | import java.io.IOException; 12 | import java.text.ParseException; 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | import java.util.Optional; 16 | 17 | public class WumadFSTDataProviderLoader implements FSTDataProviderLoader { 18 | @Getter 19 | private static final WumadFSTDataProviderLoader instance = new WumadFSTDataProviderLoader(); 20 | 21 | private WumadFSTDataProviderLoader() { 22 | } 23 | 24 | @Override 25 | public Optional loadInfo(File input) { 26 | if (input != null && input.exists()) { 27 | try { 28 | return Optional.of(WumadLoader.load(input)); 29 | } catch (Exception e) { 30 | e.printStackTrace(); 31 | } 32 | } 33 | return Optional.empty(); 34 | } 35 | 36 | @Override 37 | public List getDataProvider(WumadInfo info) { 38 | List dps = new ArrayList<>(); 39 | try { 40 | dps = WumadLoader.getPartitonsAsFSTDataProvider(info, Settings.retailCommonKey); 41 | } catch (Exception e) { 42 | try { 43 | dps = WumadLoader.getPartitonsAsFSTDataProvider(info, Settings.devCommonKey); 44 | } catch (IOException | ParseException e1) { 45 | return dps; 46 | } 47 | } 48 | return dps; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/de/mas/wiiu/jnus/fuse_wiiu/interfaces/FSTDataProviderLoader.java: -------------------------------------------------------------------------------- 1 | package de.mas.wiiu.jnus.fuse_wiiu.interfaces; 2 | 3 | import de.mas.wiiu.jnus.interfaces.FSTDataProvider; 4 | 5 | import java.io.File; 6 | import java.util.List; 7 | import java.util.Optional; 8 | 9 | public interface FSTDataProviderLoader { 10 | Optional loadInfo(File input); 11 | 12 | List getDataProvider(T info); 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/de/mas/wiiu/jnus/fuse_wiiu/interfaces/FuseContainer.java: -------------------------------------------------------------------------------- 1 | package de.mas.wiiu.jnus.fuse_wiiu.interfaces; 2 | 3 | import jnr.ffi.Pointer; 4 | import jnr.ffi.types.off_t; 5 | import jnr.ffi.types.size_t; 6 | import ru.serce.jnrfuse.FuseFillDir; 7 | import ru.serce.jnrfuse.struct.FileStat; 8 | import ru.serce.jnrfuse.struct.FuseFileInfo; 9 | 10 | /** 11 | * Simplified version of the FuseFS interface. 12 | * 13 | * @author Maschell 14 | */ 15 | public interface FuseContainer extends FuseDirectory { 16 | /** 17 | * Wrapper for the getattr function of the FuseFS interface. 18 | * When this function is called, the path will be relative to this FuseContainer 19 | *

20 | * Get file attributes. 21 | *

22 | * Similar to stat(). The 'st_dev' and 'st_blksize' fields are 23 | * ignored. The 'st_ino' field is ignored except if the 'use_ino' 24 | * mount option is given. 25 | */ 26 | int getattr(String path, FileStat stat); 27 | 28 | /** 29 | * Wrapper for the getattr function of the FuseFS interface. 30 | * When this function is called, the path will be relative to this FuseContainer 31 | *

32 | * File open operation 33 | *

34 | * No creation (O_CREAT, O_EXCL) and by default also no 35 | * truncation (O_TRUNC) flags will be passed to open(). If an 36 | * application specifies O_TRUNC, fuse first calls truncate() 37 | * and then open(). Only if 'atomic_o_trunc' has been 38 | * specified and kernel version is 2.6.24 or later, O_TRUNC is 39 | * passed on to open. 40 | *

41 | * Unless the 'default_permissions' mount option is given, 42 | * open should check if the operation is permitted for the 43 | * given flags. Optionally open may also return an arbitrary 44 | * filehandle in the fuse_file_info structure, which will be 45 | * passed to all file operations. 46 | * 47 | * @see jnr.constants.platform.OpenFlags 48 | */ 49 | int open(String path, FuseFileInfo fi); 50 | 51 | /** 52 | * Wrapper for the readdir function of the FuseFS interface. 53 | * When this function is called, the path will be relative to this FuseContainer 54 | *

55 | * Read directory 56 | *

57 | * This supersedes the old getdir() interface. New applications 58 | * should use this. 59 | *

60 | * The filesystem may choose between two modes of operation: 61 | *

62 | * 1) The readdir implementation ignores the offset parameter, and 63 | * passes zero to the filler function's offset. The filler 64 | * function will not return '1' (unless an error happens), so the 65 | * whole directory is read in a single readdir operation. This 66 | * works just like the old getdir() method. 67 | *

68 | * 2) The readdir implementation keeps track of the offsets of the 69 | * directory entries. It uses the offset parameter and always 70 | * passes non-zero offset to the filler function. When the buffer 71 | * is full (or an error happens) the filler function will return 72 | * '1'. 73 | */ 74 | int readdir(String path, Pointer buf, FuseFillDir filter, @off_t long offset, FuseFileInfo fi); 75 | 76 | /** 77 | * Wrapper for the getattr function of the FuseFS interface. 78 | * When this function is called, the path will be relative to this FuseContainer 79 | *

80 | * Read data from an open file 81 | *

82 | * Read should return exactly the number of bytes requested except 83 | * on EOF or error, otherwise the rest of the data will be 84 | * substituted with zeroes. An exception to this is when the 85 | * 'direct_io' mount option is specified, in which case the return 86 | * value of the read system call will reflect the return value of 87 | * this operation. 88 | */ 89 | int read(String path, Pointer buf, @size_t long size, @off_t long offset, FuseFileInfo fi); 90 | 91 | /** 92 | * This function will be called when ever the FuseContainer needs to update it's children. 93 | */ 94 | void init(); 95 | 96 | /** 97 | * This function will be called right before this FuseContainer won't be used anymore. 98 | */ 99 | void deinit(); 100 | 101 | 102 | } 103 | -------------------------------------------------------------------------------- /src/main/java/de/mas/wiiu/jnus/fuse_wiiu/interfaces/FuseDirectory.java: -------------------------------------------------------------------------------- 1 | package de.mas.wiiu.jnus.fuse_wiiu.interfaces; 2 | 3 | import java.util.Optional; 4 | 5 | /** 6 | * Representation of a directory. 7 | * 8 | * @author Maschell 9 | */ 10 | public interface FuseDirectory { 11 | 12 | /** 13 | * Returns the parent of this FuseDirectory. 14 | * 15 | * @return parent 16 | */ 17 | Optional getParent(); 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/de/mas/wiiu/jnus/fuse_wiiu/utils/FuseContainerWrapper.java: -------------------------------------------------------------------------------- 1 | package de.mas.wiiu.jnus.fuse_wiiu.utils; 2 | 3 | import de.mas.wiiu.jnus.fuse_wiiu.implementation.*; 4 | import de.mas.wiiu.jnus.fuse_wiiu.implementation.loader.WUDFSTDataProviderLoader; 5 | import de.mas.wiiu.jnus.fuse_wiiu.implementation.loader.WumadFSTDataProviderLoader; 6 | import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FuseContainer; 7 | import de.mas.wiiu.jnus.fuse_wiiu.interfaces.FuseDirectory; 8 | import de.mas.wiiu.jnus.implementations.wud.reader.WUDDiscReaderSplitted; 9 | import de.mas.wiiu.jnus.utils.Utils; 10 | 11 | import java.io.File; 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | import java.util.Optional; 15 | 16 | public class FuseContainerWrapper { 17 | 18 | private final static String prefix = "[EMULATED] "; 19 | 20 | public static Map createFuseContainer(Optional parent, File c) { 21 | System.out.println("Mounting " + c.getAbsolutePath()); 22 | 23 | Map result = new HashMap<>(); 24 | if (c.exists() && c.isDirectory()) { 25 | File[] tmd = c.listFiles(f -> f.isFile() && f.getName().startsWith("tmd")); 26 | File[] appFiles = c.listFiles(f -> f.isFile() && f.getName().startsWith("000") && f.getName().length() == 8); 27 | if (tmd != null && tmd.length > 0 && appFiles != null && appFiles.length > 0) { 28 | result.put(prefix + c.getName(), new RemoteLocalBackupNUSTitleContainer(parent, c)); 29 | return result; 30 | } 31 | } 32 | 33 | 34 | if (c.exists() && c.isDirectory()) { 35 | File[] tmd = c.listFiles(f -> f.isFile() && (f.getName().startsWith("tmd.") || f.getName().startsWith("title.tmd"))); 36 | if (tmd != null && tmd.length > 0) { 37 | // In case there is a tmd file 38 | 39 | // Checks if we have the local backup format 40 | File[] versions = c.listFiles(f -> f.getName().startsWith("tmd.")); 41 | if (versions != null && versions.length > 0 && c.getName().length() == 16 && Utils.StringToLong(c.getName()) > 0) { 42 | result.put(prefix + c.getName(), new LocalBackupNUSTitleContainer(parent, c)); 43 | return result; 44 | } 45 | 46 | // if not return normal title container. 47 | result.put(prefix + c.getName(), new LocalNUSTitleContainer(parent, c)); 48 | return result; 49 | } 50 | } 51 | 52 | if (c.exists() && c.getName().endsWith(".woomy")) { 53 | result.put(prefix + c.getName(), new WoomyNUSTitleContainer(parent, c)); 54 | return result; 55 | } 56 | 57 | if (c.exists() && c.getName().endsWith(".wumad")) { 58 | result.put(prefix + c.getName(), new MultipleFSTDataProviderFuseContainer<>(parent, c, WumadFSTDataProviderLoader.getInstance())); 59 | result.put(prefix + "[EXTRA] " + c.getName(), new MultipleFSTDataProviderRecursiveFuseContainer<>(parent, c, WumadFSTDataProviderLoader.getInstance())); 60 | 61 | return result; 62 | } 63 | 64 | if (checkWUD(result, parent, c)) { 65 | return result; 66 | } 67 | 68 | if (c.isDirectory()) { 69 | result.put(c.getName(), new FSFuseContainer(parent, c)); 70 | return result; 71 | 72 | } 73 | return result; 74 | } 75 | 76 | private static boolean checkWUD(Map result, Optional parent, File c) { 77 | if (c.exists() && c.isFile() && (c.getName().endsWith(".wux") || c.getName().endsWith(".wud") || c.getName().endsWith(".ddi") || c.getName().endsWith(".wumada"))) { 78 | if (c.length() == WUDDiscReaderSplitted.WUD_SPLITTED_FILE_SIZE && !c.getName().endsWith("part1.wud")) { 79 | return false; 80 | } 81 | 82 | result.put(prefix + c.getName(), new MultipleFSTDataProviderFuseContainer<>(parent, c, WUDFSTDataProviderLoader.getInstance())); 83 | result.put(prefix + "[EXTRA] " + c.getName(), new MultipleFSTDataProviderRecursiveFuseContainer<>(parent, c, WUDFSTDataProviderLoader.getInstance())); 84 | if (c.getName().endsWith("part1.wud") || c.getName().endsWith(".wux")) { 85 | result.put(prefix + "[WUD] " + c.getName(), new WUDToWUDContainer(parent, c)); 86 | } 87 | return true; 88 | 89 | } 90 | return false; 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/de/mas/wiiu/jnus/fuse_wiiu/utils/TicketUtils.java: -------------------------------------------------------------------------------- 1 | package de.mas.wiiu.jnus.fuse_wiiu.utils; 2 | 3 | import de.mas.wiiu.jnus.entities.Ticket; 4 | import de.mas.wiiu.jnus.utils.FileUtils; 5 | 6 | import java.io.File; 7 | import java.io.IOException; 8 | import java.nio.file.Files; 9 | import java.util.Optional; 10 | 11 | public class TicketUtils { 12 | public static Optional getTicket(File folder, File keyFolder, long titleID, byte[] commonKey) { 13 | File ticketFile = null; 14 | if (folder != null) { 15 | ticketFile = FileUtils.getFileIgnoringFilenameCases(folder.getAbsolutePath(), "title.tik"); 16 | } 17 | if (ticketFile == null) { 18 | ticketFile = FileUtils.getFileIgnoringFilenameCases(folder.getAbsolutePath(), "cetk"); 19 | } 20 | Ticket ticket = null; 21 | if (ticketFile != null && ticketFile.exists()) { 22 | try { 23 | ticket = Ticket.parseTicket(ticketFile, commonKey); 24 | } catch (IOException e) { 25 | } 26 | } 27 | 28 | if (ticket == null && keyFolder != null) { 29 | File keyFile = FileUtils.getFileIgnoringFilenameCases(keyFolder.getAbsolutePath(), String.format("%016X", titleID) + ".key"); 30 | if (keyFile != null && keyFile.exists()) { 31 | byte[] key; 32 | try { 33 | key = Files.readAllBytes(keyFile.toPath()); 34 | if (key != null && key.length == 16) { 35 | ticket = Ticket.createTicket(key, titleID, commonKey); 36 | } 37 | } catch (IOException e) { 38 | } 39 | } 40 | } 41 | if (ticket != null) { 42 | return Optional.of(ticket); 43 | } 44 | return Optional.empty(); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/de/mas/wiiu/jnus/fuse_wiiu/utils/WUDUtils.java: -------------------------------------------------------------------------------- 1 | package de.mas.wiiu.jnus.fuse_wiiu.utils; 2 | 3 | import de.mas.wiiu.jnus.WUDLoader; 4 | import de.mas.wiiu.jnus.fuse_wiiu.Settings; 5 | import de.mas.wiiu.jnus.implementations.wud.WiiUDisc; 6 | import org.apache.commons.io.FilenameUtils; 7 | 8 | import java.io.File; 9 | import java.io.PrintWriter; 10 | import java.io.StringWriter; 11 | import java.util.Optional; 12 | 13 | public class WUDUtils { 14 | public static Optional loadWUDInfo(File file) { 15 | String FSfilename = file.getName(); 16 | String basename = FilenameUtils.getBaseName(FSfilename); 17 | File keyFile = new File(file.getParent() + File.separator + basename + ".key"); 18 | 19 | if (!keyFile.exists() && Settings.disckeyPath != null) { 20 | System.out.println(".key not found at " + keyFile.getAbsolutePath()); 21 | keyFile = new File(Settings.disckeyPath.getAbsoluteFile() + File.separator + basename + ".key"); 22 | if (!keyFile.exists()) { 23 | System.out.println(".key not found at " + keyFile.getAbsolutePath()); 24 | } 25 | } 26 | 27 | try { 28 | if (keyFile.exists()) { 29 | return Optional.of(WUDLoader.load(file.getAbsolutePath(), keyFile)); 30 | } else { 31 | System.out.println("No .key was not found. Trying dev mode."); 32 | return Optional.of(WUDLoader.loadDev(file.getAbsolutePath())); 33 | } 34 | } catch (Exception e) { 35 | e.printStackTrace(); 36 | StringWriter errors = new StringWriter(); 37 | e.printStackTrace(new PrintWriter(errors)); 38 | System.err.println(errors); 39 | } 40 | 41 | return Optional.empty(); 42 | } 43 | } 44 | --------------------------------------------------------------------------------