Initial Sandboxie Open Source release from Sophos

This commit is contained in:
DavidXanatos 2020-04-09 11:34:30 +02:00
parent 345bb57d3b
commit f22ec96fb1
542 changed files with 226881 additions and 0 deletions

621
Sandboxie/COPYING Normal file
View File

@ -0,0 +1,621 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc. <https://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

55
Sandboxie/ReadMe.txt Normal file
View File

@ -0,0 +1,55 @@
SANDBOXIE BUILD INSTRUCTIONS
Please note: there is another ReadMe.txt in the \install\ folder that explains how to create the Sandboxie installers.
1) Sandboxie builds under MS Visual Studio 2015.
2) Install the MS Windows Device Driver Kit (DDK) 7.1.0.
https://www.microsoft.com/en-us/download/details.aspx?id=11800
In the DDK setup, all you need to check is "Build Environments"
3) The VS Solution File, Sandbox.sln, is in the source code root. Open this SLN in Visual Studio.
Source Projects (in aplhabetical order)
Note: the core of Sandboxie are the driver, SbieDrv, the service, SbieSvc, and the injection DLL, SbieDll. Study these projects first.
Common (\apps\common). This builds common.lib which is used by the Control and Start projects. It contains some common GUI objects.
KmdUtil (\install\kmdutil). Builds KmdUtil.exe which is used during the installtion process. E.g. to start/stop the Sbie driver (SbieDrv.sys).
LowLevel (\core\low). Creates LowLevel.dll which is used in code injection. LowLevel.dll is embeded into SbieSvc.exe as a resource (see core\svc\lowlevel.rc for more information).
Parse (\msgs). Creates the Sbie messages files.
SandboxBITS (apps\com\BITS). Creates SandboxieBITS.exe (Background Intelligent Transfer Service)
SandboxCrypto (apps\com\Crypto) Creates SandboxieCrypto.exe
SandboxieInstall (\install\release). Creates the combined x64/x86 installer SandboxieInstall.exe by combining the x64 & x86 installer binaries into a RC file.
NOTE: SandboxieInstall is not built during the normal SLN build. It must be built manually after the x64 & x86 installers are completed.
SandboxRpcSs (\apps\com\RpcSs) Creates SandboxieRpcSs.exe. Sbie's wrapper for the Remote Procedure Call Sub-System).
SandboxWUAU (\apps\com\WUAU) Creates SandboxieWUAU.exe. Sbie's wrapper for the Windows Automatic Update Service (WUAUSERV).
SbieControl (\apps\control). Builds SbieCtrl.exe. This is the Sandboxie Control app that displays real-time sandboxed application activity.
SbieIni (\apps\ini). Creates SbieIni.exe. A utility for querying and updating the sandboxie.ini configuration file.
SboxDcomLaunch (\apps\com\DcomLaunch). Creates SandboxieDcomLaunch.exe.
SboxDll (\core\dll). Creates the Sbie injection DLL. This DLL injects into every process running in the sandbox.
SboxDrv (\core\drv). Creates the Sbie kernel-mode driver.
SboxHostDll (\SboxHostDll). Builds the Sbie host injection DLL. This DLL is injected into host processes that must be redirected into the sandbox.
Currently, the only app this is used for is MS Office. SboxHostDll.dll is injected into OfficeClickToRun.exe.
SboxMsg (\msgs). Creates SboxMsg.dll which contains the Sbie user messages in various languages.
SboxSvc (\core\svc). Creates the Sbie service.
Start (\apps\start). Creates start.exe which is used to start processes in the sandbox.

243
Sandboxie/Sandbox.sln Normal file
View File

@ -0,0 +1,243 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SboxSvc", "core\svc\SboxSvc.vcxproj", "{2D3DBCAE-883E-54A6-F8F6-11228D989033}"
ProjectSection(ProjectDependencies) = postProject
{8E0EAA5B-6F5B-E0E2-338A-453EF2B548E4} = {8E0EAA5B-6F5B-E0E2-338A-453EF2B548E4}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Start", "apps\start\Start.vcxproj", "{8B9E1B9D-FB3C-3009-9196-4315871BCD73}"
ProjectSection(ProjectDependencies) = postProject
{8E0EAA5B-6F5B-E0E2-338A-453EF2B548E4} = {8E0EAA5B-6F5B-E0E2-338A-453EF2B548E4}
{63B0DDD2-5E3B-EF38-F711-9652D2EB73B3} = {63B0DDD2-5E3B-EF38-F711-9652D2EB73B3}
{255002EC-9FC7-422E-B497-BE2CC5012B2D} = {255002EC-9FC7-422E-B497-BE2CC5012B2D}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Common", "apps\common\Common.vcxproj", "{67579365-ED6A-C1E4-E0A3-4A7C9F14072D}"
ProjectSection(ProjectDependencies) = postProject
{63B0DDD2-5E3B-EF38-F711-9652D2EB73B3} = {63B0DDD2-5E3B-EF38-F711-9652D2EB73B3}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SboxMsg", "msgs\SboxMsg.vcxproj", "{63B0DDD2-5E3B-EF38-F711-9652D2EB73B3}"
ProjectSection(ProjectDependencies) = postProject
{7BA01954-12F1-4CEE-BA97-FAD3250D9776} = {7BA01954-12F1-4CEE-BA97-FAD3250D9776}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SandboxBITS", "apps\com\BITS\SandboxBITS.vcxproj", "{E40CC819-6990-DA28-3E1F-6708BC98E37B}"
ProjectSection(ProjectDependencies) = postProject
{8E0EAA5B-6F5B-E0E2-338A-453EF2B548E4} = {8E0EAA5B-6F5B-E0E2-338A-453EF2B548E4}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SboxDll", "core\dll\SboxDll.vcxproj", "{8E0EAA5B-6F5B-E0E2-338A-453EF2B548E4}"
ProjectSection(ProjectDependencies) = postProject
{63B0DDD2-5E3B-EF38-F711-9652D2EB73B3} = {63B0DDD2-5E3B-EF38-F711-9652D2EB73B3}
{255002EC-9FC7-422E-B497-BE2CC5012B2D} = {255002EC-9FC7-422E-B497-BE2CC5012B2D}
{67579365-ED6A-C1E4-E0A3-4A7C9F14072D} = {67579365-ED6A-C1E4-E0A3-4A7C9F14072D}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SandboxCrypto", "apps\com\Crypto\SandboxCrypto.vcxproj", "{41453A79-CA9B-ABCA-981C-5242AFC72DDF}"
ProjectSection(ProjectDependencies) = postProject
{8E0EAA5B-6F5B-E0E2-338A-453EF2B548E4} = {8E0EAA5B-6F5B-E0E2-338A-453EF2B548E4}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SandboxRpcSs", "apps\com\RpcSs\SandboxRpcSs.vcxproj", "{5410C534-4858-C748-86AD-0567A2451FDE}"
ProjectSection(ProjectDependencies) = postProject
{8E0EAA5B-6F5B-E0E2-338A-453EF2B548E4} = {8E0EAA5B-6F5B-E0E2-338A-453EF2B548E4}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SboxDcomLaunch", "apps\com\DcomLaunch\SboxDcomLaunch.vcxproj", "{8055A629-631E-84F5-8F3C-1908F264C81D}"
ProjectSection(ProjectDependencies) = postProject
{8E0EAA5B-6F5B-E0E2-338A-453EF2B548E4} = {8E0EAA5B-6F5B-E0E2-338A-453EF2B548E4}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SandboxWUAU", "apps\com\WUAU\SandboxWUAU.vcxproj", "{42DB5510-0268-4655-B483-B9D6E4E48D62}"
ProjectSection(ProjectDependencies) = postProject
{8E0EAA5B-6F5B-E0E2-338A-453EF2B548E4} = {8E0EAA5B-6F5B-E0E2-338A-453EF2B548E4}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LowLevel", "core\low\LowLevel.vcxproj", "{255002EC-9FC7-422E-B497-BE2CC5012B2D}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SboxDrv", "core\drv\SboxDrv.vcxproj", "{4019C5EB-8D1E-40E4-B7D1-5601B4B27288}"
ProjectSection(ProjectDependencies) = postProject
{63B0DDD2-5E3B-EF38-F711-9652D2EB73B3} = {63B0DDD2-5E3B-EF38-F711-9652D2EB73B3}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SbieControl", "apps\control\Control.vcxproj", "{D16E291A-1F8A-4B19-AE07-0AF8CB7CCBD0}"
ProjectSection(ProjectDependencies) = postProject
{8E0EAA5B-6F5B-E0E2-338A-453EF2B548E4} = {8E0EAA5B-6F5B-E0E2-338A-453EF2B548E4}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "KmdUtil", "install\kmdutil\KmdUtil.vcxproj", "{0BF4988E-2325-4426-8CDC-BD221E4FB68C}"
ProjectSection(ProjectDependencies) = postProject
{8E0EAA5B-6F5B-E0E2-338A-453EF2B548E4} = {8E0EAA5B-6F5B-E0E2-338A-453EF2B548E4}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SbieIni", "apps\ini\SbieIni.vcxproj", "{B8D7002B-0468-44E7-93A7-94327A5D7C7A}"
ProjectSection(ProjectDependencies) = postProject
{8E0EAA5B-6F5B-E0E2-338A-453EF2B548E4} = {8E0EAA5B-6F5B-E0E2-338A-453EF2B548E4}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SandboxieInstall", "install\release\SandboxieInstall.vcxproj", "{08A656D9-CDD0-4C9F-AB3F-D98F8E5B6EC6}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Parse", "msgs\Parse.vcxproj", "{7BA01954-12F1-4CEE-BA97-FAD3250D9776}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SboxHostDll", "SboxHostDll\SboxHostDll.vcxproj", "{3A42A9F3-E0C7-4633-9570-381802D6647D}"
ProjectSection(ProjectDependencies) = postProject
{8E0EAA5B-6F5B-E0E2-338A-453EF2B548E4} = {8E0EAA5B-6F5B-E0E2-338A-453EF2B548E4}
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
SbieDebug|Win32 = SbieDebug|Win32
SbieDebug|x64 = SbieDebug|x64
SbieRelease|Win32 = SbieRelease|Win32
SbieRelease|x64 = SbieRelease|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2D3DBCAE-883E-54A6-F8F6-11228D989033}.SbieDebug|Win32.ActiveCfg = SbieDebug|Win32
{2D3DBCAE-883E-54A6-F8F6-11228D989033}.SbieDebug|Win32.Build.0 = SbieDebug|Win32
{2D3DBCAE-883E-54A6-F8F6-11228D989033}.SbieDebug|x64.ActiveCfg = SbieDebug|x64
{2D3DBCAE-883E-54A6-F8F6-11228D989033}.SbieDebug|x64.Build.0 = SbieDebug|x64
{2D3DBCAE-883E-54A6-F8F6-11228D989033}.SbieRelease|Win32.ActiveCfg = SbieRelease|Win32
{2D3DBCAE-883E-54A6-F8F6-11228D989033}.SbieRelease|Win32.Build.0 = SbieRelease|Win32
{2D3DBCAE-883E-54A6-F8F6-11228D989033}.SbieRelease|x64.ActiveCfg = SbieRelease|x64
{2D3DBCAE-883E-54A6-F8F6-11228D989033}.SbieRelease|x64.Build.0 = SbieRelease|x64
{8B9E1B9D-FB3C-3009-9196-4315871BCD73}.SbieDebug|Win32.ActiveCfg = SbieDebug|Win32
{8B9E1B9D-FB3C-3009-9196-4315871BCD73}.SbieDebug|Win32.Build.0 = SbieDebug|Win32
{8B9E1B9D-FB3C-3009-9196-4315871BCD73}.SbieDebug|x64.ActiveCfg = SbieDebug|x64
{8B9E1B9D-FB3C-3009-9196-4315871BCD73}.SbieDebug|x64.Build.0 = SbieDebug|x64
{8B9E1B9D-FB3C-3009-9196-4315871BCD73}.SbieRelease|Win32.ActiveCfg = SbieRelease|Win32
{8B9E1B9D-FB3C-3009-9196-4315871BCD73}.SbieRelease|Win32.Build.0 = SbieRelease|Win32
{8B9E1B9D-FB3C-3009-9196-4315871BCD73}.SbieRelease|x64.ActiveCfg = SbieRelease|x64
{8B9E1B9D-FB3C-3009-9196-4315871BCD73}.SbieRelease|x64.Build.0 = SbieRelease|x64
{67579365-ED6A-C1E4-E0A3-4A7C9F14072D}.SbieDebug|Win32.ActiveCfg = SbieDebug|Win32
{67579365-ED6A-C1E4-E0A3-4A7C9F14072D}.SbieDebug|Win32.Build.0 = SbieDebug|Win32
{67579365-ED6A-C1E4-E0A3-4A7C9F14072D}.SbieDebug|x64.ActiveCfg = SbieDebug|x64
{67579365-ED6A-C1E4-E0A3-4A7C9F14072D}.SbieDebug|x64.Build.0 = SbieDebug|x64
{67579365-ED6A-C1E4-E0A3-4A7C9F14072D}.SbieRelease|Win32.ActiveCfg = SbieRelease|Win32
{67579365-ED6A-C1E4-E0A3-4A7C9F14072D}.SbieRelease|Win32.Build.0 = SbieRelease|Win32
{67579365-ED6A-C1E4-E0A3-4A7C9F14072D}.SbieRelease|x64.ActiveCfg = SbieRelease|x64
{67579365-ED6A-C1E4-E0A3-4A7C9F14072D}.SbieRelease|x64.Build.0 = SbieRelease|x64
{63B0DDD2-5E3B-EF38-F711-9652D2EB73B3}.SbieDebug|Win32.ActiveCfg = SbieRelease|Win32
{63B0DDD2-5E3B-EF38-F711-9652D2EB73B3}.SbieDebug|Win32.Build.0 = SbieRelease|Win32
{63B0DDD2-5E3B-EF38-F711-9652D2EB73B3}.SbieDebug|x64.ActiveCfg = SbieRelease|x64
{63B0DDD2-5E3B-EF38-F711-9652D2EB73B3}.SbieDebug|x64.Build.0 = SbieRelease|x64
{63B0DDD2-5E3B-EF38-F711-9652D2EB73B3}.SbieRelease|Win32.ActiveCfg = SbieRelease|Win32
{63B0DDD2-5E3B-EF38-F711-9652D2EB73B3}.SbieRelease|Win32.Build.0 = SbieRelease|Win32
{63B0DDD2-5E3B-EF38-F711-9652D2EB73B3}.SbieRelease|x64.ActiveCfg = SbieRelease|x64
{63B0DDD2-5E3B-EF38-F711-9652D2EB73B3}.SbieRelease|x64.Build.0 = SbieRelease|x64
{E40CC819-6990-DA28-3E1F-6708BC98E37B}.SbieDebug|Win32.ActiveCfg = SbieDebug|Win32
{E40CC819-6990-DA28-3E1F-6708BC98E37B}.SbieDebug|Win32.Build.0 = SbieDebug|Win32
{E40CC819-6990-DA28-3E1F-6708BC98E37B}.SbieDebug|x64.ActiveCfg = SbieDebug|x64
{E40CC819-6990-DA28-3E1F-6708BC98E37B}.SbieDebug|x64.Build.0 = SbieDebug|x64
{E40CC819-6990-DA28-3E1F-6708BC98E37B}.SbieRelease|Win32.ActiveCfg = SbieRelease|Win32
{E40CC819-6990-DA28-3E1F-6708BC98E37B}.SbieRelease|Win32.Build.0 = SbieRelease|Win32
{E40CC819-6990-DA28-3E1F-6708BC98E37B}.SbieRelease|x64.ActiveCfg = SbieRelease|x64
{E40CC819-6990-DA28-3E1F-6708BC98E37B}.SbieRelease|x64.Build.0 = SbieRelease|x64
{8E0EAA5B-6F5B-E0E2-338A-453EF2B548E4}.SbieDebug|Win32.ActiveCfg = SbieDebug|Win32
{8E0EAA5B-6F5B-E0E2-338A-453EF2B548E4}.SbieDebug|Win32.Build.0 = SbieDebug|Win32
{8E0EAA5B-6F5B-E0E2-338A-453EF2B548E4}.SbieDebug|x64.ActiveCfg = SbieDebug|x64
{8E0EAA5B-6F5B-E0E2-338A-453EF2B548E4}.SbieDebug|x64.Build.0 = SbieDebug|x64
{8E0EAA5B-6F5B-E0E2-338A-453EF2B548E4}.SbieRelease|Win32.ActiveCfg = SbieRelease|Win32
{8E0EAA5B-6F5B-E0E2-338A-453EF2B548E4}.SbieRelease|Win32.Build.0 = SbieRelease|Win32
{8E0EAA5B-6F5B-E0E2-338A-453EF2B548E4}.SbieRelease|x64.ActiveCfg = SbieRelease|x64
{8E0EAA5B-6F5B-E0E2-338A-453EF2B548E4}.SbieRelease|x64.Build.0 = SbieRelease|x64
{41453A79-CA9B-ABCA-981C-5242AFC72DDF}.SbieDebug|Win32.ActiveCfg = SbieDebug|Win32
{41453A79-CA9B-ABCA-981C-5242AFC72DDF}.SbieDebug|Win32.Build.0 = SbieDebug|Win32
{41453A79-CA9B-ABCA-981C-5242AFC72DDF}.SbieDebug|x64.ActiveCfg = SbieDebug|x64
{41453A79-CA9B-ABCA-981C-5242AFC72DDF}.SbieDebug|x64.Build.0 = SbieDebug|x64
{41453A79-CA9B-ABCA-981C-5242AFC72DDF}.SbieRelease|Win32.ActiveCfg = SbieRelease|Win32
{41453A79-CA9B-ABCA-981C-5242AFC72DDF}.SbieRelease|Win32.Build.0 = SbieRelease|Win32
{41453A79-CA9B-ABCA-981C-5242AFC72DDF}.SbieRelease|x64.ActiveCfg = SbieRelease|x64
{41453A79-CA9B-ABCA-981C-5242AFC72DDF}.SbieRelease|x64.Build.0 = SbieRelease|x64
{5410C534-4858-C748-86AD-0567A2451FDE}.SbieDebug|Win32.ActiveCfg = SbieDebug|Win32
{5410C534-4858-C748-86AD-0567A2451FDE}.SbieDebug|Win32.Build.0 = SbieDebug|Win32
{5410C534-4858-C748-86AD-0567A2451FDE}.SbieDebug|x64.ActiveCfg = SbieDebug|x64
{5410C534-4858-C748-86AD-0567A2451FDE}.SbieDebug|x64.Build.0 = SbieDebug|x64
{5410C534-4858-C748-86AD-0567A2451FDE}.SbieRelease|Win32.ActiveCfg = SbieRelease|Win32
{5410C534-4858-C748-86AD-0567A2451FDE}.SbieRelease|Win32.Build.0 = SbieRelease|Win32
{5410C534-4858-C748-86AD-0567A2451FDE}.SbieRelease|x64.ActiveCfg = SbieRelease|x64
{5410C534-4858-C748-86AD-0567A2451FDE}.SbieRelease|x64.Build.0 = SbieRelease|x64
{8055A629-631E-84F5-8F3C-1908F264C81D}.SbieDebug|Win32.ActiveCfg = SbieDebug|Win32
{8055A629-631E-84F5-8F3C-1908F264C81D}.SbieDebug|Win32.Build.0 = SbieDebug|Win32
{8055A629-631E-84F5-8F3C-1908F264C81D}.SbieDebug|x64.ActiveCfg = SbieDebug|x64
{8055A629-631E-84F5-8F3C-1908F264C81D}.SbieDebug|x64.Build.0 = SbieDebug|x64
{8055A629-631E-84F5-8F3C-1908F264C81D}.SbieRelease|Win32.ActiveCfg = SbieRelease|Win32
{8055A629-631E-84F5-8F3C-1908F264C81D}.SbieRelease|Win32.Build.0 = SbieRelease|Win32
{8055A629-631E-84F5-8F3C-1908F264C81D}.SbieRelease|x64.ActiveCfg = SbieRelease|x64
{8055A629-631E-84F5-8F3C-1908F264C81D}.SbieRelease|x64.Build.0 = SbieRelease|x64
{42DB5510-0268-4655-B483-B9D6E4E48D62}.SbieDebug|Win32.ActiveCfg = SbieDebug|Win32
{42DB5510-0268-4655-B483-B9D6E4E48D62}.SbieDebug|Win32.Build.0 = SbieDebug|Win32
{42DB5510-0268-4655-B483-B9D6E4E48D62}.SbieDebug|x64.ActiveCfg = SbieDebug|x64
{42DB5510-0268-4655-B483-B9D6E4E48D62}.SbieDebug|x64.Build.0 = SbieDebug|x64
{42DB5510-0268-4655-B483-B9D6E4E48D62}.SbieRelease|Win32.ActiveCfg = SbieRelease|Win32
{42DB5510-0268-4655-B483-B9D6E4E48D62}.SbieRelease|Win32.Build.0 = SbieRelease|Win32
{42DB5510-0268-4655-B483-B9D6E4E48D62}.SbieRelease|x64.ActiveCfg = SbieRelease|x64
{42DB5510-0268-4655-B483-B9D6E4E48D62}.SbieRelease|x64.Build.0 = SbieRelease|x64
{255002EC-9FC7-422E-B497-BE2CC5012B2D}.SbieDebug|Win32.ActiveCfg = SbieRelease|Win32
{255002EC-9FC7-422E-B497-BE2CC5012B2D}.SbieDebug|Win32.Build.0 = SbieRelease|Win32
{255002EC-9FC7-422E-B497-BE2CC5012B2D}.SbieDebug|x64.ActiveCfg = SbieRelease|x64
{255002EC-9FC7-422E-B497-BE2CC5012B2D}.SbieDebug|x64.Build.0 = SbieRelease|x64
{255002EC-9FC7-422E-B497-BE2CC5012B2D}.SbieRelease|Win32.ActiveCfg = SbieRelease|Win32
{255002EC-9FC7-422E-B497-BE2CC5012B2D}.SbieRelease|Win32.Build.0 = SbieRelease|Win32
{255002EC-9FC7-422E-B497-BE2CC5012B2D}.SbieRelease|x64.ActiveCfg = SbieRelease|x64
{255002EC-9FC7-422E-B497-BE2CC5012B2D}.SbieRelease|x64.Build.0 = SbieRelease|x64
{4019C5EB-8D1E-40E4-B7D1-5601B4B27288}.SbieDebug|Win32.ActiveCfg = SbieDebug|Win32
{4019C5EB-8D1E-40E4-B7D1-5601B4B27288}.SbieDebug|Win32.Build.0 = SbieDebug|Win32
{4019C5EB-8D1E-40E4-B7D1-5601B4B27288}.SbieDebug|x64.ActiveCfg = SbieDebug|x64
{4019C5EB-8D1E-40E4-B7D1-5601B4B27288}.SbieDebug|x64.Build.0 = SbieDebug|x64
{4019C5EB-8D1E-40E4-B7D1-5601B4B27288}.SbieRelease|Win32.ActiveCfg = SbieRelease|Win32
{4019C5EB-8D1E-40E4-B7D1-5601B4B27288}.SbieRelease|Win32.Build.0 = SbieRelease|Win32
{4019C5EB-8D1E-40E4-B7D1-5601B4B27288}.SbieRelease|x64.ActiveCfg = SbieRelease|x64
{4019C5EB-8D1E-40E4-B7D1-5601B4B27288}.SbieRelease|x64.Build.0 = SbieRelease|x64
{D16E291A-1F8A-4B19-AE07-0AF8CB7CCBD0}.SbieDebug|Win32.ActiveCfg = SbieDebug|Win32
{D16E291A-1F8A-4B19-AE07-0AF8CB7CCBD0}.SbieDebug|Win32.Build.0 = SbieDebug|Win32
{D16E291A-1F8A-4B19-AE07-0AF8CB7CCBD0}.SbieDebug|x64.ActiveCfg = SbieDebug|x64
{D16E291A-1F8A-4B19-AE07-0AF8CB7CCBD0}.SbieDebug|x64.Build.0 = SbieDebug|x64
{D16E291A-1F8A-4B19-AE07-0AF8CB7CCBD0}.SbieRelease|Win32.ActiveCfg = SbieRelease|Win32
{D16E291A-1F8A-4B19-AE07-0AF8CB7CCBD0}.SbieRelease|Win32.Build.0 = SbieRelease|Win32
{D16E291A-1F8A-4B19-AE07-0AF8CB7CCBD0}.SbieRelease|x64.ActiveCfg = SbieRelease|x64
{D16E291A-1F8A-4B19-AE07-0AF8CB7CCBD0}.SbieRelease|x64.Build.0 = SbieRelease|x64
{0BF4988E-2325-4426-8CDC-BD221E4FB68C}.SbieDebug|Win32.ActiveCfg = SbieDebug|Win32
{0BF4988E-2325-4426-8CDC-BD221E4FB68C}.SbieDebug|Win32.Build.0 = SbieDebug|Win32
{0BF4988E-2325-4426-8CDC-BD221E4FB68C}.SbieDebug|x64.ActiveCfg = SbieDebug|x64
{0BF4988E-2325-4426-8CDC-BD221E4FB68C}.SbieDebug|x64.Build.0 = SbieDebug|x64
{0BF4988E-2325-4426-8CDC-BD221E4FB68C}.SbieRelease|Win32.ActiveCfg = SbieRelease|Win32
{0BF4988E-2325-4426-8CDC-BD221E4FB68C}.SbieRelease|Win32.Build.0 = SbieRelease|Win32
{0BF4988E-2325-4426-8CDC-BD221E4FB68C}.SbieRelease|x64.ActiveCfg = SbieRelease|x64
{0BF4988E-2325-4426-8CDC-BD221E4FB68C}.SbieRelease|x64.Build.0 = SbieRelease|x64
{B8D7002B-0468-44E7-93A7-94327A5D7C7A}.SbieDebug|Win32.ActiveCfg = SbieDebug|Win32
{B8D7002B-0468-44E7-93A7-94327A5D7C7A}.SbieDebug|Win32.Build.0 = SbieDebug|Win32
{B8D7002B-0468-44E7-93A7-94327A5D7C7A}.SbieDebug|x64.ActiveCfg = SbieDebug|x64
{B8D7002B-0468-44E7-93A7-94327A5D7C7A}.SbieDebug|x64.Build.0 = SbieDebug|x64
{B8D7002B-0468-44E7-93A7-94327A5D7C7A}.SbieRelease|Win32.ActiveCfg = SbieRelease|Win32
{B8D7002B-0468-44E7-93A7-94327A5D7C7A}.SbieRelease|Win32.Build.0 = SbieRelease|Win32
{B8D7002B-0468-44E7-93A7-94327A5D7C7A}.SbieRelease|x64.ActiveCfg = SbieRelease|x64
{B8D7002B-0468-44E7-93A7-94327A5D7C7A}.SbieRelease|x64.Build.0 = SbieRelease|x64
{08A656D9-CDD0-4C9F-AB3F-D98F8E5B6EC6}.SbieDebug|Win32.ActiveCfg = SbieRelease|Win32
{08A656D9-CDD0-4C9F-AB3F-D98F8E5B6EC6}.SbieDebug|Win32.Build.0 = SbieRelease|Win32
{08A656D9-CDD0-4C9F-AB3F-D98F8E5B6EC6}.SbieDebug|x64.ActiveCfg = SbieRelease|Win32
{08A656D9-CDD0-4C9F-AB3F-D98F8E5B6EC6}.SbieRelease|Win32.ActiveCfg = SbieRelease|Win32
{08A656D9-CDD0-4C9F-AB3F-D98F8E5B6EC6}.SbieRelease|x64.ActiveCfg = SbieRelease|Win32
{7BA01954-12F1-4CEE-BA97-FAD3250D9776}.SbieDebug|Win32.ActiveCfg = SbieRelease|Win32
{7BA01954-12F1-4CEE-BA97-FAD3250D9776}.SbieDebug|Win32.Build.0 = SbieRelease|Win32
{7BA01954-12F1-4CEE-BA97-FAD3250D9776}.SbieDebug|x64.ActiveCfg = SbieRelease|Win32
{7BA01954-12F1-4CEE-BA97-FAD3250D9776}.SbieRelease|Win32.ActiveCfg = SbieRelease|Win32
{7BA01954-12F1-4CEE-BA97-FAD3250D9776}.SbieRelease|Win32.Build.0 = SbieRelease|Win32
{7BA01954-12F1-4CEE-BA97-FAD3250D9776}.SbieRelease|x64.ActiveCfg = SbieRelease|Win32
{7BA01954-12F1-4CEE-BA97-FAD3250D9776}.SbieRelease|x64.Build.0 = SbieRelease|Win32
{3A42A9F3-E0C7-4633-9570-381802D6647D}.SbieDebug|Win32.ActiveCfg = SbieDebug|Win32
{3A42A9F3-E0C7-4633-9570-381802D6647D}.SbieDebug|Win32.Build.0 = SbieDebug|Win32
{3A42A9F3-E0C7-4633-9570-381802D6647D}.SbieDebug|x64.ActiveCfg = SbieDebug|x64
{3A42A9F3-E0C7-4633-9570-381802D6647D}.SbieDebug|x64.Build.0 = SbieDebug|x64
{3A42A9F3-E0C7-4633-9570-381802D6647D}.SbieRelease|Win32.ActiveCfg = SbieRelease|Win32
{3A42A9F3-E0C7-4633-9570-381802D6647D}.SbieRelease|Win32.Build.0 = SbieRelease|Win32
{3A42A9F3-E0C7-4633-9570-381802D6647D}.SbieRelease|x64.ActiveCfg = SbieRelease|x64
{3A42A9F3-E0C7-4633-9570-381802D6647D}.SbieRelease|x64.Build.0 = SbieRelease|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

42
Sandboxie/Sandbox32.props Normal file
View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros">
<WDKPATH>\WinDDK\7600.16385.1</WDKPATH>
</PropertyGroup>
<PropertyGroup>
<IncludePath>..\;..\..\;..\..\..\;$(VCInstallDir)include;$(WindowsSDK_IncludePath);$(VCInstallDir)atlmfc\include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup>
<LibraryPath>$(VCInstallDir)lib;$(SolutionDir)Bin\$(PlatformName)\$(Configuration)\;$(WindowsSdkDir)lib;$(LibraryPath)</LibraryPath>
<OutDir>$(SolutionDir)Bin\$(PlatformName)\$(Configuration)\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<PreprocessorDefinitions>_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;VISUAL_STUDIO_BUILD;_X86_;UNICODE;WINVER=0x0502;_WIN32_WINNT=0x0502;WIN32=100;_WIN32_IE=0x0603;WIN32_LEAN_AND_MEAN=1;WINNT=1;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BufferSecurityCheck>false</BufferSecurityCheck>
<CallingConvention>StdCall</CallingConvention>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
<TreatWarningAsError>true</TreatWarningAsError>
<ExceptionHandling>false</ExceptionHandling>
<DisableSpecificWarnings>4267;4312;4996;4133;4577;4091;4200;4047;4024</DisableSpecificWarnings>
<WarningLevel>Level3</WarningLevel>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions></PreprocessorDefinitions>
</ResourceCompile>
<Link>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<BuildMacro Include="WDKPATH">
<Value>$(WDKPATH)</Value>
<EnvironmentVariable>true</EnvironmentVariable>
</BuildMacro>
</ItemGroup>
</Project>

45
Sandboxie/Sandbox64.props Normal file
View File

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ImportGroup Label="PropertySheets" />
<PropertyGroup Label="UserMacros">
<WDKPATH>\WinDDK\7600.16385.1</WDKPATH>
</PropertyGroup>
<PropertyGroup>
<IncludePath>..\;..\..\;..\..\..\;$(VCInstallDir)include;$(WindowsSDK_IncludePath);$(VCInstallDir)atlmfc\include;$(IncludePath)</IncludePath>
</PropertyGroup>
<PropertyGroup>
<LibraryPath>$(VCInstallDir)lib\amd64;$(SolutionDir)Bin\$(PlatformName)\$(Configuration)\;$(WindowsSdkDir)lib\x64;$(LibraryPath)</LibraryPath>
<OutDir>$(SolutionDir)Bin\$(PlatformName)\$(Configuration)\</OutDir>
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<PreprocessorDefinitions>_CRT_NON_CONFORMING_SWPRINTFS;_CRT_SECURE_NO_WARNINGS;VISUAL_STUDIO_BUILD;_WIN64;_AMD64_;UNICODE;WINVER=0x0502;_WIN32_WINNT=0x0502;WIN32=100;_WIN32_IE=0x0603;WIN32_LEAN_AND_MEAN=1;WINNT=1;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<BufferSecurityCheck>false</BufferSecurityCheck>
<CallingConvention>StdCall</CallingConvention>
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
<DisableSpecificWarnings>4267;4312;4996;4133;4577;4091;4200</DisableSpecificWarnings>
<TreatWarningAsError>true</TreatWarningAsError>
<UndefinePreprocessorDefinitions>
</UndefinePreprocessorDefinitions>
<ExceptionHandling>false</ExceptionHandling>
<WarningLevel>Level3</WarningLevel>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
</ClCompile>
<ResourceCompile>
<PreprocessorDefinitions></PreprocessorDefinitions>
</ResourceCompile>
<Link>
<AdditionalDependencies>%(AdditionalDependencies)</AdditionalDependencies>
<ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
<SubSystem>Windows</SubSystem>
<OptimizeReferences>true</OptimizeReferences>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<BuildMacro Include="WDKPATH">
<Value>$(WDKPATH)</Value>
<EnvironmentVariable>true</EnvironmentVariable>
</BuildMacro>
</ItemGroup>
</Project>

58
Sandboxie/SandboxDrv.sln Normal file
View File

@ -0,0 +1,58 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SboxDrv", "core\drv\SboxDrv.vcxproj", "{4019C5EB-8D1E-40E4-B7D1-5601B4B27288}"
ProjectSection(ProjectDependencies) = postProject
{63B0DDD2-5E3B-EF38-F711-9652D2EB73B3} = {63B0DDD2-5E3B-EF38-F711-9652D2EB73B3}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SboxMsg", "msgs\SboxMsg.vcxproj", "{63B0DDD2-5E3B-EF38-F711-9652D2EB73B3}"
ProjectSection(ProjectDependencies) = postProject
{7BA01954-12F1-4CEE-BA97-FAD3250D9776} = {7BA01954-12F1-4CEE-BA97-FAD3250D9776}
EndProjectSection
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Parse", "msgs\Parse.vcxproj", "{7BA01954-12F1-4CEE-BA97-FAD3250D9776}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Release|Win32 = Release|Win32
Release|x64 = Release|x64
SbieDebug|Win32 = SbieDebug|Win32
SbieDebug|x64 = SbieDebug|x64
SbieRelease|Win32 = SbieRelease|Win32
SbieRelease|x64 = SbieRelease|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4019C5EB-8D1E-40E4-B7D1-5601B4B27288}.SbieDebug|Win32.ActiveCfg = SbieDebug|Win32
{4019C5EB-8D1E-40E4-B7D1-5601B4B27288}.SbieDebug|Win32.Build.0 = SbieDebug|Win32
{4019C5EB-8D1E-40E4-B7D1-5601B4B27288}.SbieDebug|x64.ActiveCfg = SbieDebug|x64
{4019C5EB-8D1E-40E4-B7D1-5601B4B27288}.SbieDebug|x64.Build.0 = SbieDebug|x64
{4019C5EB-8D1E-40E4-B7D1-5601B4B27288}.SbieRelease|Win32.ActiveCfg = SbieRelease|Win32
{4019C5EB-8D1E-40E4-B7D1-5601B4B27288}.SbieRelease|Win32.Build.0 = SbieRelease|Win32
{4019C5EB-8D1E-40E4-B7D1-5601B4B27288}.SbieRelease|x64.ActiveCfg = SbieRelease|x64
{4019C5EB-8D1E-40E4-B7D1-5601B4B27288}.SbieRelease|x64.Build.0 = SbieRelease|x64
{63B0DDD2-5E3B-EF38-F711-9652D2EB73B3}.SbieDebug|Win32.ActiveCfg = SbieRelease|Win32
{63B0DDD2-5E3B-EF38-F711-9652D2EB73B3}.SbieDebug|Win32.Build.0 = SbieRelease|Win32
{63B0DDD2-5E3B-EF38-F711-9652D2EB73B3}.SbieDebug|x64.ActiveCfg = SbieRelease|x64
{63B0DDD2-5E3B-EF38-F711-9652D2EB73B3}.SbieDebug|x64.Build.0 = SbieRelease|x64
{63B0DDD2-5E3B-EF38-F711-9652D2EB73B3}.SbieRelease|Win32.ActiveCfg = SbieRelease|Win32
{63B0DDD2-5E3B-EF38-F711-9652D2EB73B3}.SbieRelease|Win32.Build.0 = SbieRelease|Win32
{63B0DDD2-5E3B-EF38-F711-9652D2EB73B3}.SbieRelease|x64.ActiveCfg = SbieRelease|x64
{63B0DDD2-5E3B-EF38-F711-9652D2EB73B3}.SbieRelease|x64.Build.0 = SbieRelease|x64
{7BA01954-12F1-4CEE-BA97-FAD3250D9776}.SbieDebug|Win32.ActiveCfg = SbieRelease|Win32
{7BA01954-12F1-4CEE-BA97-FAD3250D9776}.SbieDebug|Win32.Build.0 = SbieRelease|Win32
{7BA01954-12F1-4CEE-BA97-FAD3250D9776}.SbieDebug|x64.ActiveCfg = SbieRelease|Win32
{7BA01954-12F1-4CEE-BA97-FAD3250D9776}.SbieDebug|x64.Build.0 = SbieRelease|Win32
{7BA01954-12F1-4CEE-BA97-FAD3250D9776}.SbieRelease|Win32.ActiveCfg = SbieRelease|Win32
{7BA01954-12F1-4CEE-BA97-FAD3250D9776}.SbieRelease|Win32.Build.0 = SbieRelease|Win32
{7BA01954-12F1-4CEE-BA97-FAD3250D9776}.SbieRelease|x64.ActiveCfg = SbieRelease|Win32
{7BA01954-12F1-4CEE-BA97-FAD3250D9776}.SbieRelease|x64.Build.0 = SbieRelease|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,142 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
// SboxHostDll.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"
#include "core/dll/sbiedll.h"
typedef BOOL (*P_OpenProcessToken)(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE phTokenOut);
static P_OpenProcessToken __sys_OpenProcessToken = NULL;
BOOL SboxHostDll_OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE phTokenOut)
{
BOOL bRet = FALSE;
HANDLE hToken = 0;
std::wstring wsLogonSid;
// if caller provide null-phTokenOut, pass it to the original call to have the same last error.
if (__sys_OpenProcessToken)
{
bRet = __sys_OpenProcessToken(ProcessHandle, DesiredAccess, phTokenOut? &hToken:phTokenOut);
}
if (bRet)
{
if (SbieApi_QueryProcessInfo((HANDLE)GetProcessId(ProcessHandle), 0) & SBIE_FLAG_VALID_PROCESS)
{
BOOL bNeedAnotherValidToken = FALSE;
LUID idLogonSession = {0};
ATL::CAccessToken token;
ATL::CSid userSid;
ATL::CSid logonSid;
token.Attach(hToken);
//if(token.IsTokenRestricted())
//{
if(token.GetUser(&userSid))
{
// this token is usable for clicktorun service
if (lstrcmpi(userSid.Sid(), _T("S-1-5-7"))==0)
{
if(token.GetLogonSid(&logonSid))
{
wsLogonSid = logonSid.Sid();
bNeedAnotherValidToken = TRUE;
}
}
}
//}
token.Detach();
if (bNeedAnotherValidToken)
{
// get a host process token with the same wsLogonSid.
HANDLE hAltToken = 0;
DWORD aPid[1024], cbReturned, nPidCount;
if (EnumProcesses( aPid, sizeof(aPid), &cbReturned ) )
{
nPidCount = cbReturned / sizeof(DWORD);
for ( UINT i = 0; i < nPidCount; i++ )
{
if (!SbieApi_QueryProcessInfo((HANDLE)aPid[i], 0) & SBIE_FLAG_VALID_PROCESS)
{
HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, TRUE, aPid[i]);
if (hProc)
{
if (__sys_OpenProcessToken(hProc, DesiredAccess, &hAltToken))
{
ATL::CAccessToken altToken;
altToken.Attach(hAltToken);
if(altToken.GetLogonSid(&logonSid))
{
std::wstring wsAltLogonSid = logonSid.Sid();
if (wsAltLogonSid == wsLogonSid)
{
altToken.Detach();
CloseHandle(hProc);
break;
}
}
altToken.Detach();
CloseHandle(hAltToken);
hAltToken = 0;
}
CloseHandle(hProc);
}
}
}
}
if (hAltToken)
{
CloseHandle(hToken);
hToken = hAltToken;
bRet = TRUE;
}
}
}
if (phTokenOut)
*phTokenOut = hToken;
}
return bRet;
}
BOOLEAN InitHook( HINSTANCE hSbieDll )
{
if (hSbieDll)
{
HMODULE hAdvapi32 = GetModuleHandle(L"Advapi32.dll");
void *OpenProcessToken = (P_OpenProcessToken)GetProcAddress(hAdvapi32, "OpenProcessToken");
if (OpenProcessToken)
SBIEDLL_HOOK(SboxHostDll_, OpenProcessToken);
}
return TRUE;
}

View File

@ -0,0 +1,20 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
#pragma once
#define SBOX_HOST_DLL_LOADED L"Global\\SboxHostDllLoaded"

Binary file not shown.

View File

@ -0,0 +1,159 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="SbieDebug|Win32">
<Configuration>SbieDebug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="SbieDebug|x64">
<Configuration>SbieDebug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="SbieRelease|Win32">
<Configuration>SbieRelease</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="SbieRelease|x64">
<Configuration>SbieRelease</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{3A42A9F3-E0C7-4633-9570-381802D6647D}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>SboxHostDll</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\Sandbox32.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\Sandbox64.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\Sandbox32.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\Sandbox64.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>Disabled</Optimization>
<ExceptionHandling>Sync</ExceptionHandling>
</ClCompile>
<Link>
<AdditionalDependencies>SbieDll.lib;psapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ShowProgress>
</ShowProgress>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<Optimization>Disabled</Optimization>
<ExceptionHandling>Sync</ExceptionHandling>
</ClCompile>
<Link>
<AdditionalDependencies>SbieDll.lib;psapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ShowProgress>
</ShowProgress>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<FunctionLevelLinking>
</FunctionLevelLinking>
<ExceptionHandling>Sync</ExceptionHandling>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>SbieDll.lib;psapi.lib;%(AdditionalDependencies)</AdditionalDependencies>
<ShowProgress>
</ShowProgress>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<FunctionLevelLinking>
</FunctionLevelLinking>
<ExceptionHandling>Sync</ExceptionHandling>
</ClCompile>
<Link>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalDependencies>SbieDll.lib;psapi.lib</AdditionalDependencies>
<ShowProgress>
</ShowProgress>
<IgnoreSpecificDefaultLibraries>msvcprt.lib;%(IgnoreSpecificDefaultLibraries)</IgnoreSpecificDefaultLibraries>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<None Include="ReadMe.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="resource.h" />
<ClInclude Include="SboxHostDll.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="targetver.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="dllmain.cpp">
</ClCompile>
<ClCompile Include="SboxHostDll.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'">Create</PrecompiledHeader>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="SboxHostDll.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,78 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"
#include "SboxHostDll.h"
using namespace std;
HANDLE g_hInjectedGlobalNameObj = NULL;
BOOLEAN InitHook( HINSTANCE hSbieDll );
extern "C" __declspec(dllexport) void InjectDllMain(HINSTANCE hSbieDll, ULONG_PTR UnusedParameter)
{
InitHook(hSbieDll);
}
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
BOOL bRet = TRUE;
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
WCHAR wszDLLPath[MAX_PATH + 1];
if (GetModuleFileName(GetModuleHandle(NULL), wszDLLPath, MAX_PATH))
{
if (wcsstr(wszDLLPath, L"OfficeClickToRun.exe"))
{
// You can use this global name object to check if the dll loaded.
g_hInjectedGlobalNameObj = CreateMutex(NULL, FALSE, SBOX_HOST_DLL_LOADED);
bRet = TRUE;
}
else
{
// injected to wrong process.
bRet = FALSE;
}
}
break;
case DLL_THREAD_ATTACH:
break;
case DLL_THREAD_DETACH:
break;
case DLL_PROCESS_DETACH:
if (g_hInjectedGlobalNameObj)
{
CloseHandle(g_hInjectedGlobalNameObj);
}
break;
}
return bRet;
}

View File

@ -0,0 +1,31 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by SboxHostDll.rc
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View File

@ -0,0 +1,25 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
// stdafx.cpp : source file that includes just the standard includes
// SboxHostDll.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information
#include "stdafx.h"
// TODO: reference any additional headers you need in STDAFX.H
// and not in this file

View File

@ -0,0 +1,35 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#pragma once
#include "targetver.h"
//#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
// Windows Header Files:
#include <windows.h>
#include <string>
#include <atlsecurity.h>
#include <Psapi.h>
// TODO: reference additional headers your program requires here

View File

@ -0,0 +1,25 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
#pragma once
// Including SDKDDKVer.h defines the highest available Windows platform.
// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
#include <SDKDDKVer.h>

View File

@ -0,0 +1,112 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="SbieDebug|Win32">
<Configuration>SbieDebug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="SbieDebug|x64">
<Configuration>SbieDebug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="SbieRelease|Win32">
<Configuration>SbieRelease</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="SbieRelease|x64">
<Configuration>SbieRelease</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{E40CC819-6990-DA28-3E1F-6708BC98E37B}</ProjectGuid>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'" Label="PropertySheets">
<Import Project="..\..\..\Sandbox32.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'" Label="PropertySheets">
<Import Project="..\..\..\Sandbox64.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'" Label="PropertySheets">
<Import Project="..\..\..\Sandbox32.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'" Label="PropertySheets">
<Import Project="..\..\..\Sandbox64.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'">
<TargetName>SandboxieBITS</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'">
<TargetName>SandboxieBITS</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'">
<TargetName>SandboxieBITS</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'">
<TargetName>SandboxieBITS</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
</ClCompile>
<Link>
<AdditionalDependencies>advapi32.lib;kernel32.lib;ntdll.lib;gdi32.lib;user32.lib;secur32.lib;psapi.lib;ole32.lib;wtsapi32.lib;SbieDll.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'">
<ClCompile>
<Optimization>Disabled</Optimization>
</ClCompile>
<Link>
<AdditionalDependencies>advapi32.lib;kernel32.lib;ntdll.lib;gdi32.lib;user32.lib;secur32.lib;psapi.lib;ole32.lib;wtsapi32.lib;SbieDll.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'">
<ClCompile />
<Link>
<AdditionalDependencies>advapi32.lib;kernel32.lib;ntdll.lib;gdi32.lib;user32.lib;secur32.lib;psapi.lib;ole32.lib;wtsapi32.lib;SbieDll.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'">
<ClCompile />
<Link>
<AdditionalDependencies>advapi32.lib;kernel32.lib;ntdll.lib;gdi32.lib;user32.lib;secur32.lib;psapi.lib;ole32.lib;wtsapi32.lib;SbieDll.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="bits.c" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="resource.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,137 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Sandboxie Background Intelligent Transfer Service (BITS)
//---------------------------------------------------------------------------
#include <ntstatus.h>
#define WIN32_NO_STATUS
typedef long NTSTATUS;
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include "common/defines.h"
#include "common/my_version.h"
//---------------------------------------------------------------------------
// Variables
//---------------------------------------------------------------------------
const WCHAR *ServiceTitle = SANDBOXIE L" BITS";
#include "../common.h"
//---------------------------------------------------------------------------
// my_CreateFileMapping
//---------------------------------------------------------------------------
HANDLE my_CreateFileMappingW(
HANDLE hFile,
LPSECURITY_ATTRIBUTES lpAttributes,
DWORD flProtect,
DWORD dwMaximumSizeHigh,
DWORD dwMaximumSizeLow,
LPCWSTR lpName)
{
typedef HANDLE (__stdcall *P_CreateFileMappingW)(
HANDLE hFile,
LPSECURITY_ATTRIBUTES lpAttributes,
DWORD flProtect,
DWORD dwMaximumSizeHigh,
DWORD dwMaximumSizeLow,
LPCWSTR lpName);
return ((P_CreateFileMappingW)__sys_CreateFileMappingW)(
hFile, lpAttributes, flProtect,
dwMaximumSizeHigh, dwMaximumSizeLow, lpName);
}
//---------------------------------------------------------------------------
// my_LogonUserW
//---------------------------------------------------------------------------
ULONG_PTR __sys_LogonUserW = 0;
BOOL my_LogonUserW(
const WCHAR *UserName, const WCHAR *DomainName, const WCHAR *Password,
DWORD dwLogonType, DWORD dwLogonProvider, HANDLE *phToken)
{
return OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, phToken);
}
//---------------------------------------------------------------------------
// my_CoImpersonateClient
//---------------------------------------------------------------------------
__declspec(dllimport) HRESULT CoImpersonateClient(void);
BOOL WTSQueryUserToken(ULONG SessionId, HANDLE *pToken);
ULONG_PTR __sys_CoImpersonateClient = 0;
HRESULT my_CoImpersonateClient(void)
{
HANDLE hPriToken, hImpToken;
BOOL ok;
if (WTSQueryUserToken(0, &hPriToken)) {
ok = DuplicateTokenEx(
hPriToken, TOKEN_ALL_ACCESS, NULL,
SecurityImpersonation, TokenImpersonation, &hImpToken);
if (ok) {
ok = SetThreadToken(NULL, hImpToken);
CloseHandle(hImpToken);
}
CloseHandle(hPriToken);
}
return (ok ? S_OK : CO_E_FAILEDTOIMPERSONATE);
}
//---------------------------------------------------------------------------
// WinMain
//---------------------------------------------------------------------------
int __stdcall WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WCHAR ServiceName[16];
BOOL hook_success = TRUE;
BOOL ok;
SetupExceptionHandler();
HOOK_WIN32(CoImpersonateClient);
HOOK_WIN32(LogonUserW);
wcscpy(ServiceName, L"BITS");
ok = Service_Start_ServiceMain(
ServiceName, L"qmgr.dll", "ServiceMain", FALSE);
return (ok ? EXIT_SUCCESS : EXIT_FAILURE);
}

View File

@ -0,0 +1,87 @@
// Copyright 2004-2020 Sandboxie Holdings, LLC
//
// 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 <https://www.gnu.org/licenses/>.
//
//Microsoft Developer Studio generated resource script.
//
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
#ifndef _MAC
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
#include "common/my_version.h"
VS_VERSION_INFO VERSIONINFO
FILEVERSION MY_VERSION_BINARY
PRODUCTVERSION MY_VERSION_BINARY
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x40004L
FILETYPE 0x2L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "Comments", "\0"
VALUE "CompanyName", MY_COMPANY_NAME_STRING "\0"
VALUE "FileDescription", MY_PRODUCT_NAME_STRING " COM Services (BITS)\0"
VALUE "FileVersion", MY_VERSION_STRING "\0"
OPTIONAL_VALUE("InternalName", "BITS\0")
VALUE "LegalCopyright", MY_COPYRIGHT_STRING "\0"
VALUE "LegalTrademarks", "\0"
OPTIONAL_VALUE("OriginalFilename", "SandboxieBITS.exe\0")
VALUE "PrivateBuild", "\0"
VALUE "ProductName", MY_PRODUCT_NAME_STRING "\0"
VALUE "ProductVersion", MY_VERSION_STRING "\0"
VALUE "SpecialBuild", "\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
#endif // !_MAC
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,116 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="SbieDebug|Win32">
<Configuration>SbieDebug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="SbieDebug|x64">
<Configuration>SbieDebug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="SbieRelease|Win32">
<Configuration>SbieRelease</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="SbieRelease|x64">
<Configuration>SbieRelease</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{41453A79-CA9B-ABCA-981C-5242AFC72DDF}</ProjectGuid>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'" Label="PropertySheets">
<Import Project="..\..\..\Sandbox32.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'" Label="PropertySheets">
<Import Project="..\..\..\Sandbox64.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'" Label="PropertySheets">
<Import Project="..\..\..\Sandbox32.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'" Label="PropertySheets">
<Import Project="..\..\..\Sandbox64.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'">
<LinkIncremental>true</LinkIncremental>
<TargetName>SandboxieCrypto</TargetName>
<LibraryPath>$(WDKPATH)\lib\wnet\i386;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'">
<LinkIncremental>true</LinkIncremental>
<TargetName>SandboxieCrypto</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'">
<TargetName>SandboxieCrypto</TargetName>
<LibraryPath>$(WDKPATH)\lib\wnet\i386;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'">
<TargetName>SandboxieCrypto</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
</ClCompile>
<Link>
<AdditionalDependencies>SbieDll.lib;ntdll.lib;kernel32.lib;secur32.lib;advapi32.lib;user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'">
<ClCompile>
<Optimization>Disabled</Optimization>
</ClCompile>
<Link>
<AdditionalDependencies>SbieDll.lib;ntdll.lib;kernel32.lib;secur32.lib;advapi32.lib;user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'">
<ClCompile />
<Link>
<AdditionalDependencies>SbieDll.lib;ntdll.lib;kernel32.lib;secur32.lib;advapi32.lib;user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'">
<ClCompile />
<Link>
<AdditionalDependencies>SbieDll.lib;ntdll.lib;kernel32.lib;secur32.lib;advapi32.lib;user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="crypto.c" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="resource.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,175 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Sandboxie Cryptography Service (CRYPTSVC)
//---------------------------------------------------------------------------
#include <ntstatus.h>
#define WIN32_NO_STATUS
typedef long NTSTATUS;
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include "common/defines.h"
#include "common/my_version.h"
//---------------------------------------------------------------------------
// Variables
//---------------------------------------------------------------------------
#define SINGLE_INSTANCE_MUTEX_NAME L"ServiceCrypto_Mutex1"
const WCHAR *ServiceTitle = SANDBOXIE L" Crypto";
#define SANDBOXIECRYPTO 1
#include "../common.h"
#include "../privs.h"
//---------------------------------------------------------------------------
static ULONG_PTR __sys_DuplicateHandle = 0;
//---------------------------------------------------------------------------
// my_CreateFileMapping
//---------------------------------------------------------------------------
HANDLE my_CreateFileMappingW(
HANDLE hFile,
LPSECURITY_ATTRIBUTES lpAttributes,
DWORD flProtect,
DWORD dwMaximumSizeHigh,
DWORD dwMaximumSizeLow,
LPCWSTR lpName)
{
typedef HANDLE (__stdcall *P_CreateFileMappingW)(
HANDLE hFile,
LPSECURITY_ATTRIBUTES lpAttributes,
DWORD flProtect,
DWORD dwMaximumSizeHigh,
DWORD dwMaximumSizeLow,
LPCWSTR lpName);
return ((P_CreateFileMappingW)__sys_CreateFileMappingW)(
hFile, lpAttributes, flProtect,
dwMaximumSizeHigh, dwMaximumSizeLow, lpName);
}
//---------------------------------------------------------------------------
// my_DuplicateHandle
//---------------------------------------------------------------------------
ALIGNED BOOL my_DuplicateHandle(
HANDLE hSourceProcessHandle,
HANDLE hSourceHandle,
HANDLE hTargetProcessHandle,
LPHANDLE lpTargetHandle,
DWORD dwDesiredAccess,
BOOL bInheritHandle,
DWORD dwOptions)
{
typedef BOOL (*P_DuplicateHandle)(
HANDLE hSourceProcessHandle,
HANDLE hSourceHandle,
HANDLE hTargetProcessHandle,
LPHANDLE lpTargetHandle,
DWORD dwDesiredAccess,
BOOL bInheritHandle,
DWORD dwOptions);
BOOL ok = ((P_DuplicateHandle)__sys_DuplicateHandle)(
hSourceProcessHandle, hSourceHandle,
hTargetProcessHandle, lpTargetHandle,
dwDesiredAccess, bInheritHandle, dwOptions);
if ((! ok) && GetLastError() == ERROR_ACCESS_DENIED) {
//
// the client process for the CryptSvc service is ocassionally
// running under LocalSystem (typically during MSI installations).
// CryptSvc tries to duplicate an event handle and fails so
// we fake successful operation.
//
if (hSourceProcessHandle != NtCurrentProcess() &&
hTargetProcessHandle == NtCurrentProcess()) {
*lpTargetHandle = CreateEvent(NULL, FALSE, FALSE, NULL);
SetLastError(ERROR_SUCCESS);
ok = TRUE;
}
}
return ok;
}
//---------------------------------------------------------------------------
// WinMain
//---------------------------------------------------------------------------
int __stdcall WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WCHAR ServiceName[16];
BOOL hook_success = TRUE;
BOOL ok;
PROCESS_DATA *myData;
if (! CheckSingleInstance()) {
// return special error code to indicate elective termination
// because this is a duplicate copy of SandboxieRpcSs.exe
// see also core/dll/ipc_start.c
return STATUS_LICENSE_QUOTA_EXCEEDED;
}
SetupExceptionHandler();
HOOK_WIN32(DuplicateHandle);
// hook privilege-related functions
if (! Hook_Privilege())
return EXIT_FAILURE;
wcscpy(ServiceName, L"CryptSvc");
// hook SetServiceStatus
// use ServiceStatus_Check to signal the CryptSvc init complete event
myData = my_findProcessData(ServiceName, 1);
if (!myData) {
return FALSE;
}
HOOK_WIN32(SetServiceStatus);
myData->tid = 0;
myData->initFlag = 0;
// run the service
ok = Service_Start_ServiceMain(ServiceName, L"cryptsvc.dll", "CryptServiceMain", FALSE);
return (ok ? EXIT_SUCCESS : EXIT_FAILURE);
}

View File

@ -0,0 +1,87 @@
// Copyright 2004-2020 Sandboxie Holdings, LLC
//
// 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 <https://www.gnu.org/licenses/>.
//
//Microsoft Developer Studio generated resource script.
//
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
#ifndef _MAC
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
#include "common/my_version.h"
VS_VERSION_INFO VERSIONINFO
FILEVERSION MY_VERSION_BINARY
PRODUCTVERSION MY_VERSION_BINARY
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x40004L
FILETYPE 0x2L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "Comments", "\0"
VALUE "CompanyName", MY_COMPANY_NAME_STRING "\0"
VALUE "FileDescription", MY_PRODUCT_NAME_STRING " COM Services (CryptSvc)\0"
VALUE "FileVersion", MY_VERSION_STRING "\0"
OPTIONAL_VALUE("InternalName", "Crypto\0")
VALUE "LegalCopyright", MY_COPYRIGHT_STRING "\0"
VALUE "LegalTrademarks", "\0"
OPTIONAL_VALUE("OriginalFilename", "SandboxieCrypto.exe\0")
VALUE "PrivateBuild", "\0"
VALUE "ProductName", MY_PRODUCT_NAME_STRING "\0"
VALUE "ProductVersion", MY_VERSION_STRING "\0"
VALUE "SpecialBuild", "\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
#endif // !_MAC
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="SbieDebug|Win32">
<Configuration>SbieDebug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="SbieDebug|x64">
<Configuration>SbieDebug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="SbieRelease|Win32">
<Configuration>SbieRelease</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="SbieRelease|x64">
<Configuration>SbieRelease</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{8055A629-631E-84F5-8F3C-1908F264C81D}</ProjectGuid>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'" Label="PropertySheets">
<Import Project="..\..\..\Sandbox32.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'" Label="PropertySheets">
<Import Project="..\..\..\Sandbox64.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'" Label="PropertySheets">
<Import Project="..\..\..\Sandbox32.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'" Label="PropertySheets">
<Import Project="..\..\..\Sandbox64.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'">
<LinkIncremental>true</LinkIncremental>
<TargetName>SandboxieDcomLaunch</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'">
<LinkIncremental>true</LinkIncremental>
<TargetName>SandboxieDcomLaunch</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'">
<TargetName>SandboxieDcomLaunch</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'">
<TargetName>SandboxieDcomLaunch</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<MinimalRebuild />
</ClCompile>
<Link>
<AdditionalDependencies>SbieDll.lib;kernel32.lib;secur32.lib;Advapi32.lib;Ntdll.lib;User32.lib</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'">
<ClCompile>
<Optimization>Disabled</Optimization>
<MinimalRebuild />
</ClCompile>
<Link>
<AdditionalDependencies>SbieDll.lib;kernel32.lib;secur32.lib;Advapi32.lib;Ntdll.lib;User32.lib</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'">
<ClCompile>
<MinimalRebuild />
</ClCompile>
<Link>
<AdditionalDependencies>SbieDll.lib;kernel32.lib;secur32.lib;Advapi32.lib;Ntdll.lib;User32.lib</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'">
<ClCompile>
<MinimalRebuild />
</ClCompile>
<Link>
<AdditionalDependencies>SbieDll.lib;kernel32.lib;secur32.lib;Advapi32.lib;Ntdll.lib;User32.lib</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="dcomlaunch.c" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="resource.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,150 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Sandboxie DCOMLAUNCH Service
//---------------------------------------------------------------------------
#include <ntstatus.h>
#define WIN32_NO_STATUS
typedef long NTSTATUS;
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include "common/defines.h"
#include "common/my_version.h"
//---------------------------------------------------------------------------
// Variables
//---------------------------------------------------------------------------
const WCHAR *ServiceTitle = SANDBOXIE L" DcomLaunch";
#include "../common.h"
#include "../privs.h"
HANDLE RotHintTable = NULL;
const WCHAR *RotHintTable_Name = L"Global\\RotHintTable";
//---------------------------------------------------------------------------
// my_CreateFileMapping
//---------------------------------------------------------------------------
_FX HANDLE my_CreateFileMappingW(
HANDLE hFile,
LPSECURITY_ATTRIBUTES lpAttributes,
DWORD flProtect,
DWORD dwMaximumSizeHigh,
DWORD dwMaximumSizeLow,
LPCWSTR lpName)
{
typedef HANDLE (__stdcall *P_CreateFileMappingW)(
HANDLE hFile,
LPSECURITY_ATTRIBUTES lpAttributes,
DWORD flProtect,
DWORD dwMaximumSizeHigh,
DWORD dwMaximumSizeLow,
LPCWSTR lpName);
HANDLE handle = 0;
if (lpName && _wcsicmp(lpName, RotHintTable_Name) == 0)
handle = RotHintTable;
if (! handle) {
handle = ((P_CreateFileMappingW)__sys_CreateFileMappingW)(
hFile, lpAttributes, flProtect,
dwMaximumSizeHigh, dwMaximumSizeLow, lpName);
}
return handle;
}
//---------------------------------------------------------------------------
// ExitWhenParentDies
//---------------------------------------------------------------------------
_FX ULONG ExitWhenParentDies(void *arg)
{
NTSTATUS status;
ULONG len;
PROCESS_BASIC_INFORMATION info;
HANDLE hParentProcess;
status = NtQueryInformationProcess(
NtCurrentProcess(), ProcessBasicInformation,
&info, sizeof(PROCESS_BASIC_INFORMATION), &len);
if (! NT_SUCCESS(status))
hParentProcess = NULL;
else {
hParentProcess = OpenProcess(
SYNCHRONIZE, FALSE, (ULONG)info.InheritedFromUniqueProcessId);
}
if (! hParentProcess)
hParentProcess = NtCurrentProcess();
status = WaitForSingleObject(hParentProcess, INFINITE);
if (status == WAIT_OBJECT_0)
ExitProcess(0);
return 0;
}
//---------------------------------------------------------------------------
// WinMain
//---------------------------------------------------------------------------
int __stdcall WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
WCHAR ServiceName[16];
BOOL ok;
HANDLE hThreadEvent;
SetupExceptionHandler();
Check_Windows_7();
// pretend we are the SCM
if (! Hook_Service_Control_Manager())
return EXIT_FAILURE;
// hook privilege-related functions
if (! Hook_Privilege())
return EXIT_FAILURE;
hThreadEvent = CreateThread(NULL, 0, ExitWhenParentDies, 0, 0, NULL);
// start dcom launcher service
wcscpy(ServiceName, L"DCOMLAUNCH");
ok = Service_Start_ServiceMain( ServiceName, L"rpcss.dll", "ServiceMain", TRUE);
if (! ok)
return EXIT_FAILURE;
WaitForSingleObject(hThreadEvent, INFINITE);
return 0;
}

View File

@ -0,0 +1,87 @@
// Copyright 2004-2020 Sandboxie Holdings, LLC
//
// 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 <https://www.gnu.org/licenses/>.
//
//Microsoft Developer Studio generated resource script.
//
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
#ifndef _MAC
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
#include "common/my_version.h"
VS_VERSION_INFO VERSIONINFO
FILEVERSION MY_VERSION_BINARY
PRODUCTVERSION MY_VERSION_BINARY
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x40004L
FILETYPE 0x2L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "Comments", "\0"
VALUE "CompanyName", MY_COMPANY_NAME_STRING "\0"
VALUE "FileDescription", MY_PRODUCT_NAME_STRING " COM Services (DCOM)\0"
VALUE "FileVersion", MY_VERSION_STRING "\0"
OPTIONAL_VALUE("InternalName", "DcomLaunch\0")
VALUE "LegalCopyright", MY_COPYRIGHT_STRING "\0"
VALUE "LegalTrademarks", "\0"
OPTIONAL_VALUE("OriginalFilename", "SandboxieDcomLaunch.exe\0")
VALUE "PrivateBuild", "\0"
VALUE "ProductName", MY_PRODUCT_NAME_STRING "\0"
VALUE "ProductVersion", MY_VERSION_STRING "\0"
VALUE "SpecialBuild", "\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
#endif // !_MAC
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,124 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="SbieDebug|Win32">
<Configuration>SbieDebug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="SbieDebug|x64">
<Configuration>SbieDebug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="SbieRelease|Win32">
<Configuration>SbieRelease</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="SbieRelease|x64">
<Configuration>SbieRelease</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{5410C534-4858-C748-86AD-0567A2451FDE}</ProjectGuid>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'" Label="PropertySheets">
<Import Project="..\..\..\Sandbox32.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'" Label="PropertySheets">
<Import Project="..\..\..\Sandbox64.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'" Label="PropertySheets">
<Import Project="..\..\..\Sandbox32.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'" Label="PropertySheets">
<Import Project="..\..\..\Sandbox64.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'">
<LinkIncremental>true</LinkIncremental>
<TargetName>SandboxieRpcSs</TargetName>
<LibraryPath>$(WDKPATH)\lib\wnet\i386;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'">
<LinkIncremental>true</LinkIncremental>
<TargetName>SandboxieRpcSs</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'">
<TargetName>SandboxieRpcSs</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'">
<TargetName>SandboxieRpcSs</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<MinimalRebuild />
</ClCompile>
<Link>
<AdditionalDependencies>SbieDll.lib;ws2_32.lib;advapi32.lib;kernel32.lib;ntdll.lib;gdi32.lib;user32.lib;secur32.lib;psapi.lib</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'">
<ClCompile>
<Optimization>Disabled</Optimization>
<MinimalRebuild />
</ClCompile>
<Link>
<AdditionalDependencies>SbieDll.lib;ws2_32.lib;advapi32.lib;kernel32.lib;ntdll.lib;gdi32.lib;user32.lib;secur32.lib;psapi.lib</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'">
<ClCompile>
<MinimalRebuild />
</ClCompile>
<Link>
<AdditionalDependencies>SbieDll.lib;ws2_32.lib;advapi32.lib;kernel32.lib;ntdll.lib;gdi32.lib;user32.lib;secur32.lib;psapi.lib</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'">
<ClCompile>
<MinimalRebuild />
</ClCompile>
<Link>
<AdditionalDependencies>SbieDll.lib;ws2_32.lib;advapi32.lib;kernel32.lib;ntdll.lib;gdi32.lib;user32.lib;secur32.lib;psapi.lib</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="dde.c" />
<ClCompile Include="linger.c" />
<ClCompile Include="rpcss.c" />
<ClCompile Include="sxs.c" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="resource.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,91 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// DDE Helper Window
//---------------------------------------------------------------------------
#include <windows.h>
#include <dde.h>
#include "core/dll/sbiedll.h"
#include "common/defines.h"
#include "common/my_version.h"
//---------------------------------------------------------------------------
//
// dummy window for DDEML support
//
// DDEML will call (internal) user32!ValidateHwnd to validate the window
// it sees in DDE messages, and if this window is outside the sandbox,
// the conversation fails. this could be fixed with UserHandleGrantAccess
// if not for the integrity level difference between the process in the
// sandbox and the window outside the sandbox.
//
// to work around this, we use this dummy window which is in the sandbox
// and at the same integrity level as the DDE server process, so always
// accepted by user32!ValidateHwnd
//
// this dummy proxy window is used by the Gui_DDE_INITIATE_Received,
// Gui_DDE_ACK_Sending and Gui_DDE_COPYDATA_Received functions
// in file core/dll/guidde.c -- see there for more
//
// note the window class name is _DDE_ProxyClass1 and there is another
// proxy window called _DDE_ProxyClass2 created by DdeProxyThreadSlave
// in the SbieSvc GUI Proxy in file core/svc/GuiServer.cpp
//
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// Dde_Thread
//---------------------------------------------------------------------------
_FX ULONG Dde_Thread(void *arg)
{
ATOM atom;
HWND hwnd;
WNDCLASS wc;
MSG msg;
if (SbieApi_QueryProcessInfo(0, 0) & SBIE_FLAG_OPEN_ALL_WIN_CLASS)
return 0;
memzero(&wc, sizeof(wc));
wc.lpfnWndProc = DefWindowProc;
wc.hInstance = GetModuleHandle(NULL);
wc.lpszClassName = SANDBOXIE L"_DDE_ProxyClass1";
atom = RegisterClass(&wc);
if (! atom)
return 0;
hwnd = CreateWindowEx(0, (LPCWSTR)atom, L"", 0,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, GetModuleHandle(NULL), NULL);
if (! hwnd)
return 0;
while (1) {
GetMessage(&msg, NULL, 0, 0);
DispatchMessage(&msg);
}
return 0;
}

View File

@ -0,0 +1,638 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// LingerProcess / LeaderProcess management
//---------------------------------------------------------------------------
#include <ntstatus.h>
#define WIN32_NO_STATUS
typedef long NTSTATUS;
#include <windows.h>
#include <stdlib.h>
#include "core/dll/sbiedll.h"
#include "common/win32_ntddk.h"
#include "common/my_version.h"
#include "common/defines.h"
//---------------------------------------------------------------------------
// Defines
//---------------------------------------------------------------------------
#define MAX_LINGER_LEADER_COUNT 512
//---------------------------------------------------------------------------
// Structures and Types
//---------------------------------------------------------------------------
typedef struct _LINGER_LEADER {
HANDLE orig_pid;
HANDLE curr_pid;
WCHAR image[1];
} LINGER_LEADER;
typedef struct _MONITOR_PIDS {
ULONG pid;
HANDLE hProcessExit;
struct _MONITOR_PIDS *next;
} MONITOR_PIDS;
//---------------------------------------------------------------------------
// Variables
//---------------------------------------------------------------------------
extern const WCHAR *_SandboxieRpcSs;
extern const WCHAR *_msiexec;
static const WCHAR *_SandboxieDcomLaunch = SANDBOXIE L"DcomLaunch.exe";
static const WCHAR *_SandboxieCrypto = SANDBOXIE L"Crypto.exe";
static const WCHAR *_SandboxieBITS = SANDBOXIE L"BITS.exe";
static const WCHAR *_SandboxieWUAU = SANDBOXIE L"WUAU.exe";
static const WCHAR *_wuauclt = L"wuauclt.exe";
static const WCHAR *_TrustedInstaller = L"TrustedInstaller.exe";
static const WCHAR *_tiworker = L"tiworker.exe";
static CRITICAL_SECTION ProcessCritSec;
static HANDLE heventProcessStart;
static HANDLE heventRpcSs;
static ULONG *pids;
static MONITOR_PIDS *pidList = NULL;
void RemovePid(ULONG myPid);
//---------------------------------------------------------------------------
// WaitOrTimerCallback
//---------------------------------------------------------------------------
VOID CALLBACK WaitOrTimerCallback( _In_ PVOID lpParameter, _In_ BOOLEAN TimerOrWaitFired )
{
EnterCriticalSection(&ProcessCritSec);
RemovePid((ULONG)(ULONG_PTR)lpParameter);
SetEvent(heventRpcSs);
LeaveCriticalSection(&ProcessCritSec);
}
//---------------------------------------------------------------------------
// RemovePid
//---------------------------------------------------------------------------
void RemovePid(ULONG myPid)
{
MONITOR_PIDS *curr = pidList;
MONITOR_PIDS *p = NULL;
if (!curr) {
return;
}
while (curr)
{
if (curr->pid == myPid) {
if (curr == pidList) {
pidList = curr->next;
CloseHandle(curr->hProcessExit);
free(curr);
}
else {
p->next = curr->next;
free(curr);
}
break;
}
p = curr;
curr = curr->next;
}
}
//---------------------------------------------------------------------------
// AddPid
//---------------------------------------------------------------------------
void AddPid(ULONG *myPids)
{
ULONG i;
MONITOR_PIDS *curr = pidList;
MONITOR_PIDS *p = NULL;
HANDLE hNewHandle;
HANDLE hProcHandle = 0;
if (myPids[0] < 1) {
return;
}
for (i = 1; i <= myPids[0]; i++)
{
curr = pidList;
p = curr;
//new list
if (!curr) {
hProcHandle = OpenProcess(SYNCHRONIZE, FALSE, myPids[i]);
curr = (MONITOR_PIDS*)calloc(1, sizeof(MONITOR_PIDS));
curr->next = NULL;
curr->pid = myPids[i];
pidList = curr;
if (hProcHandle) {
RegisterWaitForSingleObject(&curr->hProcessExit, hProcHandle, WaitOrTimerCallback, (void *)curr->pid, INFINITE, WT_EXECUTEONLYONCE);
}
}
else {
while (curr)
{
if (curr->pid == myPids[i]) {
break;
}
p = curr;
curr = curr->next;
}
//pid not found: add new member
if (!curr) {
hProcHandle = OpenProcess(SYNCHRONIZE, FALSE, myPids[i]);
curr = (MONITOR_PIDS*)calloc(1, sizeof(MONITOR_PIDS));
curr->pid = myPids[i];
p->next = curr;
curr->next = NULL;
if (hProcHandle) {
RegisterWaitForSingleObject(&hNewHandle, hProcHandle, WaitOrTimerCallback, (void *)curr->pid, INFINITE, WT_EXECUTEONLYONCE);
}
}
}
}
}
//---------------------------------------------------------------------------
// ProcessStartMonitor
//---------------------------------------------------------------------------
DWORD ProcessStartMonitor(void *arg) {
DWORD rc;
if (!heventProcessStart) {
heventProcessStart = CreateEvent(0, FALSE, FALSE, SESSION_PROCESS);
if (!heventProcessStart) {
//Can't start monitor thread!
return 0;
}
}
while (1) {
rc = WaitForSingleObject(heventProcessStart, INFINITE);
EnterCriticalSection(&ProcessCritSec);
SbieApi_EnumProcess(NULL, pids);
AddPid(pids);
LeaveCriticalSection(&ProcessCritSec);
}
return 0;
}
//---------------------------------------------------------------------------
// Add_LL_Entry
//---------------------------------------------------------------------------
_FX void Add_LL_Entry(
LINGER_LEADER **lingers, ULONG *inout_count, const WCHAR *image)
{
ULONG linger_count = *inout_count;
if (linger_count >= MAX_LINGER_LEADER_COUNT)
return;
lingers[linger_count] = HeapAlloc(
GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS,
sizeof(LINGER_LEADER) + (wcslen(image) + 4) * sizeof(WCHAR));
lingers[linger_count]->orig_pid = NULL;
lingers[linger_count]->curr_pid = NULL;
wcscpy(lingers[linger_count]->image, image);
++linger_count;
*inout_count = linger_count;
}
//---------------------------------------------------------------------------
// LingerEnumWindowsProc
//---------------------------------------------------------------------------
_FX BOOL LingerEnumWindowsProc(HWND hwnd, LPARAM lParam)
{
if (GetWindowLong(hwnd, GWL_STYLE) & WS_VISIBLE) {
ULONG *pids = (ULONG *)lParam;
ULONG i;
ULONG idProcess = 0;
GetWindowThreadProcessId(hwnd, &idProcess);
if (idProcess) {
for (i = 0; i < 510; ++i) {
if (! pids[i])
break;
if (pids[i] == idProcess) {
i = 510;
break;
}
}
if (i < 510) {
pids[i] = idProcess;
pids[i + 1] = 0;
}
}
}
return TRUE;
}
//---------------------------------------------------------------------------
// DoLingerLeader
//---------------------------------------------------------------------------
int DoLingerLeader(void)
{
ULONG *wnd_pids;
ULONG i, j;
HANDLE pids_i;
WCHAR image[128];
PROCESS_DATA *myData;
LINGER_LEADER **lingers;
LINGER_LEADER **leaders;
ULONG linger_count, leader_count, process_count;
LONG rc;
BOOLEAN any_leaders;
pids = HeapAlloc(
GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, sizeof(ULONG) * 512);
wnd_pids = HeapAlloc(
GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, sizeof(ULONG) * 512);
//
// handle linger/leader process terminations
//
linger_count = 0;
leader_count = 0;
lingers = NULL;
leaders = NULL;
any_leaders = FALSE;
InitializeCriticalSection(&ProcessCritSec);
heventRpcSs = CreateEvent(0, FALSE, FALSE, NULL);
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ProcessStartMonitor, NULL, 0, NULL);
if (1) {
//
// read and store LingerProcess configuration
//
lingers = (LINGER_LEADER**)HeapAlloc(
GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS,
sizeof(LINGER_LEADER *) * MAX_LINGER_LEADER_COUNT);
while (1)
{
rc = SbieApi_QueryConfAsIs(
NULL, L"LingerProcess", linger_count,
image, sizeof(WCHAR) * 120);
if (rc != 0)
break;
Add_LL_Entry(lingers, &linger_count, image);
}
//
// see which of the LingerProcess programs were already active
// before SandboxieRpcSs started. they will not be considered
// LingerProcess programs and will not be terminated
//
SbieApi_EnumProcess(NULL, pids);
AddPid(pids);
for (i = 1; i <= pids[0]; ++i) {
pids_i = (HANDLE) (ULONG_PTR) pids[i];
SbieApi_QueryProcess(pids_i, NULL, image, NULL, NULL);
for (j = 0; j < linger_count; ++j) {
if (_wcsicmp(lingers[j]->image, image) == 0) {
lingers[j]->orig_pid = pids_i;
break;
}
}
}
//
// add standard lingers. note that we don't check if any of
// the following processes was already active before we started
//
Add_LL_Entry(lingers, &linger_count, _SandboxieDcomLaunch);
Add_LL_Entry(lingers, &linger_count, _SandboxieCrypto);
Add_LL_Entry(lingers, &linger_count, _SandboxieBITS);
Add_LL_Entry(lingers, &linger_count, _SandboxieWUAU);
Add_LL_Entry(lingers, &linger_count, _wuauclt);
Add_LL_Entry(lingers, &linger_count, _TrustedInstaller);
Add_LL_Entry(lingers, &linger_count, _tiworker);
//
// read and store LeaderProcess configuration
//
leaders = HeapAlloc(
GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS,
sizeof(LINGER_LEADER *) * MAX_LINGER_LEADER_COUNT);
while (1) {
rc = SbieApi_QueryConfAsIs(
NULL, L"LeaderProcess", leader_count,
image, sizeof(WCHAR) * 120);
if (rc != 0)
break;
Add_LL_Entry(leaders, &leader_count, image);
}
}
//
// do StartService and StartProgram settings
//
if (1)
{
// extern DWORD ServiceStatus_CurrentState;
myData = my_findProcessData(L"RPCSS", 0);
if (!myData) {
return 0;
}
WaitForSingleObject(myData->hStartLingerEvent, INFINITE);
for (i = 0; ; ++i) {
rc = SbieApi_QueryConfAsIs(
NULL, L"StartService", i, image, sizeof(WCHAR) * 120);
if (rc != 0)
break;
SbieDll_StartBoxedService(image, TRUE);
}
for (i = 0; ; ++i) {
rc = SbieApi_QueryConfAsIs(
NULL, L"StartProgram", i, image, sizeof(WCHAR) * 120);
if (rc != 0)
break;
SbieDll_ExpandAndRunProgram(image);
}
}
//
// now just wait until such time when our COM framework is
// the only things left running in the sandbox, and then die
//
SbieApi_EnumProcess(NULL, pids);
process_count = pids[0];
while (1)
{
BOOLEAN any_leaders_local = FALSE;
BOOLEAN terminate_and_stop = TRUE;
//
// wait for the process exit event (my_event)
//
WaitForSingleObject(heventRpcSs, INFINITE);
EnterCriticalSection(&ProcessCritSec);
SbieApi_EnumProcess(NULL, pids);
process_count = pids[0];
//
// query running processes
//
for (i = 1; i <= pids[0]; ++i) {
//
// if the process in question was started by Start.exe,
// then we do not treat the process as lingering. except:
//
// - if the process is running as LocalSystem, it was probably
// spawned using Start.exe by SbieSvc::ServiceServer.
//
// - if the process is SandboxieCrypto, which can get invoked
// by Start.exe in some cases
//
BOOLEAN excluded_from_linger = FALSE;
BOOLEAN is_local_system_sid = FALSE;
pids_i = (HANDLE)(ULONG_PTR)pids[i];
image[0] = L'\0';
if (0 == SbieApi_QueryProcess(pids_i, NULL, image, NULL, NULL)
&& _wcsicmp(image, _SandboxieCrypto) != 0) {
//
// check if this is a local system process
//
HANDLE ProcessHandle = 0;
SbieApi_OpenProcess(&ProcessHandle, pids_i);
if (ProcessHandle) {
extern BOOL CheckProcessLocalSystem(HANDLE); // common.h
if (CheckProcessLocalSystem(ProcessHandle))
is_local_system_sid = TRUE;
CloseHandle(ProcessHandle);
}
if (!is_local_system_sid) {
//
// then check if the process was started explicitly
// (via forced mechanism or as a child of start.exe)
// and then don't terminate it as a linger
//
// (note that sevice processes running as local system
// are also children of start.exe, but in that case,
// is_local_system_sid would be TRUE and we would not
// reach this point.)
//
ULONG64 ProcessFlags =
SbieApi_QueryProcessInfo(pids_i, 0);
if (ProcessFlags & (SBIE_FLAG_FORCED_PROCESS |
SBIE_FLAG_PARENT_WAS_START_EXE |
SBIE_FLAG_PROCESS_IS_START_EXE )) {
excluded_from_linger = TRUE;
}
}
}
//
// ignore our own process
//
if (_wcsicmp(image, _SandboxieRpcSs) == 0)
continue;
//
// find a leader process
//
for (j = 0; j < leader_count; ++j) {
if (_wcsicmp(leaders[j]->image, image) == 0) {
any_leaders_local = TRUE;
break;
}
}
//
// for each process we find, check if the image appears on
// the linger list. if so, we update the last known pid
// for that linger. but if that process was already active
// before RpcSs started, then don't kill any lingers
//
// alternatively, if the process is not on the linger list,
// then we won't be killing any of the LingerProcess yet
//
for (j = 0; j < linger_count; ++j) {
if (_wcsicmp(lingers[j]->image, image) == 0) {
lingers[j]->curr_pid = pids_i;
if (excluded_from_linger)
lingers[j]->orig_pid = pids_i;
if (pids_i == lingers[j]->orig_pid)
terminate_and_stop = FALSE;
break;
}
}
if (j == linger_count) {
//
// we found an active process that is not a linger process,
// so reset the flag to kill lingers
//
terminate_and_stop = FALSE;
}
}
//
// if leader processes ended (i.e. after being active for some time)
// then kill all processes
//
if (any_leaders && (! any_leaders_local)) {
terminate_and_stop = TRUE;
goto do_kill_all;
} else
any_leaders = any_leaders_local;
//
// don't terminate if a lingering process has an open window
//
if (terminate_and_stop) {
wnd_pids[0] = 0;
EnumWindows(LingerEnumWindowsProc, (LPARAM)wnd_pids);
for (i = 1; i <= pids[0]; ++i) {
for (j = 0; j < 510; ++j) {
if (! wnd_pids[j])
break;
if (wnd_pids[j] == pids[i]) {
terminate_and_stop = FALSE;
break;
}
}
if (! terminate_and_stop)
break;
}
}
//
// don't terminate if a lingering process has just started recently
//
if (terminate_and_stop) {
for (i = 1; i <= pids[0]; ++i) {
HANDLE hProcess = NULL;
ULONG64 ProcessFlags = SbieApi_QueryProcessInfo(
(HANDLE) (ULONG_PTR) pids[i], 0);
if (! (ProcessFlags & SBIE_FLAG_IMAGE_FROM_SBIE_DIR)) {
hProcess = OpenProcess(
PROCESS_QUERY_INFORMATION, FALSE, pids[i]);
}
if (hProcess) {
FILETIME time, time1, time2, time3;
BOOL ok = GetProcessTimes(
hProcess, &time, &time1, &time2, &time3);
if (ok) {
LARGE_INTEGER liProcess, liCurrent;
__int64 diff;
liProcess.LowPart = time.dwLowDateTime;
liProcess.HighPart = time.dwHighDateTime;
GetSystemTimeAsFileTime(&time);
liCurrent.LowPart = time.dwLowDateTime;
liCurrent.HighPart = time.dwHighDateTime;
diff = liCurrent.QuadPart - liProcess.QuadPart;
if (diff < SECONDS(5))
terminate_and_stop = FALSE;
}
CloseHandle(hProcess);
}
if (! terminate_and_stop)
break;
}
}
//
// kill all programs and quit
//
LeaveCriticalSection(&ProcessCritSec);
do_kill_all:
if (terminate_and_stop) {
SbieDll_KillAll(-1, NULL);
break;
}
}
// this process is no longer needed
ExitProcess(0);
return 0;
}

View File

@ -0,0 +1,87 @@
// Copyright 2004-2020 Sandboxie Holdings, LLC
//
// 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 <https://www.gnu.org/licenses/>.
//
//Microsoft Developer Studio generated resource script.
//
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
#ifndef _MAC
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
#include "common/my_version.h"
VS_VERSION_INFO VERSIONINFO
FILEVERSION MY_VERSION_BINARY
PRODUCTVERSION MY_VERSION_BINARY
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x40004L
FILETYPE 0x2L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "Comments", "\0"
VALUE "CompanyName", MY_COMPANY_NAME_STRING "\0"
VALUE "FileDescription", MY_PRODUCT_NAME_STRING " COM Services (RPC)\0"
VALUE "FileVersion", MY_VERSION_STRING "\0"
OPTIONAL_VALUE("InternalName", "RpcSs\0")
VALUE "LegalCopyright", MY_COPYRIGHT_STRING "\0"
VALUE "LegalTrademarks", "\0"
OPTIONAL_VALUE("OriginalFilename", "SandboxieRpcSs.exe\0")
VALUE "PrivateBuild", "\0"
VALUE "ProductName", MY_PRODUCT_NAME_STRING "\0"
VALUE "ProductVersion", MY_VERSION_STRING "\0"
VALUE "SpecialBuild", "\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
#endif // !_MAC
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,477 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Sandboxie RPCSS Service
//---------------------------------------------------------------------------
#include <ntstatus.h>
#define WIN32_NO_STATUS
typedef long NTSTATUS;
#include <windows.h>
#include <winsock2.h>
#include <stdlib.h>
#include <stdio.h>
#include "common/defines.h"
#include "common/my_version.h"
#include "core/svc/msgids.h"
//---------------------------------------------------------------------------
// Variables
//---------------------------------------------------------------------------
#define SINGLE_INSTANCE_MUTEX_NAME L"ServiceInitComplete_Mutex1"
const WCHAR *ServiceTitle = SANDBOXIE L" RpcSs";
#include "../common.h"
#include "../privs.h"
HANDLE ComPlusCOMRegTable = NULL;
const WCHAR *ComPlusCOMRegTable_Name = L"Global\\ComPlusCOMRegTable";
const char *_localhost = "localhost";
static ULONG_PTR __sys_bind = 0;
static ULONG_PTR __sys_listen = 0;
static ULONG_PTR __sys_gethostname = 0;
static ULONG_PTR __sys_gethostbyname = 0;
static ULONG_PTR __sys_WSASocketW = 0;
static ULONG_PTR __sys_OpenThreadToken = 0;
static ULONG_PTR __sys_RegOpenKeyExW = 0;
static ULONG_PTR __sys_RegQueryValueExW = 0;
//---------------------------------------------------------------------------
// my_CreateFileMapping
//---------------------------------------------------------------------------
_FX HANDLE my_CreateFileMappingW(
HANDLE hFile,
LPSECURITY_ATTRIBUTES lpAttributes,
DWORD flProtect,
DWORD dwMaximumSizeHigh,
DWORD dwMaximumSizeLow,
LPCWSTR lpName)
{
typedef HANDLE (__stdcall *P_CreateFileMappingW)(
HANDLE hFile,
LPSECURITY_ATTRIBUTES lpAttributes,
DWORD flProtect,
DWORD dwMaximumSizeHigh,
DWORD dwMaximumSizeLow,
LPCWSTR lpName);
HANDLE handle = 0;
if (lpName && _wcsicmp(lpName, ComPlusCOMRegTable_Name) == 0)
handle = ComPlusCOMRegTable;
if (! handle) {
handle = ((P_CreateFileMappingW)__sys_CreateFileMappingW)(
hFile, lpAttributes, flProtect,
dwMaximumSizeHigh, dwMaximumSizeLow, lpName);
}
return handle;
}
//---------------------------------------------------------------------------
// my_bind
//---------------------------------------------------------------------------
_FX int my_bind(SOCKET s, const struct sockaddr *name, int namelen)
{
return 0;
}
//---------------------------------------------------------------------------
// my_listen
//---------------------------------------------------------------------------
_FX int my_listen(SOCKET s, int backlog)
{
return 0;
}
//---------------------------------------------------------------------------
// my_gethostname
//---------------------------------------------------------------------------
_FX int my_gethostname(char *name, int namelen)
{
if (namelen >= 10) {
strcpy(name, _localhost);
return 0;
} else {
WSASetLastError(WSAEFAULT);
return SOCKET_ERROR;
}
}
//---------------------------------------------------------------------------
// my_gethostbyname
//---------------------------------------------------------------------------
struct hostent *my_gethostbyname(const char *name)
{
typedef struct hostent *(*P_gethostbyname)(const char *name);
static struct hostent my_hostent;
static char *my_aliases = NULL;
static ULONG_PTR my_addr_list[2] = { 0, 0 };
static ULONG my_ip = 0x0100007f;
if (strcmp(name, _localhost) != 0)
return ((P_gethostbyname)__sys_gethostbyname)(name);
my_hostent.h_name = (char *)_localhost;
my_hostent.h_aliases = &my_aliases;
my_hostent.h_addrtype = AF_INET;
my_hostent.h_length = sizeof(ULONG);
my_hostent.h_addr_list = (char **)my_addr_list;
my_addr_list[0] = (ULONG_PTR)&my_ip;
return &my_hostent;
}
//---------------------------------------------------------------------------
// my_WSASocketW
//---------------------------------------------------------------------------
_FX SOCKET my_WSASocketW(
int af, int type, int protocol, LPWSAPROTOCOL_INFO lpProtocolInfo,
GROUP g, DWORD dwFlags)
{
WSASetLastError(WSAEACCES);
return INVALID_SOCKET;
}
//---------------------------------------------------------------------------
// my_OpenThreadToken
//---------------------------------------------------------------------------
_FX BOOL my_OpenThreadToken(
HANDLE ThreadHandle, DWORD DesiredAccess, BOOL OpenAsSelf,
PHANDLE TokenHandle)
{
typedef BOOL (*P_OpenThreadToken)(
HANDLE ThreadHandle, DWORD DesiredAccess, BOOL OpenAsSelf,
PHANDLE TokenHandle);
BOOL ok = ((P_OpenThreadToken)__sys_OpenThreadToken)(
ThreadHandle, DesiredAccess, OpenAsSelf, TokenHandle);
if ((! ok) && GetLastError() == ERROR_BAD_IMPERSONATION_LEVEL
&& (! OpenAsSelf)) {
OpenAsSelf = TRUE;
ok = ((P_OpenThreadToken)__sys_OpenThreadToken)(
ThreadHandle, DesiredAccess, OpenAsSelf, TokenHandle);
}
return ok;
}
//---------------------------------------------------------------------------
// my_RegOpenKeyExW
//---------------------------------------------------------------------------
_FX LONG my_RegOpenKeyExW(
HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired,
PHKEY phkResult)
{
typedef BOOL (*P_RegOpenKeyExW)(
HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired,
PHKEY phkResult);
typedef BOOL (*P_SetThreadToken)(PHANDLE Thread, HANDLE Token);
LONG rc = ((P_RegOpenKeyExW)__sys_RegOpenKeyExW)(
hKey, lpSubKey, ulOptions, samDesired, phkResult);
if (rc == ERROR_BAD_IMPERSONATION_LEVEL) {
ULONG LastError = GetLastError();
HANDLE Token;
BOOL ok = OpenThreadToken(
NtCurrentThread(), TOKEN_IMPERSONATE, TRUE, &Token);
if (ok && Token) {
((P_SetThreadToken)__sys_SetThreadToken)(NULL, NULL);
rc = ((P_RegOpenKeyExW)__sys_RegOpenKeyExW)(
hKey, lpSubKey, ulOptions, samDesired, phkResult);
((P_SetThreadToken)__sys_SetThreadToken)(NULL, Token);
}
SetLastError(LastError);
}
return rc;
}
//---------------------------------------------------------------------------
// my_RegQueryValueKeyExW
//---------------------------------------------------------------------------
_FX LONG my_RegQueryValueExW(
HKEY hKey, LPCWSTR lpValueName, LPDWORD lpReserved,
LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData)
{
typedef BOOL (*P_RegQueryValueExW)(
HKEY hKey, LPCWSTR lpValueName, LPDWORD lpReserved,
LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData);
typedef BOOL (*P_SetThreadToken)(PHANDLE Thread, HANDLE Token);
LONG rc = ((P_RegQueryValueExW)__sys_RegQueryValueExW)(
hKey, lpValueName, lpReserved, lpType, lpData, lpcbData);
if (rc == ERROR_BAD_IMPERSONATION_LEVEL) {
ULONG LastError = GetLastError();
HANDLE Token;
BOOL ok = OpenThreadToken(
NtCurrentThread(), TOKEN_IMPERSONATE, TRUE, &Token);
if (ok && Token) {
((P_SetThreadToken)__sys_SetThreadToken)(NULL, NULL);
rc = ((P_RegQueryValueExW)__sys_RegQueryValueExW)(
hKey, lpValueName, lpReserved, lpType, lpData, lpcbData);
((P_SetThreadToken)__sys_SetThreadToken)(NULL, Token);
}
SetLastError(LastError);
}
return rc;
}
//---------------------------------------------------------------------------
// Start_WinSock
//---------------------------------------------------------------------------
_FX BOOL Start_WinSock(void)
{
WORD wVersionRequested;
WSADATA wsaData;
BOOL hook_success = TRUE;
wVersionRequested = MAKEWORD(2, 0);
if (WSAStartup(wVersionRequested, &wsaData) != 0) {
ErrorMessageBox(L"Could not initialize WinSock");
return FALSE;
}
HOOK_WIN32(bind);
HOOK_WIN32(listen);
HOOK_WIN32(gethostname);
HOOK_WIN32(gethostbyname);
HOOK_WIN32(WSASocketW);
HOOK_WIN32(OpenThreadToken);
HOOK_WIN32(RegOpenKeyExW);
HOOK_WIN32(RegQueryValueExW);
if (! hook_success) {
ErrorMessageBox(L"Could not intercept WinSock services");
return FALSE;
}
return TRUE;
}
//---------------------------------------------------------------------------
// StartRpcEptMapper
//---------------------------------------------------------------------------
BOOL StartRpcEptMapper(void)
{
static WCHAR ServiceName2[16];
WCHAR EventName[128];
HANDLE hEvent;
BOOL ok;
//
// windows 7 requires an additional RpcEptMapper service
//
if (! KernelBase)
return TRUE;
if (IsWindows81)
CreateEvent(NULL, FALSE, TRUE, L"Global\\SC_AutoStartComplete");
wcscpy(ServiceName2, L"RpcEptMapper");
//
// prepare event for service
//
swprintf(EventName, SBIE_BOXED_ L"ServiceInitComplete_%s", ServiceName2);
hEvent = CreateEvent(NULL, TRUE, FALSE, EventName);
if (! hEvent)
return FALSE;
//
// start RpcEptMapper service on Windows 7
//
ok = Service_Start_ServiceMain(
ServiceName2, L"rpcepmap.dll", "ServiceMain", TRUE);
if (! ok)
return FALSE;
//
// wait for init complete
//
WaitForSingleObject(hEvent, INFINITE);
//
// reset service-tracking variables
//
return TRUE;
}
//---------------------------------------------------------------------------
// WinMain
//---------------------------------------------------------------------------
_FX int __stdcall WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
extern int DoLingerLeader(void);
extern ULONG Sxs_Thread(void *arg);
extern ULONG Dde_Thread(void *arg);
WCHAR ServiceName[16];
BOOL ok;
if (! (SbieApi_QueryProcessInfo(0, 0) & SBIE_FLAG_VALID_PROCESS))
return EXIT_FAILURE;
if (! CheckSingleInstance()) {
// return special error code to indicate elective termination
// because this is a duplicate copy of SandboxieRpcSs.exe
// see also core/dll/ipc_start.c
return STATUS_LICENSE_QUOTA_EXCEEDED;
}
SetupExceptionHandler();
if (1) {
ULONG idThread;
HANDLE hThread = CreateThread(
NULL, 0, Sxs_Thread, 0, CREATE_SUSPENDED, &idThread);
if (hThread) {
SetThreadPriority(hThread, THREAD_PRIORITY_ABOVE_NORMAL);
ResumeThread(hThread);
CloseHandle(hThread);
}
}
if (!SbieDll_IsOpenCOM()) {
Check_Windows_7();
// pretend we are the SCM
if (!Hook_Service_Control_Manager())
return EXIT_FAILURE;
// hook privilege-related functions
if (!Hook_Privilege())
return EXIT_FAILURE;
// start WinSock
if (!Start_WinSock())
return EXIT_FAILURE;
// create COM shared memory sections
ComPlusCOMRegTable = CreateFileMapping(
INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE | SEC_COMMIT,
0, (PAGE_SIZE * 2), ComPlusCOMRegTable_Name);
if (!StartRpcEptMapper())
return EXIT_FAILURE;
// start rpcss service
wcscpy(ServiceName, L"RPCSS");
ok = Service_Start_ServiceMain(
ServiceName, L"rpcss.dll", "ServiceMain", TRUE);
if (!ok)
return EXIT_FAILURE;
}
else {
PROCESS_DATA *myData;
myData = my_findProcessData(L"RPCSS", 1);
if (!myData) {
return EXIT_FAILURE;
}
myData->state = SERVICE_RUNNING;
InitComplete(myData);
}
if (1) {
ULONG idThread;
HANDLE hThread = CreateThread(
NULL, 0, (LPTHREAD_START_ROUTINE)Dde_Thread, 0, CREATE_SUSPENDED, &idThread);
if (hThread) {
SetThreadPriority(hThread, THREAD_PRIORITY_ABOVE_NORMAL);
ResumeThread(hThread);
CloseHandle(hThread);
}
}
if (1) {
MSG_HEADER req;
req.length = sizeof(req);
req.msgid = MSGID_SBIE_INI_RUN_SBIE_CTRL;
SbieDll_CallServer(&req);
}
return DoLingerLeader();
}

View File

@ -0,0 +1,631 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Side-by-Side (WinSxS) Service for Sandboxed Programs
//---------------------------------------------------------------------------
#include <ntstatus.h>
#define WIN32_NO_STATUS
typedef long NTSTATUS;
#include <windows.h>
#define COBJMACROS
#include <objbase.h>
#include "core/dll/sbiedll.h"
#include "common/win32_ntddk.h"
#include "common/defines.h"
#include "common/my_version.h"
//---------------------------------------------------------------------------
// Defines
//---------------------------------------------------------------------------
#define SXS_TEXT_LEN (512 * 1024)
//---------------------------------------------------------------------------
// Structures and Types
//---------------------------------------------------------------------------
typedef struct _SXS_GENERATE_ACTIVATION_CONTEXT_ARGS {
ULONG Zero00;
USHORT ArchId;
LANGID LangId;
WCHAR *StoreDir;
ULONG Zero0C;
IUnknown *ManifestStream;
WCHAR *SourcePath;
ULONG Two;
IUnknown *ConfigStream;
WCHAR *ConfigPath;
ULONG Zero24;
ULONG Zero28;
ULONG Zero2C;
ULONG Zero30;
HANDLE hSection;
ULONG Zero38;
ULONG Zero3C;
ULONG Zero40;
ULONG Zero44;
ULONG Zero48;
ULONG Zero4C;
ULONG Zero50;
ULONG Zero54;
ULONG Zero58;
ULONG Zero5C;
ULONG Zero60;
ULONG Zero64;
ULONG Zero68;
ULONG Zero6C;
ULONG Zero70;
} SXS_GENERATE_ACTIVATION_CONTEXT_ARGS;
//---------------------------------------------------------------------------
// Functions
//---------------------------------------------------------------------------
static void Sxs_Error(ULONG level, ULONG status);
static BOOLEAN Sxs_Init(void);
ULONG Sxs_Thread(void *arg);
static void Sxs_Request(
UCHAR *data, ULONG data_len, UCHAR **rsp_data, ULONG *rsp_len);
static void Sxs_Generate(UCHAR *buf, HANDLE *hSection);
static IUnknown *Sxs_CreateStreamFromBuffer(UCHAR *Text);
static void Sxs_GenerateHelper(
SXS_GENERATE_ACTIVATION_CONTEXT_ARGS *args, WCHAR *LangNames);
//---------------------------------------------------------------------------
typedef HRESULT (*P_CreateStreamOnHGlobal)(
HGLOBAL hGlobal,
BOOL fDeleteOnRelease,
void **ppStream);
typedef ULONG (*P_SxsGenerateActivationContext)(
SXS_GENERATE_ACTIVATION_CONTEXT_ARGS *args);
//---------------------------------------------------------------------------
static P_CreateStreamOnHGlobal pCreateStreamOnHGlobal = NULL;
static P_SxsGenerateActivationContext pSxsGenerateActivationContext = NULL;
//---------------------------------------------------------------------------
// Variables
//---------------------------------------------------------------------------
static BOOLEAN Sxs_WindowsVista = FALSE;
static BOOLEAN Sxs_Windows7 = FALSE;
static BOOLEAN Sxs_Windows8 = FALSE;
static BOOLEAN Sxs_Windows10 = FALSE;
static const WCHAR *Sxs_QueueName = L"RPCSS_SXS";
static HANDLE Sxs_QueueEventHandle = NULL;
//---------------------------------------------------------------------------
// Sxs_Error
//---------------------------------------------------------------------------
_FX void Sxs_Error(ULONG level, ULONG status)
{
extern const WCHAR *ServiceTitle;
SbieApi_Log(2203, L"%S - (%S) [%02X/%08X]",
Sxs_QueueName, ServiceTitle, level, status);
}
//---------------------------------------------------------------------------
// Sxs_Init
//---------------------------------------------------------------------------
_FX BOOLEAN Sxs_Init(void)
{
HMODULE mod;
OSVERSIONINFO osvi;
WCHAR EvtName[128];
HANDLE EvtHandle;
ULONG status = -1;
int retry = 0;
//
// initialize stuff needed to call SxsGenerateActivationContext
//
memzero(&osvi, sizeof(OSVERSIONINFO));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx((OSVERSIONINFO *)&osvi);
if (osvi.dwMajorVersion == 10) {
Sxs_Windows10 = TRUE;
}
else if (osvi.dwMajorVersion == 6) {
if (osvi.dwMinorVersion >= 2) // Windows 8, Windows 8.1, Windows 10 (Early builds)
Sxs_Windows8 = TRUE;
else if (osvi.dwMinorVersion == 1)
Sxs_Windows7 = TRUE;
else if (osvi.dwMinorVersion == 0)
Sxs_WindowsVista = TRUE;
else
return FALSE;
} else if (osvi.dwMajorVersion == 5) {
if (osvi.dwMinorVersion == 0)
return FALSE;
} else
return FALSE;
mod = 0;
// There is a chance for sxs.dll and ole32.dll to fail to load. There
// is a dependency on an internal component of rpcss for these dll's to
// load. A simple retry fixes this issue.
//
// Also, note that if this thread (the sxs thread) fails to start in rpcss no
// other process can start in the sandbox. It is absolutely critical for
// Windows versions Vista and above. Because of this, additional error messages
// are added to various thread exit paths to help troubleshoot issues with
// this thread starting.
while (!mod && (retry++ < 20)) {
mod = LoadLibrary(L"sxs.dll");
if (!mod) {
NtYieldExecution();
}
}
if (mod) {
pSxsGenerateActivationContext = (P_SxsGenerateActivationContext)
GetProcAddress(mod, "SxsGenerateActivationContext");
}
else {
Sxs_Error(0x77, status);
return FALSE;
}
mod = 0;
retry = 0;
while (!mod && (retry++ < 20)) {
mod = LoadLibrary(L"ole32.dll");
if (!mod) {
NtYieldExecution();
}
}
if (mod) {
pCreateStreamOnHGlobal = (P_CreateStreamOnHGlobal)
GetProcAddress(mod, "CreateStreamOnHGlobal");
}
else {
Sxs_Error(0x88, status);
return FALSE;
}
if ((! pSxsGenerateActivationContext) || (! pCreateStreamOnHGlobal)) {
Sxs_Error(0x44, status);
return FALSE;
}
//
// create the queue
//
for (retry = 0; retry < 5 * 3; ++retry) {
status = SbieDll_QueueCreate(Sxs_QueueName, &Sxs_QueueEventHandle);
if (status != STATUS_OBJECT_NAME_COLLISION)
break;
Sleep(1000 / 3);
}
if (status != 0) {
Sxs_Error(0x11, status);
return FALSE;
}
wcscpy(EvtName, SBIE_BOXED_);
wcscat(EvtName, Sxs_QueueName);
wcscat(EvtName, L"_READY");
EvtHandle = CreateEvent(NULL, TRUE, FALSE, EvtName);
if (EvtHandle) {
SetEvent(EvtHandle);
}
return TRUE;
}
//---------------------------------------------------------------------------
// Sxs_Thread
//---------------------------------------------------------------------------
_FX ULONG Sxs_Thread(void *arg)
{
ULONG req_id, data_len, rsp_len;
UCHAR *data_ptr, *rsp_data;
ULONG error = -1;
ULONG status;
if (! Sxs_Init())
return 0;
while (1) {
WaitForSingleObject(Sxs_QueueEventHandle, INFINITE);
while (1) {
status = SbieDll_QueueGetReq(
Sxs_QueueName, NULL, NULL, &req_id, &data_ptr, &data_len);
if (status != 0 && status != STATUS_END_OF_FILE)
Sxs_Error(0x22, status);
if (! req_id)
break;
rsp_len = 0;
if (data_len && data_len <= SXS_TEXT_LEN * 2) {
Sxs_Request(data_ptr, data_len, &rsp_data, &rsp_len);
}
if (! rsp_len) {
rsp_len = sizeof(ULONG);
rsp_data = (UCHAR *)&error;
}
status = SbieDll_QueuePutRpl(
Sxs_QueueName, req_id, rsp_data, rsp_len);
if (status != 0 && status != STATUS_END_OF_FILE)
Sxs_Error(0x33, status);
if (rsp_data != (UCHAR *)&error)
HeapFree(GetProcessHeap(), 0, rsp_data);
SbieDll_FreeMem(data_ptr);
}
}
return 0;
}
//---------------------------------------------------------------------------
// Sxs_Request
//---------------------------------------------------------------------------
_FX void Sxs_Request(
UCHAR *data, ULONG data_len, UCHAR **rsp_data, ULONG *rsp_len)
{
HANDLE hSection = NULL;
Sxs_Generate(data, &hSection);
if (hSection == (HANDLE)(ULONG_PTR)-1) {
// see also Sxs_CallService in core/dll/sxs.c
UCHAR *data = HeapAlloc(GetProcessHeap(), 0, 20);
if (data) {
memcpy(data, "*UseAltCreateActCtx*", 20);
*rsp_len = 20;
*rsp_data = data;
}
} else if (hSection) {
const ULONG xViewShare = 1;
NTSTATUS status;
LARGE_INTEGER ZeroOffset;
SIZE_T ViewSize = 0;
void *MappedBase = NULL;
ZeroOffset.QuadPart = 0;
status = NtMapViewOfSection(
hSection, NtCurrentProcess(), &MappedBase,
0, 0, &ZeroOffset, &ViewSize, xViewShare,
MEM_PHYSICAL, PAGE_READONLY);
if (NT_SUCCESS(status)) {
UCHAR *data = HeapAlloc(GetProcessHeap(), 0, ViewSize);
if (data) {
memcpy(data, MappedBase, ViewSize);
*rsp_len = (ULONG)ViewSize;
*rsp_data = data;
}
NtUnmapViewOfSection(NtCurrentProcess(), (void *)MappedBase);
}
CloseHandle(hSection);
}
}
//---------------------------------------------------------------------------
// Sxs_Generate
//---------------------------------------------------------------------------
_FX void Sxs_Generate(UCHAR *buf, HANDLE *hSection)
{
ULONG *ptr4;
WCHAR *ptr2;
UCHAR *ptr1;
ULONG ArchId;
ULONG LangId;
WCHAR *LangNames;
WCHAR *lpDirectory;
WCHAR *lpSourcePath;
WCHAR *lpConfigPath;
UCHAR *lpManifestText;
UCHAR *lpConfigText;
SXS_GENERATE_ACTIVATION_CONTEXT_ARGS args;
BOOLEAN ok;
*hSection = NULL;
ptr4 = (ULONG *)buf;
if (*ptr4 != 'xobs') // signature
return;
++ptr4; // skip ULONG64
++ptr4;
ArchId = *ptr4;
++ptr4; // skip ULONG
LangId = *ptr4;
++ptr4; // skip ULONG
ptr2 = (WCHAR *)ptr4;
if (wcslen(ptr2) > 64)
return;
LangNames = ptr2;
ptr2 += wcslen(ptr2) + 1;
if (wcslen(ptr2) > 1024)
return;
lpDirectory = ptr2;
ptr2 += wcslen(ptr2) + 1;
if (wcslen(ptr2) > 1024)
return;
lpSourcePath = ptr2;
ptr2 += wcslen(ptr2) + 1;
if (wcslen(ptr2) > 1024)
return;
lpConfigPath = ptr2;
ptr2 += wcslen(ptr2) + 1;
ptr1 = (UCHAR *)ptr2;
if (strlen(ptr1) > SXS_TEXT_LEN)
return;
lpManifestText = ptr1;
ptr1 += strlen(ptr1) + 1;
if (strlen(ptr1) > SXS_TEXT_LEN)
return;
lpConfigText = ptr1;
ptr1 += strlen(ptr1) + 1;
if (*ptr1 != '*')
return;
//
//
//
/*{ WCHAR txt[512];
wsprintf(txt, L"SandboxieRpcSs Generate Activation Context\n"); OutputDebugString(txt);
wsprintf(txt, L"Directory = %s\n", lpDirectory); OutputDebugString(txt);
wsprintf(txt, L"SourcePath = %s\n", lpSourcePath); OutputDebugString(txt);
wsprintf(txt, L"Languages = %s\n", LangNames); OutputDebugString(txt);
wsprintf(txt, L"------------------------------------------\n"); OutputDebugString(txt);
}*/
memzero(&args, sizeof(SXS_GENERATE_ACTIVATION_CONTEXT_ARGS));
args.Two = 2;
args.ArchId = (USHORT)ArchId;
args.LangId = (LANGID)LangId;
args.StoreDir = lpDirectory;
args.SourcePath = lpSourcePath;
ok = TRUE;
if (*lpManifestText) {
args.ManifestStream = Sxs_CreateStreamFromBuffer(lpManifestText);
if (! args.ManifestStream)
ok = FALSE;
} else
ok = FALSE;
if (ok && *lpConfigPath && *lpConfigText) {
args.ConfigPath = lpConfigPath;
args.ConfigStream = Sxs_CreateStreamFromBuffer(lpConfigText);
if (! args.ConfigStream)
ok = FALSE;
}
if (ok)
Sxs_GenerateHelper(&args, LangNames);
/*{ WCHAR txt[512];
wsprintf(txt, L"Result = %08X\n", args.hSection); OutputDebugString(txt);
wsprintf(txt, L"------------------------------------------\n"); OutputDebugString(txt);
}*/
if (args.ConfigStream)
IUnknown_Release(args.ConfigStream);
if (args.ManifestStream)
IUnknown_Release(args.ManifestStream);
*hSection = args.hSection;
}
//---------------------------------------------------------------------------
// Sxs_CreateStreamFromBuffer
//---------------------------------------------------------------------------
_FX IUnknown *Sxs_CreateStreamFromBuffer(UCHAR *Text)
{
IUnknown *pStream = NULL;
ULONG Length = strlen(Text);
HGLOBAL hGlobal = GlobalAlloc(GMEM_FIXED, Length);
if (hGlobal) {
void *pGlobal = GlobalLock(hGlobal);
if (pGlobal) {
memcpy(pGlobal, Text, Length);
GlobalUnlock(pGlobal);
if (pCreateStreamOnHGlobal(hGlobal, TRUE, &pStream) != S_OK)
pStream = NULL;
}
if (! pStream)
GlobalFree(hGlobal);
}
return pStream;
}
//---------------------------------------------------------------------------
// Sxs_GenerateHelper
//---------------------------------------------------------------------------
_FX void Sxs_GenerateHelper(
SXS_GENERATE_ACTIVATION_CONTEXT_ARGS *args, WCHAR *LangNames)
{
struct SXS_GENERATE_ACTIVATION_CONTEXT_VISTA_ARGS {
ULONG Zero00;
USHORT ArchId;
USHORT Zero06;
WCHAR *LangNames;
WCHAR *StoreDir;
ULONG Zero10;
IUnknown *ManifestStream;
WCHAR *SourcePath;
ULONG Two;
IUnknown *ConfigStream;
WCHAR *ConfigPath;
ULONG64 Zero28_2C;
#ifdef _WIN64
ULONG64 Zero30_34;
ULONG64 Zero38_3C;
HANDLE hSectionWin8;
HANDLE hSectionVista;
HANDLE hSectionWin7;
#else ! _WIN64
ULONG Zero30;
HANDLE hSectionWin8;
HANDLE hSectionVista;
HANDLE hSectionWin7;
ULONG64 Zero40_44;
ULONG64 Zero48_4C;
#endif _WIN64
ULONG64 Zero50_54;
ULONG64 Zero58_5C;
ULONG64 Zero60_64;
ULONG64 Zero68_6C;
ULONG64 Zero70_74;
ULONG64 Zero74_78; // Offset +0x0a0 Zero74_78 : Uint8B
BYTE unknownBytes[241]; // Win 10 18980 has added a bunch of unknown fields to this structure
} vista_args;
if (Sxs_WindowsVista || Sxs_Windows7 || Sxs_Windows8 || Sxs_Windows10) {
WCHAR *ptr = LangNames;
while (*ptr) {
if (*ptr == L'_')
*ptr = L'\0';
++ptr;
}
memzero(&vista_args, sizeof(vista_args));
vista_args.ArchId = args->ArchId;
vista_args.LangNames = LangNames;
vista_args.StoreDir = args->StoreDir;
vista_args.ManifestStream = args->ManifestStream;
vista_args.SourcePath = args->SourcePath;
vista_args.Two = args->Two;
vista_args.ConfigStream = args->ConfigStream;
vista_args.ConfigPath = args->ConfigPath;
if (pSxsGenerateActivationContext((void *)&vista_args)) {
if (Sxs_WindowsVista)
args->hSection = vista_args.hSectionVista;
else if (Sxs_Windows7)
args->hSection = vista_args.hSectionWin7;
else if (Sxs_Windows8 || Sxs_Windows10)
args->hSection = vista_args.hSectionWin8;
else
args->hSection = NULL;
if (! args->hSection) {
// in the esoteric case where pSxsGenerateActivationContext
// returns success but zero section, we want to signal to
// Sxs_CallService in core/dll/sxs.c to try alternate call
args->hSection = (HANDLE)(ULONG_PTR)-1;
}
} else
args->hSection = NULL;
} else {
if (! pSxsGenerateActivationContext(args))
args->hSection = NULL;
}
}

View File

@ -0,0 +1,129 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="SbieDebug|Win32">
<Configuration>SbieDebug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="SbieDebug|x64">
<Configuration>SbieDebug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="SbieRelease|Win32">
<Configuration>SbieRelease</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="SbieRelease|x64">
<Configuration>SbieRelease</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{42DB5510-0268-4655-B483-B9D6E4E48D62}</ProjectGuid>
<RootNamespace>SandboxWUAU</RootNamespace>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'" Label="PropertySheets">
<Import Project="..\..\..\Sandbox32.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'" Label="PropertySheets">
<Import Project="..\..\..\Sandbox64.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'" Label="PropertySheets">
<Import Project="..\..\..\Sandbox32.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'" Label="PropertySheets">
<Import Project="..\..\..\Sandbox64.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'">
<TargetName>SandboxieWUAU</TargetName>
<LibraryPath>$(WDKPATH)\lib\wnet\i386;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'">
<TargetName>SandboxieWUAU</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'">
<TargetName>SandboxieWUAU</TargetName>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'">
<TargetName>SandboxieWUAU</TargetName>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<MinimalRebuild />
</ClCompile>
<Link>
<AdditionalDependencies>SbieDll.lib;secur32.lib;ntdll.lib;psapi.lib;AdvApi32.lib;user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'">
<ClCompile>
<Optimization>Disabled</Optimization>
<MinimalRebuild />
</ClCompile>
<Link>
<AdditionalDependencies>SbieDll.lib;secur32.lib;ntdll.lib;psapi.lib;AdvApi32.lib;user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'">
<ClCompile>
<FunctionLevelLinking>
</FunctionLevelLinking>
<MinimalRebuild />
</ClCompile>
<Link>
<AdditionalDependencies>SbieDll.lib;secur32.lib;ntdll.lib;psapi.lib;AdvApi32.lib;user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'">
<ClCompile>
<FunctionLevelLinking>
</FunctionLevelLinking>
<MinimalRebuild />
</ClCompile>
<Link>
<AdditionalDependencies>SbieDll.lib;secur32.lib;ntdll.lib;psapi.lib;AdvApi32.lib;user32.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="wuau.c" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="resource.rc" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,87 @@
// Copyright 2004-2020 Sandboxie Holdings, LLC
//
// 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 <https://www.gnu.org/licenses/>.
//
//Microsoft Developer Studio generated resource script.
//
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
#ifndef _MAC
/////////////////////////////////////////////////////////////////////////////
//
// Version
//
#include "common/my_version.h"
VS_VERSION_INFO VERSIONINFO
FILEVERSION MY_VERSION_BINARY
PRODUCTVERSION MY_VERSION_BINARY
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x40004L
FILETYPE 0x2L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "Comments", "\0"
VALUE "CompanyName", MY_COMPANY_NAME_STRING "\0"
VALUE "FileDescription", MY_PRODUCT_NAME_STRING " COM Services (wuauserv)\0"
VALUE "FileVersion", MY_VERSION_STRING "\0"
OPTIONAL_VALUE("InternalName", "WUAU\0")
VALUE "LegalCopyright", MY_COPYRIGHT_STRING "\0"
VALUE "LegalTrademarks", "\0"
OPTIONAL_VALUE("OriginalFilename", "SandboxieWUAU.exe\0")
VALUE "PrivateBuild", "\0"
VALUE "ProductName", MY_PRODUCT_NAME_STRING "\0"
VALUE "ProductVersion", MY_VERSION_STRING "\0"
VALUE "SpecialBuild", "\0"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
#endif // !_MAC
#endif // English (U.S.) resources
/////////////////////////////////////////////////////////////////////////////

View File

@ -0,0 +1,232 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Sandboxie Windows Automatic Update Service (WUAUSERV)
//---------------------------------------------------------------------------
#include <ntstatus.h>
#define WIN32_NO_STATUS
typedef long NTSTATUS;
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include "common/defines.h"
#include "common/my_version.h"
//---------------------------------------------------------------------------
// Variables
//---------------------------------------------------------------------------
const WCHAR *ServiceTitle = SANDBOXIE L" WUAUSERV";
#include "../common.h"
//---------------------------------------------------------------------------
// my_CreateFileMapping
//---------------------------------------------------------------------------
HANDLE my_CreateFileMappingW(
HANDLE hFile,
LPSECURITY_ATTRIBUTES lpAttributes,
DWORD flProtect,
DWORD dwMaximumSizeHigh,
DWORD dwMaximumSizeLow,
LPCWSTR lpName)
{
typedef HANDLE (__stdcall *P_CreateFileMappingW)(
HANDLE hFile,
LPSECURITY_ATTRIBUTES lpAttributes,
DWORD flProtect,
DWORD dwMaximumSizeHigh,
DWORD dwMaximumSizeLow,
LPCWSTR lpName);
return ((P_CreateFileMappingW)__sys_CreateFileMappingW)(
hFile, lpAttributes, flProtect,
dwMaximumSizeHigh, dwMaximumSizeLow, lpName);
}
//---------------------------------------------------------------------------
// my_CreateProcessW
//---------------------------------------------------------------------------
ULONG_PTR __sys_CreateProcessW = 0;
BOOL my_CreateProcessW(
LPVOID lpApplicationName,
LPVOID lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPVOID lpCurrentDirectory,
LPSTARTUPINFOW lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation)
{
typedef BOOL (*P_CreateProcess)(
LPVOID lpApplicationName,
LPVOID lpCommandLine,
LPSECURITY_ATTRIBUTES lpProcessAttributes,
LPSECURITY_ATTRIBUTES lpThreadAttributes,
BOOL bInheritHandles,
DWORD dwCreationFlags,
LPVOID lpEnvironment,
LPVOID lpCurrentDirectory,
LPSTARTUPINFOW lpStartupInfo,
LPPROCESS_INFORMATION lpProcessInformation);
//
// make sure SandboxieWUAU only launches one copy of WUAUCLT.EXE
// at a time. the sequence is SandboxieWUAU launching WUAUCLT.
// then WUAUCLT calls CoRegisterClassObject for some unregistered
// CLSID and signals SandboxieWUAU. then SandboxieWUAU tries
// CoCreateInstance on that CLSID. It fails REGDB_E_CLASSNOTREG,
// and then retries from the top, spawning another instance of
// WUAUCLT. this hack prevents more than one instance of WUAUCLT.
//
WCHAR *ptr = lpCommandLine;
while (ptr) {
ptr = wcschr(ptr, L'\\');
if (ptr) {
++ptr;
if (_wcsnicmp(ptr, L"system32\\wuauclt.exe", 20) == 0) {
ULONG pid = FindProcessId(L"wuauclt.exe", FALSE);
if (! pid)
break;
SetLastError(ERROR_ACCESS_DENIED);
return FALSE;
}
}
}
return ((P_CreateProcess)__sys_CreateProcessW)(
lpApplicationName, lpCommandLine,
lpProcessAttributes, lpThreadAttributes,
bInheritHandles, dwCreationFlags,
lpEnvironment, lpCurrentDirectory,
lpStartupInfo, lpProcessInformation);
}
//---------------------------------------------------------------------------
// my_NtAlpcConnectPort
//---------------------------------------------------------------------------
ULONG_PTR __sys_NtAlpcConnectPort = 0;
_FX NTSTATUS my_NtAlpcConnectPort(
HANDLE *PortHandle, UNICODE_STRING *PortName, void *ObjectAttributes,
void *AlpcConnectInfo, ULONG ConnectionFlags, void *ServerSid,
void *ConnectionInfo, void *ConnectionInfoLength,
void *InMessageBuffer, void *OutMessageBuffer, void *Timeout)
{
NTSTATUS status;
if (PortName->Length == 8 * sizeof(WCHAR) &&
_wcsnicmp(PortName->Buffer, L"\\PdcPort", 8) == 0) {
//
// on Windows 8 the service tries to connect to an undocumented port
// provided by a driver pdc.sys. work around this by faking success
//
*PortHandle = NULL;
status = STATUS_SUCCESS;
} else {
typedef NTSTATUS (*P_NtAlpcConnectPort)(
HANDLE *PortHandle, UNICODE_STRING *PortName,
void *ObjectAttributes, void *AlpcConnectInfo,
ULONG ConnectionFlags, void *ServerSid,
void *ConnectionInfo, void *ConnectionInfoLength,
void *InMessageBuffer, void *OutMessageBuffer, void *Timeout);
status = ((P_NtAlpcConnectPort)__sys_NtAlpcConnectPort)(
PortHandle, PortName, ObjectAttributes, AlpcConnectInfo,
ConnectionFlags, ServerSid, ConnectionInfo, ConnectionInfoLength,
InMessageBuffer, OutMessageBuffer, Timeout);
}
return status;
}
//---------------------------------------------------------------------------
// WinMain
//---------------------------------------------------------------------------
int __stdcall WinMain(
HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine, int nCmdShow)
{
UCHAR WUAU_ServiceMain[64];
WCHAR ServiceName[16];
WCHAR ServiceDll[64];
BOOL hook_success = TRUE;
OSVERSIONINFO osvi;
//BOOL ok;
SetupExceptionHandler();
HOOK_WIN32(CreateProcessW);
memzero(&osvi, sizeof(OSVERSIONINFO));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx((OSVERSIONINFO *)&osvi);
if (osvi.dwMajorVersion >= 6) {
wcscpy(ServiceDll, L"wuaueng.dll");
strcpy(WUAU_ServiceMain, "WUServiceMain");
} else {
wcscpy(ServiceDll, L"wuauserv.dll");
strcpy(WUAU_ServiceMain, "ServiceMain");
}
if ((osvi.dwMajorVersion == 10) || (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion >= 2)) {
// Windows 10, Windows 8, or Windows 8.1
void *NtAlpcConnectPort = GetProcAddress(
GetModuleHandle(L"ntdll.dll"), "NtAlpcConnectPort");
HOOK_WIN32(NtAlpcConnectPort);
}
wcscpy(ServiceName, L"wuauserv");
// We NEVER want updates to run in the sandbox. Commenting
// out the next lines means the update service is not started
// in the sandbox, so all updates will fail.
// ok = Service_Start_ServiceMain(
// ServiceName, ServiceDll, WUAU_ServiceMain, FALSE);
//return (ok ? EXIT_SUCCESS : EXIT_FAILURE);
return EXIT_SUCCESS;
}

925
Sandboxie/apps/com/common.h Normal file
View File

@ -0,0 +1,925 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Service handling code, common to RpcSs and DcomLauncher
//---------------------------------------------------------------------------
#include "common/my_version.h"
#include "common/win32_ntddk.h"
#include "core/dll/sbiedll.h"
#include <sddl.h>
#pragma warning(disable : 4996)
//---------------------------------------------------------------------------
// Variables
//---------------------------------------------------------------------------
const WCHAR *_SandboxieRpcSs = SANDBOXIE L"RpcSs.exe";
const WCHAR *_msiexec = L"msiexec.exe";
static HMODULE KernelBase = NULL;
static BOOLEAN IsWindows81 = FALSE;
//---------------------------------------------------------------------------
// Useful Macros
//---------------------------------------------------------------------------
#define ErrorMessageBox(txt) { \
MessageBox( \
NULL, txt, ServiceTitle, MB_ICONEXCLAMATION | MB_OK); \
} \
#define HOOK_WIN32(func) { \
const char *FuncName = #func; \
void *SourceFunc = (void *)func; \
if (KernelBase) { \
SourceFunc = GetProcAddress(KernelBase, FuncName); \
if (! SourceFunc) \
SourceFunc = (void *)func; \
} \
__sys_##func = \
(ULONG_PTR)SbieDll_Hook(FuncName, SourceFunc, my_##func); \
if (! __sys_##func) \
hook_success = FALSE; \
}
typedef BOOL(*P_SetServiceStatus)(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus);
//---------------------------------------------------------------------------
// Check_Windows_7
//---------------------------------------------------------------------------
void Check_Windows_7(void)
{
OSVERSIONINFO osvi;
memzero(&osvi, sizeof(OSVERSIONINFO));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx((OSVERSIONINFO *)&osvi);
if (osvi.dwMajorVersion > 6 ||
osvi.dwMajorVersion == 6 && osvi.dwMinorVersion >= 1) {
KernelBase = LoadLibrary(L"KernelBase.dll");
//
// GetVersionEx in Windows 8.1 returns version 6.2, same as
// Windows 8. we detect 8.1 by looking up a new NTDLL entrypoint
//
if (GetProcAddress(GetModuleHandle(L"ntdll.dll"), "NtCreateTimer2"))
IsWindows81 = TRUE;
}
}
//---------------------------------------------------------------------------
// CheckProcessLocalSystem
//---------------------------------------------------------------------------
_FX BOOL CheckProcessLocalSystem(HANDLE ProcessHandle)
{
BOOL IsLocalSystem = FALSE;
HANDLE TokenHandle;
BOOL b = OpenProcessToken(ProcessHandle, TOKEN_QUERY, &TokenHandle);
if (b) {
union {
TOKEN_USER user;
UCHAR space[64];
} info;
ULONG len = sizeof(info);
WCHAR *sid;
b = GetTokenInformation(
TokenHandle, TokenUser, &info, len, &len);
if (b) {
b = ConvertSidToStringSid(info.user.User.Sid, &sid);
if (b) {
if (wcscmp(sid, L"S-1-5-18") == 0)
IsLocalSystem = TRUE;
LocalFree(sid);
}
}
CloseHandle(TokenHandle);
}
return IsLocalSystem;
}
//---------------------------------------------------------------------------
// FindProcessId
//---------------------------------------------------------------------------
_FX ULONG FindProcessId(
const WCHAR *ProcessName,
BOOL FindSystemToken)
{
ULONG ret_pid = 0;
ULONG *pids;
ULONG i;
WCHAR this_sid[96], that_sid[96], image[96];
HANDLE process;
process = (HANDLE)(ULONG_PTR)GetCurrentProcessId();
SbieApi_QueryProcess(process, NULL, NULL, this_sid, NULL);
pids = HeapAlloc(
GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, sizeof(ULONG) * 512);
SbieApi_EnumProcess(NULL, pids);
for (i = 1; i <= pids[0]; ++i) {
HANDLE pids_i = (HANDLE)(ULONG_PTR)pids[i];
SbieApi_QueryProcess(pids_i, NULL, image, that_sid, NULL);
if (_wcsicmp(image, ProcessName) == 0 &&
_wcsicmp(this_sid, that_sid) == 0) {
BOOL found = FALSE;
if (FindSystemToken) {
SbieApi_OpenProcess(&process, pids_i);
if (!process) {
process = OpenProcess(
PROCESS_QUERY_INFORMATION, FALSE, pids[i]);
}
if ((!process) && GetLastError() == ERROR_ACCESS_DENIED) {
// we got access denied error, so it's reasonable to
// assume the process is running under a system account
process = 0;
found = TRUE;
}
}
else {
process = 0;
found = TRUE;
}
if (process) {
if (CheckProcessLocalSystem(process))
found = TRUE;
CloseHandle(process);
}
if (found) {
ret_pid = pids[i];
break;
}
}
}
HeapFree(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, pids);
return ret_pid;
}
//---------------------------------------------------------------------------
// Service Control Manager handles
//---------------------------------------------------------------------------
#define SC_HANDLE_MIN ((SC_HANDLE)0x12345670)
#define SC_HANDLE_BITS ((SC_HANDLE)0x12345671)
#define SC_HANDLE_RPCSS ((SC_HANDLE)0x12345672)
#define SC_HANDLE_MSISERVER ((SC_HANDLE)0x12345673)
#define SC_HANDLE_EVENTSYSTEM ((SC_HANDLE)0x12345674)
#define SC_HANDLE_MAX ((SC_HANDLE)0x12345679)
#define SC_HANDLE_IS_FAKE(h) ((h) > SC_HANDLE_MIN && (h) < SC_HANDLE_MAX)
//---------------------------------------------------------------------------
// my_findProcessData
//---------------------------------------------------------------------------
PROCESS_DATA myData[DATA_SLOTS] = {
{0,0,0,0,0,0,NULL,NULL},
{0,0,0,0,0,0,NULL,NULL},
{0,0,0,0,0,0,NULL,NULL},
{0,0,0,0,0,0,NULL,NULL},
{0,0,0,0,0,0,NULL,NULL}
};
PROCESS_DATA *my_findProcessData(WCHAR *name, int createNew) {
int i = 0;
for (i = 0; i < DATA_SLOTS; i++) {
if (myData[i].name) {
if (!_wcsicmp(name, myData[i].name)) {
return &myData[i];
}
}
else {
if (createNew) {
int lenName = 0;
if (!name) {
return NULL;
}
while (name[lenName++] && lenName < 256); //strlen
if (!lenName || lenName >= 256) return NULL;
memset(&myData[i], 0, sizeof(PROCESS_DATA));
myData[i].name = (WCHAR *)calloc(sizeof(WCHAR), lenName);
myData[i].EventName = (WCHAR *)calloc(sizeof(WCHAR), 128 + lenName);
swprintf(myData[i].name, L"%s", name);
swprintf(myData[i].EventName, SBIE_BOXED_ L"ServiceInitComplete_%s", myData[i].name);
if (!_wcsicmp(name, L"RPCSS")) {
myData[i].hStartLingerEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
}
return &myData[i];
}
return NULL;
}
}
return NULL;
}
DWORD ServiceStatus_CurrentState = 0;
DWORD ServiceStatus_CheckPoint = 0;
DWORD ServiceStatus_ErrorCode = 0;
ULONG_PTR __sys_SetServiceStatus = 0;
_FX void InitComplete(PROCESS_DATA *data) {
HANDLE hInitEvent;
if (!data) {
return;
}
if (data->hStartLingerEvent) {
SetEvent(data->hStartLingerEvent);
}
hInitEvent = OpenEvent(EVENT_ALL_ACCESS, FALSE, data->EventName);
if (!hInitEvent) {
hInitEvent = CreateEvent(NULL, TRUE, FALSE, data->EventName);
}
if (hInitEvent) {
SetEvent(hInitEvent);
}
return;
}
_FX BOOL my_SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus) {
int i = 0;
//
// update service status in SbieDll
// needed for SandboxieCrypto which hooks SetServiceStatus
//
#ifdef SANDBOXIECRYPTO
((P_SetServiceStatus)__sys_SetServiceStatus)(hServiceStatus, lpServiceStatus);
#endif SANDBOXIECRYPTO
//
// update status in this process
//
while (i < DATA_SLOTS && myData[i].name)
{
if (!myData[i].initFlag)
{
if (myData[i].tid == 0 || myData[i].tid == GetCurrentThreadId())
{
myData[i].tid = GetCurrentThreadId();
if (!((lpServiceStatus->dwCurrentState == 0) || (lpServiceStatus->dwCurrentState == SERVICE_START_PENDING)))
{
if (lpServiceStatus->dwCurrentState & SERVICE_STOPPED)
myData[i].errorCode = lpServiceStatus->dwWin32ExitCode;
else
myData[i].checkpoint = lpServiceStatus->dwCheckPoint;
ServiceStatus_CheckPoint = lpServiceStatus->dwCheckPoint;
myData->initFlag = 1;
myData[i].state = lpServiceStatus->dwCurrentState;
InitComplete(&myData[i]);
}
break;
}
}
i++;
}
return TRUE;
}
//---------------------------------------------------------------------------
// my_StartServiceCtrlDispatcherW
//---------------------------------------------------------------------------
ULONG_PTR __sys_StartServiceCtrlDispatcherW = 0;
BOOL my_StartServiceCtrlDispatcherW(
const LPSERVICE_TABLE_ENTRY lpServiceTable)
{
LPTSTR parms[1];
LPSERVICE_MAIN_FUNCTION ServiceMain;
SERVICE_TABLE_ENTRY *entry = lpServiceTable;
while (entry->lpServiceName) {
ServiceMain = entry->lpServiceProc;
parms[0] = entry->lpServiceName;
ServiceMain(1, parms);
++entry;
}
return 1;
}
//---------------------------------------------------------------------------
// my_OpenServiceW
//---------------------------------------------------------------------------
ULONG_PTR __sys_OpenServiceW = 0;
SC_HANDLE my_OpenServiceW(
SC_HANDLE hSCManager,
LPCTSTR lpServiceName,
DWORD dwDesiredAccess)
{
if (_wcsicmp(lpServiceName, L"RpcSs") == 0) {
// DcomLaunch is querying the RPCSS service
SetLastError(0);
return SC_HANDLE_RPCSS;
}
else if (_wcsicmp(lpServiceName, L"MSIServer") == 0) {
// COM (in the RPCSS part) needs to query service status for
// MSIServer; see more about this in QueryServiceStatus()
SetLastError(0);
return SC_HANDLE_MSISERVER;
}
else if (_wcsicmp(lpServiceName, L"EventSystem") == 0) {
// same as above, for EventSystem
SetLastError(0);
return SC_HANDLE_EVENTSYSTEM;
}
else {
// fallback to SbieDll SCM implementation
typedef SC_HANDLE(*P_OpenService)(
SC_HANDLE hSCManager,
const void *lpServiceName,
DWORD dwDesiredAccess);
SC_HANDLE hService = ((P_OpenService)__sys_OpenServiceW)(
hSCManager, lpServiceName, dwDesiredAccess);
ULONG err = GetLastError();
//{WCHAR txt[512];
//wsprintf(txt, L"OpenService %s by Process ID %d gives %08X\n", lpServiceName, GetCurrentProcessId(), hService);
//OutputDebugString(txt);}
if (SbieDll_IsBoxedService(hService)) {
SetLastError(err);
return hService;
}
else {
SetLastError(ERROR_SERVICE_DOES_NOT_EXIST);
return 0;
}
}
}
//---------------------------------------------------------------------------
// my_CloseServiceHandle
//---------------------------------------------------------------------------
ULONG_PTR __sys_CloseServiceHandle = 0;
BOOL my_CloseServiceHandle(SC_HANDLE hSCObject)
{
if (SC_HANDLE_IS_FAKE(hSCObject)) {
SetLastError(0);
return TRUE;
}
else {
typedef BOOL(*P_CloseServiceHandle)(SC_HANDLE hSCObject);
return ((P_CloseServiceHandle)__sys_CloseServiceHandle)(hSCObject);
}
}
//---------------------------------------------------------------------------
// my_QueryServiceStatusEx
//---------------------------------------------------------------------------
ULONG_PTR __sys_QueryServiceStatusEx = 0;
BOOL my_QueryServiceStatusEx(
SC_HANDLE hService,
SC_STATUS_TYPE InfoLevel,
LPBYTE lpBuffer,
DWORD cbBufSize,
LPDWORD pcbBytesNeeded)
{
//WCHAR txt[256];
//swprintf(txt, L"QueryServiceStatusEx for Service Handle %X\n", hService);
//OutputDebugString(txt);
//swprintf(txt, L"lpBuffer = %p cbBufSize = %d pcbBytesNeeded = %p\n",
// lpBuffer, cbBufSize, pcbBytesNeeded);
//OutputDebugString(txt);
if (InfoLevel != SC_STATUS_PROCESS_INFO) {
SetLastError(ERROR_INVALID_LEVEL);
return FALSE;
}
if (cbBufSize < sizeof(SERVICE_STATUS_PROCESS)) {
*pcbBytesNeeded = sizeof(SERVICE_STATUS_PROCESS);
SetLastError(ERROR_INSUFFICIENT_BUFFER);
return FALSE;
}
if (InfoLevel == SC_STATUS_PROCESS_INFO) {
// fill in some defaults
SERVICE_STATUS_PROCESS *buf = (SERVICE_STATUS_PROCESS *)lpBuffer;
buf->dwServiceType = SERVICE_WIN32_OWN_PROCESS;
buf->dwCurrentState = SERVICE_RUNNING;
buf->dwControlsAccepted =
SERVICE_ACCEPT_STOP | SERVICE_ACCEPT_SHUTDOWN;
buf->dwWin32ExitCode = 0;
buf->dwServiceSpecificExitCode = 0;
buf->dwCheckPoint = 0;
buf->dwWaitHint = 0;
buf->dwServiceFlags = SERVICE_RUNS_IN_SYSTEM_PROCESS;
buf->dwProcessId = 0;
if (hService == SC_HANDLE_RPCSS) {
buf->dwServiceType = SERVICE_WIN32_SHARE_PROCESS;
buf->dwProcessId = FindProcessId(_SandboxieRpcSs, FALSE);
}
else if (hService == SC_HANDLE_MSISERVER) {
// when MSI Server calls CoRegisterClassObject, RPCSS/DCOMLAUNCH
// service will query the status of MSIServer service, and
// expect the service to NOT be stopped or stop-pending.
// without this, MSI server gets CO_E_WRONG_SERVER_IDENTITY.
buf->dwProcessId = FindProcessId(_msiexec, TRUE);
}
else if (hService == SC_HANDLE_EVENTSYSTEM) {
// same as above, for EventSystem service
buf->dwProcessId = 0;
}
else {
// fallback to SbieDll SCM implementation
typedef BOOL(*P_QueryServiceStatusEx)(
SC_HANDLE hService, SC_STATUS_TYPE InfoLevel,
LPBYTE lpBuffer, DWORD cbBufSize, LPDWORD pcbBytesNeeded);
return ((P_QueryServiceStatusEx)__sys_QueryServiceStatusEx)(
hService, InfoLevel, lpBuffer, cbBufSize, pcbBytesNeeded);
}
}
SetLastError(0);
return TRUE;
}
//---------------------------------------------------------------------------
// my_QueryServiceStatus
//---------------------------------------------------------------------------
ULONG_PTR __sys_QueryServiceStatus = 0;
BOOL my_QueryServiceStatus(
SC_HANDLE hService,
SERVICE_STATUS *ServiceStatus)
{
SERVICE_STATUS_PROCESS buf;
DWORD cb;
BOOL ok;
ok = QueryServiceStatusEx(
hService, SC_STATUS_PROCESS_INFO, (void *)&buf, sizeof(buf), &cb);
if (ok) {
ServiceStatus->dwServiceType = buf.dwServiceType;
ServiceStatus->dwCurrentState = buf.dwCurrentState;
ServiceStatus->dwControlsAccepted = buf.dwControlsAccepted;
ServiceStatus->dwWin32ExitCode = buf.dwWin32ExitCode;
ServiceStatus->dwServiceSpecificExitCode
= buf.dwServiceSpecificExitCode;
ServiceStatus->dwCheckPoint = buf.dwCheckPoint;
ServiceStatus->dwWaitHint = buf.dwWaitHint;
}
return ok;
}
//---------------------------------------------------------------------------
// my_StartService
//---------------------------------------------------------------------------
ULONG_PTR __sys_StartService = 0;
BOOL my_StartService(
SC_HANDLE hService,
DWORD NumArgs,
void *ArgVector)
{
BOOL ok;
if (hService == SC_HANDLE_MSISERVER) {
ok = SbieDll_StartBoxedService(L"MSIServer", FALSE);
}
else if (SbieDll_IsBoxedService(hService)) {
typedef BOOL(*P_StartService)(
SC_HANDLE hService, DWORD NumArgs, void *ArgVector);
ok = ((P_StartService)__sys_StartService)(
hService, NumArgs, ArgVector);
}
else {
SetLastError(ERROR_ACCESS_DENIED);
ok = FALSE;
}
return ok;
}
//---------------------------------------------------------------------------
// my_ControlService
//---------------------------------------------------------------------------
ULONG_PTR __sys_ControlService = 0;
BOOL my_ControlService(
SC_HANDLE hService,
DWORD dwControl,
LPSERVICE_STATUS lpServiceStatus)
{
if (SbieDll_IsBoxedService(hService)) {
typedef BOOL(*P_ControlService)(
SC_HANDLE hService,
DWORD dwControl,
LPSERVICE_STATUS lpServiceStatus);
return ((P_ControlService)__sys_ControlService)(
hService, dwControl, lpServiceStatus);
}
else
return my_QueryServiceStatus(hService, lpServiceStatus);
}
//---------------------------------------------------------------------------
// my_CreateEventW
//---------------------------------------------------------------------------
ULONG_PTR __sys_CreateEventW = 0;
HANDLE my_CreateEventW(
LPSECURITY_ATTRIBUTES lpEventAttributes,
BOOL bManualReset,
BOOL bInitialState,
LPCWSTR lpName)
{
typedef HANDLE(*P_CreateEventW)(
LPSECURITY_ATTRIBUTES lpEventAttributes,
BOOL bManualReset,
BOOL bInitialState,
LPCWSTR lpName);
HANDLE h;
if (lpName && wcscmp(lpName, L"ScmCreatedEvent") == 0) {
h = ((P_CreateEventW)__sys_CreateEventW)(NULL, TRUE, TRUE, NULL);
}
else {
h = ((P_CreateEventW)__sys_CreateEventW)(
lpEventAttributes, bManualReset, bInitialState, lpName);
}
return h;
}
//---------------------------------------------------------------------------
// my_CreateFileMappingW (forward reference)
//---------------------------------------------------------------------------
ULONG_PTR __sys_CreateFileMappingW = 0;
HANDLE my_CreateFileMappingW(
HANDLE hFile,
LPSECURITY_ATTRIBUTES lpAttributes,
DWORD flProtect,
DWORD dwMaximumSizeHigh,
DWORD dwMaximumSizeLow,
LPCWSTR lpName);
#if 0
ULONG_PTR __sys_RtlSetLastWin32Error = 0;
typedef void(*P_RtlSetLastWin32Error)(DWORD dwError);
void my_RtlSetLastWin32Error(DWORD dwError)
{
static ULONG Depth = 0;
if (dwError && (Depth == 0)) {
WCHAR txt[64];
++Depth;
wsprintf(txt, L"(%06d) SetLastError - dec=%d hex=%X\n", GetCurrentProcessId(), dwError, dwError);
OutputDebugString(txt);
--Depth;
}
((P_RtlSetLastWin32Error)__sys_RtlSetLastWin32Error)(dwError);
}
__declspec(dllimport) void RtlSetLastWin32Error(DWORD dwError);
#endif
//---------------------------------------------------------------------------
// PowerSettingRegisterNotification (for Windows 8.1)
//---------------------------------------------------------------------------
ULONG_PTR __sys_PowerSettingRegisterNotification = 0;
ULONG my_PowerSettingRegisterNotification(
void *SettingGuid, ULONG Flags, HANDLE Recipient, HANDLE *RegistrationHandle)
{
*RegistrationHandle = (HANDLE)0x12345678; // fake handle
return ERROR_SUCCESS;
}
//---------------------------------------------------------------------------
// Hook_Service_Control_Manager
//---------------------------------------------------------------------------
BOOL Hook_Service_Control_Manager(void)
{
BOOL hook_success = TRUE;
HOOK_WIN32(SetServiceStatus);
HOOK_WIN32(StartServiceCtrlDispatcherW);
HOOK_WIN32(OpenServiceW);
HOOK_WIN32(CloseServiceHandle);
HOOK_WIN32(QueryServiceStatusEx);
HOOK_WIN32(QueryServiceStatus);
HOOK_WIN32(StartService);
HOOK_WIN32(ControlService);
HOOK_WIN32(CreateFileMappingW);
#if 0
HOOK_WIN32(RtlSetLastWin32Error);
#endif
if (IsWindows81) {
HMODULE pp = LoadLibrary(L"powrprof.dll");
void *PowerSettingRegisterNotification =
GetProcAddress(pp, "PowerSettingRegisterNotification");
HOOK_WIN32(PowerSettingRegisterNotification);
}
if (!hook_success) {
ErrorMessageBox(L"Could not instrument service functions");
return FALSE;
}
else
return TRUE;
}
//---------------------------------------------------------------------------
// Service_Start_ServiceMain
//---------------------------------------------------------------------------
BOOL Service_Start_ServiceMain(WCHAR *SvcName, const WCHAR *SvcDllName, const UCHAR *SvcProcName, BOOL UseMyStartServiceCtrlDispatcher)
{
HMODULE dll;
LPSERVICE_MAIN_FUNCTION ServiceMain;
ULONG table_len;
SERVICE_TABLE_ENTRY *table;
WCHAR ErrorText[128];
dll = LoadLibrary(SvcDllName);
if (!dll) {
wcscpy(ErrorText, L"Could not load service DLL - ");
wcscat(ErrorText, SvcDllName);
ErrorMessageBox(ErrorText);
return FALSE;
}
ServiceMain = (LPSERVICE_MAIN_FUNCTION)GetProcAddress(dll, SvcProcName);
if (!ServiceMain) {
wsprintf(ErrorText,
L"Could not locate ServiceMain routine - %S", SvcProcName);
ErrorMessageBox(ErrorText);
return FALSE;
}
table_len = sizeof(SERVICE_TABLE_ENTRY) * 2;
table = HeapAlloc(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, table_len);
ZeroMemory(table, table_len);
table[0].lpServiceName = SvcName;
table[0].lpServiceProc = ServiceMain;
if (UseMyStartServiceCtrlDispatcher) {
PROCESS_DATA *myData;
myData = my_findProcessData(SvcName, 1);
if (!myData) {
return FALSE;
}
myData->tid = 0;
myData->initFlag = 0;
CreateThread(NULL, 0, my_StartServiceCtrlDispatcherW, table, 0, NULL);
}
else {
StartServiceCtrlDispatcher(table);
}
return TRUE;
}
//---------------------------------------------------------------------------
// VectoredExceptionHandler
//---------------------------------------------------------------------------
_FX LONG VectoredExceptionHandler(EXCEPTION_POINTERS *ExceptionInfo)
{
static ULONG LastExcCode = -1;
WCHAR txt[256];
//
// SkyNetRootKit crashes SandboxieRpcSs with an exception address
// beyond user space, so indicate this special condition
//
if (LastExcCode != ExceptionInfo->ExceptionRecord->ExceptionCode) {
ULONG_PTR ExceptionAddress =
(ULONG_PTR)ExceptionInfo->ExceptionRecord->ExceptionAddress;
LastExcCode = ExceptionInfo->ExceptionRecord->ExceptionCode;
if ((ExceptionAddress & 0xF0000000) >= 0x80000000) {
swprintf(txt, L"%s (%08X)", ServiceTitle, LastExcCode);
SbieApi_Log(2204, txt);
wsprintf(txt,
L"SBIE2398 Service suffers exception %08X at address %08X."
L" Last checkpoint was %d\n",
ExceptionInfo->ExceptionRecord->ExceptionCode,
ExceptionInfo->ExceptionRecord->ExceptionAddress,
ServiceStatus_CheckPoint);
ErrorMessageBox(txt);
}
}
return EXCEPTION_CONTINUE_SEARCH;
}
//---------------------------------------------------------------------------
// Setup
//---------------------------------------------------------------------------
_FX void SetupExceptionHandler(void)
{
#ifndef _WIN64
typedef void *(*P_AddVectoredExceptionHandler)(
ULONG FirstHandler,
PVECTORED_EXCEPTION_HANDLER VectoredHandler);
HMODULE kernel32 = GetModuleHandle(L"kernel32.dll");
void *ptr = GetProcAddress(kernel32, "AddVectoredExceptionHandler");
if (!ptr)
return;
((P_AddVectoredExceptionHandler)ptr)(1, VectoredExceptionHandler);
#endif _WIN64
}
//---------------------------------------------------------------------------
// SuspendMainThread
//---------------------------------------------------------------------------
#define SuspendMainThread() \
while (1) \
SuspendThread(GetCurrentThread()); \
return EXIT_SUCCESS;
//---------------------------------------------------------------------------
// CheckSingleInstance
//---------------------------------------------------------------------------
#ifdef SINGLE_INSTANCE_MUTEX_NAME
BOOLEAN CheckSingleInstance(void)
{
const WCHAR *MutexName = SBIE_BOXED_ SINGLE_INSTANCE_MUTEX_NAME;
HANDLE hMutex = OpenMutex(MUTEX_ALL_ACCESS, FALSE, MutexName);
if (!hMutex)
hMutex = CreateMutex(NULL, TRUE, MutexName);
if (hMutex) {
if (WaitForSingleObject(hMutex, 0) != WAIT_OBJECT_0) {
//
// some other instance holds the mutex, so abort
//
return FALSE;
}
}
return TRUE;
}
#endif SINGLE_INSTANCE_MUTEX_NAME

352
Sandboxie/apps/com/privs.h Normal file
View File

@ -0,0 +1,352 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Service handling code, common to RpcSs and DcomLauncher
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// Defines
//---------------------------------------------------------------------------
#define SE_ASSIGNPRIMARYTOKEN_PRIVILEGE (3L)
//---------------------------------------------------------------------------
// Functions
//---------------------------------------------------------------------------
DWORD my_RtlAdjustPrivilege(
DWORD dwPrivilege,
BOOL bEnablePrivilege,
DWORD dwAdjustWhat,
DWORD *dwPreviouslyEnabled);
BOOL my_AccessCheckByType(
PSECURITY_DESCRIPTOR pSecurityDescriptor,
PSID PrincipalSelfSid,
HANDLE ClientToken,
DWORD DesiredAccess,
POBJECT_TYPE_LIST ObjectTypeList,
DWORD ObjectTypeListLength,
PGENERIC_MAPPING GenericMapping,
PPRIVILEGE_SET PrivilegeSet,
LPDWORD PrivilegeSetLength,
LPDWORD GrantedAccess,
LPBOOL AccessStatus);
//---------------------------------------------------------------------------
__declspec(dllimport) ULONG RtlAdjustPrivilege(
DWORD dwPrivilege,
BOOL bEnablePrivilege,
DWORD dwAdjustWhat,
DWORD *dwPreviouslyEnabled);
//---------------------------------------------------------------------------
// Variables
//---------------------------------------------------------------------------
static ULONG ThreadTokenTlsIndex = TLS_OUT_OF_INDEXES;
static ULONG_PTR __sys_RtlAdjustPrivilege = 0;
static ULONG_PTR __sys_AccessCheckByType = 0;
static ULONG_PTR __sys_SetThreadToken = 0;
static ULONG_PTR __sys_GetTokenInformation = 0;
//---------------------------------------------------------------------------
// my_RtlAdjustPrivilege
//---------------------------------------------------------------------------
ALIGNED DWORD my_RtlAdjustPrivilege(
DWORD dwPrivilege,
BOOL bEnablePrivilege,
DWORD dwAdjustWhat,
DWORD *dwPreviouslyEnabled)
{
typedef DWORD (*P_RtlAdjustPrivilege)(
DWORD dwPrivilege,
BOOL bEnablePrivilege,
DWORD dwAdjustWhat,
DWORD *dwPreviouslyEnabled);
DWORD rv = ((P_RtlAdjustPrivilege)__sys_RtlAdjustPrivilege)(
dwPrivilege, bEnablePrivilege, dwAdjustWhat, dwPreviouslyEnabled);
if (rv == STATUS_PRIVILEGE_NOT_HELD &&
dwPrivilege == SE_ASSIGNPRIMARYTOKEN_PRIVILEGE)
rv = 0;
return rv;
}
//---------------------------------------------------------------------------
// my_AccessCheckByType
//---------------------------------------------------------------------------
ALIGNED BOOL my_AccessCheckByType(
PSECURITY_DESCRIPTOR pSecurityDescriptor,
PSID PrincipalSelfSid,
HANDLE ClientToken,
DWORD DesiredAccess,
POBJECT_TYPE_LIST ObjectTypeList,
DWORD ObjectTypeListLength,
PGENERIC_MAPPING GenericMapping,
PPRIVILEGE_SET PrivilegeSet,
LPDWORD PrivilegeSetLength,
LPDWORD GrantedAccess,
LPBOOL AccessStatus)
{
*GrantedAccess = 0xFFFFFFFF;
*AccessStatus = TRUE;
SetLastError(0);
return TRUE;
}
//---------------------------------------------------------------------------
// my_SetThreadToken
//---------------------------------------------------------------------------
ALIGNED BOOL my_SetThreadToken(PHANDLE Thread, HANDLE Token)
{
typedef BOOL (*P_SetThreadToken)(PHANDLE Thread, HANDLE Token);
BOOL ok;
TlsSetValue(ThreadTokenTlsIndex, NULL);
ok = ((P_SetThreadToken)__sys_SetThreadToken)(Thread, Token);
if ((! ok) && GetLastError() == ERROR_ACCESS_DENIED) {
//
// RpcSs and DcomLaunch typically run as a normal user account
// that does not have the the impersonation privilege.
// this means that if some other services (say EventSystem)
// runs as LocalSystem, RpcSs is going to have trouble
// impersonating that other service.
// to work around that, we do impersonate per the caler's
// request, but we impersonate ourselves
//
// and also:
//
// CryptSvc indirectly calls rsaenh!CPAcquireContext, which checks
// if it is running as LocalSystem and fails otherwise. the check
// begins with a call to SetThreadToken(NULL, hTokenLocalSystem),
// follows with GetTokenInformation and concludes by comparing the
// SID. we fake success by impersonating our process token, but
// remember hTokenLocalSystem for GetTokenInformation (see below).
//
if (Thread == NULL) {
HANDLE PriToken;
ok = OpenProcessToken(
NtCurrentProcess(), TOKEN_ALL_ACCESS, &PriToken);
if (ok) {
HANDLE ImpToken;
ok = DuplicateToken(
PriToken, SecurityImpersonation, &ImpToken);
CloseHandle(PriToken);
if (ok) {
ok = ((P_SetThreadToken)__sys_SetThreadToken)(
Thread, ImpToken);
CloseHandle(ImpToken);
if (ok)
TlsSetValue(ThreadTokenTlsIndex, Token);
}
}
if (ok)
SetLastError(ERROR_SUCCESS);
else
SetLastError(ERROR_ACCESS_DENIED);
}
}
return ok;
}
//---------------------------------------------------------------------------
// my_GetTokenInformation
//---------------------------------------------------------------------------
ALIGNED BOOL my_GetTokenInformation(
HANDLE TokenHandle,
TOKEN_INFORMATION_CLASS TokenInformationClass,
LPVOID TokenInformation,
DWORD TokenInformationLength,
PDWORD ReturnLength)
{
typedef BOOL (*P_GetTokenInformation)(
HANDLE TokenHandle,
TOKEN_INFORMATION_CLASS TokenInformationClass,
LPVOID TokenInformation,
DWORD TokenInformationLength,
PDWORD ReturnLength);
//
// if our faked SetThreadToken saved hTokenLocalSystem,
// then use that saved token.
//
HANDLE SavedToken = TlsGetValue(ThreadTokenTlsIndex);
if (SavedToken)
TokenHandle = SavedToken;
return ((P_GetTokenInformation)__sys_GetTokenInformation)(
TokenHandle, TokenInformationClass, TokenInformation,
TokenInformationLength, ReturnLength);
}
//---------------------------------------------------------------------------
// Hook_Privilege
//---------------------------------------------------------------------------
ALIGNED BOOL Hook_Privilege(void)
{
BOOL hook_success = TRUE;
#ifndef SANDBOXIECRYPTO
HOOK_WIN32(RtlAdjustPrivilege);
#endif
HOOK_WIN32(AccessCheckByType);
HOOK_WIN32(SetThreadToken);
HOOK_WIN32(GetTokenInformation);
if (hook_success) {
ThreadTokenTlsIndex = TlsAlloc();
} else {
ErrorMessageBox(L"Could not hook privilege adjustment services");
return FALSE;
}
return TRUE;
}
//---------------------------------------------------------------------------
// SetPrivilege
//---------------------------------------------------------------------------
#if 0
BOOL SetPrivilege(
HANDLE hToken,
LPCTSTR lpszPrivilege,
BOOL bEnablePrivilege)
{
TOKEN_PRIVILEGES tp;
LUID luid;
if ( !LookupPrivilegeValue(
NULL, // lookup privilege on local system
lpszPrivilege, // privilege to lookup
&luid ) ) // receives LUID of privilege
{
printf("LookupPrivilegeValue error: %u\n", GetLastError() );
return FALSE;
}
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
if (bEnablePrivilege)
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
else
tp.Privileges[0].Attributes = 0;
// Enable the privilege or disable all privileges.
if ( !AdjustTokenPrivileges(
hToken,
FALSE,
&tp,
sizeof(TOKEN_PRIVILEGES),
(PTOKEN_PRIVILEGES) NULL,
(PDWORD) NULL) )
{
printf("AdjustTokenPrivileges error: %u\n", GetLastError() );
return FALSE;
}
if (GetLastError() == ERROR_NOT_ALL_ASSIGNED)
{
printf("The token does not have the specified privilege. \n");
return FALSE;
}
return TRUE;
}
//---------------------------------------------------------------------------
// SetPrivilegeProcess
//---------------------------------------------------------------------------
BOOL SetPrivilegeProcess(const WCHAR *PrivName, BOOL Enable)
{
HANDLE ProcessHandle;
BOOL ok;
ok = OpenProcessToken(
GetCurrentProcess(), TOKEN_ALL_ACCESS, &ProcessHandle);
if (ok) {
ok = SetPrivilege(ProcessHandle, PrivName, Enable);
CloseHandle(ProcessHandle);
}
return ok;
}
#endif

View File

@ -0,0 +1,592 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Box Order Utility
//---------------------------------------------------------------------------
#include <windows.h>
#include "BoxOrder.h"
#include "core/dll/sbiedll.h"
#include "core/svc/SbieIniWire.h"
#include "common/defines.h"
//---------------------------------------------------------------------------
// Functions
//---------------------------------------------------------------------------
static WCHAR *BoxOrder_ReadSetting(const WCHAR *section_name);
static BOX_ORDER_ENTRY *BoxOrder_ReadGroup2(WCHAR *name, WCHAR **ptext);
static int BoxOrder_ReadGroup(BOX_ORDER_ENTRY *parent, WCHAR *text);
static int BoxOrder_ReadFindBox(BOX_ORDER_ENTRY *entry, const WCHAR *name);
static void BoxOrder_ReadMissing(BOX_ORDER_ENTRY *parent);
static BOX_ORDER_ENTRY *BoxOrder_ReadEx(int ReadUser, int ReadDefault);
static int BoxOrder_ToString2(BOX_ORDER_ENTRY *entry, WCHAR *text);
static WCHAR *BoxOrder_ToString(BOX_ORDER_ENTRY *root);
static int BoxOrder_WriteSetting(WCHAR *text);
//---------------------------------------------------------------------------
// Variables
//---------------------------------------------------------------------------
static const WCHAR *BoxOrder_SettingName = L"BoxDisplayOrder";
//---------------------------------------------------------------------------
// BoxOrder_Alloc
//---------------------------------------------------------------------------
_FX BOX_ORDER_ENTRY *BoxOrder_Alloc(const WCHAR *name)
{
ULONG name_len = (wcslen(name) + 1) * sizeof(WCHAR);
ULONG entry_len = sizeof(BOX_ORDER_ENTRY) + name_len;
BOX_ORDER_ENTRY *entry = HeapAlloc(GetProcessHeap(), 0, entry_len);
if (entry) {
memzero(entry, entry_len);
memcpy(entry->name, name, name_len);
if (name_len > 128 * sizeof(WCHAR))
entry->name[128] = L'\0';
while (1) {
WCHAR *ptr = wcschr(entry->name, L',');
if (! ptr)
ptr = wcschr(entry->name, L'(');
if (! ptr)
ptr = wcschr(entry->name, L')');
if (! ptr)
break;
*ptr = L'_';
}
}
return entry;
}
//---------------------------------------------------------------------------
// BoxOrder_Free
//---------------------------------------------------------------------------
_FX void BoxOrder_Free(BOX_ORDER_ENTRY *entry)
{
while (entry) {
BOX_ORDER_ENTRY *next = entry->next;
if (entry->children)
BoxOrder_Free(entry->children);
HeapFree(GetProcessHeap(), 0, entry);
entry = next;
}
}
//---------------------------------------------------------------------------
// BoxOrder_Append
//---------------------------------------------------------------------------
_FX void BoxOrder_Append(BOX_ORDER_ENTRY *parent, BOX_ORDER_ENTRY *child)
{
if (! parent->children)
parent->children = child;
else {
BOX_ORDER_ENTRY *last = parent->children;
while (last->next)
last = last->next;
last->next = child;
}
}
//---------------------------------------------------------------------------
// BoxOrder_ReadSetting
//---------------------------------------------------------------------------
_FX WCHAR *BoxOrder_ReadSetting(const WCHAR *section_name)
{
WCHAR *result = NULL;
if (! section_name) {
static SBIE_INI_GET_USER_RPL *rpl = NULL;
if (! rpl) {
SBIE_INI_GET_USER_REQ req;
req.h.msgid = MSGID_SBIE_INI_GET_USER;
req.h.length = sizeof(SBIE_INI_GET_USER_REQ);
rpl = (SBIE_INI_GET_USER_RPL *)SbieDll_CallServer(&req.h);
if (rpl && rpl->h.status != 0) {
SbieDll_FreeMem(rpl);
rpl = NULL;
}
}
if (rpl && rpl->h.status == 0)
section_name = rpl->section;
}
if (section_name) {
ULONG result_len;
ULONG setting_idx = 0;
ULONG status;
result_len = 8192;
result = HeapAlloc(GetProcessHeap(), 0, result_len * sizeof(WCHAR));
if (result) {
WCHAR *result_ptr = result;
while (1) {
status = SbieApi_QueryConfAsIs(
section_name, BoxOrder_SettingName,
setting_idx | CONF_GET_NO_GLOBAL | CONF_GET_NO_TEMPLS,
result_ptr, (result_len - 8) * sizeof(WCHAR));
if (status != 0)
break;
++setting_idx;
result_len -= wcslen(result_ptr);
result_ptr += wcslen(result_ptr);
*result_ptr = L',';
++result_ptr;
if (result_len <= 8)
break;
}
if (result_ptr != result)
memzero(result_ptr, 4 * sizeof(WCHAR));
else {
HeapFree(GetProcessHeap(), 0, result);
result = NULL;
}
}
}
return result;
}
//---------------------------------------------------------------------------
// BoxOrder_ReadGroup2
//---------------------------------------------------------------------------
_FX BOX_ORDER_ENTRY *BoxOrder_ReadGroup2(WCHAR *name, WCHAR **ptext)
{
BOX_ORDER_ENTRY *group;
WCHAR *ptr, *text;
int count;
text = *ptext;
*text = L'\0';
if (! *name)
name = L"?";
group = BoxOrder_Alloc(name);
*text = L'(';
ptr = text + 1;
count = 1;
while (1) {
if (*ptr == L'(')
++count;
else if (*ptr == L')') {
--count;
if (! count) {
*ptr = L'\0';
break;
}
} else if (! *ptr)
break;
++ptr;
}
*ptext = ptr;
count = BoxOrder_ReadGroup(group, text + 1);
if (! count) {
BoxOrder_Free(group);
group = NULL;
}
return group;
}
//---------------------------------------------------------------------------
// BoxOrder_ReadGroup
//---------------------------------------------------------------------------
_FX int BoxOrder_ReadGroup(BOX_ORDER_ENTRY *parent, WCHAR *text)
{
WCHAR *sep, *sep2;
BOX_ORDER_ENTRY *new_entry;
int count = 0;
while (1) {
sep = wcschr(text, L',');
if (sep)
*sep = L'\0';
if (*text) {
new_entry = NULL;
sep2 = wcschr(text, L'(');
if (sep2) {
if (sep)
*sep = L',';
sep = sep2;
new_entry = BoxOrder_ReadGroup2(text, &sep);
} else if (SbieApi_IsBoxEnabled(text) == 0)
new_entry = BoxOrder_Alloc(text);
else
new_entry = NULL;
if (new_entry) {
BoxOrder_Append(parent, new_entry);
++count;
}
if ((! sep2) && sep)
*sep = L',';
}
if (! sep)
break;
text = sep + 1;
while (*sep == L',')
++sep;
}
return count;
}
//---------------------------------------------------------------------------
// BoxOrder_ReadFindBox
//---------------------------------------------------------------------------
_FX int BoxOrder_ReadFindBox(BOX_ORDER_ENTRY *entry, const WCHAR *name)
{
while (entry) {
if (entry->children) {
if (BoxOrder_ReadFindBox(entry->children, name))
return 1;
} else if (_wcsicmp(entry->name, name) == 0)
return 1;
entry = entry->next;
}
return 0;
}
//---------------------------------------------------------------------------
// BoxOrder_ReadMissing
//---------------------------------------------------------------------------
_FX void BoxOrder_ReadMissing(BOX_ORDER_ENTRY *parent)
{
WCHAR work_name[34], *all_names, *name;
int box_count, box_index, name_index, small_index, alloc_len;
box_count = 0;
box_index = -1;
while (1) {
box_index = SbieApi_EnumBoxesEx(
box_index | CONF_GET_NO_TEMPLS, work_name, TRUE);
if (box_index == -1)
break;
if (SbieApi_IsBoxEnabled(work_name) == 0)
++box_count;
}
if (! box_count)
return;
alloc_len = box_count * (34 * sizeof(WCHAR));
all_names = HeapAlloc(GetProcessHeap(), 0, alloc_len);
name_index = 0;
box_index = -1;
while (name_index < box_count) {
name = &all_names[name_index * 34];
box_index = SbieApi_EnumBoxesEx(
box_index | CONF_GET_NO_TEMPLS, name, TRUE);
if (box_index == -1)
break;
if (SbieApi_IsBoxEnabled(name) == 0)
++name_index;
}
while (1) {
small_index = -1;
for (name_index = 0; name_index < box_count; ++name_index) {
name = &all_names[name_index * 34];
if (! *name)
continue;
if (small_index == -1)
small_index = name_index;
else {
const WCHAR *small_name = &all_names[small_index * 34];
if (_wcsicmp(small_name, name) > 0)
small_index = name_index;
}
}
if (small_index == -1)
break;
name = &all_names[small_index * 34];
if (! BoxOrder_ReadFindBox(parent, name)) {
BOX_ORDER_ENTRY *new_entry = BoxOrder_Alloc(name);
if (new_entry)
BoxOrder_Append(parent, new_entry);
}
name[0] = L'\0';
}
HeapFree(GetProcessHeap(), 0, all_names);
}
//---------------------------------------------------------------------------
// BoxOrder_ReadEx
//---------------------------------------------------------------------------
_FX BOX_ORDER_ENTRY *BoxOrder_ReadEx(int ReadUser, int ReadDefault)
{
WCHAR *text;
BOX_ORDER_ENTRY *root;
if (ReadUser)
text = BoxOrder_ReadSetting(NULL);
else
text = NULL;
if ((! text) && ReadDefault)
text = BoxOrder_ReadSetting(L"UserSettings_Default");
root = BoxOrder_Alloc(L"");
if (root) {
if (text)
BoxOrder_ReadGroup(root, text);
BoxOrder_ReadMissing(root);
}
if (text)
HeapFree(GetProcessHeap(), 0, text);
return root;
}
//---------------------------------------------------------------------------
// BoxOrder_Read
//---------------------------------------------------------------------------
_FX BOX_ORDER_ENTRY *BoxOrder_Read(void)
{
return BoxOrder_ReadEx(TRUE, TRUE);
}
//---------------------------------------------------------------------------
// BoxOrder_ReadDefault
//---------------------------------------------------------------------------
_FX BOX_ORDER_ENTRY *BoxOrder_ReadDefault(void)
{
return BoxOrder_ReadEx(FALSE, TRUE);
}
//---------------------------------------------------------------------------
// BoxOrder_ToString2
//---------------------------------------------------------------------------
_FX int BoxOrder_ToString2(BOX_ORDER_ENTRY *entry, WCHAR *text)
{
int count = wcslen(entry->name);
if (text) {
wcscpy(text, entry->name);
text += count;
}
if (entry->children) {
BOX_ORDER_ENTRY *child = entry->children;
if (*entry->name) {
++count;
if (text) {
*text = L'(';
++text;
}
}
while (child) {
int count2 = BoxOrder_ToString2(child, text);
count += count2;
if (text)
text += count2;
if (child->next) {
++count;
if (text) {
*text = L',';
++text;
}
}
child = child->next;
}
if (*entry->name) {
++count;
if (text) {
*text = L')';
++text;
}
}
}
return count;
}
//---------------------------------------------------------------------------
// BoxOrder_ToString
//---------------------------------------------------------------------------
_FX WCHAR *BoxOrder_ToString(BOX_ORDER_ENTRY *root)
{
WCHAR *text = NULL;
int count = BoxOrder_ToString2(root, NULL);
if (count) {
int count2 = (count + 1) * sizeof(WCHAR);
text = HeapAlloc(GetProcessHeap(), 0, count2);
if (text) {
count2 = BoxOrder_ToString2(root, text);
if (count2 > count)
count2 = count;
text[count2] = L'\0';
}
}
return text;
}
//---------------------------------------------------------------------------
// BoxOrder_WriteSetting
//---------------------------------------------------------------------------
_FX int BoxOrder_WriteSetting(WCHAR *text)
{
ULONG status;
WCHAR *ptr;
WCHAR opcode = L's';
for (ptr = text; ptr; text = ptr) {
if (wcslen(text) > 1000) {
ptr = text + 1000;
while (*ptr && *ptr != L',')
++ptr;
if (*ptr == L',') {
*ptr = L'\0';
++ptr;
} else
ptr = NULL;
} else
ptr = NULL;
status = SbieDll_UpdateConf(
opcode, NULL, L"UserSettings_?", BoxOrder_SettingName, text);
if (status != 0)
return 0;
opcode = L'a';
}
return 1;
}
//---------------------------------------------------------------------------
// BoxOrder_Write
//---------------------------------------------------------------------------
int BoxOrder_Write(BOX_ORDER_ENTRY *root)
{
WCHAR *text_old, *text_new;
int return_code = -1;
BOX_ORDER_ENTRY *root_old = BoxOrder_ReadDefault();
if (root_old) {
text_old = BoxOrder_ToString(root_old);
BoxOrder_Free(root_old);
} else
text_old = NULL;
text_new = BoxOrder_ToString(root);
if (text_old && text_new) {
int success_code = 1;
if (wcscmp(text_old, text_new) == 0) {
success_code = 0;
*text_new = L'\0';
}
if (BoxOrder_WriteSetting(text_new))
return_code = success_code;
}
if (text_new)
HeapFree(GetProcessHeap(), 0, text_new);
if (text_old)
HeapFree(GetProcessHeap(), 0, text_old);
return return_code;
}

View File

@ -0,0 +1,73 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Box Order Utility
//---------------------------------------------------------------------------
#ifndef _MY_BOXORDER_H
#define _MY_BOXORDER_H
#ifdef __cplusplus
extern "C" {
#endif
//---------------------------------------------------------------------------
// Types and Structures
//---------------------------------------------------------------------------
typedef struct _BOX_ORDER_ENTRY {
struct _BOX_ORDER_ENTRY *next;
struct _BOX_ORDER_ENTRY *children;
WCHAR name[1];
} BOX_ORDER_ENTRY;
//---------------------------------------------------------------------------
// Functions
//---------------------------------------------------------------------------
BOX_ORDER_ENTRY *BoxOrder_Alloc(const WCHAR *name);
void BoxOrder_Free(BOX_ORDER_ENTRY *entry);
void BoxOrder_Append(BOX_ORDER_ENTRY *parent, BOX_ORDER_ENTRY *child);
BOX_ORDER_ENTRY *BoxOrder_Read(void);
BOX_ORDER_ENTRY *BoxOrder_ReadDefault(void);
int BoxOrder_Write(BOX_ORDER_ENTRY *root);
//---------------------------------------------------------------------------
#ifdef __cplusplus
}
#endif
#endif _MY_BOXORDER_H

View File

@ -0,0 +1,118 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="SbieDebug|Win32">
<Configuration>SbieDebug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="SbieDebug|x64">
<Configuration>SbieDebug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="SbieRelease|Win32">
<Configuration>SbieRelease</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="SbieRelease|x64">
<Configuration>SbieRelease</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{67579365-ED6A-C1E4-E0A3-4A7C9F14072D}</ProjectGuid>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\Sandbox32.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\Sandbox64.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\Sandbox32.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\Sandbox64.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'">
<ClCompile>
<ExceptionHandling>Sync</ExceptionHandling>
</ClCompile>
<Lib>
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'">
<ClCompile>
<ExceptionHandling>Sync</ExceptionHandling>
</ClCompile>
<Lib>
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'">
<ClCompile>
<ExceptionHandling>Sync</ExceptionHandling>
</ClCompile>
<Lib>
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'">
<ClCompile>
<ExceptionHandling>Sync</ExceptionHandling>
</ClCompile>
<Lib>
<IgnoreAllDefaultLibraries>true</IgnoreAllDefaultLibraries>
</Lib>
</ItemDefinitionGroup>
<ItemGroup>
</ItemGroup>
<ItemGroup>
<ClCompile Include="BoxOrder.c" />
<ClCompile Include="DlgTmplRtl.cpp" />
<ClCompile Include="MyFileOp.c" />
<ClCompile Include="MyGdi.c" />
<ClCompile Include="MyMsgBox.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="BoxOrder.h" />
<ClInclude Include="CommonUtils.h" />
<ClInclude Include="MyGdi.h" />
<ClInclude Include="MyMsgBox.h" />
<ClInclude Include="MyPool.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View File

@ -0,0 +1,68 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Common Utility Functions
//---------------------------------------------------------------------------
#ifndef _MY_COMMONUTILS_H
#define _MY_COMMONUTILS_H
//---------------------------------------------------------------------------
// Functions (c++)
//---------------------------------------------------------------------------
#ifdef __cplusplus
#include <afxcmn.h>
void Common_RunStartExe(const CString &cmd, const CString &box,
BOOL wait = FALSE, BOOL inherit = FALSE);
#endif __cplusplus
//---------------------------------------------------------------------------
// Functions (c)
//---------------------------------------------------------------------------
#ifdef __cplusplus
extern "C" {
#endif
void *Common_DlgTmplRtl(HINSTANCE hInst, const WCHAR *TmplName);
int Common_SHFileOperation(void *lpSHFileOpStruct, BOOL *pYesToAll,
const WCHAR *ReplaceButtonText);
#ifdef __cplusplus
}
#endif
//---------------------------------------------------------------------------
#endif _MY_COMMONUTILS_H

View File

@ -0,0 +1,67 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Common Utility Functions
//---------------------------------------------------------------------------
#include "CommonUtils.h"
//---------------------------------------------------------------------------
// Common_DlgTmplRtl
//---------------------------------------------------------------------------
extern "C" void *Common_DlgTmplRtl(HINSTANCE hInst, const WCHAR *TmplName)
{
HRSRC hResource = ::FindResource(hInst, TmplName, RT_DIALOG);
HGLOBAL hGlobal = LoadResource(hInst, hResource);
void *DataPtr = LockResource(hGlobal);
if (DataPtr) {
typedef struct {
DWORD style;
DWORD dwExtendedStyle;
} DLGTMPL1;
typedef struct {
WORD dlgVer;
WORD signature;
DWORD helpID;
DWORD exStyle;
DWORD style;
} DLGTMPL2;
ULONG *exStyle;
ULONG DataSize = SizeofResource(hInst, hResource);
void *NewTmpl = HeapAlloc(
GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, DataSize);
memcpy(NewTmpl, DataPtr, DataSize);
if (((DLGTMPL2 *)NewTmpl)->signature == 0xFFFF)
exStyle = &((DLGTMPL2 *)NewTmpl)->exStyle;
else
exStyle = &((DLGTMPL1 *)NewTmpl)->dwExtendedStyle;
(*exStyle) |= WS_EX_LAYOUTRTL;
return NewTmpl;
}
return NULL;
}

View File

@ -0,0 +1,77 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Font Store
//---------------------------------------------------------------------------
#include "stdafx.h"
#include "FontStore.h"
#include "common/defines.h"
//---------------------------------------------------------------------------
// Variables
//---------------------------------------------------------------------------
CFontStore *CFontStore::m_instance = NULL;
//---------------------------------------------------------------------------
// Get
//---------------------------------------------------------------------------
CFont *CFontStore::Get(
const CString &TypeFaceName, int PointSize, int Weight)
{
if (! m_instance)
m_instance = new CFontStore();
CString key;
key.Format(L"%s:%d:%d", TypeFaceName, PointSize, Weight);
void *ptr;
if (m_instance->Lookup(key, ptr))
return (CFont *)ptr;
HDC hDC = ::GetDC(NULL);
int dpi = GetDeviceCaps(hDC, LOGPIXELSY);
if (dpi > 96) {
// reduce one point size for every 25% increase over the base 96 DPI
PointSize -= (dpi - 96) / 24;
}
::ReleaseDC(NULL, hDC);
LOGFONT logfont;
memzero(&logfont, sizeof(LOGFONT));
logfont.lfCharSet = DEFAULT_CHARSET;
logfont.lfHeight = PointSize * 10; // see CreatePointFontIndirect in MFC
logfont.lfWeight = Weight;
int len = max(TypeFaceName.GetLength(), 30);
wmemcpy(logfont.lfFaceName, TypeFaceName, len);
logfont.lfFaceName[len] = L'\0';
CFont *font = new CFont();
font->CreatePointFontIndirect(&logfont, NULL);
m_instance->SetAt(key, font);
return font;
}

View File

@ -0,0 +1,43 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Font Store
//---------------------------------------------------------------------------
#ifndef _MY_FONTSTORE_H
#define _MY_FONTSTORE_H
#include <afxcmn.h>
class CFontStore : public CMapStringToPtr
{
static CFontStore *m_instance;
public:
static CFont *Get(const CString &TypeFaceName, int PointSize,
int Weight = FW_NORMAL);
};
#endif // _MY_FONTSTORE_H

View File

@ -0,0 +1,737 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Layout Class
//---------------------------------------------------------------------------
#include "stdafx.h"
#include "Layout.h"
#include "common/defines.h"
#include <math.h>
//---------------------------------------------------------------------------
// CLayoutChild Class
//---------------------------------------------------------------------------
struct CLayoutChild
{
CWnd *m_wnd;
CPoint m_pos; // in percent
CSize m_size; // in percent
CSize m_size_min; // in pixels
CSize m_size_max; // in pixels
CLayoutChild(CWnd *wnd, const CPoint &pos, const CSize &size)
{
m_wnd = wnd; m_pos = pos; m_size = size;
m_size_min.cx = 0; m_size_min.cy = 0;
m_size_max.cx = 0; m_size_max.cy = 0;
}
};
//---------------------------------------------------------------------------
// CLayout Constructor
//---------------------------------------------------------------------------
CLayout::CLayout(CWnd *wnd)
{
m_wnd = wnd;
}
//---------------------------------------------------------------------------
// CLayout Destructor
//---------------------------------------------------------------------------
CLayout::~CLayout()
{
DeleteChildren();
}
//---------------------------------------------------------------------------
// CLayout::AttachChild
//---------------------------------------------------------------------------
BOOL CLayout::AttachChild(
CWnd *wnd, const CPoint &point, const CSize &size)
{
CLayoutChild *childobj = new CLayoutChild(wnd, point, size);
if (! childobj)
return FALSE;
m_children.AddTail(childobj);
if (m_wnd->IsWindowVisible())
Calculate();
return TRUE;
}
//---------------------------------------------------------------------------
// CLayout::ReplaceChild
//---------------------------------------------------------------------------
BOOL CLayout::ReplaceChild(CWnd *oldchild, CWnd *newchild)
{
POSITION pos = m_children.GetHeadPosition();
while (pos) {
POSITION save_pos = pos;
CLayoutChild *childobj = (CLayoutChild *)m_children.GetNext(pos);
if (childobj->m_wnd == oldchild) {
delete oldchild;
childobj->m_wnd = newchild;
return TRUE;
}
}
return FALSE;
}
//---------------------------------------------------------------------------
// CLayout::SetMinMaxChildObject
//---------------------------------------------------------------------------
BOOL CLayout::SetMinMaxChildObject(
CWnd *wnd, const CSize &size_min, const CSize &size_max)
{
POSITION pos = m_children.GetHeadPosition();
while (pos) {
CLayoutChild *childobj = (CLayoutChild *)m_children.GetNext(pos);
if (childobj->m_wnd == wnd) {
childobj->m_size_min = size_min;
childobj->m_size_max = size_max;
return TRUE;
}
}
return FALSE;
}
//---------------------------------------------------------------------------
// CLayout::CreateChild
//---------------------------------------------------------------------------
CWnd *CLayout::CreateChild(
int ctrlid, const WCHAR *clsnm, ULONG exstyle, ULONG style,
const CPoint &pos, const CSize &size)
{
CWnd *wnd = new CWnd();
if (wnd->CreateEx(exstyle, clsnm, L"", (style | WS_CHILD | WS_VISIBLE),
CRect(), m_wnd, ctrlid, NULL)) {
if (AttachChild(wnd, pos, size)) {
return wnd;
}
}
delete wnd;
return NULL;
}
//---------------------------------------------------------------------------
// CLayout::DeleteChild
//---------------------------------------------------------------------------
BOOL CLayout::DeleteChild(HWND hwnd)
{
POSITION pos = m_children.GetHeadPosition();
while (pos) {
POSITION save_pos = pos;
CLayoutChild *childobj = (CLayoutChild *)m_children.GetNext(pos);
if (childobj->m_wnd->m_hWnd == hwnd) {
m_children.RemoveAt(save_pos);
delete childobj->m_wnd;
delete childobj;
return TRUE;
}
}
return FALSE;
}
//---------------------------------------------------------------------------
// CLayout::DeleteChild
//---------------------------------------------------------------------------
BOOL CLayout::DeleteChild(CWnd *wnd)
{
return DeleteChild(wnd->m_hWnd);
}
//---------------------------------------------------------------------------
// CLayout::DeleteChildren
//---------------------------------------------------------------------------
void CLayout::DeleteChildren()
{
while (! m_children.IsEmpty()) {
CLayoutChild *childobj = (CLayoutChild *)m_children.RemoveHead();
delete childobj->m_wnd;
delete childobj;
}
}
//---------------------------------------------------------------------------
// CLayout::GetChildByIndex
//---------------------------------------------------------------------------
CWnd *CLayout::GetChildByIndex(int index)
{
POSITION pos = m_children.GetHeadPosition();
while (pos) {
CLayoutChild *childobj = (CLayoutChild *)m_children.GetNext(pos);
if (index == 0)
return childobj->m_wnd;
--index;
}
return NULL;
}
//---------------------------------------------------------------------------
// CLayout::CalculatePositionAndSize
//---------------------------------------------------------------------------
void CLayout::CalculatePositionAndSize(void *_childobj, int w, int h,
CPoint &out_pos, CSize &out_size)
{
CLayoutChild *childobj = (CLayoutChild *)_childobj;
int x = (int)floorf(childobj->m_pos.x * w / 100.0f + 0.5f);
int y = (int)floorf(childobj->m_pos.y * h / 100.0f + 0.5f);
int cx = (int)floorf(childobj->m_size.cx * w / 100.0f + 0.5f);
int cy = (int)floorf(childobj->m_size.cy * h / 100.0f + 0.5f);
if (childobj->m_size_min.cx && cx < childobj->m_size_min.cx)
cx = childobj->m_size_min.cx;
if (childobj->m_size_min.cy && cy < childobj->m_size_min.cy)
cy = childobj->m_size_min.cy;
if (childobj->m_size_max.cx && cx > childobj->m_size_max.cx)
cx = childobj->m_size_max.cx;
if (childobj->m_size_max.cy && cy > childobj->m_size_max.cy)
cy = childobj->m_size_max.cy;
out_pos.x = x;
out_pos.y = y;
out_size.cx = cx;
out_size.cy = cy;
}
//---------------------------------------------------------------------------
// CLayout::CalculateOneWindow
//---------------------------------------------------------------------------
void CLayout::CalculateOneWindow(void *_childobj)
{
CLayoutChild *childobj = (CLayoutChild *)_childobj;
CRect rc;
m_wnd->GetClientRect(&rc);
CPoint pos;
CSize size;
CalculatePositionAndSize(
childobj, rc.Width(), rc.Height(), pos, size);
childobj->m_wnd->SetWindowPos(NULL, pos.x, pos.y, size.cx, size.cy,
SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
}
//---------------------------------------------------------------------------
// CLayout::Calculate
//---------------------------------------------------------------------------
void CLayout::Calculate()
{
int num_children = (int)m_children.GetCount();
if (num_children <= 1) {
if (num_children == 1)
CalculateOneWindow(m_children.GetHead());
return;
}
CRect rc;
m_wnd->GetClientRect(&rc);
int w = rc.Width();
int h = rc.Height();
HDWP hdwp = BeginDeferWindowPos(num_children + 2);
POSITION pos = m_children.GetHeadPosition();
while (pos) {
CLayoutChild *childobj = (CLayoutChild *)m_children.GetNext(pos);
CPoint pos;
CSize size;
CalculatePositionAndSize(
childobj, rc.Width(), rc.Height(), pos, size);
hdwp = DeferWindowPos(
hdwp, childobj->m_wnd->m_hWnd, 0,
pos.x, pos.y, size.cx, size.cy,
SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
}
EndDeferWindowPos(hdwp);
}
//---------------------------------------------------------------------------
// CLayoutWnd Message Map
//---------------------------------------------------------------------------
BEGIN_MESSAGE_MAP(CLayoutWnd, CWnd)
ON_WM_SIZE()
ON_WM_SIZING()
ON_WM_DESTROY()
ON_WM_PARENTNOTIFY()
END_MESSAGE_MAP()
//---------------------------------------------------------------------------
// CLayoutWnd Constructor
//---------------------------------------------------------------------------
#pragma warning(push)
#pragma warning(disable: 4355)
CLayoutWnd::CLayoutWnd()
: m_layout(this)
{
}
#pragma warning(pop)
//---------------------------------------------------------------------------
// CLayoutWnd::CreateChild
//---------------------------------------------------------------------------
CWnd *CLayoutWnd::CreateChild(
int ctrlid, const WCHAR *clsnm, ULONG exstyle, ULONG style,
const CPoint &pos, const CSize &size)
{
return m_layout.CreateChild(ctrlid, clsnm, exstyle, style, pos, size);
}
//---------------------------------------------------------------------------
// CLayoutWnd::CreateLayoutCtrl
//---------------------------------------------------------------------------
CLayoutWnd *CLayoutWnd::CreateLayoutCtrl(
const CPoint &pos, const CSize &size)
{
static ATOM _layout_ctrl_atom = NULL;
if (! _layout_ctrl_atom) {
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_GLOBALCLASS;
wc.lpfnWndProc = LayoutCtrlWndClass;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = AfxGetInstanceHandle();
wc.hIcon = NULL;
wc.hCursor = ::LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = L"LayoutCtrlClass";
wc.hIconSm = NULL;
_layout_ctrl_atom = RegisterClassEx(&wc);
if (! _layout_ctrl_atom)
return FALSE;
}
CLayoutWnd *ctrl = new CLayoutWnd();
if (ctrl) {
const ULONG exstyle = 0;
const ULONG style = WS_CHILD | WS_VISIBLE;
if (ctrl->CreateEx(exstyle, (LPCTSTR)_layout_ctrl_atom, L"",
style, CRect(), this, -1, NULL)) {
if (m_layout.AttachChild(ctrl, pos, size)) {
return ctrl;
}
ctrl->DestroyWindow();
}
delete ctrl;
}
return NULL;
}
//---------------------------------------------------------------------------
// CLayoutWnd::LayoutCtrlWndClass
//---------------------------------------------------------------------------
LRESULT CLayoutWnd::LayoutCtrlWndClass(
HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if ((uMsg >= WM_CTLCOLORMSGBOX && uMsg <= WM_CTLCOLORSTATIC) ||
uMsg == WM_COMMAND) {
hwnd = ::GetParent(hwnd);
return ::SendMessage(hwnd, uMsg, wParam, lParam);
} else
return ::DefWindowProc(hwnd, uMsg, wParam, lParam);
}
//---------------------------------------------------------------------------
// CLayoutWnd::GetChildByIndex
//---------------------------------------------------------------------------
CWnd *CLayoutWnd::GetChildByIndex(int index)
{
return m_layout.GetChildByIndex(index);
}
//---------------------------------------------------------------------------
// CLayoutWnd::OnSize
//---------------------------------------------------------------------------
void CLayoutWnd::OnSize(UINT nType, int cx, int cy)
{
if (nType == SIZE_MAXIMIZED || nType == SIZE_RESTORED)
m_layout.Calculate();
CWnd::OnSize(nType, cx, cy);
}
//---------------------------------------------------------------------------
// CLayoutWnd::OnSizing
//---------------------------------------------------------------------------
void CLayoutWnd::OnSizing(UINT nSide, LPRECT lpRect)
{
m_layout.Calculate();
CWnd::OnSizing(nSide, lpRect);
}
//---------------------------------------------------------------------------
// CLayoutWnd::OnDestroy
//---------------------------------------------------------------------------
void CLayoutWnd::OnDestroy()
{
m_layout.DeleteChildren();
CWnd::OnDestroy();
}
//---------------------------------------------------------------------------
// CLayoutWnd::OnParentNotify
//---------------------------------------------------------------------------
void CLayoutWnd::OnParentNotify(UINT message, LPARAM lParam)
{
if (message == WM_DESTROY)
m_layout.DeleteChild(CWnd::FromHandle((HWND)lParam));
CWnd::OnParentNotify(message, lParam);
}
//---------------------------------------------------------------------------
// CLayoutPropertyPage Message Map
//---------------------------------------------------------------------------
BEGIN_MESSAGE_MAP(CLayoutPropertyPage, CPropertyPage)
ON_WM_ERASEBKGND()
ON_WM_CTLCOLOR()
END_MESSAGE_MAP()
//---------------------------------------------------------------------------
// CLayoutPropertyPage Constructor
//---------------------------------------------------------------------------
#pragma warning(push)
#pragma warning(disable: 4355)
CLayoutPropertyPage::CLayoutPropertyPage(int page_num)
: m_layout(this), m_page_num(page_num)
{
}
#pragma warning(pop)
//---------------------------------------------------------------------------
// CLayoutPropertyPage::InitPage
//---------------------------------------------------------------------------
void CLayoutPropertyPage::InitPage(
ULONG exstyle, const CSize &pct_size, const CSize &size_min,
const CSize &size_max, HBRUSH hbrush)
{
//
// pct_x and pct_y specify the desired size of the dialog box as
// a percent of the desktop screen size
//
CRect rc;
GetDesktopWindow()->GetWindowRect(&rc);
int cx = (int)floorf(pct_size.cx * rc.Width() / 100.0f + 0.5f);
int cy = (int)floorf(pct_size.cy * rc.Height() / 100.0f + 0.5f);
if (size_min.cx && cx < size_min.cx)
cx = size_min.cx;
if (size_min.cy && cy < size_min.cy)
cy = size_min.cy;
if (size_max.cx && cx > size_max.cx)
cx = size_max.cx;
if (size_max.cy && cy > size_max.cy)
cy = size_max.cy;
return InitPage(exstyle, CSize(cx, cy), hbrush);
}
//---------------------------------------------------------------------------
// CLayoutPropertyPage::InitPage
//---------------------------------------------------------------------------
void CLayoutPropertyPage::InitPage(
ULONG exstyle, const CSize &abs_size, HBRUSH hbrush)
{
//
// we need to convert screen units to dialog units, which are the
// average character size in the font. the font is the system default
// dialog font because we don't override that in the dialog template
//
UINT cxFont = 8, cyFont = 16;
CFont font;
if (font.CreateStockObject(DEFAULT_GUI_FONT)) {
static const WCHAR *_alphabet =
L"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
HDC hdc = ::GetDC(NULL);
HFONT oldfont = (HFONT)SelectObject(hdc, font);
SIZE size;
TEXTMETRIC tm;
GetTextMetrics(hdc, &tm);
cyFont = tm.tmHeight + tm.tmExternalLeading;
::GetTextExtentPoint32(hdc, _alphabet, 52, &size);
cxFont = (size.cx + 26) / 52;
::SelectObject(hdc, oldfont);
::ReleaseDC(NULL, hdc);
}
//
// construct a trivial and empty dialog box template
//
typedef struct {
DWORD style;
DWORD dwExtendedStyle;
WORD cdit;
short x;
short y;
short cx;
short cy;
WORD id;
} DLGTMPL1;
memzero(&m_dlgtmpl, sizeof(m_dlgtmpl));
DLGTMPL1 *tmpl = (DLGTMPL1 *)m_dlgtmpl;
tmpl->style = WS_CHILD | WS_DISABLED | WS_CAPTION;
tmpl->dwExtendedStyle = exstyle;
tmpl->cdit = 0;
tmpl->cx = (short)(abs_size.cx * 4 / cxFont);
tmpl->cy = (short)(abs_size.cy * 8 / cyFont);
m_psp.pResource = (LPCDLGTEMPLATE)tmpl;
m_psp.dwFlags |= PSP_DLGINDIRECT;
//
// set background brush
//
m_hbrush = hbrush;
}
//---------------------------------------------------------------------------
// CLayoutPropertyPage::CreateChild
//---------------------------------------------------------------------------
CWnd *CLayoutPropertyPage::CreateChild(
int ctrlid, const WCHAR *clsnm, ULONG exstyle, ULONG style,
const CPoint &pos, const CSize &size)
{
CWnd *wnd = m_layout.CreateChild(
ctrlid, clsnm, exstyle, style, pos, size);
wnd->SetFont(GetFont());
return wnd;
}
//---------------------------------------------------------------------------
// CLayoutPropertyPage::OnEraseBkgnd
//---------------------------------------------------------------------------
BOOL CLayoutPropertyPage::OnEraseBkgnd(CDC *pDC)
{
if (! m_hbrush)
return CPropertyPage::OnEraseBkgnd(pDC);
CRect rc;
GetClientRect(&rc);
pDC->SelectObject(m_hbrush);
pDC->PatBlt(0, 0, rc.Width(), rc.Height(), PATCOPY);
return TRUE;
}
//---------------------------------------------------------------------------
// CLayoutPropertyPage::OnCtlColor
//---------------------------------------------------------------------------
HBRUSH CLayoutPropertyPage::OnCtlColor(CDC *pDC, CWnd *pWnd, UINT nCtlColor)
{
HBRUSH hbr = CPropertyPage::OnCtlColor(pDC, pWnd, nCtlColor);
if (m_hbrush && nCtlColor == CTLCOLOR_STATIC) {
bool MakeTransparent = true;
WCHAR clsnm[130];
if (GetClassName(pWnd->m_hWnd, clsnm, 128 * sizeof(WCHAR)) &&
_wcsicmp(clsnm, L"Edit") == 0) {
//
// WM_CTLCOLORSTATIC (nCtlColor == CTLCOLOR_STATIC)
// is also received by read-only/disabled edit controls,
// but we don't want to change those
//
MakeTransparent = false;
}
if (MakeTransparent) {
hbr = (HBRUSH)::GetStockObject(NULL_BRUSH);
pDC->SetBkMode(TRANSPARENT);
COLORREF rgb = 0;
CString text;
pWnd->GetWindowText(text);
if (text.Left(7).Compare(L"http://") == 0)
rgb = RGB(0,0,255);
pDC->SetTextColor(rgb);
}
}
return hbr;
}
//---------------------------------------------------------------------------
// CLayoutPropertyPage::OnInitDialog
//---------------------------------------------------------------------------
BOOL CLayoutPropertyPage::OnInitDialog()
{
m_layout.Calculate();
return TRUE;
}
//---------------------------------------------------------------------------
// CLayoutPropertyPage::OnSetActive
//---------------------------------------------------------------------------
BOOL CLayoutPropertyPage::OnSetActive()
{
SetWindowPos(NULL, 0, 0, 0, 0, // fixes a problem with WS_EX_LAYOUTRTL
SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
CPropertySheet *sheet = (CPropertySheet *)GetParent();
ULONG flags = 0;
if (m_page_num > 1)
flags |= PSWIZB_BACK;
if (m_page_num == sheet->GetPageCount())
flags |= PSWIZB_FINISH;
else
flags |= PSWIZB_NEXT;
sheet->SetWizardButtons(flags);
return CPropertyPage::OnSetActive();
}

View File

@ -0,0 +1,169 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Layout Class
//---------------------------------------------------------------------------
#ifndef _MY_LAYOUT_H
#define _MY_LAYOUT_H
#include <afxcmn.h>
#include <afxdlgs.h>
//---------------------------------------------------------------------------
// CLayout Class
//---------------------------------------------------------------------------
class CLayout
{
protected:
CWnd *m_wnd;
CPtrList m_children;
protected:
void CalculatePositionAndSize(void *_childobj, int w, int h,
CPoint &out_pos, CSize &out_size);
void CalculateOneWindow(void *_childobj);
public:
CLayout(CWnd *wnd);
~CLayout();
BOOL AttachChild(CWnd *child, const CPoint &pos, const CSize &size);
BOOL ReplaceChild(CWnd *oldchild, CWnd *newchild);
BOOL SetMinMaxChildObject(
CWnd *wnd, const CSize &size_min, const CSize &size_max);
CWnd *CreateChild(int ctrlid, const WCHAR *clsnm,
ULONG exstyle, ULONG style,
const CPoint &pos, const CSize &size);
void DeleteChildren();
BOOL DeleteChild(HWND hwnd);
BOOL DeleteChild(CWnd *wnd);
CWnd *GetChildByIndex(int index);
void Calculate();
};
//---------------------------------------------------------------------------
// CLayoutWnd Class
//---------------------------------------------------------------------------
class CLayoutWnd : public CWnd
{
protected:
DECLARE_MESSAGE_MAP()
CLayout m_layout;
protected:
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnSizing(UINT nSide, LPRECT lpRect);
afx_msg void OnDestroy();
afx_msg void OnParentNotify(UINT message, LPARAM lParam);
static LRESULT LayoutCtrlWndClass(
HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
public:
CWnd *CreateChild(int ctrlid, const WCHAR *clsnm,
ULONG exstyle, ULONG style,
const CPoint &pos, const CSize &size);
CLayoutWnd *CreateLayoutCtrl(const CPoint &pos, const CSize &size);
CWnd *GetChildByIndex(int index);
CLayoutWnd();
};
//---------------------------------------------------------------------------
// CLayoutPropertyPage Class
//---------------------------------------------------------------------------
class CLayoutPropertyPage : public CPropertyPage
{
protected:
DECLARE_MESSAGE_MAP()
CLayout m_layout;
ULONG m_dlgtmpl[16];
HBRUSH m_hbrush;
int m_page_num;
protected:
virtual BOOL OnInitDialog();
virtual BOOL OnSetActive();
afx_msg BOOL OnEraseBkgnd(CDC *pDC);
afx_msg HBRUSH OnCtlColor(CDC *pDC, CWnd *pWnd, UINT nCtlColor);
public:
CWnd *CreateChild(int ctrlid, const WCHAR *clsnm,
ULONG exstyle, ULONG style,
const CPoint &pos, const CSize &size);
CLayoutPropertyPage(int page_num);
void InitPage(ULONG exstyle, const CSize &abs_size, HBRUSH hbrush);
void InitPage(ULONG exstyle, const CSize &pct_size, const CSize &size_min, const CSize &size_max, HBRUSH hbrush);
};
//---------------------------------------------------------------------------
#endif // _MY_LAYOUT_H

View File

@ -0,0 +1,132 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Command Line Parser Utility
//---------------------------------------------------------------------------
#include "stdafx.h"
#include <windows.h>
#include "MyCmdLine.h"
#include "common/defines.h"
//---------------------------------------------------------------------------
// Constructor
//---------------------------------------------------------------------------
CMyCmdLine::CMyCmdLine(const WCHAR *CommandLineString)
{
if (CommandLineString)
m_Next = CommandLineString;
else
m_Next = GetCommandLine();
if (! m_Next)
m_Next = L"";
m_Prev = NULL;
}
//---------------------------------------------------------------------------
// Destructor
//---------------------------------------------------------------------------
CMyCmdLine::~CMyCmdLine()
{
if (m_Prev)
HeapFree(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, m_Prev);
}
//---------------------------------------------------------------------------
// EatString
//---------------------------------------------------------------------------
const WCHAR *CMyCmdLine::EatString(const WCHAR *str)
{
bool quoted = false;
while (*str == L' ')
++str;
while (*str) {
if (*str == L'\"')
quoted = !quoted;
else if (*str == L' ' && (! quoted))
break;
++str;
}
while (*str == L' ')
++str;
return str;
}
//---------------------------------------------------------------------------
// Count
//---------------------------------------------------------------------------
int CMyCmdLine::Count()
{
const WCHAR *ptr = m_Next;
int n = 0;
do {
++n;
ptr = EatString(ptr);
} while (*ptr);
return (n - 1);
}
//---------------------------------------------------------------------------
// Next
//---------------------------------------------------------------------------
const WCHAR *CMyCmdLine::Next()
{
if (m_Prev) {
HeapFree(GetProcessHeap(), HEAP_GENERATE_EXCEPTIONS, m_Prev);
m_Prev = NULL;
}
m_Next = EatString(m_Next);
if (*m_Next) {
const WCHAR *Next2 = m_Next;
while (*Next2 && *Next2 != L' ')
++Next2;
ULONG len = (ULONG)(Next2 - m_Next);
m_Prev = (WCHAR *)HeapAlloc(GetProcessHeap(), 0,
(len + 1) * sizeof(WCHAR));
if (m_Prev) {
wmemcpy(m_Prev, m_Next, len);
m_Prev[len] = L'\0';
}
}
return m_Prev;
}

View File

@ -0,0 +1,46 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Command Line Parser Utility
//---------------------------------------------------------------------------
#ifndef _MY_MYCMDLINE_H
#define _MY_MYCMDLINE_H
class CMyCmdLine
{
const WCHAR *m_Next;
WCHAR *m_Prev;
static const WCHAR *EatString(const WCHAR *str);
public:
CMyCmdLine(const WCHAR *CommandLineString = NULL);
~CMyCmdLine();
int Count();
const WCHAR *Next();
};
#endif // _MY_MYCMDLINE_H

View File

@ -0,0 +1,275 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// SHFileOperation with Yes To All button
//---------------------------------------------------------------------------
#include <windows.h>
#include <shellapi.h>
#include "CommonUtils.h"
#include "common/defines.h"
//---------------------------------------------------------------------------
// Functions
//---------------------------------------------------------------------------
static LRESULT CALLBACK MyFileOp_Hook(
int nCode, WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK MyFileOp_NewWindowProc(
HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
static HWND MyFileOp_InsertYesToAllButton(HWND hwnd);
static BOOL MyFileOp_CountButtons(HWND hwnd, LPARAM lParam);
//---------------------------------------------------------------------------
// Variables
//---------------------------------------------------------------------------
static HWND MyFileOp_main_hwnd = NULL;
static HWND MyFileOp_button_hwnd = NULL;
static const WCHAR *MyFileOp_button_text = NULL;
static BOOL *MyFileOp_pYesToAll = NULL;
WNDPROC MyFileOp_OldWindowProc = NULL;
//---------------------------------------------------------------------------
// MyFileOp_Hook
//---------------------------------------------------------------------------
_FX LRESULT CALLBACK MyFileOp_Hook(
int nCode, WPARAM wParam, LPARAM lParam)
{
HWND hwnd = (HWND)wParam;
if (MyFileOp_main_hwnd != (HWND)-1) {
if (nCode == HCBT_ACTIVATE
&& GetParent(hwnd) == MyFileOp_main_hwnd) {
MyFileOp_main_hwnd = hwnd;
MyFileOp_OldWindowProc = (WNDPROC)SetWindowLongPtr(
hwnd, GWLP_WNDPROC, (ULONG_PTR)MyFileOp_NewWindowProc);
}
if (nCode == HCBT_DESTROYWND && hwnd == MyFileOp_main_hwnd) {
MyFileOp_main_hwnd = (HWND)-1;
}
}
return CallNextHookEx(NULL, nCode, wParam, lParam);
}
//---------------------------------------------------------------------------
// MyFileOp_NewWindowProc
//---------------------------------------------------------------------------
_FX LRESULT CALLBACK MyFileOp_NewWindowProc(
HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
if (MyFileOp_main_hwnd && MyFileOp_pYesToAll) {
if (msg == WM_WINDOWPOSCHANGED) {
WINDOWPOS *pos = (WINDOWPOS *)lParam;
if (pos->flags & SWP_SHOWWINDOW) {
MyFileOp_button_hwnd = MyFileOp_InsertYesToAllButton(hwnd);
}
}
if (msg == WM_COMMAND && HIWORD(wParam) == BN_CLICKED
&& lParam == (LPARAM)MyFileOp_button_hwnd) {
*MyFileOp_pYesToAll = TRUE;
msg = WM_CLOSE;
}
}
return CallWindowProc(
MyFileOp_OldWindowProc, hwnd, msg, wParam, lParam);
}
//---------------------------------------------------------------------------
// MyFileOp_InsertYesToAllButton
//---------------------------------------------------------------------------
_FX HWND MyFileOp_InsertYesToAllButton(HWND hwnd)
{
RECT rc;
SIZE sz;
int width, height;
HWND button;
HDC dc;
HFONT font;
ULONG ButtonCount;
//
// window with just one button is probably an error window
//
ButtonCount = 0;
EnumChildWindows(hwnd, MyFileOp_CountButtons, (LPARAM)&ButtonCount);
if (ButtonCount == 1)
return NULL;
//
// create a button and measure its dimensions
//
button = CreateWindow(
L"BUTTON", MyFileOp_button_text,
BS_DEFPUSHBUTTON | WS_CHILD | WS_VISIBLE,
0, 0, -1, -1, hwnd, (HMENU)'tz', NULL, NULL);
dc = GetDC(button);
font = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0);
if (font) {
SelectObject(dc, font);
SendMessage(button, WM_SETFONT, (WPARAM)font, 0);
}
GetTextExtentPoint32(
dc, MyFileOp_button_text, wcslen(MyFileOp_button_text), &sz);
ReleaseDC(button, dc);
sz.cx += 40;
sz.cy += 40;
//
// resize dialog box window
//
GetWindowRect(hwnd, &rc);
width = rc.right - rc.left;
height = rc.bottom - rc.top;
while (width < sz.cx) {
rc.left -= 20;
width += 20;
}
height += sz.cy + 10;
MoveWindow(hwnd, rc.left, rc.top, width, height, TRUE);
//
// resize and move button
//
GetClientRect(hwnd, &rc);
if (rc.right - rc.left > sz.cx + 20)
sz.cx = rc.right - rc.left - 20;
rc.bottom -= 10;
rc.top = rc.bottom - sz.cy;
rc.left = (rc.right - rc.left - sz.cx) / 2;
rc.right = rc.left + sz.cx;
SetWindowPos(button, NULL,
rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, 0);
//
// finish
//
return button;
}
//---------------------------------------------------------------------------
// MyFileOp_CountButtons
//---------------------------------------------------------------------------
_FX BOOL MyFileOp_CountButtons(HWND hwnd, LPARAM lParam)
{
WCHAR clsnm[256];
GetClassName(hwnd, clsnm, 250);
clsnm[250] = L'\0';
if (_wcsicmp(clsnm, L"BUTTON") == 0) {
ULONG *ButtonCount = (ULONG *)lParam;
++(*ButtonCount);
}
return TRUE;
}
//---------------------------------------------------------------------------
// Common_SHFileOperation
//---------------------------------------------------------------------------
_FX int Common_SHFileOperation(void *lpSHFileOpStruct, BOOL *pYesToAll,
const WCHAR *ReplaceButtonText)
{
SHFILEOPSTRUCT *shop = (SHFILEOPSTRUCT *)lpSHFileOpStruct;
HHOOK hhk = NULL;
int rv;
MyFileOp_main_hwnd = NULL;
MyFileOp_button_hwnd = NULL;
MyFileOp_button_text = NULL;
MyFileOp_pYesToAll = NULL;
if (pYesToAll) {
*pYesToAll = FALSE;
if (! (shop->fFlags & FOF_NOCONFIRMATION)) {
MyFileOp_main_hwnd = shop->hwnd;
MyFileOp_button_hwnd = NULL;
MyFileOp_button_text = ReplaceButtonText;
MyFileOp_pYesToAll = pYesToAll;
hhk = SetWindowsHookEx(
WH_CBT, MyFileOp_Hook, NULL, GetCurrentThreadId());
}
}
rv = SHFileOperation(lpSHFileOpStruct);
if (hhk) {
MyFileOp_main_hwnd = (HWND)-1;
MyFileOp_button_hwnd = NULL;
MyFileOp_button_text = NULL;
MyFileOp_pYesToAll = NULL;
UnhookWindowsHookEx(hhk);
}
return rv;
}

View File

@ -0,0 +1,151 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// GDI Plus Wrappers
//---------------------------------------------------------------------------
#define COBJMACROS
#include <objbase.h>
#include <windows.h>
#include "MyGdi.h"
#include <common/defines.h>
#if _MSC_VER == 1200 // Visual C++ 6.0
typedef ULONG ULONG_PTR;
#endif
//---------------------------------------------------------------------------
// GdiPlus Imports
//---------------------------------------------------------------------------
struct GdiplusStartupInput
{
UINT32 GdiplusVersion; // Must be 1
ULONG_PTR DebugEventCallback; // Ignored on free builds
BOOL SuppressBackgroundThread; // FALSE unless you're prepared to call
// the hook/unhook functions properly
BOOL SuppressExternalCodecs; // FALSE unless you want GDI+ only to use
// its internal image codecs.
};
ULONG GdiplusStartup(
ULONG_PTR *token, struct GdiplusStartupInput *input, ULONG_PTR *output);
typedef ULONG_PTR GpImage;
typedef ULONG_PTR GpBitmap;
ULONG GdipCreateBitmapFromStream(IStream* stream, GpBitmap **bitmap);
ULONG GdipCreateHBITMAPFromBitmap(
GpBitmap* bitmap, HBITMAP* hbmReturn, ULONG background);
ULONG GdipDisposeImage(GpImage *image);
//---------------------------------------------------------------------------
// MyGdiInit
//---------------------------------------------------------------------------
void MyGdi_Init(void)
{
static ULONG_PTR token = 0;
struct GdiplusStartupInput input;
memzero(&input, sizeof(input));
input.GdiplusVersion = 1;
GdiplusStartup(&token, &input, NULL);
}
//---------------------------------------------------------------------------
// MyGdi_CreateResourceStream
//---------------------------------------------------------------------------
void *MyGdi_CreateResourceStream(const WCHAR *rsrcName)
{
HINSTANCE hInst;
HRSRC hResource;
ULONG rsrcSize;
const void *rsrcData;
HGLOBAL hGlobal;
void *pGlobal;
IStream *pStream;
hInst = GetModuleHandle(NULL);
hResource = FindResource(hInst, rsrcName, L"IMAGE");
if (! hResource)
return NULL;
rsrcSize = SizeofResource(hInst, hResource);
if (! rsrcSize)
return NULL;
rsrcData = LockResource(LoadResource(hInst, hResource));
if (! rsrcData)
return NULL;
hGlobal = GlobalAlloc(GMEM_MOVEABLE, rsrcSize);
if (! hGlobal)
return NULL;
pGlobal = GlobalLock(hGlobal);
if (! pGlobal) {
GlobalFree(hGlobal);
return NULL;
}
memcpy(pGlobal, rsrcData, rsrcSize);
GlobalUnlock(hGlobal);
if (CreateStreamOnHGlobal(hGlobal, TRUE, &pStream) != S_OK) {
GlobalFree(hGlobal);
pStream = NULL;
}
return pStream;
}
//---------------------------------------------------------------------------
// MyGdi_CreateFromResource
//---------------------------------------------------------------------------
HBITMAP MyGdi_CreateFromResource(const WCHAR *rsrcName)
{
HBITMAP hBitmap = NULL;
IStream *pStream = (IStream *)MyGdi_CreateResourceStream(rsrcName);
if (pStream) {
GpBitmap *gdiBitmap;
if (GdipCreateBitmapFromStream(pStream, &gdiBitmap) == S_OK) {
if (GdipCreateHBITMAPFromBitmap(gdiBitmap, &hBitmap, -1) != S_OK)
hBitmap = NULL;
GdipDisposeImage((GpImage *)gdiBitmap);
}
IStream_Release(pStream);
}
return hBitmap;
}

View File

@ -0,0 +1,34 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// GDI Plus Wrappers
//---------------------------------------------------------------------------
#ifdef __cplusplus
extern "C" {
#endif
void MyGdi_Init(void);
void *MyGdi_CreateResourceStream(const WCHAR *rsrcName);
HBITMAP MyGdi_CreateFromResource(const WCHAR *rsrcName);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,100 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// MyMsg Internationalization Utility
//---------------------------------------------------------------------------
#include "..\control\stdafx.h"
#include <afxcmn.h>
#include "MyMsg.h"
#include "core/dll/sbiedll.h"
#include "common/defines.h"
//---------------------------------------------------------------------------
// Variables
//---------------------------------------------------------------------------
const CString &CMyMsg::m_unknown = CString(L"???");
//---------------------------------------------------------------------------
// Constructor
//---------------------------------------------------------------------------
CMyMsg::CMyMsg(ULONG msgid)
{
Construct(SbieDll_FormatMessage0(msgid));
}
//---------------------------------------------------------------------------
// Constructor
//---------------------------------------------------------------------------
CMyMsg::CMyMsg(ULONG msgid, const WCHAR *p1)
{
Construct(SbieDll_FormatMessage1(msgid, p1));
}
//---------------------------------------------------------------------------
// Constructor
//---------------------------------------------------------------------------
CMyMsg::CMyMsg(ULONG msgid, const WCHAR *p1, const WCHAR *p2)
{
Construct(SbieDll_FormatMessage2(msgid, p1, p2));
}
//---------------------------------------------------------------------------
// Constructor
//---------------------------------------------------------------------------
CMyMsg::CMyMsg(
ULONG msgid, const WCHAR *p1, const WCHAR *p2, const WCHAR *p3)
{
const WCHAR *ins[6];
memzero((WCHAR *)ins, sizeof(ins));
ins[1] = (WCHAR *)p1;
ins[2] = (WCHAR *)p2;
ins[3] = (WCHAR *)p3;
Construct(SbieDll_FormatMessage(msgid, ins));
}
//---------------------------------------------------------------------------
// Construct
//---------------------------------------------------------------------------
void CMyMsg::Construct(WCHAR *str)
{
if (str) {
CString::operator=(str);
LocalFree(str);
} else
CString::operator=(m_unknown);
}

View File

@ -0,0 +1,48 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// MyMsg Internationalization Utility
//---------------------------------------------------------------------------
#ifndef _MY_MYMSG_H
#define _MY_MYMSG_H
#include "msgs/msgs.h"
class CMyMsg : public CString
{
static const CString &m_unknown;
void Construct(WCHAR *str);
public:
CMyMsg(ULONG msgid);
CMyMsg(ULONG msgid, const WCHAR *p1);
CMyMsg(ULONG msgid, const WCHAR *p1, const WCHAR *p2);
CMyMsg(ULONG msgid, const WCHAR *p1, const WCHAR *p2, const WCHAR *p3);
};
#endif // _MY_MYMSG_H

View File

@ -0,0 +1,414 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Message Box Utility
//---------------------------------------------------------------------------
#include "MyMsgBox.h"
#include "common/defines.h"
//---------------------------------------------------------------------------
// Structures
//---------------------------------------------------------------------------
typedef struct _MY_MSG_BOX_DATA {
const WCHAR *CheckText;
HWND hwnd;
WCHAR *EditText;
ULONG EditStyle;
} MY_MSG_BOX_DATA;
//---------------------------------------------------------------------------
// Variables
//---------------------------------------------------------------------------
static MY_MSG_BOX_DATA *MyMsgBox_Data[4] = { NULL, NULL, NULL, NULL };
static volatile ULONG MyMsgBox_Level = 0;
#define MyMsgBox_CheckText (MyMsgBox_Data[MyMsgBox_Level]->CheckText)
#define MyMsgBox_hwnd (MyMsgBox_Data[MyMsgBox_Level]->hwnd)
#define MyInputBox_EditText (MyMsgBox_Data[MyMsgBox_Level]->EditText)
#define MyInputBox_EditStyle (MyMsgBox_Data[MyMsgBox_Level]->EditStyle)
//---------------------------------------------------------------------------
// Functions
//---------------------------------------------------------------------------
static LRESULT CALLBACK MyMsgBox_Hook(
int nCode, WPARAM wParam, LPARAM lParam);
static void MyMsgBox_InsertCheckBox(HWND hwnd);
static LRESULT CALLBACK MyInputBox_Hook(
int nCode, WPARAM wParam, LPARAM lParam);
static void MyInputBox_InsertEditBox(HWND hwnd);
static void MyMsgBox_PushPop(BOOLEAN Push);
//---------------------------------------------------------------------------
// MyMsgBox_Hook
//---------------------------------------------------------------------------
_FX LRESULT CALLBACK MyMsgBox_Hook(
int nCode, WPARAM wParam, LPARAM lParam)
{
HWND hwnd = (HWND)wParam;
if (MyMsgBox_hwnd != (HWND)-1) {
if (nCode == HCBT_ACTIVATE && GetParent(hwnd) == MyMsgBox_hwnd) {
MyMsgBox_hwnd = hwnd;
MyMsgBox_InsertCheckBox(hwnd);
}
if (nCode == HCBT_DESTROYWND && hwnd == MyMsgBox_hwnd) {
MyMsgBox_hwnd = (HWND)-1;
if (BST_CHECKED == SendDlgItemMessage(
hwnd, 'tz', BM_GETCHECK, 0, 0))
MyMsgBox_CheckText = INVALID_HANDLE_VALUE;
}
}
return CallNextHookEx(NULL, nCode, wParam, lParam);
}
//---------------------------------------------------------------------------
// MyMsgBox_InsertCheckBox
//---------------------------------------------------------------------------
_FX void MyMsgBox_InsertCheckBox(HWND hwnd)
{
RECT rc;
SIZE sz;
int width, height;
HWND button, stat;
HDC dc;
HFONT font;
//
// create a button and measure its dimensions
//
button = CreateWindow(
L"BUTTON", MyMsgBox_CheckText,
BS_AUTOCHECKBOX | WS_CHILD | WS_VISIBLE,
0, 0, -1, -1, hwnd, (HMENU)'tz', NULL, NULL);
dc = GetDC(button);
font = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0);
if (font) {
SelectObject(dc, font);
SendMessage(button, WM_SETFONT, (WPARAM)font, 0);
}
GetTextExtentPoint32(
dc, MyMsgBox_CheckText, wcslen(MyMsgBox_CheckText), &sz);
ReleaseDC(button, dc);
sz.cx += 40;
//
// resize message box window
//
GetWindowRect(hwnd, &rc);
width = rc.right - rc.left;
height = rc.bottom - rc.top;
while (width < sz.cx) {
rc.left -= 20;
width += 20;
}
height += sz.cy * 2;
MoveWindow(hwnd, rc.left, rc.top, width, height, TRUE);
//
// create empty static text window over the extended part of the
// window, to make sure the color is consistent. then reposition
// the button on top of that static
//
GetClientRect(hwnd, &rc);
stat = CreateWindow(
L"STATIC", L"", WS_CHILD | WS_VISIBLE,
0, rc.bottom - sz.cy * 2, rc.right, rc.bottom,
hwnd, (HMENU)-1, NULL, NULL);
SetWindowPos(button, stat, 10, rc.bottom - sz.cy * 2, sz.cx, sz.cy, 0);
}
//---------------------------------------------------------------------------
// MessageCheckBox
//---------------------------------------------------------------------------
_FX int MessageCheckBox(
HWND hwnd, const WCHAR *text, const WCHAR *caption, UINT flags,
const WCHAR *check)
{
HHOOK hhk;
int rv;
MyMsgBox_PushPop(TRUE);
MyMsgBox_CheckText = check;
MyMsgBox_hwnd = hwnd;
hhk = SetWindowsHookEx(
WH_CBT, MyMsgBox_Hook, NULL, GetCurrentThreadId());
rv = MessageBox(hwnd, text, caption, flags);
if (MyMsgBox_CheckText == INVALID_HANDLE_VALUE)
rv = -rv;
MyMsgBox_CheckText = NULL;
MyMsgBox_hwnd = (HWND)-1;
if (hhk)
UnhookWindowsHookEx(hhk);
MyMsgBox_PushPop(FALSE);
return rv;
}
//---------------------------------------------------------------------------
// MyInputBox_Hook
//---------------------------------------------------------------------------
_FX LRESULT CALLBACK MyInputBox_Hook(
int nCode, WPARAM wParam, LPARAM lParam)
{
HWND hwnd = (HWND)wParam;
if (MyMsgBox_hwnd != (HWND)-1) {
if (nCode == HCBT_ACTIVATE && GetParent(hwnd) == MyMsgBox_hwnd) {
MyMsgBox_hwnd = hwnd;
MyInputBox_InsertEditBox(hwnd);
}
if (nCode == HCBT_DESTROYWND && hwnd == MyMsgBox_hwnd) {
int len = (int)SendDlgItemMessage(
hwnd, 'tz', WM_GETTEXTLENGTH, 0, 0);
if (len) {
MyInputBox_EditText =
LocalAlloc(LMEM_FIXED, (len + 4) * sizeof(WCHAR));
SendDlgItemMessage(
hwnd, 'tz', WM_GETTEXT,
(WPARAM)(len + 2), (LPARAM)MyInputBox_EditText);
}
MyMsgBox_hwnd = (HWND)-1;
}
}
return CallNextHookEx(NULL, nCode, wParam, lParam);
}
//---------------------------------------------------------------------------
// MyInputBox_InsertEditBox
//---------------------------------------------------------------------------
_FX void MyInputBox_InsertEditBox(HWND hwnd)
{
HWND child, edit;
HDC dc;
HFONT font;
SIZE sz;
RECT rc;
POINT p;
ULONG oldStyleEx;
//
// hide all child windows that are not buttons
//
child = GetWindow(hwnd, GW_CHILD);
while (child) {
int id = GetDlgCtrlID(child);
if (id != IDOK && id != IDCANCEL)
ShowWindow(child, SW_HIDE);
child = GetWindow(child, GW_HWNDNEXT);
}
//
// create an edit box
//
oldStyleEx = GetWindowLong(hwnd, GWL_EXSTYLE);
SetWindowLong(hwnd, GWL_EXSTYLE, oldStyleEx | WS_EX_NOINHERITLAYOUT);
edit = CreateWindowEx(
WS_EX_CLIENTEDGE, L"EDIT", L"",
WS_CHILD | WS_VISIBLE | MyInputBox_EditStyle,
0, 0, -1, -1, hwnd, (HMENU)'tz', NULL, NULL);
SetWindowLong(hwnd, GWL_EXSTYLE, oldStyleEx);
dc = GetDC(edit);
font = (HFONT)SendMessage(hwnd, WM_GETFONT, 0, 0);
if (font) {
SelectObject(dc, font);
SendMessage(edit, WM_SETFONT, (WPARAM)font, 0);
}
GetTextExtentPoint32(dc, L"M", 1, &sz);
sz.cy += sz.cy / 2;
ReleaseDC(edit, dc);
if (MyInputBox_EditText) {
SetWindowText(edit, MyInputBox_EditText);
MyInputBox_EditText = NULL;
}
//
// get the size of the client area, excluding the buttons
//
GetWindowRect(GetDlgItem(hwnd, IDOK), &rc);
p.x = 0;
p.y = rc.top;
ScreenToClient(hwnd, &p);
GetClientRect(hwnd, &rc);
MoveWindow(edit,
20, (p.y - sz.cy) / 2,
rc.right - 20 * 2, sz.cy,
TRUE);
SetFocus(edit);
}
//---------------------------------------------------------------------------
// InputBox
//---------------------------------------------------------------------------
_FX WCHAR *InputBox(HWND hwnd, const WCHAR *caption, UINT flags,
const WCHAR *def)
{
HHOOK hhk;
int rv;
WCHAR *input;
int def_len;
WCHAR *text;
MyMsgBox_PushPop(TRUE);
MyInputBox_EditStyle = ES_AUTOHSCROLL;
if (flags & INPUTBOX_PASSWORD) {
flags &= ~INPUTBOX_PASSWORD;
MyInputBox_EditStyle |= ES_PASSWORD;
}
if (flags & INPUTBOX_READONLY) {
flags &= ~INPUTBOX_READONLY;
MyInputBox_EditStyle |= ES_READONLY;
}
MyInputBox_EditText = (WCHAR *)def;
MyMsgBox_hwnd = hwnd;
hhk = SetWindowsHookEx(
WH_CBT, MyInputBox_Hook, NULL, GetCurrentThreadId());
if (def)
def_len = wcslen(def);
else
def_len = 0;
text = LocalAlloc(LMEM_FIXED, (def_len + 50) * sizeof(WCHAR));
wcscpy(text, L"MMMMMMMMMMMMMMMMMMMMMMMMMMMMMM\nM");
while (def_len > 0) {
wcscat(text, L"MMMMM");
def_len -= 5;
}
rv = MessageBox(hwnd, text, caption, flags);
LocalFree(text);
if (rv == IDOK)
input = MyInputBox_EditText;
else {
input = NULL;
if (MyInputBox_EditText && MyInputBox_EditText != def)
LocalFree(MyInputBox_EditText);
}
MyInputBox_EditText = NULL;
MyMsgBox_hwnd = (HWND)-1;
if (hhk)
UnhookWindowsHookEx(hhk);
MyMsgBox_PushPop(FALSE);
return input;
}
//---------------------------------------------------------------------------
// MyMsgBox_PushPop
//---------------------------------------------------------------------------
_FX void MyMsgBox_PushPop(BOOLEAN Push)
{
if (Push) {
++MyMsgBox_Level;
if (! MyMsgBox_Data[MyMsgBox_Level]) {
MyMsgBox_Data[MyMsgBox_Level] =
LocalAlloc(LMEM_FIXED, sizeof(MY_MSG_BOX_DATA));
}
memzero(MyMsgBox_Data[MyMsgBox_Level], sizeof(MY_MSG_BOX_DATA));
} else
--MyMsgBox_Level;
}

View File

@ -0,0 +1,56 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Message Box Utility
//---------------------------------------------------------------------------
#include <windows.h>
#ifdef __cplusplus
extern "C" {
#endif
//
// MessageCheckBox
//
// The check parameter specifies the text for the additional checkbox.
//
int MessageCheckBox(
HWND hwnd, const WCHAR *text, const WCHAR *caption, UINT flags,
const WCHAR *check);
//
// InputBox
//
// For a password input box, pass INPUTBOX_PASSWORD in the flags parameter.
//
WCHAR *InputBox(HWND hwnd, const WCHAR *caption, UINT flags,
const WCHAR *def);
#define INPUTBOX_PASSWORD MB_SERVICE_NOTIFICATION
#define INPUTBOX_READONLY MB_DEFAULT_DESKTOP_ONLY
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,118 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// MyPool Memory Management
//---------------------------------------------------------------------------
#include <windows.h>
#include "MyPool.h"
#include "common/pool.h"
//---------------------------------------------------------------------------
// Defines
//---------------------------------------------------------------------------
#define DEBUG_MEMORY
//---------------------------------------------------------------------------
// Constructor
//---------------------------------------------------------------------------
CMyPool::CMyPool()
{
m_pool = Pool_Create();
}
//---------------------------------------------------------------------------
// Destructor
//---------------------------------------------------------------------------
CMyPool::~CMyPool()
{
if (m_pool)
Pool_Delete((POOL *)m_pool);
}
//---------------------------------------------------------------------------
// Alloc
//---------------------------------------------------------------------------
void *CMyPool::Alloc(int size)
{
UCHAR *ptr;
#ifdef DEBUG_MEMORY
size += 64 * 2;
#endif // DEBUG_MEMORY
size += sizeof(ULONG_PTR);
ptr = (UCHAR *)Pool_Alloc((POOL *)m_pool, size);
if (! ptr)
__debugbreak();
#ifdef DEBUG_MEMORY
memset(ptr, 0xCC, 64);
memset(ptr + size - 64, 0xCC, 64);
ptr += 64;
#endif // DEBUG_MEMORY
*(ULONG_PTR *)ptr = size;
ptr += sizeof(ULONG_PTR);
return ptr;
}
//---------------------------------------------------------------------------
// Free
//---------------------------------------------------------------------------
void CMyPool::Free(void *ptr)
{
UCHAR *ptr2 = ((UCHAR *)ptr) - sizeof(ULONG_PTR);
ULONG size = (ULONG)(*(ULONG_PTR *)ptr2);
#ifdef DEBUG_MEMORY
{
//WCHAR txt[64];
int i;
UCHAR *pre = ptr2 - 64;
UCHAR *post = ptr2 + size - 64 * 2;
for (i = 0; i < 64; ++i)
if (pre[i] != 0xCC || post[i] != 0xCC) {
WCHAR txt[64];
wsprintf(txt, L"Memory corrupted, ptr=%p\n", ptr);
OutputDebugString(txt);
__debugbreak();
}
ptr2 -= 64;
}
#endif // DEBUG_MEMORY
Pool_Free(ptr2, size);
}

View File

@ -0,0 +1,48 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// MyPool Memory Management
//---------------------------------------------------------------------------
#ifndef _MY_MYPOOL_H
#define _MY_MYPOOL_H
class CMyPool
{
private:
void *m_pool;
public:
CMyPool();
~CMyPool();
void *Alloc(int size);
void Free(void *ptr);
char *Alloc_char(int size) {return (char *)Alloc(size);};
UCHAR *Alloc_UCHAR(int size) {return (UCHAR *)Alloc(size);};
WCHAR *Alloc_WCHAR(int size) {return (WCHAR *)Alloc(size);};
ULONG_PTR *Alloc_ULONG_PTR(int size){return (ULONG_PTR *)Alloc(size);};
};
#endif // _MY_MYPOOL_H

View File

@ -0,0 +1,159 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Run Browser Dialog
//---------------------------------------------------------------------------
#include "..\control\stdafx.h"
#include "RunBrowser.h"
#include "CommonUtils.h"
#include "MyMsg.h"
#include "core/dll/sbiedll.h"
//---------------------------------------------------------------------------
// Message Map
//---------------------------------------------------------------------------
BEGIN_MESSAGE_MAP(CRunBrowser, CDialog)
ON_COMMAND(IDYES, OnYes)
ON_COMMAND(IDNO, OnNo)
END_MESSAGE_MAP()
//---------------------------------------------------------------------------
// Constructor
//---------------------------------------------------------------------------
CRunBrowser::CRunBrowser(CWnd *pParentWnd, const CString &url)
: CDialog((UINT)0, pParentWnd)
{
m_url = url;
m_lpszTemplateName = L"RUN_BROWSER_DIALOG";
BOOLEAN LayoutRTL;
SbieDll_GetLanguage(&LayoutRTL);
if (LayoutRTL) {
m_DlgTmplCopy =
Common_DlgTmplRtl(AfxGetInstanceHandle(), m_lpszTemplateName);
if (m_DlgTmplCopy) {
m_lpszTemplateName = NULL;
InitModalIndirect((LPCDLGTEMPLATE)m_DlgTmplCopy, m_pParentWnd);
}
} else
m_DlgTmplCopy = NULL;
DoModal();
}
//---------------------------------------------------------------------------
// Destructor
//---------------------------------------------------------------------------
CRunBrowser::~CRunBrowser()
{
if (m_DlgTmplCopy) {
HeapFree(GetProcessHeap(), 0, m_DlgTmplCopy);
m_DlgTmplCopy = NULL;
}
}
//---------------------------------------------------------------------------
// OnInitDialog
//---------------------------------------------------------------------------
BOOL CRunBrowser::OnInitDialog()
{
SetWindowText(CMyMsg(MSG_3641));
GetDlgItem(ID_RUN_BROWSER_EXPLAIN)->SetWindowText(CMyMsg(MSG_3642));
GetDlgItem(IDYES)->SetWindowText(CMyMsg(MSG_3643));
GetDlgItem(IDCANCEL)->SetWindowText(CMyMsg(MSG_3002));
GetDlgItem(IDNO)->SetWindowText(CMyMsg(MSG_3644));
GetDlgItem(ID_RUN_BROWSER_URL)->SetWindowText(m_url);
return TRUE;
}
//---------------------------------------------------------------------------
// OnYes
//---------------------------------------------------------------------------
void CRunBrowser::OnYes()
{
Common_RunStartExe(m_url, CString());
EndDialog(0);
}
//---------------------------------------------------------------------------
// OnNo
//---------------------------------------------------------------------------
void CRunBrowser::OnNo()
{
ShellExecute(
m_pParentWnd->m_hWnd, NULL, m_url, NULL, NULL, SW_SHOWNORMAL);
EndDialog(0);
}
//---------------------------------------------------------------------------
// GetTopicUrl
//---------------------------------------------------------------------------
CString CRunBrowser::GetTopicUrl(const CString &topic)
{
return L"https://www.sandboxie.com/index.php?" + topic;
}
//---------------------------------------------------------------------------
// OpenHelp
//---------------------------------------------------------------------------
void CRunBrowser::OpenHelp(CWnd *pParentWnd, const CString &topic)
{
CRunBrowser x(pParentWnd, GetTopicUrl(topic));
}
//---------------------------------------------------------------------------
// OpenForum
//---------------------------------------------------------------------------
void CRunBrowser::OpenForum(CWnd *pParentWnd)
{
CRunBrowser x(pParentWnd, L"http://forums.sandboxie.com/phpBB3/");
}

View File

@ -0,0 +1,74 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Run Browser Dialog Box
//---------------------------------------------------------------------------
#ifndef _MY_RUNBROWSER_H
#define _MY_RUNBROWSER_H
//---------------------------------------------------------------------------
// Defines
//---------------------------------------------------------------------------
#define ID_RUN_BROWSER_EXPLAIN 10111
#define ID_RUN_BROWSER_URL 10222
//---------------------------------------------------------------------------
// CRunBrowser Class
//---------------------------------------------------------------------------
#ifndef RC_INVOKED
#include <afxcmn.h>
class CRunBrowser : public CDialog
{
DECLARE_MESSAGE_MAP()
CString m_url;
void *m_DlgTmplCopy;
virtual BOOL OnInitDialog();
afx_msg void OnYes();
afx_msg void OnNo();
public:
CRunBrowser(CWnd *pParentWnd, const CString &url);
~CRunBrowser();
static CString GetTopicUrl(const CString &topic);
static void OpenHelp(CWnd *pParentWnd, const CString &topic);
static void OpenForum(CWnd *pParentWnd);
};
#endif // ! RC_INVOKED
#endif // _MY_RUNBROWSER_H

View File

@ -0,0 +1,98 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Common Utility Functions
//---------------------------------------------------------------------------
#include "..\control\stdafx.h"
#include "CommonUtils.h"
#include "common/defines.h"
#include "common/my_version.h"
#include "core/dll/sbiedll.h"
//---------------------------------------------------------------------------
// Common_RunStartExe
//---------------------------------------------------------------------------
void Common_RunStartExe(
const CString &cmd, const CString &box, BOOL wait, BOOL inherit)
{
WCHAR *cmdline = (WCHAR *)LocalAlloc(LMEM_FIXED, 2048 * sizeof(WCHAR));
wcscpy(cmdline, L"/box:");
if (box.IsEmpty())
wcscat(cmdline, L"__ask__");
else
wcscat(cmdline, box);
wcscat(cmdline, L" ");
wcscat(cmdline, cmd);
STARTUPINFO si;
PROCESS_INFORMATION pi;
memzero(&si, sizeof(si));
si.cb = sizeof(STARTUPINFO);
if (inherit)
si.lpReserved = (LPTSTR)1;
if (! SbieDll_RunFromHome(START_EXE, cmdline, &si, &pi)) {
ULONG ErrorCode = GetLastError();
WCHAR *msg = (WCHAR *)LocalAlloc(LMEM_FIXED, 2560 * sizeof(WCHAR));
DWORD FormatFlags = FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS;
FormatMessage(FormatFlags, NULL, ErrorCode,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)msg, 500, NULL);
wcscat(msg, L"\r\n\r\n" START_EXE L" ");
wcscat(msg, cmdline);
MessageBox(NULL, msg, SANDBOXIE L" " START_EXE L" Failed",
MB_OK | MB_TOPMOST);
LocalFree(msg);
} else {
CWaitCursor waitcursor;
while (wait) {
waitcursor.Restore();
ULONG rc = MsgWaitForMultipleObjects(
1, &pi.hProcess, FALSE, INFINITE, QS_ALLEVENTS);
if (rc == WAIT_OBJECT_0)
break;
MSG msg;
while (1) {
if (! PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
break;
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
}
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
}
LocalFree(cmdline);
}

View File

@ -0,0 +1,194 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// About Sandboxie Dialog Box
//---------------------------------------------------------------------------
#include "stdafx.h"
#include "MyApp.h"
#include "AboutDialog.h"
#include "SbieIni.h"
#include "common/my_version.h"
#include "apps/common/MyGdi.h"
#include "apps/common/RunBrowser.h"
//---------------------------------------------------------------------------
// Message Map
//---------------------------------------------------------------------------
BEGIN_MESSAGE_MAP(CAboutDialog, CBaseDialog)
ON_COMMAND(ID_ABOUT_TUTORIAL, OnTutorial)
END_MESSAGE_MAP()
//---------------------------------------------------------------------------
// Variables
//---------------------------------------------------------------------------
HBITMAP CAboutDialog::m_bitmap = NULL;
//---------------------------------------------------------------------------
// Constructor
//---------------------------------------------------------------------------
CAboutDialog::CAboutDialog(CWnd *pParentWnd)
: CBaseDialog(pParentWnd, NULL)
{
//
// prepare image
//
if (! m_bitmap)
m_bitmap = MyGdi_CreateFromResource(L"MASTHEADLOGO");
//
// display dialog
//
CString DialogTemplateName = L"ABOUT_DIALOG";
SetDialogTemplate(DialogTemplateName);
DoModal();
}
//---------------------------------------------------------------------------
// Destructor
//---------------------------------------------------------------------------
CAboutDialog::~CAboutDialog()
{
}
//---------------------------------------------------------------------------
// OnInitDialog
//---------------------------------------------------------------------------
BOOL CAboutDialog::OnInitDialog()
{
CStatic *pic = (CStatic *)GetDlgItem(ID_ABOUT_LOGO);
pic->SetBitmap(m_bitmap);
CRect rc;
GetClientRect(&rc);
ULONG wDlg = rc.right - rc.left;
pic->GetClientRect(&rc);
ULONG wBtn = rc.right - rc.left;
ULONG hBtn = rc.bottom - rc.top;
pic->GetWindowRect(&rc);
ScreenToClient((POINT *)&rc);
rc.left = (wDlg - wBtn) / 2;
pic->MoveWindow(rc.left, rc.top, wBtn, hBtn, TRUE);
//
//
//
pic->GetWindowRect(rc);
ScreenToClient(rc);
rc.left -= 5;
rc.top -= 10;
rc.right += 3 * 2;
rc.bottom += 3 * 2;
GetDlgItem(ID_ABOUT_FRAME)->MoveWindow(rc);
CString text = CMyMsg(MSG_3601);
SetWindowText(text);
//
//
//
const ULONG _bitness =
#ifdef _WIN64
64;
#else
32;
#endif _WIN64
ULONG U_LRO, U_PDF;
if (CMyApp::m_LayoutRTL) {
U_LRO = 0x202D; // Start of left-to-right override
U_PDF = 0x202C; // Pop directional formatting
} else {
U_LRO = L' ';
U_PDF = L' ';
}
text.Format(L"%S %c(%d-bit)%c",
MY_VERSION_STRING, U_LRO, _bitness, U_PDF);
CString ver = CMyMsg(MSG_3302, text);
GetDlgItem(ID_ABOUT_VERSION)->SetWindowText(ver);
//
//
//
text.Format(L"%S", MY_COPYRIGHT_STRING);
GetDlgItem(ID_ABOUT_COPYRIGHT)->SetWindowText(text);
GetDlgItem(IDOK)->SetWindowText(CMyMsg(MSG_3001));
return TRUE;
}
//---------------------------------------------------------------------------
// OnRegister
//---------------------------------------------------------------------------
void CAboutDialog::OnRegister()
{
}
//---------------------------------------------------------------------------
// OnTutorial
//---------------------------------------------------------------------------
void CAboutDialog::OnTutorial()
{
GetParent()->PostMessage(WM_COMMAND, ID_HELP_TUTORIAL, 0);
EndDialog(0);
}
//---------------------------------------------------------------------------
// OnOK
//---------------------------------------------------------------------------
void CAboutDialog::OnOK()
{
EndDialog(0);
}

View File

@ -0,0 +1,48 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// About Sandboxie Dialog Box
//---------------------------------------------------------------------------
#ifndef _MY_ABOUTDIALOG_H
#define _MY_ABOUTDIALOG_H
class CAboutDialog : public CBaseDialog
{
DECLARE_MESSAGE_MAP()
static HBITMAP m_bitmap;
virtual BOOL OnInitDialog();
afx_msg void OnRegister();
afx_msg void OnTutorial();
virtual void OnOK();
public:
CAboutDialog(CWnd *pParentWnd);
~CAboutDialog();
};
#endif // _MY_ABOUTDIALOG_H

View File

@ -0,0 +1,192 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Alert Programs Dialog Box
//---------------------------------------------------------------------------
#include "stdafx.h"
#include "MyApp.h"
#include "AlertDialog.h"
#include "Boxes.h"
#include "SbieIni.h"
#include "ProgramSelector.h"
//---------------------------------------------------------------------------
// Message Map
//---------------------------------------------------------------------------
BEGIN_MESSAGE_MAP(CAlertDialog, CBaseDialog)
ON_COMMAND(ID_ALERT_ADD, OnAdd)
ON_COMMAND(ID_ALERT_REMOVE, OnRemove)
END_MESSAGE_MAP()
//---------------------------------------------------------------------------
// Constructor
//---------------------------------------------------------------------------
CAlertDialog::CAlertDialog(CWnd *pParentWnd)
: CBaseDialog(pParentWnd, L"ALERT_DIALOG")
{
DoModal();
}
//---------------------------------------------------------------------------
// Destructor
//---------------------------------------------------------------------------
CAlertDialog::~CAlertDialog()
{
}
//---------------------------------------------------------------------------
// OnInitDialog
//---------------------------------------------------------------------------
BOOL CAlertDialog::OnInitDialog()
{
SetWindowText(CMyMsg(MSG_3681));
GetDlgItem(ID_ALERT_EXPLAIN)->SetWindowText(CMyMsg(MSG_3682));
GetDlgItem(ID_ALERT_ADD)->SetWindowText(CMyMsg(MSG_3355));
GetDlgItem(ID_ALERT_REMOVE)->SetWindowText(CMyMsg(MSG_3351));
GetDlgItem(IDOK)->SetWindowText(CMyMsg(MSG_3001));
GetDlgItem(IDCANCEL)->SetWindowText(CMyMsg(MSG_3002));
MakeLTR(ID_ALERT_LIST);
CListBox *listbox = (CListBox *)GetDlgItem(ID_ALERT_LIST);
listbox->SetFont(&CMyApp::m_fontFixed);
CStringList list;
CBoxes::GetInstance().GetBox(0).GetProcessList(L'A', list);
while (! list.IsEmpty()) {
CString pgm = list.RemoveHead();
listbox->AddString(pgm);
}
return TRUE;
}
//---------------------------------------------------------------------------
// OnAddName
//---------------------------------------------------------------------------
void CAlertDialog::OnAdd()
{
CProgramSelector pgmsel(this, NULL, false);
if (! pgmsel.m_pgm1.IsEmpty()) {
CListBox *pListBox = (CListBox *)GetDlgItem(ID_ALERT_LIST);
pListBox->AddString(pgmsel.m_pgm1);
if (! pgmsel.m_pgm2.IsEmpty())
pListBox->AddString(pgmsel.m_pgm2);
}
}
//---------------------------------------------------------------------------
// OnRemove
//---------------------------------------------------------------------------
void CAlertDialog::OnRemove()
{
CListBox *listbox = (CListBox *)GetDlgItem(ID_ALERT_LIST);
int index = listbox->GetCurSel();
if (index == LB_ERR)
return;
listbox->DeleteString(index);
}
//---------------------------------------------------------------------------
// OnOK
//---------------------------------------------------------------------------
void CAlertDialog::OnOK()
{
CBox &box = CBoxes::GetInstance().GetBox(0);
BOOL ok = TRUE;
CStringList list;
box.GetProcessList(L'A', list);
CListBox *listbox = (CListBox *)GetDlgItem(ID_ALERT_LIST);
int size = listbox->GetCount();
//
// remove alerts that are no longer in our list
//
POSITION pos = list.GetHeadPosition();
while (pos && ok) {
CString pgm1 = list.GetNext(pos);
BOOL found = FALSE;
for (int index = 0; index < size; ++index) {
CString pgm2;
listbox->GetText(index, pgm2);
if (pgm1 == pgm2) {
found = TRUE;
break;
}
}
if (! found)
ok = box.SetProcessSetting(L'A', pgm1, FALSE);
}
//
// add new alerts
//
for (int index = 0; (index < size) && ok; ++index) {
CString pgm1;
listbox->GetText(index, pgm1);
BOOL found = FALSE;
pos = list.GetHeadPosition();
while (pos) {
CString pgm2 = list.GetNext(pos);
if (pgm1 == pgm2) {
found = TRUE;
break;
}
}
if (! found)
ok = box.SetProcessSetting(L'A', pgm1, TRUE);
}
EndDialog(0);
}

View File

@ -0,0 +1,45 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Alert Programs Dialog Box
//---------------------------------------------------------------------------
#ifndef _MY_ALERTDIALOG_H
#define _MY_ALERTDIALOG_H
class CAlertDialog : public CBaseDialog
{
DECLARE_MESSAGE_MAP()
virtual BOOL OnInitDialog();
afx_msg void OnAdd();
afx_msg void OnRemove();
virtual void OnOK();
public:
CAlertDialog(CWnd *pParentWnd);
~CAlertDialog();
};
#endif // _MY_ALERTDIALOG_H

View File

@ -0,0 +1,354 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Animated Bitmap
//---------------------------------------------------------------------------
#include "stdafx.h"
#include "AnimatedBitmap.h"
#include "apps/common/MyGdi.h"
#include <objbase.h>
#include <gdiplus.h>
//---------------------------------------------------------------------------
// MyImage class
//---------------------------------------------------------------------------
class CMyImage : public Gdiplus::Image
{
IStream *m_pStream;
public:
CMyImage()
: Image() { nativeImage = NULL; m_pStream = NULL; }
~CMyImage()
{
if (m_pStream)
m_pStream->Release();
}
bool SetImage(const WCHAR *rsrcName)
{
m_pStream = (IStream *)MyGdi_CreateResourceStream(rsrcName);
if (! m_pStream)
return false;
lastResult = Gdiplus::DllExports::GdipLoadImageFromStream(
m_pStream, &nativeImage);
return (lastResult == 0 ? true : false);
}
};
//---------------------------------------------------------------------------
// Message Map
//---------------------------------------------------------------------------
BEGIN_MESSAGE_MAP(CAnimatedBitmap, CStatic)
ON_WM_PAINT()
ON_WM_TIMER()
END_MESSAGE_MAP()
//---------------------------------------------------------------------------
// Constructor
//---------------------------------------------------------------------------
CAnimatedBitmap::CAnimatedBitmap()
: CStatic()
{
m_image = NULL;
m_property = NULL;
m_frame_count = 0;
m_frame_index = -1;
}
//---------------------------------------------------------------------------
// Destructor
//---------------------------------------------------------------------------
CAnimatedBitmap::~CAnimatedBitmap()
{
SetImage(NULL);
}
//---------------------------------------------------------------------------
// Init
//---------------------------------------------------------------------------
bool CAnimatedBitmap::Init(HWND hwndEdit)
{
if (hwndEdit && SubclassWindow(hwndEdit)) {
ModifyStyleEx(WS_EX_LAYOUTRTL, 0);
return true;
} else
return false;
}
//---------------------------------------------------------------------------
// Init
//---------------------------------------------------------------------------
bool CAnimatedBitmap::Init(CDialog *dlg, UINT id)
{
HWND hwndEdit;
dlg->GetDlgItem(id, &hwndEdit);
return Init(hwndEdit);
}
//---------------------------------------------------------------------------
// SetImage
//---------------------------------------------------------------------------
bool CAnimatedBitmap::SetImage(const WCHAR *name)
{
//
// delete resources for old image
//
CMyImage *image = (CMyImage *)m_image;
if (image) {
delete image;
m_image = NULL;
}
if (m_property) {
free(m_property);
m_property = NULL;
}
m_frame_count = 0;
m_frame_index = -1;
//
// load image file for new image
//
if (! name)
return false;
image = new CMyImage();
if (! image)
return false;
if (! image->SetImage(name)) {
delete image;
return false;
}
//
// get frame data from the image
//
UINT dim_count = image->GetFrameDimensionsCount();
GUID *dim_ids = (GUID *)malloc(sizeof(GUID) * dim_count);
if (! dim_ids) {
delete image;
return false;
}
if (image->GetFrameDimensionsList(dim_ids, dim_count) == 0) {
m_guid = dim_ids[0];
int frame_count = image->GetFrameCount(&m_guid);
UINT item_size = 0;
Gdiplus::PropertyItem *property = NULL;
if (frame_count > 1)
item_size = image->GetPropertyItemSize(PropertyTagFrameDelay);
if (item_size)
property = (Gdiplus::PropertyItem *)malloc(item_size);
if (property) {
if (image->GetPropertyItem(
PropertyTagFrameDelay, item_size, property) == 0) {
free(dim_ids);
m_image = image;
m_property = property;
m_frame_count = frame_count;
return true;
}
}
}
free(dim_ids);
delete image;
return false;
}
//---------------------------------------------------------------------------
// Animate
//---------------------------------------------------------------------------
void CAnimatedBitmap::Animate(bool enable)
{
if (! m_image)
enable = false;
if (enable && m_frame_index == -1) {
SetTimer(26880, 10, NULL);
m_frame_index = 0;
m_frame_ticks = 0;
} else if ((! enable) && m_frame_index != -1) {
KillTimer(26880);
m_frame_index = -1;
}
}
//---------------------------------------------------------------------------
// DrawFrame
//---------------------------------------------------------------------------
void CAnimatedBitmap::DrawFrame(CDC *dc)
{
//
// create an off-screen buffer to paint into
//
CRect rc;
GetClientRect(&rc);
CBitmap mem_bmp;
mem_bmp.CreateCompatibleBitmap(dc, rc.Width(), rc.Height());
CDC mem_dc;
mem_dc.CreateCompatibleDC(dc);
CBitmap *old_bmp = mem_dc.SelectObject(&mem_bmp);
//
// paint the image into the off-screen buffer
//
CMyImage *image = (CMyImage *)m_image;
const ULONG width = image->GetWidth();
const ULONG height = image->GetHeight();
Gdiplus::Graphics graphics(mem_dc.m_hDC);
graphics.DrawImage(image, 0, 0, width, height);
//
// parent window can paint into off-screen buffer
//
CAnimatedBitmap_NM nm;
nm.hwndFrom = m_hWnd;
nm.idFrom = GetDlgCtrlID();
nm.code = NM_CUSTOMDRAW;
nm.dc = &mem_dc;
GetParent()->SendMessage(WM_NOTIFY, nm.idFrom, (LPARAM)&nm);
//
// copy off-screen buffer into our window and release it
//
dc->BitBlt(0, 0, width, height, &mem_dc, 0, 0, SRCCOPY);
mem_dc.SelectObject(old_bmp);
}
//---------------------------------------------------------------------------
// OnPaint
//---------------------------------------------------------------------------
void CAnimatedBitmap::OnPaint()
{
if (IsWindowVisible()) {
PAINTSTRUCT ps;
CDC *dc = BeginPaint(&ps);
DrawFrame(dc);
EndPaint(&ps);
}
}
//---------------------------------------------------------------------------
// OnTimer
//---------------------------------------------------------------------------
void CAnimatedBitmap::OnTimer(UINT_PTR nIDEvent)
{
if (nIDEvent == 26880 && m_image && m_frame_index != -1) {
CMyImage *image = (CMyImage *)m_image;
GUID page_guid = Gdiplus::FrameDimensionTime;
image->SelectActiveFrame(&m_guid, m_frame_index);
ULONG ticks_now = GetTickCount();
if (m_frame_ticks == 0) {
Gdiplus::PropertyItem *property =
(Gdiplus::PropertyItem *)m_property;
int frame_time = ((long *)property->value)[m_frame_index];
m_frame_ticks = ticks_now + frame_time * 10;
if (IsWindowVisible()) {
CDC *dc = GetDC();
if (dc) {
DrawFrame(dc);
ReleaseDC(dc);
}
}
} else {
if (m_frame_ticks <= ticks_now) {
m_frame_ticks = 0;
++m_frame_index;
if (m_frame_index == m_frame_count)
m_frame_index = 0;
}
}
}
CStatic::OnTimer(nIDEvent);
}

View File

@ -0,0 +1,69 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Animated Bitmap
//---------------------------------------------------------------------------
#ifndef _MY_ANIMATEDBITMAP_H
#define _MY_ANIMATEDBITMAP_H
#include <afxcmn.h>
struct CAnimatedBitmap_NM : public NMHDR
{
CDC *dc;
};
class CAnimatedBitmap : public CStatic
{
protected:
DECLARE_MESSAGE_MAP()
void *m_image;
GUID m_guid;
void *m_property;
int m_frame_count;
int m_frame_index;
ULONG m_frame_ticks;
protected:
void DrawFrame(CDC *dc);
afx_msg void OnPaint();
afx_msg void OnTimer(UINT_PTR nIDEvent);
public:
bool Init(HWND hwndEdit);
bool Init(CDialog *dlg, UINT id);
bool SetImage(const WCHAR *name);
void Animate(bool enable);
CAnimatedBitmap();
~CAnimatedBitmap();
};
#endif // _MY_ANIMATEDBITMAP_H

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,132 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Application Settings Property Page
//---------------------------------------------------------------------------
#ifndef _MY_APPPAGE_H
#define _MY_APPPAGE_H
#include "BoxPage.h"
class CAppPage : public CBoxPage
{
DECLARE_MESSAGE_MAP()
ULONG m_app;
static CObList m_app_pages;
virtual void Plugin_OnInitDialog(CBox &box);
virtual void Plugin_OnOK(CBox &box);
//
// Access
//
void Access_OnInitDialog(CBox &box);
void Access_OnOK(CBox &box);
//
// Template
//
typedef struct _TMPL_INFO {
CString ClassName;
int ClassModifier;
ULONG TitleId;
ULONG LabelId;
BOOL WithLink;
BOOL WithCreate;
} TMPL_INFO;
TMPL_INFO m_tmpl_info;
CStringList m_tmpl_sections;
BOOL m_tmpl_init_list_box;
void Template_OnInitDialog(CBox &box);
void Template_OnOK(CBox &box);
afx_msg void Template_OnAdd();
afx_msg void Template_OnRemove();
afx_msg void Template_OnToggle();
void Template_OnView();
void Template_OnLink();
void Template_OnCreate();
void Template_Filter();
void Template_Sort();
afx_msg void OnMeasureItem(int idCtrl, LPMEASUREITEMSTRUCT lpmis);
afx_msg void OnDrawItem(int idCtrl, LPDRAWITEMSTRUCT lpdis);
//
// Folders
//
CStringList m_folders_vars;
void Folders_OnInitDialog(CBox &box);
void Folders_OnOK(CBox &box);
afx_msg void Folders_OnSelect();
afx_msg void Folders_OnAdd();
afx_msg void Folders_OnRemove();
BOOL Folders_CheckExpectFile(const WCHAR *var, const WCHAR *path);
//
// More templates
//
static void UpdateWebTemplates(CBox &box);
static void UpdateEmailTemplates(CBox &box);
static void UpdateTemplates2(CBox &box,
const CString &image_name,
const CString &tmpl_name,
const CString &path1,
const CString &path2);
static void UpdateTemplates3(CBox &box,
const CString &image_name,
const CString &tmpl_name,
CStringList &files,
CStringList &keys);
public:
CAppPage(ULONG type, const CString &BoxName, ULONG TitleMsgId);
CAppPage(TMPL_INFO *info, const CString &BoxName);
~CAppPage();
static void AddPages(CPropertySheet &sheet, const CString &BoxName);
static void DeletePages();
static void UpdateTemplates(CBox &box);
static void SetDefaultTemplates6(CBox &box);
static void SetDefaultTemplates7(CBox &box);
};
#endif // _MY_APPPAGE_H

View File

@ -0,0 +1,218 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// AutoPlay
//---------------------------------------------------------------------------
#include "stdafx.h"
#include "MyApp.h"
#include "AutoPlay.h"
#include "SbieIni.h"
#include "Boxes.h"
#include "common/my_version.h"
//---------------------------------------------------------------------------
// Variables
//---------------------------------------------------------------------------
CAutoPlay *CAutoPlay::m_instance = NULL;
static GUID CLSID_MyAutoPlay = { MY_AUTOPLAY_CLSID };
//---------------------------------------------------------------------------
// QueryInterface
//---------------------------------------------------------------------------
HRESULT CAutoPlay::QueryInterface(REFIID riid, void **ppv)
{
if (IsEqualIID(riid, IID_IUnknown) ||
IsEqualIID(riid, IID_IQueryCancelAutoPlay)) {
++m_refcount;
*ppv = this;
return S_OK;
}
return E_NOINTERFACE;
}
//---------------------------------------------------------------------------
// AddRef
//---------------------------------------------------------------------------
ULONG CAutoPlay::AddRef()
{
return ++m_refcount;
}
//---------------------------------------------------------------------------
// Release
//---------------------------------------------------------------------------
ULONG CAutoPlay::Release()
{
return --m_refcount;
}
//---------------------------------------------------------------------------
// AllowAutoPlay
//---------------------------------------------------------------------------
HRESULT CAutoPlay::AllowAutoPlay(
const WCHAR *path, ULONG cttype, const WCHAR *label, ULONG sn)
{
ULONG state;
SbieApi_DisableForceProcess(NULL, &state);
if (state != 0)
return S_OK;
WCHAR drive = towupper(path[0]);
CBoxes &boxes = CBoxes::GetInstance();
for (int i = (int)boxes.GetSize() - 1; i >= 1; --i) {
CBox &box = boxes.GetBox(i);
CStringList folders;
box.GetProcessList(L'O', folders);
while (! folders.IsEmpty()) {
CString fol = folders.RemoveHead();
ULONG len = fol.GetLength();
if (len <= 3 && fol.GetAt(1) == L':') {
if (towupper(fol.GetAt(0)) == drive) {
LogAutoPlay(box.GetName(), drive);
return S_FALSE;
}
}
}
}
return S_OK;
}
//---------------------------------------------------------------------------
// LogAutoPlay
//---------------------------------------------------------------------------
void CAutoPlay::LogAutoPlay(const WCHAR *boxname, WCHAR drive)
{
WCHAR *tmp = new WCHAR[(wcslen(boxname) + 16)];
if (! tmp)
return;
wcscpy(tmp, boxname);
WCHAR *tmp2 = tmp + wcslen(tmp);
*tmp2 = L' ';
++tmp2;
wcscpy(tmp2, L"*AUTOPLAY*");
tmp2 += 10;
*tmp2 = drive;
++tmp2;
*tmp2 = L'\0';
SbieApi_Log(2199, tmp);
delete tmp;
}
//---------------------------------------------------------------------------
// Install
//---------------------------------------------------------------------------
void CAutoPlay::Install()
{
HRESULT hr;
IMoniker *pMoniker;
IRunningObjectTable *pRunningObjectTable;
ULONG cookie;
if (CMyApp::m_Windows2000)
return;
CAutoPlay *pAutoPlay = new CAutoPlay();
if (! pAutoPlay)
return;
CAutoPlay::m_instance = pAutoPlay;
pAutoPlay->m_refcount = 1;
pAutoPlay->m_pMoniker = NULL;
pAutoPlay->m_pRunningObjectTable = NULL;
pAutoPlay->m_cookie = 0;
hr = CreateClassMoniker(CLSID_MyAutoPlay, &pMoniker);
if (FAILED(hr))
return;
pAutoPlay->m_pMoniker = pMoniker;
hr = GetRunningObjectTable(0, &pRunningObjectTable);
if (FAILED(hr))
return;
pAutoPlay->m_pRunningObjectTable = pRunningObjectTable;
hr = pRunningObjectTable->Register(ROTFLAGS_REGISTRATIONKEEPSALIVE,
pAutoPlay,
pMoniker,
&cookie);
if (FAILED(hr))
return;
pAutoPlay->m_cookie = cookie;
}
//---------------------------------------------------------------------------
// Remove
//---------------------------------------------------------------------------
void CAutoPlay::Remove()
{
CAutoPlay *pAutoPlay = CAutoPlay::m_instance;
if (! pAutoPlay)
return;
if (pAutoPlay->m_cookie) {
pAutoPlay->m_pRunningObjectTable->Revoke(pAutoPlay->m_cookie);
pAutoPlay->m_cookie = 0;
}
if (pAutoPlay->m_pRunningObjectTable)
pAutoPlay->m_pRunningObjectTable->Release();
if (pAutoPlay->m_pMoniker)
pAutoPlay->m_pMoniker->Release();
}

View File

@ -0,0 +1,71 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// AutoPlay
//---------------------------------------------------------------------------
#ifndef _MY_AUTOPLAY_H
#define _MY_AUTOPLAY_H
#include "shobjidl.h"
class CAutoPlay : public IQueryCancelAutoPlay
{
private:
static CAutoPlay *m_instance;
ULONG m_refcount;
IMoniker *m_pMoniker;
IRunningObjectTable *m_pRunningObjectTable;
ULONG m_cookie;
void LogAutoPlay(const WCHAR *boxname, WCHAR drive);
public:
//
// IUnknown methods
//
STDMETHOD(QueryInterface)(REFIID riid, void **ppv);
STDMETHOD_(ULONG, AddRef)();
STDMETHOD_(ULONG, Release)();
//
// IQueryCancelAutoPlay methods
//
STDMETHOD(AllowAutoPlay)(
const WCHAR *path, ULONG cttype, const WCHAR *label, ULONG sn);
//
// static methods
//
static void Install();
static void Remove();
};
#endif // _MY_AUTOPLAY_H

View File

@ -0,0 +1,306 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Base Dialog Box
//---------------------------------------------------------------------------
#include "stdafx.h"
#include "MyApp.h"
#include "BaseDialog.h"
#include "apps/common/CommonUtils.h"
//---------------------------------------------------------------------------
// Message Map
//---------------------------------------------------------------------------
BEGIN_MESSAGE_MAP(CBaseDialog, CDialog)
ON_WM_DESTROY()
ON_WM_SIZE()
ON_WM_NCLBUTTONDOWN()
END_MESSAGE_MAP()
//---------------------------------------------------------------------------
// Constructor
//---------------------------------------------------------------------------
CBaseDialog::CBaseDialog(CWnd *pParentWnd, const WCHAR *TemplateName)
: CDialog((UINT)0, pParentWnd)
{
m_template_copy = NULL;
SetDialogTemplate(TemplateName);
}
//---------------------------------------------------------------------------
// Destructor
//---------------------------------------------------------------------------
CBaseDialog::~CBaseDialog()
{
SetDialogTemplate(NULL);
}
//---------------------------------------------------------------------------
// SetDialogTemplate
//---------------------------------------------------------------------------
void CBaseDialog::SetDialogTemplate(const WCHAR *TemplateName)
{
if (m_template_copy) {
HeapFree(GetProcessHeap(), 0, m_template_copy);
m_template_copy = NULL;
}
if (TemplateName && CMyApp::m_LayoutRTL) {
m_template_copy =
Common_DlgTmplRtl(AfxGetInstanceHandle(), TemplateName);
if (m_template_copy)
InitModalIndirect((LPCDLGTEMPLATE)m_template_copy, m_pParentWnd);
}
if (! m_template_copy)
m_lpszTemplateName = TemplateName;
}
//---------------------------------------------------------------------------
// MakeLTR
//---------------------------------------------------------------------------
void CBaseDialog::MakeLTR(CWnd *pWnd)
{
if (CMyApp::m_LayoutRTL) {
const ULONG _flag = SWP_NOACTIVATE;
pWnd->ModifyStyleEx(
WS_EX_RIGHT | WS_EX_RTLREADING | WS_EX_LAYOUTRTL, 0, _flag);
pWnd->ModifyStyle(ES_RIGHT, 0, _flag);
}
}
//---------------------------------------------------------------------------
// MakeLTR
//---------------------------------------------------------------------------
void CBaseDialog::MakeLTR(UINT id)
{
MakeLTR(GetDlgItem(id));
}
//---------------------------------------------------------------------------
// AddMinimizeButton
//---------------------------------------------------------------------------
void CBaseDialog::AddMinimizeButton()
{
ModifyStyle(0, WS_MINIMIZEBOX | WS_SYSMENU);
ModifyStyleEx(0, WS_EX_APPWINDOW);
}
//---------------------------------------------------------------------------
// OnDestroy
//---------------------------------------------------------------------------
void CBaseDialog::OnDestroy()
{
ShowOrHideAllWindows(false);
CDialog::OnDestroy();
}
//---------------------------------------------------------------------------
// OnSize
//---------------------------------------------------------------------------
void CBaseDialog::OnSize(UINT nType, int cx, int cy)
{
if (nType == SIZE_MINIMIZED)
ShowOrHideAllWindows(true);
else if (nType == SIZE_RESTORED)
ShowOrHideAllWindows(false);
}
//---------------------------------------------------------------------------
// OnNcLButtonUp
//---------------------------------------------------------------------------
void CBaseDialog::OnNcLButtonDown(UINT nHitTest, CPoint point)
{
if (nHitTest == HTMINBUTTON)
ShowWindow(SW_MINIMIZE);
else
CDialog::OnNcLButtonDown(nHitTest, point);
}
//---------------------------------------------------------------------------
// ShowOrHideAllWindows
//---------------------------------------------------------------------------
void CBaseDialog::ShowOrHideAllWindows(bool hide)
{
if (hide) {
if (! m_hidden_windows.IsEmpty())
ShowOrHideAllWindows(false);
EnumThreadWindows(
GetCurrentThreadId(), ShowOrHideAllWindowsEnum, (LPARAM)this);
} else {
while (! m_hidden_windows.IsEmpty()) {
HWND hwnd = (HWND)m_hidden_windows.RemoveHead();
::ShowWindow(hwnd, SW_SHOW);
}
}
}
//---------------------------------------------------------------------------
// ShowOrHideAllWindowsEnum
//---------------------------------------------------------------------------
BOOL CBaseDialog::ShowOrHideAllWindowsEnum(HWND hwnd, LPARAM lparam)
{
CBaseDialog *pThis = (CBaseDialog *)lparam;
bool HideWindow = false;
if (hwnd != pThis->m_hWnd) {
WCHAR clsnm[256];
GetClassName(hwnd, clsnm, 250);
clsnm[250] = L'\0';
if (_wcsicmp(clsnm, L"#32770") == 0)
HideWindow = true;
else {
CWnd *pMainWnd = AfxGetMainWnd();
if (pMainWnd && pMainWnd->m_hWnd == hwnd)
HideWindow = true;
}
}
if (HideWindow && (GetWindowLong(hwnd, GWL_STYLE) & WS_VISIBLE)) {
pThis->m_hidden_windows.AddTail(hwnd);
::ShowWindow(hwnd, SW_HIDE);
}
return TRUE;
}
//---------------------------------------------------------------------------
// GetInputWindow
//---------------------------------------------------------------------------
CWnd *CBaseDialog::GetInputWindow(bool *inModal)
{
if (inModal)
*inModal = false;
CWnd *pWnd = AfxGetMainWnd();
if (pWnd && pWnd->m_hWnd) {
HWND hWnd = NULL;
EnumThreadWindows(
GetCurrentThreadId(), GetInputWindowEnum, (LPARAM)&hWnd);
if (hWnd && hWnd != pWnd->m_hWnd) {
pWnd = CWnd::FromHandle(hWnd);
if (inModal)
*inModal = true;
}
} else
pWnd = NULL;
return pWnd;
}
//---------------------------------------------------------------------------
// GetActiveWnd
//---------------------------------------------------------------------------
BOOL CBaseDialog::GetInputWindowEnum(HWND hwnd, LPARAM lparam)
{
WCHAR clsnm[256];
GetClassName(hwnd, clsnm, 250);
clsnm[250] = L'\0';
if (_wcsicmp(clsnm, L"#32770") == 0) {
ULONG style = ::GetWindowLong(hwnd, GWL_STYLE);
if ((style & (WS_VISIBLE | WS_DISABLED)) == WS_VISIBLE) {
*(HWND *)lparam = hwnd;
return FALSE;
}
}
return TRUE;
}
//---------------------------------------------------------------------------
// InModalState
//---------------------------------------------------------------------------
bool CBaseDialog::InModalState()
{
bool inModal;
GetInputWindow(&inModal);
return inModal;
}
//---------------------------------------------------------------------------
// FlashTitle
//---------------------------------------------------------------------------
void CBaseDialog::FlashTitle()
{
FLASHWINFO flash;
memzero(&flash, sizeof(FLASHWINFO));
flash.cbSize = sizeof(FLASHWINFO);
flash.hwnd = m_hWnd;
flash.dwFlags = FLASHW_ALL | FLASHW_TIMERNOFG;
::FlashWindowEx(&flash);
}

View File

@ -0,0 +1,66 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Base Dialog Box
//---------------------------------------------------------------------------
#ifndef _MY_BASEDIALOG_H
#define _MY_BASEDIALOG_H
class CBaseDialog : public CDialog
{
protected:
DECLARE_MESSAGE_MAP()
void *m_template_copy;
CPtrList m_hidden_windows;
void ShowOrHideAllWindows(bool hide);
static BOOL ShowOrHideAllWindowsEnum(HWND hwnd, LPARAM lparam);
public:
afx_msg void OnDestroy();
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnNcLButtonDown(UINT nHitTest, CPoint point);
public:
void SetDialogTemplate(const WCHAR *TemplateName);
static void MakeLTR(CWnd *pWnd);
void MakeLTR(UINT id);
void AddMinimizeButton();
void FlashTitle();
CBaseDialog(CWnd *pParentWnd, const WCHAR *TemplateName = NULL);
~CBaseDialog();
static CWnd *GetInputWindow(bool *inModal = NULL);
static BOOL GetInputWindowEnum(HWND hwnd, LPARAM lparam);
static bool InModalState();
};
#endif // _MY_DELETEDIALOG_H

View File

@ -0,0 +1,630 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Border Guard
//---------------------------------------------------------------------------
#include "stdafx.h"
#include "resource.h"
#include "BorderGuard.h"
#include "Boxes.h"
#include "common/my_version.h"
//---------------------------------------------------------------------------
// Structures
//---------------------------------------------------------------------------
struct BoxBorderParms {
WCHAR boxname[48];
COLORREF color;
BOOL title;
};
//---------------------------------------------------------------------------
// Variables
//---------------------------------------------------------------------------
CBorderGuard *CBorderGuard::m_instance = NULL;
void *CBorderGuard::m_DwmIsCompositionEnabled = NULL;
void *CBorderGuard::m_DwmGetWindowAttribute = NULL;
//---------------------------------------------------------------------------
// Constructor
//---------------------------------------------------------------------------
CBorderGuard::CBorderGuard()
{
m_instance = this;
m_windows_8 = false;
HMODULE dwmapi = LoadLibrary(L"dwmapi.dll");
if (dwmapi) {
m_DwmIsCompositionEnabled =
GetProcAddress(dwmapi, "DwmIsCompositionEnabled");
if (m_DwmIsCompositionEnabled) {
m_DwmGetWindowAttribute =
GetProcAddress(dwmapi, "DwmGetWindowAttribute");
if (! m_DwmGetWindowAttribute)
m_DwmIsCompositionEnabled = NULL;
}
if (GetProcAddress(dwmapi, "DwmRenderGesture"))
m_windows_8 = true;
}
m_timer_id = NULL;
m_active_hwnd = NULL;
m_active_pid = 0;
m_border_hwnd = NULL;
m_border_brush = NULL;
m_border_brush_color = RGB(0,0,0);
m_border_visible = FALSE;
m_thumb_width = GetSystemMetrics(SM_CXHTHUMB);
m_thumb_height = GetSystemMetrics(SM_CYVTHUMB);
static const WCHAR *WindowClassName = SANDBOXIE_CONTROL L"BorderWindow";
WNDCLASSEX wc;
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS | CS_GLOBALCLASS;
wc.lpfnWndProc = ::DefWindowProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = AfxGetInstanceHandle();
wc.hIcon = ::LoadIcon(wc.hInstance, L"AAAPPICON");
wc.hCursor = ::LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
wc.lpszMenuName = NULL;
wc.lpszClassName = WindowClassName;
wc.hIconSm = NULL;
ATOM atom = RegisterClassEx(&wc);
if (! atom)
return;
m_border_hwnd = CreateWindowEx(
WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_NOACTIVATE
| WS_EX_TOOLWINDOW | WS_EX_TOPMOST,
(LPCWSTR)atom, WindowClassName,
WS_POPUP | WS_CLIPSIBLINGS,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, NULL, NULL, NULL);
if (! m_border_hwnd)
return;
if (m_border_hwnd) {
SetLayeredWindowAttributes(m_border_hwnd, 0, 192, LWA_ALPHA);
::ShowWindow(m_border_hwnd, SW_HIDE);
}
RefreshConf();
}
//---------------------------------------------------------------------------
// Destructor
//---------------------------------------------------------------------------
CBorderGuard::~CBorderGuard()
{
if (m_border_hwnd) {
DestroyWindow(m_border_hwnd);
m_border_hwnd = NULL;
}
}
//---------------------------------------------------------------------------
// MyTimerProc
//---------------------------------------------------------------------------
void CBorderGuard::MyTimerProc(
HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
m_instance->Refresh();
}
//---------------------------------------------------------------------------
// Refresh
//---------------------------------------------------------------------------
void CBorderGuard::Refresh()
{
if ((! m_border_hwnd) || (! m_timer_id))
return;
//
// get current foreground window,
// and its associated process id and box name
//
HWND hwnd;
ULONG style;
ULONG pid = NULL;
WCHAR boxname[48];
boxname[0] = L'\0';
hwnd = GetForegroundWindow();
if (hwnd) {
style = GetWindowLong(hwnd, GWL_STYLE);
if (style & WS_VISIBLE) {
GetWindowThreadProcessId(hwnd, &pid);
const CBoxes &boxes = CBoxes::GetInstance();
const CBox &box = boxes.GetBoxByProcessId(pid);
wcscpy(boxname, box.GetName());
}
}
//
// foreground process is sandboxed
//
if (boxname[0]) {
//
// get the bounding rectangle for the foreground window
//
RECT rect;
bool doGetWindowRect = true;
if (m_DwmIsCompositionEnabled) {
typedef HRESULT (*P_DwmIsCompositionEnabled)(BOOL *enabled);
P_DwmIsCompositionEnabled pDwmIsCompositionEnabled =
(P_DwmIsCompositionEnabled)m_DwmIsCompositionEnabled;
BOOL dwmEnabled = FALSE;
HRESULT hr = pDwmIsCompositionEnabled(&dwmEnabled);
if (SUCCEEDED(hr) && dwmEnabled) {
typedef HRESULT (*P_DwmGetWindowAttribute)(
HWND hwnd, DWORD dwAttribute,
void *pvAttribute, DWORD cbAttribute);
P_DwmGetWindowAttribute pDwmGetWindowAttribute =
(P_DwmGetWindowAttribute)m_DwmGetWindowAttribute;
const ULONG DWMWA_EXTENDED_FRAME_BOUNDS = 9;
hr = pDwmGetWindowAttribute(
hwnd, DWMWA_EXTENDED_FRAME_BOUNDS, &rect, sizeof(RECT));
if (SUCCEEDED(hr))
doGetWindowRect = false;
}
}
if (doGetWindowRect)
GetWindowRect(hwnd, &rect);
//
// check if the border has to be refreshed
//
BOOL have_cursor = FALSE;
POINT cursor;
BOOL refresh = TRUE;
if (pid == m_active_pid && hwnd == m_active_hwnd) {
if (memcmp(&rect, &m_active_rect, sizeof(RECT)) == 0) {
//
// window rect is same as last recorded window rect
// but if we track title area for border then also
// check the cursor is stil in the title area
//
refresh = FALSE;
if (m_title_mode) {
int title_mode = -1;
have_cursor = GetCursorPos(&cursor);
if (have_cursor && cursor.x >= m_title_rect.left
&& cursor.x <= m_title_rect.right
&& cursor.y >= m_title_rect.top
&& cursor.y <= m_title_rect.bottom)
title_mode = +1;
if (title_mode != m_title_mode)
refresh = TRUE;
}
} else {
if (! m_fast_timer_start_ticks)
m_timer_id = SetTimer(NULL, m_timer_id, 10, MyTimerProc);
m_fast_timer_start_ticks = GetTickCount();
}
}
//
// show the border if necessary
//
if (refresh) {
if (m_border_visible)
::ShowWindow(m_border_hwnd, SW_HIDE);
m_border_visible = FALSE;
m_active_hwnd = hwnd;
m_active_pid = pid;
memcpy(&m_active_rect, &rect, sizeof(RECT));
m_title_mode = 0;
RefreshBorder(hwnd, style, &rect, boxname);
}
//
// foreground process is not sandboxed: hide border
//
} else {
if (m_border_visible) {
::ShowWindow(m_border_hwnd, SW_HIDE);
m_border_visible = FALSE;
}
m_active_hwnd = NULL;
m_active_pid = 0;
}
//
// reprogram the timer if necessary
//
if (m_fast_timer_start_ticks) {
if (GetTickCount() - m_fast_timer_start_ticks >= 1000) {
m_fast_timer_start_ticks = 0;
m_timer_id = SetTimer(NULL, m_timer_id, 100, MyTimerProc);
}
}
}
//---------------------------------------------------------------------------
// RefreshBorder
//---------------------------------------------------------------------------
void CBorderGuard::RefreshBorder(
HWND hwnd, ULONG style, RECT *rect, const WCHAR *boxname)
{
//
// ignore very small windows
//
if (rect->right - rect->left <= 2 || rect->bottom - rect->top <= 2)
return;
//
//
//
BoxBorderParms *boxparm = NULL;
ULONG count = (ULONG)m_boxes.GetSize();
ULONG i = 0;
for (i = 0; i < count; ++i) {
boxparm = (BoxBorderParms *)m_boxes.GetAt(i);
if (wcscmp(boxparm->boxname, boxname) == 0)
break;
}
if (i == count)
return;
//
// get information about the screen containing the window.
// don't draw the color border if the window is full screen
// and also has no caption bar (i.e. a full screen app)
//
HMONITOR hmonitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONULL);
if (! hmonitor)
return;
MONITORINFO monitor;
memzero(&monitor, sizeof(MONITORINFO));
monitor.cbSize = sizeof(MONITORINFO);
if (! GetMonitorInfo(hmonitor, &monitor))
return;
const RECT *desktop = &monitor.rcMonitor;
if (rect->left <= desktop->left && rect->top <= desktop->top &&
rect->right >= desktop->right && rect->bottom >= desktop->bottom &&
(style & WS_CAPTION) != WS_CAPTION) {
return;
}
//
// display the border only if the cursor is on the title bar area,
// when the corresponding border mode is enabled
//
if (boxparm->title) {
TITLEBARINFO tbinfo;
tbinfo.cbSize = sizeof(TITLEBARINFO);
GetTitleBarInfo(hwnd, &tbinfo);
memcpy(&m_title_rect, &tbinfo.rcTitleBar, sizeof(RECT));
#define t m_title_rect
#define w (*rect)
if (t.left < w.left || t.left > w.right ||
t.top < w.top || t.top > w.bottom ||
t.right < w.left || t.right > w.right ||
t.bottom < w.top || t.bottom > w.bottom ||
t.right - t.left <= m_thumb_width ||
t.bottom - t.top <= m_thumb_height) {
// if window has no title bar area, then calculate some area
m_title_rect.left = rect->left;
m_title_rect.top = rect->top;
m_title_rect.right = rect->right;
m_title_rect.bottom = rect->top + m_thumb_height * 2;
}
/*{WCHAR xxx[256];wsprintf(xxx, L"Window %08X Rect (%d,%d)-(%d,%d) title (%d,%d)-(%d,%d) cursor (%d,%d)\n",
hwnd, rect->left,rect->top,rect->right,rect->bottom,
m_title_rect.left,m_title_rect.top,m_title_rect.right,m_title_rect.bottom,
cursor.x,cursor.y);
OutputDebugString(xxx);}*/
#undef w
#undef t
m_title_rect.top -= 8;
if (m_title_rect.top < desktop->top)
m_title_rect.top = desktop->top;
m_title_mode = -1;
POINT cursor;
if (GetCursorPos(&cursor) && cursor.x >= m_title_rect.left
&& cursor.x <= m_title_rect.right
&& cursor.y >= m_title_rect.top
&& cursor.y <= m_title_rect.bottom)
m_title_mode = +1;
if (m_title_mode == -1)
return;
}
//
// replace background brush if necessary
//
if ((! m_border_brush) ||
boxparm->color != m_border_brush_color) {
HBRUSH hbr = CreateSolidBrush(boxparm->color);
SetClassLongPtr(m_border_hwnd, GCLP_HBRBACKGROUND, (LONG_PTR)hbr);
if (m_border_brush)
DeleteObject(m_border_brush);
m_border_brush = hbr;
m_border_brush_color = boxparm->color;
}
//
// get work area of the screen containing the window,
// then compute window bounds within the work area
//
desktop = &monitor.rcWork;
int ax = rect->left;
if (ax < desktop->left)
ax = desktop->left;
int ay = rect->top;
if (ay < desktop->top)
ay = desktop->top;
int aw = -ax;
if (rect->right <= desktop->right)
aw += rect->right;
else
aw += desktop->right;
int ah = -ay;
if (rect->bottom <= desktop->bottom)
ah += rect->bottom;
else
ah += desktop->bottom;
int bb = 6;
if (rect->left <= desktop->left &&
rect->top <= desktop->top &&
rect->right >= desktop->right &&
rect->bottom >= desktop->bottom)
bb = 4;
//
// don't display the border if any of it would be obscured by
// some other window that has the "always on top" attribute
//
HWND hwndShellTrayWnd = FindWindow(L"Shell_TrayWnd", NULL);
for (i = 0; i < 4; ++i) {
POINT testpt;
if (i == 0) {
testpt.x = ax;
testpt.y = ay;
} else if (i == 1) {
testpt.x = ax + aw;
testpt.y = ay;
} else if (i == 2) {
testpt.x = ax;
testpt.y = ay + ah;
} else if (i == 3) {
testpt.x = ax + aw;
testpt.y = ay + ah;
}
if (testpt.x >= desktop->right)
testpt.x = desktop->right - 1;
if (testpt.y >= desktop->bottom)
testpt.y = desktop->bottom - 1;
HWND testwnd = WindowFromPoint(testpt);
while (testwnd) {
if ( (testwnd == hwndShellTrayWnd) || (testwnd == hwnd) )
break;
ULONG exStyle = GetWindowLong(testwnd, GWL_EXSTYLE);
if (exStyle & WS_EX_TOPMOST) {
//
// Windows 8 places invisible "always on top" windows in
// the corners of the desktop, we should ignore those
//
bool foundTopmostWindow = true;
if (m_windows_8) {
WCHAR clsnm[64];
int n = GetClassName(testwnd, clsnm, 64);
if (n == 19 &&
_wcsicmp(clsnm, L"EdgeUiInputWndClass") == 0)
foundTopmostWindow = false;
}
if (foundTopmostWindow) {
m_active_hwnd = NULL;
m_active_pid = 0;
return;
}
}
testwnd = GetParent(testwnd);
}
}
//
// compute new region
//
POINT points[16];
int num_points = 0;
#define ADD_POINT(xx,yy) \
points[num_points].x = (xx); \
points[num_points].y = (yy); \
++num_points;
ADD_POINT(0, 0 );
ADD_POINT(aw, 0 );
ADD_POINT(aw, ah );
ADD_POINT(0, ah );
ADD_POINT(0, 0 );
ADD_POINT(0 + bb, 0 + bb );
ADD_POINT(aw - bb, 0 + bb );
ADD_POINT(aw - bb, ah - bb );
ADD_POINT(0 + bb, ah - bb );
ADD_POINT(0 + bb, 0 + bb );
#undef ADD_POINT
HRGN hrgn = CreatePolygonRgn(points, num_points, ALTERNATE);
SetWindowRgn(m_border_hwnd, hrgn, TRUE);
SetWindowPos(m_border_hwnd, NULL, ax, ay, aw, ah,
SWP_SHOWWINDOW | SWP_NOACTIVATE);
m_border_visible = TRUE;
}
//---------------------------------------------------------------------------
// RefreshConf2
//---------------------------------------------------------------------------
void CBorderGuard::RefreshConf2()
{
/*if (GetSystemMetrics(SM_CXSCREEN) < 1000)
m_border_width = 2;
else
m_border_width = 4;*/
BoxBorderParms *boxparm;
int i;
while (m_boxes.GetSize()) {
boxparm = (BoxBorderParms *)m_boxes.GetAt(0);
delete boxparm;
m_boxes.RemoveAt(0);
}
CBoxes &boxes = CBoxes::GetInstance();
for (i = 1; i < boxes.GetSize(); ++i) {
CBox &box = boxes.GetBox(i);
if (! box.GetName().IsEmpty()) {
COLORREF color;
BOOL title;
BOOL enabled = box.GetBorder(&color, &title);
if (enabled) {
boxparm = new BoxBorderParms;
wcscpy(boxparm->boxname, box.GetName());
boxparm->color = color;
boxparm->title = title;
m_boxes.Add(boxparm);
}
}
}
if (m_boxes.GetSize()) {
if (! m_timer_id) {
m_fast_timer_start_ticks = 0;
m_timer_id = SetTimer(NULL, 0, 100, MyTimerProc);
}
} else if (m_timer_id) {
KillTimer(NULL, m_timer_id);
m_timer_id = NULL;
}
}
//---------------------------------------------------------------------------
// RefreshConf
//---------------------------------------------------------------------------
void CBorderGuard::RefreshConf()
{
if (! m_instance)
m_instance = new CBorderGuard();
m_instance->RefreshConf2();
}

View File

@ -0,0 +1,77 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Border Guard
//---------------------------------------------------------------------------
#ifndef _MY_BORDERGUARD_H
#define _MY_BORDERGUARD_H
class CBorderGuard
{
static CBorderGuard *m_instance;
static void *m_DwmIsCompositionEnabled;
static void *m_DwmGetWindowAttribute;
static void MyTimerProc(
HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime);
void RefreshBorder(
HWND hwnd, ULONG style, RECT *rect, const WCHAR *boxname);
void RefreshConf2();
UINT_PTR m_timer_id;
int m_fast_timer_start_ticks;
CPtrArray m_boxes;
ULONG m_active_pid;
HWND m_active_hwnd;
RECT m_active_rect;
RECT m_title_rect;
int m_title_mode;
HWND m_border_hwnd;
BOOL m_border_visible;
HBRUSH m_border_brush;
COLORREF m_border_brush_color;
int m_thumb_width;
int m_thumb_height;
//ULONG m_border_width;
bool m_windows_8;
public:
CBorderGuard();
~CBorderGuard();
void Refresh();
static void RefreshConf();
};
#endif // _MY_BORDERGUARD_H

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,169 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Boxes
//---------------------------------------------------------------------------
#ifndef _MY_BOX_H
#define _MY_BOX_H
#include "BoxProc.h"
#include "BoxFile.h"
class CBox
{
static const CString _empty;
CString m_name;
CBoxProc *m_BoxProc;
CBoxFile *m_BoxFile;
BOOL m_expandedView;
BOOL m_TemporarilyDisableQuickRecover;
public:
CBox(const CString &name);
~CBox();
const CString &GetName() const;
CBoxProc &GetBoxProc();
CBoxFile &GetBoxFile();
BOOL IsExpandedView() const;
void SetExpandedView(BOOL view);
//
// Settings
//
void SetDefaultSettings();
static void SetEnabled(const CString &BoxName);
BOOL GetProcessSetting(WCHAR type, const CString &image);
BOOL SetProcessSetting(WCHAR type, const CString &image, BOOL newval);
void GetProcessList(WCHAR type, CStringList &list,
BOOL withBrackets = FALSE);
void GetProcessGroupsInBox(CStringList &names);
void GetProcessGroupName(
const CString &GroupName,
CString &LocalGroupName, CString &GlobalGroupName);
CString GetProcessGroup(const CString &GroupName);
void SetProcessGroup(const CString &GroupName, const CString &value);
CString GetInternetProcess(BOOL *pNotify = NULL);
BOOL SetInternetProcess(const CString &program, BOOL *pNotify = NULL);
CString GetStartRunProcess(BOOL *pNotify = NULL);
BOOL SetStartRunProcess(const CString &program, BOOL *pNotify = NULL);
BOOL AddOrRemoveQuickRecoveryFolder(const CString &folder, BOOL add);
void GetQuickRecoveryFolders(CStringList &list,
BOOL withBrackets = FALSE);
BOOL AddOrRemoveAutoRecoveryIgnores(const CString &item, BOOL add);
void GetAutoRecoveryIgnores(CStringList &list,
BOOL withBrackets = FALSE);
BOOL GetImmediateRecoveryState() const;
void SetImmediateRecoveryState(BOOL enabled, BOOL temporarily);
BOOL GetAutoDelete() const;
void SetAutoDelete(BOOL enabled);
BOOL GetNeverDelete() const;
void SetNeverDelete(BOOL enabled);
CString GetDeleteCommand() const;
void SetDeleteCommand(const CString &cmd) const;
ULONG GetSetCopyLimit(BOOL set, ULONG newval = 0);
BOOL GetSetCopySilent(BOOL set, BOOL newval = FALSE);
UCHAR GetBoxNameTitle() const;
BOOL SetBoxNameTitle(UCHAR enabled);
BOOL GetBorder(COLORREF *color, BOOL *title);
BOOL SetBorder(BOOL enabled, COLORREF color, BOOL title);
BOOL GetSetBlock(WCHAR type, BOOL set, BOOL newval = FALSE);
void GetXxxPathList(ULONG type, CStringList &list,
BOOL withBrackets = FALSE);
void GetXxxPathListForPgm(
ULONG type, CStringList &list, const CString &pgm,
BOOL withBrackets = FALSE);
void SetXxxPathListForPgm(
ULONG type, const CStringList &list, const CString &pgm);
BOOL GetSetDropAdminRights(BOOL set, BOOL newval = FALSE);
BOOL GetSetBlockNetworkFiles(BOOL set, BOOL newval = FALSE);
BOOL GetSetAllowSpoolerPrintToFile(BOOL set, BOOL newval = FALSE);
static void GetSetUserAccounts(
const CString &BoxName, BOOL set, CStringList &list);
void GetSetUserAccounts(BOOL set, CStringList &list);
BOOL IsTemplateEnabled(const WCHAR *TemplateName);
BOOL EnableTemplate(const WCHAR *TemplateName, BOOL enable);
BOOL IsTemplateRejected(const WCHAR *TemplateName);
BOOL RejectTemplate(const WCHAR *TemplateName, BOOL reject);
//
// Pubic Variables
//
static const CString _Enabled;
static const CString _ProcessGroup;
static const CString _InternetAccessGroup;
static const CString _StartRunAccessGroup;
static const CString _AutoRecoverIgnore;
static const CString _ForceFolder;
static const CString _ForceProcess;
static const CString _ForceUser;
static const CString _LeaderProcess;
static const CString _LingerProcess;
static const CString _RecoverFolder;
static const CString _ClosedFilePath;
static const CString _ClosedIpcPath;
static const CString _ClosedKeyPath;
static const CString _OpenClsid;
static const CString _OpenFilePath;
static const CString _OpenIpcPath;
static const CString _OpenKeyPath;
static const CString _OpenPipePath;
static const CString _OpenWinClass;
static const CString _ReadFilePath;
static const CString _ReadKeyPath;
static const CString _WriteFilePath;
static const CString _WriteKeyPath;
};
#endif // _MY_BOX_H

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,98 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Files in Box
//---------------------------------------------------------------------------
#ifndef _MY_BOX_FILE_H
#define _MY_BOX_FILE_H
class CBoxFile
{
const CString &m_name;
CString m_FilePath;
CString m_FilePathDos;
void *m_root;
void *m_curdir;
BOOL m_IncludeDeleted;
static int m_RefreshCounter;
//
//
//
void CreateSkeletonTree();
void CreateQuickRecoveryFolders();
bool GetAbsolutePathForRecoveryFolder(WCHAR *buf, ULONG buf_len);
void DeleteFolder(void *voidfolder, BOOL DeleteSelf);
void *AddFolder(const WCHAR *name, void *parent);
BOOL ReadFolder(void *voidfolder);
//
//
//
public:
CBoxFile(const CString &name);
~CBoxFile();
const CString &GetPathNt() const;
const CString &GetPathDos() const;
void RebuildSkeletonTree();
void RebuildQuickRecoveryFolders();
CString GetCopyPathForTruePath(const WCHAR *TruePath) const;
CString GetTruePathForCopyPath(const WCHAR *CopyPath) const;
CString GetDriveNameForTruePath(const WCHAR *TruePath) const;
void TranslateNtToDosPath(CString &InOutPath) const;
int ChangeFolder(const CString &path, BOOL ForceRead = FALSE);
BOOL IsFolderExpandedView() const;
void SetFolderExpandedView(BOOL view);
BOOL IsQuickRecoverFolder() const;
BOOL IsPhysicalFolder() const;
void GetFolderPaths(CString &TruePath, CString &CopyPath) const;
void GetFolderCreationTime(FILETIME *out_time) const;
int GetFolderNumChildren() const;
POSITION GetFolderHeadPosition() const;
const WCHAR *GetNextFolder(POSITION &pos, BOOL &IsExpandedView) const;
const WCHAR *GetNextFile(POSITION &pos, ULONG64 &size) const;
void SetIncludeDeleted(BOOL include);
BOOL IsEmpty();
BOOL GetBoxCreationTime(FILETIME *out_time);
int GetBoxRefreshCounter() const;
BOOL QueryFileAttributes(const WCHAR *path, ULONG *attrs, ULONG64 *size);
};
#endif // _MY_BOX_FILE_H

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,293 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Box Settings Property Page
//---------------------------------------------------------------------------
#ifndef _MY_BOXPAGE_H
#define _MY_BOXPAGE_H
#include "Boxes.h"
#include "ToolTipButton.h"
class CBoxPage : public CPropertyPage
{
DECLARE_MESSAGE_MAP()
ULONG m_type;
CString m_template;
void *m_template_copy;
const CString &m_BoxName;
CString m_titleForTree, m_titleForPage;
BOOL m_modified;
CButton m_groupbox;
CFont *m_font;
void SetTitleForTree();
void AdjustFont();
void CenterControl(int idCtrl);
int AddStringAndSetWidth(
CListBox *pListBox, const CString &str, int index = -1);
void MakeLTR(UINT id);
bool SelectUsers(CStringList &users);
virtual BOOL OnInitDialog();
virtual BOOL OnKillActive();
virtual void OnOK();
afx_msg void OnModified();
afx_msg LRESULT OnQuerySiblings(WPARAM wParam, LPARAM lParam);
//
// Utilities
//
void AddBeforeBrackets(CListBox *pListBox, const CString &str);
BOOL CheckIfBrackets(CListBox *pListBox, int index,
const CString &SettingName,
const CString &Prefix = CString());
//
// Appearance
//
COLORREF Appearance_BorderColor;
HBITMAP Appearance_Bitmap;
CToolTipButton Appearance_ColorButton;
void Appearance_SetBorderColor();
void Appearance_OnInitDialog(CBox &box);
void Appearance_OnOK(CBox &box);
afx_msg void Appearance_OnCheckBox1();
afx_msg void Appearance_OnCheckBox2();
afx_msg void Appearance_OnShowBorder();
afx_msg void Appearance_OnBorderColor();
afx_msg void Appearance_OnBorderTitle();
//
// QuickRecover
//
void QuickRecover_OnInitDialog(CBox &box);
void QuickRecover_OnOK(CBox &box);
afx_msg void QuickRecover_OnCmdAdd();
afx_msg void QuickRecover_OnCmdRemove();
//
// AutoRecover
//
void AutoRecover_OnInitDialog(CBox &box);
void AutoRecover_OnOK(CBox &box);
afx_msg void AutoRecover_OnCmdAddFolder();
afx_msg void AutoRecover_OnCmdAddType();
//
// AutoDelete
//
void AutoDelete_OnInitDialog(CBox &box);
void AutoDelete_OnOK(CBox &box);
afx_msg void AutoDelete_OnAuto();
afx_msg void AutoDelete_OnNever();
//
// DeleteCommand
//
void DeleteCommand_OnInitDialog(CBox &box);
BOOL DeleteCommand_OnKillActive(CBox &box);
void DeleteCommand_OnOK(CBox &box);
afx_msg void DeleteCommand_RmDir();
afx_msg void DeleteCommand_SDelete();
afx_msg void DeleteCommand_EraserL();
afx_msg void DeleteCommand_Eraser6();
void DeleteCommand_SetDeleteProgram(
const WCHAR *PgmName, const WCHAR *PgmArgs);
//
// Program Groups
//
int ProgramGroups_index;
void ProgramGroups_OnInitDialog(CBox &box);
void ProgramGroups_OnOK(CBox &box);
afx_msg void ProgramGroups_OnSelectGrp();
afx_msg void ProgramGroups_OnCmdAddGrp();
afx_msg void ProgramGroups_OnCmdAddPgm();
afx_msg void ProgramGroups_OnCmdRemove();
void ProgramGroups_SwitchGrp(const CString &grp);
//
// Force / Linger / Leader
//
CString ForceLinger_editbox;
void ForceLinger_OnInitDialog(CBox &box);
void ForceLinger_OnOK(CBox &box);
afx_msg void ForceLinger_OnCmdAddPgm();
afx_msg void ForceLinger_OnCmdAddFolder();
afx_msg void ForceLinger_OnCmdRemove();
void ForceLinger_OnCmdAddPgm2(const CString &pgm);
static int CALLBACK ForceLinger_OnCmdAddFolder_Callback(
HWND hwnd, UINT uMsg,LPARAM lParam, LPARAM lpData);
bool ForceLinger_MatchPattern(const CString &pat, const CString &test);
//
// File Migrate
//
void FileMigrate_OnInitDialog(CBox &box);
void FileMigrate_OnOK(CBox &box);
afx_msg void FileMigrate_OnChangeKb();
//
// Internet/Start Restrictions
//
CString m_accAll, m_accNone;
void RestrictPgm_OnInitDialog(CBox &box);
void RestrictPgm_OnOK(CBox &box);
afx_msg void RestrictPgm_AddStar();
//
// File Access
//
int FileAccess_index;
CToolTipButton FileAccess_NegateButton;
void FileAccess_OnInitDialog(CBox &box);
void FileAccess_OnOK(CBox &box);
afx_msg void FileAccess_OnSelectPgm();
afx_msg void FileAccess_OnAddPgm();
afx_msg void FileAccess_OnNegate();
afx_msg void FileAccess_OnAddEntry();
afx_msg void FileAccess_OnEditEntry();
afx_msg void FileAccess_OnRemoveEntry();
afx_msg void FileAccess_OnSelectRes();
void FileAccess_AddAndSwitchPgm(const CString &pgm);
void FileAccess_SwitchPgm(const CString &pgm);
void FileAccess_GetPathList(CStringList &list, const CString *pgm);
BOOL FileAccess_CheckIfBrackets(CListBox *pListBox, int index);
//
// Drop Rights Restrictions
//
void DropRights_OnInitDialog(CBox &box);
void DropRights_OnOK(CBox &box);
//
// Network Files Restrictions
//
void NetworkFiles_OnInitDialog(CBox &box);
void NetworkFiles_OnOK(CBox &box);
//
// Print Spooler Restrictions
//
void PrintSpooler_OnInitDialog(CBox &box);
void PrintSpooler_OnOK(CBox &box);
//
// Low-Level Restrictions
//
void LowLevel_OnInitDialog(CBox &box);
void LowLevel_OnOK(CBox &box);
void Hardware_OnInitDialog(CBox &box);
void Hardware_OnOK(CBox &box);
//
// User Accounts
//
bool UserAccounts_restricted;
void UserAccounts_OnInitDialog(CBox &box);
void UserAccounts_OnOK(CBox &box);
void UserAccounts_OnCmdAdd();
void UserAccounts_OnCmdRemove();
//
// Pluggable derived class
//
virtual void Plugin_OnInitDialog(CBox &box);
virtual void Plugin_OnOK(CBox &box);
protected:
void SetPageTemplate(const WCHAR *TemplateName);
public:
CBoxPage(ULONG type, const CString &BoxName,
ULONG GroupMsgId, ULONG TitleMsgId);
~CBoxPage();
static void DoPropertySheet(
CWnd *pParentWnd, const CString &BoxName,
bool *ReloadBoxes, const CString &ProgramName);
};
#endif // _MY_BOXPAGE_H

View File

@ -0,0 +1,286 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Processes in Box
//---------------------------------------------------------------------------
#include "MyApp.h"
#include "BoxProc.h"
#include "WindowTitleMap.h"
//---------------------------------------------------------------------------
// Variables
//---------------------------------------------------------------------------
const CString CBoxProc::_unknown(L"???");
CStringList CBoxProc::m_RecentExes;
//---------------------------------------------------------------------------
// Constructor
//---------------------------------------------------------------------------
CBoxProc::CBoxProc(const CString &name)
: m_name(name)
{
memzero(m_pids, sizeof(m_pids));
m_images = NULL;
m_titles = NULL;
m_icons = NULL;
m_num = 0;
m_max = 0;
m_old_num = 0;
}
//---------------------------------------------------------------------------
// Destructor
//---------------------------------------------------------------------------
CBoxProc::~CBoxProc()
{
if (m_images)
delete[] m_images;
if (m_titles)
delete[] m_titles;
if (m_icons)
delete[] m_icons;
}
//---------------------------------------------------------------------------
// RefreshProcesses
//---------------------------------------------------------------------------
void CBoxProc::RefreshProcesses(void)
{
if (m_name.IsEmpty())
return;
m_old_num = m_num;
WCHAR name[256];
wcscpy(name, m_name);
SbieApi_EnumProcess(name, m_pids);
m_num = m_pids[0];
//
// shortcut case: no processes found
//
if (m_num == 0)
return;
//
// allocate buffers for process names, if needed
//
if (m_num >= m_max) {
if (m_images)
delete[] m_images;
if (m_titles)
delete[] m_titles;
if (m_icons)
delete[] m_icons;
m_max = m_num + 8;
m_images = new CString[m_max];
m_titles = new CString[m_max];
m_icons = new HICON[m_max];
}
//
// get the image name and window name for each process
//
CWindowTitleMap &theWindowTitleMap = CWindowTitleMap::GetInstance();
int i = 1;
for (i = 1; i <= m_num; ++i) {
SbieApi_QueryProcessEx(
(HANDLE)(ULONG_PTR)m_pids[i], 255, NULL, name, NULL, NULL);
if (name[0])
m_images[i] = name;
else
m_images[i] = _unknown;
HICON icon;
const WCHAR *title = theWindowTitleMap.Get(m_pids[i], icon);
if (title)
m_titles[i] = title;
else
m_titles[i] = CString();
m_icons[i] = icon;
}
//
// collect images into the list of recent EXEs
//
for (i = 1; i <= m_num; ++i) {
ULONG64 ProcessFlags =
SbieApi_QueryProcessInfo((HANDLE)(ULONG_PTR)m_pids[i], 0);
if (! (ProcessFlags & SBIE_FLAG_IMAGE_FROM_SBIE_DIR)) {
CString &exe1 = m_images[i];
AddToRecentExes(exe1);
}
}
}
//---------------------------------------------------------------------------
// GetProcessCount
//---------------------------------------------------------------------------
int CBoxProc::GetOldProcessCount() const
{
return m_old_num;
}
//---------------------------------------------------------------------------
// GetProcessCount
//---------------------------------------------------------------------------
int CBoxProc::GetProcessCount() const
{
return m_num;
}
//---------------------------------------------------------------------------
// GetProcessId
//---------------------------------------------------------------------------
int CBoxProc::GetProcessId(int index) const
{
if (index < 0 || index >= m_num)
return 0;
return m_pids[index + 1];
}
//---------------------------------------------------------------------------
// GetProcessImageName
//---------------------------------------------------------------------------
const CString &CBoxProc::GetProcessImageName(int index) const
{
if (index < 0 || index >= m_num)
return _unknown;
return m_images[index + 1];
}
//---------------------------------------------------------------------------
// GetProcessWindowTitle
//---------------------------------------------------------------------------
const CString &CBoxProc::GetProcessWindowTitle(int index) const
{
if (index < 0 || index >= m_num)
return _unknown;
return m_titles[index + 1];
}
//---------------------------------------------------------------------------
// GetProcessWindowIcon
//---------------------------------------------------------------------------
HICON CBoxProc::GetProcessWindowIcon(int index) const
{
if (index < 0 || index >= m_num)
return NULL;
return m_icons[index + 1];
}
//---------------------------------------------------------------------------
// GetIndexForProcessId
//---------------------------------------------------------------------------
int CBoxProc::GetIndexForProcessId(ULONG pid) const
{
for (int index = 0; index < m_num; ++index)
if (m_pids[index + 1] == pid)
return index;
return -1;
}
//---------------------------------------------------------------------------
// AddToRecentExes
//---------------------------------------------------------------------------
void CBoxProc::AddToRecentExes(const CString &exe1)
{
if (exe1.CompareNoCase(L"unknown executable image") == 0)
return;
if (exe1.CompareNoCase(_unknown) == 0)
return;
bool found = false;
POSITION pos = m_RecentExes.GetHeadPosition();
while (pos) {
CString &exe2 = m_RecentExes.GetNext(pos);
if (exe2.CompareNoCase(exe1) == 0) {
found = true;
break;
}
}
if (! found) {
CString exe2(exe1);
exe2.MakeLower();
m_RecentExes.AddTail(exe2);
}
}
//---------------------------------------------------------------------------
// AddRecentExesToList
//---------------------------------------------------------------------------
void CBoxProc::AddRecentExesToList(CStringList &list1)
{
list1.AddTail(&m_RecentExes);
}

View File

@ -0,0 +1,68 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Processes in Box
//---------------------------------------------------------------------------
#ifndef _MY_BOX_PROC_H
#define _MY_BOX_PROC_H
class CBoxProc
{
static const CString _unknown;
const CString &m_name;
ULONG m_pids[512];
CString *m_images;
CString *m_titles;
HICON *m_icons;
int m_num, m_max;
int m_old_num;
static CStringList m_RecentExes;
//
//
//
public:
CBoxProc(const CString &name);
~CBoxProc();
void RefreshProcesses();
int GetOldProcessCount() const;
int GetProcessCount() const;
int GetIndexForProcessId(ULONG pid) const;
int GetProcessId(int index) const;
const CString &GetProcessImageName(int index) const;
const CString &GetProcessWindowTitle(int index) const;
HICON GetProcessWindowIcon(int index) const;
static void AddToRecentExes(const CString &exe1);
static void AddRecentExesToList(CStringList &list1);
};
#endif // _MY_BOX_PROC_H

View File

@ -0,0 +1,388 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Boxes
//---------------------------------------------------------------------------
#include "stdafx.h"
#include "Boxes.h"
#include "SbieIni.h"
#include "UserSettings.h"
#include "WindowTitleMap.h"
#include "common/win32_ntddk.h"
//---------------------------------------------------------------------------
// Variables
//---------------------------------------------------------------------------
CBoxes *CBoxes::m_instance = NULL;
CString CBoxes::m_DefaultBox(L"DefaultBox");
static const CString _BoxExpandedView(L"BoxExpandedView");
//---------------------------------------------------------------------------
// Constructor
//---------------------------------------------------------------------------
CBoxes::CBoxes()
{
// _nullBox = new CBox(L"");
ReloadBoxes();
}
//---------------------------------------------------------------------------
// Destructor
//---------------------------------------------------------------------------
CBoxes::~CBoxes()
{
Clear();
// delete _nullBox;
}
//---------------------------------------------------------------------------
// GetInstance
//---------------------------------------------------------------------------
CBoxes &CBoxes::GetInstance()
{
if (! m_instance)
m_instance = new CBoxes();
return *m_instance;
}
//---------------------------------------------------------------------------
// ReloadBoxes
//---------------------------------------------------------------------------
void CBoxes::ReloadBoxes()
{
Clear();
WCHAR name[64];
int index = -1;
while (1) {
if (GetSize() == 0)
name[0] = L'\0';
else {
index = SbieApi_EnumBoxesEx(
index | CONF_GET_NO_TEMPLS, name, TRUE);
if (index == -1)
break;
LONG rc = SbieApi_IsBoxEnabled(name);
if (rc == STATUS_ACCOUNT_RESTRICTION)
m_AnyHiddenBoxes = true;
if (rc != STATUS_SUCCESS)
continue;
}
CBox *box = new CBox(name);
int index2;
for (index2 = 1; index2 < GetSize(); ++index2) {
const CBox &oldBox = GetBox(index2);
if (oldBox.GetName().CompareNoCase(name) > 0)
break;
}
if (index2 > GetSize())
Add((CObject *)box);
else
InsertAt(index2, (CObject *)box);
}
//
// if DefaultBox is missing, add it
//
bool doWriteExpandedView = false;
if (GetSize() == 1 &&
SbieApi_IsBoxEnabled(m_DefaultBox) ==
STATUS_OBJECT_NAME_NOT_FOUND) {
CBox *box = new CBox(m_DefaultBox);
Add((CObject *)box);
CBox::SetEnabled(box->GetName());
box->SetExpandedView(TRUE);
doWriteExpandedView = true;
}
ReadExpandedView();
if (doWriteExpandedView)
WriteExpandedView();
}
//---------------------------------------------------------------------------
// RefreshProcesses
//---------------------------------------------------------------------------
void CBoxes::RefreshProcesses()
{
CWindowTitleMap::GetInstance().Refresh();
for (int i = 0; i < GetSize(); ++i)
GetBox(i).GetBoxProc().RefreshProcesses();
}
//---------------------------------------------------------------------------
// Clear
//---------------------------------------------------------------------------
void CBoxes::Clear()
{
while (GetSize()) {
CBox *box = (CBox *)GetAt(0);
RemoveAt(0);
delete box;
}
m_AnyHiddenBoxes = false;
}
//---------------------------------------------------------------------------
// GetBox
//---------------------------------------------------------------------------
CBox &CBoxes::GetBox(int index) const
{
if (index < 0 || index > GetSize())
index = 0;
return *(CBox *)GetAt(index);
}
//---------------------------------------------------------------------------
// GetBox
//---------------------------------------------------------------------------
CBox &CBoxes::GetBox(const CString &name) const
{
for (int i = 0; i < GetSize(); ++i) {
CBox &box = GetBox(i);
if (box.GetName().CompareNoCase(name) == 0)
return box;
}
return GetBox(0);
}
//---------------------------------------------------------------------------
// GetBoxByProcessId
//---------------------------------------------------------------------------
CBox &CBoxes::GetBoxByProcessId(ULONG pid) const
{
for (int i = 0; i < GetSize(); ++i) {
CBox &box = GetBox(i);
if (box.GetBoxProc().GetIndexForProcessId(pid) != -1)
return box;
}
return GetBox(0);
}
//---------------------------------------------------------------------------
// GetBoxIndex
//---------------------------------------------------------------------------
int CBoxes::GetBoxIndex(const CString &name) const
{
for (int i = 0; i < GetSize(); ++i) {
CBox &box = GetBox(i);
if (box.GetName().CompareNoCase(name) == 0)
return i;
}
return 0;
}
//---------------------------------------------------------------------------
// AnyActivity
//---------------------------------------------------------------------------
BOOL CBoxes::AnyActivity() const
{
for (int i = 1; i < GetSize(); ++i) {
if (GetBox(i).GetBoxProc().GetProcessCount())
return TRUE;
}
return FALSE;
}
//---------------------------------------------------------------------------
// KillAll
//---------------------------------------------------------------------------
void CBoxes::KillAll() const
{
for (int i = 1; i < GetSize(); ++i)
SbieDll_KillAll(-1, GetBox(i).GetName());
}
//---------------------------------------------------------------------------
// AnyHiddenBoxes
//---------------------------------------------------------------------------
bool CBoxes::AnyHiddenBoxes() const
{
return m_AnyHiddenBoxes;
}
//---------------------------------------------------------------------------
// GetHiddenBoxes
//---------------------------------------------------------------------------
void CBoxes::GetHiddenBoxes(CStringList &list) const
{
while (! list.IsEmpty())
list.RemoveHead();
WCHAR name[64];
int index = -1;
while (1) {
index = SbieApi_EnumBoxesEx(index, name, TRUE);
if (index == -1)
break;
LONG rc = SbieApi_IsBoxEnabled(name);
if (rc == STATUS_ACCOUNT_RESTRICTION)
list.AddTail(name);
}
}
//---------------------------------------------------------------------------
// ReadExpandedView
//---------------------------------------------------------------------------
void CBoxes::ReadExpandedView()
{
CUserSettings &ini = CUserSettings::GetInstance();
//
// read old BoxExpandedView_boxname settings
//
for (int i = 0; i < GetSize(); ++i) {
CBox &box = GetBox(i);
CString boxname = box.GetName();
if (! boxname.IsEmpty()) {
CString setting(_BoxExpandedView);
setting += L"_";
setting += boxname;
BOOL value;
ini.GetBool(setting, value, FALSE);
if (value)
box.SetExpandedView(TRUE);
}
}
//
// read new setting BoxExpandedView=boxname1,boxname2
//
CStringList list;
ini.GetTextCsv(_BoxExpandedView, list);
while (! list.IsEmpty()) {
CString boxname = list.RemoveHead();
if (! boxname.IsEmpty()) {
CBox &box = GetBox(boxname);
if (! box.GetName().IsEmpty())
box.SetExpandedView(TRUE);
}
}
}
//---------------------------------------------------------------------------
// WriteExpandedView
//---------------------------------------------------------------------------
BOOL CBoxes::WriteExpandedView()
{
CUserSettings &ini = CUserSettings::GetInstance();
//
// write new setting BoxExpandedView=boxname1,boxname2
//
CStringList list;
for (int i = 0; i < GetSize(); ++i) {
CBox &box = GetBox(i);
CString boxname = box.GetName();
if (! boxname.IsEmpty()) {
if (box.IsExpandedView())
list.AddTail(boxname);
}
}
BOOL ok = ini.SetTextCsv(_BoxExpandedView, list);
//
// delete old BoxExpandedView_boxname settings
//
if (ok) {
CString setting(_BoxExpandedView);
setting += L"_";
int len = setting.GetLength();
CStringList names;
ini.GetSettingsNames(names);
while (! names.IsEmpty()) {
CString name = names.RemoveHead();
if (name.GetLength() >= len &&
name.Left(len).CompareNoCase(setting) == 0) {
ini.SetText(name, CString());
}
}
}
return ok;
}

View File

@ -0,0 +1,69 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Boxes
//---------------------------------------------------------------------------
#ifndef _MY_BOXES_H
#define _MY_BOXES_H
#include "Box.h"
class CBoxes : public CObArray
{
static CBoxes *m_instance;
CBoxes();
void Clear();
bool m_AnyHiddenBoxes;
public:
static CString m_DefaultBox;
~CBoxes();
static CBoxes &GetInstance();
void ReloadBoxes();
void RefreshProcesses();
CBox &GetBox(int index) const;
CBox &GetBox(const CString &name) const;
CBox &GetBoxByProcessId(ULONG pid) const;
int GetBoxIndex(const CString &name) const;
BOOL AnyActivity() const;
void KillAll() const;
bool AnyHiddenBoxes() const;
void GetHiddenBoxes(CStringList &list) const;
void ReadExpandedView();
BOOL WriteExpandedView();
};
#endif // _MY_BOXES_H

View File

@ -0,0 +1,384 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="SbieDebug|Win32">
<Configuration>SbieDebug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="SbieDebug|x64">
<Configuration>SbieDebug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="SbieRelease|Win32">
<Configuration>SbieRelease</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="SbieRelease|x64">
<Configuration>SbieRelease</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{D16E291A-1F8A-4B19-AE07-0AF8CB7CCBD0}</ProjectGuid>
<RootNamespace>Control</RootNamespace>
<ProjectName>SbieControl</ProjectName>
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<UseOfMfc>Static</UseOfMfc>
<UseOfAtl>false</UseOfAtl>
<WholeProgramOptimization>false</WholeProgramOptimization>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>Unicode</CharacterSet>
<UseOfMfc>Static</UseOfMfc>
<UseOfAtl>false</UseOfAtl>
<WholeProgramOptimization>false</WholeProgramOptimization>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>false</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<UseOfMfc>Static</UseOfMfc>
<UseOfAtl>false</UseOfAtl>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>false</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
<UseOfMfc>Static</UseOfMfc>
<UseOfAtl>false</UseOfAtl>
<PlatformToolset>v140</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\Sandbox32.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\Sandbox64.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\Sandbox32.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\..\Sandbox64.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'">
<TargetName>SbieCtrl</TargetName>
<EmbedManifest>false</EmbedManifest>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'">
<TargetName>SbieCtrl</TargetName>
<EmbedManifest>false</EmbedManifest>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'">
<TargetName>SbieCtrl</TargetName>
<EmbedManifest>false</EmbedManifest>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'">
<TargetName>SbieCtrl</TargetName>
<EmbedManifest>false</EmbedManifest>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<FunctionLevelLinking>
</FunctionLevelLinking>
<ExceptionHandling>Sync</ExceptionHandling>
<IntrinsicFunctions>false</IntrinsicFunctions>
<MinimalRebuild />
<PrecompiledHeader>Use</PrecompiledHeader>
</ClCompile>
<Link>
<AdditionalDependencies>uafxcw.lib;common.lib;SbieDll.lib;ntdll.lib;psapi.lib;wininet.lib</AdditionalDependencies>
<EntryPointSymbol>
</EntryPointSymbol>
<IgnoreSpecificDefaultLibraries>uafxcw.lib</IgnoreSpecificDefaultLibraries>
<IgnoreAllDefaultLibraries>
</IgnoreAllDefaultLibraries>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'">
<ClCompile>
<Optimization>Disabled</Optimization>
<FunctionLevelLinking>
</FunctionLevelLinking>
<ExceptionHandling>Sync</ExceptionHandling>
<MinimalRebuild />
<PrecompiledHeader>Use</PrecompiledHeader>
</ClCompile>
<Link>
<AdditionalDependencies>uafxcw.lib;common.lib;SbieDll.lib;ntdll.lib;psapi.lib;wininet.lib</AdditionalDependencies>
<EntryPointSymbol>
</EntryPointSymbol>
<IgnoreSpecificDefaultLibraries>uafxcw.lib</IgnoreSpecificDefaultLibraries>
<IgnoreAllDefaultLibraries>
</IgnoreAllDefaultLibraries>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'">
<ClCompile>
<FunctionLevelLinking>
</FunctionLevelLinking>
<ExceptionHandling>Sync</ExceptionHandling>
<MinimalRebuild />
<PrecompiledHeader>Use</PrecompiledHeader>
</ClCompile>
<Link>
<AdditionalDependencies>uafxcw.lib;common.lib;SbieDll.lib;ntdll.lib;psapi.lib;wininet.lib</AdditionalDependencies>
<EntryPointSymbol>
</EntryPointSymbol>
<IgnoreSpecificDefaultLibraries>uafxcw.lib</IgnoreSpecificDefaultLibraries>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'">
<ClCompile>
<FunctionLevelLinking>
</FunctionLevelLinking>
<ExceptionHandling>Sync</ExceptionHandling>
<MinimalRebuild />
<PrecompiledHeader>Use</PrecompiledHeader>
</ClCompile>
<Link>
<AdditionalDependencies>uafxcw.lib;common.lib;SbieDll.lib;ntdll.lib;psapi.lib;wininet.lib</AdditionalDependencies>
<EntryPointSymbol>
</EntryPointSymbol>
<IgnoreSpecificDefaultLibraries>uafxcw.lib</IgnoreSpecificDefaultLibraries>
<IgnoreAllDefaultLibraries>
</IgnoreAllDefaultLibraries>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="..\common\BoxOrder.c">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="..\common\FontStore.cpp" />
<ClCompile Include="..\common\Layout.cpp" />
<ClCompile Include="..\common\MyGdi.c">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="..\common\MyMsg.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="..\common\RunBrowser.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="..\common\RunStartExe.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="AboutDialog.cpp" />
<ClCompile Include="AlertDialog.cpp" />
<ClCompile Include="AnimatedBitmap.cpp" />
<ClCompile Include="AppPage.cpp" />
<ClCompile Include="AutoPlay.cpp" />
<ClCompile Include="BaseDialog.cpp" />
<ClCompile Include="BorderGuard.cpp" />
<ClCompile Include="Box.cpp" />
<ClCompile Include="Boxes.cpp" />
<ClCompile Include="BoxFile.cpp" />
<ClCompile Include="BoxPage.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="BoxProc.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="CreateDialog.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="DeleteDialog.cpp" />
<ClCompile Include="DisableForceDialog.cpp" />
<ClCompile Include="FileListCtrl.cpp" />
<ClCompile Include="FinderDialog.cpp" />
<ClCompile Include="FindTool.c">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="FlashingButton.cpp" />
<ClCompile Include="GettingStartedWizard.cpp" />
<ClCompile Include="InitWait.cpp" />
<ClCompile Include="LockConfigDialog.cpp" />
<ClCompile Include="MenuXP.cpp" />
<ClCompile Include="MenuXP_Draw.cpp" />
<ClCompile Include="MessageDialog.cpp" />
<ClCompile Include="MonitorDialog.cpp" />
<ClCompile Include="MyApp.cpp" />
<ClCompile Include="MyFrame.cpp" />
<ClCompile Include="MyListCtrl.cpp" />
<ClCompile Include="MyWizard.cpp" />
<ClCompile Include="ProcListCtrl.cpp" />
<ClCompile Include="ProcSettingsDialog.cpp" />
<ClCompile Include="ProgramSelector.cpp" />
<ClCompile Include="PropPageFrame.cpp" />
<ClCompile Include="PropPageFrameDefault.cpp" />
<ClCompile Include="QuickRecover.cpp" />
<ClCompile Include="RevealDialog.cpp" />
<ClCompile Include="SbieIni.cpp" />
<ClCompile Include="SetFolderDialog.cpp" />
<ClCompile Include="SetLayoutDialog.cpp" />
<ClCompile Include="ShellDialog.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieRelease|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieDebug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieRelease|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='SbieDebug|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="TabbingComboBox.cpp" />
<ClCompile Include="TemplateListBox.cpp" />
<ClCompile Include="ThirdPartyDialog.cpp" />
<ClCompile Include="ToolTipButton.cpp" />
<ClCompile Include="TreePropSheet.cpp" />
<ClCompile Include="UserSettings.cpp" />
<ClCompile Include="ViewTemplateDialog.cpp" />
<ClCompile Include="WindowTitleMap.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\common\BoxOrder.h" />
<ClInclude Include="..\common\FontStore.h" />
<ClInclude Include="..\common\Layout.h" />
<ClInclude Include="..\common\MyGdi.h" />
<ClInclude Include="..\common\MyMsg.h" />
<ClInclude Include="..\common\RunBrowser.h" />
<ClInclude Include="AboutDialog.h" />
<ClInclude Include="AlertDialog.h" />
<ClInclude Include="AnimatedBitmap.h" />
<ClInclude Include="AppPage.h" />
<ClInclude Include="AutoPlay.h" />
<ClInclude Include="BaseDialog.h" />
<ClInclude Include="BorderGuard.h" />
<ClInclude Include="Box.h" />
<ClInclude Include="Boxes.h" />
<ClInclude Include="BoxFile.h" />
<ClInclude Include="BoxPage.h" />
<ClInclude Include="BoxProc.h" />
<ClInclude Include="CreateDialog.h" />
<ClInclude Include="DeleteDialog.h" />
<ClInclude Include="DisableForceDialog.h" />
<ClInclude Include="FileListCtrl.h" />
<ClInclude Include="FinderDialog.h" />
<ClInclude Include="FindTool.h" />
<ClInclude Include="FlashingButton.h" />
<ClInclude Include="GettingStartedWizard.h" />
<ClInclude Include="InitWait.h" />
<ClInclude Include="LockConfigDialog.h" />
<ClInclude Include="MenuXP.h" />
<ClInclude Include="MenuXP_Draw.h" />
<ClInclude Include="MenuXP_Tools.h" />
<ClInclude Include="MessageDialog.h" />
<ClInclude Include="MonitorDialog.h" />
<ClInclude Include="MyApp.h" />
<ClInclude Include="MyFrame.h" />
<ClInclude Include="MyListCtrl.h" />
<ClInclude Include="MyWizard.h" />
<ClInclude Include="ProcListCtrl.h" />
<ClInclude Include="ProcSettingsDialog.h" />
<ClInclude Include="ProgramSelector.h" />
<ClInclude Include="PropPageFrame.h" />
<ClInclude Include="PropPageFrameDefault.h" />
<ClInclude Include="QuickRecover.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="RevealDialog.h" />
<ClInclude Include="SbieIni.h" />
<ClInclude Include="SetFolderDialog.h" />
<ClInclude Include="SetLayoutDialog.h" />
<ClInclude Include="ShellDialog.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="TabbingComboBox.h" />
<ClInclude Include="TemplateListBox.h" />
<ClInclude Include="ThirdPartyDialog.h" />
<ClInclude Include="ToolTipButton.h" />
<ClInclude Include="TreePropSheet.h" />
<ClInclude Include="UserSettings.h" />
<ClInclude Include="ViewTemplateDialog.h" />
<ClInclude Include="WindowTitleMap.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="SbieControl.rc" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\..\sbieweb\web\img\FrontPage\FrontPageAnimation.gif" />
<None Include="..\res\background.png" />
<None Include="..\res\bigex.ico" />
<None Include="..\res\checkmark.png" />
<None Include="..\res\controlwin.ico" />
<None Include="..\res\cycle.png" />
<None Include="..\res\exclamation.png" />
<None Include="..\res\finder-empty.bmp" />
<None Include="..\res\finder-full.bmp" />
<None Include="..\res\finder.cur" />
<None Include="..\res\folder-minus.ico" />
<None Include="..\res\folder-plus.ico" />
<None Include="..\res\GettingStartedLegend.png" />
<None Include="..\res\initwait1.ico" />
<None Include="..\res\initwait2.ico" />
<None Include="..\res\MastheadLogo.jpg" />
<None Include="..\res\none.ico" />
<None Include="..\res\proc-empty.ico" />
<None Include="..\res\proc-full-minus.ico" />
<None Include="..\res\proc-full-plus.ico" />
<None Include="..\res\questionmark.png" />
<None Include="..\res\sandbox-delete.ico" />
<None Include="..\res\sandbox-empty-dfp.ico" />
<None Include="..\res\sandbox-empty.ico" />
<None Include="..\res\sandbox-full-dfp.ico" />
<None Include="..\res\sandbox-full.ico" />
<None Include="SbieControl.rc2" />
</ItemGroup>
<ItemGroup>
<Manifest Include="..\res\xptheme.manifest" />
</ItemGroup>
<ItemGroup>
<Image Include="..\res\FrontPageAnimation.gif" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
<ProjectExtensions>
<VisualStudio>
<UserProperties RESOURCE_FILE="SbieControl.rc" />
</VisualStudio>
</ProjectExtensions>
</Project>

View File

@ -0,0 +1,221 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Create Sandbox Dialog Box
//---------------------------------------------------------------------------
#include "MyApp.h"
#include "CreateDialog.h"
#include "Boxes.h"
#include "SbieIni.h"
#include "common/win32_ntddk.h"
//---------------------------------------------------------------------------
// Message Map
//---------------------------------------------------------------------------
BEGIN_MESSAGE_MAP(CCreateDialog, CBaseDialog)
ON_CONTROL(EN_CHANGE, ID_CREATE_NAME, OnNameChange)
END_MESSAGE_MAP()
//---------------------------------------------------------------------------
// Constructor
//---------------------------------------------------------------------------
CCreateDialog::CCreateDialog(CWnd *pParentWnd, const CString origName)
: CBaseDialog(pParentWnd, L"CREATE_DIALOG")
{
//
// display dialog
//
if (origName.IsEmpty()) {
m_title_id = MSG_3665;
m_explain_id = MSG_3666;
} else {
m_name = origName;
m_title_id = MSG_3476;
m_explain_id = MSG_3528;
}
DoModal();
}
//---------------------------------------------------------------------------
// Destructor
//---------------------------------------------------------------------------
CCreateDialog::~CCreateDialog()
{
}
//---------------------------------------------------------------------------
// OnInitDialog
//---------------------------------------------------------------------------
BOOL CCreateDialog::OnInitDialog()
{
CString text = CMyMsg(m_title_id);
text.Remove(L'&');
SetWindowText(text);
GetDlgItem(ID_CREATE_EXPLAIN)->SetWindowText(CMyMsg(m_explain_id));
GetDlgItem(IDOK)->SetWindowText(CMyMsg(MSG_3001));
GetDlgItem(IDCANCEL)->SetWindowText(CMyMsg(MSG_3002));
if (m_name.IsEmpty()) {
GetDlgItem(ID_CREATE_COPY_TEXT)->SetWindowText(CMyMsg(MSG_3669));
MakeLTR(ID_CREATE_NAME);
MakeLTR(ID_CREATE_COPY_COMBO);
CComboBox *pCombo = (CComboBox *)GetDlgItem(ID_CREATE_COPY_COMBO);
pCombo->AddString(CMyMsg(MSG_3769));
CBoxes &boxes = CBoxes::GetInstance();
for (int i = 1; i < boxes.GetSize(); ++i)
pCombo->AddString(boxes.GetBox(i).GetName());
pCombo->SetCurSel(0);
} else {
GetDlgItem(ID_CREATE_COPY_TEXT)->ShowWindow(SW_HIDE);
GetDlgItem(ID_CREATE_COPY_COMBO)->ShowWindow(SW_HIDE);
}
return TRUE;
}
//---------------------------------------------------------------------------
// OnNameChange
//---------------------------------------------------------------------------
void CCreateDialog::OnNameChange()
{
if (m_hide) {
GetDlgItem(ID_CREATE_ERROR)->ShowWindow(SW_HIDE);
m_hide = FALSE;
}
}
//---------------------------------------------------------------------------
// OnOK
//---------------------------------------------------------------------------
void CCreateDialog::OnOK()
{
CWnd *edit = GetDlgItem(ID_CREATE_NAME);
CString name;
edit->GetWindowText(name);
//
// make sure name is valid and unique
//
ULONG errmsg = 0;
int i = 0;
int len = name.GetLength();
if (len <= 32) {
for (; i < len; ++i) {
if (name[i] >= L'0' && name[i] <= L'9')
continue;
if (name[i] >= L'A' && name[i] <= L'Z')
continue;
if (name[i] >= L'a' && name[i] <= L'z')
continue;
if (name[i] == L'_')
continue;
break;
}
}
if (i == 0 || i != len)
errmsg = MSG_3667;
else {
LONG rc = SbieApi_IsBoxEnabled(name);
if (rc == STATUS_OBJECT_TYPE_MISMATCH)
errmsg = MSG_3667;
else if (rc == STATUS_ACCOUNT_RESTRICTION)
errmsg = MSG_4665;
else if (rc != STATUS_OBJECT_NAME_NOT_FOUND)
errmsg = MSG_3668;
}
if (errmsg) {
GetDlgItem(ID_CREATE_ERROR)->SetWindowText(CMyMsg(errmsg));
GetDlgItem(ID_CREATE_ERROR)->ShowWindow(SW_SHOW);
edit->SetFocus();
m_hide = TRUE;
return;
}
//
// finish
//
m_name = name;
CComboBox *pCombo = (CComboBox *)GetDlgItem(ID_CREATE_COPY_COMBO);
i = pCombo->GetCurSel();
if (i != 0 && i != CB_ERR)
pCombo->GetLBText(i, m_oldname);
EndDialog(0);
}
//---------------------------------------------------------------------------
// GetName
//---------------------------------------------------------------------------
CString CCreateDialog::GetName() const
{
return m_name;
}
//---------------------------------------------------------------------------
// GetOldName
//---------------------------------------------------------------------------
CString CCreateDialog::GetOldName() const
{
return m_oldname;
}

View File

@ -0,0 +1,53 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Create Sandbox Dialog Box
//---------------------------------------------------------------------------
#ifndef _MY_CREATEDIALOG_H
#define _MY_CREATEDIALOG_H
class CCreateDialog : public CBaseDialog
{
DECLARE_MESSAGE_MAP()
BOOL m_hide;
ULONG m_title_id;
ULONG m_explain_id;
CString m_name;
CString m_oldname;
virtual BOOL OnInitDialog();
afx_msg void OnNameChange();
virtual void OnOK();
public:
CString GetName() const;
CString GetOldName() const;
CCreateDialog(CWnd *pParentWnd, const CString origName = CString());
~CCreateDialog();
};
#endif // _MY_CREATEDIALOG_H

View File

@ -0,0 +1,557 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Delete Sandbox Dialog Box
//---------------------------------------------------------------------------
#include "stdafx.h"
#include "MyApp.h"
#include "DeleteDialog.h"
#include "Boxes.h"
#include "UserSettings.h"
#include "apps/common/MyGdi.h"
//---------------------------------------------------------------------------
// Defines
//---------------------------------------------------------------------------
#define ID_TIMER 1002
//---------------------------------------------------------------------------
// Variables
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// Message Map
//---------------------------------------------------------------------------
BEGIN_MESSAGE_MAP(CDeleteDialog, CBaseDialog)
ON_WM_TIMER()
ON_COMMAND(ID_RECOVER_SAME, OnCmdRecoverSameAny)
ON_COMMAND(ID_RECOVER_ANY, OnCmdRecoverSameAny)
ON_COMMAND(ID_RECOVER_ADD, OnCmdAddFolder)
ON_COMMAND(ID_RECOVER_SELECT_ALL, OnSelectAll)
ON_WM_CONTEXTMENU()
END_MESSAGE_MAP()
//---------------------------------------------------------------------------
// Constructor
//---------------------------------------------------------------------------
CDeleteDialog::CDeleteDialog(
CWnd *pParentWnd, const WCHAR *BoxName,
BOOL WithDelete, BOOL AutoDelete,
BOOL *DeleteSpawned)
: CBaseDialog(pParentWnd, L"DELETE_DIALOG")
{
m_WithDelete = WithDelete;
m_AutoDelete = AutoDelete;
m_filelist.SetBoxNameForDialogMode(BoxName);
//
//
//
m_empty = TRUE;
m_files = 0;
m_folders = 0;
m_size = 0;
m_spawned = FALSE;
*DeleteSpawned = FALSE;
CBox &box = CBoxes::GetInstance().GetBox(BoxName);
CBoxFile &boxfile = box.GetBoxFile();
if (m_WithDelete) {
if (box.GetNeverDelete()) {
CMyMsg msg(MSG_3051, BoxName);
CMyApp::MsgBox(pParentWnd, msg, MB_OK);
return;
}
boxfile.RebuildSkeletonTree();
boxfile.ChangeFolder(L"\\");
POSITION pos = boxfile.GetFolderHeadPosition();
BOOL expanded;
const WCHAR *folder_name = boxfile.GetNextFolder(pos, expanded);
folder_name = boxfile.GetNextFolder(pos, expanded);
m_stack.AddHead(CString(L"\\") + folder_name);
}
//
// display dialog
//
DoModal();
//
// if empty box, display message
//
if (m_WithDelete && m_empty && ! m_AutoDelete) {
CMyApp::MsgBox(pParentWnd, MSG_3730, MB_OK);
}
*DeleteSpawned = m_spawned;
}
//---------------------------------------------------------------------------
// Destructor
//---------------------------------------------------------------------------
CDeleteDialog::~CDeleteDialog()
{
}
//---------------------------------------------------------------------------
// OnInitDialog
//---------------------------------------------------------------------------
BOOL CDeleteDialog::OnInitDialog()
{
//
// set title according to dialog mode
//
CString title = CMyMsg(MSG_3711);
if (m_WithDelete)
title = title.Mid(0, title.Find('|'));
else
title = title.Mid(title.Find('|') + 1);
if (CMyApp::m_LayoutRTL)
title = m_filelist.GetBoxNameForDialogMode() + L" - " + title;
title += L" - " + m_filelist.GetBoxNameForDialogMode();
SetWindowText(title);
//
// set dialog text
//
GetDlgItem(ID_DELETE_EXPLAIN_1)->SetWindowText(CMyMsg(MSG_3712));
GetDlgItem(ID_DELETE_EXPLAIN_2)->SetWindowText(CMyMsg(MSG_3713));
GetDlgItem(ID_RECOVER_SAME)->SetWindowText(CMyMsg(MSG_3720));
GetDlgItem(ID_RECOVER_ANY)->SetWindowText(CMyMsg(MSG_3721));
GetDlgItem(ID_RECOVER_ADD)->SetWindowText(CMyMsg(MSG_3358));
GetDlgItem(IDOK)->SetWindowText(CMyMsg(MSG_3714));
GetDlgItem(IDCANCEL)->SetWindowText(CMyMsg(MSG_3004));
GetDlgItem(IDCLOSE)->SetWindowText(CMyMsg(MSG_3004));
//
//
//
CWnd *pCtl = GetDlgItem(ID_RECOVER_TREE);
CRect rc;
pCtl->GetWindowRect(&rc);
ScreenToClient(&rc);
m_filelist.Create(this);
m_filelist.SetWindowPos(NULL, rc.left, rc.top, rc.Width(), rc.Height(),
SWP_NOZORDER | SWP_NOOWNERZORDER);
m_filelist.ShowWindow(SW_SHOW);
m_filelist.RefreshContent();
m_filelist.SetFocus();
//
// prepare the select all button
//
static HBITMAP checkmark_bitmap = NULL;
if (! checkmark_bitmap)
checkmark_bitmap = MyGdi_CreateFromResource(L"BLUE_CHECKMARK");
CButton *pButton = (CButton *)GetDlgItem(ID_RECOVER_SELECT_ALL);
pButton->ModifyStyle(0, BS_BITMAP | BS_CENTER);
pButton->SetBitmap(checkmark_bitmap);
rc.top += 2;
rc.bottom = rc.top + GetSystemMetrics(SM_CYVTHUMB) + 10;
if (! CMyApp::m_LayoutRTL) {
rc.right -= GetSystemMetrics(SM_CXHTHUMB) + 5;
rc.left = rc.right - 25;
} else {
rc.left += GetSystemMetrics(SM_CXHTHUMB) + 5;
rc.right = rc.left + 25;
pButton->ModifyStyleEx(WS_EX_LAYOUTRTL, 0);
}
pButton->SetWindowPos(&wndTop,
rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top,
SWP_SHOWWINDOW);
if (! SelectAllButton.m_hWnd) {
CString tip = CMyMsg(MSG_3360);
tip.Remove(L'&');
SelectAllButton.Init(pButton->m_hWnd, tip);
}
if (! m_filelist.AnyQuickRecoverFiles())
pButton->ShowWindow(SW_HIDE);
//
// hide buttons accoording to dialog mode
//
pCtl = GetDlgItem(IDCLOSE);
if (m_WithDelete) {
pCtl->ShowWindow(SW_HIDE);
} else {
pCtl->SetDlgCtrlID(IDCANCEL);
//SetWindowLongPtr(pCtl->m_hWnd, GWLP_ID, IDCANCEL);
pCtl = GetDlgItem(ID_RECOVER_GROUPBOX);
pCtl->GetClientRect(&rc);
int group_height = rc.Height();
pCtl->ShowWindow(SW_HIDE);
GetWindowRect(&rc);
rc.bottom -= group_height;
SetWindowPos(
NULL, 0, 0, rc.Width(), rc.Height(),
SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
}
//
// start timer (to count contents) if manual delete mode
//
if (m_WithDelete) {
OnTimer(ID_TIMER);
if (m_empty) {
EndDialog(0);
return FALSE;
}
if (m_AutoDelete) {
if (! m_filelist.AnyQuickRecoverFiles()) {
OnOK();
return FALSE;
}
m_DeleteButton.Init(this, IDOK);
FlashTitle();
}
SetTimer(ID_TIMER, 10, NULL);
}
AddMinimizeButton();
return FALSE;
}
//---------------------------------------------------------------------------
// OnTimer
//---------------------------------------------------------------------------
void CDeleteDialog::OnTimer(UINT_PTR nIDEvent)
{
if (nIDEvent != ID_TIMER)
return;
if (m_stack.IsEmpty())
return;
const CString &BoxName = m_filelist.GetBoxNameForDialogMode();
CBox &box = CBoxes::GetInstance().GetBox(BoxName);
CBoxFile &boxfile = box.GetBoxFile();
CString path = m_stack.RemoveHead();
boxfile.SetIncludeDeleted(TRUE);
if (boxfile.ChangeFolder(path, TRUE) == -1) {
boxfile.SetIncludeDeleted(FALSE);
return;
}
if (boxfile.GetFolderNumChildren() <= 0) {
boxfile.SetIncludeDeleted(FALSE);
return;
}
m_empty = FALSE;
if (boxfile.IsPhysicalFolder())
++m_folders;
POSITION pos = boxfile.GetFolderHeadPosition();
while (pos) {
BOOL expanded;
const WCHAR *folder_name = boxfile.GetNextFolder(pos, expanded);
if (! folder_name)
break;
m_stack.AddHead(path + L"\\" + folder_name);
}
pos = boxfile.GetFolderHeadPosition();
while (pos) {
ULONG64 size;
const WCHAR *file_name = boxfile.GetNextFile(pos, size);
if (! file_name)
break;
m_size += size;
++m_files;
}
boxfile.SetIncludeDeleted(FALSE);
//
// stringfy number of files. note that if we have any files at all,
// we will assume that the box also contains two RegHive files
//
CString strFiles;
strFiles.Format(L"%d", m_files);
CString strFolders;
strFolders.Format(L"%d", m_folders);
const WCHAR *units = L"";
ULONG64 bytes64 = m_size;
if (bytes64 >= 1024) {
bytes64 /= 1024;
units = L"KB";
if (bytes64 >= 1024) {
bytes64 /= 1024;
units = L"MB";
if (bytes64 >= 1024) {
bytes64 /= 1024;
units = L"GB";
}
}
}
CString strBytes;
if (CMyApp::m_LayoutRTL) {
const ULONG U_LRO = 0x202D; // Start of left-to-right override
const ULONG U_PDF = 0x202C; // Pop directional formatting
strBytes.Format(L"%c%d %s%c", U_LRO, (ULONG)bytes64, units, U_PDF);
} else
strBytes.Format(L"%d %s", (ULONG)bytes64, units);
CMyMsg str(MSG_3722, strFiles, strFolders, strBytes);
SetDlgItemText(ID_DELETE_SIZE, str);
}
//---------------------------------------------------------------------------
// OnOK
//---------------------------------------------------------------------------
void CDeleteDialog::OnOK()
{
if (! m_WithDelete)
return;
while (! m_stack.IsEmpty())
m_stack.RemoveHead();
const CString &BoxName = m_filelist.GetBoxNameForDialogMode();
CBox &box = CBoxes::GetInstance().GetBox(BoxName);
CBoxProc &boxproc = box.GetBoxProc();
CWaitCursor waitcursor;
SbieDll_KillAll(-1, BoxName);
int i = 0;
for (i = 0; i < 20; ++i) {
boxproc.RefreshProcesses();
if (boxproc.GetProcessCount() == 0) {
Sleep(500);
break;
}
Sleep(250);
}
if (i == 20) {
CMyApp::MsgBox(this, MSG_3731, MB_OK);
} else {
WCHAR cmd[64];
wcscpy(cmd, L"delete_sandbox");
//if (m_AutoDelete)
//wcscat(cmd, L"_silent");
CMyApp::RunStartExe(cmd, BoxName, TRUE);
box.GetBoxFile().RebuildSkeletonTree();
m_spawned = TRUE;
}
EndDialog(0);
}
//---------------------------------------------------------------------------
// OnCmdRecoverSame
//---------------------------------------------------------------------------
void CDeleteDialog::OnCmdRecoverSameAny()
{
int cmd = 0;
const MSG *msg = GetCurrentMessage();
if (LOWORD(msg->wParam) == ID_RECOVER_SAME)
cmd = ID_FILE_RECOVER_SAME;
else if (LOWORD(msg->wParam) == ID_RECOVER_ANY)
cmd = ID_FILE_RECOVER_ANY;
if (cmd)
m_filelist.PostMessage(WM_COMMAND, cmd, 0);
}
//---------------------------------------------------------------------------
// OnCmdAddFolder
//---------------------------------------------------------------------------
void CDeleteDialog::OnCmdAddFolder()
{
WCHAR path[MAX_PATH + 32];
CMyMsg title(MSG_3726);
BROWSEINFO bi;
memzero(&bi, sizeof(BROWSEINFO));
bi.hwndOwner = m_hWnd;
bi.pszDisplayName = path;
bi.lpszTitle = title;
bi.ulFlags = BIF_UAHINT | BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
if (pidl) {
BOOL ok = SHGetPathFromIDList(pidl, path);
CoTaskMemFree(pidl);
if (ok) {
//
// add the new folder
//
const CString &BoxName = m_filelist.GetBoxNameForDialogMode();
CBox &box = CBoxes::GetInstance().GetBox(BoxName);
CBoxFile &boxfile = box.GetBoxFile();
ok = box.AddOrRemoveQuickRecoveryFolder(path, TRUE);
if (! ok)
return;
m_filelist.RefreshContent();
if (m_filelist.AnyQuickRecoverFiles())
GetDlgItem(ID_RECOVER_SELECT_ALL)->ShowWindow(SW_SHOW);
//
// check if the folder is empty
//
BOOL empty = TRUE;
boxfile.ChangeFolder(L"\\");
POSITION pos = boxfile.GetFolderHeadPosition();
BOOL expanded;
const WCHAR *folder_name = boxfile.GetNextFolder(pos, expanded);
if (boxfile.ChangeFolder(folder_name) != -1) {
pos = boxfile.GetFolderHeadPosition();
while (pos) {
folder_name = boxfile.GetNextFolder(pos, expanded);
if (boxfile.ChangeFolder(folder_name) != -1) {
CString TruePath, CopyPath;
boxfile.GetFolderPaths(TruePath, CopyPath);
if (TruePath == path) {
empty = (boxfile.GetFolderNumChildren() == 0);
break;
}
boxfile.ChangeFolder(L"..");
}
}
}
if (empty)
CMyApp::MsgBox(this, MSG_3727, MB_OK);
}
}
}
//---------------------------------------------------------------------------
// OnSelectAll
//---------------------------------------------------------------------------
void CDeleteDialog::OnSelectAll()
{
m_filelist.SelectAllItems(true);
m_filelist.SetFocus();
}
//---------------------------------------------------------------------------
// OnContextMenu
//---------------------------------------------------------------------------
void CDeleteDialog::OnContextMenu(CWnd *pWnd, CPoint pt)
{
if (pWnd == &m_filelist)
m_filelist.OnContextMenu(pWnd, pt);
}

View File

@ -0,0 +1,74 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Delete Sandbox Dialog Box
//---------------------------------------------------------------------------
#ifndef _MY_DELETEDIALOG_H
#define _MY_DELETEDIALOG_H
#include "FileListCtrl.h"
#include "FlashingButton.h"
#include "ToolTipButton.h"
class CDeleteDialog : public CBaseDialog
{
DECLARE_MESSAGE_MAP()
BOOL m_WithDelete;
BOOL m_AutoDelete;
CFileListCtrl m_filelist;
CFlashingButton m_DeleteButton;
CToolTipButton SelectAllButton;
BOOL m_empty;
int m_files;
int m_folders;
ULONG64 m_size;
CStringList m_stack;
BOOL m_spawned;
virtual BOOL OnInitDialog();
afx_msg void OnTimer(UINT_PTR nIDEvent);
virtual void OnOK();
afx_msg void OnCmdAddFolder();
afx_msg void OnCmdRecoverSameAny();
afx_msg void OnSelectAll();
afx_msg void OnContextMenu(CWnd *pWnd, CPoint pt);
public:
CDeleteDialog(CWnd *pParentWnd, const WCHAR *BoxName,
BOOL WithDelete, BOOL AutoDelete,
BOOL *DeleteSpawned);
~CDeleteDialog();
};
#endif // _MY_DELETEDIALOG_H

View File

@ -0,0 +1,125 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Temporarily Disable Forced Programs Dialog Box
//---------------------------------------------------------------------------
#include "stdafx.h"
#include "MyApp.h"
#include "DisableForceDialog.h"
#include "Boxes.h"
#include "SbieIni.h"
//---------------------------------------------------------------------------
// Variables
//---------------------------------------------------------------------------
static const CString _ForceDisableSeconds(L"ForceDisableSeconds");
//---------------------------------------------------------------------------
// Constructor
//---------------------------------------------------------------------------
CDisableForceDialog::CDisableForceDialog(CWnd *pParentWnd)
: CBaseDialog(pParentWnd, L"DISABLE_FORCE_DIALOG")
{
m_endedok = FALSE;
DoModal();
}
//---------------------------------------------------------------------------
// Destructor
//---------------------------------------------------------------------------
CDisableForceDialog::~CDisableForceDialog()
{
}
//---------------------------------------------------------------------------
// OnInitDialog
//---------------------------------------------------------------------------
BOOL CDisableForceDialog::OnInitDialog()
{
SetWindowText(CMyMsg(MSG_3651));
GetDlgItem(ID_DISABLE_FORCE_LABEL_1)->SetWindowText(CMyMsg(MSG_3652));
GetDlgItem(ID_DISABLE_FORCE_LABEL_2)->SetWindowText(CMyMsg(MSG_3653));
GetDlgItem(ID_DISABLE_FORCE_LABEL_3)->SetWindowText(CMyMsg(MSG_3654));
GetDlgItem(ID_DISABLE_FORCE_LABEL_4)->SetWindowText(CMyMsg(MSG_3599));
GetDlgItem(IDOK)->SetWindowText(CMyMsg(MSG_3001));
GetDlgItem(IDCANCEL)->SetWindowText(CMyMsg(MSG_3002));
int seconds;
CSbieIni::GetInstance().GetNum(
_GlobalSettings, _ForceDisableSeconds, seconds, 10);
SetDlgItemInt(ID_DISABLE_FORCE_EDIT, seconds);
CSpinButtonCtrl *spin =
(CSpinButtonCtrl *)GetDlgItem(ID_DISABLE_FORCE_SPIN);
spin->SetRange(0, 29999);
return TRUE;
}
//---------------------------------------------------------------------------
// OnOK
//---------------------------------------------------------------------------
void CDisableForceDialog::OnOK()
{
int seconds = GetDlgItemInt(ID_DISABLE_FORCE_EDIT);
BOOL ok = CSbieIni::GetInstance().SetNum(
_GlobalSettings, _ForceDisableSeconds, seconds);
if (! ok) {
CSbieIni::GetInstance().GetNum(
_GlobalSettings, _ForceDisableSeconds, seconds, 10);
SetDlgItemInt(ID_DISABLE_FORCE_EDIT, seconds);
((CEdit *)GetDlgItem(ID_DISABLE_FORCE_EDIT))->SetSel(0, -1);
GetDlgItem(ID_DISABLE_FORCE_EDIT)->SetFocus();
return;
}
m_endedok = TRUE;
EndDialog(0);
}
//---------------------------------------------------------------------------
// EndedOk
//---------------------------------------------------------------------------
BOOL CDisableForceDialog::EndedOk() const
{
return m_endedok;
}

View File

@ -0,0 +1,46 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Temporarily Disable Forced Programs Dialog Box
//---------------------------------------------------------------------------
#ifndef _MY_DISABLEFORCEDIALOG_H
#define _MY_DISABLEFORCEDIALOG_H
class CDisableForceDialog : public CBaseDialog
{
//DECLARE_MESSAGE_MAP()
BOOL m_endedok;
virtual BOOL OnInitDialog();
virtual void OnOK();
public:
CDisableForceDialog(CWnd *pParentWnd);
~CDisableForceDialog();
BOOL EndedOk() const;
};
#endif // _MY_DISABLEFORCEDIALOG_H

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,124 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// File Tree Control
//---------------------------------------------------------------------------
#ifndef _MY_FILE_TREE_CTRL_H
#define _MY_FILE_TREE_CTRL_H
#include "MyListCtrl.h"
class CFileListCtrl : public CMyListCtrl
{
DECLARE_MESSAGE_MAP()
//
//
//
CString m_BoxName;
CString m_SaveBoxName;
CStringList m_CutPaths;
int m_anyQuickRecoverFiles;
int m_RefreshCounter;
bool m_DontClearCutMarks;
//
//
//
virtual afx_msg void OnSize(UINT nType, int cx, int cy);
void UpdateScrollBar();
virtual afx_msg void OnComboSelect();
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
afx_msg void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags);
void OnArrowKeyDown(UINT nChar);
void MyEnsureVisible(int index);
afx_msg void OnDestroyClipboard();
void RebuildCombo();
void RebuildFiles();
int InsertFolder(CBoxFile &boxfile, const CString &_boxpath,
int ListIndex, int ListIndent);
void InsertFile(const CString &VirtualPath,
const CString &FolderCopyPath, ULONG64 bytes64,
int ListIndex, int ListIndent);
void RemoveFolderItems(int ListIndex, int ListIndent);
void SetFocusByPath(CString SaveItemPath);
virtual afx_msg void OnRefreshPosted();
virtual afx_msg void OnClick(NMHDR *pNMHDR, LRESULT *pResult);
bool IsPhysicalItem(int ListIndex, bool *pIsFolder,
CString *pTruePath, CString *pCopyPath);
bool IsCutPath(const CString &CopyPath);
bool OnContextMenuMultiple(CMenu *pMenu, CPoint pt);
bool OnContextMenuSingle(int index, CMenu *pMenu, CPoint pt);
afx_msg void OnCmdRun();
afx_msg void OnCmdCreateShortcut();
afx_msg void OnCmdCut();
afx_msg void OnCmdRecoverFileOrFolder();
afx_msg void OnCmdAddOrRemoveFolder();
void AddItemsToRecoverRecursive(
CStringList &ItemsToRecover, const CString &RelativePath,
const CString &VirtualPath, const CString &CopyPath);
bool ShouldShowFileInQuickRecovery(
const WCHAR *file_name, ULONG64 bytes64,
const CString &FileCopyPath);
bool CompareSameFiles(const CString &CopyPath);
void InspectClipboard();
public:
void SetBoxNameForDialogMode(const WCHAR *BoxName);
const CString &GetBoxNameForDialogMode() const;
bool AnyQuickRecoverFiles() const;
BOOL Create(CWnd *pParentWnd);
virtual void RefreshContent();
virtual CBox &GetSelectedBox(CWnd *pWnd, CPoint pt) const;
virtual void GetSelectedItemPosition(CPoint &pt) const;
void OnContextMenu(CWnd *pWnd, CPoint pt);
void SelectAllItems(bool select);
};
#endif // _MY_FILE_TREE_CTRL_H

View File

@ -0,0 +1,581 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//
// WinSpy Finder Tool.
//
// Copyright (c) 2002 by J Brown
// Freeware
//
// This is a standalone file which implements
// a "Finder Tool" similar to that used in Spy++
//
// There are two functions you must use:
//
// 1. BOOL MakeFinderTool(HWND hwnd, WNDFINDPROC wfp)
//
// hwnd - handle to a STATIC control to base the tool around.
// MakeFinderTool converts this control to the correct
// style, adds the bitmaps and mouse support etc.
//
// wfn - Event callback function. Must not be zero.
//
// Return values:
// TRUE for success, FALSE for failure
//
//
// 2. UINT CALLBACK WndFindProc(HWND hwndTool, UINT uCode, HWND hwnd)
//
// This is a callback function that you supply when using
// MakeFinderTool. This callback can be executed for a number
// different events - described by uCode.
//
// hwndTool - handle to the finder tool
//
// hwnd - handle to the window which has been found.
//
// uCode - describes the event. Can be one of the following values.
//
// WFN_BEGIN : tool is about to become active.
// WFN_SELCHANGING : sent when tool moves from window-window.
// WFN_SELCHANGED : sent when final window is selected.
// WFN_CANCELLED : Tool cancelled. hwnd is not valid (0)
//
// Return values:
// Return value is only checked for WFN_BEGIN. Return 0 (zero)
// to continue, -1 to prevent tool from being used. Otherwise,
// return 0 (zero) for all other messages
//
#define STRICT
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include "FindTool.h"
#define INVERT_BORDER 3
HWND WindowFromPointEx(POINT pt, BOOL fShowHidden);
#if _MSC_VER == 1200 // Visual C++ 6.0
#define GetWindowLongPtr GetWindowLong
#define SetWindowLongPtr SetWindowLong
#define GWLP_USERDATA GWL_USERDATA
#define GWLP_WNDPROC GWL_WNDPROC
typedef LONG LONG_PTR;
#endif
static LONG lRefCount = 0;
static HCURSOR hOldCursor;
static HHOOK draghook = 0;
static HWND draghookhwnd = 0;
//
// Handle to the two dragger bitmaps
//
static HBITMAP hBitmapDrag1, hBitmapDrag2;
static HCURSOR hCursor;
//is the finder-tool being dragged??
static BOOL fDragging = FALSE;
// Old window procedure...?
static WNDPROC oldstaticproc;
static HWND hwndCurrent;
// show hidden windows
static BOOL fShowHidden = FALSE;
//
// Invert the specified window's border
//
void InvertWindow(HWND hwnd, BOOL fShowHidden)
{
RECT rect;
RECT rect2;
RECT rectc;
HDC hdc;
int x1,y1;
int border = INVERT_BORDER;
if(hwnd == 0)
return;
//window rectangle (screen coords)
GetWindowRect(hwnd, &rect);
//client rectangle (screen coords)
GetClientRect(hwnd, &rectc);
ClientToScreen(hwnd, (POINT *)&rectc.left);
ClientToScreen(hwnd, (POINT *)&rectc.right);
//MapWindowPoints(hwnd, 0, (POINT *)&rectc, 2);
x1 = rect.left;
y1 = rect.top;
OffsetRect(&rect, -x1, -y1);
OffsetRect(&rectc, -x1, -y1);
if(rect.bottom - border * 2 < 0)
border = 1;
if(rect.right - border * 2 < 0)
border = 1;
if(fShowHidden == TRUE)
hwnd = 0;
hdc = GetWindowDC(hwnd);
if(hdc == 0)
return;
//top edge
//border = rectc.top-rect.top;
SetRect(&rect2, 0,0,rect.right, border);
if(fShowHidden == TRUE) OffsetRect(&rect2, x1, y1);
InvertRect(hdc, &rect2);
//left edge
//border = rectc.left-rect.left;
SetRect(&rect2, 0,border,border, rect.bottom);
if(fShowHidden == TRUE) OffsetRect(&rect2, x1, y1);
InvertRect(hdc, &rect2);
//right edge
//border = rect.right-rectc.right;
SetRect(&rect2, border,rect.bottom-border,rect.right, rect.bottom);
if(fShowHidden == TRUE) OffsetRect(&rect2, x1, y1);
InvertRect(hdc, &rect2);
//bottom edge
//border = rect.bottom-rectc.bottom;
SetRect(&rect2, rect.right-border, border,rect.right, rect.bottom-border);
if(fShowHidden == TRUE) OffsetRect(&rect2, x1, y1);
InvertRect(hdc, &rect2);
ReleaseDC(hwnd, hdc);
}
void FlashWindowBorder(HWND hwnd, BOOL fShowHidden)
{
int i;
for(i = 0; i < 3 * 2; i++)
{
InvertWindow(hwnd, fShowHidden);
Sleep(100);
}
}
void LoadFinderResources()
{
hBitmapDrag1 = LoadBitmap(GetModuleHandle(0), L"FINDER_FULL");
hBitmapDrag2 = LoadBitmap(GetModuleHandle(0), L"FINDER_EMPTY");
hCursor = LoadCursor(GetModuleHandle(0), L"FINDER_CURSOR");
}
void FreeFinderResources()
{
DeleteObject(hBitmapDrag1);
DeleteObject(hBitmapDrag2);
DestroyCursor(hCursor);
}
WNDFINDPROC GetWndFindProc(HWND hwnd)
{
return (WNDFINDPROC)GetWindowLongPtr(hwnd, GWLP_USERDATA);
}
UINT FireWndFindNotify(HWND hwndTool, UINT uCode, HWND hwnd)
{
WNDFINDPROC wfp = GetWndFindProc(hwndTool);
if(wfp != 0)
return wfp(hwndTool, uCode, hwnd);
else
return 0;
}
LRESULT EndFindToolDrag(HWND hwnd, WPARAM wParam, LPARAM lParam)
{
HWND hwndParent;
hwndParent = GetParent(hwnd);
InvertWindow(hwndCurrent, fShowHidden);
ReleaseCapture();
SetCursor(hOldCursor);
// Remove keyboard hook. This is done even if the user presses ESC
UnhookWindowsHookEx(draghook);
fDragging = FALSE;
SendMessage(hwnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmapDrag1);
return 0;
}
// Keyboard hook for the Finder Tool.
// This hook just monitors the ESCAPE key
static LRESULT CALLBACK draghookproc(int code, WPARAM wParam, LPARAM lParam)
{
ULONG state = (ULONG)lParam;
static int count;
if(code < 0)
return CallNextHookEx(draghook, code, wParam, lParam);
switch(wParam)
{
case VK_ESCAPE:
if(!(state & 0x80000000))
{
//don't let the current window procedure process a VK_ESCAPE,
//because we want it to cancel the mouse capture
PostMessage(draghookhwnd, WM_CANCELMODE, 0, 0);
return -1;
}
break;
}
return CallNextHookEx(draghook, code, wParam, lParam);
}
LRESULT CALLBACK StaticProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HWND hwndParent;
switch(msg)
{
case WM_LBUTTONDBLCLK:
case WM_LBUTTONDOWN:
// Ask the callback function if we want to proceed
if(FireWndFindNotify(hwnd, WFN_BEGIN, 0) == -1)
{
return 0;
}
fDragging = TRUE;
SendMessage(hwnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmapDrag2);
hwndParent = GetParent(hwnd);
//else
{
hwndCurrent = hwnd;
InvertWindow(hwndCurrent, fShowHidden);
}
SetCapture(hwnd);
hOldCursor = SetCursor(hCursor);
// Install keyboard hook to trap ESCAPE key
// We could just set the focus to this window to receive
// normal keyboard messages - however, we don't want to
// steal focus from current window when we use the drag tool,
// so a hook is a stealthier way to monitor key presses
draghookhwnd = hwnd;
draghook = SetWindowsHookEx(WH_KEYBOARD, draghookproc, GetModuleHandle(0), 0);
// Current window has changed
FireWndFindNotify(hwnd, WFN_SELCHANGED, hwndCurrent);
return 0;
case WM_MOUSEMOVE:
if(fDragging == TRUE)
{
//MoveFindTool(hwnd, wParam, lParam);
POINT pt;
HWND hWndPoint;
pt.x = (short)LOWORD(lParam);
pt.y = (short)HIWORD(lParam);
ClientToScreen(hwnd, (POINT *)&pt);
hWndPoint = WindowFromPointEx(pt, fShowHidden);
if(hWndPoint == 0)
return 0;
if(hWndPoint != hwndCurrent)
{
InvertWindow(hwndCurrent, fShowHidden);
FireWndFindNotify(hwnd, WFN_SELCHANGED, hWndPoint);
InvertWindow(hWndPoint, fShowHidden);
hwndCurrent = hWndPoint;
}
}
return 0;
case WM_LBUTTONUP:
// Mouse has been release, so end the find-tool
if(fDragging == TRUE)
{
fDragging = FALSE;
EndFindToolDrag(hwnd, wParam, lParam);
FireWndFindNotify(hwnd, WFN_END, hwndCurrent);
}
return 0;
// Sent from the keyboard hook
case WM_CANCELMODE:
// User has pressed ESCAPE, so cancel the find-tool
if(fDragging == TRUE)
{
fDragging = FALSE;
EndFindToolDrag(hwnd, wParam, lParam);
FireWndFindNotify(hwnd, WFN_CANCELLED, 0);
}
return 0;
case WM_NCDESTROY:
// When the last finder tool has been destroyed, free
// up all the resources
if(InterlockedDecrement(&lRefCount) == 0)
{
FreeFinderResources();
}
break;
}
return CallWindowProc(oldstaticproc, hwnd, msg, wParam, lParam);
}
BOOL MakeFinderTool(HWND hwnd, WNDFINDPROC wfp)
{
DWORD dwStyle;
// If this is the first finder tool, then load
// the bitmap and mouse-cursor resources
if(InterlockedIncrement(&lRefCount) == 1)
{
LoadFinderResources();
}
// Apply styles to make this a picture control
dwStyle = GetWindowLong(hwnd, GWL_STYLE);
// Turn OFF styles we don't want
dwStyle &= ~(SS_RIGHT | SS_CENTER | SS_CENTERIMAGE);
dwStyle &= ~(SS_ICON | SS_SIMPLE | SS_LEFTNOWORDWRAP);
// Turn ON styles we must have
dwStyle |= SS_NOTIFY;
dwStyle |= SS_BITMAP;
// Now apply them..
SetWindowLong(hwnd, GWL_STYLE, dwStyle);
// Set the default bitmap
SendMessage(hwnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hBitmapDrag1);
// Set the callback for this control
SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)wfp);
// Subclass the static control
oldstaticproc = (WNDPROC)SetWindowLongPtr(hwnd, GWLP_WNDPROC, (LONG_PTR)StaticProc);
return TRUE;
}
//
// WindowFromPointEx.c
//
// Copyright (c) 2002 by J Brown
// Freeware
//
// HWND WindowFromPointEx(POINT pt)
//
// Provides a better implementation of WindowFromPoint.
// This function can return any window under the mouse,
// including controls nested inside group-boxes, nested
// dialogs etc.
//
#define STRICT
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include <tchar.h>
static HWND hwndGlobal;
static HWND hwndButton;
static BOOL g_fShowHidden;
static DWORD dwArea;
//
// Callback function used with FindBestChild
//
static BOOL CALLBACK FindBestChildProc(HWND hwnd, LPARAM lParam)
{
RECT rect;
DWORD a;
POINT pt;
pt.x = (short)LOWORD(lParam);
pt.y = (short)HIWORD(lParam);
GetWindowRect(hwnd, &rect);
// Is the mouse inside this child window?
if(PtInRect(&rect, pt))
{
// work out area of child window
a = (rect.right-rect.left) * (rect.bottom-rect.top);
// if this child window is smaller than the
// current "best", then choose this one
if(a < dwArea && (IsWindowVisible(hwnd) || g_fShowHidden == TRUE))
{
dwArea = a;
hwndGlobal = hwnd;
}
}
return TRUE;
}
//
// The problem:
//
// WindowFromPoint API is not very good. It cannot cope
// with odd window arrangements, i.e. a group-box in a dialog
// may contain a few check-boxes. These check-boxes are not
// children of the groupbox, but are at the same "level" in the
// window-hierachy. WindowFromPoint will just return the
// first available window it finds which encompasses the mouse
// (i.e. the group-box), but will NOT be able to detect the contents.
//
// Solution:
//
// We use WindowFromPoint to start us off, and then step back one
// level (i.e. from the parent of what WindowFromPoint returned).
//
// Once we have this window, we enumerate ALL children of this window
// ourselves, and find the one that best fits under the mouse -
// the smallest window that fits, in fact.
//
// I've tested this on alot of different apps, and it seems
// to work flawlessly - in fact, I havn't found a situation yet
// that this method doesn't work on.....we'll see!
//
// Inputs:
//
// hwndFound - window found with WindowFromPoint
// pt - coordinates of mouse, in screen coords
// (i.e. same coords used with WindowFromPoint)
//
static HWND FindBestChild(HWND hwndFound, POINT pt)
{
HWND hwnd;
DWORD dwStyle;
dwArea = -1; // Start off again
hwndGlobal = 0;
hwnd = GetParent(hwndFound);
dwStyle = GetWindowLong(hwndFound, GWL_STYLE);
// The original window might already be a top-level window,
// so we don't want to start at *it's* parent
if(hwnd == 0 || (dwStyle & WS_POPUP))
hwnd = hwndFound;
// Enumerate EVERY child window.
//
// Note to reader:
//
// You can get some real interesting effects if you set
// hwnd = GetDesktopWindow()
// fShowHidden = TRUE
// ...experiment!!
//
EnumChildWindows(hwnd, FindBestChildProc, MAKELPARAM(pt.x, pt.y));
if(hwndGlobal == 0)
hwndGlobal = hwnd;
return hwndGlobal;
}
//
// Find window under specified point (screen coordinates)
//
HWND WindowFromPointEx(POINT pt, BOOL fShowHidden)
{
HWND hWndPoint;
g_fShowHidden = fShowHidden;
//
// First of all find the parent window under the mouse
// We are working in SCREEN coordinates
//
hWndPoint = WindowFromPoint(pt);
if(hWndPoint == 0)
return 0;
// WindowFromPoint is not too accurate. There is quite likely
// another window under the mouse.
hWndPoint = FindBestChild(hWndPoint, pt);
//if we don't allow hidden windows, then return the parent
if(!g_fShowHidden)
{
while(hWndPoint && !IsWindowVisible(hWndPoint))
hWndPoint = GetParent(hWndPoint);
}
return hWndPoint;
}

View File

@ -0,0 +1,50 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
#ifndef FINDTOOL_INCLUDED
#define FINDTOOL_INCLUDED
#ifdef __cplusplus
extern "C" {
#endif
typedef UINT (CALLBACK * WNDFINDPROC) (HWND hwndTool, UINT uCode, HWND hwnd);
//
// uCode can be one of these values:
//
#define WFN_BEGIN 0 // tool is about to become active. hwnd(0)
#define WFN_SELCHANGED 1 // sent when tool moves from window-window.
#define WFN_END 2 // sent when final window has been selected.
#define WFN_CANCELLED 3 // Tool canceled. hwnd is not valid (0)
#define WFN_CTRL_DOWN 4 // <Control> key was pressed
#define WFN_CTRL_UP 5 // <Control> key was released
#define WFN_SHIFT_DOWN 6 // <Shift> key was pressed
#define WFN_SHIFT_UP 7 // <Shift> key was released
#define WFN_CAPTURE 8 // Capture key pressed
BOOL MakeFinderTool (HWND hwnd, WNDFINDPROC wfp);
void InvertWindow (HWND hwnd, BOOL fShowHidden);
void FlashWindowBorder (HWND hwnd, BOOL fShowHidden);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,207 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Finder Tool Dialog Box
//---------------------------------------------------------------------------
#include "stdafx.h"
#include "MyApp.h"
#include "FinderDialog.h"
#include "FindTool.h"
#include "Boxes.h"
//---------------------------------------------------------------------------
// Variables
//---------------------------------------------------------------------------
CFinderDialog *CFinderDialog::m_instance = NULL;
//---------------------------------------------------------------------------
// Constructor
//---------------------------------------------------------------------------
CFinderDialog::CFinderDialog(CWnd *pParentWnd, int id)
: CBaseDialog(pParentWnd, L"FINDER_TOOL")
{
m_instance = this;
m_pid = 0;
m_wndClose = pParentWnd;
m_idClose = id;
if (CBaseDialog::m_template_copy)
CDialog::CreateIndirect(m_template_copy, pParentWnd);
else
CDialog::Create(m_lpszTemplateName, pParentWnd);
MakeFinderTool(GetDlgItem(ID_FINDER_TARGET)->m_hWnd, FindProc);
CRect rc;
GetWindowRect(&rc);
m_InitialSize = CSize(rc.right - rc.left, rc.bottom - rc.top);
SetWindowPos(
&wndTopMost, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
}
//---------------------------------------------------------------------------
// Destructor
//---------------------------------------------------------------------------
CFinderDialog::~CFinderDialog()
{
DestroyWindow();
}
//---------------------------------------------------------------------------
// OnInitDialog
//---------------------------------------------------------------------------
BOOL CFinderDialog::OnInitDialog()
{
SetWindowText(CMyMsg(MSG_3661));
GetDlgItem(ID_FINDER_EXPLAIN)->SetWindowText(CMyMsg(MSG_3662));
GetDlgItem(IDCANCEL)->SetWindowText(CMyMsg(MSG_3004));
return TRUE;
}
//---------------------------------------------------------------------------
// FindProc
//---------------------------------------------------------------------------
UINT CALLBACK CFinderDialog::FindProc(HWND hwndTool, UINT uCode, HWND hwnd)
{
if (uCode == WFN_CANCELLED)
m_instance->OnCancel();
else {
ULONG pid;
if (uCode == WFN_END)
GetWindowThreadProcessId(hwnd, &pid);
else
pid = 0;
if (pid)
m_instance->ShowInfo(pid);
else
m_instance->HideInfo();
}
return 0;
}
//---------------------------------------------------------------------------
// ShowInfo
//---------------------------------------------------------------------------
void CFinderDialog::ShowInfo(ULONG pid)
{
m_pid = pid;
if (pid == GetCurrentProcessId()) {
HideInfo();
return;
}
SetWindowPos(
&wndTopMost, 0, 0, m_InitialSize.cx, m_InitialSize.cy + 160,
SWP_SHOWWINDOW | SWP_NOMOVE);
CBoxes &boxes = CBoxes::GetInstance();
CBox &box = boxes.GetBoxByProcessId(pid);
const CString &boxName = box.GetName();
if (! boxName.IsEmpty()) {
CBoxProc &boxproc = box.GetBoxProc();
int index = boxproc.GetIndexForProcessId(pid);
const CString &imageName = boxproc.GetProcessImageName(index);
GetDlgItem(ID_FINDER_RESULT)->SetWindowText(
CMyMsg(MSG_3663, imageName, boxName));
::ShowWindow(GetDlgItem(ID_FINDER_YES_BOXED)->m_hWnd, SW_SHOW);
} else {
GetDlgItem(ID_FINDER_RESULT)->SetWindowText(CMyMsg(MSG_3664));
::ShowWindow(GetDlgItem(ID_FINDER_NOT_BOXED)->m_hWnd, SW_SHOW);
}
::ShowWindow(GetDlgItem(ID_FINDER_RESULT)->m_hWnd, SW_SHOW);
::ShowWindow(GetDlgItem(IDCANCEL)->m_hWnd, SW_SHOW);
}
//---------------------------------------------------------------------------
// HideInfo
//---------------------------------------------------------------------------
void CFinderDialog::HideInfo()
{
if (! m_pid)
return;
m_pid = 0;
SetWindowPos(
&wndTopMost, 0, 0, m_InitialSize.cx, m_InitialSize.cy,
SWP_SHOWWINDOW | SWP_NOMOVE);
::ShowWindow(GetDlgItem(ID_FINDER_YES_BOXED)->m_hWnd, SW_HIDE);
::ShowWindow(GetDlgItem(ID_FINDER_NOT_BOXED)->m_hWnd, SW_HIDE);
::ShowWindow(GetDlgItem(ID_FINDER_RESULT)->m_hWnd, SW_HIDE);
::ShowWindow(GetDlgItem(IDCANCEL)->m_hWnd, SW_HIDE);
}
//---------------------------------------------------------------------------
// OnCancel
//---------------------------------------------------------------------------
void CFinderDialog::OnCancel()
{
::SendMessage(m_wndClose->m_hWnd, WM_COMMAND, m_idClose, 0);
}
//---------------------------------------------------------------------------
// GetProcessId
//---------------------------------------------------------------------------
ULONG CFinderDialog::GetProcessId()
{
return m_pid;
}

View File

@ -0,0 +1,55 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Finder Tool Dialog Box
//---------------------------------------------------------------------------
#ifndef _MY_FINDERDIALOG_H
#define _MY_FINDERDIALOG_H
class CFinderDialog : public CBaseDialog
{
static CFinderDialog *m_instance;
CSize m_InitialSize;
CWnd *m_wndClose;
int m_idClose;
ULONG m_pid;
virtual BOOL OnInitDialog();
static UINT CALLBACK FindProc(HWND hwndTool, UINT uCode, HWND hwnd);
void ShowInfo(ULONG pid);
void HideInfo();
virtual void OnCancel();
public:
CFinderDialog(CWnd *pParentWnd, int id);
~CFinderDialog();
ULONG GetProcessId();
};
#endif // _MY_FINDERDIALOG_H

View File

@ -0,0 +1,192 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Flashing Button
//---------------------------------------------------------------------------
#include "stdafx.h"
#include "FlashingButton.h"
//---------------------------------------------------------------------------
// Message Map
//---------------------------------------------------------------------------
BEGIN_MESSAGE_MAP(CFlashingButton, CButton)
ON_WM_PAINT()
ON_WM_MOUSEMOVE()
ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave)
ON_WM_TIMER()
END_MESSAGE_MAP()
//---------------------------------------------------------------------------
// Constructor
//---------------------------------------------------------------------------
CFlashingButton::CFlashingButton()
: CButton()
{
}
//---------------------------------------------------------------------------
// Destructor
//---------------------------------------------------------------------------
CFlashingButton::~CFlashingButton()
{
if (m_timer)
KillTimer(m_timer);
}
//---------------------------------------------------------------------------
// Init
//---------------------------------------------------------------------------
bool CFlashingButton::Init(HWND hwndButton)
{
if (hwndButton) {
if (SubclassWindow(hwndButton)) {
RECT rc;
::GetWindowRect(hwndButton, &rc);
m_width = rc.right - rc.left + 1;
m_height = rc.bottom - rc.top + 1;
m_enable = true;
m_invert = 1;
m_timer = SetTimer(1234, 750, 0);
return true;
}
}
return false;
}
//---------------------------------------------------------------------------
// Init
//---------------------------------------------------------------------------
bool CFlashingButton::Init(CWnd *dlg, UINT id)
{
HWND hwndButton;
dlg->GetDlgItem(id, &hwndButton);
return Init(hwndButton);
}
//---------------------------------------------------------------------------
// EnableFlashing
//---------------------------------------------------------------------------
void CFlashingButton::EnableFlashing(bool enable)
{
m_enable = enable;
}
//---------------------------------------------------------------------------
// OnPaint
//---------------------------------------------------------------------------
void CFlashingButton::OnPaint()
{
if (m_enable && m_invert == 1) {
PAINTSTRUCT ps;
HDC hWinDC = ::BeginPaint(m_hWnd, &ps);
HDC hMemDC = CreateCompatibleDC(hWinDC);
HBITMAP hBitmap = CreateCompatibleBitmap(hWinDC, m_width, m_height);
SelectObject(hMemDC, hBitmap);
DefWindowProc(WM_PAINT, (WPARAM)hMemDC, NULL);
BitBlt(hWinDC, 0, 0, m_width, m_height, hMemDC, 0, 0, NOTSRCCOPY);
DeleteObject(hBitmap);
DeleteDC(hMemDC);
::EndPaint(m_hWnd, &ps);
} else {
DefWindowProc(WM_PAINT, NULL, NULL);
}
}
//---------------------------------------------------------------------------
// OnMouseMove
//---------------------------------------------------------------------------
void CFlashingButton::OnMouseMove(UINT nFlags, CPoint point)
{
if (m_invert) {
TRACKMOUSEEVENT tme;
tme.cbSize = sizeof(TRACKMOUSEEVENT);
tme.dwFlags = TME_LEAVE;
tme.hwndTrack = m_hWnd;
if (_TrackMouseEvent(&tme)) {
m_invert = 0;
Invalidate();
}
}
DefWindowProc(WM_MOUSEMOVE, nFlags, MAKELPARAM(point.x, point.y));
}
//---------------------------------------------------------------------------
// OnMouseLeave
//---------------------------------------------------------------------------
LRESULT CFlashingButton::OnMouseLeave(WPARAM wParam, LPARAM lParam)
{
m_invert = 1;
Invalidate();
return 0;
}
//---------------------------------------------------------------------------
// OnTimer
//---------------------------------------------------------------------------
void CFlashingButton::OnTimer(UINT_PTR nIDEvent)
{
if (m_invert) {
m_invert = -m_invert;
Invalidate();
}
}

View File

@ -0,0 +1,62 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Flashing Button
//---------------------------------------------------------------------------
#ifndef _MY_FLASHINGBUTTON_H
#define _MY_FLASHINGBUTTON_H
#include <afxcmn.h>
class CFlashingButton : public CButton
{
DECLARE_MESSAGE_MAP()
ULONG m_width;
ULONG m_height;
ULONG_PTR m_timer;
int m_invert;
bool m_enable;
protected:
afx_msg void OnPaint();
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
afx_msg LRESULT OnMouseLeave(WPARAM wParam, LPARAM lParam);
afx_msg void OnTimer(UINT_PTR nIDEvent);
public:
bool Init(HWND hwndButton);
bool Init(CWnd *dlg, UINT id);
void EnableFlashing(bool enable);
CFlashingButton();
~CFlashingButton();
};
#endif // _MY_FLASHINGBUTTON_H

View File

@ -0,0 +1,711 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Getting Started Wizard
//---------------------------------------------------------------------------
#include "stdafx.h"
#include "MyApp.h"
#include "GettingStartedWizard.h"
#include "Boxes.h"
#include "MessageDialog.h"
#include "DeleteDialog.h"
#include "MyFrame.h"
#include "apps/common/FontStore.h"
#include "apps/common/MyGdi.h"
//---------------------------------------------------------------------------
// CShadowWnd
//---------------------------------------------------------------------------
class CShadowWnd : public CWnd
{
protected:
DECLARE_MESSAGE_MAP()
afx_msg void OnPaint();
public:
HRGN m_hrgn;
CShadowWnd();
void ExcludeWindows(HWND rectwnd, HWND circlewnd);
};
//---------------------------------------------------------------------------
// Defines
//---------------------------------------------------------------------------
#define ID_TIMER 10001
#define ID_IMAGE_PAGE2 10201
#define ID_DESKTOP_PAGE3 10301
#define IDNEXT 0x3024
//---------------------------------------------------------------------------
// Message Map
//---------------------------------------------------------------------------
BEGIN_MESSAGE_MAP(CGettingStartedPage, CLayoutPropertyPage)
ON_NOTIFY(NM_CUSTOMDRAW, ID_IMAGE_PAGE2, OnImageFrame_Page2)
ON_COMMAND(ID_DESKTOP_PAGE3, OnShowDesktop_Page3)
ON_WM_CTLCOLOR()
ON_WM_TIMER()
ON_COMMAND(ID_SANDBOX_MENU | ID_SANDBOX_RECOVER,
OnImmediateRecover_Page4)
ON_COMMAND(ID_SANDBOX_MENU | ID_SANDBOX_EXPLORE,
OnShowBalloon_Page5)
ON_COMMAND(ID_SANDBOX_MENU | ID_SANDBOX_TERMINATE,
OnHideBalloon_Page5)
ON_COMMAND(ID_SANDBOX_MENU | ID_SANDBOX_DELETE,
OnDeleteContents_Page5)
END_MESSAGE_MAP()
//---------------------------------------------------------------------------
// Constructor
//---------------------------------------------------------------------------
CGettingStartedPage::CGettingStartedPage(int page_num)
: CMyWizardPage(page_num)
{
memzero(&u, sizeof(u));
}
//---------------------------------------------------------------------------
// Destructor
//---------------------------------------------------------------------------
CGettingStartedPage::~CGettingStartedPage()
{
if (m_page_num == 2) {
delete u.page2.m_legend_bitmap;
}
if (m_page_num == 3 || m_page_num == 5) {
KillTimer(ID_TIMER);
}
if (m_page_num == 5) {
CShadowWnd *shadow_wnd = (CShadowWnd *)u.page5.m_shadow_wnd;
delete shadow_wnd;
}
}
//---------------------------------------------------------------------------
// OnInitDialog
//---------------------------------------------------------------------------
BOOL CGettingStartedPage::OnInitDialog()
{
typedef void (CGettingStartedPage::*P_OnInitDialogProc)(void);
P_OnInitDialogProc init_procs[] = { NULL,
&CGettingStartedPage::OnInitDialog_Page1,
&CGettingStartedPage::OnInitDialog_Page2,
&CGettingStartedPage::OnInitDialog_Page3,
&CGettingStartedPage::OnInitDialog_Page4,
&CGettingStartedPage::OnInitDialog_Page5,
&CGettingStartedPage::OnInitDialog_Page6
};
(this->*(init_procs[m_page_num]))();
return CMyWizardPage::OnInitDialog();
}
//---------------------------------------------------------------------------
// OnInitDialog_Page1
//---------------------------------------------------------------------------
void CGettingStartedPage::OnInitDialog_Page1()
{
SetPageTitle(MSG_7851);
CreateStatic(MSG_7852, CPoint(5, 15), CSize(90, 60));
CBox &box = CBoxes::GetInstance().GetBox(CBoxes::m_DefaultBox);
if (box.GetName().CompareNoCase(CBoxes::m_DefaultBox) != 0) {
CreateStatic(MSG_7853, CPoint(5, 80), CSize(90, 20));
}
}
//---------------------------------------------------------------------------
// OnInitDialog_Page2
//---------------------------------------------------------------------------
void CGettingStartedPage::OnInitDialog_Page2()
{
SetPageTitle(MSG_7854);
u.page2.m_legend_bitmap = new CBitmap();
u.page2.m_legend_bitmap->Attach(
MyGdi_CreateFromResource(L"WELCOME_LEGEND"));
CStatic *image = (CStatic *)CreateChild(
ID_IMAGE_PAGE2, L"STATIC", 0, SS_CENTER,
CPoint(15, 17), CSize(80, 80));
u.page2.m_animation = new CAnimatedBitmap();
u.page2.m_animation->Init(image->UnsubclassWindow());
u.page2.m_animation->SetImage(L"WELCOME_ANIM");
u.page2.m_animation->Animate(true);
m_layout.ReplaceChild(image, u.page2.m_animation);
}
//---------------------------------------------------------------------------
// OnInitDialog_Page3
//---------------------------------------------------------------------------
void CGettingStartedPage::OnInitDialog_Page3()
{
SetPageTitle(MSG_7855);
CreateStatic(MSG_7856, CPoint(5, 15), CSize(90, 20));
u.page3.m_runsandbox_icon =
::LoadIcon(AfxGetInstanceHandle(), L"TRAYICON_FULL");
CStatic *icon = (CStatic *)CreateChild(
-1, L"STATIC", 0, SS_ICON, CPoint(45, 35), CSize(1, 1));
m_layout.SetMinMaxChildObject(icon, CSize(64, 64), CSize(64, 64));
u.page3.m_runsandbox_pwnd = icon;
CString link_name = CMyMsg(MSG_3698);
int dot = link_name.ReverseFind(L'.');
if (dot != -1)
link_name = link_name.Left(dot);
CStatic *icon_name = (CStatic *)CreateChild(
-1, L"STATIC", 0, SS_CENTER, CPoint(5, 55), CSize(90, 20));
icon_name->SetWindowText(link_name);
icon_name->SetFont(CFontStore::Get(L"Tahoma", 12, FW_NORMAL));
CButton *button = (CButton *)CreateChild(
ID_DESKTOP_PAGE3, L"BUTTON", 0, BS_PUSHBUTTON | BS_CENTER,
CPoint(15, 75), CSize(70, 10));
button->SetWindowText(CMyMsg(MSG_7857));
button->SetFont(CFontStore::Get(L"Tahoma", 10, FW_NORMAL));
CBox &box = CBoxes::GetInstance().GetBox(CBoxes::m_DefaultBox);
if (box.GetName().CompareNoCase(CBoxes::m_DefaultBox) == 0)
SetTimer(ID_TIMER, 5 * 1000, NULL);
}
//---------------------------------------------------------------------------
// OnInitDialog_Page4
//---------------------------------------------------------------------------
void CGettingStartedPage::OnInitDialog_Page4()
{
SetPageTitle(MSG_7858);
CreateStatic(MSG_7859, CPoint(5, 15), CSize(90, 80));
CMessageDialog::m_GettingStartedWindow = this;
}
//---------------------------------------------------------------------------
// OnInitDialog_Page5
//---------------------------------------------------------------------------
void CGettingStartedPage::OnInitDialog_Page5()
{
SetPageTitle(MSG_7860);
CreateStatic(MSG_7861, CPoint(5, 15), CSize(90, 40));
CString msg = CMyMsg(MSG_7862) + L"\n\n" + CMyMsg(MSG_7863);
CreateStatic(msg, CPoint(5, 50), CSize(90, 50));
OSVERSIONINFO osvi;
memzero(&osvi, sizeof(OSVERSIONINFO));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx((OSVERSIONINFO *)&osvi);
if ((osvi.dwMajorVersion == 10) || (osvi.dwMajorVersion == 6 && osvi.dwMinorVersion >= 1))
// Windows 7 and above
u.page5.m_open_tray = true;
u.page5.m_shadow_wnd = new CShadowWnd();
CMyFrame::m_GettingStartedWindow = this;
OnShowBalloon_Page5();
}
//---------------------------------------------------------------------------
// OnInitDialog_Page6
//---------------------------------------------------------------------------
void CGettingStartedPage::OnInitDialog_Page6()
{
SetPageTitle(MSG_7864);
CreateStatic(MSG_7865, CPoint(5, 15), CSize(90, 70));
}
//---------------------------------------------------------------------------
// OnKillActive
//---------------------------------------------------------------------------
BOOL CGettingStartedPage::OnKillActive()
{
if (m_page_num == 5 && u.page5.m_shadow_wnd)
u.page5.m_shadow_wnd->ShowWindow(SW_HIDE);
if (CMyFrame::m_GettingStartedWindow)
CMyApp::BalloonTrayIcon(CString(), 10);
CMessageDialog::m_GettingStartedWindow = NULL;
CMyFrame::m_GettingStartedWindow = NULL;
KillTimer(ID_TIMER);
CGettingStartedWizard *wizard = (CGettingStartedWizard *)GetParent();
wizard->FlashNextButton(false);
return CLayoutPropertyPage::OnKillActive();
}
//---------------------------------------------------------------------------
// OnKillActive
//---------------------------------------------------------------------------
void CGettingStartedPage::OnCancel()
{
if (m_page_num == 5 && u.page5.m_shadow_wnd)
u.page5.m_shadow_wnd->ShowWindow(SW_HIDE);
if (CMessageDialog::m_GettingStartedWindow)
CMessageDialog::m_GettingStartedWindow = NULL;
if (CMyFrame::m_GettingStartedWindow) {
CMyApp::BalloonTrayIcon(CString(), 10);
CMyFrame::m_GettingStartedWindow = NULL;
}
return CLayoutPropertyPage::OnCancel();
}
//---------------------------------------------------------------------------
// OnImageFrame_Page2
//---------------------------------------------------------------------------
void CGettingStartedPage::OnImageFrame_Page2(NMHDR *pNMHDR, LRESULT *pResult)
{
BITMAP info;
if (u.page2.m_legend_bitmap->GetBitmap(&info)) {
CAnimatedBitmap_NM *nm = (CAnimatedBitmap_NM *)pNMHDR;
CDC bmp_dc;
bmp_dc.CreateCompatibleDC(nm->dc);
CBitmap *bmp_old = bmp_dc.SelectObject(u.page2.m_legend_bitmap);
nm->dc->BitBlt(10, 10, info.bmWidth, info.bmHeight, &bmp_dc, 0, 0, SRCCOPY);
bmp_dc.SelectObject(bmp_old);
}
}
//---------------------------------------------------------------------------
// OnShowDesktop_Page3
//---------------------------------------------------------------------------
void CGettingStartedPage::OnShowDesktop_Page3()
{
CWnd *traywnd = FindWindow(L"Shell_TrayWnd", NULL);
if (traywnd)
traywnd->SendMessage(WM_COMMAND, 407, 0);
}
//---------------------------------------------------------------------------
// OnCtlColor
//---------------------------------------------------------------------------
HBRUSH CGettingStartedPage::OnCtlColor(
CDC *pDC, CWnd *pWnd, UINT nCtlColor)
{
if (m_page_num == 3 && pWnd == u.page3.m_runsandbox_pwnd) {
pDC->SetBkMode(TRANSPARENT);
DrawIconEx(pDC->m_hDC, 0, 0, u.page3.m_runsandbox_icon,
64, 64, 0, NULL, DI_NORMAL);
return (HBRUSH)::GetStockObject(NULL_BRUSH);
}
return CLayoutPropertyPage::OnCtlColor(pDC, pWnd, nCtlColor);
}
//---------------------------------------------------------------------------
// OnTimer
//---------------------------------------------------------------------------
void CGettingStartedPage::OnTimer(UINT_PTR nIDEvent)
{
if (nIDEvent == ID_TIMER && m_page_num == 3) {
int process_count =
CBoxes::GetInstance().GetBox(CBoxes::m_DefaultBox)
.GetBoxProc().GetProcessCount();
if (process_count) {
KillTimer(ID_TIMER);
CGettingStartedWizard *wizard =
(CGettingStartedWizard *)GetParent();
wizard->FlashNextButton(true);
}
}
if (nIDEvent == ID_TIMER && m_page_num == 5) {
OnShowBalloon_Page5();
}
return CLayoutPropertyPage::OnTimer(nIDEvent);
}
//---------------------------------------------------------------------------
// OnImmediateRecover_Page4
//---------------------------------------------------------------------------
void CGettingStartedPage::OnImmediateRecover_Page4()
{
CMessageDialog::m_GettingStartedWindow = NULL;
CGettingStartedWizard *wizard =
(CGettingStartedWizard *)GetParent();
wizard->FlashNextButton(true);
}
//---------------------------------------------------------------------------
// OnShowBalloon_Page5
//---------------------------------------------------------------------------
void CGettingStartedPage::OnShowBalloon_Page5()
{
if (CMyFrame::m_GettingStartedWindow) {
if (! u.page5.m_tray_opened) {
//
// find the button on the tray that it used to show/expand
// hidden notification icons and use that as a target for
// the arrow window
//
HWND ButtonWnd = FindTrayButton(NULL, NULL);
CShadowWnd *shadow_wnd = (CShadowWnd *)u.page5.m_shadow_wnd;
shadow_wnd->ExcludeWindows(GetParent()->m_hWnd, ButtonWnd);
//
// on Windows 7, if the tray button is visible, then some
// icons are hidden in the icon overflow area of the tray.
// in case our icon is hidden, we fake a click on the button
// so the icon overflow area is made visible
//
if (u.page5.m_open_tray &&
ButtonWnd && ::IsWindowVisible(ButtonWnd)) {
bool OverflowIconsAlreadyVisible = false;
HWND NotifyAreaWnd =
::FindWindow(L"NotifyIconOverflowWindow", NULL);
if (NotifyAreaWnd && ::IsWindowVisible(NotifyAreaWnd))
OverflowIconsAlreadyVisible = true;
HWND TrayNotifyWnd = ::GetParent(ButtonWnd);
WPARAM wParam = ::GetDlgCtrlID(ButtonWnd);
LPARAM lParam = (LPARAM)ButtonWnd;
::SendMessage(TrayNotifyWnd, WM_COMMAND, wParam, lParam);
if (OverflowIconsAlreadyVisible)
::SendMessage(TrayNotifyWnd, WM_COMMAND, wParam, lParam);
}
//
// request a secondary WM_TIMER which to show the balloon
//
u.page5.m_tray_opened = true;
PostMessage(WM_TIMER, ID_TIMER, 0);
} else {
u.page5.m_tray_opened = false;
SetTimer(ID_TIMER, 5 * 1000, NULL);
CString tip = L"\n" + CMyMsg(MSG_7863);
CMyApp::BalloonTrayIcon(tip, 10);
}
}
}
//---------------------------------------------------------------------------
// OnHideBalloon_Page5
//---------------------------------------------------------------------------
void CGettingStartedPage::OnHideBalloon_Page5()
{
if (CMyFrame::m_GettingStartedWindow) {
KillTimer(ID_TIMER);
CMyApp::BalloonTrayIcon(CString(), 10);
}
}
//---------------------------------------------------------------------------
// OnDeleteContents_Page5
//---------------------------------------------------------------------------
void CGettingStartedPage::OnDeleteContents_Page5()
{
if (m_page_num == 5 && u.page5.m_shadow_wnd)
u.page5.m_shadow_wnd->ShowWindow(SW_HIDE);
CMyFrame::m_GettingStartedWindow = NULL;
GetParent()->ShowWindow(SW_HIDE);
BOOL spawned;
CDeleteDialog dlg(this, CBoxes::m_DefaultBox, TRUE, FALSE, &spawned);
if (! m_hWnd) // in case window was destroyed by exit command
return;
GetParent()->ShowWindow(SW_SHOW);
CGettingStartedWizard *wizard = (CGettingStartedWizard *)GetParent();
wizard->FlashNextButton(true);
}
//---------------------------------------------------------------------------
// Find
//---------------------------------------------------------------------------
HWND CGettingStartedPage::FindTrayButton(HWND hwnd, LPARAM lParam)
{
if (lParam) {
WCHAR clsnm[64];
int n = GetClassName(hwnd, clsnm, 64);
if (n == 6 && _wcsicmp(clsnm, L"BUTTON") == 0) {
int id = ::GetDlgCtrlID(hwnd);
if (id == 0x5DE) {
*(HWND *)lParam = hwnd;
return NULL;
}
}
return (HWND)TRUE;
} else {
HWND hwndResult = NULL;
HWND ShellTrayWnd = ::FindWindow(L"Shell_TrayWnd", NULL);
if (ShellTrayWnd) {
HWND TrayNotifyWnd = ::FindWindowEx(
ShellTrayWnd, NULL, L"TrayNotifyWnd", NULL);
if (TrayNotifyWnd) {
EnumChildWindows(TrayNotifyWnd, (WNDENUMPROC)FindTrayButton,
(LPARAM)&hwndResult);
}
}
return hwndResult;
}
}
//---------------------------------------------------------------------------
// CGettingStartedWizard Constructor
//---------------------------------------------------------------------------
CGettingStartedWizard::CGettingStartedWizard(CWnd *pParentWnd)
: CMyWizard(pParentWnd, 7850)
{
for (int i = 1; i <= 6; ++i)
AddPage(new CGettingStartedPage(i));
pParentWnd->ShowWindow(SW_HIDE);
DoModal();
pParentWnd->ShowWindow(SW_SHOW);
CMessageDialog::m_GettingStartedWindow = NULL;
CMyFrame::m_GettingStartedWindow = NULL;
}
//---------------------------------------------------------------------------
// FlashNextButton
//---------------------------------------------------------------------------
void CGettingStartedWizard::FlashNextButton(bool enable)
{
if (enable) {
ShowWindow(SW_RESTORE);
SetForegroundWindow();
m_pBaseDialog->FlashTitle();
}
if (! m_next_button.m_hWnd)
m_next_button.Init(this, IDNEXT);
m_next_button.EnableFlashing(enable);
}
//---------------------------------------------------------------------------
// CArrowWnd Message Map
//---------------------------------------------------------------------------
BEGIN_MESSAGE_MAP(CShadowWnd, CWnd)
ON_WM_PAINT()
END_MESSAGE_MAP()
//---------------------------------------------------------------------------
// CShadowWnd Constructor
//---------------------------------------------------------------------------
CShadowWnd::CShadowWnd()
{
m_hrgn = NULL;
CRect rc;
GetDesktopWindow()->GetWindowRect(&rc);
CWnd::CreateEx(WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_NOACTIVATE
| WS_EX_TOOLWINDOW | WS_EX_TOPMOST,
NULL, NULL, WS_POPUP | WS_CLIPCHILDREN | WS_VISIBLE,
2, 2, rc.Width() - 2 * 2, rc.Height() - 2 * 2,
NULL, NULL, NULL);
::SetLayeredWindowAttributes(m_hWnd, 0, 192, LWA_ALPHA);
}
//---------------------------------------------------------------------------
// CShadowWnd::ExcludeWindows
//---------------------------------------------------------------------------
void CShadowWnd::ExcludeWindows(HWND rectwnd, HWND circlewnd)
{
CRect rc;
GetDesktopWindow()->GetWindowRect(&rc);
HRGN rgn1 = CreateRectRgn(rc.left, rc.top, rc.right, rc.bottom);
int desk_right = rc.right;
if (::IsWindowVisible(rectwnd) & (! ::IsIconic(rectwnd)))
::GetWindowRect(rectwnd, &rc);
else
memzero(&rc, sizeof(RECT));
HRGN rgn2 = CreateRectRgn(
rc.left - 4, rc.top - 4, rc.right + 4, rc.bottom + 4);
if (circlewnd) {
::GetWindowRect(circlewnd, &rc);
int rad = desk_right - rc.right;
if (GetWindowLong(circlewnd, GWL_EXSTYLE) & WS_EX_LAYOUTRTL)
rad = rc.right;
HRGN rgn3 = CreateEllipticRgn(rc.left - rad, rc.top - rad,
rc.right + rad, rc.bottom + rad);
CombineRgn(rgn2, rgn2, rgn3, RGN_OR);
DeleteObject(rgn3);
}
CombineRgn(rgn1, rgn1, rgn2, RGN_XOR);
DeleteObject(rgn2);
SetWindowRgn(rgn1, TRUE);
}
//---------------------------------------------------------------------------
// CShadowWnd::OnPaint
//---------------------------------------------------------------------------
void CShadowWnd::OnPaint()
{
CRect rc;
GetClientRect(&rc);
PAINTSTRUCT ps;
CDC *dc = BeginPaint(&ps);
dc->FillSolidRect(rc, 0);
EndPaint(&ps);
}

View File

@ -0,0 +1,126 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Getting Started Wizard
//---------------------------------------------------------------------------
#ifndef _MY_GETTINGSTARTEDWIZARD_H
#define _MY_GETTINGSTARTEDWIZARD_H
#include "MyWizard.h"
#include "FlashingButton.h"
#include "FileListCtrl.h"
#include "AnimatedBitmap.h"
class CGettingStartedPage : public CMyWizardPage
{
protected:
DECLARE_MESSAGE_MAP()
union {
struct {
CAnimatedBitmap *m_animation;
CBitmap *m_legend_bitmap;
} page2;
struct {
HICON m_runsandbox_icon;
CWnd *m_runsandbox_pwnd;
} page3;
struct {
CWnd *m_shadow_wnd;
bool m_open_tray;
bool m_tray_opened;
} page5;
} u;
protected:
virtual BOOL OnInitDialog();
void OnInitDialog_Page1();
void OnInitDialog_Page2();
void OnInitDialog_Page3();
void OnInitDialog_Page4();
void OnInitDialog_Page5();
void OnInitDialog_Page6();
virtual BOOL OnKillActive();
virtual void OnCancel();
afx_msg void OnImageFrame_Page2(NMHDR *pNMHDR, LRESULT *pResult);
afx_msg void OnShowDesktop_Page3();
afx_msg HBRUSH OnCtlColor(CDC *pDC, CWnd *pWnd, UINT nCtlColor);
afx_msg void OnTimer(UINT_PTR nIDEvent);
afx_msg void OnImmediateRecover_Page4();
afx_msg void OnShowBalloon_Page5();
afx_msg void OnHideBalloon_Page5();
afx_msg void OnDeleteContents_Page5();
static HWND FindTrayButton(HWND hwnd, LPARAM lParam);
public:
CGettingStartedPage(int page_num);
~CGettingStartedPage();
};
class CGettingStartedWizard : public CMyWizard
{
friend class CGettingStartedPage;
protected:
CFlashingButton m_next_button;
protected:
void FlashNextButton(bool enable);
public:
CGettingStartedWizard(CWnd *pParentWnd);
};
#endif // _MY_GETTINGSTARTEDWIZARD_H

View File

@ -0,0 +1,320 @@
/*
* Copyright 2004-2020 Sandboxie Holdings, LLC
*
* 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 <https://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
// Initialization Wait
//---------------------------------------------------------------------------
#include "stdafx.h"
#include "MyApp.h"
#include "InitWait.h"
#include "core/svc/SbieIniWire.h"
#include "common/my_version.h"
#include "common/win32_ntddk.h"
//---------------------------------------------------------------------------
// Defines
//---------------------------------------------------------------------------
#define ID_TIMER 1003
//---------------------------------------------------------------------------
// Message Map
//---------------------------------------------------------------------------
BEGIN_MESSAGE_MAP(CInitWait, CWnd)
ON_COMMAND(ID_EXIT, OnDestroy)
ON_COMMAND(ID_SHOW_ERRORS, OnShowErrors)
ON_WM_DESTROY()
ON_WM_TIMER()
ON_REGISTERED_MESSAGE(CMyApp::m_TaskbarCreated, OnTaskbarCreated)
ON_MESSAGE(WM_TRAYICON, OnTrayIcon)
END_MESSAGE_MAP()
//---------------------------------------------------------------------------
// Constructor
//---------------------------------------------------------------------------
CInitWait::CInitWait(CWinApp *myApp)
{
//
// on entry, compare version against driver and service
//
m_pMessageDialog = NULL;
m_hIconPtr = NULL;
m_pMenu = NULL;
m_app_ver.Format(L"%S", MY_VERSION_STRING);
m_svc_ver = L"?";
m_drv_ver = L"?";
m_try_elevate = CMyApp::m_WindowsVista;
GetVersions();
if (m_app_ver == m_svc_ver && m_app_ver == m_drv_ver)
return;
//
// if we got here, it means either service or driver is
// not yet ready, so create window and tray icon for the wait
//
CreateEx( 0, (LPCTSTR)CMyApp::m_atom, CMyApp::m_appTitle,
WS_OVERLAPPEDWINDOW | WS_CAPTION | WS_SYSMENU,
0, 0, 0, 0, NULL, NULL, NULL);
myApp->m_pMainWnd = this;
//
//
//
HINSTANCE hInstance = AfxGetInstanceHandle();
m_hIcon1 = ::LoadIcon(hInstance, L"INITWAIT1");
m_hIcon2 = ::LoadIcon(hInstance, L"INITWAIT2");
m_hIconPtr = m_hIcon1;
m_pMenu = CMyApp::MyLoadMenu(L"WAIT_MENU");
OnTaskbarCreated(0, 0);
SetTimer(ID_TIMER, 1000, NULL);
//
// start SbieSvc
//
SbieDll_StartSbieSvc(FALSE);
//
// temporary message loop while we initialize
//
while (m_hIconPtr) {
MSG msg;
BOOL b = ::GetMessage(&msg, NULL, 0, 0);
if (! b)
break;
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
if (m_app_ver != m_svc_ver || m_app_ver != m_drv_ver)
exit(0);
KillTimer(ID_TIMER);
CMyApp::DeleteTrayIcon();
}
//---------------------------------------------------------------------------
// Destructor
//---------------------------------------------------------------------------
CInitWait::~CInitWait()
{
}
//---------------------------------------------------------------------------
// GetVersions
//---------------------------------------------------------------------------
void CInitWait::GetVersions()
{
BOOL fail = FALSE;
WCHAR drv_ver[16];
if (1) {
bool init_complete = false;
MSG_HEADER req;
req.length = sizeof(MSG_HEADER);
req.msgid = MSGID_PROCESS_CHECK_INIT_COMPLETE;
MSG_HEADER *rpl = SbieDll_CallServer(&req);
if (rpl) {
if (rpl->status == 0)
init_complete = true;
SbieDll_FreeMem(rpl);
}
if (! init_complete)
return;
}
if (m_svc_ver.GetAt(0) == L'?') {
SBIE_INI_GET_VERSION_REQ req;
req.h.length = sizeof(SBIE_INI_GET_VERSION_REQ);
req.h.msgid = MSGID_SBIE_INI_GET_VERSION;
SBIE_INI_GET_VERSION_RPL *rpl =
(SBIE_INI_GET_VERSION_RPL *)SbieDll_CallServer(&req.h);
if (rpl) {
if (rpl->h.status == 0 && rpl->version[0]) {
m_svc_ver = rpl->version;
if (m_svc_ver != m_app_ver)
fail = TRUE;
}
SbieDll_FreeMem(rpl);
}
}
if (m_drv_ver.GetAt(0) == L'?') {
SbieApi_GetVersion(drv_ver);
if (drv_ver[0] && _wcsicmp(drv_ver, L"unknown") != 0) {
m_drv_ver = drv_ver;
if (m_drv_ver != m_app_ver)
fail = TRUE;
}
}
if (fail) {
CMyMsg msg(MSG_3304, m_app_ver, m_svc_ver, m_drv_ver);
CMyApp::MsgBox(NULL, msg, MB_OK);
exit(0);
}
}
//---------------------------------------------------------------------------
// OnDestroy
//---------------------------------------------------------------------------
void CInitWait::OnDestroy()
{
CMyApp::DeleteTrayIcon();
if (m_hIconPtr)
exit(0);
}
//---------------------------------------------------------------------------
// OnTimer
//---------------------------------------------------------------------------
void CInitWait::OnTimer(UINT_PTR nIDEvent)
{
if (! m_hIconPtr)
return;
if (m_hIconPtr == m_hIcon1)
m_hIconPtr = m_hIcon2;
else
m_hIconPtr = m_hIcon1;
CMyApp::ChangeTrayIcon(m_hIconPtr, CString());
GetVersions();
if (m_app_ver == m_svc_ver && m_app_ver == m_drv_ver)
m_hIconPtr = NULL;
else if (m_try_elevate) {
//
// on Windows Vista, elevate to start the service
//
const WCHAR *StartError = SbieDll_GetStartError();
if (StartError && wcsstr(StartError, L"[22 / 5]")) {
m_try_elevate = FALSE;
WCHAR path[512];
GetSystemWindowsDirectoryW(path, MAX_PATH);
wcscat(path, L"\\system32\\sc.exe");
SHELLEXECUTEINFO shex;
memzero(&shex, sizeof(SHELLEXECUTEINFO));
shex.cbSize = sizeof(SHELLEXECUTEINFO);
shex.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
shex.hwnd = NULL;
shex.lpFile = path;
shex.lpParameters = L"start " SBIESVC;
shex.nShow = SW_SHOWNORMAL;
shex.lpVerb = L"runas";
ShellExecuteEx(&shex);
}
}
}
//---------------------------------------------------------------------------
// OnTaskbarCreated
//---------------------------------------------------------------------------
LRESULT CInitWait::OnTaskbarCreated(WPARAM wParam, LPARAM lParam)
{
CMyApp::CreateTrayIcon(this, m_hIconPtr, CMyMsg(MSG_3303));
return 0;
}
//---------------------------------------------------------------------------
// OnTrayIcon
//---------------------------------------------------------------------------
LRESULT CInitWait::OnTrayIcon(WPARAM wParam, LPARAM lParam)
{
if (LOWORD(lParam) == WM_RBUTTONUP) {
CPoint pt = (CPoint)GetMessagePos();
SetForegroundWindow();
m_pMenu->GetSubMenu(0)->TrackPopupMenu(0, pt.x, pt.y, this, NULL);
PostMessage(WM_NULL, 0, 0);
return 0;
}
return 1;
}
//---------------------------------------------------------------------------
// OnShowErrors
//---------------------------------------------------------------------------
void CInitWait::OnShowErrors()
{
CMessageDialog msgdlg(this, MSGDLG_EVENT_VIEWER);
}

Some files were not shown because too many files have changed in this diff Show More