public
Last active

gdbinit74

  • Download Gist
gdbinit
1 2 3 4 5 6 7 8 9 10 11 12 13 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 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633
# INSTALL INSTRUCTIONS: save as ~/.gdbinit
#
# DESCRIPTION: A user-friendly gdb configuration file.
#
# REVISION : 7.4 (22/05/2011)
#
# CONTRIBUTORS: mammon_, elaine, pusillus, mong, zhang le, l0kit,
# truthix the cyberpunk, fG!, gln, dipswitch
#
# FEEDBACK: https://www.reverse-engineering.net
# The Linux Area
# Topic: "+HCU's .gdbinit Version 7.1 -- humble announce"
# http://reverse.put.as
#
# NOTES: 'help user' in gdb will list the commands/descriptions in this file
# 'context on' now enables auto-display of context screen
#
# MAC OS X NOTES: If you are using this on Mac OS X, you must either attach gdb to a process
# or launch gdb without any options and then load the binary file you want to analyse with "exec-file" option
# If you load the binary from the command line, like $gdb binary-name, this will not work as it should
# For more information, read it here http://reverse.put.as/2008/11/28/apples-gdb-bug/
#
# UPDATE: This bug can be fixed in gdb source. Refer to http://reverse.put.as/2009/08/10/fix-for-apples-gdb-bug-or-why-apple-forks-are-bad/
# and http://reverse.put.as/2009/08/26/gdb-patches/ (if you want the fixed binary for i386)
#
# CHANGELOG:
#
# Version 7.4 (22/05/2011)
# create-reg-snapshot and check-reg-snapshot allowes you to create a snapshot of the all the registers and later check them
# against the current onces and see the differences
# BUG: mmx, fpu change detection no work yet
# TODO: show locals now also allowes you to show the differences between now and then
 
# Autodetection via $rip now works I believe... only tested it for myself ofc
# colors verywhere! Now we need the program HIGHLIGHT though. For x86_64, mmx, fpu register highlighting download: http://pastebin.com/mQUCMbVY and replace it in /usr/share/highlight
# make stepi en nexti show what instruction was executed before the context
# locals is an alias for info locals
# make return show context aswell
#
# Version 7.3 (16/04/2010)
# Support for 64bits targets. Default is 32bits, you should modify the variable or use the 32bits or 64bits to choose the mode.
# I couldn't find another way to recognize the type of binary… Testing the register doesn't work that well.
# TODO: fix objectivec messages and stepo for 64bits
#
# Version 7.2.1 (24/11/2009)
# Another fix to stepo (0xFF92 missing)
#
# Version 7.2 (11/10/2009)
# Added the smallregisters function to create 16 and 8 bit versions from the registers EAX, EBX, ECX, EDX
# Revised and fixed all the dumpjump stuff, following Intel manuals. There were some errors (thx to rev who pointed the jle problem).
# Small fix to stepo command (missed a few call types)
#
# Version 7.1.7
# Added the possibility to modify what's displayed with the context window. You can change default options at the gdb options part. For example, kernel debugging is much slower if the stack display is enabled...
# New commands enableobjectivec, enablecpuregisters, enablestack, enabledatawin and their disable equivalents (to support realtime change of default options)
# Fixed problem with the assemble command. I was calling /bin/echo which doesn't support the -e option ! DUH ! Should have used bash internal version.
# Small fixes to colours...
# New commands enablesolib and disablesolib . Just shortcuts for the stop-on-solib-events fantastic trick ! Hey... I'm lazy ;)
# Fixed this: Possible removal of "u" command, info udot is missing in gdb 6.8-debian . Doesn't exist on OS X so bye bye !!!
# Displays affected flags in jump decisions
#
# Version 7.1.6
# Added modified assemble command from Tavis Ormandy (further modified to work with Mac OS X) (shell commands used use full path name, working for Leopard, modify for others if necessary)
# Renamed thread command to threads because thread is an internal gdb command that allows to move between program threads
#
# Version 7.1.5 (04/01/2009)
# Fixed crash on Leopard ! There was a If Else condition where the else had no code and that made gdb crash on Leopard (CRAZY!!!!)
# Better code indention
#
# Version 7.1.4 (02/01/2009)
# Bug in show objective c messages with Leopard ???
# Nop routine support for single address or range (contribution from gln [ghalen at hack.se])
# Used the same code from nop to null routine
#
# Version 7.1.3 (31/12/2008)
# Added a new command 'stepo'. This command will step a temporary breakpoint on next instruction after the call, so you can skip over
# the call. Did this because normal commands not always skip over (mainly with objc_msgSend)
#
# Version 7.1.2 (31/12/2008)
# Support for the jump decision (will display if a conditional jump will be taken or not)
#
# Version 7.1.1 (29/12/2008)
# Moved gdb options to the beginning (makes more sense)
# Added support to dump message being sent to msgSend (easier to understand what's going on)
#
# Version 7.1
# Fixed serious (and old) bug in dd and datawin, causing dereference of
# obviously invalid address. See below:
# gdb$ dd 0xffffffff
# FFFFFFFF : Cannot access memory at address 0xffffffff
#
# Version 7.0
# Added cls command.
# Improved documentation of many commands.
# Removed bp_alloc, was neither portable nor usefull.
# Checking of passed argument(s) in these commands:
# contextsize-stack, contextsize-data, contextsize-code
# bp, bpc, bpe, bpd, bpt, bpm, bhb,...
# Fixed bp and bhb inconsistencies, look at * signs in Version 6.2
# Bugfix in bhb command, changed "break" to "hb" command body
# Removed $SHOW_CONTEXT=1 from several commands, this variable
# should only be controlled globally with context-on and context-off
# Improved stack, func, var and sig, dis, n, go,...
# they take optional argument(s) now
# Fixed wrong $SHOW_CONTEXT assignment in context-off
# Fixed serious bug in cft command, forgotten ~ sign
# Fixed these bugs in step_to_call:
# 1) the correct logging sequence is:
# set logging file > set logging redirect > set logging on
# 2) $SHOW_CONTEXT is now correctly restored from $_saved_ctx
# Fixed these bugs in trace_calls:
# 1) the correct logging sequence is:
# set logging file > set logging overwrite >
# set logging redirect > set logging on
# 2) removed the "clean up trace file" part, which is not needed now,
# stepi output is properly redirected to /dev/null
# 3) $SHOW_CONTEXT is now correctly restored from $_saved_ctx
# Fixed bug in trace_run:
# 1) $SHOW_CONTEXT is now correctly restored from $_saved_ctx
# Fixed print_insn_type -- removed invalid semicolons!, wrong value checking,
# Added TODO entry regarding the "u" command
# Changed name from gas_assemble to assemble_gas due to consistency
# Output from assemble and assemble_gas is now similar, because i made
# both of them to use objdump, with respect to output format (AT&T|Intel).
# Whole code was checked and made more consistent, readable/maintainable.
#
# Version 6.2
# Add global variables to allow user to control stack, data and code window sizes
# Increase readability for registers
# Some corrections (hexdump, ddump, context, cfp, assemble, gas_asm, tips, prompt)
#
# Version 6.1-color-user
# Took the Gentoo route and ran sed s/user/user/g
#
# Version 6.1-color
# Added color fixes from
# http://gnurbs.blogsome.com/2006/12/22/colorizing-mamons-gdbinit/
#
# Version 6.1
# Fixed filename in step_to_call so it points to /dev/null
# Changed location of logfiles from /tmp to ~
#
# Version 6
# Added print_insn_type, get_insn_type, context-on, context-off commands
# Added trace_calls, trace_run, step_to_call commands
# Changed hook-stop so it checks $SHOW_CONTEXT variable
#
# Version 5
# Added bpm, dump_bin, dump_hex, bp_alloc commands
# Added 'assemble' by elaine, 'gas_asm' by mong
# Added Tip Topics for aspiring users ;)
#
# Version 4
# Added eflags-changing insns by pusillus
# Added bp, nop, null, and int3 patch commands, also hook-stop
#
# Version 3
# Incorporated elaine's if/else goodness into the hex/ascii dump
#
# Version 2
# Radix bugfix by elaine
#
# TODO:
# Add dump, append, set write, etc commands
# Add more tips !
 
# _____________default configs________________
#### moar colors mean moar fun!
set prompt \033[01;31m\n(gdb) > \033[0m
 
set disassembly-flavor intel
set print pretty on
set print array on
set print repeats 25
set disassemble-next-line off
set confirm off
 
set output-radix 0x10
set input-radix 0x10
 
# These make gdb never pause in its output
set height 0
set width 0
 
set $SHOW_CONTEXT = 1
set $SHOW_NEST_INSN = 0
 
set $CONTEXTSIZE_STACK = 6
set $CONTEXTSIZE_DATA = 8
set $CONTEXTSIZE_CODE = 8
 
set $HIGHLIGHT = 0
 
# set to 0 to remove display of objectivec messages (default is 1)
set $SHOWOBJECTIVEC = 0
# set to 0 to remove display of cpu registers (default is 1)
set $SHOWCPUREGISTERS = 1
# set to 1 to enable display of stack (default is 0)
set $SHOWSTACK = 0
# set to 1 to enable display of data window (default is 0)
set $SHOWDATAWIN = 0
# __________________end gdb options_________________
 
# _____________breakpoint aliases_____________
define bpl
info breakpoints
end
document bpl
List all breakpoints.
end
 
define bp
if $argc != 1
help bp
else
break $arg0
end
end
document bp
Set breakpoint.
Usage: bp LOCATION
LOCATION may be a line number, function name, or "*" and an address.
 
To break on a symbol you must enclose symbol name inside "".
Example:
bp "[NSControl stringValue]"
Or else you can use directly the break command (break [NSControl stringValue])
end
 
define bpc
if $argc != 1
help bpc
else
clear $arg0
end
end
document bpc
Clear breakpoint.
Usage: bpc LOCATION
LOCATION may be a line number, function name, or "*" and an address.
end
 
define bpe
if $argc != 1
help bpe
else
enable $arg0
end
end
document bpe
Enable breakpoint with number NUM.
Usage: bpe NUM
end
 
define bpd
if $argc != 1
help bpd
else
disable $arg0
end
end
document bpd
Disable breakpoint with number NUM.
Usage: bpd NUM
end
 
define bpt
if $argc != 1
help bpt
else
tbreak $arg0
end
end
document bpt
Set a temporary breakpoint.
Will be deleted when hit!
Usage: bpt LOCATION
LOCATION may be a line number, function name, or "*" and an address.
end
 
define bpm
if $argc != 1
help bpm
else
awatch $arg0
end
end
document bpm
Set a read/write breakpoint on EXPRESSION, e.g. *address.
Usage: bpm EXPRESSION
end
 
define bhb
if $argc != 1
help bhb
else
hb $arg0
end
end
document bhb
Set hardware assisted breakpoint.
Usage: bhb LOCATION
LOCATION may be a line number, function name, or "*" and an address.
end
 
# ______________process information____________
define argv
show args
end
document argv
Print program arguments.
end
 
define stack
if $argc == 0
info stack
end
if $argc == 1
info stack $arg0
end
if $argc > 1
help stack
end
end
document stack
Print backtrace of the call stack, or innermost COUNT frames.
Usage: stack <COUNT>
end
 
define frame
info frame
info args
info locals
end
document frame
Print stack frame.
end
 
define flags
# OF (overflow) flag
if (($eflags >> 0xB) & 1)
printf "O "
set $_of_flag = 1
else
printf "o "
set $_of_flag = 0
end
if (($eflags >> 0xA) & 1)
printf "D "
else
printf "d "
end
if (($eflags >> 9) & 1)
printf "I "
else
printf "i "
end
if (($eflags >> 8) & 1)
printf "T "
else
printf "t "
end
# SF (sign) flag
if (($eflags >> 7) & 1)
printf "S "
set $_sf_flag = 1
else
printf "s "
set $_sf_flag = 0
end
# ZF (zero) flag
if (($eflags >> 6) & 1)
printf "Z "
set $_zf_flag = 1
else
printf "z "
set $_zf_flag = 0
end
if (($eflags >> 4) & 1)
printf "A "
else
printf "a "
end
# PF (parity) flag
if (($eflags >> 2) & 1)
printf "P "
set $_pf_flag = 1
else
printf "p "
set $_pf_flag = 0
end
# CF (carry) flag
if ($eflags & 1)
printf "C "
set $_cf_flag = 1
else
printf "c "
set $_cf_flag = 0
end
printf "\n"
end
document flags
Print flags register.
end
 
define eflags
printf " OF <%d> DF <%d> IF <%d> TF <%d>",\
(($eflags >> 0xB) & 1), (($eflags >> 0xA) & 1), \
(($eflags >> 9) & 1), (($eflags >> 8) & 1)
printf " SF <%d> ZF <%d> AF <%d> PF <%d> CF <%d>\n",\
(($eflags >> 7) & 1), (($eflags >> 6) & 1),\
(($eflags >> 4) & 1), (($eflags >> 2) & 1), ($eflags & 1)
printf " ID <%d> VIP <%d> VIF <%d> AC <%d>",\
(($eflags >> 0x15) & 1), (($eflags >> 0x14) & 1), \
(($eflags >> 0x13) & 1), (($eflags >> 0x12) & 1)
printf " VM <%d> RF <%d> NT <%d> IOPL <%d>\n",\
(($eflags >> 0x11) & 1), (($eflags >> 0x10) & 1),\
(($eflags >> 0xE) & 1), (($eflags >> 0xC) & 3)
end
document eflags
Print eflags register.
end
 
define reg
if $rip
# 64bits stuff
printf " "
echo \033[32m
printf "RAX:"
echo \033[0m
printf " 0x%016lX ", $rax
echo \033[32m
printf "RBX:"
echo \033[0m
printf " 0x%016lX ", $rbx
echo \033[32m
printf "RCX:"
echo \033[0m
printf " 0x%016lX ", $rcx
echo \033[32m
printf "RDX:"
echo \033[0m
printf " 0x%016lX ", $rdx
echo \033[1m\033[4m\033[31m
flags
echo \033[0m
printf " "
echo \033[32m
printf "RSI:"
echo \033[0m
printf " 0x%016lX ", $rsi
echo \033[32m
printf "RDI:"
echo \033[0m
printf " 0x%016lX ", $rdi
echo \033[32m
printf "RBP:"
echo \033[0m
printf " 0x%016lX ", $rbp
echo \033[32m
printf "RSP:"
echo \033[0m
printf " 0x%016lX ", $rsp
echo \033[32m
printf "RIP:"
echo \033[0m
printf " 0x%016lX\n ", $rip
echo \033[32m
printf "R8 :"
echo \033[0m
printf " 0x%016lX ", $r8
echo \033[32m
printf "R9 :"
echo \033[0m
printf " 0x%016lX ", $r9
echo \033[32m
printf "R10:"
echo \033[0m
printf " 0x%016lX ", $r10
echo \033[32m
printf "R11:"
echo \033[0m
printf " 0x%016lX ", $r11
echo \033[32m
printf "R12:"
echo \033[0m
printf " 0x%016lX\n ", $r12
echo \033[32m
printf "R13:"
echo \033[0m
printf " 0x%016lX ", $r13
echo \033[32m
printf "R14:"
echo \033[0m
printf " 0x%016lX ", $r14
echo \033[32m
printf "R15:"
echo \033[0m
printf " 0x%016lX\n ", $r15
# 32bits stuff
else
printf " "
echo \033[32m
printf "EAX:"
echo \033[0m
printf " 0x%08X ", $eax
echo \033[32m
printf "EBX:"
echo \033[0m
printf " 0x%08X ", $ebx
echo \033[32m
printf "ECX:"
echo \033[0m
printf " 0x%08X ", $ecx
echo \033[32m
printf "EDX:"
echo \033[0m
printf " 0x%08X ", $edx
echo \033[1m\033[4m\033[31m
flags
echo \033[0m
printf " "
echo \033[32m
printf "ESI:"
echo \033[0m
printf " 0x%08X ", $esi
echo \033[32m
printf "EDI:"
echo \033[0m
printf " 0x%08X ", $edi
echo \033[32m
printf "EBP:"
echo \033[0m
printf " 0x%08X ", $ebp
echo \033[32m
printf "ESP:"
echo \033[0m
printf " 0x%08X ", $esp
echo \033[32m
printf "EIP:"
echo \033[0m
printf " 0x%08X\n ", $eip
end
echo \033[32m
printf "CS:"
echo \033[0m
printf " %04X ", $cs
echo \033[32m
printf "DS:"
echo \033[0m
printf " %04X ", $ds
echo \033[32m
printf "ES:"
echo \033[0m
printf " %04X ", $es
echo \033[32m
printf "FS:"
echo \033[0m
printf " %04X ", $fs
echo \033[32m
printf "GS:"
echo \033[0m
printf " %04X ", $gs
echo \033[32m
printf "SS:"
echo \033[0m
printf " %04X", $ss
echo \033[0m
# call smallregisters
smallregisters
# display conditional jump routine
if $rip
printf "\t\t\t\t"
end
dumpjump
printf "\n"
end
document reg
Print CPU registers.
end
 
define smallregisters
if $rip
#64bits stuff
# from rax
set $eax = $rax & 0xffffffff
set $ax = $rax & 0xffff
set $al = $ax & 0xff
set $ah = $ax >> 8
# from rbx
set $bx = $rbx & 0xffff
set $bl = $bx & 0xff
set $bh = $bx >> 8
# from rcx
set $ecx = $rcx & 0xffffffff
set $cx = $rcx & 0xffff
set $cl = $cx & 0xff
set $ch = $cx >> 8
# from rdx
set $edx = $rdx & 0xffffffff
set $dx = $rdx & 0xffff
set $dl = $dx & 0xff
set $dh = $dx >> 8
# from rsi
set $esi = $rsi & 0xffffffff
set $si = $rsi & 0xffff
# from rdi
set $edi = $rdi & 0xffffffff
set $di = $rdi & 0xffff
#32 bits stuff
else
# from eax
set $ax = $eax & 0xffff
set $al = $ax & 0xff
set $ah = $ax >> 8
# from ebx
set $bx = $ebx & 0xffff
set $bl = $bx & 0xff
set $bh = $bx >> 8
# from ecx
set $cx = $ecx & 0xffff
set $cl = $cx & 0xff
set $ch = $cx >> 8
# from edx
set $dx = $edx & 0xffff
set $dl = $dx & 0xff
set $dh = $dx >> 8
# from esi
set $si = $esi & 0xffff
# from edi
set $di = $edi & 0xffff
end
end
document smallregisters
Create the 16 and 8 bit cpu registers (gdb doesn't have them by default)
And 32bits if we are dealing with 64bits binaries
end
 
define func
if $argc == 0
info functions
end
if $argc == 1
info functions $arg0
end
if $argc > 1
help func
end
end
document func
Print all function names in target, or those matching REGEXP.
Usage: func <REGEXP>
end
 
 
define var
if $argc == 0
info variables
end
if $argc == 1
info variables $arg0
end
if $argc > 1
help var
end
end
document var
Print all global and static variable names (symbols), or those matching REGEXP.
Usage: var <REGEXP>
end
 
 
define lib
info sharedlibrary
end
document lib
Print shared libraries linked to target.
end
 
 
define sig
if $argc == 0
info signals
end
if $argc == 1
info signals $arg0
end
if $argc > 1
help sig
end
end
document sig
Print what debugger does when program gets various signals.
Specify a SIGNAL as argument to print info on that signal only.
Usage: sig <SIGNAL>
end
 
 
define threads
info threads
end
document threads
Print threads in target.
end
 
 
define dis
if $argc == 0
disassemble
end
if $argc == 1
disassemble $arg0
end
if $argc == 2
disassemble $arg0 $arg1
end
if $argc > 2
help dis
end
end
document dis
Disassemble a specified section of memory.
Default is to disassemble the function surrounding the PC (program counter)
of selected frame. With one argument, ADDR1, the function surrounding this
address is dumped. Two arguments are taken as a range of memory to dump.
Usage: dis <ADDR1> <ADDR2>
end
 
# __________hex/ascii dump an address_________
define ascii_char
if $argc != 1
help ascii_char
else
# thanks elaine :)
set $_c = *(unsigned char *)($arg0)
if ($_c < 0x20 || $_c > 0x7E)
printf "."
else
printf "%c", $_c
end
end
end
document ascii_char
Print ASCII value of byte at address ADDR.
Print "." if the value is unprintable.
Usage: ascii_char ADDR
end
 
 
define hex_quad
if $argc != 1
help hex_quad
else
printf "%02X %02X %02X %02X %02X %02X %02X %02X", \
*(unsigned char*)($arg0), *(unsigned char*)($arg0 + 1), \
*(unsigned char*)($arg0 + 2), *(unsigned char*)($arg0 + 3), \
*(unsigned char*)($arg0 + 4), *(unsigned char*)($arg0 + 5), \
*(unsigned char*)($arg0 + 6), *(unsigned char*)($arg0 + 7)
end
end
document hex_quad
Print eight hexadecimal bytes starting at address ADDR.
Usage: hex_quad ADDR
end
 
define hexdump
if $argc != 1
help hexdump
else
echo \033[1m
if ($64BITS == 1)
printf "0x%016lX : ", $arg0
else
printf "0x%08X : ", $arg0
end
echo \033[0m
hex_quad $arg0
echo \033[1m
printf " - "
echo \033[0m
hex_quad $arg0+8
printf " "
echo \033[1m
ascii_char $arg0+0x0
ascii_char $arg0+0x1
ascii_char $arg0+0x2
ascii_char $arg0+0x3
ascii_char $arg0+0x4
ascii_char $arg0+0x5
ascii_char $arg0+0x6
ascii_char $arg0+0x7
ascii_char $arg0+0x8
ascii_char $arg0+0x9
ascii_char $arg0+0xA
ascii_char $arg0+0xB
ascii_char $arg0+0xC
ascii_char $arg0+0xD
ascii_char $arg0+0xE
ascii_char $arg0+0xF
echo \033[0m
printf "\n"
end
end
document hexdump
Display a 16-byte hex/ASCII dump of memory at address ADDR.
Usage: hexdump ADDR
end
 
# _______________data window__________________
define ddump
if $argc != 1
help ddump
else
echo \033[34m
if $rip
printf "[0x%04X:0x%016lX]", $ds, $data_addr
else
printf "[0x%04X:0x%08X]", $ds, $data_addr
end
echo \033[34m
printf "------------------------"
printf "-------------------------------"
if $rip
printf "-------------------------------------"
end
echo \033[1;34m
printf "[data]\n"
echo \033[0m
set $_count = 0
while ($_count < $arg0)
set $_i = ($_count * 0x10)
hexdump $data_addr+$_i
set $_count++
end
end
end
document ddump
Display NUM lines of hexdump for address in $data_addr global variable.
Usage: ddump NUM
end
 
 
define dd
if $argc != 1
help dd
else
if ((($arg0 >> 0x18) == 0x40) || (($arg0 >> 0x18) == 0x08) || (($arg0 >> 0x18) == 0xBF))
set $data_addr = $arg0
ddump 0x10
else
printf "Invalid address: %08X\n", $arg0
end
end
end
document dd
Display 16 lines of a hex dump of address starting at ADDR.
Usage: dd ADDR
end
 
 
define datawin
if $rip
if ((($rsi >> 0x18) == 0x40) || (($rsi >> 0x18) == 0x08) || (($rsi >> 0x18) == 0xBF))
set $data_addr = $rsi
else
if ((($rdi >> 0x18) == 0x40) || (($rdi >> 0x18) == 0x08) || (($rdi >> 0x18) == 0xBF))
set $data_addr = $rdi
else
if ((($rax >> 0x18) == 0x40) || (($rax >> 0x18) == 0x08) || (($rax >> 0x18) == 0xBF))
set $data_addr = $rax
else
set $data_addr = $rsp
end
end
end
else
if ((($esi >> 0x18) == 0x40) || (($esi >> 0x18) == 0x08) || (($esi >> 0x18) == 0xBF))
set $data_addr = $esi
else
if ((($edi >> 0x18) == 0x40) || (($edi >> 0x18) == 0x08) || (($edi >> 0x18) == 0xBF))
set $data_addr = $edi
else
if ((($eax >> 0x18) == 0x40) || (($eax >> 0x18) == 0x08) || (($eax >> 0x18) == 0xBF))
set $data_addr = $eax
else
set $data_addr = $esp
end
end
end
end
ddump $CONTEXTSIZE_DATA
end
document datawin
Display valid address from one register in data window.
Registers to choose are: esi, edi, eax, or esp.
end
 
################################
##### ALERT ALERT ALERT ########
################################
# Huge mess going here :) HAHA #
################################
define dumpjump
## grab the first two bytes from the instruction so we can determine the jump instruction
set $_byte1 = *(unsigned char *)$pc
set $_byte2 = *(unsigned char *)($pc+1)
## and now check what kind of jump we have (in case it's a jump instruction)
## I changed the flags routine to save the flag into a variable, so we don't need to repeat the process :) (search for "define flags")
## opcode 0x77: JA, JNBE (jump if CF=0 and ZF=0)
## opcode 0x0F87: JNBE, JA
if ( ($_byte1 == 0x77) || ($_byte1 == 0x0F && $_byte2 == 0x87) )
# cf=0 and zf=0
if ($_cf_flag == 0 && $_zf_flag == 0)
echo \033[31m
printf " Jump is taken (c=0 and z=0)"
else
# cf != 0 or zf != 0
echo \033[31m
printf " Jump is NOT taken (c!=0 or z!=0)"
end
end
## opcode 0x73: JAE, JNB, JNC (jump if CF=0)
## opcode 0x0F83: JNC, JNB, JAE (jump if CF=0)
if ( ($_byte1 == 0x73) || ($_byte1 == 0x0F && $_byte2 == 0x83) )
# cf=0
if ($_cf_flag == 0)
echo \033[31m
printf " Jump is taken (c=0)"
else
# cf != 0
echo \033[31m
printf " Jump is NOT taken (c!=0)"
end
end
## opcode 0x72: JB, JC, JNAE (jump if CF=1)
## opcode 0x0F82: JNAE, JB, JC
if ( ($_byte1 == 0x72) || ($_byte1 == 0x0F && $_byte2 == 0x82) )
# cf=1
if ($_cf_flag == 1)
echo \033[31m
printf " Jump is taken (c=1)"
else
# cf != 1
echo \033[31m
printf " Jump is NOT taken (c!=1)"
end
end
## opcode 0x76: JBE, JNA (jump if CF=1 or ZF=1)
## opcode 0x0F86: JBE, JNA
if ( ($_byte1 == 0x76) || ($_byte1 == 0x0F && $_byte2 == 0x86) )
# cf=1 or zf=1
if (($_cf_flag == 1) || ($_zf_flag == 1))
echo \033[31m
printf " Jump is taken (c=1 or z=1)"
else
# cf != 1 or zf != 1
echo \033[31m
printf " Jump is NOT taken (c!=1 or z!=1)"
end
end
## opcode 0xE3: JCXZ, JECXZ, JRCXZ (jump if CX=0 or ECX=0 or RCX=0)
if ($_byte1 == 0xE3)
# cx=0 or ecx=0
if (($ecx == 0) || ($cx == 0))
echo \033[31m
printf " Jump is taken (cx=0 or ecx=0)"
else
#
echo \033[31m
printf " Jump is NOT taken (cx!=0 or ecx!=0)"
end
end
## opcode 0x74: JE, JZ (jump if ZF=1)
## opcode 0x0F84: JZ, JE, JZ (jump if ZF=1)
if ( ($_byte1 == 0x74) || ($_byte1 == 0x0F && $_byte2 == 0x84) )
# ZF = 1
if ($_zf_flag == 1)
echo \033[31m
printf " Jump is taken (z=1)"
else
# ZF = 0
echo \033[31m
printf " Jump is NOT taken (z!=1)"
end
end
## opcode 0x7F: JG, JNLE (jump if ZF=0 and SF=OF)
## opcode 0x0F8F: JNLE, JG (jump if ZF=0 and SF=OF)
if ( ($_byte1 == 0x7F) || ($_byte1 == 0x0F && $_byte2 == 0x8F) )
# zf = 0 and sf = of
if (($_zf_flag == 0) && ($_sf_flag == $_of_flag))
echo \033[31m
printf " Jump is taken (z=0 and s=o)"
else
#
echo \033[31m
printf " Jump is NOT taken (z!=0 or s!=o)"
end
end
## opcode 0x7D: JGE, JNL (jump if SF=OF)
## opcode 0x0F8D: JNL, JGE (jump if SF=OF)
if ( ($_byte1 == 0x7D) || ($_byte1 == 0x0F && $_byte2 == 0x8D) )
# sf = of
if ($_sf_flag == $_of_flag)
echo \033[31m
printf " Jump is taken (s=o)"
else
#
echo \033[31m
printf " Jump is NOT taken (s!=o)"
end
end
## opcode: 0x7C: JL, JNGE (jump if SF != OF)
## opcode: 0x0F8C: JNGE, JL (jump if SF != OF)
if ( ($_byte1 == 0x7C) || ($_byte1 == 0x0F && $_byte2 == 0x8C) )
# sf != of
if ($_sf_flag != $_of_flag)
echo \033[31m
printf " Jump is taken (s!=o)"
else
#
echo \033[31m
printf " Jump is NOT taken (s=o)"
end
end
## opcode 0x7E: JLE, JNG (jump if ZF = 1 or SF != OF)
## opcode 0x0F8E: JNG, JLE (jump if ZF = 1 or SF != OF)
if ( ($_byte1 == 0x7E) || ($_byte1 == 0x0F && $_byte2 == 0x8E) )
# zf = 1 or sf != of
if (($_zf_flag == 1) || ($_sf_flag != $_of_flag))
echo \033[31m
printf " Jump is taken (zf=1 or sf!=of)"
else
#
echo \033[31m
printf " Jump is NOT taken (zf!=1 or sf=of)"
end
end
## opcode 0x75: JNE, JNZ (jump if ZF = 0)
## opcode 0x0F85: JNE, JNZ (jump if ZF = 0)
if ( ($_byte1 == 0x75) || ($_byte1 == 0x0F && $_byte2 == 0x85) )
# ZF = 0
if ($_zf_flag == 0)
echo \033[31m
printf " Jump is taken (z=0)"
else
# ZF = 1
echo \033[31m
printf " Jump is NOT taken (z!=0)"
end
end
## opcode 0x71: JNO (OF = 0)
## opcode 0x0F81: JNO (OF = 0)
if ( ($_byte1 == 0x71) || ($_byte1 == 0x0F && $_byte2 == 0x81) )
# OF = 0
if ($_of_flag == 0)
echo \033[31m
printf " Jump is taken (o=0)"
else
# OF != 0
echo \033[31m
printf " Jump is NOT taken (o!=0)"
end
end
## opcode 0x7B: JNP, JPO (jump if PF = 0)
## opcode 0x0F8B: JPO (jump if PF = 0)
if ( ($_byte1 == 0x7B) || ($_byte1 == 0x0F && $_byte2 == 0x8B) )
# PF = 0
if ($_pf_flag == 0)
echo \033[31m
printf " Jump is NOT taken (p=0)"
else
# PF != 0
echo \033[31m
printf " Jump is taken (p!=0)"
end
end
## opcode 0x79: JNS (jump if SF = 0)
## opcode 0x0F89: JNS (jump if SF = 0)
if ( ($_byte1 == 0x79) || ($_byte1 == 0x0F && $_byte2 == 0x89) )
# SF = 0
if ($_sf_flag == 0)
echo \033[31m
printf " Jump is taken (s=0)"
else
# SF != 0
echo \033[31m
printf " Jump is NOT taken (s!=0)"
end
end
## opcode 0x70: JO (jump if OF=1)
## opcode 0x0F80: JO (jump if OF=1)
if ( ($_byte1 == 0x70) || ($_byte1 == 0x0F && $_byte2 == 0x80) )
# OF = 1
if ($_of_flag == 1)
echo \033[31m
printf " Jump is taken (o=1)"
else
# OF != 1
echo \033[31m
printf " Jump is NOT taken (o!=1)"
end
end
## opcode 0x7A: JP, JPE (jump if PF=1)
## opcode 0x0F8A: JP, JPE (jump if PF=1)
if ( ($_byte1 == 0x7A) || ($_byte1 == 0x0F && $_byte2 == 0x8A) )
# PF = 1
if ($_pf_flag == 1)
echo \033[31m
printf " Jump is taken (p=1)"
else
# PF = 0
echo \033[31m
printf " Jump is NOT taken (p!=1)"
end
end
## opcode 0x78: JS (jump if SF=1)
## opcode 0x0F88: JS (jump if SF=1)
if ( ($_byte1 == 0x78) || ($_byte1 == 0x0F && $_byte2 == 0x88) )
# SF = 1
if ($_sf_flag == 1)
echo \033[31m
printf " Jump is taken (s=1)"
else
# SF != 1
echo \033[31m
printf " Jump is NOT taken (s!=1)"
end
end
# end of dumpjump function
end
document dumpjump
Display if conditional jump will be taken or not
end
 
# _______________process context______________
# initialize variable
set $displayobjectivec = 0
 
define context
echo \033[34m
if $SHOWCPUREGISTERS == 1
printf "----------------------------------------"
printf "----------------------------------"
if $rip
printf "---------------------------------------------"
end
echo \033[34m\033[1m
printf "[regs]\n"
echo \033[0m
reg
echo \033[36m
end
if $SHOWSTACK == 1
echo \033[34m
if $rip
printf "[0x%04X:0x%016lX]", $ss, $rsp
else
printf "[0x%04X:0x%08X]", $ss, $esp
end
echo \033[34m
printf "-------------------------"
printf "-----------------------------"
if $rip
printf "-------------------------------------"
end
echo \033[34m\033[1m
printf "[stack]\n"
echo \033[0m
set $context_i = $CONTEXTSIZE_STACK
while ($context_i > 0)
set $context_t = $sp + 0x10 * ($context_i - 1)
hexdump $context_t
set $context_i--
end
end
# show the objective C message being passed to msgSend
if $SHOWOBJECTIVEC == 1
#FIXME64
# What a piece of crap that's going on here :)
# detect if it's the correct opcode we are searching for
set $__byte1 = *(unsigned char *)$pc
set $__byte = *(int *)$pc
#
if ($__byte == 0x4244489)
set $objectivec = $eax
set $displayobjectivec = 1
end
#
if ($__byte == 0x4245489)
set $objectivec = $edx
set $displayobjectivec = 1
end
#
if ($__byte == 0x4244c89)
set $objectivec = $edx
set $displayobjectivec = 1
end
# and now display it or not (we have no interest in having the info displayed after the call)
if $__byte1 == 0xE8
if $displayobjectivec == 1
echo \033[34m
printf "--------------------------------------------------------------------"
if $rip
printf "---------------------------------------------"
end
echo \033[34m\033[1m
printf "[ObjectiveC]\n"
echo \033[0m\033[30m
x/s $objectivec
end
set $displayobjectivec = 0
end
if $displayobjectivec == 1
echo \033[34m
printf "--------------------------------------------------------------------"
if $rip
printf "---------------------------------------------"
end
echo \033[34m\033[1m
printf "[ObjectiveC]\n"
echo \033[0m\033[30m
x/s $objectivec
end
end
echo \033[0m
# and this is the end of this little crap
if $SHOWDATAWIN == 1
datawin
end
 
echo \033[34m
printf "--------------------------------------------------------------------------"
if $rip
printf "---------------------------------------------"
end
echo \033[34m\033[1m
printf "[code]\n"
echo \033[0m
DS-start-redirect
set $context_i = $CONTEXTSIZE_CODE
if($context_i > 0)
x /i $pc
set $context_i--
end
while ($context_i > 0)
x /i
set $context_i--
end
DS-stop-redirect
echo \033[34m
printf "----------------------------------------"
printf "----------------------------------------"
if $rip
printf "---------------------------------------------\n"
else
printf "\n"
end
echo \033[0m
end
document context
Print context window, i.e. regs, stack, ds:esi and disassemble cs:eip.
end
 
define context-on
set $SHOW_CONTEXT = 1
printf "Displaying of context is now ON\n"
end
document context-on
Enable display of context on every program break.
end
 
 
define context-off
set $SHOW_CONTEXT = 0
printf "Displaying of context is now OFF\n"
end
document context-off
Disable display of context on every program break.
end
 
# _______________process control______________
define n
if $argc == 0
nexti
end
if $argc == 1
nexti $arg0
end
if $argc > 1
help n
end
end
document n
Step one instruction, but proceed through subroutine calls.
If NUM is given, then repeat it NUM times or till program stops.
This is alias for nexti.
Usage: n <NUM>
end
 
define go
if $argc == 0
stepi
end
if $argc == 1
stepi $arg0
end
if $argc > 1
help go
end
end
document go
Step one instruction exactly.
If NUM is given, then repeat it NUM times or till program stops.
This is alias for stepi.
Usage: go <NUM>
end
 
 
define pret
finish
end
document pret
Execute until selected stack frame returns (step out of current call).
Upon return, the value returned is printed and put in the value history.
end
 
 
define init
set $SHOW_NEST_INSN = 0
tbreak _init
r
end
document init
Run program and break on _init().
end
 
 
define start
set $SHOW_NEST_INSN = 0
tbreak _start
r
end
document start
Run program and break on _start().
end
 
 
define sstart
set $SHOW_NEST_INSN = 0
tbreak __libc_start_main
r
end
document sstart
Run program and break on __libc_start_main().
Useful for stripped executables.
end
 
 
define main
set $SHOW_NEST_INSN = 0
tbreak main
r
end
document main
Run program and break on main().
end
 
# FIXME64
#### WARNING ! WARNING !!
#### More more messy stuff starting !!!
#### I was thinking about how to do this and then it ocurred me that it could be as simple as this ! :)
define stepo
## we know that an opcode starting by 0xE8 has a fixed length
## for the 0xFF opcodes, we can enumerate what is possible to have
# first we grab the first 3 bytes from the current program counter
set $_byte1 = *(unsigned char *)$pc
set $_byte2 = *(unsigned char *)($pc+1)
set $_byte3 = *(unsigned char *)($pc+2)
# and start the fun
# if it's a 0xE8 opcode, the total instruction size will be 5 bytes
# so we can simply calculate the next address and use a temporary breakpoint ! Voila :)
set $_nextaddress = 0
# this one is the must useful for us !!!
if ($_byte1 == 0xE8)
set $_nextaddress = $pc + 0x5
else
# just other cases we might be interested in... maybe this should be removed since the 0xE8 opcode is the one we will use more
# this is a big fucking mess and can be improved for sure :) I don't like the way it is ehehehe
if ($_byte1 == 0xFF)
# call *%eax (0xFFD0) || call *%edx (0xFFD2) || call *(%ecx) (0xFFD1) || call (%eax) (0xFF10) || call *%esi (0xFFD6) || call *%ebx (0xFFD3)
if ($_byte2 == 0xD0 || $_byte2 == 0xD1 || $_byte2 == 0xD2 || $_byte2 == 0xD3 || $_byte2 == 0xD6 || $_byte2 == 0x10 )
set $_nextaddress = $pc + 0x2
end
# call *0x??(%ebp) (0xFF55??) || call *0x??(%esi) (0xFF56??) || call *0x??(%edi) (0xFF5F??) || call *0x??(%ebx)
# call *0x??(%edx) (0xFF52??) || call *0x??(%ecx) (0xFF51??) || call *0x??(%edi) (0xFF57??) || call *0x??(%eax) (0xFF50??)
if ($_byte2 == 0x55 || $_byte2 == 0x56 || $_byte2 == 0x5F || $_byte2 == 0x53 || $_byte2 == 0x52 || $_byte2 == 0x51 || $_byte2 == 0x57 || $_byte2 == 0x50)
set $_nextaddress = $pc + 0x3
end
# call *0x????????(%ebx) (0xFF93????????) ||
if ($_byte2 == 0x93 || $_byte2 == 0x94 || $_byte2 == 0x90 || $_byte2 == 0x92)
set $_nextaddress = $pc + 6
end
# call *0x????????(%ebx,%eax,4) (0xFF94??????????)
if ($_byte2 == 0x94)
set $_nextaddress = $pc + 7
end
end
end
# if we have found a call to bypass we set a temporary breakpoint on next instruction and continue
if ($_nextaddress != 0)
tbreak *$_nextaddress
continue
# else we just single step
else
nexti
end
# end of stepo function
end
document stepo
Step over calls (interesting to bypass the ones to msgSend)
This function will set a temporary breakpoint on next instruction after the call so the call will be bypassed
You can safely use it instead nexti or n since it will single step code if it's not a call instruction (unless you want to go into the call function)
end
 
# _______________eflags commands______________
define cfc
if ($eflags & 1)
set $eflags = $eflags&~0x1
else
set $eflags = $eflags|0x1
end
end
document cfc
Change Carry Flag.
end
 
define cfp
if (($eflags >> 2) & 1)
set $eflags = $eflags&~0x4
else
set $eflags = $eflags|0x4
end
end
document cfp
Change Parity Flag.
end
 
define cfa
if (($eflags >> 4) & 1)
set $eflags = $eflags&~0x10
else
set $eflags = $eflags|0x10
end
end
document cfa
Change Auxiliary Carry Flag.
end
 
define cfz
if (($eflags >> 6) & 1)
set $eflags = $eflags&~0x40
else
set $eflags = $eflags|0x40
end
end
document cfz
Change Zero Flag.
end
 
define cfs
if (($eflags >> 7) & 1)
set $eflags = $eflags&~0x80
else
set $eflags = $eflags|0x80
end
end
document cfs
Change Sign Flag.
end
 
define cft
if (($eflags >>8) & 1)
set $eflags = $eflags&~0x100
else
set $eflags = $eflags|0x100
end
end
document cft
Change Trap Flag.
end
 
define cfi
if (($eflags >> 9) & 1)
set $eflags = $eflags&~0x200
else
set $eflags = $eflags|0x200
end
end
document cfi
Change Interrupt Flag.
Only privileged applications (usually the OS kernel) may modify IF.
This only applies to protected mode (real mode code may always modify IF).
end
 
define cfd
if (($eflags >>0xA) & 1)
set $eflags = $eflags&~0x400
else
set $eflags = $eflags|0x400
end
end
document cfd
Change Direction Flag.
end
 
define cfo
if (($eflags >> 0xB) & 1)
set $eflags = $eflags&~0x800
else
set $eflags = $eflags|0x800
end
end
document cfo
Change Overflow Flag.
end
 
# ____________________patch___________________
define nop
if ($argc > 2 || $argc == 0)
help nop
end
if ($argc == 1)
set *(unsigned char *)$arg0 = 0x90
else
set $addr = $arg0
while ($addr < $arg1)
set *(unsigned char *)$addr = 0x90
set $addr = $addr + 1
end
end
end
document nop
Usage: nop ADDR1 [ADDR2]
Patch a single byte at address ADDR1, or a series of bytes between ADDR1 and ADDR2 to a NOP (0x90) instruction.
end
 
define null
if ( $argc >2 || $argc == 0)
help null
end
if ($argc == 1)
set *(unsigned char *)$arg0 = 0
else
set $addr = $arg0
while ($addr < $arg1)
set *(unsigned char *)$addr = 0
set $addr = $addr +1
end
end
end
document null
Usage: null ADDR1 [ADDR2]
Patch a single byte at address ADDR1 to NULL (0x00), or a series of bytes between ADDR1 and ADDR2.
end
 
define int3
if $argc != 1
help int3
else
set *(unsigned char *)$arg0 = 0xCC
end
end
document int3
Patch byte at address ADDR to an INT3 (0xCC) instruction.
Usage: int3 ADDR
end
 
# ____________________cflow___________________
define print_insn_type
if $argc != 1
help print_insn_type
else
if ($arg0 < 0 || $arg0 > 5)
printf "UNDEFINED/WRONG VALUE"
end
if ($arg0 == 0)
printf "UNKNOWN"
end
if ($arg0 == 1)
printf "JMP"
end
if ($arg0 == 2)
printf "JCC"
end
if ($arg0 == 3)
printf "CALL"
end
if ($arg0 == 4)
printf "RET"
end
if ($arg0 == 5)
printf "INT"
end
end
end
document print_insn_type
Print human-readable mnemonic for the instruction type (usually $INSN_TYPE).
Usage: print_insn_type INSN_TYPE_NUMBER
end
 
 
define get_insn_type
if $argc != 1
help get_insn_type
else
set $INSN_TYPE = 0
set $_byte1 = *(unsigned char *)$arg0
if ($_byte1 == 0x9A || $_byte1 == 0xE8)
# "call"
set $INSN_TYPE = 3
end
if ($_byte1 >= 0xE9 && $_byte1 <= 0xEB)
# "jmp"
set $INSN_TYPE = 1
end
if ($_byte1 >= 0x70 && $_byte1 <= 0x7F)
# "jcc"
set $INSN_TYPE = 2
end
if ($_byte1 >= 0xE0 && $_byte1 <= 0xE3 )
# "jcc"
set $INSN_TYPE = 2
end
if ($_byte1 == 0xC2 || $_byte1 == 0xC3 || $_byte1 == 0xCA || \
$_byte1 == 0xCB || $_byte1 == 0xCF)
# "ret"
set $INSN_TYPE = 4
end
if ($_byte1 >= 0xCC && $_byte1 <= 0xCE)
# "int"
set $INSN_TYPE = 5
end
if ($_byte1 == 0x0F )
# two-byte opcode
set $_byte2 = *(unsigned char *)($arg0 + 1)
if ($_byte2 >= 0x80 && $_byte2 <= 0x8F)
# "jcc"
set $INSN_TYPE = 2
end
end
if ($_byte1 == 0xFF)
# opcode extension
set $_byte2 = *(unsigned char *)($arg0 + 1)
set $_opext = ($_byte2 & 0x38)
if ($_opext == 0x10 || $_opext == 0x18)
# "call"
set $INSN_TYPE = 3
end
if ($_opext == 0x20 || $_opext == 0x28)
# "jmp"
set $INSN_TYPE = 1
end
end
end
end
document get_insn_type
Recognize instruction type at address ADDR.
Take address ADDR and set the global $INSN_TYPE variable to
0, 1, 2, 3, 4, 5 if the instruction at that address is
unknown, a jump, a conditional jump, a call, a return, or an interrupt.
Usage: get_insn_type ADDR
end
 
define step_to_call
set $_saved_ctx = $SHOW_CONTEXT
set $SHOW_CONTEXT = 0
set $SHOW_NEST_INSN = 0
set logging file /dev/null
set logging redirect on
set logging on
set $_cont = 1
while ($_cont > 0)
stepi
get_insn_type $pc
if ($INSN_TYPE == 3)
set $_cont = 0
end
end
set logging off
if ($_saved_ctx > 0)
context
end
set $SHOW_CONTEXT = $_saved_ctx
set $SHOW_NEST_INSN = 0
set logging file ~/gdb.txt
set logging redirect off
set logging on
printf "step_to_call command stopped at:\n "
x/i $pc
printf "\n"
set logging off
end
document step_to_call
Single step until a call instruction is found.
Stop before the call is taken.
Log is written into the file ~/gdb.txt.
end
 
define trace_calls
printf "Tracing...please wait...\n"
set $_saved_ctx = $SHOW_CONTEXT
set $SHOW_CONTEXT = 0
set $SHOW_NEST_INSN = 0
set $_nest = 1
set listsize 0
set logging overwrite on
set logging file ~/gdb_trace_calls.txt
set logging on
set logging off
set logging overwrite off
while ($_nest > 0)
get_insn_type $pc
# handle nesting
if ($INSN_TYPE == 3)
set $_nest = $_nest + 1
else
if ($INSN_TYPE == 4)
set $_nest = $_nest - 1
end
end
# if a call, print it
if ($INSN_TYPE == 3)
set logging file ~/gdb_trace_calls.txt
set logging redirect off
set logging on
set $x = $_nest - 2
while ($x > 0)
printf "\t"
set $x = $x - 1
end
x/i $pc
end
set logging off
set logging file /dev/null
set logging redirect on
set logging on
stepi
set logging redirect off
set logging off
end
set $SHOW_CONTEXT = $_saved_ctx
set $SHOW_NEST_INSN = 0
printf "Done, check ~/gdb_trace_calls.txt\n"
end
document trace_calls
Create a runtime trace of the calls made by target.
Log overwrites(!) the file ~/gdb_trace_calls.txt.
end
 
define trace_run
printf "Tracing...please wait...\n"
set $_saved_ctx = $SHOW_CONTEXT
set $SHOW_CONTEXT = 0
set $SHOW_NEST_INSN = 1
set logging overwrite on
set logging file ~/gdb_trace_run.txt
set logging redirect on
set logging on
set $_nest = 1
while ( $_nest > 0 )
get_insn_type $pc
# jmp, jcc, or cll
if ($INSN_TYPE == 3)
set $_nest = $_nest + 1
else
# ret
if ($INSN_TYPE == 4)
set $_nest = $_nest - 1
end
end
stepi
end
printf "\n"
set $SHOW_CONTEXT = $_saved_ctx
set $SHOW_NEST_INSN = 0
set logging redirect off
set logging off
# clean up trace file
shell grep -v ' at ' ~/gdb_trace_run.txt > ~/gdb_trace_run.1
shell grep -v ' in ' ~/gdb_trace_run.1 > ~/gdb_trace_run.txt
shell rm -f ~/gdb_trace_run.1
printf "Done, check ~/gdb_trace_run.txt\n"
end
document trace_run
Create a runtime trace of target.
Log overwrites(!) the file ~/gdb_trace_run.txt.
end
 
# ____________________misc____________________
# original by Tavis Ormandy (http://my.opera.com/taviso/blog/index.dml/tag/gdb) (great fix!)
# modified to work with Mac OS X by fG!
# seems nasm shipping with Mac OS X has problems accepting input from stdin or heredoc
# input is read into a variable and sent to a temporary file which nasm can read
define assemble
# dont enter routine again if user hits enter
dont-repeat
if ($argc)
if (*$arg0 = *$arg0)
# check if we have a valid address by dereferencing it,
# if we havnt, this will cause the routine to exit.
end
printf "Instructions will be written to %#x.\n", $arg0
else
printf "Instructions will be written to stdout.\n"
end
printf "Type instructions, one per line."
echo \033[1m
printf " Do not forget to use NASM assembler syntax!\n"
echo \033[0m
printf "End with a line saying just \"end\".\n"
if ($argc)
# argument specified, assemble instructions into memory at address specified.
shell ASMOPCODE="$(while read -ep '>' r && test "$r" != end ; do echo -E "$r"; done)" ; FILENAME=$RANDOM; \
echo -e "BITS 32\n$ASMOPCODE" >/tmp/$FILENAME ; /usr/bin/nasm -f bin -o /dev/stdout /tmp/$FILENAME | /usr/bin/hexdump -ve '1/1 "set *((unsigned char *) $arg0 + %#2_ax) = %#02x\n"' >/tmp/gdbassemble ; /bin/rm -f /tmp/$FILENAME
source /tmp/gdbassemble
# all done. clean the temporary file
shell /bin/rm -f /tmp/gdbassemble
else
# no argument, assemble instructions to stdout
shell ASMOPCODE="$(while read -ep '>' r && test "$r" != end ; do echo -E "$r"; done)" ; FILENAME=$RANDOM; \
echo -e "BITS 32\n$ASMOPCODE" >/tmp/$FILENAME ; /usr/bin/nasm -f bin -o /dev/stdout /tmp/$FILENAME | /usr/bin/ndisasm -i -b32 /dev/stdin ; /bin/rm -f /tmp/$FILENAME
end
end
document assemble
Assemble instructions using nasm.
Type a line containing "end" to indicate the end.
If an address is specified, insert/modify instructions at that address.
If no address is specified, assembled instructions are printed to stdout.
Use the pseudo instruction "org ADDR" to set the base address.
end
 
define assemble_gas
printf "\nType code to assemble and hit Ctrl-D when finished.\n"
printf "You must use GNU assembler (AT&T) syntax.\n"
shell filename=$(mktemp); \
binfilename=$(mktemp); \
echo -e "Writing into: ${filename}\n"; \
cat > $filename; echo ""; \
as -o $binfilename < $filename; \
objdump -d -j .text $binfilename; \
rm -f $binfilename; \
rm -f $filename; \
echo -e "temporaly files deleted.\n"
end
document assemble_gas
Assemble instructions to binary opcodes. Uses GNU as and objdump.
Usage: assemble_gas
end
 
 
define dump_hexfile
dump ihex memory $arg0 $arg1 $arg2
end
document dump_hexfile
Write a range of memory to a file in Intel ihex (hexdump) format.
The range is specified by ADDR1 and ADDR2 addresses.
Usage: dump_hexfile FILENAME ADDR1 ADDR2
end
 
 
define dump_binfile
dump memory $arg0 $arg1 $arg2
end
document dump_binfile
Write a range of memory to a binary file.
The range is specified by ADDR1 and ADDR2 addresses.
Usage: dump_binfile FILENAME ADDR1 ADDR2
end
 
 
define cls
shell clear
end
document cls
Clear screen.
end
 
## backtrace coloring
define hook-backtrace
echo \033[01;33m
end
 
define hookpost-backtrace
echo \033[0m
end
 
## syntax highlighting
define hook-list
DS-start-redirect
end
 
define hookpost-list
DS-stop-redirect
end
 
define hook-disassemble
DS-start-redirect
end
 
define hookpost-disassemble
DS-stop-redirect
end
 
define hook-quit
shell rm /tmp/colorPipe 2> /dev/null
end
 
## functions
define current-instruction
DS-start-redirect
if $rip
x/i $rip
else
x/i $eip
end
DS-stop-redirect
end
 
define DS-start-redirect
if ($HIGHLIGHT > 0)
shell mkfifo /tmp/colorPipe
shell cat /tmp/colorPipe | highlight --syntax=asm --out-format=xterm256 &
set logging redirect on
set logging on /tmp/colorPipe
end
end
 
define DS-stop-redirect
if ($HIGHLIGHT > 0)
set logging off
set logging redirect off
shell sleep 0.1s
shell rm /tmp/colorPipe
end
end
 
define create-reg-snapshot
if $rip
#64bits version
set $rsp_b = $rsp
set $rbp_b = $rbp
set $rax_b = $rax
set $rbx_b = $rbx
set $rcx_b = $rcx
set $rdx_b = $rdx
set $rdi_b = $rdi
set $rsi_b = $rsi
set $r8_b = $r8
set $r9_b = $r9
set $r10_b = $r10
set $r11_b = $r11
set $r12_b = $r12
set $r13_b = $r13
set $r14_b = $r14
set $r15_b = $r15
else
#32bits version
set $esp_b = $esp
set $ebp_b = $ebp
set $eax_b = $eax
set $ebx_b = $ebx
set $ecx_b = $ecx
set $edx_b = $edx
set $edi_b = $edi
set $esi_b = $esi
end
 
if $st0
#fpu
set $st0_b = $st0
set $st1_b = $st1
set $st2_b = $st2
set $st3_b = $st3
set $st4_b = $st4
set $st5_b = $st5
set $st6_b = $st6
set $st7_b = $st7
set $fctrl_b = $fctrl
set $fstat_b = $fstat
set $ftag_b = $ftag
set $fiseg_b = $fiseg
set $fioff_b = $fioff
set $foseg_b = $foseg
set $fosff_b = $fosff
set $fop_b = $fop
end
 
if $xmm0
set $xmm0_b = $xmm0
set $xmm1_b = $xmm1
set $xmm2_b = $xmm2
set $xmm3_b = $xmm3
set $xmm4_b = $xmm4
set $xmm5_b = $xmm5
set $xmm6_b = $xmm6
set $xmm7_b = $xmm7
set $mxcsr_b = $mxcsr
end
 
if $xmm8
#64bit extension
set $xmm8_b = $xmm8
set $xmm9_b = $xmm9
set $xmm10_b = $xmm10
set $xmm11_b = $xmm11
set $xmm12_b = $xmm12
set $xmm13_b = $xmm13
set $xmm14_b = $xmm14
set $xmm15_b = $xmm15
end
 
if $mm0
#32bit extension
set $mm0_b = $mm0
set $mm1_b = $mm1
set $mm2_b = $mm2
set $mm3_b = $mm3
set $mm4_b = $mm4
set $mm5_b = $mm5
set $mm6_b = $mm6
set $mm7_b = $mm7
end
 
set $cs_b = $cs
set $ss_b = $ss
set $ds_b = $ds
set $es_b = $es
set $fs_b = $fs
set $gs_b = $gs
set $eflags_b = $eflags
set $created_snapshot = 1
end
 
define check-reg-snapshot
if ( $created_snapshot = 1 )
if $rip
#64bits version
if ( $rsp_b != $rsp )
printf "[RSP] 0x%x -> 0x%x\n", $rsp_b, $rsp
end
if ( $rbp_b != $rbp )
printf "[RBP] 0x%x -> 0x%x\n", $rbp_b, $rbp
end
if ( $rax_b != $rax )
printf "[RAX] 0x%x -> 0x%x\n", $rax_b, $rax
end
if ( $rbx_b != $rbx )
printf "[RBX] 0x%x -> 0x%x\n", $rbx_b, $rbx
end
 
if ( $rcx_b != $rcx )
printf "[RCX] 0x%x -> 0x%x\n", $rcx_b, $rcx
end
 
if ( $rdx_b != $rdx )
printf "[RDX] 0x%x -> 0x%x\n", $rdx_b, $rdx
end
 
if ( $rdi_b != $rdi )
printf "[RDI] 0x%x -> 0x%x\n", $rdi_b, $rdi
end
 
if ( $rsi_b != $rsi )
printf "[RSI] 0x%x -> 0x%x\n", $rsi_b, $rsi
end
 
if ( $r8_b != $r8 )
printf "[R8 ] 0x%x -> 0x%x\n", $r8_b, $r8
end
 
if ( $r9_b != $r9 )
printf "[R9 ] 0x%x -> 0x%x\n", $r9_b, $r9
end
 
if ( $r10_b != $r10 )
printf "[R10] 0x%x -> 0x%x\n", $r10_b, $r10
end
 
if ( $r11_b != $r11 )
printf "[R11] 0x%x -> 0x%x\n", $r11_b, $r11
end
 
if ( $r12_b != $r12 )
printf "[R12] 0x%x -> 0x%x\n", $r12_b, $r12
end
 
if ( $r13_b != $r13 )
printf "[R13] 0x%x -> 0x%x\n", $r13_b, $r13
end
 
if ( $r14_b != $r14 )
printf "[R14] 0x%x -> 0x%x\n", $r14_b, $r14
end
 
if ( $r15_b != $r15 )
printf "[R15] 0x%x -> 0x%x\n", $r15_b, $r15
end
else
#32bits version
if ( $esp_b != $esp )
printf "[ESP] 0x%x -> 0x%x\n", $esp_b, $esp
end
 
if ( $ebp_b != $ebp )
printf "[EBP] 0x%x -> 0x%x\n", $ebp_b, $ebp
end
 
if ( $eax_b != $eax )
printf "[EAX] 0x%x -> 0x%x\n", $eax_b, $eax
end
 
if ( $ebx_b != $ebx )
printf "[EBX] 0x%x -> 0x%x\n", $ebx_b, $ebx
end
 
if ( $ecx_b != $ecx )
printf "[ECX] 0x%x -> 0x%x\n", $ecx_b, $ecx
end
 
if ( $edx_b != $edx )
printf "[EDX] 0x%x -> 0x%x\n", $edx_b, $edx
end
 
if ( $edi_b != $edi )
printf "[EDI] 0x%x -> 0x%x\n", $edi_b, $edi
end
 
if ( $esi_b != $esi )
printf "[ESI] 0x%x -> 0x%x\n", $esi_b, $esi
end
end
 
if $st0
if ( $st0_b != $st0 )
printf "[ST0] 0x%x -> 0x%x\n", $st0_b, $st0
end
 
if ( $st1_b != $st1 )
printf "[ST1] 0x%x -> 0x%x\n", $st1_b, $st1
end
 
if ( $st2_b != $st2 )
printf "[ST2] 0x%x -> 0x%x\n", $st2_b, $st2
end
 
if ( $st3_b != $st3 )
printf "[ST3] 0x%x -> 0x%x\n", $st3_b, $st3
end
 
if ( $st4_b != $st4 )
printf "[ST4] 0x%x -> 0x%x\n", $st4_b, $st4
end
 
if ( $st5_b != $st5 )
printf "[ST5] 0x%x -> 0x%x\n", $st5_b, $st5
end
 
if ( $st6_b != $st6 )
printf "[ST6] 0x%x -> 0x%x\n", $st6_b, $st6
end
 
if ( $st7_b != $st7 )
printf "[ST7] 0x%x -> 0x%x\n", $st7_b, $st7
end
 
if ( $fctrl_b != $fctrl )
printf "[FCTRL] 0x%x -> 0x%x\n", $fctrl_b, $fctrl
end
 
if ( $fstat_b != $fstat )
printf "[FSTAT] 0x%x -> 0x%x\n", $fstat_b, $fstat
end
 
if ( $ftag_b != $ftag )
printf "[FTAG] 0x%x -> 0x%x\n", $ftag_b, $ftag
end
 
if ( $fiseg_b != $fiseg )
printf "[FISEG] 0x%x -> 0x%x\n", $fiseg_b, $fiseg
end
 
if ( $fioff_b != $fioff )
printf "[FIOFF] 0x%x -> 0x%x\n", $fioff_b, $fioff
end
 
if ( $foseg_b != $foseg )
printf "[FOSEG] 0x%x -> 0x%x\n", $foseg_b, $foseg
end
 
if ( $fosff_b != $fosff )
printf "[FOSFF] 0x%x -> 0x%x\n", $fosff_b, $fosff
end
 
if ( $fop_b != $fop )
printf "[FOP] 0x%x -> 0x%x\n", $fop_b, $fop
end
end
if $xmm0
if ( $xmm0_b != $xmm0 )
printf "[XMM0] 0x%016x%016x -> 0x%016x%016x\n", $xmm0_b.v2_int64[0], $xmm0_b.v2_int64[1], $xmm0.v2_int64[0], $xmm0.v2_int64[1]
end
 
if ( $xmm1_b != $xmm1 )
printf "[XMM1] 0x%016x%016x -> 0x%016x%016x\n", $xmm1_b.v2_int64[0], $xmm1_b.v2_int64[1], $xmm1.v2_int64[0], $xmm1.v2_int64[1]
end
 
if ( $xmm2_b != $xmm2 )
printf "[XMM2] 0x%016x%016x -> 0x%016x%016x\n", $xmm2_b.v2_int64[0], $xmm2_b.v2_int64[1], $xmm2.v2_int64[0], $xmm2.v2_int64[1]
end
 
if ( $xmm3_b != $xmm3 )
printf "[XMM3] 0x%016x%016x -> 0x%016x%016x\n", $xmm3_b.v2_int64[0], $xmm3_b.v2_int64[1], $xmm3.v2_int64[0], $xmm3.v2_int64[1]
end
 
if ( $xmm4_b != $xmm4 )
printf "[XMM4] 0x%016x%016x -> 0x%016x%016x\n", $xmm4_b.v2_int64[0], $xmm4_b.v2_int64[1], $xmm4.v2_int64[0], $xmm4.v2_int64[1]
end
 
if ( $xmm5_b != $xmm5 )
printf "[XMM5] 0x%016x%016x -> 0x%016x%016x\n", $xmm5_b.v2_int64[0], $xmm5_b.v2_int64[1], $xmm5.v2_int64[0], $xmm5.v2_int64[1]
end
 
if ( $xmm6_b != $xmm6 )
printf "[XMM6] 0x%016x%016x -> 0x%016x%016x\n", $xmm6_b.v2_int64[0], $xmm6_b.v2_int64[1], $xmm6.v2_int64[0], $xmm6.v2_int64[1]
end
 
if ( $xmm7_b != $xmm7 )
printf "[XMM7] 0x%016x%016x -> 0x%016x%016x\n", $xmm7_b.v2_int64[0], $xmm7_b.v2_int64[1], $xmm7.v2_int64[0], $xmm7.v2_int64[1]
end
 
if ( $mxcsr_b != $mxcsr )
printf "[MXCSR] 0x%x -> 0x%x\n", $mxcsr_b, $mxcsr
end
end
 
if $xmm8
if ( $xmm8_b != $xmm8 )
printf "[XMM8] 0x%016x%016x -> 0x%016x%016x\n", $xmm8_b.v2_int64[0], $xmm8_b.v2_int64[1], $xmm8.v2_int64[0], $xmm8.v2_int64[1]
end
 
if ( $xmm9_b != $xmm9 )
printf "[XMM9] 0x%016x%016x -> 0x%016x%016x\n", $xmm9_b.v2_int64[0], $xmm9_b.v2_int64[1], $xmm9.v2_int64[0], $xmm9.v2_int64[1]
end
 
if ( $xmm10_b != $xmm10 )
printf "[XMM10] 0x%016x%016x -> 0x%016x%016x\n", $xmm10_b.v2_int64[0], $xmm10_b.v2_int64[1], $xmm10.v2_int64[0], $xmm10.v2_int64[1]
end
 
if ( $xmm11_b != $xmm11 )
printf "[XMM11] 0x%016x%016x -> 0x%016x%016x\n", $xmm11_b.v2_int64[0], $xmm11_b.v2_int64[1], $xmm11.v2_int64[0], $xmm11.v2_int64[1]
end
 
if ( $xmm12_b != $xmm12 )
printf "[XMM12] 0x%016x%016x -> 0x%016x%016x\n", $xmm12_b.v2_int64[0], $xmm12_b.v2_int64[1], $xmm12.v2_int64[0], $xmm12.v2_int64[1]
end
 
if ( $xmm13_b != $xmm13 )
printf "[XMM13] 0x%016x%016x -> 0x%016x%016x\n", $xmm13_b.v2_int64[0], $xmm13_b.v2_int64[1], $xmm13.v2_int64[0], $xmm13.v2_int64[1]
end
 
if ( $xmm14_b != $xmm14 )
printf "[XMM14] 0x%016x%016x -> 0x%016x%016x\n", $xmm14_b.v2_int64[0], $xmm14_b.v2_int64[1], $xmm14.v2_int64[0], $xmm14.v2_int64[1]
end
 
if ( $xmm15_b != $xmm15 )
printf "[XMM15] 0x%016x%016x -> 0x%016x%016x\n", $xmm15_b.v2_int64[0], $xmm15_b.v2_int64[1], $xmm15.v2_int64[0], $xmm15.v2_int64[1]
end
end
 
if $mm0
if ( $mm0_b != $mm0 )
printf "[MM0] 0x%x -> 0x%x\n", $mm0_b.uint64, $mm0.uint64
end
 
if ( $mm1_b != $mm1 )
printf "[MM1] 0x%x -> 0x%x\n", $mm1_b.uint64, $mm1.uint64
end
 
if ( $mm2_b != $mm2 )
printf "[MM2] 0x%x -> 0x%x\n", $mm2_b.uint64, $mm2.uint64
end
 
if ( $mm3_b != $mm3 )
printf "[MM3] 0x%x -> 0x%x\n", $mm3_b.uint64, $mm3.uint64
end
 
if ( $mm4_b != $mm4 )
printf "[MM4] 0x%x -> 0x%x\n", $mm4_b.uint64, $mm4.uint64
end
 
if ( $mm5_b != $mm5 )
printf "[MM5] 0x%x -> 0x%x\n", $mm5_b.uint64, $mm5.uint64
end
 
if ( $mm6_b != $mm6 )
printf "[MM6] 0x%x -> 0x%x\n", $mm6_b.uint64, $mm6.uint64
end
 
if ( $mm7_b != $mm7 )
printf "[MM7] 0x%x -> 0x%x\n", $mm7_b.uint64, $mm7.uint64
end
end
 
if ( $cs_b != $cs )
printf "[CS ] 0x%x -> 0x%x\n", $cs_b, $cs
end
 
if ( $ss_b != $ss )
printf "[SS ] 0x%x -> 0x%x\n", $ss_b, $ss
end
 
if ( $ds_b != $ds )
printf "[DS ] 0x%x -> 0x%x\n", $ds_b, $ds
end
 
if ( $es_b != $es )
printf "[ES ] 0x%x -> 0x%x\n", $es_b, $es
end
 
if ( $fs_b != $fs )
printf "[FS ] 0x%x -> 0x%x\n", $fs_b, $fs
end
 
if ( $gs_b != $gs )
printf "[GS ] 0x%x -> 0x%x\n", $gs_b, $gs
end
 
if ( $eflags_b != $eflags )
printf "[EFLAGS] 0x%x -> 0x%x\n", $eflags_b, $eflags
end
end
end
 
## show debug info
define hook-stepi
if ($SHOW_CONTEXT > 0)
current-instruction
end
end
 
define hook-nexti
if ($SHOW_CONTEXT > 0)
current-instruction
end
end
 
define locals
info locals
end
 
define hook-stop
# this makes 'context' be called at every BP/step
if ($SHOW_CONTEXT > 0)
context
end
if ($SHOW_NEST_INSN > 0)
set $x = $_nest
while ($x > 0)
printf "\t"
set $x = $x - 1
end
end
end
document hook-stop
!!! FOR INTERNAL USE ONLY - DO NOT CALL !!!
end
 
define hook-return
hook-stepi
end
 
define hookpost-return
hook-stop
end
 
# _________________user tips_________________
# The 'tips' command is used to provide tutorial-like info to the user
define tips
printf "Tip Topic Commands:\n"
printf "\ttip_display : Automatically display values on each break\n"
printf "\ttip_patch : Patching binaries\n"
printf "\ttip_strip : Dealing with stripped binaries\n"
printf "\ttip_syntax : AT&T vs Intel syntax\n"
end
document tips
Provide a list of tips from users on various topics.
end
 
define tip_patch
printf "\n"
printf " PATCHING MEMORY\n"
printf "Any address can be patched using the 'set' command:\n"
printf "\t`set ADDR = VALUE` \te.g. `set *0x8049D6E = 0x90`\n"
printf "\n"
printf " PATCHING BINARY FILES\n"
printf "Use `set write` in order to patch the target executable\n"
printf "directly, instead of just patching memory\n"
printf "\t`set write on` \t`set write off`\n"
printf "Note that this means any patches to the code or data segments\n"
printf "will be written to the executable file\n"
printf "When either of these commands has been issued,\n"
printf "the file must be reloaded.\n"
printf "\n"
end
document tip_patch
Tips on patching memory and binary files.
end
 
define tip_strip
printf "\n"
printf " STOPPING BINARIES AT ENTRY POINT\n"
printf "Stripped binaries have no symbols, and are therefore tough to\n"
printf "start automatically. To debug a stripped binary, use\n"
printf "\tinfo file\n"
printf "to get the entry point of the file\n"
printf "The first few lines of output will look like this:\n"
printf "\tSymbols from '/tmp/a.out'\n"
printf "\tLocal exec file:\n"
printf "\t `/tmp/a.out', file type elf32-i386.\n"
printf "\t Entry point: 0x80482e0\n"
printf "Use this entry point to set an entry point:\n"
printf "\t`tbreak *0x80482e0`\n"
printf "The breakpoint will delete itself after the program stops as\n"
printf "the entry point\n"
printf "\n"
end
document tip_strip
Tips on dealing with stripped binaries.
end
 
define tip_syntax
printf "\n"
printf "\t INTEL SYNTAX AT&T SYNTAX\n"
printf "\tmnemonic dest, src, imm mnemonic src, dest, imm\n"
printf "\t[base+index*scale+disp] disp(base, index, scale)\n"
printf "\tregister: eax register: %%eax\n"
printf "\timmediate: 0xFF immediate: $0xFF\n"
printf "\tdereference: [addr] dereference: addr(,1)\n"
printf "\tabsolute addr: addr absolute addr: *addr\n"
printf "\tbyte insn: mov byte ptr byte insn: movb\n"
printf "\tword insn: mov word ptr word insn: movw\n"
printf "\tdword insn: mov dword ptr dword insn: movd\n"
printf "\tfar call: call far far call: lcall\n"
printf "\tfar jump: jmp far far jump: ljmp\n"
printf "\n"
printf "Note that order of operands in reversed, and that AT&T syntax\n"
printf "requires that all instructions referencing memory operands \n"
printf "use an operand size suffix (b, w, d, q)\n"
printf "\n"
end
document tip_syntax
Summary of Intel and AT&T syntax differences.
end
 
define tip_display
printf "\n"
printf "Any expression can be set to automatically be displayed every time\n"
printf "the target stops. The commands for this are:\n"
printf "\t`display expr' : automatically display expression 'expr'\n"
printf "\t`display' : show all displayed expressions\n"
printf "\t`undisplay num' : turn off autodisplay for expression # 'num'\n"
printf "Examples:\n"
printf "\t`display/x *(int *)$esp` : print top of stack\n"
printf "\t`display/x *(int *)($ebp+8)` : print first parameter\n"
printf "\t`display (char *)$esi` : print source string\n"
printf "\t`display (char *)$edi` : print destination string\n"
printf "\n"
end
document tip_display
Tips on automatically displaying values when a program stops.
end
 
# bunch of semi-useless commands
# enable and disable shortcuts for stop-on-solib-events fantastic trick!
define enablesolib
set stop-on-solib-events 1
end
document enablesolib
Shortcut to enable stop-on-solib-events trick!
end
 
define disablesolib
set stop-on-solib-events 0
end
document disablesolib
Shortcut to disable stop-on-solib-events trick!
end
 
# enable commands for different displays
define enableobjectivec
set $SHOWOBJECTIVEC = 1
end
document enableobjectivec
Enable display of objective-c information in the context window
end
 
define enablecpuregisters
set $SHOWCPUREGISTERS = 1
end
document enablecpuregisters
Enable display of cpu registers in the context window
end
 
define enablestack
set $SHOWSTACK = 1
end
document enablestack
Enable display of stack in the context window
end
 
define enabledatawin
set $SHOWDATAWIN = 1
end
document enabledatawin
Enable display of data window in the context window
end
 
define enablehighlighting
set $HIGHLIGHT = 1
end
document enablehighlighting
Enable syntax highlighting
end
 
# disable commands for different displays
define disableobjectivec
set $SHOWOBJECTIVEC = 0
end
document disableobjectivec
Disable display of objective-c information in the context window
end
 
define disablecpuregisters
set $SHOWCPUREGISTERS = 0
end
document disablecpuregisters
Disable display of cpu registers in the context window
end
 
define disablestack
set $SHOWSTACK = 0
end
document disablestack
Disable display of stack information in the context window
end
 
define disabledatawin
set $SHOWDATAWIN = 0
end
document disabledatawin
Disable display of data window in the context window
end
 
define disablehighlighting
set $HIGHLIGHT = 0
end
document disablehighlighting
Disable syntax highlighting
end
 
define 32bits
printf "Obsolete, arch is autodetected"
end
document 32bits
obsolete
end
 
define 64bits
printf "Obsolete, arch is autodetected"
end
document 64bits
obsolete
end
#EOF

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.