├── .gitignore ├── COPYING ├── MANIFEST.in ├── README.markdown ├── description.rst ├── requirements.txt ├── runtests.py ├── screenshot.png ├── setup.py ├── tests ├── __init__.py ├── interface.py ├── patching.py ├── platform.py ├── target.py └── types.py └── voidwalker ├── __init__.py ├── application ├── __init__.py ├── commands │ ├── __init__.py │ ├── context.py │ ├── dump.py │ └── voidwalker.py ├── cpus │ ├── __init__.py │ ├── generic.py │ ├── mips.py │ ├── mips_instructions.py │ ├── x86.py │ ├── x86_64.py │ └── x86_instructions.py ├── parameters │ ├── __init__.py │ ├── context.py │ ├── show.py │ └── voidwalker.py └── patching │ ├── __init__.py │ ├── interface.py │ └── nop.py ├── backends ├── __init__.py ├── gdb │ ├── __init__.py │ ├── command.py │ ├── event.py │ ├── hooks.py │ ├── parameter.py │ ├── platform.py │ ├── target.py │ ├── terminal.py │ └── tools │ │ ├── __init__.py │ │ ├── breakpoints.py │ │ └── interface.py └── test │ ├── __init__.py │ ├── interface.py │ ├── platform.py │ └── target.py ├── framework ├── __init__.py ├── interface │ ├── __init__.py │ ├── command.py │ ├── config.py │ └── parameter.py ├── patching │ ├── __init__.py │ ├── composer.py │ ├── snippet.py │ └── types.py ├── platform │ ├── __init__.py │ ├── context.py │ ├── cpu.py │ └── factory.py ├── system │ ├── __init__.py │ └── event.py ├── target │ ├── __init__.py │ ├── inferior.py │ └── thread.py ├── types │ ├── __init__.py │ ├── data.py │ └── instructions.py └── utils │ ├── __init__.py │ ├── enum.py │ ├── ordereddict.py │ └── recipes.py ├── version.py └── voidwalker.py /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | .#* 3 | *_flymake.py 4 | *.pyc 5 | .coverage 6 | 7 | dist/ 8 | build/ 9 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include voidwalker.py README.markdown run-tests.py description.rst 2 | recursive-include voidwalker/ *.py 3 | recursive-exclude voidwalker/ *.pyc 4 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | # (void)walker 2 | 3 | (void)walker is a toolbox for GDB which provides utilities for debugging 4 | software on an instruction level. It is heavily influenced by the 5 | [gdbinit](https://github.com/gdbinit/Gdbinit) by *mammon_*, *elaine*, *fG!* 6 | et al. but opens up for a much more advanced solution by using Python instead 7 | of GDB commands. 8 | 9 | ![(void)walker session](https://github.com/dholm/voidwalker/raw/master/screenshot.png) 10 | 11 | 12 | ## Requirements 13 | 14 | * [GDB](http://www.gnu.org/software/gdb/) 7.5 or later built with support for 15 | Python extensions. 16 | * [FlowUI](https://github.com/dholm/FlowUI) 0.2.1 or later. 17 | 18 | Currently (void)walker has support for the following architectures, but adding 19 | new ones should be fairly easy at this point. 20 | 21 | * X86 22 | * X86-64 23 | * MIPS 24 | 25 | 26 | ## Installation 27 | 28 | Install the requirements using pip: 29 | 30 | pip install -r requirements.txt 31 | 32 | Install (void)walker using the supplied *setup.py* by executing: 33 | 34 | python setup.py install 35 | 36 | Finally add the following line to your *~/.gdbinit* to have it loaded 37 | automatically whenever GDB is launched: 38 | 39 | python from voidwalker import voidwalker 40 | 41 | The next time you start GDB you should see (void)walker being loaded. 42 | 43 | You should also install all the (void)walker hooks in order to complete the 44 | integration with GDB. 45 | 46 | 47 | ## Usage 48 | 49 | Dumping the context of the current stack frame: 50 | 51 | voidwalker context 52 | 53 | Dumping data by specifying address and length: 54 | 55 | voidwalker dump data
56 | 57 | Dumping disassembly by specifying address and the number of instructions: 58 | 59 | voidwalker dump instructions
60 | 61 | Set a breakpoint at the start of the .text section. This command can be useful 62 | in setting a breakpoint at start if no symbols are available. 63 | 64 | voidwalker gdb break text 65 | 66 | The following commands can be used to patch the loaded binary. All 67 | modifications are applied on the loaded binary and the original file is never 68 | touched. 69 | 70 | voidwalker patch snippet list 71 | voidwalker patch snippet apply
72 | 73 | 74 | ### Hooks 75 | 76 | (void)walker commands that are prefixed with *hook-* are intended to be put 77 | into hooks of the same name in *~/.gdbinit*, for example: 78 | 79 | define hook-stop 80 | voidwalker hook-stop 81 | end 82 | 83 | 84 | ## Parameters 85 | 86 | Changing themes: 87 | 88 | voidwalker-theme 89 | 90 | For instance, to set Zenburn as the default theme instead of Solarized add the 91 | following line to *~/.gdbinit*: 92 | 93 | set voidwalker-theme zenburn 94 | 95 | Controlling what is shown as part of a context: 96 | 97 | voidwalker-context-stackdw 98 | voidwalker-context-instructions 99 | 100 | For instance, to suppress the stack from being dumped when calling *voidwalker 101 | context* add the following line to ~/.gdbinit: 102 | 103 | set voidwalker-context-stackdw 0 104 | 105 | Modifying what is performed when hooks are executed by GDB: 106 | 107 | voidwalker-hook-context 108 | 109 | 110 | ## License 111 | 112 | (void)walker is distributed under the GPLv3 license, the same as GDB. See the 113 | file called COPYING for the full license text. 114 | -------------------------------------------------------------------------------- /description.rst: -------------------------------------------------------------------------------- 1 | .. -*- restructuredtext -*- 2 | 3 | (void)walker 4 | ============ 5 | 6 | `(void)walker` is a toolbox for `GDB` which provides utilities for debugging 7 | software on an instruction level. 8 | 9 | 10 | Requirements 11 | ------------ 12 | 13 | * `GDB `_ 7.5 or later built with support 14 | for Python extensions. 15 | * `FlowUI `_ 0.2.1 or later. 16 | 17 | Currently (void)walker has support for the following architectures:: 18 | 19 | * X86 20 | * X86-64 21 | * MIPS 22 | 23 | 24 | Usage 25 | ----- 26 | 27 | (void)walker can be loaded manually from within ``GDB`` by running:: 28 | 29 | python from voidwalker import voidwalker 30 | 31 | By adding the previous line to ``~/.gdbinit`` (void)walker will be loaded 32 | automatically whenever ``GDB`` is launched. 33 | 34 | Also register the following hooks in ``~/.gdbinit``:: 35 | 36 | define hook-stop 37 | voidwalker hook-stop 38 | end 39 | 40 | 41 | Commands 42 | -------- 43 | 44 | Here follows a list of a few commands, see the ``README`` for a complete list. 45 | 46 | Dumping the context of the current stack frame:: 47 | 48 | voidwalker context 49 | 50 | Dumping data by specifying address and length:: 51 | 52 | voidwalker dump data
53 | 54 | Dumping disassembly by specifying address and the number of instructions:: 55 | 56 | voidwalker dump instructions
57 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | FlowUI>=0.2.1 2 | -------------------------------------------------------------------------------- /runtests.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # (void)walker unit tests 4 | # Copyright (C) 2012 David Holm 5 | 6 | # This program is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | import sys 20 | import unittest 21 | 22 | import tests 23 | 24 | 25 | suite = tests.suite() 26 | runner = unittest.TextTestRunner(verbosity=2) 27 | result = runner.run(suite) 28 | sys.exit({True: 0, False: 3}[result.wasSuccessful()]) 29 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dholm/voidwalker/73eff8b7e1882c6e0b6af44a4fdf7e8746026d7a/screenshot.png -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import os 4 | 5 | from distutils.core import setup 6 | from voidwalker import __version__ 7 | 8 | 9 | long_description = open(os.path.join(os.path.dirname(__file__), 10 | 'description.rst')).read() 11 | 12 | setup(name='voidwalker', 13 | packages=['voidwalker', 14 | 'voidwalker.framework', 15 | 'voidwalker.framework.interface', 16 | 'voidwalker.framework.patching', 17 | 'voidwalker.framework.platform', 18 | 'voidwalker.framework.system', 19 | 'voidwalker.framework.target', 20 | 'voidwalker.framework.types', 21 | 'voidwalker.framework.utils', 22 | 'voidwalker.backends', 23 | 'voidwalker.backends.gdb', 24 | 'voidwalker.backends.gdb.tools', 25 | 'voidwalker.application', 26 | 'voidwalker.application.commands', 27 | 'voidwalker.application.parameters', 28 | 'voidwalker.application.patching', 29 | 'voidwalker.application.cpus'], 30 | requires=['FlowUI (>=0.2.1)'], 31 | version=__version__, 32 | description=('A GDB toolbox for low-level debugging and reverse ' 33 | 'engineering'), 34 | author='David Holm', 35 | author_email='dholmster@gmail.com', 36 | url='http://github.com/dholm/voidwalker/', 37 | download_url=('https://github.com/dholm/voidwalker/archive/v%s.zip' % 38 | __version__), 39 | license='GPLv3', 40 | keywords=['debugging', 'gdb', 'reverse engineering', 'console', 41 | 'terminal'], 42 | classifiers=[ 43 | 'Environment :: Console', 44 | 'Topic :: Software Development', 45 | 'Intended Audience :: Developers', 46 | 'Intended Audience :: Science/Research', 47 | 'License :: OSI Approved :: GNU General Public License v3 (GPLv3)', 48 | 'Operating System :: MacOS :: MacOS X', 49 | 'Operating System :: POSIX', 50 | 'Operating System :: Unix', 51 | 'Topic :: Security', 52 | 'Programming Language :: Python :: 2.6', 53 | 'Programming Language :: Python :: 2.7'], 54 | long_description=long_description) 55 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | # (void)walker unit tests 2 | # Copyright (C) 2012-2013 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | import unittest 18 | 19 | import tests.interface 20 | import tests.patching 21 | import tests.platform 22 | import tests.target 23 | import tests.types 24 | 25 | 26 | def suite(): 27 | loader = unittest.TestLoader() 28 | test_suite = unittest.TestSuite() 29 | test_suite.addTests(loader.loadTestsFromModule(tests.interface)) 30 | test_suite.addTests(loader.loadTestsFromModule(tests.patching)) 31 | test_suite.addTests(loader.loadTestsFromModule(tests.platform)) 32 | test_suite.addTests(loader.loadTestsFromModule(tests.target)) 33 | test_suite.addTests(loader.loadTestsFromModule(tests.types)) 34 | return test_suite 35 | -------------------------------------------------------------------------------- /tests/interface.py: -------------------------------------------------------------------------------- 1 | # (void)walker unit tests 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from flowui.terminal import AnsiTerminal 18 | from flowui.terminals import SysTerminal 19 | from flowui.themes import Solarized 20 | from unittest import TestCase 21 | 22 | from voidwalker.framework.interface import BooleanParameter 23 | from voidwalker.framework.interface import CommandBuilder 24 | from voidwalker.framework.interface import Configuration 25 | from voidwalker.framework.interface import DataCommand 26 | from voidwalker.framework.interface import EnumParameter 27 | from voidwalker.framework.interface import Parameter 28 | from voidwalker.framework.interface import ParameterBuilder 29 | from voidwalker.framework.interface import PrefixCommand 30 | from voidwalker.framework.interface import register_command 31 | from voidwalker.framework.interface import register_parameter 32 | from voidwalker.framework.platform import CpuFactory 33 | from voidwalker.framework.target import InferiorRepository 34 | 35 | from voidwalker.backends.test import TestCommandFactory 36 | from voidwalker.backends.test import TestInferiorFactory 37 | from voidwalker.backends.test import TestParameterFactory 38 | from voidwalker.backends.test import TestPlatformFactory 39 | from voidwalker.backends.test import TestThreadFactory 40 | 41 | 42 | @register_command 43 | class TestCommand(PrefixCommand): 44 | @staticmethod 45 | def name(): 46 | return 'test' 47 | 48 | 49 | @register_command 50 | class TestDataCommand(DataCommand): 51 | @staticmethod 52 | def name(): 53 | return '%s %s' % (TestCommand.name(), 'data') 54 | 55 | def execute(self, terminal, thread, argument): 56 | pass 57 | 58 | 59 | class CommandTest(TestCase): 60 | def setUp(self): 61 | self._terminal = AnsiTerminal(SysTerminal(), Solarized()) 62 | 63 | def test_command(self): 64 | inferior_factory = TestInferiorFactory() 65 | thread_factory = TestThreadFactory() 66 | inferior_repository = InferiorRepository() 67 | bldr = CommandBuilder(TestCommandFactory(), inferior_repository, 68 | TestPlatformFactory(), inferior_factory, 69 | thread_factory, Configuration(), self._terminal) 70 | 71 | self.assertIn(TestCommand.name(), bldr.commands) 72 | self.assertIn(TestDataCommand.name(), bldr.commands) 73 | 74 | 75 | @register_parameter 76 | class TestParameter(Parameter): 77 | '''test parameter''' 78 | 79 | def init(self): 80 | pass 81 | 82 | def default_value(self): 83 | return None 84 | 85 | @staticmethod 86 | def name(): 87 | return 'test' 88 | 89 | 90 | @register_parameter 91 | class BooleanParameterTest(BooleanParameter): 92 | '''test boolean parameter''' 93 | 94 | def default_value(self): 95 | return True 96 | 97 | @staticmethod 98 | def name(): 99 | return '%s %s' % (TestParameter.name(), 'boolean') 100 | 101 | 102 | @register_parameter 103 | class EnumParameterTest(EnumParameter): 104 | '''test enum parameter''' 105 | 106 | values = ['alpha', 'beta', 'gamma'] 107 | 108 | def default_value(self): 109 | return self.values[0] 110 | 111 | def init(self): 112 | pass 113 | 114 | def sequence(self): 115 | return self.values 116 | 117 | @staticmethod 118 | def name(): 119 | return '%s %s' % (TestParameter.name(), 'enum') 120 | 121 | 122 | class ParameterTest(TestCase): 123 | def setUp(self): 124 | config = Configuration() 125 | ParameterBuilder(TestParameterFactory(), config) 126 | self._config = config 127 | 128 | def test_parameter(self): 129 | name = TestParameter.name() 130 | self.assertIsNotNone(self._config.parameter(name)) 131 | 132 | def test_boolean_parameter(self): 133 | name = BooleanParameterTest.name() 134 | self.assertIsNotNone(self._config.parameter(name)) 135 | 136 | def test_enum_parameter(self): 137 | name = EnumParameterTest.name() 138 | self.assertIsNotNone(self._config.parameter(name)) 139 | -------------------------------------------------------------------------------- /tests/patching.py: -------------------------------------------------------------------------------- 1 | # (void)walker unit tests 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from unittest import TestCase 18 | 19 | from voidwalker.framework.patching import SnippetRepository 20 | 21 | import voidwalker.application.patching 22 | 23 | 24 | class SnippetsTest(TestCase): 25 | def test_snippet_manager(self): 26 | snippet_repository = SnippetRepository() 27 | for name, snippet in snippet_repository.snippets(): 28 | print 'Snippet: %s %s' % (name, snippet.description()) 29 | for architecture in snippet.architectures(): 30 | implementation = snippet.implementation(architecture) 31 | print '\t%s' % implementation.hex() 32 | -------------------------------------------------------------------------------- /tests/platform.py: -------------------------------------------------------------------------------- 1 | # (void)walker unit tests 2 | # Copyright (C) 2012-2013 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from unittest import TestCase 18 | 19 | from voidwalker.framework.interface import Configuration 20 | from voidwalker.framework.platform import CpuFactory 21 | from voidwalker.framework.platform import CpuRepository 22 | from voidwalker.framework.target import InferiorRepository 23 | 24 | from voidwalker.application.cpus import MipsCpu 25 | from voidwalker.application.cpus import X8664Cpu 26 | from voidwalker.application.cpus import X86Cpu 27 | 28 | from voidwalker.backends.test import TestCpu 29 | from voidwalker.backends.test import TestCpuFactory 30 | from voidwalker.backends.test import TestInferiorFactory 31 | from voidwalker.backends.test import TestThreadFactory 32 | from voidwalker.backends.test import TestPlatformFactory 33 | 34 | 35 | class CpuTest(TestCase): 36 | def setUp(self): 37 | self._cpu_factory = TestCpuFactory() 38 | 39 | def test_test(self): 40 | cpu_repository = CpuRepository(TestCpuFactory()) 41 | cpu = cpu_repository.get_cpu(TestCpu.architecture()) 42 | for register_list in TestCpu.register_dict.itervalues(): 43 | for name in register_list: 44 | self.assertIsNotNone(cpu.register(name)) 45 | register = cpu.register(name) 46 | self.assertEqual(name, register.name()) 47 | 48 | def test_x86(self): 49 | cpu = X86Cpu(self._cpu_factory) 50 | self.assertIsNotNone(cpu.register('eax')) 51 | 52 | def test_x86_64(self): 53 | cpu = X8664Cpu(self._cpu_factory) 54 | self.assertIsNotNone(cpu.register('rax')) 55 | 56 | def test_mips(self): 57 | cpu = MipsCpu(self._cpu_factory) 58 | self.assertIsNotNone(cpu.register('a0')) 59 | 60 | 61 | class ContextTest(TestCase): 62 | def setUp(self): 63 | cpu_factory = TestCpuFactory() 64 | cpu = cpu_factory.create_cpu(TestCpu.architecture()) 65 | inferior_factory = TestInferiorFactory() 66 | inferior = inferior_factory.create_inferior(cpu, 0) 67 | self._inferior_repository = InferiorRepository() 68 | self._inferior_repository.add_inferior(inferior) 69 | thread_factory = TestThreadFactory() 70 | thread_factory.create_thread(inferior, 0) 71 | self._platform_factory = TestPlatformFactory() 72 | 73 | def test_registers(self): 74 | inferior = self._inferior_repository.get_inferior(0) 75 | thread = inferior.thread(0) 76 | context = self._platform_factory.create_context(Configuration(), 77 | inferior, thread) 78 | for _, register_dict in inferior.cpu().registers(): 79 | for name, register in register_dict.iteritems(): 80 | self.assertIsNotNone(context.register(name)) 81 | context_register = context.register(name) 82 | self.assertEqual(register.size(), context_register.size()) 83 | self.assertEqual(register.value(), context_register.value()) 84 | -------------------------------------------------------------------------------- /tests/target.py: -------------------------------------------------------------------------------- 1 | # (void)walker unit tests 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from unittest import TestCase 18 | 19 | from voidwalker.framework.platform import CpuFactory 20 | from voidwalker.framework.target import InferiorRepository 21 | 22 | from voidwalker.backends.test import TestPlatformFactory 23 | from voidwalker.backends.test import TestThreadFactory 24 | from voidwalker.backends.test import TestInferiorFactory 25 | 26 | from voidwalker.backends.test.platform import TestCpuFactory 27 | from voidwalker.backends.test.target import TestInferiorFactory 28 | from voidwalker.backends.test.target import TestThreadFactory 29 | 30 | 31 | class InferiorTest(TestCase): 32 | def setUp(self): 33 | cpu_factory = TestCpuFactory() 34 | self._cpu = cpu_factory.create_cpu(None) 35 | 36 | def test_inferior_repository(self): 37 | inferior_repository = InferiorRepository() 38 | self.assertFalse(inferior_repository.has_inferior(0)) 39 | 40 | def test_inferior(self): 41 | inferior_factory = TestInferiorFactory() 42 | inferior = inferior_factory.create_inferior(self._cpu, 0) 43 | 44 | self.assertEqual(0, inferior.id()) 45 | self.assertEqual(inferior.cpu().architecture(), 46 | self._cpu.architecture()) 47 | 48 | def test_thread(self): 49 | inferior_factory = TestInferiorFactory() 50 | inferior = inferior_factory.create_inferior(self._cpu, 0) 51 | thread_factory = TestThreadFactory() 52 | thread = thread_factory.create_thread(inferior, 0) 53 | inferior.add_thread(thread) 54 | 55 | self.assertTrue(inferior.has_thread(0)) 56 | thread = inferior.thread(0) 57 | self.assertEqual(0, thread.id()) 58 | -------------------------------------------------------------------------------- /tests/types.py: -------------------------------------------------------------------------------- 1 | # (void)walker unit tests 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from array import array 18 | from flowui.terminal import AnsiTerminal 19 | from flowui.terminals import SysTerminal 20 | from flowui.themes import Solarized 21 | from unittest import TestCase 22 | 23 | from voidwalker.framework.types.data import DataChunk 24 | from voidwalker.framework.types.data import DataWidget 25 | from voidwalker.framework.types.instructions import Instruction 26 | from voidwalker.framework.types.instructions import InstructionListing 27 | from voidwalker.framework.types.instructions import InstructionListingWidget 28 | 29 | 30 | class WidgetsTest(TestCase): 31 | def _draw_widget(self, widget): 32 | self._terminal.write('\n\t# Current terminal width #\n') 33 | widget.draw(self._terminal, self._terminal.width()) 34 | 35 | self._terminal.write(('\n\t# Default width (%d) #\n' % 36 | self._terminal.DEFAULT_WIDTH)) 37 | widget.draw(self._terminal, self._terminal.DEFAULT_WIDTH) 38 | 39 | def setUp(self): 40 | self._terminal = AnsiTerminal(SysTerminal(), Solarized()) 41 | 42 | def test_datachunk(self): 43 | address = 0xf00fba11 44 | data = array('c', ['\x00', '\x01', '\xff', '\x12']) 45 | data_chunk = DataChunk(address, buffer(data)) 46 | self.assertEqual(address, data_chunk.address()) 47 | self.assertItemsEqual(data, data_chunk.buffer()) 48 | 49 | def test_datawidget(self): 50 | address = 0xf00fba11 51 | data = '\x00test\x12\x67\x90\xff\x0042\xff\x15\x16' 52 | data_chunk = DataChunk(address, buffer(data)) 53 | data_widget = DataWidget(data_chunk) 54 | self._draw_widget(data_widget) 55 | 56 | def test_instruction(self): 57 | opcode = array('c', ['\x83', '\xc0', '\x02']) 58 | mnemonic = 'add' 59 | operands = '$0x2,%%eax' 60 | symbol = '' 61 | instruction = Instruction(opcode, mnemonic, operands, symbol) 62 | self.assertEqual(opcode, instruction.opcode()) 63 | self.assertEqual(mnemonic, instruction.mnemonic()) 64 | self.assertEqual(operands, instruction.operands()) 65 | self.assertEqual(symbol, instruction.symbol()) 66 | 67 | def test_instruction_listing(self): 68 | listing = InstructionListing() 69 | listing.add_instruction(0xed4, Instruction(array('c', ['\x83', '\xc0', 70 | '\x02']), 71 | 'add', '$0x2,%%eax', 72 | '')) 73 | long_symbol_name = ['x' for _ in range(self._terminal.DEFAULT_WIDTH)] 74 | listing.add_instruction(0xed7, Instruction(array('c', ['\x48', '\x89', 75 | '\xc7']), 76 | 'mov', '%%rax,%%rdi', 77 | ''.join(long_symbol_name))) 78 | 79 | listing_widget = InstructionListingWidget(listing, 0xed4) 80 | self._draw_widget(listing_widget) 81 | -------------------------------------------------------------------------------- /voidwalker/__init__.py: -------------------------------------------------------------------------------- 1 | # (void)walker GDB plugin 2 | # Copyright (C) 2012-2013 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from .version import __version__ 18 | -------------------------------------------------------------------------------- /voidwalker/application/__init__.py: -------------------------------------------------------------------------------- 1 | # (void)walker application implementation 2 | # Copyright (C) 2012-2013 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from . import commands 18 | from . import cpus 19 | from . import parameters 20 | from . import patching 21 | -------------------------------------------------------------------------------- /voidwalker/application/commands/__init__.py: -------------------------------------------------------------------------------- 1 | # (void)walker command interface 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from .voidwalker import VoidwalkerCommand 18 | from .context import ContextCommand 19 | from .dump import DumpCommand 20 | from .dump import DumpDataCommand 21 | from .dump import DumpInstructionsCommand 22 | -------------------------------------------------------------------------------- /voidwalker/application/commands/context.py: -------------------------------------------------------------------------------- 1 | # (void)walker command interface 2 | # Copyright (C) 2012-2013 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from flowui import Widget 18 | from flowui.widgets import Section 19 | from flowui.widgets.table import Cell 20 | from flowui.widgets.table import Table 21 | 22 | from ...framework.interface import StackCommand 23 | from ...framework.interface import register_command 24 | from ...framework.platform import PlatformFactory 25 | from ...framework.types import DataWidget 26 | from ...framework.types import InstructionListingWidget 27 | 28 | from .voidwalker import VoidwalkerCommand 29 | 30 | 31 | class ContextWidget(Widget): 32 | def __init__(self, previous_context, context): 33 | super(ContextWidget, self).__init__() 34 | self._previous_context = previous_context 35 | self._context = context 36 | 37 | def _create_registers_section(self, previous_context, context): 38 | registers_section = Section('registers') 39 | for _, register_dict in context.registers(): 40 | reg_size = 0 41 | for name in register_dict.iterkeys(): 42 | reg_size = max(reg_size, len(name)) 43 | 44 | table = Table() 45 | for name, register in register_dict.iteritems(): 46 | contents = [('%(face-identifier)s' + 47 | (('%%-%ds: ' % reg_size) % name))] 48 | 49 | value = register.value() 50 | face = '%(face-constant)s' 51 | if previous_context.register(register.name()).value() != value: 52 | face = '%(face-special)s' 53 | 54 | if value is not None: 55 | contents += [('%s%s' % (face, register.str()))] 56 | 57 | else: 58 | contents += [('%(face-comment)s' + 59 | (' %(register)s ' % 60 | {'register': register.str()}))] 61 | 62 | cell = Cell(''.join(contents)) 63 | table.add_cell(cell) 64 | 65 | registers_section.add_component(table) 66 | 67 | return registers_section 68 | 69 | def _create_stack_section(self, context): 70 | section = Section('stack') 71 | section.add_component(DataWidget(context.stack())) 72 | return section 73 | 74 | def _create_code_section(self, context): 75 | section = Section('code') 76 | listing = InstructionListingWidget(context.instruction_listing()) 77 | section.add_component(listing) 78 | return section 79 | 80 | def draw(self, terminal, width): 81 | section = Section('context') 82 | regs = self._create_registers_section(self._previous_context, 83 | self._context) 84 | section.add_component(regs) 85 | 86 | if self._context.stack() is not None and len(self._context.stack()): 87 | stack = self._create_stack_section(self._context) 88 | section.add_component(stack) 89 | 90 | if len(self._context.instruction_listing()): 91 | instructions = self._create_code_section(self._context) 92 | section.add_component(instructions) 93 | 94 | section.draw(terminal, width) 95 | terminal.reset() 96 | 97 | 98 | @register_command 99 | class ContextCommand(StackCommand): 100 | '''Show the current context. 101 | 102 | If the current thread of the inferior is valid the context will be recorded and 103 | dumped. The contents of the context can be controlled using the (void)walker 104 | parameters''' 105 | 106 | @staticmethod 107 | def name(): 108 | return '%s %s' % (VoidwalkerCommand.name(), 'context') 109 | 110 | def __init__(self): 111 | super(ContextCommand, self).__init__() 112 | 113 | def execute(self, config, terminal, thread, platform_factory, argument): 114 | if not thread.is_valid(): 115 | return 116 | 117 | context = platform_factory.create_context(config, thread) 118 | previous_context = context 119 | if len(thread.contexts()): 120 | previous_context = thread.contexts()[-1] 121 | 122 | context_widget = ContextWidget(previous_context, context) 123 | context_widget.draw(terminal, terminal.width()) 124 | -------------------------------------------------------------------------------- /voidwalker/application/commands/dump.py: -------------------------------------------------------------------------------- 1 | # (void)walker command interface 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from flowui.widgets import Section 18 | 19 | from ...framework.interface.command import DataCommand 20 | from ...framework.interface.command import PrefixCommand 21 | from ...framework.interface.command import register_command 22 | from ...framework.types.data import DataChunk 23 | from ...framework.types.data import DataWidget 24 | from ...framework.types.instructions import InstructionListingWidget 25 | 26 | from .voidwalker import VoidwalkerCommand 27 | 28 | 29 | @register_command 30 | class DumpCommand(PrefixCommand): 31 | '''Commands for dumping data''' 32 | 33 | @staticmethod 34 | def name(): 35 | return '%s %s' % (VoidwalkerCommand.name(), 'dump') 36 | 37 | def __init__(self): 38 | super(DumpCommand, self).__init__() 39 | 40 | 41 | @register_command 42 | class DumpDataCommand(DataCommand): 43 | '''Dump data:
44 | 45 | Dumps data starting from the specified address. The output is shown using the 46 | data widget which displays it in hexadecimal and ascii form (when possible).''' 47 | 48 | @staticmethod 49 | def name(): 50 | return '%s %s' % (DumpCommand.name(), 'data') 51 | 52 | def __init__(self): 53 | super(DumpDataCommand, self).__init__() 54 | 55 | def execute(self, terminal, thread, arguments): 56 | if len(arguments) != 2: 57 | terminal.write(('%(face-error)sError:' 58 | '%(face-normal)s invalid arguments!\n')) 59 | return 60 | 61 | address = abs(long(arguments[0])) 62 | size = abs(long(arguments[1])) 63 | 64 | inferior = thread.get_inferior() 65 | data_dump = inferior.read_memory(address, size) 66 | data_chunk = DataChunk(address, data_dump) 67 | 68 | section = Section('0x%016lX' % address) 69 | section.add_component(DataWidget(data_chunk)) 70 | section.draw(terminal, terminal.width()) 71 | 72 | 73 | @register_command 74 | class DumpInstructionsCommand(DataCommand): 75 | '''Dump instructions:
76 | 77 | Dump disassembly starting from the specified address. The output is shown 78 | using the instruction listing widget and perform syntax highlighting on the 79 | output.''' 80 | 81 | @staticmethod 82 | def name(): 83 | return '%s %s' % (DumpCommand.name(), 'instructions') 84 | 85 | def __init__(self): 86 | super(DumpInstructionsCommand, self).__init__() 87 | 88 | def execute(self, terminal, thread, arguments): 89 | if len(arguments) != 2: 90 | terminal.write(('%(face-error)sError:' 91 | '%(face-normal)s invalid arguments!\n')) 92 | return 93 | 94 | address = abs(long(arguments[0])) 95 | size = abs(long(arguments[1])) 96 | 97 | inferior = thread.get_inferior() 98 | listing = inferior.disassemble(address, size) 99 | 100 | section = Section('0x%016lX' % address) 101 | section.add_component(InstructionListingWidget(listing)) 102 | section.draw(terminal, terminal.width()) 103 | -------------------------------------------------------------------------------- /voidwalker/application/commands/voidwalker.py: -------------------------------------------------------------------------------- 1 | # (void)walker command interface 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from ...framework.interface.command import PrefixCommand 18 | from ...framework.interface.command import register_command 19 | 20 | 21 | @register_command 22 | class VoidwalkerCommand(PrefixCommand): 23 | '''(void)walker is a GDB toolbox for low-level software debugging. 24 | 25 | https://github.com/dholm/voidwalker''' 26 | 27 | @staticmethod 28 | def name(): 29 | return 'voidwalker' 30 | 31 | def __init__(self): 32 | super(VoidwalkerCommand, self).__init__() 33 | -------------------------------------------------------------------------------- /voidwalker/application/cpus/__init__.py: -------------------------------------------------------------------------------- 1 | # (void)walker CPU architecture support 2 | # Copyright (C) 2012-2013 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from .generic import GenericCpu 18 | from .mips import MipsCpu 19 | from .x86 import X86Cpu 20 | from .x86_64 import X8664Cpu 21 | 22 | import mips_instructions 23 | import x86_instructions 24 | -------------------------------------------------------------------------------- /voidwalker/application/cpus/generic.py: -------------------------------------------------------------------------------- 1 | # (void)walker CPU architecture support 2 | # Copyright (C) 2013 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from ...framework.platform import Architecture 18 | from ...framework.platform import Cpu 19 | from ...framework.platform import Register 20 | from ...framework.platform import register_cpu 21 | 22 | 23 | @register_cpu 24 | class GenericCpu(Cpu): 25 | def __init__(self, cpu_factory, registers): 26 | for group, register_list in registers.iteritems(): 27 | registers[group] = [Register(x) for x in register_list] 28 | super(GenericCpu, self).__init__(cpu_factory, registers) 29 | 30 | @classmethod 31 | def architecture(cls): 32 | return Architecture.Generic 33 | 34 | def stack_pointer(self): 35 | return self.register('sp') 36 | 37 | def program_counter(self): 38 | return self.register('pc') 39 | -------------------------------------------------------------------------------- /voidwalker/application/cpus/mips.py: -------------------------------------------------------------------------------- 1 | # (void)walker CPU architecture support 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from ...framework.platform import Architecture 18 | from ...framework.platform import Cpu 19 | from ...framework.platform import Register 20 | from ...framework.platform import register_cpu 21 | from ...framework.utils import OrderedDict 22 | 23 | 24 | class CauseRegister(Register): 25 | '''MIPS Cause Register 26 | 27 | BD - Branch delay slot 28 | CE - Coprocessor unit 29 | IP - Interrupt pending 30 | 31 | Exception codes 32 | Int - Interrupt 33 | Mod - TLB modification 34 | TLBL - TLB exception load/instruction fetch 35 | TLBS - TLB exception store 36 | AdEL - Address error load/instruction fetch 37 | AdES - Address error store 38 | IBE - Bus error instruction fetch 39 | DBE - Bus error data reference: load or store 40 | Sys - Syscall 41 | Bp - Breakpoint 42 | RI - Reserved instruction 43 | CpU - Coprocessor unusable 44 | Ov - Arithmetic overflow 45 | Tr - Trap 46 | VCEI - Virtual coherency exception instruction 47 | FPE - Floating-point 48 | WATCH - Reference to WatchHi/WatchLo address 49 | VCED - Virtual coherency exception data''' 50 | 51 | _exception = {0: 'Int', 1: 'Mod', 2: 'TLBL', 3: 'TLBS', 4: 'AdEL', 52 | 5: 'AdES', 6: 'IBE', 7: 'DBE', 8: 'Sys', 9: 'Bp', 53 | 10: 'RI', 11: 'CpU', 12: 'Ov', 13: 'Tr', 14: 'VCEI', 54 | 15: 'FPE', 23: 'WATCH', 31: 'VCED'} 55 | 56 | def __init__(self, name): 57 | super(CauseRegister, self).__init__(name) 58 | 59 | def size(self): 60 | raise NotImplementedError 61 | 62 | def value(self): 63 | raise NotImplementedError 64 | 65 | def str(self): 66 | value = self.value() 67 | cause_list = [] 68 | cause_list.append(self._exception.get((value >> 2) & 0x1f, '')) 69 | for i in range(8, 15): 70 | if value & (1 << i): 71 | cause_list.append('IP%d' % i) 72 | 73 | if value & (1 << 11): 74 | cause_list.append('CE%d' % ((value >> 27) & 3)) 75 | 76 | if value & (1 << 31): 77 | cause_list.append('BD') 78 | 79 | return ' '.join(cause_list) 80 | 81 | 82 | class StatusRegister(Register): 83 | '''MIPS Status Register 84 | 85 | CUx - Coprocessor usability 86 | RP - Reduced-power operation 87 | FR - Additional floating point registers 88 | RE - Reverse-endian 89 | IMx - Interrupt mask 90 | KX - 64-bit addressing in kernel mode 91 | SX - 64-bit addressing and operations in supervisor mode 92 | UX - 64-bit addressing and operations in user mode 93 | ERL - Error level 94 | EXL - Exception level 95 | IE - Interrupt enable 96 | 97 | Diagnostic Status 98 | BEV - Location of TLB refill and general exception vectors 99 | TS - TLB shutdown 100 | SR - Soft reset 101 | CH - Cache hit 102 | CE - ECC register modified on cache hit 103 | DE - Disable ECC exceptions''' 104 | 105 | _flags = {'RP': (1 << 27), 'FR': (1 << 26), 'RE': (1 << 25), 106 | 'KX': (1 << 7), 'SX': (1 << 6), 'UX': (1 << 5), 'EXL': (1 << 1), 107 | 'IE': (1 << 0)} 108 | _ds_flags = {'BEV': (1 << 22), 'TS': (1 << 21), 'SR': (1 << 20), 109 | 'CH': (1 << 18), 'CE': (1 << 17), 'DE': (1 << 16)} 110 | _mode = {2: 'Usr', 1: 'Svi', 0: 'Krn'} 111 | 112 | def __init__(self, name): 113 | super(StatusRegister, self).__init__(name) 114 | 115 | def size(self): 116 | raise NotImplementedError 117 | 118 | def value(self): 119 | raise NotImplementedError 120 | 121 | def str(self): 122 | value = self.value() 123 | status_list = [] 124 | for flag, mask in self._flags.iteritems(): 125 | if value & mask: 126 | status_list.append('%s' % flag) 127 | 128 | ds_list = [] 129 | for flag, mask in self._ds_flags.iteritems(): 130 | if value & mask: 131 | ds_list.append('%s' % flag) 132 | if len(ds_list): 133 | status_list.append('DS[%s]' % ' '.join(ds_list)) 134 | 135 | status_list.append('CU') 136 | for i in range(28, 31): 137 | if value & (1 << i): 138 | status_list.append('%d' % i) 139 | 140 | status_list.append('IM[%02X]' % ((value >> 8) & 0xff)) 141 | status_list.append(self._mode[(value >> 3) & 3]) 142 | 143 | return ' '.join(status_list) 144 | 145 | 146 | @register_cpu 147 | class MipsCpu(Cpu): 148 | _registers = OrderedDict([('gp', ('zero at v0 v1 a0 a1 a2 a3 t0 t1 t2 t3 ' 149 | 't4 t5 t6 t7 s0 s1 s2 s3 s4 s5 s6 s7 ' 150 | 't8 t9 kt0 kt1 gp sp s9 ra').split()), 151 | ('sp', ('lo hi bad pc').split())]) 152 | 153 | def __init__(self, cpu_factory): 154 | registers = OrderedDict() 155 | for group, register_list in self._registers.iteritems(): 156 | registers[group] = [Register(x) for x in register_list] 157 | registers['sp'].append(CauseRegister('cause')) 158 | registers['sp'].append(StatusRegister('sr')) 159 | super(MipsCpu, self).__init__(cpu_factory, registers) 160 | 161 | @classmethod 162 | def architecture(cls): 163 | return Architecture.Mips 164 | 165 | def stack_pointer(self): 166 | return self.register('sp') 167 | 168 | def program_counter(self): 169 | return self.register('pc') 170 | -------------------------------------------------------------------------------- /voidwalker/application/cpus/mips_instructions.py: -------------------------------------------------------------------------------- 1 | # (void)walker MIPS opcodes 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from ...framework.patching.types import Instruction 18 | 19 | 20 | @Instruction.factory 21 | def nop(instruction): 22 | instruction.word(0x00000000) 23 | -------------------------------------------------------------------------------- /voidwalker/application/cpus/x86.py: -------------------------------------------------------------------------------- 1 | # (void)walker CPU architecture support 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from ...framework.platform import Architecture 18 | from ...framework.platform import Cpu 19 | from ...framework.platform import Register 20 | from ...framework.platform import register_cpu 21 | from ...framework.utils import OrderedDict 22 | 23 | 24 | class EflagsRegister(Register): 25 | _flags = OrderedDict([('c', (1 << 0)), ('p', (1 << 2)), ('a', (1 << 4)), 26 | ('z', (1 << 6)), ('s', (1 << 7)), ('t', (1 << 8)), 27 | ('i', (1 << 9)), ('d', (1 << 10)), ('o', (1 << 11)), 28 | 29 | ('nt', (1 << 14)), ('r', (1 << 16)), 30 | ('vm', (1 << 17)), ('ac', (1 << 18)), 31 | ('vi', (1 << 19)), ('vip', (1 << 20)), 32 | ('id', (1 << 21))]) 33 | 34 | def __init__(self, name): 35 | super(EflagsRegister, self).__init__(name) 36 | 37 | def size(self): 38 | raise NotImplementedError 39 | 40 | def value(self): 41 | raise NotImplementedError 42 | 43 | def str(self): 44 | value = self.value() 45 | flag_list = [] 46 | for flag, mask in self._flags.iteritems(): 47 | if value & mask: 48 | flag_list.append('%s ' % flag.upper()) 49 | 50 | return ''.join(flag_list) 51 | 52 | 53 | @register_cpu 54 | class X86Cpu(Cpu): 55 | _registers = OrderedDict([('gp', ('eax ecx edx ebx esp ebp esi ' 56 | 'edi').split()), 57 | ('fp', ('st0 st1 st2 st3 st4 st5 st6 ' 58 | 'st7').split()), 59 | ('sp', ('cs ss ds es fs gs eip').split())]) 60 | 61 | def __init__(self, cpu_factory): 62 | registers = OrderedDict() 63 | for group, register_list in self._registers.iteritems(): 64 | registers[group] = [Register(x) for x in register_list] 65 | registers['sp'].append(EflagsRegister('eflags')) 66 | super(X86Cpu, self).__init__(cpu_factory, registers) 67 | 68 | @classmethod 69 | def architecture(cls): 70 | return Architecture.X86 71 | 72 | def stack_pointer(self): 73 | return self.register('esp') 74 | 75 | def program_counter(self): 76 | return self.register('eip') 77 | -------------------------------------------------------------------------------- /voidwalker/application/cpus/x86_64.py: -------------------------------------------------------------------------------- 1 | # (void)walker CPU architecture support 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from ...framework.platform import Architecture 18 | from ...framework.platform import Cpu 19 | from ...framework.platform import Register 20 | from ...framework.platform import register_cpu 21 | from ...framework.utils import OrderedDict 22 | 23 | from .x86 import EflagsRegister 24 | 25 | 26 | @register_cpu 27 | class X8664Cpu(Cpu): 28 | _registers = OrderedDict([('gp', ('rax rcx rdx rbx rsp rbp rsi rdi r8 r9 ' 29 | 'r10 r11 r12 r13 r14 r15').split()), 30 | ('fp', ('st0 st1 st2 st3 st4 st5 st6 ' 31 | 'st7').split()), 32 | ('sp', ('cs ss ds es fs gs rip').split())]) 33 | 34 | def __init__(self, cpu_factory): 35 | registers = OrderedDict() 36 | for group, register_list in self._registers.iteritems(): 37 | registers[group] = [Register(x) for x in register_list] 38 | registers['sp'].append(EflagsRegister('eflags')) 39 | super(X8664Cpu, self).__init__(cpu_factory, registers) 40 | 41 | @classmethod 42 | def architecture(cls): 43 | return Architecture.X8664 44 | 45 | def stack_pointer(self): 46 | return self.register('rsp') 47 | 48 | def program_counter(self): 49 | return self.register('rip') 50 | -------------------------------------------------------------------------------- /voidwalker/application/cpus/x86_instructions.py: -------------------------------------------------------------------------------- 1 | # (void)walker x86 instructions 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from ...framework.patching.types import Instruction 18 | 19 | 20 | @Instruction.factory 21 | def nop(instruction): 22 | instruction.byte(0x90) 23 | -------------------------------------------------------------------------------- /voidwalker/application/parameters/__init__.py: -------------------------------------------------------------------------------- 1 | # (void)walker configuration parameters 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from .voidwalker import VoidwalkerParameter 18 | from .show import ShowParameter 19 | from .context import ContextParameter 20 | from .context import ContextStackParameter 21 | from .context import ContextInstructionsParameter 22 | -------------------------------------------------------------------------------- /voidwalker/application/parameters/context.py: -------------------------------------------------------------------------------- 1 | # (void)walker configuration parameters 2 | # Copyright (C) 2012-2013 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from ...framework.interface.parameter import PrefixParameter 18 | from ...framework.interface.parameter import IntegerParameter 19 | from ...framework.interface.parameter import register_parameter 20 | 21 | from .voidwalker import VoidwalkerParameter 22 | 23 | 24 | @register_parameter 25 | class ContextParameter(PrefixParameter): 26 | '''(void)walker context command parameters''' 27 | 28 | def __init__(self): 29 | super(ContextParameter, self).__init__() 30 | 31 | def default_value(self): 32 | return None 33 | 34 | @staticmethod 35 | def name(): 36 | return '%s %s' % (VoidwalkerParameter.name(), 'context') 37 | 38 | 39 | @register_parameter 40 | class ContextStackParameter(IntegerParameter): 41 | '''Number of doublewords of stack 42 | 43 | Controls the number of doublewords of stack to include in each context.''' 44 | 45 | DEFAULT_VALUE = 8 46 | 47 | show_doc = 'Number of doublewords of stack to show is set to' 48 | 49 | def __init__(self): 50 | super(ContextStackParameter, self).__init__() 51 | 52 | def default_value(self): 53 | return self.DEFAULT_VALUE 54 | 55 | @staticmethod 56 | def name(): 57 | return '%s %s' % (ContextParameter.name(), 'stackdw') 58 | 59 | 60 | @register_parameter 61 | class ContextInstructionsParameter(IntegerParameter): 62 | '''Number of instructions 63 | 64 | The total number of instructions to include in each context.''' 65 | 66 | DEFAULT_VALUE = 6 67 | 68 | show_doc = 'Number of instructions to show is set to' 69 | 70 | def __init__(self): 71 | super(ContextInstructionsParameter, self).__init__() 72 | 73 | def default_value(self): 74 | return self.DEFAULT_VALUE 75 | 76 | @staticmethod 77 | def name(): 78 | return '%s %s' % (ContextParameter.name(), 'instructions') 79 | -------------------------------------------------------------------------------- /voidwalker/application/parameters/show.py: -------------------------------------------------------------------------------- 1 | # (void)walker configuration parameters 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from ...framework.interface.parameter import PrefixParameter 18 | from ...framework.interface.parameter import register_parameter 19 | 20 | from .voidwalker import VoidwalkerParameter 21 | 22 | 23 | @register_parameter 24 | class ShowParameter(PrefixParameter): 25 | '''(void)walker show parameters''' 26 | 27 | def __init__(self): 28 | super(ShowParameter, self).__init__() 29 | 30 | def default_value(self): 31 | return None 32 | 33 | @staticmethod 34 | def name(): 35 | return '%s %s' % (VoidwalkerParameter.name(), 'show') 36 | -------------------------------------------------------------------------------- /voidwalker/application/parameters/voidwalker.py: -------------------------------------------------------------------------------- 1 | # (void)walker configuration parameters 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from ...framework.interface.parameter import PrefixParameter 18 | from ...framework.interface.parameter import register_parameter 19 | 20 | 21 | @register_parameter 22 | class VoidwalkerParameter(PrefixParameter): 23 | '''(void)walker parameters''' 24 | 25 | def __init__(self): 26 | super(VoidwalkerParameter, self).__init__() 27 | 28 | def init(self): 29 | pass 30 | 31 | def default_value(self): 32 | return None 33 | 34 | @staticmethod 35 | def name(): 36 | return 'voidwalker' 37 | -------------------------------------------------------------------------------- /voidwalker/application/patching/__init__.py: -------------------------------------------------------------------------------- 1 | # (void)walker code patching 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | 18 | from .interface import PatchCommand 19 | from .interface import SnippetCommand 20 | from .interface import SnippetCommandBuilder 21 | from .nop import NopSnippet 22 | -------------------------------------------------------------------------------- /voidwalker/application/patching/interface.py: -------------------------------------------------------------------------------- 1 | # (void)walker code patching interface 2 | # Copyright (C) 2012-2013 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from flowui.widgets import Section 18 | from flowui.widgets.table import Cell 19 | from flowui.widgets.table import Row 20 | from flowui.widgets.table import Table 21 | 22 | from ...framework.interface import PrefixCommand 23 | from ...framework.interface import StackCommand 24 | from ...framework.interface import SupportCommand 25 | from ...framework.interface import register_command 26 | from ...framework.platform import Architecture 27 | 28 | from ..commands.voidwalker import VoidwalkerCommand 29 | 30 | 31 | @register_command 32 | class PatchCommand(PrefixCommand): 33 | '''Commands for patching code''' 34 | 35 | @staticmethod 36 | def name(): 37 | return '%s %s' % (VoidwalkerCommand.name(), 'patch') 38 | 39 | def __init__(self): 40 | super(PatchCommand, self).__init__() 41 | 42 | 43 | @register_command 44 | class SnippetCommand(PrefixCommand): 45 | '''Predefined snippets for patching''' 46 | 47 | @staticmethod 48 | def name(): 49 | return '%s %s' % (PatchCommand.name(), 'snippet') 50 | 51 | def __init__(self): 52 | super(SnippetCommand, self).__init__() 53 | 54 | 55 | class SnippetCommandBuilder(object): 56 | def __init__(self, snippet_repository): 57 | @register_command 58 | class ListSnippetsCommand(SupportCommand): 59 | '''List all the available snippets''' 60 | 61 | @staticmethod 62 | def name(): 63 | return '%s %s' % (SnippetCommand.name(), 'list') 64 | 65 | def __init__(self): 66 | super(ListSnippetsCommand, self).__init__() 67 | 68 | def execute(self, terminal, *_): 69 | table = Table() 70 | for name, snippet in snippet_repository.snippets(): 71 | row = Row() 72 | row.add_cell(Cell('%s%s' % ('%(face-identifier)s', name))) 73 | row.add_cell(Cell('%s%s' % ('%(face-comment)s', 74 | snippet.description()))) 75 | table.add_row(row) 76 | 77 | section = Section('snippets') 78 | section.add_component(table) 79 | section.draw(terminal, terminal.width()) 80 | 81 | @register_command 82 | class ApplySnippetCommand(StackCommand): 83 | '''Apply a snippet:
84 | 85 | Apply the specified snippet at the specified address. This operation will 86 | overwrite whatever is at that location in memory. The original binary is never 87 | touched by this command.''' 88 | 89 | @staticmethod 90 | def name(): 91 | return '%s %s' % (SnippetCommand.name(), 'apply') 92 | 93 | def __init__(self): 94 | super(ApplySnippetCommand, self).__init__() 95 | 96 | def execute(self, config, terminal, thread, platform_factory, 97 | argument): 98 | if len(argument) < 2: 99 | terminal.write('%(face-error)s' 100 | 'Wrong number of arguments!\n') 101 | return 102 | 103 | inferior = thread.get_inferior() 104 | snippet = snippet_repository.snippet(argument[0]) 105 | if snippet is None: 106 | terminal.write(' '.join(['%(face-error)sSnippet', 107 | argument[0], 108 | '%s does not exist!\n'])) 109 | return 110 | 111 | architecture = inferior.cpu().architecture() 112 | implementation = None 113 | if ((architecture == Architecture.X8664 and 114 | architecture not in snippet.architectures())): 115 | assert Architecture.X86 in snippet.architectures() 116 | implementation = snippet.implementation(Architecture.X86) 117 | 118 | else: 119 | implementation = snippet.implementation(architecture) 120 | 121 | address = abs(long(argument[1])) 122 | code = implementation.assemble() 123 | inferior.write_memory(code, address) 124 | 125 | terminal.write('Applied snippet %s%s%s at %s0x%x\n' % 126 | ('%(face-identifier)s', argument[0], 127 | '%(face-normal)s', '%(face-constant)s', 128 | address)) 129 | -------------------------------------------------------------------------------- /voidwalker/application/patching/nop.py: -------------------------------------------------------------------------------- 1 | # (void)walker nop snippets 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from ...framework.patching.composer import CodeBlock 18 | from ...framework.patching.snippet import Snippet 19 | from ...framework.patching.snippet import register_snippet 20 | from ...framework.platform.cpu import Architecture 21 | 22 | from ..cpus import mips_instructions as mips 23 | from ..cpus import x86_instructions as x86 24 | 25 | 26 | @register_snippet 27 | class NopSnippet(Snippet): 28 | _code = {Architecture.X86: CodeBlock(x86.nop()), 29 | Architecture.Mips: CodeBlock(mips.nop())} 30 | 31 | def __init__(self): 32 | pass 33 | 34 | def architectures(self): 35 | return NopSnippet._code.iterkeys() 36 | 37 | def len(self, architecture): 38 | code = self.implementation(architecture) 39 | return len(code) 40 | 41 | def implementation(self, architecture): 42 | assert architecture in NopSnippet._code.iterkeys() 43 | return NopSnippet._code[architecture] 44 | 45 | @staticmethod 46 | def description(): 47 | return ('No-operations are used to overwrite instructions that ' 48 | 'shouldn\'t be executed') 49 | 50 | @staticmethod 51 | def name(): 52 | return 'nop' 53 | -------------------------------------------------------------------------------- /voidwalker/backends/__init__.py: -------------------------------------------------------------------------------- 1 | # (void)walker backends 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | -------------------------------------------------------------------------------- /voidwalker/backends/gdb/__init__.py: -------------------------------------------------------------------------------- 1 | # (void)walker GDB backend 2 | # Copyright (C) 2012-2013 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from .target import GdbInferiorFactory 18 | from .target import GdbThreadFactory 19 | from .terminal import GdbTerminal 20 | from .parameter import GdbParameterFactory 21 | from .command import GdbCommandFactory 22 | from .platform import GdbCpuFactory 23 | from .platform import GdbPlatformFactory 24 | from .hooks import HookParameter 25 | from .hooks import ContextHookParameter 26 | from .hooks import VoidwalkerHookStop 27 | 28 | import tools 29 | -------------------------------------------------------------------------------- /voidwalker/backends/gdb/command.py: -------------------------------------------------------------------------------- 1 | # (void)walker GDB backend 2 | # Copyright (C) 2012-2013 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | import gdb 18 | 19 | from functools import partial 20 | 21 | from ...framework.interface import BreakpointCommand 22 | from ...framework.interface import Command 23 | from ...framework.interface import CommandFactory 24 | from ...framework.interface import DataCommand 25 | from ...framework.interface import PrefixCommand 26 | from ...framework.interface import StackCommand 27 | from ...framework.interface import SupportCommand 28 | 29 | 30 | def get_current_inferior(inferior_repository, inferior_factory): 31 | inferior_num = gdb.selected_inferior().num 32 | if not inferior_repository.has_inferior(inferior_num): 33 | inferior = inferior_factory.create_inferior(inferior_num) 34 | inferior_repository.add_inferior(inferior) 35 | 36 | return inferior_repository.get_inferior(inferior_num) 37 | 38 | 39 | def get_current_thread(inferior_repository, inferior_factory, 40 | thread_factory): 41 | if gdb.selected_thread() is not None: 42 | thread_num = gdb.selected_thread().num 43 | 44 | inferior = get_current_inferior(inferior_repository, inferior_factory) 45 | if not inferior.has_thread(thread_num): 46 | thread_factory.create_thread(inferior, thread_num) 47 | 48 | if inferior.has_thread(thread_num): 49 | return inferior.thread(thread_num) 50 | 51 | return None 52 | 53 | 54 | def parse_argument_list(argument): 55 | args = [] 56 | for obj in gdb.string_to_argv(argument): 57 | try: 58 | obj = gdb.parse_and_eval('%s' % obj) 59 | except gdb.error: 60 | pass 61 | 62 | args.append(obj) 63 | return args 64 | 65 | 66 | class GdbCommandFactory(CommandFactory, object): 67 | def create_data_command(self, command_type, terminal, inferior_repo, 68 | inferior_factory, thread_factory): 69 | class GdbDataCommand(gdb.Command, command_type): 70 | __doc__ = command_type.__doc__ 71 | 72 | def __init__(self): 73 | command_type.__init__(self) 74 | gdb.Command.__init__(self, command_type.name(), 75 | gdb.COMMAND_DATA, gdb.COMPLETE_NONE) 76 | 77 | def invoke(self, argument, _): 78 | thread = get_current_thread(inferior_repo, inferior_factory, 79 | thread_factory) 80 | if thread is not None: 81 | args = parse_argument_list(argument) 82 | command_type.execute(self, terminal, thread, args) 83 | 84 | return GdbDataCommand() 85 | 86 | def create_stack_command(self, command_type, config, terminal, 87 | inferior_repo, platform_factory, inferior_factory, 88 | thread_factory): 89 | class GdbStackCommand(gdb.Command, command_type): 90 | __doc__ = command_type.__doc__ 91 | 92 | def __init__(self): 93 | command_type.__init__(self) 94 | gdb.Command.__init__(self, command_type.name(), 95 | gdb.COMMAND_STACK, gdb.COMPLETE_NONE) 96 | 97 | def invoke(self, argument, _): 98 | thread = get_current_thread(inferior_repo, inferior_factory, 99 | thread_factory) 100 | if thread is not None: 101 | args = parse_argument_list(argument) 102 | command_type.execute(self, config, terminal, thread, 103 | platform_factory, args) 104 | 105 | return GdbStackCommand() 106 | 107 | def create_prefix_command(self, command_type, _): 108 | class GdbPrefixCommand(gdb.Command, command_type): 109 | __doc__ = command_type.__doc__ 110 | 111 | def __init__(self): 112 | command_type.__init__(self) 113 | gdb.Command.__init__(self, command_type.name(), 114 | gdb.COMMAND_USER, 115 | gdb.COMPLETE_COMMAND, True) 116 | 117 | return GdbPrefixCommand() 118 | 119 | def create_support_command(self, command_type, terminal): 120 | class GdbSupportCommand(gdb.Command, command_type): 121 | __doc__ = command_type.__doc__ 122 | 123 | def __init__(self): 124 | command_type.__init__(self) 125 | gdb.Command.__init__(self, command_type.name(), 126 | gdb.COMMAND_SUPPORT, 127 | gdb.COMPLETE_NONE, True) 128 | 129 | def invoke(self, argument, _): 130 | args = parse_argument_list(argument) 131 | command_type.execute(self, terminal, args) 132 | 133 | return GdbSupportCommand() 134 | 135 | def create_brkp_command(self, command_type, terminal, inferior_repo): 136 | class GdbBreakpointCommand(gdb.Command, command_type): 137 | def __init__(self): 138 | command_type.__init__(self) 139 | gdb.Command.__init__(self, command_type.name(), 140 | gdb.COMMAND_BREAKPOINTS, 141 | gdb.COMPLETE_NONE) 142 | 143 | def invoke(self, argument, _): 144 | inferior = get_current_inferior(inferior_repo) 145 | if inferior is not None: 146 | args = parse_argument_list(argument) 147 | command_type.execute(self, terminal, inferior, args) 148 | 149 | return GdbBreakpointCommand() 150 | 151 | def create_generic_command(self, command_type): 152 | class GdbCommand(gdb.Command, command_type): 153 | __doc__ = command_type.__doc__ 154 | 155 | def __init__(self): 156 | command_type.__init__(self) 157 | gdb.Command.__init__(self, command_type.name(), 158 | gdb.COMMAND_USER, 159 | gdb.COMPLETE_COMMAND) 160 | 161 | return GdbCommand() 162 | 163 | def create(self, command_type, inferior_repository, platform_factory, 164 | inferior_factory, thread_factory, config, terminal): 165 | create_method = [(DataCommand, partial(self.create_data_command, 166 | command_type, terminal, 167 | inferior_repository, 168 | inferior_factory, 169 | thread_factory)), 170 | (StackCommand, partial(self.create_stack_command, 171 | command_type, config, terminal, 172 | inferior_repository, 173 | platform_factory, 174 | inferior_factory, 175 | thread_factory)), 176 | (PrefixCommand, partial(self.create_prefix_command, 177 | command_type, terminal)), 178 | (SupportCommand, partial(self.create_support_command, 179 | command_type, terminal)), 180 | (BreakpointCommand, partial(self.create_brkp_command, 181 | command_type, terminal, 182 | inferior_repository)), 183 | (Command, partial(self.create_generic_command, 184 | command_type))] 185 | for ctype, create in create_method: 186 | if issubclass(command_type, ctype): 187 | return create() 188 | else: 189 | raise TypeError('Command %s of type %s unknown!' % 190 | (command_type.name(), repr(command_type))) 191 | -------------------------------------------------------------------------------- /voidwalker/backends/gdb/event.py: -------------------------------------------------------------------------------- 1 | # (void)walker GDB backend 2 | # Copyright (C) 2013 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | import gdb 18 | 19 | from ...framework.system.event import EventQueue 20 | 21 | 22 | class GdbEventQueue(EventQueue): 23 | def __init__(self): 24 | super(GdbEventQueue, self).__init__() 25 | 26 | def onEnqueue(self): 27 | gdb.post_event(self) 28 | 29 | def __call__(self): 30 | if bool(self): 31 | event = self.dequeue() 32 | event() 33 | -------------------------------------------------------------------------------- /voidwalker/backends/gdb/hooks.py: -------------------------------------------------------------------------------- 1 | # (void)walker GDB backend 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | import gdb 18 | 19 | from ...framework.interface.command import StackCommand 20 | from ...framework.interface.command import register_command 21 | from ...framework.interface.parameter import BooleanParameter 22 | from ...framework.interface.parameter import PrefixParameter 23 | from ...framework.interface.parameter import register_parameter 24 | 25 | from ...application.commands.context import ContextCommand 26 | from ...application.commands.voidwalker import VoidwalkerCommand 27 | from ...application.parameters.voidwalker import VoidwalkerParameter 28 | 29 | 30 | @register_parameter 31 | class HookParameter(PrefixParameter): 32 | '''(void)walker hook parameters''' 33 | 34 | def __init__(self): 35 | super(HookParameter, self).__init__() 36 | 37 | def default_value(self): 38 | return None 39 | 40 | @staticmethod 41 | def name(): 42 | return '%s %s' % (VoidwalkerParameter.name(), 'hook') 43 | 44 | 45 | @register_parameter 46 | class ContextHookParameter(BooleanParameter): 47 | '''Dump context when relevant hooks are called''' 48 | 49 | DEFAULT_VALUE = True 50 | 51 | def __init__(self): 52 | super(ContextHookParameter, self).__init__() 53 | 54 | @staticmethod 55 | def name(): 56 | return '%s %s' % (HookParameter.name(), 'context') 57 | 58 | def default_value(self): 59 | return self.DEFAULT_VALUE 60 | 61 | 62 | @register_command 63 | class VoidwalkerHookStop(StackCommand): 64 | '''This command should be called from GDB hook-stop. 65 | 66 | To support all features of (void)walker this command must be called from GDB's 67 | hook-stop command. If you haven't defined hook-stop simply add the following 68 | to your ~/.gdbinit: 69 | 70 | define hook-stop 71 | voidwalker hook-stop 72 | end''' 73 | 74 | def __init__(self): 75 | super(VoidwalkerHookStop, self).__init__() 76 | self._terminal = None 77 | 78 | @staticmethod 79 | def name(): 80 | return '%s %s' % (VoidwalkerCommand.name(), 'hook-stop') 81 | 82 | def execute(self, config, *_): 83 | context_hook_name = ContextHookParameter.name() 84 | if config.parameter(context_hook_name).value(): 85 | gdb.execute(ContextCommand.name()) 86 | -------------------------------------------------------------------------------- /voidwalker/backends/gdb/parameter.py: -------------------------------------------------------------------------------- 1 | # (void)walker GDB backend 2 | # Copyright (C) 2012-2013 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | import gdb 18 | 19 | from ...framework.interface.parameter import BooleanParameter 20 | from ...framework.interface.parameter import EnumParameter 21 | from ...framework.interface.parameter import IntegerParameter 22 | from ...framework.interface.parameter import Parameter 23 | from ...framework.interface.parameter import PrefixParameter 24 | 25 | 26 | class GdbBaseParameter(gdb.Parameter, object): 27 | def __init__(self, name, command, param, sequence=None): 28 | if param == gdb.PARAM_ENUM: 29 | gdb.Parameter.__init__(self, name, command, param, sequence) 30 | else: 31 | gdb.Parameter.__init__(self, name, command, param) 32 | 33 | def get_value(self): 34 | return self.value 35 | 36 | def get_set_string(self): 37 | return str(self.value) 38 | 39 | def get_show_string(self, value): 40 | return value 41 | 42 | 43 | class GdbParameterFactory(object): 44 | def create_enum_parameter(self, parameter_type): 45 | class GdbParameterEnum(GdbBaseParameter, parameter_type): 46 | __doc__ = parameter_type.__doc__ 47 | show_doc = __doc__ 48 | set_doc = __doc__ 49 | 50 | def __init__(self): 51 | parameter_type.__init__(self) 52 | gdb_name = parameter_type.name().replace(' ', '-') 53 | GdbBaseParameter.__init__(self, gdb_name, 54 | gdb.COMMAND_SUPPORT, 55 | gdb.PARAM_ENUM, 56 | parameter_type.sequence(self)) 57 | self.value = parameter_type.default_value(self) 58 | 59 | return GdbParameterEnum() 60 | 61 | def create_integer_parameter(self, parameter_type): 62 | class GdbParameterInteger(GdbBaseParameter, parameter_type): 63 | __doc__ = parameter_type.__doc__ 64 | show_doc = __doc__ 65 | set_doc = __doc__ 66 | 67 | def __init__(self): 68 | parameter_type.__init__(self) 69 | gdb_name = parameter_type.name().replace(' ', '-') 70 | GdbBaseParameter.__init__(self, gdb_name, 71 | gdb.COMMAND_SUPPORT, 72 | gdb.PARAM_ZINTEGER) 73 | self.value = parameter_type.default_value(self) 74 | 75 | return GdbParameterInteger() 76 | 77 | def create_boolean_parameter(self, parameter_type): 78 | class GdbParameterBoolean(GdbBaseParameter, parameter_type): 79 | __doc__ = parameter_type.__doc__ 80 | show_doc = __doc__ 81 | set_doc = __doc__ 82 | 83 | def __init__(self): 84 | parameter_type.__init__(self) 85 | gdb_name = parameter_type.name().replace(' ', '-') 86 | GdbBaseParameter.__init__(self, gdb_name, 87 | gdb.COMMAND_SUPPORT, 88 | gdb.PARAM_BOOLEAN) 89 | self.value = parameter_type.default_value(self) 90 | 91 | return GdbParameterBoolean() 92 | 93 | def create_generic_parameter(self, parameter_type): 94 | class GdbParameter(parameter_type): 95 | __doc__ = parameter_type.__doc__ 96 | 97 | def __init__(self): 98 | parameter_type.__init__(self) 99 | 100 | return GdbParameter() 101 | 102 | def create(self, parameter_type): 103 | create_method = [(EnumParameter, self.create_enum_parameter), 104 | (IntegerParameter, self.create_integer_parameter), 105 | (BooleanParameter, self.create_boolean_parameter), 106 | (PrefixParameter, self.create_generic_parameter), 107 | (Parameter, self.create_generic_parameter)] 108 | for ptype, create in create_method: 109 | if issubclass(parameter_type, ptype): 110 | return create(parameter_type) 111 | 112 | else: 113 | raise TypeError('Parameter %s of type %s unknown!' % 114 | parameter_type.name(), str(type(parameter_type))) 115 | -------------------------------------------------------------------------------- /voidwalker/backends/gdb/platform.py: -------------------------------------------------------------------------------- 1 | # (void)walker GDB backend 2 | # Copyright (C) 2012-2013 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | import gdb 18 | import re 19 | 20 | from ...framework.platform import Context 21 | from ...framework.platform import CpuFactory 22 | from ...framework.platform import PlatformFactory 23 | from ...framework.platform import create_static_register 24 | from ...framework.types import DataChunk 25 | from ...framework.utils import OrderedDict 26 | 27 | from ...application.parameters.context import ContextInstructionsParameter 28 | from ...application.parameters.context import ContextStackParameter 29 | 30 | 31 | class GdbCpuFactory(CpuFactory, object): 32 | def create_register(self, cpu, register): 33 | class GdbRegister(type(register), object): 34 | _value_exp = re.compile(r'(?P.+)\s*=\s*(?P.+)') 35 | 36 | def __init__(self, name): 37 | super(GdbRegister, self).__init__(name) 38 | 39 | def size(self): 40 | size = gdb.parse_and_eval('sizeof($%s)' % register.name()) 41 | try: 42 | return int(size) 43 | except gdb.error: 44 | return None 45 | 46 | def value(self): 47 | try: 48 | result = gdb.execute('p /x $%s' % register.name(), 49 | to_string=True) 50 | match = self._value_exp.search(result) 51 | 52 | return abs(long(match.group('value'), 16)) 53 | except ValueError: 54 | return None 55 | except gdb.error: 56 | return None 57 | 58 | return GdbRegister(register.name()) 59 | 60 | 61 | class GdbPlatformFactory(PlatformFactory, object): 62 | def create_context(self, config, thread): 63 | stackdws = config.parameter(ContextStackParameter.name()).value() 64 | instrs_name = ContextInstructionsParameter.name() 65 | instructions = config.parameter(instrs_name).value() 66 | inferior = thread.get_inferior() 67 | 68 | class GdbContext(Context): 69 | def _update_registers(self): 70 | for group, register_dict in inferior.cpu().registers(): 71 | tuples = [(x.name(), create_static_register(x)) 72 | for x in register_dict.itervalues()] 73 | register_dict = OrderedDict(tuples) 74 | self._registers[group] = register_dict 75 | 76 | def _update_stack(self): 77 | size = stackdws * 0x8 78 | address = inferior.cpu().stack_pointer().value() & ~0xf 79 | stack = inferior.read_memory(address, size) 80 | self._stack = DataChunk(address, stack) 81 | 82 | def _update_instructions(self): 83 | address = inferior.cpu().program_counter().value() 84 | length = instructions 85 | listing = inferior.disassemble(address, length) 86 | self._instruction_listing = listing 87 | 88 | def __init__(self): 89 | cpu = inferior.cpu() 90 | program_counter = cpu.program_counter().name() 91 | super(GdbContext, self).__init__(program_counter) 92 | 93 | self._update_registers() 94 | self._update_stack() 95 | self._update_instructions() 96 | 97 | return GdbContext() 98 | -------------------------------------------------------------------------------- /voidwalker/backends/gdb/target.py: -------------------------------------------------------------------------------- 1 | # (void)walker GDB backend 2 | # Copyright (C) 2012-2013 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | import gdb 18 | import os.path 19 | import re 20 | 21 | from ...application.cpus.generic import GenericCpu 22 | from ...framework.platform import Architecture 23 | from ...framework.target.inferior import Inferior 24 | from ...framework.target.inferior import InferiorFactory 25 | from ...framework.target.thread import Thread 26 | from ...framework.target.thread import ThreadFactory 27 | from ...framework.types.instructions import Instruction 28 | from ...framework.types.instructions import InstructionListing 29 | from ...framework.utils import OrderedDict 30 | 31 | 32 | class GdbThread(Thread): 33 | def __init__(self, inferior, gdb_thread): 34 | super(GdbThread, self).__init__(inferior) 35 | self._gdb_thread = gdb_thread 36 | 37 | def name(self): 38 | return self._gdb_thread.name 39 | 40 | def id(self): 41 | return self._gdb_thread.num 42 | 43 | def is_valid(self): 44 | return self._gdb_thread.is_valid() 45 | 46 | 47 | class GdbInferior(Inferior): 48 | _instruction_exp = re.compile((r'(?P\S+)?\s*' 49 | r'(?P
0x[0-9a-f]+){1}\s*' 50 | r'(?:<(?P.+)>){0,1}:\s*' 51 | r'(?P\S+){1}\s*' 52 | r'(?P.+)?$'), 53 | re.IGNORECASE) 54 | 55 | def __init__(self, cpu, gdb_inferior): 56 | super(GdbInferior, self).__init__(cpu) 57 | self._gdb_inferior = gdb_inferior 58 | 59 | def id(self): 60 | return self._gdb_inferior.num 61 | 62 | def gdb_inferior(self): 63 | return self._gdb_inferior 64 | 65 | def disassemble(self, address, length): 66 | result = gdb.execute(('x /%di 0x%x' % (length + 1, address)), 67 | to_string=True) 68 | parsed = [] 69 | for line in result.split('\n'): 70 | line = line.replace('%', '%%') 71 | instruction = self._instruction_exp.search(line) 72 | if instruction: 73 | parsed.append(instruction.groupdict()) 74 | 75 | listing = InstructionListing() 76 | for i in range(len(parsed) - 1): 77 | size = (long(parsed[i + 1]['address'], 16) - 78 | long(parsed[i]['address'], 16)) 79 | address = long(parsed[i]['address'], 16) 80 | data = self.read_memory(address, size) 81 | 82 | symbol = parsed[i]['symbol'] 83 | mnemonic = parsed[i]['mnemonic'] 84 | operands = parsed[i]['operands'] 85 | instruction = Instruction(data, mnemonic, operands, symbol) 86 | listing.add_instruction(address, instruction) 87 | 88 | return listing 89 | 90 | def read_memory(self, address, length): 91 | return self._gdb_inferior.read_memory(address, length) 92 | 93 | def write_memory(self, buf, address): 94 | self._gdb_inferior.write_memory(address, buf) 95 | 96 | 97 | class GdbInferiorFactory(InferiorFactory, object): 98 | _file_expression = re.compile((r'`(?P[^\']+)\', ' 99 | r'file type (?P\S+).')) 100 | _inferior_expression = re.compile((r'(?P\d+)\s+' 101 | r'(?P\S+ \S*)\s+' 102 | r'(?P.+)$')) 103 | 104 | def __init__(self, cpu_factory): 105 | super(GdbInferiorFactory, self).__init__(cpu_factory) 106 | 107 | @classmethod 108 | def _target_to_architecture(cls, target): 109 | if re.match(r'.*-x86-64', target): 110 | return Architecture.X8664 111 | if re.match(r'.*-i386', target): 112 | return Architecture.X86 113 | if re.match(r'.*-.*mips[^-]*', target): 114 | return Architecture.Mips 115 | if re.match(r'.*-arm[^-]*', target): 116 | return Architecture.Arm 117 | return None 118 | 119 | def _registers(self): 120 | info_registers = gdb.execute('info registers', False, True) 121 | registers = OrderedDict([('gp', []), ('sp', ('sp pc').split())]) 122 | for line in info_registers.split('\n'): 123 | words = line.split() 124 | if not len(words) or words[0] in registers['sp']: 125 | continue 126 | registers['gp'].append(words[0]) 127 | 128 | return registers 129 | 130 | def create_inferior(self, inferior_id): 131 | gdb_inferior = None 132 | try: 133 | gdb_inferior = (i for i in gdb.inferiors() 134 | if i.num == inferior_id).next() 135 | except StopIteration: 136 | return None 137 | 138 | cpu = None 139 | info_inferiors = gdb.execute('info inferiors', False, True) 140 | info_target = gdb.execute('info target', False, True) 141 | try: 142 | matches = self._inferior_expression.findall(info_inferiors) 143 | inferior = (i for i in matches if int(i[0]) == inferior_id).next() 144 | 145 | inferior_path = os.path.abspath(inferior[2]).strip() 146 | matches = self._file_expression.findall(info_target) 147 | try: 148 | target = (i[1] for i in matches 149 | if os.path.abspath(i[0]).strip() == 150 | inferior_path).next() 151 | 152 | architecture = self._target_to_architecture(target) 153 | cpu = self._cpu_factory.create_cpu(architecture) 154 | 155 | except StopIteration: 156 | registers = self._registers() 157 | cpu = GenericCpu(self._cpu_factory, registers) 158 | 159 | except TypeError: 160 | return None 161 | 162 | return GdbInferior(cpu, gdb_inferior) 163 | 164 | 165 | class GdbThreadFactory(ThreadFactory, object): 166 | def create_thread(self, inferior, thread_id): 167 | gdb_thread = None 168 | try: 169 | gdb_thread = (i for i in inferior.gdb_inferior().threads() 170 | if i.num == thread_id).next() 171 | thread = GdbThread(inferior, gdb_thread) 172 | inferior.add_thread(thread) 173 | return thread 174 | 175 | except StopIteration: 176 | pass 177 | 178 | return None 179 | -------------------------------------------------------------------------------- /voidwalker/backends/gdb/terminal.py: -------------------------------------------------------------------------------- 1 | # (void)walker GDB backend 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | import gdb 18 | 19 | from flowui import Terminal 20 | from flowui.terminals import SysTerminal 21 | 22 | 23 | class GdbTerminal(Terminal): 24 | def reset(self): 25 | pass 26 | 27 | def __init__(self): 28 | width = gdb.parameter('width') 29 | height = gdb.parameter('height') 30 | 31 | sys_terminal = SysTerminal() 32 | depth = sys_terminal.depth() 33 | if not width: 34 | width = sys_terminal.width() 35 | if not height: 36 | height = sys_terminal.height() 37 | 38 | super(GdbTerminal, self).__init__(width, height, depth) 39 | 40 | def write(self, string, dictionary=None): 41 | if dictionary is not None: 42 | string = string.format(dictionary) 43 | gdb.write(string) 44 | -------------------------------------------------------------------------------- /voidwalker/backends/gdb/tools/__init__.py: -------------------------------------------------------------------------------- 1 | # (void)walker GDB-specific features 2 | # Copyright (C) 2012-2013 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from .interface import GdbCommand 18 | from .breakpoints import BreakCommand 19 | from .breakpoints import BreakTextCommand 20 | -------------------------------------------------------------------------------- /voidwalker/backends/gdb/tools/breakpoints.py: -------------------------------------------------------------------------------- 1 | # (void)walker GDB breakpoint control 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | import gdb 18 | import re 19 | 20 | from ....framework.interface.command import BreakpointCommand 21 | from ....framework.interface.command import PrefixCommand 22 | from ....framework.interface.command import register_command 23 | 24 | from .interface import GdbCommand 25 | 26 | 27 | @register_command 28 | class BreakCommand(PrefixCommand): 29 | '''Commands for GDB breakpoints''' 30 | 31 | @staticmethod 32 | def name(): 33 | return '%s %s' % (GdbCommand.name(), 'break') 34 | 35 | def __init__(self): 36 | super(BreakCommand, self).__init__() 37 | 38 | 39 | @register_command 40 | class BreakTextCommand(BreakpointCommand): 41 | '''Break on text section entry point 42 | 43 | Sets a breakpoint at the text section entrypoint. This command is useful if 44 | there are no symbols and no known address to set a breakpoint at.''' 45 | 46 | _text_exp = re.compile(r'(?P0x[0-9a-z]+)\s*-\s*(?P0x[0-9a-z]+)' 47 | r'\s+is\s+(?P
[^\s]+)', re.IGNORECASE) 48 | 49 | @staticmethod 50 | def name(): 51 | return '%s %s' % (BreakCommand.name(), 'text') 52 | 53 | def __init__(self): 54 | super(BreakTextCommand, self).__init__() 55 | self._terminal = None 56 | 57 | def invoke(self, thread, argument, from_tty=False): 58 | sections = gdb.execute('info target', to_string=True) 59 | address = None 60 | for match in self._text_exp.finditer(sections): 61 | if match.group('section') == '.text': 62 | address = abs(long(match.group('start'), 16)) 63 | break 64 | 65 | if address is not None: 66 | gdb.Breakpoint('*0x%x' % address) 67 | else: 68 | raise gdb.error('Unable to locate .text section!') 69 | -------------------------------------------------------------------------------- /voidwalker/backends/gdb/tools/interface.py: -------------------------------------------------------------------------------- 1 | # (void)walker GDB-specific interface 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from ....framework.interface.command import PrefixCommand 18 | from ....framework.interface.command import register_command 19 | 20 | from ....application.commands.voidwalker import VoidwalkerCommand 21 | 22 | 23 | @register_command 24 | class GdbCommand(PrefixCommand): 25 | '''Commands for interacting with GDB''' 26 | 27 | @staticmethod 28 | def name(): 29 | return '%s %s' % (VoidwalkerCommand.name(), 'gdb') 30 | 31 | def __init__(self): 32 | super(GdbCommand, self).__init__() 33 | -------------------------------------------------------------------------------- /voidwalker/backends/test/__init__.py: -------------------------------------------------------------------------------- 1 | # (void)walker unit test backend 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from .platform import TestCpu 18 | from .platform import TestCpuFactory 19 | from .platform import TestPlatformFactory 20 | from .target import TestThread 21 | from .target import TestThreadFactory 22 | from .target import TestInferior 23 | from .target import TestInferiorFactory 24 | 25 | from .interface import TestCommandFactory 26 | from .interface import TestParameterFactory 27 | -------------------------------------------------------------------------------- /voidwalker/backends/test/interface.py: -------------------------------------------------------------------------------- 1 | # (void)walker unit test backend 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from ...framework.interface import BooleanParameter 18 | from ...framework.interface import Command 19 | from ...framework.interface import CommandFactory 20 | from ...framework.interface import DataCommand 21 | from ...framework.interface import EnumParameter 22 | from ...framework.interface import Parameter 23 | from ...framework.interface import ParameterFactory 24 | 25 | from .target import TestInferior 26 | from .target import TestThread 27 | 28 | 29 | class TestCommandFactory(CommandFactory, object): 30 | def create(self, command_type, inferior_repository, platform_factory, 31 | inferior_factory, thread_factory, config, terminal): 32 | if issubclass(command_type, DataCommand): 33 | class TestDataCommand(command_type): 34 | __doc__ = command_type.__doc__ 35 | 36 | def __init__(self): 37 | command_type.__init__(self) 38 | 39 | def invoke(self, argument, _): 40 | inferior = TestInferior() 41 | thread = TestThread(inferior.id(), 0) 42 | command_type.execute(self, terminal, thread, argument) 43 | 44 | return TestDataCommand() 45 | 46 | if issubclass(command_type, Command): 47 | class TestCommand(command_type): 48 | __doc__ = command_type.__doc__ 49 | 50 | def __init__(self): 51 | command_type.__init__(self) 52 | 53 | def invoke(self, argument, _): 54 | command_type.execute(self, terminal, argument) 55 | 56 | return TestCommand() 57 | 58 | else: 59 | raise TypeError('Command type %s unknown!' % 60 | str(command_type)) 61 | 62 | 63 | class TestParameterFactory(ParameterFactory, object): 64 | def create(self, parameter_type): 65 | if issubclass(parameter_type, EnumParameter): 66 | class TestParameterEnum(parameter_type): 67 | def __init__(self): 68 | parameter_type.__init__(self) 69 | self.value = parameter_type.default_value(self) 70 | 71 | return TestParameterEnum() 72 | 73 | elif issubclass(parameter_type, BooleanParameter): 74 | class TestParameterBoolean(parameter_type): 75 | def __init__(self): 76 | parameter_type.__init__(self) 77 | self.value = parameter_type.default_value(self) 78 | 79 | return TestParameterBoolean() 80 | 81 | elif issubclass(parameter_type, Parameter): 82 | class TestParameter(parameter_type): 83 | def __init__(self): 84 | parameter_type.__init__(self) 85 | 86 | return TestParameter() 87 | 88 | else: 89 | raise TypeError('Parameter type %s unknown!' % 90 | str(type(parameter_type))) 91 | -------------------------------------------------------------------------------- /voidwalker/backends/test/platform.py: -------------------------------------------------------------------------------- 1 | # (void)walker platform test implementation 2 | # Copyright (C) 2013 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from ...framework.platform import Architecture 18 | from ...framework.platform import Context 19 | from ...framework.platform import Cpu 20 | from ...framework.platform import CpuFactory 21 | from ...framework.platform import PlatformFactory 22 | from ...framework.platform import Register 23 | from ...framework.platform import create_static_register 24 | from ...framework.platform import register_cpu 25 | from ...framework.utils import OrderedDict 26 | 27 | 28 | @register_cpu 29 | class TestCpu(Cpu): 30 | register_dict = OrderedDict([('gp', ('r0 r1').split()), 31 | ('sp', ('pc sp flags').split())]) 32 | 33 | def __init__(self, cpu_factory): 34 | registers = OrderedDict() 35 | for group, register_list in self.register_dict.items(): 36 | registers[group] = [Register(x) for x in register_list] 37 | super(TestCpu, self).__init__(cpu_factory, registers) 38 | 39 | @classmethod 40 | def architecture(cls): 41 | return Architecture.Test 42 | 43 | def stack_pointer(self): 44 | return self.register('sp') 45 | 46 | def program_counter(self): 47 | return self.register('pc') 48 | 49 | 50 | class TestCpuFactory(CpuFactory): 51 | def __init__(self): 52 | self._registers = None 53 | 54 | def create_cpu(self, architecture): 55 | return TestCpu(self) 56 | 57 | def create_register(self, cpu, register): 58 | class TestRegister(type(register), object): 59 | def __init__(self, name): 60 | super(TestRegister, self).__init__(name) 61 | self._size = 8 62 | self._value = 0 63 | 64 | def size(self): 65 | return self._size 66 | 67 | def value(self): 68 | return self._value 69 | 70 | return TestRegister(register.name()) 71 | 72 | 73 | class TestPlatformFactory(PlatformFactory, object): 74 | def __init__(self): 75 | self._registers = None 76 | self.reset() 77 | 78 | def reset(self): 79 | self._registers = {} 80 | 81 | def create_context(self, config, inferior, thread): 82 | class TestContext(Context): 83 | def __init__(self): 84 | sp = inferior.cpu().stack_pointer() 85 | super(TestContext, self).__init__(sp) 86 | 87 | for group, register_dict in inferior.cpu().registers(): 88 | register_dict = dict((x.name(), create_static_register(x)) 89 | for x in register_dict.itervalues()) 90 | self._registers[group] = register_dict 91 | 92 | return TestContext() 93 | -------------------------------------------------------------------------------- /voidwalker/backends/test/target.py: -------------------------------------------------------------------------------- 1 | # (void)walker unit test backend 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from ...framework.target import Inferior 18 | from ...framework.target import InferiorFactory 19 | from ...framework.target import Thread 20 | from ...framework.target import ThreadFactory 21 | 22 | from .platform import TestCpu 23 | from .platform import TestCpuFactory 24 | 25 | 26 | class TestInferior(Inferior): 27 | def __init__(self, cpu, inferior_id): 28 | super(TestInferior, self).__init__(cpu) 29 | self._id = inferior_id 30 | 31 | def id(self): 32 | return self._id 33 | 34 | def disassemble(self, address, length): 35 | return None 36 | 37 | def read_memory(self, address, length): 38 | return None 39 | 40 | def write_memory(self, buf, address): 41 | return None 42 | 43 | 44 | class TestInferiorFactory(InferiorFactory): 45 | def __init__(self): 46 | super(TestInferiorFactory, self).__init__(TestCpuFactory()) 47 | 48 | def create_inferior(self, cpu, inferior_id): 49 | return TestInferior(cpu, inferior_id) 50 | 51 | def create_thread(self, inferior, thread_id): 52 | thread = TestThread(inferior.id(), thread_id) 53 | inferior.add_thread(thread) 54 | return thread 55 | 56 | 57 | class TestThread(Thread): 58 | def __init__(self, inferior, thread_id): 59 | super(TestThread, self).__init__(inferior) 60 | self._thread_id = thread_id 61 | 62 | def name(self): 63 | return ('thread %d' % self._thread_id) 64 | 65 | def id(self): 66 | return self._thread_id 67 | 68 | def is_valid(self): 69 | return True 70 | 71 | 72 | class TestThreadFactory(ThreadFactory): 73 | def create_thread(self, inferior, thread_id): 74 | thread = TestThread(inferior, thread_id) 75 | inferior.add_thread(thread) 76 | return thread 77 | -------------------------------------------------------------------------------- /voidwalker/framework/__init__.py: -------------------------------------------------------------------------------- 1 | # (void)walker framework 2 | # Copyright (C) 2012-2013 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from . import utils 18 | from . import target 19 | from . import interface 20 | from . import platform 21 | from . import patching 22 | -------------------------------------------------------------------------------- /voidwalker/framework/interface/__init__.py: -------------------------------------------------------------------------------- 1 | # (void)walker command line interface 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from .command import BreakpointCommand 18 | from .command import Command 19 | from .command import CommandBuilder 20 | from .command import CommandFactory 21 | from .command import DataCommand 22 | from .command import PrefixCommand 23 | from .command import StackCommand 24 | from .command import SupportCommand 25 | from .command import register_command 26 | 27 | from .parameter import Parameter 28 | from .parameter import PrefixParameter 29 | from .parameter import BooleanParameter 30 | from .parameter import EnumParameter 31 | from .parameter import IntegerParameter 32 | from .parameter import ParameterFactory 33 | from .parameter import ParameterBuilder 34 | from .parameter import register_parameter 35 | 36 | from .config import Configuration 37 | -------------------------------------------------------------------------------- /voidwalker/framework/interface/command.py: -------------------------------------------------------------------------------- 1 | # (void)walker command line interface 2 | # Copyright (C) 2012-2013 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | import abc 18 | 19 | 20 | class Command(object): 21 | pass 22 | 23 | 24 | class PrefixCommand(Command): 25 | def execute(self, terminal): 26 | terminal.write('%(face-error)sAttempting to invoke an ' 27 | 'incomplete command!\n') 28 | 29 | 30 | class DataCommand(Command): 31 | __metaclass__ = abc.ABCMeta 32 | 33 | @abc.abstractmethod 34 | def execute(self, terminal, thread, argument): 35 | raise NotImplementedError 36 | 37 | 38 | class StackCommand(Command): 39 | __metaclass__ = abc.ABCMeta 40 | 41 | @abc.abstractmethod 42 | def execute(self, config, terminal, thread, platform_factory, argument): 43 | raise NotImplementedError 44 | 45 | 46 | class BreakpointCommand(Command): 47 | __metaclass__ = abc.ABCMeta 48 | 49 | @abc.abstractmethod 50 | def execute(self, terminal, inferior, argument): 51 | raise NotImplementedError 52 | 53 | 54 | class SupportCommand(Command): 55 | __metaclass__ = abc.ABCMeta 56 | 57 | @abc.abstractmethod 58 | def execute(self, terminal, argument): 59 | raise NotImplementedError 60 | 61 | 62 | class CommandFactory(object): 63 | __metaclass__ = abc.ABCMeta 64 | 65 | @abc.abstractmethod 66 | def create(self, command_type, inferior_repository, platform_factory, 67 | inferior_factory, thread_factory, config, terminal): 68 | raise NotImplementedError 69 | 70 | 71 | class CommandBuilder(object): 72 | def __init__(self, command_factory, inferior_repository, platform_factory, 73 | inferior_factory, thread_factory, config, terminal): 74 | self.commands = {} 75 | for Cmd in _command_list: 76 | cmd = command_factory.create(Cmd, inferior_repository, 77 | platform_factory, inferior_factory, 78 | thread_factory, config, terminal) 79 | self.commands[Cmd.name()] = cmd 80 | 81 | 82 | def register_command(cls): 83 | _command_list.append(cls) 84 | return cls 85 | 86 | _command_list = [] 87 | -------------------------------------------------------------------------------- /voidwalker/framework/interface/config.py: -------------------------------------------------------------------------------- 1 | # (void)walker configuration interface 2 | # Copyright (C) 2013 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | 18 | class ConfigurationNode(object): 19 | def __init__(self, parameter=None): 20 | self._children = {} 21 | self._parameter = parameter 22 | 23 | def __contains__(self, name): 24 | return name in self._children 25 | 26 | def __repr__(self): 27 | s = [] 28 | if self._parameter is not None: 29 | s += [self._parameter.name(), ': '] 30 | s.append('{') 31 | for child in self._children.values(): 32 | s += [repr(child), ', '] 33 | s.append('}') 34 | return ''.join(s) 35 | 36 | def append(self, parameter): 37 | assert parameter.name() not in self._children 38 | node = ConfigurationNode(parameter) 39 | name = parameter.name().split(' ')[-1] 40 | self._children[name] = node 41 | 42 | def value(self): 43 | return self._parameter.get_value() 44 | 45 | def get(self, name): 46 | assert name in self._children 47 | return self._children[name] 48 | 49 | 50 | class Configuration(object): 51 | def __init__(self): 52 | self._root = ConfigurationNode() 53 | 54 | def _get_parent(self, path): 55 | node = self._root 56 | for tag in path.split(' ')[:-1]: 57 | node = node.get(tag) 58 | return node 59 | 60 | def register_parameter(self, parameter): 61 | parent = self._get_parent(parameter.name()) 62 | parent.append(parameter) 63 | 64 | def parameter(self, path): 65 | node = self._root 66 | for tag in path.split(' '): 67 | if tag not in node: 68 | raise KeyError('Parameter %s not found!' % path) 69 | node = node.get(tag) 70 | return node 71 | 72 | def __repr__(self): 73 | return repr(self._root) 74 | 75 | -------------------------------------------------------------------------------- /voidwalker/framework/interface/parameter.py: -------------------------------------------------------------------------------- 1 | # (void)walker command line interface 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | import abc 18 | 19 | 20 | class Parameter(object): 21 | __metaclass__ = abc.ABCMeta 22 | 23 | def init(self): 24 | pass 25 | 26 | @staticmethod 27 | def name(): 28 | raise NotImplementedError 29 | 30 | @abc.abstractmethod 31 | def default_value(self): 32 | raise NotImplementedError 33 | 34 | 35 | class PrefixParameter(Parameter): 36 | __metaclass__ = abc.ABCMeta 37 | 38 | @classmethod 39 | def get_value(cls): 40 | raise TypeError 41 | 42 | @abc.abstractmethod 43 | def default_value(self): 44 | raise NotImplementedError 45 | 46 | 47 | class BooleanParameter(Parameter): 48 | __metaclass__ = abc.ABCMeta 49 | 50 | @abc.abstractmethod 51 | def default_value(self): 52 | raise NotImplementedError 53 | 54 | 55 | class EnumParameter(Parameter): 56 | __metaclass__ = abc.ABCMeta 57 | 58 | @abc.abstractmethod 59 | def sequence(self): 60 | raise NotImplementedError 61 | 62 | 63 | class IntegerParameter(Parameter): 64 | __metaclass__ = abc.ABCMeta 65 | 66 | @abc.abstractmethod 67 | def default_value(self): 68 | raise NotImplementedError 69 | 70 | 71 | class ParameterFactory(object): 72 | __metaclass__ = abc.ABCMeta 73 | 74 | @abc.abstractmethod 75 | def create(self, parameter_type): 76 | raise NotImplementedError 77 | 78 | 79 | class ParameterBuilder(object): 80 | def __init__(self, factory, config): 81 | for Param in _parameter_list: 82 | param = factory.create(Param) 83 | param.init() 84 | config.register_parameter(param) 85 | 86 | 87 | def register_parameter(cls): 88 | _parameter_list.append(cls) 89 | return cls 90 | 91 | _parameter_list = [] 92 | -------------------------------------------------------------------------------- /voidwalker/framework/patching/__init__.py: -------------------------------------------------------------------------------- 1 | # (void)walker support for patching 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from .snippet import Snippet 18 | from .snippet import SnippetRepository 19 | from .snippet import register_snippet 20 | from .composer import CodeBlock 21 | from .types import ByteStream 22 | from .types import Instruction 23 | -------------------------------------------------------------------------------- /voidwalker/framework/patching/composer.py: -------------------------------------------------------------------------------- 1 | # (void)walker assembler composer 2 | # Based on Pyasm by Florian Boesch, https://bitbucket.org/pyalot/pyasm/ 3 | # Copyright (C) 2012 David Holm 4 | 5 | # This program is free software; you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation; either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU General Public License 16 | # along with this program. If not, see . 17 | 18 | from .types import ByteStream 19 | 20 | 21 | class CodeBlock(object): 22 | def __init__(self, *instructions): 23 | self._instructions = list(instructions) 24 | 25 | def __len__(self): 26 | return len(self._instructions) 27 | 28 | def hex(self): 29 | stream = ByteStream() 30 | (x.assemble(stream) for x in self._instructions).next() 31 | return ' '.join('%02x' % ord(x) 32 | for x in stream.buffer()) 33 | 34 | def assemble(self): 35 | stream = ByteStream() 36 | (x.assemble(stream) for x in self._instructions).next() 37 | return stream.buffer() 38 | -------------------------------------------------------------------------------- /voidwalker/framework/patching/snippet.py: -------------------------------------------------------------------------------- 1 | # (void)walker code snippet support 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | 18 | class SnippetRepository(object): 19 | def snippet(self, name): 20 | assert name in _snippet_map 21 | return _snippet_map[name] 22 | 23 | def snippets(self): 24 | return _snippet_map.items() 25 | 26 | 27 | def register_snippet(cls): 28 | _snippet_map[cls.name()] = cls() 29 | return cls 30 | 31 | _snippet_map = {} 32 | 33 | 34 | class Snippet(object): 35 | def architectures(self): 36 | raise NotImplementedError 37 | 38 | def implementation(self, architecture): 39 | raise NotImplementedError 40 | 41 | @staticmethod 42 | def description(): 43 | raise NotImplementedError 44 | 45 | @staticmethod 46 | def name(): 47 | raise NotImplementedError 48 | -------------------------------------------------------------------------------- /voidwalker/framework/patching/types.py: -------------------------------------------------------------------------------- 1 | # (void)walker assembler types 2 | # Copyright (C) 2012 David Holm 3 | # 4 | # Based on Pyasm by Florian Boesch, https://bitbucket.org/pyalot/pyasm/ 5 | 6 | # This program is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 3 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU General Public License 17 | # along with this program. If not, see . 18 | 19 | import struct 20 | 21 | 22 | class ByteStream(object): 23 | def __init__(self): 24 | self._buffer = bytes() 25 | 26 | def buffer(self): 27 | return self._buffer 28 | 29 | def byte(self, value): 30 | self._buffer += struct.pack('B', value) 31 | 32 | def halfword(self, value): 33 | self._buffer += struct.pack('H', value) 34 | 35 | def word(self, value): 36 | self._buffer += struct.pack('I', value) 37 | 38 | def doubleword(self, value): 39 | self._buffer += struct.pack('Q', value) 40 | 41 | 42 | class Instruction(object): 43 | def __init__(self, function, *args, **kwargs): 44 | self._function = function 45 | self._name = function.__name__ 46 | self._args = args 47 | self._kwargs = kwargs 48 | 49 | def __str__(self): 50 | return '%s %s' % (self._name, ', '.join([str(x) for x in self._args])) 51 | 52 | def assemble(self, stream): 53 | self._function(stream, *self._args, **self._kwargs) 54 | return stream 55 | 56 | @classmethod 57 | def factory(cls, function): 58 | def builder(*args, **kwargs): 59 | instruction = cls(function, *args, **kwargs) 60 | return instruction 61 | return builder 62 | -------------------------------------------------------------------------------- /voidwalker/framework/platform/__init__.py: -------------------------------------------------------------------------------- 1 | # (void)walker hardware platform support 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from .cpu import Architecture 18 | from .cpu import Cpu 19 | from .cpu import CpuFactory 20 | from .cpu import CpuRepository 21 | from .cpu import Register 22 | from .cpu import create_static_register 23 | from .cpu import register_cpu 24 | 25 | from .context import Context 26 | 27 | from .factory import PlatformFactory 28 | -------------------------------------------------------------------------------- /voidwalker/framework/platform/context.py: -------------------------------------------------------------------------------- 1 | # (void)walker hardware platform support 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from ..types.instructions import InstructionListing 18 | from ..utils import OrderedDict 19 | 20 | 21 | class Context(object): 22 | def __init__(self, program_counter): 23 | self._registers = OrderedDict() 24 | self._stack = None 25 | self._instruction_listing = InstructionListing() 26 | 27 | self._program_counter = program_counter 28 | 29 | def stack(self): 30 | return self._stack 31 | 32 | def register(self, name): 33 | for register_dict in self._registers.itervalues(): 34 | if name in register_dict: 35 | return register_dict[name] 36 | 37 | return None 38 | 39 | def registers(self): 40 | return self._registers.iteritems() 41 | 42 | def instruction_listing(self): 43 | return self._instruction_listing 44 | 45 | def program_counter(self): 46 | return self.register(self._program_counter) 47 | -------------------------------------------------------------------------------- /voidwalker/framework/platform/cpu.py: -------------------------------------------------------------------------------- 1 | # (void)walker hardware platform support 2 | # Copyright (C) 2012-2013 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | import abc 18 | 19 | from ..utils import OrderedDict 20 | from ..utils import enum 21 | 22 | 23 | Architecture = enum('Test', 'X86', 'X8664', 'Mips', 'Arm', 'Generic', 24 | enum_type='Architecture') 25 | 26 | 27 | class Register(object): 28 | _register_fmt = {16: '0x%032lX', 29 | 10: '0x%020lX', 30 | 8: '0x%016lX', 31 | 4: '0x%08lX', 32 | 2: '0x%04lX', 33 | 1: '0x%02lX'} 34 | 35 | def __init__(self, name): 36 | self._name = name 37 | 38 | def name(self): 39 | return self._name 40 | 41 | def size(self): 42 | raise NotImplementedError 43 | 44 | def value(self): 45 | raise NotImplementedError 46 | 47 | def str(self): 48 | if self.value() is not None: 49 | return self._register_fmt[self.size()] % self.value() 50 | chars_per_byte = 2 51 | return ''.join(['-' * (self.size() * chars_per_byte)]) 52 | 53 | 54 | def create_static_register(register): 55 | class StaticRegister(type(register), object): 56 | def __init__(self, name): 57 | super(StaticRegister, self).__init__(name) 58 | self._size = register.size() 59 | self._value = register.value() 60 | 61 | def size(self): 62 | return self._size 63 | 64 | def value(self): 65 | return self._value 66 | 67 | return StaticRegister(register.name()) 68 | 69 | 70 | class Cpu(object): 71 | __metaclass__ = abc.ABCMeta 72 | 73 | def __init__(self, cpu_factory, registers): 74 | self._registers = OrderedDict() 75 | for group, register_list in registers.iteritems(): 76 | registers = OrderedDict([(x.name(), 77 | cpu_factory.create_register(self, x)) 78 | for x in register_list]) 79 | 80 | self._registers[group] = registers 81 | 82 | @classmethod 83 | @abc.abstractmethod 84 | def architecture(cls): 85 | raise NotImplementedError 86 | 87 | def register(self, name): 88 | for register_dict in self._registers.itervalues(): 89 | if name in register_dict: 90 | return register_dict[name] 91 | 92 | return None 93 | 94 | def registers(self): 95 | return self._registers.iteritems() 96 | 97 | @abc.abstractmethod 98 | def stack_pointer(self): 99 | raise NotImplementedError 100 | 101 | @abc.abstractmethod 102 | def program_counter(self): 103 | raise NotImplementedError 104 | 105 | 106 | class CpuFactory(object): 107 | __metaclass__ = abc.ABCMeta 108 | 109 | def create_cpu(self, architecture): 110 | assert architecture in _cpu_map 111 | return _cpu_map.get(architecture, 112 | None)(self) 113 | 114 | @abc.abstractmethod 115 | def create_register(self, cpu, register): 116 | raise NotImplementedError 117 | 118 | 119 | class CpuRepository(object): 120 | def __init__(self, cpu_factory): 121 | self._cpu_factory = cpu_factory 122 | self._cpus = {} 123 | 124 | def get_cpu(self, architecture): 125 | if architecture in self._cpus: 126 | return self._cpus[architecture] 127 | cpu = self._cpu_factory.create_cpu(architecture) 128 | self._cpus[architecture] = cpu 129 | return cpu 130 | 131 | 132 | def register_cpu(cls): 133 | _cpu_map[cls.architecture()] = cls 134 | return cls 135 | 136 | _cpu_map = {} 137 | -------------------------------------------------------------------------------- /voidwalker/framework/platform/factory.py: -------------------------------------------------------------------------------- 1 | # (void)walker hardware platform support 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | import abc 18 | 19 | 20 | class PlatformFactory(object): 21 | __metaclass__ = abc.ABCMeta 22 | 23 | @abc.abstractmethod 24 | def create_context(self, config, thread): 25 | raise NotImplementedError 26 | -------------------------------------------------------------------------------- /voidwalker/framework/system/__init__.py: -------------------------------------------------------------------------------- 1 | # (void)walker system backend 2 | # Copyright (C) 2013 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from . import event 18 | -------------------------------------------------------------------------------- /voidwalker/framework/system/event.py: -------------------------------------------------------------------------------- 1 | # (void)walker event processing 2 | # Copyright (C) 2013 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from collections import deque 18 | 19 | 20 | class Event(object): 21 | def __init__(self, *args, **kwargs): 22 | self._args = args 23 | self._kwargs = kwargs 24 | 25 | def eval(self, *args, **kwargs): 26 | raise NotImplementedError() 27 | 28 | def __call__(self): 29 | self.eval(*self._args, **self._kwargs) 30 | 31 | 32 | class EventQueue(object): 33 | def __init__(self): 34 | self._queue = deque() 35 | 36 | def __nonzero__(self): 37 | return bool(self._queue) 38 | 39 | def onEnqueue(self): 40 | raise NotImplementedError() 41 | 42 | def enqueue(self, event): 43 | self._queue.append(event) 44 | self.onEnqueue() 45 | 46 | def dequeue(self): 47 | return self._queue.pop() 48 | -------------------------------------------------------------------------------- /voidwalker/framework/target/__init__.py: -------------------------------------------------------------------------------- 1 | # (void)walker target support 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from .inferior import Inferior 18 | from .inferior import InferiorFactory 19 | from .inferior import InferiorRepository 20 | from .thread import Thread 21 | from .thread import ThreadFactory 22 | -------------------------------------------------------------------------------- /voidwalker/framework/target/inferior.py: -------------------------------------------------------------------------------- 1 | # (void)walker target support 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | import abc 18 | 19 | 20 | class Inferior(object): 21 | __metaclass__ = abc.ABCMeta 22 | 23 | def __init__(self, cpu): 24 | self._cpu = cpu 25 | self._threads = {} 26 | 27 | @abc.abstractmethod 28 | def id(self): 29 | raise NotImplementedError 30 | 31 | def cpu(self): 32 | return self._cpu 33 | 34 | def has_thread(self, thread_id): 35 | return thread_id in self._threads 36 | 37 | def add_thread(self, thread): 38 | self._threads[thread.id()] = thread 39 | 40 | def thread(self, thread_id): 41 | assert self.has_thread(thread_id) 42 | return self._threads[thread_id] 43 | 44 | @abc.abstractmethod 45 | def disassemble(self, address, length): 46 | raise NotImplementedError 47 | 48 | @abc.abstractmethod 49 | def read_memory(self, address, length): 50 | raise NotImplementedError 51 | 52 | @abc.abstractmethod 53 | def write_memory(self, buf, address): 54 | raise NotImplementedError 55 | 56 | 57 | class InferiorFactory(object): 58 | __metaclass__ = abc.ABCMeta 59 | 60 | def __init__(self, cpu_factory): 61 | self._cpu_factory = cpu_factory 62 | 63 | @abc.abstractmethod 64 | def create_inferior(self, inferior_id): 65 | raise NotImplementedError 66 | 67 | 68 | class InferiorRepository(object): 69 | def __init__(self): 70 | self._inferiors = {} 71 | 72 | def add_inferior(self, inferior): 73 | self._inferiors[inferior.id()] = inferior 74 | 75 | def has_inferior(self, inferior_id): 76 | return inferior_id in self._inferiors 77 | 78 | def get_inferior(self, inferior_id): 79 | assert self.has_inferior(inferior_id), ('inferior %r not found' % 80 | inferior_id) 81 | return self._inferiors[inferior_id] 82 | -------------------------------------------------------------------------------- /voidwalker/framework/target/thread.py: -------------------------------------------------------------------------------- 1 | # (void)walker target support 2 | # Copyright (C) 2012-2013 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | import abc 18 | 19 | from collections import deque 20 | 21 | 22 | class Thread(object): 23 | __metaclass__ = abc.ABCMeta 24 | 25 | def __init__(self, inferior): 26 | self._inferior = inferior 27 | self._contexts = deque() 28 | 29 | def get_inferior(self): 30 | return self._inferior 31 | 32 | def contexts(self): 33 | return self._contexts 34 | 35 | @abc.abstractmethod 36 | def name(self): 37 | raise NotImplementedError 38 | 39 | @abc.abstractmethod 40 | def id(self): 41 | raise NotImplementedError 42 | 43 | @abc.abstractmethod 44 | def is_valid(self): 45 | raise NotImplementedError 46 | 47 | 48 | class ThreadFactory(object): 49 | __metaclass__ = abc.ABCMeta 50 | 51 | @abc.abstractmethod 52 | def create_thread(self, inferior, thread_id): 53 | raise NotImplementedError 54 | -------------------------------------------------------------------------------- /voidwalker/framework/types/__init__.py: -------------------------------------------------------------------------------- 1 | # (void)walker basic types 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from .data import DataChunk 18 | from .data import DataWidget 19 | 20 | from .instructions import Instruction 21 | from .instructions import InstructionListing 22 | from .instructions import InstructionListingWidget 23 | -------------------------------------------------------------------------------- /voidwalker/framework/types/data.py: -------------------------------------------------------------------------------- 1 | # (void)walker basic types 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | import string 18 | 19 | from flowui import Widget 20 | from flowui.widgets.table import Cell 21 | from flowui.widgets.table import Row 22 | from flowui.widgets.table import Table 23 | 24 | from ..utils.recipes import grouper 25 | 26 | 27 | class DataChunk(object): 28 | def __init__(self, address, data_buffer): 29 | self._address = address 30 | self._buffer = data_buffer 31 | 32 | def __len__(self): 33 | return len(self._buffer) 34 | 35 | def address(self): 36 | return self._address 37 | 38 | def buffer(self): 39 | return self._buffer 40 | 41 | 42 | class DataWidget(Widget): 43 | _ascii_filter = ''.join([['.', chr(x)] 44 | [chr(x) in string.printable[:-5]] 45 | for x in xrange(256)]) 46 | 47 | def __init__(self, data_chunk): 48 | super(DataWidget, self).__init__() 49 | self._data_chunk = data_chunk 50 | 51 | def draw(self, terminal, width): 52 | table = Table() 53 | 54 | line_len = 16 55 | if width < 100: 56 | line_len = 8 57 | 58 | address = self._data_chunk.address() 59 | for line in grouper(line_len, self._data_chunk.buffer()): 60 | hex_string = [] 61 | ascii_string = [] 62 | for octuple in grouper(8, line): 63 | for quadruple in grouper(4, octuple): 64 | hex_string += [(' %02X' % ord(i)) 65 | for i in quadruple 66 | if i is not None] 67 | filtered = ''.join([x.translate(self._ascii_filter) 68 | for x in quadruple 69 | if x is not None]) 70 | ascii_string += filtered.replace('%', '%%') 71 | 72 | hex_string += [' '] 73 | ascii_string += [' '] 74 | 75 | row = Row() 76 | row.add_cell(Cell('0x%016X:' % address)) 77 | row.add_cell(Cell(''.join(hex_string))) 78 | row.add_cell(Cell(''.join(ascii_string))) 79 | table.add_row(row) 80 | 81 | address += line_len 82 | 83 | table.draw(terminal, width) 84 | -------------------------------------------------------------------------------- /voidwalker/framework/types/instructions.py: -------------------------------------------------------------------------------- 1 | # (void)walker basic types 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | import re 18 | 19 | from flowui import Widget 20 | from flowui.widgets.table import Cell 21 | from flowui.widgets.table import Row 22 | from flowui.widgets.table import Table 23 | 24 | from ..utils import OrderedDict 25 | 26 | 27 | class Instruction(object): 28 | def __init__(self, opcode, mnemonic, operands, symbol=None): 29 | self._opcode = opcode 30 | self._mnemonic = mnemonic 31 | self._operands = operands 32 | self._symbol = symbol 33 | 34 | def opcode(self): 35 | return self._opcode 36 | 37 | def mnemonic(self): 38 | return self._mnemonic 39 | 40 | def operands(self): 41 | return self._operands 42 | 43 | def symbol(self): 44 | return self._symbol 45 | 46 | 47 | class InstructionListing(object): 48 | def __init__(self): 49 | self._instructions = OrderedDict() 50 | 51 | def __len__(self): 52 | return len(self._instructions) 53 | 54 | def instructions(self): 55 | return self._instructions.iteritems() 56 | 57 | def add_instruction(self, address, instruction): 58 | self._instructions[address] = instruction 59 | 60 | 61 | class InstructionListingWidget(Widget): 62 | _operands_scanner = re.Scanner([ 63 | (r'[\$-]?0[xX]([0-9A-Fa-f]+)', 64 | lambda scanner, token:('CONSTANT', token)), 65 | (r'[\$-]?\d+h?', lambda scanner, token:('CONSTANT', token)), 66 | (r'%*[A-Za-z_][A-Za-z0-9_]*', 67 | lambda scanner, token:('IDENTIFIER', token)), 68 | (r'<[^>]+>', 69 | lambda scanner, token:('SYMBOL', token)), 70 | (r'[,]+', lambda scanner, token:('PUNCTUATION', token)), 71 | (r'[-+*:$\(\)]', lambda scanner, token:('OPERAND', token)), 72 | (r'#.*$', lambda scanner, token:('COMMENT', token)), 73 | (r'\s+', lambda scanner, token:('WHITESPACE', token))]) 74 | _operands_face = {'CONSTANT': '%(face-constant)s', 75 | 'IDENTIFIER': '%(face-identifier)s', 76 | 'SYMBOL': '%(face-type)s', 77 | 'PUNCTUATION': '', 78 | 'OPERAND': '', 79 | 'COMMENT': '%(face-comment)s', 80 | 'WHITESPACE': ''} 81 | 82 | def __init__(self, instruction_listing, program_counter=None): 83 | self._instruction_listing = instruction_listing 84 | self._program_counter = program_counter 85 | 86 | def _fmt_operands(self, operands): 87 | operands_list = [] 88 | parsed, remainder = self._operands_scanner.scan(operands) 89 | for token in parsed: 90 | face = self._operands_face.get(token[0], '') 91 | operands_list.append(face) 92 | operands_list.append(token[1]) 93 | if len(face): 94 | operands_list.append('%(face-normal)s') 95 | 96 | return ''.join(operands_list + [remainder]) 97 | 98 | def draw(self, terminal, width): 99 | table = Table() 100 | for address, instruction in self._instruction_listing.instructions(): 101 | row = Row() 102 | 103 | const_face = '%(face-normal)s' 104 | if address == self._program_counter: 105 | const_face = '%(face-underlined)s' 106 | row.add_cell(Cell('%s0x%016lX:' % (const_face, address))) 107 | 108 | if instruction.symbol() is not None: 109 | identifier = ['%(face-identifier)s', instruction.symbol(), ':'] 110 | row.add_cell(Cell(''.join(identifier))) 111 | else: 112 | row.add_cell(Cell()) 113 | 114 | hex_string = [('%02X' % ord(i)) 115 | for i in instruction.opcode() 116 | if i is not None] 117 | row.add_cell(Cell('%s%s' % (const_face, ' '.join(hex_string)))) 118 | 119 | row.add_cell(Cell('%s%s' % ('%(face-statement)s', 120 | instruction.mnemonic()))) 121 | 122 | if instruction.operands() is not None: 123 | operands = self._fmt_operands(instruction.operands()) 124 | row.add_cell(Cell(operands)) 125 | else: 126 | row.add_cell(Cell()) 127 | 128 | table.add_row(row) 129 | 130 | table.draw(terminal, width) 131 | -------------------------------------------------------------------------------- /voidwalker/framework/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # (void)walker utility library 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from .enum import enum 18 | from .ordereddict import OrderedDict 19 | from .recipes import grouper 20 | -------------------------------------------------------------------------------- /voidwalker/framework/utils/enum.py: -------------------------------------------------------------------------------- 1 | # (void)walker enumerator support 2 | # Copyright (C) 2013 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | 18 | def enum(*sequential, **named): 19 | enums = dict(zip(sequential, range(len(sequential))), **named) 20 | reverse = dict((value, key) for key, value in enums.items()) 21 | enums['reverse_mapping'] = reverse 22 | return type(named.get('enum_type', 'Enum'), (), enums) 23 | 24 | -------------------------------------------------------------------------------- /voidwalker/framework/utils/ordereddict.py: -------------------------------------------------------------------------------- 1 | ## {{{ http://code.activestate.com/recipes/576693/ (r9) 2 | # Backport of OrderedDict() class that runs on Python 2.4, 2.5, 2.6, 2.7 and 3 | # pypy. 4 | # Passes Python2.7's test suite and incorporates all the latest updates. 5 | 6 | try: 7 | from thread import get_ident as _get_ident 8 | except ImportError: 9 | from dummy_thread import get_ident as _get_ident 10 | 11 | try: 12 | from _abcoll import KeysView, ValuesView, ItemsView 13 | except ImportError: 14 | pass 15 | 16 | 17 | class OrderedDict(dict): 18 | 'Dictionary that remembers insertion order' 19 | # An inherited dict maps keys to values. 20 | # The inherited dict provides __getitem__, __len__, __contains__, and get. 21 | # The remaining methods are order-aware. 22 | # Big-O running times for all methods are the same as for regular 23 | # dictionaries. 24 | 25 | # The internal self.__map dictionary maps keys to links in a doubly linked 26 | # list. 27 | # The circular doubly linked list starts and ends with a sentinel element. 28 | # The sentinel element never gets deleted (this simplifies the algorithm). 29 | # Each link is stored as a list of length three: [PREV, NEXT, KEY]. 30 | 31 | def __init__(self, *args, **kwds): 32 | '''Initialize an ordered dictionary. Signature is the same as for 33 | regular dictionaries, but keyword arguments are not recommended 34 | because their insertion order is arbitrary. 35 | 36 | ''' 37 | if len(args) > 1: 38 | raise TypeError('expected at most 1 arguments, got %d' % len(args)) 39 | try: 40 | self.__root 41 | except AttributeError: 42 | self.__root = root = [] # sentinel node 43 | root[:] = [root, root, None] 44 | self.__map = {} 45 | self.__update(*args, **kwds) 46 | 47 | def __setitem__(self, key, value, dict_setitem=dict.__setitem__): 48 | 'od.__setitem__(i, y) <==> od[i]=y' 49 | # Setting a new item creates a new link which goes at the end of the 50 | # linked list, and the inherited dictionary is updated with the new 51 | # key/value pair. 52 | if key not in self: 53 | root = self.__root 54 | last = root[0] 55 | last[1] = root[0] = self.__map[key] = [last, root, key] 56 | dict_setitem(self, key, value) 57 | 58 | def __delitem__(self, key, dict_delitem=dict.__delitem__): 59 | 'od.__delitem__(y) <==> del od[y]' 60 | # Deleting an existing item uses self.__map to find the link which is 61 | # then removed by updating the links in the predecessor and successor 62 | # nodes. 63 | dict_delitem(self, key) 64 | link_prev, link_next, key = self.__map.pop(key) 65 | link_prev[1] = link_next 66 | link_next[0] = link_prev 67 | 68 | def __iter__(self): 69 | 'od.__iter__() <==> iter(od)' 70 | root = self.__root 71 | curr = root[1] 72 | while curr is not root: 73 | yield curr[2] 74 | curr = curr[1] 75 | 76 | def __reversed__(self): 77 | 'od.__reversed__() <==> reversed(od)' 78 | root = self.__root 79 | curr = root[0] 80 | while curr is not root: 81 | yield curr[2] 82 | curr = curr[0] 83 | 84 | def clear(self): 85 | 'od.clear() -> None. Remove all items from od.' 86 | try: 87 | for node in self.__map.itervalues(): 88 | del node[:] 89 | root = self.__root 90 | root[:] = [root, root, None] 91 | self.__map.clear() 92 | except AttributeError: 93 | pass 94 | dict.clear(self) 95 | 96 | def popitem(self, last=True): 97 | '''od.popitem() -> (k, v), return and remove a (key, value) pair. 98 | Pairs are returned in LIFO order if last is true or FIFO order if 99 | false. 100 | 101 | ''' 102 | if not self: 103 | raise KeyError('dictionary is empty') 104 | root = self.__root 105 | if last: 106 | link = root[0] 107 | link_prev = link[0] 108 | link_prev[1] = root 109 | root[0] = link_prev 110 | else: 111 | link = root[1] 112 | link_next = link[1] 113 | root[1] = link_next 114 | link_next[0] = root 115 | key = link[2] 116 | del self.__map[key] 117 | value = dict.pop(self, key) 118 | return key, value 119 | 120 | # -- the following methods do not depend on the internal structure -- 121 | 122 | def keys(self): 123 | 'od.keys() -> list of keys in od' 124 | return list(self) 125 | 126 | def values(self): 127 | 'od.values() -> list of values in od' 128 | return [self[key] for key in self] 129 | 130 | def items(self): 131 | 'od.items() -> list of (key, value) pairs in od' 132 | return [(key, self[key]) for key in self] 133 | 134 | def iterkeys(self): 135 | 'od.iterkeys() -> an iterator over the keys in od' 136 | return iter(self) 137 | 138 | def itervalues(self): 139 | 'od.itervalues -> an iterator over the values in od' 140 | for k in self: 141 | yield self[k] 142 | 143 | def iteritems(self): 144 | 'od.iteritems -> an iterator over the (key, value) items in od' 145 | for k in self: 146 | yield (k, self[k]) 147 | 148 | def update(*args, **kwds): 149 | '''od.update(E, **F) -> None. Update od from dict/iterable E and F. 150 | 151 | If E is a dict instance, does: for k in E: od[k] = E[k] 152 | If E has a .keys() method, does: for k in E.keys(): od[k] = E[k] 153 | Or if E is an iterable of items, does: for k, v in E: od[k] = v 154 | In either case, this is followed by: for k, v in F.items(): od[k] = v 155 | 156 | ''' 157 | if len(args) > 2: 158 | raise TypeError('update() takes at most 2 positional ' 159 | 'arguments (%d given)' % (len(args),)) 160 | elif not args: 161 | raise TypeError('update() takes at least 1 argument (0 given)') 162 | self = args[0] 163 | # Make progressively weaker assumptions about "other" 164 | other = () 165 | if len(args) == 2: 166 | other = args[1] 167 | if isinstance(other, dict): 168 | for key in other: 169 | self[key] = other[key] 170 | elif hasattr(other, 'keys'): 171 | for key in other.keys(): 172 | self[key] = other[key] 173 | else: 174 | for key, value in other: 175 | self[key] = value 176 | for key, value in kwds.items(): 177 | self[key] = value 178 | 179 | # let subclasses override update without breaking __init__ 180 | __update = update 181 | 182 | __marker = object() 183 | 184 | def pop(self, key, default=__marker): 185 | '''od.pop(k[,d]) -> v, remove specified key and return the 186 | corresponding value. If key is not found, d is returned if given, 187 | otherwise KeyError is raised. 188 | 189 | ''' 190 | if key in self: 191 | result = self[key] 192 | del self[key] 193 | return result 194 | if default is self.__marker: 195 | raise KeyError(key) 196 | return default 197 | 198 | def setdefault(self, key, default=None): 199 | 'od.setdefault(k[,d]) -> od.get(k,d), also set od[k]=d if k not in od' 200 | if key in self: 201 | return self[key] 202 | self[key] = default 203 | return default 204 | 205 | def __repr__(self, _repr_running={}): 206 | 'od.__repr__() <==> repr(od)' 207 | call_key = id(self), _get_ident() 208 | if call_key in _repr_running: 209 | return '...' 210 | _repr_running[call_key] = 1 211 | try: 212 | if not self: 213 | return '%s()' % (self.__class__.__name__,) 214 | return '%s(%r)' % (self.__class__.__name__, self.items()) 215 | finally: 216 | del _repr_running[call_key] 217 | 218 | def __reduce__(self): 219 | 'Return state information for pickling' 220 | items = [[k, self[k]] for k in self] 221 | inst_dict = vars(self).copy() 222 | for k in vars(OrderedDict()): 223 | inst_dict.pop(k, None) 224 | if inst_dict: 225 | return (self.__class__, (items,), inst_dict) 226 | return self.__class__, (items,) 227 | 228 | def copy(self): 229 | 'od.copy() -> a shallow copy of od' 230 | return self.__class__(self) 231 | 232 | @classmethod 233 | def fromkeys(cls, iterable, value=None): 234 | '''OD.fromkeys(S[, v]) -> New ordered dictionary with keys from S 235 | and values equal to v (which defaults to None). 236 | 237 | ''' 238 | d = cls() 239 | for key in iterable: 240 | d[key] = value 241 | return d 242 | 243 | def __eq__(self, other): 244 | '''od.__eq__(y) <==> od==y. Comparison to another OD is 245 | order-sensitive while comparison to a regular mapping is 246 | order-insensitive. 247 | 248 | ''' 249 | if isinstance(other, OrderedDict): 250 | return len(self) == len(other) and self.items() == other.items() 251 | return dict.__eq__(self, other) 252 | 253 | def __ne__(self, other): 254 | return not self == other 255 | 256 | # -- the following methods are only used in Python 2.7 -- 257 | 258 | def viewkeys(self): 259 | "od.viewkeys() -> a set-like object providing a view on od's keys" 260 | return KeysView(self) 261 | 262 | def viewvalues(self): 263 | "od.viewvalues() -> an object providing a view on od's values" 264 | return ValuesView(self) 265 | 266 | def viewitems(self): 267 | "od.viewitems() -> a set-like object providing a view on od's items" 268 | return ItemsView(self) 269 | ## end of http://code.activestate.com/recipes/576693/ }}} 270 | -------------------------------------------------------------------------------- /voidwalker/framework/utils/recipes.py: -------------------------------------------------------------------------------- 1 | # (void)walker utility library 2 | # Copyright (C) 2012 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | from itertools import izip_longest 18 | 19 | 20 | def grouper(n, iterable, fillvalue=None): 21 | args = [iter(iterable)] * n 22 | return izip_longest(*args, fillvalue=fillvalue) 23 | -------------------------------------------------------------------------------- /voidwalker/version.py: -------------------------------------------------------------------------------- 1 | VERSION = (0, 2, 999, 'dev') 2 | __version__ = ''.join(['-.' [type(x) == int] + str(x) for x in VERSION])[1:] 3 | -------------------------------------------------------------------------------- /voidwalker/voidwalker.py: -------------------------------------------------------------------------------- 1 | # (void)walker GDB plugin 2 | # Copyright (C) 2012-2013 David Holm 3 | 4 | # This program is free software; you can redistribute it and/or modify 5 | # it under the terms of the GNU General Public License as published by 6 | # the Free Software Foundation; either version 3 of the License, or 7 | # (at your option) any later version. 8 | # 9 | # This program is distributed in the hope that it will be useful, 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | # GNU General Public License for more details. 13 | # 14 | # You should have received a copy of the GNU General Public License 15 | # along with this program. If not, see . 16 | 17 | import sys 18 | if 'voidwalker' not in sys.modules: 19 | import inspect 20 | import os.path 21 | self_path = os.path.abspath(inspect.getfile(inspect.currentframe())) 22 | pkg_path = os.path.abspath(os.path.join(os.path.dirname(self_path), 23 | os.pardir)) 24 | sys.path.insert(0, pkg_path) 25 | from voidwalker import voidwalker 26 | 27 | else: 28 | from flowui.terminal import AnsiTerminal 29 | from flowui.themes import Solarized 30 | 31 | from .framework.interface import CommandBuilder 32 | from .framework.interface import Configuration 33 | from .framework.interface import ParameterBuilder 34 | from .framework.patching import SnippetRepository 35 | from .framework.target import InferiorRepository 36 | 37 | from .backends.gdb import GdbCommandFactory 38 | from .backends.gdb import GdbCpuFactory 39 | from .backends.gdb import GdbParameterFactory 40 | from .backends.gdb import GdbPlatformFactory 41 | from .backends.gdb import GdbInferiorFactory 42 | from .backends.gdb import GdbThreadFactory 43 | from .backends.gdb import GdbTerminal 44 | 45 | from .application.patching import SnippetCommandBuilder 46 | 47 | # Register all commands, parameters, cpus and themes 48 | from .backends.gdb import tools 49 | from . import application 50 | 51 | from version import __version__ 52 | 53 | class VoidwalkerBuilder(object): 54 | def __init__(self, version): 55 | config = Configuration() 56 | ParameterBuilder(GdbParameterFactory(), config) 57 | 58 | snippet_repository = SnippetRepository() 59 | SnippetCommandBuilder(snippet_repository) 60 | 61 | platform_factory = GdbPlatformFactory() 62 | inferior_factory = GdbInferiorFactory(GdbCpuFactory()) 63 | inferior_repository = InferiorRepository() 64 | ansi_terminal = AnsiTerminal(GdbTerminal(), Solarized()) 65 | CommandBuilder(GdbCommandFactory(), inferior_repository, 66 | platform_factory, inferior_factory, 67 | GdbThreadFactory(), config, ansi_terminal) 68 | 69 | msg = ('%(face-underlined)s(void)walker%(face-normal)s ' 70 | 'v%(version)s installed\n') 71 | ansi_terminal.write(msg, {'version': version}) 72 | 73 | voidwalker_builder = VoidwalkerBuilder(__version__) 74 | --------------------------------------------------------------------------------