├── .gitignore ├── LICENSE.txt ├── README.md ├── example ├── conflict.gif ├── f396862963d4f7ec5f518b09bee77115.yaml └── gzip-O3-moutline ├── labsync.cfg ├── labsync.py ├── requirements.txt ├── ruff.toml └── test_labsync.py /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__/ 2 | .ruff_cache/ 3 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # LabSync 2 | 3 | LabSync is an IDA plugin that can be used to partially synchronize IDBs between different users 4 | working on reversing the same binaries. 5 | 6 | LabSync is intended to be non-intrusive, lightweight, and easy to use for very frequent syncs 7 | (think as frequently and easily as you saved your IDB before Undo was a thing). 8 | 9 | The leading use case is multiple people reversing the same binary at the same time, and especially 10 | for binaries that don't start from a good "baseline" IDB (i.e. no typing information, non-standard 11 | formats or architectures), and whose structure keeps changing during the reversing process. 12 | 13 | ## How it works 14 | 15 | When enabled, whenever the IDB is saved, LabSync will synchronize some of its data with other 16 | reverse engineers using a shared git repo. 17 | 18 | LabSync generates a YAML from some of the data stored in your IDB (e.g. names, types, inlined 19 | functions, etc.), and when you save the IDB this YAML is also committed to the shared git repo. The 20 | repo is then pulled and pushed to sync with others. 21 | 22 | In case there were any remote changes since the last time you saved your IDB, they will be fetched 23 | during the git pull operation and merged into your local changes. 24 | 25 | In case of any merge conflicts, git mergetool will automatically be started for you to resolve them 26 | in a convenient textual format, and the sync process will finish afterwards. 27 | 28 | The YAML for each IDB is saved under the MD5 of the input file, so LabSync is able to sync it with 29 | other reverse engineers no matter their local IDB filename, as long as it originated from the same 30 | binary. 31 | 32 | ## Example 33 | 34 | We generated an example YAML for the `gzip-O3-moutline` example from the FunctionInliner repo 35 | ([source](https://github.com/cellebrite-labs/FunctionInliner/tree/master/test) / 36 | [binary](example/gzip-O3-moutline)) after inlining all outlined 37 | functions, and you can take a look at it [here](example/f396862963d4f7ec5f518b09bee77115.yaml). 38 | 39 | An example of conflict resolution can be seen in the following animation (we change some function 40 | name and sync, while it was also changed in upstream since our last change): 41 | 42 | ![](example/conflict.gif) 43 | 44 | ## Motivation 45 | 46 | In Cellebrite Labs we often have multiple researchers working at the same time on reversing huge 47 | binaries with no symbols or typing information. The structure of some of these also undergos 48 | drastic changes during the reversing process (e.g. when 49 | [FunctionInliner](https://github.com/cellebrite-labs/FunctionInliner) is used). 50 | 51 | After reviewing past and existing IDA synchronization solutions, we failed to find a solution that 52 | satisfied the following requirements: 53 | 54 | 1. Syncing should be very fast and non-intrusive -- either live or as quick and easy as a keypress. 55 | 2. In case of non-live synchronization or live-synchronization supporting offline work 56 | (i.e. where conflicts can occur), we want conflict resolution to be clear, intuitive and 57 | non-intrusive. 58 | 1. Require the least amount of user interaction 59 | 2. Be "easy" for a user unfamiliar with IDA/the solution internals 60 | 3. Conflict resolution should not be a "must" when you just want to open the IDB to check 61 | something 62 | 3. [FunctionInliner](https://github.com/cellebrite-labs/FunctionInliner) should be a "first class 63 | citizen" 64 | 1. IDA's [built-in outlined function support](https://hex-rays.com/blog/igors-tip-of-the-week-106-outlined-functions) 65 | (which is trivial to sync) is not sufficient for "deep" reversing, for example because xrefs 66 | from outlined chunks to functions/data are not propagated the "parent" functions, and because 67 | it makes static analysis of disassembly practically impossible. 68 | 2. Non-live syncing of FunctionInliner's effects on the IDB are practically impossible without 69 | the solution being "FunctionInliner-aware" (i.e. because if two users inline different 70 | functions before syncing, the "clone" segments will most likely collide on the same unused 71 | EAs). 72 | 73 | We tried to develop a solution based on the Pareto principle -- support the minimum amount of 74 | features that will give the maximum amount of assistance to shared reversing work. We also 75 | chose to dismiss syncing of features that, even if very helpful, would require a lot of 76 | maintenance, or would require going down deep rabbit holes of edge cases. For example, we chose to 77 | *not* sync decompiler comments, because we suspected that it will require exact-same decompilation 78 | for all users which is impossible in the general case unless perfect synchronization is achieved 79 | for a lot of other features). 80 | 81 | We chose to use YAML files to store the data because they're easily editable by humans that will 82 | need to understand what's going on and resolve potential conflicts. 83 | 84 | We chose to use git as a backend because it's proven to work well for storing text files, 85 | handling merges and conflicts and everyone already knows how to use it (or should :) ). 86 | 87 | ## Installing 88 | 89 | 1. Install the dependencies listed in `requirements.txt` where IDA can import them. For example 90 | using `/path/to/python3/used/by/ida -m pip install -r requirements.txt`. 91 | 2. Optionally install [FunctionInliner](https://github.com/cellebrite-labs/FunctionInliner). 92 | 3. Clone this repository and symlink `~/.idapro/plugins/labsync.py` to `labsync.py` in the cloned 93 | repo. 94 | 4. Create a new (empty) git repository that will be used for the synchronization data. This repo 95 | should be cloned by all of the users that will share their work. 96 | 5. Follow the next section on how to configure LabSync. 97 | 98 | ## Configuring 99 | 100 | 1. LabSync expects to find its configuration file under `~/.idapro/cfg/labsync.cfg` 101 | 2. Copy the example `labsync.cfg` from this repository and change `repo_path` to point to the path 102 | where your local clone of the *data* repository is (i.e. the one from step 4 above). 103 | 3. Make sure that you have `merge.tool` configured in your git configuration (either globally or 104 | locally for the *data* repo). 105 | 1. You can check what it's globally configured to with `git config --global merge.tool` 106 | 2. In case the above is empty, you should configure it e.g. with 107 | `git config --global merge.tool opendiff` 108 | 3. You can test your configured `merge.tool` using 109 | [this repo](https://github.com/redguardtoo/test-git-mergetool). 110 | 111 | ## Usage 112 | 113 | To start synchronizing the current IDB to LabSync, use `Edit > Plugins > LabSync > Enable`. 114 | 115 | Afterwards -- just save your IDB regularly in order to synchronize to the repository. 116 | 117 | NOTE: when resolving merge conflicts for names/prototypes, make sure that you verify the EAs of the 118 | conflicting chunks you're comparing. Git's merge strategy compares the files line-by-line and 119 | isn't aware of YAML's syntax, so it may create a conflict when two different adjacent keys have 120 | been added to a dictionary such as `names` or `prototypes`. 121 | 122 | ## What does it sync? 123 | 124 | We currently only sync: 125 | 126 | 1. Names given to EAs (e.g. functions, globals) 127 | 2. EAs of functions that have been inlined with functioninliner 128 | 3. Local types (i.e. structures, unions, enums) 129 | 4. Function prototypes 130 | 131 | ## Advanced features 132 | 133 | ### Branching out 134 | 135 | You can checkout a different branch on the data repository and push it to the remote data 136 | repository, and then your changes will sync only with people that are using the same branch, 137 | and won't affect everyone else. 138 | 139 | Unless you intend to merge back into the main branch eventually, it's recommended to keep a copy 140 | of your IDB before you do the above so it'll be easy to revert once done. 141 | 142 | ### Local type tracking 143 | 144 | LabSync generates a UUID for each local type and documents it in a comment above the local type 145 | definition written in the YAML. This is used to track renames of local types, so that we don't 146 | delete and re-create a local type in case it was renamed remotely (since then all references to it 147 | will be destroyed). 148 | 149 | When first enabling sync on an IDB whose binary has already been synced in the past, LabSync will 150 | try to "adopt" the UUIDs saved in the repo for local types that have the same names as those saved 151 | in the repo. 152 | 153 | Note that this is a best-effort heuristical approach to reduce the amount of "duplicate" local 154 | types that will then have to be replaced manually. However, this heuristic might not be complete, 155 | and/or may also lead to false positives (e.g. a logically-different local type with the same name 156 | as one saved in the repo will be assigned its UUID). 157 | 158 | Please take the above into consideration when reviewing the initial commit merge, and replace 159 | false-positive UUIDs with new random ones. 160 | 161 | ### Resetting synchronization 162 | 163 | In order to reset the synchronization state of an IDB, you should first disable the synchronization 164 | using `Edit > Plugins > LabSync > Disable` and then use `Edit > Plugins > LabSync > Reset`. 165 | 166 | If LabSync will be enabled afterwards, it'll treat the IDB as "new" when syncing it with the repo, 167 | and in case it won't be deleted from git, it'll be merged with the existing repo data. 168 | 169 | ### Mapping segments to a different data file 170 | 171 | In some cases it's useful to reverse a binary together with a software library that it uses in the 172 | same IDB. In order to support syncing features related to the library between the IDBs of different 173 | binaries that use it, you can ask LabSync to sync some segments to separate files. 174 | 175 | Note that all of the local types will be synced to all of the associated files, so in case of a 176 | conflict involving local types, you may have to resolve it more than once during conflict 177 | resolution. 178 | 179 | This functionality is mostly intended to be used by IDA loaders, so we don't expose it using UI, 180 | but rather using the following API: 181 | 182 | ```python 183 | from labsync import LabSyncPlugin 184 | LabSyncPlugin.map_segments_to_idb_id(seg_prefix, idb_id) 185 | ``` 186 | 187 | Where `seg_prefix` is e.g. `libwhatever.` and `idb_id` can technically be any string, but is 188 | expected to be the MD5 hash of the `libwhatever` binary. This will cause LabSync to sync features 189 | (e.g. names, prototypes) related to EAs whose segment name starts with `` to 190 | `.yaml` instead of the main YAML file. 191 | 192 | Because the library may be loaded to different EAs in different IDBs, the EAs in the library 193 | YAML will be relative to the start EA of the first matching segment. If needed, you can override 194 | the base EA by providing a `base_ea` argument to `map_segments_to_idb_id`. 195 | 196 | ## Known issues 197 | 198 | 1. LabSync does not currently do things as creating functions or changing their properties, so this 199 | may lead to issues e.g. when syncing inlined functions that don't have the same function end. 200 | 201 | Therefore we recommend to start using LabSync on a certain IDB only after it has passed the 202 | basic preprocessing it has to go through, in case there is any (e.g. inlining all outlined 203 | functions, on applicable IDBs). 204 | 205 | 2. When testing LabSync with IDBs created from binaries that had some type information, we found 206 | that there are multiple kinds of issues with local types and prototypes autogenerated by IDA, 207 | where if you just try to reapply the same local type or prototype that are already there it will 208 | already fail. 209 | 210 | We tried to solve some of them, e.g. by adding forward declarations of pointed types that were 211 | used in function prototypes, but some were more problematic to solve and you will have to solve 212 | them manually. 213 | 214 | Some kinds of the issues we don't currently resolve: 215 | 1. IDA sometimes has issues reapplying prototypes which use namespaced types (e.g. try repplying 216 | the type for the `_copy` function in the `gzip-O3-moutline` example that we used [above]( 217 | #example)). In such cases it's best it's best to tick `Don't display this message again` when 218 | the `Bad declaration. See the message window for details.` popup shows and ignore it. 219 | 2. Syncing of templated types, e.g. from stl (currently we skip dumping them to the YAML and 220 | spit a warning instead). 221 | 3. In some cases IDA generates 222 | [VFT structs](https://docs.hex-rays.com/user-guide/user-interface/menu-bar/view/c++-type-details) 223 | with the `_vtbl_layout` suffix instead of `_vtbl`. 224 | On reimport, IDA will yell that constructors/destructors must have the name of the class 225 | (even though it allows a `_vtbl` suffix). You can rename these structs and change the 226 | `_vtbl_layout` suffix to `_vtbl` in order to work around the issue. 227 | 4. We encountered cases where IDA would complain about `Type 'id' is already defined` where 228 | some struct name is `id` under namespaces. You can rename it to work around the issue. 229 | 5. We encountered an issue where IDA misinterprets nested namespaces, e.g. for: 230 | ```c 231 | struct B::fields { 232 | int b; 233 | }; 234 | 235 | struct A { 236 | B::fields b; 237 | }; 238 | ``` 239 | It complains that `B::A::fields` does not exist. This is problematic with the naming scheme 240 | used by `ida_kernelcache`. We're currently investigating a workaround for this issue. 241 | 242 | ## Troubleshooting 243 | 244 | - Q: I finished resolving a conflict with the mergetool, but IDA still hangs! 245 | - A: In case you're using macOS, you have to actually quit the mergetool application for git/IDA 246 | to see that it's "done". 247 | 248 | 249 | 250 | - Q: Something went wrong during conflict resolution and I just want to go back! 251 | - A: Go to your data repository and do `git merge --abort` 252 | 253 | 254 | 255 | - Q: I have a merge conflict on the UUID comment that LabSync added. What should I do? 256 | - A: First read the part about *Local type tracking* above to understand what these UUIDs mean. 257 | Essentially, what happened is that both you and upstream have added a type with the same 258 | name. If these types are logically different, you can just rename one of them during conflict 259 | resolution. If these types are logically same, you should do the same (rename one of them) and 260 | then replace all of its usages to the other, delete it, and resync. On older IDA versions 261 | there was an [automated way to do it](https://hex-rays.com/blog/igors-tip-of-the-week-142-mapping-local-types), 262 | but at least on IDA 8.4 it seems to be gone. 263 | 264 | ## Future work 265 | 266 | 1. Auto-resolving of YAML conflicts -- a lot of git conflicts can be resolved by a YAML-aware merger 267 | (e.g. when two adjacent functions are renamed, git will conflict but there is no logical 268 | conflict) 269 | 2. Sync "data" types -- currently we only sync types for function EAs (i.e. prototypes) and not for 270 | "data" EAs 271 | 3. Merging names of functions and their prototypes into one in the YAML (currently a logical 272 | conflict in a function name change will result in two git conflicts) 273 | 4. "git blame" tooltip -- see who last named/typed a function to ask them about it 274 | 5. YAML metadata -- add a title/description of the IDB to the YAML 275 | 276 | ## Meta 277 | 278 | Authored by Tomer Harpaz of Cellebrite Labs 279 | Developed and tested for IDA 8.4 on macOS with Python 3.9.19 280 | -------------------------------------------------------------------------------- /example/conflict.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cellebrite-labs/LabSync/07e66fb25e11c85738b32b64248b6620615036b1/example/conflict.gif -------------------------------------------------------------------------------- /example/f396862963d4f7ec5f518b09bee77115.yaml: -------------------------------------------------------------------------------- 1 | inlined_funcs: 2 | - 0x10000dbf8 3 | - 0x10000dc00 4 | - 0x10000dc10 5 | - 0x10000dc1c 6 | - 0x10000dc34 7 | - 0x10000dc44 8 | - 0x10000dc5c 9 | - 0x10000dc64 10 | - 0x10000dc88 11 | - 0x10000dc98 12 | - 0x10000dcc0 13 | - 0x10000dcc8 14 | - 0x10000dcdc 15 | - 0x10000dcf0 16 | - 0x10000dcfc 17 | - 0x10000dd10 18 | - 0x10000dd1c 19 | - 0x10000dd28 20 | - 0x10000dd34 21 | - 0x10000dd4c 22 | - 0x10000dd64 23 | - 0x10000dd7c 24 | - 0x10000dd98 25 | - 0x10000ddb0 26 | - 0x10000ddb8 27 | - 0x10000ddc4 28 | - 0x10000ddd0 29 | - 0x10000dddc 30 | - 0x10000ddf8 31 | - 0x10000de14 32 | - 0x10000de24 33 | - 0x10000de34 34 | - 0x10000de44 35 | - 0x10000de54 36 | - 0x10000de68 37 | - 0x10000de78 38 | - 0x10000de88 39 | - 0x10000dea0 40 | - 0x10000debc 41 | - 0x10000decc 42 | - 0x10000dee8 43 | - 0x10000def4 44 | - 0x10000df08 45 | - 0x10000df14 46 | - 0x10000df20 47 | - 0x10000df34 48 | - 0x10000df4c 49 | - 0x10000df5c 50 | - 0x10000df74 51 | - 0x10000df8c 52 | - 0x10000dfa4 53 | - 0x10000dfac 54 | - 0x10000dfbc 55 | - 0x10000dfdc 56 | - 0x10000dfec 57 | - 0x10000dffc 58 | - 0x10000e008 59 | - 0x10000e010 60 | - 0x10000e018 61 | - 0x10000e028 62 | - 0x10000e038 63 | - 0x10000e044 64 | - 0x10000e05c 65 | - 0x10000e070 66 | - 0x10000e088 67 | - 0x10000e098 68 | - 0x10000e0b8 69 | - 0x10000e0d4 70 | - 0x10000e0e4 71 | - 0x10000e0f8 72 | - 0x10000e10c 73 | - 0x10000e120 74 | - 0x10000e12c 75 | - 0x10000e140 76 | - 0x10000e154 77 | - 0x10000e160 78 | - 0x10000e174 79 | - 0x10000e17c 80 | - 0x10000e18c 81 | - 0x10000e1a0 82 | - 0x10000e1b4 83 | - 0x10000e1d0 84 | - 0x10000e1dc 85 | - 0x10000e1e8 86 | - 0x10000e1f0 87 | - 0x10000e204 88 | - 0x10000e210 89 | - 0x10000e21c 90 | - 0x10000e230 91 | - 0x10000e238 92 | - 0x10000e240 93 | - 0x10000e254 94 | - 0x10000e268 95 | - 0x10000e27c 96 | - 0x10000e290 97 | - 0x10000e29c 98 | - 0x10000e2a8 99 | - 0x10000e2b4 100 | - 0x10000e2c0 101 | - 0x10000e2cc 102 | - 0x10000e2d4 103 | local_types: |- 104 | /* >> LABSYNC DO NOT TOUCH: 5acbdd09-fb3c-4ea8-bf8a-0c8bee6459ce << */ 105 | struct _RuneCharClass 106 | { 107 | char __name[14]; 108 | __uint32_t __mask; 109 | }; 110 | 111 | /* >> LABSYNC DO NOT TOUCH: 2d818a33-0259-4061-82db-e1a6d943d47e << */ 112 | struct _RuneEntry 113 | { 114 | __darwin_rune_t __min; 115 | __darwin_rune_t __max; 116 | __darwin_rune_t __map; 117 | __uint32_t *__types; 118 | }; 119 | 120 | /* >> LABSYNC DO NOT TOUCH: 4e2dc9c5-6cb8-4d6f-a984-bcbb69eda153 << */ 121 | struct _RuneLocale 122 | { 123 | char __magic[8]; 124 | char __encoding[32]; 125 | __darwin_rune_t (__cdecl *__sgetrune)(const char *, __darwin_size_t, const char **); 126 | int (__cdecl *__sputrune)(__darwin_rune_t, char *, __darwin_size_t, char **); 127 | __darwin_rune_t __invalid_rune; 128 | __uint32_t __runetype[256]; 129 | __darwin_rune_t __maplower[256]; 130 | __darwin_rune_t __mapupper[256]; 131 | _RuneRange __runetype_ext; 132 | _RuneRange __maplower_ext; 133 | _RuneRange __mapupper_ext; 134 | void *__variable; 135 | int __variable_len; 136 | int __ncharclasses; 137 | _RuneCharClass *__charclasses; 138 | }; 139 | 140 | /* >> LABSYNC DO NOT TOUCH: 3f221dd1-ba46-40f4-9674-3ba0e8c83150 << */ 141 | struct _RuneRange 142 | { 143 | int __nranges; 144 | _RuneEntry *__ranges; 145 | }; 146 | 147 | /* >> LABSYNC DO NOT TOUCH: 23ad52d3-b27c-45b6-b4ef-2e6b29f41102 << */ 148 | typedef __int64_t __darwin_blkcnt_t; 149 | 150 | /* >> LABSYNC DO NOT TOUCH: 5830a09c-64e3-49cf-adb1-7c95da42764d << */ 151 | typedef __int32_t __darwin_blksize_t; 152 | 153 | /* >> LABSYNC DO NOT TOUCH: 961eb519-612d-4165-80ee-b4f4d4931d06 << */ 154 | typedef __int32_t __darwin_dev_t; 155 | 156 | /* >> LABSYNC DO NOT TOUCH: 1fcd322b-9900-4931-b66a-e48e50a95901 << */ 157 | typedef __uint32_t __darwin_gid_t; 158 | 159 | /* >> LABSYNC DO NOT TOUCH: ba544ace-be19-420b-b925-7fe250df7d72 << */ 160 | typedef __uint64_t __darwin_ino64_t; 161 | 162 | /* >> LABSYNC DO NOT TOUCH: b50fc9d0-ae4f-4684-a90b-0daa8cac609d << */ 163 | typedef __uint16_t __darwin_mode_t; 164 | 165 | /* >> LABSYNC DO NOT TOUCH: 2a88c553-411f-44b5-9945-ab07e185c072 << */ 166 | typedef __int64_t __darwin_off_t; 167 | 168 | /* >> LABSYNC DO NOT TOUCH: 5ec1d659-94a0-4c9d-a7d6-1f3877c7618c << */ 169 | typedef __darwin_wchar_t __darwin_rune_t; 170 | 171 | /* >> LABSYNC DO NOT TOUCH: d60b92ae-3e37-4bfa-be13-bbb6b80ac3da << */ 172 | typedef unsigned __int64 __darwin_size_t; 173 | 174 | /* >> LABSYNC DO NOT TOUCH: 4114422b-3e48-48da-9497-c7c32a1197a7 << */ 175 | typedef __int64 __darwin_time_t; 176 | 177 | /* >> LABSYNC DO NOT TOUCH: 37da2e80-af94-44f3-9e19-7e3b11de903f << */ 178 | typedef __uint32_t __darwin_uid_t; 179 | 180 | /* >> LABSYNC DO NOT TOUCH: 57cbd9ef-c228-43cc-954a-7802db709b84 << */ 181 | typedef int __darwin_wchar_t; 182 | 183 | /* >> LABSYNC DO NOT TOUCH: 2169feda-a5d4-4f46-8961-c62c6bd0d67f << */ 184 | typedef int __int32_t; 185 | 186 | /* >> LABSYNC DO NOT TOUCH: 756f423f-8d5d-4cde-884b-05f74481284f << */ 187 | typedef __int64 __int64_t; 188 | 189 | /* >> LABSYNC DO NOT TOUCH: d3fd903e-9fd4-4a71-a2c6-ecbb5a2c2981 << */ 190 | union __attribute__((aligned(8))) __n128 191 | { 192 | unsigned __int64 n128_u64[2]; 193 | unsigned __int32 n128_u32[4]; 194 | unsigned __int16 n128_u16[8]; 195 | unsigned __int8 n128_u8[16]; 196 | __int64 n128_i64[2]; 197 | __int32 n128_i32[4]; 198 | __int16 n128_i16[8]; 199 | __int8 n128_i8[16]; 200 | float n128_f32[4]; 201 | double n128_f64[2]; 202 | }; 203 | 204 | /* >> LABSYNC DO NOT TOUCH: 866ba5ac-0770-4ec3-b749-6672d21fbd3a << */ 205 | union __attribute__((aligned(8))) __n64 206 | { 207 | unsigned __int64 n64_u64[1]; 208 | unsigned __int32 n64_u32[2]; 209 | unsigned __int16 n64_u16[4]; 210 | unsigned __int8 n64_u8[8]; 211 | __int64 n64_i64[1]; 212 | __int32 n64_i32[2]; 213 | __int16 n64_i16[4]; 214 | __int8 n64_i8[8]; 215 | float n64_f32[2]; 216 | double n64_f64[1]; 217 | }; 218 | 219 | /* >> LABSYNC DO NOT TOUCH: a36a6c9d-afa6-4fb1-a307-b31d39c222e7 << */ 220 | typedef unsigned __int16 __uint16_t; 221 | 222 | /* >> LABSYNC DO NOT TOUCH: 985a4a22-2144-4f77-be7e-aed577891491 << */ 223 | typedef unsigned int __uint32_t; 224 | 225 | /* >> LABSYNC DO NOT TOUCH: c9a8b4f6-de58-46a2-9fe7-1e2f501abe29 << */ 226 | typedef unsigned __int64 __uint64_t; 227 | 228 | /* >> LABSYNC DO NOT TOUCH: e512452e-e829-4fc2-9925-026bbe3f23f2 << */ 229 | typedef __darwin_blkcnt_t blkcnt_t; 230 | 231 | /* >> LABSYNC DO NOT TOUCH: 046a1035-675c-4c3e-8350-ca5df1e1987b << */ 232 | typedef __darwin_blksize_t blksize_t; 233 | 234 | /* >> LABSYNC DO NOT TOUCH: 66bd002a-10f2-4108-9563-af0d17f7a3af << */ 235 | struct build_version_command 236 | { 237 | uint32_t cmd; 238 | uint32_t cmdsize; 239 | uint32_t platform; 240 | uint32_t minos; 241 | uint32_t sdk; 242 | uint32_t ntools; 243 | }; 244 | 245 | /* >> LABSYNC DO NOT TOUCH: c8fc54b8-2193-4465-aea7-9dc8f3e75335 << */ 246 | typedef __darwin_dev_t dev_t; 247 | 248 | /* >> LABSYNC DO NOT TOUCH: 95bff06c-412e-42fc-b43f-ad3078c2b977 << */ 249 | struct dyld_info_command 250 | { 251 | uint32_t cmd; 252 | uint32_t cmdsize; 253 | uint32_t rebase_off; 254 | uint32_t rebase_size; 255 | uint32_t bind_off; 256 | uint32_t bind_size; 257 | uint32_t weak_bind_off; 258 | uint32_t weak_bind_size; 259 | uint32_t lazy_bind_off; 260 | uint32_t lazy_bind_size; 261 | uint32_t export_off; 262 | uint32_t export_size; 263 | }; 264 | 265 | /* >> LABSYNC DO NOT TOUCH: c29daf04-4027-4039-a4ae-60500fd4d765 << */ 266 | struct dylib 267 | { 268 | lc_str name; 269 | uint32_t timestamp; 270 | uint32_t current_version; 271 | uint32_t compatibility_version; 272 | }; 273 | 274 | /* >> LABSYNC DO NOT TOUCH: 824cfa9a-83f5-484b-aab8-7ab4e6b007ea << */ 275 | struct dylib_command 276 | { 277 | uint32_t cmd; 278 | uint32_t cmdsize; 279 | dylib dylib; 280 | }; 281 | 282 | /* >> LABSYNC DO NOT TOUCH: 20ac51a8-fe70-4fe0-b5ce-6d6eec53ffd7 << */ 283 | struct dylinker_command 284 | { 285 | uint32_t cmd; 286 | uint32_t cmdsize; 287 | lc_str name; 288 | }; 289 | 290 | /* >> LABSYNC DO NOT TOUCH: 3ba4b053-70ef-41da-bc09-77dc73aa85c7 << */ 291 | struct dysymtab_command 292 | { 293 | uint32_t cmd; 294 | uint32_t cmdsize; 295 | uint32_t ilocalsym; 296 | uint32_t nlocalsym; 297 | uint32_t iextdefsym; 298 | uint32_t nextdefsym; 299 | uint32_t iundefsym; 300 | uint32_t nundefsym; 301 | uint32_t tocoff; 302 | uint32_t ntoc; 303 | uint32_t modtaboff; 304 | uint32_t nmodtab; 305 | uint32_t extrefsymoff; 306 | uint32_t nextrefsyms; 307 | uint32_t indirectsymoff; 308 | uint32_t nindirectsyms; 309 | uint32_t extreloff; 310 | uint32_t nextrel; 311 | uint32_t locreloff; 312 | uint32_t nlocrel; 313 | }; 314 | 315 | /* >> LABSYNC DO NOT TOUCH: 974e690c-0e27-431e-beb4-775ab098c46e << */ 316 | struct entry_point_command 317 | { 318 | uint32_t cmd; 319 | uint32_t cmdsize; 320 | uint64_t entryoff; 321 | uint64_t stacksize; 322 | }; 323 | 324 | /* >> LABSYNC DO NOT TOUCH: 54768367-3987-4ff3-af0e-a4842935100e << */ 325 | typedef float16x4_t float16x2_t; 326 | 327 | /* >> LABSYNC DO NOT TOUCH: 44f80af5-79a5-4185-b0e4-71b2a6a60a50 << */ 328 | typedef __darwin_gid_t gid_t; 329 | 330 | /* >> LABSYNC DO NOT TOUCH: b2705078-e71f-4465-af74-08b0db811216 << */ 331 | typedef int16x4_t int16x2_t; 332 | 333 | /* >> LABSYNC DO NOT TOUCH: af9fc1f4-d91c-4ee4-a4e2-1f2f3d218372 << */ 334 | typedef int int32_t; 335 | 336 | /* >> LABSYNC DO NOT TOUCH: 1739cc51-aa3a-4f93-bf45-7537e362e901 << */ 337 | union lc_str 338 | { 339 | uint32_t offset; 340 | }; 341 | 342 | /* >> LABSYNC DO NOT TOUCH: 71073399-a183-43e0-9dc6-ae252c641bb7 << */ 343 | struct linkedit_data_command 344 | { 345 | uint32_t cmd; 346 | uint32_t cmdsize; 347 | uint32_t dataoff; 348 | uint32_t datasize; 349 | }; 350 | 351 | /* >> LABSYNC DO NOT TOUCH: ce4306db-1003-42ae-946e-263e6eacd58d << */ 352 | struct mach_header_64 353 | { 354 | uint32_t magic; 355 | int32_t cputype; 356 | int32_t cpusubtype; 357 | uint32_t filetype; 358 | uint32_t ncmds; 359 | uint32_t sizeofcmds; 360 | uint32_t flags; 361 | uint32_t reserved; 362 | }; 363 | 364 | /* >> LABSYNC DO NOT TOUCH: 9d734e39-277e-40f1-8c19-cc0590603b20 << */ 365 | typedef __darwin_mode_t mode_t; 366 | 367 | /* >> LABSYNC DO NOT TOUCH: 0012d8a6-a6ef-41c9-b92f-408e7159c9f6 << */ 368 | typedef __uint16_t nlink_t; 369 | 370 | /* >> LABSYNC DO NOT TOUCH: f6ecd5f9-54d7-45db-9bad-46fd0b338d09 << */ 371 | typedef __darwin_off_t off_t; 372 | 373 | /* >> LABSYNC DO NOT TOUCH: 6dd54d24-31aa-4866-8cc5-953e3212cec8 << */ 374 | struct section_64 375 | { 376 | char sectname[16] __strlit(C,"UTF-8"); 377 | char segname[16] __strlit(C,"UTF-8"); 378 | uint64_t addr; 379 | uint64_t size; 380 | uint32_t offset; 381 | uint32_t align; 382 | uint32_t reloff; 383 | uint32_t nreloc; 384 | uint32_t flags; 385 | uint32_t reserved1; 386 | uint32_t reserved2; 387 | uint32_t reserved3; 388 | }; 389 | 390 | /* >> LABSYNC DO NOT TOUCH: fbc3b44e-8448-4241-9955-214c91b8edaf << */ 391 | struct segment_command_64 392 | { 393 | uint32_t cmd; 394 | uint32_t cmdsize; 395 | char segname[16] __strlit(C,"UTF-8"); 396 | uint64_t vmaddr; 397 | uint64_t vmsize; 398 | uint64_t fileoff; 399 | uint64_t filesize; 400 | int32_t maxprot; 401 | int32_t initprot; 402 | uint32_t nsects; 403 | uint32_t flags; 404 | }; 405 | 406 | /* >> LABSYNC DO NOT TOUCH: 51daed76-64f3-4c64-9392-cd82cfd1c1f1 << */ 407 | struct source_version_command 408 | { 409 | uint32_t cmd; 410 | uint32_t cmdsize; 411 | uint64_t version; 412 | }; 413 | 414 | /* >> LABSYNC DO NOT TOUCH: de37c4b5-0ec2-4cfb-95bd-7e85361e27f5 << */ 415 | struct stat 416 | { 417 | dev_t st_dev; 418 | mode_t st_mode; 419 | nlink_t st_nlink; 420 | __darwin_ino64_t st_ino; 421 | uid_t st_uid; 422 | gid_t st_gid; 423 | dev_t st_rdev; 424 | timespec st_atimespec; 425 | timespec st_mtimespec; 426 | timespec st_ctimespec; 427 | timespec st_birthtimespec; 428 | off_t st_size; 429 | blkcnt_t st_blocks; 430 | blksize_t st_blksize; 431 | __uint32_t st_flags; 432 | __uint32_t st_gen; 433 | __int32_t st_lspare; 434 | __int64_t st_qspare[2]; 435 | }; 436 | 437 | /* >> LABSYNC DO NOT TOUCH: 1aa588d7-4d71-4ba7-8e85-9ac75753f253 << */ 438 | struct symtab_command 439 | { 440 | uint32_t cmd; 441 | uint32_t cmdsize; 442 | uint32_t symoff; 443 | uint32_t nsyms; 444 | uint32_t stroff; 445 | uint32_t strsize; 446 | }; 447 | 448 | /* >> LABSYNC DO NOT TOUCH: 8b27fdb5-a146-440d-ba0a-15faef0f91e2 << */ 449 | typedef __darwin_time_t time_t; 450 | 451 | /* >> LABSYNC DO NOT TOUCH: 7f9f9eaf-a2f2-4627-b738-976aca72cc37 << */ 452 | struct timespec 453 | { 454 | __darwin_time_t tv_sec; 455 | __int64 tv_nsec; 456 | }; 457 | 458 | /* >> LABSYNC DO NOT TOUCH: d1d70767-818a-4d0c-bab1-545df4b16694 << */ 459 | typedef unsigned int u_int32_t; 460 | 461 | /* >> LABSYNC DO NOT TOUCH: 9dc51d65-2de3-4771-9020-70bcc497a13c << */ 462 | typedef unsigned __int64 u_int64_t; 463 | 464 | /* >> LABSYNC DO NOT TOUCH: d4948a53-1864-4107-8484-912bf5b67b36 << */ 465 | typedef unsigned __int8 u_int8_t; 466 | 467 | /* >> LABSYNC DO NOT TOUCH: c8b2e277-690e-4259-94e8-07b8f4f63841 << */ 468 | typedef __darwin_uid_t uid_t; 469 | 470 | /* >> LABSYNC DO NOT TOUCH: 7237edb2-e0ab-40f9-95e4-08232922e0cd << */ 471 | typedef uint16x4_t uint16x2_t; 472 | 473 | /* >> LABSYNC DO NOT TOUCH: 9b913b91-db29-40c3-a47a-85745d939b7c << */ 474 | typedef u_int32_t uint32_t; 475 | 476 | /* >> LABSYNC DO NOT TOUCH: 0ecbf17f-b3db-4cf5-a4ac-76456e96ee85 << */ 477 | typedef u_int64_t uint64_t; 478 | 479 | /* >> LABSYNC DO NOT TOUCH: 9758bf7e-c5a0-4888-ae4b-a5f81671454a << */ 480 | typedef u_int8_t uint8_t; 481 | 482 | /* >> LABSYNC DO NOT TOUCH: 0fc9f00a-b75f-4564-bca1-b45f4ef139a2 << */ 483 | struct utimbuf 484 | { 485 | time_t actime; 486 | time_t modtime; 487 | }; 488 | 489 | /* >> LABSYNC DO NOT TOUCH: d9880975-e8a9-4cfa-bb72-5927bdbcde62 << */ 490 | struct uuid_command 491 | { 492 | uint32_t cmd; 493 | uint32_t cmdsize; 494 | uint8_t uuid[16]; 495 | }; 496 | names: 497 | 0x100000000: __mh_execute_header 498 | 0x1000005ec: aUsrLibDyld 499 | 0x100000678: aUsrLibLibsyste 500 | 0x10000173c: _bi_init 501 | 0x100001768: _file_read 502 | 0x100001864: _send_bits 503 | 0x1000019bc: _flush_outbuf 504 | 0x1000019fc: _bi_reverse 505 | 0x100001a28: _bi_windup 506 | 0x100001b8c: _copy_block 507 | 0x100001d9c: _lm_init 508 | 0x10000201c: _error 509 | 0x10000205c: _longest_match 510 | 0x1000022ec: _deflate 511 | 0x100002ed4: _ct_tally 512 | 0x100003208: _flush_block 513 | 0x100003898: __getopt_internal 514 | 0x100004480: _getopt 515 | 0x10000448c: _zip 516 | 0x100004954: _main 517 | 0x1000051c4: def_100004B84 518 | 0x100005208: _base_name 519 | 0x100005230: _add_envopt 520 | 0x100005414: _abort_gzip_signal 521 | 0x100005424: _getopt_long 522 | 0x100005428: _lzw 523 | 0x100005494: _treat_file 524 | 0x100005cfc: _treat_stdin 525 | 0x1000060d4: _do_list 526 | 0x100006738: _abort_gzip 527 | 0x1000067a4: _huft_build 528 | 0x100006f64: _huft_free 529 | 0x100006f8c: _inflate_codes 530 | 0x10000757c: _fill_inbuf 531 | 0x100007718: _flush_window 532 | 0x100007798: _inflate_stored 533 | 0x100007a74: _inflate_fixed 534 | 0x100007bc8: _inflate_dynamic 535 | 0x100008220: _inflate_block 536 | 0x10000836c: _inflate 537 | 0x100008460: _ct_init 538 | 0x10000882c: _gen_codes 539 | 0x1000089c4: _init_block 540 | 0x100008adc: _build_tree_1 541 | 0x100009138: _compress_block 542 | 0x1000092ac: _unlzh 543 | 0x100009bb0: _write_buf 544 | 0x100009c14: _unlzw 545 | 0x10000a3ac: _read_error 546 | 0x10000a418: _unpack 547 | 0x10000ab2c: _check_zipfile 548 | 0x10000ac3c: _unzip 549 | 0x10000b4f8: _updcrc 550 | 0x10000b538: _copy 551 | 0x10000b648: _clear_bufs 552 | 0x10000b674: _write_error 553 | 0x10000b6c0: _strlwr 554 | 0x10000b73c: _xunlink 555 | 0x10000b740: _make_simple_name 556 | 0x10000b78c: _xmalloc 557 | 0x10000b7e0: _warning 558 | 0x10000b84c: _display_ratio 559 | 0x10000b894: _fprint_off 560 | 0x10000b9a8: _yesno 561 | 0x10000ba6c: _rpmatch 562 | 0x10000baa0: _getopt_long_only 563 | 0x10000baa8: _get_method 564 | 0x10000c41c: _reset_times 565 | 0x10000c4e0: _make_ofname 566 | 0x10000c730: _create_outfile 567 | 0x10000ccc4: _copy_stat 568 | 0x10000ce94: _get_suffix 569 | 0x10000d01c: _shorten_name 570 | 0x10000d24c: _do_remove 571 | 0x10000d280: _send_tree 572 | 0x10000d590: _fillbuf 573 | 0x10000d6bc: _read_pt_len 574 | 0x10000d8a4: _make_table 575 | 0x10000dbf0: _OUTLINED_FUNCTION_0 576 | 0x10000dcb0: _OUTLINED_FUNCTION_11 577 | 0x10000dcb8: _OUTLINED_FUNCTION_12 578 | 0x10000dd08: _OUTLINED_FUNCTION_18 579 | 0x10000dda8: _OUTLINED_FUNCTION_27 580 | 0x10000de98: _OUTLINED_FUNCTION_42 581 | 0x10000dec4: _OUTLINED_FUNCTION_45 582 | 0x10000df2c: _OUTLINED_FUNCTION_52 583 | 0x10000dfd4: _OUTLINED_FUNCTION_61 584 | 0x10000e068: _OUTLINED_FUNCTION_72 585 | 0x10000e0b0: _OUTLINED_FUNCTION_76 586 | 0x10000e184: _OUTLINED_FUNCTION_89 587 | 0x10000e1c8: _OUTLINED_FUNCTION_93 588 | 0x10000e2e0: _progerror 589 | 0x10000e330: _treat_file.cold.1 590 | 0x10000e380: _treat_file.cold.2 591 | 0x10000e404: _treat_file.cold.3 592 | 0x10000e454: _treat_stdin.cold.1 593 | 0x10000e4e8: _write_buf.cold.1 594 | 0x10000e534: _unlzw.cold.1 595 | 0x10000e580: _create_outfile.cold.1 596 | 0x10000e5ec: _create_outfile.cold.2 597 | 0x10000e66c: _create_outfile.cold.3 598 | 0x10000e6c0: ___error 599 | 0x10000e6cc: ___maskrune 600 | 0x10000e6d8: ___strcat_chk 601 | 0x10000e6e4: ___strcpy_chk 602 | 0x10000e6f0: ___tolower 603 | 0x10000e6fc: __exit 604 | 0x10000e708: _atoi 605 | 0x10000e714: _bzero 606 | 0x10000e720: _calloc 607 | 0x10000e72c: _close 608 | 0x10000e738: _closedir 609 | 0x10000e744: _ctime 610 | 0x10000e750: _exit 611 | 0x10000e75c: _fchmod 612 | 0x10000e768: _fchown 613 | 0x10000e774: _fflush 614 | 0x10000e780: _fileno 615 | 0x10000e78c: _fprintf 616 | 0x10000e798: _fputc 617 | 0x10000e7a4: _free 618 | 0x10000e7b0: _fstat 619 | 0x10000e7bc: _fwrite 620 | 0x10000e7c8: _getchar 621 | 0x10000e7d4: _getenv 622 | 0x10000e7e0: _isatty 623 | 0x10000e7ec: _lseek 624 | 0x10000e7f8: _lstat 625 | 0x10000e804: _malloc 626 | 0x10000e810: _memcpy 627 | 0x10000e81c: _memset 628 | 0x10000e828: _memset_pattern16 629 | 0x10000e834: _open 630 | 0x10000e840: _opendir 631 | 0x10000e84c: _perror 632 | 0x10000e858: _printf 633 | 0x10000e864: _putc 634 | 0x10000e870: _putchar 635 | 0x10000e87c: _puts 636 | 0x10000e888: _read 637 | 0x10000e894: _readdir 638 | 0x10000e8a0: _signal 639 | 0x10000e8ac: _stat 640 | 0x10000e8b8: _strchr 641 | 0x10000e8c4: _strcmp 642 | 0x10000e8d0: _strcpy 643 | 0x10000e8dc: _strcspn 644 | 0x10000e8e8: _strlen 645 | 0x10000e8f4: _strncmp 646 | 0x10000e900: _strrchr 647 | 0x10000e90c: _strspn 648 | 0x10000e918: _unlink 649 | 0x10000e924: _utime 650 | 0x10000e930: _write 651 | 0x10000ebd0: jpt_100004B84 652 | 0x10000ecc0: _configuration_table 653 | 0x10000ed10: _border 654 | 0x10000ed5c: _bl_order 655 | 0x10000edb0: aBadPackLevel 656 | 0x10000edc2: aSOptionSIsAmbi 657 | 0x10000ede0: aSOptionSDoesnT 658 | 0x10000ee0d: aSOptionCSDoesn 659 | 0x10000ee3a: aSOptionSRequir 660 | 0x10000ee60: aSUnrecognizedO 661 | 0x10000ee80: aSUnrecognizedO_0 662 | 0x10000eea1: aSIllegalOption 663 | 0x10000eebb: aSInvalidOption 664 | 0x10000eed5: aSOptionRequire 665 | 0x10000eefc: aSOptionWSIsAmb 666 | 0x10000ef1d: aSOptionWSDoesn 667 | 0x10000ef4b: aAscii 668 | 0x10000ef51: aToStdout 669 | 0x10000ef5b: aStdout 670 | 0x10000ef62: aDecompress 671 | 0x10000ef6d: aUncompress 672 | 0x10000ef78: aForce 673 | 0x10000ef7e: aHelp 674 | 0x10000ef83: aList 675 | 0x10000ef88: aLicense 676 | 0x10000ef90: aNoName 677 | 0x10000ef98: aName 678 | 0x10000ef9d: aQuiet 679 | 0x10000efa3: aSilent 680 | 0x10000efaa: aRecursive 681 | 0x10000efb4: aSuffix 682 | 0x10000efbb: aTest 683 | 0x10000efc0: aNoTime 684 | 0x10000efc8: aVerbose 685 | 0x10000efd0: aVersion 686 | 0x10000efd8: aFast 687 | 0x10000efdd: aBest 688 | 0x10000efe2: aLzw 689 | 0x10000efe6: aBits 690 | 0x10000efeb: aRsyncable 691 | 0x10000eff5: aExe 692 | 0x10000effa: aGzip 693 | 0x10000efff: aUn 694 | 0x10000f002: aGun 695 | 0x10000f006: aCat 696 | 0x10000f00a: aGzcat 697 | 0x10000f010: aGz 698 | 0x10000f014: aAbCdfhhLlmmnnq 699 | 0x10000f035: aSBOperandIsNot 700 | 0x10000f057: aSZNotSupported 701 | 0x10000f07d: aSOptionAsciiIg 702 | 0x10000f0a8: aSIncorrectSuff 703 | 0x10000f0c3: aIncompleteLite 704 | 0x10000f0dd: aIncompleteDist 705 | 0x10000f0f8: aOutputInCompre 706 | 0x10000f124: aSSWarningUnkno 707 | 0x10000f14a: aSSCompressedWi 708 | 0x10000f185: aCorruptInput 709 | 0x10000f194: aCorruptInputUs 710 | 0x10000f1c2: aInvalidCompres 711 | 0x10000f1e8: aSSNotAValidZip 712 | 0x10000f207: aSSFirstEntryNo 713 | 0x10000f241: aSSEncryptedFil 714 | 0x10000f267: aOutOfMemory 715 | 0x10000f275: aInvalidCompres_0 716 | 0x10000f29e: aLenLdSizLd 717 | 0x10000f2b0: aInvalidCompres_1 718 | 0x10000f2d9: aInternalErrorI 719 | 0x10000f2f8: aSSInvalidCompr 720 | 0x10000f325: aSSInvalidCompr_0 721 | 0x10000f355: aSSHasMoreThanO 722 | 0x10000f383: aSSHasMoreThanO_0 723 | 0x10000f3b3: aArgc0 724 | 0x10000f3bb: aSSS 725 | 0x10000f3c8: aSSWarningS 726 | 0x10000f3dd: aS 727 | 0x10000f3e3: aSUnexpectedEnd 728 | 0x10000f3ff: a51f 729 | 0x10000f40a: aPosixlyCorrect 730 | 0x10000f41a: aUsageSScdfhlln 731 | 0x10000f451: aR 732 | 0x10000f453: aCStdoutWriteOn 733 | 0x10000f49d: aDDecompressDec 734 | 0x10000f4ba: aFForceForceOve 735 | 0x10000f4fe: aHHelpGiveThisH 736 | 0x10000f51f: aLListListCompr 737 | 0x10000f54f: aLLicenseDispla 738 | 0x10000f57a: aNNoNameDoNotSa 739 | 0x10000f5c4: aNNameSaveOrRes 740 | 0x10000f607: aQQuietSuppress 741 | 0x10000f62f: aRRecursiveOper 742 | 0x10000f664: aSSufSuffixSufU 743 | 0x10000f6a4: aTTestTestCompr 744 | 0x10000f6d5: aVVerboseVerbos 745 | 0x10000f6f4: aVVersionDispla 746 | 0x10000f71d: a1FastCompressF 747 | 0x10000f73f: a9BestCompressB 748 | 0x10000f761: aRsyncableMakeR 749 | 0x10000f78f: aFileFilesToDeC 750 | 0x10000f7db: aReportBugsToBu 751 | 0x10000f7fe: aSSS_0 752 | 0x10000f80a: a135 753 | 0x10000f810: a20020930 754 | 0x10000f81b: aCopyright2002F 755 | 0x10000f843: aCopyright19921 756 | 0x10000f868: aThisProgramCom 757 | 0x10000f898: aYouMayRedistri 758 | 0x10000f8c4: aUnderTheTermsO 759 | 0x10000f8f7: aForMoreInforma 760 | 0x10000f93d: aCompilationOpt 761 | 0x10000f959: aDirent 762 | 0x10000f960: aUtime 763 | 0x10000f966: aStdcHeaders 764 | 0x10000f974: aHaveUnistdH 765 | 0x10000f983: aHaveMemoryH 766 | 0x10000f992: aHaveStringH 767 | 0x10000f9a1: aHaveLstat 768 | 0x10000f9ad: aSCompressedDat 769 | 0x10000f9f4: aReadFrom 770 | 0x10000f9fe: aWrittenTo 771 | 0x10000fa09: aDe 772 | 0x10000fa0c: aForHelpTypeSH 773 | 0x10000fa23: aStdin 774 | 0x10000fa29: aStandardInput 775 | 0x10000fa38: aOk 776 | 0x10000fa3d: aS_0 777 | 0x10000fa45: aSSUnknownMetho 778 | 0x10000fa71: aSSIsEncryptedN 779 | 0x10000fa97: aSSIsAAMultiPar 780 | 0x10000facc: aSSHasFlags0xXN 781 | 0x10000faf4: aSSPartNumberU 782 | 0x10000fb0c: aSSExtraFieldOf 783 | 0x10000fb35: aCorruptedInput 784 | 0x10000fb5c: aPk 785 | 0x10000fb6a: aSSNotInGzipFor 786 | 0x10000fb87: aSSDecompressio 787 | 0x10000fbbf: aSSDecompressio_0 788 | 0x10000fbf6: aSSIsADirectory 789 | 0x10000fc18: aSSIsNotADirect 790 | 0x10000fc4f: aSSHasLuOtherLi 791 | 0x10000fc79: aSSCompressedTo 792 | 0x10000fc92: aS_1 793 | 0x10000fc97: aOk_0 794 | 0x10000fc9b: aReplacedWithS 795 | 0x10000fcb0: aZ 796 | 0x10000fcb3: aZ_0 797 | 0x10000fcb6: aZ_1 798 | 0x10000fcb9: aSSFileNameTooL 799 | 0x10000fcd5: aTaz 800 | 0x10000fcda: aTgz 801 | 0x10000fcdf: aGz_0 802 | 0x10000fce3: aZ_2 803 | 0x10000fce6: aZ_3 804 | 0x10000fced: aSSSPathnameToo 805 | 0x10000fd0b: aSSUnknownSuffi 806 | 0x10000fd2e: aTar 807 | 0x10000fd33: aSSAlreadyHasSS 808 | 0x10000fd5e: aSSWarningNameT 809 | 0x10000fd7f: aSSCannotScompr 810 | 0x10000fda6: aSSAndSAreTheSa 811 | 0x10000fdc7: aSSAlreadyExist 812 | 0x10000fdde: aDoYouWishToOve 813 | 0x10000fe03: aNotOverwritten 814 | 0x10000fe15: aNameTooShort 815 | 0x10000fe24: aCanTRecoverSuf 816 | 0x10000fe3a: aInternalErrorI_0 817 | 0x10000fe59: aSTimeStampRest 818 | 0x10000fe72: aStore 819 | 0x10000fe78: aCompr 820 | 0x10000fe7e: aPack 821 | 0x10000fe84: aLzh 822 | 0x10000fe8a: aDefla 823 | 0x10000fe90: aMethodCrcDateT 824 | 0x10000fead: aSSRatioUncompr 825 | 0x10000fed3: aCompressed 826 | 0x10000fede: aUncompressed 827 | 0x10000ff08: a5s08lx11s 828 | 0x10000ff18: aS_2 829 | 0x10000ff1d: aBadTable 830 | 0x10000ff28: aInvalidCompres_2 831 | 0x10000ff5a: aTooManyLeavesI 832 | 0x10000ff7a: aWrittenByJeanL 833 | 0x10000ff97: aTotals 834 | 0x100010000: __DefaultRuneLocale_ptr 835 | 0x100010008: ___stderrp_ptr 836 | 0x100010010: ___stdinp_ptr 837 | 0x100010018: ___stdoutp_ptr 838 | 0x100010020: dyld_stub_binder_ptr 839 | 0x100010028: _do_list.methods 840 | 0x100014000: ___error_ptr 841 | 0x100014008: ___maskrune_ptr 842 | 0x100014010: ___strcat_chk_ptr 843 | 0x100014018: ___strcpy_chk_ptr 844 | 0x100014020: ___tolower_ptr 845 | 0x100014028: __exit_ptr 846 | 0x100014030: _atoi_ptr 847 | 0x100014038: _bzero_ptr 848 | 0x100014040: _calloc_ptr 849 | 0x100014048: _close_ptr 850 | 0x100014050: _closedir_ptr 851 | 0x100014058: _ctime_ptr 852 | 0x100014060: _exit_ptr 853 | 0x100014068: _fchmod_ptr 854 | 0x100014070: _fchown_ptr 855 | 0x100014078: _fflush_ptr 856 | 0x100014080: _fileno_ptr 857 | 0x100014088: _fprintf_ptr 858 | 0x100014090: _fputc_ptr 859 | 0x100014098: _free_ptr 860 | 0x1000140a0: _fstat_ptr 861 | 0x1000140a8: _fwrite_ptr 862 | 0x1000140b0: _getchar_ptr 863 | 0x1000140b8: _getenv_ptr 864 | 0x1000140c0: _isatty_ptr 865 | 0x1000140c8: _lseek_ptr 866 | 0x1000140d0: _lstat_ptr 867 | 0x1000140d8: _malloc_ptr 868 | 0x1000140e0: _memcpy_ptr 869 | 0x1000140e8: _memset_ptr 870 | 0x1000140f0: _memset_pattern16_ptr 871 | 0x1000140f8: _open_ptr 872 | 0x100014100: _opendir_ptr 873 | 0x100014108: _perror_ptr 874 | 0x100014110: _printf_ptr 875 | 0x100014118: _putc_ptr 876 | 0x100014120: _putchar_ptr 877 | 0x100014128: _puts_ptr 878 | 0x100014130: _read_ptr 879 | 0x100014138: _readdir_ptr 880 | 0x100014140: _signal_ptr 881 | 0x100014148: _stat_ptr 882 | 0x100014150: _strchr_ptr 883 | 0x100014158: _strcmp_ptr 884 | 0x100014160: _strcpy_ptr 885 | 0x100014168: _strcspn_ptr 886 | 0x100014170: _strlen_ptr 887 | 0x100014178: _strncmp_ptr 888 | 0x100014180: _strrchr_ptr 889 | 0x100014188: _strspn_ptr 890 | 0x100014190: _unlink_ptr 891 | 0x100014198: _utime_ptr 892 | 0x1000141a0: _write_ptr 893 | 0x1000141a8: __dyld_private 894 | 0x1000141b0: _window_size 895 | 0x1000141b8: _optind 896 | 0x1000141bc: _opterr 897 | 0x1000141c0: _optopt 898 | 0x1000141c4: _no_name 899 | 0x1000141c8: _no_time 900 | 0x1000141cc: _maxbits 901 | 0x1000141d0: _method 902 | 0x1000141d4: _level 903 | 0x1000141d8: _longopts 904 | 0x1000144f8: _work 905 | 0x100014500: _mask_bits 906 | 0x100014524: _lbits 907 | 0x100014528: _dbits 908 | 0x10001452c: _block_mode 909 | 0x100014530: _updcrc.crc 910 | 0x100014538: _crc_32_tab 911 | 0x100014d38: _get_istat.suffixes 912 | 0x100014d68: _get_suffix.known_suffixes 913 | 0x100014db0: _extra_blbits 914 | 0x100014e00: __MergedGlobals 915 | 0x100015058: _read_buf 916 | 0x100015060: _outcnt 917 | 0x100015064: _good_match 918 | 0x100015068: _nice_match 919 | 0x10001506c: _max_chain_length 920 | 0x100015070: _strstart 921 | 0x100015078: _block_start 922 | 0x100015080: _prev_length 923 | 0x100015084: _match_start 924 | 0x100015088: _rsync 925 | 0x100015090: _optarg 926 | 0x100015098: ___getopt_initialized 927 | 0x10001509c: _ascii 928 | 0x1000150a0: _to_stdout 929 | 0x1000150a4: _decompress 930 | 0x1000150a8: _force 931 | 0x1000150ac: _recursive 932 | 0x1000150b0: _list 933 | 0x1000150b4: _verbose 934 | 0x1000150b8: _quiet 935 | 0x1000150bc: _do_lzw 936 | 0x1000150c0: _test 937 | 0x1000150c4: _exit_code 938 | 0x1000150c8: _args 939 | 0x1000150d0: _remove_ofname 940 | 0x1000150d8: _progname 941 | 0x1000150e0: _env 942 | 0x1000150e8: _foreground 943 | 0x1000150f0: _z_suffix 944 | 0x1000150f8: _z_len 945 | 0x100015100: _hufts 946 | 0x100015108: _bb 947 | 0x100015110: _bk 948 | 0x100015114: _inptr 949 | 0x100015118: _insize 950 | 0x10001511c: _inbuf 951 | 0x10001d160: _file_type 952 | 0x10001d168: _file_method 953 | 0x10001d170: _d_buf 954 | 0x10002d170: _ifd 955 | 0x10002d174: _ofd 956 | 0x10002d178: _ifname 957 | 0x10002d578: _bytes_in 958 | 0x10002d580: _bytes_out 959 | 0x10002d588: _pkzip 960 | 0x10002d58c: _ext_header 961 | 0x10002d590: _decrypt 962 | 0x10002d594: _ofname 963 | 0x10002d994: _save_orig_name 964 | 0x10002d998: _time_stamp 965 | 0x10002d9a0: _header_bytes 966 | 0x10002d9a8: _outbuf 967 | 0x1000321a8: _window 968 | 0x1000421a8: _prev 969 | 0x1000621a8: _last_member 970 | 0x1000621ac: _part_nb 971 | 0x1000621b0: _ifile_size 972 | 0x1000621b8: _total_in 973 | 0x1000621c0: _total_out 974 | 0x1000621c8: _istat 975 | 0x100062258: _key 976 | 0x100062260: _msg_done 977 | 0x100062261: _flag_buf 978 | 0x100063264: _do_list.first_time 979 | 0x100063268: _do_exit.in_exit 980 | 0x10006326c: _heap 981 | 0x100063b60: __MergedGlobals.212 982 | 0x1000648ae: __MergedGlobals.213 983 | 0x100065630: __DefaultRuneLocale 984 | 0x100065638: ___stderrp 985 | 0x100065640: ___stdinp 986 | 0x100065648: ___stdoutp 987 | 0x100065650: dyld_stub_binder 988 | 0x100065658: __imp____error 989 | 0x100065660: __imp____maskrune 990 | 0x100065668: __imp____strcat_chk 991 | 0x100065670: __imp____strcpy_chk 992 | 0x100065678: __imp____tolower 993 | 0x100065680: __imp___exit 994 | 0x100065688: __imp__atoi 995 | 0x100065690: __imp__bzero 996 | 0x100065698: __imp__calloc 997 | 0x1000656a0: __imp__close 998 | 0x1000656a8: __imp__closedir 999 | 0x1000656b0: __imp__ctime 1000 | 0x1000656b8: __imp__exit 1001 | 0x1000656c0: __imp__fchmod 1002 | 0x1000656c8: __imp__fchown 1003 | 0x1000656d0: __imp__fflush 1004 | 0x1000656d8: __imp__fileno 1005 | 0x1000656e0: __imp__fprintf 1006 | 0x1000656e8: __imp__fputc 1007 | 0x1000656f0: __imp__free 1008 | 0x1000656f8: __imp__fstat 1009 | 0x100065700: __imp__fwrite 1010 | 0x100065708: __imp__getchar 1011 | 0x100065710: __imp__getenv 1012 | 0x100065718: __imp__isatty 1013 | 0x100065720: __imp__lseek 1014 | 0x100065728: __imp__lstat 1015 | 0x100065730: __imp__malloc 1016 | 0x100065738: __imp__memcpy 1017 | 0x100065740: __imp__memset 1018 | 0x100065748: __imp__memset_pattern16 1019 | 0x100065750: __imp__open 1020 | 0x100065758: __imp__opendir 1021 | 0x100065760: __imp__perror 1022 | 0x100065768: __imp__printf 1023 | 0x100065770: __imp__putc 1024 | 0x100065778: __imp__putchar 1025 | 0x100065780: __imp__puts 1026 | 0x100065788: __imp__read 1027 | 0x100065790: __imp__readdir 1028 | 0x100065798: __imp__signal 1029 | 0x1000657a0: __imp__stat 1030 | 0x1000657a8: __imp__strchr 1031 | 0x1000657b0: __imp__strcmp 1032 | 0x1000657b8: __imp__strcpy 1033 | 0x1000657c0: __imp__strcspn 1034 | 0x1000657c8: __imp__strlen 1035 | 0x1000657d0: __imp__strncmp 1036 | 0x1000657d8: __imp__strrchr 1037 | 0x1000657e0: __imp__strspn 1038 | 0x1000657e8: __imp__unlink 1039 | 0x1000657f0: __imp__utime 1040 | 0x1000657f8: __imp__write 1041 | prototypes: 1042 | 0x100001768: __int64 __fastcall _file_read(void *, size_t) 1043 | 0x1000022ec: int __cdecl _deflate(z_streamp strm, int flush) 1044 | 0x100003898: __int64 __fastcall __getopt_internal(int, int, char *__s) 1045 | 0x100004480: int __cdecl _getopt(int, char *const [], const char *) 1046 | 0x100004954: int __fastcall _main(int argc, const char **argv, const char **envp) 1047 | 0x100005230: __int64 __fastcall _add_envopt(int, int, char *) 1048 | 0x100005424: int __cdecl _getopt_long(int, char *const *, const char *, const option 1049 | *, int *) 1050 | 0x100005494: __int64 __fastcall _treat_file(_QWORD) 1051 | 0x100005cfc: __int64 __fastcall _treat_stdin(_QWORD) 1052 | 0x1000060d4: __int64 __fastcall _do_list(int) 1053 | 0x10000836c: int __cdecl _inflate(z_streamp strm, int flush) 1054 | 0x100008460: __int64 __fastcall _ct_init(__int64, __int64) 1055 | 0x10000882c: __int64 _gen_codes(void) 1056 | 0x1000089c4: __int64 __fastcall _init_block(_QWORD) 1057 | 0x100009bb0: __int64 __fastcall _write_buf(int, int, size_t __nbyte) 1058 | 0x100009c14: __int64 __fastcall _unlzw(int, int) 1059 | 0x10000b538: void __cdecl _copy(const std::__fs::filesystem::path *__from, const 1060 | std::__fs::filesystem::path *__to, std::__fs::filesystem::copy_options __opt, 1061 | std::error_code *__ec) 1062 | 0x10000b73c: int __cdecl _xunlink(const char *) 1063 | 0x10000b78c: __int64 __fastcall _xmalloc(size_t __size) 1064 | 0x10000ba6c: int __cdecl _rpmatch(const char *) 1065 | 0x10000baa0: int __cdecl _getopt_long_only(int, char *const *, const char *, const 1066 | option *, int *) 1067 | 0x10000de98: __int64 __fastcall _OUTLINED_FUNCTION_42(_QWORD) 1068 | 0x10000dfd4: void __noreturn _OUTLINED_FUNCTION_61(void) 1069 | 0x10000e6c0: int *___error(void) 1070 | 0x10000e6f0: int __cdecl ___tolower(int) 1071 | 0x10000e6fc: void __cdecl __noreturn __exit(int) 1072 | 0x10000e708: int __cdecl _atoi(const char *) 1073 | 0x10000e714: void __cdecl _bzero(void *, size_t) 1074 | 0x10000e720: void *__cdecl _calloc(size_t __count, size_t __size) 1075 | 0x10000e72c: int __cdecl _close(int) 1076 | 0x10000e738: int __cdecl _closedir(DIR *) 1077 | 0x10000e744: char *__cdecl _ctime(const time_t *) 1078 | 0x10000e750: void __cdecl __noreturn _exit(int) 1079 | 0x10000e75c: int __cdecl _fchmod(int, mode_t) 1080 | 0x10000e768: int __cdecl _fchown(int, uid_t, gid_t) 1081 | 0x10000e774: int __cdecl _fflush(FILE *) 1082 | 0x10000e780: int __cdecl _fileno(FILE *) 1083 | 0x10000e78c: int _fprintf(FILE *, const char *, ...) 1084 | 0x10000e798: int __cdecl _fputc(int, FILE *) 1085 | 0x10000e7a4: void __cdecl _free(void *) 1086 | 0x10000e7b0: int __cdecl _fstat(int, stat *) 1087 | 0x10000e7bc: size_t __cdecl _fwrite(const void *__ptr, size_t __size, size_t __nitems, 1088 | FILE *__stream) 1089 | 0x10000e7c8: int _getchar(void) 1090 | 0x10000e7d4: char *__cdecl _getenv(const char *) 1091 | 0x10000e7e0: int __cdecl _isatty(int) 1092 | 0x10000e7ec: off_t __cdecl _lseek(int, off_t, int) 1093 | 0x10000e7f8: int __cdecl _lstat(const char *, stat *) 1094 | 0x10000e804: void *__cdecl _malloc(size_t __size) 1095 | 0x10000e810: void *__cdecl _memcpy(void *__dst, const void *__src, size_t __n) 1096 | 0x10000e81c: void *__cdecl _memset(void *__b, int __c, size_t __len) 1097 | 0x10000e828: void __cdecl _memset_pattern16(void *__b, const void *__pattern16, 1098 | size_t __len) 1099 | 0x10000e834: int _open(const char *, int, ...) 1100 | 0x10000e840: DIR *__cdecl _opendir(const char *) 1101 | 0x10000e84c: void __cdecl _perror(const char *) 1102 | 0x10000e858: int _printf(const char *, ...) 1103 | 0x10000e864: int __cdecl _putc(int, FILE *) 1104 | 0x10000e870: int __cdecl _putchar(int) 1105 | 0x10000e87c: int __cdecl _puts(const char *) 1106 | 0x10000e888: ssize_t __cdecl _read(int, void *, size_t) 1107 | 0x10000e894: dirent *__cdecl _readdir(DIR *) 1108 | 0x10000e8a0: void (__cdecl *__cdecl _signal(int, void (__cdecl *)(int)))(int) 1109 | 0x10000e8ac: int __cdecl _stat(const char *, stat *) 1110 | 0x10000e8b8: char *__cdecl _strchr(char *__s, int __c) 1111 | 0x10000e8c4: int __cdecl _strcmp(const char *__s1, const char *__s2) 1112 | 0x10000e8d0: char *__cdecl _strcpy(char *__dst, const char *__src) 1113 | 0x10000e8dc: size_t __cdecl _strcspn(const char *__s, const char *__charset) 1114 | 0x10000e8e8: size_t __cdecl _strlen(const char *__s) 1115 | 0x10000e8f4: int __cdecl _strncmp(const char *__s1, const char *__s2, size_t __n) 1116 | 0x10000e900: char *__cdecl _strrchr(char *__s, int __c) 1117 | 0x10000e90c: size_t __cdecl _strspn(const char *__s, const char *__charset) 1118 | 0x10000e918: int __cdecl _unlink(const char *) 1119 | 0x10000e924: int __cdecl _utime(const char *, const utimbuf *) 1120 | 0x10000e930: ssize_t __cdecl _write(int __fd, const void *__buf, size_t __nbyte) 1121 | version: 0x4 1122 | -------------------------------------------------------------------------------- /example/gzip-O3-moutline: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cellebrite-labs/LabSync/07e66fb25e11c85738b32b64248b6620615036b1/example/gzip-O3-moutline -------------------------------------------------------------------------------- /labsync.cfg: -------------------------------------------------------------------------------- 1 | repo_path = /path/to/labsync/data/repo 2 | log = INFO 3 | 4 | # advanced 5 | lock_timeout_sec = 10 6 | -------------------------------------------------------------------------------- /labsync.py: -------------------------------------------------------------------------------- 1 | from __future__ import annotations 2 | 3 | import configparser 4 | import contextlib 5 | import dataclasses 6 | import functools 7 | import heapq 8 | import io 9 | import logging 10 | import os 11 | import pathlib 12 | import re 13 | import string 14 | import tempfile 15 | import time 16 | import uuid 17 | from collections.abc import Generator 18 | from typing import IO, Any, Optional 19 | 20 | import git 21 | import parse 22 | import yaml 23 | 24 | try: 25 | import functioninliner 26 | except ModuleNotFoundError: 27 | # define a mock that will allow us to work without functioninliner installed 28 | class functioninliner: # noqa: N801 29 | class ClonesStorage(dict): 30 | def update_from_storage(self) -> None: 31 | pass 32 | 33 | try: 34 | import ida_diskio 35 | import ida_idaapi 36 | import ida_idp 37 | import ida_kernwin 38 | import ida_loader 39 | import ida_nalt 40 | import ida_name 41 | import ida_segment 42 | import ida_typeinf 43 | import ida_xref 44 | import idautils 45 | import netnode 46 | import sark 47 | except ModuleNotFoundError: 48 | # define mocks to support importing outside of IDA for testing 49 | class ida_kernwin: # noqa: N801 50 | class action_handler_t: # noqa: N801 51 | pass 52 | 53 | class UI_Hooks: # noqa: N801 54 | pass 55 | 56 | class ida_idaapi: # noqa: N801 57 | PLUGIN_MOD = 0 58 | PLUGIN_HIDE = 0 59 | BADADDR = 0 60 | 61 | class plugin_t: # noqa: N801 62 | pass 63 | 64 | class ida_idp: # noqa: N801 65 | IDP_INTERFACE_VERSION = 0 66 | 67 | class ida_typeinf: # noqa: N801 68 | class text_sink_t: # noqa: N801 69 | pass 70 | 71 | class tinfo_t: # noqa: N801 72 | pass 73 | 74 | class netnode: # noqa: N801 75 | class Netnode: 76 | pass 77 | 78 | 79 | # CONFIGURATION 80 | 81 | 82 | # we decided not to normalize prototypes because it makes it much harder to resolve conflicts since 83 | # you don't know which function you're looking at 84 | # 85 | # the downside is that a conflict on a function name change will result in two conflicts (one on 86 | # the name and one on the prototype) 87 | NORMALIZE_PROTOTYPES = False 88 | 89 | # we decided not to remove names and prototypes that are missing in the YAML since some times 90 | # exporting/importing them remotely can be an issue and so they will be removed locally as well 91 | REMOVE_MISSING_NAMES_AND_PROTOTYPES = False 92 | 93 | LOCAL_TYPES_COMMENT_FMT = "/* >> LABSYNC DO NOT TOUCH: {} << */" 94 | 95 | LOCKFILE = "labsync.lock" 96 | DEFAULT_LOCK_TIMEOUT = 60 # sec 97 | 98 | 99 | # LOGGING 100 | 101 | 102 | class LoggerWithTrace(logging.getLoggerClass()): 103 | def __init__(self, *args, **kwargs): 104 | super().__init__(*args, **kwargs) 105 | 106 | logging.TRACE = 5 107 | logging.addLevelName(logging.TRACE, "TRACE") 108 | 109 | def trace(self, msg: str, *args, **kwargs) -> None: 110 | self.log(logging.TRACE, msg, *args, **kwargs) 111 | 112 | 113 | logger = LoggerWithTrace("LabSync") 114 | 115 | 116 | # EXCEPTIONS 117 | 118 | 119 | class LabSyncError(Exception): 120 | pass 121 | 122 | 123 | class LabSyncLockError(LabSyncError): 124 | pass 125 | 126 | 127 | class LabSyncBinaryMatchingError(LabSyncError): 128 | pass 129 | 130 | 131 | # HELPERS 132 | 133 | 134 | class LabSyncYAMLDumper(yaml.CDumper): 135 | @staticmethod 136 | def _hex_representer(dumper: yaml.Dumper, data: int) -> str: 137 | return dumper.represent_scalar("tag:yaml.org,2002:int", hex(data)) 138 | 139 | @staticmethod 140 | def _str_representer(dumper: yaml.dumper, data: str) -> str: 141 | if "\n" in data: 142 | return dumper.represent_scalar("tag:yaml.org,2002:str", data, style="|") 143 | else: 144 | return dumper.represent_scalar("tag:yaml.org,2002:str", data) 145 | 146 | 147 | LabSyncYAMLDumper.add_representer(int, LabSyncYAMLDumper._hex_representer) # noqa: SLF001 148 | LabSyncYAMLDumper.add_representer(str, LabSyncYAMLDumper._str_representer) # noqa: SLF001 149 | 150 | 151 | @contextlib.contextmanager 152 | def wait_box(msg: str, *, hide_cancel: bool = False) -> None: 153 | prefix = "HIDECANCEL\n" if hide_cancel else "" 154 | ida_kernwin.show_wait_box(prefix + msg) 155 | try: 156 | yield None 157 | finally: 158 | ida_kernwin.hide_wait_box() 159 | 160 | 161 | class StringIOTextSink(ida_typeinf.text_sink_t): 162 | def __init__(self): 163 | super().__init__() 164 | self.sio = io.StringIO() 165 | 166 | def _print(self, thing: str) -> int: 167 | self.sio.write(thing) 168 | return 0 169 | 170 | 171 | def local_types() -> Generator[str]: 172 | name = ida_typeinf.first_named_type(None, ida_typeinf.NTF_TYPE) 173 | while name: 174 | yield name 175 | name = ida_typeinf.next_named_type(None, name, ida_typeinf.NTF_TYPE) 176 | 177 | 178 | # EXPORT LOGIC 179 | 180 | 181 | @dataclasses.dataclass(eq=True, order=True) 182 | class SyncedBinary: 183 | idb_id: str = dataclasses.field(compare=False) 184 | start_ea: int = 0 # must be the first field, because we rely on it when sorting 185 | end_ea: int = ida_idaapi.BADADDR # exclusive 186 | base_ea: int = 0 187 | seg_prefix: Optional[str] = None 188 | 189 | def contains(self, ea: int) -> bool: 190 | return self.start_ea <= ea < self.end_ea 191 | 192 | def ea2dump(self, ea: int) -> int: 193 | return ea - self.base_ea 194 | 195 | def dump2ea(self, dea: int) -> int: 196 | return dea + self.base_ea 197 | 198 | 199 | def dump_names(binary: SyncedBinary, storage: functioninliner.ClonesStorage) -> dict[int, str]: 200 | d = {} 201 | for ea, name in idautils.Names(): 202 | if not binary.contains(ea): 203 | continue 204 | 205 | seg = ida_segment.getseg(ea) 206 | seg_name = ida_segment.get_segm_name(seg) 207 | 208 | # skip names that are in inlined chunks 209 | if seg_name.startswith("inlined_"): 210 | continue 211 | 212 | # skip names for inlined functions 213 | if ea in storage: 214 | continue 215 | 216 | dea = binary.ea2dump(ea) 217 | d[dea] = name 218 | 219 | return d 220 | 221 | 222 | def dump_inlined_funcs(binary: SyncedBinary, storage: functioninliner.ClonesStorage) -> list[int]: 223 | funcs = (binary.ea2dump(ea) for ea in storage if binary.contains(ea)) 224 | return list(sorted(funcs)) # noqa: C413 225 | 226 | 227 | def stable_topological_sort(graph: dict[Any, set[Any]]) -> Generator[Any]: 228 | heap = [] 229 | next_v = None 230 | 231 | while heap or graph: 232 | for v, edges in list(graph.items()): 233 | if next_v is not None: 234 | edges.discard(next_v) 235 | if not edges: 236 | heapq.heappush(heap, v) 237 | del graph[v] 238 | 239 | if not heap: 240 | msg = "graph contains unsolvable dependencies" 241 | raise ValueError(msg) 242 | 243 | next_v = heapq.heappop(heap) 244 | yield next_v 245 | 246 | 247 | def dump_local_types(types: netnode.Netnode) -> str: 248 | # we emulate print_decls() ourselves because it internally uses PRTYPE_NOREGEX and this 249 | # removes namespaces which starts with double underscore (e.g. std::__1::__libcpp_refstring) 250 | 251 | local_types_by_ordinal = {} # ordinal: (name, decl, dependencies) 252 | local_types_by_name = {} # name: (ordinal, decl, dependencies) 253 | 254 | tinfo = ida_typeinf.tinfo_t() 255 | for ordinal in range(1, ida_typeinf.get_ordinal_qty(None)): 256 | if not tinfo.get_numbered_type(None, ordinal): 257 | continue # deleted ordinal 258 | 259 | name = tinfo.get_type_name() 260 | 261 | flags = ( 262 | ida_typeinf.PRTYPE_MULTI | # multiline 263 | ida_typeinf.PRTYPE_TYPE | # required to have it named 264 | ida_typeinf.PRTYPE_PRAGMA | # include alignment pragmas 265 | ida_typeinf.PRTYPE_SEMI | # end with semicolon 266 | ida_typeinf.PRTYPE_CPP | # unsure if this is needed, but to be on the safe side... 267 | ida_typeinf.PRTYPE_DEF | # required to have a full definition 268 | ida_typeinf.PRTYPE_NOREGEX # required to keep the name as-is 269 | ) 270 | 271 | decl = ida_typeinf.print_tinfo(None, 2, 0, flags, tinfo, name, None) 272 | decl = decl.strip() 273 | # also strip trailing spaces since they arn't block-encodable in YAML 274 | decl = "\n".join(line.rstrip() for line in decl.splitlines()) 275 | 276 | # TODO @TH: there is an IDA bug where comment-only changes to local types are not updated 277 | # when using parse_decls() so for now we just strip all comments until it'll be 278 | # fixed 279 | decl = strip_comments(decl) 280 | 281 | # IDA apparently can't handle templates in parse_decls(), so we we don't bother syncing 282 | # them at all. hopefully no sane reverser actually uses them and these are only imported 283 | # from debug symbols and never touched 284 | if "<" in decl: 285 | logger.warning( 286 | f"skipping syncing of local type {name!r} because templates are unsupported" # noqa: COM812 287 | ) 288 | continue 289 | 290 | # do a sanity for the extract of the name, since it'll be used when updating 291 | parsed_name, _ = decl_to_name_and_type(decl) 292 | assert name == parsed_name 293 | 294 | # see if this type is dependent on others 295 | dependencies = set() 296 | 297 | udt = ida_typeinf.udt_type_data_t() 298 | if tinfo.get_udt_details(udt): 299 | for i in range(udt.size()): 300 | udm = udt[i] 301 | udm_ordinal = udm.type.get_ordinal() 302 | if udm_ordinal: 303 | dependencies.add(udm_ordinal) 304 | 305 | # keep it 306 | local_types_by_ordinal[ordinal] = (name, decl, dependencies) 307 | assert name not in local_types_by_name 308 | local_types_by_name[name] = (ordinal, decl, dependencies) 309 | 310 | dep_graph = {} 311 | for name, _, deps in local_types_by_ordinal.values(): 312 | dep_names = {local_types_by_ordinal[d][0] for d in deps if d in local_types_by_ordinal} 313 | if len(dep_names) != len(deps): 314 | logger.warning( 315 | f"skipping syncing of local type {name!r} because it depends on other non-synced " 316 | "local types" # noqa: COM812 317 | ) 318 | continue 319 | 320 | dep_graph[name] = dep_names 321 | 322 | # generate a normalized header file that is sorted by dependecy order and lexigraphically, 323 | # to make YAML diffs sane 324 | nhdr = io.StringIO() 325 | 326 | for name in stable_topological_sort(dep_graph): 327 | _, decl, _ = local_types_by_name[name] 328 | 329 | # add uuid 330 | tid = ida_typeinf.get_named_type_tid(name) 331 | if tid == ida_idaapi.BADADDR: 332 | msg = f"failed to resolve tid of local type {name!r}:\n{decl}" 333 | raise LabSyncError(msg) 334 | decl_uuid = types.get(tid) 335 | if not decl_uuid: 336 | types[tid] = decl_uuid = str(uuid.uuid4()) 337 | 338 | nhdr.write(LOCAL_TYPES_COMMENT_FMT.format(decl_uuid)) 339 | nhdr.write("\n") 340 | nhdr.write(decl) 341 | nhdr.write("\n\n") 342 | 343 | return nhdr.getvalue().strip() 344 | 345 | 346 | def strip_comments(decl: str) -> str: 347 | stripped_lines = [] 348 | 349 | for line in decl.splitlines(): 350 | try: 351 | line = line[:line.index("//")].rstrip() 352 | if not line: 353 | continue 354 | except ValueError: 355 | pass 356 | stripped_lines.append(line) 357 | 358 | return "\n".join(stripped_lines) 359 | 360 | 361 | @functools.cache 362 | def decl_to_type_name_pat() -> re.Pattern: 363 | """this generates a pattern that tries to match the first line of a (stripped) decl to the 364 | its type (e.g. struct/union/typedef) and name 365 | 366 | the regex matches 2N groups where group 2i is "type" and group 2i+1 is name, for different 367 | possible subregexes. Only 2 groups (for some i) should be matched 368 | 369 | this regex is a bit more "allowing" than how IDA formats decls, since we also use it to 370 | match decls from YAMLs in which the user might've changed some whitespacing while manually 371 | resolving a merge conflict 372 | """ 373 | 374 | # from ida.cfg:TypeNameChars 375 | name_chars = r"_:$()`'{}" + string.digits + string.ascii_letters 376 | # from blackbox testing what's allowed from name_chars as the first character 377 | name_first_chars = r"_$`" + string.ascii_letters 378 | 379 | name_pat = r"([" + re.escape(name_first_chars) + "][" + re.escape(name_chars) + "]*?)" 380 | 381 | type_pat = ( 382 | r"(?!typedef)(\S+)(?=\s)" # only match non-typedefs 383 | r".*?\s" + # everything up to the name (i.e. type + attributes) 384 | name_pat + 385 | r"(?:\s*(? tuple[str, str]: 421 | # skip pragma/comment lines 422 | for first_line in decl.splitlines(): 423 | if not any(first_line.lstrip().startswith(x) for x in ("#", "//")): 424 | break 425 | else: 426 | msg = f"empty local type:\n{decl}" 427 | raise LabSyncError(msg) 428 | 429 | # strip the first line 430 | first_line = first_line.strip() 431 | 432 | # extract the name and decl type 433 | pat = decl_to_type_name_pat() 434 | m = pat.match(first_line) 435 | 436 | if not m: 437 | msg = f"failed to parse local type:\n{decl}" 438 | raise LabSyncError(msg) 439 | 440 | decl_type = m.group(m.lastindex - 1) 441 | name = m.group(m.lastindex) 442 | # should never happen according to our regex 443 | assert decl_type 444 | assert name 445 | 446 | return name, decl_type 447 | 448 | 449 | def fix_non_present_arguments(name: str, tinfo: ida_typeinf.tinfo_t, *, add: bool = True) \ 450 | -> tuple[ida_typeinf.tinfo_t, bool]: 451 | 452 | def type_exists(tinfo: ida_typeinf.tinfo_t) -> bool: 453 | if tinfo.present(): 454 | return True 455 | 456 | # originally we used just tinfo.present(), but for some reason it keeps returning False 457 | # even after we saved the type (as a forward declaration) 458 | # 459 | # then we used tinfo.get_ordinal() > 0 as a test, but on huge IDBs with >10k types, for 460 | # some reason it kept returning 0 even after we saved the type 461 | # 462 | # therefore we moved to checking if we can get the tid for the type name. you have to watch 463 | # out, however, since for deleted types tinfo.get_type_name() raises UnicodeDecodeError 464 | try: 465 | tname = tinfo.get_type_name() 466 | except UnicodeDecodeError: 467 | return False 468 | 469 | tid = ida_typeinf.get_named_type_tid(tname) 470 | return tid != ida_idaapi.BADADDR 471 | 472 | def fix_non_present(tinfo: ida_typeinf.tinfo_t) -> tuple[ida_typeinf.tinfo_t, bool]: 473 | tinfo_orig = tinfo.copy() 474 | 475 | # deref pointer/array until we reach the actual type 476 | depth = 0 477 | while depth < 128: 478 | if not tinfo.remove_ptr_or_array(): 479 | break 480 | depth += 1 481 | else: 482 | msg = "max pointer depth reached" 483 | raise LabSyncError(msg) 484 | 485 | # if we're allowed to and this type is missing, add its base to local types 486 | if not type_exists(tinfo) and add: 487 | # add the type to local types 488 | if tinfo.save_type() == 0: 489 | tname = tinfo.get_type_name() 490 | 491 | logger.warning( 492 | f"the prototype for {name} used type {tname} that was not present in the TIL. " 493 | "we silently added it to allow syncing" # noqa: COM812 494 | ) 495 | 496 | return tinfo_orig, False 497 | else: 498 | # we can't use tname for deleted types (it raises UnicodeDecodeError) 499 | tinfo_clean = tinfo.copy() 500 | tinfo_clean.set_modifiers(0) 501 | tname = tinfo_clean.dstr() 502 | 503 | logger.warning( 504 | f"the prototype for {name} used type {tname} that was not present in the TIL. " 505 | "we failed to silently add it to allow syncing (perhaps a deleted type?)" # noqa: COM812 506 | ) 507 | 508 | # TODO @TH: IDA has a bug where they can't parse _BOOL8 args, so we replace them. 509 | # remove this flow after they fix it 510 | bool8_realtype = ida_typeinf.BT_BOOL | ida_typeinf.BTMT_BOOL8 511 | if tinfo.get_realtype() == bool8_realtype: 512 | pass 513 | elif type_exists(tinfo): 514 | # if it's real present type, we're good 515 | return tinfo_orig, False 516 | 517 | # replace the type with an unknown type 518 | tinfo_generic = ida_typeinf.tinfo_t() 519 | assert tinfo_generic.create_simple_type(ida_typeinf.BT_UNKNOWN) 520 | 521 | # set the original modifiers 522 | tinfo_generic.set_modifiers(tinfo.get_modifiers()) 523 | 524 | # recrate the pointer depth on top of tinfo_generic 525 | for _ in range(depth): 526 | assert tinfo_generic.create_ptr(tinfo_generic) 527 | 528 | return tinfo_generic, True 529 | 530 | ftype = ida_typeinf.func_type_data_t() 531 | assert tinfo.get_func_details(ftype, ida_typeinf.GTD_NO_ARGLOCS) 532 | 533 | ftype.rettype, fixed = fix_non_present(ftype.rettype) 534 | for i, argtype in enumerate(ftype): 535 | ftype[i].type, arg_fixed = fix_non_present(argtype.type) 536 | fixed |= arg_fixed 537 | 538 | tinfo_new = ida_typeinf.tinfo_t() 539 | assert tinfo_new.create_func(ftype) 540 | 541 | return tinfo_new, fixed 542 | 543 | 544 | def prototype(ea: int) -> str: 545 | tinfo = ida_typeinf.tinfo_t() 546 | if not ida_nalt.get_tinfo(tinfo, ea): 547 | return None 548 | 549 | name = ida_name.get_ea_name(ea, ida_name.GN_VISIBLE) 550 | 551 | # replace non-present arguments in the prototype if relevant 552 | tinfo_new, fixed = fix_non_present_arguments(name, tinfo) 553 | 554 | if fixed: 555 | ptype = ida_typeinf.print_tinfo(None, 0, 0, ida_typeinf.PRTYPE_1LINE, tinfo, None, None) 556 | new_ptype = ida_typeinf.print_tinfo(None, 0, 0, ida_typeinf.PRTYPE_1LINE, tinfo_new, None, 557 | None) 558 | logger.warning( 559 | f"replacing prototype for {name} because it uses types that are not present in the " 560 | f"TIL from:\n\t{ptype!r}\nto:\n\t{new_ptype!r}" # noqa: COM812 561 | ) 562 | 563 | if not ida_nalt.set_tinfo(ea, tinfo_new): 564 | logger.warning(f"failed setting new prototype for {name}! skipping it") 565 | return None 566 | 567 | tinfo = tinfo_new 568 | 569 | # generate the prototype to dump 570 | if NORMALIZE_PROTOTYPES: 571 | name = "FUNCTION" 572 | 573 | # we have to remove special characters from the name, otherwise we'll have an issue applying 574 | # the prototype afterwards (e.g. `__Foo.cxx_destruct_`) 575 | allowed = r"_$" + string.digits + string.ascii_letters 576 | pname = "".join(c if c in allowed else "_" for c in name) 577 | return ida_typeinf.print_tinfo(None, 0, 0, ida_typeinf.PRTYPE_1LINE, tinfo, pname, None) 578 | 579 | 580 | def dump_prototypes( 581 | binary: SyncedBinary, storage: functioninliner.ClonesStorage) -> dict[int, str]: 582 | 583 | d = {} 584 | for ea in idautils.Functions(): 585 | if not binary.contains(ea): 586 | continue 587 | 588 | seg = ida_segment.getseg(ea) 589 | seg_name = ida_segment.get_segm_name(seg) 590 | 591 | # skip funcs that are in inlined chunks somehow (shouldn't happen) 592 | if seg_name.startswith("inlined_"): 593 | continue 594 | 595 | # skip funcs that have been inlined 596 | if ea in storage: 597 | continue 598 | 599 | ptype = prototype(ea) 600 | if ptype: 601 | dea = binary.ea2dump(ea) 602 | d[dea] = ptype 603 | 604 | return d 605 | 606 | 607 | def dump(binary: SyncedBinary, types: netnode.Netnode) -> str: 608 | storage = functioninliner.ClonesStorage() 609 | storage.update_from_storage() 610 | 611 | d = { 612 | "version": 4, 613 | "names": dump_names(binary, storage), 614 | "inlined_funcs": dump_inlined_funcs(binary, storage), 615 | # we have to dump prototypes before we dump local types because this may add new types to 616 | # the TIL 617 | "prototypes": dump_prototypes(binary, storage), 618 | "local_types": dump_local_types(types), 619 | } 620 | 621 | return yaml.dump( 622 | d, Dumper=LabSyncYAMLDumper, default_flow_style=False, sort_keys=True, 623 | ) 624 | 625 | 626 | # IMPORT LOGIC 627 | 628 | 629 | def update_names( 630 | binary: SyncedBinary, storage: functioninliner.ClonesStorage, names: dict[int, str]) -> None: 631 | 632 | # delete names if required 633 | if REMOVE_MISSING_NAMES_AND_PROTOTYPES: 634 | for dea in dump_names(binary, storage): 635 | # delete name if unnamed in the new dict 636 | if dea not in names: 637 | ea = binary.dump2ea(dea) 638 | 639 | msg = f"removing name from {ea:#x}" 640 | logger.debug(msg) 641 | 642 | success = ida_name.set_name(ea, "", ida_name.SN_NOWARN) 643 | if not success: 644 | if logger.getEffectiveLevel() > logging.DEBUG: 645 | logger.warning("failed " + msg) 646 | else: 647 | logger.warning("removal failed!") 648 | 649 | # update names 650 | for dea, name in names.items(): 651 | ea = binary.dump2ea(dea) 652 | cur_name = ida_name.get_name(ea) 653 | 654 | if cur_name != name: 655 | msg = f"renaming {ea:#x} from {cur_name!r} to {name!r}" 656 | logger.debug(msg) 657 | 658 | # check if the new name already exists in the database 659 | cur_ea = ida_name.get_name_ea(ida_idaapi.BADADDR, name) 660 | name_changed = False 661 | try: 662 | # if the new name is already in use in the IDB -- 663 | if cur_ea != ida_idaapi.BADADDR: 664 | # verify that the repo also has a different name for the EA currently holding 665 | # the new name 666 | # 667 | # perhaps we can even assert that this never happens 668 | cur_dea = binary.ea2dump(cur_ea) 669 | if cur_dea not in names: 670 | logger.warning( 671 | f"cannot rename {ea:#x} to {name!r} as this name already " 672 | f"exists in the IDB for {cur_ea:#x}, and that EA doesn't " 673 | "have a different name in the repo" # noqa: COM812 674 | ) 675 | continue 676 | 677 | # temporarily rename it to something else 678 | msg2 = f"temporarily renaming {cur_ea:#x} away from {name!r}" 679 | logger.debug("\t" + msg2) 680 | success = ida_name.set_name( 681 | cur_ea, 682 | name + "_labsync_temp", 683 | ida_name.SN_NOWARN | ida_name.SN_FORCE, 684 | ) 685 | 686 | # handle temporary rename failure 687 | if not success: 688 | if logger.getEffectiveLevel() > logging.DEBUG: 689 | logger.warning("failed " + msg2) 690 | else: 691 | logger.warning("\ttemporary rename failed!") 692 | continue 693 | 694 | # now do the actual rename 695 | success = ida_name.set_name(ea, name, ida_name.SN_NOWARN) 696 | 697 | # handle rename failure 698 | if not success: 699 | if logger.getEffectiveLevel() > logging.DEBUG: 700 | logger.warning("failed " + msg) 701 | else: 702 | logger.warning("rename failed!") 703 | continue 704 | 705 | name_changed = True 706 | finally: 707 | # if we failed, undo the temporary rename if we did any 708 | if cur_ea != ida_idaapi.BADADDR and not name_changed: 709 | msg2 = f"undoing the temporarily rename of {cur_ea:#x}" 710 | logger.debug("\t" + msg2) 711 | success = ida_name.set_name(cur_ea, name, ida_name.SN_NOWARN) 712 | 713 | # handle temporary rename undoing failure 714 | if not success: 715 | if logger.getEffectiveLevel() > logging.DEBUG: 716 | logger.warning("failed " + msg2) 717 | else: 718 | logger.warning("\ttemporary rename undoing failed!") 719 | 720 | 721 | def update_inlined_funcs( 722 | binary: SyncedBinary, storage: functioninliner.ClonesStorage, funcs: list[int]) -> None: 723 | 724 | cur = {ea for ea in storage if binary.contains(ea)} 725 | new = set(map(binary.dump2ea, funcs)) 726 | 727 | undo = cur - new 728 | do = new - cur 729 | 730 | for ea in undo: 731 | func = sark.Function(ea) 732 | if func.ea != ea: 733 | logger.warning(f"\tcannot undo inlining of {ea:#x} since it's not a function start!") 734 | continue 735 | msg = f"undoing inlining of {func.name}" 736 | logger.debug(msg) 737 | functioninliner.undo_inline_function(func) 738 | 739 | for ea in do: 740 | func = sark.Function(ea) 741 | if func.ea != ea: 742 | logger.warning( 743 | f"not inlining function @ {ea:#x} since it's not a function start" # noqa: COM812 744 | ) 745 | logger.debug(f"inlining {func.name}") 746 | functioninliner.inline_function(func) 747 | 748 | 749 | def _rename_local_type(tid: int, name: str) -> tuple[int, str]: 750 | """note: if name is in use by another local type, that local type will be removed""" 751 | 752 | ordinal = ida_typeinf.get_tid_ordinal(tid) 753 | assert ordinal 754 | 755 | tinfo = ida_typeinf.tinfo_t() 756 | assert tinfo.get_numbered_type(None, ordinal) 757 | 758 | # TODO @TH: perhaps tinfo.rename_type can be used instead? found out about it later 759 | err = tinfo.set_numbered_type(None, ordinal, ida_typeinf.NTF_REPLACE, name) 760 | errstr = ida_typeinf.tinfo_errstr(err) 761 | return err, errstr 762 | 763 | 764 | def rename_local_type( 765 | cur_name: str, name: str, types: netnode.Netnode, uuids: dict[int, str], 766 | ) -> None: 767 | 768 | msg = f"renaming local type {cur_name!r} to {name!r}" 769 | logger.debug(msg) 770 | 771 | # resolve the type we're changing 772 | tid = ida_typeinf.get_named_type_tid(cur_name) 773 | assert tid != ida_idaapi.BADADDR 774 | 775 | # check if the new name is in use 776 | cur_tid = ida_typeinf.get_named_type_tid(name) 777 | name_changed = False 778 | try: 779 | # if the new name is already in use in the IDB -- 780 | if cur_tid != ida_idaapi.BADADDR: 781 | # assert that the repo also has a different name for the type currently holding the new 782 | # name 783 | # 784 | # this is an assertion because if it's missing from the repo we should've already 785 | # deleted it 786 | # 787 | # also, we don't actually verify that the name since we already verified beforehand 788 | # that there are no duplicate names 789 | cur_uuid = types[cur_tid] 790 | assert cur_uuid in uuids 791 | 792 | # temporarily rename it to something else 793 | msg2 = f"temporarily renaming local type {name!r}" 794 | logger.debug("\t" + msg2) 795 | err, errstr = _rename_local_type(cur_tid, name + "_labsync_temp") 796 | 797 | # handle temporary rename failure 798 | if err: 799 | if logger.getEffectiveLevel() > logging.DEBUG: 800 | logger.warning("failed " + msg2 + f": {errstr}") 801 | else: 802 | logger.warning(f"\ttemporary rename failed: {errstr}") 803 | return False 804 | 805 | # now do the actual rename 806 | err, errstr = _rename_local_type(tid, name) 807 | 808 | # handle rename failure 809 | if err: 810 | if logger.getEffectiveLevel() > logging.DEBUG: 811 | logger.warning("failed " + msg + f": {errstr}") 812 | else: 813 | logger.warning(f"rename failed: {errstr}") 814 | return False 815 | 816 | name_changed = True 817 | finally: 818 | # if we failed, undo the temporary rename if we did any 819 | if cur_tid != ida_idaapi.BADADDR and not name_changed: 820 | msg2 = f"undoing the temporarily rename of local type {name!r}" 821 | logger.debug("\t" + msg2) 822 | err, errstr = _rename_local_type(cur_tid, name) 823 | 824 | # handle temporary rename undoing failure 825 | if err: 826 | if logger.getEffectiveLevel() > logging.DEBUG: 827 | logger.warning("failed " + msg2 + f": {errstr}") 828 | else: 829 | logger.warning(f"\ttemporary rename undoing failed: {errstr}") 830 | 831 | return bool(err) 832 | 833 | 834 | def parse_local_types(nhdr: str) -> Generator[tuple[str, str, str, str]]: 835 | # split according to empty lines 836 | decls = re.split(r"\n\n", nhdr) 837 | 838 | for decl in decls: 839 | decl = decl.strip() 840 | 841 | # extract the uuid of the type 842 | uuid_line, decl = decl.split("\n", maxsplit=1) 843 | r = parse.parse(LOCAL_TYPES_COMMENT_FMT, uuid_line) 844 | if not r: 845 | msg = f"failed to extract uuid from local type uuid line:\n{uuid_line}" 846 | raise LabSyncError(msg) 847 | decl_uuid = r.fixed[0] 848 | 849 | # extract the name of the type and generate a forward declaration for it 850 | name, decl_type = decl_to_name_and_type(decl) 851 | 852 | yield name, decl_uuid, decl, decl_type 853 | 854 | 855 | def update_local_types(nhdr: str, types: netnode.Netnode) -> None: 856 | # parse type declaration names 857 | name2decl = {} 858 | uuids = {} 859 | decls = [] 860 | fdecls = [] 861 | typedefs = [] 862 | for name, decl_uuid, decl, decl_type in parse_local_types(nhdr): 863 | # make sure it's unique, mostly for sanity purposes 864 | if name in name2decl: 865 | if (name2decl[name] == decl and 866 | uuids.get(decl_uuid) == name): 867 | # duplicate local type with same decl and UUID. probably accidentally copied from 868 | # both sides during conflict resolution. we'll skip the redundant copy 869 | continue 870 | 871 | msg = f"found two local type declarations with the same name: {name}" 872 | raise LabSyncError(msg) 873 | name2decl[name] = decl 874 | 875 | # remember the name for each uuid 876 | uuids[decl_uuid] = name 877 | 878 | # accumulate 879 | if decl_type in {"struct", "union", "enum", "class"}: 880 | decls.append(decl) 881 | 882 | fdecl = f"{decl_type} {name};" 883 | fdecls.append(fdecl) 884 | elif decl_type == "typedef": 885 | typedefs.append(decl) 886 | else: 887 | msg = f"found unexpected kind of local type:\n{decl}" 888 | raise LabSyncError(msg) 889 | 890 | # remove local types if required 891 | for tid, decl_uuid in list(types.items()): 892 | if decl_uuid not in uuids: 893 | name = ida_typeinf.get_tid_name(tid) 894 | logger.debug(f"removing local type {name!r}") 895 | ida_typeinf.del_named_type(None, name, ida_typeinf.NTF_TYPE) 896 | del types[tid] 897 | 898 | # rename local types if required 899 | # create a mapping from uuid to type name in our IDB 900 | cur_uuid_to_name = {u: ida_typeinf.get_tid_name(t) for t, u in types.items()} 901 | 902 | for decl_uuid, name in uuids.items(): 903 | # skip if uuid doesn't exist (this is a new type) or name didn't change 904 | cur_name = cur_uuid_to_name.get(decl_uuid) 905 | if not cur_name or cur_name == name: 906 | continue 907 | 908 | # do the renaming 909 | rename_local_type(cur_name, name, types, uuids) 910 | 911 | # create a reordered header that that should be parsable with regards to forward declarations 912 | hdr = "\n".join(fdecls) + "\n\n" + "\n".join(typedefs) + "\n\n" + "\n\n".join(decls) 913 | 914 | # iteratively try to load the header as long as dependencies get resolved 915 | # 916 | # TODO @TH: originally we didn't move the typedefs to before the decls, so honestly I think 917 | # that now there should always be just one iteration here. we should probably verify 918 | # that and remove the loop here afterwards 919 | last_n_errors = float("inf") 920 | iters = 1 921 | while iters < len(name2decl) + 1: 922 | # parse some more local types 923 | n_errors = ida_typeinf.parse_decls(None, hdr, None, ida_typeinf.HTI_DCL) 924 | logger.debug(f"loaded local types with {n_errors} errors") 925 | 926 | # add new uuids. we do this on every iteration in case we will eventually bail out -- 927 | # we don't want to have added new types without keeping their uuids 928 | for decl_uuid, name in uuids.items(): 929 | tid = ida_typeinf.get_named_type_tid(name) 930 | if tid != ida_idaapi.BADADDR: 931 | if tid not in types: 932 | types[tid] = decl_uuid 933 | else: 934 | assert types[tid] == decl_uuid 935 | 936 | # stop if there are no more errors or if we didn't add anything on this iteration 937 | if n_errors == 0 or n_errors >= last_n_errors: 938 | break 939 | 940 | last_n_errors = n_errors 941 | iters += 1 942 | else: 943 | msg = "local type loading took more than it makes sense. aborting" 944 | raise LabSyncError(msg) 945 | 946 | logger.debug( 947 | f"finished loading local types with {n_errors} errors after {iters} iterations " 948 | f"({len(name2decl)} types)" # noqa: COM812 949 | ) 950 | 951 | if n_errors: 952 | # IDA SDK doesn't properly export an interface for printer_t so we can't get the actual 953 | # errors :/ 954 | fd, hdr_path = tempfile.mkstemp(suffix=".h", text=True) 955 | os.write(fd, hdr.encode("latin1")) 956 | os.close(fd) 957 | 958 | logger.error( 959 | "run the following in IDC shell to see the local types parsing errors:\n" 960 | f'\tparse_decls("{hdr_path}", PT_FILE)' # noqa: COM812 961 | ) 962 | 963 | msg = f"failed to parse local types ({n_errors} errors)" 964 | raise LabSyncError(msg) 965 | 966 | # in case loading the local types resulted in a new type being created, we might've encountered 967 | # a bug where IDA recreates an anonymous local type for an unnamed embedded subtype 968 | # 969 | # in that case, look for and delete dangling anonymous local types that should've been left 970 | new_names = set(local_types()) 971 | if set(name2decl.keys()) != new_names: 972 | for name in new_names: 973 | tinfo = ida_typeinf.tinfo_t() 974 | assert tinfo.get_named_type(None, name) 975 | 976 | # check if anonymous 977 | if not tinfo.is_anonymous_udt(): 978 | continue 979 | 980 | # check if it has any xrefs 981 | tid = tinfo.get_tid() 982 | if (ida_xref.get_first_cref_to(tid) != ida_idaapi.BADADDR or 983 | ida_xref.get_first_dref_to(tid) != ida_idaapi.BADADDR): 984 | continue 985 | 986 | # check if it's referenced by any typedef 987 | used_by_typedef = False 988 | 989 | any_tinfo = ida_typeinf.tinfo_t() 990 | for any_name in local_types(): 991 | assert any_tinfo.get_named_type(None, any_name) 992 | 993 | if not any_tinfo.is_typedef(): 994 | continue 995 | 996 | if any_tinfo.get_next_type_name() != name: 997 | continue 998 | 999 | used_by_typedef = True 1000 | break 1001 | 1002 | if used_by_typedef: 1003 | continue 1004 | 1005 | # remove it 1006 | logger.debug(f"removing dangling local type {name!r}") 1007 | ida_typeinf.del_named_type(None, name, ida_typeinf.NTF_TYPE) 1008 | del types[tid] 1009 | 1010 | 1011 | def update_prototypes( 1012 | binary: SyncedBinary, storage: functioninliner.ClonesStorage, d: dict[int, str]) -> None: 1013 | 1014 | # delete prototypes if required 1015 | if REMOVE_MISSING_NAMES_AND_PROTOTYPES: 1016 | # dump_prototypes() is a bit heavy, so we duplicate some code here instead of calling it 1017 | # because we don't need the actual prototypes 1018 | for ea in idautils.Functions(): 1019 | seg = ida_segment.getseg(ea) 1020 | seg_name = ida_segment.get_segm_name(seg) 1021 | 1022 | # skip funcs that are in inlined chunks somehow (shouldn't happen) 1023 | if seg_name.startswith("inlined_"): 1024 | continue 1025 | 1026 | # skip funcs that have been inlined 1027 | if ea in storage: 1028 | continue 1029 | 1030 | # delete type if untyped in the new dict 1031 | dea = binary.ea2dump(ea) 1032 | if dea not in d: 1033 | logger.debug(f"removing prototype from {ea:#x}") 1034 | ida_nalt.del_tinfo(ea) 1035 | 1036 | # update prototypes 1037 | for dea, ptype in d.items(): 1038 | ea = binary.dump2ea(dea) 1039 | cur_ptype = prototype(ea) 1040 | 1041 | # TODO @TH: because we had numerous issues with prototypes syncing, we want to make sure 1042 | # that we always apply all prototypes so that issues will be raised early. 1043 | # we can probably undo it after we feel more confident 1044 | # if cur_ptype != ptype: 1045 | if True: 1046 | msg = f"changing {ea:#x} prototype from:\n\t{cur_ptype!r}\nto\n\t{ptype!r}" 1047 | if cur_ptype != ptype: 1048 | logger.debug(msg) 1049 | 1050 | success = ida_typeinf.apply_cdecl( 1051 | None, ea, ptype + ";", ida_typeinf.TINFO_DEFINITE, 1052 | ) 1053 | 1054 | if not success: 1055 | if logger.getEffectiveLevel() > logging.DEBUG or cur_ptype == ptype: 1056 | logger.warning("failed " + msg) 1057 | else: 1058 | logger.warning("prototype change failed!") 1059 | 1060 | 1061 | def migrate(d: dict, types: netnode.Netnode) -> dict: # noqa: ARG001 1062 | ver = d["version"] 1063 | if ver not in {1, 2, 3, 4}: 1064 | msg = f"data file is of unexpected version: {ver}" 1065 | raise LabSyncError(msg) 1066 | 1067 | # version 4 is latest 1068 | if ver == 4: 1069 | return d 1070 | 1071 | # version 3 was missing local type uuids 1072 | # we dropped the logic here since it was non-trivial to update per newer changes in code 1073 | # and this version is very old anyway 1074 | msg = ("migrating from YAML version 3 is not supported. use an older version of LabSync to do " 1075 | "so") 1076 | raise NotImplementedError(msg) 1077 | 1078 | if ver == 3: 1079 | return d 1080 | 1081 | # version 2 was missing prototypes 1082 | d["prototypes"] = dump_prototypes() 1083 | 1084 | if ver == 2: 1085 | return d 1086 | 1087 | # version 1 was missing local types 1088 | d["local_types"] = dump_local_types() 1089 | 1090 | return d 1091 | 1092 | 1093 | def parse_data(data: str, types: netnode.Netnode) -> dict: 1094 | d = yaml.load(data, Loader=yaml.CLoader) # noqa: S506 1095 | return migrate(d, types) 1096 | 1097 | 1098 | def update(binary: SyncedBinary, data: str, types: netnode.Netnode) -> None: 1099 | storage = functioninliner.ClonesStorage() 1100 | storage.update_from_storage() 1101 | 1102 | d = parse_data(data, types) 1103 | 1104 | update_names(binary, storage, d["names"]) 1105 | update_inlined_funcs(binary, storage, d["inlined_funcs"]) 1106 | update_local_types(d["local_types"], types) 1107 | update_prototypes(binary, storage, d["prototypes"]) 1108 | 1109 | 1110 | def adopt_uuids(data: str, types: netnode.Netnode) -> None: 1111 | # extract local types normalized header 1112 | d = parse_data(data, types) 1113 | nhdr = d["local_types"] 1114 | 1115 | # parse uuids 1116 | name_to_uuid = {} 1117 | for name, decl_uuid, _, _ in parse_local_types(nhdr): 1118 | if name in name_to_uuid: 1119 | msg = ( 1120 | f"found two local type declarations with the same name: {name} (uuids " 1121 | f"{name_to_uuid[name]} and {decl_uuid})" 1122 | ) 1123 | raise LabSyncError(msg) 1124 | 1125 | name_to_uuid[name] = decl_uuid 1126 | 1127 | # adopt uuids for local types we don't already have uuids for, if their names match 1128 | for name in local_types(): 1129 | tid = ida_typeinf.get_named_type_tid(name) 1130 | if tid == ida_idaapi.BADADDR: 1131 | msg = f"failed to resolve tid of local type {name!r}" 1132 | raise LabSyncError(msg) 1133 | 1134 | # skip local types that already have a uuid 1135 | if tid in types: 1136 | continue 1137 | 1138 | # adopt the uuid from the repo if it has a local type with the same name (best effort 1139 | # heuristic) 1140 | if name in name_to_uuid: 1141 | decl_uuid = name_to_uuid[name] 1142 | logger.debug(f"adopting repo uuid for local type {name!r}: {decl_uuid}") 1143 | types[tid] = decl_uuid 1144 | 1145 | 1146 | # REPO 1147 | 1148 | 1149 | class LabSyncRepo: 1150 | _path: str 1151 | _repo: git.Repo 1152 | 1153 | def __init__(self, path: str): 1154 | # TODO @TH: we should add a mechanism to lock the repo while we're doing git operations on 1155 | # it, in case multiple IDBs are using it at the same time 1156 | 1157 | self._path = path 1158 | self._repo = git.Repo(path) 1159 | 1160 | with self._repo.config_reader() as cr: 1161 | try: 1162 | mergetool = cr.get("merge", "tool") 1163 | logger.info(f"using merge.tool = {mergetool}") 1164 | except (configparser.NoOptionError, configparser.NoSectionError): 1165 | msg = "merge.tool must be set in git configuration to use this plugin" 1166 | raise LabSyncError(msg) # noqa: B904 1167 | 1168 | if self._repo.active_branch.name != "master": 1169 | logger.warning("data repo is not on branch 'master'") 1170 | 1171 | with self._repo.config_writer() as cw: 1172 | cw.set_value("mergetool", "keepbackup", "false") 1173 | cw.set_value("mergetool", "writetotemp", "true") 1174 | cw.set_value("mergetool", "hideresolved", "true") 1175 | 1176 | def _is_clean(self) -> bool: 1177 | return not (self._repo.is_dirty() or self._repo.untracked_files) 1178 | 1179 | def _ensure_clean(self) -> None: 1180 | if self._repo.is_dirty(): 1181 | msg = "data repo is dirty. please fix this externally for now" 1182 | raise LabSyncError(msg) 1183 | 1184 | if self._repo.untracked_files: 1185 | msg = "data repo has untracked files. please fix this externally for now" 1186 | raise LabSyncError(msg) 1187 | 1188 | @property 1189 | def path(self) -> str: 1190 | return self._path 1191 | 1192 | def _pull(self) -> None: 1193 | assert self._is_clean() 1194 | 1195 | # resolve remote tracking branch 1196 | current = self._repo.active_branch 1197 | tracking_branch = current.tracking_branch() 1198 | if not tracking_branch: 1199 | logger.warning("no remote tracking branch. skipping pull") 1200 | return 1201 | 1202 | # pull 1203 | try: 1204 | self._repo.git.pull(rebase="false", allow_unrelated_histories=True) 1205 | except git.GitCommandError as e: 1206 | if "fix conflicts and then commit" not in e.stdout: 1207 | raise 1208 | 1209 | logger.warning(f"pull failed with: {e.stdout}") 1210 | else: 1211 | return 1212 | 1213 | # resolve conflicts 1214 | try: 1215 | self._repo.git.mergetool("--no-prompt", "--gui") 1216 | except git.GitCommandError as e: 1217 | msg = ( 1218 | "mergetool returned failure. please fix the conflict and conclude the merge " 1219 | "manually" 1220 | ) 1221 | raise LabSyncError(msg) from e 1222 | 1223 | # conclude the merge 1224 | self._repo.git.commit("--no-edit") 1225 | 1226 | # make sure that we're done 1227 | if self._repo.is_dirty(): 1228 | msg = ( 1229 | "data repo is still dirty after supposedly committing the fixed merge. please " 1230 | "fix the repo manually" 1231 | ) 1232 | raise LabSyncError(msg) 1233 | 1234 | def _id_path(self, _id: str) -> pathlib.Path: 1235 | return pathlib.Path(self.path) / f"{_id}.yaml" 1236 | 1237 | @contextlib.contextmanager 1238 | def _open(self, _id: str, mode: str) -> IO: 1239 | path = self._id_path(_id) 1240 | with path.open(mode) as fp: 1241 | yield fp 1242 | 1243 | def _commit(self, _id: str) -> None: 1244 | index = self._repo.index 1245 | index.add([_id + ".yaml"]) 1246 | # this is broken for some reason: index.commit(f"updated {_id}") 1247 | self._repo.git.commit("-m", f"updated {_id}") 1248 | 1249 | def _commit_dangling(self, _id: str) -> None: 1250 | index = self._repo.index 1251 | index.add([_id + ".yaml"]) 1252 | index.commit(f"initial commit for {_id}", []) 1253 | 1254 | def _push(self) -> None: 1255 | assert self._is_clean() 1256 | 1257 | # resolve remote tracking branch 1258 | current = self._repo.active_branch 1259 | tracking_branch = current.tracking_branch() 1260 | if not tracking_branch: 1261 | logger.warning("no remote tracking branch. skipping push") 1262 | return 1263 | 1264 | # push 1265 | self._repo.git.push() 1266 | 1267 | def get(self, _id: str) -> tuple[Optional[str], str]: 1268 | self._ensure_clean() 1269 | 1270 | self._pull() 1271 | 1272 | commit = self._repo.commit().hexsha 1273 | 1274 | if self._id_path(_id).exists(): 1275 | with self._open(_id, "rt") as fp: 1276 | data = fp.read() 1277 | else: 1278 | data = None 1279 | 1280 | return data, commit 1281 | 1282 | def put(self, _id: str, content: str, *, base: Optional[str]) -> tuple[str, bool]: 1283 | self._ensure_clean() 1284 | 1285 | if base and self._repo.head.commit.hexsha != base: 1286 | # we need to fetch before resetting, because if the IDB was copied from somewhere, 1287 | # it could be that we don't locally have the base commit 1288 | logger.debug("fetching repo") 1289 | self._repo.git.fetch() 1290 | 1291 | logger.debug(f"resetting HEAD to {base}") 1292 | self._repo.head.reset(base, working_tree=True) 1293 | 1294 | with self._open(_id, "wt") as fp: 1295 | fp.write(content) 1296 | 1297 | if self._is_clean(): 1298 | logger.debug("no changes") 1299 | 1300 | changed = False 1301 | else: 1302 | if base: 1303 | self._commit(_id) 1304 | else: 1305 | logger.debug("committing to a danging commit") 1306 | self._commit_dangling(_id) 1307 | 1308 | changed = True 1309 | 1310 | return self._repo.commit().hexsha, changed 1311 | 1312 | def sync(self) -> str: 1313 | self._pull() 1314 | self._push() 1315 | 1316 | return self._repo.commit().hexsha 1317 | 1318 | def ping(self) -> bool: 1319 | try: 1320 | self._repo.git.ls_remote(heads=True) 1321 | except git.GitCommandError: 1322 | return False 1323 | else: 1324 | return True 1325 | 1326 | 1327 | # PLUGIN STUFF 1328 | 1329 | 1330 | class LabSyncActionBase(ida_kernwin.action_handler_t): 1331 | plugin: ida_idaapi.plugin_t 1332 | 1333 | def __init__(self, plugin: ida_idaapi.plugin_t): 1334 | super().__init__() 1335 | self.plugin = plugin 1336 | 1337 | @property 1338 | def name(self) -> str: 1339 | return f"{self.plugin.wanted_name}:{self.__class__.__name__}" 1340 | 1341 | @property 1342 | def label(self) -> str: 1343 | raise NotImplementedError 1344 | 1345 | @property 1346 | def shortcut(self) -> Optional[str]: 1347 | return None 1348 | 1349 | @property 1350 | def tooltip(self) -> Optional[str]: 1351 | return None 1352 | 1353 | @property 1354 | def icon(self) -> int: 1355 | return 0 1356 | 1357 | @property 1358 | def flags(self) -> int: 1359 | return 0 1360 | 1361 | @property 1362 | def path(self) -> str: 1363 | return f"Edit/Plugins/{self.plugin.wanted_name}/" 1364 | 1365 | def register(self) -> None: 1366 | desc = ida_kernwin.action_desc_t( 1367 | self.name, 1368 | self.label, 1369 | self, 1370 | self.shortcut, 1371 | self.tooltip, 1372 | self.icon, 1373 | ) 1374 | ida_kernwin.register_action(desc) 1375 | 1376 | def unregister(self) -> None: 1377 | ida_kernwin.unregister_action(self.name) 1378 | 1379 | def activate(self, ctx: Any) -> None: 1380 | raise NotImplementedError 1381 | 1382 | def update(self, ctx: Any) -> None: 1383 | raise NotImplementedError 1384 | 1385 | 1386 | class LabSyncEnableAction(LabSyncActionBase): 1387 | @property 1388 | def label(self) -> str: 1389 | return "Enable" 1390 | 1391 | def activate(self, ctx: Any) -> None: 1392 | self.plugin.enable() 1393 | 1394 | def update(self, ctx: Any) -> None: 1395 | if self.plugin.enabled: 1396 | return ida_kernwin.AST_DISABLE 1397 | else: 1398 | return ida_kernwin.AST_ENABLE 1399 | 1400 | 1401 | class LabSyncDisableAction(LabSyncActionBase): 1402 | @property 1403 | def label(self) -> str: 1404 | return "Disable" 1405 | 1406 | def activate(self, ctx: Any) -> None: 1407 | self.plugin.disable() 1408 | 1409 | def update(self, ctx: Any) -> None: 1410 | if self.plugin.enabled: 1411 | return ida_kernwin.AST_ENABLE 1412 | else: 1413 | return ida_kernwin.AST_DISABLE 1414 | 1415 | 1416 | class LabSyncResetAction(LabSyncActionBase): 1417 | @property 1418 | def label(self) -> str: 1419 | return "Reset" 1420 | 1421 | def activate(self, ctx: Any) -> None: 1422 | self.plugin.reset() 1423 | 1424 | def update(self, ctx: Any) -> None: 1425 | if self.plugin.enabled: 1426 | return ida_kernwin.AST_DISABLE 1427 | else: 1428 | return ida_kernwin.AST_ENABLE 1429 | 1430 | 1431 | class LabSyncHooks(ida_kernwin.UI_Hooks): 1432 | plugin: ida_idaapi.plugin_t 1433 | menu_actions: list[LabSyncActionBase] 1434 | 1435 | def __init__(self, plugin: ida_idaapi.plugin_t, menu_actions: list[LabSyncActionBase]): 1436 | super().__init__() 1437 | 1438 | self.plugin = plugin 1439 | self.menu_actions = menu_actions 1440 | 1441 | def ready_to_run(self) -> None: 1442 | for action in self.menu_actions: 1443 | ida_kernwin.attach_action_to_menu( 1444 | action.path, action.name, ida_kernwin.SETMENU_APP, 1445 | ) 1446 | 1447 | def saved(self) -> None: 1448 | if not self.plugin.enabled: 1449 | return 1450 | 1451 | if self.plugin.sync_in_progress: 1452 | return 1453 | 1454 | # TODO @TH: we need to figure out a way not to have this run on "Save as...". 1455 | # or if we do want it to run -- get_path(PATH_TYPE_IDB) here will still hold the 1456 | # "old" path so reinvoke the 2nd save differently 1457 | changed = self.plugin.sync() 1458 | if changed: 1459 | logger.debug("resaving the idb with synced changes") 1460 | idb_name = ida_loader.get_path(ida_loader.PATH_TYPE_IDB) 1461 | # TODO @TH: can we somehow find the flags the original save was invoked with and reuse 1462 | # them? 1463 | ida_loader.save_database(idb_name, 0) 1464 | 1465 | 1466 | class LabSyncPlugin(ida_idaapi.plugin_t): 1467 | version: int = ida_idp.IDP_INTERFACE_VERSION 1468 | flags: int = ida_idaapi.PLUGIN_MOD | ida_idaapi.PLUGIN_HIDE 1469 | 1470 | comment: str = "helps to partially synchronize IDBs over git" 1471 | help: str = "" 1472 | wanted_name: str = "LabSync" 1473 | wanted_hotkey: str = "" 1474 | 1475 | menu_actions_types: list[type[LabSyncActionBase], ...] = \ 1476 | (LabSyncEnableAction, LabSyncDisableAction, LabSyncResetAction) 1477 | 1478 | CFGFILE: str = "labsync.cfg" 1479 | NETNODE: str = "$ labsync.plugin" 1480 | TYPES_NETNODE: str = "$ labsync.types" 1481 | BINARIES_NETNODE: str = "$ labsync.binaries" 1482 | 1483 | COMMIT_KEY_PREFIX = "commit." 1484 | 1485 | def __init__(self, *args, **kwargs): 1486 | super().__init__(*args, **kwargs) 1487 | 1488 | self.menu_actions = [] 1489 | self.hooks = None 1490 | 1491 | self._sync_in_progress = False 1492 | 1493 | @classmethod 1494 | @property 1495 | @functools.cache 1496 | def netnode(cls) -> netnode.Netnode: 1497 | """this netnode holds: 1498 | commit.: Optional[str] # the git commit this binary is synced to 1499 | enabled: bool # whether LabSync is enabled 1500 | custom_idb_id: Optional[str] # override of the IDB id to use 1501 | """ 1502 | return netnode.Netnode(LabSyncPlugin.NETNODE) 1503 | 1504 | @classmethod 1505 | @functools.cache 1506 | def types(cls, idb_id: str) -> netnode.Netnode: 1507 | """this netnode matches: 1508 | tid [int] # of a local type 1509 | to 1510 | uuid [str] # of it in the YAML 1511 | """ 1512 | name = f"{LabSyncPlugin.TYPES_NETNODE}.{idb_id}" 1513 | return netnode.Netnode(name) 1514 | 1515 | @classmethod 1516 | @property 1517 | @functools.cache 1518 | def _binaries_netnode(cls) -> netnode.Netnode: 1519 | """this netnode matches: 1520 | seg_prefix [str] # prefix of segment names 1521 | to 1522 | tuple[str, int] # of (, ) to use for mapping segments to separate 1523 | # YAMLs 1524 | """ 1525 | return netnode.Netnode(LabSyncPlugin.BINARIES_NETNODE) 1526 | 1527 | @classmethod 1528 | @property 1529 | @functools.cache 1530 | def cfg(cls) -> dict: 1531 | path = ( 1532 | pathlib.Path(ida_diskio.get_user_idadir()) / ida_diskio.CFG_SUBDIR / 1533 | LabSyncPlugin.CFGFILE 1534 | ) 1535 | try: 1536 | cfg_raw = path.open("rt").read() 1537 | except OSError as e: 1538 | logger.error(f"failed to read configuration file from {path!r}: {e}") # noqa: TRY400 1539 | return None 1540 | 1541 | cfg_parser = configparser.ConfigParser() 1542 | try: 1543 | cfg_parser.read_string("[section]\n" + cfg_raw) 1544 | except Exception: 1545 | logger.exception("failed to parse configuration file") 1546 | return None 1547 | 1548 | return dict(cfg_parser["section"].items()) 1549 | 1550 | @classmethod 1551 | @property 1552 | @functools.cache 1553 | def repo(cls) -> LabSyncRepo: 1554 | # validate/apply basic configuration 1555 | if "repo_path" not in cls.cfg: 1556 | logger.error("repo_path not found in configuration file") 1557 | return None 1558 | 1559 | try: 1560 | repo = LabSyncRepo(cls.cfg["repo_path"]) 1561 | except Exception: 1562 | logger.exception("configured repo_path does not point to a valid git repo") 1563 | return None 1564 | 1565 | logger.info(f"using repo: {repo.path}") 1566 | 1567 | return repo 1568 | 1569 | @classmethod 1570 | @property 1571 | def idb_id(cls) -> str: 1572 | default_id = ida_nalt.retrieve_input_file_md5().hex() 1573 | return cls.netnode.get("custom_idb_id", default_id) 1574 | 1575 | @classmethod 1576 | def commit_key(cls, idb_id: str) -> str: 1577 | return f"{cls.COMMIT_KEY_PREFIX}{idb_id}" 1578 | 1579 | def _register(self) -> None: 1580 | for t in LabSyncPlugin.menu_actions_types: 1581 | a = t(self) 1582 | a.register() 1583 | self.menu_actions.append(a) 1584 | 1585 | self.hooks = LabSyncHooks(self, self.menu_actions) 1586 | self.hooks.hook() 1587 | 1588 | def _deregister(self) -> None: 1589 | if self.hooks: 1590 | self.hooks.unhook() 1591 | 1592 | for a in self.menu_actions: 1593 | a.unregister() 1594 | 1595 | @staticmethod 1596 | def is_compatible() -> bool: 1597 | info = ida_idaapi.get_inf_structure() 1598 | return info.procname == "ARM" and info.is_64bit() 1599 | 1600 | @staticmethod 1601 | def _init_logging() -> None: 1602 | logger_formatter = logging.Formatter( 1603 | fmt="{name}.{levelname:<5s}: {message}", style="{", 1604 | ) 1605 | 1606 | logger_hdlr = logging.StreamHandler() 1607 | logger_hdlr.setFormatter(logger_formatter) 1608 | 1609 | logger.addHandler(logger_hdlr) 1610 | 1611 | # may be overridden with the 'log' config entry 1612 | logger.setLevel(logging.INFO) 1613 | 1614 | def migrate(self) -> None: 1615 | # migrate types to be per binary 1616 | old_types = netnode.Netnode(LabSyncPlugin.TYPES_NETNODE) 1617 | new_types = self.types(self.idb_id) 1618 | for tid, _uuid in list(old_types.items()): 1619 | new_types[tid] = _uuid 1620 | del old_types[tid] 1621 | 1622 | # migrate commit to be per binary 1623 | old_commit = self.netnode.get("commit") 1624 | if old_commit is not None: 1625 | self.netnode[self.commit_key(self.idb_id)] = old_commit 1626 | del self.netnode["commit"] 1627 | 1628 | def init(self) -> int: 1629 | LabSyncPlugin._init_logging() 1630 | 1631 | if not self.cfg or not self.repo: 1632 | return ida_idaapi.PLUGIN_SKIP 1633 | 1634 | for binary in self.binaries: 1635 | if binary.seg_prefix is None: 1636 | name = "main" 1637 | else: 1638 | name = f"{binary.seg_prefix}*" 1639 | logger.info(f"{name} idb id: {binary.idb_id}") 1640 | 1641 | if self.enabled: 1642 | logger.info("syncing enabled") 1643 | else: 1644 | logger.info("syncing disabled") 1645 | 1646 | self.migrate() 1647 | 1648 | for binary in self.binaries: 1649 | commit = self.netnode.get(self.commit_key(binary.idb_id)) 1650 | if self.enabled or commit: 1651 | logger.info( 1652 | f"{binary.idb_id} last synced to commit: {commit}", 1653 | ) 1654 | 1655 | log_level = self.cfg.get("log") 1656 | if log_level: 1657 | logger.setLevel(log_level) 1658 | 1659 | self._register() 1660 | 1661 | logger.info("initialized successfully") 1662 | 1663 | return ida_idaapi.PLUGIN_KEEP 1664 | 1665 | def term(self) -> None: 1666 | self._deregister() 1667 | 1668 | def run(self, arg: int = 0) -> None: 1669 | pass 1670 | 1671 | @classmethod 1672 | @property 1673 | def _lockfile_path(cls) -> pathlib.Path: 1674 | return pathlib.Path(__file__).parent / LOCKFILE 1675 | 1676 | @contextlib.contextmanager 1677 | def _lock( 1678 | self, wait_timeout: Optional[float] = None, 1679 | ) -> contextlib.AbstractContextManager[None]: 1680 | """it makes more sense to logically lock the LabSyncRepo and not LabSyncPlugin, but it's 1681 | problematic because we want to use a lockfile which orignally wasn't in the .gitignore of 1682 | that repo (and so syncing older IDBs will fail because we'll create the lockfile and that 1683 | will make the repo dirty) 1684 | """ 1685 | 1686 | deadline = time.monotonic() + wait_timeout 1687 | while True: # we want to try once even if the timeout is 0 1688 | logger.debug("taking lock on the repo") 1689 | try: 1690 | fd = os.open(self._lockfile_path, os.O_CREAT | os.O_EXCL | os.O_WRONLY) 1691 | break 1692 | except FileExistsError: 1693 | pass 1694 | 1695 | if time.monotonic() >= deadline: 1696 | logger.error( 1697 | "failed to get lock on the data repository within the configured timeout. " 1698 | "either another IDA instance is still syncing, or something bad happened " 1699 | "during a previous sync. if you're sure it's safe, you can delete the " 1700 | f"lockfile manually: {self._lockfile_path}" # noqa: COM812 1701 | ) 1702 | msg = "failed to get repo lock" 1703 | raise LabSyncLockError(msg) 1704 | 1705 | try: 1706 | yield 1707 | finally: 1708 | logger.debug("releasing lock on the repo") 1709 | os.close(fd) 1710 | self._lockfile_path.unlink() 1711 | 1712 | @property 1713 | def sync_in_progress(self) -> bool: 1714 | return self._sync_in_progress 1715 | 1716 | @classmethod 1717 | @property 1718 | def binaries(cls) -> tuple[SyncedBinary, ...]: 1719 | rules = dict(cls._binaries_netnode.items()) 1720 | return cls._binaries_from_mapping_rules(rules) 1721 | 1722 | @classmethod 1723 | def _binaries_from_mapping_rules( 1724 | cls, rules: dict[str, tuple[str, Optional[int]]]) -> tuple[SyncedBinary, ...]: 1725 | 1726 | if not rules: 1727 | return (SyncedBinary(idb_id=cls.idb_id),) 1728 | 1729 | # generate a synced binary per every segment matching rule and the default 1730 | seg2bin = {} 1731 | for seg_prefix, (idb_id, base_ea) in rules.items(): 1732 | # start with start_ea/end_ea pointing at max/min, and we'll have update them in the 1733 | # next loop 1734 | seg2bin[seg_prefix] = SyncedBinary( 1735 | idb_id=idb_id, start_ea=ida_idaapi.BADADDR, end_ea=0, base_ea=base_ea, 1736 | seg_prefix=seg_prefix, 1737 | ) 1738 | default_bin = SyncedBinary( 1739 | idb_id=cls.idb_id, start_ea=ida_idaapi.BADADDR, end_ea=0, seg_prefix=None, 1740 | ) 1741 | 1742 | # find the start/end EAs for each synced binary 1743 | for i in range(ida_segment.get_segm_qty()): 1744 | seg = ida_segment.getnseg(i) 1745 | name = ida_segment.get_segm_name(seg) 1746 | 1747 | # skip inlined chunks segments 1748 | if name.startswith("inlined_"): 1749 | continue 1750 | 1751 | matched = False 1752 | for seg_prefix, binary in seg2bin.items(): 1753 | if name.startswith(seg_prefix): 1754 | binary.start_ea = min(binary.start_ea, seg.start_ea) 1755 | binary.end_ea = max(binary.end_ea, seg.end_ea) 1756 | matched = True 1757 | 1758 | if not matched: 1759 | default_bin.start_ea = min(default_bin.start_ea, seg.start_ea) 1760 | default_bin.end_ea = max(default_bin.end_ea, seg.end_ea) 1761 | 1762 | # remove synced binaries that didn't match any segment 1763 | for seg, _bin in list(seg2bin.items()): 1764 | if _bin.start_ea == ida_idaapi.BADADDR: 1765 | del seg2bin[seg] 1766 | if default_bin.start_ea == ida_idaapi.BADADDR: 1767 | assert default_bin.end_ea == 0 1768 | default_bin.start_ea = 0 # make it empty 1769 | 1770 | # make sure that none of the synced binaries overlap 1771 | last_bin = None 1772 | last_seg = None 1773 | for _bin, seg in sorted( 1774 | [(_bin, seg) for (seg, _bin) in seg2bin.items()] + [(default_bin, "")], 1775 | ): 1776 | 1777 | assert _bin.start_ea <= _bin.end_ea 1778 | if last_bin: 1779 | assert last_bin.start_ea <= _bin.start_ea 1780 | if last_bin.end_ea > _bin.start_ea: 1781 | msg = f"Found overlapping segments for {last_seg!r} and {seg!r}" 1782 | raise LabSyncBinaryMatchingError(msg) 1783 | 1784 | last_bin = _bin 1785 | last_seg = seg 1786 | 1787 | # validate/set base_ea-s 1788 | for seg, _bin in seg2bin.items(): 1789 | if _bin.base_ea is None: 1790 | _bin.base_ea = _bin.start_ea 1791 | elif _bin.base_ea > _bin.start_ea: 1792 | msg = f"Base EA for {seg!r} is greater than its start EA" 1793 | raise LabSyncBinaryMatchingError(msg) 1794 | 1795 | binaries = (default_bin, *seg2bin.values()) 1796 | 1797 | # make sure the we don't have overlapping IDB ids 1798 | assert len(binaries) == len({b.idb_id for b in binaries}) 1799 | 1800 | return binaries 1801 | 1802 | @classmethod 1803 | def map_segments_to_idb_id( 1804 | cls, seg_prefix: str, idb_id: str, *, base_ea: Optional[int] = None) -> None: 1805 | 1806 | rules = dict(cls._binaries_netnode.items()) 1807 | 1808 | new_rules = rules.copy() 1809 | seg_rule = (idb_id, base_ea) 1810 | new_rules[seg_prefix] = seg_rule 1811 | 1812 | # check that the new rules are valid 1813 | try: 1814 | cls._binaries_from_mapping_rules(new_rules) 1815 | except LabSyncBinaryMatchingError: 1816 | logger.exception(f"failed mapping segment prefix {seg_prefix!r} to idb id {idb_id}") 1817 | return 1818 | 1819 | # add the rule to netnode 1820 | cls._binaries_netnode[seg_prefix] = seg_rule 1821 | 1822 | # invalidate previous types if we had them (since they might be outdated) 1823 | types = cls.types(idb_id) 1824 | for tid in list(types.keys()): 1825 | del types[tid] 1826 | 1827 | def sync(self) -> None: 1828 | assert not self.sync_in_progress 1829 | 1830 | try: 1831 | self._sync_in_progress = True 1832 | 1833 | logger.debug("checking that the remote repository is reachable") 1834 | if not self.repo.ping(): 1835 | logger.warning("skipping sync because the remote repository is unreachable") 1836 | return False 1837 | 1838 | timeout = float(self.cfg.get("lock_timeout_sec", DEFAULT_LOCK_TIMEOUT)) 1839 | with self._lock(timeout): 1840 | binaries = self.binaries 1841 | for binary in self.binaries: 1842 | if len(binaries) > 1: 1843 | logger.debug(f"syncing {binary.idb_id}") 1844 | 1845 | # in case this is the initial commit, try to adopt local types from the repo 1846 | # (in case this IDB was already synced) 1847 | base = self.netnode.get(self.commit_key(binary.idb_id)) 1848 | if not base: 1849 | latest_data, latest_commit = self.repo.get(binary.idb_id) 1850 | if latest_data: 1851 | logger.debug(f"adopting local type uuids from commit: {latest_commit}") 1852 | adopt_uuids(latest_data, self.types(binary.idb_id)) 1853 | 1854 | # sync IDB -> repo 1855 | logger.debug("saving changes to repo") 1856 | 1857 | data = dump(binary, self.types(binary.idb_id)) 1858 | commit, changed = self.repo.put(binary.idb_id, data, base=base) 1859 | 1860 | if changed: 1861 | # save the IDB with the updated types and commit, in case something will 1862 | # break later during the merge 1863 | # 1864 | # TODO @TH: this path will be wrong if we're under "Save as..." flow. 1865 | # see comments under LabSyncHooks.saved 1866 | self.netnode[self.commit_key(binary.idb_id)] = commit 1867 | 1868 | idb_name = ida_loader.get_path(ida_loader.PATH_TYPE_IDB) 1869 | ida_loader.save_database(idb_name, 0) 1870 | 1871 | # sync repo with upstream 1872 | self.repo.sync() 1873 | 1874 | # sync repo -> IDB 1875 | new_data, new_commit = self.repo.get(binary.idb_id) 1876 | 1877 | # if there's a new commit with new data for our IDB -- update 1878 | if new_data != data: 1879 | logger.debug("updating with changes from repo") 1880 | with wait_box("updating with changes from repo...", hide_cancel=True): 1881 | update(binary, new_data, self.types(binary.idb_id)) 1882 | changed = True 1883 | 1884 | # save the commit we're synced to in netnode (even if just the commit 1885 | # changed) 1886 | if new_commit != commit: 1887 | self.netnode[self.commit_key(binary.idb_id)] = new_commit 1888 | changed = True 1889 | 1890 | p = "" if len(binaries) == 1 else f"{binary.idb_id} " 1891 | s = "" if changed else " (no changes)" 1892 | logger.info(f"{p}synced to commit: {new_commit}{s}") 1893 | 1894 | return changed 1895 | except BaseException as exc: # noqa: BLE001 1896 | ida_kernwin.warning("LabSync synchronization failed. See output window for more " 1897 | "details") 1898 | if not isinstance(exc, LabSyncLockError): 1899 | raise 1900 | finally: 1901 | self._sync_in_progress = False 1902 | 1903 | @classmethod 1904 | def enable(cls) -> None: 1905 | cls.netnode["enabled"] = True 1906 | logger.info("syncing enabled") 1907 | 1908 | for binary in cls.binaries: 1909 | commit = cls.netnode.get(cls.commit_key(binary.idb_id)) 1910 | logger.info( 1911 | f"{binary.idb_id} last synced to commit: {commit}", 1912 | ) 1913 | 1914 | @classmethod 1915 | def disable(cls) -> None: 1916 | cls.netnode["enabled"] = False 1917 | logger.info("syncing disabled") 1918 | 1919 | @classmethod 1920 | def reset(cls) -> None: 1921 | # make sure that we're already disabled, to make sure that no one resets by mistake 1922 | assert not cls.enabled 1923 | 1924 | idb_ids = {} 1925 | 1926 | # delete the commit states 1927 | for k in cls.netnode.keys(): # noqa: SIM118 1928 | if k.startswith(cls.COMMIT_KEY_PREFIX): 1929 | idb_ids.add(k[len(cls.COMMIT_KEY_PREFIX):]) 1930 | del cls.netnode[k] 1931 | 1932 | for binary in cls.binaries: 1933 | idb_ids.add(binary.idb_id) 1934 | 1935 | # delete the tid->uuid mapping for all of the IDB ids we noted 1936 | for idb_id in idb_ids: 1937 | types = cls.types(idb_id) 1938 | for tid in list(types.keys()): 1939 | del types[tid] 1940 | 1941 | logger.info("sync data reset") 1942 | 1943 | @classmethod 1944 | @property 1945 | def enabled(cls) -> bool: 1946 | return cls.netnode.get("enabled", False) 1947 | 1948 | 1949 | def PLUGIN_ENTRY() -> ida_idaapi.plugin_t: # noqa: N802 1950 | return LabSyncPlugin() 1951 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | PyYAML 2 | GitPython 3 | sark 4 | ida-netnode 5 | parse 6 | # functioninliner 7 | -------------------------------------------------------------------------------- /ruff.toml: -------------------------------------------------------------------------------- 1 | target-version = "py39" 2 | line-length = 99 3 | 4 | [lint] 5 | preview = true 6 | select = ["ALL"] 7 | ignore = [ 8 | "D", "S101", "TD003", "FIX002", "PLR0912", "PLR0913", "RET505", "RET506", "TRY003", 9 | "PLR2004", "G004", "C901", "PLR0915", "S311", "SIM108", "PLW2901", "G003", "TCH003", 10 | "UP007", "ARG002", "ANN101", "ANN204", "ANN002", "ANN003", "ANN401", "ANN102", "CPY", 11 | "E116", "PLR1702", "PLR0914", 12 | ] 13 | -------------------------------------------------------------------------------- /test_labsync.py: -------------------------------------------------------------------------------- 1 | import random 2 | import string 3 | 4 | import pytest 5 | 6 | from labsync import decl_to_name_and_type, stable_topological_sort 7 | 8 | 9 | class MockTypes: 10 | def __getitem__(self, key: str) -> str: 11 | return "00000000-0000-0000-0000-000000000000" 12 | 13 | @staticmethod 14 | def get(key: str) -> str: # noqa: ARG004 15 | return "00000000-0000-0000-0000-000000000000" 16 | 17 | 18 | def test_decl_to_name_pat() -> None: 19 | tests = ( 20 | ( # normal local type 21 | "struct __CFString", 22 | "__CFString", 23 | ), 24 | ( # typedef 25 | "typedef const __CFString *CFStringRef;", 26 | "CFStringRef", 27 | ), 28 | ( # fptr typedef 29 | "typedef CFStringRef (__cdecl *CFArrayCopyDescriptionCallBack)(const void *);", 30 | "CFArrayCopyDescriptionCallBack", 31 | ), 32 | ( # forward declaration 33 | "struct x;", 34 | "x", 35 | ), 36 | ) 37 | 38 | for t, n in tests: 39 | assert decl_to_name_and_type(t)[0] == n 40 | 41 | 42 | def test_stable_topological_sort() -> None: 43 | tests = ( 44 | ( 45 | { 46 | "a": {"b"}, 47 | "b": {"c"}, 48 | "c": set(), 49 | }, 50 | ("c", "b", "a"), 51 | ), 52 | ( 53 | { 54 | "a": {"b"}, 55 | "b": set(), 56 | "c": set(), 57 | }, 58 | ("b", "a", "c"), 59 | ), 60 | ) 61 | 62 | for graph, expected_result in tests: 63 | result = tuple(stable_topological_sort(graph)) 64 | assert result == expected_result 65 | 66 | # test bad graphs 67 | with pytest.raises(ValueError): # noqa: PT011 68 | tuple(stable_topological_sort({"a": "b", "b": "a"})) 69 | with pytest.raises(ValueError): # noqa: PT011 70 | tuple(stable_topological_sort({"a": "a"})) 71 | with pytest.raises(ValueError): # noqa: PT011 72 | tuple(stable_topological_sort({"a": "b"})) 73 | 74 | # test lexical ordering 75 | for _ in range(10): 76 | vertices = [random.choice(string.ascii_letters) for _ in range(10)] 77 | graph = {x: set() for x in vertices} 78 | result = tuple(stable_topological_sort(graph)) 79 | expected_result = tuple(sorted(set(vertices))) 80 | assert result == expected_result 81 | --------------------------------------------------------------------------------