···7575 src/dyld/binfmt_misc.cpp
7676)
77777878+SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib${SUFFIX}/darling")
7979+#SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--enable-new-dtags")
8080+7881add_executable(dyld${SUFFIX} ${dyld_SRCS})
7982target_link_libraries(dyld${SUFFIX} -ldl -lpthread mach-o util)
80838181-set(fatmacho-extract_SRCS
8282- src/dyld/extract.cpp
8383-)
8484+#set(fatmacho-extract_SRCS
8585+# src/dyld/extract.cpp
8686+#)
84878585-add_executable(fatmacho-extract ${fatmacho-extract_SRCS})
8686-target_link_libraries(fatmacho-extract -ldl -lpthread -l:./libmach-o.so -Wl,-export-dynamic)
8888+#add_executable(fatmacho-extract ${fatmacho-extract_SRCS})
8989+#target_link_libraries(fatmacho-extract -ldl -lpthread -l:./libmach-o.so -Wl,-export-dynamic)
87908891set(motool_SRCS
8992 src/motool/motool.cpp
···969997100# If building on a 64bit system, only install these for 64bits
98101if (NOT DEFINED SUFFIX OR SUFFIX STREQUAL "64")
9999- install(TARGETS fatmacho-extract motool DESTINATION bin)
102102+ install(TARGETS motool DESTINATION bin)
100103 install(FILES etc/dylib.conf DESTINATION /etc/darling)
104104+ add_subdirectory(src/macbinary)
105105+ add_subdirectory(src/libmacarchive)
101106endif(NOT DEFINED SUFFIX OR SUFFIX STREQUAL "64")
102107103103-install(TARGETS mach-o DESTINATION lib${SUFFIX})
108108+install(TARGETS mach-o DESTINATION "lib${SUFFIX}/darling")
104109105110add_subdirectory(src/libSystem)
106111#add_subdirectory(src/libcxxdarwin)
107112add_subdirectory(src/libobjcdarwin)
108113#add_subdirectory(src/libunwind-darwin-gcc)
109114add_subdirectory(src/libncurses)
110110-#add_subdirectory(src/CoreServices)
115115+add_subdirectory(src/CoreSecurity)
116116+add_subdirectory(src/thin)
111117112118add_dependencies(dyld${SUFFIX} mach-o)
113119add_dependencies(System.B.dylib genfuncmap)
+674
LICENSE
···11+ GNU GENERAL PUBLIC LICENSE
22+ Version 3, 29 June 2007
33+44+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
55+ Everyone is permitted to copy and distribute verbatim copies
66+ of this license document, but changing it is not allowed.
77+88+ Preamble
99+1010+ The GNU General Public License is a free, copyleft license for
1111+software and other kinds of works.
1212+1313+ The licenses for most software and other practical works are designed
1414+to take away your freedom to share and change the works. By contrast,
1515+the GNU General Public License is intended to guarantee your freedom to
1616+share and change all versions of a program--to make sure it remains free
1717+software for all its users. We, the Free Software Foundation, use the
1818+GNU General Public License for most of our software; it applies also to
1919+any other work released this way by its authors. You can apply it to
2020+your programs, too.
2121+2222+ When we speak of free software, we are referring to freedom, not
2323+price. Our General Public Licenses are designed to make sure that you
2424+have the freedom to distribute copies of free software (and charge for
2525+them if you wish), that you receive source code or can get it if you
2626+want it, that you can change the software or use pieces of it in new
2727+free programs, and that you know you can do these things.
2828+2929+ To protect your rights, we need to prevent others from denying you
3030+these rights or asking you to surrender the rights. Therefore, you have
3131+certain responsibilities if you distribute copies of the software, or if
3232+you modify it: responsibilities to respect the freedom of others.
3333+3434+ For example, if you distribute copies of such a program, whether
3535+gratis or for a fee, you must pass on to the recipients the same
3636+freedoms that you received. You must make sure that they, too, receive
3737+or can get the source code. And you must show them these terms so they
3838+know their rights.
3939+4040+ Developers that use the GNU GPL protect your rights with two steps:
4141+(1) assert copyright on the software, and (2) offer you this License
4242+giving you legal permission to copy, distribute and/or modify it.
4343+4444+ For the developers' and authors' protection, the GPL clearly explains
4545+that there is no warranty for this free software. For both users' and
4646+authors' sake, the GPL requires that modified versions be marked as
4747+changed, so that their problems will not be attributed erroneously to
4848+authors of previous versions.
4949+5050+ Some devices are designed to deny users access to install or run
5151+modified versions of the software inside them, although the manufacturer
5252+can do so. This is fundamentally incompatible with the aim of
5353+protecting users' freedom to change the software. The systematic
5454+pattern of such abuse occurs in the area of products for individuals to
5555+use, which is precisely where it is most unacceptable. Therefore, we
5656+have designed this version of the GPL to prohibit the practice for those
5757+products. If such problems arise substantially in other domains, we
5858+stand ready to extend this provision to those domains in future versions
5959+of the GPL, as needed to protect the freedom of users.
6060+6161+ Finally, every program is threatened constantly by software patents.
6262+States should not allow patents to restrict development and use of
6363+software on general-purpose computers, but in those that do, we wish to
6464+avoid the special danger that patents applied to a free program could
6565+make it effectively proprietary. To prevent this, the GPL assures that
6666+patents cannot be used to render the program non-free.
6767+6868+ The precise terms and conditions for copying, distribution and
6969+modification follow.
7070+7171+ TERMS AND CONDITIONS
7272+7373+ 0. Definitions.
7474+7575+ "This License" refers to version 3 of the GNU General Public License.
7676+7777+ "Copyright" also means copyright-like laws that apply to other kinds of
7878+works, such as semiconductor masks.
7979+8080+ "The Program" refers to any copyrightable work licensed under this
8181+License. Each licensee is addressed as "you". "Licensees" and
8282+"recipients" may be individuals or organizations.
8383+8484+ To "modify" a work means to copy from or adapt all or part of the work
8585+in a fashion requiring copyright permission, other than the making of an
8686+exact copy. The resulting work is called a "modified version" of the
8787+earlier work or a work "based on" the earlier work.
8888+8989+ A "covered work" means either the unmodified Program or a work based
9090+on the Program.
9191+9292+ To "propagate" a work means to do anything with it that, without
9393+permission, would make you directly or secondarily liable for
9494+infringement under applicable copyright law, except executing it on a
9595+computer or modifying a private copy. Propagation includes copying,
9696+distribution (with or without modification), making available to the
9797+public, and in some countries other activities as well.
9898+9999+ To "convey" a work means any kind of propagation that enables other
100100+parties to make or receive copies. Mere interaction with a user through
101101+a computer network, with no transfer of a copy, is not conveying.
102102+103103+ An interactive user interface displays "Appropriate Legal Notices"
104104+to the extent that it includes a convenient and prominently visible
105105+feature that (1) displays an appropriate copyright notice, and (2)
106106+tells the user that there is no warranty for the work (except to the
107107+extent that warranties are provided), that licensees may convey the
108108+work under this License, and how to view a copy of this License. If
109109+the interface presents a list of user commands or options, such as a
110110+menu, a prominent item in the list meets this criterion.
111111+112112+ 1. Source Code.
113113+114114+ The "source code" for a work means the preferred form of the work
115115+for making modifications to it. "Object code" means any non-source
116116+form of a work.
117117+118118+ A "Standard Interface" means an interface that either is an official
119119+standard defined by a recognized standards body, or, in the case of
120120+interfaces specified for a particular programming language, one that
121121+is widely used among developers working in that language.
122122+123123+ The "System Libraries" of an executable work include anything, other
124124+than the work as a whole, that (a) is included in the normal form of
125125+packaging a Major Component, but which is not part of that Major
126126+Component, and (b) serves only to enable use of the work with that
127127+Major Component, or to implement a Standard Interface for which an
128128+implementation is available to the public in source code form. A
129129+"Major Component", in this context, means a major essential component
130130+(kernel, window system, and so on) of the specific operating system
131131+(if any) on which the executable work runs, or a compiler used to
132132+produce the work, or an object code interpreter used to run it.
133133+134134+ The "Corresponding Source" for a work in object code form means all
135135+the source code needed to generate, install, and (for an executable
136136+work) run the object code and to modify the work, including scripts to
137137+control those activities. However, it does not include the work's
138138+System Libraries, or general-purpose tools or generally available free
139139+programs which are used unmodified in performing those activities but
140140+which are not part of the work. For example, Corresponding Source
141141+includes interface definition files associated with source files for
142142+the work, and the source code for shared libraries and dynamically
143143+linked subprograms that the work is specifically designed to require,
144144+such as by intimate data communication or control flow between those
145145+subprograms and other parts of the work.
146146+147147+ The Corresponding Source need not include anything that users
148148+can regenerate automatically from other parts of the Corresponding
149149+Source.
150150+151151+ The Corresponding Source for a work in source code form is that
152152+same work.
153153+154154+ 2. Basic Permissions.
155155+156156+ All rights granted under this License are granted for the term of
157157+copyright on the Program, and are irrevocable provided the stated
158158+conditions are met. This License explicitly affirms your unlimited
159159+permission to run the unmodified Program. The output from running a
160160+covered work is covered by this License only if the output, given its
161161+content, constitutes a covered work. This License acknowledges your
162162+rights of fair use or other equivalent, as provided by copyright law.
163163+164164+ You may make, run and propagate covered works that you do not
165165+convey, without conditions so long as your license otherwise remains
166166+in force. You may convey covered works to others for the sole purpose
167167+of having them make modifications exclusively for you, or provide you
168168+with facilities for running those works, provided that you comply with
169169+the terms of this License in conveying all material for which you do
170170+not control copyright. Those thus making or running the covered works
171171+for you must do so exclusively on your behalf, under your direction
172172+and control, on terms that prohibit them from making any copies of
173173+your copyrighted material outside their relationship with you.
174174+175175+ Conveying under any other circumstances is permitted solely under
176176+the conditions stated below. Sublicensing is not allowed; section 10
177177+makes it unnecessary.
178178+179179+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180180+181181+ No covered work shall be deemed part of an effective technological
182182+measure under any applicable law fulfilling obligations under article
183183+11 of the WIPO copyright treaty adopted on 20 December 1996, or
184184+similar laws prohibiting or restricting circumvention of such
185185+measures.
186186+187187+ When you convey a covered work, you waive any legal power to forbid
188188+circumvention of technological measures to the extent such circumvention
189189+is effected by exercising rights under this License with respect to
190190+the covered work, and you disclaim any intention to limit operation or
191191+modification of the work as a means of enforcing, against the work's
192192+users, your or third parties' legal rights to forbid circumvention of
193193+technological measures.
194194+195195+ 4. Conveying Verbatim Copies.
196196+197197+ You may convey verbatim copies of the Program's source code as you
198198+receive it, in any medium, provided that you conspicuously and
199199+appropriately publish on each copy an appropriate copyright notice;
200200+keep intact all notices stating that this License and any
201201+non-permissive terms added in accord with section 7 apply to the code;
202202+keep intact all notices of the absence of any warranty; and give all
203203+recipients a copy of this License along with the Program.
204204+205205+ You may charge any price or no price for each copy that you convey,
206206+and you may offer support or warranty protection for a fee.
207207+208208+ 5. Conveying Modified Source Versions.
209209+210210+ You may convey a work based on the Program, or the modifications to
211211+produce it from the Program, in the form of source code under the
212212+terms of section 4, provided that you also meet all of these conditions:
213213+214214+ a) The work must carry prominent notices stating that you modified
215215+ it, and giving a relevant date.
216216+217217+ b) The work must carry prominent notices stating that it is
218218+ released under this License and any conditions added under section
219219+ 7. This requirement modifies the requirement in section 4 to
220220+ "keep intact all notices".
221221+222222+ c) You must license the entire work, as a whole, under this
223223+ License to anyone who comes into possession of a copy. This
224224+ License will therefore apply, along with any applicable section 7
225225+ additional terms, to the whole of the work, and all its parts,
226226+ regardless of how they are packaged. This License gives no
227227+ permission to license the work in any other way, but it does not
228228+ invalidate such permission if you have separately received it.
229229+230230+ d) If the work has interactive user interfaces, each must display
231231+ Appropriate Legal Notices; however, if the Program has interactive
232232+ interfaces that do not display Appropriate Legal Notices, your
233233+ work need not make them do so.
234234+235235+ A compilation of a covered work with other separate and independent
236236+works, which are not by their nature extensions of the covered work,
237237+and which are not combined with it such as to form a larger program,
238238+in or on a volume of a storage or distribution medium, is called an
239239+"aggregate" if the compilation and its resulting copyright are not
240240+used to limit the access or legal rights of the compilation's users
241241+beyond what the individual works permit. Inclusion of a covered work
242242+in an aggregate does not cause this License to apply to the other
243243+parts of the aggregate.
244244+245245+ 6. Conveying Non-Source Forms.
246246+247247+ You may convey a covered work in object code form under the terms
248248+of sections 4 and 5, provided that you also convey the
249249+machine-readable Corresponding Source under the terms of this License,
250250+in one of these ways:
251251+252252+ a) Convey the object code in, or embodied in, a physical product
253253+ (including a physical distribution medium), accompanied by the
254254+ Corresponding Source fixed on a durable physical medium
255255+ customarily used for software interchange.
256256+257257+ b) Convey the object code in, or embodied in, a physical product
258258+ (including a physical distribution medium), accompanied by a
259259+ written offer, valid for at least three years and valid for as
260260+ long as you offer spare parts or customer support for that product
261261+ model, to give anyone who possesses the object code either (1) a
262262+ copy of the Corresponding Source for all the software in the
263263+ product that is covered by this License, on a durable physical
264264+ medium customarily used for software interchange, for a price no
265265+ more than your reasonable cost of physically performing this
266266+ conveying of source, or (2) access to copy the
267267+ Corresponding Source from a network server at no charge.
268268+269269+ c) Convey individual copies of the object code with a copy of the
270270+ written offer to provide the Corresponding Source. This
271271+ alternative is allowed only occasionally and noncommercially, and
272272+ only if you received the object code with such an offer, in accord
273273+ with subsection 6b.
274274+275275+ d) Convey the object code by offering access from a designated
276276+ place (gratis or for a charge), and offer equivalent access to the
277277+ Corresponding Source in the same way through the same place at no
278278+ further charge. You need not require recipients to copy the
279279+ Corresponding Source along with the object code. If the place to
280280+ copy the object code is a network server, the Corresponding Source
281281+ may be on a different server (operated by you or a third party)
282282+ that supports equivalent copying facilities, provided you maintain
283283+ clear directions next to the object code saying where to find the
284284+ Corresponding Source. Regardless of what server hosts the
285285+ Corresponding Source, you remain obligated to ensure that it is
286286+ available for as long as needed to satisfy these requirements.
287287+288288+ e) Convey the object code using peer-to-peer transmission, provided
289289+ you inform other peers where the object code and Corresponding
290290+ Source of the work are being offered to the general public at no
291291+ charge under subsection 6d.
292292+293293+ A separable portion of the object code, whose source code is excluded
294294+from the Corresponding Source as a System Library, need not be
295295+included in conveying the object code work.
296296+297297+ A "User Product" is either (1) a "consumer product", which means any
298298+tangible personal property which is normally used for personal, family,
299299+or household purposes, or (2) anything designed or sold for incorporation
300300+into a dwelling. In determining whether a product is a consumer product,
301301+doubtful cases shall be resolved in favor of coverage. For a particular
302302+product received by a particular user, "normally used" refers to a
303303+typical or common use of that class of product, regardless of the status
304304+of the particular user or of the way in which the particular user
305305+actually uses, or expects or is expected to use, the product. A product
306306+is a consumer product regardless of whether the product has substantial
307307+commercial, industrial or non-consumer uses, unless such uses represent
308308+the only significant mode of use of the product.
309309+310310+ "Installation Information" for a User Product means any methods,
311311+procedures, authorization keys, or other information required to install
312312+and execute modified versions of a covered work in that User Product from
313313+a modified version of its Corresponding Source. The information must
314314+suffice to ensure that the continued functioning of the modified object
315315+code is in no case prevented or interfered with solely because
316316+modification has been made.
317317+318318+ If you convey an object code work under this section in, or with, or
319319+specifically for use in, a User Product, and the conveying occurs as
320320+part of a transaction in which the right of possession and use of the
321321+User Product is transferred to the recipient in perpetuity or for a
322322+fixed term (regardless of how the transaction is characterized), the
323323+Corresponding Source conveyed under this section must be accompanied
324324+by the Installation Information. But this requirement does not apply
325325+if neither you nor any third party retains the ability to install
326326+modified object code on the User Product (for example, the work has
327327+been installed in ROM).
328328+329329+ The requirement to provide Installation Information does not include a
330330+requirement to continue to provide support service, warranty, or updates
331331+for a work that has been modified or installed by the recipient, or for
332332+the User Product in which it has been modified or installed. Access to a
333333+network may be denied when the modification itself materially and
334334+adversely affects the operation of the network or violates the rules and
335335+protocols for communication across the network.
336336+337337+ Corresponding Source conveyed, and Installation Information provided,
338338+in accord with this section must be in a format that is publicly
339339+documented (and with an implementation available to the public in
340340+source code form), and must require no special password or key for
341341+unpacking, reading or copying.
342342+343343+ 7. Additional Terms.
344344+345345+ "Additional permissions" are terms that supplement the terms of this
346346+License by making exceptions from one or more of its conditions.
347347+Additional permissions that are applicable to the entire Program shall
348348+be treated as though they were included in this License, to the extent
349349+that they are valid under applicable law. If additional permissions
350350+apply only to part of the Program, that part may be used separately
351351+under those permissions, but the entire Program remains governed by
352352+this License without regard to the additional permissions.
353353+354354+ When you convey a copy of a covered work, you may at your option
355355+remove any additional permissions from that copy, or from any part of
356356+it. (Additional permissions may be written to require their own
357357+removal in certain cases when you modify the work.) You may place
358358+additional permissions on material, added by you to a covered work,
359359+for which you have or can give appropriate copyright permission.
360360+361361+ Notwithstanding any other provision of this License, for material you
362362+add to a covered work, you may (if authorized by the copyright holders of
363363+that material) supplement the terms of this License with terms:
364364+365365+ a) Disclaiming warranty or limiting liability differently from the
366366+ terms of sections 15 and 16 of this License; or
367367+368368+ b) Requiring preservation of specified reasonable legal notices or
369369+ author attributions in that material or in the Appropriate Legal
370370+ Notices displayed by works containing it; or
371371+372372+ c) Prohibiting misrepresentation of the origin of that material, or
373373+ requiring that modified versions of such material be marked in
374374+ reasonable ways as different from the original version; or
375375+376376+ d) Limiting the use for publicity purposes of names of licensors or
377377+ authors of the material; or
378378+379379+ e) Declining to grant rights under trademark law for use of some
380380+ trade names, trademarks, or service marks; or
381381+382382+ f) Requiring indemnification of licensors and authors of that
383383+ material by anyone who conveys the material (or modified versions of
384384+ it) with contractual assumptions of liability to the recipient, for
385385+ any liability that these contractual assumptions directly impose on
386386+ those licensors and authors.
387387+388388+ All other non-permissive additional terms are considered "further
389389+restrictions" within the meaning of section 10. If the Program as you
390390+received it, or any part of it, contains a notice stating that it is
391391+governed by this License along with a term that is a further
392392+restriction, you may remove that term. If a license document contains
393393+a further restriction but permits relicensing or conveying under this
394394+License, you may add to a covered work material governed by the terms
395395+of that license document, provided that the further restriction does
396396+not survive such relicensing or conveying.
397397+398398+ If you add terms to a covered work in accord with this section, you
399399+must place, in the relevant source files, a statement of the
400400+additional terms that apply to those files, or a notice indicating
401401+where to find the applicable terms.
402402+403403+ Additional terms, permissive or non-permissive, may be stated in the
404404+form of a separately written license, or stated as exceptions;
405405+the above requirements apply either way.
406406+407407+ 8. Termination.
408408+409409+ You may not propagate or modify a covered work except as expressly
410410+provided under this License. Any attempt otherwise to propagate or
411411+modify it is void, and will automatically terminate your rights under
412412+this License (including any patent licenses granted under the third
413413+paragraph of section 11).
414414+415415+ However, if you cease all violation of this License, then your
416416+license from a particular copyright holder is reinstated (a)
417417+provisionally, unless and until the copyright holder explicitly and
418418+finally terminates your license, and (b) permanently, if the copyright
419419+holder fails to notify you of the violation by some reasonable means
420420+prior to 60 days after the cessation.
421421+422422+ Moreover, your license from a particular copyright holder is
423423+reinstated permanently if the copyright holder notifies you of the
424424+violation by some reasonable means, this is the first time you have
425425+received notice of violation of this License (for any work) from that
426426+copyright holder, and you cure the violation prior to 30 days after
427427+your receipt of the notice.
428428+429429+ Termination of your rights under this section does not terminate the
430430+licenses of parties who have received copies or rights from you under
431431+this License. If your rights have been terminated and not permanently
432432+reinstated, you do not qualify to receive new licenses for the same
433433+material under section 10.
434434+435435+ 9. Acceptance Not Required for Having Copies.
436436+437437+ You are not required to accept this License in order to receive or
438438+run a copy of the Program. Ancillary propagation of a covered work
439439+occurring solely as a consequence of using peer-to-peer transmission
440440+to receive a copy likewise does not require acceptance. However,
441441+nothing other than this License grants you permission to propagate or
442442+modify any covered work. These actions infringe copyright if you do
443443+not accept this License. Therefore, by modifying or propagating a
444444+covered work, you indicate your acceptance of this License to do so.
445445+446446+ 10. Automatic Licensing of Downstream Recipients.
447447+448448+ Each time you convey a covered work, the recipient automatically
449449+receives a license from the original licensors, to run, modify and
450450+propagate that work, subject to this License. You are not responsible
451451+for enforcing compliance by third parties with this License.
452452+453453+ An "entity transaction" is a transaction transferring control of an
454454+organization, or substantially all assets of one, or subdividing an
455455+organization, or merging organizations. If propagation of a covered
456456+work results from an entity transaction, each party to that
457457+transaction who receives a copy of the work also receives whatever
458458+licenses to the work the party's predecessor in interest had or could
459459+give under the previous paragraph, plus a right to possession of the
460460+Corresponding Source of the work from the predecessor in interest, if
461461+the predecessor has it or can get it with reasonable efforts.
462462+463463+ You may not impose any further restrictions on the exercise of the
464464+rights granted or affirmed under this License. For example, you may
465465+not impose a license fee, royalty, or other charge for exercise of
466466+rights granted under this License, and you may not initiate litigation
467467+(including a cross-claim or counterclaim in a lawsuit) alleging that
468468+any patent claim is infringed by making, using, selling, offering for
469469+sale, or importing the Program or any portion of it.
470470+471471+ 11. Patents.
472472+473473+ A "contributor" is a copyright holder who authorizes use under this
474474+License of the Program or a work on which the Program is based. The
475475+work thus licensed is called the contributor's "contributor version".
476476+477477+ A contributor's "essential patent claims" are all patent claims
478478+owned or controlled by the contributor, whether already acquired or
479479+hereafter acquired, that would be infringed by some manner, permitted
480480+by this License, of making, using, or selling its contributor version,
481481+but do not include claims that would be infringed only as a
482482+consequence of further modification of the contributor version. For
483483+purposes of this definition, "control" includes the right to grant
484484+patent sublicenses in a manner consistent with the requirements of
485485+this License.
486486+487487+ Each contributor grants you a non-exclusive, worldwide, royalty-free
488488+patent license under the contributor's essential patent claims, to
489489+make, use, sell, offer for sale, import and otherwise run, modify and
490490+propagate the contents of its contributor version.
491491+492492+ In the following three paragraphs, a "patent license" is any express
493493+agreement or commitment, however denominated, not to enforce a patent
494494+(such as an express permission to practice a patent or covenant not to
495495+sue for patent infringement). To "grant" such a patent license to a
496496+party means to make such an agreement or commitment not to enforce a
497497+patent against the party.
498498+499499+ If you convey a covered work, knowingly relying on a patent license,
500500+and the Corresponding Source of the work is not available for anyone
501501+to copy, free of charge and under the terms of this License, through a
502502+publicly available network server or other readily accessible means,
503503+then you must either (1) cause the Corresponding Source to be so
504504+available, or (2) arrange to deprive yourself of the benefit of the
505505+patent license for this particular work, or (3) arrange, in a manner
506506+consistent with the requirements of this License, to extend the patent
507507+license to downstream recipients. "Knowingly relying" means you have
508508+actual knowledge that, but for the patent license, your conveying the
509509+covered work in a country, or your recipient's use of the covered work
510510+in a country, would infringe one or more identifiable patents in that
511511+country that you have reason to believe are valid.
512512+513513+ If, pursuant to or in connection with a single transaction or
514514+arrangement, you convey, or propagate by procuring conveyance of, a
515515+covered work, and grant a patent license to some of the parties
516516+receiving the covered work authorizing them to use, propagate, modify
517517+or convey a specific copy of the covered work, then the patent license
518518+you grant is automatically extended to all recipients of the covered
519519+work and works based on it.
520520+521521+ A patent license is "discriminatory" if it does not include within
522522+the scope of its coverage, prohibits the exercise of, or is
523523+conditioned on the non-exercise of one or more of the rights that are
524524+specifically granted under this License. You may not convey a covered
525525+work if you are a party to an arrangement with a third party that is
526526+in the business of distributing software, under which you make payment
527527+to the third party based on the extent of your activity of conveying
528528+the work, and under which the third party grants, to any of the
529529+parties who would receive the covered work from you, a discriminatory
530530+patent license (a) in connection with copies of the covered work
531531+conveyed by you (or copies made from those copies), or (b) primarily
532532+for and in connection with specific products or compilations that
533533+contain the covered work, unless you entered into that arrangement,
534534+or that patent license was granted, prior to 28 March 2007.
535535+536536+ Nothing in this License shall be construed as excluding or limiting
537537+any implied license or other defenses to infringement that may
538538+otherwise be available to you under applicable patent law.
539539+540540+ 12. No Surrender of Others' Freedom.
541541+542542+ If conditions are imposed on you (whether by court order, agreement or
543543+otherwise) that contradict the conditions of this License, they do not
544544+excuse you from the conditions of this License. If you cannot convey a
545545+covered work so as to satisfy simultaneously your obligations under this
546546+License and any other pertinent obligations, then as a consequence you may
547547+not convey it at all. For example, if you agree to terms that obligate you
548548+to collect a royalty for further conveying from those to whom you convey
549549+the Program, the only way you could satisfy both those terms and this
550550+License would be to refrain entirely from conveying the Program.
551551+552552+ 13. Use with the GNU Affero General Public License.
553553+554554+ Notwithstanding any other provision of this License, you have
555555+permission to link or combine any covered work with a work licensed
556556+under version 3 of the GNU Affero General Public License into a single
557557+combined work, and to convey the resulting work. The terms of this
558558+License will continue to apply to the part which is the covered work,
559559+but the special requirements of the GNU Affero General Public License,
560560+section 13, concerning interaction through a network will apply to the
561561+combination as such.
562562+563563+ 14. Revised Versions of this License.
564564+565565+ The Free Software Foundation may publish revised and/or new versions of
566566+the GNU General Public License from time to time. Such new versions will
567567+be similar in spirit to the present version, but may differ in detail to
568568+address new problems or concerns.
569569+570570+ Each version is given a distinguishing version number. If the
571571+Program specifies that a certain numbered version of the GNU General
572572+Public License "or any later version" applies to it, you have the
573573+option of following the terms and conditions either of that numbered
574574+version or of any later version published by the Free Software
575575+Foundation. If the Program does not specify a version number of the
576576+GNU General Public License, you may choose any version ever published
577577+by the Free Software Foundation.
578578+579579+ If the Program specifies that a proxy can decide which future
580580+versions of the GNU General Public License can be used, that proxy's
581581+public statement of acceptance of a version permanently authorizes you
582582+to choose that version for the Program.
583583+584584+ Later license versions may give you additional or different
585585+permissions. However, no additional obligations are imposed on any
586586+author or copyright holder as a result of your choosing to follow a
587587+later version.
588588+589589+ 15. Disclaimer of Warranty.
590590+591591+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592592+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593593+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594594+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595595+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596596+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597597+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598598+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599599+600600+ 16. Limitation of Liability.
601601+602602+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603603+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604604+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605605+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606606+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607607+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608608+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609609+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610610+SUCH DAMAGES.
611611+612612+ 17. Interpretation of Sections 15 and 16.
613613+614614+ If the disclaimer of warranty and limitation of liability provided
615615+above cannot be given local legal effect according to their terms,
616616+reviewing courts shall apply local law that most closely approximates
617617+an absolute waiver of all civil liability in connection with the
618618+Program, unless a warranty or assumption of liability accompanies a
619619+copy of the Program in return for a fee.
620620+621621+ END OF TERMS AND CONDITIONS
622622+623623+ How to Apply These Terms to Your New Programs
624624+625625+ If you develop a new program, and you want it to be of the greatest
626626+possible use to the public, the best way to achieve this is to make it
627627+free software which everyone can redistribute and change under these terms.
628628+629629+ To do so, attach the following notices to the program. It is safest
630630+to attach them to the start of each source file to most effectively
631631+state the exclusion of warranty; and each file should have at least
632632+the "copyright" line and a pointer to where the full notice is found.
633633+634634+ <one line to give the program's name and a brief idea of what it does.>
635635+ Copyright (C) <year> <name of author>
636636+637637+ This program is free software: you can redistribute it and/or modify
638638+ it under the terms of the GNU General Public License as published by
639639+ the Free Software Foundation, either version 3 of the License, or
640640+ (at your option) any later version.
641641+642642+ This program is distributed in the hope that it will be useful,
643643+ but WITHOUT ANY WARRANTY; without even the implied warranty of
644644+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645645+ GNU General Public License for more details.
646646+647647+ You should have received a copy of the GNU General Public License
648648+ along with this program. If not, see <http://www.gnu.org/licenses/>.
649649+650650+Also add information on how to contact you by electronic and paper mail.
651651+652652+ If the program does terminal interaction, make it output a short
653653+notice like this when it starts in an interactive mode:
654654+655655+ <program> Copyright (C) <year> <name of author>
656656+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657657+ This is free software, and you are welcome to redistribute it
658658+ under certain conditions; type `show c' for details.
659659+660660+The hypothetical commands `show w' and `show c' should show the appropriate
661661+parts of the General Public License. Of course, your program's commands
662662+might be different; for a GUI interface, you would use an "about box".
663663+664664+ You should also get your employer (if you work as a programmer) or school,
665665+if any, to sign a "copyright disclaimer" for the program, if necessary.
666666+For more information on this, and how to apply and follow the GNU GPL, see
667667+<http://www.gnu.org/licenses/>.
668668+669669+ The GNU General Public License does not permit incorporating your program
670670+into proprietary programs. If your program is a subroutine library, you
671671+may consider it more useful to permit linking proprietary applications with
672672+the library. If this is what you want to do, use the GNU Lesser General
673673+Public License instead of this License. But first, please read
674674+<http://www.gnu.org/philosophy/why-not-lgpl.html>.
···11+/*
22+This file is part of Darling.
33+44+Copyright (C) 2012 Lubos Dolezel
55+Copyright (C) 2011 Shinichiro Hamaji
66+77+Darling is free software: you can redistribute it and/or modify
88+it under the terms of the GNU General Public License as published by
99+the Free Software Foundation, either version 3 of the License, or
1010+(at your option) any later version.
1111+1212+Darling is distributed in the hope that it will be useful,
1313+but WITHOUT ANY WARRANTY; without even the implied warranty of
1414+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1515+GNU General Public License for more details.
1616+1717+You should have received a copy of the GNU General Public License
1818+along with Foobar. If not, see <http://www.gnu.org/licenses/>.
1919+*/
120221#include "FileMap.h"
322#include <cassert>
+19
src/dyld/FileMap.h
···11+/*
22+This file is part of Darling.
33+44+Copyright (C) 2012 Lubos Dolezel
55+Copyright (C) 2011 Shinichiro Hamaji
66+77+Darling is free software: you can redistribute it and/or modify
88+it under the terms of the GNU General Public License as published by
99+the Free Software Foundation, either version 3 of the License, or
1010+(at your option) any later version.
1111+1212+Darling is distributed in the hope that it will be useful,
1313+but WITHOUT ANY WARRANTY; without even the implied warranty of
1414+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1515+GNU General Public License for more details.
1616+1717+You should have received a copy of the GNU General Public License
1818+along with Foobar. If not, see <http://www.gnu.org/licenses/>.
1919+*/
120221#ifndef FILEMAP_H
322#define FILEMAP_H
+21-1
src/dyld/MachOLoader.cpp
···11+/*
22+This file is part of Darling.
33+44+Copyright (C) 2012 Lubos Dolezel
55+Copyright (C) 2011 Shinichiro Hamaji
66+77+Darling is free software: you can redistribute it and/or modify
88+it under the terms of the GNU General Public License as published by
99+the Free Software Foundation, either version 3 of the License, or
1010+(at your option) any later version.
1111+1212+Darling is distributed in the hope that it will be useful,
1313+but WITHOUT ANY WARRANTY; without even the implied warranty of
1414+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1515+GNU General Public License for more details.
1616+1717+You should have received a copy of the GNU General Public License
1818+along with Foobar. If not, see <http://www.gnu.org/licenses/>.
1919+*/
2020+121#include "config.h"
222#include "MachOLoader.h"
323#include "MachO.h"
···209229 }
210230211231 if (mach.get_eh_frame().first)
212212- __register_frame(reinterpret_cast<void*>(mach.get_eh_frame().first));
232232+ __register_frame(reinterpret_cast<void*>(mach.get_eh_frame().first + *slide));
213233}
214234215235void MachOLoader::checkMmapMinAddr(intptr addr)
+20
src/dyld/MachOLoader.h
···11+/*
22+This file is part of Darling.
33+44+Copyright (C) 2012 Lubos Dolezel
55+Copyright (C) 2011 Shinichiro Hamaji
66+77+Darling is free software: you can redistribute it and/or modify
88+it under the terms of the GNU General Public License as published by
99+the Free Software Foundation, either version 3 of the License, or
1010+(at your option) any later version.
1111+1212+Darling is distributed in the hope that it will be useful,
1313+but WITHOUT ANY WARRANTY; without even the implied warranty of
1414+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1515+GNU General Public License for more details.
1616+1717+You should have received a copy of the GNU General Public License
1818+along with Foobar. If not, see <http://www.gnu.org/licenses/>.
1919+*/
2020+121#ifndef MACHOLOADER_H
222#define MACHOLOADER_H
323#include <vector>
···11+/*
22+This file is part of Darling.
33+44+Copyright (C) 2012 Lubos Dolezel
55+66+Darling is free software: you can redistribute it and/or modify
77+it under the terms of the GNU General Public License as published by
88+the Free Software Foundation, either version 3 of the License, or
99+(at your option) any later version.
1010+1111+Darling is distributed in the hope that it will be useful,
1212+but WITHOUT ANY WARRANTY; without even the implied warranty of
1313+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1414+GNU General Public License for more details.
1515+1616+You should have received a copy of the GNU General Public License
1717+along with Foobar. If not, see <http://www.gnu.org/licenses/>.
1818+*/
1919+120#include "Trampoline.h"
221#include <unistd.h>
322#include <sys/mman.h>
···827#include <fstream>
928#include <sstream>
1029#include <stack>
3030+#include <cxxabi.h>
3131+#include "../util/log.h"
11321233TrampolineMgr* TrampolineMgr::m_pInstance = 0;
1334std::map<std::string, TrampolineMgr::FunctionInfo> TrampolineMgr::m_functionInfo;
···6889 if ((targetAddr > m_pMem && targetAddr < m_pMem+m_nMax) || !isExecutable(targetAddr))
6990 return targetAddr; // will not create a trampoline for a trampoline
70917171- AddrEntry e = { name, targetAddr };
9292+ AddrEntry e = { name, name, targetAddr };
7293 if (m_nNext >= m_nMax)
7394 throw std::runtime_error("TrampolineMgr buffer full");
9595+9696+ //std::cout << e.name << std::endl;
9797+ if (e.name.compare(0, 2, "_Z") == 0)
9898+ {
9999+ int status;
100100+ char* n = abi::__cxa_demangle(e.name.c_str(), 0, 0, &status);
101101+102102+ //std::cout << n << std::endl;
103103+104104+ if (n)
105105+ {
106106+ e.printName = n;
107107+ e.printName += " - ";
108108+ e.printName += e.name;
109109+ free(n);
110110+ }
111111+ }
7411275113 m_entries.push_back(e);
76114 m_pMem[m_nNext].init(m_nNext, TrampolineMgr::printInfo, TrampolineMgr::printInfoR);
···96134 return false;
97135}
98136137137+std::string TrampolineMgr::inFile(void* addr)
138138+{
139139+ for (auto it = m_memoryMap.begin(); it != m_memoryMap.end(); it++)
140140+ {
141141+ if (addr >= it->start && addr < it->end)
142142+ return it->file;
143143+ }
144144+ return "?";
145145+}
146146+99147void TrampolineMgr::invalidateMemoryMap()
100148{
101149 m_memoryMap.clear();
···116164 s++;
117165 pages.end = (void*) strtol(s, (char**) &s, 16);
118166 pages.executable = (*(s+3) == 'x') && (*(s+2) == '-'); // not writable
167167+168168+ if (line.size() > 74)
169169+ pages.file = line.substr(73);
119170120171 //std::cout << line << " -> " << pages.start << " - " << pages.end << " " << pages.executable << std::endl;
121172 m_memoryMap.push_back(pages);
···231282void* TrampolineMgr::printInfo(uint32_t index, CallStack* stack)
232283{
233284 FunctionInfo* info = 0;
234234- const std::string& name = m_pInstance->m_entries[index].name;
235235- auto it = m_functionInfo.find(name);
285285+ const AddrEntry& e = m_pInstance->m_entries[index];
286286+ auto it = m_functionInfo.find(e.name);
236287 std::ostream* out;
237288 ReturnInfo retInfo;
238289···251302 ArgumentWalker w(stack);
252303 bool first = true;
253304254254- (*out) << name << '(';
305305+ (*out) << e.printName << '(';
255306256307 for (char c : it->second.arguments)
257308 {
···262313263314 (*out) << w.next(c);
264315 }
265265- (*out) << ")\n" << std::flush;
316316+ (*out) << ") ";
266317 }
267318 else
268268- (*out) << m_pInstance->m_entries[index].name << "(?)\n" << std::flush;
319319+ (*out) << e.printName << "(?) ";
320320+ (*out) << "ret_ip=" << stack->retAddr /*<< '(' << m_pInstance->inFile(stack->retAddr) << ')'*/ << std::endl << std::flush;
269321270322 retInfo.retAddr = stack->retAddr;
271323 gettimeofday(&retInfo.callTime, 0);
···290342 (*out) << '[' << stamp << "] ";
291343 (*out) << std::string(g_returnInfo->size(), ' ');
292344345345+ ArgumentWalker w(stack);
293346 if (it != m_functionInfo.end())
294294- {
295295- ArgumentWalker w(stack);
296347 (*out) << "-> " << w.ret(it->second.retType);
297297- }
298348 else
299299- (*out) << "-> ?";
349349+ (*out) << "-> ? (" << w.ret('p') << ')';
300350301301- (*out) << " {" << callTime() << "}\n" << std::flush;
351351+ (*out) << " {" << callTime() << "} errno=" << errno << std::endl << std::flush;
302352303353 g_returnInfo->pop();
304354
+22-1
src/dyld/Trampoline.h
···11+/*
22+This file is part of Darling.
33+44+Copyright (C) 2012 Lubos Dolezel
55+66+Darling is free software: you can redistribute it and/or modify
77+it under the terms of the GNU General Public License as published by
88+the Free Software Foundation, either version 3 of the License, or
99+(at your option) any later version.
1010+1111+Darling is distributed in the hope that it will be useful,
1212+but WITHOUT ANY WARRANTY; without even the implied warranty of
1313+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1414+GNU General Public License for more details.
1515+1616+You should have received a copy of the GNU General Public License
1717+along with Foobar. If not, see <http://www.gnu.org/licenses/>.
1818+*/
1919+120#ifndef TRAMPOLINE_H
221#define TRAMPOLINE_H
322#include <stdint.h>
···18371938 void* generate(void* targetAddr, const char* name);
2039 bool isExecutable(void* targetAddr);
4040+ std::string inFile(void* addr);
2141 void invalidateMemoryMap();
22422343 static void loadFunctionInfo(const char* path);
···6181private:
6282 struct AddrEntry
6383 {
6464- std::string name;
8484+ std::string name, printName;
6585 void* addr;
6686 };
6787 struct MemoryPages
···6989 void* start;
7090 void* end;
7191 bool executable;
9292+ std::string file;
72937394 bool operator<(const MemoryPages& o) { return start < o.start; }
7495 bool operator<(void* p) { return start < p; }
+19
src/dyld/UndefinedFunction.cpp
···11+/*
22+This file is part of Darling.
33+44+Copyright (C) 2012 Lubos Dolezel
55+66+Darling is free software: you can redistribute it and/or modify
77+it under the terms of the GNU General Public License as published by
88+the Free Software Foundation, either version 3 of the License, or
99+(at your option) any later version.
1010+1111+Darling is distributed in the hope that it will be useful,
1212+but WITHOUT ANY WARRANTY; without even the implied warranty of
1313+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1414+GNU General Public License for more details.
1515+1616+You should have received a copy of the GNU General Public License
1717+along with Foobar. If not, see <http://www.gnu.org/licenses/>.
1818+*/
1919+120#include "UndefinedFunction.h"
221#include <unistd.h>
322#include <sys/mman.h>
+19
src/dyld/UndefinedFunction.h
···11+/*
22+This file is part of Darling.
33+44+Copyright (C) 2012 Lubos Dolezel
55+66+Darling is free software: you can redistribute it and/or modify
77+it under the terms of the GNU General Public License as published by
88+the Free Software Foundation, either version 3 of the License, or
99+(at your option) any later version.
1010+1111+Darling is distributed in the hope that it will be useful,
1212+but WITHOUT ANY WARRANTY; without even the implied warranty of
1313+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1414+GNU General Public License for more details.
1515+1616+You should have received a copy of the GNU General Public License
1717+along with Foobar. If not, see <http://www.gnu.org/licenses/>.
1818+*/
1919+120#ifndef UNDEFINEDFUNCTION_H
221#define UNDEFINEDFUNCTION_H
322#include <cstdio>
+19
src/dyld/binfmt_misc.cpp
···11+/*
22+This file is part of Darling.
33+44+Copyright (C) 2012 Lubos Dolezel
55+66+Darling is free software: you can redistribute it and/or modify
77+it under the terms of the GNU General Public License as published by
88+the Free Software Foundation, either version 3 of the License, or
99+(at your option) any later version.
1010+1111+Darling is distributed in the hope that it will be useful,
1212+but WITHOUT ANY WARRANTY; without even the implied warranty of
1313+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1414+GNU General Public License for more details.
1515+1616+You should have received a copy of the GNU General Public License
1717+along with Foobar. If not, see <http://www.gnu.org/licenses/>.
1818+*/
1919+120#include "binfmt_misc.h"
221#include <fstream>
322#include <stdexcept>
+19
src/dyld/binfmt_misc.h
···11+/*
22+This file is part of Darling.
33+44+Copyright (C) 2012 Lubos Dolezel
55+66+Darling is free software: you can redistribute it and/or modify
77+it under the terms of the GNU General Public License as published by
88+the Free Software Foundation, either version 3 of the License, or
99+(at your option) any later version.
1010+1111+Darling is distributed in the hope that it will be useful,
1212+but WITHOUT ANY WARRANTY; without even the implied warranty of
1313+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1414+GNU General Public License for more details.
1515+1616+You should have received a copy of the GNU General Public License
1717+along with Foobar. If not, see <http://www.gnu.org/licenses/>.
1818+*/
1919+120#ifndef BINFMTMISC_H
221#define BINFMTMISC_H
322
+20
src/dyld/dyld.cpp
···11+/*
22+This file is part of Darling.
33+44+Copyright (C) 2012 Lubos Dolezel
55+Copyright (C) 2011 Shinichiro Hamaji
66+77+Darling is free software: you can redistribute it and/or modify
88+it under the terms of the GNU General Public License as published by
99+the Free Software Foundation, either version 3 of the License, or
1010+(at your option) any later version.
1111+1212+Darling is distributed in the hope that it will be useful,
1313+but WITHOUT ANY WARRANTY; without even the implied warranty of
1414+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1515+GNU General Public License for more details.
1616+1717+You should have received a copy of the GNU General Public License
1818+along with Foobar. If not, see <http://www.gnu.org/licenses/>.
1919+*/
2020+121#include "MachO.h"
222#include "MachOLoader.h"
323#include "arch.h"
-121
src/dyld/extract.cpp
···11-// Copyright 2011 Shinichiro Hamaji. All rights reserved.
22-//
33-// Redistribution and use in source and binary forms, with or without
44-// modification, are permitted provided that the following conditions
55-// are met:
66-//
77-// 1. Redistributions of source code must retain the above copyright
88-// notice, this list of conditions and the following disclaimer.
99-//
1010-// 2. Redistributions in binary form must reproduce the above
1111-// copyright notice, this list of conditions and the following
1212-// disclaimer in the documentation and/or other materials
1313-// provided with the distribution.
1414-//
1515-// THIS SOFTWARE IS PROVIDED BY Shinichiro Hamaji ``AS IS'' AND ANY
1616-// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1717-// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
1818-// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Shinichiro Hamaji OR
1919-// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2020-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2121-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
2222-// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
2323-// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2424-// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
2525-// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2626-// SUCH DAMAGE.
2727-2828-// A command line tool to extract a Mach-O binary from a fat binary.
2929-3030-#include <fcntl.h>
3131-#include <sys/mman.h>
3232-#include <sys/types.h>
3333-#include <sys/stat.h>
3434-#include <unistd.h>
3535-#include <errno.h>
3636-#include <cstdio>
3737-3838-#include <map>
3939-#include <string>
4040-#include <iostream>
4141-4242-#include <mach-o/fat.h>
4343-4444-#include "FatMachO.h"
4545-4646-static std::string getFileName(std::string path);
4747-4848-int main(int argc, char** argv)
4949-{
5050- if (argc < 2 || argc > 4)
5151- {
5252- std::cerr << "Usage: " << argv[0] << " <file> [arch-out]\n";
5353- return 1;
5454- }
5555-5656- int fd = ::open(argv[1], O_RDONLY);
5757- if (fd < 0)
5858- {
5959- perror("open");
6060- return 1;
6161- }
6262-6363- off_t len = ::lseek(fd, 0, SEEK_END);
6464- const char* bin = reinterpret_cast<char*>(::mmap(NULL, len, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE, fd, 0));
6565-6666- if (bin == MAP_FAILED)
6767- {
6868- perror("mmap");
6969- return -errno;
7070- }
7171-7272- std::map<std::string, fat_arch> archs;
7373- if (!FatMachO::readFatInfo(fd, &archs))
7474- {
7575- std::cerr << "Failed to read the Fat Mach-O header\n";
7676- return 1;
7777- }
7878-7979- std::cout << archs.size() << " archs:\n";
8080-8181- for (std::map<std::string, fat_arch>::const_iterator iter = archs.begin(); iter != archs.end(); ++iter)
8282- {
8383- const fat_arch& arch = iter->second;
8484- std::cout << "cputype=" << arch.cputype << " (" << iter->first << ") "
8585- "cpusubtype=" << arch.cpusubtype << " offset=" << arch.offset << " size=" << arch.size
8686- << " align=" << arch.align << std::endl;
8787- }
8888-8989- for (int i = 2; i < argc; i++)
9090- {
9191- const char* arch_name = argv[i];
9292- std::map<std::string, fat_arch>::const_iterator found = archs.find(arch_name);
9393- if (found == archs.end())
9494- {
9595- std::cerr << "Architecture not present: " << arch_name << std::endl;
9696- continue;
9797- }
9898-9999- const fat_arch& arch = found->second;
100100- std::string outname = getFileName(argv[0]) + "." + arch_name;
101101- int out = ::open(outname.c_str(), O_WRONLY | O_CREAT, 0777);
102102-103103- if (::write(out, bin + arch.offset, arch.size) != arch.size)
104104- {
105105- perror("write");
106106- return -errno;
107107- }
108108-109109- ::close(out);
110110- }
111111-}
112112-113113-std::string getFileName(std::string path)
114114-{
115115- size_t pos = path.rfind('/');
116116- if (pos == std::string::npos)
117117- return path;
118118-119119- return path.substr(pos+1);
120120-}
121121-
+19
src/dyld/ld.cpp
···11+/*
22+This file is part of Darling.
33+44+Copyright (C) 2012 Lubos Dolezel
55+66+Darling is free software: you can redistribute it and/or modify
77+it under the terms of the GNU General Public License as published by
88+the Free Software Foundation, either version 3 of the License, or
99+(at your option) any later version.
1010+1111+Darling is distributed in the hope that it will be useful,
1212+but WITHOUT ANY WARRANTY; without even the implied warranty of
1313+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1414+GNU General Public License for more details.
1515+1616+You should have received a copy of the GNU General Public License
1717+along with Foobar. If not, see <http://www.gnu.org/licenses/>.
1818+*/
1919+120#include "config.h"
221#define DARWIN_LD_INTERNAL
322#include "MachOLoader.h"
+19
src/dyld/ld.h
···11+/*
22+This file is part of Darling.
33+44+Copyright (C) 2012 Lubos Dolezel
55+66+Darling is free software: you can redistribute it and/or modify
77+it under the terms of the GNU General Public License as published by
88+the Free Software Foundation, either version 3 of the License, or
99+(at your option) any later version.
1010+1111+Darling is distributed in the hope that it will be useful,
1212+but WITHOUT ANY WARRANTY; without even the implied warranty of
1313+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1414+GNU General Public License for more details.
1515+1616+You should have received a copy of the GNU General Public License
1717+along with Foobar. If not, see <http://www.gnu.org/licenses/>.
1818+*/
1919+120#ifndef DARWIN_LD_H
221#define DARWIN_LD_H
322#include <dlfcn.h>
+19
src/dyld/public.cpp
···11+/*
22+This file is part of Darling.
33+44+Copyright (C) 2012 Lubos Dolezel
55+66+Darling is free software: you can redistribute it and/or modify
77+it under the terms of the GNU General Public License as published by
88+the Free Software Foundation, either version 3 of the License, or
99+(at your option) any later version.
1010+1111+Darling is distributed in the hope that it will be useful,
1212+but WITHOUT ANY WARRANTY; without even the implied warranty of
1313+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1414+GNU General Public License for more details.
1515+1616+You should have received a copy of the GNU General Public License
1717+along with Foobar. If not, see <http://www.gnu.org/licenses/>.
1818+*/
1919+120#include "config.h"
221#include "public.h"
322#include "MachOLoader.h"
+19
src/dyld/public.h
···11+/*
22+This file is part of Darling.
33+44+Copyright (C) 2012 Lubos Dolezel
55+66+Darling is free software: you can redistribute it and/or modify
77+it under the terms of the GNU General Public License as published by
88+the Free Software Foundation, either version 3 of the License, or
99+(at your option) any later version.
1010+1111+Darling is distributed in the hope that it will be useful,
1212+but WITHOUT ANY WARRANTY; without even the implied warranty of
1313+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1414+GNU General Public License for more details.
1515+1616+You should have received a copy of the GNU General Public License
1717+along with Foobar. If not, see <http://www.gnu.org/licenses/>.
1818+*/
1919+120#ifndef DYLD_PUBLIC_H
221#define DYLD_PUBLIC_H
322#include <stdint.h>
+18
src/dyld/trampoline_helper.nasm
···11+;
22+; This file is part of Darling.
33+;
44+; Copyright (C) 2012 Lubos Dolezel
55+;
66+; Darling is free software: you can redistribute it and/or modify
77+; it under the terms of the GNU General Public License as published by
88+; the Free Software Foundation, either version 3 of the License, or
99+; (at your option) any later version.
1010+;
1111+; Darling is distributed in the hope that it will be useful,
1212+; but WITHOUT ANY WARRANTY; without even the implied warranty of
1313+; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1414+; GNU General Public License for more details.
1515+1616+; You should have received a copy of the GNU General Public License
1717+; along with Foobar. If not, see <http://www.gnu.org/licenses/>.
1818+119global trampoline_start
220global trampoline_end
321global reg_saveall
···2323# -luuid to make uuid_ functions available for Darwin apps
2424target_link_libraries(ncurses.5.4.dylib -lncurses)
25252626-install(TARGETS ncurses.5.4.dylib DESTINATION lib${SUFFIX})
2626+install(TARGETS ncurses.5.4.dylib DESTINATION "lib${SUFFIX}/darling")
2727
···11+/** Implementation for GNUStep of NSString concrete subclasses
22+ Copyright (C) 1997,1998,2000 Free Software Foundation, Inc.
33+44+ Base on code written by Stevo Crvenkovski <stevo@btinternet.com>
55+ Date: February 1997
66+77+ Based on NSGCString and NSString
88+ Written by: Andrew Kachites McCallum
99+ <mccallum@gnu.ai.mit.edu>
1010+ Date: March 1995
1111+1212+ Optimised by Richard Frith-Macdonald <richard@brainstorm.co.uk>
1313+ Date: October 1998
1414+1515+ Redesign/rewrite by Richard Frith-Macdonald <rfm@gnu.org>
1616+ Date: September 2000
1717+1818+ This file is part of the GNUstep Base Library.
1919+2020+ This library is free software; you can redistribute it and/or
2121+ modify it under the terms of the GNU Lesser General Public
2222+ License as published by the Free Software Foundation; either
2323+ version 2 of the License, or (at your option) any later version.
2424+2525+ This library is distributed in the hope that it will be useful,
2626+ but WITHOUT ANY WARRANTY; without even the implied warranty of
2727+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2828+ Library General Public License for more details.
2929+3030+ You should have received a copy of the GNU Lesser General Public
3131+ License along with this library; if not, write to the Free
3232+ Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
3333+ Boston, MA 02111 USA.
3434+3535+ This file derives a NSCFString class from the NXConstantString implementaion. (Luboš Doležel)
3636+*/
3737+3838+#import "NSCFString.h"
3939+#import <Foundation/NSException.h>
4040+4141+/* Determine the length of the UTF-8 string as a unicode (UTF-16) string.
4242+ * sets the ascii flag according to the content found.
4343+ */
4444+static NSUInteger
4545+lengthUTF8(const uint8_t *p, unsigned l, BOOL *ascii, BOOL *latin1)
4646+{
4747+ const uint8_t *e = p + l;
4848+ BOOL a = YES;
4949+ BOOL l1 = YES;
5050+5151+ l = 0;
5252+ while (p < e)
5353+ {
5454+ uint8_t c = *p;
5555+ uint32_t u = c;
5656+5757+ if (c > 0x7f)
5858+ {
5959+ int i, sle = 0;
6060+6161+ a = NO;
6262+ /* calculated the expected sequence length */
6363+ while (c & 0x80)
6464+ {
6565+ c = c << 1;
6666+ sle++;
6767+ }
6868+6969+ /* legal ? */
7070+ if ((sle < 2) || (sle > 6))
7171+ {
7272+ [NSException raise: NSInternalInconsistencyException
7373+ format: @"Bad sequence length in constant string"];
7474+ }
7575+7676+ if (p + sle > e)
7777+ {
7878+ [NSException raise: NSInternalInconsistencyException
7979+ format: @"Short data in constant string"];
8080+ }
8181+8282+ /* get the codepoint */
8383+ for (i = 1; i < sle; i++)
8484+ {
8585+ if (p[i] < 0x80 || p[i] >= 0xc0)
8686+ break;
8787+ u = (u << 6) | (p[i] & 0x3f);
8888+ }
8989+9090+ if (i < sle)
9191+ {
9292+ [NSException raise: NSInternalInconsistencyException
9393+ format: @"Codepoint out of range in constant string"];
9494+ }
9595+ u = u & ~(0xffffffff << ((5 * sle) + 1));
9696+ p += sle;
9797+9898+ /*
9999+ * We check for invalid codepoints here.
100100+ */
101101+ if (u > 0x10ffff || u == 0xfffe || u == 0xffff
102102+ || (u >= 0xfdd0 && u <= 0xfdef))
103103+ {
104104+ [NSException raise: NSInternalInconsistencyException
105105+ format: @"Codepoint invalid in constant string"];
106106+ }
107107+108108+ if ((u >= 0xd800) && (u <= 0xdfff))
109109+ {
110110+ [NSException raise: NSInternalInconsistencyException
111111+ format: @"Bad surrogate pair in constant string"];
112112+ }
113113+ }
114114+ else
115115+ {
116116+ p++;
117117+ }
118118+119119+ /*
120120+ * Add codepoint as either a single unichar for BMP
121121+ * or as a pair of surrogates for codepoints over 16 bits.
122122+ */
123123+ if (u < 0x10000)
124124+ {
125125+ l++;
126126+ if (u > 255)
127127+ {
128128+ l1 = NO;
129129+ }
130130+ }
131131+ else
132132+ {
133133+ l += 2;
134134+ }
135135+ }
136136+ if (0 != ascii)
137137+ {
138138+ *ascii = a;
139139+ }
140140+ if (0 != latin1)
141141+ {
142142+ *latin1 = l1;
143143+ }
144144+ return l;
145145+}
146146+147147+/* Sequentially extracts characters from UTF-8 string
148148+ * p = pointer to the utf-8 data
149149+ * l = length (bytes) of the utf-8 data
150150+ * o = pointer to current offset within the data
151151+ * n = pointer to either zero or the next pre-read part of a surrogate pair.
152152+ * The condition for having read the entire string is that the offset (*o)
153153+ * is the number of bytes in the string, and the unichar pointed to by *n
154154+ * is zero (meaning there is no second part of a surrogate pair remaining).
155155+ */
156156+static inline unichar
157157+nextUTF8(const uint8_t *p, unsigned l, unsigned *o, unichar *n)
158158+{
159159+ unsigned i;
160160+161161+ /* If we still have the second part of a surrogate pair, return it.
162162+ */
163163+ if (*n > 0)
164164+ {
165165+ unichar u = *n;
166166+167167+ *n = 0;
168168+ return u;
169169+ }
170170+171171+ if ((i = *o) < l)
172172+ {
173173+ uint8_t c = p[i];
174174+ uint32_t u = c;
175175+176176+ if (c > 0x7f)
177177+ {
178178+ int j, sle = 0;
179179+180180+ /* calculated the expected sequence length */
181181+ while (c & 0x80)
182182+ {
183183+ c = c << 1;
184184+ sle++;
185185+ }
186186+187187+ /* legal ? */
188188+ if ((sle < 2) || (sle > 6))
189189+ {
190190+ [NSException raise: NSInvalidArgumentException
191191+ format: @"bad multibyte character length"];
192192+ }
193193+194194+ if (sle + i > l)
195195+ {
196196+ [NSException raise: NSInvalidArgumentException
197197+ format: @"multibyte character extends beyond data"];
198198+ }
199199+200200+ /* get the codepoint */
201201+ for (j = 1; j < sle; j++)
202202+ {
203203+ uint8_t b = p[i + j];
204204+205205+ if (b < 0x80 || b >= 0xc0)
206206+ break;
207207+ u = (u << 6) | (b & 0x3f);
208208+ }
209209+210210+ if (j < sle)
211211+ {
212212+ [NSException raise: NSInvalidArgumentException
213213+ format: @"bad data in multibyte character"];
214214+ }
215215+ u = u & ~(0xffffffff << ((5 * sle) + 1));
216216+ i += sle;
217217+218218+ /*
219219+ * We discard invalid codepoints here.
220220+ */
221221+ if (u > 0x10ffff || u == 0xfffe || u == 0xffff
222222+ || (u >= 0xfdd0 && u <= 0xfdef))
223223+ {
224224+ [NSException raise: NSInvalidArgumentException
225225+ format: @"invalid unicode codepoint"];
226226+ }
227227+228228+ if ((u >= 0xd800) && (u <= 0xdfff))
229229+ {
230230+ [NSException raise: NSInvalidArgumentException
231231+ format: @"unmatched half of surrogate pair"];
232232+ }
233233+ }
234234+ else
235235+ {
236236+ i++;
237237+ }
238238+239239+ /*
240240+ * Add codepoint as either a single unichar for BMP
241241+ * or as a pair of surrogates for codepoints over 16 bits.
242242+ */
243243+ if (u >= 0x10000)
244244+ {
245245+ unichar ul, uh;
246246+247247+ u -= 0x10000;
248248+ ul = u & 0x3ff;
249249+ uh = (u >> 10) & 0x3ff;
250250+251251+ *n = ul + 0xdc00; // record second part of pair
252252+ u = uh + 0xd800; // return first part.
253253+ }
254254+ *o = i; // Return new index
255255+ return (unichar)u;
256256+ }
257257+ [NSException raise: NSInvalidArgumentException
258258+ format: @"no more data in UTF-8 string"];
259259+ return 0;
260260+}
261261+262262+@implementation NSCFString
263263+264264+- (const char*) UTF8String
265265+{
266266+ return nxcsptr;
267267+}
268268+269269+- (unichar) characterAtIndex: (NSUInteger)index
270270+{
271271+ NSUInteger l = 0;
272272+ unichar u;
273273+ unichar n = 0;
274274+ unsigned i = 0;
275275+276276+ while (i < nxcslen || n > 0)
277277+ {
278278+ u = nextUTF8((const uint8_t *)nxcsptr, nxcslen, &i, &n);
279279+ if (l++ == index)
280280+ {
281281+ return u;
282282+ }
283283+ }
284284+285285+ [NSException raise: NSInvalidArgumentException
286286+ format: @"-characterAtIndex: index out of range"];
287287+ return 0;
288288+}
289289+290290+- (void) dealloc
291291+{
292292+ GSNOSUPERDEALLOC;
293293+}
294294+295295+/* Must match the implementation in NSString
296296+ */
297297+- (NSUInteger) hash
298298+{
299299+ if (nxcslen > 0)
300300+ {
301301+ unsigned ret = 0;
302302+ unichar n = 0;
303303+ unsigned i = 0;
304304+ unichar c;
305305+306306+ while (i < nxcslen)
307307+ {
308308+ c = nextUTF8((const uint8_t *)nxcsptr, nxcslen, &i, &n);
309309+ ret = (ret << 5) + ret + c;
310310+ }
311311+ if (0 != n)
312312+ {
313313+ ret = (ret << 5) + ret + n; // Add final character
314314+ }
315315+ ret &= 0x0fffffff;
316316+ if (ret == 0)
317317+ {
318318+ ret = 0x0fffffff;
319319+ }
320320+ return ret;
321321+ }
322322+ else
323323+ {
324324+ return 0x0ffffffe; /* Hash for an empty string. */
325325+ }
326326+}
327327+328328+- (id) initWithBytes: (const void*)bytes
329329+ length: (NSUInteger)length
330330+ encoding: (NSStringEncoding)encoding
331331+{
332332+ [NSException raise: NSGenericException
333333+ format: @"Attempt to init a constant string"];
334334+ return nil;
335335+}
336336+337337+- (id) initWithBytesNoCopy: (void*)bytes
338338+ length: (NSUInteger)length
339339+ encoding: (NSStringEncoding)encoding
340340+ freeWhenDone: (BOOL)flag
341341+{
342342+ [NSException raise: NSGenericException
343343+ format: @"Attempt to init a constant string"];
344344+ return nil;
345345+}
346346+347347+- (BOOL) isEqual: (id)anObject
348348+{
349349+ if ([anObject isKindOfClass: [NSCFString class]])
350350+ {
351351+ NSCFString* str = (NSCFString*) anObject;
352352+ if (nxcslen != str->nxcslen)
353353+ return NO;
354354+ else
355355+ return memcmp(nxcsptr, str->nxcsptr, nxcslen) == 0;
356356+ }
357357+ else if ([anObject isKindOfClass: [NSString class]])
358358+ return [anObject isEqual: self];
359359+ else
360360+ return NO;
361361+}
362362+363363+- (BOOL) isEqualToString: (NSString*)other
364364+{
365365+ if ([other isKindOfClass: [NSCFString class]])
366366+ {
367367+ NSCFString* str = (NSCFString*) other;
368368+ if (nxcslen != str->nxcslen)
369369+ return NO;
370370+ else
371371+ return memcmp(nxcsptr, str->nxcsptr, nxcslen) == 0;
372372+ }
373373+ else
374374+ return [other isEqual: self];
375375+}
376376+377377+- (NSUInteger) length
378378+{
379379+ return lengthUTF8((const uint8_t*)nxcsptr, nxcslen, 0, 0);
380380+}
381381+382382+- (id) retain
383383+{
384384+ return self;
385385+}
386386+387387+- (oneway void) release
388388+{
389389+ return;
390390+}
391391+392392+- (id) autorelease
393393+{
394394+ return self;
395395+}
396396+397397+- (id) copyWithZone: (NSZone*)z
398398+{
399399+ return self;
400400+}
401401+402402+- (NSZone*) zone
403403+{
404404+ return NSDefaultMallocZone();
405405+}
406406+407407+- (NSStringEncoding) fastestEncoding
408408+{
409409+ return NSUTF8StringEncoding;
410410+}
411411+412412+- (NSStringEncoding) smallestEncoding
413413+{
414414+ return NSUTF8StringEncoding;
415415+}
416416+417417+@end
418418+
···11+/*
22+ * This file is part of Darling.
33+ *
44+ * Copyright (C) 2012 Lubos Dolezel
55+ *
66+ * Darling is free software: you can redistribute it and/or modify
77+ * it under the terms of the GNU General Public License as published by
88+ * the Free Software Foundation, either version 3 of the License, or
99+ * (at your option) any later version.
1010+ *
1111+ * Darling is distributed in the hope that it will be useful,
1212+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1313+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1414+ * GNU General Public License for more details.
1515+ *
1616+ * You should have received a copy of the GNU General Public License
1717+ * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
1818+ * */
1919+120#include "MachO.h"
221#include "FatMachO.h"
322#include <iostream>