├── .gitattributes
├── .gitignore
├── LICENSE
├── README.md
├── cpbypass32_ms
├── Makefile
├── Tweak.mm
├── Tweak.x
├── control
├── cpbypass.plist
└── layout
│ └── usr
│ └── bin
│ └── sysent_patch
├── cpbypass64_ms
├── Makefile
├── Tweak.mm
├── Tweak.x
├── control
└── cpbypass.plist
└── kernel
├── README.md
├── mk32.sh
├── mk64.sh
├── patchfinder32
├── patchfinder32.c
└── patchfinder32.h
├── patchfinder64
└── .empty
├── payload
├── mk32.sh
├── payload32.h
├── stat_sysent32.c
└── stat_sysent64.c
├── sysent_patch32.c
├── sysent_patch64.c
└── tfp0.xml
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 |
--------------------------------------------------------------------------------
/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 | # CP-Bypass Public
2 |
3 | ****による脱獄検知を回避するTweak/Patch
4 |
5 | ## 動作環境
6 | - non-KPP/KTRR devices
7 | - KPP devices (iOS 10.0-10.3.3)
8 |
9 | ## 使い方
10 | ### kernel patch
11 | 32-bitの場合: インストール後、Terminalから`sysent_patch -p`を実行してカーネルにパッチを適用。
12 | 64-bit (KPP devices)の場合: KPP bypassを行ってCPBypassのカーネルパッチを追加した脱獄を適用。
13 |
14 | ### mobile substrate
15 | 共通: `/Library/MobileSubstrate/DynamicLibraries/cpbypass.plist`に回避を実行したいアプリのバンドルIDを追加して起動。
16 |
17 | ## 対応状況
18 | ### デバイス
19 | 32-bitプロセッサ搭載のiOS 10デバイスであればパッチを実行することで動きます。
20 | 64-bitプロセッサ搭載デバイスの場合、iOS 8.4.1以下、またはiOS 10.0-10.3.3のKPPデバイスで動作確認済です。ただし、iOS 10.0-10.3.3ではカーネルパッチを行う際にKPP(/KTRR) Bypassが必要となります。
21 |
22 | ### アプリ対応状況一覧
23 |
24 |
25 | ### 対応アプリの追加
26 | アプリによって確認しているパスに差異があるため、一部回避できないものがあります。ほとんどの場合はsyscallでの検知以外が入っているため、こちらの回避も必要となります。
27 | 32-bitデバイスを使用できるアプリであれば、カーネルにパッチすることでIOLogから検知パスの情報を得ることができます。
28 | ****の検知手法が現状のまま変わらなければsyscallによる検知の回避は簡単に対応可能です。
29 | 64-bitデバイスでは現バージョンではログの出力がうまくいっていないようです。
30 |
31 | ## Credits
32 | [cp-c](https://github.com/akusio/cp-c) by akusio
33 |
34 | 2020/12/12 made by dora2ios
35 | 2020/12/16 update: for 64bit
36 | 2021/02/28 public release (under GPLv3)
37 |
--------------------------------------------------------------------------------
/cpbypass32_ms/Makefile:
--------------------------------------------------------------------------------
1 | include $(THEOS)/makefiles/common.mk
2 | ARCHS = armv7
3 | TWEAK_NAME = cpbypass
4 |
5 | cpbypass_FILES = Tweak.x
6 | cpbypass_CFLAGS = -fobjc-arc
7 | cpbypass_FRAMEWORKS = UIKit
8 | include $(THEOS_MAKE_PATH)/tweak.mk
9 |
10 | after-install::
11 | install.exec "killall -9 SpringBoard"
--------------------------------------------------------------------------------
/cpbypass32_ms/Tweak.mm:
--------------------------------------------------------------------------------
1 | /* Tweak.mm: Bypass file detection with MS hooking
2 | * 2020/12/12
3 | * made by dora2ios
4 | */
5 |
6 | #import
7 | #import
8 | #import
9 |
10 | #import
11 | #import
12 | #import
13 | #import
14 | #import
15 | #import
16 | #include
17 | #include
18 | #import
19 | #import
20 | #import
21 | #include
22 | #include
23 | #include
24 |
25 | int checkfiles(const char *path){
26 |
27 | /* **f**u****c--*k* v3.0.0 */
28 |
29 | if (strcasecmp(path, "/User") == 0 ||
30 | strcasecmp(path, "/boot") == 0 ||
31 | strcasecmp(path, "/lib") == 0 ||
32 | strcasecmp(path, "/mnt") == 0 ||
33 | strcasecmp(path, "/.cydia_no_stash") == 0 ||
34 | strcasecmp(path, "/bin/bash") == 0 ||
35 | strcasecmp(path, "/bin/sh") == 0 ||
36 | strcasecmp(path, "/Applications/Cydia.app") == 0 ||
37 | strcasecmp(path, "/Library/MobileSubstrate") == 0 ||
38 | strcasecmp(path, "/Library/MobileSubstrate/DynamicLibraries") == 0 ||
39 | strcasecmp(path, "/Library/MobileSubstrate/MobileSubstrate.dylib") == 0 ||
40 | strcasecmp(path, "/Library/Frameworks/CydiaSubstrate.framework") == 0 ||
41 | strcasecmp(path, "/Library/Frameworks/CydiaSubstrate.framework/Libraries") == 0 ||
42 | strcasecmp(path, "/Library/Frameworks/CydiaSubstrate.framework/Libraries/SubstrateLoader.dylib") == 0 ||
43 | strcasecmp(path, "/Library/Frameworks/CydiaSubstrate.framework/CydiaSubstrate") == 0 ||
44 | strcasecmp(path, "/private/var/lib") == 0 ||
45 | strcasecmp(path, "/var/lib") == 0 ||
46 | strcasecmp(path, "/private/var/lib/apt") == 0 ||
47 | strcasecmp(path, "/var/lib/apt") == 0 ||
48 | strcasecmp(path, "/private/var/db/stash") == 0 ||
49 | strcasecmp(path, "/var/db/stash") == 0 ||
50 | strcasecmp(path, "/private/var/stash") == 0 ||
51 | strcasecmp(path, "/var/stash") == 0 ||
52 | strcasecmp(path, "/private/var/mobile/Library/Cydia") == 0 ||
53 | strcasecmp(path, "/var/mobile/Library/Cydia") == 0 ||
54 | strcasecmp(path, "/private/var/mobile/Library/Caches/com.saurik.Cydia") == 0 ||
55 | strcasecmp(path, "/var/mobile/Library/Caches/com.saurik.Cydia") == 0 ||
56 | strcasecmp(path, "/private/var/mobile/Library/Preferences/com.saurik.Cydia.plist") == 0 ||
57 | strcasecmp(path, "/var/mobile/Library/Preferences/com.saurik.Cydia.plist") == 0 ||
58 | strcasecmp(path, "/private/etc/ssh") == 0 ||
59 | strcasecmp(path, "/etc/ssh") == 0 ||
60 | strcasecmp(path, "/private/etc/apt") == 0 ||
61 | strcasecmp(path, "/etc/apt") == 0 ||
62 | strcasecmp(path, "/usr/bin/ssh") == 0 ||
63 | strcasecmp(path, "/usr/sbin/sshd") == 0 ||
64 | strcasecmp(path, "/usr/libexec/cydia") == 0){
65 | return 0;
66 | }
67 | return -1;
68 | }
69 |
70 | %group hookf
71 |
72 | /* ---- Bypass by akusio's cp-c https://github.com/akusio/cp-c/blob/master/Tweak.xm#L29 ---- */
73 | struct dirent* readdir(DIR* dir);
74 | %hookf(struct dirent*,readdir,DIR* dir)
75 | {
76 |
77 | struct dirent* dire;
78 |
79 | while((dire = %orig(dir)) != NULL)
80 | {
81 | if (strcasecmp(dire->d_name,"User") == 0)
82 | {
83 | strcpy(dire->d_name,"System");
84 | }
85 | if (strcasecmp(dire->d_name,"boot") == 0)
86 | {
87 | strcpy(dire->d_name,"System");
88 | }
89 | if (strcasecmp(dire->d_name,"lib") == 0)
90 | {
91 | strcpy(dire->d_name,"System");
92 | }
93 | if (strcasecmp(dire->d_name,"mnt") == 0)
94 | {
95 | strcpy(dire->d_name,"System");
96 | }
97 |
98 | return dire;
99 | }
100 | return %orig;
101 |
102 | }
103 | /* ---- end ---- */
104 |
105 | %hookf(FILE *, fopen, const char *path, const char *mode) {
106 | if (checkfiles(path) == 0){
107 | errno = ENOENT;
108 | return NULL;
109 | }
110 |
111 | return %orig;
112 | }
113 |
114 | %hookf(int, stat, const char *path, struct stat *buf) {
115 | if (checkfiles(path) == 0){
116 | errno = ENOENT;
117 | return -1;
118 | }
119 |
120 | return %orig;
121 | }
122 |
123 | %hookf(int, lstat, const char *path, struct stat *buf) {
124 | if (checkfiles(path) == 0){
125 | errno = ENOENT;
126 | return -1;
127 | }
128 |
129 | return %orig;
130 | }
131 |
132 | %hookf(int, getattrlist, const char* path, struct attrlist * attrList, void * attrBuf, size_t attrBufSize, unsigned long options){
133 | if (checkfiles(path) == 0){
134 | errno = ENOENT;
135 | return -1;
136 | }
137 |
138 | return %orig;
139 | }
140 |
141 | %hookf(DIR *,__opendir2,const char *path, int buf){
142 | if (checkfiles(path) == 0){
143 | errno = ENOENT;
144 | return NULL;
145 | }
146 |
147 | return %orig;
148 | }
149 | %end
150 |
151 | static int (*orig_open)(const char *path, int oflag, ...);
152 | static int hook_open(const char *path, int oflag, ...) { // not need ?
153 | va_list args;
154 | int fd = 0;
155 |
156 | if (checkfiles(path) == 0){
157 | errno = ENOENT;
158 | return -1;
159 | }
160 |
161 | if ((oflag & O_CREAT) == O_CREAT){
162 | mode_t mode;
163 |
164 | va_start(args, oflag);
165 | mode = (mode_t) va_arg(args, int);
166 | va_end(args);
167 |
168 | fd = orig_open(path, oflag, mode);
169 | } else {
170 | fd = orig_open(path, oflag);
171 | }
172 | return fd;
173 | }
174 |
175 | %ctor{
176 | %init(hookf);
177 | MSHookFunction((void *) open, (void *) hook_open, (void **) &orig_open);
178 | }
179 |
--------------------------------------------------------------------------------
/cpbypass32_ms/Tweak.x:
--------------------------------------------------------------------------------
1 | Tweak.mm
--------------------------------------------------------------------------------
/cpbypass32_ms/control:
--------------------------------------------------------------------------------
1 | Package: jp.dora2ios.cpbypass
2 | Name: CP-Bypass
3 | Depends: mobilesubstrate, firmware(>=9.1)
4 | Version: 1.4.1
5 | Architecture: iphoneos-arm
6 | Description: JB detection bypass for CrackProof.
7 | Maintainer: dora2ios
8 | Author: dora2ios
9 | Section: System
10 |
--------------------------------------------------------------------------------
/cpbypass32_ms/cpbypass.plist:
--------------------------------------------------------------------------------
1 | {
2 | Filter = {
3 | Bundles = ();
4 | };
5 | }
--------------------------------------------------------------------------------
/cpbypass32_ms/layout/usr/bin/sysent_patch:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dora2ios/CPBypass-public/935df36bf9b8239aa23509c95b8dbe8dee9283f1/cpbypass32_ms/layout/usr/bin/sysent_patch
--------------------------------------------------------------------------------
/cpbypass64_ms/Makefile:
--------------------------------------------------------------------------------
1 | include $(THEOS)/makefiles/common.mk
2 | ARCHS = arm64
3 | TWEAK_NAME = cpbypass
4 |
5 | cpbypass_FILES = Tweak.x
6 | cpbypass_CFLAGS = -fobjc-arc
7 | cpbypass_FRAMEWORKS = UIKit
8 | include $(THEOS_MAKE_PATH)/tweak.mk
9 |
10 | after-install::
11 | install.exec "killall -9 SpringBoard"
--------------------------------------------------------------------------------
/cpbypass64_ms/Tweak.mm:
--------------------------------------------------------------------------------
1 | /* Tweak.mm: Bypass file detection with MS hooking
2 | * 2020/12/12
3 | * made by dora2ios
4 | */
5 |
6 | #import
7 | #import
8 | #import
9 |
10 | #import
11 | #import
12 | #import
13 | #import
14 | #import
15 | #import
16 | #include
17 | #include
18 | #import
19 | #import
20 | #import
21 | #include
22 | #include
23 | #include
24 |
25 | int checkfiles(const char *path){
26 |
27 | /* ***f****u**c***k* v3.0.0 */
28 |
29 | if (strcasecmp(path, "/User") == 0 ||
30 | strcasecmp(path, "/boot") == 0 ||
31 | strcasecmp(path, "/lib") == 0 ||
32 | strcasecmp(path, "/mnt") == 0 ||
33 | strcasecmp(path, "/.cydia_no_stash") == 0 ||
34 | strcasecmp(path, "/bin/bash") == 0 ||
35 | strcasecmp(path, "/bin/sh") == 0 ||
36 | strcasecmp(path, "/Applications/Cydia.app") == 0 ||
37 | strcasecmp(path, "/Library/MobileSubstrate") == 0 ||
38 | strcasecmp(path, "/Library/MobileSubstrate/DynamicLibraries") == 0 ||
39 | strcasecmp(path, "/Library/MobileSubstrate/MobileSubstrate.dylib") == 0 ||
40 | strcasecmp(path, "/Library/Frameworks/CydiaSubstrate.framework") == 0 ||
41 | strcasecmp(path, "/Library/Frameworks/CydiaSubstrate.framework/Libraries") == 0 ||
42 | strcasecmp(path, "/Library/Frameworks/CydiaSubstrate.framework/Libraries/SubstrateLoader.dylib") == 0 ||
43 | strcasecmp(path, "/Library/Frameworks/CydiaSubstrate.framework/CydiaSubstrate") == 0 ||
44 | strcasecmp(path, "/private/var/lib") == 0 ||
45 | strcasecmp(path, "/var/lib") == 0 ||
46 | strcasecmp(path, "/private/var/lib/apt") == 0 ||
47 | strcasecmp(path, "/var/lib/apt") == 0 ||
48 | strcasecmp(path, "/private/var/db/stash") == 0 ||
49 | strcasecmp(path, "/var/db/stash") == 0 ||
50 | strcasecmp(path, "/private/var/stash") == 0 ||
51 | strcasecmp(path, "/var/stash") == 0 ||
52 | strcasecmp(path, "/private/var/mobile/Library/Cydia") == 0 ||
53 | strcasecmp(path, "/var/mobile/Library/Cydia") == 0 ||
54 | strcasecmp(path, "/private/var/mobile/Library/Caches/com.saurik.Cydia") == 0 ||
55 | strcasecmp(path, "/var/mobile/Library/Caches/com.saurik.Cydia") == 0 ||
56 | strcasecmp(path, "/private/var/mobile/Library/Preferences/com.saurik.Cydia.plist") == 0 ||
57 | strcasecmp(path, "/var/mobile/Library/Preferences/com.saurik.Cydia.plist") == 0 ||
58 | strcasecmp(path, "/private/etc/ssh") == 0 ||
59 | strcasecmp(path, "/etc/ssh") == 0 ||
60 | strcasecmp(path, "/private/etc/apt") == 0 ||
61 | strcasecmp(path, "/etc/apt") == 0 ||
62 | strcasecmp(path, "/usr/bin/ssh") == 0 ||
63 | strcasecmp(path, "/usr/sbin/sshd") == 0 ||
64 | strcasecmp(path, "/usr/libexec/cydia") == 0){
65 | return 0;
66 | }
67 | return -1;
68 | }
69 |
70 | %group hookf
71 |
72 | /* ---- Bypass by akusio's cp-c https://github.com/akusio/cp-c/blob/master/Tweak.xm#L29 ---- */
73 | struct dirent* readdir(DIR* dir);
74 | %hookf(struct dirent*,readdir,DIR* dir)
75 | {
76 |
77 | struct dirent* dire;
78 |
79 | while((dire = %orig(dir)) != NULL)
80 | {
81 | if (strcasecmp(dire->d_name,"User") == 0)
82 | {
83 | strcpy(dire->d_name,"System");
84 | }
85 | if (strcasecmp(dire->d_name,"boot") == 0)
86 | {
87 | strcpy(dire->d_name,"System");
88 | }
89 | if (strcasecmp(dire->d_name,"lib") == 0)
90 | {
91 | strcpy(dire->d_name,"System");
92 | }
93 | if (strcasecmp(dire->d_name,"mnt") == 0)
94 | {
95 | strcpy(dire->d_name,"System");
96 | }
97 |
98 | return dire;
99 | }
100 | return %orig;
101 |
102 | }
103 | /* ---- end ---- */
104 |
105 | %hookf(FILE *, fopen, const char *path, const char *mode) {
106 | if (checkfiles(path) == 0){
107 | errno = ENOENT;
108 | return NULL;
109 | }
110 |
111 | return %orig;
112 | }
113 |
114 | %hookf(int, stat, const char *path, struct stat *buf) {
115 | if (checkfiles(path) == 0){
116 | errno = ENOENT;
117 | return -1;
118 | }
119 |
120 | return %orig;
121 | }
122 |
123 | %hookf(int, lstat, const char *path, struct stat *buf) {
124 | if (checkfiles(path) == 0){
125 | errno = ENOENT;
126 | return -1;
127 | }
128 |
129 | return %orig;
130 | }
131 |
132 |
133 | %hookf(int, getattrlist, const char* path, struct attrlist * attrList, void * attrBuf, size_t attrBufSize, unsigned long options){
134 | if (checkfiles(path) == 0){
135 | errno = ENOENT;
136 | return -1;
137 | }
138 |
139 | return %orig;
140 | }
141 |
142 | %hookf(DIR *,__opendir2,const char *path, int buf){
143 | if (checkfiles(path) == 0){
144 | errno = ENOENT;
145 | return NULL;
146 | }
147 |
148 | return %orig;
149 | }
150 | %end
151 |
152 | static int (*orig_open)(const char *path, int oflag, ...);
153 | static int hook_open(const char *path, int oflag, ...) { // not need ?
154 | va_list args;
155 | int fd = 0;
156 |
157 | if (checkfiles(path) == 0){
158 | errno = ENOENT;
159 | return -1;
160 | }
161 |
162 | if ((oflag & O_CREAT) == O_CREAT){
163 | mode_t mode;
164 |
165 | va_start(args, oflag);
166 | mode = (mode_t) va_arg(args, int);
167 | va_end(args);
168 |
169 | fd = orig_open(path, oflag, mode);
170 | } else {
171 | fd = orig_open(path, oflag);
172 | }
173 | return fd;
174 | }
175 |
176 | %ctor{
177 | %init(hookf);
178 | MSHookFunction((void *) open, (void *) hook_open, (void **) &orig_open);
179 | }
180 |
--------------------------------------------------------------------------------
/cpbypass64_ms/Tweak.x:
--------------------------------------------------------------------------------
1 | Tweak.mm
--------------------------------------------------------------------------------
/cpbypass64_ms/control:
--------------------------------------------------------------------------------
1 | Package: jp.dora2ios.cpbypass64
2 | Name: CP-Bypass64
3 | Depends: mobilesubstrate
4 | Version: 0.0.2
5 | Architecture: iphoneos-arm
6 | Description: JB detection bypass for CrackProof.
7 | Maintainer: dora2ios
8 | Author: dora2ios
9 | Section: System
10 |
--------------------------------------------------------------------------------
/cpbypass64_ms/cpbypass.plist:
--------------------------------------------------------------------------------
1 | {
2 | Filter = {
3 | Bundles = ();
4 | };
5 | }
--------------------------------------------------------------------------------
/kernel/README.md:
--------------------------------------------------------------------------------
1 | # CP-Bypass - kernel
2 |
3 | syscallによる脱獄検知を回避するKernel Patch
4 | 注意: ほとんどのアプリでは通常のファイル検知も行なっているようなので、こちらはMobileSubstrateによるHookingで対応する必要があります。
5 |
6 | ## 動作環境
7 | - non-KPP/KTRR devices
8 | - KPP devices (iOS 10.0-10.3.3)
9 |
10 | ## 対応状況
11 | ### armv7
12 | - sysent_patch32.cをビルドして脱獄環境でカーネルパッチすることで動作するようになります。
13 | - コンソールからkernelプロセスを確認することで_stat()が呼ばれた際のパスの確認が行えます。
14 | 32-bitのiOS 7.1-9.0.2 (8.4.1を除く)で脱獄している場合、脱獄ツールによるsb_evaluate()をHookするpayloadと位置が競合する可能性があります。パッチ前にpayloadの位置を確認した上で、被るようならアドレスをズラしてください。
15 |
16 |
17 | ### arm64(KPP devices)
18 | sysent_patch64.cは不完全なコードです。このコードはyalu102のKPP bypassを利用する脱獄に組み込むことで利用できます。
19 | 64bit環境では現在IOLogによるログ出力が機能していません。
20 |
21 |
--------------------------------------------------------------------------------
/kernel/mk32.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | xcrun -sdk iphoneos clang -arch armv7 sysent_patch32.c patchfinder32/patchfinder32.c -o sysent_patch32; ldid -Stfp0.xml sysent_patch32; mv -v sysent_patch32 sysent_patch
3 |
--------------------------------------------------------------------------------
/kernel/mk64.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | xcrun -sdk iphoneos clang -arch arm64 -o sysent_patch64 sysent_patch64.c patchfinder64/patchfinder64.c; ldid -Stfp0.xml sysent_patch64
3 |
--------------------------------------------------------------------------------
/kernel/patchfinder32/patchfinder32.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | #include
5 | #include
6 |
7 | #include "patchfinder32.h"
8 |
9 | /* --- planetbeing patchfinder --- */
10 | static uint32_t bit_range(uint32_t x, int start, int end) {
11 | x = (x << (31 - start)) >> (31 - start);
12 | x = (x >> end);
13 | return x;
14 | }
15 |
16 | static uint32_t ror(uint32_t x, int places) {
17 | return (x >> places) | (x << (32 - places));
18 | }
19 |
20 | static int thumb_expand_imm_c(uint16_t imm12) {
21 | if (bit_range(imm12, 11, 10) == 0) {
22 | switch (bit_range(imm12, 9, 8)) {
23 | case 0:
24 | return bit_range(imm12, 7, 0);
25 | case 1:
26 | return (bit_range(imm12, 7, 0) << 16) | bit_range(imm12, 7, 0);
27 | case 2:
28 | return (bit_range(imm12, 7, 0) << 24) | (bit_range(imm12, 7, 0) << 8);
29 | case 3:
30 | return (bit_range(imm12, 7, 0) << 24) | (bit_range(imm12, 7, 0) << 16) | (bit_range(imm12, 7, 0) << 8) | bit_range(imm12, 7, 0);
31 | default:
32 | return 0;
33 | }
34 | } else {
35 | uint32_t unrotated_value = 0x80 | bit_range(imm12, 6, 0);
36 | return ror(unrotated_value, bit_range(imm12, 11, 7));
37 | }
38 | }
39 |
40 | static int insn_is_32bit(uint16_t *i) {
41 | return (*i & 0xe000) == 0xe000 && (*i & 0x1800) != 0x0;
42 | }
43 |
44 | static int insn_is_bl(uint16_t *i) {
45 | if ((*i & 0xf800) == 0xf000 && (*(i + 1) & 0xd000) == 0xd000)
46 | return 1;
47 | else if ((*i & 0xf800) == 0xf000 && (*(i + 1) & 0xd001) == 0xc000)
48 | return 1;
49 | else
50 | return 0;
51 | }
52 |
53 | static uint32_t insn_bl_imm32(uint16_t *i) {
54 | uint16_t insn0 = *i;
55 | uint16_t insn1 = *(i + 1);
56 | uint32_t s = (insn0 >> 10) & 1;
57 | uint32_t j1 = (insn1 >> 13) & 1;
58 | uint32_t j2 = (insn1 >> 11) & 1;
59 | uint32_t i1 = ~(j1 ^ s) & 1;
60 | uint32_t i2 = ~(j2 ^ s) & 1;
61 | uint32_t imm10 = insn0 & 0x3ff;
62 | uint32_t imm11 = insn1 & 0x7ff;
63 | uint32_t imm32 = (imm11 << 1) | (imm10 << 12) | (i2 << 22) | (i1 << 23) | (s ? 0xff000000 : 0);
64 | return imm32;
65 | }
66 |
67 | static int insn_is_b_conditional(uint16_t *i) {
68 | return (*i & 0xF000) == 0xD000 && (*i & 0x0F00) != 0x0F00 && (*i & 0x0F00) != 0xE;
69 | }
70 |
71 | static int insn_is_b_unconditional(uint16_t *i) {
72 | if ((*i & 0xF800) == 0xE000)
73 | return 1;
74 | else if ((*i & 0xF800) == 0xF000 && (*(i + 1) & 0xD000) == 9)
75 | return 1;
76 | else
77 | return 0;
78 | }
79 |
80 | static int insn_is_ldr_literal(uint16_t *i) {
81 | return (*i & 0xF800) == 0x4800 || (*i & 0xFF7F) == 0xF85F;
82 | }
83 |
84 | static int insn_ldr_literal_rt(uint16_t *i) {
85 | if ((*i & 0xF800) == 0x4800)
86 | return (*i >> 8) & 7;
87 | else if ((*i & 0xFF7F) == 0xF85F)
88 | return (*(i + 1) >> 12) & 0xF;
89 | else
90 | return 0;
91 | }
92 |
93 | static int insn_ldr_literal_imm(uint16_t *i) {
94 | if ((*i & 0xF800) == 0x4800)
95 | return (*i & 0xF) << 2;
96 | else if ((*i & 0xFF7F) == 0xF85F)
97 | return (*(i + 1) & 0xFFF) * (((*i & 0x0800) == 0x0800) ? 1 : -1);
98 | else
99 | return 0;
100 | }
101 |
102 | static int insn_ldr_imm_rt(uint16_t *i) {
103 | return (*i & 7);
104 | }
105 |
106 | static int insn_ldr_imm_rn(uint16_t *i) {
107 | return ((*i >> 3) & 7);
108 | }
109 |
110 | static int insn_ldr_imm_imm(uint16_t *i) {
111 | return ((*i >> 6) & 0x1F);
112 | }
113 |
114 | static int insn_is_add_reg(uint16_t *i) {
115 | if ((*i & 0xFE00) == 0x1800)
116 | return 1;
117 | else if ((*i & 0xFF00) == 0x4400)
118 | return 1;
119 | else if ((*i & 0xFFE0) == 0xEB00)
120 | return 1;
121 | else
122 | return 0;
123 | }
124 |
125 | static int insn_add_reg_rd(uint16_t *i) {
126 | if ((*i & 0xFE00) == 0x1800)
127 | return (*i & 7);
128 | else if ((*i & 0xFF00) == 0x4400)
129 | return (*i & 7) | ((*i & 0x80) >> 4);
130 | else if ((*i & 0xFFE0) == 0xEB00)
131 | return (*(i + 1) >> 8) & 0xF;
132 | else
133 | return 0;
134 | }
135 |
136 | static int insn_add_reg_rn(uint16_t *i) {
137 | if ((*i & 0xFE00) == 0x1800)
138 | return ((*i >> 3) & 7);
139 | else if ((*i & 0xFF00) == 0x4400)
140 | return (*i & 7) | ((*i & 0x80) >> 4);
141 | else if ((*i & 0xFFE0) == 0xEB00)
142 | return (*i & 0xF);
143 | else
144 | return 0;
145 | }
146 |
147 | static int insn_add_reg_rm(uint16_t *i) {
148 | if ((*i & 0xFE00) == 0x1800)
149 | return (*i >> 6) & 7;
150 | else if ((*i & 0xFF00) == 0x4400)
151 | return (*i >> 3) & 0xF;
152 | else if ((*i & 0xFFE0) == 0xEB00)
153 | return *(i + 1) & 0xF;
154 | else
155 | return 0;
156 | }
157 |
158 | static int insn_is_movt(uint16_t *i) {
159 | return (*i & 0xFBF0) == 0xF2C0 && (*(i + 1) & 0x8000) == 0;
160 | }
161 |
162 | static int insn_movt_rd(uint16_t *i) {
163 | return (*(i + 1) >> 8) & 0xF;
164 | }
165 |
166 | static int insn_movt_imm(uint16_t *i) {
167 | return ((*i & 0xF) << 12) | ((*i & 0x0400) << 1) | ((*(i + 1) & 0x7000) >> 4) | (*(i + 1) & 0xFF);
168 | }
169 |
170 | static int insn_is_mov_imm(uint16_t *i) {
171 | if ((*i & 0xF800) == 0x2000)
172 | return 1;
173 | else if ((*i & 0xFBEF) == 0xF04F && (*(i + 1) & 0x8000) == 0)
174 | return 1;
175 | else if ((*i & 0xFBF0) == 0xF240 && (*(i + 1) & 0x8000) == 0)
176 | return 1;
177 | else
178 | return 0;
179 | }
180 |
181 | static int insn_mov_imm_rd(uint16_t *i) {
182 | if ((*i & 0xF800) == 0x2000)
183 | return (*i >> 8) & 7;
184 | else if ((*i & 0xFBEF) == 0xF04F && (*(i + 1) & 0x8000) == 0)
185 | return (*(i + 1) >> 8) & 0xF;
186 | else if ((*i & 0xFBF0) == 0xF240 && (*(i + 1) & 0x8000) == 0)
187 | return (*(i + 1) >> 8) & 0xF;
188 | else
189 | return 0;
190 | }
191 |
192 | static int insn_mov_imm_imm(uint16_t *i) {
193 | if ((*i & 0xF800) == 0x2000)
194 | return *i & 0xF;
195 | else if ((*i & 0xFBEF) == 0xF04F && (*(i + 1) & 0x8000) == 0)
196 | return thumb_expand_imm_c(((*i & 0x0400) << 1) | ((*(i + 1) & 0x7000) >> 4) | (*(i + 1) & 0xFF));
197 | else if ((*i & 0xFBF0) == 0xF240 && (*(i + 1) & 0x8000) == 0)
198 | return ((*i & 0xF) << 12) | ((*i & 0x0400) << 1) | ((*(i + 1) & 0x7000) >> 4) | (*(i + 1) & 0xFF);
199 | else
200 | return 0;
201 | }
202 |
203 | // Given an instruction, search backwards until an instruction is found matching the specified criterion.
204 | static uint16_t *find_last_insn_matching(uint8_t *kdata, size_t ksize, uint16_t *current_instruction, int (*match_func) (uint16_t *)) {
205 | while ((uintptr_t) current_instruction > (uintptr_t) kdata) {
206 | if (insn_is_32bit(current_instruction - 2) && !insn_is_32bit(current_instruction - 3)) {
207 | current_instruction -= 2;
208 | } else {
209 | --current_instruction;
210 | }
211 | if (match_func(current_instruction)) {
212 | return current_instruction;
213 | }
214 | }
215 | return NULL;
216 | }
217 |
218 | // Given an instruction and a register, find the PC-relative address that was stored inside the register by the time the instruction was reached.
219 | static uint32_t find_pc_rel_value(uint8_t *kdata, size_t ksize, uint16_t *insn, int reg) {
220 | // Find the last instruction that completely wiped out this register
221 | int found = 0;
222 | uint16_t *current_instruction = insn;
223 | while ((uintptr_t) current_instruction > (uintptr_t) kdata) {
224 | if (insn_is_32bit(current_instruction - 2)) {
225 | current_instruction -= 2;
226 | } else {
227 | --current_instruction;
228 | }
229 |
230 | if (insn_is_mov_imm(current_instruction) && insn_mov_imm_rd(current_instruction) == reg) {
231 | found = 1;
232 | break;
233 | }
234 |
235 | if (insn_is_ldr_literal(current_instruction) && insn_ldr_literal_rt(current_instruction) == reg) {
236 | found = 1;
237 | break;
238 | }
239 | }
240 |
241 | if (!found)
242 | return 0;
243 |
244 | // Step through instructions, executing them as a virtual machine, only caring about instructions that affect the target register and are commonly used for PC-relative addressing.
245 | uint32_t value = 0;
246 | while ((uintptr_t) current_instruction < (uintptr_t) insn) {
247 | if (insn_is_mov_imm(current_instruction) && insn_mov_imm_rd(current_instruction) == reg) {
248 | value = insn_mov_imm_imm(current_instruction);
249 | } else if (insn_is_ldr_literal(current_instruction) && insn_ldr_literal_rt(current_instruction) == reg) {
250 | value = *(uint32_t *) (kdata + (((((uintptr_t) current_instruction - (uintptr_t) kdata) + 4) & 0xFFFFFFFC) + insn_ldr_literal_imm(current_instruction)));
251 | } else if (insn_is_movt(current_instruction) && insn_movt_rd(current_instruction) == reg) {
252 | value |= insn_movt_imm(current_instruction) << 16;
253 | } else if (insn_is_add_reg(current_instruction) && insn_add_reg_rd(current_instruction) == reg) {
254 | if (insn_add_reg_rm(current_instruction) != 15 || insn_add_reg_rn(current_instruction) != reg) {
255 | // Can't handle this kind of operation!
256 | return 0;
257 | }
258 | value += ((uintptr_t) current_instruction - (uintptr_t) kdata) + 4;
259 | }
260 | current_instruction += insn_is_32bit(current_instruction) ? 2 : 1;
261 | }
262 | return value;
263 | }
264 |
265 | // Find PC-relative references to a certain address (relative to kdata). This is basically a virtual machine that only cares about instructions used in PC-relative addressing, so no branches, etc.
266 | static uint16_t *find_literal_ref(uint8_t *kdata, size_t ksize, uint16_t *insn, uint32_t address) {
267 | uint16_t *current_instruction = insn;
268 | uint32_t value[16];
269 | memset(value, 0, sizeof(value));
270 |
271 | while ((uintptr_t) current_instruction < (uintptr_t) (kdata + ksize)) {
272 | if (insn_is_mov_imm(current_instruction)) {
273 | value[insn_mov_imm_rd(current_instruction)] = insn_mov_imm_imm(current_instruction);
274 | } else if (insn_is_ldr_literal(current_instruction)) {
275 | uintptr_t literal_address = (uintptr_t) kdata + ((((uintptr_t) current_instruction - (uintptr_t) kdata) + 4) & 0xFFFFFFFC) + insn_ldr_literal_imm(current_instruction);
276 | if (literal_address >= (uintptr_t) kdata && (literal_address + 4) <= ((uintptr_t) kdata + ksize)) {
277 | value[insn_ldr_literal_rt(current_instruction)] = *(uint32_t *) (literal_address);
278 | }
279 | } else if (insn_is_movt(current_instruction)) {
280 | value[insn_movt_rd(current_instruction)] |= insn_movt_imm(current_instruction) << 16;
281 | } else if (insn_is_add_reg(current_instruction)) {
282 | int reg = insn_add_reg_rd(current_instruction);
283 | if (insn_add_reg_rm(current_instruction) == 15 && insn_add_reg_rn(current_instruction) == reg) {
284 | value[reg] += ((uintptr_t) current_instruction - (uintptr_t) kdata) + 4;
285 | if (value[reg] == address) {
286 | return current_instruction;
287 | }
288 | }
289 | }
290 | current_instruction += insn_is_32bit(current_instruction) ? 2 : 1;
291 | }
292 | return NULL;
293 | }
294 |
295 | static int find_macho_section(struct mach_header *hdr, size_t size, const char *segname, const char *sectname, uint32_t *ret_addr, uint32_t *ret_size) {
296 | /* Doesn't do bounds checking for size and other values */
297 | if (hdr->magic == MH_MAGIC) {
298 | struct load_command *cmd = (struct load_command *)(hdr + 1);
299 | for (int i = 0; i < hdr->ncmds; i++) {
300 | if (cmd->cmd == LC_SEGMENT) {
301 | struct segment_command *seg = (struct segment_command *)cmd;
302 | if (!strncmp(seg->segname, segname, 16)) {
303 | for (uint32_t j = 0; j < seg->nsects; j++) {
304 | struct section *sect = ((struct section *)(seg + 1)) + j;
305 | if (!strncmp(sect->sectname, sectname, 16)) {
306 | *ret_addr = sect->addr;
307 | *ret_size = sect->size;
308 | return 0;
309 | }
310 | }
311 | }
312 | }
313 | cmd = (struct load_command *)(((uint8_t *)cmd) + cmd->cmdsize);
314 | }
315 | }
316 | return 1;
317 | }
318 |
319 | /* Buggy, but re-implemented because some old versions of iOS don't have memmem */
320 | static void * buggy_memmem(const void *haystack, size_t haystacklen, const void *needle, size_t needlelen) {
321 | if (haystack == NULL || haystacklen == 0 || needle == NULL || needlelen == 0) {
322 | printf("ERROR: Invalid arguments for buggy_memmem.\n");
323 | return NULL;
324 | }
325 | for (size_t i = 0; i < haystacklen; i++) {
326 | if (*(uint8_t *)(haystack + i) == *(uint8_t *)needle && i + needlelen <= haystacklen && 0 == memcmp(((uint8_t *)haystack) + i, needle, needlelen)) {
327 | return (void *)(((uint8_t *)haystack) + i);
328 | }
329 | }
330 | return NULL;
331 | }
332 |
333 | static uint32_t find_kernel_pmap_pre_iOS_6(uint8_t *pmap_map_bd, uint32_t kernel_base, uint8_t *kdata, size_t ksize) {
334 | /* Find xref to string "pmap_map_bd" (that function also references kernel_pmap) */
335 | uint32_t xref = 0;
336 | for (size_t i = 0; i < ksize; i += 4)
337 | if (*(uint32_t *)(kdata + i) == (uint32_t)(kernel_base + pmap_map_bd - kdata)) {
338 | xref = i;
339 | break;
340 | }
341 | if (0 == xref) {
342 | printf("ERROR: Failed to find xref to string \"pmap_map_bd\".\n");
343 | return -1;
344 | }
345 |
346 | /* Find beginning of next function */
347 | uint32_t next_func_start = 0;
348 | for (int i = 0; i < 128; i += 2) {
349 | if (*(uint16_t *)(kdata + xref + i) == 0xB5F0) {
350 | /* Align to 4-byte boundary */
351 | next_func_start = (xref + i) & ~3;
352 | break;
353 | }
354 | }
355 | if (0 == next_func_start) {
356 | printf("ERROR: Failed to find next function within 128 bytes.\n");
357 | return -1;
358 | }
359 |
360 | /* Find end of this function */
361 | uint32_t this_func_end = 0;
362 | for (int i = 0; i < 64; i += 2) {
363 | if (*(uint16_t *)(kdata + xref - i) == 0xBDF0) {
364 | /* Align to 4-byte boundary */
365 | this_func_end = (xref - i + 4) & ~3;
366 | break;
367 | }
368 | }
369 | if (0 == this_func_end) {
370 | printf("ERROR: Failed to find end of this function within 64 bytes.\n");
371 | return -1;
372 | }
373 |
374 | uint32_t vm_addr = 0, vm_size = 0;
375 | /* Find location of __DATA __data section */
376 | if (0 != find_macho_section((struct mach_header *)kdata, ksize, SEG_DATA, SECT_DATA, &vm_addr, &vm_size)) {
377 | printf("ERROR: Failed to find __DATA __data in Mach-O header.\n");
378 | return -1;
379 | }
380 |
381 | uint32_t pmap = 0;
382 | for (uint32_t *search = (uint32_t *)(kdata + this_func_end); search < (uint32_t *)(kdata + next_func_start); search += 1) {
383 | if (vm_addr <= *search && *search < vm_addr + vm_size) {
384 | if (pmap != 0 && pmap != *search) {
385 | printf("ERROR: Multiple possible values within __DATA __data section were found.\n");
386 | return -1;
387 | }
388 | pmap = *search;
389 | }
390 | }
391 | if (0 == pmap) {
392 | printf("ERROR: No values within __DATA __data section were found.\n");
393 | return -1;
394 | }
395 |
396 | return pmap - (kernel_base);
397 | }
398 |
399 | // This points to kernel_pmap. Use that to change the page tables if necessary.
400 | static uint32_t find_kernel_pmap_post_iOS_6(uint8_t *pmap_map_bd, uint8_t *kdata, size_t ksize) {
401 | // Find a reference to the pmap_map_bd string. That function also references kernel_pmap
402 | uint16_t *ptr = find_literal_ref(kdata, ksize, (uint16_t *)kdata, (uintptr_t)pmap_map_bd - (uintptr_t)kdata);
403 | if (!ptr) {
404 | return 0;
405 | }
406 |
407 | // Find the beginning of it (we may have a version that throws panic after the function end).
408 | while (*ptr != 0xB5F0) {
409 | if ((uint8_t *)ptr == kdata) {
410 | return 0;
411 | }
412 | ptr--;
413 | }
414 |
415 | // Find the end of it.
416 | const uint8_t search_function_end[] = { 0xF0, 0xBD };
417 | ptr = buggy_memmem(ptr, ksize - ((uintptr_t)ptr - (uintptr_t)kdata), search_function_end, sizeof(search_function_end));
418 | if (!ptr) {
419 | return 0;
420 | }
421 |
422 | // Find the last BL before the end of it. The third argument to it should be kernel_pmap
423 | uint16_t *bl = find_last_insn_matching(kdata, ksize, ptr, insn_is_bl);
424 | if (!bl) {
425 | return 0;
426 | }
427 |
428 | // Find the last LDR R2, [R*] before it that's before any branches. If there are branches, then we have a version of the function that assumes kernel_pmap instead of being passed it.
429 | uint16_t *ldr_r2 = NULL;
430 | uint16_t *current_instruction = bl;
431 | while ((uintptr_t) current_instruction > (uintptr_t) kdata) {
432 | if (insn_is_32bit(current_instruction - 2) && !insn_is_32bit(current_instruction - 3)) {
433 | current_instruction -= 2;
434 | } else {
435 | --current_instruction;
436 | }
437 |
438 | if (insn_ldr_imm_rt(current_instruction) == 2 && insn_ldr_imm_imm(current_instruction) == 0) {
439 | ldr_r2 = current_instruction;
440 | break;
441 | } else if (insn_is_b_conditional(current_instruction) || insn_is_b_unconditional(current_instruction)) {
442 | break;
443 | }
444 | }
445 |
446 | // The function has a third argument, which must be kernel_pmap. Find out its address
447 | if (ldr_r2) {
448 | return find_pc_rel_value(kdata, ksize, ldr_r2, insn_ldr_imm_rn(ldr_r2));
449 | }
450 |
451 | // The function has no third argument, Follow the BL.
452 | uint32_t imm32 = insn_bl_imm32(bl);
453 | uint32_t target = ((uintptr_t) bl - (uintptr_t) kdata) + 4 + imm32;
454 | if (target > ksize) {
455 | return 0;
456 | }
457 |
458 | // Find the first PC-relative reference in this function.
459 | current_instruction = (uint16_t *) (kdata + target);
460 | while ((uintptr_t) current_instruction < (uintptr_t) (kdata + ksize)) {
461 | if (insn_is_add_reg(current_instruction) && insn_add_reg_rm(current_instruction) == 15) {
462 | current_instruction += insn_is_32bit(current_instruction) ? 2 : 1;
463 | return find_pc_rel_value(kdata, ksize, current_instruction, insn_add_reg_rd(current_instruction));
464 | }
465 | current_instruction += insn_is_32bit(current_instruction) ? 2 : 1;
466 | }
467 |
468 | return 0;
469 | }
470 |
471 | static uint32_t find_larm_init_tramp(uint8_t *kdata, size_t ksize) {
472 | // ldr lr, [pc, lr]; b +0x0; cpsid if
473 | const uint8_t search[] = { 0x0E, 0xE0, 0x9F, 0xE7, 0xFF, 0xFF, 0xFF, 0xEA, 0xC0, 0x00, 0x0C, 0xF1 };
474 | void *ptr = buggy_memmem(kdata, ksize, search, sizeof(search));
475 | if (ptr) {
476 | return ((uintptr_t)ptr) - ((uintptr_t)kdata);
477 | }
478 |
479 | // ldr lr, [pc #value]; b +0x0; cpsid if
480 | const uint8_t search2[] = {/* ??, ?? */ 0x9F, 0xE5, 0xFF, 0xFF, 0xFF, 0xEA, 0xC0, 0x00, 0x0C, 0xF1 };
481 | ptr = buggy_memmem(kdata, ksize, search2, sizeof(search2));
482 | if (ptr) {
483 | return ((uintptr_t)ptr) - 2 - ((uintptr_t)kdata);
484 | }
485 |
486 | printf("ERROR: Failed to locate larm_init_tramp.\n");
487 | return -1;
488 | }
489 |
490 | uint32_t get_kernel_pmap(vm_address_t kernel_base, uint8_t *kernel_dump, size_t ksize) {
491 | uint8_t *pmap_map_bd = buggy_memmem(kernel_dump, ksize, "\"pmap_map_bd\"", strlen("\"pmap_map_bd\""));
492 | if (NULL == pmap_map_bd) {
493 | printf("ERROR: Failed to find string \"pmap_map_bd\".\n");
494 | return -1;
495 | }
496 | uint32_t kernel_pmap_offset = 0;
497 | kernel_pmap_offset = find_kernel_pmap_post_iOS_6(pmap_map_bd, kernel_dump, ksize);
498 | if (0 == kernel_pmap_offset) {
499 | printf("ERROR: Failed to find kernel_pmap offset.");
500 | return -1;
501 | }
502 | return kernel_pmap_offset;
503 | }
504 |
505 | /* --- end --- */
506 |
507 | // taig8's patchfinder
508 | struct find_search_mask
509 | {
510 | uint16_t mask;
511 | uint16_t value;
512 | };
513 |
514 | // Search the range of kdata for a series of 16-bit values that match the search mask.
515 | static uint16_t* find_with_search_mask(uint32_t region, uint8_t* kdata, size_t ksize, int num_masks, const struct find_search_mask* masks)
516 | {
517 | uint16_t* end = (uint16_t*)(kdata + ksize - (num_masks * sizeof(uint16_t)));
518 | uint16_t* cur;
519 | for(cur = (uint16_t*) kdata; cur <= end; ++cur)
520 | {
521 | int matched = 1;
522 | int i;
523 | for(i = 0; i < num_masks; ++i)
524 | {
525 | if((*(cur + i) & masks[i].mask) != masks[i].value)
526 | {
527 | matched = 0;
528 | break;
529 | }
530 | }
531 |
532 | if(matched)
533 | return cur;
534 | }
535 |
536 | return NULL;
537 | }
538 |
539 |
540 | uint32_t find_copyinstr(uint32_t region, uint8_t* kdata, size_t ksize)
541 | {
542 | const struct find_search_mask search_masks[] =
543 | {
544 | {0x0FFF, 0x0F90},
545 | {0xFFFF, 0xEE1D},
546 | {0x0000, 0x0000},
547 | {0xFFF0, 0xE590},
548 | {0x0000, 0x0000},
549 | {0xFFF0, 0xE580},
550 | {0x0000, 0x0000},
551 | {0xFFF0, 0xE590},
552 | {0x0FFF, 0x0F10},
553 | {0xFFFF, 0xEE02},
554 | {0x0000, 0x0000},
555 | {0xFFF0, 0xE590},
556 | {0x0FFF, 0x0F30},
557 | {0xFFFF, 0xEE0D}
558 | };
559 |
560 | uint16_t* insn = find_with_search_mask(region, kdata, ksize, sizeof(search_masks) / sizeof(*search_masks), search_masks);
561 | if(!insn)
562 | return 0;
563 |
564 | // Find the beginning of the function
565 | for ( ; (uint8_t*)insn > kdata; insn -= 2 )
566 | {
567 | if ( (insn[1] & 0xFFF0) == 0xE920 )
568 | break;
569 | }
570 |
571 | return ((uintptr_t)insn) - ((uintptr_t)kdata);
572 | }
573 |
574 | // Function used to find IOLog for printing debug messages
575 | uint32_t find_IOLog(uint32_t region, uint8_t* kdata, size_t ksize)
576 | {
577 | // Find location of the "%s: error mapping interrupt[%d]\n" string.
578 | uint8_t* msg = memmem(kdata, ksize, "%s: error mapping interrupt[%d]\n", sizeof("%s: error mapping interrupt[%d]\n"));
579 | if(!msg)
580 | return 0;
581 |
582 | // Find a reference to the "%s: error mapping interrupt[%d]\n" string.
583 | uint16_t* ref = find_literal_ref(kdata, ksize, (uint16_t*) kdata, (uintptr_t)msg - (uintptr_t)kdata);
584 | if(!ref)
585 | return 0;
586 |
587 | uint16_t* bl = NULL;
588 | uint16_t* current_instruction = ref;
589 | while((uintptr_t)current_instruction < (uintptr_t)(kdata + ksize))
590 | {
591 | if(insn_is_bl(current_instruction))
592 | {
593 | bl = current_instruction;
594 | break;
595 | }
596 |
597 | current_instruction += insn_is_32bit(current_instruction) ? 2 : 1;
598 | }
599 |
600 | if(!bl)
601 | return 0;
602 |
603 | uint32_t imm32 = insn_bl_imm32(bl);
604 | uint32_t target = ((uintptr_t)bl - (uintptr_t)kdata) + 4 + imm32;
605 | if(target > ksize)
606 | return 0;
607 |
608 | return target + 1;
609 | }
610 |
611 | // Function to find the syscall 0 function pointer. Used to modify the syscall table to call our own code.
612 | uint32_t find_syscall188(uint32_t region, uint8_t* kdata, size_t ksize, int sysent)
613 | {
614 |
615 | /* find syscall(0) */
616 | uint32_t syscall0;
617 | uint8_t* str = memmem(kdata, ksize, ".HFS+ Private Directory Data\r", sizeof(".HFS+ Private Directory Data\r"));
618 | if(str) {
619 | uint32_t address = ((uintptr_t)str) + region - ((uintptr_t)kdata);
620 | uint8_t *offset = memmem(kdata, ksize, (const char *)&address, sizeof(uint32_t));
621 | // "HFS+" string offset preceded syscall table
622 | syscall0 = ((uintptr_t)offset) + 4 - ((uintptr_t)kdata);
623 | }
624 |
625 | if(!syscall0) return 0;
626 |
627 | if(*(uint32_t*)&kdata[syscall0+0x4] == 0x1 && // syscall0.sy_return_type
628 | *(uint16_t*)&kdata[syscall0+0x8] == 0x0 && // syscall0.sy_narg
629 | *(uint16_t*)&kdata[syscall0+0xa] == 0x0 && // syscall0.sy_arg_bytes
630 | *(uint32_t*)&kdata[syscall0+0x10] == 0x0 && // syscall1.sy_return_type
631 | *(uint16_t*)&kdata[syscall0+0x14] == 0x1 && // syscall1.sy_narg
632 | *(uint16_t*)&kdata[syscall0+0x16] == 0x4 && // syscall1.sy_arg_bytes
633 | *(uint32_t*)&kdata[syscall0+0x8D4] == 0x1 && // syscall188.sy_return_type
634 | *(uint16_t*)&kdata[syscall0+0x8D8] == 0x2 && // syscall188.sy_narg
635 | *(uint16_t*)&kdata[syscall0+0x8DA] == 0x8){ // syscall188.sy_arg_bytes
636 |
637 | if(sysent) return *(uint32_t*)&kdata[syscall0+0x8D0] - region; // syscall188.sy_call
638 | if(!sysent) return syscall0+0x8D0;
639 | }
640 |
641 | return 0;
642 | }
643 |
644 | // for iOS 10.x
645 | uint32_t find_syscall188_post_iOSX(uint32_t region, uint8_t* kdata, size_t ksize, int sysent)
646 | {
647 | const uint8_t syscall0_search[] = {0x80, 0xb5, 0x6f, 0x46, 0x82, 0xb0, 0x1d, 0xee, 0x90, 0x2f, 0x00, 0x20, 0x01, 0x90, 0x0c, 0x20, 0x00, 0x90, 0x00, 0x20, 0x00, 0x21, 0x04, 0x23};
648 |
649 | void* ptr = memmem(kdata, ksize, syscall0_search, sizeof(syscall0_search));
650 | if(!ptr)
651 | return 0;
652 |
653 | uint32_t syscall0_ptr = ((uintptr_t)ptr) - ((uintptr_t)kdata) + region + 1;
654 |
655 | for(int i=0;i<0x800000;i++){
656 | if(*(uint32_t*)&kdata[i] == syscall0_ptr && // syscall0.sy_call
657 | *(uint32_t*)&kdata[i+0x4] == 0x1 && // syscall0.sy_return_type
658 | *(uint16_t*)&kdata[i+0x8] == 0x0 && // syscall0.sy_narg
659 | *(uint16_t*)&kdata[i+0xa] == 0x0 && // syscall0.sy_arg_bytes
660 | *(uint32_t*)&kdata[i+0x10] == 0x0 && // syscall1.sy_return_type
661 | *(uint16_t*)&kdata[i+0x14] == 0x1 && // syscall1.sy_narg
662 | *(uint16_t*)&kdata[i+0x16] == 0x4 && // syscall1.sy_arg_bytes
663 | *(uint32_t*)&kdata[i+0x8D4] == 0x1 && // syscall188.sy_return_type
664 | *(uint16_t*)&kdata[i+0x8D8] == 0x2 && // syscall188.sy_narg
665 | *(uint16_t*)&kdata[i+0x8DA] == 0x8){ // syscall188.sy_arg_bytes
666 |
667 | if(sysent) return *(uint32_t*)&kdata[i+0x8D0] - region; // syscall188.sy_call
668 | if(!sysent) return i+0x8D0;
669 | }
670 | }
671 |
672 | return 0;
673 | }
674 |
675 |
676 | uint32_t find_strcmp(uint32_t region, uint8_t* kdata, size_t ksize)
677 | {
678 | const uint8_t strcmp_searchX[] = {0x01, 0x31, 0x01, 0x30, 0x00, 0x2a, 0x04, 0xbf, 0x00, 0x20, 0x70, 0x47};
679 |
680 | void* ptrX = memmem(kdata, ksize, strcmp_searchX, sizeof(strcmp_searchX));
681 | if(!ptrX){
682 | const uint8_t strcmp_searchIX[] = {0x00, 0x2a, 0x00, 0xf1, 0x01, 0x00, 0x01, 0xf1, 0x01, 0x01, 0x04, 0xbf, 0x00, 0x20, 0x70, 0x47};
683 | void* ptrIX = memmem(kdata, ksize, strcmp_searchIX, sizeof(strcmp_searchIX));
684 | if(!ptrIX){
685 | return 0;
686 | }
687 | return ((uintptr_t)ptrIX) - ((uintptr_t)kdata) - 0x2;
688 | }
689 |
690 | return ((uintptr_t)ptrX) - ((uintptr_t)kdata) - 0x2;
691 |
692 | }
693 |
694 | uint32_t get_kernel_str(uint32_t region, uint8_t* kdata, size_t ksize, char* str)
695 | {
696 | uint8_t *ptr = buggy_memmem(kdata, ksize, str, strlen(str) + 1);
697 | if (NULL == ptr) {
698 | printf("ERROR: Failed to find strings: %s\n", str);
699 | return -1;
700 | }
701 |
702 | return ((uintptr_t)ptr) - ((uintptr_t)kdata);
703 | }
704 |
705 | uint32_t find_IOLog_post_iOSX(uint32_t region, uint8_t* kdata, size_t ksize)
706 | {
707 | const uint8_t IOLog_search[] = {0x83, 0xB0, 0x90, 0xB5, 0x01, 0xAF, 0x85, 0xB0, 0x04, 0x46, 0x3B, 0x61, 0xFA, 0x60, 0xB9, 0x60, 0x07, 0xF1, 0x08, 0x00, 0x02, 0x90, 0x04, 0x90, 0x04, 0x98, 0x03, 0x90, 0x04, 0x99, 0x20, 0x46};
708 | void* ptr = memmem(kdata, ksize, IOLog_search, sizeof(IOLog_search));
709 | if(!ptr)
710 | return 0;
711 |
712 | return ((uintptr_t)ptr) - ((uintptr_t)kdata);
713 |
714 | return 0;
715 | }
716 | // end
717 |
718 | // make_bl - from iloader by xerub
719 | uint32_t make_bl(int blx, int pos, int tgt)
720 | {
721 | int delta;
722 | unsigned short pfx;
723 | unsigned short sfx;
724 | unsigned int omask = 0xF800;
725 | unsigned int amask = 0x7FF;
726 | if (blx) { // XXX untested
727 | omask = 0xE800;
728 | amask = 0x7FE;
729 | pos &= ~3;
730 | }
731 | delta = tgt - pos - 4; // range: 0x400000
732 | pfx = 0xF000 | ((delta >> 12) & 0x7FF);
733 | sfx = omask | ((delta >> 1) & amask);
734 | return (unsigned int)pfx | ((unsigned int)sfx << 16);
735 | }
736 |
737 | unsigned int
738 | make_b_w(int pos, int tgt)
739 | {
740 | int delta;
741 | unsigned int i;
742 | unsigned short pfx;
743 | unsigned short sfx;
744 |
745 | unsigned int omask_1k = 0xB800;
746 | unsigned int omask_2k = 0xB000;
747 | unsigned int omask_3k = 0x9800;
748 | unsigned int omask_4k = 0x9000;
749 |
750 | unsigned int amask = 0x7FF;
751 | int range;
752 |
753 | range = 0x400000;
754 |
755 | delta = tgt - pos - 4; // range: 0x400000
756 | i = 0;
757 | if(tgt > pos) i = tgt - pos - 4;
758 | if(tgt < pos) i = pos - tgt - 4;
759 |
760 | if (i < range){
761 | pfx = 0xF000 | ((delta >> 12) & 0x7FF);
762 | sfx = omask_1k | ((delta >> 1) & amask);
763 |
764 | return (unsigned int)pfx | ((unsigned int)sfx << 16);
765 | }
766 |
767 | if (range < i && i < range*2){ // range: 0x400000-0x800000
768 | delta -= range;
769 | pfx = 0xF000 | ((delta >> 12) & 0x7FF);
770 | sfx = omask_2k | ((delta >> 1) & amask);
771 |
772 | return (unsigned int)pfx | ((unsigned int)sfx << 16);
773 | }
774 |
775 | if (range*2 < i && i < range*3){ // range: 0x800000-0xc000000
776 | delta -= range*2;
777 | pfx = 0xF000 | ((delta >> 12) & 0x7FF);
778 | sfx = omask_3k | ((delta >> 1) & amask);
779 |
780 | return (unsigned int)pfx | ((unsigned int)sfx << 16);
781 | }
782 |
783 | if (range*3 < i && i < range*4){ // range: 0xc00000-0x10000000
784 | delta -= range*3;
785 | pfx = 0xF000 | ((delta >> 12) & 0x7FF);
786 | sfx = omask_4k | ((delta >> 1) & amask);
787 | return (unsigned int)pfx | ((unsigned int)sfx << 16);
788 | }
789 |
790 | return -1;
791 | }
792 |
--------------------------------------------------------------------------------
/kernel/patchfinder32/patchfinder32.h:
--------------------------------------------------------------------------------
1 |
2 | uint32_t get_kernel_pmap(vm_address_t kernel_base, uint8_t *kernel_dump, size_t ksize);
3 | uint32_t find_copyinstr(uint32_t region, uint8_t* kdata, size_t ksize);
4 | uint32_t find_IOLog(uint32_t region, uint8_t* kdata, size_t ksize);
5 | uint32_t find_syscall188_post_iOSX(uint32_t region, uint8_t* kdata, size_t ksize, int sysent);
6 | uint32_t find_syscall188(uint32_t region, uint8_t* kdata, size_t ksize, int sysent);
7 | uint32_t find_strcmp(uint32_t region, uint8_t* kdata, size_t ksize);
8 | uint32_t get_kernel_str(uint32_t region, uint8_t* kdata, size_t ksize, char* str);
9 | uint32_t find_IOLog_post_iOSX(uint32_t region, uint8_t* kdata, size_t ksize);
10 |
11 | uint32_t make_bl(int blx, int pos, int tgt);
12 | unsigned int make_b_w(int pos, int tgt);
13 |
--------------------------------------------------------------------------------
/kernel/patchfinder64/.empty:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/dora2ios/CPBypass-public/935df36bf9b8239aa23509c95b8dbe8dee9283f1/kernel/patchfinder64/.empty
--------------------------------------------------------------------------------
/kernel/payload/mk32.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | /opt/gnuarm/bin/arm-none-eabi-gcc -c -Os -march=armv7 -mthumb stat_sysent32.c
4 |
--------------------------------------------------------------------------------
/kernel/payload/payload32.h:
--------------------------------------------------------------------------------
1 | unsigned char sysent_stat_bin[] = {
2 | 0xff, 0xf7, 0xfe, 0xbf, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3 | 0x1b, 0x02, 0x00, 0x00, 0x15, 0x02, 0x00, 0x00, 0x10, 0x02, 0x00, 0x00,
4 | 0x0b, 0x02, 0x00, 0x00, 0xf3, 0x01, 0x00, 0x00, 0xe2, 0x01, 0x00, 0x00,
5 | 0xd9, 0x01, 0x00, 0x00, 0xa5, 0x01, 0x00, 0x00, 0x79, 0x01, 0x00, 0x00,
6 | 0x68, 0x01, 0x00, 0x00, 0x4f, 0x01, 0x00, 0x00, 0x22, 0x01, 0x00, 0x00,
7 | 0x0c, 0x01, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0xeb, 0x00, 0x00, 0x00,
8 | 0xe0, 0x00, 0x00, 0x00, 0xc4, 0x00, 0x00, 0x00, 0xae, 0x00, 0x00, 0x00,
9 | 0x76, 0x00, 0x00, 0x00, 0x5f, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x00,
10 | 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x2d, 0xe9, 0xf0, 0x41,
11 | 0xad, 0xf5, 0x81, 0x6d, 0x00, 0x23, 0x80, 0x46, 0x0e, 0x46, 0x17, 0x46,
12 | 0x01, 0x93, 0x4f, 0xf4, 0x80, 0x62, 0x08, 0x68, 0x01, 0xab, 0x02, 0xa9,
13 | 0xff, 0xf7, 0xfe, 0xff, 0x08, 0xb1, 0x02, 0x20, 0x98, 0xe0, 0x4e, 0x4c,
14 | 0x02, 0xaa, 0x94, 0xe8, 0x03, 0x00, 0xff, 0xf7, 0xfe, 0xff, 0x02, 0xa8,
15 | 0xa1, 0x68, 0xff, 0xf7, 0xfe, 0xff, 0x00, 0x28, 0xf1, 0xd0, 0x02, 0xa8,
16 | 0xe1, 0x68, 0xff, 0xf7, 0xfe, 0xff, 0x00, 0x28, 0xeb, 0xd0, 0x02, 0xa8,
17 | 0x21, 0x69, 0xff, 0xf7, 0xfe, 0xff, 0x00, 0x28, 0xe5, 0xd0, 0x02, 0xa8,
18 | 0x61, 0x69, 0xff, 0xf7, 0xfe, 0xff, 0x00, 0x28, 0xdf, 0xd0, 0x02, 0xa8,
19 | 0xa1, 0x69, 0xff, 0xf7, 0xfe, 0xff, 0x00, 0x28, 0xd9, 0xd0, 0x02, 0xa8,
20 | 0xe1, 0x69, 0xff, 0xf7, 0xfe, 0xff, 0x00, 0x28, 0xd3, 0xd0, 0x02, 0xa8,
21 | 0x21, 0x6a, 0xff, 0xf7, 0xfe, 0xff, 0x00, 0x28, 0xcd, 0xd0, 0x02, 0xa8,
22 | 0x61, 0x6a, 0xff, 0xf7, 0xfe, 0xff, 0x00, 0x28, 0xc7, 0xd0, 0x02, 0xa8,
23 | 0xa1, 0x6a, 0xff, 0xf7, 0xfe, 0xff, 0x00, 0x28, 0xc1, 0xd0, 0x02, 0xa8,
24 | 0xe1, 0x6a, 0xff, 0xf7, 0xfe, 0xff, 0x00, 0x28, 0xbb, 0xd0, 0x02, 0xa8,
25 | 0x21, 0x6b, 0xff, 0xf7, 0xfe, 0xff, 0x00, 0x28, 0xb5, 0xd0, 0x02, 0xa8,
26 | 0x61, 0x6b, 0xff, 0xf7, 0xfe, 0xff, 0x00, 0x28, 0xaf, 0xd0, 0x02, 0xa8,
27 | 0xa1, 0x6b, 0xff, 0xf7, 0xfe, 0xff, 0x00, 0x28, 0xa9, 0xd0, 0x02, 0xa8,
28 | 0xe1, 0x6b, 0xff, 0xf7, 0xfe, 0xff, 0x00, 0x28, 0xa3, 0xd0, 0x02, 0xa8,
29 | 0x21, 0x6c, 0xff, 0xf7, 0xfe, 0xff, 0x00, 0x28, 0x9d, 0xd0, 0x02, 0xa8,
30 | 0x61, 0x6c, 0xff, 0xf7, 0xfe, 0xff, 0x00, 0x28, 0x97, 0xd0, 0x02, 0xa8,
31 | 0xa1, 0x6c, 0xff, 0xf7, 0xfe, 0xff, 0x00, 0x28, 0x91, 0xd0, 0x02, 0xa8,
32 | 0xe1, 0x6c, 0xff, 0xf7, 0xfe, 0xff, 0x00, 0x28, 0x8b, 0xd0, 0x02, 0xa8,
33 | 0x21, 0x6d, 0xff, 0xf7, 0xfe, 0xff, 0x00, 0x28, 0x85, 0xd0, 0x02, 0xa8,
34 | 0x61, 0x6d, 0xff, 0xf7, 0xfe, 0xff, 0x00, 0x28, 0x3f, 0xf4, 0x7f, 0xaf,
35 | 0x02, 0xa8, 0xa1, 0x6d, 0xff, 0xf7, 0xfe, 0xff, 0x00, 0x28, 0x3f, 0xf4,
36 | 0x78, 0xaf, 0x02, 0xa8, 0xe1, 0x6d, 0xff, 0xf7, 0xfe, 0xff, 0x00, 0x28,
37 | 0x3f, 0xf4, 0x71, 0xaf, 0x02, 0xa8, 0x21, 0x6e, 0xff, 0xf7, 0xfe, 0xff,
38 | 0x00, 0x28, 0x3f, 0xf4, 0x6a, 0xaf, 0x40, 0x46, 0x31, 0x46, 0x3a, 0x46,
39 | 0xff, 0xf7, 0xfe, 0xff, 0x0d, 0xf5, 0x81, 0x6d, 0xbd, 0xe8, 0xf0, 0x81,
40 | 0x00, 0x00, 0x00, 0x00, 0x62, 0x00, 0x61, 0x00, 0x2f, 0x70, 0x72, 0x69,
41 | 0x76, 0x61, 0x74, 0x65, 0x2f, 0x76, 0x61, 0x72, 0x2f, 0x6d, 0x6f, 0x62,
42 | 0x69, 0x6c, 0x65, 0x2f, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x2f,
43 | 0x46, 0x6c, 0x65, 0x78, 0x33, 0x00, 0x2f, 0x4c, 0x69, 0x62, 0x72, 0x61,
44 | 0x72, 0x79, 0x2f, 0x50, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63,
45 | 0x65, 0x4c, 0x6f, 0x61, 0x64, 0x65, 0x72, 0x2f, 0x50, 0x72, 0x65, 0x66,
46 | 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x73, 0x2f, 0x4e, 0x6f, 0x53, 0x75,
47 | 0x62, 0x73, 0x74, 0x69, 0x74, 0x75, 0x74, 0x65, 0x2e, 0x70, 0x6c, 0x69,
48 | 0x73, 0x74, 0x00, 0x2f, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74,
49 | 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x46, 0x6c, 0x65, 0x78, 0x2e, 0x61, 0x70,
50 | 0x70, 0x00, 0x2f, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x2f, 0x50,
51 | 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e, 0x63, 0x65, 0x4c, 0x6f, 0x61,
52 | 0x64, 0x65, 0x72, 0x2f, 0x50, 0x72, 0x65, 0x66, 0x65, 0x72, 0x65, 0x6e,
53 | 0x63, 0x65, 0x73, 0x2f, 0x4c, 0x69, 0x62, 0x65, 0x72, 0x74, 0x79, 0x50,
54 | 0x72, 0x65, 0x66, 0x2e, 0x70, 0x6c, 0x69, 0x73, 0x74, 0x00, 0x2f, 0x4c,
55 | 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x2f, 0x42, 0x72, 0x65, 0x61, 0x6b,
56 | 0x54, 0x68, 0x72, 0x6f, 0x75, 0x67, 0x68, 0x00, 0x2f, 0x75, 0x73, 0x72,
57 | 0x2f, 0x6c, 0x69, 0x62, 0x2f, 0x6c, 0x69, 0x62, 0x73, 0x75, 0x62, 0x73,
58 | 0x74, 0x72, 0x61, 0x74, 0x65, 0x2e, 0x64, 0x79, 0x6c, 0x69, 0x62, 0x00,
59 | 0x2f, 0x76, 0x61, 0x72, 0x2f, 0x73, 0x74, 0x61, 0x73, 0x68, 0x00, 0x2f,
60 | 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65, 0x2f, 0x76, 0x61, 0x72, 0x2f,
61 | 0x73, 0x74, 0x61, 0x73, 0x68, 0x00, 0x2f, 0x76, 0x61, 0x72, 0x2f, 0x64,
62 | 0x62, 0x2f, 0x73, 0x74, 0x61, 0x73, 0x68, 0x00, 0x2f, 0x70, 0x72, 0x69,
63 | 0x76, 0x61, 0x74, 0x65, 0x2f, 0x76, 0x61, 0x72, 0x2f, 0x64, 0x62, 0x2f,
64 | 0x73, 0x74, 0x61, 0x73, 0x68, 0x00, 0x2f, 0x4c, 0x69, 0x62, 0x72, 0x61,
65 | 0x72, 0x79, 0x2f, 0x46, 0x72, 0x61, 0x6d, 0x65, 0x77, 0x6f, 0x72, 0x6b,
66 | 0x73, 0x2f, 0x43, 0x79, 0x64, 0x69, 0x61, 0x53, 0x75, 0x62, 0x73, 0x74,
67 | 0x72, 0x61, 0x74, 0x65, 0x2e, 0x66, 0x72, 0x61, 0x6d, 0x65, 0x77, 0x6f,
68 | 0x72, 0x6b, 0x00, 0x2f, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x2f,
69 | 0x4d, 0x6f, 0x62, 0x69, 0x6c, 0x65, 0x53, 0x75, 0x62, 0x73, 0x74, 0x72,
70 | 0x61, 0x74, 0x65, 0x00, 0x2f, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74, 0x65,
71 | 0x2f, 0x65, 0x74, 0x63, 0x2f, 0x73, 0x73, 0x68, 0x00, 0x2f, 0x76, 0x61,
72 | 0x72, 0x2f, 0x6d, 0x6f, 0x62, 0x69, 0x6c, 0x65, 0x2f, 0x4c, 0x69, 0x62,
73 | 0x72, 0x61, 0x72, 0x79, 0x2f, 0x43, 0x61, 0x63, 0x68, 0x65, 0x73, 0x2f,
74 | 0x63, 0x6f, 0x6d, 0x2e, 0x73, 0x61, 0x75, 0x72, 0x69, 0x6b, 0x2e, 0x43,
75 | 0x79, 0x64, 0x69, 0x61, 0x00, 0x2f, 0x70, 0x72, 0x69, 0x76, 0x61, 0x74,
76 | 0x65, 0x2f, 0x76, 0x61, 0x72, 0x2f, 0x6d, 0x6f, 0x62, 0x69, 0x6c, 0x65,
77 | 0x2f, 0x4c, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x2f, 0x43, 0x61, 0x63,
78 | 0x68, 0x65, 0x73, 0x2f, 0x63, 0x6f, 0x6d, 0x2e, 0x73, 0x61, 0x75, 0x72,
79 | 0x69, 0x6b, 0x2e, 0x43, 0x79, 0x64, 0x69, 0x61, 0x00, 0x2f, 0x76, 0x61,
80 | 0x72, 0x2f, 0x6c, 0x69, 0x62, 0x00, 0x2f, 0x70, 0x72, 0x69, 0x76, 0x61,
81 | 0x74, 0x65, 0x2f, 0x76, 0x61, 0x72, 0x2f, 0x6c, 0x69, 0x62, 0x00, 0x2f,
82 | 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73,
83 | 0x2f, 0x43, 0x79, 0x64, 0x69, 0x61, 0x2e, 0x61, 0x70, 0x70, 0x00, 0x2f,
84 | 0x6d, 0x6e, 0x74, 0x00, 0x2f, 0x6c, 0x69, 0x62, 0x00, 0x2f, 0x62, 0x6f,
85 | 0x6f, 0x74, 0x00, 0x2f, 0x55, 0x73, 0x65, 0x72, 0x00, 0x00, 0x00, 0x00
86 | };
87 |
88 | unsigned int sysent_stat_bin_sz = 1008;
89 |
--------------------------------------------------------------------------------
/kernel/payload/stat_sysent32.c:
--------------------------------------------------------------------------------
1 | /* stat_sysent.c: Bypassing file detection with kernel hooking
2 | * 2020/12/12
3 | * made by dora2ios
4 | */
5 |
6 | #include
7 |
8 | typedef uint32_t user_addr_t;
9 | typedef uint32_t size_t;
10 | typedef struct vfs_context *vfs_context_t;
11 | typedef uintptr_t vm_size_t;
12 | typedef struct vm_allocation_site vm_allocation_site_t;
13 |
14 | int
15 | strcmp(const char *s1, const char *s2);
16 |
17 | __attribute__((noinline)) int _pre_strcmp(const char *a, const char *b){
18 | return strcmp(a, b);
19 | }
20 |
21 | void IOLog(const char *format, ...)
22 | __attribute__((format(printf, 1, 2)));
23 |
24 | #define MAXPATHLEN 0x400
25 |
26 | #if 0
27 | /* 64-bit */
28 | /* rootlessjb */
29 | const char *STR_JB = "/jb"; // not need
30 | const char *STR_VAR_CONT_BUNDLES_BINPACK64 = "/var/containers/Bundle/iosbinpack64"; // not need
31 | const char *STR_PRV_VAR_CONT_BUNDLES_BINPACK64 = "/private/var/containers/Bundle/iosbinpack64"; // not need
32 | const char *STR_VAR_LIBEXEC = "/var/libexec"; // not need
33 | const char *STR_PRV_VAR_LIBEXEC = "/private/var/libexec"; // not need
34 | /* sileo */
35 | const char *STR_APP_SILEO = "/Applications/Sileo.app"; // not need
36 | const char *STR_PRV_VAR_MOBILE_LIBRARY_CACHES_SNAPSHOTS_SILEO = "/private/var/mobile/Library/Caches/Snapshots/org.coolstar.SileoStore"; // not need
37 | const char *STR_PRV_VAR_MOBILE_LIBRARY_PREF_SILEO = "/private/var/mobile/Library/Preferences/org.coolstar.SileoStore.plist"; // not need
38 | /* zebra */
39 | const char *STR_APP_ZEBRA = "/Applications/Zebra.app"; // not need
40 | const char *STR_LIBRARY_DPKG_INFO_ZEBRA = "/Library/dpkg/info/xyz.willy.zebra.list"; // not need
41 | const char *STR_PRV_VAR_MOBILE_LIBRARY_PREF_ZEBRA = "/private/var/mobile/Library/Preferences/xyz.willy.Zebra.plist"; // not need
42 | #endif
43 |
44 | /* Universal */
45 | const char *STR_USER = "/User";
46 | const char *STR_BOOT = "/boot";
47 | const char *STR_LIB = "/lib";
48 | const char *STR_MNT = "/mnt";
49 | const char *STR_APP_CYDIA = "/Applications/Cydia.app";
50 | const char *STR_PRV_VAR_LIB = "/private/var/lib";
51 | const char *STR_VAR_LIB = "/var/lib"; // not need?
52 | const char *STR_PRV_VAR_MOBILE_LIBRARY_CACHES_CYDIA = "/private/var/mobile/Library/Caches/com.saurik.Cydia";
53 | const char *STR_VAR_MOBILE_LIBRARY_CACHES_CYDIA = "/var/mobile/Library/Caches/com.saurik.Cydia";
54 | const char *STR_PRV_ETC_SSH = "/private/etc/ssh";
55 | const char *STR_LIBRARY_MS = "/Library/MobileSubstrate";
56 | const char *STR_LIBRARY_FRAMEWORKS_MS = "/Library/Frameworks/CydiaSubstrate.framework";
57 | const char *STR_PRIV_VAR_DB_STASH = "/private/var/db/stash";
58 | const char *STR_VAR_DB_STASH = "/var/db/stash";
59 | const char *STR_PRIV_VAR_STASH = "/private/var/stash";
60 | const char *STR_VAR_STASH = "/var/stash";
61 | const char *STR_USR_LIB_SUBSTRATE = "/usr/lib/libsubstrate.dylib";
62 |
63 | /* anti-anti jb detection */
64 | const char *STR_LIBRARY_BT = "/Library/BreakThrough";
65 | const char *STR_LIBRARY_PREFLOADER_PREF_LIBERTY = "/Library/PreferenceLoader/Preferences/LibertyPref.plist";
66 | const char *STR_APP_FLEX = "/Applications/Flex.app";
67 | const char *STR_LIBRARY_PREFLOADER_PREF_NOMS = "/Library/PreferenceLoader/Preferences/NoSubstitute.plist";
68 | const char *STR_PRIV_VAR_MOBILE_LIBRARY_FLEX3 = "/private/var/mobile/Library/Flex3";
69 | const char *STR_VAR_MOBILE_LIBRARY_FLEX3 = "/var/mobile/Library/Flex3";
70 |
71 | /* IOLog */
72 | const char *LOGDUMP = "a";
73 | const char *BLOCKDUMP = "b";
74 |
75 | /* hook */
76 | struct proc;
77 | typedef uint32_t sy_call_t(struct proc *arg1, void *arg2, int *arg3);
78 | uint32_t orig_stat(struct proc *p, struct stat_args *uap, /* __unused */ uint32_t *retval);
79 |
80 | struct stat_args {
81 | uint32_t path;
82 | uint32_t ub;
83 | };
84 |
85 | uint32_t main(struct proc *p, struct stat_args *uap, /* __unused */ uint32_t *retval){
86 |
87 | char pathname[MAXPATHLEN];
88 | size_t dummy=0;
89 | int error;
90 |
91 | error = copyinstr(uap->path, pathname, MAXPATHLEN, &dummy);
92 | if(error) return 2;
93 |
94 | // iPhone5,2 11D27 kern_offsets
95 | // 803aab6f db "%s: %s\n"
96 | // 803b3a2d db "path"
97 | //
98 | // LOGDUMP -> "%s: %s\n"
99 | // BLOCKDUMP -> "path"
100 |
101 | IOLog(LOGDUMP, BLOCKDUMP, pathname);
102 | //_IOLog("%s: %s\n", "path", pathname);
103 |
104 | if(_pre_strcmp(pathname, STR_USER) == 0 ||
105 | _pre_strcmp(pathname, STR_BOOT) == 0 ||
106 | _pre_strcmp(pathname, STR_LIB) == 0 ||
107 | _pre_strcmp(pathname, STR_MNT) == 0 ||
108 | _pre_strcmp(pathname, STR_APP_CYDIA) == 0 ||
109 | _pre_strcmp(pathname, STR_PRV_VAR_LIB) == 0 ||
110 | _pre_strcmp(pathname, STR_VAR_LIB) == 0 ||
111 | _pre_strcmp(pathname, STR_PRV_VAR_MOBILE_LIBRARY_CACHES_CYDIA) == 0 ||
112 | _pre_strcmp(pathname, STR_VAR_MOBILE_LIBRARY_CACHES_CYDIA) == 0 ||
113 | _pre_strcmp(pathname, STR_PRV_ETC_SSH) == 0 ||
114 | _pre_strcmp(pathname, STR_LIBRARY_MS) == 0 ||
115 |
116 | _pre_strcmp(pathname, STR_LIBRARY_FRAMEWORKS_MS) == 0 ||
117 | _pre_strcmp(pathname, STR_PRIV_VAR_DB_STASH) == 0 ||
118 | _pre_strcmp(pathname, STR_VAR_DB_STASH) == 0 ||
119 | _pre_strcmp(pathname, STR_PRIV_VAR_STASH) == 0 ||
120 | _pre_strcmp(pathname, STR_VAR_STASH) == 0 ||
121 | _pre_strcmp(pathname, STR_USR_LIB_SUBSTRATE) == 0 ||
122 |
123 | _pre_strcmp(pathname, STR_LIBRARY_BT) == 0 ||
124 | _pre_strcmp(pathname, STR_LIBRARY_PREFLOADER_PREF_LIBERTY) == 0 ||
125 | _pre_strcmp(pathname, STR_APP_FLEX) == 0 ||
126 | _pre_strcmp(pathname, STR_LIBRARY_PREFLOADER_PREF_NOMS) == 0 ||
127 | _pre_strcmp(pathname, STR_PRIV_VAR_MOBILE_LIBRARY_FLEX3) == 0 ||
128 | _pre_strcmp(pathname, STR_VAR_MOBILE_LIBRARY_FLEX3) == 0){
129 | // return ENOENT;
130 | return 2;
131 | }
132 |
133 | return orig_stat(p, uap, retval);
134 | }
135 |
--------------------------------------------------------------------------------
/kernel/payload/stat_sysent64.c:
--------------------------------------------------------------------------------
1 | /* stat_sysent.c: Bypassing file detection with kernel hooking
2 | * 2020/12/12
3 | * made by dora2ios
4 | */
5 |
6 | #include
7 |
8 | typedef uint64_t user_addr_t;
9 | typedef uint64_t size_t;
10 | typedef struct vfs_context *vfs_context_t;
11 | typedef uintptr_t vm_size_t;
12 | typedef struct vm_allocation_site vm_allocation_site_t;
13 |
14 | #define MAXPATHLEN 0x400
15 |
16 | #if 0
17 | /* 64-bit */
18 | /* rootlessjb */
19 | const char *STR_JB = "/jb"; // not need
20 | const char *STR_VAR_CONT_BUNDLES_BINPACK64 = "/var/containers/Bundle/iosbinpack64"; // not need
21 | const char *STR_PRV_VAR_CONT_BUNDLES_BINPACK64 = "/private/var/containers/Bundle/iosbinpack64"; // not need
22 | const char *STR_VAR_LIBEXEC = "/var/libexec"; // not need
23 | const char *STR_PRV_VAR_LIBEXEC = "/private/var/libexec"; // not need
24 | /* sileo */
25 | const char *STR_APP_SILEO = "/Applications/Sileo.app"; // not need
26 | const char *STR_PRV_VAR_MOBILE_LIBRARY_CACHES_SNAPSHOTS_SILEO = "/private/var/mobile/Library/Caches/Snapshots/org.coolstar.SileoStore"; // not need
27 | const char *STR_PRV_VAR_MOBILE_LIBRARY_PREF_SILEO = "/private/var/mobile/Library/Preferences/org.coolstar.SileoStore.plist"; // not need
28 | /* zebra */
29 | const char *STR_APP_ZEBRA = "/Applications/Zebra.app"; // not need
30 | const char *STR_LIBRARY_DPKG_INFO_ZEBRA = "/Library/dpkg/info/xyz.willy.zebra.list"; // not need
31 | const char *STR_PRV_VAR_MOBILE_LIBRARY_PREF_ZEBRA = "/private/var/mobile/Library/Preferences/xyz.willy.Zebra.plist"; // not need
32 | #endif
33 |
34 | /* Universal */
35 | const char *STR_USER = "/User";
36 | const char *STR_BOOT = "/boot";
37 | const char *STR_LIB = "/lib";
38 | const char *STR_MNT = "/mnt";
39 | const char *STR_APP_CYDIA = "/Applications/Cydia.app";
40 | const char *STR_PRV_VAR_LIB = "/private/var/lib";
41 | const char *STR_VAR_LIB = "/var/lib"; // not need?
42 | const char *STR_PRV_VAR_MOBILE_LIBRARY_CACHES_CYDIA = "/private/var/mobile/Library/Caches/com.saurik.Cydia";
43 | const char *STR_VAR_MOBILE_LIBRARY_CACHES_CYDIA = "/var/mobile/Library/Caches/com.saurik.Cydia";
44 | const char *STR_PRV_ETC_SSH = "/private/etc/ssh";
45 | const char *STR_LIBRARY_MS = "/Library/MobileSubstrate";
46 | const char *STR_LIBRARY_FRAMEWORKS_MS = "/Library/Frameworks/CydiaSubstrate.framework";
47 | const char *STR_PRIV_VAR_DB_STASH = "/private/var/db/stash";
48 | const char *STR_VAR_DB_STASH = "/var/db/stash";
49 | const char *STR_PRIV_VAR_STASH = "/private/var/stash";
50 | const char *STR_VAR_STASH = "/var/stash";
51 | const char *STR_USR_LIB_SUBSTRATE = "/usr/lib/libsubstrate.dylib";
52 |
53 | /* anti-anti jb detection */
54 | const char *STR_LIBRARY_BT = "/Library/BreakThrough";
55 | const char *STR_LIBRARY_PREFLOADER_PREF_LIBERTY = "/Library/PreferenceLoader/Preferences/LibertyPref.plist";
56 | const char *STR_APP_FLEX = "/Applications/Flex.app";
57 | const char *STR_LIBRARY_PREFLOADER_PREF_NOMS = "/Library/PreferenceLoader/Preferences/NoSubstitute.plist";
58 | const char *STR_PRIV_VAR_MOBILE_LIBRARY_FLEX3 = "/private/var/mobile/Library/Flex3";
59 | const char *STR_VAR_MOBILE_LIBRARY_FLEX3 = "/var/mobile/Library/Flex3";
60 |
61 | /* IOLog */ // not working...
62 | const char *LOGDUMP = "[%s]: %s\n";
63 | const char *BLOCKDUMP = "stat";
64 |
65 | /* hook */
66 | struct proc;
67 | typedef uint64_t sy_call_t(struct proc *arg1, void *arg2, int *arg3);
68 | typedef int (*orig_stat_t)(struct proc *p, struct stat_args *uap, /* __unused */ uint32_t *retval);
69 | __attribute__((noinline)) orig_stat_t orig_stat = 0x4444444444444444;
70 |
71 | struct stat_args {
72 | uint64_t path;
73 | uint64_t ub;
74 | };
75 |
76 | typedef int (*copyinstr_t)(const user_addr_t uaddr, void *kaddr, size_t len, size_t *done);
77 | __attribute__((noinline)) copyinstr_t copyinstr = 0x4141414141414141;
78 |
79 | typedef int (*strcmp_t)(const char *s1, const char *s2);
80 | //__attribute__((noinline)) strcmp_t _strcmp = 0x4242424242424242;
81 | __attribute__((noinline)) strcmp_t _pre_strcmp = 0x4242424242424242;
82 |
83 | typedef void (*IOLog_t)(const char *format, ...)
84 | __attribute__((format(printf, 1, 2)));
85 | __attribute__((noinline)) IOLog_t IOLog = 0x4343434343434343;
86 |
87 | //__attribute__((noinline)) int _pre_strcmp(const char *a, const char *b){
88 | // return _strcmp(a, b);
89 | //}
90 |
91 | uint64_t payload(struct proc *p, struct stat_args *uap, /* __unused */ uint64_t *retval){
92 |
93 | char pathname[MAXPATHLEN];
94 | size_t dummy=0;
95 | int error;
96 |
97 | error = copyinstr(uap->path, pathname, MAXPATHLEN, &dummy);
98 | if(error) return 2;
99 |
100 | // iPhone5,2 11D27 kern_offsets
101 | // 803aab6f db "%s: %s\n"
102 | // 803b3a2d db "path"
103 | //
104 | // LOGDUMP -> "%s: %s\n"
105 | // BLOCKDUMP -> "path"
106 |
107 | IOLog(LOGDUMP, BLOCKDUMP, pathname);
108 | //_IOLog("%s: %s\n", "path", pathname);
109 |
110 | if(_pre_strcmp(pathname, STR_USER) == 0 ||
111 | _pre_strcmp(pathname, STR_BOOT) == 0 ||
112 | _pre_strcmp(pathname, STR_LIB) == 0 ||
113 | _pre_strcmp(pathname, STR_MNT) == 0 ||
114 | _pre_strcmp(pathname, STR_APP_CYDIA) == 0 ||
115 | _pre_strcmp(pathname, STR_PRV_VAR_LIB) == 0 ||
116 | _pre_strcmp(pathname, STR_VAR_LIB) == 0 ||
117 | _pre_strcmp(pathname, STR_PRV_VAR_MOBILE_LIBRARY_CACHES_CYDIA) == 0 ||
118 | _pre_strcmp(pathname, STR_VAR_MOBILE_LIBRARY_CACHES_CYDIA) == 0 ||
119 | _pre_strcmp(pathname, STR_PRV_ETC_SSH) == 0 ||
120 | _pre_strcmp(pathname, STR_LIBRARY_MS) == 0 ||
121 |
122 | _pre_strcmp(pathname, STR_LIBRARY_FRAMEWORKS_MS) == 0 ||
123 | _pre_strcmp(pathname, STR_PRIV_VAR_DB_STASH) == 0 ||
124 | _pre_strcmp(pathname, STR_VAR_DB_STASH) == 0 ||
125 | _pre_strcmp(pathname, STR_PRIV_VAR_STASH) == 0 ||
126 | _pre_strcmp(pathname, STR_VAR_STASH) == 0 ||
127 | _pre_strcmp(pathname, STR_USR_LIB_SUBSTRATE) == 0 ||
128 |
129 | _pre_strcmp(pathname, STR_LIBRARY_BT) == 0 ||
130 | _pre_strcmp(pathname, STR_LIBRARY_PREFLOADER_PREF_LIBERTY) == 0 ||
131 | _pre_strcmp(pathname, STR_APP_FLEX) == 0 ||
132 | _pre_strcmp(pathname, STR_LIBRARY_PREFLOADER_PREF_NOMS) == 0 ||
133 | _pre_strcmp(pathname, STR_PRIV_VAR_MOBILE_LIBRARY_FLEX3) == 0 ||
134 | _pre_strcmp(pathname, STR_VAR_MOBILE_LIBRARY_FLEX3) == 0){
135 | // return ENOENT;
136 | return 2;
137 | }
138 |
139 | return orig_stat(p, uap, retval);
140 | }
141 |
--------------------------------------------------------------------------------
/kernel/sysent_patch32.c:
--------------------------------------------------------------------------------
1 | /* sysent_patch32.c: Patch the kernel and hook syscall(188) for iOS 10.x
2 | * 2020/12/12
3 | * made by dora2ios
4 | *
5 | */
6 |
7 | #include
8 | #include
9 | #include
10 |
11 | #include
12 | #include
13 | #include
14 | #include
15 | #include "patchfinder32/patchfinder32.h"
16 | #include "payload/payload32.h"
17 |
18 | /* ARM page bits for L1 sections */
19 | #define L1_SHIFT 20 /* log2(1MB) */
20 |
21 | #define L1_SECT_PROTO (1 << 1) /* 0b10 */
22 |
23 | #define L1_SECT_B_BIT (1 << 2)
24 | #define L1_SECT_C_BIT (1 << 3)
25 |
26 | #define L1_SECT_SORDER (0) /* 0b00, not cacheable, strongly ordered */
27 | #define L1_SECT_SH_DEVICE (L1_SECT_B_BIT)
28 | #define L1_SECT_WT_NWA (L1_SECT_C_BIT)
29 | #define L1_SECT_WB_NWA (L1_SECT_B_BIT | L1_SECT_C_BIT)
30 | #define L1_SECT_S_BIT (1 << 16)
31 |
32 | #define L1_SECT_AP_URW (1 << 10) | (1 << 11)
33 | #define L1_SECT_PFN(x) (x & 0xFFF00000)
34 |
35 | #define L1_SECT_DEFPROT (L1_SECT_AP_URW)
36 | #define L1_SECT_DEFCACHE (L1_SECT_SORDER)
37 |
38 | #define L1_SECT_APX (1 << 15)
39 | #define L1_PAGE_PROTO (1 << 0)
40 | #define L1_COARSE_PT (0xFFFFFC00)
41 | #define PT_SIZE 256
42 | #define L2_PAGE_APX (1 << 9)
43 |
44 | #define L1_PROTO_TTE(paddr) (L1_SECT_PFN(paddr) | L1_SECT_S_BIT | L1_SECT_DEFPROT | L1_SECT_DEFCACHE | L1_SECT_PROTO)
45 |
46 | #define PFN_SHIFT 2
47 | #define TTB_OFFSET(vaddr) ((vaddr >> L1_SHIFT) << PFN_SHIFT)
48 |
49 | #define TTB_SIZE 4096
50 | #define DEFAULT_KERNEL_SLIDE 0x80000000
51 | #define KDUMP_SIZE 0x1200000
52 | #define CHUNK_SIZE 2048
53 |
54 |
55 | mach_port_t tfp0;
56 |
57 | kern_return_t mach_vm_read_overwrite(vm_map_t target_task, mach_vm_address_t address, mach_vm_size_t size, mach_vm_address_t data, mach_vm_size_t *outsize);
58 | kern_return_t mach_vm_write(vm_map_t target_task, mach_vm_address_t address, vm_offset_t data, mach_msg_type_number_t dataCnt);
59 | kern_return_t mach_vm_protect(vm_map_t target_task, mach_vm_address_t address, mach_vm_size_t size, boolean_t set_maximum, vm_prot_t new_protection);
60 | kern_return_t mach_vm_allocate(vm_map_t target, mach_vm_address_t *address, mach_vm_size_t size, int flags);
61 |
62 | void copyin(void* to, uint32_t from, size_t size) {
63 | mach_vm_size_t outsize = size;
64 | size_t szt = size;
65 | if (size > 0x1000) {
66 | size = 0x1000;
67 | }
68 | size_t off = 0;
69 | while (1) {
70 | mach_vm_read_overwrite(tfp0, off+from, size, (mach_vm_offset_t)(off+to), &outsize);
71 | szt -= size;
72 | off += size;
73 | if (szt == 0) {
74 | break;
75 | }
76 | size = szt;
77 | if (size > 0x1000) {
78 | size = 0x1000;
79 | }
80 |
81 | }
82 | }
83 |
84 | void copyout(uint32_t to, void* from, size_t size) {
85 | mach_vm_write(tfp0, to, (vm_offset_t)from, (mach_msg_type_number_t)size);
86 | }
87 |
88 | uint32_t rk32(uint32_t addr) {
89 | uint32_t val = 0;
90 | copyin(&val, addr, 4);
91 | return val;
92 | }
93 |
94 | uint32_t wk32(uint32_t addr, uint32_t val) {
95 | copyout(addr, &val, 4);
96 | return val;
97 | }
98 |
99 | uint32_t wk16(uint32_t addr, uint16_t val) {
100 | copyout(addr, &val, 2);
101 | return val;
102 | }
103 | /* -- end -- */
104 |
105 | mach_port_t get_kernel_task() {
106 | task_t kernel_task;
107 | if (KERN_SUCCESS != task_for_pid(mach_task_self(), 0, &kernel_task)) {
108 | if (KERN_SUCCESS != host_get_special_port(mach_host_self(), HOST_LOCAL_NODE, 4, &kernel_task)){
109 | return -1;
110 | }
111 | return kernel_task;
112 | }
113 | return kernel_task;
114 | }
115 |
116 | /*--- 32bit ---*/
117 | vm_address_t get_kernel_base() {
118 | vm_region_submap_info_data_64_t info;
119 | vm_size_t size;
120 | mach_msg_type_number_t info_count = VM_REGION_SUBMAP_INFO_COUNT_64;
121 | unsigned int depth = 0;
122 | vm_address_t addr = 0x81200000;
123 | while (1) {
124 | if (KERN_SUCCESS != vm_region_recurse_64(tfp0, &addr, &size, &depth, (vm_region_info_t) & info, &info_count))
125 | break;
126 | if (size > 1024 * 1024 * 1024) {
127 | /*
128 | * https://code.google.com/p/iphone-dataprotection/
129 | * hax, sometimes on iOS7 kernel starts at +0x200000 in the 1Gb region
130 | */
131 | pointer_t buf;
132 | mach_msg_type_number_t sz = 0;
133 | addr += 0x200000;
134 | vm_read(tfp0, addr + 0x1000, 512, &buf, &sz);
135 | if (*((uint32_t *)buf) != MH_MAGIC) {
136 | addr -= 0x200000;
137 | vm_read(tfp0, addr + 0x1000, 512, &buf, &sz);
138 | if (*((uint32_t*)buf) != MH_MAGIC) {
139 | break;
140 | }
141 | }
142 | vm_address_t kbase = addr + 0x1000;
143 | return kbase;
144 | }
145 | addr += size;
146 | }
147 | return -1;
148 | }
149 |
150 | void dump_kernel(vm_address_t kernel_base, uint8_t *dest, size_t ksize) {
151 | for (vm_address_t addr = kernel_base, e = 0; addr < kernel_base + ksize; addr += CHUNK_SIZE, e += CHUNK_SIZE) {
152 | pointer_t buf = 0;
153 | vm_address_t sz = 0;
154 | vm_read(tfp0, addr, CHUNK_SIZE, &buf, &sz);
155 | if (buf == 0 || sz == 0)
156 | continue;
157 | bcopy((uint8_t *)buf, dest + e, CHUNK_SIZE);
158 | }
159 | }
160 |
161 | /*-- jailbreak --*/
162 | void patch_page_table(uint32_t tte_virt, uint32_t tte_phys, uint32_t page) {
163 | uint32_t i = page >> 20;
164 | uint32_t j = (page >> 12) & 0xFF;
165 | uint32_t addr = tte_virt+(i<<2);
166 | uint32_t entry = rk32(addr);
167 | if ((entry & L1_PAGE_PROTO) == L1_PAGE_PROTO) {
168 | uint32_t page_entry = ((entry & L1_COARSE_PT) - tte_phys) + tte_virt;
169 | uint32_t addr2 = page_entry+(j<<2);
170 | uint32_t entry2 = rk32(addr2);
171 | if (entry2) {
172 | uint32_t new_entry2 = (entry2 & (~L2_PAGE_APX));
173 | wk32(addr2, new_entry2);
174 | }
175 | } else if ((entry & L1_SECT_PROTO) == L1_SECT_PROTO) {
176 | uint32_t new_entry = L1_PROTO_TTE(entry);
177 | new_entry &= ~L1_SECT_APX;
178 | wk32(addr, new_entry);
179 | }
180 | usleep(200000);
181 | }
182 |
183 | int find_ios_version() {
184 | struct utsname u = { 0 };
185 | uname(&u);
186 | if (strcmp(u.release, "15.0.0") == 0 ||
187 | strcmp(u.release, "15.4.0") == 0 ||
188 | strcmp(u.release, "15.5.0") == 0 ||
189 | strcmp(u.release, "15.6.0") == 0){
190 | return 9;
191 | }
192 |
193 | if (strcmp(u.release, "16.0.0") == 0 ||
194 | strcmp(u.release, "16.1.0") == 0 ||
195 | strcmp(u.release, "16.3.0") == 0 ||
196 | strcmp(u.release, "16.5.0") == 0 ||
197 | strcmp(u.release, "16.6.0") == 0 ||
198 | strcmp(u.release, "16.7.0") == 0){
199 | return 10;
200 | }
201 |
202 | return -1;
203 | }
204 |
205 | void usage(char** argv) {
206 | printf("sysent_patcher v1.4\n");
207 | printf("[2020/12/27] by dora2ios\n");
208 | printf("Supported devices: iOS 9 - 10 (32-bit only)\n");
209 | printf("\n");
210 | printf("usage: %s [options]\n", argv[0]);
211 | printf("\t-p\t\tpatch syscall(188)\n");
212 | printf("\n");
213 | printf("!!!! warning !!!!\n");
214 | printf("This software patches the kernel. As a result, the entire system may become unstable.\n");
215 | }
216 |
217 | int main(int argc, char** argv){
218 |
219 | #define PAYLOAD 0x80001c00
220 |
221 | int pwn_syscall;
222 |
223 | if(argc == 1) {
224 | usage(argv);
225 | return -1;
226 | }
227 |
228 | if(!strcmp(argv[1], "-p")) {
229 | pwn_syscall = 1;
230 | }
231 |
232 | if(pwn_syscall == 1){
233 |
234 | int iosver;
235 |
236 | iosver = find_ios_version();
237 | if(iosver == -1){
238 | printf("Failed to get ios version!\n");
239 | return -1;
240 | }
241 |
242 | tfp0 = get_kernel_task();
243 | if (!tfp0) {
244 | printf("Failed to get tfp0!\n");
245 | return -1;
246 | }
247 | printf("tfp0: %08x\n", tfp0);
248 |
249 | uint32_t kbase = get_kernel_base();
250 | if (!kbase) {
251 | printf("Failed to get kernel base!\n");
252 | return -1;
253 | }
254 | printf("kernel_base: %08x\n", kbase);
255 |
256 | uint32_t kslide = kbase - 0x80001000;
257 | printf("kslide: %08x\n", kslide);
258 |
259 | unsigned char *kdump;
260 | size_t ksize = KDUMP_SIZE;
261 |
262 | kdump = malloc(ksize);
263 | dump_kernel(kbase, kdump, ksize);
264 | if (!(*(uint32_t*)&kdump[0] == MH_MAGIC)) {
265 | printf("Failed to dump kernel!\n");
266 | return -1;
267 | }
268 |
269 | uint32_t kernel_pmap = kbase + get_kernel_pmap(kbase, kdump, ksize);
270 | if (!kbase) {
271 | printf("Failed to get kernel_pmap!\n");
272 | return -1;
273 | }
274 | printf("kernel_pmap: %08x\n", kernel_pmap);
275 |
276 | uint32_t kernel_pmap_store = rk32(kernel_pmap);
277 | uint32_t tte_virt = rk32(kernel_pmap_store);
278 | uint32_t tte_phys = rk32(kernel_pmap_store+4);
279 |
280 | printf("virt: %08x, phys: %08x\n", tte_virt, tte_phys);
281 |
282 | /* offsetfinder */
283 | uint32_t payload;
284 | uint32_t payload_start;
285 | uint32_t _copyinstr;
286 | uint32_t _IOLog;
287 | uint32_t _sysent_stat;
288 | uint32_t _syscall_stat;
289 | uint32_t _strcmp;
290 | uint32_t logdump;
291 | uint32_t blockdump;
292 |
293 | payload = PAYLOAD + kslide;
294 | payload_start = payload + 0x69;
295 |
296 | _copyinstr = find_copyinstr(kbase, kdump, ksize);
297 | _strcmp = find_strcmp(kbase, kdump, ksize);
298 | logdump = get_kernel_str(kbase, kdump, ksize, "%s: %s\n");
299 | blockdump = get_kernel_str(kbase, kdump, ksize, "path");
300 |
301 | if(iosver == 10){
302 | _IOLog = find_IOLog_post_iOSX(kbase, kdump, ksize);
303 | _sysent_stat = kbase + find_syscall188_post_iOSX(kbase, kdump, ksize, 0);
304 | _syscall_stat = find_syscall188_post_iOSX(kbase, kdump, ksize, 1);
305 | }
306 |
307 | if(iosver == 9){
308 | _IOLog = find_IOLog(kbase, kdump, ksize);
309 | _sysent_stat = kbase + find_syscall188(kbase, kdump, ksize, 0);
310 | _syscall_stat = find_syscall188(kbase, kdump, ksize, 1);
311 | }
312 |
313 | if((_syscall_stat + kbase) == payload_start){
314 | printf("Already patched.\n");
315 | return 0;
316 | }
317 |
318 | patch_page_table(tte_virt, tte_phys, _sysent_stat & ~0xFFF);
319 | patch_page_table(tte_virt, tte_phys, payload & ~0xFFF);
320 |
321 | /*
322 | * payload
323 | * 80001c00: _pre_strcmp
324 | * 80001c04: .data START
325 | * 80001c64: .data END
326 | * 80001c68: .text START, _payload
327 | * 80001c84: blx _copyinstr
328 | * 80001c96: bl _IOLog
329 | * 80001dbc: bl _orig_stat
330 | */
331 |
332 | copyout(payload, sysent_stat_bin, sysent_stat_bin_sz);
333 |
334 | // Use make_b_w instead of static offsets
335 | wk32(payload + 0x0000, make_b_w(0xc00, _strcmp)); // range: 0x10000000
336 |
337 | /* fix ptr */
338 | wk32(payload + 0x0004, logdump + kbase);
339 | wk32(payload + 0x0008, blockdump + kbase);
340 | wk32(payload + 0x000c, 0x000003e7 + payload);
341 | wk32(payload + 0x0010, 0x000003e1 + payload);
342 | wk32(payload + 0x0014, 0x000003dc + payload);
343 | wk32(payload + 0x0018, 0x000003d7 + payload);
344 | wk32(payload + 0x001c, 0x000003bf + payload);
345 | wk32(payload + 0x0020, 0x000003ae + payload);
346 | wk32(payload + 0x0024, 0x000003a5 + payload);
347 | wk32(payload + 0x0028, 0x00000371 + payload);
348 | wk32(payload + 0x002c, 0x00000345 + payload);
349 | wk32(payload + 0x0030, 0x00000334 + payload);
350 | wk32(payload + 0x0034, 0x0000031b + payload);
351 | wk32(payload + 0x0038, 0x000002ee + payload);
352 | wk32(payload + 0x003c, 0x000002d8 + payload);
353 | wk32(payload + 0x0040, 0x000002ca + payload);
354 | wk32(payload + 0x0044, 0x000002b7 + payload);
355 | wk32(payload + 0x0048, 0x000002ac + payload);
356 | wk32(payload + 0x004c, 0x00000290 + payload);
357 | wk32(payload + 0x0050, 0x0000027a + payload);
358 | wk32(payload + 0x0054, 0x00000242 + payload);
359 | wk32(payload + 0x0058, 0x0000022b + payload);
360 | wk32(payload + 0x005c, 0x000001f2 + payload);
361 | wk32(payload + 0x0060, 0x000001d8 + payload);
362 | wk32(payload + 0x0064, 0x000001d0 + payload);
363 |
364 | wk32(payload + 0x01c8, 0x00000004 + payload);
365 |
366 |
367 | /* make bl(x) */
368 | // Use make_bl instead of static offsets // range: 0x400000
369 | wk32(payload + 0x0084, make_bl(1, 0xc84, _copyinstr));
370 | wk32(payload + 0x0096, make_bl(0, 0xc96, _IOLog));
371 | wk32(payload + 0x01bc, make_bl(0, 0xdbc, _syscall_stat));
372 |
373 | /*
374 | * fix bl
375 | * global offsets
376 | */
377 | wk32(payload + 0x009e, 0xffaff7ff); // bl _pre_strcmp
378 | wk32(payload + 0x00aa, 0xffa9f7ff); // bl _pre_strcmp
379 | wk32(payload + 0x00b6, 0xffa3f7ff); // bl _pre_strcmp
380 | wk32(payload + 0x00c2, 0xff9df7ff); // bl _pre_strcmp
381 | wk32(payload + 0x00ce, 0xff97f7ff); // bl _pre_strcmp
382 | wk32(payload + 0x00da, 0xff91f7ff); // bl _pre_strcmp
383 | wk32(payload + 0x00e6, 0xff8bf7ff); // bl _pre_strcmp
384 | wk32(payload + 0x00f2, 0xff85f7ff); // bl _pre_strcmp
385 | wk32(payload + 0x00fe, 0xff7ff7ff); // bl _pre_strcmp
386 | wk32(payload + 0x010a, 0xff79f7ff); // bl _pre_strcmp
387 | wk32(payload + 0x0116, 0xff73f7ff); // bl _pre_strcmp
388 | wk32(payload + 0x0122, 0xff6df7ff); // bl _pre_strcmp
389 | wk32(payload + 0x012e, 0xff67f7ff); // bl _pre_strcmp
390 | wk32(payload + 0x013a, 0xff61f7ff); // bl _pre_strcmp
391 | wk32(payload + 0x0146, 0xff5bf7ff); // bl _pre_strcmp
392 | wk32(payload + 0x0152, 0xff55f7ff); // bl _pre_strcmp
393 | wk32(payload + 0x015e, 0xff4ff7ff); // bl _pre_strcmp
394 | wk32(payload + 0x016a, 0xff49f7ff); // bl _pre_strcmp
395 | wk32(payload + 0x0176, 0xff43f7ff); // bl _pre_strcmp
396 | wk32(payload + 0x0182, 0xff3df7ff); // bl _pre_strcmp
397 | wk32(payload + 0x0190, 0xff36f7ff); // bl _pre_strcmp
398 | wk32(payload + 0x019e, 0xff2ff7ff); // bl _pre_strcmp
399 | wk32(payload + 0x01ac, 0xff28f7ff); // bl _pre_strcmp
400 |
401 | /*
402 | * hook sysent
403 | * orig_stat -> _payload
404 | */
405 | wk32(_sysent_stat, payload_start);
406 |
407 | printf("DONE!?\n");
408 | }
409 |
410 | return 0;
411 | }
412 |
413 | /* svc list
414 | * stat, symlink, __sysctl, getpid, ptrace
415 | */
416 |
--------------------------------------------------------------------------------
/kernel/sysent_patch64.c:
--------------------------------------------------------------------------------
1 | /* sysent_patch64.c: Patch the kernel and hook syscall(188)
2 | * 2021/01/01
3 | * made by dora2ios
4 | *
5 | */
6 |
7 | #include
8 | #include
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 |
15 | #include "patchfinder64/patchfinder64.h"
16 |
17 | #define IMAGE_OFFSET 0x2000
18 | #define MACHO_HEADER_MAGIC 0xfeedfacf
19 | #define MAX_KASLR_SLIDE 0x21000000
20 | #define KERNEL_SEARCH_ADDRESS 0xfffffff007004000
21 | #define ptrSize sizeof(uintptr_t)
22 |
23 | // krnl offsets: for n51, 10.2.1(14d27)
24 | uint64_t OFFSETOF_COPYINSTR = 0xfffffff007183734;
25 | uint64_t OFFSETOF_STRCMP = 0xfffffff007166d78;
26 | uint64_t OFFSETOF_IOLOG = 0xfffffff0074653d0;
27 | uint64_t OFFSETOF_SYSENT_STAT = 0xfffffff007067798;
28 |
29 | mach_port_t tfp0;
30 |
31 | kern_return_t mach_vm_read_overwrite(vm_map_t target_task, mach_vm_address_t address, mach_vm_size_t size, mach_vm_address_t data, mach_vm_size_t *outsize);
32 | kern_return_t mach_vm_write(vm_map_t target_task, mach_vm_address_t address, vm_offset_t data, mach_msg_type_number_t dataCnt);
33 |
34 | kern_return_t mach_vm_protect(vm_map_t target_task, mach_vm_address_t address, mach_vm_size_t size, boolean_t set_maximum, vm_prot_t new_protection);
35 | kern_return_t mach_vm_allocate(vm_map_t target, mach_vm_address_t *address, mach_vm_size_t size, int flags);
36 |
37 | void copyin(void* to, uint64_t from, size_t size) {
38 | mach_vm_size_t outsize = size;
39 | size_t szt = size;
40 | if (size > 0x1000) {
41 | size = 0x1000;
42 | }
43 | size_t off = 0;
44 | while (1) {
45 | mach_vm_read_overwrite(tfp0, off+from, size, (mach_vm_offset_t)(off+to), &outsize);
46 | szt -= size;
47 | off += size;
48 | if (szt == 0) {
49 | break;
50 | }
51 | size = szt;
52 | if (size > 0x1000) {
53 | size = 0x1000;
54 | }
55 |
56 | }
57 | }
58 |
59 | void copyout(uint64_t to, void* from, size_t size) {
60 | mach_vm_write(tfp0, to, (vm_offset_t)from, (mach_msg_type_number_t)size);
61 | }
62 |
63 | uint64_t ReadAnywhere16(uint64_t addr) {
64 | uint16_t val = 0;
65 | copyin(&val, addr, 2);
66 | return val;
67 | }
68 |
69 | uint64_t ReadAnywhere32(uint64_t addr) {
70 | uint32_t val = 0;
71 | copyin(&val, addr, 4);
72 | return val;
73 | }
74 |
75 | uint64_t WriteAnywhere32(uint64_t addr, uint32_t val) {
76 | copyout(addr, &val, 4);
77 | return val;
78 | }
79 |
80 | uint64_t ReadAnywhere64(uint64_t addr) {
81 | uint64_t val = 0;
82 | copyin(&val, addr, 8);
83 | return val;
84 | }
85 |
86 | uint64_t WriteAnywhere64(uint64_t addr, uint64_t val) {
87 | copyout(addr, &val, 8);
88 | return val;
89 | }
90 |
91 |
92 | task_t get_kernel_task() {
93 | task_t kt = 0;
94 | kern_return_t r = task_for_pid(mach_task_self(), 0, &kt);
95 |
96 | if (r) {
97 | r = host_get_special_port(mach_host_self(), HOST_LOCAL_NODE, 4, &kt);
98 | if (r) {
99 | printf("task_for_pid and host_get_special_port failed\n");
100 | exit(-1);
101 | }
102 | }
103 |
104 | return kt;
105 | }
106 |
107 | uint64_t get_kernel_base(mach_port_t kernel_task) {
108 | uint64_t addr = 0;
109 | addr = KERNEL_SEARCH_ADDRESS+MAX_KASLR_SLIDE;
110 | while (1) {
111 | char *buf;
112 | mach_msg_type_number_t sz = 0;
113 | kern_return_t ret = vm_read(kernel_task, addr, 0x200, (vm_offset_t*)&buf, &sz);
114 | if (ret) {
115 | goto next;
116 | }
117 | if (*((uint32_t *)buf) == MACHO_HEADER_MAGIC) {
118 | int ret = vm_read(kernel_task, addr, 0x1000, (vm_offset_t*)&buf, &sz);
119 | if (ret != KERN_SUCCESS) {
120 | printf("Failed vm_read %i\n", ret);
121 | goto next;
122 | }
123 | for (uintptr_t i=addr; i < (addr+0x2000); i+=(ptrSize)) {
124 | mach_msg_type_number_t sz;
125 | int ret = vm_read(kernel_task, i, 0x120, (vm_offset_t*)&buf, &sz);
126 | if (ret != KERN_SUCCESS) {
127 | printf("Failed vm_read %i\n", ret);
128 | return 0;
129 | }
130 | if (!strcmp(buf, "__text") && !strcmp(buf+0x10, "__PRELINK_TEXT")) {
131 | return addr;
132 | }
133 | }
134 | }
135 | next:
136 | addr -= 0x200000;
137 | }
138 | printf("ERROR: Failed to find kernel base.\n");
139 | return 0;
140 | }
141 |
142 | #include "patchfinder64/pte_stuff.h"
143 |
144 | uint64_t gPhysBase;
145 | uint64_t gVirtBase;
146 | uint64_t level1_table;
147 |
148 | void kpp(int uref, uint64_t kernbase, uint64_t slide){
149 |
150 | int hooked;
151 |
152 | checkvad();
153 | uint64_t entryp;
154 |
155 | int rv = init_kernel(kernbase, NULL);
156 | assert(rv == 0);
157 |
158 | /*
159 | * @qwertyoruiop's KPP bypass
160 | *
161 | *
162 | */
163 |
164 |
165 | // hook sysent_stat
166 | {
167 | uint64_t payload_base = 0;
168 | kern_return_t err = mach_vm_allocate(tfp0, &payload_base, isvad == 0 ? 0x4000 : 0x1000, VM_FLAGS_ANYWHERE);
169 |
170 | uint64_t copyinstr_ptr = OFFSETOF_COPYINSTR + slide;
171 | uint64_t strcmp_ptr = OFFSETOF_STRCMP + slide;
172 | uint64_t IOLog_ptr = OFFSETOF_IOLOG + slide;
173 | uint64_t sysent_stat_addr = OFFSETOF_SYSENT_STAT + slide;
174 | uint64_t orig_stat = ReadAnywhere64(sysent_stat_addr);
175 |
176 | printf("sysent_stat_addr: 0x%016llx\n", sysent_stat_addr);
177 | printf("orig_stat: 0x%016llx\n", orig_stat);
178 | printf("copyinstr: 0x%016llx\n", copyinstr_ptr);
179 | printf("strcmp: 0x%016llx\n", strcmp_ptr);
180 | printf("IOLog: 0x%016llx\n", IOLog_ptr); // not work??
181 |
182 | printf("allocate: 0x%x\n", err);
183 | printf("payload_base: 0x%016llx\n", payload_base);
184 |
185 | printf("writing payload...\n");
186 | // Section __text
187 | // Range: [0x0; 0x2d8[ (728 bytes)
188 | WriteAnywhere32(0x000 + payload_base, 0xa9bc6ffc);
189 | WriteAnywhere32(0x004 + payload_base, 0xa90157f6);
190 | WriteAnywhere32(0x008 + payload_base, 0xa9024ff4);
191 | WriteAnywhere32(0x00c + payload_base, 0xa9037bfd);
192 | WriteAnywhere32(0x010 + payload_base, 0x9100c3fd);
193 | WriteAnywhere32(0x014 + payload_base, 0xd11083ff);
194 | WriteAnywhere32(0x018 + payload_base, 0xaa0103f4);
195 | WriteAnywhere32(0x01c + payload_base, 0xf9000fff);
196 | WriteAnywhere32(0x020 + payload_base, 0x90000008);
197 | WriteAnywhere32(0x024 + payload_base, 0xf942f909);
198 | WriteAnywhere32(0x028 + payload_base, 0xf9400288);
199 | WriteAnywhere32(0x02c + payload_base, 0xaa0203f3);
200 | WriteAnywhere32(0x030 + payload_base, 0xaa0003f5);
201 | WriteAnywhere32(0x034 + payload_base, 0x910083e1);
202 | WriteAnywhere32(0x038 + payload_base, 0x321603e2);
203 | WriteAnywhere32(0x03c + payload_base, 0x910063e3);
204 | WriteAnywhere32(0x040 + payload_base, 0xaa0803e0);
205 | WriteAnywhere32(0x044 + payload_base, 0x910083f6);
206 | WriteAnywhere32(0x048 + payload_base, 0xd63f0120);
207 | WriteAnywhere32(0x04c + payload_base, 0x34000100);
208 | WriteAnywhere32(0x050 + payload_base, 0x321f03e0);
209 | WriteAnywhere32(0x054 + payload_base, 0x911083ff);
210 | WriteAnywhere32(0x058 + payload_base, 0xa9437bfd);
211 | WriteAnywhere32(0x05c + payload_base, 0xa9424ff4);
212 | WriteAnywhere32(0x060 + payload_base, 0xa94157f6);
213 | WriteAnywhere32(0x064 + payload_base, 0xa8c46ffc);
214 | WriteAnywhere32(0x068 + payload_base, 0xd65f03c0);
215 | WriteAnywhere32(0x06c + payload_base, 0x90000008);
216 | WriteAnywhere32(0x070 + payload_base, 0x90000009);
217 | WriteAnywhere32(0x074 + payload_base, 0x9000000a);
218 | WriteAnywhere32(0x078 + payload_base, 0xf9430108);
219 | WriteAnywhere32(0x07c + payload_base, 0xf942ed20);
220 | WriteAnywhere32(0x080 + payload_base, 0xf942f149);
221 | WriteAnywhere32(0x084 + payload_base, 0xa9005be9);
222 | WriteAnywhere32(0x088 + payload_base, 0xd63f0100);
223 | WriteAnywhere32(0x08c + payload_base, 0x90000016);
224 | WriteAnywhere32(0x090 + payload_base, 0x90000008);
225 | WriteAnywhere32(0x094 + payload_base, 0xf942fec9);
226 | WriteAnywhere32(0x098 + payload_base, 0xf9429101);
227 | WriteAnywhere32(0x09c + payload_base, 0x910083e0);
228 | WriteAnywhere32(0x0a0 + payload_base, 0xd63f0120);
229 | WriteAnywhere32(0x0a4 + payload_base, 0x34fffd60);
230 | WriteAnywhere32(0x0a8 + payload_base, 0x90000009);
231 | WriteAnywhere32(0x0ac + payload_base, 0xf942fec8);
232 | WriteAnywhere32(0x0b0 + payload_base, 0xf9429521);
233 | WriteAnywhere32(0x0b4 + payload_base, 0x910083e0);
234 | WriteAnywhere32(0x0b8 + payload_base, 0xd63f0100);
235 | WriteAnywhere32(0x0bc + payload_base, 0x34fffca0);
236 | WriteAnywhere32(0x0c0 + payload_base, 0x90000009);
237 | WriteAnywhere32(0x0c4 + payload_base, 0xf942fec8);
238 | WriteAnywhere32(0x0c8 + payload_base, 0xf9429921);
239 | WriteAnywhere32(0x0cc + payload_base, 0x910083e0);
240 | WriteAnywhere32(0x0d0 + payload_base, 0xd63f0100);
241 | WriteAnywhere32(0x0d4 + payload_base, 0x34fffbe0);
242 | WriteAnywhere32(0x0d8 + payload_base, 0x90000009);
243 | WriteAnywhere32(0x0dc + payload_base, 0xf942fec8);
244 | WriteAnywhere32(0x0e0 + payload_base, 0xf9429d21);
245 | WriteAnywhere32(0x0e4 + payload_base, 0x910083e0);
246 | WriteAnywhere32(0x0e8 + payload_base, 0xd63f0100);
247 | WriteAnywhere32(0x0ec + payload_base, 0x34fffb20);
248 | WriteAnywhere32(0x0f0 + payload_base, 0x90000009);
249 | WriteAnywhere32(0x0f4 + payload_base, 0xf942fec8);
250 | WriteAnywhere32(0x0f8 + payload_base, 0xf942a121);
251 | WriteAnywhere32(0x0fc + payload_base, 0x910083e0);
252 | WriteAnywhere32(0x100 + payload_base, 0xd63f0100);
253 | WriteAnywhere32(0x104 + payload_base, 0x34fffa60);
254 | WriteAnywhere32(0x108 + payload_base, 0x90000009);
255 | WriteAnywhere32(0x10c + payload_base, 0xf942fec8);
256 | WriteAnywhere32(0x110 + payload_base, 0xf942a521);
257 | WriteAnywhere32(0x114 + payload_base, 0x910083e0);
258 | WriteAnywhere32(0x118 + payload_base, 0xd63f0100);
259 | WriteAnywhere32(0x11c + payload_base, 0x34fff9a0);
260 | WriteAnywhere32(0x120 + payload_base, 0x90000009);
261 | WriteAnywhere32(0x124 + payload_base, 0xf942fec8);
262 | WriteAnywhere32(0x128 + payload_base, 0xf942a921);
263 | WriteAnywhere32(0x12c + payload_base, 0x910083e0);
264 | WriteAnywhere32(0x130 + payload_base, 0xd63f0100);
265 | WriteAnywhere32(0x134 + payload_base, 0x34fff8e0);
266 | WriteAnywhere32(0x138 + payload_base, 0x90000009);
267 | WriteAnywhere32(0x13c + payload_base, 0xf942fec8);
268 | WriteAnywhere32(0x140 + payload_base, 0xf942ad21);
269 | WriteAnywhere32(0x144 + payload_base, 0x910083e0);
270 | WriteAnywhere32(0x148 + payload_base, 0xd63f0100);
271 | WriteAnywhere32(0x14c + payload_base, 0x34fff820);
272 | WriteAnywhere32(0x150 + payload_base, 0x90000009);
273 | WriteAnywhere32(0x154 + payload_base, 0xf942fec8);
274 | WriteAnywhere32(0x158 + payload_base, 0xf942b121);
275 | WriteAnywhere32(0x15c + payload_base, 0x910083e0);
276 | WriteAnywhere32(0x160 + payload_base, 0xd63f0100);
277 | WriteAnywhere32(0x164 + payload_base, 0x34fff760);
278 | WriteAnywhere32(0x168 + payload_base, 0x90000009);
279 | WriteAnywhere32(0x16c + payload_base, 0xf942fec8);
280 | WriteAnywhere32(0x170 + payload_base, 0xf942b521);
281 | WriteAnywhere32(0x174 + payload_base, 0x910083e0);
282 | WriteAnywhere32(0x178 + payload_base, 0xd63f0100);
283 | WriteAnywhere32(0x17c + payload_base, 0x34fff6a0);
284 | WriteAnywhere32(0x180 + payload_base, 0x90000009);
285 | WriteAnywhere32(0x184 + payload_base, 0xf942fec8);
286 | WriteAnywhere32(0x188 + payload_base, 0xf942b921);
287 | WriteAnywhere32(0x18c + payload_base, 0x910083e0);
288 | WriteAnywhere32(0x190 + payload_base, 0xd63f0100);
289 | WriteAnywhere32(0x194 + payload_base, 0x34fff5e0);
290 | WriteAnywhere32(0x198 + payload_base, 0x90000009);
291 | WriteAnywhere32(0x19c + payload_base, 0xf942fec8);
292 | WriteAnywhere32(0x1a0 + payload_base, 0xf942bd21);
293 | WriteAnywhere32(0x1a4 + payload_base, 0x910083e0);
294 | WriteAnywhere32(0x1a8 + payload_base, 0xd63f0100);
295 | WriteAnywhere32(0x1ac + payload_base, 0x34fff520);
296 | WriteAnywhere32(0x1b0 + payload_base, 0x90000009);
297 | WriteAnywhere32(0x1b4 + payload_base, 0xf942fec8);
298 | WriteAnywhere32(0x1b8 + payload_base, 0xf942c121);
299 | WriteAnywhere32(0x1bc + payload_base, 0x910083e0);
300 | WriteAnywhere32(0x1c0 + payload_base, 0xd63f0100);
301 | WriteAnywhere32(0x1c4 + payload_base, 0x34fff460);
302 | WriteAnywhere32(0x1c8 + payload_base, 0x90000009);
303 | WriteAnywhere32(0x1cc + payload_base, 0xf942fec8);
304 | WriteAnywhere32(0x1d0 + payload_base, 0xf942c521);
305 | WriteAnywhere32(0x1d4 + payload_base, 0x910083e0);
306 | WriteAnywhere32(0x1d8 + payload_base, 0xd63f0100);
307 | WriteAnywhere32(0x1dc + payload_base, 0x34fff3a0);
308 | WriteAnywhere32(0x1e0 + payload_base, 0x90000009);
309 | WriteAnywhere32(0x1e4 + payload_base, 0xf942fec8);
310 | WriteAnywhere32(0x1e8 + payload_base, 0xf942c921);
311 | WriteAnywhere32(0x1ec + payload_base, 0x910083e0);
312 | WriteAnywhere32(0x1f0 + payload_base, 0xd63f0100);
313 | WriteAnywhere32(0x1f4 + payload_base, 0x34fff2e0);
314 | WriteAnywhere32(0x1f8 + payload_base, 0x90000009);
315 | WriteAnywhere32(0x1fc + payload_base, 0xf942fec8);
316 | WriteAnywhere32(0x200 + payload_base, 0xf942cd21);
317 | WriteAnywhere32(0x204 + payload_base, 0x910083e0);
318 | WriteAnywhere32(0x208 + payload_base, 0xd63f0100);
319 | WriteAnywhere32(0x20c + payload_base, 0x34fff220);
320 | WriteAnywhere32(0x210 + payload_base, 0x90000009);
321 | WriteAnywhere32(0x214 + payload_base, 0xf942fec8);
322 | WriteAnywhere32(0x218 + payload_base, 0xf942d121);
323 | WriteAnywhere32(0x21c + payload_base, 0x910083e0);
324 | WriteAnywhere32(0x220 + payload_base, 0xd63f0100);
325 | WriteAnywhere32(0x224 + payload_base, 0x34fff160);
326 | WriteAnywhere32(0x228 + payload_base, 0x90000009);
327 | WriteAnywhere32(0x22c + payload_base, 0xf942fec8);
328 | WriteAnywhere32(0x230 + payload_base, 0xf942d521);
329 | WriteAnywhere32(0x234 + payload_base, 0x910083e0);
330 | WriteAnywhere32(0x238 + payload_base, 0xd63f0100);
331 | WriteAnywhere32(0x23c + payload_base, 0x34fff0a0);
332 | WriteAnywhere32(0x240 + payload_base, 0x90000009);
333 | WriteAnywhere32(0x244 + payload_base, 0xf942fec8);
334 | WriteAnywhere32(0x248 + payload_base, 0xf942d921);
335 | WriteAnywhere32(0x24c + payload_base, 0x910083e0);
336 | WriteAnywhere32(0x250 + payload_base, 0xd63f0100);
337 | WriteAnywhere32(0x254 + payload_base, 0x34ffefe0);
338 | WriteAnywhere32(0x258 + payload_base, 0x90000009);
339 | WriteAnywhere32(0x25c + payload_base, 0xf942fec8);
340 | WriteAnywhere32(0x260 + payload_base, 0xf942dd21);
341 | WriteAnywhere32(0x264 + payload_base, 0x910083e0);
342 | WriteAnywhere32(0x268 + payload_base, 0xd63f0100);
343 | WriteAnywhere32(0x26c + payload_base, 0x34ffef20);
344 | WriteAnywhere32(0x270 + payload_base, 0x90000009);
345 | WriteAnywhere32(0x274 + payload_base, 0xf942fec8);
346 | WriteAnywhere32(0x278 + payload_base, 0xf942e121);
347 | WriteAnywhere32(0x27c + payload_base, 0x910083e0);
348 | WriteAnywhere32(0x280 + payload_base, 0xd63f0100);
349 | WriteAnywhere32(0x284 + payload_base, 0x34ffee60);
350 | WriteAnywhere32(0x288 + payload_base, 0x90000009);
351 | WriteAnywhere32(0x28c + payload_base, 0xf942fec8);
352 | WriteAnywhere32(0x290 + payload_base, 0xf942e521);
353 | WriteAnywhere32(0x294 + payload_base, 0x910083e0);
354 | WriteAnywhere32(0x298 + payload_base, 0xd63f0100);
355 | WriteAnywhere32(0x29c + payload_base, 0x34ffeda0);
356 | WriteAnywhere32(0x2a0 + payload_base, 0x90000009);
357 | WriteAnywhere32(0x2a4 + payload_base, 0xf942fec8);
358 | WriteAnywhere32(0x2a8 + payload_base, 0xf942e921);
359 | WriteAnywhere32(0x2ac + payload_base, 0x910083e0);
360 | WriteAnywhere32(0x2b0 + payload_base, 0xd63f0100);
361 | WriteAnywhere32(0x2b4 + payload_base, 0x34ffece0);
362 | WriteAnywhere32(0x2b8 + payload_base, 0x90000008);
363 | WriteAnywhere32(0x2bc + payload_base, 0xf942f508);
364 | WriteAnywhere32(0x2c0 + payload_base, 0xaa1503e0);
365 | WriteAnywhere32(0x2c4 + payload_base, 0xaa1403e1);
366 | WriteAnywhere32(0x2c8 + payload_base, 0xaa1303e2);
367 | WriteAnywhere32(0x2cc + payload_base, 0xd63f0100);
368 | WriteAnywhere32(0x2d0 + payload_base, 0x93407c00);
369 | WriteAnywhere32(0x2d4 + payload_base, 0x17ffff60);
370 |
371 |
372 | // Section __cstring
373 | // Range: [0x2d8; 0x51e[ (582 bytes)
374 | WriteAnywhere32(0x2d8 + payload_base, 0x6573552f);
375 | WriteAnywhere32(0x2dc + payload_base, 0x622f0072);
376 | WriteAnywhere32(0x2e0 + payload_base, 0x00746f6f);
377 | WriteAnywhere32(0x2e4 + payload_base, 0x62696c2f);
378 | WriteAnywhere32(0x2e8 + payload_base, 0x6e6d2f00);
379 | WriteAnywhere32(0x2ec + payload_base, 0x412f0074);
380 | WriteAnywhere32(0x2f0 + payload_base, 0x696c7070);
381 | WriteAnywhere32(0x2f4 + payload_base, 0x69746163);
382 | WriteAnywhere32(0x2f8 + payload_base, 0x2f736e6f);
383 | WriteAnywhere32(0x2fc + payload_base, 0x69647943);
384 | WriteAnywhere32(0x300 + payload_base, 0x70612e61);
385 | WriteAnywhere32(0x304 + payload_base, 0x702f0070);
386 | WriteAnywhere32(0x308 + payload_base, 0x61766972);
387 | WriteAnywhere32(0x30c + payload_base, 0x762f6574);
388 | WriteAnywhere32(0x310 + payload_base, 0x6c2f7261);
389 | WriteAnywhere32(0x314 + payload_base, 0x2f006269);
390 | WriteAnywhere32(0x318 + payload_base, 0x2f726176);
391 | WriteAnywhere32(0x31c + payload_base, 0x0062696c);
392 | WriteAnywhere32(0x320 + payload_base, 0x6972702f);
393 | WriteAnywhere32(0x324 + payload_base, 0x65746176);
394 | WriteAnywhere32(0x328 + payload_base, 0x7261762f);
395 | WriteAnywhere32(0x32c + payload_base, 0x626f6d2f);
396 | WriteAnywhere32(0x330 + payload_base, 0x2f656c69);
397 | WriteAnywhere32(0x334 + payload_base, 0x7262694c);
398 | WriteAnywhere32(0x338 + payload_base, 0x2f797261);
399 | WriteAnywhere32(0x33c + payload_base, 0x68636143);
400 | WriteAnywhere32(0x340 + payload_base, 0x632f7365);
401 | WriteAnywhere32(0x344 + payload_base, 0x732e6d6f);
402 | WriteAnywhere32(0x348 + payload_base, 0x69727561);
403 | WriteAnywhere32(0x34c + payload_base, 0x79432e6b);
404 | WriteAnywhere32(0x350 + payload_base, 0x00616964);
405 | WriteAnywhere32(0x354 + payload_base, 0x7261762f);
406 | WriteAnywhere32(0x358 + payload_base, 0x626f6d2f);
407 | WriteAnywhere32(0x35c + payload_base, 0x2f656c69);
408 | WriteAnywhere32(0x360 + payload_base, 0x7262694c);
409 | WriteAnywhere32(0x364 + payload_base, 0x2f797261);
410 | WriteAnywhere32(0x368 + payload_base, 0x68636143);
411 | WriteAnywhere32(0x36c + payload_base, 0x632f7365);
412 | WriteAnywhere32(0x370 + payload_base, 0x732e6d6f);
413 | WriteAnywhere32(0x374 + payload_base, 0x69727561);
414 | WriteAnywhere32(0x378 + payload_base, 0x79432e6b);
415 | WriteAnywhere32(0x37c + payload_base, 0x00616964);
416 | WriteAnywhere32(0x380 + payload_base, 0x6972702f);
417 | WriteAnywhere32(0x384 + payload_base, 0x65746176);
418 | WriteAnywhere32(0x388 + payload_base, 0x6374652f);
419 | WriteAnywhere32(0x38c + payload_base, 0x6873732f);
420 | WriteAnywhere32(0x390 + payload_base, 0x694c2f00);
421 | WriteAnywhere32(0x394 + payload_base, 0x72617262);
422 | WriteAnywhere32(0x398 + payload_base, 0x6f4d2f79);
423 | WriteAnywhere32(0x39c + payload_base, 0x656c6962);
424 | WriteAnywhere32(0x3a0 + payload_base, 0x73627553);
425 | WriteAnywhere32(0x3a4 + payload_base, 0x74617274);
426 | WriteAnywhere32(0x3a8 + payload_base, 0x4c2f0065);
427 | WriteAnywhere32(0x3ac + payload_base, 0x61726269);
428 | WriteAnywhere32(0x3b0 + payload_base, 0x462f7972);
429 | WriteAnywhere32(0x3b4 + payload_base, 0x656d6172);
430 | WriteAnywhere32(0x3b8 + payload_base, 0x6b726f77);
431 | WriteAnywhere32(0x3bc + payload_base, 0x79432f73);
432 | WriteAnywhere32(0x3c0 + payload_base, 0x53616964);
433 | WriteAnywhere32(0x3c4 + payload_base, 0x74736275);
434 | WriteAnywhere32(0x3c8 + payload_base, 0x65746172);
435 | WriteAnywhere32(0x3cc + payload_base, 0x6172662e);
436 | WriteAnywhere32(0x3d0 + payload_base, 0x6f77656d);
437 | WriteAnywhere32(0x3d4 + payload_base, 0x2f006b72);
438 | WriteAnywhere32(0x3d8 + payload_base, 0x76697270);
439 | WriteAnywhere32(0x3dc + payload_base, 0x2f657461);
440 | WriteAnywhere32(0x3e0 + payload_base, 0x2f726176);
441 | WriteAnywhere32(0x3e4 + payload_base, 0x732f6264);
442 | WriteAnywhere32(0x3e8 + payload_base, 0x68736174);
443 | WriteAnywhere32(0x3ec + payload_base, 0x61762f00);
444 | WriteAnywhere32(0x3f0 + payload_base, 0x62642f72);
445 | WriteAnywhere32(0x3f4 + payload_base, 0x6174732f);
446 | WriteAnywhere32(0x3f8 + payload_base, 0x2f006873);
447 | WriteAnywhere32(0x3fc + payload_base, 0x76697270);
448 | WriteAnywhere32(0x400 + payload_base, 0x2f657461);
449 | WriteAnywhere32(0x404 + payload_base, 0x2f726176);
450 | WriteAnywhere32(0x408 + payload_base, 0x73617473);
451 | WriteAnywhere32(0x40c + payload_base, 0x762f0068);
452 | WriteAnywhere32(0x410 + payload_base, 0x732f7261);
453 | WriteAnywhere32(0x414 + payload_base, 0x68736174);
454 | WriteAnywhere32(0x418 + payload_base, 0x73752f00);
455 | WriteAnywhere32(0x41c + payload_base, 0x696c2f72);
456 | WriteAnywhere32(0x420 + payload_base, 0x696c2f62);
457 | WriteAnywhere32(0x424 + payload_base, 0x62757362);
458 | WriteAnywhere32(0x428 + payload_base, 0x61727473);
459 | WriteAnywhere32(0x42c + payload_base, 0x642e6574);
460 | WriteAnywhere32(0x430 + payload_base, 0x62696c79);
461 | WriteAnywhere32(0x434 + payload_base, 0x694c2f00);
462 | WriteAnywhere32(0x438 + payload_base, 0x72617262);
463 | WriteAnywhere32(0x43c + payload_base, 0x72422f79);
464 | WriteAnywhere32(0x440 + payload_base, 0x546b6165);
465 | WriteAnywhere32(0x444 + payload_base, 0x756f7268);
466 | WriteAnywhere32(0x448 + payload_base, 0x2f006867);
467 | WriteAnywhere32(0x44c + payload_base, 0x7262694c);
468 | WriteAnywhere32(0x450 + payload_base, 0x2f797261);
469 | WriteAnywhere32(0x454 + payload_base, 0x66657250);
470 | WriteAnywhere32(0x458 + payload_base, 0x6e657265);
471 | WriteAnywhere32(0x45c + payload_base, 0x6f4c6563);
472 | WriteAnywhere32(0x460 + payload_base, 0x72656461);
473 | WriteAnywhere32(0x464 + payload_base, 0x6572502f);
474 | WriteAnywhere32(0x468 + payload_base, 0x65726566);
475 | WriteAnywhere32(0x46c + payload_base, 0x7365636e);
476 | WriteAnywhere32(0x470 + payload_base, 0x62694c2f);
477 | WriteAnywhere32(0x474 + payload_base, 0x79747265);
478 | WriteAnywhere32(0x478 + payload_base, 0x66657250);
479 | WriteAnywhere32(0x47c + payload_base, 0x696c702e);
480 | WriteAnywhere32(0x480 + payload_base, 0x2f007473);
481 | WriteAnywhere32(0x484 + payload_base, 0x6c707041);
482 | WriteAnywhere32(0x488 + payload_base, 0x74616369);
483 | WriteAnywhere32(0x48c + payload_base, 0x736e6f69);
484 | WriteAnywhere32(0x490 + payload_base, 0x656c462f);
485 | WriteAnywhere32(0x494 + payload_base, 0x70612e78);
486 | WriteAnywhere32(0x498 + payload_base, 0x4c2f0070);
487 | WriteAnywhere32(0x49c + payload_base, 0x61726269);
488 | WriteAnywhere32(0x4a0 + payload_base, 0x502f7972);
489 | WriteAnywhere32(0x4a4 + payload_base, 0x65666572);
490 | WriteAnywhere32(0x4a8 + payload_base, 0x636e6572);
491 | WriteAnywhere32(0x4ac + payload_base, 0x616f4c65);
492 | WriteAnywhere32(0x4b0 + payload_base, 0x2f726564);
493 | WriteAnywhere32(0x4b4 + payload_base, 0x66657250);
494 | WriteAnywhere32(0x4b8 + payload_base, 0x6e657265);
495 | WriteAnywhere32(0x4bc + payload_base, 0x2f736563);
496 | WriteAnywhere32(0x4c0 + payload_base, 0x75536f4e);
497 | WriteAnywhere32(0x4c4 + payload_base, 0x69747362);
498 | WriteAnywhere32(0x4c8 + payload_base, 0x65747574);
499 | WriteAnywhere32(0x4cc + payload_base, 0x696c702e);
500 | WriteAnywhere32(0x4d0 + payload_base, 0x2f007473);
501 | WriteAnywhere32(0x4d4 + payload_base, 0x76697270);
502 | WriteAnywhere32(0x4d8 + payload_base, 0x2f657461);
503 | WriteAnywhere32(0x4dc + payload_base, 0x2f726176);
504 | WriteAnywhere32(0x4e0 + payload_base, 0x69626f6d);
505 | WriteAnywhere32(0x4e4 + payload_base, 0x4c2f656c);
506 | WriteAnywhere32(0x4e8 + payload_base, 0x61726269);
507 | WriteAnywhere32(0x4ec + payload_base, 0x462f7972);
508 | WriteAnywhere32(0x4f0 + payload_base, 0x3378656c);
509 | WriteAnywhere32(0x4f4 + payload_base, 0x61762f00);
510 | WriteAnywhere32(0x4f8 + payload_base, 0x6f6d2f72);
511 | WriteAnywhere32(0x4fc + payload_base, 0x656c6962);
512 | WriteAnywhere32(0x500 + payload_base, 0x62694c2f);
513 | WriteAnywhere32(0x504 + payload_base, 0x79726172);
514 | WriteAnywhere32(0x508 + payload_base, 0x656c462f);
515 | WriteAnywhere32(0x50c + payload_base, 0x5b003378);
516 | WriteAnywhere32(0x510 + payload_base, 0x3a5d7325);
517 | WriteAnywhere32(0x514 + payload_base, 0x0a732520);
518 | WriteAnywhere32(0x518 + payload_base, 0x61747300);
519 | WriteAnywhere32(0x51c + payload_base, 0x00000074);
520 |
521 | // Section __data
522 | // Range: [0x520; 0x608[ (232 bytes)
523 | WriteAnywhere64(0x520 + payload_base, 0x00000000000002d8 + payload_base);
524 | WriteAnywhere64(0x528 + payload_base, 0x00000000000002de + payload_base);
525 | WriteAnywhere64(0x530 + payload_base, 0x00000000000002e4 + payload_base);
526 | WriteAnywhere64(0x538 + payload_base, 0x00000000000002e9 + payload_base);
527 | WriteAnywhere64(0x540 + payload_base, 0x00000000000002ee + payload_base);
528 | WriteAnywhere64(0x548 + payload_base, 0x0000000000000306 + payload_base);
529 | WriteAnywhere64(0x550 + payload_base, 0x0000000000000317 + payload_base);
530 | WriteAnywhere64(0x558 + payload_base, 0x0000000000000320 + payload_base);
531 | WriteAnywhere64(0x560 + payload_base, 0x0000000000000354 + payload_base);
532 | WriteAnywhere64(0x568 + payload_base, 0x0000000000000380 + payload_base);
533 | WriteAnywhere64(0x570 + payload_base, 0x0000000000000391 + payload_base);
534 | WriteAnywhere64(0x578 + payload_base, 0x00000000000003aa + payload_base);
535 | WriteAnywhere64(0x580 + payload_base, 0x00000000000003d7 + payload_base);
536 | WriteAnywhere64(0x588 + payload_base, 0x00000000000003ed + payload_base);
537 | WriteAnywhere64(0x590 + payload_base, 0x00000000000003fb + payload_base);
538 | WriteAnywhere64(0x598 + payload_base, 0x000000000000040e + payload_base);
539 | WriteAnywhere64(0x5a0 + payload_base, 0x0000000000000419 + payload_base);
540 | WriteAnywhere64(0x5a8 + payload_base, 0x0000000000000435 + payload_base);
541 | WriteAnywhere64(0x5b0 + payload_base, 0x000000000000044b + payload_base);
542 | WriteAnywhere64(0x5b8 + payload_base, 0x0000000000000483 + payload_base);
543 | WriteAnywhere64(0x5c0 + payload_base, 0x000000000000049a + payload_base);
544 | WriteAnywhere64(0x5c8 + payload_base, 0x00000000000004d3 + payload_base);
545 | WriteAnywhere64(0x5d0 + payload_base, 0x00000000000004f5 + payload_base);
546 | WriteAnywhere64(0x5d8 + payload_base, 0x000000000000050f + payload_base);
547 | WriteAnywhere64(0x5e0 + payload_base, 0x0000000000000519 + payload_base);
548 | WriteAnywhere64(0x5e8 + payload_base, orig_stat); // _orig_stat
549 | WriteAnywhere64(0x5f0 + payload_base, copyinstr_ptr); // _copyinstr
550 | WriteAnywhere64(0x5f8 + payload_base, strcmp_ptr); // _strcmp
551 | WriteAnywhere64(0x600 + payload_base, IOLog_ptr); // _IOLog
552 |
553 | err = mach_vm_protect(tfp0, payload_base, isvad == 0 ? 0x4000 : 0x1000, 0, VM_PROT_READ|VM_PROT_EXECUTE);
554 | printf("vm_protect: 0x%d\n", err);
555 | sleep(1);
556 |
557 | RemapPage(sysent_stat_addr);
558 | printf("0x%016llx -> 0x%016llx\n", sysent_stat_addr, NewPointer(sysent_stat_addr));
559 | printf("patching kernel...\n");
560 | WriteAnywhere64(NewPointer(sysent_stat_addr), payload_base);
561 |
562 | }
563 |
564 | }
565 |
566 | int main(){
567 |
568 | uint64_t kbase;
569 | uint64_t kslide;
570 |
571 | tfp0 = get_kernel_task();
572 | kbase = get_kernel_base(tfp0);
573 | kslide = kbase - KERNEL_SEARCH_ADDRESS;
574 | printf("kernel base: 0x%016llx\n", kbase);
575 | printf("kslide: 0x%016llx\n", kslide);
576 |
577 | kpp(0, kbase, kslide);
578 |
579 | printf("well done??\n");
580 |
581 | return 0;
582 | }
583 |
--------------------------------------------------------------------------------
/kernel/tfp0.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | get-task-allow
6 |
7 | run-unsigned-code
8 |
9 | task_for_pid-allow
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------