mirror of
https://github.com/darlinghq/darling.git
synced 2024-11-26 22:00:29 +00:00
Loads of work, libmacarchive added, copyright headers...
This commit is contained in:
parent
947280d80a
commit
ab7a28f7de
@ -75,15 +75,18 @@ set(dyld_SRCS
|
||||
src/dyld/binfmt_misc.cpp
|
||||
)
|
||||
|
||||
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib${SUFFIX}/darling")
|
||||
#SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--enable-new-dtags")
|
||||
|
||||
add_executable(dyld${SUFFIX} ${dyld_SRCS})
|
||||
target_link_libraries(dyld${SUFFIX} -ldl -lpthread mach-o util)
|
||||
|
||||
set(fatmacho-extract_SRCS
|
||||
src/dyld/extract.cpp
|
||||
)
|
||||
#set(fatmacho-extract_SRCS
|
||||
# src/dyld/extract.cpp
|
||||
#)
|
||||
|
||||
add_executable(fatmacho-extract ${fatmacho-extract_SRCS})
|
||||
target_link_libraries(fatmacho-extract -ldl -lpthread -l:./libmach-o.so -Wl,-export-dynamic)
|
||||
#add_executable(fatmacho-extract ${fatmacho-extract_SRCS})
|
||||
#target_link_libraries(fatmacho-extract -ldl -lpthread -l:./libmach-o.so -Wl,-export-dynamic)
|
||||
|
||||
set(motool_SRCS
|
||||
src/motool/motool.cpp
|
||||
@ -96,18 +99,21 @@ install(TARGETS dyld${SUFFIX} DESTINATION bin)
|
||||
|
||||
# If building on a 64bit system, only install these for 64bits
|
||||
if (NOT DEFINED SUFFIX OR SUFFIX STREQUAL "64")
|
||||
install(TARGETS fatmacho-extract motool DESTINATION bin)
|
||||
install(TARGETS motool DESTINATION bin)
|
||||
install(FILES etc/dylib.conf DESTINATION /etc/darling)
|
||||
add_subdirectory(src/macbinary)
|
||||
add_subdirectory(src/libmacarchive)
|
||||
endif(NOT DEFINED SUFFIX OR SUFFIX STREQUAL "64")
|
||||
|
||||
install(TARGETS mach-o DESTINATION lib${SUFFIX})
|
||||
install(TARGETS mach-o DESTINATION "lib${SUFFIX}/darling")
|
||||
|
||||
add_subdirectory(src/libSystem)
|
||||
#add_subdirectory(src/libcxxdarwin)
|
||||
add_subdirectory(src/libobjcdarwin)
|
||||
#add_subdirectory(src/libunwind-darwin-gcc)
|
||||
add_subdirectory(src/libncurses)
|
||||
#add_subdirectory(src/CoreServices)
|
||||
add_subdirectory(src/CoreSecurity)
|
||||
add_subdirectory(src/thin)
|
||||
|
||||
add_dependencies(dyld${SUFFIX} mach-o)
|
||||
add_dependencies(System.B.dylib genfuncmap)
|
||||
|
674
LICENSE
Normal file
674
LICENSE
Normal file
@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<http://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
|
@ -3,9 +3,13 @@ libintl.8.dylib=libSystem.B.dylib.so
|
||||
libiconv.2.dylib=libSystem.B.dylib.so
|
||||
libstdc++.6.dylib=libSystem.B.dylib.so
|
||||
#libncurses.5.4.dylib=libncurses.so.5
|
||||
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation=libCoreFoundation.so
|
||||
/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices=libgnustep-base.so
|
||||
/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation=libgnustep-base.so
|
||||
/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit=libgnustep-gui.so
|
||||
|
||||
#/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation=libCoreFoundation.so
|
||||
#/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation=libgnustep-corebase.so
|
||||
/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices=/dev/null
|
||||
/System/Library/Frameworks/Foundation.framework/Versions/C/Foundation=libobjc.A.dylib.so
|
||||
/System/Library/Frameworks/AppKit.framework/Versions/C/AppKit=libAppKit.so
|
||||
/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa=libCocoa.so
|
||||
/System/Library/Frameworks/IOKit.framework/Versions/A/IOKit=/dev/null
|
||||
/System/Library/Frameworks/Security.framework/Versions/A/Security=libCoreSecurity.so
|
||||
/System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices=/dev/null
|
||||
|
||||
|
@ -1,3 +1,22 @@
|
||||
/*
|
||||
This file is part of Darling.
|
||||
|
||||
Copyright (C) 2012 Lubos Dolezel
|
||||
Copyright (C) 2011 Shinichiro Hamaji
|
||||
|
||||
Darling is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Darling is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "FileMap.h"
|
||||
#include <cassert>
|
||||
|
@ -1,3 +1,22 @@
|
||||
/*
|
||||
This file is part of Darling.
|
||||
|
||||
Copyright (C) 2012 Lubos Dolezel
|
||||
Copyright (C) 2011 Shinichiro Hamaji
|
||||
|
||||
Darling is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Darling is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef FILEMAP_H
|
||||
#define FILEMAP_H
|
||||
|
@ -1,3 +1,23 @@
|
||||
/*
|
||||
This file is part of Darling.
|
||||
|
||||
Copyright (C) 2012 Lubos Dolezel
|
||||
Copyright (C) 2011 Shinichiro Hamaji
|
||||
|
||||
Darling is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Darling is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "MachOLoader.h"
|
||||
#include "MachO.h"
|
||||
@ -209,7 +229,7 @@ void MachOLoader::loadSegments(const MachO& mach, intptr* slide, intptr* base)
|
||||
}
|
||||
|
||||
if (mach.get_eh_frame().first)
|
||||
__register_frame(reinterpret_cast<void*>(mach.get_eh_frame().first));
|
||||
__register_frame(reinterpret_cast<void*>(mach.get_eh_frame().first + *slide));
|
||||
}
|
||||
|
||||
void MachOLoader::checkMmapMinAddr(intptr addr)
|
||||
|
@ -1,3 +1,23 @@
|
||||
/*
|
||||
This file is part of Darling.
|
||||
|
||||
Copyright (C) 2012 Lubos Dolezel
|
||||
Copyright (C) 2011 Shinichiro Hamaji
|
||||
|
||||
Darling is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Darling is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef MACHOLOADER_H
|
||||
#define MACHOLOADER_H
|
||||
#include <vector>
|
||||
|
@ -1,30 +0,0 @@
|
||||
#include "Timer.h"
|
||||
|
||||
Timer g_timer;
|
||||
|
||||
static void initGlobalTimer() __attribute__((constructor));
|
||||
|
||||
Timer::Timer()
|
||||
: start_time(0)
|
||||
{
|
||||
}
|
||||
|
||||
void Timer::start()
|
||||
{
|
||||
if (FLAGS_PRINT_TIME)
|
||||
start_time = clock();
|
||||
}
|
||||
|
||||
void Timer::print(const char* name)
|
||||
{
|
||||
if (FLAGS_PRINT_TIME)
|
||||
{
|
||||
double elapsed = ((double)clock() - start_time) / CLOCKS_PER_SEC;
|
||||
printf("Elapsed time (%s): %f sec\n", name, elapsed);
|
||||
}
|
||||
}
|
||||
|
||||
void initGlobalTimer()
|
||||
{
|
||||
g_timer.start();
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
#ifndef DYLD_TIMER_H
|
||||
#define DYLD_TIMER_H
|
||||
#include <time.h>
|
||||
|
||||
#define FLAGS_PRINT_TIME 0
|
||||
|
||||
class Timer
|
||||
{
|
||||
public:
|
||||
Timer();
|
||||
void start();
|
||||
void print(const char* name);
|
||||
private:
|
||||
clock_t start_time;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,3 +1,22 @@
|
||||
/*
|
||||
This file is part of Darling.
|
||||
|
||||
Copyright (C) 2012 Lubos Dolezel
|
||||
|
||||
Darling is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Darling is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "Trampoline.h"
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
@ -8,6 +27,8 @@
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <stack>
|
||||
#include <cxxabi.h>
|
||||
#include "../util/log.h"
|
||||
|
||||
TrampolineMgr* TrampolineMgr::m_pInstance = 0;
|
||||
std::map<std::string, TrampolineMgr::FunctionInfo> TrampolineMgr::m_functionInfo;
|
||||
@ -68,10 +89,27 @@ void* TrampolineMgr::generate(void* targetAddr, const char* name)
|
||||
if ((targetAddr > m_pMem && targetAddr < m_pMem+m_nMax) || !isExecutable(targetAddr))
|
||||
return targetAddr; // will not create a trampoline for a trampoline
|
||||
|
||||
AddrEntry e = { name, targetAddr };
|
||||
AddrEntry e = { name, name, targetAddr };
|
||||
if (m_nNext >= m_nMax)
|
||||
throw std::runtime_error("TrampolineMgr buffer full");
|
||||
|
||||
//std::cout << e.name << std::endl;
|
||||
if (e.name.compare(0, 2, "_Z") == 0)
|
||||
{
|
||||
int status;
|
||||
char* n = abi::__cxa_demangle(e.name.c_str(), 0, 0, &status);
|
||||
|
||||
//std::cout << n << std::endl;
|
||||
|
||||
if (n)
|
||||
{
|
||||
e.printName = n;
|
||||
e.printName += " - ";
|
||||
e.printName += e.name;
|
||||
free(n);
|
||||
}
|
||||
}
|
||||
|
||||
m_entries.push_back(e);
|
||||
m_pMem[m_nNext].init(m_nNext, TrampolineMgr::printInfo, TrampolineMgr::printInfoR);
|
||||
|
||||
@ -96,6 +134,16 @@ bool TrampolineMgr::isExecutable(void* addr)
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string TrampolineMgr::inFile(void* addr)
|
||||
{
|
||||
for (auto it = m_memoryMap.begin(); it != m_memoryMap.end(); it++)
|
||||
{
|
||||
if (addr >= it->start && addr < it->end)
|
||||
return it->file;
|
||||
}
|
||||
return "?";
|
||||
}
|
||||
|
||||
void TrampolineMgr::invalidateMemoryMap()
|
||||
{
|
||||
m_memoryMap.clear();
|
||||
@ -117,6 +165,9 @@ void TrampolineMgr::loadMemoryMap()
|
||||
pages.end = (void*) strtol(s, (char**) &s, 16);
|
||||
pages.executable = (*(s+3) == 'x') && (*(s+2) == '-'); // not writable
|
||||
|
||||
if (line.size() > 74)
|
||||
pages.file = line.substr(73);
|
||||
|
||||
//std::cout << line << " -> " << pages.start << " - " << pages.end << " " << pages.executable << std::endl;
|
||||
m_memoryMap.push_back(pages);
|
||||
}
|
||||
@ -231,8 +282,8 @@ std::ostream* TrampolineMgr::getLogger()
|
||||
void* TrampolineMgr::printInfo(uint32_t index, CallStack* stack)
|
||||
{
|
||||
FunctionInfo* info = 0;
|
||||
const std::string& name = m_pInstance->m_entries[index].name;
|
||||
auto it = m_functionInfo.find(name);
|
||||
const AddrEntry& e = m_pInstance->m_entries[index];
|
||||
auto it = m_functionInfo.find(e.name);
|
||||
std::ostream* out;
|
||||
ReturnInfo retInfo;
|
||||
|
||||
@ -251,7 +302,7 @@ void* TrampolineMgr::printInfo(uint32_t index, CallStack* stack)
|
||||
ArgumentWalker w(stack);
|
||||
bool first = true;
|
||||
|
||||
(*out) << name << '(';
|
||||
(*out) << e.printName << '(';
|
||||
|
||||
for (char c : it->second.arguments)
|
||||
{
|
||||
@ -262,10 +313,11 @@ void* TrampolineMgr::printInfo(uint32_t index, CallStack* stack)
|
||||
|
||||
(*out) << w.next(c);
|
||||
}
|
||||
(*out) << ")\n" << std::flush;
|
||||
(*out) << ") ";
|
||||
}
|
||||
else
|
||||
(*out) << m_pInstance->m_entries[index].name << "(?)\n" << std::flush;
|
||||
(*out) << e.printName << "(?) ";
|
||||
(*out) << "ret_ip=" << stack->retAddr /*<< '(' << m_pInstance->inFile(stack->retAddr) << ')'*/ << std::endl << std::flush;
|
||||
|
||||
retInfo.retAddr = stack->retAddr;
|
||||
gettimeofday(&retInfo.callTime, 0);
|
||||
@ -290,15 +342,13 @@ void* TrampolineMgr::printInfoR(uint32_t index, CallStack* stack)
|
||||
(*out) << '[' << stamp << "] ";
|
||||
(*out) << std::string(g_returnInfo->size(), ' ');
|
||||
|
||||
if (it != m_functionInfo.end())
|
||||
{
|
||||
ArgumentWalker w(stack);
|
||||
if (it != m_functionInfo.end())
|
||||
(*out) << "-> " << w.ret(it->second.retType);
|
||||
}
|
||||
else
|
||||
(*out) << "-> ?";
|
||||
(*out) << "-> ? (" << w.ret('p') << ')';
|
||||
|
||||
(*out) << " {" << callTime() << "}\n" << std::flush;
|
||||
(*out) << " {" << callTime() << "} errno=" << errno << std::endl << std::flush;
|
||||
|
||||
g_returnInfo->pop();
|
||||
|
||||
|
@ -1,3 +1,22 @@
|
||||
/*
|
||||
This file is part of Darling.
|
||||
|
||||
Copyright (C) 2012 Lubos Dolezel
|
||||
|
||||
Darling is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Darling is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef TRAMPOLINE_H
|
||||
#define TRAMPOLINE_H
|
||||
#include <stdint.h>
|
||||
@ -18,6 +37,7 @@ public:
|
||||
|
||||
void* generate(void* targetAddr, const char* name);
|
||||
bool isExecutable(void* targetAddr);
|
||||
std::string inFile(void* addr);
|
||||
void invalidateMemoryMap();
|
||||
|
||||
static void loadFunctionInfo(const char* path);
|
||||
@ -61,7 +81,7 @@ public:
|
||||
private:
|
||||
struct AddrEntry
|
||||
{
|
||||
std::string name;
|
||||
std::string name, printName;
|
||||
void* addr;
|
||||
};
|
||||
struct MemoryPages
|
||||
@ -69,6 +89,7 @@ private:
|
||||
void* start;
|
||||
void* end;
|
||||
bool executable;
|
||||
std::string file;
|
||||
|
||||
bool operator<(const MemoryPages& o) { return start < o.start; }
|
||||
bool operator<(void* p) { return start < p; }
|
||||
|
@ -1,3 +1,22 @@
|
||||
/*
|
||||
This file is part of Darling.
|
||||
|
||||
Copyright (C) 2012 Lubos Dolezel
|
||||
|
||||
Darling is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Darling is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "UndefinedFunction.h"
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
|
@ -1,3 +1,22 @@
|
||||
/*
|
||||
This file is part of Darling.
|
||||
|
||||
Copyright (C) 2012 Lubos Dolezel
|
||||
|
||||
Darling is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Darling is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef UNDEFINEDFUNCTION_H
|
||||
#define UNDEFINEDFUNCTION_H
|
||||
#include <cstdio>
|
||||
|
@ -1,3 +1,22 @@
|
||||
/*
|
||||
This file is part of Darling.
|
||||
|
||||
Copyright (C) 2012 Lubos Dolezel
|
||||
|
||||
Darling is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Darling is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "binfmt_misc.h"
|
||||
#include <fstream>
|
||||
#include <stdexcept>
|
||||
|
@ -1,3 +1,22 @@
|
||||
/*
|
||||
This file is part of Darling.
|
||||
|
||||
Copyright (C) 2012 Lubos Dolezel
|
||||
|
||||
Darling is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Darling is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef BINFMTMISC_H
|
||||
#define BINFMTMISC_H
|
||||
|
||||
|
@ -1,3 +1,23 @@
|
||||
/*
|
||||
This file is part of Darling.
|
||||
|
||||
Copyright (C) 2012 Lubos Dolezel
|
||||
Copyright (C) 2011 Shinichiro Hamaji
|
||||
|
||||
Darling is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Darling is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "MachO.h"
|
||||
#include "MachOLoader.h"
|
||||
#include "arch.h"
|
||||
|
@ -1,121 +0,0 @@
|
||||
// Copyright 2011 Shinichiro Hamaji. All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions
|
||||
// are met:
|
||||
//
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
//
|
||||
// 2. Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following
|
||||
// disclaimer in the documentation and/or other materials
|
||||
// provided with the distribution.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY Shinichiro Hamaji ``AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Shinichiro Hamaji OR
|
||||
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
||||
// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
||||
// OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
// SUCH DAMAGE.
|
||||
|
||||
// A command line tool to extract a Mach-O binary from a fat binary.
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <cstdio>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
#include <mach-o/fat.h>
|
||||
|
||||
#include "FatMachO.h"
|
||||
|
||||
static std::string getFileName(std::string path);
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc < 2 || argc > 4)
|
||||
{
|
||||
std::cerr << "Usage: " << argv[0] << " <file> [arch-out]\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
int fd = ::open(argv[1], O_RDONLY);
|
||||
if (fd < 0)
|
||||
{
|
||||
perror("open");
|
||||
return 1;
|
||||
}
|
||||
|
||||
off_t len = ::lseek(fd, 0, SEEK_END);
|
||||
const char* bin = reinterpret_cast<char*>(::mmap(NULL, len, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE, fd, 0));
|
||||
|
||||
if (bin == MAP_FAILED)
|
||||
{
|
||||
perror("mmap");
|
||||
return -errno;
|
||||
}
|
||||
|
||||
std::map<std::string, fat_arch> archs;
|
||||
if (!FatMachO::readFatInfo(fd, &archs))
|
||||
{
|
||||
std::cerr << "Failed to read the Fat Mach-O header\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::cout << archs.size() << " archs:\n";
|
||||
|
||||
for (std::map<std::string, fat_arch>::const_iterator iter = archs.begin(); iter != archs.end(); ++iter)
|
||||
{
|
||||
const fat_arch& arch = iter->second;
|
||||
std::cout << "cputype=" << arch.cputype << " (" << iter->first << ") "
|
||||
"cpusubtype=" << arch.cpusubtype << " offset=" << arch.offset << " size=" << arch.size
|
||||
<< " align=" << arch.align << std::endl;
|
||||
}
|
||||
|
||||
for (int i = 2; i < argc; i++)
|
||||
{
|
||||
const char* arch_name = argv[i];
|
||||
std::map<std::string, fat_arch>::const_iterator found = archs.find(arch_name);
|
||||
if (found == archs.end())
|
||||
{
|
||||
std::cerr << "Architecture not present: " << arch_name << std::endl;
|
||||
continue;
|
||||
}
|
||||
|
||||
const fat_arch& arch = found->second;
|
||||
std::string outname = getFileName(argv[0]) + "." + arch_name;
|
||||
int out = ::open(outname.c_str(), O_WRONLY | O_CREAT, 0777);
|
||||
|
||||
if (::write(out, bin + arch.offset, arch.size) != arch.size)
|
||||
{
|
||||
perror("write");
|
||||
return -errno;
|
||||
}
|
||||
|
||||
::close(out);
|
||||
}
|
||||
}
|
||||
|
||||
std::string getFileName(std::string path)
|
||||
{
|
||||
size_t pos = path.rfind('/');
|
||||
if (pos == std::string::npos)
|
||||
return path;
|
||||
|
||||
return path.substr(pos+1);
|
||||
}
|
||||
|
@ -1,3 +1,22 @@
|
||||
/*
|
||||
This file is part of Darling.
|
||||
|
||||
Copyright (C) 2012 Lubos Dolezel
|
||||
|
||||
Darling is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Darling is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#define DARWIN_LD_INTERNAL
|
||||
#include "MachOLoader.h"
|
||||
|
@ -1,3 +1,22 @@
|
||||
/*
|
||||
This file is part of Darling.
|
||||
|
||||
Copyright (C) 2012 Lubos Dolezel
|
||||
|
||||
Darling is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Darling is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef DARWIN_LD_H
|
||||
#define DARWIN_LD_H
|
||||
#include <dlfcn.h>
|
||||
|
@ -1,3 +1,22 @@
|
||||
/*
|
||||
This file is part of Darling.
|
||||
|
||||
Copyright (C) 2012 Lubos Dolezel
|
||||
|
||||
Darling is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Darling is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "public.h"
|
||||
#include "MachOLoader.h"
|
||||
|
@ -1,3 +1,22 @@
|
||||
/*
|
||||
This file is part of Darling.
|
||||
|
||||
Copyright (C) 2012 Lubos Dolezel
|
||||
|
||||
Darling is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Darling is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef DYLD_PUBLIC_H
|
||||
#define DYLD_PUBLIC_H
|
||||
#include <stdint.h>
|
||||
|
@ -1,3 +1,21 @@
|
||||
;
|
||||
; This file is part of Darling.
|
||||
;
|
||||
; Copyright (C) 2012 Lubos Dolezel
|
||||
;
|
||||
; Darling is free software: you can redistribute it and/or modify
|
||||
; it under the terms of the GNU General Public License as published by
|
||||
; the Free Software Foundation, either version 3 of the License, or
|
||||
; (at your option) any later version.
|
||||
;
|
||||
; Darling is distributed in the hope that it will be useful,
|
||||
; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
; GNU General Public License for more details.
|
||||
|
||||
; You should have received a copy of the GNU General Public License
|
||||
; along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
global trampoline_start
|
||||
global trampoline_end
|
||||
global reg_saveall
|
||||
|
@ -94,5 +94,5 @@ add_library(System.B.dylib SHARED ${libc_SRCS} ${bsdkern_SRCS} ${machkern_SRCS})
|
||||
target_link_libraries(System.B.dylib -ldl -lpthread -luuid -l:../../libmach-o.so -lrt -lssl -lbsd -l:libobjc.so.4)
|
||||
add_dependencies(System.B.dylib mach-o)
|
||||
|
||||
install(TARGETS System.B.dylib DESTINATION lib${SUFFIX})
|
||||
install(TARGETS System.B.dylib DESTINATION "lib${SUFFIX}/darling")
|
||||
|
||||
|
@ -273,10 +273,15 @@ int __darwin_uname(__darwin_utsname* buf) {
|
||||
return r;
|
||||
|
||||
// Linux's buf size is currently much smaller, only 65, so strcpy() is safe
|
||||
strcpy(buf->sysname, linux_buf.sysname);
|
||||
//strcpy(buf->sysname, linux_buf.sysname);
|
||||
//strcpy(buf->nodename, linux_buf.nodename);
|
||||
//strcpy(buf->release, linux_buf.release);
|
||||
//strcpy(buf->version, linux_buf.version);
|
||||
//strcpy(buf->machine, linux_buf.machine);
|
||||
strcpy(buf->sysname, "Darwin");
|
||||
strcpy(buf->nodename, linux_buf.nodename);
|
||||
strcpy(buf->release, linux_buf.release);
|
||||
strcpy(buf->version, linux_buf.version);
|
||||
strcpy(buf->release, "12.0.0");
|
||||
strcpy(buf->version, "Darwin Kernel Version 12.0.0");
|
||||
strcpy(buf->machine, linux_buf.machine);
|
||||
return 0;
|
||||
}
|
||||
|
22
src/libmacarchive/CMakeLists.txt
Normal file
22
src/libmacarchive/CMakeLists.txt
Normal file
@ -0,0 +1,22 @@
|
||||
project(macarchive)
|
||||
|
||||
cmake_minimum_required(VERSION 2.4.0)
|
||||
if(COMMAND cmake_policy)
|
||||
cmake_policy(SET CMP0003 NEW)
|
||||
endif(COMMAND cmake_policy)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC")
|
||||
|
||||
set(macarchive_SRCS
|
||||
FileStream.cpp
|
||||
MacBinaryStream.cpp
|
||||
DMGStream.cpp
|
||||
adc.c
|
||||
)
|
||||
|
||||
add_library(macarchive SHARED ${macarchive_SRCS})
|
||||
target_link_libraries(macarchive -lssl -lz -lbz2)
|
||||
|
||||
install(TARGETS macarchive DESTINATION "lib{SUFFIX}/darling")
|
||||
|
||||
|
41
src/libmacarchive/DMGStream.cpp
Normal file
41
src/libmacarchive/DMGStream.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#include "DMGStream.h"
|
||||
|
||||
IStream* DMGStream::open(IStream* stream)
|
||||
{
|
||||
DMGStream* o = new DMGStream(stream);
|
||||
stream->seek(-512, SEEK_END);
|
||||
stream->read(&o->m_koly, 512);
|
||||
|
||||
if (o->m_koly.Signature.msb() != 'koly')
|
||||
{
|
||||
delete o;
|
||||
return nullptr;
|
||||
}
|
||||
else
|
||||
return o;
|
||||
}
|
||||
|
||||
DMGStream::DMGStream(IStream* stream)
|
||||
: m_stream(stream)
|
||||
{
|
||||
static_assert(sizeof(m_koly) == 512, "Invalid kolyblk declaration");
|
||||
|
||||
// TODO: process the headers
|
||||
}
|
||||
|
||||
DMGStream::~DMGStream()
|
||||
{
|
||||
}
|
||||
|
||||
ssize_t DMGStream::read(void* buffer, ssize_t bytes)
|
||||
{
|
||||
}
|
||||
|
||||
int64_t DMGStream::seek(int64_t offset, int whence)
|
||||
{
|
||||
}
|
||||
|
||||
int64_t DMGStream::length() const
|
||||
{
|
||||
}
|
||||
|
79
src/libmacarchive/DMGStream.h
Normal file
79
src/libmacarchive/DMGStream.h
Normal file
@ -0,0 +1,79 @@
|
||||
#ifndef DMGSTREAM_H
|
||||
#define DMGSTREAM_H
|
||||
#include <stdint.h>
|
||||
#include "IStream.h"
|
||||
#include "../util/MSB.h"
|
||||
|
||||
// TODO: copyright vo1tur
|
||||
|
||||
// base64: http://www.ioncannon.net/programming/34/howto-base64-encode-with-cc-and-openssl/
|
||||
|
||||
struct kolyblk {
|
||||
MSB<uint32_t> Signature;
|
||||
MSB<uint32_t> Version;
|
||||
MSB<uint32_t> HeaderSize;
|
||||
MSB<uint32_t> Flags;
|
||||
MSB<uint64_t> RunningDataForkOffset;
|
||||
MSB<uint64_t> DataForkOffset;
|
||||
MSB<uint64_t> DataForkLength;
|
||||
MSB<uint64_t> RsrcForkOffset;
|
||||
MSB<uint64_t> RsrcForkLength;
|
||||
MSB<uint32_t> SegmentNumber;
|
||||
MSB<uint32_t> SegmentCount;
|
||||
MSB<uint32_t> SegmentID1;
|
||||
MSB<uint32_t> SegmentID2;
|
||||
MSB<uint32_t> SegmentID3;
|
||||
MSB<uint32_t> SegmentID4;
|
||||
MSB<uint32_t> DataForkChecksumType;
|
||||
MSB<uint32_t> Reserved1;
|
||||
MSB<uint32_t> DataForkChecksum;
|
||||
MSB<uint32_t> Reserved2;
|
||||
char Reserved3[120];
|
||||
MSB<uint64_t> XMLOffset;
|
||||
MSB<uint64_t> XMLLength;
|
||||
char Reserved4[120];
|
||||
MSB<uint32_t> MasterChecksumType;
|
||||
MSB<uint32_t> Reserved5;
|
||||
MSB<uint32_t> MasterChecksum;
|
||||
MSB<uint32_t> Reserved6;
|
||||
char Reserved7[120];
|
||||
MSB<uint32_t> ImageVariant;
|
||||
MSB<uint64_t> SectorCount;
|
||||
char Reserved8[12];
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
struct _mishblk {
|
||||
MSB<uint32_t> BlocksSignature;
|
||||
MSB<uint32_t> InfoVersion;
|
||||
MSB<uint64_t> FirstSectorNumber;
|
||||
MSB<uint64_t> SectorCount;
|
||||
MSB<uint64_t> DataStart;
|
||||
MSB<uint32_t> DecompressedBufferRequested;
|
||||
MSB<uint32_t> BlocksDescriptor;
|
||||
char Reserved1[24];
|
||||
MSB<uint32_t> ChecksumType;
|
||||
MSB<uint32_t> Reserved2;
|
||||
MSB<uint32_t> Checksum;
|
||||
MSB<uint32_t> Reserved3;
|
||||
char Reserved4[120];
|
||||
MSB<uint32_t> BlocksRunCount;
|
||||
char *Data;
|
||||
} __attribute__ ((__packed__));
|
||||
|
||||
class DMGStream : public IStream
|
||||
{
|
||||
private:
|
||||
DMGStream(IStream* stream);
|
||||
public:
|
||||
static IStream* open(IStream* stream);
|
||||
virtual ~DMGStream();
|
||||
virtual ssize_t read(void* buffer, ssize_t bytes) override;
|
||||
virtual int64_t seek(int64_t offset, int whence) override;
|
||||
virtual int64_t length() const override;
|
||||
private:
|
||||
IStream* m_stream;
|
||||
kolyblk m_koly;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
41
src/libmacarchive/FileStream.cpp
Normal file
41
src/libmacarchive/FileStream.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
#include "FileStream.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
FileStream::FileStream(int fd)
|
||||
: m_fd(fd)
|
||||
{
|
||||
m_length = lseek(fd, 0, SEEK_END);
|
||||
lseek(fd, 0, SEEK_SET);
|
||||
}
|
||||
|
||||
IStream* FileStream::open(const char* path)
|
||||
{
|
||||
int fd = ::open(path, O_RDONLY);
|
||||
if (fd < 0)
|
||||
return nullptr;
|
||||
return new FileStream(fd);
|
||||
}
|
||||
|
||||
FileStream::~FileStream()
|
||||
{
|
||||
close(m_fd);
|
||||
}
|
||||
|
||||
ssize_t FileStream::read(void* buffer, ssize_t bytes)
|
||||
{
|
||||
return ::read(m_fd, buffer, bytes);
|
||||
}
|
||||
|
||||
int64_t FileStream::seek(int64_t offset, int whence)
|
||||
{
|
||||
return lseek(m_fd, offset, whence);
|
||||
}
|
||||
|
||||
int64_t FileStream::length() const
|
||||
{
|
||||
return m_length;
|
||||
}
|
||||
|
21
src/libmacarchive/FileStream.h
Normal file
21
src/libmacarchive/FileStream.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef FILESTREAM_H
|
||||
#define FILESTREAM_H
|
||||
#include "IStream.h"
|
||||
|
||||
class FileStream : public IStream
|
||||
{
|
||||
private:
|
||||
FileStream(int fd);
|
||||
public:
|
||||
static IStream* open(const char* path);
|
||||
virtual ~FileStream();
|
||||
virtual ssize_t read(void* buffer, ssize_t bytes) override;
|
||||
virtual int64_t seek(int64_t offset, int whence) override;
|
||||
virtual int64_t length() const override;
|
||||
private:
|
||||
int m_fd;
|
||||
int64_t m_length;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
25
src/libmacarchive/IStorage.h
Normal file
25
src/libmacarchive/IStorage.h
Normal file
@ -0,0 +1,25 @@
|
||||
#ifndef ISTORAGE_H
|
||||
#define ISTORAGE_H
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <stdint.h>
|
||||
|
||||
class IStream;
|
||||
|
||||
struct FileEntry
|
||||
{
|
||||
std::string name;
|
||||
int64_t size;
|
||||
unsigned char d_type; // see readdir()
|
||||
};
|
||||
|
||||
class IStorage
|
||||
{
|
||||
public:
|
||||
virtual ~IStorage() = 0;
|
||||
virtual IStream* open(const char* path) = 0;
|
||||
virtual std::vector<FileEntry> list() = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
17
src/libmacarchive/IStream.h
Normal file
17
src/libmacarchive/IStream.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef ISTREAM_H
|
||||
#define ISTREAM_H
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
class IStream
|
||||
{
|
||||
public:
|
||||
virtual ~IStream() = 0;
|
||||
virtual ssize_t read(void* buffer, ssize_t bytes) = 0;
|
||||
virtual int64_t seek(int64_t offset, int whence) = 0;
|
||||
virtual int64_t length() const = 0;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
61
src/libmacarchive/MacBinaryStream.cpp
Normal file
61
src/libmacarchive/MacBinaryStream.cpp
Normal file
@ -0,0 +1,61 @@
|
||||
#include "MacBinaryStream.h"
|
||||
|
||||
MacBinaryStream::MacBinaryStream(IStream* stream)
|
||||
: m_stream(stream), m_pos(0)
|
||||
{
|
||||
m_stream->read(&m_header, sizeof(m_header));
|
||||
|
||||
uint32_t extraLen = 0;
|
||||
|
||||
if (m_header.signature == 'mBIN')
|
||||
extraLen = m_header.sec_header_len;
|
||||
|
||||
m_dataOffset = 128 + extraLen;
|
||||
m_stream->seek(m_dataOffset, SEEK_SET);
|
||||
}
|
||||
|
||||
IStream* MacBinaryStream::open(IStream* stream)
|
||||
{
|
||||
return new MacBinaryStream(stream);
|
||||
}
|
||||
|
||||
MacBinaryStream::~MacBinaryStream()
|
||||
{
|
||||
}
|
||||
|
||||
ssize_t MacBinaryStream::read(void* buffer, ssize_t bytes)
|
||||
{
|
||||
if (m_pos + bytes > m_header.data_len)
|
||||
bytes = m_header.data_len - m_pos;
|
||||
|
||||
bytes = m_stream->read(buffer, bytes);
|
||||
|
||||
if (bytes > 0)
|
||||
m_pos += bytes;
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
int64_t MacBinaryStream::seek(int64_t offset, int whence)
|
||||
{
|
||||
if (whence == SEEK_SET)
|
||||
m_pos = offset;
|
||||
else if (whence == SEEK_CUR)
|
||||
m_pos += offset;
|
||||
else if (whence == SEEK_END)
|
||||
m_pos = m_header.data_len - offset;
|
||||
|
||||
if (m_pos > m_header.data_len)
|
||||
m_pos = m_header.data_len;
|
||||
if (m_pos < 0)
|
||||
m_pos = 0;
|
||||
|
||||
m_stream->seek(m_pos, SEEK_SET);
|
||||
return m_pos;
|
||||
}
|
||||
|
||||
int64_t MacBinaryStream::length() const
|
||||
{
|
||||
return m_header.data_len;
|
||||
}
|
||||
|
24
src/libmacarchive/MacBinaryStream.h
Normal file
24
src/libmacarchive/MacBinaryStream.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef MACBINARYSTREAM_H
|
||||
#define MACBINARYSTREAM_H
|
||||
#include "../macbinary/macbinary.h"
|
||||
#include "IStream.h"
|
||||
|
||||
class MacBinaryStream : public IStream
|
||||
{
|
||||
private:
|
||||
MacBinaryStream(IStream* stream);
|
||||
public:
|
||||
static IStream* open(IStream* stream);
|
||||
|
||||
~MacBinaryStream();
|
||||
virtual ssize_t read(void* buffer, ssize_t bytes) override;
|
||||
virtual int64_t seek(int64_t offset, int whence) override;
|
||||
virtual int64_t length() const override;
|
||||
private:
|
||||
IStream* m_stream;
|
||||
MacBinaryHeader m_header;
|
||||
int64_t m_pos, m_dataOffset;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
114
src/libmacarchive/adc.c
Normal file
114
src/libmacarchive/adc.c
Normal file
@ -0,0 +1,114 @@
|
||||
#include "adc.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
int adc_decompress(int in_size, unsigned char *input, int avail_size, unsigned char *output, int *bytes_written)
|
||||
{
|
||||
if (in_size == 0)
|
||||
return 0;
|
||||
bool output_full = false;
|
||||
unsigned char *inp = input;
|
||||
unsigned char *outp = output;
|
||||
int chunk_type;
|
||||
int chunk_size;
|
||||
int offset;
|
||||
int i;
|
||||
|
||||
while (inp - input < in_size) {
|
||||
chunk_type = adc_chunk_type(*inp);
|
||||
switch (chunk_type) {
|
||||
case ADC_PLAIN:
|
||||
chunk_size = adc_chunk_size(*inp);
|
||||
if (outp + chunk_size - output > avail_size) {
|
||||
output_full = true;
|
||||
break;
|
||||
}
|
||||
memcpy(outp, inp + 1, chunk_size);
|
||||
inp += chunk_size + 1;
|
||||
outp += chunk_size;
|
||||
break;
|
||||
|
||||
case ADC_2BYTE:
|
||||
chunk_size = adc_chunk_size(*inp);
|
||||
offset = adc_chunk_offset(inp);
|
||||
if (outp + chunk_size - output > avail_size) {
|
||||
output_full = true;
|
||||
break;
|
||||
}
|
||||
if (offset == 0) {
|
||||
memset(outp, *(outp - offset - 1), chunk_size);
|
||||
outp += chunk_size;
|
||||
inp += 2;
|
||||
} else {
|
||||
for (i = 0; i < chunk_size; i++) {
|
||||
memcpy(outp, outp - offset - 1, 1);
|
||||
outp++;
|
||||
}
|
||||
inp += 2;
|
||||
}
|
||||
break;
|
||||
|
||||
case ADC_3BYTE:
|
||||
chunk_size = adc_chunk_size(*inp);
|
||||
offset = adc_chunk_offset(inp);
|
||||
if (outp + chunk_size - output > avail_size) {
|
||||
output_full = true;
|
||||
break;
|
||||
}
|
||||
if (offset == 0) {
|
||||
memset(outp, *(outp - offset - 1), chunk_size);
|
||||
outp += chunk_size;
|
||||
inp += 3;
|
||||
} else {
|
||||
for (i = 0; i < chunk_size; i++) {
|
||||
memcpy(outp, outp - offset - 1, 1);
|
||||
outp++;
|
||||
}
|
||||
inp += 3;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (output_full)
|
||||
break;
|
||||
}
|
||||
*bytes_written = outp - output;
|
||||
return inp - input;
|
||||
}
|
||||
|
||||
int adc_chunk_type(char _byte)
|
||||
{
|
||||
if (_byte & 0x80)
|
||||
return ADC_PLAIN;
|
||||
if (_byte & 0x40)
|
||||
return ADC_3BYTE;
|
||||
return ADC_2BYTE;
|
||||
}
|
||||
|
||||
int adc_chunk_size(char _byte)
|
||||
{
|
||||
switch (adc_chunk_type(_byte)) {
|
||||
case ADC_PLAIN:
|
||||
return (_byte & 0x7F) + 1;
|
||||
case ADC_2BYTE:
|
||||
return ((_byte & 0x3F) >> 2) + 3;
|
||||
case ADC_3BYTE:
|
||||
return (_byte & 0x3F) + 4;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int adc_chunk_offset(unsigned char *chunk_start)
|
||||
{
|
||||
unsigned char *c = chunk_start;
|
||||
switch (adc_chunk_type(*c)) {
|
||||
case ADC_PLAIN:
|
||||
return 0;
|
||||
case ADC_2BYTE:
|
||||
return ((((unsigned char)*c & 0x03)) << 8) + (unsigned char)*(c + 1);
|
||||
case ADC_3BYTE:
|
||||
return (((unsigned char)*(c + 1)) << 8) + (unsigned char)*(c + 2);
|
||||
}
|
||||
return -1;
|
||||
}
|
15
src/libmacarchive/adc.h
Normal file
15
src/libmacarchive/adc.h
Normal file
@ -0,0 +1,15 @@
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define ADC_PLAIN 0x01
|
||||
#define ADC_2BYTE 0x02
|
||||
#define ADC_3BYTE 0x03
|
||||
|
||||
#define bool short
|
||||
#define true 1
|
||||
#define false 0
|
||||
|
||||
int adc_decompress(int in_size, unsigned char *input, int avail_size, unsigned char *output, int *bytes_written);
|
||||
int adc_chunk_type(char _byte);
|
||||
int adc_chunk_size(char _byte);
|
||||
int adc_chunk_offset(unsigned char *chunk_start);
|
@ -23,5 +23,5 @@ add_library(ncurses.5.4.dylib SHARED ${libncurses_SRCS})
|
||||
# -luuid to make uuid_ functions available for Darwin apps
|
||||
target_link_libraries(ncurses.5.4.dylib -lncurses)
|
||||
|
||||
install(TARGETS ncurses.5.4.dylib DESTINATION lib${SUFFIX})
|
||||
install(TARGETS ncurses.5.4.dylib DESTINATION "lib${SUFFIX}/darling")
|
||||
|
||||
|
@ -12,6 +12,9 @@ enable_language(ASM_NASM)
|
||||
#endif (NOT "${CMAKE_CXX_COMPILER} ${CMAKE_CXX_COMPILER_ARG1}" MATCHES ".*clang")
|
||||
|
||||
#configure_file(config.h.in config.h)
|
||||
|
||||
add_definitions(-D__STDC_LIMIT_MACROS)
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -fPIC -fvisibility=hidden -ggdb")
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -fPIC -fvisibility=hidden -ggdb")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fPIC")
|
||||
@ -19,6 +22,7 @@ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fPIC")
|
||||
set(objcdarwin_SRCS
|
||||
objc_msgSend_fixup.nasm
|
||||
objc_msgSendSuper.nasm
|
||||
objc_msgSend.nasm
|
||||
NameTranslate.cpp
|
||||
ClassRegister.cpp
|
||||
|
||||
@ -37,10 +41,13 @@ set(objcdarwin_SRCS
|
||||
new/protocol.cpp
|
||||
|
||||
NSBundle_dyld.mm
|
||||
NSCFString.mm
|
||||
misc.mm
|
||||
zero.c
|
||||
)
|
||||
|
||||
add_library(objc.A.dylib SHARED ${objcdarwin_SRCS})
|
||||
target_link_libraries(objc.A.dylib -l:libobjc.so.4 -lgnustep-base)
|
||||
|
||||
install(TARGETS objc.A.dylib DESTINATION lib${SUFFIX})
|
||||
install(TARGETS objc.A.dylib DESTINATION "lib${SUFFIX}/darling")
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
#ifndef NSBUNDLE_DYLD_H
|
||||
#define NSBUNDLE_DYLD_H
|
||||
#define __STDC_LIMIT_MACROS
|
||||
#include <Foundation/NSBundle.h>
|
||||
|
||||
@interface NSBundle (NSBundle_dyld)
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
extern char g_darwin_executable_path[PATH_MAX];
|
||||
static NSBundle* _mainBundle = 0;
|
||||
static NSAutoreleasePool* g_pool = 0;
|
||||
|
||||
void MethodSwizzle(Class aClass, SEL orig_sel, SEL alt_sel);
|
||||
|
||||
@ -20,18 +21,23 @@ __attribute__((constructor)) static void myinit()
|
||||
|
||||
MethodSwizzle(objc_getMetaClass("NSBundle"), @selector(mainBundle), @selector(x_mainBundle));
|
||||
|
||||
g_pool = [[NSAutoreleasePool alloc] init];
|
||||
|
||||
const char* last = strrchr(g_darwin_executable_path, '/');
|
||||
if (last != 0)
|
||||
{
|
||||
last++;
|
||||
|
||||
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
|
||||
NSString* str = [NSString stringWithUTF8String:last];
|
||||
[[NSProcessInfo processInfo] setProcessName:str];
|
||||
[pool drain];
|
||||
}
|
||||
}
|
||||
|
||||
__attribute__((destructor)) static void myexit()
|
||||
{
|
||||
[g_pool drain];
|
||||
g_pool = 0;
|
||||
}
|
||||
|
||||
@implementation NSBundle (NSBundle_dyld)
|
||||
/*
|
||||
@ -56,6 +62,14 @@ __attribute__((constructor)) static void myinit()
|
||||
path.resize(pos+1);
|
||||
//path += "Resources";
|
||||
|
||||
if ((pos = path.find(".app/")) != std::string::npos)
|
||||
{
|
||||
// "path.endsWith()"
|
||||
// if (path.compare(path.size()-7, 7, "/MacOS/") == 0)
|
||||
// path.resize(path.size() - 7);
|
||||
path.resize(pos+6);
|
||||
}
|
||||
|
||||
LOG << "NSBundle::x_mainBundle(): deduced " << path << " as resource path\n";
|
||||
|
||||
_mainBundle = [self alloc];
|
||||
|
14
src/libobjcdarwin/NSCFString.h
Normal file
14
src/libobjcdarwin/NSCFString.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef NSCFSTRING_H
|
||||
#define NSCFSTRING_H
|
||||
#include <Foundation/NSString.h>
|
||||
|
||||
@interface NSCFString : NSString
|
||||
{
|
||||
unsigned long info;
|
||||
const char* nxcsptr;
|
||||
unsigned long nxcslen;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
418
src/libobjcdarwin/NSCFString.mm
Normal file
418
src/libobjcdarwin/NSCFString.mm
Normal file
@ -0,0 +1,418 @@
|
||||
/** Implementation for GNUStep of NSString concrete subclasses
|
||||
Copyright (C) 1997,1998,2000 Free Software Foundation, Inc.
|
||||
|
||||
Base on code written by Stevo Crvenkovski <stevo@btinternet.com>
|
||||
Date: February 1997
|
||||
|
||||
Based on NSGCString and NSString
|
||||
Written by: Andrew Kachites McCallum
|
||||
<mccallum@gnu.ai.mit.edu>
|
||||
Date: March 1995
|
||||
|
||||
Optimised by Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
Date: October 1998
|
||||
|
||||
Redesign/rewrite by Richard Frith-Macdonald <rfm@gnu.org>
|
||||
Date: September 2000
|
||||
|
||||
This file is part of the GNUstep Base Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Library General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free
|
||||
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
Boston, MA 02111 USA.
|
||||
|
||||
This file derives a NSCFString class from the NXConstantString implementaion. (Luboš Doležel)
|
||||
*/
|
||||
|
||||
#import "NSCFString.h"
|
||||
#import <Foundation/NSException.h>
|
||||
|
||||
/* Determine the length of the UTF-8 string as a unicode (UTF-16) string.
|
||||
* sets the ascii flag according to the content found.
|
||||
*/
|
||||
static NSUInteger
|
||||
lengthUTF8(const uint8_t *p, unsigned l, BOOL *ascii, BOOL *latin1)
|
||||
{
|
||||
const uint8_t *e = p + l;
|
||||
BOOL a = YES;
|
||||
BOOL l1 = YES;
|
||||
|
||||
l = 0;
|
||||
while (p < e)
|
||||
{
|
||||
uint8_t c = *p;
|
||||
uint32_t u = c;
|
||||
|
||||
if (c > 0x7f)
|
||||
{
|
||||
int i, sle = 0;
|
||||
|
||||
a = NO;
|
||||
/* calculated the expected sequence length */
|
||||
while (c & 0x80)
|
||||
{
|
||||
c = c << 1;
|
||||
sle++;
|
||||
}
|
||||
|
||||
/* legal ? */
|
||||
if ((sle < 2) || (sle > 6))
|
||||
{
|
||||
[NSException raise: NSInternalInconsistencyException
|
||||
format: @"Bad sequence length in constant string"];
|
||||
}
|
||||
|
||||
if (p + sle > e)
|
||||
{
|
||||
[NSException raise: NSInternalInconsistencyException
|
||||
format: @"Short data in constant string"];
|
||||
}
|
||||
|
||||
/* get the codepoint */
|
||||
for (i = 1; i < sle; i++)
|
||||
{
|
||||
if (p[i] < 0x80 || p[i] >= 0xc0)
|
||||
break;
|
||||
u = (u << 6) | (p[i] & 0x3f);
|
||||
}
|
||||
|
||||
if (i < sle)
|
||||
{
|
||||
[NSException raise: NSInternalInconsistencyException
|
||||
format: @"Codepoint out of range in constant string"];
|
||||
}
|
||||
u = u & ~(0xffffffff << ((5 * sle) + 1));
|
||||
p += sle;
|
||||
|
||||
/*
|
||||
* We check for invalid codepoints here.
|
||||
*/
|
||||
if (u > 0x10ffff || u == 0xfffe || u == 0xffff
|
||||
|| (u >= 0xfdd0 && u <= 0xfdef))
|
||||
{
|
||||
[NSException raise: NSInternalInconsistencyException
|
||||
format: @"Codepoint invalid in constant string"];
|
||||
}
|
||||
|
||||
if ((u >= 0xd800) && (u <= 0xdfff))
|
||||
{
|
||||
[NSException raise: NSInternalInconsistencyException
|
||||
format: @"Bad surrogate pair in constant string"];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
p++;
|
||||
}
|
||||
|
||||
/*
|
||||
* Add codepoint as either a single unichar for BMP
|
||||
* or as a pair of surrogates for codepoints over 16 bits.
|
||||
*/
|
||||
if (u < 0x10000)
|
||||
{
|
||||
l++;
|
||||
if (u > 255)
|
||||
{
|
||||
l1 = NO;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
l += 2;
|
||||
}
|
||||
}
|
||||
if (0 != ascii)
|
||||
{
|
||||
*ascii = a;
|
||||
}
|
||||
if (0 != latin1)
|
||||
{
|
||||
*latin1 = l1;
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
/* Sequentially extracts characters from UTF-8 string
|
||||
* p = pointer to the utf-8 data
|
||||
* l = length (bytes) of the utf-8 data
|
||||
* o = pointer to current offset within the data
|
||||
* n = pointer to either zero or the next pre-read part of a surrogate pair.
|
||||
* The condition for having read the entire string is that the offset (*o)
|
||||
* is the number of bytes in the string, and the unichar pointed to by *n
|
||||
* is zero (meaning there is no second part of a surrogate pair remaining).
|
||||
*/
|
||||
static inline unichar
|
||||
nextUTF8(const uint8_t *p, unsigned l, unsigned *o, unichar *n)
|
||||
{
|
||||
unsigned i;
|
||||
|
||||
/* If we still have the second part of a surrogate pair, return it.
|
||||
*/
|
||||
if (*n > 0)
|
||||
{
|
||||
unichar u = *n;
|
||||
|
||||
*n = 0;
|
||||
return u;
|
||||
}
|
||||
|
||||
if ((i = *o) < l)
|
||||
{
|
||||
uint8_t c = p[i];
|
||||
uint32_t u = c;
|
||||
|
||||
if (c > 0x7f)
|
||||
{
|
||||
int j, sle = 0;
|
||||
|
||||
/* calculated the expected sequence length */
|
||||
while (c & 0x80)
|
||||
{
|
||||
c = c << 1;
|
||||
sle++;
|
||||
}
|
||||
|
||||
/* legal ? */
|
||||
if ((sle < 2) || (sle > 6))
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"bad multibyte character length"];
|
||||
}
|
||||
|
||||
if (sle + i > l)
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"multibyte character extends beyond data"];
|
||||
}
|
||||
|
||||
/* get the codepoint */
|
||||
for (j = 1; j < sle; j++)
|
||||
{
|
||||
uint8_t b = p[i + j];
|
||||
|
||||
if (b < 0x80 || b >= 0xc0)
|
||||
break;
|
||||
u = (u << 6) | (b & 0x3f);
|
||||
}
|
||||
|
||||
if (j < sle)
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"bad data in multibyte character"];
|
||||
}
|
||||
u = u & ~(0xffffffff << ((5 * sle) + 1));
|
||||
i += sle;
|
||||
|
||||
/*
|
||||
* We discard invalid codepoints here.
|
||||
*/
|
||||
if (u > 0x10ffff || u == 0xfffe || u == 0xffff
|
||||
|| (u >= 0xfdd0 && u <= 0xfdef))
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"invalid unicode codepoint"];
|
||||
}
|
||||
|
||||
if ((u >= 0xd800) && (u <= 0xdfff))
|
||||
{
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"unmatched half of surrogate pair"];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
i++;
|
||||
}
|
||||
|
||||
/*
|
||||
* Add codepoint as either a single unichar for BMP
|
||||
* or as a pair of surrogates for codepoints over 16 bits.
|
||||
*/
|
||||
if (u >= 0x10000)
|
||||
{
|
||||
unichar ul, uh;
|
||||
|
||||
u -= 0x10000;
|
||||
ul = u & 0x3ff;
|
||||
uh = (u >> 10) & 0x3ff;
|
||||
|
||||
*n = ul + 0xdc00; // record second part of pair
|
||||
u = uh + 0xd800; // return first part.
|
||||
}
|
||||
*o = i; // Return new index
|
||||
return (unichar)u;
|
||||
}
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"no more data in UTF-8 string"];
|
||||
return 0;
|
||||
}
|
||||
|
||||
@implementation NSCFString
|
||||
|
||||
- (const char*) UTF8String
|
||||
{
|
||||
return nxcsptr;
|
||||
}
|
||||
|
||||
- (unichar) characterAtIndex: (NSUInteger)index
|
||||
{
|
||||
NSUInteger l = 0;
|
||||
unichar u;
|
||||
unichar n = 0;
|
||||
unsigned i = 0;
|
||||
|
||||
while (i < nxcslen || n > 0)
|
||||
{
|
||||
u = nextUTF8((const uint8_t *)nxcsptr, nxcslen, &i, &n);
|
||||
if (l++ == index)
|
||||
{
|
||||
return u;
|
||||
}
|
||||
}
|
||||
|
||||
[NSException raise: NSInvalidArgumentException
|
||||
format: @"-characterAtIndex: index out of range"];
|
||||
return 0;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
GSNOSUPERDEALLOC;
|
||||
}
|
||||
|
||||
/* Must match the implementation in NSString
|
||||
*/
|
||||
- (NSUInteger) hash
|
||||
{
|
||||
if (nxcslen > 0)
|
||||
{
|
||||
unsigned ret = 0;
|
||||
unichar n = 0;
|
||||
unsigned i = 0;
|
||||
unichar c;
|
||||
|
||||
while (i < nxcslen)
|
||||
{
|
||||
c = nextUTF8((const uint8_t *)nxcsptr, nxcslen, &i, &n);
|
||||
ret = (ret << 5) + ret + c;
|
||||
}
|
||||
if (0 != n)
|
||||
{
|
||||
ret = (ret << 5) + ret + n; // Add final character
|
||||
}
|
||||
ret &= 0x0fffffff;
|
||||
if (ret == 0)
|
||||
{
|
||||
ret = 0x0fffffff;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0x0ffffffe; /* Hash for an empty string. */
|
||||
}
|
||||
}
|
||||
|
||||
- (id) initWithBytes: (const void*)bytes
|
||||
length: (NSUInteger)length
|
||||
encoding: (NSStringEncoding)encoding
|
||||
{
|
||||
[NSException raise: NSGenericException
|
||||
format: @"Attempt to init a constant string"];
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (id) initWithBytesNoCopy: (void*)bytes
|
||||
length: (NSUInteger)length
|
||||
encoding: (NSStringEncoding)encoding
|
||||
freeWhenDone: (BOOL)flag
|
||||
{
|
||||
[NSException raise: NSGenericException
|
||||
format: @"Attempt to init a constant string"];
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (BOOL) isEqual: (id)anObject
|
||||
{
|
||||
if ([anObject isKindOfClass: [NSCFString class]])
|
||||
{
|
||||
NSCFString* str = (NSCFString*) anObject;
|
||||
if (nxcslen != str->nxcslen)
|
||||
return NO;
|
||||
else
|
||||
return memcmp(nxcsptr, str->nxcsptr, nxcslen) == 0;
|
||||
}
|
||||
else if ([anObject isKindOfClass: [NSString class]])
|
||||
return [anObject isEqual: self];
|
||||
else
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL) isEqualToString: (NSString*)other
|
||||
{
|
||||
if ([other isKindOfClass: [NSCFString class]])
|
||||
{
|
||||
NSCFString* str = (NSCFString*) other;
|
||||
if (nxcslen != str->nxcslen)
|
||||
return NO;
|
||||
else
|
||||
return memcmp(nxcsptr, str->nxcsptr, nxcslen) == 0;
|
||||
}
|
||||
else
|
||||
return [other isEqual: self];
|
||||
}
|
||||
|
||||
- (NSUInteger) length
|
||||
{
|
||||
return lengthUTF8((const uint8_t*)nxcsptr, nxcslen, 0, 0);
|
||||
}
|
||||
|
||||
- (id) retain
|
||||
{
|
||||
return self;
|
||||
}
|
||||
|
||||
- (oneway void) release
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
- (id) autorelease
|
||||
{
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id) copyWithZone: (NSZone*)z
|
||||
{
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSZone*) zone
|
||||
{
|
||||
return NSDefaultMallocZone();
|
||||
}
|
||||
|
||||
- (NSStringEncoding) fastestEncoding
|
||||
{
|
||||
return NSUTF8StringEncoding;
|
||||
}
|
||||
|
||||
- (NSStringEncoding) smallestEncoding
|
||||
{
|
||||
return NSUTF8StringEncoding;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -40,6 +40,11 @@ static bool ClassTranslator(char* name)
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (strcmp(name, "__CFConstantStringClassReference") == 0)
|
||||
{
|
||||
strcpy(name, "_OBJC_CLASS_NSCFString");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include "attribute.h"
|
||||
#include "../../util/log.h"
|
||||
#include <cassert>
|
||||
|
||||
bool nextAttribute(objc_property_attribute_t& next, const char*& pos, std::vector<std::string>& strings)
|
||||
@ -39,5 +40,7 @@ bool nextAttribute(objc_property_attribute_t& next, const char*& pos, std::vecto
|
||||
next.value = strings.back().c_str();
|
||||
}
|
||||
|
||||
LOG << "Attr: name: " << next.name << "; value: " << next.value << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -6,11 +6,13 @@
|
||||
#include "../../util/log.h"
|
||||
#include "attribute.h"
|
||||
#include <vector>
|
||||
#include <cstring>
|
||||
|
||||
template<typename PropList, typename Func>
|
||||
void ConvertProperties(const PropList* props, Func f)
|
||||
{
|
||||
LOG << "Registering " << props->count << " properties\n";
|
||||
|
||||
for (uint32_t i = 0; i < props->count; i++)
|
||||
{
|
||||
auto* prop = &props->list[i];
|
||||
@ -18,9 +20,24 @@ void ConvertProperties(const PropList* props, Func f)
|
||||
std::vector<std::string> strings;
|
||||
objc_property_attribute_t next;
|
||||
const char* pos = prop->attributes;
|
||||
bool hadName = false;
|
||||
|
||||
LOG << "Converting " << prop->attributes << std::endl;
|
||||
|
||||
while (nextAttribute(next, pos, strings))
|
||||
{
|
||||
// THIS IS VERY WRONG
|
||||
// But needed as a workaround for a serious mistake made in libobjc2's design!
|
||||
if (strcmp(next.name, "V") == 0)
|
||||
{
|
||||
next.value = prop->name;
|
||||
hadName = true;
|
||||
}
|
||||
attribs.push_back(next);
|
||||
}
|
||||
|
||||
if (!hadName)
|
||||
attribs.push_back(objc_property_attribute_t{"V", prop->name});
|
||||
|
||||
//attribs.clear();
|
||||
LOG << "\tProperty " << prop->name << " with " << attribs.size() << " attributes\n";
|
||||
|
8
src/libobjcdarwin/misc.mm
Normal file
8
src/libobjcdarwin/misc.mm
Normal file
@ -0,0 +1,8 @@
|
||||
#import <Foundation/NSException.h>
|
||||
#include "visibility.h"
|
||||
|
||||
DARLING_VISIBLE extern "C" void objc_enumerationMutation(id obj)
|
||||
{
|
||||
[NSException raise: NSGenericException format: @"Collection %@ was mutated while being enumerated", obj];
|
||||
}
|
||||
|
@ -1,74 +1,22 @@
|
||||
global __darwin_objc_msgSend
|
||||
global __darwin_objc_msgSend_noarg
|
||||
|
||||
extern objcdarwin_class_lookup
|
||||
extern objc_msg_lookup
|
||||
extern sel_get_any_uid
|
||||
extern objcdarwin_SaveRegisters
|
||||
extern objcdarwin_RestoreRegisters
|
||||
extern objcdarwin_sel_lookup
|
||||
extern objc_msgSend
|
||||
|
||||
%ifidn __OUTPUT_FORMAT__, elf64
|
||||
|
||||
BITS 64
|
||||
section text
|
||||
|
||||
__darwin_objc_msgSend:
|
||||
; Procedure:
|
||||
; 1) get the converted GNU class from an Apple class
|
||||
; 2) convert Apple selector to GNU
|
||||
; 3) run objc_msg_lookup
|
||||
; 4) jump to the pointer returned by objc_msg_lookup
|
||||
|
||||
call objcdarwin_SaveRegisters WRT ..plt
|
||||
call objcdarwin_class_lookup WRT ..plt
|
||||
mov [rsp], rax ; save the converted value
|
||||
|
||||
; move the second argument into the first argument
|
||||
mov rdi, [rsp+8]
|
||||
call objcdarwin_sel_lookup WRT ..plt
|
||||
; rax now has the GNU selector
|
||||
; move rax to the second argument
|
||||
mov rsi, rax
|
||||
mov [rsp+8], rax
|
||||
; restore the first argument
|
||||
mov rdi, [rsp]
|
||||
call objc_msg_lookup WRT ..plt
|
||||
|
||||
call objcdarwin_RestoreRegisters WRT ..plt
|
||||
jmp rax
|
||||
__darwin_objc_msgSend_noarg:
|
||||
jmp objc_msgSend WRT ..plt
|
||||
|
||||
%elifidn __OUTPUT_FORMAT__, elf
|
||||
|
||||
BITS 32
|
||||
section text
|
||||
|
||||
__darwin_objc_msgSend:
|
||||
;enter 8
|
||||
|
||||
mov ecx, [esp+4]
|
||||
push ecx ; arg for func call
|
||||
|
||||
call objcdarwin_class_lookup ;WRT ..plt
|
||||
|
||||
add esp, 4 ; remove argument
|
||||
mov [esp+4], eax ; change the class id
|
||||
|
||||
mov ecx, [esp+8] ; second argument
|
||||
push ecx
|
||||
|
||||
call objcdarwin_sel_lookup ;WRT ..plt
|
||||
|
||||
add esp, 4
|
||||
mov [esp+8], eax
|
||||
|
||||
push eax ; reuse the sel_get_any_uid retval
|
||||
mov eax, [esp+8]
|
||||
push eax ; class id
|
||||
|
||||
call objc_msg_lookup ;WRT ..plt
|
||||
add esp, 8
|
||||
|
||||
jmp eax
|
||||
__darwin_objc_msgSend_noarg:
|
||||
jmp objc_msgSend
|
||||
|
||||
%else
|
||||
|
||||
|
7
src/libobjcdarwin/visibility.h
Normal file
7
src/libobjcdarwin/visibility.h
Normal file
@ -0,0 +1,7 @@
|
||||
#ifndef VISIBILITY_H
|
||||
#define VISIBILITY_H
|
||||
|
||||
#define DARLING_VISIBLE __attribute__((visibility("default")))
|
||||
|
||||
#endif
|
||||
|
16
src/macbinary/CMakeLists.txt
Normal file
16
src/macbinary/CMakeLists.txt
Normal file
@ -0,0 +1,16 @@
|
||||
project(macbinary)
|
||||
|
||||
cmake_minimum_required(VERSION 2.4.0)
|
||||
if(COMMAND cmake_policy)
|
||||
cmake_policy(SET CMP0003 NEW)
|
||||
endif(COMMAND cmake_policy)
|
||||
|
||||
set(macbinary_SRCS
|
||||
macbinary.cpp
|
||||
)
|
||||
|
||||
add_executable(macbinary ${macbinary_SRCS})
|
||||
|
||||
install(TARGETS macbinary DESTINATION bin)
|
||||
|
||||
|
175
src/macbinary/macbinary.cpp
Normal file
175
src/macbinary/macbinary.cpp
Normal file
@ -0,0 +1,175 @@
|
||||
#define FOR_MACBINARY
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
#include "macbinary.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc != 3 && argc != 4)
|
||||
printHelp();
|
||||
|
||||
Command cmd = getCommand(argv[1]);
|
||||
std::ifstream file;
|
||||
|
||||
try
|
||||
{
|
||||
MacBinaryHeader hdr;
|
||||
|
||||
file.exceptions(std::ifstream::failbit | std::ifstream::badbit | std::ifstream::eofbit);
|
||||
file.open(argv[2], std::ios_base::binary | std::ios_base::in);
|
||||
|
||||
file.read((char*) &hdr, sizeof hdr);
|
||||
checkHeader(hdr);
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case PrintName:
|
||||
printName(file, hdr);
|
||||
break;
|
||||
case ExtractDF:
|
||||
extractDF(file, hdr, (argc == 4)? argv[3] : 0);
|
||||
break;
|
||||
case ExtractRF:
|
||||
extractRF(file, hdr, (argc == 4)? argv[3] : 0);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
catch (const std::ifstream::failure& e)
|
||||
{
|
||||
std::cerr << "Error reading input file: " << argv[2] << std::endl;
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
std::cerr << e.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
void printHelp()
|
||||
{
|
||||
std::cerr << "Usage: macbinary <command> <file> [outfile]\n\n"
|
||||
"Commands: \ndf - extract the data fork\n"
|
||||
"rf - extract the resource fork (will append '.rf' to the original file name)\n"
|
||||
"fn - print the original file name\n";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
Command getCommand(const char* cmd)
|
||||
{
|
||||
if (!strcmp(cmd, "df"))
|
||||
return ExtractDF;
|
||||
else if (!strcmp(cmd, "rf"))
|
||||
return ExtractRF;
|
||||
else if (!strcmp(cmd, "pn"))
|
||||
return PrintName;
|
||||
else
|
||||
{
|
||||
printHelp();
|
||||
return PrintName; // never reached
|
||||
}
|
||||
}
|
||||
|
||||
void printName(std::ifstream& file, const MacBinaryHeader& hdr)
|
||||
{
|
||||
std::cout << std::string(hdr.filename, hdr.filename_len) << std::endl;
|
||||
}
|
||||
|
||||
void extractRF(std::ifstream& file, const MacBinaryHeader& hdr, const char* outName)
|
||||
{
|
||||
if (!hdr.resource_len)
|
||||
std::cerr << "Warning: the resource fork is empty\n";
|
||||
|
||||
uint32_t extraLen = 0;
|
||||
std::string name;
|
||||
|
||||
if (uint32_t(hdr.signature) == 'mBIN')
|
||||
extraLen = hdr.sec_header_len;
|
||||
|
||||
extraLen += hdr.data_len;
|
||||
extraLen = (extraLen+127) / 128 * 128;
|
||||
|
||||
if (outName)
|
||||
name = outName;
|
||||
else
|
||||
name = std::string(hdr.filename, hdr.filename_len) + ".rf";
|
||||
|
||||
extract(file, 128 + extraLen, hdr.resource_len, name);
|
||||
}
|
||||
|
||||
void extractDF(std::ifstream& file, const MacBinaryHeader& hdr, const char* outName)
|
||||
{
|
||||
if (!hdr.data_len)
|
||||
std::cerr << "Warning: the data fork is empty\n";
|
||||
|
||||
uint32_t extraLen = 0;
|
||||
std::string name;
|
||||
|
||||
if (hdr.signature == 'mBIN')
|
||||
extraLen = hdr.sec_header_len;
|
||||
|
||||
if (outName)
|
||||
name = outName;
|
||||
else
|
||||
name = std::string(hdr.filename, hdr.filename_len);
|
||||
|
||||
extract(file, 128 + extraLen, hdr.data_len, name);
|
||||
}
|
||||
|
||||
void extract(std::ifstream& file, uint32_t offset, uint32_t len, std::string outName)
|
||||
{
|
||||
std::ofstream fout;
|
||||
std::ostream* out;
|
||||
uint32_t pos = 0;
|
||||
|
||||
std::cerr << "Extracting into " << outName << std::endl;
|
||||
|
||||
try
|
||||
{
|
||||
if (outName != "-")
|
||||
{
|
||||
fout.exceptions(std::ofstream::failbit | std::ofstream::badbit);
|
||||
fout.open(outName, std::ios_base::out | std::ios_base::binary);
|
||||
out = &fout;
|
||||
}
|
||||
else
|
||||
out = &std::cout;
|
||||
|
||||
file.seekg(offset);
|
||||
|
||||
while (pos < len)
|
||||
{
|
||||
char buffer[4096];
|
||||
uint32_t toRead = std::min<uint32_t>(len-pos, sizeof buffer);
|
||||
|
||||
file.read(buffer, toRead);
|
||||
out->write(buffer, toRead);
|
||||
|
||||
pos += toRead;
|
||||
}
|
||||
}
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
std::stringstream ss;
|
||||
ss << "Error writing output file: ";
|
||||
ss << outName;
|
||||
throw ss.str();
|
||||
}
|
||||
}
|
||||
|
||||
void checkHeader(const MacBinaryHeader& hdr)
|
||||
{
|
||||
if (hdr.signature == 'mBIN')
|
||||
return; // MacBinary III
|
||||
// TODO: crc // may be MacBinary II
|
||||
if (hdr.zero2 == 0)
|
||||
return; // may be MacBinary I
|
||||
}
|
||||
|
49
src/macbinary/macbinary.h
Normal file
49
src/macbinary/macbinary.h
Normal file
@ -0,0 +1,49 @@
|
||||
#ifndef MACBINARY_H
|
||||
#define MACBINARY_H
|
||||
#include <stdint.h>
|
||||
#include "../util/MSB.h"
|
||||
|
||||
// http://hackipedia.org/File%20formats/Containers/MacBinary%20(archive)/MacBinary%20III%20file%20format.html
|
||||
|
||||
#pragma pack(1)
|
||||
struct MacBinaryHeader
|
||||
{
|
||||
uint8_t old_ver;
|
||||
uint8_t filename_len;
|
||||
char filename[63];
|
||||
MSB<uint32_t> file_type, file_creator;
|
||||
uint8_t orig_finder_flags;
|
||||
uint8_t zero;
|
||||
MSB<uint16_t> vertical_pos, horizontal_pos;
|
||||
MSB<uint16_t> win_folder_id;
|
||||
uint8_t _protected, zero2;
|
||||
MSB<uint32_t> data_len, resource_len;
|
||||
MSB<uint32_t> created, last_modified;
|
||||
MSB<uint16_t> getinfo_comment_len;
|
||||
uint8_t finder_flags;
|
||||
MSB<uint32_t> signature; // 'mBIN'
|
||||
uint8_t script, ext_finder_flags, unused[8];
|
||||
MSB<uint32_t> total_len; // unused
|
||||
MSB<uint16_t> sec_header_len;
|
||||
uint8_t version_write, version_read;
|
||||
MSB<uint16_t> crc;
|
||||
char padding[2]; // pad to 128 bytes
|
||||
};
|
||||
#pragma pack()
|
||||
|
||||
static_assert(sizeof(MacBinaryHeader) == 128, "Invalid header length");
|
||||
|
||||
#ifdef FOR_MACBINARY
|
||||
enum Command { ExtractDF, ExtractRF, PrintName };
|
||||
|
||||
void printHelp();
|
||||
Command getCommand(const char* cmd);
|
||||
void printName(std::ifstream& file, const MacBinaryHeader& hdr);
|
||||
void extractRF(std::ifstream& file, const MacBinaryHeader& hdr, const char* outName);
|
||||
void extractDF(std::ifstream& file, const MacBinaryHeader& hdr, const char* outName);
|
||||
void extract(std::ifstream& file, uint32_t offset, uint32_t len, std::string outName);
|
||||
void checkHeader(const MacBinaryHeader& hdr);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -1,3 +1,22 @@
|
||||
/*
|
||||
* This file is part of Darling.
|
||||
*
|
||||
* Copyright (C) 2012 Lubos Dolezel
|
||||
*
|
||||
* Darling is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Darling is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
||||
* */
|
||||
|
||||
#include "MachO.h"
|
||||
#include "FatMachO.h"
|
||||
#include <iostream>
|
||||
|
24
src/util/MSB.h
Normal file
24
src/util/MSB.h
Normal file
@ -0,0 +1,24 @@
|
||||
#ifndef MSB_H
|
||||
#define MSB_H
|
||||
#ifndef _BSD_SOURCE
|
||||
# define _BSD_SOURCE
|
||||
#endif
|
||||
#include <endian.h>
|
||||
#include <stdint.h>
|
||||
|
||||
template<typename T>
|
||||
class MSB
|
||||
{
|
||||
protected:
|
||||
static uint16_t convert(uint16_t v) { return be16toh(v); }
|
||||
static uint32_t convert(uint32_t v) { return be32toh(v); }
|
||||
static uint64_t convert(uint64_t v) { return be64toh(v); }
|
||||
|
||||
public:
|
||||
operator T() const { return convert(m_data); }
|
||||
T msb() const { return m_data; }
|
||||
private:
|
||||
T m_data;
|
||||
};
|
||||
|
||||
#endif
|
@ -3,20 +3,17 @@
|
||||
#import <objc/runtime.h>
|
||||
|
||||
@interface helloclass : NSObject {
|
||||
@private int var;
|
||||
@private int varName;
|
||||
}
|
||||
@property (readwrite,assign) int var;
|
||||
@property (readwrite,assign) int propName;
|
||||
@end
|
||||
|
||||
@implementation helloclass
|
||||
@synthesize var;
|
||||
@synthesize propName = varName;
|
||||
@end
|
||||
|
||||
int main()
|
||||
{
|
||||
helloclass* c = [helloclass new];
|
||||
c.var = 5;
|
||||
|
||||
unsigned int outCount, i;
|
||||
objc_property_t *properties = class_copyPropertyList([helloclass class], &outCount);
|
||||
printf("%u properties\n", outCount);
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
set -e
|
||||
|
||||
cfile=/tmp/sizeof.$$.c
|
||||
cfile=/tmp/sizeof.$$.cpp
|
||||
include="$1"
|
||||
struct="$2"
|
||||
|
||||
@ -18,7 +18,7 @@ int main()
|
||||
|
||||
END
|
||||
|
||||
gcc -w $cfile -o $cfile.bin
|
||||
g++ -w $cfile -o $cfile.bin
|
||||
$cfile.bin
|
||||
|
||||
rm $cfile*
|
||||
|
Loading…
Reference in New Issue
Block a user