├── OllyHeapTrace.bdsproj ├── OllyHeapTraceGroup.bdsgroup ├── Readme.md ├── bin ├── OLLYDBG.LIB └── OllyHeapTrace.dll ├── gpl-3.0.txt ├── screenshot1.gif └── src ├── OllyHeapTrace.res ├── Plugin.h ├── hooks.c ├── hooks.h └── main.c /OllyHeapTrace.bdsproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | src\main.c 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | False 191 | False 192 | 1 193 | 1 194 | 0 195 | 0 196 | False 197 | False 198 | False 199 | False 200 | False 201 | 1033 202 | 1252 203 | 204 | 205 | Harmony Security 206 | OllyHeapTrace 207 | 1.1.0.0 208 | 209 | 210 | 211 | 212 | 213 | 1.0.0.0 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | False 223 | 224 | 225 | 226 | 227 | 228 | 229 | False 230 | 231 | False 232 | 233 | True 234 | False 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | -------------------------------------------------------------------------------- /OllyHeapTraceGroup.bdsgroup: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | OllyHeapTrace.bdsproj 15 | OllyHeapTrace.dll 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | About 2 | ===== 3 | 4 | OllyHeapTrace (Written in 2008) is a plugin for OllyDbg (version 1.10) to trace the heap operations being performed by a process. It will monitor heap allocations and frees for multiple heaps, as well as operations such as creating or destroying heaps and reallocations. All parameters as well as return values are recorded and the trace is highlighted with a unique colour for each heap being traced. 5 | 6 | The primary purpose of this plugin is to aid in the debugging of heap overflows where you wish to be able to control the heap layout to overwrite a specific structure such as a chunk header, critical section structure or some application specific data. By tracing the heap operations performed during actions you can control (for example opening a connection, sending a packet, closing a connection) you can begin to predict the heap operations and thus control the heap layout. 7 | 8 | Build 9 | ===== 10 | 11 | To build OllyHeapTrace from source, checkout the latest revision from the SVN trunk and then open OllyHeapTraceGroup.bdsgroup with either Borland's Turbo C++ Explorer (free) or any recent version of C++ Builder and build the OllyHeapTrace project. 12 | 13 | Usage 14 | ===== 15 | 16 | Simply install the plugin and activate OllyHeapTrace when you wish to begin tracing heap operations. OllyHeapTrace will automatically create the breakpoints needed (RtlAllocateHeap, RtlFreeHeap, RtlCreateHeap, RtlDestroyHeap, RtlReAllocateHeap, RtlSizeHeap, GetProcessHeap and RtlInitializeCriticalSection, RtlDeleteCriticalSection) and record the relevant information when these breakpoints are hit. To view the heap trace select the OllyHeapTrace Log. 17 | 18 | Double clicking on any row in the OllyHeapTrace Log window will bring you to the callers location in the OllyDbg disassembly window. The recorded heap trace is highlighted with a unique colour for each heap being traced. Right clicking on any row will give you some options such as to view the heap chunks data or the heap itself (only a raw dump of the memory is given, no parsing of the heap structures is performed). You can also filter out unwanted information if you are only concerned with a specific heap. 19 | 20 | Screenshot 21 | ========== 22 | 23 | ![OllyHeapTrace Screenshot 1](https://github.com/stephenfewer/OllyHeapTrace/raw/master/screenshot1.gif "OllyHeapTrace Screenshot 1") 24 | 25 | License 26 | ======= 27 | 28 | The OllyHeapTrace source code is available under the GPLv3 license, please see the included file gpl-3.0.txt for details. 29 | -------------------------------------------------------------------------------- /bin/OLLYDBG.LIB: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stephenfewer/OllyHeapTrace/cbc5faab5f9c902599be617c171c1a730743b3e6/bin/OLLYDBG.LIB -------------------------------------------------------------------------------- /bin/OllyHeapTrace.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stephenfewer/OllyHeapTrace/cbc5faab5f9c902599be617c171c1a730743b3e6/bin/OllyHeapTrace.dll -------------------------------------------------------------------------------- /gpl-3.0.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /screenshot1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stephenfewer/OllyHeapTrace/cbc5faab5f9c902599be617c171c1a730743b3e6/screenshot1.gif -------------------------------------------------------------------------------- /src/OllyHeapTrace.res: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stephenfewer/OllyHeapTrace/cbc5faab5f9c902599be617c171c1a730743b3e6/src/OllyHeapTrace.res -------------------------------------------------------------------------------- /src/Plugin.h: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // // 3 | // OLLYDBG PLUGIN API // 4 | // // 5 | // Version 1.10 // 6 | // // 7 | // Written by Oleh Yuschuk (ollydbg@t-online.de) // 8 | // // 9 | // Internet: http://home.t-online.de/home/Ollydbg // 10 | // // 11 | // This code is distributed "as is", without warranty of any kind, expressed // 12 | // or implied, including, but not limited to warranty of fitness for any // 13 | // particular purpose. In no event will Oleh Yuschuk be liable to you for any // 14 | // special, incidental, indirect, consequential or any other damages caused // 15 | // by the use, misuse, or the inability to use of this code, including any // 16 | // lost profits or lost savings, even if Oleh Yuschuk has been advised of the // 17 | // possibility of such damages. // 18 | // // 19 | //////////////////////////////////////////////////////////////////////////////// 20 | 21 | 22 | //////////////////////////////////////////////////////////////////////////////// 23 | //////////////////////////// IMPORTANT INFORMATION ///////////////////////////// 24 | 25 | // 1. Export all callback functions by name, NOT by ordinal! 26 | // 2. Force byte alignment of OllyDbg structures! 27 | // 3. Set default char type to unsigned! 28 | // 4. Read documentation! 29 | 30 | // If you prefere Borland, this will force necessary settings (but, as a side 31 | // effect, may cause plenty of warnings if other include files will be compiled 32 | // with different options): 33 | #ifdef __BORLANDC__ 34 | 35 | #pragma option -a1 // Byte alignment 36 | #pragma option -K // Unsigned char 37 | 38 | // And here I check that settings are correct. Unfortunately, Microsoft C (at 39 | // least C++ 5.0) doesn't allow for sizeof and typecasts in conditionals: 40 | 41 | typedef struct t_aligntest { 42 | char a; 43 | long b; 44 | } t_aligntest; 45 | 46 | #if (sizeof(t_aligntest)!=sizeof(char)+sizeof(long)) 47 | #error Please assure byte alignment of OllyDbg structures 48 | #endif 49 | #undef t_aligntest 50 | 51 | #if ((char)0xFF!=255) 52 | #error Please set default char type to unsigned 53 | #endif 54 | 55 | #endif 56 | 57 | // If you like Microsoft compiler, this will force byte alignment and verify 58 | // that character is set to unsigned. 59 | #ifdef _MSC_VER 60 | 61 | #pragma pack(1) // Force byte alignment of structures 62 | 63 | #ifndef _CHAR_UNSIGNED // Verify that character is unsigned 64 | #error Please set default char type to unsigned (option /J) 65 | #endif 66 | 67 | // Borland adds underscore to export automatically, whereas I don't know any 68 | // such option for Microsoft compiler. This solution is not too elegant but 69 | // works. 70 | #define ODBG_Plugindata _ODBG_Plugindata 71 | #define ODBG_Plugininit _ODBG_Plugininit 72 | #define ODBG_Pluginmainloop _ODBG_Pluginmainloop 73 | #define ODBG_Pluginsaveudd _ODBG_Pluginsaveudd 74 | #define ODBG_Pluginuddrecord _ODBG_Pluginuddrecord 75 | #define ODBG_Pluginmenu _ODBG_Pluginmenu 76 | #define ODBG_Pluginaction _ODBG_Pluginaction 77 | #define ODBG_Pluginshortcut _ODBG_Pluginshortcut 78 | #define ODBG_Pluginreset _ODBG_Pluginreset 79 | #define ODBG_Pluginclose _ODBG_Pluginclose 80 | #define ODBG_Plugindestroy _ODBG_Plugindestroy 81 | #define ODBG_Paused _ODBG_Paused 82 | #define ODBG_Pausedex _ODBG_Pausedex 83 | #define ODBG_Plugincmd _ODBG_Plugincmd 84 | 85 | #endif 86 | 87 | 88 | //////////////////////////////////////////////////////////////////////////////// 89 | ///////////////////////////// GENERAL DECLARATIONS ///////////////////////////// 90 | 91 | #define PLUGIN_VERSION 110 // Version of plugin interface 92 | 93 | #ifdef __cplusplus 94 | #define extc extern "C" // Assure that names are not mangled 95 | #else 96 | #define extc extern 97 | #endif 98 | 99 | #define _export __declspec(dllexport) 100 | 101 | typedef unsigned char uchar; // Unsigned character (byte) 102 | typedef unsigned short ushort; // Unsigned short 103 | typedef unsigned int uint; // Unsigned integer 104 | typedef unsigned long ulong; // Unsigned long 105 | 106 | #define TEXTLEN 256 // Maximal length of text string 107 | #define ARGLEN 1024 // Maximal length of argument string 108 | #define USERLEN 4096 // Maximal length of record in .udd file 109 | #define SHORTLEN 8 // Maximal length of short name 110 | 111 | #define BLACK 0 // Indices of colours used by OllyDbg. In 112 | #define BLUE 1 // syntax highlighting, use only colours 113 | #define GREEN 2 // 0 to 15 in the least significant bits 114 | #define CYAN 3 // of the corresponding mask byte. 115 | #define RED 4 116 | #define MAGENTA 5 117 | #define BROWN 6 118 | #define LIGHTGRAY 7 119 | #define DARKGRAY 8 120 | #define LIGHTBLUE 9 121 | #define LIGHTGREEN 10 122 | #define LIGHTCYAN 11 123 | #define LIGHTRED 12 124 | #define LIGHTMAGENTA 13 125 | #define YELLOW 14 126 | #define WHITE 15 127 | #define MINT 16 128 | #define SKYBLUE 17 129 | #define IVORY 18 130 | #define GRAY 19 131 | 132 | #define NCOLORS 20 // Total number of defined colours 133 | 134 | #define BKTRANSP 0x00 // Background colours in syntax hiliting 135 | #define BKBLACK 0x10 136 | #define BKGRAY 0x20 137 | #define BKWHITE 0x30 138 | #define BKCYAN 0x40 139 | #define BKGREEN 0x50 140 | #define BKRED 0x60 141 | #define BKYELLOW 0x70 142 | 143 | #define BLACKWHITE 0 // Colour schemes used by OllyDbg 144 | #define BLUEGOLD 1 145 | #define SKYWIND 2 146 | #define NIGHTSTARS 3 147 | #define SCHEME4 4 148 | #define SCHEME5 5 149 | #define SCHEME6 6 150 | #define SCHEME7 7 151 | 152 | #define FIXEDFONT 0 // Fonts used by OllyDbg. Variable-pitch 153 | #define TERMINAL6 1 // fonts are placed at the end of this 154 | #define FIXEDSYS 2 // table. 155 | #define COURIERFONT 3 156 | #define LUCIDACONS 4 157 | #define FONT5 5 158 | #define FONT6 6 159 | #define FONT7 7 160 | #define MAINFONT 8 161 | #define SYSFONT 9 162 | #define INFOFONT 10 163 | 164 | //////////////////////////////////////////////////////////////////////////////// 165 | //////////////////////////// INFORMATION FUNCTIONS ///////////////////////////// 166 | 167 | extc void cdecl Addtolist(long addr,int highlight,char *format,...); 168 | extc void cdecl Updatelist(void); 169 | extc HWND cdecl Createlistwindow(void); 170 | extc void cdecl Error(char *format,...); 171 | extc void cdecl Message(ulong addr,char *format,...); 172 | extc void cdecl Infoline(char *format,...); 173 | extc void cdecl Progress(int promille,char *format,...); 174 | extc void cdecl Flash(char *format,...); 175 | 176 | //////////////////////////////////////////////////////////////////////////////// 177 | ////////////////////////// DATA FORMATTING FUNCTIONS /////////////////////////// 178 | 179 | // Bits used in Decodeaddress(), Decoderelativeoffset() and Decodethreadname() 180 | // to specify decoding mode: 181 | #define ADC_DEFAULT 0x0000 // Default decoding mode 182 | #define ADC_DIFFMOD 0x0001 // Show module only if different 183 | #define ADC_NOMODNAME 0x0002 // Never show module name 184 | #define ADC_VALID 0x0004 // Only decode if allocated memory 185 | #define ADC_INMODULE 0x0008 // Only decode if in some module 186 | #define ADC_SAMEMOD 0x0010 // Decode only address in same module 187 | #define ADC_SYMBOL 0x0020 // Only decode if symbolic name 188 | #define ADC_JUMP 0x0040 // Check if points to JMP/CALL command 189 | #define ADC_OFFSET 0x0080 // Check if symbol for data 190 | #define ADC_STRING 0x0100 // Check if pointer to ASCII or UNICODE 191 | #define ADC_ENTRY 0x0200 // Check if entry to subroutine 192 | #define ADC_UPPERCASE 0x0400 // First letter in uppercase if possible 193 | #define ADC_WIDEFORM 0x0800 // Extended form of decoded name 194 | #define ADC_NONTRIVIAL 0x1000 // Name + non-zero offset 195 | #define ADC_DYNAMIC 0x2000 // JMP/CALL to dynamically loaded name 196 | 197 | #define PLAINASCII 0x01 // Plain ASCII character 198 | #define DIACRITICAL 0x02 // Diacritical character 199 | #define RAREASCII 0x10 // Rare ASCII character 200 | 201 | extc int cdecl Decodeaddress(ulong addr,ulong base,int addrmode, 202 | char *symb,int nsymb,char *comment); 203 | extc int cdecl Decoderelativeoffset(ulong addr,int addrmode, 204 | char *symb,int nsymb); 205 | extc int cdecl Decodecharacter(char *s,uint c); 206 | extc int cdecl Printfloat4(char *s,float f); 207 | extc int cdecl Printfloat8(char *s,double d); 208 | extc int cdecl Printfloat10(char *s,long double ext); 209 | extc int cdecl Print3dnow(char *s,uchar *f); 210 | extc int cdecl Printsse(char *s,char *f); 211 | extc ulong cdecl Followcall(ulong addr); 212 | extc int cdecl IstextA(char c); 213 | extc int cdecl IstextW(wchar_t w); 214 | extc int cdecl Stringtotext(char *data,int ndata,char *text,int ntext); 215 | 216 | //////////////////////////////////////////////////////////////////////////////// 217 | ///////////////////////////// DATA INPUT FUNCTIONS ///////////////////////////// 218 | 219 | #define MAXCMDSIZE 16 // Maximal length of 80x86 command 220 | #define NSEQ 8 // Max length of command sequence 221 | #define NMODELS 8 // Number of assembler search models 222 | 223 | // Note that each of dialog functions decodes only subset of listed flags. 224 | #define DIA_ASKGLOBAL 0x0001 // Display checkbox "Global search" 225 | #define DIA_HEXONLY 0x0002 // Hexadecimal format only 226 | #define DIA_ALIGNED 0x0004 // Display checkbox "Aligned search" 227 | #define DIA_DEFHEX 0x0000 // On startup, cursor in hex control 228 | #define DIA_DEFASCII 0x0010 // On startup, cursor in ASCII control 229 | #define DIA_DEFUNICODE 0x0020 // On startup, cursor in UNICODE control 230 | #define DIA_SEARCH 0x0040 // Is a search dialog 231 | #define DIA_HISTORY 0x0100 // Allows previous hex strings 232 | 233 | // Status of animation or trace. 234 | #define ANIMATE_OFF 0 // No animation 235 | #define ANIMATE_IN 1 // Animate into 236 | #define ANIMATE_OVER 2 // Animate over 237 | #define ANIMATE_RET 3 // Execute till RET 238 | #define ANIMATE_SKPRET 4 // Skip RET instruction 239 | #define ANIMATE_USER 5 // Execute till user code 240 | #define ANIMATE_TRIN 6 // Run trace in 241 | #define ANIMATE_TROVER 7 // Run trace over 242 | #define ANIMATE_STOP 8 // Gracefully stop animation 243 | 244 | typedef struct t_hexstr { // String used for hex/text search 245 | int n; // String length 246 | uchar data[TEXTLEN]; // Data 247 | uchar mask[TEXTLEN]; // Mask, 0 bits are masked 248 | } t_hexstr; 249 | 250 | typedef struct t_asmmodel { // Model to search for assembler command 251 | uchar code[MAXCMDSIZE]; // Binary code 252 | uchar mask[MAXCMDSIZE]; // Mask for binary code (0: bit ignored) 253 | int length; // Length of code, bytes (0: empty) 254 | int jmpsize; // Offset size if relative jump 255 | int jmpoffset; // Offset relative to IP 256 | int jmppos; // Position of jump offset in command 257 | } t_asmmodel; 258 | 259 | typedef struct t_extmodel { // Model for extended command search 260 | char code[MAXCMDSIZE]; // Binary code 261 | char mask[MAXCMDSIZE]; // Mask for binary code (0: bit ignored) 262 | int length; // Length of code, bytes (0: empty) 263 | int jmpsize; // Offset size if relative jump 264 | int jmpoffset; // Offset relative to IP 265 | int jmppos; // Position of jump offset in command 266 | int isany; // Count for ANY's argument 267 | int cmdoffset; // Offset of command in the source 268 | char ramask[MAXCMDSIZE]; // Mask for pseudoregister RA 269 | char rbmask[MAXCMDSIZE]; // Mask for pseudoregister RB 270 | } t_extmodel; 271 | 272 | extc int cdecl Getlong(char *title,ulong *data,int datasize, 273 | char letter,int mode); 274 | extc int cdecl Getlongxy(char *title,ulong *data,int datasize, 275 | char letter,int mode,int x,int y); 276 | extc int cdecl Getregxy(char *title,ulong *data,char letter,int x,int y); 277 | extc int cdecl Getline(char *title,ulong *data); 278 | extc int cdecl Getlinexy(char *title,ulong *data,int x,int y); 279 | extc int cdecl Getfloat10(char *title,long double *fdata, 280 | uchar *tag,char letter,int mode); 281 | extc int cdecl Getfloat10xy(char *title,long double *fdata, 282 | char *tag,char letter,int mode,int x,int y); 283 | extc int cdecl Getfloat(char *title,void *fdata,int size, 284 | char letter,int mode); 285 | extc int cdecl Getfloatxy(char *title,void *fdata,int size, 286 | char letter,int mode,int x,int y); 287 | extc void cdecl Getasmfindmodel(t_asmmodel model[NMODELS], 288 | char letter,int searchall); 289 | extc void cdecl Getasmfindmodelxy(t_asmmodel model[NMODELS], 290 | char letter,int searchall,int x,int y); 291 | extc int cdecl Gettext(char *title,char *text, 292 | char letter,int type,int fontindex); 293 | extc int cdecl Gettextxy(char *title,char *text,char letter, 294 | int type,int fontindex,int x,int y); 295 | extc int cdecl Gethexstring(char *title,t_hexstr *hs, 296 | int mode,int fontindex,char letter); 297 | extc int cdecl Gethexstringxy(char *title,t_hexstr *hs,int mode, 298 | int fontindex,char letter,int x,int y); 299 | extc int cdecl Getmmx(char *title,uchar *data,int mode); 300 | extc int cdecl Getmmxxy(char *title,char *data,int mode,int x,int y); 301 | extc int cdecl Get3dnow(char *title,uchar *data,int mode); 302 | extc int cdecl Get3dnowxy(char *title,char *data,int mode,int x,int y); 303 | extc int cdecl Browsefilename(char *title,char *name,char *defext, 304 | int getarguments); 305 | extc int cdecl OpenEXEfile(char *path,int dropped); 306 | extc int cdecl Attachtoactiveprocess(int newprocessid); 307 | extc void cdecl Animate(int animation); 308 | 309 | //////////////////////////////////////////////////////////////////////////////// 310 | //////////////////////////// SORTED DATA FUNCTIONS ///////////////////////////// 311 | 312 | #define NBAR 17 // Max allowed number of segments in bar 313 | 314 | #define BAR_PRESSED 0x01 // Bar segment pressed, used internally 315 | #define BAR_DISABLED 0x02 // Bar segment disabled 316 | #define BAR_NOSORT 0x04 // Flat bar column, supports no sorting 317 | #define BAR_NORESIZE 0x08 // Bar column cannot be resized 318 | #define BAR_BUTTON 0x10 // Segment sends WM_USER_BAR 319 | #define BAR_SHIFTSEL 0x20 // Selection shifted 1/2 char to left 320 | 321 | #define CAPT_FREE 0 // Bar and data are not captured 322 | 323 | #define TABLE_DIR 0x0001 // Bottom-to-top table 324 | #define TABLE_COPYMENU 0x0002 // Attach copy item 325 | #define TABLE_SORTMENU 0x0004 // Attach sort menu 326 | #define TABLE_APPMENU 0x0010 // Attach appearance menu 327 | #define TABLE_WIDECOL 0x0020 // Attach wide columns menu item 328 | #define TABLE_USERAPP 0x0040 // Attach user-processed appearance menu 329 | #define TABLE_USERDEF 0x0080 // User-drawn table 330 | #define TABLE_NOHSCR 0x0100 // Table contains no horizontal scroll 331 | #define TABLE_SAVEPOS 0x0200 // Save position & appearance to .ini 332 | #define TABLE_CPU 0x0400 // Table belongs to CPU window 333 | #define TABLE_FASTSEL 0x0800 // Update when selection changes 334 | #define TABLE_COLSEL 0x1000 // Column-wide selection 335 | #define TABLE_SAVEAPP 0x2000 // Save multiinstance appearance to .ini 336 | #define TABLE_HILMENU 0x4000 // Attach Syntax highlighting menu 337 | #define TABLE_ONTOP 0x8000 // Attach Always on top menu 338 | 339 | #define DRAW_NORMAL 0x0000 // Normal plain text 340 | #define DRAW_GRAY 0x0001 // Grayed text 341 | #define DRAW_HILITE 0x0002 // Highlighted text 342 | #define DRAW_UL 0x0004 // Underlined text 343 | #define DRAW_SELECT 0x0008 // Selected background 344 | #define DRAW_EIP 0x0010 // Inverted normal text/background 345 | #define DRAW_BREAK 0x0020 // Breakpoint background 346 | #define DRAW_GRAPH 0x0040 // Graphical element 347 | #define DRAW_DIRECT 0x0080 // Direct text colour index (mask only) 348 | #define DRAW_MASK 0x0080 // Use mask to set individual colors 349 | #define DRAW_EXTSEL 0x0100 // Extend mask till end of column 350 | #define DRAW_UNICODE 0x0200 // Text in UNICODE 351 | #define DRAW_TOP 0x0400 // Draw upper half of text 352 | #define DRAW_BOTTOM 0x0800 // Draw lower half of text 353 | 354 | // Symbolic names for graphical characters. Any other character is displayed 355 | // as space. Use only characters in range [1..0x7F]! 356 | #define D_SPACE 'N' // Space 357 | #define D_SEP ' ' // Thin separating line 358 | #define D_BEGIN 'B' // Begin of procedure or scope 359 | #define D_BODY 'I' // Body of procedure or scope 360 | #define D_ENTRY 'J' // Loop entry point 361 | #define D_LEAF 'K' // Intermediate leaf on a tree 362 | #define D_END 'E' // End of procedure or scope 363 | #define D_SINGLE 'S' // Single-line scope 364 | #define D_ENDBEG 'T' // End and begin of stack scope 365 | #define D_POINT '.' // Point 366 | #define D_JMPUP 'U' // Jump upstairs 367 | #define D_JMPOUT '<' // Jump to same location or out of module 368 | #define D_JMPDN 'D' // Jump downstairs 369 | #define D_PATHUP 'u' // Jump path upstairs (highlighted) 370 | #define D_GRAYUP 'v' // Jump path upstairs (grayed) 371 | #define D_PATH 'i' // Jump path through text (highlighted) 372 | #define D_GRAYPATH 'j' // Jump path through text (grayed) 373 | #define D_PATHDN 'd' // Jump path downstairs (highlighted) 374 | #define D_GRAYDN 'e' // Jump path downstairs (grayed) 375 | #define D_PATHUPEND 'r' // End of path upstairs (highlighted) 376 | #define D_GRAYUPEND 's' // End of path upstairs (grayed) 377 | #define D_PATHDNEND 'f' // End of path downstairs (highlighted) 378 | #define D_GRAYDNEND 'g' // End of path downstairs (grayed) 379 | #define D_SWTOP 't' // Start of switch 380 | #define D_SWBODY 'b' // Switch body 381 | #define D_CASE 'c' // Intermediate switch case 382 | #define D_LASTCASE 'l' // Last switch case 383 | 384 | // Please note: Although types here contain mostly unique bit assignments, it's 385 | // not really necessary. Same bits, except for reserved general types, can be 386 | // freely shared between different types of sorted data. 387 | // General item types: 388 | #define TY_NEW 0x00000001 // Item is new 389 | #define TY_CONFIRMED 0x00000002 // Item still exists 390 | #define TY_MAIN 0x00000004 // Main item (thread or module) 391 | #define TY_INVALID 0x00000008 // Invalid type (item does not exist) 392 | #define TY_SELECTED 0x80000000 // Reserved for multiple selection 393 | // Module-specific types: 394 | #define TY_REPORTED 0x00000010 // Stop on module was reported 395 | // Reference-specific types: 396 | #define TY_REFERENCE 0x00000020 // Item is a real reference 397 | #define TY_ORIGIN 0x00000040 // Item is a search origin 398 | // Breakpoint-specific types: 399 | #define TY_STOPAN 0x00000080 // Stop animation if TY_ONESHOT 400 | #define TY_SET 0x00000100 // Code INT3 is in memory 401 | #define TY_ACTIVE 0x00000200 // Permanent breakpoint 402 | #define TY_DISABLED 0x00000400 // Permanent disabled breakpoint 403 | #define TY_ONESHOT 0x00000800 // Temporary stop 404 | #define TY_TEMP 0x00001000 // Temporary breakpoint 405 | #define TY_KEEPCODE 0x00002000 // Set and keep command code 406 | #define TY_KEEPCOND 0x00004000 // Keep condition unchanged (0: remove) 407 | #define TY_NOUPDATE 0x00008000 // Don't redraw breakpoint window 408 | #define TY_RTRACE 0x00010000 // Pseudotype of run trace breakpoint 409 | // Namelist-specific types: 410 | #define TY_EXPORT 0x00010000 // Exported name 411 | #define TY_IMPORT 0x00020000 // Imported name 412 | #define TY_LIBRARY 0x00040000 // Name extracted from object file 413 | #define TY_LABEL 0x00080000 // User-defined name 414 | #define TY_ANYNAME 0x000F0000 // Any of the namelist flags above 415 | #define TY_KNOWN 0x00100000 // Name of known function 416 | // Memory-specific types: 417 | #define TY_DEFHEAP 0x00020000 // Contains default heap 418 | #define TY_HEAP 0x00040000 // Contains non-default heap 419 | #define TY_SFX 0x00080000 // Contains self-extractor 420 | #define TY_CODE 0x00100000 // Contains image of code section 421 | #define TY_DATA 0x00200000 // Contains image of data section 422 | #define TY_IMPDATA 0x00400000 // Memory block includes import data 423 | #define TY_EXPDATA 0x00800000 // Memory block includes export data 424 | #define TY_RSRC 0x01000000 // Memory block includes resources 425 | #define TY_RELOC 0x02000000 // Memory block includes relocation data 426 | #define TY_STACK 0x04000000 // Contains stack of some thread 427 | #define TY_THREAD 0x08000000 // Contains data block of some thread 428 | #define TY_HEADER 0x10000000 // COFF header 429 | #define TY_ANYMEM 0x1FFE0000 // Any of the memory flags above 430 | #define TY_GUARDED 0x20000000 // NT only: guarded memory block 431 | // Procedure data-specific types: 432 | #define TY_PURE 0x00004000 // No side effects except in stack 433 | #define TY_PASCAL 0x00010000 // Procedure ends with RET nnn 434 | #define TY_C 0x00020000 // ADD ESP,nnn after call to procedure 435 | #define TY_NOTENTRY 0x00100000 // Not necessarily entry point 436 | // Switch data-specific types. 437 | #define TY_CHARSW 0x00100000 // ASCII switch 438 | #define TY_WMSW 0x00200000 // Window message switch 439 | #define TY_EXCEPTSW 0x00400000 // Exception switch 440 | // Stack walk data-specific types. 441 | #define TY_RELIABLE 0x01000000 // Reliable call 442 | #define TY_GUESSED 0x02000000 // Not a real entry, just guessed 443 | #define TY_BELONGS 0x04000000 // Not a real entry, just belongs to proc 444 | // Call tree-specific types. 445 | #define TY_RECURSIVE 0x00000100 // Routine calls self 446 | #define TY_TERMINAL 0x00000200 // Leaf function, doesn't call others 447 | #define TY_SYSTEM 0x00000400 // Function resides in system DLL 448 | #define TY_DIRECT 0x00000800 // Called directly 449 | #define TY_NODATA 0x00001000 // Not analyzed or outside procedure 450 | #define TY_DUMMY 0x00002000 // Consists of single RET command 451 | #define TY_NOSIDE 0x00004000 // No side effects except in stack 452 | 453 | typedef struct t_scheme { // Color scheme 454 | char *name; // Name of the scheme 455 | int textcolor; // Colour used to draw text 456 | int hitextcolor; // Colour used to draw highlited text 457 | int lowcolor; // Colour used to draw auxiliary text 458 | int bkcolor; // Colour used to draw backgrounds 459 | int selbkcolor; // Colour used for selecting background 460 | int linecolor; // Colour used for separating lines 461 | int auxcolor; // Colour used for auxiliary objects 462 | int condbkcolor; // Colour used for background of cond brk 463 | } t_scheme; 464 | 465 | typedef struct t_schemeopt { // Color scheme, alternative form 466 | char *name; // Name of the scheme 467 | int color[8]; // Colours used as in t_scheme 468 | } t_schemeopt; 469 | 470 | typedef struct t_bar { 471 | int nbar; // Number of active columns 472 | int font; // Font used for bar segments 473 | int dx[NBAR]; // Actual widths of columns, pixels 474 | int defdx[NBAR]; // Default widths of columns, chars 475 | char *name[NBAR]; // Column names (may be NULL) 476 | uchar mode[NBAR]; // Combination of BAR_xxx bits 477 | int captured; // One of CAPT_xxx, set to CAPT_FREE 478 | int active; // Info about how mouse is captured 479 | int prevx; // Previous mouse coordinate 480 | } t_bar; 481 | 482 | typedef struct t_sortheader { // Header of sorted data field 483 | ulong addr; // Base address of the entry 484 | ulong size; // Size address of the entry 485 | ulong type; // Entry type, TY_xxx 486 | } t_sortheader; 487 | 488 | typedef int SORTFUNC(const t_sortheader *,const t_sortheader *,const int); 489 | typedef int DRAWFUNC(char *,char *,int *,t_sortheader *,int); 490 | typedef void DESTFUNC(t_sortheader *); 491 | 492 | #define AUTOARRANGE ((SORTFUNC *)1) // Autoarrangeable sorted data 493 | 494 | typedef struct t_sorted { // Descriptor of sorted table 495 | char name[MAX_PATH]; // Name of table, as appears in error 496 | int n; // Actual number of entries 497 | int nmax; // Maximal number of entries 498 | int selected; // Index of selected entry or -1 499 | ulong seladdr; // Base address of selected entry 500 | int itemsize; // Size of single entry 501 | ulong version; // Unique version of table 502 | void *data; // Entries, sorted by address 503 | SORTFUNC *sortfunc; // Function which sorts data or NULL 504 | DESTFUNC *destfunc; // Destructor function or NULL 505 | int sort; // Sorting criterium (column) 506 | int sorted; // Whether indexes are sorted 507 | int *index; // Indexes, sorted by criterium 508 | int suppresserr; // Suppress multiple overflow errors 509 | } t_sorted; 510 | 511 | typedef struct t_table { // Window with sorted data and bar 512 | HWND hw; // Handle of window or NULL 513 | t_sorted data; // Sorted data 514 | t_bar bar; // Description of bar 515 | int showbar; // Bar: 1-displayed, 0-hidden, -1-absent 516 | short hscroll; // Horiz. scroll: 1-displayed, 0-hidden 517 | short colsel; // Column in TABLE_COLSEL window 518 | int mode; // Combination of bits TABLE_xxx 519 | int font; // Font used by window 520 | short scheme; // Colour scheme used by window 521 | short hilite; // Syntax highlighting used by window 522 | int offset; // First displayed row 523 | int xshift; // Shift in X direction, pixels 524 | DRAWFUNC *drawfunc; // Function which decodes table fields 525 | } t_table; 526 | 527 | extc int cdecl Createsorteddata(t_sorted *sd,char *name,int itemsize, 528 | int nmax,SORTFUNC *sortfunc,DESTFUNC *destfunc); 529 | extc void cdecl Destroysorteddata(t_sorted *sd); 530 | extc void cdecl *Addsorteddata(t_sorted *sd,void *item); 531 | extc void cdecl Deletesorteddata(t_sorted *sd,ulong addr); 532 | extc void cdecl Deletesorteddatarange(t_sorted *sd,ulong addr0,ulong addr1); 533 | extc int cdecl Deletenonconfirmedsorteddata(t_sorted *sd); 534 | extc void* cdecl Findsorteddata(t_sorted *sd,ulong addr); 535 | extc void* cdecl Findsorteddatarange(t_sorted *sd,ulong addr0,ulong addr1); 536 | extc int cdecl Findsorteddataindex(t_sorted *sd,ulong addr0,ulong addr1); 537 | extc int cdecl Sortsorteddata(t_sorted *sd,int sort); 538 | extc void* cdecl Getsortedbyselection(t_sorted *sd,int index); 539 | extc void cdecl Defaultbar(t_bar *pb); 540 | extc int cdecl Tablefunction(t_table *pt, 541 | HWND hw,UINT msg,WPARAM wp,LPARAM lp); 542 | extc void cdecl Painttable(HWND hw,t_table *pt,DRAWFUNC getline); 543 | extc int cdecl Gettableselectionxy(t_table *pt,int column,int *px,int *py); 544 | extc void cdecl Selectandscroll(t_table *pt,int index,int mode); 545 | 546 | //////////////////////////////////////////////////////////////////////////////// 547 | //////////////////////////////// NAME FUNCTIONS //////////////////////////////// 548 | 549 | // Types of names used in name functions. Note that higher-priority types have 550 | // smaller identifiers! 551 | #define NM_NONAME 0x00 // Undefined name 552 | #define NM_ANYNAME 0xFF // Name of any type 553 | // Names saved in the data file of module they appear. 554 | #define NM_PLUGCMD 0x30 // Plugin commands to execute at break 555 | #define NM_LABEL 0x31 // User-defined label 556 | #define NM_EXPORT 0x32 // Exported (global) name 557 | #define NM_IMPORT 0x33 // Imported name 558 | #define NM_LIBRARY 0x34 // Name from library or object file 559 | #define NM_CONST 0x35 // User-defined constant 560 | #define NM_COMMENT 0x36 // User-defined comment 561 | #define NM_LIBCOMM 0x37 // Comment from library or object file 562 | #define NM_BREAK 0x38 // Condition related with breakpoint 563 | #define NM_ARG 0x39 // Arguments decoded by analyzer 564 | #define NM_ANALYSE 0x3A // Comment added by analyzer 565 | #define NM_BREAKEXPR 0x3B // Expression related with breakpoint 566 | #define NM_BREAKEXPL 0x3C // Explanation related with breakpoint 567 | #define NM_ASSUME 0x3D // Assume function with known arguments 568 | #define NM_STRUCT 0x3E // Code structure decoded by analyzer 569 | #define NM_CASE 0x3F // Case description decoded by analyzer 570 | // Names saved in the data file of main module. 571 | #define NM_INSPECT 0x40 // Several last inspect expressions 572 | #define NM_WATCH 0x41 // Watch expressions 573 | #define NM_ASM 0x42 // Several last assembled strings 574 | #define NM_FINDASM 0x43 // Several last find assembler strings 575 | #define NM_LASTWATCH 0x48 // Several last watch expressions 576 | #define NM_SOURCE 0x49 // Several last source search strings 577 | #define NM_REFTXT 0x4A // Several last ref text search strings 578 | #define NM_GOTO 0x4B // Several last expressions to follow 579 | #define NM_GOTODUMP 0x4C // Several expressions to follow in Dump 580 | #define NM_TRPAUSE 0x4D // Several expressions to pause trace 581 | // Pseudonames. 582 | #define NM_IMCALL 0xFE // Intermodular call 583 | 584 | #define NMHISTORY 0x40 // Converts NM_xxx to type of init list 585 | 586 | extc int cdecl Insertname(ulong addr,int type,char *name); 587 | extc int cdecl Quickinsertname(ulong addr,int type,char *name); 588 | extc void cdecl Mergequicknames(void); 589 | extc void cdecl Discardquicknames(void); 590 | extc int cdecl Findname(ulong addr,int type,char *name); 591 | extc int cdecl Decodename(ulong addr,int type,char *name); 592 | extc ulong cdecl Findnextname(char *name); 593 | extc int cdecl Findlabel(ulong addr,char *name); 594 | extc void cdecl Deletenamerange(ulong addr0,ulong addr1,int type); 595 | extc int cdecl Findlabelbyname(char *name,ulong *addr, 596 | ulong addr0,ulong addr1); 597 | extc ulong cdecl Findimportbyname(char *name,ulong addr0,ulong addr1); 598 | extc int cdecl Demanglename(char *name,int type,char *undecorated); 599 | extc int cdecl Findsymbolicname(ulong addr,char *fname); 600 | 601 | //////////////////////////////////////////////////////////////////////////////// 602 | //////////////////////////// DISASSEMBLY FUNCTIONS ///////////////////////////// 603 | 604 | #define REG_EAX 0 // Indexes of general-purpose registers 605 | #define REG_ECX 1 // in t_reg. 606 | #define REG_EDX 2 607 | #define REG_EBX 3 608 | #define REG_ESP 4 609 | #define REG_EBP 5 610 | #define REG_ESI 6 611 | #define REG_EDI 7 612 | 613 | #define SEG_UNDEF -1 614 | #define SEG_ES 0 // Indexes of segment/selector registers 615 | #define SEG_CS 1 // in t_reg. 616 | #define SEG_SS 2 617 | #define SEG_DS 3 618 | #define SEG_FS 4 619 | #define SEG_GS 5 620 | 621 | // Selected items in register window. 622 | #define RS_NONE 0x0000 // No selection 623 | #define RS_INT 0x0010 // General-purpose 32-bit registers 624 | #define RS_EIP 0x0020 // EIP (instruction pointer) 625 | #define RS_FLG 0x0030 // 1-bit decoded flags 626 | #define RS_SEG 0x0040 // Segment (selector) registers 627 | #define RS_EFL 0x0050 // 32-bit flag register 628 | #define RS_TAG 0x0060 // FPU register tag 629 | #define RS_FPU 0x0070 // 80-bit FPU registers 630 | #define RS_FST 0x0080 // FPU status 631 | #define RS_FCO 0x0090 // FPU condition bits 632 | #define RS_FER 0x00A0 // FPU error bits 633 | #define RS_FCW 0x00B0 // FPU control word 634 | #define RS_FPR 0x00C0 // FPU precision fields 635 | #define RS_FEM 0x00D0 // FPU error mask bits 636 | #define RS_MMX 0x00E0 // MMX registers 637 | #define RS_3DN 0x00F0 // 3DNow! registers 638 | #define RS_SSE 0x0100 // SSE registers 639 | #define RS_CSR 0x0110 // SSE MXCSR register 640 | #define RS_CSB 0x0120 // SSE MXCSR bits 641 | #define RS_CPR 0x0130 // SSE rounding control 642 | #define RS_ERR 0x0140 // Last thread error 643 | 644 | #define RS_GROUP 0x01F0 // Mask to extract group of registers 645 | #define RS_INDEX 0x000F // Mask to extract index of register 646 | 647 | #define NREGSTACK 32 // Length of stack trace buffer 648 | #define MAXCALSIZE 8 // Max length of CALL without prefixes 649 | 650 | #define INT3 0xCC // Code of 1-byte breakpoint 651 | #define NOP 0x90 // Code of 1-byte NOP command 652 | #define TRAPFLAG 0x00000100 // Trap flag in CPU flag register 653 | 654 | #define C_TYPEMASK 0xF0 // Mask for command type 655 | #define C_CMD 0x00 // Ordinary instruction 656 | #define C_PSH 0x10 // PUSH instruction 657 | #define C_POP 0x20 // POP instruction 658 | #define C_MMX 0x30 // MMX instruction 659 | #define C_FLT 0x40 // FPU instruction 660 | #define C_JMP 0x50 // JUMP instruction 661 | #define C_JMC 0x60 // Conditional JUMP instruction 662 | #define C_CAL 0x70 // CALL instruction 663 | #define C_RET 0x80 // RET instruction 664 | #define C_FLG 0x90 // Changes system flags 665 | #define C_RTF 0xA0 // C_JMP and C_FLG simultaneously 666 | #define C_REP 0xB0 // Instruction with REPxx prefix 667 | #define C_PRI 0xC0 // Privileged instruction 668 | #define C_SSE 0xD0 // SSE instruction 669 | #define C_NOW 0xE0 // 3DNow! instruction 670 | #define C_BAD 0xF0 // Unrecognized command 671 | #define C_RARE 0x08 // Rare command, seldom used in programs 672 | #define C_SIZEMASK 0x07 // MMX data size or special flag 673 | #define C_EXPL 0x01 // (non-MMX) Specify explicit memory size 674 | 675 | #define C_DANGER95 0x01 // Command is dangerous under Win95/98 676 | #define C_DANGER 0x03 // Command is dangerous everywhere 677 | #define C_DANGERLOCK 0x07 // Dangerous with LOCK prefix 678 | 679 | #define DEC_TYPEMASK 0x1F // Type of memory byte 680 | #define DEC_UNKNOWN 0x00 // Unknown type 681 | #define DEC_BYTE 0x01 // Accessed as byte 682 | #define DEC_WORD 0x02 // Accessed as short 683 | #define DEC_NEXTDATA 0x03 // Subsequent byte of data 684 | #define DEC_DWORD 0x04 // Accessed as long 685 | #define DEC_FLOAT4 0x05 // Accessed as float 686 | #define DEC_FWORD 0x06 // Accessed as descriptor/long pointer 687 | #define DEC_FLOAT8 0x07 // Accessed as double 688 | #define DEC_QWORD 0x08 // Accessed as 8-byte integer 689 | #define DEC_FLOAT10 0x09 // Accessed as long double 690 | #define DEC_TBYTE 0x0A // Accessed as 10-byte integer 691 | #define DEC_STRING 0x0B // Zero-terminated ASCII string 692 | #define DEC_UNICODE 0x0C // Zero-terminated UNICODE string 693 | #define DEC_3DNOW 0x0D // Accessed as 3Dnow operand 694 | #define DEC_SSE 0x0E // Accessed as SSE operand 695 | #define DEC_TEXT 0x10 // For use in t_result only 696 | #define DEC_BYTESW 0x11 // Accessed as byte index to switch 697 | #define DEC_NEXTCODE 0x13 // Subsequent byte of command 698 | #define DEC_COMMAND 0x1D // First byte of command 699 | #define DEC_JMPDEST 0x1E // Jump destination 700 | #define DEC_CALLDEST 0x1F // Call (and maybe jump) destination 701 | #define DEC_PROCMASK 0x60 // Procedure analysis 702 | #define DEC_PROC 0x20 // Start of procedure 703 | #define DEC_PBODY 0x40 // Body of procedure 704 | #define DEC_PEND 0x60 // End of procedure 705 | #define DEC_CHECKED 0x80 // Byte was analysed 706 | #define DEC_SIGNED 0x100 // For use in t_result only 707 | 708 | #define DISASM_SIZE 0 // Determine command size only 709 | #define DISASM_DATA 1 // Determine size and analysis data 710 | #define DISASM_TRACE 2 // Trace integer registers 711 | #define DISASM_FILE 3 // Disassembly, no symbols/registers 712 | #define DISASM_CODE 4 // Disassembly, registers undefined 713 | #define DISASM_ALL 5 // Complete disassembly 714 | #define DISASM_RTRACE 6 // Disassemble with run-trace registers 715 | 716 | #define DISASM_MODE 0x0000000F // Mask to extract disassembling mode 717 | #define DISASM_HILITE 0x000F0000 // Mask to extract highlighting mode 718 | #define DISASM_HLSHIFT 16 // Shift to extract highlighting mode 719 | 720 | // Warnings issued by Disasm(): 721 | #define DAW_FARADDR 0x0001 // Command is a far jump, call or return 722 | #define DAW_SEGMENT 0x0002 // Command loads segment register 723 | #define DAW_PRIV 0x0004 // Privileged command 724 | #define DAW_IO 0x0008 // I/O command 725 | #define DAW_SHIFT 0x0010 // Shift constant out of range 1..31 726 | #define DAW_PREFIX 0x0020 // Superfluous prefix 727 | #define DAW_LOCK 0x0040 // Command has LOCK prefix 728 | #define DAW_STACK 0x0080 // Unaligned stack operation 729 | #define DAW_DANGER95 0x1000 // May mess up Win95/98 if executed 730 | #define DAW_DANGEROUS 0x3000 // May mess up any OS if executed 731 | 732 | #define RST_INVALID 0 // Register undefined 733 | #define RST_VALUE 1 // Register contains regdata 734 | #define RST_VFIXUP 2 // Reg contains regdata that is fixup 735 | #define RST_INDIRECT 3 // Register contains [regdata] 736 | 737 | #define NREGSTACK 32 // Length of stack trace buffer 738 | 739 | typedef struct t_reg { // Excerpt from context 740 | int modified; // Some regs modified, update context 741 | int modifiedbyuser; // Among modified, some modified by user 742 | int singlestep; // Type of single step, SS_xxx 743 | ulong r[8]; // EAX,ECX,EDX,EBX,ESP,EBP,ESI,EDI 744 | ulong ip; // Instruction pointer (EIP) 745 | ulong flags; // Flags 746 | int top; // Index of top-of-stack 747 | long double f[8]; // Float registers, f[top] - top of stack 748 | char tag[8]; // Float tags (0x3 - empty register) 749 | ulong fst; // FPU status word 750 | ulong fcw; // FPU control word 751 | ulong s[6]; // Segment registers ES,CS,SS,DS,FS,GS 752 | ulong base[6]; // Segment bases 753 | ulong limit[6]; // Segment limits 754 | char big[6]; // Default size (0-16, 1-32 bit) 755 | ulong dr6; // Debug register DR6 756 | ulong threadid; // ID of thread that owns registers 757 | ulong lasterror; // Last thread error or 0xFFFFFFFF 758 | int ssevalid; // Whether SSE registers valid 759 | int ssemodified; // Whether SSE registers modified 760 | char ssereg[8][16]; // SSE registers 761 | ulong mxcsr; // SSE control and status register 762 | int selected; // Reports selected register to plugin 763 | ulong drlin[4]; // Debug registers DR0..DR3 764 | ulong dr7; // Debug register DR7 765 | } t_reg; 766 | 767 | typedef struct t_operand { // Full decription of command's operand 768 | char optype; // DEC_xxx (mem) or DECR_xxx (reg,const) 769 | char opsize; // Size of operand 770 | char regscale[8]; // Scales of registers 771 | char seg; // Segment register 772 | ulong opconst; // Constant 773 | } t_operand; 774 | 775 | typedef struct t_disasm { // Results of disassembling 776 | ulong ip; // Instrucion pointer 777 | char dump[TEXTLEN]; // Hexadecimal dump of the command 778 | char result[TEXTLEN]; // Disassembled command 779 | char comment[TEXTLEN]; // Brief comment 780 | char opinfo[3][TEXTLEN]; // Comments to command's operands 781 | int cmdtype; // One of C_xxx 782 | int memtype; // Type of addressed variable in memory 783 | int nprefix; // Number of prefixes 784 | int indexed; // Address contains register(s) 785 | ulong jmpconst; // Constant jump address 786 | ulong jmptable; // Possible address of switch table 787 | ulong adrconst; // Constant part of address 788 | ulong immconst; // Immediate constant 789 | int zeroconst; // Whether contains zero constant 790 | int fixupoffset; // Possible offset of 32-bit fixups 791 | int fixupsize; // Possible total size of fixups or 0 792 | ulong jmpaddr; // Destination of jump/call/return 793 | int condition; // 0xFF:unconditional, 0:false, 1:true 794 | int error; // Error while disassembling command 795 | int warnings; // Combination of DAW_xxx 796 | int optype[3]; // Type of operand (extended set DEC_xxx) 797 | int opsize[3]; // Size of operand, bytes 798 | int opgood[3]; // Whether address and data valid 799 | ulong opaddr[3]; // Address if memory, index if register 800 | ulong opdata[3]; // Actual value (only integer operands) 801 | t_operand op[3]; // Full description of operand 802 | ulong regdata[8]; // Registers after command is executed 803 | int regstatus[8]; // Status of registers, one of RST_xxx 804 | ulong addrdata; // Traced memory address 805 | int addrstatus; // Status of addrdata, one of RST_xxx 806 | ulong regstack[NREGSTACK]; // Stack tracing buffer 807 | int rststatus[NREGSTACK]; // Status of stack items 808 | int nregstack; // Number of items in stack trace buffer 809 | ulong reserved[29]; // Reserved for plugin compatibility 810 | } t_disasm; 811 | 812 | extc ulong cdecl Disasm(uchar *src,ulong srcsize,ulong srcip,uchar *srcdec, 813 | t_disasm *disasm,int disasmmode,ulong threadid); 814 | extc ulong cdecl Disassembleback(uchar *block,ulong base,ulong size, 815 | ulong ip,int n,int usedec); 816 | extc ulong cdecl Disassembleforward(uchar *block,ulong base,ulong size, 817 | ulong ip,int n,int usedec); 818 | extc int cdecl Issuspicious(char *cmd,ulong size,ulong ip, 819 | ulong threadid,t_reg *preg,char *s); 820 | extc int cdecl Isfilling(ulong offset,char *data,ulong size,ulong align); 821 | 822 | //////////////////////////////////////////////////////////////////////////////// 823 | ////////////////////////////// ASSEMBLY FUNCTIONS ////////////////////////////// 824 | 825 | extc int cdecl Assemble(char *cmd,ulong ip,t_asmmodel *model,int attempt, 826 | int constsize,char *errtext); 827 | extc int cdecl Checkcondition(int code,ulong flags); 828 | 829 | //////////////////////////////////////////////////////////////////////////////// 830 | ///////////////////////////////// EXPRESSIONS ////////////////////////////////// 831 | 832 | typedef struct t_result { // Result of expression's evaluation 833 | int type; // Type of expression, DEC(R)_xxx 834 | int dtype; // Type of data, DEC_xxx 835 | union { 836 | uchar data[10]; // Binary form of expression's value 837 | ulong u; // Value as unsigned integer 838 | long l; // Value as signed integer 839 | long double f; }; // Value as 80-bit float 840 | union { 841 | char value[TEXTLEN]; // ASCII form of expression's value 842 | wchar_t wvalue[TEXTLEN/2]; }; // UNICODE form of expression's value 843 | ulong lvaddr; // Address of lvalue or NULL 844 | } t_result; 845 | 846 | extc int cdecl Expression(t_result *result,char *expression,int a,int b, 847 | uchar *data,ulong database,ulong datasize,ulong threadid); 848 | 849 | //////////////////////////////////////////////////////////////////////////////// 850 | /////////////////////////////// THREAD FUNCTIONS /////////////////////////////// 851 | 852 | typedef struct t_thread { // Information about active threads 853 | ulong threadid; // Thread identifier 854 | ulong dummy; // Always 1 855 | ulong type; // Service information, TY_xxx 856 | HANDLE thread; // Thread handle 857 | ulong datablock; // Per-thread data block 858 | ulong entry; // Thread entry point 859 | ulong stacktop; // Working variable of Listmemory() 860 | ulong stackbottom; // Working variable of Listmemory() 861 | CONTEXT context; // Actual context of the thread 862 | t_reg reg; // Actual contents of registers 863 | int regvalid; // Whether reg is valid 864 | t_reg oldreg; // Previous contents of registers 865 | int oldregvalid; // Whether oldreg is valid 866 | int suspendcount; // Suspension count (may be negative) 867 | long usertime; // Time in user mode, 1/10th ms, or -1 868 | long systime; // Time in system mode, 1/10th ms, or -1 869 | ulong reserved[16]; // Reserved for future compatibility 870 | } t_thread; 871 | 872 | extc HWND cdecl Createthreadwindow(void); 873 | extc t_thread* cdecl Findthread(ulong threadid); 874 | extc int cdecl Decodethreadname(char *s,ulong threadid,int mode); 875 | extc ulong cdecl Getcputhreadid(void); 876 | extc ulong cdecl Runsinglethread(ulong threadid); 877 | extc void cdecl Restoreallthreads(void); 878 | 879 | 880 | //////////////////////////////////////////////////////////////////////////////// 881 | /////////////////////////////// MEMORY FUNCTIONS /////////////////////////////// 882 | 883 | // Mode bits recognized by Readmemory() and Writememory(). 884 | #define MM_RESTORE 0x01 // Restore or remove INT3 breakpoints 885 | #define MM_SILENT 0x02 // Don't display error message 886 | #define MM_DELANAL 0x04 // Delete analysis from the memory 887 | 888 | #define MM_RESILENT (MM_RESTORE|MM_SILENT) 889 | 890 | typedef struct t_memory { // Memory block descriptor 891 | ulong base; // Base address of memory block 892 | ulong size; // Size of block 893 | ulong type; // Service information, TY_xxx 894 | ulong owner; // Address of owner of the memory 895 | ulong initaccess; // Initial read/write access 896 | ulong access; // Actual status and read/write access 897 | ulong threadid; // Block belongs to this thread or 0 898 | char sect[SHORTLEN]; // Name of module section 899 | uchar *copy; // Copy used in CPU window or NULL 900 | ulong reserved[8]; // Reserved for plugin compatibility 901 | } t_memory; 902 | 903 | typedef struct t_heap { // Heap block descriptor 904 | ulong base; // Base address of heap block 905 | ulong size; // Size of heap block 906 | ulong type; // Service information, TY_xxx 907 | ulong parent; // Handle of heap descriptor block 908 | } t_heap; 909 | 910 | extc int cdecl Listmemory(void); 911 | extc t_memory* cdecl Findmemory(ulong addr); 912 | extc int cdecl Guardmemory(ulong base,ulong size,int guard); 913 | extc void cdecl Havecopyofmemory(uchar *copy,ulong base,ulong size); 914 | extc ulong cdecl Readmemory(void *buf,ulong addr,ulong size,int mode); 915 | extc ulong cdecl Writememory(void *buf,ulong addr,ulong size,int mode); 916 | extc ulong cdecl Readcommand(ulong ip,char *cmd); 917 | 918 | //////////////////////////////////////////////////////////////////////////////// 919 | /////////////////////////////// MODULE FUNCTIONS /////////////////////////////// 920 | 921 | #define NVERS 32 // Max allowed length of file version 922 | 923 | // Types of recognized jumps. 924 | #define JT_JUMP 0 // Unconditional jump 925 | #define JT_COND 1 // Conditional jump 926 | #define JT_SWITCH 2 // Jump via switch table 927 | 928 | typedef struct t_ahint { // User-supplied hint for analysis 929 | ulong addr; // Hint address 930 | ulong size; // Hint size 931 | ulong type; // Hint type, bits from DEC_TYPEMASK 932 | } t_ahint; 933 | 934 | typedef struct t_stringtable { // Pointers to string resources 935 | ulong name; // Name of block of strings 936 | ulong language; // Language identifier 937 | ulong addr; // Address of block in memory 938 | ulong size; // Size of block in memory 939 | } t_stringtable; 940 | 941 | typedef struct t_fixup { 942 | ulong base; // Address of fixup 943 | ulong size; // Size of fixup (usually 2 or 4 bytes) 944 | } t_fixup; 945 | 946 | typedef struct t_symvar { // Symbolic variable from debug data 947 | int next; // Index of next variable in chain or -1 948 | ushort kind; // Kind of variable 949 | union { 950 | ulong type; // Type of variable 951 | ulong regs; }; // Registers in optvar 952 | union { 953 | ulong addr; // Address or description of registers 954 | long offset; }; // Offset for EBP-relative data 955 | ulong size; // Size of variable or optvar data 956 | int optvar; // Index of optvar chain or -1 957 | ulong nameaddr; // NM_DEBUG address of var's name 958 | } t_symvar; 959 | 960 | typedef struct t_jdest { // Element of jump data 961 | char type; // Type of jump, one of JT_xxx 962 | ulong from; // Jump source 963 | ulong to; // Jump destination 964 | } t_jdest; 965 | 966 | typedef struct t_module { // Executable module descriptor 967 | ulong base; // Base address of module 968 | ulong size; // Size occupied by module 969 | ulong type; // Service information, TY_xxx 970 | ulong codebase; // Base address of module code block 971 | ulong codesize; // Size of module code block 972 | ulong resbase; // Base address of resources 973 | ulong ressize; // Size of resources 974 | t_stringtable *stringtable; // Pointers to string resources or NULL 975 | int nstringtable; // Actual number of used stringtable 976 | int maxstringtable; // Actual number of allocated stringtable 977 | ulong entry; // Address of or NULL 978 | ulong database; // Base address of module data block 979 | ulong idatatable; // Base address of import data table 980 | ulong idatabase; // Base address of import data block 981 | ulong edatatable; // Base address of export data table 982 | ulong edatasize; // Size of export data table 983 | ulong reloctable; // Base address of relocation table 984 | ulong relocsize; // Size of relocation table 985 | char name[SHORTLEN]; // Short name of the module 986 | char path[MAX_PATH]; // Full name of the module 987 | int nsect; // Number of sections in the module 988 | IMAGE_SECTION_HEADER *sect; // Copy of section headers from file 989 | ulong headersize; // Total size of headers in executable 990 | ulong fixupbase; // Base of image in executable file 991 | int nfixup; // Number of fixups in executable 992 | t_fixup *fixup; // Extracted fixups or NULL 993 | char *codedec; // Decoded code features or NULL 994 | ulong codecrc; // Code CRC for actual decoding 995 | char *hittrace; // Hit tracing data or NULL 996 | char *hittracecopy; // Copy of INT3-substituted code 997 | char *datadec; // Decoded data features or NULL 998 | t_table namelist; // List of module names 999 | t_symvar *symvar; // Descriptions of symbolic variables 1000 | int nsymvar; // Actual number of elements in symvar 1001 | int maxsymvar; // Maximal number of elements in symvar 1002 | char *globaltypes; // Global types from debug info 1003 | ulong mainentry; // Address of WinMain() etc. in dbg data 1004 | ulong realsfxentry; // Entry of packed code or NULL 1005 | int updatenamelist; // Request to update namelist 1006 | ulong origcodesize; // Original size of module code block 1007 | ulong sfxbase; // Base of memory block with SFX 1008 | ulong sfxsize; // Size of memory block with SFX 1009 | int issystemdll; // Whether system DLL 1010 | int processed; // 0: not processed, 1: good, -1: bad 1011 | int dbghelpsym; // 1: symbols loaded by dbghelp.dll 1012 | char version[NVERS]; // Version of executable file 1013 | t_jdest *jddata; // Recognized jumps within the module 1014 | int njddata; // Number of recognized jumps 1015 | ulong reserved[15]; // Reserved for plugin compatibility 1016 | } t_module; 1017 | 1018 | extc t_module* cdecl Findmodule(ulong addr); 1019 | extc t_fixup* cdecl Findfixup(t_module *pmod,ulong addr); 1020 | extc uchar* cdecl Finddecode(ulong addr,ulong *psize); 1021 | extc ulong cdecl Findfileoffset(t_module *pmod,ulong addr); 1022 | extc int cdecl Decoderange(ulong addr,ulong size,char *s); 1023 | extc int cdecl Analysecode(t_module *pm); 1024 | 1025 | //////////////////////////////////////////////////////////////////////////////// 1026 | ///////////////////////////////////// DUMP ///////////////////////////////////// 1027 | 1028 | // Standard dump types. 1029 | #define DU_ESCAPABLE 0x20000L // Create escapable dump window 1030 | #define DU_BACKUP 0x10000L // Bit indicates that backup is displayed 1031 | #define DU_TYPE 0x0F000L // Mask for dump type 1032 | #define DU_COUNT 0x00FF0L // Mask for number of items/line 1033 | #define DU_SIZE 0x0000FL // Mask for size of single item 1034 | 1035 | #define DU_UNDEF 0x00000L // Undefined dump type 1036 | #define DU_HEXTEXT 0x01000L // Hexadecimal dump with ASCII text 1037 | #define DU_TEXT 0x02000L // Character dump 1038 | #define DU_UNICODE 0x03000L // Unicode dump 1039 | #define DU_INT 0x04000L // Integer signed dump 1040 | #define DU_UINT 0x05000L // Integer unsigned dump 1041 | #define DU_IHEX 0x06000L // Integer hexadecimal dump 1042 | #define DU_FLOAT 0x07000L // Floating-point dump 1043 | #define DU_ADDR 0x08000L // Address dump 1044 | #define DU_DISASM 0x09000L // Disassembly 1045 | #define DU_HEXUNI 0x0A000L // Hexadecimal dump with UNICODE text 1046 | #define DU_ADRASC 0x0B000L // Address dump with ASCII text 1047 | #define DU_ADRUNI 0x0C000L // Address dump with UNICODE text 1048 | #define DU_SPEC 0x0D000L // Special decoding 1049 | 1050 | // Standard menu types. 1051 | #define MT_BACKUP 0x0001 // Backup, Undo 1052 | #define MT_COPY 0x0002 // Copy to clipboard 1053 | #define MT_EDIT 0x0004 // Edit, Modify, Assemble 1054 | #define MT_SEARCH 0x0008 // Search, Next 1055 | #define MT_DHISTORY 0x0010 // Previous, Next in history 1056 | 1057 | typedef ulong SPECFUNC(char *,ulong,ulong,ulong,t_disasm *,int); 1058 | 1059 | typedef struct t_dump { // Current status of dump window 1060 | t_table table; // Treat dump window as custom table 1061 | int dimmed; // Draw in lowcolor if nonzero 1062 | ulong threadid; // Use decoding and registers if not 0 1063 | int dumptype; // Current dump type, DU_xxx+count+size 1064 | SPECFUNC *specdump; // Decoder of DU_SPEC dump types 1065 | int menutype; // Standard menues, MT_xxx 1066 | int itemwidth; // Length of displayed item, characters 1067 | int showstackframes; // Show stack frames in address dump 1068 | int showstacklocals; // Show names of locals in stack 1069 | int commentmode; // 0: comment, 1: source, 2: profile 1070 | char filename[MAX_PATH]; // Name of displayed or backup file 1071 | ulong base; // Start of memory block or file 1072 | ulong size; // Size of memory block or file 1073 | ulong addr; // Address of first displayed byte 1074 | ulong lastaddr; // Address of last displayed byte + 1 1075 | ulong sel0; // Address of first selected byte 1076 | ulong sel1; // Last selected byte (not included!) 1077 | ulong startsel; // Start of last selection 1078 | int captured; // Mouse is captured by dump 1079 | ulong reladdr; // Addresses relative to this 1080 | char relname[SHORTLEN]; // Symbol for relative zero address base 1081 | uchar *filecopy; // Copy of the file or NULL 1082 | uchar *backup; // Old backup of memory/file or NULL 1083 | int runtraceoffset; // Offset back in run trace 1084 | ulong reserved[8]; // Reserved for the future extentions 1085 | } t_dump; 1086 | 1087 | //////////////////////////////////////////////////////////////////////////////// 1088 | /////////////////////////////// WINDOW FUNCTIONS /////////////////////////////// 1089 | 1090 | #define WM_USER_MENU (WM_USER+101) // Activate context-sensitive menu 1091 | #define WM_USER_SCR (WM_USER+102) // Redraw scroll(s) 1092 | #define WM_USER_SAVE (WM_USER+103) // Save data to disk 1093 | #define WM_USER_VABS (WM_USER+104) // Scroll contents of window by lines 1094 | #define WM_USER_VREL (WM_USER+105) // Scroll contents of window by percent 1095 | #define WM_USER_VBYTE (WM_USER+106) // Scroll contents of window by bytes 1096 | #define WM_USER_STS (WM_USER+107) // Start selection in window 1097 | #define WM_USER_CNTS (WM_USER+108) // Continue selection in window 1098 | #define WM_USER_CHGS (WM_USER+109) // Move single-line selection 1099 | #define WM_USER_BAR (WM_USER+110) // Message from bar segment as button 1100 | #define WM_USER_DBLCLK (WM_USER+111) // Doubleclick in column 1101 | #define WM_USER_SIZE (WM_USER+112) // Resize children in CPU window 1102 | #define WM_USER_FOCUS (WM_USER+113) // Set focus to child of CPU window 1103 | #define WM_USER_FILE (WM_USER+114) // Change state of file dump 1104 | #define WM_USER_HERE (WM_USER+115) // Query presence list 1105 | #define WM_USER_CHALL (WM_USER+116) // Redraw (almost) everything 1106 | #define WM_USER_CHMEM (WM_USER+117) // Range of debuggee's memory changed 1107 | #define WM_USER_CHREG (WM_USER+118) // Debuggee's register(s) changed 1108 | #define WM_USER_CHNAM (WM_USER+119) // Redraw name tables 1109 | #define WM_USER_MOUSE (WM_USER+120) // Check mouse coordinates 1110 | #define WM_USER_KEY (WM_USER+121) // Emulate WM_KEYDOWN 1111 | #define WM_USER_SYSKEY (WM_USER+122) // Emulate WM_SYSKEYDOWN 1112 | 1113 | // Constants used for scrolling and selection. 1114 | #define MAXTRACK 16384 // Maximal scroll of user-drawn table 1115 | #define MOVETOP 0x7FFFFFFFL // Move selection to top of table 1116 | #define MOVEBOTTOM 0x7FFFFFFEL // Move selection to bottom of table 1117 | 1118 | #define CONT_BROADCAST 0x0000 // Continue sending msg to other windows 1119 | #define STOP_BROADCAST 0x1234 // Stop sending message to other windows 1120 | 1121 | // Dumpbackup() actions. 1122 | #define BKUP_CREATE 1 // Create or update backup copy 1123 | #define BKUP_VIEWDATA 2 // View original data 1124 | #define BKUP_VIEWCOPY 3 // View backup copy 1125 | #define BKUP_LOADCOPY 4 // Read backup copy from file 1126 | #define BKUP_SAVEDATA 5 // Save original data to file 1127 | #define BKUP_SAVECOPY 6 // Save backup copy to file 1128 | #define BKUP_DELETE 7 // Delete backup copy 1129 | 1130 | extc int cdecl Registerotclass(char *classname, 1131 | char *iconname,WNDPROC classproc); 1132 | extc HWND cdecl Newtablewindow(t_table *pt,int nlines,int maxcolumns, 1133 | char *winclass,char *wintitle); 1134 | extc HWND cdecl Quicktablewindow(t_table *pt,int nlines,int maxcolumns, 1135 | char *winclass,char *wintitle); 1136 | extc HWND cdecl Createdumpwindow(char *name,ulong base,ulong size, 1137 | ulong addr,int type,SPECFUNC *specdump); 1138 | extc void cdecl Setdumptype(t_dump *pd,int dumptype); 1139 | extc void cdecl Dumpbackup(t_dump *pd,int action); 1140 | extc int cdecl Broadcast(UINT msg,WPARAM wp,LPARAM lp); 1141 | 1142 | //////////////////////////////////////////////////////////////////////////////// 1143 | ////////////////////////// DATA CONVERSION FUNCTIONS /////////////////////////// 1144 | 1145 | extc ulong cdecl Compress(uchar *bufin,ulong nbufin, 1146 | uchar *bufout,ulong nbufout); 1147 | extc ulong cdecl Getoriginaldatasize(char *bufin,ulong nbufin); 1148 | extc ulong cdecl Decompress(uchar *bufin,ulong nbufin, 1149 | uchar *bufout,ulong nbufout); 1150 | extc ulong cdecl Calculatecrc(uchar *copy,ulong base,ulong size, 1151 | t_module *pmod,ulong fixupoffset); 1152 | 1153 | //////////////////////////////////////////////////////////////////////////////// 1154 | //////////////////////////// REFERENCES AND SEARCH ///////////////////////////// 1155 | 1156 | typedef struct t_ref { // Description of reference 1157 | ulong addr; // Address of reference 1158 | ulong size; // 1: single command, otherwise size 1159 | ulong type; // Type of reference, TY_xxx 1160 | ulong dest; // Destination of call 1161 | } t_ref; 1162 | 1163 | extc int cdecl Findreferences(ulong base,ulong size,ulong addr0,ulong addr1, 1164 | ulong origin,int recurseonjump,char *title); 1165 | extc int cdecl Findstrings(ulong base,ulong size,ulong origin,char *title); 1166 | extc int cdecl Findalldllcalls(t_dump *pd,ulong origin,char *title); 1167 | extc int cdecl Findallcommands(t_dump *pd,t_asmmodel *model, 1168 | ulong origin,char *title); 1169 | extc int cdecl Findallsequences(t_dump *pd,t_extmodel model[NSEQ][NMODELS], 1170 | ulong origin,char *title); 1171 | extc ulong cdecl Walkreference(int dir); 1172 | extc ulong cdecl Walkreferenceex(int dir,ulong *size); 1173 | 1174 | //////////////////////////////////////////////////////////////////////////////// 1175 | //////////////////////// BREAKPOINT AND TRACE FUNCTIONS //////////////////////// 1176 | 1177 | #define MEMBP_READ 0x0001 // Memory breakpoint on read 1178 | #define MEMBP_WRITE 0x0002 // Memory breakpoint on write 1179 | #define MEMBP_SFX 0x1000 // Skip self-extraction 1180 | 1181 | // Bits of module hit trace buffer. 1182 | #define TR_HIT 0x01 // Command was executed during trace 1183 | #define TR_SET 0x02 // Code INT3 is in memory, copy valid 1184 | #define TR_RTSKIP 0x20 // Disable run trace on command 1185 | #define TR_RTRACE 0x40 // Force run trace on command 1186 | #define TR_TRACE 0x80 // Command is included in trace 1187 | 1188 | #define HB_FREE 0 // Breakpoint is not used 1189 | #define HB_CODE 1 // Active on command execution 1190 | #define HB_ACCESS 2 // Active on read/write access 1191 | #define HB_WRITE 3 // Active on write access 1192 | #define HB_IO 4 // Active on port I/O 1193 | #define HB_ONESHOT 5 // One-shot on command execution 1194 | #define HB_STOPAN 6 // One-shot on command and stop 1195 | #define HB_TEMP 7 // Temporary on command execution 1196 | 1197 | // Parameter mode of function Modifyhittrace(). 1198 | #define ATR_ADD 1 // Add trace to buffer 1199 | #define ATR_ADDPROC 2 // Add only recognized procedures 1200 | #define ATR_RESET 3 // Mark range as not traced 1201 | #define ATR_REMOVE 4 // Remove range and breakpoints 1202 | #define ATR_REMOVEALL 5 // Destroy range and breakpoints 1203 | #define ATR_RESTORE 6 // Restore breakpoints 1204 | #define ATR_RTRADD 7 // Add trace and force run trace 1205 | #define ATR_RTRJUMPS 8 // Add trace and run trace jumps only 1206 | #define ATR_RTRENTRY 9 // Add trace and run trace entries only 1207 | #define ATR_RTREMOVE 10 // Remove trace from range 1208 | #define ATR_RTSKIP 11 // Skip when run tracing 1209 | 1210 | // Breakpoint conditions (first byte of NM_BREAKEXPR associated with 1211 | // breakpoint). Strange settings of bits COND_NOBREAK and COND_BRKALWAYS are 1212 | // for backward compatibility with version 1.0. If both bits are 0, program 1213 | // pauses when condition is met. If both bits are set, COND_NOBREAK has higher 1214 | // priority. 1215 | #define COND_NOBREAK 0x01 // Don't break on this breakpoint 1216 | #define COND_LOGTRUE 0x02 // Log expression if condition true 1217 | #define COND_LOGALWAYS 0x04 // Log expression each pass 1218 | #define COND_ARGTRUE 0x08 // Log arguments if condition true 1219 | #define COND_ARGALWAYS 0x10 // Log arguments each pass 1220 | #define COND_BRKALWAYS 0x20 // Always break on this breakpoint 1221 | #define COND_MASK 0x3F // Mask for conditional break type bits 1222 | #define COND_FILLING 0x40 // Used to assure that byte is non-zero 1223 | 1224 | typedef struct t_bpoint { // Description of INT3 breakpoint 1225 | ulong addr; // Address of breakpoint 1226 | ulong dummy; // Always 1 1227 | ulong type; // Type of breakpoint, TY_xxx 1228 | char cmd; // Old value of command 1229 | ulong passcount; // Actual pass count 1230 | } t_bpoint; 1231 | 1232 | typedef struct t_hardbpoint { // Description of hardware breakpoint 1233 | ulong addr; // Base address of hardware breakpoint 1234 | int size; // Size of hardware breakpoint 1235 | int type; // Type of breakpoint, one of HB_xxx 1236 | ulong reserved[4]; // Reserved for the future 1237 | } t_hardbpoint; 1238 | 1239 | extc int cdecl Setbreakpoint(ulong addr,ulong type,uchar cmd); 1240 | extc int cdecl Setbreakpointext(ulong addr,ulong type,char cmd, 1241 | ulong passcount); 1242 | extc int cdecl Manualbreakpoint(ulong addr, 1243 | int key,int shiftkey,ulong nametype,int font); 1244 | extc void cdecl Deletebreakpoints(ulong addr0,ulong addr1,int silent); 1245 | extc ulong cdecl Getbreakpointtype(ulong addr); 1246 | extc ulong cdecl Getbreakpointtypecount(ulong addr,ulong *passcount); 1247 | extc ulong cdecl Getnextbreakpoint(ulong addr,ulong *type,int *cmd); 1248 | extc void cdecl Tempbreakpoint(ulong addr,int mode); 1249 | extc int cdecl Hardbreakpoints(int closeondelete); 1250 | extc int cdecl Sethardwarebreakpoint(ulong addr,int size,int type); 1251 | extc int cdecl Deletehardwarebreakpoint(int index); 1252 | extc int cdecl Deletehardwarebreakbyaddr(ulong addr); 1253 | extc int cdecl Setmembreakpoint(int type,ulong addr,ulong size); 1254 | extc uchar* cdecl Findhittrace(ulong addr,uchar **ptracecopy,ulong *psize); 1255 | extc int cdecl Modifyhittrace(ulong addr0,ulong addr1,int mode); 1256 | extc ulong cdecl Isretaddr(ulong retaddr,ulong *procaddr); 1257 | extc HWND cdecl Creatertracewindow(void); 1258 | extc void cdecl Settracecondition(char *cond,int onsuspicious, 1259 | ulong in0,ulong in1,ulong out0,ulong out1); 1260 | extc void cdecl Settracecount(ulong count); 1261 | extc void cdecl Settracepauseoncommands(char *cmdset); 1262 | extc int cdecl Startruntrace(t_reg *preg); 1263 | extc void cdecl Deleteruntrace(void); 1264 | extc int cdecl Runtracesize(void); 1265 | extc int cdecl Findprevruntraceip(ulong ip,int startback); 1266 | extc int cdecl Findnextruntraceip(ulong ip,int startback); 1267 | extc int cdecl Getruntraceregisters(int nback,t_reg *preg, 1268 | t_reg *pold,char *cmd,char *comment); 1269 | extc int cdecl Getruntraceprofile(ulong addr,ulong size,ulong *profile); 1270 | extc void cdecl Scrollruntracewindow(int back); 1271 | extc HWND cdecl Createprofilewindow(ulong base,ulong size); 1272 | 1273 | 1274 | //////////////////////////////////////////////////////////////////////////////// 1275 | //////////////////////////////// CODE INJECTION //////////////////////////////// 1276 | 1277 | typedef int INJECTANSWER(char *data,ulong datasize,ulong parm2); 1278 | 1279 | typedef struct t_inject { // Description of injected code 1280 | ulong codesize; // Size of code, including INT3 1281 | char *code; // Pointer to code 1282 | int stacksize; // Stack size to save 1283 | int datatype; // 0: in/out, 1: in, 2: out 1284 | } t_inject; 1285 | 1286 | extc int cdecl Injectcode(ulong threadid,t_inject *inject,char *data, 1287 | ulong datasize,ulong parm1,ulong parm2, 1288 | INJECTANSWER *answerfunc); 1289 | 1290 | 1291 | //////////////////////////////////////////////////////////////////////////////// 1292 | //////////////////////////// CPU-SPECIFIC FUNCTIONS //////////////////////////// 1293 | 1294 | // Setcpu modes. 1295 | #define CPU_ASMHIST 0x00001 // Add change to Disassembler history 1296 | #define CPU_ASMCENTER 0x00004 // Make address in the middle of window 1297 | #define CPU_ASMFOCUS 0x00008 // Move focus to Disassembler 1298 | #define CPU_DUMPHIST 0x00010 // Add change to Dump history 1299 | #define CPU_DUMPFIRST 0x00020 // Make address the first byte in Dump 1300 | #define CPU_DUMPFOCUS 0x00080 // Move focus to Dump 1301 | #define CPU_REGAUTO 0x00100 // Automatically switch to FPU/MMX/3DNow! 1302 | #define CPU_RUNTRACE 0x00200 // Show run trace data at offset asmaddr 1303 | #define CPU_STACKFOCUS 0x00800 // Move focus to Stack 1304 | #define CPU_NOCREATE 0x04000 // Don't create CPU window if absent 1305 | #define CPU_REDRAW 0x08000 // Redraw CPU window immediately 1306 | #define CPU_NOFOCUS 0x10000 // Don't assign focus to main window 1307 | 1308 | extc void cdecl Setcpu(ulong threadid,ulong asmaddr, 1309 | ulong dumpaddr,ulong stackaddr,int mode); 1310 | extc void cdecl Setdisasm(ulong asmaddr,ulong selsize,int mode); 1311 | extc void cdecl Redrawdisassembler(void); 1312 | extc void cdecl Getdisassemblerrange(ulong *pbase,ulong *psize); 1313 | extc ulong cdecl Findprocbegin(ulong addr); 1314 | extc ulong cdecl Findprocend(ulong addr); 1315 | extc ulong cdecl Findprevproc(ulong addr); 1316 | extc ulong cdecl Findnextproc(ulong addr); 1317 | extc int cdecl Getproclimits(ulong addr,ulong *start,ulong *end); 1318 | extc void cdecl Sendshortcut(int where,ulong addr, 1319 | int msg,int ctrl,int shift,int vkcode); 1320 | 1321 | //////////////////////////////////////////////////////////////////////////////// 1322 | /////////////////////////////// PROCESS CONTROL //////////////////////////////// 1323 | 1324 | // Parameter stepmode in call to Go(). 1325 | #define STEP_SAME 0 // Same action as on previous call 1326 | #define STEP_RUN 1 // Run program 1327 | #define STEP_OVER 2 // Step over 1328 | #define STEP_IN 3 // Step in 1329 | #define STEP_SKIP 4 // Skip sequence 1330 | 1331 | typedef enum t_status { // Thread/process status 1332 | STAT_NONE=0, // Thread/process is empty 1333 | STAT_STOPPED, // Thread/process suspended 1334 | STAT_EVENT, // Processing debug event, process paused 1335 | STAT_RUNNING, // Thread/process running 1336 | STAT_FINISHED, // Process finished 1337 | STAT_CLOSING // Process is requested to terminate 1338 | } t_status; 1339 | 1340 | extc t_status cdecl Getstatus(void); 1341 | extc int cdecl Go(ulong threadid,ulong tilladdr,int stepmode, 1342 | int givechance,int backupregs); 1343 | extc int cdecl Suspendprocess(int processevents); 1344 | 1345 | //////////////////////////////////////////////////////////////////////////////// 1346 | //////////////////////////// DECODING OF ARGUMENTS ///////////////////////////// 1347 | 1348 | #define DASC_TEST 0 // Test whether a string 1349 | #define DASC_NOHEX 1 // Test, print nothing if not a string 1350 | #define DASC_ASCII 2 // Force ASCII 1351 | #define DASC_PASCAL 3 // Force Pascal 1352 | 1353 | extc uchar* cdecl Findknownfunction(ulong addr,int direct, 1354 | int level,char *fname); 1355 | extc int cdecl Decodeknownargument(ulong addr,uchar *arg,ulong value, 1356 | int valid,char *s,char *mask,uchar *pset[]); 1357 | extc char cdecl *Findunknownfunction(ulong ip,char *code,char *dec, 1358 | ulong size,char *fname); 1359 | extc int cdecl Decodeascii(ulong value,char *s,int len,int mode); 1360 | extc int cdecl Decodeunicode(ulong value,char *s,int len); 1361 | 1362 | //////////////////////////////////////////////////////////////////////////////// 1363 | ///////////////////////////// SOURCE CODE SUPPORT ////////////////////////////// 1364 | 1365 | #define FIRST_CODE_LINE 0xFFFFFFFF // First available source line 1366 | 1367 | typedef struct t_sourceline { // Source line descriptor 1368 | ulong addr; // Start address of corresponding code 1369 | ulong size; // Code size 1370 | ulong srcname; // Index of source name (as NM_DEBUG) 1371 | ulong line; // 0-based line number 1372 | } t_sourceline; 1373 | 1374 | extc HWND cdecl Showsourcefromaddress(ulong addr,int show); 1375 | extc int cdecl Getresourcestring(t_module *pm,ulong id,char *s); 1376 | extc t_sourceline* cdecl Getlinefromaddress(ulong addr); 1377 | extc ulong cdecl Getaddressfromline(ulong addr0,ulong addr1, 1378 | char *path,ulong line); 1379 | extc int cdecl Getsourcefilelimits(ulong nameaddr, 1380 | ulong *addr0,ulong *addr1); 1381 | extc int cdecl Decodefullvarname(t_module *pmod,t_symvar *psym, 1382 | int offset,char *name); 1383 | extc int cdecl Getbprelname(t_module *pmod,ulong addr,long offset, 1384 | char *s,int nsymb); 1385 | 1386 | //////////////////////////////////////////////////////////////////////////////// 1387 | //////////////////////////////// WATCH SUPPORT ///////////////////////////////// 1388 | 1389 | extc HWND cdecl Createwatchwindow(void); 1390 | extc int cdecl Deletewatch(int indexone); 1391 | extc int cdecl Insertwatch(int indexone,char *text); 1392 | extc int cdecl Getwatch(int indexone,char *text); 1393 | 1394 | //////////////////////////////////////////////////////////////////////////////// 1395 | ////////////////////////// WINDOWS-SPECIFIC FUNCTIONS ////////////////////////// 1396 | 1397 | #define MAXNEST 32 // Max allowed code structure nesting 1398 | 1399 | typedef struct t_window { // Description of window 1400 | ulong hwnd; // Window's handle 1401 | ulong dummy; // Must be 1 1402 | ulong type; // Type of window, TY_xxx 1403 | ulong parenthw; // Handle of parent or 0 1404 | ulong winproc; // Address of WinProc or 0 1405 | ulong threadid; // ID of the owning thread 1406 | ulong exstyle; // Extended style 1407 | ulong style; // Style 1408 | ulong id; // Identifier 1409 | ulong classproc; // Address of default (class) WinProc 1410 | int child; // Index of next child 1411 | int level; // Level in genealogy (0: topmost) 1412 | int sibling; // Index of next sibling 1413 | int byparent; // Index when sorted by parent 1414 | char title[TEXTLEN]; // Window's title 1415 | char classname[TEXTLEN]; // Class name 1416 | char tree[MAXNEST]; // Tree display 1417 | } t_window; 1418 | 1419 | extc HWND cdecl Createwinwindow(void); 1420 | 1421 | 1422 | //////////////////////////////////////////////////////////////////////////////// 1423 | /////////////////////////////////// PATCHES //////////////////////////////////// 1424 | 1425 | typedef struct t_patch { 1426 | ulong addr; // Base address of patch in memory 1427 | ulong size; // Size of patch, bytes 1428 | ulong type; // Type of patch, set of TY_xxx 1429 | char orig[TEXTLEN]; // Original code 1430 | char mod[TEXTLEN]; // Patched code 1431 | } t_patch; 1432 | 1433 | extc HWND cdecl Createpatchwindow(void); 1434 | 1435 | 1436 | //////////////////////////////////////////////////////////////////////////////// 1437 | ////////////////////////// PLUGIN-SPECIFIC FUNCTIONS /////////////////////////// 1438 | 1439 | // Parameters of Plugingetvalue(). 1440 | #define VAL_HINST 1 // Current program instance 1441 | #define VAL_HWMAIN 2 // Handle of the main window 1442 | #define VAL_HWCLIENT 3 // Handle of the MDI client window 1443 | #define VAL_NCOLORS 4 // Number of common colors 1444 | #define VAL_COLORS 5 // RGB values of common colors 1445 | #define VAL_BRUSHES 6 // Handles of common color brushes 1446 | #define VAL_PENS 7 // Handles of common color pens 1447 | #define VAL_NFONTS 8 // Number of common fonts 1448 | #define VAL_FONTS 9 // Handles of common fonts 1449 | #define VAL_FONTNAMES 10 // Internal font names 1450 | #define VAL_FONTWIDTHS 11 // Average widths of common fonts 1451 | #define VAL_FONTHEIGHTS 12 // Average heigths of common fonts 1452 | #define VAL_NFIXFONTS 13 // Actual number of fixed-pitch fonts 1453 | #define VAL_DEFFONT 14 // Index of default font 1454 | #define VAL_NSCHEMES 15 // Number of color schemes 1455 | #define VAL_SCHEMES 16 // Color schemes 1456 | #define VAL_DEFSCHEME 17 // Index of default colour scheme 1457 | #define VAL_DEFHSCROLL 18 // Default horizontal scroll 1458 | #define VAL_RESTOREWINDOWPOS 19 // Restore window positions from .ini 1459 | #define VAL_HPROCESS 20 // Handle of Debuggee 1460 | #define VAL_PROCESSID 21 // Process ID of Debuggee 1461 | #define VAL_HMAINTHREAD 22 // Handle of main thread 1462 | #define VAL_MAINTHREADID 23 // Thread ID of main thread 1463 | #define VAL_MAINBASE 24 // Base of main module in the process 1464 | #define VAL_PROCESSNAME 25 // Name of the active process 1465 | #define VAL_EXEFILENAME 26 // Name of the main debugged file 1466 | #define VAL_CURRENTDIR 27 // Current directory for debugged process 1467 | #define VAL_SYSTEMDIR 28 // Windows system directory 1468 | #define VAL_DECODEANYIP 29 // Decode registers dependless on EIP 1469 | #define VAL_PASCALSTRINGS 30 // Decode Pascal-style string constants 1470 | #define VAL_ONLYASCII 31 // Only printable ASCII chars in dump 1471 | #define VAL_DIACRITICALS 32 // Allow diacritical symbols in strings 1472 | #define VAL_GLOBALSEARCH 33 // Search from the beginning of block 1473 | #define VAL_ALIGNEDSEARCH 34 // Search aligned to item's size 1474 | #define VAL_IGNORECASE 35 // Ignore case in string search 1475 | #define VAL_SEARCHMARGIN 36 // Floating search allows error margin 1476 | #define VAL_KEEPSELSIZE 37 // Keep size of hex edit selection 1477 | #define VAL_MMXDISPLAY 38 // MMX display mode in dialog 1478 | #define VAL_WINDOWFONT 39 // Use calling window's font in dialog 1479 | #define VAL_TABSTOPS 40 // Distance between tab stops 1480 | #define VAL_MODULES 41 // Table of modules (.EXE and .DLL) 1481 | #define VAL_MEMORY 42 // Table of allocated memory blocks 1482 | #define VAL_THREADS 43 // Table of active threads 1483 | #define VAL_BREAKPOINTS 44 // Table of active breakpoints 1484 | #define VAL_REFERENCES 45 // Table with found references 1485 | #define VAL_SOURCELIST 46 // Table of source files 1486 | #define VAL_WATCHES 47 // Table of watches 1487 | #define VAL_CPUFEATURES 50 // CPU feature bits 1488 | #define VAL_TRACEFILE 51 // Handle of run trace log file 1489 | #define VAL_ALIGNDIALOGS 52 // Whether to align dialogs 1490 | #define VAL_CPUDASM 53 // Dump descriptor of CPU Disassembler 1491 | #define VAL_CPUDDUMP 54 // Dump descriptor of CPU Dump 1492 | #define VAL_CPUDSTACK 55 // Dump descriptor of CPU Stack 1493 | #define VAL_APIHELP 56 // Name of selected API help file 1494 | #define VAL_HARDBP 57 // Whether hardware breakpoints enabled 1495 | #define VAL_PATCHES 58 // Table of patches 1496 | #define VAL_HINTS 59 // Sorted data with analysis hints 1497 | 1498 | extc int cdecl Registerpluginclass(char *classname,char *iconname, 1499 | HINSTANCE dllinst,WNDPROC classproc); 1500 | extc void cdecl Unregisterpluginclass(char *classname); 1501 | extc int cdecl Pluginwriteinttoini(HINSTANCE dllinst,char *key,int value); 1502 | extc int cdecl Pluginwritestringtoini(HINSTANCE dllinst,char *key,char *s); 1503 | extc int cdecl Pluginreadintfromini(HINSTANCE dllinst,char *key,int def); 1504 | extc int cdecl Pluginreadstringfromini(HINSTANCE dllinst,char *key, 1505 | char *s,char *def); 1506 | extc int cdecl Pluginsaverecord(ulong tag,ulong size,void *data); 1507 | extc int cdecl Plugingetvalue(int type); 1508 | 1509 | //////////////////////////////////////////////////////////////////////////////// 1510 | ////////////////////// EXPORTED PLUGIN CALLBACK FUNCTIONS ////////////////////// 1511 | 1512 | // Origins of standard OllyDbg windows as passed to plugin. In parenthesis is 1513 | // the type of item you get in ODBG_Pluginmenu(), ODBG_Pluginaction() and 1514 | // ODBG_Pluginshortcut(). Note that this item can be NULL! 1515 | #define PM_MAIN 0 // Main window (NULL) 1516 | #define PM_DUMP 10 // Any Dump window (t_dump*) 1517 | #define PM_MODULES 11 // Modules window (t_module*) 1518 | #define PM_MEMORY 12 // Memory window (t_memory*) 1519 | #define PM_THREADS 13 // Threads window (t_thread*) 1520 | #define PM_BREAKPOINTS 14 // Breakpoints window (t_bpoint*) 1521 | #define PM_REFERENCES 15 // References window (t_ref*) 1522 | #define PM_RTRACE 16 // Run trace window (int*) 1523 | #define PM_WATCHES 17 // Watches window (1-based index) 1524 | #define PM_WINDOWS 18 // Windows window (t_window*) 1525 | #define PM_DISASM 31 // CPU Disassembler (t_dump*) 1526 | #define PM_CPUDUMP 32 // CPU Dump (t_dump*) 1527 | #define PM_CPUSTACK 33 // CPU Stack (t_dump*) 1528 | #define PM_CPUREGS 34 // CPU Registers (t_reg*) 1529 | 1530 | // Reasons why debugged application was paused, as a first argument in call to 1531 | // ODBG_Paused(), ODBG_Pausedex() and ODBG_Plugincmd(). 1532 | #define PP_MAIN 0x0003 // Mask to extract main reason 1533 | #define PP_EVENT 0x0000 // Paused on debugging event 1534 | #define PP_PAUSE 0x0001 // Paused on user's request 1535 | #define PP_TERMINATED 0x0002 // Application terminated 1536 | // Extended reasons in ODBG_Pausedex(). 1537 | #define PP_BYPROGRAM 0x0004 // Debugging event caused by program 1538 | #define PP_INT3BREAK 0x0010 // INT3 breakpoint 1539 | #define PP_MEMBREAK 0x0020 // Memory breakpoint 1540 | #define PP_HWBREAK 0x0040 // Hardware breakpoint 1541 | #define PP_SINGLESTEP 0x0080 // Single-step trap 1542 | #define PP_EXCEPTION 0x0100 // Exception, like division by 0 1543 | #define PP_ACCESS 0x0200 // Access violation 1544 | #define PP_GUARDED 0x0400 // Guarded page 1545 | 1546 | // Record tags in .udd files. 1547 | #define MI_SIGNATURE 0x00646F4DL // Module info signature 1548 | #define MI_VERSION 0x7265560AL // OllyDbg version 1549 | #define MI_FILENAME 0x6C69460AL // Record with full name of executable 1550 | #define MI_FILESIZE 0x7A69530AL // Record with file size 1551 | #define MI_TIMESTAMP 0x7473540AL // Record with timestamp file data 1552 | #define MI_SFXENTRY 0x6566530AL // Real entry of SFX-able module 1553 | #define MI_PATCH 0x7461500AL // Record with patch data 1554 | #define MI_USER 0x0073550AL // Record with user-defined label/comment 1555 | #define MI_PROCDATA 0x6372500AL // Record with procedure data 1556 | #define MI_SWDATA 0x6977530AL // Record with switch data 1557 | #define MI_CALLFINT 0x6966430AL // Record with internal call 1558 | #define MI_CALLFMOD 0x6D66430AL // Record with intermodular call 1559 | #define MI_CALLFABS 0x6166430AL // Record with absolute call 1560 | #define MI_INT3BREAK 0x7470420AL // Record with breakpoint data 1561 | #define MI_INT3BRKC 0x6370420AL // Record with checked breakpoint data 1562 | #define MI_HDWRBREAK 0x7262480AL // Record with hardware breakpoint data 1563 | #define MI_JDDATA 0x74644A0AL // Record with all module jump data 1564 | #define MI_ANALYSIS 0x616E410AL // Record with analysis data 1565 | #define MI_ANALPACK 0x636E410AL // Record with compressed analysis data 1566 | #define MI_AHINT 0x7468410AL // Record with analysis hint data 1567 | #define MI_TRACE 0x6172540AL // Record with trace data 1568 | #define MI_TRACEPACK 0x6372540AL // Record with compressed trace data 1569 | #define MI_CODECRC 0x7263430AL // Record with CRC of code for analysis 1570 | #define MI_SAVEAREA 0x6176530AL // Record with general-purpose save area 1571 | #define MI_END 0x646E450AL // End of module info data 1572 | // Tags reserved for 3rd-party plugins. 1573 | #define MI_WINJUG 0x67754A0AL // WindowJuggler by EsseEmme 1574 | #define MI_WINJU1 0x31754A0AL 1575 | #define MI_WINJU2 0x32754A0AL 1576 | #define MI_WINJU3 0x33754A0AL 1577 | #define MI_APPST 0x73614F0AL // OllyAppStarter by Homunculus 1578 | 1579 | // Prototypes for plugin callback functions. 1580 | extc int _export cdecl ODBG_Plugindata(char shortname[32]); 1581 | extc int _export cdecl ODBG_Plugininit(int ollydbgversion,HWND hw, 1582 | ulong *features); 1583 | extc void _export cdecl ODBG_Pluginmainloop(DEBUG_EVENT *debugevent); 1584 | extc void _export cdecl ODBG_Pluginsaveudd(t_module *pmod,int ismainmodule); 1585 | extc int _export cdecl ODBG_Pluginuddrecord(t_module *pmod,int ismainmodule, 1586 | ulong tag,ulong size,void *data); 1587 | extc int _export cdecl ODBG_Pluginmenu(int origin,char data[4096],void *item); 1588 | extc void _export cdecl ODBG_Pluginaction(int origin,int action,void *item); 1589 | extc int _export cdecl ODBG_Pluginshortcut( 1590 | int origin,int ctrl,int alt,int shift,int key, 1591 | void *item); 1592 | extc void _export cdecl ODBG_Pluginreset(void); 1593 | extc int _export cdecl ODBG_Pluginclose(void); 1594 | extc void _export cdecl ODBG_Plugindestroy(void); 1595 | extc int _export cdecl ODBG_Paused(int reason,t_reg *reg); 1596 | extc int _export cdecl ODBG_Pausedex(int reasonex,int dummy,t_reg *reg, 1597 | DEBUG_EVENT *debugevent); 1598 | extc int _export cdecl ODBG_Plugincmd(int reason,t_reg *reg,char *cmd); 1599 | 1600 | -------------------------------------------------------------------------------- /src/hooks.c: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | // OllyHeapTrace - A Heap Tracer plugin for OllyDbg 3 | // By Stephen Fewer of Harmony Security (www.harmonysecurity.com) 4 | // Copyright (c) 2008 Stephen Fewer of Harmony Security 5 | //--------------------------------------------------------------------------- 6 | #include 7 | //#include 8 | 9 | #include "hooks.h" 10 | 11 | extern DWORD dwProcessHeap; 12 | 13 | struct HEAPFLAGS 14 | { 15 | DWORD dwValue; 16 | const char * cpName; 17 | }; 18 | //--------------------------------------------------------------------------- 19 | struct HEAPFLAGS flags[] = { 20 | 21 | { HEAP_GENERATE_EXCEPTIONS, "HEAP_GENERATE_EXCEPTIONS" }, 22 | { HEAP_NO_SERIALIZE, "HEAP_NO_SERIALIZE" }, 23 | { HEAP_ZERO_MEMORY, "HEAP_ZERO_MEMORY" }, 24 | 25 | { NULL, NULL } 26 | }; 27 | //--------------------------------------------------------------------------- 28 | VOID ResolveHeapFlags( DWORD dwFlags, char * cpOutput ) 29 | { 30 | int iCount = 0, i = 0; 31 | memset( cpOutput, 0, MAX_PATH ); 32 | 33 | while( flags[i].cpName != NULL ) 34 | { 35 | if( dwFlags & flags[i].dwValue == flags[i].dwValue ) 36 | { 37 | if( iCount > 0 ) 38 | strcat( cpOutput, " | " ); 39 | strcat( cpOutput, flags[i].cpName ); 40 | iCount++; 41 | } 42 | i++; 43 | } 44 | 45 | if( iCount == 0 ) 46 | strcat( cpOutput, "0" ); 47 | } 48 | //--------------------------------------------------------------------------- 49 | BOOL DefaultDWORD_Return( LPLOGDATA pLogData, t_reg * pRegisters ) 50 | { 51 | snprintf( pLogData->cReturnMessage, BUFFER_SIZE, "0x%.8X", pRegisters->r[REG_EAX] ); 52 | return TRUE; 53 | } 54 | //--------------------------------------------------------------------------- 55 | BOOL DefaultINT_Return( LPLOGDATA pLogData, t_reg * pRegisters ) 56 | { 57 | snprintf( pLogData->cReturnMessage, BUFFER_SIZE, "%d", pRegisters->r[REG_EAX] ); 58 | return TRUE; 59 | } 60 | //--------------------------------------------------------------------------- 61 | BOOL DefaultBOOL_Return( LPLOGDATA pLogData, t_reg * pRegisters ) 62 | { 63 | snprintf( pLogData->cReturnMessage, BUFFER_SIZE, "%s", (pRegisters->r[REG_EAX] ? "TRUE" : "FALSE" ) ); 64 | return TRUE; 65 | } 66 | //--------------------------------------------------------------------------- 67 | BOOL RtlInitializeCriticalSection_Call( LPLOGDATA pLogData, t_reg * pRegisters ) 68 | { 69 | DWORD dwParameter; 70 | Readmemory( &dwParameter, pRegisters->r[REG_ESP]+4, 4, MM_SILENT ); 71 | snprintf( pLogData->cMessage, BUFFER_SIZE, "RtlInitializeCriticalSection( 0x%.8X )", dwParameter ); 72 | return TRUE; 73 | } 74 | //--------------------------------------------------------------------------- 75 | BOOL RtlDeleteCriticalSection_Call( LPLOGDATA pLogData, t_reg * pRegisters ) 76 | { 77 | DWORD dwParameter; 78 | Readmemory( &dwParameter, pRegisters->r[REG_ESP]+4, 4, MM_SILENT ); 79 | snprintf( pLogData->cMessage, BUFFER_SIZE, "RtlDeleteCriticalSection( 0x%.8X )", dwParameter ); 80 | return TRUE; 81 | } 82 | //--------------------------------------------------------------------------- 83 | BOOL RtlAllocateHeap_Call( LPLOGDATA pLogData, t_reg * pRegisters ) 84 | { 85 | char cFlagsOutput[MAX_PATH]; 86 | DWORD dwParameters[3]; 87 | Readmemory( &dwParameters, pRegisters->r[REG_ESP]+4, 12, MM_SILENT ); 88 | ResolveHeapFlags( dwParameters[1], (char *)&cFlagsOutput ); 89 | if( dwProcessHeap != NULL && dwParameters[0] == dwProcessHeap ) 90 | snprintf( pLogData->cMessage, BUFFER_SIZE, "RtlAllocateHeap( GetProcessHeap(), %s, %d )", cFlagsOutput, dwParameters[2] ); 91 | else 92 | snprintf( pLogData->cMessage, BUFFER_SIZE, "RtlAllocateHeap( 0x%.8X, %s, %d )", dwParameters[0], cFlagsOutput, dwParameters[2] ); 93 | pLogData->dwHeap = dwParameters[0]; 94 | pLogData->dwHeapBlockSize = dwParameters[2]; 95 | return TRUE; 96 | } 97 | //--------------------------------------------------------------------------- 98 | BOOL RtlAllocateHeap_Return( LPLOGDATA pLogData, t_reg * pRegisters ) 99 | { 100 | pLogData->dwHeapBlock = pRegisters->r[REG_EAX]; 101 | snprintf( pLogData->cReturnMessage, BUFFER_SIZE, "0x%.8X", pLogData->dwHeapBlock ); 102 | return TRUE; 103 | } 104 | //--------------------------------------------------------------------------- 105 | BOOL RtlReAllocateHeap_Call( LPLOGDATA pLogData, t_reg * pRegisters ) 106 | { 107 | char cFlagsOutput[MAX_PATH]; 108 | DWORD dwParameters[4]; 109 | Readmemory( &dwParameters, pRegisters->r[REG_ESP]+4, 16, MM_SILENT ); 110 | ResolveHeapFlags( dwParameters[1], (char *)&cFlagsOutput ); 111 | if( dwProcessHeap != NULL && dwParameters[0] == dwProcessHeap ) 112 | snprintf( pLogData->cMessage, BUFFER_SIZE, "RtlReAllocateHeap( GetProcessHeap(), %s, 0x%.8X, %d )", cFlagsOutput, dwParameters[2], dwParameters[3] ); 113 | else 114 | snprintf( pLogData->cMessage, BUFFER_SIZE, "RtlReAllocateHeap( 0x%.8X, %s, 0x%.8X, %d )", dwParameters[0], cFlagsOutput, dwParameters[2], dwParameters[3] ); 115 | pLogData->dwHeap = dwParameters[0]; 116 | pLogData->dwHeapBlockSize = dwParameters[3]; 117 | pLogData->dwHeapBlock = dwParameters[2]; 118 | return TRUE; 119 | } 120 | //--------------------------------------------------------------------------- 121 | BOOL RtlFreeHeap_Call( LPLOGDATA pLogData, t_reg * pRegisters ) 122 | { 123 | char cFlagsOutput[MAX_PATH]; 124 | DWORD dwParameters[3]; 125 | Readmemory( &dwParameters, pRegisters->r[REG_ESP]+4, 12, MM_SILENT ); 126 | ResolveHeapFlags( dwParameters[1], (char *)&cFlagsOutput ); 127 | if( dwProcessHeap != NULL && dwParameters[0] == dwProcessHeap ) 128 | snprintf( pLogData->cMessage, BUFFER_SIZE, "RtlFreeHeap( GetProcessHeap(), %s, 0x%.8X )", cFlagsOutput, dwParameters[2] ); 129 | else 130 | snprintf( pLogData->cMessage, BUFFER_SIZE, "RtlFreeHeap( 0x%.8X, %s, 0x%.8X )", dwParameters[0], cFlagsOutput, dwParameters[2] ); 131 | pLogData->dwHeap = dwParameters[0]; 132 | pLogData->dwHeapBlock = dwParameters[2]; 133 | return TRUE; 134 | } 135 | //--------------------------------------------------------------------------- 136 | BOOL RtlCreateHeap_Call( LPLOGDATA pLogData, t_reg * pRegisters ) 137 | { 138 | char cFlagsOutput[MAX_PATH]; 139 | DWORD dwParameters[3]; 140 | Readmemory( &dwParameters, pRegisters->r[REG_ESP]+4, 12, MM_SILENT ); 141 | ResolveHeapFlags( dwParameters[0], (char *)&cFlagsOutput ); 142 | snprintf( pLogData->cMessage, BUFFER_SIZE, "RtlCreateHeap( %s, %d, %d )", cFlagsOutput, dwParameters[1], dwParameters[2] ); 143 | return TRUE; 144 | } 145 | //--------------------------------------------------------------------------- 146 | BOOL RtlCreateHeap_Return( LPLOGDATA pLogData, t_reg * pRegisters ) 147 | { 148 | snprintf( pLogData->cReturnMessage, BUFFER_SIZE, "0x%.8X", pRegisters->r[REG_EAX] ); 149 | pLogData->dwHeap = pRegisters->r[REG_EAX]; 150 | return TRUE; 151 | } 152 | //--------------------------------------------------------------------------- 153 | BOOL GetProcessHeap_Call( LPLOGDATA pLogData, t_reg * pRegisters ) 154 | { 155 | snprintf( pLogData->cMessage, BUFFER_SIZE, "GetProcessHeap()" ); 156 | return TRUE; 157 | } 158 | //--------------------------------------------------------------------------- 159 | BOOL GetProcessHeap_Return( LPLOGDATA pLogData, t_reg * pRegisters ) 160 | { 161 | dwProcessHeap = pRegisters->r[REG_EAX]; 162 | snprintf( pLogData->cReturnMessage, BUFFER_SIZE, "0x%.8X", dwProcessHeap ); 163 | pLogData->dwHeap = dwProcessHeap; 164 | return TRUE; 165 | } 166 | //--------------------------------------------------------------------------- 167 | BOOL RtlDestroyHeap_Call( LPLOGDATA pLogData, t_reg * pRegisters ) 168 | { 169 | DWORD dwParameter; 170 | Readmemory( &dwParameter, pRegisters->r[REG_ESP]+4, 4, MM_SILENT ); 171 | if( dwProcessHeap != NULL && dwParameter == dwProcessHeap ) 172 | snprintf( pLogData->cMessage, BUFFER_SIZE, "RtlDestroyHeap( GetProcessHeap() )" ); 173 | else 174 | snprintf( pLogData->cMessage, BUFFER_SIZE, "RtlDestroyHeap( 0x%.8X )", dwParameter ); 175 | pLogData->dwHeap = dwParameter; 176 | return TRUE; 177 | } 178 | //--------------------------------------------------------------------------- 179 | BOOL RtlSizeHeap_Call( LPLOGDATA pLogData, t_reg * pRegisters ) 180 | { 181 | char cFlagsOutput[MAX_PATH]; 182 | DWORD dwParameters[3]; 183 | Readmemory( &dwParameters, pRegisters->r[REG_ESP]+4, 12, MM_SILENT ); 184 | ResolveHeapFlags( dwParameters[1], (char *)&cFlagsOutput ); 185 | if( dwProcessHeap != NULL && dwParameters[0] == dwProcessHeap ) 186 | snprintf( pLogData->cMessage, BUFFER_SIZE, "RtlSizeHeap( GetProcessHeap(), %s, 0x%.8X )", cFlagsOutput, dwParameters[2] ); 187 | else 188 | snprintf( pLogData->cMessage, BUFFER_SIZE, "RtlSizeHeap( 0x%.8X, %s, 0x%.8X )", dwParameters[0], cFlagsOutput, dwParameters[2] ); 189 | pLogData->dwHeap = dwParameters[0]; 190 | pLogData->dwHeapBlock = dwParameters[2]; 191 | return TRUE; 192 | } 193 | //--------------------------------------------------------------------------- 194 | 195 | -------------------------------------------------------------------------------- /src/hooks.h: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | // OllyHeapTrace - A Heap Tracer plugin for OllyDbg 3 | // By Stephen Fewer of Harmony Security (www.harmonysecurity.com) 4 | // Copyright (c) 2008 Stephen Fewer of Harmony Security 5 | //--------------------------------------------------------------------------- 6 | #ifndef HOOKS_H 7 | #define HOOKS_h 8 | 9 | #define WIN32_LEAN_AND_MEAN 10 | #include 11 | 12 | #include "Plugin.h" 13 | 14 | #pragma nopackwarning 15 | 16 | #define BUFFER_SIZE 256 17 | 18 | typedef struct _LOGDATA 19 | { 20 | DWORD dwAddress; 21 | DWORD dwSize; 22 | DWORD dwType; 23 | 24 | DWORD dwCallerAddress; 25 | DWORD dwThreadId; 26 | DWORD dwHeap; 27 | DWORD dwHeapBlock; 28 | DWORD dwHeapBlockSize; 29 | char cMessage[BUFFER_SIZE]; 30 | char cReturnMessage[BUFFER_SIZE]; 31 | BOOL bReturnMessageSet; 32 | int iHookIndex; 33 | 34 | } LOGDATA, * LPLOGDATA; 35 | 36 | typedef BOOL (* HOOK_FUNC)( LPLOGDATA pLogData, t_reg * pRegisters ); 37 | 38 | struct HOOK 39 | { 40 | const char * cpModuleName; 41 | const char * cpFunctionName; 42 | DWORD dwFunctionAddress; 43 | HOOK_FUNC handle_call; 44 | HOOK_FUNC handle_return; 45 | }; 46 | 47 | BOOL DefaultDWORD_Return( LPLOGDATA, t_reg * ); 48 | BOOL DefaultBOOL_Return( LPLOGDATA, t_reg * ); 49 | BOOL DefaultINT_Return( LPLOGDATA, t_reg * ); 50 | 51 | BOOL RtlInitializeCriticalSection_Call( LPLOGDATA, t_reg * ); 52 | BOOL RtlDeleteCriticalSection_Call( LPLOGDATA, t_reg * ); 53 | 54 | BOOL RtlAllocateHeap_Call( LPLOGDATA , t_reg * ); 55 | BOOL RtlAllocateHeap_Return( LPLOGDATA , t_reg * ); 56 | BOOL RtlReAllocateHeap_Call( LPLOGDATA , t_reg * ); 57 | BOOL RtlFreeHeap_Call( LPLOGDATA , t_reg * ); 58 | BOOL RtlCreateHeap_Call( LPLOGDATA , t_reg * ); 59 | BOOL RtlCreateHeap_Return( LPLOGDATA, t_reg * ); 60 | BOOL GetProcessHeap_Call( LPLOGDATA , t_reg * ); 61 | BOOL GetProcessHeap_Return( LPLOGDATA, t_reg * ); 62 | BOOL RtlDestroyHeap_Call( LPLOGDATA, t_reg * ); 63 | BOOL RtlSizeHeap_Call( LPLOGDATA, t_reg * ); 64 | 65 | #endif 66 | -------------------------------------------------------------------------------- /src/main.c: -------------------------------------------------------------------------------- 1 | //--------------------------------------------------------------------------- 2 | // OllyHeapTrace - A Heap Tracer plugin for OllyDbg 3 | // By Stephen Fewer of Harmony Security (www.harmonysecurity.com) 4 | // Copyright (c) 2008 Stephen Fewer of Harmony Security 5 | //--------------------------------------------------------------------------- 6 | #define WIN32_LEAN_AND_MEAN 7 | #include 8 | #include 9 | #include 10 | 11 | #include "hooks.h" 12 | #pragma nopackwarning 13 | //--------------------------------------------------------------------------- 14 | #pragma link ".\\bin\\OllyDbg.lib" 15 | //--------------------------------------------------------------------------- 16 | #define OLLYHT_NAME "OllyHeapTrace" 17 | #define OLLYHT_VERSION "1.1" 18 | #define OLLYHT_ABOUT "By Stephen Fewer of Harmony Security (www.harmonysecurity.com)" 19 | 20 | struct COLORS 21 | { 22 | BYTE bColor; 23 | DWORD dwHeap; 24 | }; 25 | 26 | struct COLORS colors[NCOLORS-1] = {0}; 27 | //--------------------------------------------------------------------------- 28 | struct HOOK hooks[] = { 29 | { "ntdll", "RtlAllocateHeap", NULL, RtlAllocateHeap_Call, RtlAllocateHeap_Return }, 30 | { "ntdll", "RtlFreeHeap", NULL, RtlFreeHeap_Call, DefaultBOOL_Return }, 31 | { "ntdll", "RtlCreateHeap", NULL, RtlCreateHeap_Call, RtlCreateHeap_Return }, 32 | { "ntdll", "RtlDestroyHeap", NULL, RtlDestroyHeap_Call, DefaultBOOL_Return }, 33 | { "ntdll", "RtlReAllocateHeap", NULL, RtlReAllocateHeap_Call, RtlAllocateHeap_Return }, 34 | { "ntdll", "RtlSizeHeap", NULL, RtlSizeHeap_Call, DefaultINT_Return }, 35 | { "ntdll", "RtlInitializeCriticalSection", NULL, RtlInitializeCriticalSection_Call, NULL }, 36 | { "ntdll", "RtlDeleteCriticalSection", NULL, RtlDeleteCriticalSection_Call, NULL }, 37 | 38 | { "kernel32", "GetProcessHeap", NULL, GetProcessHeap_Call, GetProcessHeap_Return }, 39 | 40 | { NULL, NULL, NULL, NULL, NULL } 41 | }; 42 | //--------------------------------------------------------------------------- 43 | HINSTANCE hDll = NULL; 44 | HANDLE hOllyWindow = NULL; 45 | volatile BOOL bEnabled = FALSE; 46 | char cLogWindowClass[32] = { 0 }; 47 | t_table logtable = { 0 }; 48 | 49 | volatile DWORD dwLogIndex = 0; 50 | //DWORD dwIgnoreHeaps[MAX_PATH] = {0}; 51 | DWORD dwProcessHeap = NULL; 52 | //--------------------------------------------------------------------------- 53 | int WINAPI DllEntryPoint( HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved ) 54 | { 55 | if( dwReason == DLL_PROCESS_ATTACH ) 56 | hDll = hInstance; 57 | return 1; 58 | } 59 | //--------------------------------------------------------------------------- 60 | int _export cdecl ODBG_Plugindata( char cShortname[32] ) 61 | { 62 | strcpy( cShortname, OLLYHT_NAME ); 63 | return PLUGIN_VERSION; 64 | } 65 | //--------------------------------------------------------------------------- 66 | BYTE GetColor( DWORD dwHeap ) 67 | { 68 | int i; 69 | for( i=0 ; idwHeap ); 90 | 91 | if( iColumn == 0 ) 92 | { 93 | *pSelect = DRAW_GRAY; 94 | i = Decodeaddress( pLogData->dwCallerAddress, 0, ADC_VALID, cpBuffer, BUFFER_SIZE, NULL ); 95 | if( i == 0 ) 96 | i = snprintf( cpBuffer, BUFFER_SIZE, "0x%.8X", pLogData->dwCallerAddress ); 97 | } 98 | else if( iColumn == 1 ) 99 | { 100 | *pSelect = DRAW_GRAY; 101 | i = snprintf( cpBuffer, BUFFER_SIZE, "0x%.8X", pLogData->dwThreadId ); 102 | } 103 | else if( iColumn == 2 ) 104 | { 105 | i = snprintf( cpBuffer, BUFFER_SIZE, "%s", pLogData->cMessage ); 106 | *pSelect = DRAW_MASK; 107 | memset( pMask, DRAW_DIRECT|bColor, i ); 108 | } 109 | else if( iColumn == 3 ) 110 | { 111 | if( strlen( pLogData->cReturnMessage ) > 0 ) 112 | { 113 | i = snprintf( cpBuffer, BUFFER_SIZE, "%s", pLogData->cReturnMessage ); 114 | *pSelect = DRAW_MASK; 115 | memset( pMask, DRAW_DIRECT|bColor, i ); 116 | } 117 | } 118 | return i; 119 | } 120 | //--------------------------------------------------------------------------- 121 | void CreateLogWindow( void ) 122 | { 123 | if( logtable.bar.nbar == 0 ) 124 | { 125 | logtable.bar.name[0] = "Caller"; 126 | logtable.bar.defdx[0] = 20; 127 | logtable.bar.mode[0] = BAR_NOSORT; 128 | 129 | logtable.bar.name[1] = "Thread"; 130 | logtable.bar.defdx[1] = 12; 131 | logtable.bar.mode[1] = BAR_NOSORT; 132 | 133 | logtable.bar.name[2] = "Function Call"; 134 | logtable.bar.defdx[2] = 64; 135 | logtable.bar.mode[2] = BAR_NOSORT; 136 | 137 | logtable.bar.name[3] = "Return Value"; 138 | logtable.bar.defdx[3] = 16; 139 | logtable.bar.mode[3] = BAR_NOSORT; 140 | 141 | logtable.bar.nbar = 4; 142 | logtable.mode = TABLE_COPYMENU|TABLE_APPMENU|TABLE_SAVEPOS|TABLE_ONTOP; 143 | logtable.drawfunc = LogWindowGetText; 144 | } 145 | Quicktablewindow( &logtable, 15, logtable.bar.nbar, cLogWindowClass, "OllyHeapTrace - Log" ); 146 | } 147 | //--------------------------------------------------------------------------- 148 | VOID HandleRightClick( HWND hw ) 149 | { 150 | LPLOGDATA pLogData; 151 | HMENU hMenu; 152 | int i; 153 | char cBuffer[BUFFER_SIZE]; 154 | 155 | hMenu = CreatePopupMenu(); 156 | pLogData = (LPLOGDATA)Getsortedbyselection( &(logtable.data), logtable.data.selected ); 157 | if( hMenu != NULL && pLogData != NULL ) 158 | { 159 | if( pLogData->dwHeap != NULL ) 160 | { 161 | snprintf( cBuffer, BUFFER_SIZE, "Delete trace for heap 0x%.8X", pLogData->dwHeap ); 162 | AppendMenu( hMenu, MF_STRING, 1, cBuffer ); 163 | 164 | snprintf( cBuffer, BUFFER_SIZE, "View dump of heap 0x%.8X", pLogData->dwHeap ); 165 | AppendMenu( hMenu, MF_STRING, 2, cBuffer ); 166 | 167 | if( pLogData->dwHeapBlock != NULL ) 168 | { 169 | snprintf( cBuffer, BUFFER_SIZE, "View dump of heap block 0x%.8X", pLogData->dwHeapBlock ); 170 | AppendMenu( hMenu, MF_STRING, 3, cBuffer ); 171 | } 172 | } 173 | 174 | } 175 | i = Tablefunction( &logtable, hw, WM_USER_MENU, 0, (LPARAM)hMenu ); 176 | if( hMenu != NULL ) 177 | DestroyMenu( hMenu ); 178 | 179 | if( i == 1 ) 180 | { 181 | DWORD dwHeap = pLogData->dwHeap; 182 | pLogData = (LPLOGDATA)logtable.data.data; 183 | for( i=0 ; idwHeap, 4096, 0, 0x01101, NULL ); 197 | } 198 | else if( i == 3 && pLogData->dwHeapBlock != NULL ) 199 | { 200 | if( pLogData->dwHeapBlockSize == NULL ) 201 | pLogData->dwHeapBlockSize = 4096; 202 | Createdumpwindow( "OllyHeapTrace - Dump Heap Block", pLogData->dwHeapBlock, pLogData->dwHeapBlockSize, 0, 0x01101, NULL ); 203 | //Createdumpwindow( "OllyHeapTrace - Dump Heap Block", pLogData->dwHeapBlock - 8, pLogData->dwHeapBlockSize + 8, 0, 0x01101, NULL ); 204 | } 205 | } 206 | //--------------------------------------------------------------------------- 207 | LRESULT CALLBACK LogWindowProc( HWND hw,UINT msg,WPARAM wp,LPARAM lp) 208 | { 209 | LPLOGDATA pLogData; 210 | 211 | switch( msg ) 212 | { 213 | case WM_DESTROY: 214 | case WM_MOUSEMOVE: 215 | case WM_LBUTTONDOWN: 216 | case WM_LBUTTONDBLCLK: 217 | case WM_LBUTTONUP: 218 | case WM_RBUTTONDOWN: 219 | case WM_RBUTTONDBLCLK: 220 | case WM_HSCROLL: 221 | case WM_VSCROLL: 222 | case WM_TIMER: 223 | case WM_SYSKEYDOWN: 224 | case WM_USER_SCR: 225 | case WM_USER_VABS: 226 | case WM_USER_VREL: 227 | case WM_USER_VBYTE: 228 | case WM_USER_STS: 229 | case WM_USER_CNTS: 230 | case WM_USER_CHGS: 231 | case WM_KEYDOWN: 232 | return Tablefunction( &logtable, hw, msg, wp, lp ); 233 | case WM_USER_MENU: 234 | HandleRightClick( hw ); 235 | return 0; 236 | case WM_USER_DBLCLK: 237 | pLogData = (LPLOGDATA)Getsortedbyselection( &(logtable.data), logtable.data.selected ); 238 | if ( pLogData != NULL ) 239 | Setcpu( 0, pLogData->dwCallerAddress, 0, 0, CPU_ASMHIST|CPU_ASMCENTER|CPU_ASMFOCUS ); 240 | return 1; 241 | case WM_USER_CHALL: 242 | case WM_USER_CHMEM: 243 | InvalidateRect( hw, NULL, FALSE ); 244 | return 0; 245 | case WM_PAINT: 246 | Painttable( hw, &logtable, LogWindowGetText ); 247 | return 0; 248 | default: break; 249 | } 250 | return DefMDIChildProc( hw, msg, wp, lp ); 251 | } 252 | //--------------------------------------------------------------------------- 253 | int _export cdecl ODBG_Plugininit( int iOllyVersion, HWND hWindow, DWORD * features ) 254 | { 255 | int i; 256 | if( iOllyVersion < PLUGIN_VERSION ) 257 | return -1; 258 | 259 | hOllyWindow = hWindow; 260 | 261 | bEnabled = FALSE; 262 | 263 | if( Createsorteddata( &(logtable.data), NULL, sizeof(LOGDATA), 64, NULL, NULL ) != 0 ) 264 | return -1; 265 | 266 | if( Registerpluginclass( cLogWindowClass, NULL, hDll, LogWindowProc ) < 0 ) 267 | { 268 | Destroysorteddata( &(logtable.data) ); 269 | return -1; 270 | } 271 | 272 | for( i=0 ; idata.data; 292 | for( i=0 ; idata.n ; i++ ) 293 | { 294 | if( strnicmp( cpName, m[i].name, SHORTLEN ) == 0 ) 295 | return &m[i]; 296 | } 297 | return NULL; 298 | } 299 | //--------------------------------------------------------------------------- 300 | VOID CreateBreakpoint( t_module * m, const char * cpName, DWORD * pAddress ) 301 | { 302 | if( Findlabelbyname( (char *)cpName, pAddress, m->codebase, (m->codebase + m->codesize) ) != NM_NONAME ) 303 | { 304 | if( Setbreakpoint( *pAddress, TY_ACTIVE, 0 ) == 0 ) 305 | return; 306 | } 307 | /* 308 | *pAddress = Findimportbyname( cpName, 0, 0x80000000 ); 309 | if( *pAddress != 0 ) 310 | { 311 | if( Setbreakpoint( *pAddress, TY_ACTIVE, 0 ) == 0 ) 312 | return; 313 | } 314 | */ 315 | //*pAddress = NULL; 316 | 317 | Addtolist( 0, 1, "%s: Failed to create breakpoint for %s.", OLLYHT_NAME, cpName ); 318 | //RaiseException( 1, 0, 0, NULL ); 319 | } 320 | //--------------------------------------------------------------------------- 321 | void DisableBreakpoints( BOOL bDisable ) 322 | { 323 | int i = 0; 324 | 325 | while( hooks[i].cpModuleName != NULL ) 326 | { 327 | if( hooks[i].dwFunctionAddress != NULL ) 328 | { 329 | if( bDisable ) 330 | Setbreakpoint( hooks[i].dwFunctionAddress, TY_DISABLED, 0 ); 331 | hooks[i].dwFunctionAddress = NULL; 332 | } 333 | i++; 334 | } 335 | } 336 | //--------------------------------------------------------------------------- 337 | BOOL EnableBreakpoints( void ) 338 | { 339 | BOOL bSuccess; 340 | t_module * m; 341 | int i = 0; 342 | t_table * modtable = (t_table *)Plugingetvalue( VAL_MODULES ); 343 | 344 | __try 345 | { 346 | while( hooks[i].cpModuleName != NULL ) 347 | { 348 | // fix case insensitive search!!! 349 | m = FindModule( modtable, hooks[i].cpModuleName ); 350 | if( m == NULL ) 351 | { 352 | Addtolist( 0, 1, "%s: Failed to find module %s.", OLLYHT_NAME, hooks[i].cpModuleName ); 353 | RaiseException( 2, 0, 0, NULL ); 354 | } 355 | CreateBreakpoint( m, hooks[i].cpFunctionName, &hooks[i].dwFunctionAddress ); 356 | i++; 357 | } 358 | bSuccess = TRUE; 359 | } 360 | __except( EXCEPTION_EXECUTE_HANDLER ) 361 | { 362 | //PEXCEPTION_POINTERS x = GetExceptionInformation(); 363 | //if( x->ExceptionCode == 1 ) 364 | //{ 365 | DisableBreakpoints( TRUE ); 366 | bSuccess = FALSE; 367 | Addtolist( 0, 1, "%s failed to enable required breakpoints.", OLLYHT_NAME ); 368 | // Addtolist( 0, 1, " Breakpoint for %s failed.", w->ExceptionInformation[0] ); 369 | //} 370 | } 371 | return bSuccess; 372 | } 373 | //--------------------------------------------------------------------------- 374 | void _export cdecl ODBG_Plugindestroy( void ) 375 | { 376 | //int i; 377 | //LPLOGDATA pLogData; 378 | bEnabled = FALSE; 379 | 380 | Unregisterpluginclass( cLogWindowClass ); 381 | 382 | /*pLogData = (LPLOGDATA)logtable.data.data; 383 | for( i=0 ; iip == hooks[i].dwFunctionAddress ) 478 | { 479 | pLogData = (LPLOGDATA)malloc( sizeof(LOGDATA) ); 480 | memset( pLogData, 0, sizeof(LOGDATA) ); 481 | pLogData->dwAddress = dwLogIndex++; 482 | pLogData->dwSize = 1; 483 | 484 | pLogData->iHookIndex = i; 485 | pLogData->dwThreadId = pDebugEvent->dwThreadId; 486 | 487 | Readmemory( &pLogData->dwCallerAddress, pRegisters->r[REG_ESP], 4, MM_SILENT ); 488 | 489 | if( hooks[i].handle_call != NULL ) 490 | hooks[i].handle_call( pLogData, pRegisters ); 491 | 492 | if( hooks[i].handle_return != NULL ) 493 | Setbreakpoint( pLogData->dwCallerAddress, TY_ONESHOT, 0 );//TY_ONESHOT//TY_ACTIVE 494 | 495 | Addsorteddata( &(logtable.data), pLogData ); 496 | bFound = TRUE; 497 | break; 498 | } 499 | i++; 500 | } 501 | 502 | if( !bFound ) 503 | { 504 | pLogData = (LPLOGDATA)logtable.data.data; 505 | for( i=0 ; iip == pLogData[i].dwCallerAddress && !pLogData[i].bReturnMessageSet ) 508 | { 509 | if( hooks[pLogData[i].iHookIndex].handle_return != NULL ) 510 | pLogData[i].bReturnMessageSet = hooks[pLogData[i].iHookIndex].handle_return( &pLogData[i], pRegisters ); 511 | bFound = TRUE; 512 | break; 513 | } 514 | } 515 | } 516 | 517 | if( bFound ) 518 | { 519 | Go( 0, 0, STEP_RUN, 1, 1 ); 520 | return 1; 521 | } 522 | 523 | return 0; 524 | } 525 | //--------------------------------------------------------------------------- 526 | 527 | --------------------------------------------------------------------------------