├── .gitignore
├── LICENSE
├── Makefile
├── README.md
├── bin
└── .gitignore
├── notes
├── scraps
├── forktest.c
├── grandchild.c
├── hashdriver.c
├── random.c
├── syscall_test.c
├── test.c
└── threads.c
├── src
├── arm32
│ └── registers.c
├── arm64
│ └── registers.c
├── attach.c
├── hashmap.c
├── hashmap.h
├── strings.c
├── strings.h
├── utilities.c
├── whatfiles.c
├── whatfiles.h
├── x86
│ └── registers.c
└── x86_64
│ └── registers.c
└── whatfiles.geany
/.gitignore:
--------------------------------------------------------------------------------
1 | whatfiles1588*
2 |
3 | # notes
4 | bin/*
5 | .vscode
6 |
7 | # Prerequisites
8 | *.d
9 |
10 | # Object files
11 | *.o
12 | *.ko
13 | *.obj
14 | *.elf
15 |
16 | # Linker output
17 | *.ilk
18 | *.map
19 | *.exp
20 |
21 | # Precompiled Headers
22 | *.gch
23 | *.pch
24 |
25 | # Libraries
26 | *.lib
27 | *.a
28 | *.la
29 | *.lo
30 |
31 | # Shared objects (inc. Windows DLLs)
32 | *.dll
33 | *.so
34 | *.so.*
35 | *.dylib
36 |
37 | # Executables
38 | *.exe
39 | *.out
40 | *.app
41 | *.i*86
42 | *.x86_64
43 | *.hex
44 |
45 | # Debug files
46 | *.dSYM/
47 | *.su
48 | *.idb
49 | *.pdb
50 |
51 | # Kernel Module Compile Results
52 | *.mod*
53 | *.cmd
54 | .tmp_versions/
55 | modules.order
56 | Module.symvers
57 | Mkfile.old
58 | dkms.conf
59 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | CC = gcc
2 | CFLAGS = -Wall -std=gnu99
3 | SOURCES = $(addprefix src/, whatfiles.c attach.c utilities.c hashmap.c strings.c)
4 |
5 | INSTALL = /usr/bin/install -c
6 |
7 | ARCH = $(shell uname -m)
8 | ifeq ($(findstring arm,$(ARCH)), arm)
9 | ARCH_DIR = arm32
10 | else ifeq ($(findstring aarch64,$(ARCH)), aarch64)
11 | ARCH_DIR = arm64
12 | else ifeq ($(findstring i386,$(ARCH)), i386)
13 | ARCH_DIR = x86
14 | else ifeq ($(findstring i686,$(ARCH)), i686)
15 | ARCH_DIR = x86
16 | else
17 | ARCH_DIR = x86_64
18 | endif
19 |
20 | all: bin/whatfiles
21 |
22 | bin/whatfiles: $(SOURCES)
23 | $(CC) $(CFLAGS) -o $@ $(SOURCES) src/$(ARCH_DIR)/registers.c
24 |
25 | # utils
26 |
27 | install: bin/whatfiles
28 | ${INSTALL} ./bin/whatfiles /usr/local/bin/whatfiles
29 |
30 | clean:
31 | rm -rf bin/*
32 |
33 | check: bin/whatfiles bin/hashmap
34 | valgrind --leak-check=full bin/whatfiles cal
35 | valgrind --leak-check=full bin/hashmap
36 |
37 | # ignore these, just tests used during development
38 |
39 | scraps: bin/forktest bin/grandchild bin/threads bin/hashmap bin/random
40 |
41 | bin/forktest: scraps/forktest.c
42 | $(CC) $(CFLAGS) -o $@ $^
43 |
44 | bin/grandchild: scraps/grandchild.c
45 | $(CC) $(CFLAGS) -o $@ $^
46 |
47 | bin/threads: scraps/threads.c
48 | $(CC) $(CFLAGS) -pthread -o $@ $^
49 |
50 | bin/hashmap: scraps/hashdriver.c src/hashmap.c src/strings.c
51 | $(CC) $(CFLAGS) -o $@ $^
52 |
53 | bin/random: scraps/random.c
54 | $(CC) $(CFLAGS) -o $@ $^
55 |
56 | bin/syscall_test: scraps/syscall_test.c
57 | $(CC) $(CFLAGS) -o $@ $^
58 |
59 |
60 | chain: bin/whatfiles bin/forktest bin/grandchild
61 | bin/whatfiles bin/forktest
62 |
63 | redo: bin/whatfiles bin/threads
64 | bin/whatfiles bin/threads a s d f
65 | cat whatfiles*
66 |
67 | syscall_test: bin/whatfiles bin/syscall_test
68 | bin/whatfiles -ds bin/syscall_test
69 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # whatfiles
2 | Whatfiles is a Linux utility that logs what files another program reads/writes/creates/deletes on your system. It traces any new processes and threads that are created by the targeted process as well.
3 |
4 | ## Rationale:
5 | I've long been frustrated at the lack of a simple utility to see which files a process touches from `main()` to exit. Whether you don't trust a software vendor or are concerned about malware, it's important to be able to know what a program or installer does to your system. `lsof` only observes a moment in time and `strace` is large and somewhat complicated.
6 |
7 | ## Sample output:
8 | ```
9 | mode: read, file: /home/theron/.gimp-2.8/tool-options/gimp-clone-tool, syscall: openat(), PID: 8566, process: gimp
10 | mode: read, file: /home/theron/.gimp-2.8/tool-options/gimp-heal-tool, syscall: openat(), PID: 8566, process: gimp
11 | mode: read, file: /home/theron/.gimp-2.8/tool-options/gimp-perspective-clone-tool, syscall: openat(), PID: 8566, process: gimp
12 | mode: read, file: /home/theron/.gimp-2.8/tool-options/gimp-convolve-tool, syscall: openat(), PID: 8566, process: gimp
13 | mode: read, file: /home/theron/.gimp-2.8/tool-options/gimp-smudge-tool, syscall: openat(), PID: 8566, process: gimp
14 | mode: read, file: /home/theron/.gimp-2.8/tool-options/gimp-dodge-burn-tool, syscall: openat(), PID: 8566, process: gimp
15 | mode: read, file: /home/theron/.gimp-2.8/tool-options/gimp-desaturate-tool, syscall: openat(), PID: 8566, process: gimp
16 | mode: read, file: /home/theron/.gimp-2.8/plug-ins, syscall: openat(), PID: 8566, process: gimp
17 | mode: read, file: /usr/lib/gimp/2.0/plug-ins, syscall: openat(), PID: 8566, process: gimp
18 | mode: read, file: /home/theron/.gimp-2.8/pluginrc, syscall: openat(), PID: 8566, process: gimp
19 | mode: read, file: /usr/share/locale/en_US/LC_MESSAGES/gimp20-std-plug-ins.mo, syscall: openat(), PID: 8566, process: gimp
20 | mode: read, file: /usr/lib/gimp/2.0/plug-ins/script-fu, syscall: openat(), PID: 8566, process: gimp
21 | mode: read, file: /etc/ld.so.cache, syscall: openat(), PID: 8574, process: /usr/lib/gimp/2.0/plug-ins/script-fu
22 | mode: read, file: /etc/ld.so.cache, syscall: openat(), PID: 8574, process: /usr/lib/gimp/2.0/plug-ins/script-fu
23 | mode: read, file: /usr/lib/libgimpui-2.0.so.0, syscall: openat(), PID: 8574, process: /usr/lib/gimp/2.0/plug-ins/script-fu
24 | mode: read, file: /usr/lib/libgimpwidgets-2.0.so.0, syscall: openat(), PID: 8574, process: /usr/lib/gimp/2.0/plug-ins/script-fu
25 | mode: read, file: /usr/lib/libgimpwidgets-2.0.so.0, syscall: openat(), PID: 8574, process: /usr/lib/gimp/2.0/plug-ins/script-fu
26 | mode: read, file: /usr/lib/libgimp-2.0.so.0, syscall: openat(), PID: 8574, process: /usr/lib/gimp/2.0/plug-ins/script-fu
27 | mode: read, file: /usr/lib/libgimpcolor-2.0.so.0, syscall: openat(), PID: 8574, process: /usr/lib/gimp/2.0/plug-ins/script-fu
28 | ```
29 |
30 | ## Use:
31 |
32 | - basic use, launches `ls` and writes output to a log file in the current directory:
33 |
34 | `$ whatfiles ls -lah ~/Documents`
35 |
36 | - specify output file location with `-o`:
37 |
38 | `$ whatfiles -o MyLogFile cd ..`
39 |
40 | - include debug output, print to stdout rather than log file:
41 |
42 | `$ whatfiles -d -s apt install zoom`
43 |
44 | - attach to currently running process (requires root privileges):
45 |
46 | `$ sudo whatfiles -p 1234`
47 |
48 | ## Distribution
49 | Ready-to-use binaries are on the [releases](https://github.com/spieglt/whatfiles/releases) page! Someone also kindly added it to the [Arch](https://aur.archlinux.org/packages/whatfiles-git/) repository, and [letompouce](https://github.com/letompouce) set up a [GitLab](https://gitlab.com/l3tompouce/builders/whatfiles) pipeline as well.
50 |
51 | ## Compilation (requires `gcc` and `make`):
52 | ```
53 | $ cd whatfiles
54 | $ make
55 | $ sudo make install
56 | ```
57 | Supports x86, x86_64, ARM32, and ARM64 architectures.
58 |
59 | ## Questions that could be asked at some point:
60 |
61 | - _Isn't this just a reimplementation of `strace -fe trace=creat,open,openat,unlink,unlinkat ./program`?_
62 |
63 | Yes. Though it aims to be simpler and more user friendly.
64 |
65 | - _Are there Mac and Windows versions?_
66 |
67 | No. Tracing syscalls on Mac requires `task_for_pid()`, which requires code signing, which I can't get to work, and anyway I have no interest in paying Apple $100/year to write free software. `dtruss` on Mac can be used to follow a single process and its children, though the `-t` flag seems to only accept a single syscall to filter on. `fs_usage` does something similar though I'm not sure if it follows child processes/threads. Process Monitor for Windows is pretty great.
68 |
69 | ## Known issues:
70 |
71 | - Tabs crash when `whatfiles` is used to launch Firefox. (Attaching with `-p [PID]` once it's running works fine, as does using `whatfiles` to launch a second Firefox window if one's already open.)
72 |
73 | ## Planned features:
74 |
75 | - None currently, open to requests and PRs.
76 |
77 | Thank you for your interest, and please also check out [Cloaker](https://github.com/spieglt/cloaker), [Nestur](https://github.com/spieglt/nestur), and [Flying Carpet](https://github.com/spieglt/flyingcarpet)!
78 |
--------------------------------------------------------------------------------
/bin/.gitignore:
--------------------------------------------------------------------------------
1 | *
2 | !.gitignore
3 |
--------------------------------------------------------------------------------
/notes:
--------------------------------------------------------------------------------
1 | https://nullprogram.com/blog/2018/06/23/
2 | http://man7.org/linux/man-pages/man2/ptrace.2.html
3 | https://www.linuxjournal.com/article/6100
4 | https://blog.nelhage.com/2010/08/write-yourself-an-strace-in-70-lines-of-code/
5 | https://stackoverflow.com/questions/18577956/how-to-use-ptrace-to-get-a-consistent-view-of-multiple-threads
6 | https://pramode.net/articles/lfy/ptrace/pramode.html
7 |
8 |
9 | https://filippo.io/linux-syscall-table/
10 | https://blog.rchapman.org/posts/Linux_System_Call_Table_for_x86_64/
11 | http://man7.org/linux/man-pages/man2/syscall.2.html
12 |
13 | https://www.cyphar.com/blog/post/20160703-remainroot-ptrace-hell
14 | https://stackoverflow.com/questions/13532137/tracing-syscalls-of-a-process-and-all-forked-processes
15 | https://stackoverflow.com/questions/5477976/how-to-ptrace-a-multi-threaded-application
16 |
17 |
18 | https://groups.google.com/forum/#!topic/comp.os.linux.development.system/jJVf5Y4XUwY
19 |
20 | mac:
21 | https://www.spaceflint.com/?p=150
22 | http://os-tres.net/blog/2010/02/17/mac-os-x-and-task-for-pid-mach-call/
23 |
--------------------------------------------------------------------------------
/scraps/forktest.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | int main() {
7 | printf("forktest pid: %d\n", getpid());
8 | fflush(stdout);
9 | pid_t pid = fork();
10 | if (pid == 0) {
11 | printf("grandchild pid: %d\n", getpid());
12 | fflush(stdout);
13 | // printf("child ppid: %d\n", getppid());
14 | execl("./bin/grandchild", "./bin/grandchild", (char*)0);
15 | }
16 | int status;
17 | while (1) {
18 | waitpid(pid, &status, 0);
19 | if(WIFEXITED(status)) {
20 | printf("grandchild exited\n");
21 | return 0;
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/scraps/grandchild.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | int main() {
7 | printf("grandchild pid: %d\n", getpid());
8 | fflush(stdout);
9 | pid_t pid = fork();
10 | if (pid == 0) {
11 | printf("great-grandchild pid: %d\n", getpid());
12 | fflush(stdout);
13 | // printf("child ppid: %d\n", getppid());
14 | execl("/bin/ls", "/bin/ls", (char*)0);
15 | }
16 | int status;
17 | while (1) {
18 | waitpid(pid, &status, 0);
19 | if(WIFEXITED(status)) {
20 | printf("great-grandchild exited\n");
21 | return 0;
22 | }
23 | }
24 | }
--------------------------------------------------------------------------------
/scraps/hashdriver.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | #include "../src/hashmap.h"
9 |
10 | #define INSERT_NUM 5000
11 |
12 | #define RESET(map) \
13 | { \
14 | destroy(map); \
15 | init_hashmap(map); \
16 | }
17 |
18 | DebugStats_t DebugStats = {0};
19 |
20 | void insert_test(HashMap map, bool with_names) {
21 | int num = 100000;
22 | for (int i = 0; i < num; i++) {
23 | int r = rand();
24 | insert(r, 1, map);
25 | size_t idx = 0;
26 | find_index(r, map, &idx);
27 | if (!map->names[idx].data && with_names) {
28 | set_name(r, "yeah what's up", map);
29 | }
30 | }
31 | printf("collisions: %d\nsteps: %d\n", DebugStats.collisions, DebugStats.steps);
32 | printf("used: %ld\n", map->used);
33 | // there will be duplicates so this will fail. should pass on mac which doesn't repeat randoms till MAX_RAND-1
34 | // assert(map->used == num);
35 | }
36 |
37 | void delete_test(HashMap map)
38 | {
39 | for (int i = 0; i < map->size; i++) {
40 | if (map->keys[i]) {
41 | remove_pid(map->keys[i], map);
42 | }
43 | }
44 | }
45 |
46 | void memory_leak_test()
47 | {
48 | struct HashMap hashmap;
49 | HashMap m = &hashmap;
50 | for (int i = 0; i < 5; i++) {
51 | init_hashmap(m);
52 | insert_test(m, true);
53 | delete_test(m);
54 | insert_test(m, false);
55 | delete_test(m);
56 | HashError err = destroy(m);
57 | if (err) {
58 | printf("could not destroy\n");
59 | exit(1);
60 | }
61 | }
62 | }
63 |
64 | int main()
65 | {
66 | srand(time(0));
67 |
68 | struct HashMap m;
69 | HashMap map = &m;
70 | init_hashmap(map);
71 | insert_test(map, true);
72 |
73 | RESET(map);
74 | // destroy(map);
75 |
76 | int pids[INSERT_NUM] = {0};
77 | int counts[INSERT_NUM] = {0};
78 | for (int i = 0; i < INSERT_NUM; i++) {
79 | pids[i] = rand();
80 | counts[i] = rand();
81 | insert(pids[i], counts[i], map);
82 | }
83 | for (int i = 0; i < INSERT_NUM; i++) {
84 | size_t res = 0;
85 | get_status(pids[i], map, &res);
86 | assert(res == counts[i]);
87 | }
88 | destroy(map);
89 | printf("done\n");
90 | memory_leak_test();
91 | }
92 |
--------------------------------------------------------------------------------
/scraps/random.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | int main() {
7 | size_t size = ((size_t)RAND_MAX) + 1;
8 | char *randoms = calloc(size, sizeof(char));
9 | int dups = 0;
10 | srand(time(0));
11 | for (int i = 0; i < RAND_MAX; i++) {
12 | int r = rand();
13 | if (randoms[r]) {
14 | // printf("duplicate at %d\n", r);
15 | dups++;
16 | }
17 | randoms[r] = 1;
18 | }
19 | printf("duplicates: %d\n", dups);
20 | }
21 |
--------------------------------------------------------------------------------
/scraps/syscall_test.c:
--------------------------------------------------------------------------------
1 |
2 | #define _GNU_SOURCE
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | #include
11 | // #include
12 | // #include
13 |
14 | int cloned_func(void *arg)
15 | {
16 | printf("hello from clone\n");
17 | fflush(stdout);
18 | return 0;
19 | }
20 |
21 | int main()
22 | {
23 | char *temp_filename = "./tempfile";
24 | char *message = "special message\n";
25 | char *clone_stack = malloc(1024);
26 | char *clone_stack_top = clone_stack + 1024;
27 |
28 | // SYS_fork
29 | printf("testing fork\n");
30 | fflush(stdout);
31 | pid_t child_pid = fork();
32 | if (child_pid == 0) { // if in child
33 | printf("testing exec\n");
34 | fflush(stdout);
35 | // SYS_execve
36 | execl("/bin/ls", "ls", (char*)0);
37 | return 0;
38 | }
39 | wait(NULL);
40 |
41 | // SYS_clone
42 | printf("testing clone\n");
43 | pid_t cloned_pid = clone(cloned_func, clone_stack_top, SIGCHLD, 0);
44 | wait(NULL);
45 |
46 | // SYS_creat
47 | printf("testing creat\n");
48 | int tfd = creat(temp_filename, S_IRWXU);
49 | close(tfd);
50 |
51 | // SYS_open
52 | printf("testing open\n");
53 | tfd = open(temp_filename, O_RDWR);
54 | write(tfd, message, strlen(message));
55 | close(tfd);
56 |
57 | // SYS_openat
58 | printf("testing openat\n");
59 | tfd = openat(AT_FDCWD, temp_filename, O_RDWR | O_APPEND);
60 | close(tfd);
61 |
62 | // SYS_unlink
63 | printf("testing unlink\n");
64 | unlink(temp_filename);
65 |
66 | // SYS_unlinkat
67 | printf("testing unlinkat\n");
68 | tfd = creat(temp_filename, S_IRWXU);
69 | close(tfd);
70 | unlinkat(AT_FDCWD, temp_filename, 0);
71 |
72 | return 0;
73 | }
74 |
--------------------------------------------------------------------------------
/scraps/test.c:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include "src/strings.h"
8 |
9 | #define SYS_ERR(msg) { \
10 | perror(msg); \
11 | exit(errno); \
12 | }
13 |
14 | void read_file(struct String *str, size_t size, FILE *file)
15 | {
16 | char c;
17 | for (size_t read = 0; read < size && (c = fgetc(file)) != EOF; read++) {
18 | append_char(c, str);
19 | }
20 | }
21 |
22 | char read_status(pid_t pid)
23 | {
24 | char path[128] = {0};
25 | sprintf(path, "/proc/%d/status", pid);
26 |
27 | struct String string = {0};
28 | struct String *str = &string;
29 |
30 | init_string(str, 4096);
31 | FILE *h_status = fopen(path, "rb");
32 | read_file(str, 4096, h_status);
33 |
34 | // find status line, grab value after colon and spaces
35 | regex_t regex;
36 | int err;
37 | regmatch_t pmatch[2];
38 | if (regcomp(®ex, "State:\\W+([A-Z])", REG_EXTENDED) != 0)
39 | SYS_ERR("regex compilation error");
40 | err = regexec(®ex, str->data, 2, pmatch, 0);
41 | regfree(®ex);
42 | if (err) SYS_ERR("failed to find regex match in /proc/[PID]/status file");
43 | // printf("%s\n", str->data + pmatch[1].rm_so);
44 | return *(str->data + pmatch[1].rm_so);
45 | }
46 |
47 | int main()
48 | {
49 | char x = read_status(2909);
50 | printf("%c\n", x);
51 | }
52 |
--------------------------------------------------------------------------------
/scraps/threads.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | #define handle_error_en(en, msg) \
13 | do { errno = en; perror(msg); exit(EXIT_FAILURE); } while (0)
14 |
15 | #define handle_error(msg) \
16 | do { perror(msg); exit(EXIT_FAILURE); } while (0)
17 |
18 | struct thread_info { /* Used as argument to thread_start() */
19 | pthread_t thread_id; /* ID returned by pthread_create() */
20 | int thread_num; /* Application-defined thread # */
21 | char *argv_string; /* From command-line argument */
22 | };
23 |
24 | /* Thread start function: display address near top of our stack,
25 | and return upper-cased copy of argv_string */
26 |
27 | static void *
28 | thread_start(void *arg)
29 | {
30 | struct thread_info *tinfo = arg;
31 | char *uargv, *p;
32 |
33 | // printf("Thread %d: top of stack near %p; argv_string=%s\n",
34 | // tinfo->thread_num, &p, tinfo->argv_string);
35 | // fflush(stdout);
36 | // open("./fakefile", O_WRONLY);
37 | fopen("./fakefile", "w");
38 |
39 | uargv = strdup(tinfo->argv_string);
40 | if (uargv == NULL)
41 | handle_error("strdup");
42 |
43 | for (p = uargv; *p != '\0'; p++)
44 | *p = toupper(*p);
45 |
46 | return uargv;
47 | }
48 |
49 | int
50 | main(int argc, char *argv[])
51 | {
52 | int s, tnum, opt, num_threads;
53 | struct thread_info *tinfo;
54 | pthread_attr_t attr;
55 | int stack_size;
56 | void *res;
57 |
58 | /* The "-s" option specifies a stack size for our threads */
59 |
60 | stack_size = -1;
61 | while ((opt = getopt(argc, argv, "s:")) != -1) {
62 | switch (opt) {
63 | case 's':
64 | stack_size = strtoul(optarg, NULL, 0);
65 | break;
66 |
67 | default:
68 | fprintf(stderr, "Usage: %s [-s stack-size] arg...\n",
69 | argv[0]);
70 | exit(EXIT_FAILURE);
71 | }
72 | }
73 |
74 | num_threads = argc - optind;
75 |
76 | /* Initialize thread creation attributes */
77 |
78 | s = pthread_attr_init(&attr);
79 | if (s != 0)
80 | handle_error_en(s, "pthread_attr_init");
81 |
82 | if (stack_size > 0) {
83 | s = pthread_attr_setstacksize(&attr, stack_size);
84 | if (s != 0)
85 | handle_error_en(s, "pthread_attr_setstacksize");
86 | }
87 |
88 | /* Allocate memory for pthread_create() arguments */
89 |
90 | tinfo = calloc(num_threads, sizeof(struct thread_info));
91 | if (tinfo == NULL)
92 | handle_error("calloc");
93 |
94 | /* Create one thread for each command-line argument */
95 |
96 | for (tnum = 0; tnum < num_threads; tnum++) {
97 | tinfo[tnum].thread_num = tnum + 1;
98 | tinfo[tnum].argv_string = argv[optind + tnum];
99 |
100 | /* The pthread_create() call stores the thread ID into
101 | corresponding element of tinfo[] */
102 |
103 | s = pthread_create(&tinfo[tnum].thread_id, &attr,
104 | &thread_start, &tinfo[tnum]);
105 | if (s != 0)
106 | handle_error_en(s, "pthread_create");
107 | }
108 |
109 | /* Destroy the thread attributes object, since it is no
110 | longer needed */
111 |
112 | s = pthread_attr_destroy(&attr);
113 | if (s != 0)
114 | handle_error_en(s, "pthread_attr_destroy");
115 |
116 | /* Now join with each thread, and display its returned value */
117 |
118 | for (tnum = 0; tnum < num_threads; tnum++) {
119 | s = pthread_join(tinfo[tnum].thread_id, &res);
120 | if (s != 0)
121 | handle_error_en(s, "pthread_join");
122 |
123 | // printf("Joined with thread %d; returned value was %s\n",
124 | // tinfo[tnum].thread_num, (char *) res);
125 | // free(res); /* Free memory allocated by thread */
126 | }
127 |
128 | free(tinfo);
129 | printf("exiting threads \n");
130 | fflush(stdout);
131 | exit(EXIT_SUCCESS);
132 | }
133 |
--------------------------------------------------------------------------------
/src/arm32/registers.c:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 |
5 | #include
6 | #include
7 | #include
8 |
9 | #include "../hashmap.h"
10 | #include "../whatfiles.h"
11 |
12 | void check_syscall(pid_t current_pid, void *registers, HashMap map)
13 | {
14 | struct pt_regs *regs = (struct pt_regs*)registers;
15 | struct String filename = {0};
16 | struct String output = {0};
17 | init_string(&filename, 64);
18 | init_string(&output, 64);
19 | char mode[MODE_LEN] = {0};
20 |
21 | pid_t parent_tid, child_tid;
22 | unsigned long flags;
23 | unsigned long newsp;
24 |
25 | size_t index;
26 | HashError err = find_index(current_pid, map, &index);
27 | if (err) DEBUG("unknown pid %d, syscall %ld\n", current_pid, regs->ARM_r7);
28 |
29 | switch (regs->ARM_r7)
30 | {
31 | case SYS_execve:
32 | DEBUG("PID %d exec'd. r7: %ld\n", current_pid, regs->ARM_r7);
33 | if (peek_filename(current_pid, regs->ARM_ORIG_r0, &filename)) {
34 | DEBUG("associated process %d with name \"%s\"\n", current_pid, filename.data);
35 | set_name(current_pid, filename.data, map);
36 | }
37 | break;
38 | case SYS_fork:
39 | DEBUG("PID %d forked. r7: %ld\n", current_pid, regs->ARM_r7);
40 | break;
41 | case SYS_clone:
42 | flags = regs->ARM_ORIG_r0;
43 | newsp = regs->ARM_r1;
44 | parent_tid = ptrace(PTRACE_PEEKDATA, current_pid, (void*)regs->ARM_r2, 0);
45 | child_tid = ptrace(PTRACE_PEEKDATA, current_pid, (void*)regs->ARM_r4, 0);
46 | DEBUG("PID %d cloned. r7: %ld, flags: 0x%ld, newsp: 0x%ld, parent pid: %d, child pid: %d\n",
47 | current_pid, regs->ARM_r7, flags, newsp, parent_tid, child_tid);
48 | break;
49 | case SYS_creat:
50 | peek_filename(current_pid, regs->ARM_ORIG_r0, &filename);
51 | get_mode(regs->ARM_r1, mode);
52 | build_output(mode, "creat()", regs->ARM_r1, current_pid, &filename, &output, map);
53 | OUTPUT("%s", output.data);
54 | break;
55 | case SYS_open:
56 | peek_filename(current_pid, regs->ARM_ORIG_r0, &filename);
57 | get_mode(regs->ARM_r2, mode);
58 | build_output(mode, "open()", regs->ARM_r2, current_pid, &filename, &output, map);
59 | OUTPUT("%s", output.data);
60 | break;
61 | case SYS_openat:
62 | peek_filename(current_pid, regs->ARM_r1, &filename);
63 | get_mode(regs->ARM_r3, mode);
64 | build_output(mode, "openat()", regs->ARM_r3, current_pid, &filename, &output, map);
65 | OUTPUT("%s", output.data);
66 | break;
67 | case SYS_unlink:
68 | peek_filename(current_pid, regs->ARM_ORIG_r0, &filename);
69 | build_output("delete", "unlink()", 0, current_pid, &filename, &output, map);
70 | OUTPUT("%s", output.data);
71 | break;
72 | case SYS_unlinkat:
73 | peek_filename(current_pid, regs->ARM_r1, &filename);
74 | build_output("delete", "unlinkat()", 0, current_pid, &filename, &output, map);
75 | OUTPUT("%s", output.data);
76 | break;
77 | default:
78 | // DEBUG("syscall: %lld, pid: %d, %s\n", regs->ARM_r7, current_pid, proc_name);
79 | break;
80 | }
81 | free(filename.data);
82 | free(output.data);
83 | }
84 |
85 |
86 | bool step_syscall(pid_t current_pid, int proc_status, HashMap map)
87 | {
88 | long res;
89 | struct pt_regs regs;
90 | bool could_read = false;
91 | // get current register values
92 | // TODO: make this fault tolerant to a dead PID
93 | res = ptrace(PTRACE_GETREGS, current_pid, ®s, ®s);
94 | if (res == -1L) {
95 | DEBUG("CURRENT PID: %d, failed to get registers\n", current_pid);
96 | }
97 |
98 | // can't get some registers for some reason
99 | if (regs.ARM_r7 != -1) {
100 | could_read = true;
101 | // If it's the same PID performing the same syscall (has same orig_rax) as last time, we don't care. Just means it's exiting the syscall.
102 | // Might want to keep for debug mode? This might result in missing some output, in the case where two threads of the same process enter the same syscall before either exits,
103 | // because they will both return the same PID to wait() when given SIGTRAP as part of the syscall-enter-exit loop. Might also result in double-printing,
104 | // because if two threads (that report the same PID) enter two different syscalls before either exits, the "last" syscall for the PID won't be the entry by that thread.
105 | if (!is_exiting(current_pid, regs.ARM_r7) /*|| Debug*/) {
106 | check_syscall(current_pid, (void*)®s, map);
107 | }
108 | LastSyscall.pid = current_pid;
109 | LastSyscall.syscall = regs.ARM_r7;
110 | check_ptrace_event(current_pid, proc_status, map);
111 | // continue, catching next entry or exit from syscall
112 | res = ptrace(PTRACE_SYSCALL, current_pid, 0, 0);
113 | if (res == -1L) DEBUG("ptrace() failed to resume");
114 | } else {
115 | DEBUG("can't get registers, detaching from %d\n", current_pid);
116 | res = ptrace(PTRACE_DETACH, current_pid, 0, 0); // "Under Linux, a tracee can be detached in this way regardless of which method was used to initiate tracing."
117 | if (res == -1L) DEBUG("ptrace() failed to detach from %d\n", current_pid);
118 | }
119 | return could_read;
120 | }
121 |
--------------------------------------------------------------------------------
/src/arm64/registers.c:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 | #include // for NT_PRSTATUS
5 | #include // for struct iovec
6 |
7 | #include
8 | #include
9 | #include
10 |
11 | #include "../hashmap.h"
12 | #include "../whatfiles.h"
13 |
14 | void check_syscall(pid_t current_pid, void *registers, HashMap map)
15 | {
16 | struct user_pt_regs *regs = (struct user_pt_regs*)registers;
17 | struct String filename = {0};
18 | struct String output = {0};
19 | init_string(&filename, 64);
20 | init_string(&output, 64);
21 | char mode[MODE_LEN] = {0};
22 |
23 | pid_t parent_tid, child_tid;
24 | unsigned long flags;
25 | unsigned long newsp;
26 |
27 | size_t index;
28 | HashError err = find_index(current_pid, map, &index);
29 | if (err) DEBUG("unknown pid %d, syscall %lld\n", current_pid, regs->regs[8]);
30 |
31 | switch (regs->regs[8])
32 | {
33 | case SYS_execve:
34 | DEBUG("PID %d exec'd. x8: %lld\n", current_pid, regs->regs[8]);
35 | if (peek_filename(current_pid, regs->regs[0], &filename)) {
36 | DEBUG("associated process %d with name \"%s\"\n", current_pid, filename.data);
37 | set_name(current_pid, filename.data, map);
38 | }
39 | break;
40 | case SYS_clone:
41 | flags = regs->regs[0];
42 | newsp = regs->regs[1];
43 | parent_tid = ptrace(PTRACE_PEEKDATA, current_pid, (void*)regs->regs[2], 0);
44 | child_tid = ptrace(PTRACE_PEEKDATA, current_pid, (void*)regs->regs[4], 0);
45 | DEBUG("PID %d cloned. x8: %lld, flags: 0x%ld, newsp: 0x%ld, parent pid: %d, child pid: %d\n",
46 | current_pid, regs->regs[8], flags, newsp, parent_tid, child_tid);
47 | break;
48 | case SYS_openat:
49 | peek_filename(current_pid, regs->regs[1], &filename);
50 | get_mode(regs->regs[3], mode);
51 | build_output(mode, "openat()", regs->regs[2], current_pid, &filename, &output, map);
52 | OUTPUT("%s", output.data);
53 | break;
54 | case SYS_unlinkat:
55 | peek_filename(current_pid, regs->regs[1], &filename);
56 | build_output("delete", "unlinkat()", 0, current_pid, &filename, &output, map);
57 | OUTPUT("%s", output.data);
58 | break;
59 | default:
60 | // DEBUG("syscall: %lld, pid: %d, %s\n", regs->ARM_r7, current_pid, proc_name);
61 | break;
62 | }
63 | free(filename.data);
64 | free(output.data);
65 | }
66 |
67 |
68 | bool step_syscall(pid_t current_pid, int proc_status, HashMap map)
69 | {
70 | long res;
71 | struct user_pt_regs regs = {0};
72 | struct iovec iovec = { ®s, sizeof(regs) };
73 | bool could_read = false;
74 | // get current register values
75 | // TODO: make this fault tolerant to a dead PID
76 | res = ptrace(PTRACE_GETREGSET, current_pid, NT_PRSTATUS, &iovec);
77 | if (res == -1L) {
78 | DEBUG("CURRENT PID: %d, failed to get registers\n", current_pid);
79 | }
80 |
81 | // can't get some registers for some reason
82 | if (regs.regs[8] != -1) {
83 | could_read = true;
84 | // If it's the same PID performing the same syscall (has same orig_rax) as last time, we don't care. Just means it's exiting the syscall.
85 | // Might want to keep for debug mode? This might result in missing some output, in the case where two threads of the same process enter the same syscall before either exits,
86 | // because they will both return the same PID to wait() when given SIGTRAP as part of the syscall-enter-exit loop. Might also result in double-printing,
87 | // because if two threads (that report the same PID) enter two different syscalls before either exits, the "last" syscall for the PID won't be the entry by that thread.
88 | if (!is_exiting(current_pid, regs.regs[8]) /*|| Debug*/) {
89 | check_syscall(current_pid, (void*)®s, map);
90 | }
91 | LastSyscall.pid = current_pid;
92 | LastSyscall.syscall = regs.regs[8];
93 | check_ptrace_event(current_pid, proc_status, map);
94 | // continue, catching next entry or exit from syscall
95 | res = ptrace(PTRACE_SYSCALL, current_pid, 0, 0);
96 | if (res == -1L) DEBUG("ptrace() failed to resume");
97 | } else {
98 | DEBUG("can't get registers, detaching from %d\n", current_pid);
99 | res = ptrace(PTRACE_DETACH, current_pid, 0, 0); // "Under Linux, a tracee can be detached in this way regardless of which method was used to initiate tracing."
100 | if (res == -1L) DEBUG("ptrace() failed to detach from %d\n", current_pid);
101 | }
102 | return could_read;
103 | }
104 |
105 |
--------------------------------------------------------------------------------
/src/attach.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | #include "whatfiles.h"
13 |
14 | // Most of this file gratefully adapted from Nominal Animal's answer at
15 | // https://stackoverflow.com/questions/18577956/how-to-use-ptrace-to-get-a-consistent-view-of-multiple-threads
16 |
17 | void read_file(struct String *str, size_t size, FILE *file)
18 | {
19 | int c;
20 | for (size_t read = 0; read < size && (c = fgetc(file)) != EOF; read++) {
21 | append_char((char)c, str);
22 | }
23 | }
24 |
25 | // returns 0 if status file couldn't be read, character of status otherwise
26 | char read_status(pid_t pid)
27 | {
28 | char c = 0;
29 | char path[128] = {0};
30 | sprintf(path, "/proc/%d/status", pid);
31 |
32 | struct String string = {0};
33 | struct String *str = &string;
34 |
35 | init_string(str, 4096);
36 | FILE *h_status = fopen(path, "rb");
37 | if (!h_status) return 0;
38 | read_file(str, 4096, h_status);
39 |
40 | int err;
41 | regmatch_t pmatch[2];
42 | err = regexec(®ex, str->data, 2, pmatch, 0);
43 | if (err) {
44 | DEBUG("failed to find regex match in /proc/%d/status file\n", pid);
45 | } else {
46 | c = *(str->data + pmatch[1].rm_so);
47 | }
48 | free(str->data);
49 | fclose(h_status);
50 | return c;
51 | }
52 |
53 | bool read_task(pid_t tid, struct String *str)
54 | {
55 | char path[128] = {0};
56 | sprintf(path, "/proc/%d/comm", tid);
57 | FILE *h_comm = fopen(path, "rb");
58 | if (!h_comm) {
59 | DEBUG("tried to read nonexistent /proc/%d/comm\n", tid);
60 | return false;
61 | }
62 | read_file(str, 4096, h_comm);
63 | if (str->data[str->len-1] == '\n') delete_char(str); // remove newline if present
64 | fclose(h_comm);
65 | return str->len > 0;
66 | }
67 |
68 | int attach_to_process(pid_t pid, HashMap map)
69 | {
70 |
71 | pid_t *tid = 0;
72 | size_t tids = 0;
73 | size_t tids_max = 0;
74 | size_t t;
75 | long r, sys_err;
76 |
77 | // stop the process and its threads
78 | kill(pid, SIGSTOP);
79 | // can't wait() on a process that's not a child
80 | while (1) {
81 | char status = read_status(pid);
82 | if (status == 'T' || status == 't') break;
83 | struct timespec ts = {0, 1000000 * 250}; // quarter second
84 | nanosleep(&ts, &ts);
85 | DEBUG("waiting for PID %d to stop\n", pid);
86 | }
87 |
88 | // get thread IDs from /proc/[PID]/task/
89 | tids = get_tids(&tid, &tids_max, pid);
90 | if (!tids)
91 | {
92 | DEBUG("process %d has no threads\n", pid);
93 | // kill(pid, SIGCONT);
94 | // return 0;
95 | } else {
96 | DEBUG("Process %d has %d tasks\n", (int)pid, (int)tids);
97 | }
98 |
99 | /* Attach to all tasks. */
100 | for (t = 0; t < tids; t++) {
101 | do {
102 | r = ptrace(PTRACE_ATTACH, tid[t], (void *)0, (void *)0);
103 | } while (r == -1L && (errno == EBUSY || errno == EFAULT || errno == ESRCH));
104 | if (r == -1L) {
105 | DEBUG("ptrace attach error\n");
106 | const int saved_errno = errno;
107 | while (t-- > 0) {
108 | do {
109 | r = ptrace(PTRACE_DETACH, tid[t], (void *)0, (void *)0);
110 | } while (r == -1L && (errno == EBUSY || errno == EFAULT || errno == ESRCH));
111 | }
112 | tids = 0;
113 | errno = saved_errno;
114 | return errno;
115 | }
116 | // if successfully attached, add to map
117 | insert(tid[t], 0, map);
118 | struct String str = {0};
119 | init_string(&str, 4096);
120 | if (read_task(tid[t], &str)) {
121 | set_name(tid[t], str.data, map);
122 | }
123 | free(str.data);
124 | }
125 |
126 | // set ptrace options
127 | // register for the ptrace events we want to catch
128 | sys_err = ptrace(PTRACE_SETOPTIONS, pid, (char*)0, PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK | PTRACE_O_TRACECLONE | PTRACE_O_TRACEEXEC);
129 | if (sys_err == -1) SYS_ERR("ptrace() failed to set options");
130 |
131 | for (t = 0; t < tids; t++) {
132 | sys_err = ptrace(PTRACE_SYSCALL, tid[t], 0, 0);
133 | if (sys_err == -1) SYS_ERR("ptrace() failed to resume thread");
134 | }
135 | kill(pid, SIGCONT);
136 | return 0;
137 | }
138 |
139 | // used upon exit as signal handler when whatfiles was used to attach to a process already in progress
140 | void detach_from_process(HashMap map)
141 | {
142 | for (int i = 0; i < map->size; i++) {
143 | pid_t pid = map->keys[i];
144 | if (pid) {
145 | int r;
146 | int counter = 0;
147 | char status = 0;
148 | // make sure the thread is stopped
149 | kill(pid, SIGSTOP);
150 | while (1) {
151 | status = read_status(pid);
152 | if (status == 'T' || status == 't') break; // thread stopped, due to kill(SIGSTOP) above or ptrace syscall SIGTRAP
153 | struct timespec ts = {0, 100000000}; // 100 million nanoseconds = tenth of a second
154 | nanosleep(&ts, &ts);
155 | DEBUG("waiting for PID %d to stop\n", pid);
156 | if (counter > 9) {
157 | DEBUG("could not detach from PID %d\n", pid);
158 | break;
159 | }
160 | counter++;
161 | }
162 | if (counter > 9) continue; // if we weren't able to detach from this process, move on
163 | do {
164 | r = ptrace(PTRACE_DETACH, pid, (void *)0, (void *)0);
165 | } while (r == -1L && (errno == EBUSY || errno == EFAULT || errno == ESRCH));
166 | if (r == -1) fprintf(stderr, "error detaching from PID %d\n", pid);
167 | else DEBUG("detached from process %d\n", pid);
168 | kill(pid, SIGCONT);
169 | }
170 | }
171 | }
172 |
173 | size_t get_tids(pid_t **const listptr, size_t *const sizeptr, const pid_t pid)
174 | {
175 | char dirname[64];
176 | DIR *dir;
177 | pid_t *list;
178 | size_t size, used = 0;
179 |
180 | // make sure we've been given non-null pointers and a valid pid
181 | if (!listptr || !sizeptr || pid < (pid_t)1) {
182 | errno = EINVAL;
183 | return (size_t)0;
184 | }
185 |
186 | // if sizeptr points to 0 or less, null contents of listptr and sizeptr
187 | if (*sizeptr > 0) {
188 | list = *listptr;
189 | size = *sizeptr;
190 | } else {
191 | list = *listptr = NULL;
192 | size = *sizeptr = 0;
193 | }
194 |
195 | if (snprintf(dirname, sizeof dirname, "/proc/%d/task/", (int)pid) >= (int)sizeof dirname) {
196 | errno = ENOTSUP;
197 | return (size_t)0;
198 | }
199 |
200 | dir = opendir(dirname);
201 | if (!dir) {
202 | errno = ESRCH;
203 | return (size_t)0;
204 | }
205 |
206 | while (1) {
207 | struct dirent *ent;
208 | int value;
209 | char dummy;
210 |
211 | errno = 0;
212 | ent = readdir(dir);
213 | if (!ent) break;
214 |
215 | /* Parse TIDs. Ignore non-numeric entries. */
216 | if (sscanf(ent->d_name, "%d%c", &value, &dummy) != 1) continue;
217 |
218 | /* Ignore obviously invalid entries. */
219 | if (value < 1) continue;
220 |
221 | /* Make sure there is room for another TID. */
222 | if (used >= size) {
223 | size = (used | 127) + 128;
224 | list = realloc(list, size * sizeof list[0]);
225 | if (!list) {
226 | closedir(dir);
227 | errno = ENOMEM;
228 | return (size_t)0;
229 | }
230 | *listptr = list;
231 | *sizeptr = size;
232 | }
233 |
234 | /* Add to list. */
235 | list[used++] = (pid_t)value;
236 | }
237 |
238 | if (errno) {
239 | const int saved_errno = errno;
240 | closedir(dir);
241 | errno = saved_errno;
242 | return (size_t)0;
243 | }
244 | if (closedir(dir)) {
245 | errno = EIO;
246 | return (size_t)0;
247 | }
248 |
249 | /* None? */
250 | if (used < 1) {
251 | errno = ESRCH;
252 | return (size_t)0;
253 | }
254 |
255 | /* Make sure there is room for a terminating (pid_t)0. */
256 | if (used >= size) {
257 | size = used + 1;
258 | list = realloc(list, size * sizeof list[0]);
259 | if (!list) {
260 | errno = ENOMEM;
261 | return (size_t)0;
262 | }
263 | *listptr = list;
264 | *sizeptr = size;
265 | }
266 |
267 | /* Terminate list; done. */
268 | list[used] = (pid_t)0;
269 | errno = 0;
270 | return used;
271 | }
272 |
--------------------------------------------------------------------------------
/src/hashmap.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | #include "hashmap.h"
11 | #include "strings.h"
12 |
13 | /*
14 | Not the best hash map. Open addressing, quadratic probing
15 | (which doesn't seem to perform much better than linear for random int inputs),
16 | and wastes three quarters of its space to minimize collisions.
17 | Would benefit from separate chaining with linked lists. But good enough for now.
18 | Also not using all of the functionality in whatfiles, but keeping so that it can
19 | be easily modified and reused as a generic hashmap later.
20 | */
21 |
22 | void init_hashmap(HashMap map)
23 | {
24 | map->size = INITIAL_SIZE;
25 | map->used = 0;
26 | map->keys = calloc(INITIAL_SIZE, sizeof(pid_t));
27 | map->status = calloc(INITIAL_SIZE, sizeof(size_t));
28 | map->names = calloc(INITIAL_SIZE, sizeof(struct String));
29 | if (!(map->keys && map->status && map->names)) {
30 | perror("calloc() error");
31 | exit(errno);
32 | }
33 | }
34 |
35 | HashError set_name(pid_t pid, char *name, HashMap map)
36 | {
37 | size_t index;
38 | HashError err = find_index(pid, map, &index);
39 | if (err == OK) {
40 | init_string(&map->names[index], 64);
41 | append_str(name, strlen(name), &map->names[index]);
42 | }
43 | return err;
44 | }
45 |
46 | // also changes status value if pid already present
47 | HashError insert(pid_t pid, Status status, HashMap map)
48 | {
49 | if (map->used >= map->size / 4) {
50 | resize_hashmap(map);
51 | }
52 | size_t index = pid % map->size;
53 | int base = 1;
54 | int c = 0;
55 |
56 | while (map->keys[index] != 0) {
57 | if (map->keys[index] == pid) {
58 | map->status[index] = status;
59 | return OK;
60 | }
61 | c++; DebugStats.steps++;
62 | // index = (index+1) % map->size; // linear probe
63 | index = (index + base * base) % map->size; // quadratic probe
64 | base++;
65 | }
66 |
67 | if (c) DebugStats.collisions++;
68 |
69 | map->keys[index] = pid;
70 | map->status[index] = status;
71 | map->used++;
72 | return OK;
73 | }
74 |
75 | HashError find_index(pid_t pid, HashMap map, size_t *result)
76 | {
77 | size_t index = pid % map->size;
78 | size_t start = index;
79 | while (map->keys[index] != pid) {
80 | index = (index + 1) % map->size;
81 | if (index == start) {
82 | return KEY_NOT_FOUND;
83 | }
84 | }
85 | *result = index;
86 | return OK;
87 | }
88 |
89 | HashError destroy(HashMap map)
90 | {
91 | if (!(map->keys && map->status && map->names)) {
92 | return NULL_PTR_IN_MAP;
93 | }
94 | // this loop never fired because I had map->size = 0 at the top. I'm an idiot.
95 | for (int i = 0; i < map->size; i++) {
96 | free(map->names[i].data);
97 | }
98 | free(map->keys);
99 | free(map->status);
100 | free(map->names);
101 | map->size = 0;
102 | map->used = 0;
103 | return OK;
104 | }
105 |
106 | void resize_hashmap(HashMap map)
107 | {
108 | pid_t *orig_pids = map->keys;
109 | Status *orig_status = map->status;
110 | struct String *orig_names = map->names;
111 | size_t orig_size = map->size;
112 |
113 | map->used = 0;
114 | map->size *= 2;
115 | map->keys = calloc(map->size, sizeof(pid_t));
116 | map->status = calloc(map->size, sizeof(Status));
117 | map->names = calloc(map->size, sizeof(struct String));
118 | if (!(map->keys && map->status && map->names)) {
119 | perror("calloc() error");
120 | exit(errno);
121 | }
122 |
123 | for (int i = 0; i < orig_size; i++) {
124 | if (!orig_pids[i]) continue;
125 | insert(orig_pids[i], orig_status[i], map);
126 | if (orig_names[i].data) {
127 | set_name(orig_pids[i], orig_names[i].data, map);
128 | free(orig_names[i].data);
129 | }
130 | }
131 | free(orig_pids);
132 | free(orig_status);
133 | free(orig_names);
134 | }
135 |
136 | HashError get_name(pid_t pid, HashMap map, struct String *name)
137 | {
138 | size_t index;
139 | HashError err = find_index(pid, map, &index);
140 | if (err == OK) {
141 | name = &map->names[index];
142 | }
143 | return err;
144 | }
145 |
146 | HashError get_status(pid_t pid, HashMap map, size_t *result)
147 | {
148 | size_t idx = 0;
149 | HashError res = find_index(pid, map, &idx);
150 | if (res == OK) {
151 | *result = map->status[idx];
152 | }
153 | return res;
154 | }
155 |
156 | HashError increment(pid_t pid, HashMap map)
157 | {
158 | size_t idx = 0;
159 | HashError res = find_index(pid, map, &idx);
160 | if (res == OK && map->status[idx] < __INT_MAX__) {
161 | map->status[idx]++;
162 | }
163 | return res;
164 | }
165 |
166 | HashError decrement(pid_t pid, HashMap map)
167 | {
168 | size_t idx = 0;
169 | HashError res = find_index(pid, map, &idx);
170 | if (res == OK && map->status[idx] > 0) {
171 | map->status[idx]--;
172 | }
173 | return res;
174 | }
175 |
176 | HashError remove_pid(pid_t pid, HashMap map)
177 | {
178 | size_t idx = 0;
179 | HashError res = find_index(pid, map, &idx);
180 | if (res == OK) {
181 | map->keys[idx] = 0;
182 | map->status[idx] = 0;
183 | free(map->names[idx].data);
184 | struct String zeroed = {0};
185 | map->names[idx] = zeroed;
186 | map->used--;
187 | }
188 | return res;
189 | }
190 |
--------------------------------------------------------------------------------
/src/hashmap.h:
--------------------------------------------------------------------------------
1 | #ifndef HASHMAP_H
2 | #define HASHMAP_H
3 |
4 | #include "strings.h"
5 |
6 | #define INITIAL_SIZE 1024
7 |
8 | // tracks whether the process is entering or exiting the current syscall
9 | typedef enum {
10 | ENTRY = 0,
11 | EXIT = 1,
12 | } Status;
13 |
14 | typedef enum {
15 | OK = 0,
16 | KEY_NOT_FOUND,
17 | NULL_PTR_IN_MAP,
18 | } HashError;
19 |
20 | struct HashMap {
21 | size_t size;
22 | size_t used;
23 | pid_t *keys;
24 | Status *status;
25 | struct String *names;
26 | };
27 | typedef struct HashMap* HashMap;
28 |
29 | void init_hashmap(HashMap map);
30 | void resize_hashmap(HashMap map);
31 |
32 | HashError destroy(HashMap map);
33 | HashError find_index(pid_t key, HashMap map, size_t *result);
34 | HashError insert(pid_t key, Status status, HashMap map);
35 | HashError get_status(pid_t key, HashMap map, size_t *result);
36 | HashError remove_pid(pid_t key, HashMap map);
37 | HashError increment(pid_t key, HashMap map);
38 | HashError decrement(pid_t key, HashMap map);
39 | HashError set_name(pid_t key, char *name, HashMap map);
40 | HashError get_name(pid_t key, HashMap map, struct String *name);
41 |
42 | typedef struct {
43 | int collisions;
44 | int steps;
45 | } DebugStats_t;
46 |
47 | extern DebugStats_t DebugStats;
48 |
49 | #endif /* !HASHMAP_H */
50 |
--------------------------------------------------------------------------------
/src/strings.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #include "strings.h"
6 |
7 | // new String pointers must be zeroed before being handed to this function
8 | void init_string(struct String *str, size_t initial_capacity)
9 | {
10 | free(str->data);
11 | str->data = malloc(initial_capacity);
12 | if (str->data == NULL) {
13 | perror("malloc() failed");
14 | exit(errno);
15 | }
16 | str->cap = initial_capacity;
17 | str->len = 0;
18 | *(str->data) = 0;
19 | }
20 |
21 | void resize_string(struct String *str)
22 | {
23 | str->data = realloc((void*)str->data, str->cap * 2);
24 | if (str->data == NULL) {
25 | perror("realloc() failed");
26 | exit(errno);
27 | }
28 | str->cap = str->cap * 2;
29 | }
30 |
31 | void append_str(char *input_str, size_t len, struct String *str)
32 | {
33 | while (str->len + len >= str->cap - 1) {
34 | resize_string(str);
35 | }
36 | strcpy(str->data + str->len, input_str);
37 | str->len += len;
38 | }
39 |
40 | void append_char(char c, struct String *str)
41 | {
42 | if (str->len >= str->cap - 1) {
43 | resize_string(str);
44 | }
45 | str->data[str->len] = c;
46 | str->len += 1;
47 | str->data[str->len] = '\0';
48 | }
49 |
50 | void delete_char(struct String *str)
51 | {
52 | str->len -= 1;
53 | str->data[str->len] = '\0';
54 | }
55 |
--------------------------------------------------------------------------------
/src/strings.h:
--------------------------------------------------------------------------------
1 | #ifndef STRINGS_H
2 | #define STRINGS_H
3 |
4 | #include
5 |
6 | struct String {
7 | size_t cap;
8 | size_t len;
9 | char* data;
10 | };
11 |
12 | void init_string(struct String *str, size_t initial_capacity);
13 | void append_str(char *input_str, size_t len, struct String *str);
14 | void append_char(char c, struct String *str);
15 | void delete_char(struct String *str);
16 |
17 | #endif /* !STRINGS_H */
18 |
--------------------------------------------------------------------------------
/src/utilities.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | #include "string.h"
8 | #include "whatfiles.h"
9 |
10 | char *FLAGS = "ado:p:s";
11 |
12 | void build_output(
13 | char *mode,
14 | char *syscall_name,
15 | unsigned long reg,
16 | pid_t pid,
17 | struct String *filename,
18 | struct String *result,
19 | HashMap map
20 | )
21 | {
22 | size_t index;
23 | HashError err = find_index(pid, map, &index); // find_index() returns OK = 0 or NOT_FOUND = 1
24 | struct String *proc_string = err ? NULL : &map->names[index];
25 |
26 | char mode_str[MODE_LEN] = {0};
27 | // grab detected mode or the raw number
28 | *mode ? sprintf(mode_str, "%5s", mode) : sprintf(mode_str, "0x%lX", reg);
29 | append_str("mode: ", strlen("mode: "), result);
30 | append_str(mode_str, strlen(mode_str), result);
31 |
32 | append_str(", file: ", strlen(", file: "), result);
33 | append_str(filename->data, strlen(filename->data), result);
34 |
35 | append_str(", syscall: ", strlen(", syscall: "), result);
36 | append_str(syscall_name, strlen(syscall_name), result);
37 |
38 | char pid_str[MODE_LEN] = {0};
39 | sprintf(pid_str, ", PID: %d", pid);
40 | append_str(pid_str, strlen(pid_str), result);
41 |
42 | // make sure proc_string points to a `struct String`, that the String has been initialized, and that the first char isn't just a null byte
43 | char *proc_name = proc_string && proc_string->data && *proc_string->data
44 | ? proc_string->data
45 | : "[unknown]";
46 | append_str(", process: ", strlen(", process: "), result);
47 | append_str(proc_name, strlen(proc_name), result);
48 | append_str("\n", strlen("\n"), result);
49 | }
50 |
51 | void get_mode(unsigned long long m, char *mode)
52 | {
53 | char *strings[] = {"read", "write", "rd/wr", "create"};
54 | int modes[] = {O_RDONLY, O_WRONLY, O_RDWR, O_CREAT};
55 | for (int i=0; i<4; i++) {
56 | if (m & modes[i] || m == modes[i]) {
57 | assert(strlen(strings[i]) < MODE_LEN);
58 | strcpy(mode, strings[i]);
59 | }
60 | }
61 | }
62 |
63 | void get_command(pid_t current_pid, char *command, size_t len)
64 | {
65 | char proc_str[64] = {0};
66 | FILE *proc_file;
67 | sprintf(proc_str, "/proc/%d/cmdline", current_pid);
68 | proc_file = fopen(proc_str, "r");
69 | if (proc_file) {
70 | getline(&command, &len, proc_file);
71 | fclose(proc_file);
72 | }
73 | }
74 |
75 | bool peek_filename(pid_t pid, unsigned long p_reg, struct String *str)
76 | {
77 | char get_next_word = 1;
78 | long *addr = (long*)p_reg;
79 | do {
80 | // get next long-sized chunk of data from the address
81 | long res = ptrace(PTRACE_PEEKDATA, pid, (void*)addr, 0);
82 | if (res == -1) return 0;
83 | // iterate over it, appending to our filepath string, bailing if we encounter a null character
84 | for (int i = 0; i < sizeof(res); i++) {
85 | char current_byte = (char)(res >> (8*i) & 0xFF);
86 | if (current_byte) {
87 | append_char(current_byte, str);
88 | } else {
89 | get_next_word = 0;
90 | break;
91 | }
92 | }
93 | addr++;
94 | } while (get_next_word);
95 | return 1;
96 | }
97 |
98 | // void toggle_status(pid_t current_pid, HashMap map)
99 | // {
100 | // size_t index;
101 | // HashError err = find_index(current_pid, map, &index);
102 | // HASH_ERR_CHECK(err, "index not found in map when trying to change syscall status");
103 | // // if (map->status[index]) decrement(current_pid, map);
104 | // // else increment(current_pid, map);
105 | // if (map->status[index] == ENTRY) err = insert(current_pid, EXIT, map);
106 | // else if (map->status[index] == EXIT) err = insert(current_pid, ENTRY, map);
107 | // else SYS_ERR("syscall status not 0 or 1");
108 | // }
109 |
110 | // Returns whether the current ptrace stop is an entry to a syscall or exit from one, which we track by comparing it to the previous one.
111 | // Can return false positives, if multiple threads of a single process/PID enter the same syscall before either exits; can also return false negatives,
112 | // if multiple threads of a single process/PID enter different syscalls before either exits.
113 | bool is_exiting(pid_t pid, unsigned long long syscall)
114 | {
115 | return pid == LastSyscall.pid && syscall == LastSyscall.syscall;
116 | }
117 |
118 | // return index within argv of the beginning of the user's command and end of whatfiles' flags
119 | // no: now that we're attaching to processes, we aren't necessarily going to have a beginning of command
120 | // so need to return index of last whatfiles arg.
121 | int discover_flags(int argc, char *argv[])
122 | {
123 | int i;
124 | for (i = 1; i < argc; i++) {
125 | char *current_arg = argv[i];
126 | char *last_arg = argv[i-1];
127 | char last_char = last_arg[strlen(last_arg)-1];
128 | if (*current_arg == '-') {
129 | continue; // in an option
130 | } else if (*last_arg == '-' && (last_char == 'o' || last_char == 'p')) {
131 | continue; // not in an option, but in argument to option
132 | }
133 | return i; // if still here, we're at the user's command
134 | }
135 | return i;
136 | }
137 |
138 | char *parse_flags(int argc, char *argv[], pid_t *pid, bool *stdout_override, bool *attach)
139 | {
140 | int c;
141 | char *filename = NULL;
142 | while ((c = getopt(argc, argv, FLAGS)) != -1) {
143 | switch(c)
144 | {
145 | case 'a':
146 | about();
147 | break;
148 | case 'd':
149 | Debug = 1;
150 | break;
151 | case 'o':
152 | filename = optarg;
153 | break;
154 | case 'p':
155 | *attach = true;
156 | *pid = atoi(optarg);
157 | if (!*pid || *pid < 1) {
158 | fprintf(stderr, "Bad PID %s given, must be integer.\n", optarg);
159 | exit(1);
160 | }
161 | // check if the given `pid` is valid
162 | if (getpgid(*pid) < 0) {
163 | fprintf(stderr, "Bad PID %s given. PID is not valid or does not exist.\n", optarg);
164 | exit(1);
165 | }
166 | break;
167 | case 's':
168 | *stdout_override = true;
169 | break;
170 | case '?':
171 | if (optopt == 'o') {
172 | fprintf(stderr, "Option -o requires the desired location of the output file as argument.\n");
173 | } else if (optopt == 'p') {
174 | fprintf(stderr, "Option -p requires the PID of the process to be tracked as argument.\n");
175 | } else if (isprint(optopt)) {
176 | fprintf(stderr, "Unknown option `-%c'.\n", optopt);
177 | } else {
178 | fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
179 | }
180 | usage();
181 | break;
182 | default:
183 | usage();
184 | break;
185 | }
186 | }
187 | return filename;
188 | }
189 |
190 | void usage()
191 | {
192 | fprintf(stderr, "\n ======== Usage ========\n");
193 | fprintf(stderr, "Whatfiles can be used to log what files a process accesses, and in what mode.\n");
194 | fprintf(stderr, "To track the entire lifetime of a program, use it (and whatever arguments) after whatfiles flags.\n");
195 | fprintf(stderr, "You can also attach to a currently-running program, though this requires root privileges.\n");
196 | fprintf(stderr, "\n ======== Flags ========\n");
197 | fprintf(stderr, " -o ./output.log : specify log file location\n");
198 | fprintf(stderr, " -p [PID] : attach to currently running process (requires sudo)\n");
199 | fprintf(stderr, " -s : output to stdout rather than log file\n");
200 | fprintf(stderr, " -d : include debug output\n");
201 | fprintf(stderr, " -a : print about/license\n");
202 | fprintf(stderr, "\n ======== Examples ========\n");
203 | fprintf(stderr, "Basic use, write what files the calendar uses to log:\n");
204 | fprintf(stderr, " $ whatfiles cal\n");
205 | fprintf(stderr, "Run `ls`, include debug output, and log to stdout:\n");
206 | fprintf(stderr, " $ whatfiles -ds ls -lah /var/log\n");
207 | fprintf(stderr, "Attach to currently open process with PID 1234:\n");
208 | fprintf(stderr, " $ sudo whatfiles -p 1234\n");
209 | fprintf(stderr, "Watch what files an installation creates and name the log:\n");
210 | fprintf(stderr, " $ sudo whatfiles -o ./firefox.log apt install firefox\n");
211 | exit(1);
212 | }
213 |
214 | void about()
215 | {
216 | char *about_message =
217 | "https://github.com/spieglt/whatfiles\n"
218 | "Copyright (C) 2020 Theron Spiegl. All rights reserved.\n\n"
219 |
220 | "Whatfiles is a Linux utility used to log what files another program accesses and in what mode, "
221 | "as well as that program's child processes and threads.\n\n"
222 |
223 | " This program is free software: you can redistribute it and/or modify\n"
224 | " it under the terms of the GNU General Public License as published by\n"
225 | " the Free Software Foundation, either version 3 of the License, or\n"
226 | " (at your option) any later version.\n\n"
227 | " This program is distributed in the hope that it will be useful,\n"
228 | " but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
229 | " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
230 | " GNU General Public License for more details.\n\n"
231 | " You should have received a copy of the GNU General Public License\n"
232 | " along with this program. If not, see .\n";
233 | printf("%s\n", about_message);
234 | exit(0);
235 | }
236 |
--------------------------------------------------------------------------------
/src/whatfiles.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 | #include
9 | #include
10 | #include
11 |
12 | #include "whatfiles.h"
13 | #include "hashmap.h"
14 | #include "strings.h"
15 |
16 | FILE *Handle = (FILE*)NULL;
17 | int Debug = 0;
18 | regex_t regex;
19 | LastSyscall_t LastSyscall;
20 | DebugStats_t DebugStats;
21 |
22 | // responsible for seeing new processes and threads created by forks, clones, or vforks, and inserting them into the hashmap
23 | void check_ptrace_event(pid_t current_pid, int proc_status, HashMap map)
24 | {
25 | struct String new_proc = {0};
26 | init_string(&new_proc, 128);
27 |
28 | unsigned long ptrace_event;
29 | long res = ptrace(PTRACE_GETEVENTMSG, current_pid, (char*)0, &ptrace_event);
30 | if (res == -1L) {
31 | DEBUG("ptrace() failed to get event msg");
32 | return;
33 | }
34 | switch (proc_status >> 8)
35 | {
36 | case SIGTRAP | (PTRACE_EVENT_FORK << 8):
37 | DEBUG("caught PTRACE_EVENT_FORK from pid %d. new pid: %ld\n", current_pid, ptrace_event);
38 | insert((pid_t)ptrace_event, ENTRY, map);
39 | if (read_task((pid_t)ptrace_event, &new_proc)) {
40 | set_name((pid_t)ptrace_event, new_proc.data, map);
41 | }
42 | break;
43 | case SIGTRAP | (PTRACE_EVENT_CLONE << 8):
44 | DEBUG("caught PTRACE_EVENT_CLONE from pid %d. new pid: %ld\n", current_pid, ptrace_event);
45 | insert((pid_t)ptrace_event, ENTRY, map);
46 | if (read_task((pid_t)ptrace_event, &new_proc)) {
47 | set_name((pid_t)ptrace_event, new_proc.data, map);
48 | }
49 | break;
50 | case SIGTRAP | (PTRACE_EVENT_VFORK << 8):
51 | DEBUG("caught PTRACE_EVENT_VFORK from pid %d. new pid: %ld\n", current_pid, ptrace_event);
52 | insert((pid_t)ptrace_event, ENTRY, map);
53 | if (read_task((pid_t)ptrace_event, &new_proc)) {
54 | set_name((pid_t)ptrace_event, new_proc.data, map);
55 | }
56 | break;
57 | case SIGTRAP | (PTRACE_EVENT_EXEC << 8):
58 | DEBUG("caught PTRACE_EVENT_EXEC from pid %d. former pid: %ld\n", current_pid, ptrace_event);
59 | /*
60 | from ptrace man page, "execve(2) under ptrace":
61 | When one thread in a multithreaded process calls execve(2), the kernel destroys all other threads in the
62 | process, and resets the thread ID of the execing thread to the thread group ID (process ID). (Or, to put
63 | things another way, when a multithreaded process does an execve(2), at completion of the call, it appears as
64 | though the execve(2) occurred in the thread group leader, regardless of which thread did the execve(2).)
65 | This resetting of the thread ID looks very confusing to tracers:
66 | [...]
67 | * The execing tracee changes its thread ID while it is in the execve(2). (Remember, under ptrace, the
68 | "pid" returned from waitpid(2), or fed into ptrace calls, is the tracee's thread ID.) That is, the
69 | tracee's thread ID is reset to be the same as its process ID, which is the same as the thread group
70 | leader's thread ID.
71 | * Then a PTRACE_EVENT_EXEC stop happens, if the PTRACE_O_TRACEEXEC option was turned on.
72 | So, we should not insert the ptrace_event value, but the current_pid, as by the time we (the tracer)
73 | see this event, the PID has already been changed.
74 | */
75 | // insert((pid_t)ptrace_event, ENTRY, map);
76 | insert(current_pid, ENTRY, map);
77 | break;
78 | default:
79 | break;
80 | }
81 |
82 | free(new_proc.data);
83 | }
84 |
85 | int main(int argc, char* argv[])
86 | {
87 | int pid, status;
88 | HashError err;
89 | int sys_err;
90 | bool stdout_override = false;
91 | bool attach = false;
92 |
93 | struct HashMap hm = {0};
94 | HashMap hashmap = &hm;
95 | init_hashmap(hashmap);
96 |
97 | if (regcomp(®ex, "State:\\W+([A-Za-z])", REG_EXTENDED) != 0) {
98 | SYS_ERR("regex compilation error");
99 | }
100 |
101 | int start_of_user_command = discover_flags(argc, argv);
102 | char *user_filename = parse_flags(start_of_user_command, argv, &pid, &stdout_override, &attach);
103 | if (start_of_user_command == argc && !attach) {
104 | fprintf(stderr, "Must specify a command to be run (after whatfiles arguments) or use the -p flag followed by a PID to attach to an existing process.\n");
105 | usage();
106 | }
107 | if (stdout_override) {
108 | Handle = stdout;
109 | } else {
110 | if (!user_filename) { // if filename is still empty string, make default
111 | char default_filename[64];
112 | sprintf(default_filename, "./whatfiles%lu.log", time(NULL));
113 | Handle = fopen(default_filename, "w");
114 | printf("whatfiles log location: %s\n", default_filename);
115 | } else {
116 | Handle = fopen(user_filename, "w");
117 | printf("whatfiles log location: %s\n", user_filename);
118 | }
119 | if (!Handle) SYS_ERR("could not open output file");
120 | }
121 |
122 | DEBUG("whatfiles pid: %d\n", getpid());
123 |
124 | if (attach) {
125 | OUTPUT("attaching to pid %d\n", pid);
126 | sys_err = attach_to_process(pid, hashmap);
127 | if (sys_err) SYS_ERR("error attaching to process");
128 | } else {
129 | // child process starts here
130 | if((pid = fork()) == 0) {
131 | DEBUG("whatfiles child pid: %d\n", getpid());
132 | sys_err = ptrace(PTRACE_TRACEME, 0, 0, 0);
133 | if (sys_err == -1) SYS_ERR("ptrace() failed to TRACEME");
134 | /*
135 | http://man7.org/linux/man-pages/man2/ptrace.2.html
136 | "If the PTRACE_O_TRACEEXEC option is not in effect, all successful
137 | calls to execve(2) by the traced process will cause it to be sent a
138 | SIGTRAP signal, giving the parent a chance to gain control before the
139 | new program begins execution."
140 | */
141 | execvp(argv[start_of_user_command], &argv[start_of_user_command]);
142 | struct String err_msg = {0};
143 | init_string(&err_msg, 128);
144 | char *failed = "failed to execute ";
145 | append_str(failed, strlen(failed), &err_msg);
146 | append_str(argv[start_of_user_command], strlen(argv[start_of_user_command]), &err_msg);
147 | SYS_ERR(err_msg.data);
148 | free(err_msg.data); // not really necessary because SYS_ERR will exit() but meh
149 | }
150 | if (pid == -1) SYS_ERR("fork() failed");
151 |
152 | // tracing process continues here
153 |
154 | pid = wait(&status); // initial stop caused by exec in child process
155 | if (pid == -1) SYS_ERR("wait() failed");
156 | insert(pid, ENTRY, hashmap);
157 |
158 | if(WIFEXITED(status)) return 0;
159 | if(!WIFSTOPPED(status)) SYS_ERR("received non-SIGTRAP signal, ptrace() not working");
160 | err = set_name(pid, argv[start_of_user_command], &hm);
161 | HASH_ERR_CHECK(err, "could not set name for initial process");
162 | /*
163 | "When the tracee is in ptrace-stop, the tracer can read and write data
164 | to the tracee using informational commands. These commands leave the
165 | tracee in ptrace-stopped state:"
166 | [PTRACE_SETOPTIONS among others]
167 | */
168 | // register for the ptrace events we want to catch
169 | sys_err = ptrace(PTRACE_SETOPTIONS, pid, (char*)0, PTRACE_O_TRACEFORK | PTRACE_O_TRACEVFORK | PTRACE_O_TRACECLONE | PTRACE_O_TRACEEXEC);
170 | if (sys_err == -1) SYS_ERR("ptrace() failed");
171 |
172 | // start PTRACE_SYSCALL/wait() loop. process/thread will receive SIGTRAP every time it makes a syscall
173 | sys_err = ptrace(PTRACE_SYSCALL, pid, 0, 0);
174 | if (sys_err == -1) SYS_ERR("ptrace() failed");
175 | }
176 |
177 | // by this point, whether attaching or spawning,
178 | // options should be in place and all processes/threads should be resumed with PTRACE_SYSCALL
179 |
180 | // if we're attaching to a process already in progress, block SIGINT and SIGTERM signals
181 | // so that we can detach from everything if whatfiles is closed while the process is still running
182 | sigset_t block_mask, pending_mask;
183 | if (attach) {
184 | sigemptyset(&block_mask);
185 | sigaddset(&block_mask, SIGINT);
186 | sigaddset(&block_mask, SIGTERM);
187 | sigprocmask(SIG_SETMASK, &block_mask, NULL);
188 | }
189 |
190 | // main loop
191 | for (;;) {
192 | if (attach) {
193 | sigpending(&pending_mask);
194 | if (sigismember(&pending_mask, SIGINT) || sigismember(&pending_mask, SIGTERM)) {
195 | DEBUG("pending signal caught\n");
196 | detach_from_process(hashmap);
197 | exit(errno);
198 | }
199 | }
200 | // catch any traced process' or thread's next state change
201 | pid = wait(&status);
202 | if (pid == -1) SYS_ERR("whatfiles exiting");
203 | if (WIFEXITED(status) || WIFSIGNALED(status)) {
204 | DEBUG("PID %d exited", pid);
205 | // ok if this fails in case of process not in hashmap
206 | err = remove_pid(pid, hashmap);
207 | if (err) DEBUG(", was not in map");
208 | DEBUG("\n");
209 | } else if (WIFSTOPPED(status)) {
210 | /*bool could_read = */ step_syscall(pid, status, hashmap);
211 | }
212 |
213 | if (hashmap->used == 0) {
214 | DEBUG("all children exited\n");
215 | break;
216 | }
217 | }
218 |
219 | regfree(®ex);
220 | err = destroy(hashmap);
221 | HASH_ERR_CHECK(err, "tried to free null pointers in hashmap.\n")
222 | fclose(Handle);
223 | }
224 |
225 | /*
226 | TODO:
227 | debug flag for use by hashdriver
228 | more hashmap tests?
229 | better allocator/destructor for String
230 | have hashmap functions return index where appropriate. just insert()?
231 | */
232 |
233 | /*
234 | Because wait() will return the same PID for any of a process's threads, we need a way to get the thread ID so that we can keep track of entering/exiting.
235 | Though the only reason we need to keep track of that is to not double-print. Can we just check whether the to-be-printed values are the same as the last ones?
236 | Maybe yes, but it would be nice to be able to keep track of that, period. And what if two threads with the same PID enter the same syscall before either exits?
237 | Then we'll only print once. Need linked list to keep track of syscalls that have entered but not exited? Would solve the problem of syscalls getting interrupted
238 | before exiting, which happens. Context switching? But wouldn't solve the problem of two threads with the same PID that enter the same syscall before either exits.
239 | But if that happens, there will just be "one on the stack twice" instead of "two on the stack once". Is that a problem?
240 |
241 | What's happening with unseen PIDs: we are informed of a process entering a clone syscall, and before it exits, the new thread is scheduled and starts executing its own syscalls,
242 | which we are informed of. Eventually followed by the original clone exiting, so does get inserted into map.
243 |
244 | TODO: maybe still haven't accounted for this:
245 | If the thread group leader has reported its PTRACE_EVENT_EXIT stop by this time, it appears to the tracer
246 | that the dead thread leader "reappears from nowhere". (Note: the thread group leader does not report
247 | death via WIFEXITED(status) until there is at least one other live thread. This eliminates the possibil‐
248 | ity that the tracer will see it dying and then reappearing.) If the thread group leader was still alive,
249 | for the tracer this may look as if thread group leader returns from a different system call than it
250 | entered, or even "returned from a system call even though it was not in any system call". If the thread
251 | group leader was not traced (or was traced by a different tracer), then during execve(2) it will appear
252 | as if it has become a tracee of the tracer of the execing tracee.
253 | */
254 |
--------------------------------------------------------------------------------
/src/whatfiles.h:
--------------------------------------------------------------------------------
1 | #ifndef WHATFILES_H
2 | #define WHATFILES_H
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | #include "hashmap.h"
10 |
11 | extern int Debug;
12 | extern FILE *Handle;
13 | extern regex_t regex;
14 |
15 | #define MODE_LEN 32
16 | #define OUTPUT(...) fprintf(Handle, __VA_ARGS__)
17 | #define DEBUG(...) if (Debug) { OUTPUT(__VA_ARGS__); }
18 | #define SYS_ERR(msg) { \
19 | perror(msg); \
20 | exit(errno); \
21 | }
22 | #define HASH_ERR_CHECK(err, msg) \
23 | if (err) { \
24 | fprintf(stderr, "Error: %s\n", msg); \
25 | exit(err); \
26 | }
27 |
28 | typedef struct {
29 | pid_t pid;
30 | unsigned long long syscall;
31 | } LastSyscall_t;
32 |
33 | extern LastSyscall_t LastSyscall;
34 |
35 | // whatfiles.c
36 | void check_ptrace_event(pid_t current_pid, int proc_status, HashMap map);
37 |
38 | // utilities.c
39 | void build_output(
40 | char *mode,
41 | char *syscall_name,
42 | unsigned long reg,
43 | pid_t pid,
44 | struct String *filename,
45 | struct String *result,
46 | HashMap map
47 | );
48 | void get_mode(unsigned long long m, char *mode);
49 | void get_command(pid_t current_pid, char *command, size_t len);
50 | bool peek_filename(pid_t pid, unsigned long p_reg, struct String *str);
51 | // void toggle_status(pid_t current_pid, HashMap map);
52 | bool is_exiting(pid_t pid, unsigned long long syscall);
53 | char *parse_flags(int argc, char *argv[], pid_t *pid, bool *stdout_override, bool *attach);
54 | int discover_flags(int argc, char *argv[]);
55 | void usage();
56 | void about();
57 |
58 | // attach.c
59 | size_t get_tids(pid_t **const listptr, size_t *const sizeptr, const pid_t pid);
60 | int attach_to_process(pid_t pid, HashMap map);
61 | void detach_from_process(HashMap map);
62 | void read_file(struct String *str, size_t size, FILE *file);
63 | char read_status(pid_t pid);
64 | bool read_task(pid_t tid, struct String *str);
65 |
66 | // architecture-specific, registers.c
67 | void check_syscall(pid_t current_pid, void *registers, HashMap map);
68 | bool step_syscall(pid_t current_pid, int proc_status, HashMap map);
69 |
70 |
71 | #endif /* !WHATFILES_H */
72 |
--------------------------------------------------------------------------------
/src/x86/registers.c:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | #include "../hashmap.h"
8 | #include "../whatfiles.h"
9 |
10 | // looks at the current syscall and outputs its information if it's one we're interested in
11 | void check_syscall(pid_t current_pid, void *registers, HashMap map)
12 | {
13 | struct user_regs_struct *regs = (struct user_regs_struct*)registers;
14 | struct String filename = {0};
15 | struct String output = {0};
16 | init_string(&filename, 64);
17 | init_string(&output, 64);
18 | char mode[MODE_LEN] = {0};
19 |
20 | pid_t parent_tid, child_tid;
21 | unsigned long flags;
22 | unsigned long newsp;
23 |
24 | size_t index;
25 | HashError err = find_index(current_pid, map, &index);
26 | if (err) DEBUG("unknown pid %d, syscall %ld\n", current_pid, regs->orig_eax);
27 |
28 | switch (regs->orig_eax)
29 | {
30 | case SYS_execve:
31 | DEBUG("PID %d exec'd. orig_eax: %ld, eax: %ld\n", current_pid, regs->orig_eax, regs->eax);
32 | if (peek_filename(current_pid, regs->ebx, &filename)) {
33 | DEBUG("associated process %d with name \"%s\"\n", current_pid, filename.data);
34 | set_name(current_pid, filename.data, map);
35 | }
36 | break;
37 | case SYS_fork:
38 | DEBUG("PID %d forked. orig_eax: %ld, eax: %ld\n", current_pid, regs->orig_eax, regs->eax);
39 | break;
40 | case SYS_clone:
41 | flags = regs->ebx;
42 | newsp = regs->ecx;
43 | parent_tid = ptrace(PTRACE_PEEKDATA, current_pid, (void*)regs->edx, 0);
44 | child_tid = ptrace(PTRACE_PEEKDATA, current_pid, (void*)regs->esi, 0);
45 | DEBUG("PID %d cloned. orig_eax: %ld, eax: %ld, flags: 0x%ld, newsp: 0x%ld, parent pid: %d, child pid: %d\n",
46 | current_pid, regs->orig_eax, regs->eax, flags, newsp, parent_tid, child_tid);
47 | break;
48 | case SYS_creat:
49 | peek_filename(current_pid, regs->ebx, &filename);
50 | get_mode(regs->ecx, mode);
51 | build_output(mode, "creat()", regs->ecx, current_pid, &filename, &output, map);
52 | OUTPUT("%s", output.data);
53 | break;
54 | case SYS_open:
55 | peek_filename(current_pid, regs->ebx, &filename);
56 | get_mode(regs->edx, mode);
57 | build_output(mode, "open()", regs->edx, current_pid, &filename, &output, map);
58 | OUTPUT("%s", output.data);
59 | break;
60 | case SYS_openat:
61 | peek_filename(current_pid, regs->ecx, &filename);
62 | get_mode(regs->esi, mode);
63 | build_output(mode, "openat()", regs->esi, current_pid, &filename, &output, map);
64 | OUTPUT("%s", output.data);
65 | break;
66 | case SYS_unlink:
67 | peek_filename(current_pid, regs->ebx, &filename);
68 | build_output("delete", "unlink()", 0, current_pid, &filename, &output, map);
69 | OUTPUT("%s", output.data);
70 | break;
71 | case SYS_unlinkat:
72 | peek_filename(current_pid, regs->ecx, &filename);
73 | build_output("delete", "unlinkat()", 0, current_pid, &filename, &output, map);
74 | OUTPUT("%s", output.data);
75 | break;
76 | default:
77 | // DEBUG("syscall: %lld, pid: %d, %s\n", regs->orig_eax, current_pid, proc_name);
78 | break;
79 | }
80 | free(filename.data);
81 | free(output.data);
82 | }
83 |
84 |
85 | bool step_syscall(pid_t current_pid, int proc_status, HashMap map)
86 | {
87 | long res;
88 | struct user_regs_struct regs;
89 | bool could_read = false;
90 | // get current register values
91 | // TODO: make this fault tolerant to a dead PID
92 | res = ptrace(PTRACE_GETREGS, current_pid, ®s, ®s);
93 | if (res == -1L) {
94 | DEBUG("CURRENT PID: %d, failed to get registers\n", current_pid);
95 | }
96 |
97 | // can't get some registers for some reason
98 | if (regs.orig_eax != -1) {
99 | could_read = true;
100 | // If it's the same PID performing the same syscall (has same orig_eax) as last time, we don't care. Just means it's exiting the syscall.
101 | // Might want to keep for debug mode? This might result in missing some output, in the case where two threads of the same process enter the same syscall before either exits,
102 | // because they will both return the same PID to wait() when given SIGTRAP as part of the syscall-enter-exit loop. Might also result in double-printing,
103 | // because if two threads (that report the same PID) enter two different syscalls before either exits, the "last" syscall for the PID won't be the entry by that thread.
104 | if (!is_exiting(current_pid, regs.orig_eax) /*|| Debug*/) {
105 | check_syscall(current_pid, (void*)®s, map);
106 | }
107 | LastSyscall.pid = current_pid;
108 | LastSyscall.syscall = regs.orig_eax;
109 | check_ptrace_event(current_pid, proc_status, map);
110 | // continue, catching next entry or exit from syscall
111 | res = ptrace(PTRACE_SYSCALL, current_pid, 0, 0);
112 | if (res == -1L) DEBUG("ptrace() failed to resume");
113 | } else {
114 | DEBUG("can't get registers, detaching from %d\n", current_pid);
115 | res = ptrace(PTRACE_DETACH, current_pid, 0, 0); // "Under Linux, a tracee can be detached in this way regardless of which method was used to initiate tracing."
116 | if (res == -1L) DEBUG("ptrace() failed to detach from %d\n", current_pid);
117 | }
118 | return could_read;
119 | }
120 |
--------------------------------------------------------------------------------
/src/x86_64/registers.c:
--------------------------------------------------------------------------------
1 |
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | #include "../hashmap.h"
8 | #include "../whatfiles.h"
9 |
10 | // looks at the current syscall and outputs its information if it's one we're interested in
11 | void check_syscall(pid_t current_pid, void *registers, HashMap map)
12 | {
13 | struct user_regs_struct *regs = (struct user_regs_struct*)registers;
14 | struct String filename = {0};
15 | struct String output = {0};
16 | init_string(&filename, 64);
17 | init_string(&output, 64);
18 | char mode[MODE_LEN] = {0};
19 |
20 | pid_t parent_tid, child_tid;
21 | unsigned long flags;
22 | unsigned long newsp;
23 |
24 | size_t index;
25 | HashError err = find_index(current_pid, map, &index);
26 | if (err) DEBUG("unknown pid %d, syscall %lld\n", current_pid, regs->orig_rax);
27 |
28 | switch (regs->orig_rax)
29 | {
30 | case SYS_execve:
31 | DEBUG("PID %d exec'd. orig_rax: %lld, rax: %lld\n", current_pid, regs->orig_rax, regs->rax);
32 | if (peek_filename(current_pid, regs->rdi, &filename)) {
33 | DEBUG("associated process %d with name \"%s\"\n", current_pid, filename.data);
34 | set_name(current_pid, filename.data, map);
35 | }
36 | break;
37 | case SYS_fork:
38 | DEBUG("PID %d forked. orig_rax: %lld, rax: %lld\n", current_pid, regs->orig_rax, regs->rax);
39 | break;
40 | case SYS_clone:
41 | flags = regs->rdi;
42 | newsp = regs->rsi;
43 | parent_tid = ptrace(PTRACE_PEEKDATA, current_pid, (void*)regs->rdx, 0);
44 | child_tid = ptrace(PTRACE_PEEKDATA, current_pid, (void*)regs->r10, 0);
45 | DEBUG("PID %d cloned. orig_rax: %lld, rax: %lld, flags: 0x%ld, newsp: 0x%ld, parent pid: %d, child pid: %d\n",
46 | current_pid, regs->orig_rax, regs->rax, flags, newsp, parent_tid, child_tid);
47 | break;
48 | case SYS_creat:
49 | peek_filename(current_pid, regs->rdi, &filename);
50 | get_mode(regs->rsi, mode);
51 | build_output(mode, "creat()", regs->rsi, current_pid, &filename, &output, map);
52 | OUTPUT("%s", output.data);
53 | break;
54 | case SYS_open:
55 | peek_filename(current_pid, regs->rdi, &filename);
56 | get_mode(regs->rdx, mode);
57 | build_output(mode, "open()", regs->rdx, current_pid, &filename, &output, map);
58 | OUTPUT("%s", output.data);
59 | break;
60 | case SYS_openat:
61 | peek_filename(current_pid, regs->rsi, &filename);
62 | get_mode(regs->r10, mode);
63 | build_output(mode, "openat()", regs->r10, current_pid, &filename, &output, map);
64 | OUTPUT("%s", output.data);
65 | break;
66 | case SYS_unlink:
67 | peek_filename(current_pid, regs->rdi, &filename);
68 | build_output("delete", "unlink()", 0, current_pid, &filename, &output, map);
69 | OUTPUT("%s", output.data);
70 | break;
71 | case SYS_unlinkat:
72 | peek_filename(current_pid, regs->rsi, &filename);
73 | build_output("delete", "unlinkat()", 0, current_pid, &filename, &output, map);
74 | OUTPUT("%s", output.data);
75 | break;
76 | default:
77 | // DEBUG("syscall: %lld, pid: %d, %s\n", regs->orig_rax, current_pid, proc_name);
78 | break;
79 | }
80 | free(filename.data);
81 | free(output.data);
82 | }
83 |
84 |
85 | bool step_syscall(pid_t current_pid, int proc_status, HashMap map)
86 | {
87 | long res;
88 | struct user_regs_struct regs;
89 | bool could_read = false;
90 | // get current register values
91 | // TODO: make this fault tolerant to a dead PID
92 | res = ptrace(PTRACE_GETREGS, current_pid, ®s, ®s);
93 | if (res == -1L) {
94 | DEBUG("CURRENT PID: %d, failed to get registers\n", current_pid);
95 | }
96 |
97 | // can't get some registers for some reason
98 | if (regs.orig_rax != -1) {
99 | could_read = true;
100 | // If it's the same PID performing the same syscall (has same orig_rax) as last time, we don't care. Just means it's exiting the syscall.
101 | // Might want to keep for debug mode? This might result in missing some output, in the case where two threads of the same process enter the same syscall before either exits,
102 | // because they will both return the same PID to wait() when given SIGTRAP as part of the syscall-enter-exit loop. Might also result in double-printing,
103 | // because if two threads (that report the same PID) enter two different syscalls before either exits, the "last" syscall for the PID won't be the entry by that thread.
104 | if (!is_exiting(current_pid, regs.orig_rax) /*|| Debug*/) {
105 | check_syscall(current_pid, (void*)®s, map);
106 | }
107 | LastSyscall.pid = current_pid;
108 | LastSyscall.syscall = regs.orig_rax;
109 | check_ptrace_event(current_pid, proc_status, map);
110 | // continue, catching next entry or exit from syscall
111 | res = ptrace(PTRACE_SYSCALL, current_pid, 0, 0);
112 | if (res == -1L) DEBUG("ptrace() failed to resume");
113 | } else {
114 | DEBUG("can't get registers, detaching from %d\n", current_pid);
115 | res = ptrace(PTRACE_DETACH, current_pid, 0, 0); // "Under Linux, a tracee can be detached in this way regardless of which method was used to initiate tracing."
116 | if (res == -1L) DEBUG("ptrace() failed to detach from %d\n", current_pid);
117 | }
118 | return could_read;
119 | }
120 |
--------------------------------------------------------------------------------
/whatfiles.geany:
--------------------------------------------------------------------------------
1 | [editor]
2 | line_wrapping=false
3 | line_break_column=72
4 | auto_continue_multiline=true
5 |
6 | [file_prefs]
7 | final_new_line=true
8 | ensure_convert_new_lines=false
9 | strip_trailing_spaces=false
10 | replace_tabs=false
11 |
12 | [indentation]
13 | indent_width=4
14 | indent_type=1
15 | indent_hard_tab_width=8
16 | detect_indent=true
17 | detect_indent_width=true
18 | indent_mode=2
19 |
20 | [project]
21 | name=whatfiles
22 | base_path=/home/pi/projects/whatfiles/
23 | description=
24 | file_patterns=
25 |
26 | [long line marker]
27 | long_line_behaviour=1
28 | long_line_column=72
29 |
30 | [files]
31 | current_page=1
32 | FILE_NAME_0=697;C;0;EUTF-8;0;1;0;%2Fhome%2Fpi%2Fwhatfiles%2Fsrc%2Farmv7l%2Fregisters.c;0;4
33 | FILE_NAME_1=567;C;0;EUTF-8;0;1;0;%2Fhome%2Fpi%2Fwhatfiles%2Fsrc%2Fattach.c;0;4
34 | FILE_NAME_2=0;C;0;EUTF-8;0;1;0;%2Fhome%2Fpi%2Fwhatfiles%2Fsrc%2Fhashmap.c;0;4
35 | FILE_NAME_3=0;C++;0;EUTF-8;0;1;0;%2Fhome%2Fpi%2Fwhatfiles%2Fsrc%2Fhashmap.h;0;4
36 | FILE_NAME_4=888;C;0;EUTF-8;0;1;0;%2Fhome%2Fpi%2Fwhatfiles%2Fsrc%2Fstrings.c;0;4
37 | FILE_NAME_5=0;C++;0;EUTF-8;0;1;0;%2Fhome%2Fpi%2Fwhatfiles%2Fsrc%2Fstrings.h;0;4
38 | FILE_NAME_6=166;C;0;EUTF-8;0;1;0;%2Fhome%2Fpi%2Fwhatfiles%2Fsrc%2Fwhatfiles.c;0;4
39 | FILE_NAME_7=1087;C++;0;EUTF-8;0;1;0;%2Fhome%2Fpi%2Fwhatfiles%2Fsrc%2Fwhatfiles.h;0;4
40 | FILE_NAME_8=0;C++;0;EUTF-8;1;1;0;%2Fusr%2Finclude%2Farm-linux-gnueabihf%2Fasm%2Fptrace.h;0;4
41 | FILE_NAME_9=0;C++;0;EUTF-8;0;1;0;%2Fusr%2Finclude%2Farm-linux-gnueabihf%2Fsys%2Fptrace.h;0;2
42 | FILE_NAME_10=0;C++;0;EUTF-8;1;1;0;%2Fusr%2Finclude%2Flinux%2Fptrace.h;0;4
43 | FILE_NAME_11=1732;C++;0;EUTF-8;0;1;0;%2Fusr%2Finclude%2Farm-linux-gnueabihf%2Fsys%2Fuser.h;0;2
44 | FILE_NAME_12=683;C;0;EUTF-8;0;1;0;%2Fhome%2Fpi%2Fwhatfiles%2Fsrc%2Futilities.c;0;4
45 | FILE_NAME_13=783;C;0;EUTF-8;0;1;0;%2Fhome%2Fpi%2Fwhatfiles%2Fsrc%2Fx86_64%2Fregisters.c;0;4
46 |
47 | [VTE]
48 | last_dir=/home/pi/whatfiles
49 |
50 | [build-menu]
51 | NF_00_LB=_Make
52 | NF_00_CM=make
53 | NF_00_WD=/home/pi/whatfiles
54 | CFT_00_LB=_Compile
55 | CFT_00_CM=gcc -Wall -c "%f"
56 | CFT_00_WD=
57 | filetypes=C;
58 |
--------------------------------------------------------------------------------