├── .gitignore ├── LICENSE ├── README.md ├── ToDo.txt ├── about-wordmark.svg ├── findUndefSyms.sh ├── make.sh ├── patch.txt ├── policies.json ├── rebrand.sh ├── shim.c ├── shimAppKit.m ├── shimCoreGraphics.c ├── shimCoreText.c ├── shimFoundation.m ├── shimObjc.c ├── shimSecurity.c ├── shimVT.c ├── trampoline.c └── unsign ├── Makefile ├── README.md ├── endian.c ├── endian.h └── unsign.c /.gitignore: -------------------------------------------------------------------------------- 1 | *.app 2 | *.zip 3 | *.webloc 4 | inject_lib 5 | findUndefSyms_nonSDK.sh 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 2.1, February 1999 3 | 4 | Copyright (C) 1991, 1999 Free Software Foundation, Inc. 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | [This is the first released version of the Lesser GPL. It also counts 10 | as the successor of the GNU Library Public License, version 2, hence 11 | the version number 2.1.] 12 | 13 | Preamble 14 | 15 | The licenses for most software are designed to take away your 16 | freedom to share and change it. By contrast, the GNU General Public 17 | Licenses are intended to guarantee your freedom to share and change 18 | free software--to make sure the software is free for all its users. 19 | 20 | This license, the Lesser General Public License, applies to some 21 | specially designated software packages--typically libraries--of the 22 | Free Software Foundation and other authors who decide to use it. You 23 | can use it too, but we suggest you first think carefully about whether 24 | this license or the ordinary General Public License is the better 25 | strategy to use in any particular case, based on the explanations below. 26 | 27 | When we speak of free software, we are referring to freedom of use, 28 | not price. Our General Public Licenses are designed to make sure that 29 | you have the freedom to distribute copies of free software (and charge 30 | for this service if you wish); that you receive source code or can get 31 | it if you want it; that you can change the software and use pieces of 32 | it in new free programs; and that you are informed that you can do 33 | these things. 34 | 35 | To protect your rights, we need to make restrictions that forbid 36 | distributors to deny you these rights or to ask you to surrender these 37 | rights. These restrictions translate to certain responsibilities for 38 | you if you distribute copies of the library or if you modify it. 39 | 40 | For example, if you distribute copies of the library, whether gratis 41 | or for a fee, you must give the recipients all the rights that we gave 42 | you. You must make sure that they, too, receive or can get the source 43 | code. If you link other code with the library, you must provide 44 | complete object files to the recipients, so that they can relink them 45 | with the library after making changes to the library and recompiling 46 | it. And you must show them these terms so they know their rights. 47 | 48 | We protect your rights with a two-step method: (1) we copyright the 49 | library, and (2) we offer you this license, which gives you legal 50 | permission to copy, distribute and/or modify the library. 51 | 52 | To protect each distributor, we want to make it very clear that 53 | there is no warranty for the free library. Also, if the library is 54 | modified by someone else and passed on, the recipients should know 55 | that what they have is not the original version, so that the original 56 | author's reputation will not be affected by problems that might be 57 | introduced by others. 58 | 59 | Finally, software patents pose a constant threat to the existence of 60 | any free program. We wish to make sure that a company cannot 61 | effectively restrict the users of a free program by obtaining a 62 | restrictive license from a patent holder. Therefore, we insist that 63 | any patent license obtained for a version of the library must be 64 | consistent with the full freedom of use specified in this license. 65 | 66 | Most GNU software, including some libraries, is covered by the 67 | ordinary GNU General Public License. This license, the GNU Lesser 68 | General Public License, applies to certain designated libraries, and 69 | is quite different from the ordinary General Public License. We use 70 | this license for certain libraries in order to permit linking those 71 | libraries into non-free programs. 72 | 73 | When a program is linked with a library, whether statically or using 74 | a shared library, the combination of the two is legally speaking a 75 | combined work, a derivative of the original library. The ordinary 76 | General Public License therefore permits such linking only if the 77 | entire combination fits its criteria of freedom. The Lesser General 78 | Public License permits more lax criteria for linking other code with 79 | the library. 80 | 81 | We call this license the "Lesser" General Public License because it 82 | does Less to protect the user's freedom than the ordinary General 83 | Public License. It also provides other free software developers Less 84 | of an advantage over competing non-free programs. These disadvantages 85 | are the reason we use the ordinary General Public License for many 86 | libraries. However, the Lesser license provides advantages in certain 87 | special circumstances. 88 | 89 | For example, on rare occasions, there may be a special need to 90 | encourage the widest possible use of a certain library, so that it becomes 91 | a de-facto standard. To achieve this, non-free programs must be 92 | allowed to use the library. A more frequent case is that a free 93 | library does the same job as widely used non-free libraries. In this 94 | case, there is little to gain by limiting the free library to free 95 | software only, so we use the Lesser General Public License. 96 | 97 | In other cases, permission to use a particular library in non-free 98 | programs enables a greater number of people to use a large body of 99 | free software. For example, permission to use the GNU C Library in 100 | non-free programs enables many more people to use the whole GNU 101 | operating system, as well as its variant, the GNU/Linux operating 102 | system. 103 | 104 | Although the Lesser General Public License is Less protective of the 105 | users' freedom, it does ensure that the user of a program that is 106 | linked with the Library has the freedom and the wherewithal to run 107 | that program using a modified version of the Library. 108 | 109 | The precise terms and conditions for copying, distribution and 110 | modification follow. Pay close attention to the difference between a 111 | "work based on the library" and a "work that uses the library". The 112 | former contains code derived from the library, whereas the latter must 113 | be combined with the library in order to run. 114 | 115 | GNU LESSER GENERAL PUBLIC LICENSE 116 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 117 | 118 | 0. This License Agreement applies to any software library or other 119 | program which contains a notice placed by the copyright holder or 120 | other authorized party saying it may be distributed under the terms of 121 | this Lesser General Public License (also called "this License"). 122 | Each licensee is addressed as "you". 123 | 124 | A "library" means a collection of software functions and/or data 125 | prepared so as to be conveniently linked with application programs 126 | (which use some of those functions and data) to form executables. 127 | 128 | The "Library", below, refers to any such software library or work 129 | which has been distributed under these terms. A "work based on the 130 | Library" means either the Library or any derivative work under 131 | copyright law: that is to say, a work containing the Library or a 132 | portion of it, either verbatim or with modifications and/or translated 133 | straightforwardly into another language. (Hereinafter, translation is 134 | included without limitation in the term "modification".) 135 | 136 | "Source code" for a work means the preferred form of the work for 137 | making modifications to it. For a library, complete source code means 138 | all the source code for all modules it contains, plus any associated 139 | interface definition files, plus the scripts used to control compilation 140 | and installation of the library. 141 | 142 | Activities other than copying, distribution and modification are not 143 | covered by this License; they are outside its scope. The act of 144 | running a program using the Library is not restricted, and output from 145 | such a program is covered only if its contents constitute a work based 146 | on the Library (independent of the use of the Library in a tool for 147 | writing it). Whether that is true depends on what the Library does 148 | and what the program that uses the Library does. 149 | 150 | 1. You may copy and distribute verbatim copies of the Library's 151 | complete source code as you receive it, in any medium, provided that 152 | you conspicuously and appropriately publish on each copy an 153 | appropriate copyright notice and disclaimer of warranty; keep intact 154 | all the notices that refer to this License and to the absence of any 155 | warranty; and distribute a copy of this License along with the 156 | Library. 157 | 158 | You may charge a fee for the physical act of transferring a copy, 159 | and you may at your option offer warranty protection in exchange for a 160 | fee. 161 | 162 | 2. You may modify your copy or copies of the Library or any portion 163 | of it, thus forming a work based on the Library, and copy and 164 | distribute such modifications or work under the terms of Section 1 165 | above, provided that you also meet all of these conditions: 166 | 167 | a) The modified work must itself be a software library. 168 | 169 | b) You must cause the files modified to carry prominent notices 170 | stating that you changed the files and the date of any change. 171 | 172 | c) You must cause the whole of the work to be licensed at no 173 | charge to all third parties under the terms of this License. 174 | 175 | d) If a facility in the modified Library refers to a function or a 176 | table of data to be supplied by an application program that uses 177 | the facility, other than as an argument passed when the facility 178 | is invoked, then you must make a good faith effort to ensure that, 179 | in the event an application does not supply such function or 180 | table, the facility still operates, and performs whatever part of 181 | its purpose remains meaningful. 182 | 183 | (For example, a function in a library to compute square roots has 184 | a purpose that is entirely well-defined independent of the 185 | application. Therefore, Subsection 2d requires that any 186 | application-supplied function or table used by this function must 187 | be optional: if the application does not supply it, the square 188 | root function must still compute square roots.) 189 | 190 | These requirements apply to the modified work as a whole. If 191 | identifiable sections of that work are not derived from the Library, 192 | and can be reasonably considered independent and separate works in 193 | themselves, then this License, and its terms, do not apply to those 194 | sections when you distribute them as separate works. But when you 195 | distribute the same sections as part of a whole which is a work based 196 | on the Library, the distribution of the whole must be on the terms of 197 | this License, whose permissions for other licensees extend to the 198 | entire whole, and thus to each and every part regardless of who wrote 199 | it. 200 | 201 | Thus, it is not the intent of this section to claim rights or contest 202 | your rights to work written entirely by you; rather, the intent is to 203 | exercise the right to control the distribution of derivative or 204 | collective works based on the Library. 205 | 206 | In addition, mere aggregation of another work not based on the Library 207 | with the Library (or with a work based on the Library) on a volume of 208 | a storage or distribution medium does not bring the other work under 209 | the scope of this License. 210 | 211 | 3. You may opt to apply the terms of the ordinary GNU General Public 212 | License instead of this License to a given copy of the Library. To do 213 | this, you must alter all the notices that refer to this License, so 214 | that they refer to the ordinary GNU General Public License, version 2, 215 | instead of to this License. (If a newer version than version 2 of the 216 | ordinary GNU General Public License has appeared, then you can specify 217 | that version instead if you wish.) Do not make any other change in 218 | these notices. 219 | 220 | Once this change is made in a given copy, it is irreversible for 221 | that copy, so the ordinary GNU General Public License applies to all 222 | subsequent copies and derivative works made from that copy. 223 | 224 | This option is useful when you wish to copy part of the code of 225 | the Library into a program that is not a library. 226 | 227 | 4. You may copy and distribute the Library (or a portion or 228 | derivative of it, under Section 2) in object code or executable form 229 | under the terms of Sections 1 and 2 above provided that you accompany 230 | it with the complete corresponding machine-readable source code, which 231 | must be distributed under the terms of Sections 1 and 2 above on a 232 | medium customarily used for software interchange. 233 | 234 | If distribution of object code is made by offering access to copy 235 | from a designated place, then offering equivalent access to copy the 236 | source code from the same place satisfies the requirement to 237 | distribute the source code, even though third parties are not 238 | compelled to copy the source along with the object code. 239 | 240 | 5. A program that contains no derivative of any portion of the 241 | Library, but is designed to work with the Library by being compiled or 242 | linked with it, is called a "work that uses the Library". Such a 243 | work, in isolation, is not a derivative work of the Library, and 244 | therefore falls outside the scope of this License. 245 | 246 | However, linking a "work that uses the Library" with the Library 247 | creates an executable that is a derivative of the Library (because it 248 | contains portions of the Library), rather than a "work that uses the 249 | library". The executable is therefore covered by this License. 250 | Section 6 states terms for distribution of such executables. 251 | 252 | When a "work that uses the Library" uses material from a header file 253 | that is part of the Library, the object code for the work may be a 254 | derivative work of the Library even though the source code is not. 255 | Whether this is true is especially significant if the work can be 256 | linked without the Library, or if the work is itself a library. The 257 | threshold for this to be true is not precisely defined by law. 258 | 259 | If such an object file uses only numerical parameters, data 260 | structure layouts and accessors, and small macros and small inline 261 | functions (ten lines or less in length), then the use of the object 262 | file is unrestricted, regardless of whether it is legally a derivative 263 | work. (Executables containing this object code plus portions of the 264 | Library will still fall under Section 6.) 265 | 266 | Otherwise, if the work is a derivative of the Library, you may 267 | distribute the object code for the work under the terms of Section 6. 268 | Any executables containing that work also fall under Section 6, 269 | whether or not they are linked directly with the Library itself. 270 | 271 | 6. As an exception to the Sections above, you may also combine or 272 | link a "work that uses the Library" with the Library to produce a 273 | work containing portions of the Library, and distribute that work 274 | under terms of your choice, provided that the terms permit 275 | modification of the work for the customer's own use and reverse 276 | engineering for debugging such modifications. 277 | 278 | You must give prominent notice with each copy of the work that the 279 | Library is used in it and that the Library and its use are covered by 280 | this License. You must supply a copy of this License. If the work 281 | during execution displays copyright notices, you must include the 282 | copyright notice for the Library among them, as well as a reference 283 | directing the user to the copy of this License. Also, you must do one 284 | of these things: 285 | 286 | a) Accompany the work with the complete corresponding 287 | machine-readable source code for the Library including whatever 288 | changes were used in the work (which must be distributed under 289 | Sections 1 and 2 above); and, if the work is an executable linked 290 | with the Library, with the complete machine-readable "work that 291 | uses the Library", as object code and/or source code, so that the 292 | user can modify the Library and then relink to produce a modified 293 | executable containing the modified Library. (It is understood 294 | that the user who changes the contents of definitions files in the 295 | Library will not necessarily be able to recompile the application 296 | to use the modified definitions.) 297 | 298 | b) Use a suitable shared library mechanism for linking with the 299 | Library. A suitable mechanism is one that (1) uses at run time a 300 | copy of the library already present on the user's computer system, 301 | rather than copying library functions into the executable, and (2) 302 | will operate properly with a modified version of the library, if 303 | the user installs one, as long as the modified version is 304 | interface-compatible with the version that the work was made with. 305 | 306 | c) Accompany the work with a written offer, valid for at 307 | least three years, to give the same user the materials 308 | specified in Subsection 6a, above, for a charge no more 309 | than the cost of performing this distribution. 310 | 311 | d) If distribution of the work is made by offering access to copy 312 | from a designated place, offer equivalent access to copy the above 313 | specified materials from the same place. 314 | 315 | e) Verify that the user has already received a copy of these 316 | materials or that you have already sent this user a copy. 317 | 318 | For an executable, the required form of the "work that uses the 319 | Library" must include any data and utility programs needed for 320 | reproducing the executable from it. However, as a special exception, 321 | the materials to be distributed need not include anything that is 322 | normally distributed (in either source or binary form) with the major 323 | components (compiler, kernel, and so on) of the operating system on 324 | which the executable runs, unless that component itself accompanies 325 | the executable. 326 | 327 | It may happen that this requirement contradicts the license 328 | restrictions of other proprietary libraries that do not normally 329 | accompany the operating system. Such a contradiction means you cannot 330 | use both them and the Library together in an executable that you 331 | distribute. 332 | 333 | 7. You may place library facilities that are a work based on the 334 | Library side-by-side in a single library together with other library 335 | facilities not covered by this License, and distribute such a combined 336 | library, provided that the separate distribution of the work based on 337 | the Library and of the other library facilities is otherwise 338 | permitted, and provided that you do these two things: 339 | 340 | a) Accompany the combined library with a copy of the same work 341 | based on the Library, uncombined with any other library 342 | facilities. This must be distributed under the terms of the 343 | Sections above. 344 | 345 | b) Give prominent notice with the combined library of the fact 346 | that part of it is a work based on the Library, and explaining 347 | where to find the accompanying uncombined form of the same work. 348 | 349 | 8. You may not copy, modify, sublicense, link with, or distribute 350 | the Library except as expressly provided under this License. Any 351 | attempt otherwise to copy, modify, sublicense, link with, or 352 | distribute the Library is void, and will automatically terminate your 353 | rights under this License. However, parties who have received copies, 354 | or rights, from you under this License will not have their licenses 355 | terminated so long as such parties remain in full compliance. 356 | 357 | 9. You are not required to accept this License, since you have not 358 | signed it. However, nothing else grants you permission to modify or 359 | distribute the Library or its derivative works. These actions are 360 | prohibited by law if you do not accept this License. Therefore, by 361 | modifying or distributing the Library (or any work based on the 362 | Library), you indicate your acceptance of this License to do so, and 363 | all its terms and conditions for copying, distributing or modifying 364 | the Library or works based on it. 365 | 366 | 10. Each time you redistribute the Library (or any work based on the 367 | Library), the recipient automatically receives a license from the 368 | original licensor to copy, distribute, link with or modify the Library 369 | subject to these terms and conditions. You may not impose any further 370 | restrictions on the recipients' exercise of the rights granted herein. 371 | You are not responsible for enforcing compliance by third parties with 372 | this License. 373 | 374 | 11. If, as a consequence of a court judgment or allegation of patent 375 | infringement or for any other reason (not limited to patent issues), 376 | conditions are imposed on you (whether by court order, agreement or 377 | otherwise) that contradict the conditions of this License, they do not 378 | excuse you from the conditions of this License. If you cannot 379 | distribute so as to satisfy simultaneously your obligations under this 380 | License and any other pertinent obligations, then as a consequence you 381 | may not distribute the Library at all. For example, if a patent 382 | license would not permit royalty-free redistribution of the Library by 383 | all those who receive copies directly or indirectly through you, then 384 | the only way you could satisfy both it and this License would be to 385 | refrain entirely from distribution of the Library. 386 | 387 | If any portion of this section is held invalid or unenforceable under any 388 | particular circumstance, the balance of the section is intended to apply, 389 | and the section as a whole is intended to apply in other circumstances. 390 | 391 | It is not the purpose of this section to induce you to infringe any 392 | patents or other property right claims or to contest validity of any 393 | such claims; this section has the sole purpose of protecting the 394 | integrity of the free software distribution system which is 395 | implemented by public license practices. Many people have made 396 | generous contributions to the wide range of software distributed 397 | through that system in reliance on consistent application of that 398 | system; it is up to the author/donor to decide if he or she is willing 399 | to distribute software through any other system and a licensee cannot 400 | impose that choice. 401 | 402 | This section is intended to make thoroughly clear what is believed to 403 | be a consequence of the rest of this License. 404 | 405 | 12. If the distribution and/or use of the Library is restricted in 406 | certain countries either by patents or by copyrighted interfaces, the 407 | original copyright holder who places the Library under this License may add 408 | an explicit geographical distribution limitation excluding those countries, 409 | so that distribution is permitted only in or among countries not thus 410 | excluded. In such case, this License incorporates the limitation as if 411 | written in the body of this License. 412 | 413 | 13. The Free Software Foundation may publish revised and/or new 414 | versions of the Lesser General Public License from time to time. 415 | Such new versions will be similar in spirit to the present version, 416 | but may differ in detail to address new problems or concerns. 417 | 418 | Each version is given a distinguishing version number. If the Library 419 | specifies a version number of this License which applies to it and 420 | "any later version", you have the option of following the terms and 421 | conditions either of that version or of any later version published by 422 | the Free Software Foundation. If the Library does not specify a 423 | license version number, you may choose any version ever published by 424 | the Free Software Foundation. 425 | 426 | 14. If you wish to incorporate parts of the Library into other free 427 | programs whose distribution conditions are incompatible with these, 428 | write to the author to ask for permission. For software which is 429 | copyrighted by the Free Software Foundation, write to the Free 430 | Software Foundation; we sometimes make exceptions for this. Our 431 | decision will be guided by the two goals of preserving the free status 432 | of all derivatives of our free software and of promoting the sharing 433 | and reuse of software generally. 434 | 435 | NO WARRANTY 436 | 437 | 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO 438 | WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 439 | EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR 440 | OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY 441 | KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE 442 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 443 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE 444 | LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME 445 | THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 446 | 447 | 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN 448 | WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY 449 | AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU 450 | FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR 451 | CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE 452 | LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING 453 | RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A 454 | FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF 455 | SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH 456 | DAMAGES. 457 | 458 | END OF TERMS AND CONDITIONS 459 | 460 | How to Apply These Terms to Your New Libraries 461 | 462 | If you develop a new library, and you want it to be of the greatest 463 | possible use to the public, we recommend making it free software that 464 | everyone can redistribute and change. You can do so by permitting 465 | redistribution under these terms (or, alternatively, under the terms of the 466 | ordinary General Public License). 467 | 468 | To apply these terms, attach the following notices to the library. It is 469 | safest to attach them to the start of each source file to most effectively 470 | convey the exclusion of warranty; and each file should have at least the 471 | "copyright" line and a pointer to where the full notice is found. 472 | 473 | 474 | Copyright (C) 475 | 476 | This library is free software; you can redistribute it and/or 477 | modify it under the terms of the GNU Lesser General Public 478 | License as published by the Free Software Foundation; either 479 | version 2.1 of the License, or (at your option) any later version. 480 | 481 | This library is distributed in the hope that it will be useful, 482 | but WITHOUT ANY WARRANTY; without even the implied warranty of 483 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 484 | Lesser General Public License for more details. 485 | 486 | You should have received a copy of the GNU Lesser General Public 487 | License along with this library; if not, write to the Free Software 488 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 489 | USA 490 | 491 | Also add information on how to contact you by electronic and paper mail. 492 | 493 | You should also get your employer (if you work as a programmer) or your 494 | school, if any, to sign a "copyright disclaimer" for the library, if 495 | necessary. Here is a sample; alter the names: 496 | 497 | Yoyodyne, Inc., hereby disclaims all copyright interest in the 498 | library `Frob' (a library for tweaking knobs) written by James Random 499 | Hacker. 500 | 501 | , 1 April 1990 502 | Ty Coon, President of Vice 503 | 504 | That's all there is to it! 505 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## As of 2021-10-24, Firefox Legacy is no longer supported. It has become increasingly challenging to update it to a more modern Firefox version, and I no longer use it myself. 2 | 3 | # FirefoxLegacy 4 | Porting more modern Firefox versions to Mac OS X 10.7 5 | -------------------------------------------------------------------------------- /ToDo.txt: -------------------------------------------------------------------------------- 1 | The crash reporter doesn't work on 10.8 yet (it itself crashes) 2 | fix drm crash mach_port_construct 3 | isLionSmartMagnifyEvent 4 | -------------------------------------------------------------------------------- /about-wordmark.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | Firefox Legacy VERSIONVERSION 4 | by ParrotGeek Software 5 | 6 | -------------------------------------------------------------------------------- /findUndefSyms.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | echo Generating available symbol list step 1 3 | nm -Uj /System/Library/Frameworks/*/Versions/*/* "$1"/Contents/MacOS/* "$1"/Contents/MacOS/*.app/Contents/MacOS/* `find "$1"/Contents/Resources -name '*.dylib' -type f` /System/Library/Frameworks/*/Versions/*/Frameworks/*/Versions/*/* /usr/lib/*.dylib /usr/lib/*/*.dylib 2>/dev/null > /tmp/_fusym_tmp 4 | echo Generating available symbol list step 2 5 | nm -Uj /System/Library/PrivateFrameworks/*/Versions/*/* /System/Library/PrivateFrameworks/*/Versions/*/Libraries/* /System/Library/PrivateFrameworks/*/Versions/*/Frameworks/*/Versions/*/* /System/Library/Frameworks/*/Versions/*/Libraries/* 2>/dev/null >> /tmp/_fusym_tmp 6 | echo Generating available symbol list step 3 7 | cat /tmp/_fusym_tmp | sort | uniq > /tmp/_fusym_tmp_ 8 | mv -f /tmp/_fusym_tmp_ /tmp/_fusym_tmp 9 | echo Generating used symbol list 10 | nm -u -m "$1/Contents/MacOS/XUL" "$1/Contents/MacOS/"*.dylib 2>/dev/null | grep -vF " weak " | grep -v "^$1" |grep -vF .objc_class_name_ | sed 's/.* external _/_/' | cut -d ' ' -f1 | grep . | sort | uniq > /tmp/_fusym_tmp2 11 | echo ---Undefined symbols--- 12 | diff /tmp/_fusym_tmp2 /tmp/_fusym_tmp | grep '^< ' | cut -c3- 13 | rm -f /tmp/_fusym_tmp* 14 | echo ---End--- 15 | -------------------------------------------------------------------------------- /make.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | cd unsign; make -s; cd .. 4 | 5 | #ok 6 | gcc -fPIC -O3 -Wall -Wextra -Werror -Wno-unused-parameter -arch x86_64 -dynamiclib -mmacosx-version-min=10.7 -Wl,-reexport_library,/usr/lib/libSystem.B.dylib -current_version 159.1 -compatibility_version 1 -o libFxShim.dylib shim.c 7 | 8 | # NSObject was in CoreFoundation in Lion, not libobjc 9 | #ok 10 | gcc -fPIC -O3 -Wall -Wextra -Werror -arch x86_64 -dynamiclib -mmacosx-version-min=10.7 -Wl,-reexport_library,/usr/lib/libobjc.A.dylib -Wl,-reexport_library,/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation -current_version 228 -compatibility_version 1 -o libFxShimObjc.dylib shimObjc.c 11 | 12 | #ok 13 | gcc -fPIC -O3 -Wall -Wextra -Werror -arch x86_64 -dynamiclib -lobjc -mmacosx-version-min=10.7 -Wl,-reexport_library,/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation -current_version 833.25 -compatibility_version 300 -o libFxShimFoundation.dylib shimFoundation.m 14 | 15 | #ok 16 | gcc -fPIC -O3 -Wall -Wextra -Werror -arch x86_64 -dynamiclib -mmacosx-version-min=10.7 -Wl,-reexport_library,/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/CoreText.framework/Versions/A/CoreText -framework CoreFoundation -current_version 1 -compatibility_version 1 -o libFxShimCoreText.dylib shimCoreText.c 17 | 18 | #ok 19 | gcc -fPIC -O3 -Wall -Wextra -Werror -Wno-unused-parameter -arch x86_64 -dynamiclib -mmacosx-version-min=10.7 -Wl,-reexport_library,/System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics -current_version 600 -compatibility_version 64 -o libFxShimCoreGraphics.dylib shimCoreGraphics.c 20 | 21 | #ok 22 | gcc -fPIC -O3 -Wall -Wextra -Werror -Wno-unused-parameter -arch x86_64 -dynamiclib -lobjc -mmacosx-version-min=10.7 -Wl,-reexport_library,/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit -current_version 1138.51 -compatibility_version 45 -o libFxShimAppKit.dylib shimAppKit.m 23 | 24 | #ok 25 | gcc -fPIC -O3 -Wall -Wextra -Werror -arch x86_64 -dynamiclib -mmacosx-version-min=10.7 -current_version 1 -compatibility_version 1 -framework CoreFoundation -o libFxShimVT.dylib shimVT.c 26 | 27 | #ok 28 | gcc -fPIC -O3 -Wall -Wextra -Werror -arch x86_64 -dynamiclib -mmacosx-version-min=10.7 -Wl,-reexport_library,/System/Library/Frameworks/Security.framework/Versions/A/Security -current_version 55148.6 -compatibility_version 1 -o libFxShimSecurity.dylib shimSecurity.c 29 | 30 | gcc -fPIC -O3 -Wall -Wextra -Werror -Wno-sign-compare -arch x86_64 -mmacosx-version-min=10.7 -framework AppKit -o trampoline trampoline.c 31 | 32 | mv libFxShim*.dylib Firefox.app/Contents/MacOS/ 33 | 34 | install_name_tool -change /usr/lib/libSystem.B.dylib '@loader_path/libFxShim.dylib' Firefox.app/Contents/MacOS/libnss3.dylib 35 | 36 | install_name_tool -change /usr/lib/libSystem.B.dylib '@loader_path/libFxShim.dylib' Firefox.app/Contents/MacOS/firefox 37 | 38 | install_name_tool -change /usr/lib/libSystem.B.dylib '@loader_path/libFxShim.dylib' Firefox.app/Contents/MacOS/XUL 39 | install_name_tool -change /usr/lib/libobjc.A.dylib '@loader_path/libFxShimObjc.dylib' Firefox.app/Contents/MacOS/XUL 40 | install_name_tool -change /System/Library/Frameworks/VideoToolbox.framework/Versions/A/VideoToolbox '@loader_path/libFxShimVT.dylib' Firefox.app/Contents/MacOS/XUL 41 | install_name_tool -change /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation '@loader_path/libFxShimFoundation.dylib' Firefox.app/Contents/MacOS/XUL 42 | install_name_tool -change /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit '@loader_path/libFxShimAppKit.dylib' Firefox.app/Contents/MacOS/XUL 43 | install_name_tool -change /System/Library/Frameworks/Security.framework/Versions/A/Security '@loader_path/libFxShimSecurity.dylib' Firefox.app/Contents/MacOS/XUL 44 | perl -pi -e 's/OBJC_CLASS_\$_NSSharingService/OBJC_CLASS_\$_NSSharingServic2/g' Firefox.app/Contents/MacOS/XUL 45 | perl -pi -e 's/OBJC_CLASS_\$_NSSharingServic2PickerTouchBarItem/OBJC_CLASS_\$_NSSharingServicePickerTouchBarItem/g' Firefox.app/Contents/MacOS/XUL # fix false positive 46 | 47 | # gma 950 48 | perl -pi -e 's/\x3D\xC8\x00\x00\x00\x0F\x82/\x3D\x64\x00\x00\x00\x0F\x82/' Firefox.app/Contents/MacOS/XUL 49 | #https://hg.mozilla.org/mozreview/gecko/file/tip/gfx/gl/GLContext.cpp 50 | # if (mVersion < 200) 51 | # return false; 52 | # to 100 53 | 54 | #widevine 55 | perl -pi -e 's/VerifyCdmHost_/VerifyCdmNOPE_/g' Firefox.app/Contents/MacOS/XUL 56 | 57 | #it must be 10.7.5 to work around coreui issue in 10.7.0-4 58 | LC_ALL=C /usr/bin/sed -i '' 's/>10.9.010.7.5' -f2 | cut -d '<' -f1` 60 | p=`cat patch.txt` 61 | bash -e ./rebrand.sh $p $v || exit $? 62 | 63 | #objc 64 | install_name_tool -change /usr/lib/libobjc.A.dylib '@loader_path/../../../libFxShimObjc.dylib' "Firefox Legacy.app/Contents/MacOS/crashreporter.app/Contents/MacOS/crashreporter" 65 | 66 | find Firefox\ Legacy.app -type f -perm 0755 -not -name '*.dylib' -not -name '*.py' | while read a; do 67 | file "$a" | grep -q executable && (mv "$a" "${a}_real"; cp trampoline "$a"; unsign/unsign "${a}_real"; cat "${a}_real.unsigned" > "${a}_real"; rm "${a}_real.unsigned"; perl -pi -e 's/\x28\x00\x00\x80/\x28\x00\x00\x00/' "${a}_real") || true 68 | done 69 | rm -f trampoline 70 | 71 | ls Firefox\ Legacy.app/Contents/MacOS/*.dylib | fgrep -v libFxShim | while read a; do 72 | unsign/unsign "$a" 73 | cat "$a.unsigned" > "$a" 74 | rm "$a.unsigned" 75 | done 76 | 77 | install_name_tool -change /System/Library/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics '@loader_path/libFxShimCoreGraphics.dylib' Firefox\ Legacy.app/Contents/MacOS/XUL 78 | install_name_tool -change /System/Library/Frameworks/CoreText.framework/Versions/A/CoreText '@loader_path/libFxShimCoreText.dylib' Firefox\ Legacy.app/Contents/MacOS/XUL 79 | install_name_tool -change /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ImageIO.framework/Versions/A/ImageIO Firefox\ Legacy.app/Contents/MacOS/XUL 80 | 81 | unsign/unsign Firefox\ Legacy.app/Contents/MacOS/XUL 82 | cat Firefox\ Legacy.app/Contents/MacOS/XUL.unsigned > Firefox\ Legacy.app/Contents/MacOS/XUL 83 | rm Firefox\ Legacy.app/Contents/MacOS/XUL.unsigned 84 | 85 | rm -rf Firefox\ Legacy.app/Contents/_CodeSignature Firefox\ Legacy.app/Contents/MacOS/*.app/Contents/_CodeSignature 86 | 87 | #updater/telemetry/studies removal, home page link 88 | rm -rf Firefox\ Legacy.app/Contents/MacOS/updater.app 89 | plutil -remove SMPrivilegedExecutables Firefox\ Legacy.app/Contents/Info.plist 90 | rm -rf Firefox\ Legacy.app/Contents/Library 91 | find Firefox\ Legacy.app -name '*.sig' -not -name libclearkey.dylib.sig -type f -delete 92 | mkdir -p Firefox\ Legacy.app/Contents/Resources/distribution 93 | cat policies.json > Firefox\ Legacy.app/Contents/Resources/distribution/policies.json 94 | 95 | rm -f FirefoxLegacy$v$p.zip unsign/unsign unsign/*.o 96 | xattr -cr Firefox\ Legacy.app 97 | zip -9 -r FirefoxLegacy$v$p.zip Firefox\ Legacy.app 98 | -------------------------------------------------------------------------------- /patch.txt: -------------------------------------------------------------------------------- 1 | p3 2 | -------------------------------------------------------------------------------- /policies.json: -------------------------------------------------------------------------------- 1 | { 2 | "policies": { 3 | "DisableAppUpdate": true, 4 | "DisableFirefoxStudies": true, 5 | "DisableTelemetry": true, 6 | "SupportMenu": { 7 | "Title": "Firefox Legacy Home Page (ParrotGeek)", 8 | "URL": "https://parrotgeek.com/fxlegacy.html", 9 | "AccessKey": "L" 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /rebrand.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | d="`pwd`" 3 | p=$1 4 | v=$2 5 | rm -rf Firefox\ Legacy.app 6 | mv Firefox.app Firefox\ Legacy.app 7 | /usr/bin/sed -i '' 's/Firefox/Firefox Legacy/g' Firefox\ Legacy.app/Contents/Info.plist 8 | /usr/bin/sed -i '' "s/$v/$v$p/g" Firefox\ Legacy.app/Contents/Info.plist 9 | find Firefox\ Legacy.app/Contents/Resources/ -name InfoPlist.strings -delete 10 | cd Firefox\ Legacy.app/Contents/Resources/browser 11 | rm -rf omni 12 | unzip -qqd omni omni.ja 2>/dev/null || true 13 | cd omni 14 | rm -f ../omni.ja 15 | cp "$d/about-wordmark.svg" chrome/browser/content/branding/ 16 | /usr/bin/sed -i '' "s/VERSIONVERSION/$v$p/" chrome/browser/content/branding/about-wordmark.svg 17 | /usr/bin/sed -i '' 's/%OS_VERSION%/Darwin 13.0.0/g' defaults/preferences/firefox.js # Widevine CDM 18 | /usr/bin/sed -i '' 's/pref("dom.push.enabled", false);/pref("dom.push.enabled", true);/g' defaults/preferences/firefox.js 19 | /usr/bin/sed -i '' 's/pref("dom.serviceWorkers.enabled", false);/pref("dom.serviceWorkers.enabled", true);/g' defaults/preferences/firefox.js 20 | /usr/bin/sed -i '' 's/pref("security.cert_pinning.enforcement_level", 1);/pref("security.cert_pinning.enforcement_level", 0);/g' defaults/preferences/firefox.js 21 | /usr/bin/sed -i '' 's/pref("permissions.desktop-notification.postPrompt.enabled", false);/pref("permissions.desktop-notification.postPrompt.enabled", true);/g' defaults/preferences/firefox.js 22 | LC_ALL=C find . -name brand.dtd -exec /usr/bin/sed -i '' -e 's/Firefox and the Firefox logos are trademarks of the Mozilla Foundation./Firefox and the Firefox logos are trademarks of the Mozilla Foundation. Firefox Legacy is a modification of Firefox created by ParrotGeek Software./g' -e 's/Firefox"/Firefox Legacy"/g' -e 's/Mozilla Firefox/Firefox/g' {} \; 23 | LC_ALL=C find . -name brand.ftl -exec /usr/bin/sed -i '' -e 's/Firefox and the Firefox logos are trademarks of the Mozilla Foundation./Firefox and the Firefox logos are trademarks of the Mozilla Foundation. Firefox Legacy is a modification of Firefox created by ParrotGeek Software./g' -e 's/Firefox$/Firefox Legacy/g' -e 's/Mozilla Firefox/Firefox/g' {} \; 24 | LC_ALL=C find . -name aboutDialog.ftl -exec /usr/bin/sed -i '' -e 's/update-adminDisabled =.*/update-adminDisabled = Check for Firefox Legacy updates at parrotgeek.com./g' -e 's/{ -brand-short-name } is designed by/{ -brand-short-name } is a modification of Firefox, which is designed by/' {} \; 25 | zip -qr0XD ../omni.ja * 26 | cd .. 27 | rm -rf omni 28 | cd .. 29 | rm -rf omni 30 | unzip -qqd omni omni.ja 2>/dev/null || true 31 | cd omni 32 | rm -f ../omni.ja 33 | /usr/bin/sed -i '' 's/%OS_VERSION%/Darwin 13.0.0/g' greprefs.js # Widevine CDM 34 | cat << EOF >> greprefs.js 35 | pref("browser.tabs.remote.useCrossOriginEmbedderPolicy", true); 36 | pref("browser.tabs.remote.useCrossOriginOpenerPolicy", true); 37 | pref("dom.animations-api.getAnimations.enabled", true); 38 | pref("dom.animations-api.timelines.enabled", true); 39 | pref("dom.battery.enabled", false); 40 | pref("dom.promise_rejection_events.enabled", true); 41 | pref("dom.security.featurePolicy.enabled", true); 42 | pref("dom.webnotifications.requireuserinteraction", true); 43 | pref("javascript.options.experimental.fields", true); 44 | pref("javascript.options.shared_memory", true); 45 | pref("javascript.options.experimental.await_fix", true); 46 | pref("layout.css.clip-path-path.enabled", true); 47 | pref("layout.css.column-span.enabled", true); 48 | pref("layout.css.contain.enabled", true); 49 | pref("layout.css.individual-transform.enabled", true); 50 | pref("layout.css.motion-path.enabled", true); 51 | pref("layout.css.outline-style-auto.enabled", true); 52 | pref("layout.css.resizeobserver.enabled", true); 53 | pref("media.getusermedia.screensharing.enabled", false); 54 | pref("security.tls.version.min", 3); 55 | EOF 56 | zip -qr0XD ../omni.ja * 57 | cd .. 58 | rm -rf omni 59 | cd "$d" 60 | touch Firefox\ Legacy.app 61 | -------------------------------------------------------------------------------- /shim.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #define _POSIX_C_SOURCE 200809L 7 | #include 8 | #undef _POSIX_C_SOURCE 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | static int lion = 0; 17 | 18 | // fake TCP fast open support for libnspr 19 | 20 | typedef __uint32_t sae_associd_t; 21 | typedef __uint32_t sae_connid_t; 22 | 23 | typedef struct my_sa_endpoints { 24 | unsigned int sae_srcif; /* optional source interface */ 25 | struct sockaddr *sae_srcaddr; /* optional source address */ 26 | socklen_t sae_srcaddrlen; /* size of source address */ 27 | struct sockaddr *sae_dstaddr; /* destination address */ 28 | socklen_t sae_dstaddrlen; /* size of destination address */ 29 | } my_sa_endpoints_t; 30 | 31 | typedef int (pr_realconnectx) (int, const my_sa_endpoints_t *, sae_associd_t, unsigned int, const struct iovec *, unsigned int, size_t *, sae_connid_t *); 32 | typedef pr_realconnectx* pt_pr_realconnectx; 33 | static pt_pr_realconnectx realconnectx = NULL; 34 | 35 | typedef int (pr_realposix_spawn) (pid_t *restrict, const char *restrict,const posix_spawn_file_actions_t *,const posix_spawnattr_t *restrict, char *const [restrict],char *const [restrict]); 36 | typedef pr_realposix_spawn* pt_pr_realposix_spawn; 37 | static pt_pr_realposix_spawn realposix_spawn = NULL; 38 | static pt_pr_realposix_spawn realposix_spawnp = NULL; 39 | typedef int (pr_realsandbox_init_with_parameters) (const char *, uint64_t, const char *const[], char **); 40 | typedef pr_realsandbox_init_with_parameters* pt_pr_realsandbox_init_with_parameters; 41 | static pt_pr_realsandbox_init_with_parameters realsandbox_init_with_parameters = NULL; 42 | 43 | __attribute__((constructor)) static void initCShim(){ 44 | void *handle = dlopen ("/usr/lib/libSystem.B.dylib", RTLD_NOW); 45 | if (!handle) { 46 | puts (dlerror()); 47 | abort(); 48 | } 49 | realconnectx = (pt_pr_realconnectx) dlsym(handle, "connectx"); 50 | realposix_spawn = (pt_pr_realposix_spawn) dlsym(handle, "posix_spawn"); 51 | if(!realposix_spawn) { 52 | puts("No posix_spawn"); 53 | abort(); 54 | } 55 | realposix_spawnp = (pt_pr_realposix_spawn) dlsym(handle, "posix_spawnp"); 56 | if(!realposix_spawnp) { 57 | puts("No posix_spawnp"); 58 | abort(); 59 | } 60 | struct utsname buffer; 61 | if (uname(&buffer) != 0) { 62 | puts("uname failed"); 63 | abort(); 64 | } 65 | 66 | if(strlen(buffer.release) >= 3) { 67 | if(buffer.release[0]=='1' && buffer.release[1]=='1' && buffer.release[2]=='.') { 68 | lion = 1; 69 | } 70 | } 71 | 72 | if(realconnectx) { 73 | // 10.9+ 74 | realsandbox_init_with_parameters = (pt_pr_realsandbox_init_with_parameters) dlsym(handle, "sandbox_init_with_parameters"); 75 | if(!realsandbox_init_with_parameters) { 76 | fprintf(stderr,"weird, can't find sandbox_init_with_parameters"); 77 | abort(); 78 | } 79 | } 80 | } 81 | 82 | int connectx(int socket, const my_sa_endpoints_t *endpoints,sae_associd_t associd, unsigned int flags, const struct iovec *iov,unsigned int iovcnt, size_t *len, sae_connid_t *connid) { 83 | if(realconnectx) return realconnectx(socket,endpoints,associd,flags,iov,iovcnt,len,connid); 84 | if(iovcnt != 1) { 85 | fprintf(stderr,"unimplemented shim connectx with iovcnt %u != 1\n",iovcnt); 86 | abort(); 87 | } 88 | *len = sendto(socket, iov[0].iov_base, iov[0].iov_len,0,endpoints->sae_dstaddr, endpoints->sae_dstaddrlen); 89 | return 0; 90 | } 91 | 92 | // new secure intrinsics used by llvm 93 | // https://github.com/unofficial-opensource-apple/Libc/tree/master/secure 94 | 95 | static void my__chk_overlap (const void *a, size_t an, const void *b, size_t bn) 96 | { 97 | if (((uintptr_t)a) <= ((uintptr_t)b)+bn && ((uintptr_t)b) <= ((uintptr_t)a)+an) 98 | abort(); 99 | } 100 | 101 | void * 102 | __memccpy_chk (void *dest, const void *src, int c, size_t len, size_t dstlen) 103 | { 104 | void *retval; 105 | 106 | if (__builtin_expect (dstlen < len, 0)) 107 | abort (); 108 | 109 | /* retval is NULL if len was copied, otherwise retval is the 110 | * byte *after* the last one written. 111 | */ 112 | retval = memccpy (dest, src, c, len); 113 | 114 | if (retval != NULL) { 115 | len = (uintptr_t)retval - (uintptr_t)dest; 116 | } 117 | 118 | my__chk_overlap(dest, len, src, len); 119 | 120 | return retval; 121 | } 122 | 123 | size_t 124 | __strlcat_chk (char *restrict dest, char *restrict src, 125 | size_t len, size_t dstlen) 126 | { 127 | size_t initial_srclen; 128 | size_t initial_dstlen; 129 | 130 | if (__builtin_expect (dstlen < len, 0)) 131 | abort (); 132 | 133 | initial_srclen = strlen(src); 134 | initial_dstlen = strnlen(dest, len); 135 | 136 | if (initial_dstlen == len) 137 | return len+initial_srclen; 138 | 139 | if (initial_srclen < len - initial_dstlen) { 140 | my__chk_overlap(dest, initial_srclen + initial_dstlen + 1, src, initial_srclen + 1); 141 | memcpy(dest+initial_dstlen, src, initial_srclen + 1); 142 | } else { 143 | my__chk_overlap(dest, initial_srclen + initial_dstlen + 1, src, len - initial_dstlen - 1); 144 | memcpy(dest+initial_dstlen, src, len - initial_dstlen - 1); 145 | dest[len-1] = '\0'; 146 | } 147 | 148 | return initial_srclen + initial_dstlen; 149 | } 150 | 151 | size_t 152 | __strlcpy_chk (char *restrict dest, char *restrict src, 153 | size_t len, size_t dstlen) 154 | { 155 | size_t retval; 156 | if (__builtin_expect (dstlen < len, 0)) 157 | abort (); 158 | 159 | retval = strlcpy (dest, src, len); 160 | 161 | if (retval < len) 162 | len = retval + 1; 163 | 164 | my__chk_overlap(dest, len, src, len); 165 | 166 | return retval; 167 | } 168 | 169 | // new math intrinsics used by llvm 170 | 171 | struct __myfloat2 { float __sinval; float __cosval; }; 172 | struct __mydouble2 { double __sinval; double __cosval; }; 173 | 174 | struct __myfloat2 __sincosf_stret(float x) { 175 | struct __myfloat2 s; 176 | s.__sinval = sinf(x); 177 | s.__cosval = cosf(x); 178 | return s; 179 | } 180 | struct __mydouble2 __sincos_stret(double x) { 181 | struct __mydouble2 s; 182 | s.__sinval = sin(x); 183 | s.__cosval = cos(x); 184 | return s; 185 | } 186 | 187 | double __exp10(double arg) { 188 | return pow(10, arg); 189 | } 190 | 191 | float __exp10f(float arg) { 192 | return powf(10, arg); 193 | } 194 | 195 | int sandbox_init_with_parameters(const char *profile, uint64_t flags, const char *const parameters[], char **errorbuf) { 196 | if(realsandbox_init_with_parameters) return realsandbox_init_with_parameters(profile, flags, parameters, errorbuf); 197 | if(errorbuf) *errorbuf = 0; 198 | return 0; 199 | } 200 | 201 | // from old Mozilla code 202 | static void SetAllFDsToCloseOnExec() { 203 | const char fd_dir[] = "/dev/fd"; 204 | DIR *dir = opendir(fd_dir); 205 | if (NULL == dir) { 206 | fprintf(stderr,"Unable to open %s\n", fd_dir); 207 | return; 208 | } 209 | 210 | struct dirent *ent; 211 | while ((ent = readdir(dir))) { 212 | // Skip . and .. entries. 213 | if (ent->d_name[0] == '.') 214 | continue; 215 | int i = atoi(ent->d_name); 216 | // We don't close stdin, stdout or stderr. 217 | if (i <= STDERR_FILENO) 218 | continue; 219 | 220 | int flags = fcntl(i, F_GETFD); 221 | if ((flags == -1) || (fcntl(i, F_SETFD, flags | FD_CLOEXEC) == -1)) { 222 | fprintf(stderr,"fcntl failure.\n"); 223 | } 224 | } 225 | } 226 | 227 | // kernel panic workaround posix_spawnattr_setflags cloexec simply does not work in Lion at all 228 | int 229 | posix_spawn(pid_t *restrict pid, const char *restrict path, 230 | const posix_spawn_file_actions_t *file_actions, 231 | const posix_spawnattr_t *restrict attrp, char *const argv[restrict], 232 | char *const envp[restrict]){ 233 | if(lion && attrp) { 234 | short flags = 0; 235 | if(posix_spawnattr_getflags(attrp,&flags) == 0) { 236 | if((flags & POSIX_SPAWN_CLOEXEC_DEFAULT) == POSIX_SPAWN_CLOEXEC_DEFAULT) { 237 | flags &= ~POSIX_SPAWN_CLOEXEC_DEFAULT; 238 | if(posix_spawnattr_setflags((posix_spawnattr_t *)attrp,flags) != 0) { 239 | abort(); 240 | } 241 | SetAllFDsToCloseOnExec(); 242 | } 243 | } 244 | } 245 | return realposix_spawn(pid,path,file_actions,attrp,argv,envp); 246 | } 247 | 248 | int 249 | posix_spawnp(pid_t *restrict pid, const char *restrict file, 250 | const posix_spawn_file_actions_t *file_actions, 251 | const posix_spawnattr_t *restrict attrp, char *const argv[restrict], 252 | char *const envp[restrict]){ 253 | if(lion && attrp) { 254 | short flags = 0; 255 | if(posix_spawnattr_getflags(attrp,&flags) == 0) { 256 | if((flags & POSIX_SPAWN_CLOEXEC_DEFAULT) == POSIX_SPAWN_CLOEXEC_DEFAULT) { 257 | flags &= ~POSIX_SPAWN_CLOEXEC_DEFAULT; 258 | if(posix_spawnattr_setflags((posix_spawnattr_t *)attrp,flags) != 0) { 259 | abort(); 260 | } 261 | SetAllFDsToCloseOnExec(); 262 | } 263 | } 264 | } 265 | return realposix_spawnp(pid,file,file_actions,attrp,argv,envp); 266 | } 267 | -------------------------------------------------------------------------------- /shimAppKit.m: -------------------------------------------------------------------------------- 1 | #import 2 | #include 3 | #import 4 | #import 5 | 6 | static BOOL my_drawInRect(id self, SEL _cmd, NSRect rect) { 7 | [self drawInRect:rect fromRect:NSZeroRect operation:NSCompositeSourceOver fraction:1.0f]; 8 | return YES; 9 | } 10 | 11 | @implementation NSImage (FFLegacyMavAPIs) 12 | 13 | +(void)load { 14 | @autoreleasepool { 15 | if(![NSImage instancesRespondToSelector:@selector(drawInRect:)]) { 16 | const char *types = [[NSString stringWithFormat:@"c@:%s", @encode(NSRect)] UTF8String]; 17 | class_addMethod([NSImage class], @selector(drawInRect:), (IMP)my_drawInRect, types); 18 | } 19 | } 20 | } 21 | @end 22 | 23 | // not in 10.7 24 | NSString * const NSSharingServiceNamePostOnTwitter = @"com.apple.share.Twitter.post"; 25 | 26 | static Class realNSSharingService = nil; 27 | 28 | __attribute__((constructor)) static void initNSSharingServiceShim(){ 29 | void *handle = dlopen ("/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit", RTLD_NOW); 30 | if (!handle) { 31 | puts (dlerror()); 32 | abort(); 33 | } 34 | realNSSharingService = (Class) dlsym(handle, "OBJC_CLASS_$_NSSharingService"); 35 | } 36 | 37 | @interface NSSharingServic2 : NSObject 38 | 39 | +(NSArray *)sharingServicesForItems:(NSArray *)items; 40 | + (id)sharingServiceNamed:(NSString *)serviceName; 41 | 42 | @end 43 | 44 | 45 | @implementation NSSharingServic2 46 | 47 | +(NSArray *)sharingServicesForItems:(NSArray *)items { 48 | if(realNSSharingService) 49 | return [realNSSharingService sharingServicesForItems:items]; 50 | return [NSArray array]; 51 | } 52 | 53 | +(id)sharingServiceNamed:(NSString *)serviceName{ 54 | if(realNSSharingService) 55 | return [realNSSharingService sharingServiceNamed:serviceName]; 56 | return nil; 57 | } 58 | 59 | @end 60 | -------------------------------------------------------------------------------- /shimCoreGraphics.c: -------------------------------------------------------------------------------- 1 | // No use implementing them because they wouldn't work anyway 2 | void *CGDisplayStreamCreate(void) { return 0; } 3 | void *CGDisplayStreamGetRunLoopSource(void) { return 0; } 4 | void *CGDisplayStreamStart(void) { return 0; } 5 | void *CGDisplayStreamStop(void) { return 0; } 6 | void *CGDisplayStreamUpdateGetRects(void) { return 0; } 7 | -------------------------------------------------------------------------------- /shimCoreText.c: -------------------------------------------------------------------------------- 1 | #include 2 | // not in 10.7 3 | // fixme: actually implement this 4 | const CFStringRef kCTWritingDirectionAttributeName = CFSTR("NSWritingDirection"); 5 | -------------------------------------------------------------------------------- /shimFoundation.m: -------------------------------------------------------------------------------- 1 | #import 2 | // not in 10.7 3 | NSString * const NSUserNotificationDefaultSoundName = @"DefaultSoundName"; 4 | -------------------------------------------------------------------------------- /shimObjc.c: -------------------------------------------------------------------------------- 1 | #include 2 | // not in lion 3 | extern void objc_setProperty(id self, SEL _cmd, ptrdiff_t offset, id newValue, BOOL atomic, BOOL shouldCopy); 4 | 5 | void objc_setProperty_atomic(id self, SEL _cmd, id newValue, ptrdiff_t offset) { 6 | objc_setProperty(self,_cmd,offset,newValue,YES,NO); 7 | } 8 | -------------------------------------------------------------------------------- /shimSecurity.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | // OSStatus SecTrustSetNetworkFetchAllowed(SecTrustRef trust, Boolean allowFetch); 10 | 11 | typedef OSStatus (pr_realSecTrustSetNetworkFetchAllowed) (void *, Boolean); 12 | typedef pr_realSecTrustSetNetworkFetchAllowed* pt_pr_realSecTrustSetNetworkFetchAllowed; 13 | static pt_pr_realSecTrustSetNetworkFetchAllowed realSecTrustSetNetworkFetchAllowed; 14 | 15 | __attribute__((constructor)) static void initSecShim(){ 16 | void *handle = dlopen ("/System/Library/Frameworks/Security.framework/Versions/A/Security", RTLD_NOW); 17 | if (!handle) { 18 | puts (dlerror()); 19 | abort(); 20 | } 21 | 22 | realSecTrustSetNetworkFetchAllowed = (pt_pr_realSecTrustSetNetworkFetchAllowed) dlsym(handle, "SecTrustSetNetworkFetchAllowed"); 23 | } 24 | 25 | OSStatus SecTrustSetNetworkFetchAllowed(void *trust, Boolean allowFetch) { 26 | if(realSecTrustSetNetworkFetchAllowed) { 27 | return realSecTrustSetNetworkFetchAllowed(trust, allowFetch); 28 | } else { 29 | return 0; 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /shimVT.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | // I hate this as much as you do. 9 | 10 | typedef OSStatus (pr_realVTDecompressionSessionCreate) (CFAllocatorRef, void *, CFDictionaryRef, CFDictionaryRef, const void *, void *); 11 | typedef pr_realVTDecompressionSessionCreate* pt_pr_realVTDecompressionSessionCreate; 12 | static pt_pr_realVTDecompressionSessionCreate realVTDecompressionSessionCreate; 13 | 14 | typedef OSStatus (pr_realVTDecompressionSessionDecodeFrame) (void *, void *, uint32_t, void *, uint32_t *); 15 | typedef pr_realVTDecompressionSessionDecodeFrame* pt_pr_realVTDecompressionSessionDecodeFrame; 16 | static pt_pr_realVTDecompressionSessionDecodeFrame realVTDecompressionSessionDecodeFrame; 17 | 18 | typedef void (pr_realVTDecompressionSessionInvalidate) (void *); 19 | typedef pr_realVTDecompressionSessionInvalidate* pt_pr_realVTDecompressionSessionInvalidate; 20 | static pt_pr_realVTDecompressionSessionInvalidate realVTDecompressionSessionInvalidate; 21 | 22 | typedef OSStatus (pr_realVTDecompressionSessionWaitForAsynchronousFrames) (void *); 23 | typedef pr_realVTDecompressionSessionWaitForAsynchronousFrames* pt_pr_realVTDecompressionSessionWaitForAsynchronousFrames; 24 | static pt_pr_realVTDecompressionSessionWaitForAsynchronousFrames realVTDecompressionSessionWaitForAsynchronousFrames; 25 | 26 | typedef OSStatus (pr_realVTSessionCopyProperty) (void *, CFStringRef, CFAllocatorRef, void *); 27 | typedef pr_realVTSessionCopyProperty* pt_pr_realVTSessionCopyProperty; 28 | static pt_pr_realVTSessionCopyProperty realVTSessionCopyProperty; 29 | 30 | const CFStringRef kVTVideoDecoderSpecification_EnableHardwareAcceleratedVideoDecoder = CFSTR("EnableHardwareAcceleratedVideoDecoder"); 31 | 32 | const CFStringRef kVTDecompressionPropertyKey_UsingHardwareAcceleratedVideoDecoder = CFSTR("UsingHardwareAcceleratedVideoDecoder"); 33 | 34 | __attribute__((constructor)) static void initVTShim(){ 35 | void *handle = dlopen ("/System/Library/Frameworks/VideoToolbox.framework/Versions/A/VideoToolbox", RTLD_NOW); 36 | if (!handle) { 37 | handle = dlopen ("/System/Library/PrivateFrameworks/VideoToolbox.framework/Versions/A/VideoToolbox", RTLD_NOW); 38 | if (!handle) { 39 | puts (dlerror()); 40 | abort(); 41 | } 42 | } 43 | realVTDecompressionSessionCreate = (pt_pr_realVTDecompressionSessionCreate) dlsym(handle, "VTDecompressionSessionCreate"); 44 | if(!realVTDecompressionSessionCreate) { 45 | puts ("No VTDecompressionSessionCreate"); 46 | abort(); 47 | } 48 | realVTDecompressionSessionDecodeFrame = (pt_pr_realVTDecompressionSessionDecodeFrame) dlsym(handle, "VTDecompressionSessionDecodeFrame"); 49 | if(!realVTDecompressionSessionDecodeFrame) { 50 | puts ("No VTDecompressionSessionDecodeFrame"); 51 | abort(); 52 | } 53 | realVTDecompressionSessionInvalidate = (pt_pr_realVTDecompressionSessionInvalidate) dlsym(handle, "VTDecompressionSessionInvalidate"); 54 | if(!realVTDecompressionSessionInvalidate) { 55 | puts ("No VTDecompressionSessionInvalidate"); 56 | abort(); 57 | } 58 | realVTDecompressionSessionWaitForAsynchronousFrames = (pt_pr_realVTDecompressionSessionWaitForAsynchronousFrames) dlsym(handle, "VTDecompressionSessionWaitForAsynchronousFrames"); 59 | if(!realVTDecompressionSessionWaitForAsynchronousFrames) { 60 | puts ("No VTDecompressionSessionWaitForAsynchronousFrames"); 61 | abort(); 62 | } 63 | realVTSessionCopyProperty = (pt_pr_realVTSessionCopyProperty) dlsym(handle, "VTSessionCopyProperty"); 64 | if(!realVTSessionCopyProperty) { 65 | puts ("No VTSessionCopyProperty"); 66 | abort(); 67 | } 68 | } 69 | 70 | OSStatus VTDecompressionSessionCreate(CFAllocatorRef allocator, void *videoFormatDescription, CFDictionaryRef videoDecoderSpecification, CFDictionaryRef destinationImageBufferAttributes, const void *outputCallback, void *decompressionSessionOut) { 71 | return realVTDecompressionSessionCreate(allocator,videoFormatDescription,videoDecoderSpecification,destinationImageBufferAttributes,outputCallback,decompressionSessionOut); 72 | } 73 | 74 | OSStatus VTDecompressionSessionDecodeFrame(void *session, void *sampleBuffer, uint32_t decodeFlags, void *sourceFrameRefCon, uint32_t *infoFlagsOut) { 75 | return realVTDecompressionSessionDecodeFrame(session,sampleBuffer, decodeFlags, sourceFrameRefCon,infoFlagsOut); 76 | } 77 | 78 | void VTDecompressionSessionInvalidate(void *session) { 79 | realVTDecompressionSessionInvalidate(session); 80 | } 81 | 82 | OSStatus VTDecompressionSessionWaitForAsynchronousFrames(void *session) { 83 | return realVTDecompressionSessionWaitForAsynchronousFrames(session); 84 | } 85 | 86 | OSStatus VTSessionCopyProperty(void *session, CFStringRef propertyKey, CFAllocatorRef allocator, void *propertyValueOut) { 87 | return realVTSessionCopyProperty(session,propertyKey,allocator,propertyValueOut); 88 | } 89 | -------------------------------------------------------------------------------- /trampoline.c: -------------------------------------------------------------------------------- 1 | // based on https://gist.github.com/steventroughtonsmith/33e2962f85b8b4a9112c 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #define MY_WEIRD_LC_MAIN 0x28 13 | 14 | /* 15 | * The entry_point_command is a replacement for thread_command. 16 | * It is used for main executables to specify the location (file offset) 17 | * of main(). If -stack_size was used at link time, the stacksize 18 | * field will contain the stack size need for the main thread. 19 | */ 20 | // uncomment if fails to compile 21 | //struct entry_point_command { 22 | // uint32_t cmd; /* LC_MAIN only used in MH_EXECUTE filetypes */ 23 | // uint32_t cmdsize; /* 24 */ 24 | // uint64_t entryoff; /* file (__TEXT) offset of main() */ 25 | // uint64_t stacksize;/* if not zero, initial stack size */ 26 | //}; 27 | 28 | int callEntryPointOfImage(char *path, int argc, char **argv,char *envp[], char *apple[]) 29 | { 30 | void *handle; 31 | int (*binary_main)(int binary_argc, char **binary_argv,char *envp[], char *apple[]); 32 | char *error; 33 | int err = 0; 34 | 35 | handle = dlopen (path, RTLD_LAZY); 36 | if (!handle) { 37 | puts (dlerror()); 38 | err = 1; 39 | } 40 | 41 | uint64_t entryoff = 0; 42 | 43 | /* Find LC_MAIN, entryoff */ 44 | 45 | uint32_t count = _dyld_image_count(); 46 | 47 | int didFind = 0; 48 | 49 | for(uint32_t i = 0; i < count; i++) 50 | { 51 | //Name of image (includes full path) 52 | const char *dyld = _dyld_get_image_name(i); 53 | if (!strcmp(dyld, path)) 54 | { 55 | didFind = 1; 56 | const struct mach_header *header = (struct mach_header *)_dyld_get_image_header(i); 57 | 58 | if (header->magic == MH_MAGIC_64) 59 | { 60 | const struct mach_header_64 *header64 = (struct mach_header_64 *)_dyld_get_image_header(i); 61 | 62 | uint8_t *imageHeaderPtr = (uint8_t*)header64; 63 | typedef struct load_command load_command; 64 | 65 | imageHeaderPtr += sizeof(struct mach_header_64); 66 | load_command *command = (load_command*)imageHeaderPtr; 67 | 68 | for(int i = 0; i < header->ncmds > 0; ++i) 69 | { 70 | if(command->cmd == MY_WEIRD_LC_MAIN) 71 | { 72 | struct entry_point_command ucmd = *(struct entry_point_command*)imageHeaderPtr; 73 | 74 | entryoff = ucmd.entryoff; 75 | didFind = 1; 76 | break; 77 | } 78 | 79 | imageHeaderPtr += command->cmdsize; 80 | command = (load_command*)imageHeaderPtr; 81 | } 82 | } 83 | 84 | if (didFind) 85 | { 86 | break; 87 | } 88 | } 89 | } 90 | 91 | if (didFind) 92 | { 93 | binary_main = dlsym(handle, "_mh_execute_header")+entryoff; 94 | if ((error = dlerror()) != NULL) { 95 | puts(error); 96 | err = 1; 97 | } 98 | 99 | if (err == 0) 100 | { 101 | return (*binary_main)(argc, argv,envp,apple); 102 | } else { 103 | abort(); 104 | } 105 | } 106 | return 1; 107 | } 108 | int main(int argc, char *argv[], char *envp[], char *apple[]) { 109 | char pathbuf[10240 + 1]; 110 | char real_executable[10240 + 1+5]; 111 | unsigned int bufsize = sizeof(pathbuf); 112 | 113 | _NSGetExecutablePath( pathbuf, &bufsize); 114 | 115 | strcpy(real_executable, pathbuf); 116 | strcat(real_executable, "_real"); 117 | return callEntryPointOfImage(real_executable,argc,argv,envp,apple); 118 | } 119 | -------------------------------------------------------------------------------- /unsign/Makefile: -------------------------------------------------------------------------------- 1 | CC := gcc 2 | ARCHS := -arch x86_64 3 | CFLAGS := -c -std=c99 -O2 -pedantic -Wall -Wextra $(ARCHS) -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 4 | LD := gcc 5 | LDFLAGS := $(ARCHS) 6 | 7 | unsign: unsign.o endian.o 8 | $(LD) $(LDFLAGS) $^ -o $@ 9 | 10 | endian.o: endian.c endian.h 11 | $(CC) $(CFLAGS) $< -o $@ 12 | 13 | unsign.o: unsign.c endian.h 14 | $(CC) $(CFLAGS) $< -o $@ 15 | 16 | clean: 17 | rm -f unsign endian.o unsign.o 18 | -------------------------------------------------------------------------------- /unsign/README.md: -------------------------------------------------------------------------------- 1 | [![Join the chat at https://gitter.im/unsign-mach-o/Lobby](https://badges.gitter.im/unsign-mach-o/Lobby.svg)](https://gitter.im/unsign-mach-o/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![ISC License](https://img.shields.io/badge/license-ISC%20License-blue.svg)](https://opensource.org/licenses/ISC) 2 | 3 | ### Building 4 | 5 | make 6 | 7 | ### Installing 8 | 9 | 1. `make`. 10 | 2. Move `unsign` to wherever you like. 11 | 12 | ### License 13 | ISC 14 | 15 | ### Original 16 | 17 | http://www.woodmann.com/collaborative/tools/index.php/Unsign 18 | 19 | -------------------------------------------------------------------------------- /unsign/endian.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2002 Thomas Moestl 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 | * SUCH DAMAGE. 25 | * 26 | * $FreeBSD$ 27 | */ 28 | 29 | #include 30 | 31 | #include "endian.h" 32 | 33 | /* Alignment-agnostic encode/decode bytestream to/from little/big endian. */ 34 | 35 | uint16_t be16dec(const void *pp) 36 | { 37 | uint8_t const *p = (uint8_t const *)pp; 38 | 39 | return ((p[0] << 8) | p[1]); 40 | } 41 | 42 | uint32_t be32dec(const void *pp) 43 | { 44 | uint8_t const *p = (uint8_t const *)pp; 45 | 46 | return (((unsigned)p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3]); 47 | } 48 | 49 | uint64_t be64dec(const void *pp) 50 | { 51 | uint8_t const *p = (uint8_t const *)pp; 52 | 53 | return (((uint64_t)be32dec(p) << 32) | be32dec(p + 4)); 54 | } 55 | 56 | uint16_t le16dec(const void *pp) 57 | { 58 | uint8_t const *p = (uint8_t const *)pp; 59 | 60 | return ((p[1] << 8) | p[0]); 61 | } 62 | 63 | uint32_t le32dec(const void *pp) 64 | { 65 | uint8_t const *p = (uint8_t const *)pp; 66 | 67 | return (((unsigned)p[3] << 24) | (p[2] << 16) | (p[1] << 8) | p[0]); 68 | } 69 | 70 | uint64_t le64dec(const void *pp) 71 | { 72 | uint8_t const *p = (uint8_t const *)pp; 73 | 74 | return (((uint64_t)le32dec(p + 4) << 32) | le32dec(p)); 75 | } 76 | 77 | void be16enc(void *pp, uint16_t u) 78 | { 79 | uint8_t *p = (uint8_t *)pp; 80 | 81 | p[0] = (u >> 8) & 0xff; 82 | p[1] = u & 0xff; 83 | } 84 | 85 | void be32enc(void *pp, uint32_t u) 86 | { 87 | uint8_t *p = (uint8_t *)pp; 88 | 89 | p[0] = (u >> 24) & 0xff; 90 | p[1] = (u >> 16) & 0xff; 91 | p[2] = (u >> 8) & 0xff; 92 | p[3] = u & 0xff; 93 | } 94 | 95 | void be64enc(void *pp, uint64_t u) 96 | { 97 | uint8_t *p = (uint8_t *)pp; 98 | 99 | be32enc(p, (uint32_t)(u >> 32)); 100 | be32enc(p + 4, (uint32_t)(u & 0xffffffffU)); 101 | } 102 | 103 | void le16enc(void *pp, uint16_t u) 104 | { 105 | uint8_t *p = (uint8_t *)pp; 106 | 107 | p[0] = u & 0xff; 108 | p[1] = (u >> 8) & 0xff; 109 | } 110 | 111 | void le32enc(void *pp, uint32_t u) 112 | { 113 | uint8_t *p = (uint8_t *)pp; 114 | 115 | p[0] = u & 0xff; 116 | p[1] = (u >> 8) & 0xff; 117 | p[2] = (u >> 16) & 0xff; 118 | p[3] = (u >> 24) & 0xff; 119 | } 120 | 121 | void le64enc(void *pp, uint64_t u) 122 | { 123 | uint8_t *p = (uint8_t *)pp; 124 | 125 | le32enc(p, (uint32_t)(u & 0xffffffffU)); 126 | le32enc(p + 4, (uint32_t)(u >> 32)); 127 | } 128 | -------------------------------------------------------------------------------- /unsign/endian.h: -------------------------------------------------------------------------------- 1 | #ifndef ENDIAN_H 2 | #define ENDIAN_H 3 | 4 | #include 5 | 6 | /* Alignment-agnostic encode/decode bytestream to/from little/big endian. */ 7 | 8 | uint16_t be16dec(const void *pp); 9 | uint32_t be32dec(const void *pp); 10 | uint64_t be64dec(const void *pp); 11 | 12 | uint16_t le16dec(const void *pp); 13 | uint32_t le32dec(const void *pp); 14 | uint64_t le64dec(const void *pp); 15 | 16 | void be16enc(void *pp, uint16_t u); 17 | void be32enc(void *pp, uint32_t u); 18 | void be64enc(void *pp, uint64_t u); 19 | 20 | void le16enc(void *pp, uint16_t u); 21 | void le32enc(void *pp, uint32_t u); 22 | void le64enc(void *pp, uint64_t u); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /unsign/unsign.c: -------------------------------------------------------------------------------- 1 | /* 2 | unsign: remove code signing from Mach-O and Universal Binary files. 3 | 4 | This program removes the LC_CODE_SIGNATURE load command and 5 | zeroes out the signature in the __LINKEDIT section. 6 | 7 | TODO: handle EOF errors better 8 | TODO: handle assumption failures with more grace 9 | 10 | Copyright (c) 2010 11 | 12 | Permission to use, copy, modify, and/or distribute this software for any 13 | purpose with or without fee is hereby granted, provided that the above 14 | copyright notice and this permission notice appear in all copies. 15 | 16 | The software is provided "as is" and the author disclaims all warranties 17 | with regard to this software including all implied warranties of 18 | merchantability and fitness. In no event shall the author be liable for 19 | any special, direct, indirect, or consequential damages or any damages 20 | whatsoever resulting from loss of use, data or profits, whether in an 21 | action of contract, negligence or other tortious action, arising out of 22 | or in connection with the use or performance of this software. 23 | */ 24 | 25 | #include "endian.h" 26 | 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | 34 | #include 35 | #include 36 | #include 37 | 38 | #include 39 | #include 40 | 41 | #define BUF_SZ 4096 42 | 43 | static void 44 | expect(bool b, const char* s) { 45 | if (!b) { 46 | perror(s); 47 | abort(); 48 | } 49 | } 50 | 51 | static size_t 52 | fzero(size_t size, size_t count, FILE *stream) { 53 | for (size_t i = 0; i < count; i++) { 54 | for (size_t j = 0; j < size; j++) { 55 | if (fputc(0, stream) == EOF) { 56 | return i; 57 | } 58 | } 59 | } 60 | return count; 61 | } 62 | 63 | static void 64 | fcopy(size_t size, FILE *in, FILE *out, const char *infile, const char *outfile) { 65 | uint8_t buffer[512]; 66 | while (size) { 67 | size_t to_copy = size; 68 | if(to_copy > sizeof(buffer)) { 69 | to_copy = sizeof(buffer); 70 | } 71 | expect(fread(&buffer, 1, to_copy, in) == to_copy, infile); 72 | expect(fwrite(&buffer, 1, to_copy, out) == to_copy, outfile); 73 | size -= to_copy; 74 | } 75 | } 76 | 77 | static inline uintmax_t 78 | to_align(uintmax_t n, uintmax_t a) { 79 | uintmax_t mask = a - 1; 80 | 81 | assert((a & mask) == 0); 82 | return (a - (n & mask)) & mask; 83 | } 84 | 85 | static void 86 | align_file(FILE* f, const char *name, uintmax_t align) { 87 | off_t o = ftello(f); 88 | expect(o != -1, name); 89 | 90 | size_t to_write = to_align(o, align); 91 | expect(fzero(1, to_write, f) == to_write, name); 92 | } 93 | 94 | static void 95 | macho_unsign(FILE *in, FILE *out, const char *infile, const char *outfile, off_t size) { 96 | off_t start = ftello(in); 97 | expect(start != -1, infile); 98 | 99 | uint8_t magicb[4]; 100 | expect(fread(&magicb, sizeof(magicb), 1, in) == 1, infile); 101 | uint32_t magicbe = be32dec(&magicb); 102 | uint32_t magicle = le32dec(&magicb); 103 | 104 | bool big_endian, sixtyfourbits; 105 | if (magicbe == MH_MAGIC) { 106 | big_endian = true; 107 | sixtyfourbits = false; 108 | } else if (magicbe == MH_MAGIC_64) { 109 | big_endian = true; 110 | sixtyfourbits = true; 111 | } else if (magicle == MH_MAGIC) { 112 | big_endian = false; 113 | sixtyfourbits = false; 114 | } else if (magicle == MH_MAGIC_64) { 115 | big_endian = false; 116 | sixtyfourbits = true; 117 | } else { 118 | fprintf(stderr, "Unknown mach-o magic number %02x %02x %02x %02x\n", 119 | magicb[0], magicb[1], magicb[2], magicb[3]); 120 | abort(); 121 | } 122 | 123 | expect(fseeko(in, start, SEEK_SET) != -1, infile); 124 | 125 | uint32_t (*x32dec)(const void*) = big_endian ? be32dec : le32dec; 126 | void (*x32enc)(void*, uint32_t) = big_endian ? be32enc : le32enc; 127 | 128 | uint32_t ncmds; 129 | uint32_t sizeofcmds; 130 | if (sixtyfourbits) { 131 | struct mach_header_64 header; 132 | expect(fread(&header, sizeof(header), 1, in) == 1, infile); 133 | ncmds = x32dec(&header.ncmds); 134 | sizeofcmds = x32dec(&header.sizeofcmds); 135 | x32enc(&header.ncmds, ncmds - 1); 136 | x32enc(&header.sizeofcmds, sizeofcmds - sizeof(struct linkedit_data_command)); 137 | expect(fwrite(&header, sizeof(header), 1, out) == 1, outfile); 138 | } else { 139 | struct mach_header header; 140 | expect(fread(&header, sizeof(header), 1, in) == 1, infile); 141 | ncmds = x32dec(&header.ncmds); 142 | sizeofcmds = x32dec(&header.sizeofcmds); 143 | x32enc(&header.ncmds, ncmds - 1); 144 | x32enc(&header.sizeofcmds, sizeofcmds - sizeof(struct linkedit_data_command)); 145 | expect(fwrite(&header, sizeof(header), 1, out) == 1, outfile); 146 | } 147 | 148 | uint32_t dataoff = 0, datasize = 0; 149 | for (uint32_t i = 0; i < ncmds; i++) { 150 | off_t lc_start = ftello(in); 151 | expect(lc_start != -1, infile); 152 | 153 | struct load_command lc; 154 | expect(fread(&lc, sizeof(lc), 1, in) == 1, infile); 155 | uint32_t cmd = x32dec(&lc.cmd); 156 | uint32_t cmdsize = x32dec(&lc.cmdsize); 157 | 158 | expect(fseeko(in, lc_start, SEEK_SET) != -1, infile); 159 | if (cmd != LC_CODE_SIGNATURE) { 160 | fcopy(cmdsize, in, out, infile, outfile); 161 | } else { 162 | assert(dataoff == 0); 163 | struct linkedit_data_command lc_sig; 164 | assert(cmdsize == sizeof(lc_sig)); 165 | expect(fread(&lc_sig, sizeof(lc_sig), 1, in) == 1, infile); 166 | dataoff = x32dec(&lc_sig.dataoff); 167 | assert(dataoff != 0); 168 | datasize = x32dec(&lc_sig.datasize); 169 | } 170 | } 171 | assert(dataoff != 0); 172 | expect(fzero(sizeof(struct linkedit_data_command), 1, out) == 1, outfile); 173 | off_t after_lc = ftello(in); 174 | expect(after_lc != -1, infile); 175 | fcopy(dataoff - (after_lc - start), in, out, infile, outfile); 176 | expect(fzero(1, datasize, out) == datasize, outfile); 177 | expect(fseeko(in, datasize, SEEK_CUR) != -1, infile); 178 | off_t after_data = ftello(in); 179 | expect(after_data != -1, infile); 180 | fcopy(size - (after_data - start), in, out, infile, outfile); 181 | } 182 | 183 | static void 184 | ub_unsign(FILE *in, FILE *out, const char *infile, const char *outfile, off_t size) { 185 | uint8_t magicb[4]; 186 | expect(fread(&magicb, sizeof(magicb), 1, in) == 1, infile); 187 | if (be32dec(&magicb) != FAT_MAGIC) { 188 | expect(! fseeko(in, 0, SEEK_SET), infile); 189 | macho_unsign(in, out, infile, outfile, size); 190 | return; 191 | } 192 | 193 | uint8_t nfat_archb[4]; 194 | expect(fread(&nfat_archb, sizeof(nfat_archb), 1, in) == 1, infile); 195 | 196 | expect(fwrite(&magicb, sizeof(magicb), 1, out) == 1, outfile); 197 | expect(fwrite(&nfat_archb, sizeof(nfat_archb), 1, out) == 1, outfile); 198 | 199 | uint32_t nfat_arch = be32dec(&nfat_archb); 200 | 201 | off_t outarcho = ftello(out); 202 | expect(outarcho != -1, outfile); 203 | 204 | expect(fzero(sizeof(struct fat_arch), nfat_arch, out) == nfat_arch, outfile); 205 | 206 | for (uint32_t i = 0; i < nfat_arch; i++) { 207 | struct fat_arch arch; 208 | expect(fread(&arch, sizeof(arch), 1, in) == 1, infile); 209 | off_t inarcho = ftello(in); 210 | expect(inarcho != -1, infile); 211 | 212 | uint32_t alignment = be32dec(&arch.align); 213 | assert(alignment < 32); 214 | alignment = 1 << alignment; 215 | align_file(out, outfile, alignment); 216 | 217 | expect(! fseeko(in, be32dec(&arch.offset), SEEK_SET), infile); 218 | 219 | off_t offset = ftello(out); 220 | 221 | macho_unsign(in, out, infile, outfile, be32dec(&arch.size)); 222 | 223 | expect(! fseeko(in, inarcho, SEEK_SET), infile); 224 | 225 | off_t end = ftello(out); 226 | expect(end != -1, outfile); 227 | off_t size = end - offset; 228 | 229 | errno = ERANGE; 230 | uint32_t uoffset = offset; 231 | expect(uoffset == offset, "offset"); 232 | uint32_t usize = size; 233 | expect(usize == size, "size"); 234 | 235 | be32enc(&arch.offset, uoffset); 236 | be32enc(&arch.size, usize); 237 | 238 | off_t outo = ftello(out); 239 | expect(outo != -1, outfile); 240 | 241 | expect(! fseeko(out, outarcho, SEEK_SET), outfile); 242 | expect(fwrite(&arch, sizeof(arch), 1, out) == 1, outfile); 243 | outarcho = ftello(out); 244 | expect(outarcho != -1, outfile); 245 | expect(! fseeko(out, outo, SEEK_SET), outfile); 246 | } 247 | } 248 | 249 | const char *suffix = ".unsigned"; 250 | 251 | int 252 | main(int argc, const char *const *argv) { 253 | if(argc < 2 || argc > 3) { 254 | puts("usage: unsign file [outfile]"); 255 | return 1; 256 | } 257 | 258 | const char *infile = argv[1]; 259 | char *outfile; 260 | if(argc > 2) { 261 | outfile = strdup(argv[2]); 262 | expect(outfile, "allocate"); 263 | } else { 264 | outfile = malloc(strlen(infile) + strlen(suffix) + 1); 265 | expect(outfile, "allocate"); 266 | sprintf(outfile, "%s%s", infile, suffix); 267 | } 268 | 269 | int infd = open(infile, O_RDONLY); 270 | expect(infd != -1, infile); 271 | struct stat stat; 272 | expect(fstat(infd, &stat) != -1, infile); 273 | 274 | 275 | FILE *in = fdopen(infd, "rb"); 276 | expect(in, infile); 277 | 278 | FILE * outtmp = tmpfile(); 279 | expect(outtmp, "unable to open temp file"); 280 | 281 | ub_unsign(in, outtmp, infile, outfile, stat.st_size); 282 | 283 | fclose(in); 284 | 285 | int outfd = open(outfile, O_CREAT | O_TRUNC | O_WRONLY, 286 | S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH /*755*/); 287 | expect(outfd != -1, outfile); 288 | FILE *outactual = fdopen(outfd, "wb"); 289 | expect(outactual, outfile); 290 | 291 | unsigned char buf[BUF_SZ]; 292 | 293 | fseek(outtmp, 0, SEEK_SET); 294 | do { 295 | size_t bytes_read = fread(buf, 1, BUF_SZ, outtmp); 296 | 297 | if (bytes_read > 0) { 298 | size_t bytes_written = fwrite(buf, 1, bytes_read, outactual); 299 | expect(bytes_written == bytes_read, "didnt write output file completely"); 300 | } 301 | } while (!feof(outtmp)); 302 | } 303 | --------------------------------------------------------------------------------