├── .gitignore
├── CMakeLists.txt
├── LICENSE
├── MSVS
├── .gitignore
├── VS2013
│ ├── WinConsole.filters
│ ├── WinConsole.sln
│ └── WinConsole.vcxproj
└── VS2015
│ ├── WinConsole.filters
│ ├── WinConsole.sln
│ └── WinConsole.vcxproj
├── README.md
├── appveyor.yml
├── clearcmakebuild.bat
├── g++make.bat
├── g++makeall.bat
├── header
├── default.hpp
├── diff.hpp
├── download.hpp
├── pipedebug.hpp
└── ptrerr.hpp
├── object-runwithcode
├── choose.cpp
├── choose.exe.manifest
├── choose.rc
└── g++make.bat
├── tool.cpp
├── tool.exe.manifest
├── tool.rc
└── wininet.lib
/.gitignore:
--------------------------------------------------------------------------------
1 | # Compiled Object files
2 | *.slo
3 | *.lo
4 | *.o
5 | *.obj
6 |
7 | # Precompiled Headers
8 | *.gch
9 | *.pch
10 |
11 | # Compiled Dynamic libraries
12 | *.so
13 | *.dylib
14 | *.dll
15 |
16 | # Fortran module files
17 | *.mod
18 |
19 | # Compiled Static libraries
20 | *.lai
21 | *.la
22 | *.a
23 |
24 | # Executables
25 | *.exe
26 | *.out
27 | *.app
28 |
29 | # tmp
30 | *.tmp
31 | *.zip
32 |
33 | # C-Free tmp file
34 | *.cpp~
35 | *.*~
36 | ~*.*
37 |
38 | ## CMake tmp file
39 | cmake-build-debug/
40 |
41 | ## CLion
42 | .idea/
43 |
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.8)
2 | project(hosts)
3 |
4 | set(CMAKE_CXX_STANDARD 11)
5 | set(CMAKE_VERBOSE_MAKEFILE ON)
6 |
7 | set(SOURCE_FILES
8 | tool.cpp
9 | tool.rc)
10 | link_libraries(wininet)
11 |
12 | add_executable(hosts ${SOURCE_FILES})
13 |
14 | set(OBJECT_SOURCE_CODE
15 | object-runwithcode/choose.cpp
16 | object-runwithcode/choose.rc)
17 |
18 | add_executable(choose ${OBJECT_SOURCE_CODE})
19 |
20 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 | {one line to give the program's name and a brief idea of what it does.}
635 | Copyright (C) {year} {name of author}
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | {project} Copyright (C) {year} {fullname}
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/MSVS/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # Build results
11 | [Dd]ebug/
12 | [Dd]ebugPublic/
13 | [Rr]elease/
14 | [Rr]eleases/
15 | x64/
16 | x86/
17 | build/
18 | bld/
19 | [Bb]in/
20 | [Oo]bj/
21 |
22 | # Roslyn cache directories
23 | *.ide/
24 |
25 | # MSTest test Results
26 | [Tt]est[Rr]esult*/
27 | [Bb]uild[Ll]og.*
28 |
29 | #NUNIT
30 | *.VisualState.xml
31 | TestResult.xml
32 |
33 | # Build Results of an ATL Project
34 | [Dd]ebugPS/
35 | [Rr]eleasePS/
36 | dlldata.c
37 |
38 | *_i.c
39 | *_p.c
40 | *_i.h
41 | *.ilk
42 | *.meta
43 | *.obj
44 | *.pch
45 | *.pdb
46 | *.pgc
47 | *.pgd
48 | *.rsp
49 | *.sbr
50 | *.tlb
51 | *.tli
52 | *.tlh
53 | *.tmp
54 | *.tmp_proj
55 | *.log
56 | *.vspscc
57 | *.vssscc
58 | .builds
59 | *.pidb
60 | *.svclog
61 | *.scc
62 |
63 | # Chutzpah Test files
64 | _Chutzpah*
65 |
66 | # Visual C++ cache files
67 | ipch/
68 | *.aps
69 | *.ncb
70 | *.opensdf
71 | *.sdf
72 | *.cachefile
73 |
74 | # Visual Studio profiler
75 | *.psess
76 | *.vsp
77 | *.vspx
78 |
79 | # TFS 2012 Local Workspace
80 | $tf/
81 |
82 | # Guidance Automation Toolkit
83 | *.gpState
84 |
85 | # ReSharper is a .NET coding add-in
86 | _ReSharper*/
87 | *.[Rr]e[Ss]harper
88 | *.DotSettings.user
89 |
90 | # JustCode is a .NET coding addin-in
91 | .JustCode
92 |
93 | # TeamCity is a build add-in
94 | _TeamCity*
95 |
96 | # DotCover is a Code Coverage Tool
97 | *.dotCover
98 |
99 | # NCrunch
100 | _NCrunch_*
101 | .*crunch*.local.xml
102 |
103 | # MightyMoose
104 | *.mm.*
105 | AutoTest.Net/
106 |
107 | # Web workbench (sass)
108 | .sass-cache/
109 |
110 | # Installshield output folder
111 | [Ee]xpress/
112 |
113 | # DocProject is a documentation generator add-in
114 | DocProject/buildhelp/
115 | DocProject/Help/*.HxT
116 | DocProject/Help/*.HxC
117 | DocProject/Help/*.hhc
118 | DocProject/Help/*.hhk
119 | DocProject/Help/*.hhp
120 | DocProject/Help/Html2
121 | DocProject/Help/html
122 |
123 | # Click-Once directory
124 | publish/
125 |
126 | # Publish Web Output
127 | *.[Pp]ublish.xml
128 | *.azurePubxml
129 | # TODO: Comment the next line if you want to checkin your web deploy settings
130 | # but database connection strings (with potential passwords) will be unencrypted
131 | *.pubxml
132 | *.publishproj
133 |
134 | # NuGet Packages
135 | *.nupkg
136 | # The packages folder can be ignored because of Package Restore
137 | **/packages/*
138 | # except build/, which is used as an MSBuild target.
139 | !**/packages/build/
140 | # If using the old MSBuild-Integrated Package Restore, uncomment this:
141 | #!**/packages/repositories.config
142 |
143 | # Windows Azure Build Output
144 | csx/
145 | *.build.csdef
146 |
147 | # Windows Store app package directory
148 | AppPackages/
149 |
150 | # Others
151 | sql/
152 | *.Cache
153 | ClientBin/
154 | [Ss]tyle[Cc]op.*
155 | ~$*
156 | *~
157 | *.dbmdl
158 | *.dbproj.schemaview
159 | *.pfx
160 | *.publishsettings
161 | node_modules/
162 |
163 | # RIA/Silverlight projects
164 | Generated_Code/
165 |
166 | # Backup & report files from converting an old project file
167 | # to a newer Visual Studio version. Backup files are not needed,
168 | # because we have git ;-)
169 | _UpgradeReport_Files/
170 | Backup*/
171 | UpgradeLog*.XML
172 | UpgradeLog*.htm
173 |
174 | # SQL Server files
175 | *.mdf
176 | *.ldf
177 |
178 | # Business Intelligence projects
179 | *.rdl.data
180 | *.bim.layout
181 | *.bim_*.settings
182 |
183 | # Microsoft Fakes
184 | FakesAssemblies/
185 |
186 | # =========================
187 | # Operating System Files
188 | # =========================
189 |
190 | # OSX
191 | # =========================
192 |
193 | .DS_Store
194 | .AppleDouble
195 | .LSOverride
196 |
197 | # Thumbnails
198 | ._*
199 |
200 | # Files that might appear on external disk
201 | .Spotlight-V100
202 | .Trashes
203 |
204 | # Directories potentially created on remote AFP share
205 | .AppleDB
206 | .AppleDesktop
207 | Network Trash Folder
208 | Temporary Items
209 | .apdisk
210 |
211 | # Windows
212 | # =========================
213 |
214 | # Windows image file caches
215 | Thumbs.db
216 | ehthumbs.db
217 |
218 | # Folder config file
219 | Desktop.ini
220 |
221 | # Recycle Bin used on file shares
222 | $RECYCLE.BIN/
223 |
224 | # Windows Installer files
225 | *.cab
226 | *.msi
227 | *.msm
228 | *.msp
229 |
230 | # Windows shortcuts
231 | *.lnk
232 |
--------------------------------------------------------------------------------
/MSVS/VS2013/WinConsole.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Header Files
20 |
21 |
22 | Header Files
23 |
24 |
25 | Header Files
26 |
27 |
28 | Header Files
29 |
30 |
31 | Header Files
32 |
33 |
34 |
35 |
36 | Source Files
37 |
38 |
39 |
--------------------------------------------------------------------------------
/MSVS/VS2013/WinConsole.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.21005.1
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WinConsole", "WinConsole.vcxproj", "{98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Win32 = Debug|Win32
11 | Debug|x64 = Debug|x64
12 | fortestonline|Win32 = fortestonline|Win32
13 | fortestonline|x64 = fortestonline|x64
14 | fortestonline1|Win32 = fortestonline1|Win32
15 | fortestonline1|x64 = fortestonline1|x64
16 | Release|Win32 = Release|Win32
17 | Release|x64 = Release|x64
18 | EndGlobalSection
19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
20 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}.Debug|Win32.ActiveCfg = Debug|Win32
21 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}.Debug|Win32.Build.0 = Debug|Win32
22 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}.Debug|x64.ActiveCfg = Debug|x64
23 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}.Debug|x64.Build.0 = Debug|x64
24 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}.fortestonline|Win32.ActiveCfg = fortestonline|Win32
25 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}.fortestonline|Win32.Build.0 = fortestonline|Win32
26 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}.fortestonline|x64.ActiveCfg = fortestonline|x64
27 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}.fortestonline|x64.Build.0 = fortestonline|x64
28 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}.fortestonline1|Win32.ActiveCfg = fortestonline1|Win32
29 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}.fortestonline1|Win32.Build.0 = fortestonline1|Win32
30 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}.fortestonline1|x64.ActiveCfg = fortestonline1|x64
31 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}.fortestonline1|x64.Build.0 = fortestonline1|x64
32 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}.Release|Win32.ActiveCfg = Release|Win32
33 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}.Release|Win32.Build.0 = Release|Win32
34 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}.Release|x64.ActiveCfg = Release|x64
35 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}.Release|x64.Build.0 = Release|x64
36 | EndGlobalSection
37 | GlobalSection(SolutionProperties) = preSolution
38 | HideSolutionNode = FALSE
39 | EndGlobalSection
40 | EndGlobal
41 |
--------------------------------------------------------------------------------
/MSVS/VS2013/WinConsole.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Debug
10 | x64
11 |
12 |
13 | fortestonline
14 | Win32
15 |
16 |
17 | fortestonline
18 | x64
19 |
20 |
21 | fortestonline1
22 | Win32
23 |
24 |
25 | fortestonline1
26 | x64
27 |
28 |
29 | Release
30 | Win32
31 |
32 |
33 | Release
34 | x64
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}
49 | Win32Proj
50 | WinConsole
51 |
52 |
53 |
54 | Application
55 | true
56 | v120
57 | Unicode
58 |
59 |
60 | Application
61 | true
62 | v120
63 | Unicode
64 |
65 |
66 | Application
67 | false
68 | v120
69 | true
70 | Unicode
71 |
72 |
73 | Application
74 | false
75 | v120
76 | true
77 | Unicode
78 |
79 |
80 | Application
81 | false
82 | v120
83 | true
84 | Unicode
85 |
86 |
87 | Application
88 | false
89 | v120
90 | true
91 | Unicode
92 |
93 |
94 | Application
95 | false
96 | v120
97 | true
98 | Unicode
99 |
100 |
101 | Application
102 | false
103 | v120
104 | true
105 | Unicode
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 | true
137 | true
138 | $(SolutionDir)bin\$(PlatformTarget)\$(Configuration)\
139 | obj\$(PlatformTarget)\$(Configuration)\
140 |
141 |
142 | true
143 | true
144 | $(SolutionDir)bin\$(PlatformTarget)\$(Configuration)\
145 | obj\$(PlatformTarget)\$(Configuration)\
146 |
147 |
148 | false
149 | $(SolutionDir)bin\$(PlatformTarget)\$(Configuration)\
150 | obj\$(PlatformTarget)\$(Configuration)\
151 | true
152 |
153 |
154 | false
155 | $(SolutionDir)bin\$(PlatformTarget)\$(Configuration)\
156 | obj\$(PlatformTarget)\$(Configuration)\
157 | true
158 |
159 |
160 | false
161 | $(SolutionDir)bin\$(PlatformTarget)\$(Configuration)\
162 | obj\$(PlatformTarget)\$(Configuration)\
163 | true
164 |
165 |
166 | false
167 | $(SolutionDir)bin\$(PlatformTarget)\$(Configuration)\
168 | obj\$(PlatformTarget)\$(Configuration)\
169 | true
170 |
171 |
172 | false
173 | $(SolutionDir)bin\$(PlatformTarget)\$(Configuration)\
174 | obj\$(PlatformTarget)\$(Configuration)\
175 | true
176 |
177 |
178 | false
179 | $(SolutionDir)bin\$(PlatformTarget)\$(Configuration)\
180 | obj\$(PlatformTarget)\$(Configuration)\
181 | true
182 |
183 |
184 |
185 | NotUsing
186 | Level3
187 | Disabled
188 | WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)
189 | ProgramDatabase
190 | false
191 | false
192 | true
193 | MultiThreadedDebug
194 | false
195 | false
196 | $(SolutionDir)..\..\libmicrohttp;%(AdditionalIncludeDirectories)
197 |
198 |
199 | Console
200 | true
201 | Ws2_32.lib;Wininet.lib;%(AdditionalDependencies)
202 | RequireAdministrator
203 | false
204 | false
205 | false
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 | NotUsing
215 | Level3
216 | Disabled
217 | WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)
218 | ProgramDatabase
219 | false
220 | false
221 | false
222 | true
223 | MultiThreadedDebug
224 | false
225 | false
226 | $(SolutionDir)..\..\libmicrohttp;%(AdditionalIncludeDirectories)
227 |
228 |
229 | Console
230 | true
231 | Ws2_32.lib;Wininet.lib;%(AdditionalDependencies)
232 | RequireAdministrator
233 | false
234 | false
235 | false
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 | Level3
245 | NotUsing
246 | MaxSpeed
247 | true
248 | true
249 | WIN32;NDEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)
250 | ProgramDatabase
251 | false
252 | true
253 | Speed
254 | true
255 | true
256 | MultiThreaded
257 | true
258 | $(SolutionDir)..\..\libmicrohttp;%(AdditionalIncludeDirectories)
259 |
260 |
261 | Console
262 | false
263 | true
264 | true
265 | Ws2_32.lib;Wininet.lib;%(AdditionalDependencies)
266 | RequireAdministrator
267 | UseLinkTimeCodeGeneration
268 | false
269 |
270 |
271 |
272 |
273 | Level3
274 | NotUsing
275 | MaxSpeed
276 | true
277 | true
278 | WIN32;NDEBUG;_TESTONLINE;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)
279 | ProgramDatabase
280 | false
281 | true
282 | Speed
283 | true
284 | true
285 | MultiThreaded
286 | true
287 | $(SolutionDir)..\..\libmicrohttp;%(AdditionalIncludeDirectories)
288 |
289 |
290 | Console
291 | false
292 | true
293 | true
294 | Ws2_32.lib;Wininet.lib;%(AdditionalDependencies)
295 | RequireAdministrator
296 | UseLinkTimeCodeGeneration
297 | false
298 |
299 |
300 |
301 |
302 | Level3
303 | NotUsing
304 | MaxSpeed
305 | true
306 | true
307 | WIN32;NDEBUG;_TESTONLINE;HOSTS_HARD_RESET;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)
308 | ProgramDatabase
309 | false
310 | true
311 | Speed
312 | true
313 | true
314 | MultiThreaded
315 | true
316 | $(SolutionDir)..\..\libmicrohttp;%(AdditionalIncludeDirectories)
317 |
318 |
319 | Console
320 | false
321 | true
322 | true
323 | Ws2_32.lib;Wininet.lib;%(AdditionalDependencies)
324 | RequireAdministrator
325 | UseLinkTimeCodeGeneration
326 | false
327 |
328 |
329 |
330 |
331 | Level3
332 | NotUsing
333 | MaxSpeed
334 | true
335 | true
336 | WIN32;NDEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)
337 | ProgramDatabase
338 | false
339 | true
340 | Speed
341 | true
342 | true
343 | MultiThreaded
344 | true
345 | $(SolutionDir)..\..\libmicrohttp;%(AdditionalIncludeDirectories)
346 |
347 |
348 | Console
349 | false
350 | true
351 | true
352 | Ws2_32.lib;Wininet.lib;%(AdditionalDependencies)
353 | RequireAdministrator
354 | UseLinkTimeCodeGeneration
355 | false
356 |
357 |
358 |
359 |
360 | Level3
361 | NotUsing
362 | MaxSpeed
363 | true
364 | true
365 | WIN32;NDEBUG;_CONSOLE;_TESTONLINE;HOSTS_HARD_RESET;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)
366 | ProgramDatabase
367 | false
368 | true
369 | Speed
370 | true
371 | true
372 | MultiThreaded
373 | true
374 | $(SolutionDir)..\..\libmicrohttp;%(AdditionalIncludeDirectories)
375 |
376 |
377 | Console
378 | false
379 | true
380 | true
381 | Ws2_32.lib;Wininet.lib;%(AdditionalDependencies)
382 | RequireAdministrator
383 | UseLinkTimeCodeGeneration
384 | false
385 |
386 |
387 |
388 |
389 | Level3
390 | NotUsing
391 | MaxSpeed
392 | true
393 | true
394 | WIN32;NDEBUG;_CONSOLE;_TESTONLINE;HOSTS_HARD_RESET;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)
395 | ProgramDatabase
396 | false
397 | true
398 | Speed
399 | true
400 | true
401 | MultiThreaded
402 | true
403 | $(SolutionDir)..\..\libmicrohttp;%(AdditionalIncludeDirectories)
404 |
405 |
406 | Console
407 | false
408 | true
409 | true
410 | Ws2_32.lib;Wininet.lib;%(AdditionalDependencies)
411 | RequireAdministrator
412 | UseLinkTimeCodeGeneration
413 | false
414 |
415 |
416 |
417 |
418 |
419 |
--------------------------------------------------------------------------------
/MSVS/VS2015/WinConsole.filters:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
7 |
8 |
9 | {93995380-89BD-4b04-88EB-625FBE52EBFB}
10 | h;hh;hpp;hxx;hm;inl;inc;xsd
11 |
12 |
13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
15 |
16 |
17 |
18 |
19 | Header Files
20 |
21 |
22 | Header Files
23 |
24 |
25 | Header Files
26 |
27 |
28 | Header Files
29 |
30 |
31 | Header Files
32 |
33 |
34 |
35 |
36 | Source Files
37 |
38 |
39 |
--------------------------------------------------------------------------------
/MSVS/VS2015/WinConsole.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 14
4 | VisualStudioVersion = 14.0.23107.0
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WinConsole", "WinConsole.vcxproj", "{98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Win32 = Debug|Win32
11 | Debug|x64 = Debug|x64
12 | fortestonline|Win32 = fortestonline|Win32
13 | fortestonline|x64 = fortestonline|x64
14 | fortestonline1|Win32 = fortestonline1|Win32
15 | fortestonline1|x64 = fortestonline1|x64
16 | Release|Win32 = Release|Win32
17 | Release|x64 = Release|x64
18 | EndGlobalSection
19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
20 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}.Debug|Win32.ActiveCfg = Debug|Win32
21 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}.Debug|Win32.Build.0 = Debug|Win32
22 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}.Debug|x64.ActiveCfg = Debug|x64
23 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}.Debug|x64.Build.0 = Debug|x64
24 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}.fortestonline|Win32.ActiveCfg = fortestonline|Win32
25 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}.fortestonline|Win32.Build.0 = fortestonline|Win32
26 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}.fortestonline|x64.ActiveCfg = fortestonline|x64
27 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}.fortestonline|x64.Build.0 = fortestonline|x64
28 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}.fortestonline1|Win32.ActiveCfg = fortestonline1|Win32
29 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}.fortestonline1|Win32.Build.0 = fortestonline1|Win32
30 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}.fortestonline1|x64.ActiveCfg = fortestonline1|x64
31 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}.fortestonline1|x64.Build.0 = fortestonline1|x64
32 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}.Release|Win32.ActiveCfg = Release|Win32
33 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}.Release|Win32.Build.0 = Release|Win32
34 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}.Release|x64.ActiveCfg = Release|x64
35 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}.Release|x64.Build.0 = Release|x64
36 | EndGlobalSection
37 | GlobalSection(SolutionProperties) = preSolution
38 | HideSolutionNode = FALSE
39 | EndGlobalSection
40 | EndGlobal
41 |
--------------------------------------------------------------------------------
/MSVS/VS2015/WinConsole.vcxproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | Win32
7 |
8 |
9 | Debug
10 | x64
11 |
12 |
13 | fortestonline1
14 | Win32
15 |
16 |
17 | fortestonline1
18 | x64
19 |
20 |
21 | fortestonline
22 | Win32
23 |
24 |
25 | fortestonline
26 | x64
27 |
28 |
29 | Release
30 | Win32
31 |
32 |
33 | Release
34 | x64
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 | {98D6ADA9-79C7-4808-AAC6-DDC417BFA6C9}
49 | Win32Proj
50 | WinConsole
51 |
52 |
53 |
54 | Application
55 | true
56 | v140
57 | Unicode
58 |
59 |
60 | Application
61 | true
62 | v140
63 | Unicode
64 |
65 |
66 | Application
67 | false
68 | v140
69 | true
70 | Unicode
71 |
72 |
73 | Application
74 | false
75 | v140
76 | true
77 | Unicode
78 |
79 |
80 | Application
81 | false
82 | v140
83 | true
84 | Unicode
85 |
86 |
87 | Application
88 | false
89 | v140
90 | true
91 | Unicode
92 |
93 |
94 | Application
95 | false
96 | v140
97 | true
98 | Unicode
99 |
100 |
101 | Application
102 | false
103 | v140
104 | true
105 | Unicode
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 | true
137 | true
138 | $(SolutionDir)bin\$(PlatformTarget)\$(Configuration)\
139 | obj\$(PlatformTarget)\$(Configuration)\
140 |
141 |
142 | true
143 | true
144 | $(SolutionDir)bin\$(PlatformTarget)\$(Configuration)\
145 | obj\$(PlatformTarget)\$(Configuration)\
146 |
147 |
148 | false
149 | $(SolutionDir)bin\$(PlatformTarget)\$(Configuration)\
150 | obj\$(PlatformTarget)\$(Configuration)\
151 | true
152 |
153 |
154 | false
155 | $(SolutionDir)bin\$(PlatformTarget)\$(Configuration)\
156 | obj\$(PlatformTarget)\$(Configuration)\
157 | true
158 |
159 |
160 | false
161 | $(SolutionDir)bin\$(PlatformTarget)\$(Configuration)\
162 | obj\$(PlatformTarget)\$(Configuration)\
163 | true
164 |
165 |
166 | false
167 | $(SolutionDir)bin\$(PlatformTarget)\$(Configuration)\
168 | obj\$(PlatformTarget)\$(Configuration)\
169 | true
170 |
171 |
172 | false
173 | $(SolutionDir)bin\$(PlatformTarget)\$(Configuration)\
174 | obj\$(PlatformTarget)\$(Configuration)\
175 | true
176 |
177 |
178 | false
179 | $(SolutionDir)bin\$(PlatformTarget)\$(Configuration)\
180 | obj\$(PlatformTarget)\$(Configuration)\
181 | true
182 |
183 |
184 |
185 | NotUsing
186 | Level3
187 | Disabled
188 | WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)
189 | ProgramDatabase
190 | false
191 | false
192 | true
193 | MultiThreadedDebug
194 | false
195 | false
196 | $(SolutionDir)..\..\libmicrohttp;%(AdditionalIncludeDirectories)
197 |
198 |
199 | Console
200 | true
201 | Ws2_32.lib;Wininet.lib;%(AdditionalDependencies)
202 | RequireAdministrator
203 | false
204 | false
205 | false
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 | NotUsing
215 | Level3
216 | Disabled
217 | WIN32;_DEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)
218 | ProgramDatabase
219 | false
220 | false
221 | false
222 | true
223 | MultiThreadedDebug
224 | false
225 | false
226 | $(SolutionDir)..\..\libmicrohttp;%(AdditionalIncludeDirectories)
227 |
228 |
229 | Console
230 | true
231 | Ws2_32.lib;Wininet.lib;%(AdditionalDependencies)
232 | RequireAdministrator
233 | false
234 | false
235 | false
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 | Level3
245 | NotUsing
246 | MaxSpeed
247 | true
248 | true
249 | WIN32;NDEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)
250 | ProgramDatabase
251 | false
252 | true
253 | Speed
254 | true
255 | true
256 | MultiThreaded
257 | true
258 | $(SolutionDir)..\..\libmicrohttp;%(AdditionalIncludeDirectories)
259 |
260 |
261 | Console
262 | false
263 | true
264 | true
265 | Ws2_32.lib;Wininet.lib;%(AdditionalDependencies)
266 | RequireAdministrator
267 | UseLinkTimeCodeGeneration
268 | false
269 |
270 |
271 |
272 |
273 | Level3
274 | NotUsing
275 | MaxSpeed
276 | true
277 | true
278 | WIN32;NDEBUG;_TESTONLINE;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)
279 | ProgramDatabase
280 | false
281 | true
282 | Speed
283 | true
284 | true
285 | MultiThreaded
286 | true
287 | $(SolutionDir)..\..\libmicrohttp;%(AdditionalIncludeDirectories)
288 |
289 |
290 | Console
291 | false
292 | true
293 | true
294 | Ws2_32.lib;Wininet.lib;%(AdditionalDependencies)
295 | RequireAdministrator
296 | UseLinkTimeCodeGeneration
297 | false
298 |
299 |
300 |
301 |
302 | Level3
303 | NotUsing
304 | MaxSpeed
305 | true
306 | true
307 | WIN32;NDEBUG;_TESTONLINE;HOSTS_HARD_SET;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)
308 | ProgramDatabase
309 | false
310 | true
311 | Speed
312 | true
313 | true
314 | MultiThreaded
315 | true
316 | $(SolutionDir)..\..\libmicrohttp;%(AdditionalIncludeDirectories)
317 |
318 |
319 | Console
320 | false
321 | true
322 | true
323 | Ws2_32.lib;Wininet.lib;%(AdditionalDependencies)
324 | RequireAdministrator
325 | UseLinkTimeCodeGeneration
326 | false
327 |
328 |
329 |
330 |
331 | Level3
332 | NotUsing
333 | MaxSpeed
334 | true
335 | true
336 | WIN32;NDEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)
337 | ProgramDatabase
338 | false
339 | true
340 | Speed
341 | true
342 | true
343 | MultiThreaded
344 | true
345 | $(SolutionDir)..\..\libmicrohttp;%(AdditionalIncludeDirectories)
346 |
347 |
348 | Console
349 | false
350 | true
351 | true
352 | Ws2_32.lib;Wininet.lib;%(AdditionalDependencies)
353 | RequireAdministrator
354 | UseLinkTimeCodeGeneration
355 | false
356 |
357 |
358 |
359 |
360 | Level3
361 | NotUsing
362 | MaxSpeed
363 | true
364 | true
365 | WIN32;NDEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)
366 | ProgramDatabase
367 | false
368 | true
369 | Speed
370 | true
371 | true
372 | MultiThreaded
373 | true
374 | $(SolutionDir)..\..\libmicrohttp;%(AdditionalIncludeDirectories)
375 |
376 |
377 | Console
378 | false
379 | true
380 | true
381 | Ws2_32.lib;Wininet.lib;%(AdditionalDependencies)
382 | RequireAdministrator
383 | UseLinkTimeCodeGeneration
384 | false
385 |
386 |
387 |
388 |
389 | Level3
390 | NotUsing
391 | MaxSpeed
392 | true
393 | true
394 | WIN32;NDEBUG;_CONSOLE;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)
395 | ProgramDatabase
396 | false
397 | true
398 | Speed
399 | true
400 | true
401 | MultiThreaded
402 | true
403 | $(SolutionDir)..\..\libmicrohttp;%(AdditionalIncludeDirectories)
404 |
405 |
406 | Console
407 | false
408 | true
409 | true
410 | Ws2_32.lib;Wininet.lib;%(AdditionalDependencies)
411 | RequireAdministrator
412 | UseLinkTimeCodeGeneration
413 | false
414 |
415 |
416 |
417 |
418 |
419 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 使用本项目前 请仔细阅读本README文件
2 |
3 | # Download Executable File
4 |
5 | [](https://ci.appveyor.com/project/Too-Naive/windows/branch/master)
6 | Last update: Jan. 17th, 2018
7 |
8 | #### 下载地址:(v2.2.1)
9 |
10 | - zip Package (Include `tool.exe` and `choose.exe`)
11 | - [点我来下载](https://git.io/vN8tJ)
12 |
13 | 如只需下载tool.exe请到[release](https://github.com/HostsTools/Windows/releases/latest)页面手动下载
14 |
15 | OS type | Minimun Supported Version
16 | --------|-------------------
17 | WorkStation | Microsoft Windows XP Family
18 | Server | Microsoft Windows Server 2003 Family
19 |
20 | # Hosts Tool
21 |
22 | 这个工具可以帮助你全自动的更换 备份原来的hosts文件
23 | 所有麻烦的事情只需要打开一个程序就能搞定
24 | 如果你愿意,程序还可以作为服务安装随系统启动
25 | 每次开机后每隔30分钟会自动检测hosts文件的更新噢!
26 |
27 | **在此特别感谢[@qwerty258](https://github.com/qwerty258)为本程序提供了Visual Studio的工程文件**
28 |
29 | ## 声明
30 |
31 | ~~作者弃坑了~~
32 |
33 | ## 警告
34 |
35 | 1. **请不要删除`# Copyright (c) 2017-2018, googlehosts members.`(作为程序的识别位点) 否则 有可能发生不可预料的后果**
36 | 2. **如果先前没有使用本项目hosts文件 而使用了其他项目的hosts文件的 请重置hosts文件(具体方法看下方使用说明)后 再使用本程序**
37 |
38 | ## How to use?
39 |
40 | 修改hosts涉及到系统文件的修改,安装服务也有可能触发安全软件的提示,如有安全软件提示请放行通过.
41 |
42 | main program file: `tool.exe`
43 |
44 | - 无参数运行`tool.exe` 用来更新hosts文件 如有更新 程序会备份原有的hosts文件
45 | - 运行`choose.exe` 来选择更多的运行选项
46 |
47 | ## 现有功能
48 |
49 | * 启动程序后,从指定的源自动更新hosts文件
50 | * 程序会保留先前的自定义hosts,如果您有使用其他的hosts,请在备份好自己自定义的hosts之后重置hosts文件
51 | * 可选的以服务启动,在后台自动更新hosts文件
52 | * 可选的以用户态模式(静默)开机启动,在后台自动更新hosts文件 (打开`choose.exe`后输入11按下回车)
53 | * 程序会留下一份更新备份,如出现问题可直接更改备份文件名还原
54 | * 程序可以直接重置hosts文件
55 | * 可选的在服务出现问题时,使用 Debug 模式进行监听服务的状态
56 |
57 | ## 注意事项
58 |
59 | 1. 如果安装服务 程序会往`%SystemRoot%`下复制一个`hoststools.exe`文件用来作为服务启动的主程序
60 | 2. 安装服务后 日志文件会保存在`C:\Hosts_Tool_log.log`下 您可以通过查看日志观察服务的工作状态
61 | 3. 本程序一切有更改hosts文件的行为前都会先备份hosts文件。
62 | 4. 请间隔一段时间后清理`%SystemRoot%\system32\drivers\etc\`文件夹 (程序加入了询问删除早期备份文件的功能)
63 | 5. 如有任何疑问或bug反馈,请开新的issue (如是服务问题请附上日志文件)
64 |
65 |
66 | ## License:
67 |
68 | General Public License Version 3
69 |
--------------------------------------------------------------------------------
/appveyor.yml:
--------------------------------------------------------------------------------
1 | version: 2.1.19-b.{build}
2 | branches:
3 | only:
4 | - master
5 | skip_tags: true
6 | image: Visual Studio 2015
7 | configuration: fortestonline1
8 | environment:
9 | pg: C:\projects\windows\MSVS\VS2015\bin\x86\fortestonline1\WinConsole.exe
10 | hsf: '%SystemRoot%\system32\drivers\etc\hosts'
11 | pgr: C:\projects\windows\MSVS\VS2015\bin\x86\fortestonline1\
12 | before_build:
13 | - cmd: >-
14 | cd /d C:\projects\windows
15 |
16 | cmake .
17 |
18 | clearcmakebuild.bat
19 |
20 | rd /s /q C:\projects\windows\MSVS\VS2013
21 | build:
22 | verbosity: minimal
23 | test_script:
24 | - cmd: >-
25 | REM add a row to hosts file (first test)
26 |
27 | echo.127.0.0.1 baidu.com >> %hsf%
28 |
29 | REM Run program to test
30 |
31 | %pg%
32 |
33 | REM reset hosts file
34 |
35 | %pg% -r
36 |
--------------------------------------------------------------------------------
/clearcmakebuild.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | del /q *.vcx*
3 | del /q *.sln
--------------------------------------------------------------------------------
/g++make.bat:
--------------------------------------------------------------------------------
1 | @set TARGETNAME=tool
2 | @set LDCOMMAND=-lwininet
3 | windres %TARGETNAME%.rc -o tmp.o
4 | g++ -o %TARGETNAME%.exe %TARGETNAME%.cpp tmp.o -s %LDCOMMAND% -O2
5 | del /q tmp.o
6 | pause
--------------------------------------------------------------------------------
/g++makeall.bat:
--------------------------------------------------------------------------------
1 | @set TARGETNAME=tool
2 | @set LDCOMMAND=-lwininet
3 | windres %TARGETNAME%.rc -o tmp.o
4 | g++ -o %TARGETNAME%.exe %TARGETNAME%.cpp tmp.o -s %LDCOMMAND% -O2
5 | del /q tmp.o
6 | @cd object-runwithcode
7 | @set TARGETNAME=choose
8 | @set LDCOMMAND=
9 | windres %TARGETNAME%.rc -o tmp.o
10 | g++ -o %TARGETNAME%.exe %TARGETNAME%.cpp tmp.o -s %LDCOMMAND% -O2
11 | del /q tmp.o
12 | @cd ..
13 | pause
--------------------------------------------------------------------------------
/header/default.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include
3 | const TCHAR * szDefatult_hostsfile=_T("\
4 | # Copyright (c) 1993-2009 Microsoft Corp.\n\
5 | #\n\
6 | # This is a sample HOSTS file used by Microsoft TCP/IP for Windows.\n\
7 | #\n\
8 | # This file contains the mappings of IP addresses to host names. Each\n\
9 | # entry should be kept on an individual line. The IP address should\n\
10 | # be placed in the first column followed by the corresponding host name.\n\
11 | # The IP address and the host name should be separated by at least one\n\
12 | # space.\n\
13 | #\n\
14 | # Additionally, comments (such as these) may be inserted on individual\n\
15 | # lines or following the machine name denoted by a '#' symbol.\n\
16 | #\n\
17 | # For example:\n\
18 | #\n\
19 | # 102.54.94.97 rhino.acme.com # source server\n\
20 | # 38.25.63.10 x.acme.com # x client host\n\
21 | \n\
22 | # localhost name resolution is handled within DNS itself.\n\
23 | # 127.0.0.1 localhost\n\
24 | # ::1 localhost\n\
25 | ");
26 |
--------------------------------------------------------------------------------
/header/diff.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * This source code was published under GPL v3
3 | *
4 | * Copyright (C) 2016-2018 Too-Naive
5 | *
6 | */
7 |
8 | #pragma once
9 | #include
10 | #include
11 | #include
12 |
13 | bool Func_CheckDiff(const TCHAR *lFilePath, const TCHAR * rFilePath) throw(){
14 | const size_t BUFFER_SIZE=2048;
15 | FILE * lFile=_tfopen(lFilePath,_T("rb")),*rFile=_tfopen(rFilePath,_T("rb"));
16 | if(!(lFile && rFile))
17 | return true;
18 | char *lBuffer = new char[BUFFER_SIZE];
19 | char *rBuffer = new char[BUFFER_SIZE];
20 | if (!lBuffer||!rBuffer)
21 | _tprintf(_T("Can't allocate memory to buffer in Func_diff\n")),abort();
22 | do {
23 | memset(lBuffer,0,BUFFER_SIZE);
24 | memset(rBuffer,0,BUFFER_SIZE);
25 | fread(lBuffer,sizeof(char),BUFFER_SIZE,lFile);
26 | fread(rBuffer,sizeof(char),BUFFER_SIZE,rFile);
27 | if (memcmp(lBuffer, rBuffer, BUFFER_SIZE)||
28 | ((!feof(lFile)&&feof(rFile))||(feof(lFile)&&!(feof(rFile))))){
29 | delete [] lBuffer;
30 | delete [] rBuffer;
31 | fclose(lFile);
32 | fclose(rFile);
33 | return true;
34 | }
35 | } while ((!feof(lFile))&&(!feof(rFile)));
36 | delete [] lBuffer;
37 | delete [] rBuffer;
38 | fclose(lFile);
39 | fclose(rFile);
40 | return false;
41 | }
42 |
--------------------------------------------------------------------------------
/header/download.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * This source code was published under GPL v3
3 | *
4 | * Copyright (C) 2016-2018 Too-Naive
5 | *
6 | */
7 | //download.hpp(Re-edit)
8 |
9 | #pragma once
10 |
11 | #include
12 | #include
13 | #include
14 |
15 | //need wininet.lib
16 |
17 | #ifdef _MSC_VER
18 | #pragma comment(lib,"wininet.lib")
19 | #endif
20 |
21 | //define _pNULL_
22 | #ifndef _pNULL_
23 | #if (defined(__GXX_EXPERIMENTAL_CXX0X__)||\
24 | (defined(_MSC_VER)&&(_MSC_VER>=1800)))
25 | #define _pNULL_ nullptr
26 | #else
27 | #define _pNULL_ NULL
28 | #endif
29 | #endif
30 | //end
31 |
32 |
33 | #define ___userAgent _T("Mozilla/4.0 (compatible; Windows NT 6.1)")
34 |
35 | bool Func_DownloadEx(const TCHAR * url,const TCHAR * file,const DWORD FileAttributes){
36 | const size_t dwBuffer=2048; //buffer size
37 | HINTERNET hWeb,hRequest; //Internet request handle
38 | DWORD dwReadByte=0,dwReserved; //read byte count
39 | char szBuffer[dwBuffer]=""; //read buff
40 | HANDLE hdFile=INVALID_HANDLE_VALUE; //file handle
41 | //bug check begin
42 | if (!(hWeb=InternetOpen(___userAgent,INTERNET_OPEN_TYPE_PRECONFIG,_pNULL_,_pNULL_,0))) return false;
43 | if (!(hRequest=InternetOpenUrl(hWeb,url,_pNULL_,0,INTERNET_FLAG_DONT_CACHE,0))){
44 | InternetCloseHandle(hWeb);
45 | return false;
46 | }
47 | if ((hdFile=CreateFile(file,GENERIC_WRITE,0,_pNULL_,CREATE_ALWAYS,FileAttributes,_pNULL_))==INVALID_HANDLE_VALUE){
48 | InternetCloseHandle(hWeb);
49 | InternetCloseHandle(hRequest);
50 | return false;
51 | }
52 | //end.
53 | while (InternetReadFile(hRequest,(PVOID)szBuffer,dwBuffer,&dwReadByte) && dwReadByte)
54 | WriteFile(hdFile,szBuffer,dwReadByte,&dwReserved,_pNULL_);
55 | CloseHandle(hdFile);
56 | InternetCloseHandle(hRequest);
57 | InternetCloseHandle(hWeb);
58 | return true;
59 | }
60 |
61 | inline bool __fastcall Func_Download(const TCHAR * url,const TCHAR * file){//for backward compatibility
62 | return Func_DownloadEx(url,file,FILE_ATTRIBUTE_NORMAL);
63 | }
64 |
65 | inline bool __fastcall Func_easyDownload(const TCHAR * url){
66 | const TCHAR * _szLocate_=_pNULL_;
67 | for (_szLocate_=url;*++_szLocate_;);
68 | if (*--_szLocate_=='/') return false;
69 | for (;*(--_szLocate_)!='/';);
70 | _szLocate_++;
71 | return Func_Download(url,_szLocate_);
72 | }
73 |
--------------------------------------------------------------------------------
/header/pipedebug.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * This source code was published under GPL v3
3 | *
4 | * Copyright (C) 2016-2018 Too-Naive
5 | *
6 | */
7 | #pragma once
8 | #include
9 | #include
10 | #include
11 |
12 | //define _pNULL_
13 | #ifndef _pNULL_
14 | #if (defined(__GXX_EXPERIMENTAL_CXX0X__)||\
15 | (defined(_MSC_VER)&&(_MSC_VER>=1800)))
16 | #define _pNULL_ nullptr
17 | #else
18 | #define _pNULL_ NULL
19 | #endif
20 | #endif
21 | //end
22 |
23 | extern const TCHAR * pipeName;
24 | HANDLE hdPipe=INVALID_HANDLE_VALUE;
25 | extern void ___Func_pipeCallBack(TCHAR const *);
26 | namespace __Dpipe{
27 | //for pipe debug
28 | const DWORD PIPE_TIMEOUT=5000;
29 | const size_t BUFSIZE=4096;
30 | typedef struct _PIPEINST{
31 | OVERLAPPED oOverlap;
32 | HANDLE hPipeInst;
33 | TCHAR chRequest[BUFSIZE];
34 | DWORD cbRead;
35 | TCHAR chReply[BUFSIZE];
36 | DWORD cbToWrite;
37 | } PIPEINST, *LPPIPEINST;
38 | //end
39 | HANDLE ___pipeopen();
40 | inline DWORD ___pipeclose();
41 | DWORD __stdcall OpenPipeService(LPVOID);
42 | DWORD ___pipesendmsg(const TCHAR *);
43 | //pipe debug area
44 | void DisconnectAndClose(LPPIPEINST);
45 | BOOL CreateAndConnectInstance(LPOVERLAPPED);
46 | BOOL ConnectToNewClient(HANDLE, LPOVERLAPPED);
47 | inline void GetAnswerToRequest(LPPIPEINST);
48 | void WINAPI CompletedWriteRoutine(DWORD, DWORD, LPOVERLAPPED);
49 | void WINAPI CompletedReadRoutine(DWORD, DWORD, LPOVERLAPPED);
50 | //end.
51 | DWORD __stdcall OpenPipeService(LPVOID){
52 | HANDLE hConnectEvent;
53 | OVERLAPPED oConnect;
54 | LPPIPEINST lpPipeInst;
55 | DWORD dwWait, cbRet;
56 | BOOL fSuccess, fPendingIO;
57 | if (!(hConnectEvent = CreateEvent(_pNULL_,TRUE,TRUE,_pNULL_)))
58 | return 0*_tprintf(_T("CreateEvent failed with %ld.\n"), GetLastError());
59 | oConnect.hEvent = hConnectEvent;
60 | fPendingIO = CreateAndConnectInstance(&oConnect);
61 | while (1){
62 | dwWait = WaitForSingleObjectEx(hConnectEvent,INFINITE,TRUE);
63 | switch (dwWait){
64 | case 0:
65 | if (fPendingIO)
66 | if (!(fSuccess = GetOverlappedResult(hdPipe,&oConnect,&cbRet,FALSE)))
67 | return _tprintf(_T("ConnectNamedPipe (%ld)\n"), GetLastError());
68 | if (!(lpPipeInst=(LPPIPEINST) HeapAlloc(GetProcessHeap(),0,sizeof(PIPEINST))))
69 | return _tprintf(_T("GlobalAlloc failed (%ld)\n"), GetLastError());
70 | lpPipeInst->hPipeInst = hdPipe;
71 | lpPipeInst->cbToWrite = 0;
72 | CompletedWriteRoutine(0, 0, (LPOVERLAPPED) lpPipeInst);
73 | fPendingIO = CreateAndConnectInstance(&oConnect);
74 | break;
75 | case WAIT_IO_COMPLETION:
76 | break;
77 | default:
78 | return _tprintf(_T("WaitForSingleObjectEx (%ld)\n"), GetLastError());
79 | }
80 | }
81 | return 0;
82 | }
83 | void WINAPI CompletedWriteRoutine(DWORD dwErr,DWORD cbWritten,LPOVERLAPPED lpOverLap){
84 | LPPIPEINST lpPipeInst;
85 | BOOL fRead = FALSE;
86 | lpPipeInst = (LPPIPEINST) lpOverLap;
87 | if ((dwErr == 0) && (cbWritten == lpPipeInst->cbToWrite)){
88 | fRead = ReadFileEx(lpPipeInst->hPipeInst,lpPipeInst->chRequest,
89 | BUFSIZE*sizeof(TCHAR),(LPOVERLAPPED) lpPipeInst,
90 | (LPOVERLAPPED_COMPLETION_ROUTINE) CompletedReadRoutine);
91 | }
92 | if (!fRead) DisconnectAndClose(lpPipeInst);
93 | }
94 | void WINAPI CompletedReadRoutine(DWORD dwErr,DWORD cbBytesRead,LPOVERLAPPED lpOverLap){
95 | LPPIPEINST lpPipeInst;
96 | BOOL fWrite = FALSE;
97 | lpPipeInst = (LPPIPEINST) lpOverLap;
98 | if ((dwErr == 0) && (cbBytesRead != 0)){
99 | GetAnswerToRequest(lpPipeInst);
100 | fWrite = WriteFileEx(lpPipeInst->hPipeInst,lpPipeInst->chReply,
101 | lpPipeInst->cbToWrite,(LPOVERLAPPED) lpPipeInst,
102 | (LPOVERLAPPED_COMPLETION_ROUTINE) CompletedWriteRoutine);
103 | }
104 | if (!fWrite) DisconnectAndClose(lpPipeInst);
105 | }
106 | void DisconnectAndClose(LPPIPEINST lpPipeInst){
107 | if (! DisconnectNamedPipe(lpPipeInst->hPipeInst))
108 | _tprintf(_T("DisconnectNamedPipe failed with %ld.\n"), GetLastError());
109 | CloseHandle(lpPipeInst->hPipeInst);
110 | if (lpPipeInst != _pNULL_)
111 | HeapFree(GetProcessHeap(),0, lpPipeInst);
112 | }
113 | BOOL CreateAndConnectInstance(LPOVERLAPPED lpoOverlap)
114 | {
115 | if (!(hdPipe = CreateNamedPipe(pipeName,PIPE_ACCESS_DUPLEX |FILE_FLAG_OVERLAPPED,
116 | PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
117 | PIPE_UNLIMITED_INSTANCES,BUFSIZE*sizeof(TCHAR),BUFSIZE*sizeof(TCHAR),
118 | PIPE_TIMEOUT,_pNULL_)))
119 | return 0*(_tprintf(_T("CreateNamedPipe failed with %ld.\n"), GetLastError()));
120 | return ConnectToNewClient(hdPipe, lpoOverlap);
121 | }
122 | BOOL ConnectToNewClient(HANDLE hPipe, LPOVERLAPPED lpo)
123 | {
124 | BOOL fConnected, fPendingIO = FALSE;
125 | if ((fConnected = ConnectNamedPipe(hPipe, lpo)))
126 | return 0*_tprintf(_T("ConnectNamedPipe failed with %ld.\n"), GetLastError());
127 | switch (GetLastError()){
128 | case ERROR_IO_PENDING:
129 | fPendingIO = TRUE;
130 | break;
131 | case ERROR_PIPE_CONNECTED:
132 | if (SetEvent(lpo->hEvent))
133 | break;
134 | default:
135 | return 0*_tprintf(_T("ConnectNamedPipe failed with %ld.\n"), GetLastError());
136 | }
137 | return fPendingIO;
138 | }
139 | inline void GetAnswerToRequest(LPPIPEINST pipe)
140 | {
141 | ___Func_pipeCallBack(pipe->chRequest);
142 | // _tprintf( TEXT("%s"), pipe->chRequest);
143 | //reserved:
144 | /* _tprintf( TEXT("[%p] %s"), pipe->hPipeInst, pipe->chRequest);
145 | lstrcpyn( pipe->chReply, TEXT("") ,BUFSIZE);
146 | pipe->cbToWrite = (lstrlen(pipe->chReply)+1)*sizeof(TCHAR);*/
147 | }
148 | HANDLE ___pipeopen(){
149 | while (1){
150 | if ((hdPipe = CreateFile(pipeName,GENERIC_READ|GENERIC_WRITE,0,
151 | _pNULL_,OPEN_EXISTING,0,_pNULL_))!=INVALID_HANDLE_VALUE)
152 | break;
153 | if (GetLastError()!=ERROR_PIPE_BUSY) {
154 | #include "ptrerr.hpp"
155 | #pragma message("other hander file request")
156 | Func_FastPMNTS(_T("%s Error! (%ld)\n"),_T("___pipeopen()"),GetLastError());
157 | return INVALID_HANDLE_VALUE;
158 | }
159 | WaitNamedPipe(pipeName, 2000);
160 | }
161 | return hdPipe;
162 | }
163 | extern DWORD ___OnError(const TCHAR *);
164 | DWORD ___pipesendmsg(const TCHAR * szSent){
165 | DWORD dwReserved=PIPE_READMODE_MESSAGE;
166 | if (!SetNamedPipeHandleState(hdPipe,&dwReserved,_pNULL_,_pNULL_))
167 | ___OnError(_T("WriteFile"));
168 | // Func_FastPMNTS(_T("SetNamedPipeHandleState() Error! (%ld)\n"),GetLastError());
169 | if (!WriteFile(hdPipe,szSent,(lstrlen(szSent)+1)*sizeof(TCHAR),&dwReserved,_pNULL_))
170 | ___OnError(_T("WriteFile"));
171 | // Func_FastPMNTS(_T("WriteFile() Error! (%ld)\n"),GetLastError());
172 | return GetLastError();
173 | }
174 | inline DWORD ___pipeclose(){
175 | CloseHandle(hdPipe);
176 | return GetLastError();
177 | }
178 | }
179 |
--------------------------------------------------------------------------------
/header/ptrerr.hpp:
--------------------------------------------------------------------------------
1 | /*
2 | * This source code was published under GPL v3
3 | *
4 | * Copyright (C) 2016-2018 Too-Naive
5 | *
6 | */
7 | //ptrerr.hpp
8 |
9 | #pragma once
10 |
11 | #include
12 | #include
13 | #include
14 |
15 |
16 | #ifndef _pNULL_
17 | #if (defined(__GXX_EXPERIMENTAL_CXX0X__)||\
18 | (defined(_MSC_VER)&&(_MSC_VER>=1800)))
19 | #define _pNULL_ nullptr
20 | #else
21 | #define _pNULL_ NULL
22 | #endif
23 | #endif
24 |
25 | FILE * ptr_ErrorFileStream=stderr;
26 | bool is_ErrorFileSet=0;
27 | const TCHAR * sz__ErrorFileName__=_pNULL_;
28 | const TCHAR * sz__ErrorFileStream__=_pNULL_;
29 |
30 | FILE * Func_SetErrorFile(const TCHAR*, const TCHAR*);
31 | inline void * __fastcall ___Func_Close_File_Stream(FILE *);
32 | inline int __fastcall ___Func_PrintErrorTimeToFileStream(FILE *);
33 | inline void * ___Func__Check_File_Set(void);
34 | FILE * Func_SetErrorFileEx(const TCHAR *,const TCHAR *);
35 |
36 | #define __BEGIN__ Func_SetErrorFileEx(sz__ErrorFileName__,sz__ErrorFileStream__)
37 | #define __END__ ___Func_Close_File_Stream(_pNULL_)
38 |
39 |
40 | /*
41 | note:
42 | *visual studio ver:
43 | http://stackoverflow.com/questions/70013/
44 | how-to-detect-if-im-compiling-code-with-visual-studio-2008
45 | *c++11 support:
46 | https://msdn.microsoft.com/en-us/library/hh567368.aspx
47 | */
48 |
49 |
50 | #define Func_PETTFS ___Func_PrintErrorTimeToFileStream
51 | #define Func_PETTStdout \
52 | Func_PETTFS(stdout)
53 | #define Func_PETTStderr \
54 | Func_PETTFS(stderr)
55 | #define Func_PET(___ptr_fp) \
56 | Func_PETTFS(___ptr_fp)
57 |
58 | #define Func_FastPETTS(___ptr_fp) \
59 | __BEGIN__, \
60 | Func_PET(___ptr_fp), \
61 | __END__
62 | #define Func_FastPETTSS \
63 | __BEGIN__, \
64 | Func_PET(ptr_ErrorFileStream),\
65 | __END__
66 |
67 | #if (defined(__GXX_EXPERIMENTAL_CXX0X__)||\
68 | (defined(_MSC_VER)&&(_MSC_VER>=1800)))
69 | #pragma message("C++11 Feature supported, using \"Variable-templates\"")
70 |
71 | template
72 | void Func_PrintMessage(FILE * ___ptr_fp,Args... arg){
73 | _ftprintf(___ptr_fp,arg...);
74 | }
75 | #define Func_PM Func_PrintMessage
76 | template
77 | void Func_PMNT(FILE * ___ptr_fp,Args... arg){
78 | ___Func_PrintErrorTimeToFileStream(___ptr_fp);
79 | _ftprintf(___ptr_fp, arg...);
80 | }
81 | template
82 | void Func_PMNTTStdout(Args... arg){
83 | Func_PMNT(stdout, arg...);
84 | }
85 | template
86 | void Func_PMNTTStderr(Args... arg){
87 | Func_PMNT(stderr, arg...);
88 | }
89 | template
90 | void Func_PMNTTS(Args... arg){
91 | Func_PMNT(ptr_ErrorFileStream, arg...);
92 | }
93 | template
94 | void Func_FastPMNT(FILE * ___ptr_fp,Args... arg){
95 | __BEGIN__;
96 | Func_PMNT(___ptr_fp,arg...);
97 | __END__;
98 | }
99 | template
100 | void Func_FastPMNTS(Args... arg){
101 | Func_FastPMNT(ptr_ErrorFileStream, arg...);
102 | }
103 | template
104 | void Func_PrintMessageNeedSpace(FILE * ___ptr_fp,Args... arg){
105 | _ftprintf(___ptr_fp,_T(" "));
106 | _ftprintf(___ptr_fp,arg...);
107 | }
108 | #define Func_PMNS Func_PrintMessageNeedSpace
109 | template
110 | void Func_PMNStdout(Args... arg){
111 | Func_PMNS(stdout,arg...);
112 | }
113 | template
114 | void Func_PMNStderr(Args... arg){
115 | Func_PMNS(stderr,arg...);
116 | }
117 | template
118 | void Func_PMNSS(Args... arg){
119 | Func_PMNS(ptr_ErrorFileStream,arg...);
120 | }
121 | template
122 | void Func_FastPMNS(FILE * ___ptr_fp,Args... arg){
123 | __BEGIN__;
124 | Func_PMNS(___ptr_fp, arg...);
125 | __END__;
126 | }
127 | template
128 | void Func_FastPMNSS(Args... arg){
129 | Func_FastPMNS(ptr_ErrorFileStream,arg...);
130 | }
131 |
132 | #else /*If Not support C++11*/
133 | #pragma message("using variable marco")
134 | #ifndef _MSC_VER /*Microsoft Visual C++ Compile*/
135 | #define Func_PrintMessage(___ptr_fp,arg...) \
136 | _ftprintf(___ptr_fp, ##arg)
137 | #define Func_PM Func_PrintMessage
138 | #define Func_PMNT(___ptr_fp,arg...) \
139 | ___Func_PrintErrorTimeToFileStream(___ptr_fp), \
140 | _ftprintf(___ptr_fp, ##arg)
141 | #define Func_PMNTTStdout(arg...) \
142 | Func_PMNT(stdout, ##arg)
143 | #define Func_PMNTTStderr(arg...) \
144 | Func_PMNT(stderr, ##arg)
145 | #define Func_PMNTTS(arg...) \
146 | Func_PMNT(ptr_ErrorFileStream, ##arg)
147 |
148 | #define Func_FastPMNT(___ptr_fp,arg...) \
149 | __BEGIN__, \
150 | Func_PMNT(___ptr_fp, ##arg), \
151 | __END__
152 | #define Func_FastPMNTS(arg...) \
153 | Func_FastPMNT(ptr_ErrorFileStream, ##arg)
154 |
155 | #define Func_PrintMessageNeedSpace(___ptr_fp,arg...) \
156 | _ftprintf(___ptr_fp, _T(" ")), \
157 | _ftprintf(___ptr_fp, ##arg)
158 | #define Func_PMNS(___ptr_fp,arg...) \
159 | Func_PrintMessageNeedSpace(___ptr_fp, ##arg)
160 | #define Func_PMNStdout(arg...) \
161 | Func_PMNS(stdout, ##arg)
162 | #define Func_PMNStderr(arg...) \
163 | Func_PMNS(stderr, ##arg)
164 | #define Func_PMNSS(arg...) \
165 | Func_PMNS(ptr_ErrorFileStream, ##arg)
166 |
167 | #define Func_FastPMNS(___ptr_fp,arg...) \
168 | __BEGIN__, \
169 | Func_PMNS(___ptr_fp, ##arg), \
170 | __END__
171 | #define Func_FastPMNSS(arg...) \
172 | Func_FastPMNS(ptr_ErrorFileStream, ##arg)
173 |
174 | #else /*GNU G++ Compile*/
175 |
176 | #define Func_PrintMessage(___ptr_fp,...) \
177 | _ftprintf(___ptr_fp, ##__VA_ARGS__)
178 | #define Func_PM Func_PrintMessage
179 | #define Func_PMNT(___ptr_fp,...) \
180 | ___Func_PrintErrorTimeToFileStream(___ptr_fp), \
181 | _ftprintf(___ptr_fp, ##__VA_ARGS__)
182 | #define Func_PMNTTStdout(...) \
183 | Func_PMNT(stdout, ##__VA_ARGS__)
184 | #define Func_PMNTTStderr(...) \
185 | Func_PMNT(stderr, ##__VA_ARGS__)
186 | #define Func_PMNTTS(...) \
187 | Func_PMNT(ptr_ErrorFileStream, ##__VA_ARGS__)
188 |
189 | #define Func_FastPMNT(___ptr_fp,...) \
190 | __BEGIN__, \
191 | Func_PMNT(___ptr_fp, ##__VA_ARGS__), \
192 | __END__
193 | #define Func_FastPMNTS(...) \
194 | Func_FastPMNT(ptr_ErrorFileStream, ##__VA_ARGS__)
195 |
196 | #define Func_PrintMessageNeedSpace(___ptr_fp,...) \
197 | _ftprintf(___ptr_fp, _T(" ")), \
198 | _ftprintf(___ptr_fp, ##__VA_ARGS__)
199 | #define Func_PMNS(___ptr_fp,...) \
200 | Func_PrintMessageNeedSpace(___ptr_fp, ##__VA_ARGS__)
201 | #define Func_PMNStdout(...) \
202 | Func_PMNS(stdout, ##__VA_ARGS__)
203 | #define Func_PMNStderr(...) \
204 | Func_PMNS(stderr, ##__VA_ARGS__)
205 | #define Func_PMNSS(...) \
206 | Func_PMNS(ptr_ErrorFileStream, ##__VA_ARGS__)
207 |
208 | #define Func_FastPMNS(___ptr_fp,...) \
209 | __BEGIN__, \
210 | Func_PMNS(___ptr_fp, ##__VA_ARGS__), \
211 | __END__
212 | #define Func_FastPMNSS(...) \
213 | Func_FastPMNS(ptr_ErrorFileStream, ##__VA_ARGS__)
214 |
215 | #endif /*End not support c++11 feature compile*/
216 |
217 | #endif /*Haven't define any compile type macro*/
218 |
219 | inline void * ___Func__Check_File_Set(void){
220 | if (!is_ErrorFileSet) SetLastError(ERROR_FILE_OFFLINE);
221 | return _pNULL_;
222 | }
223 |
224 | inline void * __fastcall ___Func_Close_File_Stream(FILE * ___ptr_fp){
225 | if (!___ptr_fp && ptr_ErrorFileStream) fclose(ptr_ErrorFileStream),ptr_ErrorFileStream=_pNULL_;
226 | else fclose(___ptr_fp),___ptr_fp=_pNULL_;
227 | return _pNULL_;
228 | }
229 |
230 | FILE * Func_SetErrorFileEx(const TCHAR * _FileName_,const TCHAR * _StreamStatus){
231 | if (!(ptr_ErrorFileStream=_tfopen(_FileName_,_StreamStatus)))
232 | MessageBox(_pNULL_,_T("_tfopen() Error!"),_T("Fatal Error!(cause by: ptrerr.hpp)"),MB_SETFOREGROUND|MB_ICONSTOP);
233 | return ptr_ErrorFileStream;
234 | }
235 |
236 | FILE * Func_SetErrorFile(const TCHAR * _FileName_,const TCHAR * _StreamStatus){
237 | sz__ErrorFileName__=_FileName_;
238 | sz__ErrorFileStream__=_StreamStatus;
239 | if (!(ptr_ErrorFileStream=_tfopen(_FileName_,_StreamStatus)))
240 | MessageBox(_pNULL_,_T("_tfopen() Error!"),_T("Fatal Error!(cause by: ptrerr.hpp)"),MB_SETFOREGROUND|MB_ICONSTOP);
241 | return ptr_ErrorFileStream;
242 | }
243 |
244 | inline int __fastcall ___Func_PrintErrorTimeToFileStream(FILE * ___ptr_fp){
245 | SYSTEMTIME _st_={0,0,0,0,0,0,0,0};
246 | GetLocalTime(&_st_);
247 | return _ftprintf(___ptr_fp,_T("%04d/%02d/%02d %02d:%02d:%02d "),_st_.wYear,_st_.wMonth,
248 | _st_.wDay,_st_.wHour,_st_.wMinute,_st_.wSecond);
249 | }
250 |
--------------------------------------------------------------------------------
/object-runwithcode/choose.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * This source code was published under GPL v3
3 | *
4 | * Copyright (C) 2016-2018 Too-Naive
5 | *
6 | */
7 |
8 |
9 | #include
10 | #include
11 | #include
12 | #include
13 | #include
14 |
15 | #define WIN32_LEAN_AND_MEAN
16 |
17 | #define ExecutableFileName _T("tool.exe")
18 |
19 | TCHAR const *szParameters[]={
20 | _T("svc"), //for backward compatibility
21 | _T("fi"), //1
22 | _T("fu"), //2
23 | _T("hardreset"), //3
24 | _T("-debug-reset"), //4
25 | _T("fi2"), //5
26 | _T("?"), //6
27 | _T("-debug-stop"), //7
28 | _T("-debug-start"), //8
29 | _T("-debug-reiu"), //9
30 | _T("-debug-pipe"), //10
31 | _T("--pipe"), //11
32 | _T("r"), //12
33 | _T("h"),
34 | _T("h2")
35 | };
36 |
37 | TCHAR const * showNotice="\
38 | 1. Run normaly\n\
39 | 2. Install automanic update service\n\
40 | 3. Uninstall automanic update service\n\
41 | 4. Reset Hosts File\n\
42 | 5. Reset Hosts File(Set to Default Hosts File)\n\
43 | 6. Show help message\n\
44 | 7. Open debug mode to listen service\n\
45 | 8. Stop Service\n\
46 | 9. Start Service\n\
47 | 10. Open \".ini\" file\n\
48 | 11. Install automantic update process(via normal mode to start)\n\
49 | ";
50 | const int max_input_int=11;
51 |
52 |
53 | TCHAR _[20]=_T("");
54 |
55 | int _tmain(int,TCHAR const **){
56 | SetConsoleTitle(_T("Run Execute"));
57 | int inputn;
58 | const TCHAR * str=_T("");
59 | _tprintf(_T("Program mode list:\n%s\n"),showNotice);
60 | _tprintf(_T("Please enter the number what you want to run:"));
61 | _tscanf(_T("%d"),&inputn);
62 | if (inputn>max_input_int || inputn<1) abort();
63 | switch (inputn){
64 | case 1:ShellExecute(NULL,_T("open"),ExecutableFileName,NULL,NULL,SW_SHOWNORMAL);
65 | exit(0);
66 | case 2:str=_T("fi");break;
67 | case 3:str=_T("fu");break;
68 | case 4:
69 | case 5:str=_T("r");break;
70 | case 6:str=_T("?");break;
71 | case 7:str=szParameters[10];break;
72 | case 8:str=szParameters[7];break;
73 | case 9:str=szParameters[8];break;
74 | case 10:ShellExecute(NULL,_T("open"),_T("notepad"),_T(" %windir%\\hstool.ini"),NULL,SW_SHOWDEFAULT);
75 | exit(0);
76 | case 11:str=szParameters[5];break;
77 | // case 12:str=szParameters[13];break;
78 | }
79 | if (inputn==5)
80 | _stprintf(_,_T("-%s %s"),str,szParameters[3]);
81 | else _stprintf(_,_T("-%s"),str);
82 | ShellExecute(NULL,_T("open"),ExecutableFileName,_,NULL,SW_SHOWNORMAL);
83 | }
84 |
--------------------------------------------------------------------------------
/object-runwithcode/choose.exe.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/object-runwithcode/choose.rc:
--------------------------------------------------------------------------------
1 | 1 24 "choose.exe.manifest"
2 |
--------------------------------------------------------------------------------
/object-runwithcode/g++make.bat:
--------------------------------------------------------------------------------
1 | @set TARGETNAME=choose
2 | @set LDCOMMAND=
3 | windres %TARGETNAME%.rc -o tmp.o
4 | g++ -o %TARGETNAME%.exe %TARGETNAME%.cpp tmp.o -s %LDCOMMAND% -O2
5 | del /q tmp.o
6 | pause
--------------------------------------------------------------------------------
/tool.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * This source code was published under GPL v3
3 | *
4 | * Copyright (C) 2016-2018 Too-Naive
5 | *
6 | */
7 |
8 | #include
9 | #include
10 | #include
11 | #include "header/download.hpp"
12 | #include
13 | #include
14 | #include "header/ptrerr.hpp"
15 | #include "header/diff.hpp"
16 | #include
17 | #include "header/pipedebug.hpp"
18 | #include "header/default.hpp"
19 |
20 | #define WIN32_LEAN_AND_MEAN
21 |
22 | //For microsoft visual studio debug(online)
23 |
24 | #ifdef _MSC_VER
25 | #pragma warning (disable:4996 4390)
26 | #endif
27 |
28 | #ifdef _TESTONLINE
29 | #undef MessageBox
30 | #define MessageBox(Reserved1,x,reserved2,reserved3) \
31 | _tprintf(_T("%s\n"),x),exit(0)
32 | #define callsystempause ((void*)0)
33 | #else
34 | #define callsystempause system("pause")
35 | #endif
36 |
37 | //end.
38 |
39 | #define DEFBUF(x,y) x[y]=_T("")
40 | #define THROWERR(x) throw expection(x)
41 |
42 | //Hosts file web address set
43 | #define hostsfile _T("https://raw.githubusercontent.com/googlehosts/hosts/master/hosts-files/hosts")
44 | //#define hostsfile1 _T("https://coding.net/u/scaffrey/p/hosts/git/raw/master/hosts-files/hosts")
45 |
46 | #ifdef _LOCAL
47 | #undef hostsfile
48 | #undef hostsfile1
49 | // #ifdef _LOCAL
50 | #define hostsfile _T("http://localhost/hosts")
51 | #define hostsfile1 hostsfile
52 | /* #else
53 | #define hostsfile1 hostsfile
54 | #endif*/
55 | #endif
56 | #define objectwebsite _T("https:\x2f\x2fgithub.com/HostsTools/Windows")
57 | //end.
58 |
59 | #define ConsoleTitle _T("googlehosts tool v2.2.1 Build time:Jan. 17th, '18")
60 |
61 | #define CASE(x,y) case x : y; break;
62 | #define DEBUGCASE(x) CASE(x,___debug_point_reset(x))
63 | #define pWait _T("\n \
64 | There seems something wrong in download file, we will retry after 5 seconds.\n")
65 |
66 | #define createT(x) CreateThread(_pNULL_,0,(x),_pNULL_,0,_pNULL_)
67 |
68 | //tmpfile set
69 | #define DownLocated _T("hosts.tmp")
70 | #define ChangeCTLR _T("hostsq.tmp")
71 | #define ReservedFile _T("hosts_n.tmp")
72 | //end.
73 |
74 | #define BAD_EXIT \
75 | _tprintf(_T("Bad Parameters.\nUsing \"-?\" Parameter to show how to use.\n")),\
76 | abort();
77 | #define _BAKFORMAT _T("%s\\drivers\\etc\\hosts.%04d%02d%02d.%02d%02d%02d.bak")
78 |
79 | //debug & log file set
80 | #define LogFileLocate _T("c:\\Hosts_Tool_log.log")
81 | const TCHAR * pipeName=_T("\\\\.\\pipe\\hoststoolnamepipe");
82 | #define szErrMeg _T("\nFatal Error:\n%s (GetLastError():%ld)\n\
83 | Please contact the application's support team for more information.\n")
84 | using namespace __Dpipe;
85 | //end.
86 |
87 | //service name
88 | //for backward compatibility DO NOT CHANGE IT
89 | TCHAR Sname[]=_T("racaljk-hoststool");
90 | TCHAR const *SzName[]={
91 | Sname
92 | };
93 | const TCHAR * szServiceShowName=_T("googlehosts Tool");
94 | //end
95 |
96 | //register key name
97 | const TCHAR * _keyname=_T("hoststool-windows");
98 | //end
99 |
100 | const size_t localbufsize=1024;
101 |
102 | //private file const set
103 | const TCHAR * privateFileName=_T("hstool.ini");
104 | const TCHAR * privateAppName=_T("toolIgnore");
105 | const TCHAR * privateCommitName=_T("Commit");
106 | const TCHAR * privateNewLineName=_T("NewLine");
107 | //end
108 |
109 | struct expection{
110 | const TCHAR *Message;
111 | expection(const TCHAR * _1){
112 | this->Message=_1;
113 | }
114 | };
115 |
116 | #define SHOW_HELP _T("%s\n\
117 | Usage: tool [-? | -r | -fi | -fu | --debug-pipe]\n\n\
118 | Options:\n\
119 | -? : Show this help message.\n\
120 | -r : Reset system hosts file to default.\n\
121 | -fi : Install Auto-Update hosts service(Service Name:%s).\n\
122 | -fu : Uninstall service.\n\
123 | --debug-pipe : Debug Mode(reserved for deverloper)\n\
124 | Example:\n\
125 | tool -fi\n\n\
126 | If you need more imformation about debug mode,\n\
127 | Please see the page in: https:\x2f\x2fgit.io/vwjyB\n\n")
128 |
129 | #define welcomeShow _T("\
130 | **********************************************\n\
131 | * *\n\
132 | * *\n\
133 | * *\n\
134 | * Welcome to use googlehosts/hosts tool! *\n\
135 | * *\n\
136 | * *\n\
137 | * Powered by: @Too-Naive *\n\
138 | **********************************************")
139 |
140 | #define copyrightshow _T("\
141 | ------------------------------------------------------------\n\
142 | Hosts Tool for Windows Console by: Too-Naive\n\
143 | Copyright (C) 2016-2018 @Too-Naive License:General Public License\n\
144 | ------------------------------------------------------------\n")
145 |
146 | //Global variable
147 | SERVICE_STATUS_HANDLE ssh;
148 | SERVICE_STATUS ss;
149 | HANDLE lphdThread[]={
150 | INVALID_HANDLE_VALUE,INVALID_HANDLE_VALUE
151 | };
152 | bool request_client,bIsServiceMode,bIgnoreNewline,bIgnoreCommit,bIsNulFile=true;
153 | WIN32_FIND_DATA wfd={0,{0,0},{0,0},{0,0},0,0,0,0,{0},{0}};
154 | //end.
155 |
156 | //function declaration
157 | int __fastcall __Check_Parameters(int,TCHAR const**);
158 | void WINAPI Service_Main(DWORD, LPTSTR *);
159 | void WINAPI Service_Control(DWORD);
160 | void Func_Service_Install(bool);
161 | void Func_Service_UnInstall(bool);
162 | DWORD __stdcall NormalEntry(LPVOID);
163 | void ___debug_point_reset(int);
164 | inline void __show_str(TCHAR const *,TCHAR const *,TCHAR const *);
165 | void Func_ResetFile();
166 | void ___Func_pipeCallBack(TCHAR const*);
167 | void Func_CallCopyHostsFile();
168 | void Func_CheckProFile();
169 | TCHAR * dotdotcheck(TCHAR *);
170 | void Func_countBackupFile(SYSTEMTIME *);
171 | bool Func_checkBackupFileTime(const SYSTEMTIME & , TCHAR const *);
172 | DWORD WINAPI MonitorServiceThread(LPVOID);
173 | inline bool Func_checkBusyTime();
174 | void Func_hiddenStart(const TCHAR *);
175 | void Func_hiddenEntry();
176 | void Func_installHiddenStart(const TCHAR *);
177 | //DWORD __stdcall Func_Update(LPVOID);
178 |
179 |
180 | SERVICE_TABLE_ENTRY STE[2]={{Sname,Service_Main},{_pNULL_,_pNULL_}};
181 |
182 | //define buffer
183 | TCHAR DEFBUF(buf1,localbufsize),DEFBUF(buf2,localbufsize),
184 | DEFBUF(buf3,localbufsize),DEFBUF(szline,localbufsize);
185 | char iobuffer[localbufsize];
186 | //end.
187 |
188 | //define parameters
189 | #define EXEC_START_NORMAL (1<<0x00)
190 | //#define EXEC_START_RUNAS (1<<0x01)
191 | #define EXEC_START_SERVICE (1<<0x02)
192 | #define EXEC_START_INSTALL_SERVICE (1<<0x03)
193 | #define EXEC_START_UNINSTALL_SERVICE (1<<0x04)
194 | #define EXEC_START_HELP (1<<0x05)
195 | //#define SHOW_LICENSE (1<<0x06)
196 | #define RESET_FILE (1<<0x07)
197 | #define EXEC_BAD_PARAMETERS (1073741824)
198 | #define EXEC_START_INSTALL2 (1<<0x06|EXEC_START_INSTALL_SERVICE)
199 | #define EXEC_HIDDEN_START (1<<0x01)
200 | #define EXEC_HIDDEN_STARTED (EXEC_HIDDEN_START|1<<0x03)
201 | #define EXEC_START_UNINSTALL_SERVICE2 (1<<0x06|EXEC_START_UNINSTALL_SERVICE)
202 |
203 | #define DEBUG_ENTRY (1<<0x00)
204 | #define EXEC_DEBUG_RESET (DEBUG_ENTRY|(1<<0x01))
205 | #define DEBUG_SERVICE_STOP (DEBUG_ENTRY|(1<<0x02))
206 | #define DEBUG_SERVICE_START (DEBUG_ENTRY|(1<<0x03))
207 | #define DEBUG_SERVICE_REINSTALL (DEBUG_ENTRY|(1<<0x04))
208 | #define OPEN_LISTEN (DEBUG_ENTRY|(1<<0x05))
209 |
210 | #define STOP_WITH_RESTART (1<<0x02)
211 | //end.
212 |
213 | //define _In_ parameters string
214 | TCHAR const *szParameters[]={
215 | _T("svc"), //for backward compatibility
216 | _T("fi"), //1
217 | _T("fu"), //2
218 | _T("hardreset"), //3
219 | _T("-debug-reset"), //4
220 | _T("fi2"), //5
221 | _T("?"), //6
222 | _T("-debug-stop"), //7
223 | _T("-debug-start"), //8
224 | _T("-debug-reiu"), //9
225 | _T("-debug-pipe"), //10
226 | _T("--pipe"), //11
227 | _T("r"), //12
228 | _T("h"),
229 | _T("h2")
230 | };
231 |
232 | //Check parameters function
233 | int __fastcall __Check_Parameters(int argc,TCHAR const **argv){
234 | if (argc==1) return EXEC_START_NORMAL;
235 | if (argc>3||!(( argv[1][0]==_T('/') ||
236 | argv[1][0]==_T('-')) && argv[1][1]!=_T('\0'))) BAD_EXIT;
237 | size_t i=0;
238 | for (;_tcscmp(&(argv[1][1]),szParameters[i]) &&
239 | i2) BAD_EXIT;
242 | if (argc==3 &&
243 | (!_tcscmp(argv[2],szParameters[11]) || !_tcscmp(argv[2],szParameters[3])))
244 | request_client=1;
245 | else if (argc==3 && !request_client) BAD_EXIT;
246 | switch (i){
247 | case 0: bIsServiceMode=true;
248 | return EXEC_START_SERVICE;
249 | case 1: return EXEC_START_INSTALL_SERVICE;
250 | case 2: return EXEC_START_UNINSTALL_SERVICE;
251 | case 4: return EXEC_DEBUG_RESET; //restart service
252 | case 5: return EXEC_START_INSTALL2;
253 | case 6: return EXEC_START_HELP;
254 | case 7: return DEBUG_SERVICE_STOP; //stop service
255 | case 8: return DEBUG_SERVICE_START; //start service
256 | case 9: return DEBUG_SERVICE_REINSTALL;//reinstall service
257 | case 10: return OPEN_LISTEN;
258 | case 12: return RESET_FILE;
259 | case 13: return EXEC_HIDDEN_START;
260 | case 14: return EXEC_HIDDEN_STARTED;
261 | default: BAD_EXIT;
262 | }
263 | BAD_EXIT;
264 | }
265 | //end.
266 |
267 | //main entry
268 | int _tmain(int argc,TCHAR const ** argv){
269 | SetConsoleTitle(ConsoleTitle);
270 | try {
271 | switch (__Check_Parameters(argc,argv)){
272 | CASE(EXEC_START_NORMAL,NormalEntry(_pNULL_));
273 | CASE(EXEC_START_INSTALL_SERVICE,Func_Service_Install(true));
274 | CASE(EXEC_START_UNINSTALL_SERVICE,Func_Service_UnInstall(true));
275 | CASE(EXEC_START_SERVICE,StartServiceCtrlDispatcher(STE));
276 | CASE(EXEC_START_HELP,__show_str(SHOW_HELP,copyrightshow,Sname));
277 | // CASE(SHOW_LICENSE,__show_str(szgpl_Raw,_pNULL_));
278 | DEBUGCASE(EXEC_DEBUG_RESET);
279 | DEBUGCASE(DEBUG_SERVICE_STOP);
280 | DEBUGCASE(DEBUG_SERVICE_START);
281 | DEBUGCASE(DEBUG_SERVICE_REINSTALL);
282 | CASE(OPEN_LISTEN,___debug_point_reset(OPEN_LISTEN));
283 | CASE(RESET_FILE,Func_ResetFile());
284 | CASE(EXEC_HIDDEN_START,Func_hiddenStart(argv[0]));
285 | CASE(EXEC_HIDDEN_STARTED,Func_hiddenEntry());
286 | CASE(EXEC_START_INSTALL2,Func_installHiddenStart(argv[0]));
287 | default:break;
288 | }
289 | }
290 | catch (...){
291 |
292 | }
293 | return 0;
294 | }
295 |
296 | void Func_hiddenStart(const TCHAR * _exec){
297 | ShellExecute(NULL,_T("open"),_exec,_T("-h2"),NULL,SW_HIDE);
298 | exit(0);
299 | }
300 |
301 | void Func_hiddenEntry(){
302 | bIsServiceMode=true;
303 | Func_SetErrorFile(LogFileLocate,_T("a+"));
304 | Sleep(30000);//waiting for network
305 | NormalEntry(_pNULL_);
306 | //TODO: if program throw expections, user may cannot find error.
307 | return ;
308 | }
309 |
310 | void Func_installHiddenStart(const TCHAR * __path){
311 | HKEY _hkey_=_pNULL_;
312 | try {
313 | if (!GetSystemDirectory(buf1,localbufsize))
314 | _tprintf(_T("GetSystemDirectory() Failed.(%ld)\n"),GetLastError());
315 | _stprintf(buf2,_T("%s\\..\\hostsstart.exe"),buf1);
316 | dotdotcheck(buf2);
317 | if (!CopyFile(__path,buf2,FALSE))
318 | THROWERR(_T("CopyFile() Failed in Func_installHiddenStart().\n"));
319 | _stprintf(buf1,_T("\"%s\" -h"),buf2);
320 | if (RegOpenKey(HKEY_LOCAL_MACHINE,_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"),&_hkey_))
321 | THROWERR(_T("RegOpenKey() Error!\n"));
322 | if (ERROR_FILE_NOT_FOUND==RegQueryValueEx(_hkey_,_keyname,NULL,NULL,NULL,NULL))
323 | if (RegSetValueEx(_hkey_,_keyname,0,REG_SZ,(BYTE *)buf1,_tcslen(buf1)))
324 | THROWERR(_T("RegSetValueEx() Error!\n"));
325 | }
326 |
327 | catch (expection r){
328 | if (!_hkey_) RegCloseKey(_hkey_);
329 | // FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,NULL,0,0,szline,localbufsize,NULL);
330 | _tprintf(szErrMeg,r.Message,GetLastError());
331 | _tprintf(_T("\n[Debug Message]\n%s\n%s\n%s\n"),buf1,buf2,buf3);
332 | abort();
333 | }
334 | RegCloseKey(_hkey_);
335 | MessageBox(_pNULL_,_T("Register statrup successfully."),_T("Congratulations!"),MB_OK|MB_ICONINFORMATION);
336 | return ;
337 | }
338 | /*
339 | void Func_uninstallHiddenStart(){
340 | HKEY _hkey_=_pNULL_;
341 | try {
342 | if (RegOpenKey(HKEY_LOCAL_MACHINE,_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"),&_hkey_))
343 | THROWERR(_T("RegOpenKey() Error!\n"));
344 | if (ERROR_FILE_NOT_FOUND==RegQueryValueEx(_hkey_,_keyname,NULL,NULL,NULL,NULL))
345 | if (!RegSetValueEx(_hkey_,_keyname,0,REG_SZ,(BYTE *)buf1,_tcslen(buf1)))
346 | THROWERR(_T("RegSetValueEx() Error!\n"));
347 | RegDeleteValue(HKEY_LOCAL_MACHINE,_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"));
348 | }
349 | catch (expection r){
350 | if (!_hkey_) RegCloseKey(_hkey_);
351 | _tprintf(szErrMeg,r.Message,GetLastError());
352 | _tprintf(_T("\n[Debug Message]\n%s\n%s\n%s\n"),buf1,buf2,buf3);
353 | abort();
354 | }
355 | RegCloseKey(_hkey_);
356 | MessageBox(_pNULL_,_T("Register statrup successfully."),_T("Congratulations!"),MB_OK|MB_ICONINFORMATION);
357 | return ;
358 | }
359 | */
360 | void Func_CheckProFile(){
361 | SetLastError(ERROR_SUCCESS);
362 | GetPrivateProfileString(privateAppName,
363 | privateCommitName,
364 | _T("false"),
365 | szline,
366 | localbufsize,
367 | privateFileName);
368 | // printf("%ld",GetLastError());
369 | if (GetLastError()==ERROR_FILE_NOT_FOUND){
370 | WritePrivateProfileString(privateAppName,
371 | privateCommitName,
372 | _T("false"),
373 | privateFileName);
374 | WritePrivateProfileString(privateAppName,
375 | privateNewLineName,
376 | _T("false"),
377 | privateFileName);
378 | }
379 | if (!_tcscmp(szline,_T("true"))) bIgnoreCommit=true;
380 | GetPrivateProfileString(privateAppName,
381 | privateNewLineName,
382 | _T("false"),
383 | szline,
384 | localbufsize,
385 | privateFileName);
386 | if (!_tcscmp(szline,_T("true"))) bIgnoreNewline=true;
387 | return ;
388 | }
389 |
390 | namespace __Dpipe{
391 | DWORD ___OnError(const TCHAR *__szAdditionalMessage){
392 | Func_FastPMNTS(_T("%s() Error! (%ld)\n"),__szAdditionalMessage,GetLastError());
393 | //We need it?
394 | ss.dwServiceSpecificExitCode=STOP_WITH_RESTART;
395 | ss.dwWin32ExitCode=ERROR_SERVICE_SPECIFIC_ERROR;
396 | ss.dwCurrentState=SERVICE_STOPPED;
397 | SetServiceStatus(ssh,&ss);
398 | ExitProcess(1);
399 | return GetLastError();
400 | }
401 | }
402 |
403 | void Func_ResetFile(){
404 | SYSTEMTIME st={0,0,0,0,0,0,0,0};
405 | bool chk=false;
406 | _tprintf(copyrightshow);
407 | if (!GetSystemDirectory(buf3,localbufsize))
408 | _tprintf(_T(" GetSystemDirectory() Error!(GetLastError():%ld)\n\
409 | \tCannot get system path!"),GetLastError()),abort();
410 | GetLocalTime(&st);
411 | _stprintf(buf1,_T("%s\\drivers\\etc\\hosts"),buf3);
412 | _stprintf(buf2,_BAKFORMAT,buf3,st.wYear,st.wMonth,st.wDay,st.wHour,st.wMinute,st.wSecond);
413 | if (CopyFile(buf1,buf2,FALSE))
414 | _tprintf(_T("Backup File success\nFilename:%s\n\n"),buf2);
415 | else
416 | _tprintf(_T("Unable to backup file.(%ld)\n"),GetLastError()),abort();
417 | //reset file start
418 | FILE *fp=_tfopen(buf1,request_client?_T("w"):_T("r"));
419 | if (!fp) {//,abort();
420 | if (request_client){
421 | _tprintf(_T("Cannot open file!\nUsing plan B.\n"));
422 | fp=_tfopen(ReservedFile,_T("w"));
423 | fclose(fp);
424 | fp=_pNULL_;
425 | chk=true;
426 | }else{
427 | _tprintf(_T("Cannot open file!\n"));
428 | abort();
429 | }
430 | }
431 | if (request_client){
432 | if (chk) {
433 | if (!CopyFile(ReservedFile,buf1,FALSE)){
434 | _stprintf(szline,
435 | _T("CopyFile() Failed!(%ld)\nPlease copy the \"%s\" file to\
436 | \"%%systemroot%%\\drivers\\etc\\hosts\" Manually."),
437 | GetLastError(),ReservedFile);
438 | MessageBox(NULL,_T("Fatal Error"),szline,MB_SETFOREGROUND|MB_ICONSTOP);
439 | abort();
440 | }
441 | }
442 | else _ftprintf(fp,_T("%s"),szDefatult_hostsfile);
443 | fclose(fp);
444 | _tprintf(_T(" Reset file successfully.\n"));
445 | callsystempause;
446 | ExitProcess(0);
447 | }
448 | if (!GetEnvironmentVariable(_T("TEMP"),szline,localbufsize))
449 | _tprintf(_T("Can't get TEMP path, using current directory.(%ld)\n"),
450 | GetLastError()),
451 | *szline=_T('.');
452 | SetCurrentDirectory(szline);
453 | FILE * _=_tfopen(ReservedFile,_T("w"));
454 | if (!_) _tprintf(_T("Can't open \"%s\" file.\n"),ReservedFile),abort();
455 | // memset(buf3,0,sizeof(buf3));
456 | while (!feof(fp)){
457 | memset(szline,0,sizeof(szline));
458 | _fgetts(szline,localbufsize,fp);
459 | if (_tcsstr(szline,_T("googlehosts members")))
460 | _fputts(szline,_);
461 | else break;
462 | }
463 | fclose(fp);
464 | fclose(_);
465 | if (!CopyFile(ReservedFile,buf1,FALSE))
466 | _tprintf(_T("CopyFile() Failed.(%ld)\nPlease copy the \"%s\" file to \
467 | \"%%systemroot%%\\drivers\\etc\\hosts\" Manually."),GetLastError(),ReservedFile),
468 | abort();
469 | //reset file end
470 | DeleteFile(ReservedFile);
471 | _tprintf(_T(" Reset file successfully.\n"));
472 | callsystempause;
473 | return ;
474 | }
475 |
476 | void __abrt(int){
477 | SetConsoleTitle(_T("Recieved signal SIGINT"));
478 | _tprintf(_T("Received signal SIGINT\nPlease waiting program exit!\n"));
479 | request_client=0;
480 | _tprintf(_T("Uninstall service.\n"));
481 | Func_Service_UnInstall(false);
482 | TerminateThread(lphdThread[0],0);
483 | if (!lphdThread[1]) TerminateThread(lphdThread[1],0);
484 | CloseHandle(lphdThread[0]);
485 | CloseHandle(lphdThread[1]);
486 | CloseHandle(hdPipe);
487 | _tprintf(_T("Program will now exit.\n"));
488 | exit(0);
489 | }
490 |
491 | void __abrt1(int){
492 | for (int i=3;i--;_tprintf(_T("Please check anti-virus software then open this program again.\n")));
493 | }
494 |
495 |
496 | inline void __show_str(TCHAR const* st,TCHAR const * str2,TCHAR const * str3){
497 | _tprintf(st,str2,str3);
498 | callsystempause;
499 | return ;
500 | }
501 |
502 | void ___debug_point_reset(int _par){
503 | SC_HANDLE shMang=_pNULL_,shSvc=_pNULL_;
504 | if (_par==DEBUG_SERVICE_REINSTALL){
505 | Func_Service_UnInstall(false);
506 | Func_Service_Install(false);
507 | return ;
508 | }
509 | try {
510 | if (_par!=OPEN_LISTEN) {
511 | if (!(shMang=OpenSCManager(_pNULL_,_pNULL_,SC_MANAGER_ALL_ACCESS)))
512 | THROWERR(_T("OpenSCManager() Error in debug_reset."));
513 | if (!(shSvc=OpenService(shMang,Sname,SERVICE_STOP|SERVICE_START)))
514 | THROWERR(_T("OpenService() Error in debug_reset."));
515 | }
516 | switch(_par){
517 | case DEBUG_SERVICE_STOP:
518 | case EXEC_DEBUG_RESET:
519 | if (!ControlService(shSvc,SERVICE_CONTROL_STOP,&ss))
520 | THROWERR(_T("ControlService() Error in debug_reset."));
521 | Sleep(1000);
522 | if (_par==DEBUG_SERVICE_STOP) break;
523 | case OPEN_LISTEN:
524 | if (_par!=EXEC_DEBUG_RESET){
525 | signal(SIGINT,__abrt);
526 | _tprintf(_T(" Warning:\n \
527 | You are in debug mode, please press CTRL+C to exit the debug mode.\n\t\t\
528 | DO NOT CLOSE THE CONSOLE DIRECT!!!\n"));
529 | request_client=1;
530 | _tprintf(_T("Reinstall service\n"));
531 | ___debug_point_reset(DEBUG_SERVICE_REINSTALL);
532 | ___debug_point_reset(DEBUG_SERVICE_START);
533 | if (!(lphdThread[0]=createT(OpenPipeService)))
534 | THROWERR(_T("CreateThread() Error!"));
535 | if (!(lphdThread[1]=createT(MonitorServiceThread)))
536 | _tprintf(_T("CreateThread() Error! in\
537 | create MonitorServiceThread.(%ld)\n"),GetLastError());
538 | WaitForSingleObject(lphdThread[0],INFINITE);
539 | CloseHandle(hdPipe);
540 | return ;
541 | }
542 | case DEBUG_SERVICE_START:
543 | if (!StartService(shSvc,1,SzName))
544 | THROWERR(_T("StartService() Error in debug_reset."));
545 | default : break;
546 | }
547 | }
548 | catch (expection _r){
549 | _tprintf(_T("\nFatal Error:\n%s (GetLastError():%ld)\n\
550 | Please contact the application's support team for more information.\n"),
551 | _r.Message,GetLastError());
552 | CloseServiceHandle(shSvc);
553 | CloseServiceHandle(shMang);
554 | abort();
555 | }
556 | CloseServiceHandle(shSvc);
557 | CloseServiceHandle(shMang);
558 | return ;
559 | }
560 |
561 | DWORD WINAPI MonitorServiceThread(LPVOID){
562 | SC_HANDLE shMang=_pNULL_,shSvc=_pNULL_;
563 | if (!(shMang=OpenSCManager(_pNULL_,_pNULL_,SC_MANAGER_ALL_ACCESS))){
564 | _tprintf(_T("OpenSCManager() Error in Monitor.(%ld)\n"),GetLastError());
565 | abort();
566 | }
567 | if (!(shSvc=OpenService(shMang,Sname,SERVICE_QUERY_STATUS))){
568 | if (GetLastError()==ERROR_SERVICE_NOT_FOUND){
569 | CloseServiceHandle(shMang);
570 | ___debug_point_reset(DEBUG_SERVICE_REINSTALL);
571 | }
572 | else{
573 | _tprintf(_T("OpenService() Error in Monitor.(%ld)\n"),GetLastError());
574 | abort();
575 | }
576 | }
577 | SERVICE_STATUS mon_ss={0l,0l,0l,0l,0l,0l,0l};
578 | while (1){
579 | QueryServiceStatus(shSvc,&mon_ss);
580 | if (mon_ss.dwCurrentState==SERVICE_STOPPED || mon_ss.dwCurrentState==SERVICE_STOP_PENDING)
581 | if (mon_ss.dwWin32ExitCode==ERROR_SERVICE_SPECIFIC_ERROR &&
582 | mon_ss.dwServiceSpecificExitCode==STOP_WITH_RESTART){
583 | // ___debug_point_reset(DEBUG_SERVICE_REINSTALL);
584 | _tprintf(_T("This production may need restart to finish this.\n\
585 | Please press Ctrl+C to terminate program then restart again.\n\
586 | Error code:(%ld)\n"),GetLastError());
587 | break;
588 | }
589 | Sleep(1000);
590 | }
591 | CloseServiceHandle(shMang);
592 | CloseServiceHandle(shSvc);
593 | return GetLastError();
594 | }
595 |
596 | //short path if str has ".."
597 | //Should we need check "\\..\\" ?
598 | TCHAR * dotdotcheck(TCHAR * str){
599 | TCHAR * _,*_tmp=new TCHAR[MAX_PATH];
600 | memset(_tmp,0,sizeof(_tmp));
601 | if ((_=_tcsstr(str,_T("..")))){
602 | _stscanf(_+2,_T("%100s"),_tmp);
603 | --_;
604 | while ((*(--_))!='\\');
605 | _stprintf(_,_T("%s"),_tmp);
606 | }
607 | delete [] _tmp;
608 | return str;
609 | }
610 |
611 | void Func_Service_UnInstall(bool _quite){
612 | SC_HANDLE shMang=_pNULL_,shSvc=_pNULL_;
613 | Sleep(1000);
614 | try{
615 | if (!GetSystemDirectory(buf3,localbufsize))
616 | THROWERR(_T("GetSystemDirectory() Error in UnInstall Service."));
617 | _stprintf(buf1,_T("%s\\..\\hoststools.exe"),buf3);
618 | if (!GetModuleFileName(_pNULL_,buf2,localbufsize))
619 | THROWERR(_T("GetModuleFileName() Error in UnInstall Service."));
620 | if (!_tcscmp(dotdotcheck(buf1),buf2)){
621 | if (!GetEnvironmentVariable(_T("TEMP"),buf3,localbufsize))
622 | THROWERR(_T("GetEnvironmentVariable() Error in UnInstall Service."));
623 | _stprintf(buf1,_T("%s\\Au__.exe"),buf3);
624 | if (!CopyFile(buf2,buf1,FALSE))
625 | THROWERR(_T("CopyFile() Error(To temp directory) in UnInstall Service."));
626 | if (!ShellExecute(NULL,_T("open"),buf1,_T("-fu"),NULL,SW_SHOWNORMAL))
627 | THROWERR(_T("ShellExecute() Error in UnInstall Service."));
628 | exit(0);
629 | }
630 | if (!(shMang=OpenSCManager(_pNULL_,_pNULL_,SC_MANAGER_ALL_ACCESS)))
631 | THROWERR(_T("OpenSCManager() Error in Uninstall service."));
632 | if (!(shSvc=OpenService(shMang,Sname,SERVICE_ALL_ACCESS)))
633 | if (_quite)
634 | THROWERR(_T("OpenService() Error in Uninstall service.\nIs service exist?"));
635 | if (!ControlService(shSvc,SERVICE_CONTROL_STOP,&ss))
636 | if (_quite)
637 | _tprintf(_T("ControlService() Error in Uninstall service.\n%s"),
638 | _T("Service may not in running.\n"));
639 | Sleep(2000);//Wait for service stop
640 | if (!DeleteService(shSvc))
641 | if (_quite)
642 | THROWERR(_T("DeleteService() Error in UnInstall service."));
643 | if (!DeleteFile(buf1))
644 | if (_quite) {
645 | _tprintf(_T("Executable File located:%s\n"),buf1);
646 | THROWERR(_T("DeleteFile() Error in Uninstall service.\n\
647 | You may should delete it manually."));
648 | }
649 | }
650 | catch (expection _r){
651 | _tprintf(_T("\nFatal Error:\n%s (GetLastError():%ld)\n\
652 | Please contact the application's support team for more information.\n"),
653 | _r.Message,GetLastError());
654 | _tprintf(_T("\n[Debug Message]\n%s\n%s\n"),buf1,buf2);
655 | CloseServiceHandle(shSvc);
656 | CloseServiceHandle(shMang);
657 | if (_quite) abort();
658 | }
659 | CloseServiceHandle(shSvc);
660 | CloseServiceHandle(shMang);
661 | _tprintf(_T("Service Uninstall Successfully\n"));
662 | return ;
663 | }
664 |
665 | void Func_Service_Install(bool _q){
666 | SC_HANDLE shMang=_pNULL_,shSvc=_pNULL_;
667 | if (_q){
668 | _tprintf(_T(" LICENSE:General Public License\n \
669 | Copyright (C) 2016-2018 @Too-Naive\n\n"));
670 | _tprintf(_T(" Bug report:[hidden] \n\t \
671 | Or open new issue\n------------------------------------------------------\n\n"));
672 | }
673 | try {
674 | if (!GetSystemDirectory(buf3,localbufsize))
675 | THROWERR(_T("GetSystemDirectory() Error in Install Service."));
676 | _stprintf(buf1,_T("%s\\..\\hoststools.exe"),buf3);
677 | _stprintf(buf2,_T("\"%s\\..\\hoststools.exe\" -svc"),buf3);
678 | if (request_client)
679 | _stprintf(szline,_T("%s %s"),buf2,szParameters[11]),
680 | _tcscpy(buf2,szline),memset(szline,0,sizeof(szline)/sizeof(TCHAR));
681 | if (!GetModuleFileName(_pNULL_,szline,sizeof(szline)/sizeof(TCHAR)))
682 | THROWERR(_T("GetModuleFileName() Error in Install Service."));
683 | if (_q) _tprintf(_T(" Step1:Copy file.\n"));
684 | if (!CopyFile(szline,buf1,FALSE))
685 | THROWERR(_T("CopyFile() Error in Install Service.(Is service has been installed?)"));
686 | if (_q) _tprintf(_T(" Step2:Connect to SCM.\n"));
687 | if (!(shMang=OpenSCManager(_pNULL_,_pNULL_,SC_MANAGER_ALL_ACCESS)))
688 | THROWERR(_T("OpenSCManager() failed."));
689 | if (_q) _tprintf(_T(" Step3:Write service.\n"));
690 | if (!(shSvc=CreateService(shMang,
691 | Sname,
692 | szServiceShowName,
693 | SERVICE_ALL_ACCESS,
694 | SERVICE_WIN32_OWN_PROCESS,
695 | request_client?SERVICE_DEMAND_START:SERVICE_AUTO_START,
696 | SERVICE_ERROR_NORMAL,
697 | buf2,//Program located
698 | _pNULL_,
699 | _pNULL_,
700 | _pNULL_,
701 | _pNULL_,
702 | _pNULL_
703 | ))){
704 | if (GetLastError()==ERROR_SERVICE_EXISTS){
705 | if (!(shSvc=OpenService(shMang,Sname,SERVICE_ALL_ACCESS)))
706 | THROWERR(_T("OpenService() Error in install service."));
707 | if (!DeleteService(shSvc))
708 | THROWERR(_T("DeleteService() Error in Install Service."));
709 | CloseServiceHandle(shSvc);
710 | if (!(shSvc=CreateService(shMang,
711 | Sname,
712 | szServiceShowName,
713 | SERVICE_ALL_ACCESS,
714 | SERVICE_WIN32_OWN_PROCESS,
715 | request_client?SERVICE_DEMAND_START:SERVICE_AUTO_START,
716 | SERVICE_ERROR_NORMAL,
717 | buf2,
718 | _pNULL_,
719 | _pNULL_,
720 | _pNULL_,
721 | _pNULL_,
722 | _pNULL_
723 | )))
724 | THROWERR(_T("CreateService() failed.(2)")),CloseServiceHandle(shMang);
725 | }
726 | else
727 | THROWERR(_T("CreateService() failed."));
728 | }
729 | else
730 | _tprintf(_T("Install service successfully.\n"));
731 | if (!request_client){
732 | if (!(shSvc=OpenService(shMang,Sname,SERVICE_START)))
733 | THROWERR(_T("OpenService() Failed"));
734 | else
735 | if (!StartService(shSvc,1,SzName))
736 | THROWERR(_T("StartService() Failed."));
737 | else
738 | MessageBox(_pNULL_,_T("Service started successfully"),
739 | _T("Congratulations!"),
740 | MB_SETFOREGROUND|MB_ICONINFORMATION);
741 | }
742 | }
743 | catch (expection _r){
744 | _tprintf(_T("\nFatal Error:\n%s (GetLastError():%ld)\n\
745 | Please contact the application's support team for more information.\n"),
746 | _r.Message,GetLastError());
747 | _tprintf(_T("\n[Debug Message]\n%s\n%s\n%s\n"),buf1,buf2,buf3);
748 | abort();
749 | }
750 | CloseServiceHandle(shMang);
751 | CloseServiceHandle(shSvc);
752 | if (_q) system("pause");
753 | return ;
754 | }
755 |
756 | inline void __fastcall ___autocheckmsg(const TCHAR * szPstr){
757 | if (!request_client)
758 | Func_FastPMNTS(szPstr);
759 | else
760 | ___pipesendmsg(szPstr);
761 | }
762 |
763 | inline void __fastcall ___checkEx(const TCHAR * szPstr,bool space_need){
764 | if (!request_client)
765 | if (!space_need) Func_FastPMNSS(szPstr);
766 | else Func_FastPMNTS(szPstr);
767 | else
768 | ___pipesendmsg(szPstr);
769 | }
770 |
771 | inline void __fastcall _perr_T(const TCHAR * _str,bool _Reserved){
772 | if (!bIsServiceMode) _tprintf(_str);
773 | else if (_Reserved) Func_FastPMNTS(_str);
774 | else Func_FastPMNSS(_str);
775 | return ;
776 | }
777 |
778 | void ___Func_pipeCallBack(const TCHAR * str){
779 | _tprintf(_T("%s"),str);
780 | return ;
781 | }
782 |
783 | void Func_CallCopyHostsFile(SYSTEMTIME & st){
784 | FILE * filepoint1,*filepoint2;
785 | signal(SIGABRT,__abrt1);
786 |
787 | //empty file check
788 | if (!bIsNulFile){
789 | TCHAR ch;
790 | filepoint2=_tfopen(ReservedFile,_T("r"));
791 | for (ch=_fgettc(filepoint2);ch==_T(' ') || ch==_T('\n') || ch==_T('\r');ch=_fgettc(filepoint2));
792 | if (ch==EOF) bIsNulFile=true;
793 | }
794 | //end
795 |
796 | if (!CopyFile(buf1,buf2,FALSE))
797 | THROWERR(_T("CopyFile() Error on copy a backup file"));
798 | if (!bIsServiceMode) _tprintf(_T("\tDone.\n Step3:Replace Default Hosts File..."));
799 | if (!CopyFile(ReservedFile,buf1,FALSE))
800 | THROWERR(_T("CopyFile() Error on copy hosts file to system path"));
801 | try {
802 | if (!(filepoint2=_tfopen(buf1,_T("ab+"))))
803 | throw buf1;
804 | _fputts(_T(""),filepoint2);
805 | if (!(filepoint1=_tfopen(ChangeCTLR,_T("rb"))))
806 | throw ChangeCTLR;
807 | if (!bIsNulFile) _ftprintf(filepoint2,_T("\n"));
808 | size_t readbyte=0;
809 | while ((readbyte=fread(iobuffer,sizeof(char),localbufsize,filepoint1)))
810 | fwrite(iobuffer,sizeof(char),readbyte,filepoint2);
811 | fclose(filepoint1);fclose(filepoint2);
812 | }
813 | catch(TCHAR const * _FileName){
814 | _stprintf(szline,_T("_tfopen() Error in open \"%s\".\n"),_FileName);
815 | MessageBox(NULL,szline,_T("Error!"),MB_ICONSTOP|MB_SETFOREGROUND);
816 | abort();
817 | }
818 | if (!bIsServiceMode) _tprintf(_T("Replace File Successfully\n"));
819 | else ___autocheckmsg(_T("Replace File Successfully\n"));
820 | if (!bIsServiceMode) Func_countBackupFile(&st),MessageBox(_pNULL_,
821 | _T("Hosts File Set Success!"),
822 | _T("Congratulations!"),MB_ICONINFORMATION|MB_SETFOREGROUND);
823 | return ;
824 | }
825 |
826 |
827 | //TODO: temp C-Sytle string length only 1000(TCHAR)
828 | //Is safe for this program? I don't know.
829 |
830 | //Q:Why don't you use std::string?
831 | //A:STL will made my program so big(?)
832 |
833 | DWORD __stdcall NormalEntry(LPVOID){
834 | SYSTEMTIME st={0,0,0,0,0,0,0,0};
835 | FILE * fp=_pNULL_,*_=_pNULL_;
836 | HANDLE hdThread=INVALID_HANDLE_VALUE;
837 | if (!GetSystemDirectory(buf3,localbufsize))
838 | Func_PMNTTS(_T("GetSystemDirectory() Error!(GetLastError():%ld)\n\
839 | \tCannot get system path!"),GetLastError()),abort();
840 | _stprintf(buf1,_T("%s\\.."),buf3);
841 | SetCurrentDirectory(buf1);
842 | Func_CheckProFile();
843 | if (!GetEnvironmentVariable(_T("TEMP"),szline,localbufsize))
844 | Func_PMNTTS(_T("GetEnvironmentVariable() Error!(GetLastError():%ld)\n\
845 | \tCannot get %%TEMP%% path!"),GetLastError()),abort();
846 | SetCurrentDirectory(szline);
847 | if (!bIsServiceMode){
848 | _tprintf(_T(" LICENSE:General Public License\n%s\n\
849 | Copyright (C) 2016-2018 @Too-Naive\n"),welcomeShow);
850 | _tprintf(_T(" Project website:%s\n"),objectwebsite);
851 | _tprintf(_T(" Bug report:[hidden] \n\t\
852 | Or open new issue\n\n\n"));
853 | _tprintf(_T(" Start replace hosts file:\n"));
854 | } else {
855 | if (request_client) ___pipeopen(),___pipesendmsg(_T("\nMessage from service:\n\n"));
856 | Func_FastPMNTS(_T("Open log file.\n"));
857 | ___checkEx(_T("LICENSE:General Public License\n"),1);
858 | ___checkEx(_T("Copyright (C) 2016-2018 Too-Naive\n"),0);
859 | ___checkEx(_T("Bug report:[hidden]\n"),0);
860 | ___checkEx(_T(" Or open new issue.(https://github.com/HostsTools/Windows)\n"),0);
861 | }
862 | do {
863 | Sleep(bIsServiceMode?(request_client?0:60000):0);//Waiting for network
864 | GetLocalTime(&st);
865 | if (bIsServiceMode) ___autocheckmsg(_T("Start replace hosts file.\n"));
866 | _stprintf(buf1,_T("%s\\drivers\\etc\\hosts"),buf3);
867 | _stprintf(buf2,_BAKFORMAT,buf3,st.wYear,st.wMonth,st.wDay,st.wHour,
868 | st.wMinute,st.wSecond);
869 | SetFileAttributes(buf1,FILE_ATTRIBUTE_NORMAL);//To avoid CopyFile or _tfopen failed.
870 | try {
871 | if (!bIsServiceMode) _tprintf(_T(" Step1:Download hosts file..."));
872 | //download
873 | if (bIsServiceMode) if (request_client) ___pipesendmsg(_T("Download files\n"));
874 | for (int errcunt=0;(//!Func_Download(hostsfile1,DownLocated)&&
875 | !Func_Download(hostsfile,DownLocated));errcunt++)
876 | if (errcunt>2) THROWERR(_T("DownLoad hosts file Error!"));
877 | else if (!bIsServiceMode) {
878 | _tprintf(pWait);
879 | Sleep(bIsServiceMode?(request_client?1000:10000):5000);
880 | if (!bIsServiceMode) _tprintf(_T("\tDownload hosts file..."));
881 | }
882 | //end.
883 | if (!bIsServiceMode) _tprintf(_T("\tDone.\n Step2:Change Line Endings..."));
884 | try {
885 | //Change Line Ending
886 | //Open file and check if is open
887 | if (!(fp=_tfopen(DownLocated,_T("r"))))
888 | throw DownLocated;
889 | if (!(_=_tfopen(ChangeCTLR,_T("w"))))
890 | throw ChangeCTLR;
891 | //end, Read and Write to change the line ending to CRLF
892 | while (!feof(fp)){
893 | memset(szline,0,sizeof(szline));
894 | _fgetts(szline,localbufsize,fp);
895 | _fputts(szline,_);
896 | }
897 | fclose(fp);fclose(_);
898 | fp=_pNULL_,_=_pNULL_;
899 | //end
900 |
901 | //delete tmpfile
902 | if (!DeleteFile(DownLocated)){
903 | if (bIsServiceMode)
904 | Func_FastPMNTS(_T("Delete tmpfile error.(%ld)\n"),GetLastError());
905 | else
906 | _tprintf(_T("Delete tmpfile error.(%ld)\n"),GetLastError());
907 | }
908 |
909 | //Read user-defined hosts start
910 | //Open and check file is open?
911 | if (!(fp=_tfopen(buf1,_T("r"))))
912 | throw buf1;
913 | if (!(_=_tfopen(ReservedFile,_T("w"))))
914 | throw ReservedFile;
915 | while (!feof(fp)){ //checking is end of file?
916 | //to prevent print complex line
917 | memset(szline,0,sizeof(szline));
918 | _fgetts(szline,localbufsize,fp);
919 | if (*szline==_T('#')) { //fast check is comment
920 | //File original hosts start
921 | if (_tcsstr(szline,_T("googlehosts members")))
922 | break; else
923 | if (_tcsstr(szline,_T("\x72\x61\x63\x61\x6c\x6a\x6b")))
924 | break; //else
925 | // check is need ignore the commits
926 | if (bIgnoreCommit) continue;
927 | }
928 | //check is need ignore the new line
929 | if (bIgnoreNewline && *szline==_T('\n')) continue;
930 | //empty file check (if read least one line.)
931 | bIsNulFile=false;
932 | // print user-defined hosts to tmp file.
933 | _fputts(szline,_);
934 | }
935 | // close and save the file
936 | fclose(_);
937 | _=_pNULL_;
938 | //end
939 |
940 | //Critical function: Check is original file same with hosts file from network
941 | if (!feof(fp)){//check is original file is read in endof file?
942 | // no? start copy file function
943 | if (!(_=_tfopen(DownLocated,_T("w"))))
944 | throw DownLocated;
945 | _fputts(szline,_);
946 | while (!feof(fp)) {
947 | memset(szline,0,sizeof(szline));
948 | _fgetts(szline,localbufsize,fp);
949 | _fputts(szline,_);
950 | }
951 | fclose(_);
952 | }
953 | fclose(fp);
954 | fp=_pNULL_,_=_pNULL_;
955 | //end.
956 | }
957 |
958 | //catch area
959 | catch (TCHAR const * _FileName){
960 | _stprintf(szline,_T("Open \"%s\" Error(_tfopen() Error)!\n"),_FileName);
961 | MessageBox(NULL,szline,_T("Error!"),MB_ICONSTOP|MB_SETFOREGROUND);
962 | abort();
963 | }
964 | //end.
965 |
966 | if (!Func_CheckDiff(ChangeCTLR,DownLocated)){
967 | if (!bIsServiceMode) _tprintf(_T("\tDone.\n\n \
968 | Finish:Hosts file Not update.\n\n"));
969 | else ___autocheckmsg(_T("Finish:Hosts file Not update.\n\n"));
970 | if (!bIsServiceMode) {
971 | Func_countBackupFile(&st);
972 | callsystempause;
973 | return GetLastError();
974 | }
975 | }
976 | else Func_CallCopyHostsFile(st);
977 | if (!hdThread) TerminateThread(hdThread,0);
978 | }
979 | catch(expection runtimeerr){
980 | if (bIsServiceMode){
981 | if (!request_client){
982 | Func_FastPMNTS(_T("Fatal Error:\n"));
983 | Func_FastPMNSS(_T("%s (GetLastError():%ld)\n"),
984 | runtimeerr.Message,GetLastError());
985 | Func_FastPMNSS(_T("Please contact the application's\
986 | support team for more information.\n"));
987 | }
988 | else {
989 | _stprintf(szline,szErrMeg,runtimeerr.Message,GetLastError());
990 | ___pipesendmsg(szline);
991 | }
992 | }
993 | else{
994 | _tprintf(szErrMeg,runtimeerr.Message,GetLastError());
995 | _tprintf(_T("\n[Debug Message]\n%s\n%s\n%s\n"),buf1,buf2,buf3);
996 | abort();
997 | }
998 | }
999 | Sleep(bIsServiceMode?(request_client?10000:(Func_checkBusyTime()?29*60000:60*60000)):0);
1000 | } while (bIsServiceMode);
1001 | return GetLastError();
1002 | }
1003 |
1004 | bool Func_checkBackupFileTime(const SYSTEMTIME & st,TCHAR const * name){
1005 | WORD year,month,day;
1006 | if (_stscanf(name,_T("hosts.%4hd%2hd%2hd.%*2d%*2d%*2d"),&year,&month,&day)!=3)
1007 | return false;
1008 | long systime=st.wYear*365+st.wMonth*30+st.wDay;
1009 | if (labs(systime-(year*365+month*30+day))>=60)
1010 | return true;
1011 | return false;
1012 | }
1013 |
1014 | inline bool Func_checkBusyTime(){
1015 | SYSTEMTIME st={0,0,0,0,0,0,0,0};
1016 | GetSystemTime(&st);
1017 | if (st.wHour<3 || st.wHour>7) return true;
1018 | return false;
1019 | }
1020 |
1021 | void Func_countBackupFile(SYSTEMTIME * st){
1022 | HANDLE hdHandle=INVALID_HANDLE_VALUE;
1023 | DWORD __count__=0;
1024 | TCHAR * sizbuf=new TCHAR[localbufsize];
1025 | _stprintf(sizbuf,_T("%s\\drivers\\etc\\hosts.20*"),buf3);
1026 | if ((hdHandle=FindFirstFile(sizbuf,&wfd))==INVALID_HANDLE_VALUE){
1027 | _tprintf(_T("FindFirstFile() Error!(%ld)\n"),GetLastError());
1028 | delete [] sizbuf;
1029 | return ;
1030 | }
1031 | do {
1032 | if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue;
1033 | if (_tcsstr(wfd.cFileName,_T("hosts.")))
1034 | __count__++;
1035 | } while (FindNextFile(hdHandle,&wfd));
1036 | FindClose(hdHandle);
1037 | #ifndef _TESTONLINE
1038 | if (__count__>20)
1039 | if (MessageBox(NULL,_T("You number of backup file is more than 20.\n\n\
1040 | Do you want to delete out of date(Over 60 days) backup file?"),
1041 | _T("Delete request"),
1042 | MB_ICONQUESTION|MB_YESNO|MB_SETFOREGROUND|MB_DEFBUTTON2)
1043 | ==IDYES){
1044 | if ((hdHandle=FindFirstFile(sizbuf,&wfd))==INVALID_HANDLE_VALUE)
1045 | _tprintf(_T("FindFirstFile() Error!(%ld)\n"),GetLastError());
1046 | _stprintf(buf1,_T("%s\\drivers\\etc"),buf3);
1047 | SetCurrentDirectory(buf1);
1048 | do {
1049 | if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) continue;
1050 | // _tprintf(_T("%s"),wfd.cFileName);
1051 | if (Func_checkBackupFileTime(*st,wfd.cFileName))
1052 | if (DeleteFile(wfd.cFileName))
1053 | _tprintf(_T(" \
1054 | Delete file \"%s\" successfully\n"),wfd.cFileName);
1055 | } while (FindNextFile(hdHandle,&wfd));
1056 | FindClose(hdHandle);
1057 | }
1058 | #endif
1059 | delete [] sizbuf;
1060 | sizbuf=_pNULL_;
1061 | return ;
1062 | }
1063 |
1064 | void WINAPI Service_Main(DWORD,LPTSTR *){
1065 | Func_SetErrorFile(LogFileLocate,_T("a+"));
1066 | if (!(ssh=RegisterServiceCtrlHandler(Sname,Service_Control)))
1067 | Func_FastPMNTS(_T("RegisterServiceCtrlHandler() Error with %ld \n\
1068 | Cannot start service!\n"),GetLastError()),abort();
1069 | ss.dwServiceType=SERVICE_WIN32_OWN_PROCESS;
1070 | ss.dwCurrentState=SERVICE_START_PENDING;
1071 | ss.dwControlsAccepted=SERVICE_ACCEPT_STOP|SERVICE_ACCEPT_SHUTDOWN;
1072 | ss.dwServiceSpecificExitCode=0;
1073 | ss.dwWin32ExitCode=0;
1074 | ss.dwCheckPoint=0;
1075 | ss.dwWaitHint=1000;
1076 | SetServiceStatus(ssh,&ss);
1077 | ss.dwCurrentState=SERVICE_RUNNING;
1078 | ss.dwCheckPoint=0;
1079 | ss.dwWaitHint=0;
1080 | SetServiceStatus(ssh,&ss);
1081 | if (!(lphdThread[0]=createT(NormalEntry))){
1082 | Func_FastPMNTS(_T("CreateThread() Error with %ld \n\
1083 | Cannot start main thread to update hosts!\n"),GetLastError());
1084 | ss.dwWin32ExitCode=ERROR_SERVICE_NO_THREAD;
1085 | ss.dwCurrentState=SERVICE_STOPPED;
1086 | ss.dwCheckPoint=1;
1087 | ss.dwWaitHint=0;
1088 | SetServiceStatus(ssh,&ss);
1089 | abort();
1090 | }
1091 | WaitForSingleObject(lphdThread[0],INFINITE);
1092 | ss.dwCurrentState=SERVICE_STOPPED;
1093 | ss.dwCheckPoint=0;
1094 | ss.dwWaitHint=0;
1095 | SetServiceStatus(ssh,&ss);
1096 | return ;
1097 | }
1098 |
1099 | void WINAPI Service_Control(DWORD dwControl){
1100 | switch (dwControl){
1101 | case SERVICE_CONTROL_SHUTDOWN:
1102 | case SERVICE_CONTROL_STOP:
1103 | ss.dwCurrentState=SERVICE_STOP_PENDING;
1104 | ss.dwCheckPoint=0;
1105 | ss.dwWaitHint=1000;
1106 | SetServiceStatus(ssh,&ss);
1107 | //Why we use terminate?
1108 | TerminateThread(lphdThread[0],0);
1109 | if (request_client) CloseHandle(hdPipe);
1110 | ss.dwCurrentState=SERVICE_STOPPED;
1111 | ss.dwCheckPoint=0;
1112 | ss.dwWaitHint=0;
1113 | SetServiceStatus(ssh,&ss);
1114 | default:break;
1115 | }
1116 | return ;
1117 | }
1118 |
--------------------------------------------------------------------------------
/tool.exe.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/tool.rc:
--------------------------------------------------------------------------------
1 | 1 24 "tool.exe.manifest"
2 |
--------------------------------------------------------------------------------
/wininet.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/HostsTools/Windows/4abaaff06d4710302b7e6d9f0cd9e5d81afb26a7/wininet.lib
--------------------------------------------------------------------------------