[
  {
    "path": ".github/FUNDING.yml",
    "content": "github: nikias\npatreon: nikias\ncustom: [\"https://www.paypal.me/NikiasBassen\"]\n"
  },
  {
    "path": ".github/workflows/build.yml",
    "content": "name: build\n\non:\n  push:\n  pull_request:\n  schedule:\n    - cron: '0 0 1 * *'\n\njobs:\n  build-linux-ubuntu:\n    runs-on: ubuntu-latest\n    steps:\n    - name: install dependencies\n      run: |\n          sudo apt-get update\n          sudo apt-get install libcurl4-openssl-dev libxml2-dev\n    - name: prepare environment\n      run: |\n          echo \"target_triplet=`gcc -dumpmachine`\" >> $GITHUB_ENV\n    - name: fetch libplist\n      uses: dawidd6/action-download-artifact@v6\n      with:\n        github_token: ${{secrets.GITHUB_TOKEN}}\n        workflow: build.yml\n        name: libplist-latest_${{env.target_triplet}}\n        repo: libimobiledevice/libplist\n    - name: fetch libusbmuxd\n      uses: dawidd6/action-download-artifact@v6\n      with:\n        github_token: ${{secrets.GITHUB_TOKEN}}\n        workflow: build.yml\n        name: libusbmuxd-latest_${{env.target_triplet}}\n        repo: libimobiledevice/libusbmuxd\n    - name: fetch libimobiledevice-glue\n      uses: dawidd6/action-download-artifact@v6\n      with:\n        github_token: ${{secrets.GITHUB_TOKEN}}\n        workflow: build.yml\n        name: libimobiledevice-glue-latest_${{env.target_triplet}}\n        repo: libimobiledevice/libimobiledevice-glue\n    - name: fetch libimobiledevice\n      uses: dawidd6/action-download-artifact@v6\n      with:\n        github_token: ${{secrets.GITHUB_TOKEN}}\n        workflow: build.yml\n        name: libimobiledevice-latest_${{env.target_triplet}}\n        repo: libimobiledevice/libimobiledevice\n    - name: install external dependencies\n      run: |\n          mkdir extract\n          for I in *.tar; do\n            tar -C extract -xvf $I\n          done\n          rm -rf extract/lib\n          sudo cp -r extract/* /\n          sudo ldconfig\n    - uses: actions/checkout@v4\n      with:\n        fetch-depth: 0\n    - name: autogen\n      run: ./autogen.sh PKG_CONFIG_PATH=/usr/local/lib/pkgconfig\n    - name: make\n      run: make\n    - name: make install\n      run: sudo make install\n    - name: prepare artifact\n      run: |\n          mkdir -p dest\n          DESTDIR=`pwd`/dest make install\n          tar -C dest -cf libideviceactivation.tar usr\n    - name: publish artifact\n      uses: actions/upload-artifact@v4\n      with:\n        name: libideviceactivation-latest_${{env.target_triplet}}\n        path: libideviceactivation.tar\n  build-macOS:\n    runs-on: macOS-latest\n    steps:\n    - name: install dependencies\n      run: |\n          if test -x \"`which port`\"; then\n            sudo port install libtool autoconf automake pkgconfig\n          else\n            brew install libtool autoconf automake pkgconfig\n          fi\n      shell: bash\n    - name: fetch libplist\n      uses: dawidd6/action-download-artifact@v6\n      with:\n        github_token: ${{secrets.GITHUB_TOKEN}}\n        workflow: build.yml\n        name: libplist-latest_macOS\n        repo: libimobiledevice/libplist\n    - name: fetch libusbmuxd\n      uses: dawidd6/action-download-artifact@v6\n      with:\n        github_token: ${{secrets.GITHUB_TOKEN}}\n        workflow: build.yml\n        name: libusbmuxd-latest_macOS\n        repo: libimobiledevice/libusbmuxd\n    - name: fetch libimobiledevice-glue\n      uses: dawidd6/action-download-artifact@v6\n      with:\n        github_token: ${{secrets.GITHUB_TOKEN}}\n        workflow: build.yml\n        name: libimobiledevice-glue-latest_macOS\n        repo: libimobiledevice/libimobiledevice-glue\n    - name: fetch libimobiledevice\n      uses: dawidd6/action-download-artifact@v6\n      with:\n        github_token: ${{secrets.GITHUB_TOKEN}}\n        workflow: build.yml\n        name: libimobiledevice-latest_macOS\n        repo: libimobiledevice/libimobiledevice\n    - name: install external dependencies\n      run: |\n          mkdir extract\n          for I in *.tar; do\n            tar -C extract -xvf $I\n          done\n          sudo cp -r extract/* /\n    - uses: actions/checkout@v4\n    - name: install additional requirements\n      run: |\n          SDKDIR=`xcrun --sdk macosx --show-sdk-path 2>/dev/null`\n          echo \"SDKDIR=$SDKDIR\" >> $GITHUB_ENV\n          TESTARCHS=\"arm64 x86_64\"\n          USEARCHS=\n          for ARCH in $TESTARCHS; do\n            if echo \"int main(int argc, char **argv) { return 0; }\" |clang -arch $ARCH -o /dev/null -isysroot $SDKDIR -x c - 2>/dev/null; then\n              USEARCHS=\"$USEARCHS -arch $ARCH\"\n            fi\n          done\n          export CFLAGS=\"$USEARCHS -isysroot $SDKDIR\"\n          echo \"Using CFLAGS: $CFLAGS\"\n          echo \"BUILD_CFLAGS=$CFLAGS\" >> $GITHUB_ENV\n    - name: autogen\n      run: |\n          export CFLAGS=\"${{env.BUILD_CFLAGS}} -Wno-nullability-completeness -Wno-expansion-to-defined\"\n          echo \"Using CFLAGS: $CFLAGS\"\n          ./autogen.sh PKG_CONFIG_PATH=/usr/local/lib/pkgconfig \\\n              libcurl_CFLAGS=\"-I${{env.SDKDIR}}/usr/include\" libcurl_LIBS=\"-lcurl\" \\\n              libxml2_CFLAGS=\"-I${{env.SDKDIR}}/usr/include\" libxml2_LIBS=\"-lxml2\" \\\n              libimobiledevice_CFLAGS=\"-I/usr/local/include\" libimobiledevice_LIBS=\"-L/usr/local/lib -limobiledevice-1.0\"\n    - name: make\n      run: make\n    - name: make install\n      run: sudo make install\n    - name: prepare artifact\n      run: |\n          mkdir -p dest\n          DESTDIR=`pwd`/dest make install\n          tar -C dest -cf libideviceactivation.tar usr\n    - name: publish artifact\n      uses: actions/upload-artifact@v4\n      with:\n        name: libideviceactivation-latest_macOS\n        path: libideviceactivation.tar\n  build-windows:\n    runs-on: windows-latest\n    defaults:\n      run:\n        shell: msys2 {0}\n    strategy:\n      fail-fast: false\n      matrix:\n        include: [\n          { msystem: MINGW64, arch: x86_64 },\n          { msystem: MINGW32, arch: i686   }\n        ]\n    steps:\n    - uses: msys2/setup-msys2@v2\n      with:\n        msystem: ${{ matrix.msystem }}\n        release: false\n        update: false\n        install: >-\n          base-devel\n          git\n          mingw-w64-${{ matrix.arch }}-gcc\n          mingw-w64-${{ matrix.arch }}-pkg-config\n          mingw-w64-${{ matrix.arch }}-openssl\n          mingw-w64-${{ matrix.arch }}-libxml2\n          make\n          libtool\n          autoconf\n          automake-wrapper\n    - name: prepare environment\n      run: |\n          dest=`echo ${{ matrix.msystem }} |tr [:upper:] [:lower:]`\n          echo \"dest=$dest\" >> $GITHUB_ENV\n          echo \"target_triplet=`gcc -dumpmachine`\" >> $GITHUB_ENV\n    - name: fetch libplist\n      uses: dawidd6/action-download-artifact@v6\n      with:\n        github_token: ${{secrets.GITHUB_TOKEN}}\n        workflow: build.yml\n        name: libplist-latest_${{ matrix.arch }}-${{ env.dest }}\n        repo: libimobiledevice/libplist\n    - name: fetch libusbmuxd\n      uses: dawidd6/action-download-artifact@v6\n      with:\n        github_token: ${{secrets.GITHUB_TOKEN}}\n        workflow: build.yml\n        name: libusbmuxd-latest_${{ matrix.arch }}-${{ env.dest }}\n        repo: libimobiledevice/libusbmuxd\n    - name: fetch libimobiledevice-glue\n      uses: dawidd6/action-download-artifact@v6\n      with:\n        github_token: ${{secrets.GITHUB_TOKEN}}\n        workflow: build.yml\n        name: libimobiledevice-glue-latest_${{ matrix.arch }}-${{ env.dest }}\n        repo: libimobiledevice/libimobiledevice-glue\n    - name: fetch libimobiledevice\n      uses: dawidd6/action-download-artifact@v6\n      with:\n        github_token: ${{secrets.GITHUB_TOKEN}}\n        workflow: build.yml\n        name: libimobiledevice-latest_${{ matrix.arch }}-${{ env.dest }}\n        repo: libimobiledevice/libimobiledevice\n    - name: install external dependencies\n      run: |\n          mkdir extract\n          for I in *.tar; do\n            tar -C extract -xvf $I\n          done\n          cp -r extract/* /\n    - uses: actions/checkout@v4\n    - name: install additional requirements\n      run: |\n          mkdir deps\n          FILENAME=\"libcurl-8.1.0-static.tar.bz2\"\n          curl -o $FILENAME.b64 -Ls \"https://gist.github.com/nikias/6c397a0a2f4f4eafd91b81cccd22b761/raw/85216e60af6787f3b351291165eb91bd585ff09a/libcurl-8.1.0-static-${{matrix.arch}}-${{env.dest}}.tar.bz2\"\n          base64 -d < $FILENAME.b64 > $FILENAME\n          tar -C deps -xjf $FILENAME\n          echo \"LIBCURL_CFLAGS=-I`pwd`/deps/include -DCURL_STATICLIB\" >> $GITHUB_ENV\n          echo \"LIBCURL_LIBS=-Xlinker `pwd`/deps/lib/libcurl.a -Xlinker /${{env.dest}}/lib/libzstd.a -Xlinker /${{env.dest}}/lib/libz.a -Xlinker -lws2_32 -Xlinker -lcrypt32 -Xlinker -lwldap32 -Xlinker -lbcrypt -Xlinker -lssl -Xlinker -lcrypto\" >> $GITHUB_ENV\n    - name: autogen\n      run: ./autogen.sh libcurl_CFLAGS=\"${{env.LIBCURL_CFLAGS}}\" libcurl_LIBS=\"${{env.LIBCURL_LIBS}}\"\n    - name: make\n      run: make\n    - name: make install\n      run: make install\n    - name: prepare artifact\n      run: |\n          mkdir -p dest\n          DESTDIR=`pwd`/dest make install\n          tar -C dest -cf libideviceactivation.tar ${{ env.dest }}\n    - name: publish artifact\n      uses: actions/upload-artifact@v4\n      with:\n        name: libideviceactivation-latest_${{ matrix.arch }}-${{ env.dest }}\n        path: libideviceactivation.tar\n"
  },
  {
    "path": ".gitignore",
    "content": "*.[oa]\n*~\n*.po\n*.lo\n*.la\n.*.swp\n*/.deps/*\n*.patch\nMakefile\nMakefile.in\naclocal.m4\nautom4te.cache\ncompile\nconfig.guess\nconfig.h\nconfig.h.in\nconfig.log\nconfig.status\nconfig.sub\nconfigure\ndepcomp\ninstall-sh\nlibideviceactivation-1.0.pc\nlibtool\nltmain.sh\nm4\nmissing\nsrc/.libs\ntools/.libs\ntools/ideviceactivation\nstamp-h1\n"
  },
  {
    "path": "AUTHORS",
    "content": "Konstantin Sokolov\nMartin Szulecki\nNikias Bassen\n"
  },
  {
    "path": "COPYING",
    "content": "                    GNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The GNU General Public License is a free, copyleft license for\nsoftware and other kinds of works.\n\n  The licenses for most software and other practical works are designed\nto take away your freedom to share and change the works.  By contrast,\nthe GNU General Public License is intended to guarantee your freedom to\nshare and change all versions of a program--to make sure it remains free\nsoftware for all its users.  We, the Free Software Foundation, use the\nGNU General Public License for most of our software; it applies also to\nany other work released this way by its authors.  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthem if you wish), that you receive source code or can get it if you\nwant it, that you can change the software or use pieces of it in new\nfree programs, and that you know you can do these things.\n\n  To protect your rights, we need to prevent others from denying you\nthese rights or asking you to surrender the rights.  Therefore, you have\ncertain responsibilities if you distribute copies of the software, or if\nyou modify it: responsibilities to respect the freedom of others.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must pass on to the recipients the same\nfreedoms that you received.  You must make sure that they, too, receive\nor can get the source code.  And you must show them these terms so they\nknow their rights.\n\n  Developers that use the GNU GPL protect your rights with two steps:\n(1) assert copyright on the software, and (2) offer you this License\ngiving you legal permission to copy, distribute and/or modify it.\n\n  For the developers' and authors' protection, the GPL clearly explains\nthat there is no warranty for this free software.  For both users' and\nauthors' sake, the GPL requires that modified versions be marked as\nchanged, so that their problems will not be attributed erroneously to\nauthors of previous versions.\n\n  Some devices are designed to deny users access to install or run\nmodified versions of the software inside them, although the manufacturer\ncan do so.  This is fundamentally incompatible with the aim of\nprotecting users' freedom to change the software.  The systematic\npattern of such abuse occurs in the area of products for individuals to\nuse, which is precisely where it is most unacceptable.  Therefore, we\nhave designed this version of the GPL to prohibit the practice for those\nproducts.  If such problems arise substantially in other domains, we\nstand ready to extend this provision to those domains in future versions\nof the GPL, as needed to protect the freedom of users.\n\n  Finally, every program is threatened constantly by software patents.\nStates should not allow patents to restrict development and use of\nsoftware on general-purpose computers, but in those that do, we wish to\navoid the special danger that patents applied to a free program could\nmake it effectively proprietary.  To prevent this, the GPL assures that\npatents cannot be used to render the program non-free.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                       TERMS AND CONDITIONS\n\n  0. Definitions.\n\n  \"This License\" refers to version 3 of the GNU General Public License.\n\n  \"Copyright\" also means copyright-like laws that apply to other kinds of\nworks, such as semiconductor masks.\n\n  \"The Program\" refers to any copyrightable work licensed under this\nLicense.  Each licensee is addressed as \"you\".  \"Licensees\" and\n\"recipients\" may be individuals or organizations.\n\n  To \"modify\" a work means to copy from or adapt all or part of the work\nin a fashion requiring copyright permission, other than the making of an\nexact copy.  The resulting work is called a \"modified version\" of the\nearlier work or a work \"based on\" the earlier work.\n\n  A \"covered work\" means either the unmodified Program or a work based\non the Program.\n\n  To \"propagate\" a work means to do anything with it that, without\npermission, would make you directly or secondarily liable for\ninfringement under applicable copyright law, except executing it on a\ncomputer or modifying a private copy.  Propagation includes copying,\ndistribution (with or without modification), making available to the\npublic, and in some countries other activities as well.\n\n  To \"convey\" a work means any kind of propagation that enables other\nparties to make or receive copies.  Mere interaction with a user through\na computer network, with no transfer of a copy, is not conveying.\n\n  An interactive user interface displays \"Appropriate Legal Notices\"\nto the extent that it includes a convenient and prominently visible\nfeature that (1) displays an appropriate copyright notice, and (2)\ntells the user that there is no warranty for the work (except to the\nextent that warranties are provided), that licensees may convey the\nwork under this License, and how to view a copy of this License.  If\nthe interface presents a list of user commands or options, such as a\nmenu, a prominent item in the list meets this criterion.\n\n  1. Source Code.\n\n  The \"source code\" for a work means the preferred form of the work\nfor making modifications to it.  \"Object code\" means any non-source\nform of a work.\n\n  A \"Standard Interface\" means an interface that either is an official\nstandard defined by a recognized standards body, or, in the case of\ninterfaces specified for a particular programming language, one that\nis widely used among developers working in that language.\n\n  The \"System Libraries\" of an executable work include anything, other\nthan the work as a whole, that (a) is included in the normal form of\npackaging a Major Component, but which is not part of that Major\nComponent, and (b) serves only to enable use of the work with that\nMajor Component, or to implement a Standard Interface for which an\nimplementation is available to the public in source code form.  A\n\"Major Component\", in this context, means a major essential component\n(kernel, window system, and so on) of the specific operating system\n(if any) on which the executable work runs, or a compiler used to\nproduce the work, or an object code interpreter used to run it.\n\n  The \"Corresponding Source\" for a work in object code form means all\nthe source code needed to generate, install, and (for an executable\nwork) run the object code and to modify the work, including scripts to\ncontrol those activities.  However, it does not include the work's\nSystem Libraries, or general-purpose tools or generally available free\nprograms which are used unmodified in performing those activities but\nwhich are not part of the work.  For example, Corresponding Source\nincludes interface definition files associated with source files for\nthe work, and the source code for shared libraries and dynamically\nlinked subprograms that the work is specifically designed to require,\nsuch as by intimate data communication or control flow between those\nsubprograms and other parts of the work.\n\n  The Corresponding Source need not include anything that users\ncan regenerate automatically from other parts of the Corresponding\nSource.\n\n  The Corresponding Source for a work in source code form is that\nsame work.\n\n  2. Basic Permissions.\n\n  All rights granted under this License are granted for the term of\ncopyright on the Program, and are irrevocable provided the stated\nconditions are met.  This License explicitly affirms your unlimited\npermission to run the unmodified Program.  The output from running a\ncovered work is covered by this License only if the output, given its\ncontent, constitutes a covered work.  This License acknowledges your\nrights of fair use or other equivalent, as provided by copyright law.\n\n  You may make, run and propagate covered works that you do not\nconvey, without conditions so long as your license otherwise remains\nin force.  You may convey covered works to others for the sole purpose\nof having them make modifications exclusively for you, or provide you\nwith facilities for running those works, provided that you comply with\nthe terms of this License in conveying all material for which you do\nnot control copyright.  Those thus making or running the covered works\nfor you must do so exclusively on your behalf, under your direction\nand control, on terms that prohibit them from making any copies of\nyour copyrighted material outside their relationship with you.\n\n  Conveying under any other circumstances is permitted solely under\nthe conditions stated below.  Sublicensing is not allowed; section 10\nmakes it unnecessary.\n\n  3. Protecting Users' Legal Rights From Anti-Circumvention Law.\n\n  No covered work shall be deemed part of an effective technological\nmeasure under any applicable law fulfilling obligations under article\n11 of the WIPO copyright treaty adopted on 20 December 1996, or\nsimilar laws prohibiting or restricting circumvention of such\nmeasures.\n\n  When you convey a covered work, you waive any legal power to forbid\ncircumvention of technological measures to the extent such circumvention\nis effected by exercising rights under this License with respect to\nthe covered work, and you disclaim any intention to limit operation or\nmodification of the work as a means of enforcing, against the work's\nusers, your or third parties' legal rights to forbid circumvention of\ntechnological measures.\n\n  4. Conveying Verbatim Copies.\n\n  You may convey verbatim copies of the Program's source code as you\nreceive it, in any medium, provided that you conspicuously and\nappropriately publish on each copy an appropriate copyright notice;\nkeep intact all notices stating that this License and any\nnon-permissive terms added in accord with section 7 apply to the code;\nkeep intact all notices of the absence of any warranty; and give all\nrecipients a copy of this License along with the Program.\n\n  You may charge any price or no price for each copy that you convey,\nand you may offer support or warranty protection for a fee.\n\n  5. Conveying Modified Source Versions.\n\n  You may convey a work based on the Program, or the modifications to\nproduce it from the Program, in the form of source code under the\nterms of section 4, provided that you also meet all of these conditions:\n\n    a) The work must carry prominent notices stating that you modified\n    it, and giving a relevant date.\n\n    b) The work must carry prominent notices stating that it is\n    released under this License and any conditions added under section\n    7.  This requirement modifies the requirement in section 4 to\n    \"keep intact all notices\".\n\n    c) You must license the entire work, as a whole, under this\n    License to anyone who comes into possession of a copy.  This\n    License will therefore apply, along with any applicable section 7\n    additional terms, to the whole of the work, and all its parts,\n    regardless of how they are packaged.  This License gives no\n    permission to license the work in any other way, but it does not\n    invalidate such permission if you have separately received it.\n\n    d) If the work has interactive user interfaces, each must display\n    Appropriate Legal Notices; however, if the Program has interactive\n    interfaces that do not display Appropriate Legal Notices, your\n    work need not make them do so.\n\n  A compilation of a covered work with other separate and independent\nworks, which are not by their nature extensions of the covered work,\nand which are not combined with it such as to form a larger program,\nin or on a volume of a storage or distribution medium, is called an\n\"aggregate\" if the compilation and its resulting copyright are not\nused to limit the access or legal rights of the compilation's users\nbeyond what the individual works permit.  Inclusion of a covered work\nin an aggregate does not cause this License to apply to the other\nparts of the aggregate.\n\n  6. Conveying Non-Source Forms.\n\n  You may convey a covered work in object code form under the terms\nof sections 4 and 5, provided that you also convey the\nmachine-readable Corresponding Source under the terms of this License,\nin one of these ways:\n\n    a) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by the\n    Corresponding Source fixed on a durable physical medium\n    customarily used for software interchange.\n\n    b) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by a\n    written offer, valid for at least three years and valid for as\n    long as you offer spare parts or customer support for that product\n    model, to give anyone who possesses the object code either (1) a\n    copy of the Corresponding Source for all the software in the\n    product that is covered by this License, on a durable physical\n    medium customarily used for software interchange, for a price no\n    more than your reasonable cost of physically performing this\n    conveying of source, or (2) access to copy the\n    Corresponding Source from a network server at no charge.\n\n    c) Convey individual copies of the object code with a copy of the\n    written offer to provide the Corresponding Source.  This\n    alternative is allowed only occasionally and noncommercially, and\n    only if you received the object code with such an offer, in accord\n    with subsection 6b.\n\n    d) Convey the object code by offering access from a designated\n    place (gratis or for a charge), and offer equivalent access to the\n    Corresponding Source in the same way through the same place at no\n    further charge.  You need not require recipients to copy the\n    Corresponding Source along with the object code.  If the place to\n    copy the object code is a network server, the Corresponding Source\n    may be on a different server (operated by you or a third party)\n    that supports equivalent copying facilities, provided you maintain\n    clear directions next to the object code saying where to find the\n    Corresponding Source.  Regardless of what server hosts the\n    Corresponding Source, you remain obligated to ensure that it is\n    available for as long as needed to satisfy these requirements.\n\n    e) Convey the object code using peer-to-peer transmission, provided\n    you inform other peers where the object code and Corresponding\n    Source of the work are being offered to the general public at no\n    charge under subsection 6d.\n\n  A separable portion of the object code, whose source code is excluded\nfrom the Corresponding Source as a System Library, need not be\nincluded in conveying the object code work.\n\n  A \"User Product\" is either (1) a \"consumer product\", which means any\ntangible personal property which is normally used for personal, family,\nor household purposes, or (2) anything designed or sold for incorporation\ninto a dwelling.  In determining whether a product is a consumer product,\ndoubtful cases shall be resolved in favor of coverage.  For a particular\nproduct received by a particular user, \"normally used\" refers to a\ntypical or common use of that class of product, regardless of the status\nof the particular user or of the way in which the particular user\nactually uses, or expects or is expected to use, the product.  A product\nis a consumer product regardless of whether the product has substantial\ncommercial, industrial or non-consumer uses, unless such uses represent\nthe only significant mode of use of the product.\n\n  \"Installation Information\" for a User Product means any methods,\nprocedures, authorization keys, or other information required to install\nand execute modified versions of a covered work in that User Product from\na modified version of its Corresponding Source.  The information must\nsuffice to ensure that the continued functioning of the modified object\ncode is in no case prevented or interfered with solely because\nmodification has been made.\n\n  If you convey an object code work under this section in, or with, or\nspecifically for use in, a User Product, and the conveying occurs as\npart of a transaction in which the right of possession and use of the\nUser Product is transferred to the recipient in perpetuity or for a\nfixed term (regardless of how the transaction is characterized), the\nCorresponding Source conveyed under this section must be accompanied\nby the Installation Information.  But this requirement does not apply\nif neither you nor any third party retains the ability to install\nmodified object code on the User Product (for example, the work has\nbeen installed in ROM).\n\n  The requirement to provide Installation Information does not include a\nrequirement to continue to provide support service, warranty, or updates\nfor a work that has been modified or installed by the recipient, or for\nthe User Product in which it has been modified or installed.  Access to a\nnetwork may be denied when the modification itself materially and\nadversely affects the operation of the network or violates the rules and\nprotocols for communication across the network.\n\n  Corresponding Source conveyed, and Installation Information provided,\nin accord with this section must be in a format that is publicly\ndocumented (and with an implementation available to the public in\nsource code form), and must require no special password or key for\nunpacking, reading or copying.\n\n  7. Additional Terms.\n\n  \"Additional permissions\" are terms that supplement the terms of this\nLicense by making exceptions from one or more of its conditions.\nAdditional permissions that are applicable to the entire Program shall\nbe treated as though they were included in this License, to the extent\nthat they are valid under applicable law.  If additional permissions\napply only to part of the Program, that part may be used separately\nunder those permissions, but the entire Program remains governed by\nthis License without regard to the additional permissions.\n\n  When you convey a copy of a covered work, you may at your option\nremove any additional permissions from that copy, or from any part of\nit.  (Additional permissions may be written to require their own\nremoval in certain cases when you modify the work.)  You may place\nadditional permissions on material, added by you to a covered work,\nfor which you have or can give appropriate copyright permission.\n\n  Notwithstanding any other provision of this License, for material you\nadd to a covered work, you may (if authorized by the copyright holders of\nthat material) supplement the terms of this License with terms:\n\n    a) Disclaiming warranty or limiting liability differently from the\n    terms of sections 15 and 16 of this License; or\n\n    b) Requiring preservation of specified reasonable legal notices or\n    author attributions in that material or in the Appropriate Legal\n    Notices displayed by works containing it; or\n\n    c) Prohibiting misrepresentation of the origin of that material, or\n    requiring that modified versions of such material be marked in\n    reasonable ways as different from the original version; or\n\n    d) Limiting the use for publicity purposes of names of licensors or\n    authors of the material; or\n\n    e) Declining to grant rights under trademark law for use of some\n    trade names, trademarks, or service marks; or\n\n    f) Requiring indemnification of licensors and authors of that\n    material by anyone who conveys the material (or modified versions of\n    it) with contractual assumptions of liability to the recipient, for\n    any liability that these contractual assumptions directly impose on\n    those licensors and authors.\n\n  All other non-permissive additional terms are considered \"further\nrestrictions\" within the meaning of section 10.  If the Program as you\nreceived it, or any part of it, contains a notice stating that it is\ngoverned by this License along with a term that is a further\nrestriction, you may remove that term.  If a license document contains\na further restriction but permits relicensing or conveying under this\nLicense, you may add to a covered work material governed by the terms\nof that license document, provided that the further restriction does\nnot survive such relicensing or conveying.\n\n  If you add terms to a covered work in accord with this section, you\nmust place, in the relevant source files, a statement of the\nadditional terms that apply to those files, or a notice indicating\nwhere to find the applicable terms.\n\n  Additional terms, permissive or non-permissive, may be stated in the\nform of a separately written license, or stated as exceptions;\nthe above requirements apply either way.\n\n  8. Termination.\n\n  You may not propagate or modify a covered work except as expressly\nprovided under this License.  Any attempt otherwise to propagate or\nmodify it is void, and will automatically terminate your rights under\nthis License (including any patent licenses granted under the third\nparagraph of section 11).\n\n  However, if you cease all violation of this License, then your\nlicense from a particular copyright holder is reinstated (a)\nprovisionally, unless and until the copyright holder explicitly and\nfinally terminates your license, and (b) permanently, if the copyright\nholder fails to notify you of the violation by some reasonable means\nprior to 60 days after the cessation.\n\n  Moreover, your license from a particular copyright holder is\nreinstated permanently if the copyright holder notifies you of the\nviolation by some reasonable means, this is the first time you have\nreceived notice of violation of this License (for any work) from that\ncopyright holder, and you cure the violation prior to 30 days after\nyour receipt of the notice.\n\n  Termination of your rights under this section does not terminate the\nlicenses of parties who have received copies or rights from you under\nthis License.  If your rights have been terminated and not permanently\nreinstated, you do not qualify to receive new licenses for the same\nmaterial under section 10.\n\n  9. Acceptance Not Required for Having Copies.\n\n  You are not required to accept this License in order to receive or\nrun a copy of the Program.  Ancillary propagation of a covered work\noccurring solely as a consequence of using peer-to-peer transmission\nto receive a copy likewise does not require acceptance.  However,\nnothing other than this License grants you permission to propagate or\nmodify any covered work.  These actions infringe copyright if you do\nnot accept this License.  Therefore, by modifying or propagating a\ncovered work, you indicate your acceptance of this License to do so.\n\n  10. Automatic Licensing of Downstream Recipients.\n\n  Each time you convey a covered work, the recipient automatically\nreceives a license from the original licensors, to run, modify and\npropagate that work, subject to this License.  You are not responsible\nfor enforcing compliance by third parties with this License.\n\n  An \"entity transaction\" is a transaction transferring control of an\norganization, or substantially all assets of one, or subdividing an\norganization, or merging organizations.  If propagation of a covered\nwork results from an entity transaction, each party to that\ntransaction who receives a copy of the work also receives whatever\nlicenses to the work the party's predecessor in interest had or could\ngive under the previous paragraph, plus a right to possession of the\nCorresponding Source of the work from the predecessor in interest, if\nthe predecessor has it or can get it with reasonable efforts.\n\n  You may not impose any further restrictions on the exercise of the\nrights granted or affirmed under this License.  For example, you may\nnot impose a license fee, royalty, or other charge for exercise of\nrights granted under this License, and you may not initiate litigation\n(including a cross-claim or counterclaim in a lawsuit) alleging that\nany patent claim is infringed by making, using, selling, offering for\nsale, or importing the Program or any portion of it.\n\n  11. Patents.\n\n  A \"contributor\" is a copyright holder who authorizes use under this\nLicense of the Program or a work on which the Program is based.  The\nwork thus licensed is called the contributor's \"contributor version\".\n\n  A contributor's \"essential patent claims\" are all patent claims\nowned or controlled by the contributor, whether already acquired or\nhereafter acquired, that would be infringed by some manner, permitted\nby this License, of making, using, or selling its contributor version,\nbut do not include claims that would be infringed only as a\nconsequence of further modification of the contributor version.  For\npurposes of this definition, \"control\" includes the right to grant\npatent sublicenses in a manner consistent with the requirements of\nthis License.\n\n  Each contributor grants you a non-exclusive, worldwide, royalty-free\npatent license under the contributor's essential patent claims, to\nmake, use, sell, offer for sale, import and otherwise run, modify and\npropagate the contents of its contributor version.\n\n  In the following three paragraphs, a \"patent license\" is any express\nagreement or commitment, however denominated, not to enforce a patent\n(such as an express permission to practice a patent or covenant not to\nsue for patent infringement).  To \"grant\" such a patent license to a\nparty means to make such an agreement or commitment not to enforce a\npatent against the party.\n\n  If you convey a covered work, knowingly relying on a patent license,\nand the Corresponding Source of the work is not available for anyone\nto copy, free of charge and under the terms of this License, through a\npublicly available network server or other readily accessible means,\nthen you must either (1) cause the Corresponding Source to be so\navailable, or (2) arrange to deprive yourself of the benefit of the\npatent license for this particular work, or (3) arrange, in a manner\nconsistent with the requirements of this License, to extend the patent\nlicense to downstream recipients.  \"Knowingly relying\" means you have\nactual knowledge that, but for the patent license, your conveying the\ncovered work in a country, or your recipient's use of the covered work\nin a country, would infringe one or more identifiable patents in that\ncountry that you have reason to believe are valid.\n\n  If, pursuant to or in connection with a single transaction or\narrangement, you convey, or propagate by procuring conveyance of, a\ncovered work, and grant a patent license to some of the parties\nreceiving the covered work authorizing them to use, propagate, modify\nor convey a specific copy of the covered work, then the patent license\nyou grant is automatically extended to all recipients of the covered\nwork and works based on it.\n\n  A patent license is \"discriminatory\" if it does not include within\nthe scope of its coverage, prohibits the exercise of, or is\nconditioned on the non-exercise of one or more of the rights that are\nspecifically granted under this License.  You may not convey a covered\nwork if you are a party to an arrangement with a third party that is\nin the business of distributing software, under which you make payment\nto the third party based on the extent of your activity of conveying\nthe work, and under which the third party grants, to any of the\nparties who would receive the covered work from you, a discriminatory\npatent license (a) in connection with copies of the covered work\nconveyed by you (or copies made from those copies), or (b) primarily\nfor and in connection with specific products or compilations that\ncontain the covered work, unless you entered into that arrangement,\nor that patent license was granted, prior to 28 March 2007.\n\n  Nothing in this License shall be construed as excluding or limiting\nany implied license or other defenses to infringement that may\notherwise be available to you under applicable patent law.\n\n  12. No Surrender of Others' Freedom.\n\n  If conditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot convey a\ncovered work so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you may\nnot convey it at all.  For example, if you agree to terms that obligate you\nto collect a royalty for further conveying from those to whom you convey\nthe Program, the only way you could satisfy both those terms and this\nLicense would be to refrain entirely from conveying the Program.\n\n  13. Use with the GNU Affero General Public License.\n\n  Notwithstanding any other provision of this License, you have\npermission to link or combine any covered work with a work licensed\nunder version 3 of the GNU Affero General Public License into a single\ncombined work, and to convey the resulting work.  The terms of this\nLicense will continue to apply to the part which is the covered work,\nbut the special requirements of the GNU Affero General Public License,\nsection 13, concerning interaction through a network will apply to the\ncombination as such.\n\n  14. Revised Versions of this License.\n\n  The Free Software Foundation may publish revised and/or new versions of\nthe GNU General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\n  Each version is given a distinguishing version number.  If the\nProgram specifies that a certain numbered version of the GNU General\nPublic License \"or any later version\" applies to it, you have the\noption of following the terms and conditions either of that numbered\nversion or of any later version published by the Free Software\nFoundation.  If the Program does not specify a version number of the\nGNU General Public License, you may choose any version ever published\nby the Free Software Foundation.\n\n  If the Program specifies that a proxy can decide which future\nversions of the GNU General Public License can be used, that proxy's\npublic statement of acceptance of a version permanently authorizes you\nto choose that version for the Program.\n\n  Later license versions may give you additional or different\npermissions.  However, no additional obligations are imposed on any\nauthor or copyright holder as a result of your choosing to follow a\nlater version.\n\n  15. Disclaimer of Warranty.\n\n  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\nAPPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY\nOF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\nIS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\nALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. Limitation of Liability.\n\n  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\nTHE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\nGENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\nUSE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\nDATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\nPARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\nEVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\nSUCH DAMAGES.\n\n  17. Interpretation of Sections 15 and 16.\n\n  If the disclaimer of warranty and limitation of liability provided\nabove cannot be given local legal effect according to their terms,\nreviewing courts shall apply local law that most closely approximates\nan absolute waiver of all civil liability in connection with the\nProgram, unless a warranty or assumption of liability accompanies a\ncopy of the Program in return for a fee.\n\n                     END OF TERMS AND CONDITIONS\n\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nstate the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program.  If not, see <http://www.gnu.org/licenses/>.\n\nAlso add information on how to contact you by electronic and paper mail.\n\n  If the program does terminal interaction, make it output a short\nnotice like this when it starts in an interactive mode:\n\n    <program>  Copyright (C) <year>  <name of author>\n    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, your program's commands\nmight be different; for a GUI interface, you would use an \"about box\".\n\n  You should also get your employer (if you work as a programmer) or school,\nif any, to sign a \"copyright disclaimer\" for the program, if necessary.\nFor more information on this, and how to apply and follow the GNU GPL, see\n<http://www.gnu.org/licenses/>.\n\n  The GNU General Public License does not permit incorporating your program\ninto proprietary programs.  If your program is a subroutine library, you\nmay consider it more useful to permit linking proprietary applications with\nthe library.  If this is what you want to do, use the GNU Lesser General\nPublic License instead of this License.  But first, please read\n<http://www.gnu.org/philosophy/why-not-lgpl.html>.\n"
  },
  {
    "path": "COPYING.LESSER",
    "content": "\t\t  GNU LESSER GENERAL PUBLIC LICENSE\n\t\t       Version 2.1, February 1999\n\n Copyright (C) 1991, 1999 Free Software Foundation, Inc.\n 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n[This is the first released version of the Lesser GPL.  It also counts\n as the successor of the GNU Library Public License, version 2, hence\n the version number 2.1.]\n\n\t\t\t    Preamble\n\n  The licenses for most software are designed to take away your\nfreedom to share and change it.  By contrast, the GNU General Public\nLicenses are intended to guarantee your freedom to share and change\nfree software--to make sure the software is free for all its users.\n\n  This license, the Lesser General Public License, applies to some\nspecially designated software packages--typically libraries--of the\nFree Software Foundation and other authors who decide to use it.  You\ncan use it too, but we suggest you first think carefully about whether\nthis license or the ordinary General Public License is the better\nstrategy to use in any particular case, based on the explanations below.\n\n  When we speak of free software, we are referring to freedom of use,\nnot price.  Our General Public Licenses are designed to make sure that\nyou have the freedom to distribute copies of free software (and charge\nfor this service if you wish); that you receive source code or can get\nit if you want it; that you can change the software and use pieces of\nit in new free programs; and that you are informed that you can do\nthese things.\n\n  To protect your rights, we need to make restrictions that forbid\ndistributors to deny you these rights or to ask you to surrender these\nrights.  These restrictions translate to certain responsibilities for\nyou if you distribute copies of the library or if you modify it.\n\n  For example, if you distribute copies of the library, whether gratis\nor for a fee, you must give the recipients all the rights that we gave\nyou.  You must make sure that they, too, receive or can get the source\ncode.  If you link other code with the library, you must provide\ncomplete object files to the recipients, so that they can relink them\nwith the library after making changes to the library and recompiling\nit.  And you must show them these terms so they know their rights.\n\n  We protect your rights with a two-step method: (1) we copyright the\nlibrary, and (2) we offer you this license, which gives you legal\npermission to copy, distribute and/or modify the library.\n\n  To protect each distributor, we want to make it very clear that\nthere is no warranty for the free library.  Also, if the library is\nmodified by someone else and passed on, the recipients should know\nthat what they have is not the original version, so that the original\nauthor's reputation will not be affected by problems that might be\nintroduced by others.\n\f\n  Finally, software patents pose a constant threat to the existence of\nany free program.  We wish to make sure that a company cannot\neffectively restrict the users of a free program by obtaining a\nrestrictive license from a patent holder.  Therefore, we insist that\nany patent license obtained for a version of the library must be\nconsistent with the full freedom of use specified in this license.\n\n  Most GNU software, including some libraries, is covered by the\nordinary GNU General Public License.  This license, the GNU Lesser\nGeneral Public License, applies to certain designated libraries, and\nis quite different from the ordinary General Public License.  We use\nthis license for certain libraries in order to permit linking those\nlibraries into non-free programs.\n\n  When a program is linked with a library, whether statically or using\na shared library, the combination of the two is legally speaking a\ncombined work, a derivative of the original library.  The ordinary\nGeneral Public License therefore permits such linking only if the\nentire combination fits its criteria of freedom.  The Lesser General\nPublic License permits more lax criteria for linking other code with\nthe library.\n\n  We call this license the \"Lesser\" General Public License because it\ndoes Less to protect the user's freedom than the ordinary General\nPublic License.  It also provides other free software developers Less\nof an advantage over competing non-free programs.  These disadvantages\nare the reason we use the ordinary General Public License for many\nlibraries.  However, the Lesser license provides advantages in certain\nspecial circumstances.\n\n  For example, on rare occasions, there may be a special need to\nencourage the widest possible use of a certain library, so that it becomes\na de-facto standard.  To achieve this, non-free programs must be\nallowed to use the library.  A more frequent case is that a free\nlibrary does the same job as widely used non-free libraries.  In this\ncase, there is little to gain by limiting the free library to free\nsoftware only, so we use the Lesser General Public License.\n\n  In other cases, permission to use a particular library in non-free\nprograms enables a greater number of people to use a large body of\nfree software.  For example, permission to use the GNU C Library in\nnon-free programs enables many more people to use the whole GNU\noperating system, as well as its variant, the GNU/Linux operating\nsystem.\n\n  Although the Lesser General Public License is Less protective of the\nusers' freedom, it does ensure that the user of a program that is\nlinked with the Library has the freedom and the wherewithal to run\nthat program using a modified version of the Library.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.  Pay close attention to the difference between a\n\"work based on the library\" and a \"work that uses the library\".  The\nformer contains code derived from the library, whereas the latter must\nbe combined with the library in order to run.\n\f\n\t\t  GNU LESSER GENERAL PUBLIC LICENSE\n   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION\n\n  0. This License Agreement applies to any software library or other\nprogram which contains a notice placed by the copyright holder or\nother authorized party saying it may be distributed under the terms of\nthis Lesser General Public License (also called \"this License\").\nEach licensee is addressed as \"you\".\n\n  A \"library\" means a collection of software functions and/or data\nprepared so as to be conveniently linked with application programs\n(which use some of those functions and data) to form executables.\n\n  The \"Library\", below, refers to any such software library or work\nwhich has been distributed under these terms.  A \"work based on the\nLibrary\" means either the Library or any derivative work under\ncopyright law: that is to say, a work containing the Library or a\nportion of it, either verbatim or with modifications and/or translated\nstraightforwardly into another language.  (Hereinafter, translation is\nincluded without limitation in the term \"modification\".)\n\n  \"Source code\" for a work means the preferred form of the work for\nmaking modifications to it.  For a library, complete source code means\nall the source code for all modules it contains, plus any associated\ninterface definition files, plus the scripts used to control compilation\nand installation of the library.\n\n  Activities other than copying, distribution and modification are not\ncovered by this License; they are outside its scope.  The act of\nrunning a program using the Library is not restricted, and output from\nsuch a program is covered only if its contents constitute a work based\non the Library (independent of the use of the Library in a tool for\nwriting it).  Whether that is true depends on what the Library does\nand what the program that uses the Library does.\n  \n  1. You may copy and distribute verbatim copies of the Library's\ncomplete source code as you receive it, in any medium, provided that\nyou conspicuously and appropriately publish on each copy an\nappropriate copyright notice and disclaimer of warranty; keep intact\nall the notices that refer to this License and to the absence of any\nwarranty; and distribute a copy of this License along with the\nLibrary.\n\n  You may charge a fee for the physical act of transferring a copy,\nand you may at your option offer warranty protection in exchange for a\nfee.\n\f\n  2. You may modify your copy or copies of the Library or any portion\nof it, thus forming a work based on the Library, and copy and\ndistribute such modifications or work under the terms of Section 1\nabove, provided that you also meet all of these conditions:\n\n    a) The modified work must itself be a software library.\n\n    b) You must cause the files modified to carry prominent notices\n    stating that you changed the files and the date of any change.\n\n    c) You must cause the whole of the work to be licensed at no\n    charge to all third parties under the terms of this License.\n\n    d) If a facility in the modified Library refers to a function or a\n    table of data to be supplied by an application program that uses\n    the facility, other than as an argument passed when the facility\n    is invoked, then you must make a good faith effort to ensure that,\n    in the event an application does not supply such function or\n    table, the facility still operates, and performs whatever part of\n    its purpose remains meaningful.\n\n    (For example, a function in a library to compute square roots has\n    a purpose that is entirely well-defined independent of the\n    application.  Therefore, Subsection 2d requires that any\n    application-supplied function or table used by this function must\n    be optional: if the application does not supply it, the square\n    root function must still compute square roots.)\n\nThese requirements apply to the modified work as a whole.  If\nidentifiable sections of that work are not derived from the Library,\nand can be reasonably considered independent and separate works in\nthemselves, then this License, and its terms, do not apply to those\nsections when you distribute them as separate works.  But when you\ndistribute the same sections as part of a whole which is a work based\non the Library, the distribution of the whole must be on the terms of\nthis License, whose permissions for other licensees extend to the\nentire whole, and thus to each and every part regardless of who wrote\nit.\n\nThus, it is not the intent of this section to claim rights or contest\nyour rights to work written entirely by you; rather, the intent is to\nexercise the right to control the distribution of derivative or\ncollective works based on the Library.\n\nIn addition, mere aggregation of another work not based on the Library\nwith the Library (or with a work based on the Library) on a volume of\na storage or distribution medium does not bring the other work under\nthe scope of this License.\n\n  3. You may opt to apply the terms of the ordinary GNU General Public\nLicense instead of this License to a given copy of the Library.  To do\nthis, you must alter all the notices that refer to this License, so\nthat they refer to the ordinary GNU General Public License, version 2,\ninstead of to this License.  (If a newer version than version 2 of the\nordinary GNU General Public License has appeared, then you can specify\nthat version instead if you wish.)  Do not make any other change in\nthese notices.\n\f\n  Once this change is made in a given copy, it is irreversible for\nthat copy, so the ordinary GNU General Public License applies to all\nsubsequent copies and derivative works made from that copy.\n\n  This option is useful when you wish to copy part of the code of\nthe Library into a program that is not a library.\n\n  4. You may copy and distribute the Library (or a portion or\nderivative of it, under Section 2) in object code or executable form\nunder the terms of Sections 1 and 2 above provided that you accompany\nit with the complete corresponding machine-readable source code, which\nmust be distributed under the terms of Sections 1 and 2 above on a\nmedium customarily used for software interchange.\n\n  If distribution of object code is made by offering access to copy\nfrom a designated place, then offering equivalent access to copy the\nsource code from the same place satisfies the requirement to\ndistribute the source code, even though third parties are not\ncompelled to copy the source along with the object code.\n\n  5. A program that contains no derivative of any portion of the\nLibrary, but is designed to work with the Library by being compiled or\nlinked with it, is called a \"work that uses the Library\".  Such a\nwork, in isolation, is not a derivative work of the Library, and\ntherefore falls outside the scope of this License.\n\n  However, linking a \"work that uses the Library\" with the Library\ncreates an executable that is a derivative of the Library (because it\ncontains portions of the Library), rather than a \"work that uses the\nlibrary\".  The executable is therefore covered by this License.\nSection 6 states terms for distribution of such executables.\n\n  When a \"work that uses the Library\" uses material from a header file\nthat is part of the Library, the object code for the work may be a\nderivative work of the Library even though the source code is not.\nWhether this is true is especially significant if the work can be\nlinked without the Library, or if the work is itself a library.  The\nthreshold for this to be true is not precisely defined by law.\n\n  If such an object file uses only numerical parameters, data\nstructure layouts and accessors, and small macros and small inline\nfunctions (ten lines or less in length), then the use of the object\nfile is unrestricted, regardless of whether it is legally a derivative\nwork.  (Executables containing this object code plus portions of the\nLibrary will still fall under Section 6.)\n\n  Otherwise, if the work is a derivative of the Library, you may\ndistribute the object code for the work under the terms of Section 6.\nAny executables containing that work also fall under Section 6,\nwhether or not they are linked directly with the Library itself.\n\f\n  6. As an exception to the Sections above, you may also combine or\nlink a \"work that uses the Library\" with the Library to produce a\nwork containing portions of the Library, and distribute that work\nunder terms of your choice, provided that the terms permit\nmodification of the work for the customer's own use and reverse\nengineering for debugging such modifications.\n\n  You must give prominent notice with each copy of the work that the\nLibrary is used in it and that the Library and its use are covered by\nthis License.  You must supply a copy of this License.  If the work\nduring execution displays copyright notices, you must include the\ncopyright notice for the Library among them, as well as a reference\ndirecting the user to the copy of this License.  Also, you must do one\nof these things:\n\n    a) Accompany the work with the complete corresponding\n    machine-readable source code for the Library including whatever\n    changes were used in the work (which must be distributed under\n    Sections 1 and 2 above); and, if the work is an executable linked\n    with the Library, with the complete machine-readable \"work that\n    uses the Library\", as object code and/or source code, so that the\n    user can modify the Library and then relink to produce a modified\n    executable containing the modified Library.  (It is understood\n    that the user who changes the contents of definitions files in the\n    Library will not necessarily be able to recompile the application\n    to use the modified definitions.)\n\n    b) Use a suitable shared library mechanism for linking with the\n    Library.  A suitable mechanism is one that (1) uses at run time a\n    copy of the library already present on the user's computer system,\n    rather than copying library functions into the executable, and (2)\n    will operate properly with a modified version of the library, if\n    the user installs one, as long as the modified version is\n    interface-compatible with the version that the work was made with.\n\n    c) Accompany the work with a written offer, valid for at\n    least three years, to give the same user the materials\n    specified in Subsection 6a, above, for a charge no more\n    than the cost of performing this distribution.\n\n    d) If distribution of the work is made by offering access to copy\n    from a designated place, offer equivalent access to copy the above\n    specified materials from the same place.\n\n    e) Verify that the user has already received a copy of these\n    materials or that you have already sent this user a copy.\n\n  For an executable, the required form of the \"work that uses the\nLibrary\" must include any data and utility programs needed for\nreproducing the executable from it.  However, as a special exception,\nthe materials to be distributed need not include anything that is\nnormally distributed (in either source or binary form) with the major\ncomponents (compiler, kernel, and so on) of the operating system on\nwhich the executable runs, unless that component itself accompanies\nthe executable.\n\n  It may happen that this requirement contradicts the license\nrestrictions of other proprietary libraries that do not normally\naccompany the operating system.  Such a contradiction means you cannot\nuse both them and the Library together in an executable that you\ndistribute.\n\f\n  7. You may place library facilities that are a work based on the\nLibrary side-by-side in a single library together with other library\nfacilities not covered by this License, and distribute such a combined\nlibrary, provided that the separate distribution of the work based on\nthe Library and of the other library facilities is otherwise\npermitted, and provided that you do these two things:\n\n    a) Accompany the combined library with a copy of the same work\n    based on the Library, uncombined with any other library\n    facilities.  This must be distributed under the terms of the\n    Sections above.\n\n    b) Give prominent notice with the combined library of the fact\n    that part of it is a work based on the Library, and explaining\n    where to find the accompanying uncombined form of the same work.\n\n  8. You may not copy, modify, sublicense, link with, or distribute\nthe Library except as expressly provided under this License.  Any\nattempt otherwise to copy, modify, sublicense, link with, or\ndistribute the Library is void, and will automatically terminate your\nrights under this License.  However, parties who have received copies,\nor rights, from you under this License will not have their licenses\nterminated so long as such parties remain in full compliance.\n\n  9. You are not required to accept this License, since you have not\nsigned it.  However, nothing else grants you permission to modify or\ndistribute the Library or its derivative works.  These actions are\nprohibited by law if you do not accept this License.  Therefore, by\nmodifying or distributing the Library (or any work based on the\nLibrary), you indicate your acceptance of this License to do so, and\nall its terms and conditions for copying, distributing or modifying\nthe Library or works based on it.\n\n  10. Each time you redistribute the Library (or any work based on the\nLibrary), the recipient automatically receives a license from the\noriginal licensor to copy, distribute, link with or modify the Library\nsubject to these terms and conditions.  You may not impose any further\nrestrictions on the recipients' exercise of the rights granted herein.\nYou are not responsible for enforcing compliance by third parties with\nthis License.\n\f\n  11. If, as a consequence of a court judgment or allegation of patent\ninfringement or for any other reason (not limited to patent issues),\nconditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot\ndistribute so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you\nmay not distribute the Library at all.  For example, if a patent\nlicense would not permit royalty-free redistribution of the Library by\nall those who receive copies directly or indirectly through you, then\nthe only way you could satisfy both it and this License would be to\nrefrain entirely from distribution of the Library.\n\nIf any portion of this section is held invalid or unenforceable under any\nparticular circumstance, the balance of the section is intended to apply,\nand the section as a whole is intended to apply in other circumstances.\n\nIt is not the purpose of this section to induce you to infringe any\npatents or other property right claims or to contest validity of any\nsuch claims; this section has the sole purpose of protecting the\nintegrity of the free software distribution system which is\nimplemented by public license practices.  Many people have made\ngenerous contributions to the wide range of software distributed\nthrough that system in reliance on consistent application of that\nsystem; it is up to the author/donor to decide if he or she is willing\nto distribute software through any other system and a licensee cannot\nimpose that choice.\n\nThis section is intended to make thoroughly clear what is believed to\nbe a consequence of the rest of this License.\n\n  12. If the distribution and/or use of the Library is restricted in\ncertain countries either by patents or by copyrighted interfaces, the\noriginal copyright holder who places the Library under this License may add\nan explicit geographical distribution limitation excluding those countries,\nso that distribution is permitted only in or among countries not thus\nexcluded.  In such case, this License incorporates the limitation as if\nwritten in the body of this License.\n\n  13. The Free Software Foundation may publish revised and/or new\nversions of the Lesser General Public License from time to time.\nSuch new versions will be similar in spirit to the present version,\nbut may differ in detail to address new problems or concerns.\n\nEach version is given a distinguishing version number.  If the Library\nspecifies a version number of this License which applies to it and\n\"any later version\", you have the option of following the terms and\nconditions either of that version or of any later version published by\nthe Free Software Foundation.  If the Library does not specify a\nlicense version number, you may choose any version ever published by\nthe Free Software Foundation.\n\f\n  14. If you wish to incorporate parts of the Library into other free\nprograms whose distribution conditions are incompatible with these,\nwrite to the author to ask for permission.  For software which is\ncopyrighted by the Free Software Foundation, write to the Free\nSoftware Foundation; we sometimes make exceptions for this.  Our\ndecision will be guided by the two goals of preserving the free status\nof all derivatives of our free software and of promoting the sharing\nand reuse of software generally.\n\n\t\t\t    NO WARRANTY\n\n  15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO\nWARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.\nEXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR\nOTHER PARTIES PROVIDE THE LIBRARY \"AS IS\" WITHOUT WARRANTY OF ANY\nKIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE\nIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE\nLIBRARY IS WITH YOU.  SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME\nTHE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN\nWRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY\nAND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU\nFOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR\nCONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE\nLIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING\nRENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A\nFAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF\nSUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH\nDAMAGES.\n\n\t\t     END OF TERMS AND CONDITIONS\n\f\n           How to Apply These Terms to Your New Libraries\n\n  If you develop a new library, and you want it to be of the greatest\npossible use to the public, we recommend making it free software that\neveryone can redistribute and change.  You can do so by permitting\nredistribution under these terms (or, alternatively, under the terms of the\nordinary General Public License).\n\n  To apply these terms, attach the following notices to the library.  It is\nsafest to attach them to the start of each source file to most effectively\nconvey the exclusion of warranty; and each file should have at least the\n\"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the library's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This library is free software; you can redistribute it and/or\n    modify it under the terms of the GNU Lesser General Public\n    License as published by the Free Software Foundation; either\n    version 2.1 of the License, or (at your option) any later version.\n\n    This library is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n    Lesser General Public License for more details.\n\n    You should have received a copy of the GNU Lesser General Public\n    License along with this library; if not, write to the Free Software\n    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\n\nAlso add information on how to contact you by electronic and paper mail.\n\nYou should also get your employer (if you work as a programmer) or your\nschool, if any, to sign a \"copyright disclaimer\" for the library, if\nnecessary.  Here is a sample; alter the names:\n\n  Yoyodyne, Inc., hereby disclaims all copyright interest in the\n  library `Frob' (a library for tweaking knobs) written by James Random Hacker.\n\n  <signature of Ty Coon>, 1 April 1990\n  Ty Coon, President of Vice\n\nThat's all there is to it!\n"
  },
  {
    "path": "Makefile.am",
    "content": "AUTOMAKE_OPTIONS = foreign\nACLOCAL_AMFLAGS = -I m4\nSUBDIRS = src include tools man\n\nEXTRA_DIST = \\\n\tREADME.md \\\n\tgit-version-gen\n\nDISTCHECK_CONFIGURE_FLAGS =\n\ndist-hook:\n\t@if ! git diff --quiet; then echo \"Uncommitted changes present; not releasing\"; exit 1; fi\n\techo $(VERSION) > $(distdir)/.tarball-version\n\nindent:\n\tindent -kr -ut -ts4 -l120 src/*.c src/*.h dev/*.c\n"
  },
  {
    "path": "NEWS",
    "content": "Version 1.1.1\n~~~~~~~~~~~~~\n\n* Changes:\n  - Ignore SIGPIPE signal\n  - Add \"--network\" and \"--version\" options to ideviceactivation tool\n  - Bump libimobiledevice dependency to 1.3.0\n  - Bump libplist dependency to 2.2.0\n  - Improve README.md with project description, installation, contributing and\n    usage sections\n  - Rename library and all related files by adding an API version resulting\n    in \"libideviceactivation-1.0\"\n\nVersion 1.1.0\n~~~~~~~~~~~~~\n\n* Changes:\n  - Updated to use new mobileactivation service (requires latest libimobiledevice),\n    introducing 'drmHandshake' / session mode for activating newer devices\n  - Add API calls to query if an input field is secure and to get its placeholder (buddyml)\n  - Mask input on console when querying secure input fields\n  - Fix parsing of updated activation lock buddyml page\n  - Add '-b' command line switch to run non-interactively\n  - Remove length check on UDID argument to support newer devices\n  - Set CURLOPT_FOLLOWLOCATION to handle 302 redirects from Apples activation server\n  - Add new 'state' command to query device for activation state\n  - Lots of other bug fixes\n\nVersion 1.0.0\n~~~~~~~~~~~~~\n\n* Changes:\n  - Add basic man page for ideviceactivation tool\n  - Avoid exporting-non-public symbols\n  - Add \"--version\" argument to print version number in ideviceactivation tool\n  - Add \"--service\" argument to allow setting custom activaton service URL\n\nVersion 0.9.0\n~~~~~~~~~~~~~\n\n* Changes:\n  - Refactor interface to allow handling forms\n  - BuddyML and HTML parsing support\n  - Minor fixes\n\nVersion 0.5.0\n~~~~~~~~~~~~~\n\n* Changes:\n  - Add debug level setter to enable verbose curl debugging\n  - Minor fixes\n\nVersion 0.1.0\n~~~~~~~~~~~~~\n\n* Changes:\n  - Implement basic API to interact with activation webservice\n  - Add basic ideviceactivation tool\n  - Setup build system\n"
  },
  {
    "path": "README.md",
    "content": "# libideviceactivation\n\n*A library to manage the activation process of Apple iOS devices.*\n\n![](https://github.com/libimobiledevice/libideviceactivation/actions/workflows/build.yml/badge.svg)\n\n## Features\n\nThis project provides an interface to activate and deactivate iOS devices by\ntalking to Apple's webservice alongside a command-line utility named\n`ideviceactivation`.\n\nSome key features are:\n\n- **Status:** Implements complete activation and deactivation process\n- **Compatibility**: Supports legacy and latest activation webservice APIs\n- **Utility:** Provides `ideviceactivation` utility for command-line usage\n- **Interactive:** Requests user input if the activation process uses forms\n- **Cross-Platform:** Tested on Linux, macOS, Windows and Android platforms\n\n## Installation / Getting started\n\n### Debian / Ubuntu Linux\n\nFirst install all required dependencies and build tools:\n```shell\nsudo apt-get install \\\n\tbuild-essential \\\n\tpkg-config \\\n\tcheckinstall \\\n\tgit \\\n\tautoconf \\\n\tautomake \\\n\tlibtool-bin \\\n\tlibplist-dev \\\n\tlibimobiledevice-dev \\\n\tlibxml2-dev \\\n\tlibcurl4-openssl-dev \\\n\tusbmuxd\n```\n\nThen clone the actual project repository:\n```shell\ngit clone https://github.com/libimobiledevice/libideviceactivation.git\ncd libideviceactivation\n```\n\nNow you can build and install it:\n```shell\n./autogen.sh\nmake\nsudo make install\n```\n\n## Usage\n\nTo query the activation state of a device use:\n```shell\nideviceactivation state\n```\n\nTo activate a device use:\n```shell\nideviceactivation activate\n```\n\nPlease consult the usage information or manual page for a full documentation of\navailable command line options:\n```shell\nideviceactivation --help\nman ideviceactivation\n```\n\n## Contributing\n\nWe welcome contributions from anyone and are grateful for every pull request!\n\nIf you'd like to contribute, please fork the `master` branch, change, commit and\nsend a pull request for review. Once approved it can be merged into the main\ncode base.\n\nIf you plan to contribute larger changes or a major refactoring, please create a\nticket first to discuss the idea upfront to ensure less effort for everyone.\n\nPlease make sure your contribution adheres to:\n* Try to follow the code style of the project\n* Commit messages should describe the change well without being too short\n* Try to split larger changes into individual commits of a common domain\n* Use your real name and a valid email address for your commits\n\nWe are still working on the guidelines so bear with us!\n\n## Links\n\n* Homepage: https://libimobiledevice.org/\n* Repository: https://github.com/libimobiledevice/libideviceactivation.git\n* Repository (Mirror): https://git.libimobiledevice.org/libideviceactivation.git\n* Issue Tracker: https://github.com/libimobiledevice/libideviceactivation/issues\n* Mailing List: https://lists.libimobiledevice.org/mailman/listinfo/libimobiledevice-devel\n* Twitter: https://twitter.com/libimobiledev\n\n## License\n\nThis library is licensed under the [GNU Lesser General Public License v2.1](https://www.gnu.org/licenses/lgpl-2.1.en.html),\nalso included in the repository in the `COPYING.LESSER` file.\n\nThe `ideviceactivation` utility is licensed under the [GNU General Public License v3.0](https://www.gnu.org/licenses/gpl-3.0.en.html),\nalso included in the repository in the `COPYING` file.\n\n## Credits\n\nInspired by the activation utility from Joshua Hill aka p0sixninja:\nhttps://github.com/posixninja/ideviceactivate/\n\nApple, iPhone, iPad, iPod, iPod Touch, Apple TV, Apple Watch, Mac, iOS,\niPadOS, tvOS, watchOS, and macOS are trademarks of Apple Inc.\n\nThis project is an independent software library and has not been authorized,\nsponsored, or otherwise approved by Apple Inc.\n\nREADME Updated on: 2024-10-22\n"
  },
  {
    "path": "autogen.sh",
    "content": "#!/bin/sh\n\nolddir=`pwd`\nsrcdir=`dirname $0`\ntest -z \"$srcdir\" && srcdir=.\n\n(\n  cd \"$srcdir\"\n\n  gprefix=`which glibtoolize 2>&1 >/dev/null`\n  if [ $? -eq 0 ]; then\n    glibtoolize --force\n  else\n    libtoolize --force\n  fi\n  aclocal -I m4\n  autoheader\n  automake --add-missing\n  autoconf\n\n  cd \"$olddir\"\n)\n\nif [ -z \"$NOCONFIGURE\" ]; then\n  $srcdir/configure \"$@\"\nfi\n"
  },
  {
    "path": "configure.ac",
    "content": "#                                               -*- Autoconf -*-\n# Process this file with autoconf to produce a configure script.\n\nAC_PREREQ([2.68])\nAC_INIT([libideviceactivation], [m4_esyscmd(./git-version-gen $RELEASE_VERSION)], [https://github.com/libimobiledevice/libideviceactivation/issues], [], [https://libimobiledevice.org])\nAM_INIT_AUTOMAKE([dist-bzip2 no-dist-gzip check-news])\nm4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES])\nAC_CONFIG_SRCDIR([src/])\nAC_CONFIG_HEADERS([config.h])\nAC_CONFIG_MACRO_DIR([m4])\n\ndnl libtool versioning\n# +1 : 0 : +1  == adds new functions to the interface\n# +1 : 0 : 0   == changes or removes functions (changes include both\n#                 changes to the signature and the semantic)\n#  ? :+1 : ?   == just internal changes\n# CURRENT : REVISION : AGE\nLIBIDEVICEACTIVATION_SO_VERSION=3:0:1\n\ndnl Minimum package versions\nLIBIMOBILEDEVICE_VERSION=1.3.0\nLIBPLIST_VERSION=2.2.0\nLIBCURL_VERSION=7.20\nLIBXML2_VERSION=2.9\n\nAC_SUBST(LIBIDEVICEACTIVATION_SO_VERSION)\nAC_SUBST(LIBIMOBILEDEVICE_VERSION)\nAC_SUBST(LIBPLIST_VERSION)\nAC_SUBST(LIBCURL_VERSION)\nAC_SUBST(LIBXML2_VERSION)\n\n# Checks for programs.\nAC_PROG_CC\n#AC_PROG_CXX\nAM_PROG_CC_C_O\nLT_INIT\n\n# Checks for libraries.\nPKG_CHECK_MODULES(libimobiledevice, libimobiledevice-1.0 >= $LIBIMOBILEDEVICE_VERSION)\nPKG_CHECK_MODULES(libplist, libplist-2.0 >= $LIBPLIST_VERSION)\nPKG_CHECK_MODULES(libcurl, libcurl >= $LIBCURL_VERSION)\nPKG_CHECK_MODULES(libxml2, libxml-2.0 >= $LIBXML2_VERSION)\n\n# Checks for header files.\nAC_CHECK_HEADERS([stdint.h stdlib.h string.h sys/socket.h])\n\n# Checks for typedefs, structures, and compiler characteristics.\nAC_C_CONST\nAC_TYPE_SIZE_T\nAC_TYPE_SSIZE_T\nAC_TYPE_UINT16_T\nAC_TYPE_UINT32_T\nAC_TYPE_UINT8_T\n\n# Checks for library functions.\nAC_CHECK_FUNCS([strcasecmp strdup strerror strndup])\n\n# Check for operating system\nAC_MSG_CHECKING([for platform-specific build settings])\ncase ${host_os} in\n  *mingw32*|*cygwin*)\n    AC_MSG_RESULT([${host_os}])\n    win32=true\n    deplibs_check_method='pass_all'\n    ;;\n  darwin*|*android*)\n    AC_MSG_RESULT([${host_os}])\n    ;;\n  *)\n    AC_MSG_RESULT([${host_os}])\n    ;;\nesac\nAM_CONDITIONAL(WIN32, test x$win32 = xtrue)\n\nAS_COMPILER_FLAGS(GLOBAL_CFLAGS, \"-Wall -Wextra -Wmissing-declarations -Wredundant-decls -Wshadow -Wpointer-arith  -Wwrite-strings -Wswitch-default -Wno-unused-parameter -fsigned-char -fvisibility=hidden\")\n\nif test \"x$enable_static\" = \"xyes\" -a \"x$enable_shared\" = \"xno\"; then\n  GLOBAL_CFLAGS+=\" -DIDEVICE_ACTIVATION_STATIC\"\nfi\n\nAC_SUBST(GLOBAL_CFLAGS)\n\nm4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])\n\nAC_CONFIG_FILES([\nMakefile\nsrc/Makefile\nsrc/libideviceactivation-1.0.pc\ninclude/Makefile\ntools/Makefile\nman/Makefile\n])\nAC_OUTPUT\n\necho \"\nConfiguration for $PACKAGE $VERSION:\n-------------------------------------------\n\n  Install prefix: .........: $prefix\n\n  Now type 'make' to build $PACKAGE $VERSION,\n  and then 'make install' for installation.\n\"\n"
  },
  {
    "path": "git-version-gen",
    "content": "#!/bin/sh\nSRCDIR=`dirname $0`\nif test -n \"$1\"; then\n  VER=$1\nelse\n  if test -r \"${SRCDIR}/.git\" && test -x \"`which git`\" ; then\n    git update-index -q --refresh\n    if ! VER=`git describe --tags --dirty 2>/dev/null`; then\n      COMMIT=`git rev-parse --short HEAD`\n      DIRTY=`git diff --quiet HEAD || echo \"-dirty\"`\n      VER=`sed -n '1,/RE/s/Version \\(.*\\)/\\1/p' ${SRCDIR}/NEWS`-git-${COMMIT}${DIRTY}\n    fi\n  else\n    if test -f \"${SRCDIR}/.tarball-version\"; then\n      VER=`cat \"${SRCDIR}/.tarball-version\"`\n    fi\n  fi\nfi\nVER=`printf %s \"$VER\" | head -n1`\nprintf %s \"$VER\"\n"
  },
  {
    "path": "include/Makefile.am",
    "content": "nobase_include_HEADERS = \\\n\tlibideviceactivation.h\n"
  },
  {
    "path": "include/libideviceactivation.h",
    "content": "/**\n * @file libideviceactivation.h\n * @brief Manage device activation process.\n *\n * Copyright (c) 2016-2019 Nikias Bassen, All Rights Reserved.\n * Copyright (c) 2014-2015 Martin Szulecki, All Rights Reserved.\n * Copyright (c) 2011-2014 Mirell Development, All Rights Reserved.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\n */\n\n#ifndef LIBIDEVICEACTIVATION_H\n#define LIBIDEVICEACTIVATION_H\n\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#include <libimobiledevice/lockdown.h>\n#include <plist/plist.h>\n\n#ifndef IDEVICE_ACTIVATION_API\n  #ifdef IDEVICE_ACTIVATION_STATIC\n    #define IDEVICE_ACTIVATION_API\n  #elif defined(_WIN32)\n    #define IDEVICE_ACTIVATION_API __declspec(dllimport)\n  #else\n    #define IDEVICE_ACTIVATION_API\n  #endif\n#endif\n\ntypedef enum {\n\tIDEVICE_ACTIVATION_E_SUCCESS                =  0,\n\tIDEVICE_ACTIVATION_E_INCOMPLETE_INFO        = -1,\n\tIDEVICE_ACTIVATION_E_OUT_OF_MEMORY          = -2,\n\tIDEVICE_ACTIVATION_E_UNKNOWN_CONTENT_TYPE   = -3,\n\tIDEVICE_ACTIVATION_E_BUDDYML_PARSING_ERROR  = -4,\n\tIDEVICE_ACTIVATION_E_PLIST_PARSING_ERROR    = -5,\n\tIDEVICE_ACTIVATION_E_HTML_PARSING_ERROR     = -6,\n\tIDEVICE_ACTIVATION_E_UNSUPPORTED_FIELD_TYPE = -7,\n\tIDEVICE_ACTIVATION_E_INTERNAL_ERROR         = -255\n} idevice_activation_error_t;\n\ntypedef enum {\n\tIDEVICE_ACTIVATION_CLIENT_MOBILE_ACTIVATION,\n\tIDEVICE_ACTIVATION_CLIENT_ITUNES\n} idevice_activation_client_type_t;\n\ntypedef struct idevice_activation_request_private idevice_activation_request;\ntypedef idevice_activation_request* idevice_activation_request_t;\ntypedef struct idevice_activation_response_private idevice_activation_response;\ntypedef idevice_activation_response* idevice_activation_response_t;\n\n/* Interface */\n\nIDEVICE_ACTIVATION_API void idevice_activation_set_debug_level(int level);\n\nIDEVICE_ACTIVATION_API idevice_activation_error_t idevice_activation_request_new(idevice_activation_client_type_t activation_type, idevice_activation_request_t* request);\nIDEVICE_ACTIVATION_API idevice_activation_error_t idevice_activation_request_new_from_lockdownd(idevice_activation_client_type_t activation_type, lockdownd_client_t lockdown, idevice_activation_request_t* request);\nIDEVICE_ACTIVATION_API idevice_activation_error_t idevice_activation_drm_handshake_request_new(idevice_activation_client_type_t client_type, idevice_activation_request_t* request);\nIDEVICE_ACTIVATION_API void idevice_activation_request_free(idevice_activation_request_t request);\n\nIDEVICE_ACTIVATION_API void idevice_activation_request_get_fields(idevice_activation_request_t request, plist_t* fields);\nIDEVICE_ACTIVATION_API void idevice_activation_request_set_fields(idevice_activation_request_t request, plist_t fields);\nIDEVICE_ACTIVATION_API void idevice_activation_request_set_fields_from_response(idevice_activation_request_t request, const idevice_activation_response_t response);\nIDEVICE_ACTIVATION_API void idevice_activation_request_set_field(idevice_activation_request_t request, const char* key, const char* value);\nIDEVICE_ACTIVATION_API void idevice_activation_request_get_field(idevice_activation_request_t request, const char* key, char** value);\n\nIDEVICE_ACTIVATION_API void idevice_activation_request_get_url(idevice_activation_request_t request, const char** url);\nIDEVICE_ACTIVATION_API void idevice_activation_request_set_url(idevice_activation_request_t request, const char* url);\n\nIDEVICE_ACTIVATION_API idevice_activation_error_t idevice_activation_response_new(idevice_activation_response_t* response);\nIDEVICE_ACTIVATION_API idevice_activation_error_t idevice_activation_response_new_from_html(const char* content, idevice_activation_response_t* response);\nIDEVICE_ACTIVATION_API idevice_activation_error_t idevice_activation_response_to_buffer(idevice_activation_response_t response, char** buffer, size_t* size);\nIDEVICE_ACTIVATION_API void idevice_activation_response_free(idevice_activation_response_t response);\n\nIDEVICE_ACTIVATION_API void idevice_activation_response_get_field(idevice_activation_response_t response, const char* key, char** value);\nIDEVICE_ACTIVATION_API void idevice_activation_response_get_fields(idevice_activation_response_t response, plist_t* fields);\nIDEVICE_ACTIVATION_API void idevice_activation_response_get_label(idevice_activation_response_t response, const char* key, char** value);\nIDEVICE_ACTIVATION_API void idevice_activation_response_get_placeholder(idevice_activation_response_t response, const char* key, char **value);\n\nIDEVICE_ACTIVATION_API void idevice_activation_response_get_title(idevice_activation_response_t response, const char** title);\nIDEVICE_ACTIVATION_API void idevice_activation_response_get_description(idevice_activation_response_t response, const char** description);\nIDEVICE_ACTIVATION_API void idevice_activation_response_get_activation_record(idevice_activation_response_t response, plist_t* activation_record);\nIDEVICE_ACTIVATION_API void idevice_activation_response_get_headers(idevice_activation_response_t response, plist_t* headers);\n\nIDEVICE_ACTIVATION_API int idevice_activation_response_is_activation_acknowledged(idevice_activation_response_t response);\nIDEVICE_ACTIVATION_API int idevice_activation_response_is_authentication_required(idevice_activation_response_t response);\nIDEVICE_ACTIVATION_API int idevice_activation_response_field_requires_input(idevice_activation_response_t response, const char* key);\nIDEVICE_ACTIVATION_API int idevice_activation_response_field_secure_input(idevice_activation_response_t response, const char* key);\nIDEVICE_ACTIVATION_API int idevice_activation_response_has_errors(idevice_activation_response_t response);\n\nIDEVICE_ACTIVATION_API idevice_activation_error_t idevice_activation_send_request(idevice_activation_request_t request, idevice_activation_response_t* response);\n\n#ifdef __cplusplus\n}\n#endif\n\n#endif\n"
  },
  {
    "path": "man/Makefile.am",
    "content": "man_MANS = ideviceactivation.1\nEXTRA_DIST = $(man_MANS)\n"
  },
  {
    "path": "man/ideviceactivation.1",
    "content": ".TH \"ideviceactivation\" 1\n.SH NAME\nideviceactivation \\- Activate or deactivate an iOS device.\n.SH SYNOPSIS\n.B ideviceactivation\nactivate [OPTIONS]\n\n.B ideviceactivation\ndeactivate [OPTIONS]\n\n.B ideviceactivation\nstate [OPTIONS]\n\n.SH DESCRIPTION\n\nAllows to activate and deactivate iOS devices by talking to Apple's webservice.\n\nIf the activation process uses forms, input will be requested from the user.\n\n.SH COMMANDS\n.TP\n.B activate\nAttempt to activate the device.\n.TP\n.B deactivate\nDeactivates the device.\n.TP\n.B state\nQuery device for activation state.\n\n.SH OPTIONS\n.TP\n.B \\-d, \\-\\-debug\nEnable communication debugging.\n.TP\n.B \\-u, \\-\\-udid UDID\nTarget specific device by UDID.\n.TP\n.B \\-n, \\-\\-network\nConnect to network device.\n.TP\n.B \\-b, \\-\\-batch\nExplicitly run in non-interactive mode (default: auto-detect).\n.TP\n.B \\-s, \\-\\-service URL\nUse activation webservice at URL instead of default.\n.TP\n.B \\-v, \\-\\-version\nPrint version information and exit.\n.TP\n.B \\-h, \\-\\-help\nPrints usage information.\n\n.SH AUTHOR\nMartin Szulecki\n\n.SH ON THE WEB\nhttp://www.libimobiledevice.org\n\nhttps://github.com/libimobiledevice/libideviceactivation/\n"
  },
  {
    "path": "src/Makefile.am",
    "content": "AM_CPPFLAGS = \\\n\t-I$(top_srcdir)/include\n\nAM_CFLAGS = \\\n\t$(GLOBAL_CFLAGS) \\\n\t$(libimobiledevice_CFLAGS) \\\n\t$(libplist_CFLAGS) \\\n\t$(libcurl_CFLAGS) \\\n\t$(libxml2_CFLAGS)\n\nAM_LDFLAGS = \\\n\t$(GLOBAL_LIBS) \\\n\t$(libimobiledevice_LIBS) \\\n\t$(libplist_LIBS) \\\n\t$(libcurl_LIBS) \\\n\t$(libxml2_LIBS)\n\nlib_LTLIBRARIES = libideviceactivation-1.0.la\nlibideviceactivation_1_0_la_LDFLAGS = $(AM_LDFLAGS) -version-info $(LIBIDEVICEACTIVATION_SO_VERSION) -no-undefined\nlibideviceactivation_1_0_la_SOURCES = \\\n\t\tactivation.c\n\nif WIN32\nlibideviceactivation_1_0_la_LDFLAGS += -avoid-version\nendif\n\npkgconfigdir = $(libdir)/pkgconfig\npkgconfig_DATA = libideviceactivation-1.0.pc\n"
  },
  {
    "path": "src/activation.c",
    "content": "/**\n * @file activation.c\n *\n * Copyright (c) 2016-2019 Nikias Bassen, All Rights Reserved.\n * Copyright (c) 2014-2015 Martin Szulecki, All Rights Reserved.\n * Copyright (c) 2011-2014 Mirell Development, All Rights Reserved.\n *\n * This library is free software; you can redistribute it and/or\n * modify it under the terms of the GNU Lesser General Public\n * License as published by the Free Software Foundation; either\n * version 2.1 of the License, or (at your option) any later version.\n *\n * This library is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this library; if not, write to the Free Software\n * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA\n */\n\n#ifdef HAVE_CONFIG_H\n#include <config.h>\n#endif\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <libxml/parser.h>\n#include <libxml/xpath.h>\n#include <libxml/HTMLtree.h>\n#include <curl/curl.h>\n\n#ifdef IDEVICE_ACTIVATION_STATIC\n  #define IDEVICE_ACTIVATION_API\n#elif defined(_WIN32)\n  #define IDEVICE_ACTIVATION_API __declspec( dllexport )\n#else\n  #if __GNUC__ >= 4\n    #define IDEVICE_ACTIVATION_API __attribute__((visibility(\"default\")))\n  #else\n    #define IDEVICE_ACTIVATION_API\n  #endif\n#endif\n\n#ifdef _WIN32\n#include <windows.h>\n#define strncasecmp _strnicmp\n#endif\n\n#include <libideviceactivation.h>\n\n// Reference: https://stackoverflow.com/a/2390626/1806760\n// Initializer/finalizer sample for MSVC and GCC/Clang.\n// 2010-2016 Joe Lowe. Released into the public domain.\n\n#ifdef __cplusplus\n    #define INITIALIZER(f) \\\n        static void f(void); \\\n        struct f##_t_ { f##_t_(void) { f(); } }; static f##_t_ f##_; \\\n        static void f(void)\n#elif defined(_MSC_VER)\n    #pragma section(\".CRT$XCU\",read)\n    #define INITIALIZER2_(f,p) \\\n        static void f(void); \\\n        __declspec(allocate(\".CRT$XCU\")) void (*f##_)(void) = f; \\\n        __pragma(comment(linker,\"/include:\" p #f \"_\")) \\\n        static void f(void)\n    #ifdef _WIN64\n        #define INITIALIZER(f) INITIALIZER2_(f,\"\")\n    #else\n        #define INITIALIZER(f) INITIALIZER2_(f,\"_\")\n    #endif\n#else\n    #define INITIALIZER(f) \\\n        static void f(void) __attribute__((__constructor__)); \\\n        static void f(void)\n#endif\n\n#define IDEVICE_ACTIVATION_USER_AGENT_IOS \"iOS Device Activator (MobileActivation-592.103.2)\"\n#define IDEVICE_ACTIVATION_USER_AGENT_ITUNES \"iTunes/11.1.4 (Macintosh; OS X 10.9.1) AppleWebKit/537.73.11\"\n#define IDEVICE_ACTIVATION_DEFAULT_URL \"https://albert.apple.com/deviceservices/deviceActivation\"\n#define IDEVICE_ACTIVATION_DRM_HANDSHAKE_DEFAULT_URL \"https://albert.apple.com/deviceservices/drmHandshake\"\n\ntypedef enum {\n\tIDEVICE_ACTIVATION_CONTENT_TYPE_URL_ENCODED,\n\tIDEVICE_ACTIVATION_CONTENT_TYPE_MULTIPART_FORMDATA,\n\tIDEVICE_ACTIVATION_CONTENT_TYPE_HTML,\n\tIDEVICE_ACTIVATION_CONTENT_TYPE_BUDDYML,\n\tIDEVICE_ACTIVATION_CONTENT_TYPE_PLIST,\n\tIDEVICE_ACTIVATION_CONTENT_TYPE_UNKNOWN\n} idevice_activation_content_type_t;\n\nstruct idevice_activation_request_private {\n\tidevice_activation_client_type_t client_type;\n\tidevice_activation_content_type_t content_type;\n\tchar* url;\n\tplist_t fields;\n};\n\nstruct idevice_activation_response_private {\n\tchar* raw_content;\n\tsize_t raw_content_size;\n\tidevice_activation_content_type_t content_type;\n\tchar* title;\n\tchar* description;\n\tplist_t activation_record;\n\tplist_t headers;\n\tplist_t fields;\n\tplist_t fields_require_input;\n\tplist_t fields_secure_input;\n\tplist_t labels;\n\tplist_t labels_placeholder;\n\tint is_activation_ack;\n\tint is_auth_required;\n\tint has_errors;\n};\n\nstatic void internal_libideviceactivation_deinit(void)\n{\n\tcurl_global_cleanup();\n}\n\nINITIALIZER(internal_libideviceactivation_init)\n{\n\tcurl_global_init(CURL_GLOBAL_ALL);\n\tatexit(internal_libideviceactivation_deinit);\n}\n\nstatic int debug_level = 0;\n\nvoid idevice_activation_set_debug_level(int level) {\n\tdebug_level = level;\n}\n\nstatic idevice_activation_error_t idevice_activation_activation_record_from_plist(idevice_activation_response_t response, plist_t plist)\n{\n\tplist_t record = plist_dict_get_item(plist, \"ActivationRecord\");\n\tif (record != NULL) {\n\t\tplist_t ack_received = plist_dict_get_item(record, \"ack-received\");\n\t\tif (ack_received) {\n\t\t\tuint8_t val = 0;\n\t\t\tplist_get_bool_val(ack_received, &val);\n\t\t\tif (val) {\n\t\t\t\tresponse->is_activation_ack = 1;\n\t\t\t}\n\t\t}\n\t\tresponse->activation_record = plist_new_data(response->raw_content, response->raw_content_size);\n\t} else {\n\t\tplist_t activation_node = plist_dict_get_item(plist, \"iphone-activation\");\n\t\tif (!activation_node) {\n\t\t\tactivation_node = plist_dict_get_item(plist, \"device-activation\");\n\t\t}\n\t\tif (!activation_node) {\n\t\t\treturn IDEVICE_ACTIVATION_E_PLIST_PARSING_ERROR;\n\t\t}\n\t\tplist_t ack_received = plist_dict_get_item(activation_node, \"ack-received\");\n\t\tif (ack_received) {\n\t\t\tuint8_t val = 0;\n\t\t\tplist_get_bool_val(ack_received, &val);\n\t\t\tif (val) {\n\t\t\t\tresponse->is_activation_ack = 1;\n\t\t\t}\n\t\t}\n\t\trecord = plist_dict_get_item(activation_node, \"activation-record\");\n\t\tif (record) {\n\t\t\tresponse->activation_record = plist_copy(record);\n\t\t}\n\t}\n\treturn IDEVICE_ACTIVATION_E_SUCCESS;\n}\n\nstatic void idevice_activation_response_add_field(idevice_activation_response_t response, const char* key, const char* value, int required_input, int secure_input)\n{\n\tplist_dict_set_item(response->fields, key, plist_new_string(value));\n\tif (required_input) {\n\t\tplist_dict_set_item(response->fields_require_input, key, plist_new_bool(1));\n\t}\n\tif (secure_input) {\n\t\tplist_dict_set_item(response->fields_secure_input, key, plist_new_bool(1));\n\t}\n}\n\nstatic idevice_activation_error_t idevice_activation_parse_buddyml_response(idevice_activation_response_t response)\n{\n\tidevice_activation_error_t result = IDEVICE_ACTIVATION_E_SUCCESS;\n\txmlDocPtr doc = NULL;\n\txmlXPathContextPtr context = NULL;\n\txmlXPathObjectPtr xpath_result = NULL;\n\tint i = 0;\n\n\tif (response->content_type != IDEVICE_ACTIVATION_CONTENT_TYPE_BUDDYML)\n\t\treturn IDEVICE_ACTIVATION_E_UNKNOWN_CONTENT_TYPE;\n\n\tdoc = xmlReadMemory(response->raw_content, response->raw_content_size, \"ideviceactivation.xml\", NULL, XML_PARSE_NOERROR);\n\tif (!doc) {\n\t\tresult = IDEVICE_ACTIVATION_E_BUDDYML_PARSING_ERROR;\n\t\tgoto cleanup;\n\t}\n\n\tcontext = xmlXPathNewContext(doc);\n\tif (!context) {\n\t\tresult = IDEVICE_ACTIVATION_E_BUDDYML_PARSING_ERROR;\n\t\tgoto cleanup;\n\t}\n\n\t// check for an error\n\t// <navigationBar> appears directly under <xmlui> only in case of an error\n\txpath_result = xmlXPathEvalExpression((const xmlChar*) \"/xmlui/navigationBar/@title\", context);\n\tif (!xpath_result) {\n\t\tresult = IDEVICE_ACTIVATION_E_INTERNAL_ERROR;\n\t\tgoto cleanup;\n\t}\n\n\tif (xpath_result->nodesetval && xpath_result->nodesetval->nodeNr) {\n\t\txmlChar* content =  xmlNodeListGetString(doc, xpath_result->nodesetval->nodeTab[0]->xmlChildrenNode, 1);\n\t\tif (content) {\n\t\t\tresponse->title = strdup((const char*) content);\n\t\t\txmlFree(content);\n\t\t}\n\n\t\tresponse->has_errors = 1;\n\t\tgoto cleanup;\n\t}\n\n\t// check for activation ack\n\tif (xpath_result) {\n\t\txmlXPathFreeObject(xpath_result);\n\t\txpath_result = NULL;\n\t}\n\txpath_result = xmlXPathEvalExpression((const xmlChar*) \"/xmlui/clientInfo[@ack-received='true']\", context);\n\tif (!xpath_result) {\n\t\tresult = IDEVICE_ACTIVATION_E_INTERNAL_ERROR;\n\t\tgoto cleanup;\n\t}\n\n\tif (xpath_result->nodesetval && xpath_result->nodesetval->nodeNr) {\n\t\t// existing activation_acknowledged\n\t\tresponse->is_activation_ack = 1;\n\t\tgoto cleanup;\n\t}\n\n\t// retrieve response title\n\tif (xpath_result) {\n\t\txmlXPathFreeObject(xpath_result);\n\t\txpath_result = NULL;\n\t}\n\txpath_result = xmlXPathEvalExpression((const xmlChar*) \"/xmlui/alert/@title\", context);\n\tif (!xpath_result) {\n\t\tresult = IDEVICE_ACTIVATION_E_INTERNAL_ERROR;\n\t\tgoto cleanup;\n\t}\n\n\tif (xpath_result->nodesetval && xpath_result->nodesetval->nodeNr) {\n\t\t// incorrect credentials\n\t\t// <alert> exists only in case of incorrect credentials\n\t\txmlChar* content =  xmlNodeListGetString(doc, xpath_result->nodesetval->nodeTab[0]->xmlChildrenNode, 1);\n\t\tif (content) {\n\t\t\tresponse->title = strdup((const char*) content);\n\t\t\txmlFree(content);\n\t\t}\n\t} else {\n\t\tif (xpath_result) {\n\t\t\txmlXPathFreeObject(xpath_result);\n\t\t\txpath_result = NULL;\n\t\t}\n\t\txpath_result = xmlXPathEvalExpression((const xmlChar*) \"/xmlui/page/navigationBar/@title\", context);\n\t\tif (!xpath_result) {\n\t\t\tresult = IDEVICE_ACTIVATION_E_INTERNAL_ERROR;\n\t\t\tgoto cleanup;\n\t\t}\n\n\t\tif (!xpath_result->nodesetval) {\n\t\t\tresult =  IDEVICE_ACTIVATION_E_BUDDYML_PARSING_ERROR;\n\t\t\tgoto cleanup;\n\t\t}\n\t\txmlChar* content =  xmlNodeListGetString(doc, xpath_result->nodesetval->nodeTab[0]->xmlChildrenNode, 1);\n\t\tif (content) {\n\t\t\tresponse->title = strdup((const char*) content);\n\t\t\txmlFree(content);\n\t\t}\n\t}\n\n\t// retrieve response description\n\tif (xpath_result) {\n\t\txmlXPathFreeObject(xpath_result);\n\t\txpath_result = NULL;\n\t}\n\txpath_result = xmlXPathEvalExpression((const xmlChar*) \"/xmlui/page/tableView/section/footer[not (@url)]\", context);\n\tif (!xpath_result) {\n\t\tresult = IDEVICE_ACTIVATION_E_INTERNAL_ERROR;\n\t\tgoto cleanup;\n\t}\n\tif (!xpath_result->nodesetval) {\n\t\txmlXPathFreeObject(xpath_result);\n\t\txpath_result = xmlXPathEvalExpression((const xmlChar*) \"/xmlui/page/tableView/section[@footer and not(@footerLinkURL)]/@footer\", context);\n\t\tresult = IDEVICE_ACTIVATION_E_INTERNAL_ERROR;\n\t\tgoto cleanup;\n\t}\n\n\tif (xpath_result->nodesetval) {\n\t\tchar* response_description = (char*) malloc(sizeof(char));\n\t\tresponse_description[0] = '\\0';\n\n\t\tfor(i = 0; i < xpath_result->nodesetval->nodeNr; i++) {\n\t\t\txmlChar* content = xmlNodeListGetString(doc, xpath_result->nodesetval->nodeTab[i]->xmlChildrenNode, 1);\n\t\t\tif (content) {\n\t\t\t\tconst size_t len = strlen(response_description);\n\t\t\t\tresponse_description = (char*) realloc(response_description, len + xmlStrlen(content) + 2);\n\t\t\t\tsprintf(&response_description[len], \"%s\\n\", (const char*) content);\n\t\t\t\txmlFree(content);\n\t\t\t}\n\t\t}\n\n\t\tif (strlen(response_description) > 0) {\n\t\t\t// remove the last '\\n'\n\t\t\tresponse_description[strlen(response_description) - 1] = '\\0';\n\t\t\tresponse->description = response_description;\n\t\t} else {\n\t\t\tfree(response_description);\n\t\t}\n\t}\n\n\t// retrieve input fields\n\tif (xpath_result) {\n\t\txmlXPathFreeObject(xpath_result);\n\t\txpath_result = NULL;\n\t}\n\n\txpath_result = xmlXPathEvalExpression((const xmlChar*) \"/xmlui/page//editableTextRow\", context);\n\tif (!xpath_result) {\n\t\tresult = IDEVICE_ACTIVATION_E_INTERNAL_ERROR;\n\t\tgoto cleanup;\n\t}\n\n\tif (xpath_result->nodesetval) {\n\t\tfor(i = 0; i < xpath_result->nodesetval->nodeNr; i++) {\n\t\t\txmlChar* id = xmlGetProp(xpath_result->nodesetval->nodeTab[i], (const xmlChar*) \"id\");\n\t\t\tif (!id) {\n\t\t\t\tresult = IDEVICE_ACTIVATION_E_BUDDYML_PARSING_ERROR;\n\t\t\t\tgoto cleanup;\n\t\t\t}\n\t\t\tint secure_input = 0;\n\t\t\txmlChar* secure = xmlGetProp(xpath_result->nodesetval->nodeTab[i], (const xmlChar*) \"secure\");\n\t\t\tif (secure) {\n\t\t\t\tif (!strcmp((const char*)secure, \"true\")) {\n\t\t\t\t\tsecure_input = 1;\n\t\t\t\t}\n\t\t\t\txmlFree(secure);\n\t\t\t}\n\n\t\t\tidevice_activation_response_add_field(response, (const char*) id, \"\", 1, secure_input);\n\n\t\t\txmlChar* label = xmlGetProp(xpath_result->nodesetval->nodeTab[i], (const xmlChar*) \"label\");\n\t\t\tif (label) {\n\t\t\t\tplist_dict_set_item(response->labels, (const char*)id, plist_new_string((const char*) label));\n\t\t\t\txmlFree(label);\n\t\t\t}\n\t\t\txmlChar* placeholder = xmlGetProp(xpath_result->nodesetval->nodeTab[i], (const xmlChar*) \"placeholder\");\n\t\t\tif (placeholder) {\n\t\t\t\tplist_dict_set_item(response->labels_placeholder, (const char*)id, plist_new_string((const char*) placeholder));\n\t\t\t\txmlFree(placeholder);\n\t\t\t}\n\n\t\t\txmlFree(id);\n\t\t}\n\t}\n\n\t// retrieve server info fields\n\tif (xpath_result) {\n\t\txmlXPathFreeObject(xpath_result);\n\t\txpath_result = NULL;\n\t}\n\n\txpath_result = xmlXPathEvalExpression((const xmlChar*) \"/xmlui/serverInfo/@*\", context);\n\tif (!xpath_result) {\n\t\tresult = IDEVICE_ACTIVATION_E_INTERNAL_ERROR;\n\t\tgoto cleanup;\n\t}\n\n\tif (xpath_result->nodesetval) {\n\t\tfor(i = 0; i < xpath_result->nodesetval->nodeNr; i++) {\n\t\t\txmlChar* content = xmlNodeGetContent(xpath_result->nodesetval->nodeTab[i]);\n\t\t\tif (content) {\n\t\t\t\tif (!xmlStrcmp(xpath_result->nodesetval->nodeTab[i]->name, (const xmlChar*) \"isAuthRequired\")) {\n\t\t\t\t\tresponse->is_auth_required = 1;\n\t\t\t\t}\n\n\t\t\t\tidevice_activation_response_add_field(response,\n\t\t\t\t\t(const char*) xpath_result->nodesetval->nodeTab[i]->name, (const char*) content, 0, 0);\n\t\t\t\txmlFree(content);\n\t\t\t}\n\t\t}\n\t}\n\n\tif (plist_dict_get_size(response->fields) == 0) {\n\t\tresponse->has_errors = 1;\n\t}\n\ncleanup:\n\tif (xpath_result)\n\t\txmlXPathFreeObject(xpath_result);\n\tif (context)\n\t\txmlXPathFreeContext(context);\n\tif (doc)\n\t\txmlFreeDoc(doc);\n\n\treturn result;\n}\n\nstatic idevice_activation_error_t idevice_activation_parse_html_response(idevice_activation_response_t response)\n{\n\tidevice_activation_error_t result = IDEVICE_ACTIVATION_E_SUCCESS;\n\txmlDocPtr doc = NULL;\n\txmlXPathContextPtr context = NULL;\n\txmlXPathObjectPtr xpath_result = NULL;\n\n\tif (response->content_type != IDEVICE_ACTIVATION_CONTENT_TYPE_HTML)\n\t\treturn IDEVICE_ACTIVATION_E_UNKNOWN_CONTENT_TYPE;\n\n\tdoc = xmlReadMemory(response->raw_content, response->raw_content_size, \"ideviceactivation.xml\", NULL, XML_PARSE_RECOVER | XML_PARSE_NOERROR);\n\tif (!doc) {\n\t\tresult = IDEVICE_ACTIVATION_E_HTML_PARSING_ERROR;\n\t\tgoto cleanup;\n\t}\n\n\tcontext = xmlXPathNewContext(doc);\n\tif (!context) {\n\t\tresult = IDEVICE_ACTIVATION_E_HTML_PARSING_ERROR;\n\t\tgoto cleanup;\n\t}\n\n\t// check for authentication required\n\tif (xpath_result) {\n\t\txmlXPathFreeObject(xpath_result);\n\t\txpath_result = NULL;\n\t}\n\txpath_result = xmlXPathEvalExpression((const xmlChar*) \"//input[@name='isAuthRequired' and @value='true']\", context);\n\tif (!xpath_result) {\n\t\tresult = IDEVICE_ACTIVATION_E_INTERNAL_ERROR;\n\t\tgoto cleanup;\n\t}\n\n\tif (xpath_result->nodesetval && xpath_result->nodesetval->nodeNr) {\n\t\tresponse->is_auth_required = 1;\n\t\tgoto cleanup;\n\t}\n\n\t// check for plist content\n\txpath_result = xmlXPathEvalExpression((const xmlChar*) \"//script[@type='text/x-apple-plist']/plist\", context);\n\tif (!xpath_result) {\n\t\tresult = IDEVICE_ACTIVATION_E_INTERNAL_ERROR;\n\t\tgoto cleanup;\n\t}\n\n\tif (xpath_result->nodesetval && xpath_result->nodesetval->nodeNr) {\n\t\tplist_t plist = NULL;\n\t\txmlBufferPtr plistNodeBuffer = xmlBufferCreate();\n\t\tif (htmlNodeDump(plistNodeBuffer, doc, xpath_result->nodesetval->nodeTab[0]) == -1) {\n\t\t\tresult = IDEVICE_ACTIVATION_E_HTML_PARSING_ERROR;\n\t\t\tgoto local_cleanup;\n\t\t}\n\n\t\tplist_from_xml((const char*) plistNodeBuffer->content, plistNodeBuffer->use, &plist);\n\t\tif (!plist) {\n\t\t\tresult = IDEVICE_ACTIVATION_E_PLIST_PARSING_ERROR;\n\t\t\tgoto local_cleanup;\n\t\t}\n\t\tresult = idevice_activation_activation_record_from_plist(response, plist);\n\t\tplist_free(plist);\n\n\tlocal_cleanup:\n\t\tif (plistNodeBuffer)\n\t\t\txmlBufferFree(plistNodeBuffer);\n\t\tgoto cleanup;\n\t}\n\n\tresponse->has_errors = 1;\n\ncleanup:\n\tif (xpath_result)\n\t\txmlXPathFreeObject(xpath_result);\n\tif (context)\n\t\txmlXPathFreeContext(context);\n\tif (doc)\n\t\txmlFreeDoc(doc);\n\n\treturn result;\n}\n\nstatic idevice_activation_error_t idevice_activation_parse_raw_response(idevice_activation_response_t response)\n{\n\tswitch(response->content_type)\n\t{\n\t\tcase IDEVICE_ACTIVATION_CONTENT_TYPE_PLIST:\n\t\t{\n\t\t\tidevice_activation_error_t result = IDEVICE_ACTIVATION_E_SUCCESS;\n\n\t\t\tplist_t plist = NULL;\n\t\t\tplist_from_xml(response->raw_content, response->raw_content_size, &plist);\n\n\t\t\tif (plist == NULL) {\n\t\t\t\treturn IDEVICE_ACTIVATION_E_PLIST_PARSING_ERROR;\n\t\t\t}\n\n\t\t\t/* check if this is a reply to drmHandshake request */\n\t\t\tif (plist_dict_get_item(plist, \"HandshakeResponseMessage\") != NULL) {\n\t\t\t\tresult = IDEVICE_ACTIVATION_E_SUCCESS;\n\t\t\t} else {\n\t\t\t\tresult = idevice_activation_activation_record_from_plist(response, plist);\n\t\t\t}\n\n\t\t\tplist_free(response->fields);\n\t\t\tresponse->fields = plist;\n\n\t\t\treturn result;\n\t\t}\n\t\tcase IDEVICE_ACTIVATION_CONTENT_TYPE_BUDDYML:\n\t\t\treturn idevice_activation_parse_buddyml_response(response);\n\t\tcase IDEVICE_ACTIVATION_CONTENT_TYPE_HTML:\n\t\t\treturn idevice_activation_parse_html_response(response);\n\t\tdefault:\n\t\t\treturn IDEVICE_ACTIVATION_E_UNKNOWN_CONTENT_TYPE;\n\t}\n\n\treturn IDEVICE_ACTIVATION_E_SUCCESS;\n}\n\nstatic size_t idevice_activation_write_callback(char* data, size_t size, size_t nmemb, void* userdata)\n{\n\tidevice_activation_response_t response = (idevice_activation_response_t)userdata;\n\tconst size_t total = size * nmemb;\n\n\tif (total != 0) {\n\t\tresponse->raw_content = realloc(response->raw_content, response->raw_content_size + total + 1);\n\t\tmemcpy(response->raw_content + response->raw_content_size, data, total);\n\t\tresponse->raw_content[response->raw_content_size + total] = '\\0';\n\t\tresponse->raw_content_size += total;\n\t}\n\n\treturn total;\n}\n\nstatic size_t idevice_activation_header_callback(void *data, size_t size, size_t nmemb, void *userdata)\n{\n\tidevice_activation_response_t response = (idevice_activation_response_t)userdata;\n\tconst size_t total = size * nmemb;\n\tif (total != 0) {\n\t\tchar *header = malloc(total + 1);\n\t\tchar *value = NULL;\n\t\tchar *p = NULL;\n\t\tmemcpy(header, data, total);\n\t\theader[total] = '\\0';\n\n\t\tp = strchr(header, ':');\n\t\tif (p) {\n\t\t\t*p = '\\0';\n\t\t\tp++;\n\t\t\twhile (*p == ' ') {\n\t\t\t\tp++;\n\t\t\t}\n\t\t\tif (*p != '\\0') {\n\t\t\t\tvalue = p;\n\t\t\t\twhile (*p != '\\0' && *p != '\\n' && *p != '\\r') {\n\t\t\t\t\tp++;\n\t\t\t\t}\n\t\t\t\t*p = '\\0';\n\t\t\t}\n\t\t}\n\t\tif (value) {\n\t\t\tif (strncasecmp(header, \"Content-Type\", 12) == 0) {\n\t\t\t\tif (strncasecmp(value, \"text/xml\", 8) == 0) {\n\t\t\t\t\tresponse->content_type = IDEVICE_ACTIVATION_CONTENT_TYPE_PLIST;\n\t\t\t\t} else if (strncasecmp(value, \"application/xml\", 15) == 0) {\n\t\t\t\t\tresponse->content_type = IDEVICE_ACTIVATION_CONTENT_TYPE_PLIST;\n\t\t\t\t} else if (strncasecmp(value, \"application/x-buddyml\", 21) == 0) {\n\t\t\t\t\tresponse->content_type = IDEVICE_ACTIVATION_CONTENT_TYPE_BUDDYML;\n\t\t\t\t} else if (strncasecmp(value, \"text/html\", 9) == 0) {\n\t\t\t\t\tresponse->content_type = IDEVICE_ACTIVATION_CONTENT_TYPE_HTML;\n\t\t\t\t}\n\t\t\t}\n\t\t\tplist_dict_set_item(response->headers, header, plist_new_string(value));\n\t\t}\n\t\tfree(header);\n\t}\n\treturn total;\n}\n\nstatic char* urlencode(const char* buf)\n{\n\tstatic const signed char conv_table[256] = {\n\t\t1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n\t\t1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0,\n\t\t1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n\t\t0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,\n\t\t1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n\t\t0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1,\n\t\t1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,\n\t\t0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1,\n\t\t1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n\t\t1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n\t\t1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n\t\t1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n\t\t1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n\t\t1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n\t\t1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n\t\t1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1\n\t};\n\n\tunsigned int i;\n\tint count = 0;\n\tfor (i = 0; i < strlen(buf); i++) {\n\t\tif (conv_table[(int)buf[i]]) {\n\t\t\tcount++;\n\t\t}\n\t}\n\tint newsize = strlen(buf) + count*2 + 1;\n\tchar* res = malloc(newsize);\n\tint o = 0;\n\tfor (i = 0; i < strlen(buf); i++) {\n\t\tif (conv_table[(int)buf[i]]) {\n\t\t\tsprintf(&res[o], \"%%%02X\", (unsigned char)buf[i]);\n\t\t\to+=3;\n\t\t} else {\n\t\t\tres[o] = buf[i];\n\t\t\to++;\n\t\t}\n\t}\n\tres[o] = '\\0';\n\n\treturn res;\n}\n\nstatic int plist_strip_xml(char** xmlplist)\n{\n\tif (!xmlplist || !*xmlplist)\n\t\treturn -1;\n\n\tchar* start = strstr(*xmlplist, \"<plist version=\\\"1.0\\\">\\n\");\n\tif (!start)\n\t\treturn -1;\n\n\tchar* stop = strstr(*xmlplist, \"\\n</plist>\");\n\tif (!stop)\n\t\treturn -1;\n\n\tstart += strlen(\"<plist version=\\\"1.0\\\">\\n\");\n\tuint32_t size = stop - start;\n\tchar* stripped = malloc(size + 1);\n\tif (!stripped)\n\t\treturn -1;\n\n\tmemcpy(stripped, start, size);\n\tstripped[size] = '\\0';\n\tfree(*xmlplist);\n\t*xmlplist = stripped;\n\n\treturn 0;\n}\n\nstatic int idevice_activation_curl_debug_callback(CURL *handle, curl_infotype type, char *data, size_t size, void *userptr)\n{\n\tswitch (type) {\n\tcase CURLINFO_TEXT:\n\t\tfprintf(stderr, \"* \");\n\t\tbreak;\n\tcase CURLINFO_DATA_IN:\n\tcase CURLINFO_HEADER_IN:\n\t\tfprintf(stderr, \"< \");\n\t\tbreak;\n\tcase CURLINFO_DATA_OUT:\n\tcase CURLINFO_HEADER_OUT:\n\t\tfprintf(stderr, \"> \");\n\t\tbreak;\n\tcase CURLINFO_SSL_DATA_IN:\n\tcase CURLINFO_SSL_DATA_OUT:\n\t\treturn 0;\n\tdefault:\n\t\treturn 0;\n\t}\n\n\tfwrite(data, 1, size, stderr);\n\tif (size > 0 && data[size-1] != '\\n') {\n\t\tfprintf(stderr, \"\\n\");\n\t}\n\treturn 0;\n}\n\nidevice_activation_error_t idevice_activation_request_new(idevice_activation_client_type_t client_type, idevice_activation_request_t* request)\n{\n\tif (!request)\n\t\treturn IDEVICE_ACTIVATION_E_INTERNAL_ERROR;\n\n\tidevice_activation_request_t tmp_request = (idevice_activation_request_t) malloc(sizeof(idevice_activation_request));\n\n\tif (!tmp_request) {\n\t\treturn IDEVICE_ACTIVATION_E_OUT_OF_MEMORY;\n\t}\n\n\ttmp_request->client_type = client_type;\n\ttmp_request->content_type = IDEVICE_ACTIVATION_CONTENT_TYPE_URL_ENCODED;\n\ttmp_request->url = strdup(IDEVICE_ACTIVATION_DEFAULT_URL);\n\ttmp_request->fields = plist_new_dict();\n\t*request = tmp_request;\n\n\treturn IDEVICE_ACTIVATION_E_SUCCESS;\n}\n\nidevice_activation_error_t idevice_activation_request_new_from_lockdownd(idevice_activation_client_type_t client_type, lockdownd_client_t lockdown, idevice_activation_request** request)\n{\n\tif (!lockdown || !request) {\n\t\treturn IDEVICE_ACTIVATION_E_INTERNAL_ERROR;\n\t}\n\n\tuint8_t has_telephony_capability = 0;\n\tuint8_t has_mobile_equipment_id = 0;\n\tlockdownd_error_t err;\n\tplist_t info = NULL;\n\tplist_t node = NULL;\n\tplist_t fields = plist_new_dict();\n\n\t// add InStoreActivation\n\tplist_dict_set_item(fields, \"InStoreActivation\", plist_new_string(\"false\"));\n\n\t// get a bunch of information at once\n\terr = lockdownd_get_value(lockdown, NULL, NULL, &info);\n\tif (err != LOCKDOWN_E_SUCCESS) {\n\t\tif (debug_level > 0)\n\t\t\tfprintf(stderr, \"%s: Unable to get basic information from lockdownd\\n\", __func__);\n\t\tplist_free(fields);\n\t\treturn IDEVICE_ACTIVATION_E_INCOMPLETE_INFO;\n\t}\n\n\t// add AppleSerialNumber\n\tnode = plist_dict_get_item(info, \"SerialNumber\");\n\tif (!node || plist_get_node_type(node) != PLIST_STRING) {\n\t\tif (debug_level > 0)\n\t\t\tfprintf(stderr, \"%s: Unable to get SerialNumber from lockdownd\\n\", __func__);\n\t\tplist_free(fields);\n\t\tplist_free(info);\n\t\treturn IDEVICE_ACTIVATION_E_INCOMPLETE_INFO;\n\t}\n\tplist_dict_set_item(fields, \"AppleSerialNumber\", plist_copy(node));\n\tnode = NULL;\n\n\n\t// check if device has telephone capability\n\tnode = plist_dict_get_item(info, \"TelephonyCapability\");\n\tif (!node || plist_get_node_type(node) != PLIST_BOOLEAN) {\n\t\thas_telephony_capability = 0;\n\t} else {\n\t\tplist_get_bool_val(node, &has_telephony_capability);\n\t}\n\tnode = NULL;\n\n\tif (has_telephony_capability) {\n\t\t// add IMEI\n\t\tnode = plist_dict_get_item(info, \"InternationalMobileEquipmentIdentity\");\n\t\tif (!node || plist_get_node_type(node) != PLIST_STRING) {\n\t\t\thas_mobile_equipment_id = 0;\n\t\t} else {\n\t\t\tplist_dict_set_item(fields, \"IMEI\", plist_copy(node));\n\t\t\thas_mobile_equipment_id = 1;\n\t\t}\n\t\tnode = NULL;\n\n\t\t// add MEID\n\t\tnode = plist_dict_get_item(info, \"MobileEquipmentIdentifier\");\n\t\tif (!node || plist_get_node_type(node) != PLIST_STRING) {\n\t\t\tif (debug_level > 0)\n\t\t\t\tfprintf(stderr, \"%s: Unable to get MEID from lockdownd\\n\", __func__);\n\t\t\tif (!has_mobile_equipment_id) {\n\t\t\t\tplist_free(fields);\n\t\t\t\tplist_free(info);\n\t\t\t\treturn IDEVICE_ACTIVATION_E_INCOMPLETE_INFO;\n\t\t\t}\n\t\t} else {\n\t\t\tplist_dict_set_item(fields, \"MEID\", plist_copy(node));\n\t\t}\n\t\tnode = NULL;\n\n\t\t// add IMSI\n\t\tnode = plist_dict_get_item(info, \"InternationalMobileSubscriberIdentity\");\n\t\tif (!node || plist_get_node_type(node) != PLIST_STRING) {\n\t\t\tif (debug_level > 0)\n\t\t\t\tfprintf(stderr, \"%s: Unable to get IMSI from lockdownd\\n\", __func__);\n\t\t} else {\n\t\t\tplist_dict_set_item(fields, \"IMSI\", plist_copy(node));\n\t\t}\n\t\tnode = NULL;\n\n\t\t// add ICCID\n\t\tnode = plist_dict_get_item(info, \"IntegratedCircuitCardIdentity\");\n\t\tif (!node || plist_get_node_type(node) != PLIST_STRING) {\n\t\t\tif (debug_level > 0)\n\t\t\t\tfprintf(stderr, \"%s: Unable to get ICCID from lockdownd\\n\", __func__);\n\t\t} else {\n\t\t\tplist_dict_set_item(fields, \"ICCID\", plist_copy(node));\n\t\t}\n\t\tnode = NULL;\n\t}\n\tplist_free(info);\n\tinfo = NULL;\n\n\t// add activation-info\n\terr = lockdownd_get_value(lockdown, NULL, \"ActivationInfo\", &node);\n\tif (err != LOCKDOWN_E_SUCCESS || !node || plist_get_node_type(node) != PLIST_DICT) {\n\t\tfprintf(stderr, \"%s: Unable to get ActivationInfo from lockdownd\\n\", __func__);\n\t\tplist_free(fields);\n\t\treturn IDEVICE_ACTIVATION_E_INCOMPLETE_INFO;\n\t}\n\tplist_dict_set_item(fields, \"activation-info\", plist_copy(node));\n\tplist_free(node);\n\tnode = NULL;\n\n\tidevice_activation_request* tmp_request = (idevice_activation_request*) malloc(sizeof(idevice_activation_request));\n\n\tif (!tmp_request) {\n\t\tplist_free(fields);\n\t\treturn IDEVICE_ACTIVATION_E_OUT_OF_MEMORY;\n\t}\n\n\ttmp_request->client_type = client_type;\n\ttmp_request->content_type = IDEVICE_ACTIVATION_CONTENT_TYPE_MULTIPART_FORMDATA;\n\ttmp_request->url = strdup(IDEVICE_ACTIVATION_DEFAULT_URL);\n\ttmp_request->fields = fields;\n\t*request = tmp_request;\n\n\treturn IDEVICE_ACTIVATION_E_SUCCESS;\n}\n\nidevice_activation_error_t idevice_activation_drm_handshake_request_new(idevice_activation_client_type_t client_type, idevice_activation_request_t* request)\n{\n\tif (!request)\n\t\treturn IDEVICE_ACTIVATION_E_INTERNAL_ERROR;\n\n\tidevice_activation_request_t tmp_request = (idevice_activation_request_t) malloc(sizeof(idevice_activation_request));\n\n\tif (!tmp_request) {\n\t\treturn IDEVICE_ACTIVATION_E_OUT_OF_MEMORY;\n\t}\n\n\ttmp_request->client_type = client_type;\n\ttmp_request->content_type = IDEVICE_ACTIVATION_CONTENT_TYPE_PLIST;\n\ttmp_request->url = strdup(IDEVICE_ACTIVATION_DRM_HANDSHAKE_DEFAULT_URL);\n\ttmp_request->fields = plist_new_dict();\n\t*request = tmp_request;\n\n\treturn IDEVICE_ACTIVATION_E_SUCCESS;\n}\n\nvoid idevice_activation_request_free(idevice_activation_request_t request)\n{\n\tif (!request)\n\t\treturn;\n\n\tplist_free(request->fields);\n\tfree(request);\n}\n\nvoid idevice_activation_request_get_fields(idevice_activation_request_t request, plist_t* fields)\n{\n\tif (!request || !fields)\n\t\treturn;\n\n\t*fields = plist_copy(request->fields);\n}\n\nvoid idevice_activation_request_set_fields(idevice_activation_request_t request, plist_t fields)\n{\n\tif (!request || !fields)\n\t\treturn;\n\n\tif (request->content_type == IDEVICE_ACTIVATION_CONTENT_TYPE_URL_ENCODED) {\n\t\t// if at least one of the new fields has a different type than string, we have to change the type\n\t\tplist_dict_iter iter = NULL;\n\t\tplist_dict_new_iter(fields, &iter);\n\t\tplist_t item = NULL;\n\t\tdo {\n\t\t\tplist_dict_next_item(fields, iter, NULL, &item);\n\t\t\tif (item && plist_get_node_type(item) != PLIST_STRING) {\n\t\t\t\trequest->content_type = IDEVICE_ACTIVATION_CONTENT_TYPE_MULTIPART_FORMDATA;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t} while(item);\n\t}\n\n\tplist_dict_merge(&request->fields, fields);\n}\n\nvoid idevice_activation_request_set_fields_from_response(idevice_activation_request_t request, const idevice_activation_response_t response)\n{\n\tif (!request || !response)\n\t\treturn;\n\n\tplist_t response_fields = NULL;\n\tidevice_activation_response_get_fields(response, &response_fields);\n\tif (response_fields) {\n\t\tidevice_activation_request_set_fields(request, response_fields);\n\t\tfree(response_fields);\n\t}\n}\n\nvoid idevice_activation_request_set_field(idevice_activation_request_t request, const char* key, const char* value)\n{\n\tif (!request || !key || !value)\n\t\treturn;\n\n\tplist_dict_set_item(request->fields, key, plist_new_string(value));\n}\n\nvoid idevice_activation_request_get_field(idevice_activation_request_t request, const char* key, char** value)\n{\n\tif (!request || !key || !value)\n\t\treturn;\n\n\tchar* tmp_value = NULL;\n\n\tplist_t item = plist_dict_get_item(request->fields, key);\n\n\tif (item && plist_get_node_type(item) == PLIST_STRING) {\n\t\tplist_get_string_val(item, &tmp_value);\n\t} else {\n\t\tuint32_t data_size = 0;\n\t\tplist_to_xml(item, &tmp_value, &data_size);\n\t\tplist_strip_xml(&tmp_value);\n\t}\n\n\t*value = tmp_value;\n}\n\nvoid idevice_activation_request_get_url(idevice_activation_request_t request, const char** url)\n{\n\tif (!request || !url)\n\t\treturn;\n\n\t*url = request->url;\n}\n\nvoid idevice_activation_request_set_url(idevice_activation_request_t request, const char* url)\n{\n\tif (!request || !url)\n\t\treturn;\n\n\tfree(request->url);\n\trequest->url = strdup(url);\n}\n\nidevice_activation_error_t idevice_activation_response_new(idevice_activation_response_t* response)\n{\n\tif (!response)\n\t\treturn IDEVICE_ACTIVATION_E_INTERNAL_ERROR;\n\n\tidevice_activation_response_t tmp_response = (idevice_activation_response_t) malloc(sizeof(idevice_activation_response));\n\n\tif (!tmp_response) {\n\t\treturn IDEVICE_ACTIVATION_E_OUT_OF_MEMORY;\n\t}\n\n\ttmp_response->raw_content = NULL;\n\ttmp_response->raw_content_size = 0;\n\ttmp_response->content_type = IDEVICE_ACTIVATION_CONTENT_TYPE_UNKNOWN;\n\ttmp_response->title = NULL;\n\ttmp_response->description = NULL;\n\ttmp_response->activation_record = NULL;\n\ttmp_response->headers = plist_new_dict();\n\ttmp_response->fields = plist_new_dict();\n\ttmp_response->fields_require_input = plist_new_dict();\n\ttmp_response->fields_secure_input = plist_new_dict();\n\ttmp_response->labels = plist_new_dict();\n\ttmp_response->labels_placeholder = plist_new_dict();\n\ttmp_response->is_activation_ack = 0;\n\ttmp_response->is_auth_required = 0;\n\ttmp_response->has_errors = 0;\n\t*response = tmp_response;\n\n\treturn IDEVICE_ACTIVATION_E_SUCCESS;\n}\n\nidevice_activation_error_t idevice_activation_response_new_from_html(const char* content, idevice_activation_response_t* response)\n{\n\tif (!content || !response)\n\t\treturn IDEVICE_ACTIVATION_E_INTERNAL_ERROR;\n\n\tidevice_activation_response_t tmp_response = NULL;\n\tidevice_activation_error_t result = IDEVICE_ACTIVATION_E_SUCCESS;\n\n\tresult = idevice_activation_response_new(&tmp_response);\n\tif (result != IDEVICE_ACTIVATION_E_SUCCESS) {\n\t\treturn result;\n\t}\n\n\tconst size_t tmp_size = strlen(content);\n\tchar* tmp_content = (char*) malloc(sizeof(char) * tmp_size);\n\n\tif (!tmp_content) {\n\t\tidevice_activation_response_free(tmp_response);\n\t\treturn IDEVICE_ACTIVATION_E_OUT_OF_MEMORY;\n\t}\n\n\tmemcpy(tmp_content, content, tmp_size);\n\n\ttmp_response->raw_content = tmp_content;\n\ttmp_response->raw_content_size = tmp_size;\n\ttmp_response->content_type = IDEVICE_ACTIVATION_CONTENT_TYPE_HTML;\n\n\tresult = idevice_activation_parse_html_response(tmp_response);\n\tif (result != IDEVICE_ACTIVATION_E_SUCCESS) {\n\t\tidevice_activation_response_free(tmp_response);\n\t\treturn result;\n\t}\n\n\t*response = tmp_response;\n\n\treturn result;\n}\n\nidevice_activation_error_t idevice_activation_response_to_buffer(idevice_activation_response_t response, char** buffer, size_t* size)\n{\n\tif (!response || !buffer || !size)\n\t\treturn IDEVICE_ACTIVATION_E_INTERNAL_ERROR;\n\n\tchar* tmp_buffer = (char*) malloc(sizeof(char) * response->raw_content_size);\n\tif (!tmp_buffer) {\n\t\treturn IDEVICE_ACTIVATION_E_OUT_OF_MEMORY;\n\t}\n\n\tmemcpy(tmp_buffer, response->raw_content, response->raw_content_size);\n\n\t*buffer = tmp_buffer;\n\t*size = response->raw_content_size;\n\n\treturn IDEVICE_ACTIVATION_E_SUCCESS;\n}\n\nvoid idevice_activation_response_free(idevice_activation_response_t response)\n{\n\tif (!response)\n\t\treturn;\n\n\tfree(response->raw_content);\n\tfree(response->title);\n\tfree(response->description);\n\tplist_free(response->activation_record);\n\tplist_free(response->headers);\n\tplist_free(response->fields);\n\tplist_free(response->fields_require_input);\n\tplist_free(response->fields_secure_input);\n\tplist_free(response->labels);\n\tplist_free(response->labels_placeholder);\n\tfree(response);\n}\n\nvoid idevice_activation_response_get_field(idevice_activation_response_t response, const char* key, char** value)\n{\n\tif (!response || !key || !value)\n\t\treturn;\n\n\t*value = NULL;\n\tplist_t item = plist_dict_get_item(response->fields, key);\n\n\tif (item && plist_get_node_type(item) == PLIST_STRING) {\n\t\tplist_get_string_val(item, value);\n\t}\n}\n\nvoid idevice_activation_response_get_fields(idevice_activation_response_t response, plist_t* fields)\n{\n\tif (response && response->fields && fields) {\n\t\t*fields = plist_copy(response->fields);\n\t}\n}\n\nvoid idevice_activation_response_get_label(idevice_activation_response_t response, const char* key, char** value)\n{\n\tif (!response || !key || !value)\n\t\treturn;\n\n\t*value = NULL;\n\tplist_t item = plist_dict_get_item(response->labels, key);\n\tif (item) {\n\t\tplist_get_string_val(item, value);\n\t}\n}\n\nvoid idevice_activation_response_get_placeholder(idevice_activation_response_t response, const char* key, char** value)\n{\n\tif (!response || !key || !value)\n\t\treturn;\n\n\t*value = NULL;\n\tplist_t item = plist_dict_get_item(response->labels_placeholder, key);\n\tif (item) {\n\t\tplist_get_string_val(item, value);\n\t}\n}\n\nvoid idevice_activation_response_get_title(idevice_activation_response_t response, const char** title)\n{\n\tif (!response || !title)\n\t\treturn;\n\n\t*title = response->title;\n}\n\nvoid idevice_activation_response_get_description(idevice_activation_response_t response, const char** description)\n{\n\tif (!response || !description)\n\t\treturn;\n\n\t*description = response->description;\n}\n\nvoid idevice_activation_response_get_activation_record(idevice_activation_response_t response, plist_t* activation_record)\n{\n\tif (!response || !activation_record)\n\t\treturn;\n\n\tif (response->activation_record) {\n\t\t*activation_record = plist_copy(response->activation_record);\n\t} else {\n\t\t*activation_record = NULL;\n\t}\n}\n\nvoid idevice_activation_response_get_headers(idevice_activation_response_t response, plist_t* headers)\n{\n\tif (!response || !headers)\n\t\treturn;\n\n\t*headers = plist_copy(response->headers);\n}\n\nint idevice_activation_response_is_activation_acknowledged(idevice_activation_response_t response)\n{\n\tif (!response)\n\t\treturn 0;\n\n\treturn response->is_activation_ack;\n}\n\nint idevice_activation_response_is_authentication_required(idevice_activation_response_t response)\n{\n\tif (!response)\n\t\treturn 0;\n\n\treturn response->is_auth_required;\n}\n\nint idevice_activation_response_field_requires_input(idevice_activation_response_t response, const char* key)\n{\n\tif (!response || !key)\n\t\treturn 0;\n\n\treturn (plist_dict_get_item(response->fields_require_input, key) ? 1 : 0);\n}\n\nint idevice_activation_response_field_secure_input(idevice_activation_response_t response, const char* key)\n{\n\tif (!response || !key)\n\t\treturn 0;\n\n\treturn (plist_dict_get_item(response->fields_secure_input, key) ? 1 : 0);\n}\n\nint idevice_activation_response_has_errors(idevice_activation_response_t response)\n{\n\tif (!response)\n\t\treturn 0;\n\n\treturn response->has_errors;\n}\n\nidevice_activation_error_t idevice_activation_send_request(idevice_activation_request_t request, idevice_activation_response_t* response)\n{\n\tidevice_activation_error_t result = IDEVICE_ACTIVATION_E_SUCCESS;\n\n\t// check arguments\n\tif (!request || !response) {\n\t\treturn IDEVICE_ACTIVATION_E_INTERNAL_ERROR;\n\t}\n\n\tplist_dict_iter iter = NULL;\n\tplist_dict_new_iter(request->fields, &iter);\n\tif (!iter) {\n\t\treturn IDEVICE_ACTIVATION_E_INTERNAL_ERROR;\n\t}\n\n\tCURL* handle = curl_easy_init();\n\tstruct curl_httppost* form = NULL;\n\tstruct curl_slist* slist = NULL;\n\n\tif (!handle) {\n\t\tresult = IDEVICE_ACTIVATION_E_INTERNAL_ERROR;\n\t\tgoto cleanup;\n\t}\n\n\tswitch (request->client_type) {\n\t\tcase IDEVICE_ACTIVATION_CLIENT_MOBILE_ACTIVATION:\n\t\t\tcurl_easy_setopt(handle, CURLOPT_USERAGENT, IDEVICE_ACTIVATION_USER_AGENT_IOS);\n\t\t\tbreak;\n\t\tcase IDEVICE_ACTIVATION_CLIENT_ITUNES:\n\t\t\tcurl_easy_setopt(handle, CURLOPT_USERAGENT, IDEVICE_ACTIVATION_USER_AGENT_ITUNES);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tresult = IDEVICE_ACTIVATION_E_INTERNAL_ERROR;\n\t\t\tgoto cleanup;\n\t}\n\n\tchar* key = NULL;\n\tchar* svalue = NULL;\n\tplist_t value_node = NULL;\n\n\tif (request->content_type == IDEVICE_ACTIVATION_CONTENT_TYPE_MULTIPART_FORMDATA) {\n\t\tstruct curl_httppost* last = NULL;\n\t\tdo {\n\t\t\tplist_dict_next_item(request->fields, iter, &key, &value_node);\n\t\t\tif (key != NULL) {\n\t\t\t\tif (value_node != NULL) {\n\t\t\t\t\t// serialize plist node as field value\n\t\t\t\t\tif (plist_get_node_type(value_node) == PLIST_STRING) {\n\t\t\t\t\t\tplist_get_string_val(value_node, &svalue);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tuint32_t data_size = 0;\n\t\t\t\t\t\tplist_to_xml(value_node, &svalue, &data_size);\n\t\t\t\t\t\tplist_strip_xml(&svalue);\n\t\t\t\t\t}\n\n\t\t\t\t\tcurl_formadd(&form, &last, CURLFORM_COPYNAME, key, CURLFORM_COPYCONTENTS, svalue, CURLFORM_END);\n\n\t\t\t\t\tfree(svalue);\n\t\t\t\t\tsvalue = NULL;\n\t\t\t\t}\n\t\t\t}\n\t\t} while(value_node != NULL);\n\t\tcurl_easy_setopt(handle, CURLOPT_HTTPPOST, form);\n\n\t} else if (request->content_type == IDEVICE_ACTIVATION_CONTENT_TYPE_URL_ENCODED) {\n\t\tchar* postdata = (char*) malloc(sizeof(char));\n\t\tpostdata[0] = '\\0';\n\t\tdo {\n\t\t\tplist_dict_next_item(request->fields, iter, &key, &value_node);\n\t\t\tif (key != NULL) {\n\t\t\t\tif (value_node != NULL) {\n\t\t\t\t\t// serialize plist node as field value\n\t\t\t\t\tif (plist_get_node_type(value_node) == PLIST_STRING) {\n\t\t\t\t\t\tplist_get_string_val(value_node, &svalue);\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// only strings supported\n\t\t\t\t\t\tfree(postdata);\n\t\t\t\t\t\tresult = IDEVICE_ACTIVATION_E_UNSUPPORTED_FIELD_TYPE;\n\t\t\t\t\t\tgoto cleanup;\n\t\t\t\t\t}\n\n\t\t\t\t\tchar* value_encoded = urlencode(svalue);\n\t\t\t\t\tif (value_encoded) {\n\t\t\t\t\t\tconst size_t new_size = strlen(postdata) + strlen(key) + strlen(value_encoded) + 3;\n\t\t\t\t\t\tpostdata = (char*) realloc(postdata, new_size);\n\t\t\t\t\t\tsprintf(&postdata[strlen(postdata)], \"%s=%s&\", key, value_encoded);\n\t\t\t\t\t\tfree(value_encoded);\n\t\t\t\t\t}\n\n\t\t\t\t\tfree(svalue);\n\t\t\t\t\tsvalue = NULL;\n\t\t\t\t}\n\t\t\t}\n\t\t} while(value_node != NULL);\n\n\t\t// remove the last '&'\n\t\tconst size_t postdata_len = strlen(postdata);\n\t\tif (postdata_len > 0)\n\t\t\tpostdata[postdata_len - 1] = '\\0';\n\n\t\tcurl_easy_setopt(handle, CURLOPT_POST, 1);\n\t\tcurl_easy_setopt(handle, CURLOPT_POSTFIELDS, postdata);\n\t\tcurl_easy_setopt(handle, CURLOPT_POSTFIELDSIZE, strlen(postdata));\n\t} else if (request->content_type == IDEVICE_ACTIVATION_CONTENT_TYPE_PLIST) {\n\t\tchar *postdata = NULL;\n\t\tuint32_t postdata_len = 0;\n\t\tplist_to_xml(request->fields, &postdata, &postdata_len);\n\t\tcurl_easy_setopt(handle, CURLOPT_POST, 1);\n\t\tcurl_easy_setopt(handle, CURLOPT_POSTFIELDS, postdata);\n\t\tcurl_easy_setopt(handle, CURLOPT_POSTFIELDSIZE, postdata_len);\n\t\tslist = curl_slist_append(NULL, \"Content-Type: application/x-apple-plist\");\n\t\tslist = curl_slist_append(slist, \"Accept: application/xml\");\n\t\tcurl_easy_setopt(handle, CURLOPT_HTTPHEADER, slist);\n\t}\n\telse {\n\t\tresult = IDEVICE_ACTIVATION_E_INTERNAL_ERROR;\n\t\tgoto cleanup;\n\t}\n\n\tidevice_activation_response_t tmp_response = NULL;\n\tresult = idevice_activation_response_new(&tmp_response);\n\tif (result != IDEVICE_ACTIVATION_E_SUCCESS) {\n\t\tgoto cleanup;\n\t}\n\n\tcurl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, 0);\n\tcurl_easy_setopt(handle, CURLOPT_WRITEDATA, tmp_response);\n\tcurl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, &idevice_activation_write_callback);\n\tcurl_easy_setopt(handle, CURLOPT_HEADERDATA, tmp_response);\n\tcurl_easy_setopt(handle, CURLOPT_HEADERFUNCTION, &idevice_activation_header_callback);\n\tcurl_easy_setopt(handle, CURLOPT_URL, request->url);\n\tcurl_easy_setopt(handle, CURLOPT_FORBID_REUSE, 1);\n\tcurl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1L);\n\n\t// enable communication debugging\n\tif (debug_level > 0) {\n\t\tcurl_easy_setopt(handle, CURLOPT_VERBOSE, 1);\n\t\tcurl_easy_setopt(handle, CURLOPT_DEBUGFUNCTION, idevice_activation_curl_debug_callback);\n\t}\n\n\tcurl_easy_perform(handle);\n\n\tresult = idevice_activation_parse_raw_response(tmp_response);\n\tif (result != IDEVICE_ACTIVATION_E_SUCCESS) {\n\t\tgoto cleanup;\n\t}\n\n\t*response = tmp_response;\n\n\tresult = IDEVICE_ACTIVATION_E_SUCCESS;\n\ncleanup:\n\tfree(iter);\n\tif (form)\n\t\tcurl_formfree(form);\n\tif (slist)\n\t\tcurl_slist_free_all(slist);\n\tif (handle)\n\t\tcurl_easy_cleanup(handle);\n\n\treturn result;\n}\n"
  },
  {
    "path": "src/libideviceactivation-1.0.pc.in",
    "content": "prefix=@prefix@\nexec_prefix=@exec_prefix@\nlibdir=@libdir@\nincludedir=@includedir@\n\nName: @PACKAGE_NAME@\nDescription: A library to handle activation and deactivation of iOS devices.\nVersion: @PACKAGE_VERSION@\nLibs: -L${libdir} -lideviceactivation-1.0\nCflags: -I${includedir}\nRequires: libplist-2.0 >= @LIBPLIST_VERSION@ libimobiledevice-1.0 >= @LIBIMOBILEDEVICE_VERSION@\nRequires.private: libcurl >= @LIBCURL_VERSION@ libxml-2.0 >= @LIBXML2_VERSION@\n"
  },
  {
    "path": "tools/Makefile.am",
    "content": "AM_CPPFLAGS = \\\n\t-I$(top_srcdir)/include\n\nAM_CFLAGS = \\\n\t$(GLOBAL_CFLAGS) \\\n\t$(libimobiledevice_CFLAGS) \\\n\t$(libplist_CFLAGS)\n\nAM_LDFLAGS = \\\n\t$(GLOBAL_LIBS) \\\n\t$(libimobiledevice_LIBS) \\\n\t$(libplist_LIBS)\n\nbin_PROGRAMS = ideviceactivation\n\nideviceactivation_SOURCES = ideviceactivation.c\nideviceactivation_CFLAGS = $(AM_CFLAGS)\nideviceactivation_LDFLAGS = $(AM_LDFLAGS)\nideviceactivation_LDADD = $(top_builddir)/src/libideviceactivation-1.0.la\n"
  },
  {
    "path": "tools/ideviceactivation.c",
    "content": "/*\n * ideviceactivation.c\n * A command line tool to handle the activation process\n *\n * Copyright (c) 2016-2019 Nikias Bassen, All Rights Reserved.\n * Copyright (c) 2014-2015 Martin Szulecki, All Rights Reserved.\n * Copyright (c) 2011-2015 Mirell Development, All Rights Reserved.\n *\n * This program is free software; you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation; either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program; if not, write to the Free Software Foundation,\n * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA\n */\n\n#ifdef HAVE_CONFIG_H\n#include <config.h>\n#endif\n\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <unistd.h>\n#include <ctype.h>\n#ifndef _WIN32\n#include <signal.h>\n#endif\n\n#include <plist/plist.h>\n#include <libimobiledevice/lockdown.h>\n#include <libimobiledevice/libimobiledevice.h>\n#include <libimobiledevice/mobileactivation.h>\n#include <libideviceactivation.h>\n\n#ifdef _WIN32\n#include <windows.h>\n#include <conio.h>\n#else\n#include <termios.h>\n#endif\n\nstatic void print_usage(int argc, char **argv)\n{\n\tchar *name = NULL;\n\n\tname = strrchr(argv[0], '/');\n\tprintf(\"Usage: %s COMMAND [OPTIONS]\\n\", (name ? name + 1: argv[0]));\n\tprintf(\"\\n\");\n\tprintf(\"Activate or deactivate a device.\\n\");\n\tprintf(\"\\n\");\n\tprintf(\"Where COMMAND is one of:\\n\");\n\tprintf(\"  activate\\t\\tattempt to activate the device\\n\");\n\tprintf(\"  deactivate\\t\\tdeactivate the device\\n\");\n\tprintf(\"  state\\t\\t\\tquery device about its activation state\\n\");\n\tprintf(\"  itunes\\t\\ttell the device that it has been connected to iTunes (useful for < iOS 4)\\n\");\n\tprintf(\"\\n\");\n\tprintf(\"The following OPTIONS are accepted:\\n\");\n\tprintf(\"  -d, --debug\\t\\tenable communication debugging\\n\");\n\tprintf(\"  -u, --udid UDID\\ttarget specific device by UDID\\n\");\n\tprintf(\"  -n, --network\\t\\tconnect to network device\\n\");\n\tprintf(\"  -b, --batch\\t\\texplicitly run in non-interactive mode (default: auto-detect)\\n\");\n\tprintf(\"  -s, --service URL\\tuse activation webservice at URL instead of default\\n\");\n\tprintf(\"  -v, --version\\t\\tprint version information and exit\\n\");\n\tprintf(\"  -h, --help\\t\\tprints usage information\\n\");\n\tprintf(\"\\n\");\n\tprintf(\"Homepage:    <\" PACKAGE_URL \">\\n\");\n\tprintf(\"Bug Reports: <\" PACKAGE_BUGREPORT \">\\n\");\n}\n\n#ifdef _WIN32\n#define BS_CC '\\b'\n#define my_getch getch\n#else\n#define BS_CC 0x7f\nstatic int my_getch(void)\n{\n\tstruct termios oldt, newt;\n\tint ch;\n\ttcgetattr(STDIN_FILENO, &oldt);\n\tnewt = oldt;\n\tnewt.c_lflag &= ~(ICANON | ECHO);\n\ttcsetattr(STDIN_FILENO, TCSANOW, &newt);\n\tch = getchar();\n\ttcsetattr(STDIN_FILENO, TCSANOW, &oldt);\n\treturn ch;\n}\n#endif\n\nstatic void get_user_input(char *buf, int maxlen, int secure)\n{\n\tint len = 0;\n\tint c;\n\n\twhile ((c = my_getch())) {\n\t\tif ((c == '\\r') || (c == '\\n')) {\n\t\t\tbreak;\n\t\t} else if (isprint(c)) {\n\t\t\tif (len < maxlen-1)\n\t\t\t\tbuf[len++] = c;\n\t\t\tfputc((secure) ? '*' : c, stdout);\n\t\t} else if (c == BS_CC) {\n\t\t\tif (len > 0) {\n\t\t\t\tfputs(\"\\b \\b\", stdout);\n\t\t\t\tlen--;\n\t\t\t}\n\t\t}\n\t}\n\tfputs(\"\\n\", stdout);\n\tbuf[len] = 0;\n}\n\nint main(int argc, char *argv[])\n{\n\tidevice_t device = NULL;\n\tidevice_error_t ret = IDEVICE_E_UNKNOWN_ERROR;\n\tlockdownd_client_t lockdown = NULL;\n\tmobileactivation_client_t ma = NULL;\n\tidevice_activation_request_t request = NULL;\n\tidevice_activation_response_t response = NULL;\n\tconst char* response_title = NULL;\n\tconst char* response_description = NULL;\n\tchar* field_key = NULL;\n\tchar* field_label = NULL;\n\tchar input[1024];\n\tplist_t fields = NULL;\n\tplist_dict_iter iter = NULL;\n\tplist_t record = NULL;\n\tchar *udid = NULL;\n\tchar *signing_service_url = NULL;\n\tint use_mobileactivation = 0;\n\tint session_mode = 0;\n\tint i;\n\tint interactive = 1;\n\tint result = EXIT_FAILURE;\n\tint use_network = 0;\n\n\ttypedef enum {\n\t\tOP_NONE = 0, OP_ACTIVATE, OP_DEACTIVATE, OP_GETSTATE, OP_ITUNES\n\t} op_t;\n\top_t op = OP_NONE;\n\n#ifndef _WIN32\n\tsignal(SIGPIPE, SIG_IGN);\n#endif\n\t/* parse cmdline args */\n\tfor (i = 1; i < argc; i++) {\n\t\tif (!strcmp(argv[i], \"-d\") || !strcmp(argv[i], \"--debug\")) {\n\t\t\tidevice_set_debug_level(1);\n\t\t\tidevice_activation_set_debug_level(1);\n\t\t\tcontinue;\n\t\t}\n\t\telse if (!strcmp(argv[i], \"-u\") || !strcmp(argv[i], \"--udid\")) {\n\t\t\ti++;\n\t\t\tif (!argv[i] || !*argv[i]) {\n\t\t\t\tprint_usage(argc, argv);\n\t\t\t\treturn EXIT_FAILURE;\n\t\t\t}\n\t\t\tudid = argv[i];\n\t\t\tcontinue;\n\t\t}\n\t\telse if (!strcmp(argv[i], \"-n\") || !strcmp(argv[i], \"--network\")) {\n\t\t\tuse_network = 1;\n\t\t\tcontinue;\n\t\t}\n\t\telse if (!strcmp(argv[i], \"-s\") || !strcmp(argv[i], \"--service\")) {\n\t\t\ti++;\n\t\t\tif (!argv[i]) {\n\t\t\t\tprint_usage(argc, argv);\n\t\t\t\treturn EXIT_FAILURE;\n\t\t\t}\n\t\t\tsigning_service_url = argv[i];\n\t\t\tcontinue;\n\t\t}\n\t\telse if (!strcmp(argv[i], \"-b\") || !strcmp(argv[i], \"--batch\")) {\n\t\t\tinteractive = 0;\n\t\t\tcontinue;\n\t\t}\n\t\telse if (!strcmp(argv[i], \"-h\") || !strcmp(argv[i], \"--help\")) {\n\t\t\tprint_usage(argc, argv);\n\t\t\treturn EXIT_SUCCESS;\n\t\t}\n\t\telse if (!strcmp(argv[i], \"-v\") || !strcmp(argv[i], \"--version\")) {\n\t\t\tprintf(\"ideviceactivation %s\\n\", PACKAGE_VERSION);\n\t\t\treturn EXIT_SUCCESS;\n\t\t}\n\t\telse if (!strcmp(argv[i], \"activate\")) {\n\t\t\top = OP_ACTIVATE;\n\t\t\tcontinue;\n\t\t}\n\t\telse if (!strcmp(argv[i], \"deactivate\")) {\n\t\t\top = OP_DEACTIVATE;\n\t\t\tcontinue;\n\t\t}\n\t\telse if (!strcmp(argv[i], \"state\")) {\n\t\t\top = OP_GETSTATE;\n\t\t\tcontinue;\n\t\t}\n\t\telse if (!strcmp(argv[i], \"itunes\")) {\n\t\t\top = OP_ITUNES;\n\t\t\tcontinue;\n\t\t}\n\t\telse {\n\t\t\tprint_usage(argc, argv);\n\t\t\treturn EXIT_SUCCESS;\n\t\t}\n\t}\n\n\tif (interactive) {\n\t\tif (!isatty(fileno(stdin)) || !isatty(fileno(stdout))) {\n\t\t\tinteractive = 0;\n\t\t}\n\t}\n\n\tif (op == OP_NONE) {\n\t\tprint_usage(argc, argv);\n\t\treturn EXIT_FAILURE;\n\t}\n\n\tret = idevice_new_with_options(&device, udid, (use_network) ? IDEVICE_LOOKUP_NETWORK : IDEVICE_LOOKUP_USBMUX);\n\tif (ret != IDEVICE_E_SUCCESS) {\n\t\tif (udid) {\n\t\t\tprintf(\"ERROR: Device %s not found!\\n\", udid);\n\t\t} else {\n\t\t\tprintf(\"ERROR: No device found!\\n\");\n\t\t}\n\t\treturn EXIT_FAILURE;\n\t}\n\n\tif (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(device, &lockdown, \"ideviceactivation\")) {\n\t\tfprintf(stderr, \"Failed to connect to lockdownd\\n\");\n\t\tresult = EXIT_FAILURE;\n\t\tgoto cleanup;\n\t}\n\n\tplist_t p_version = NULL;\n\tuint32_t product_version = 0;\n\tif (lockdownd_get_value(lockdown, NULL, \"ProductVersion\", &p_version) == LOCKDOWN_E_SUCCESS) {\n\t\tint vers[3] = {0, 0, 0};\n\t\tchar *s_version = NULL;\n\t\tplist_get_string_val(p_version, &s_version);\n\t\tif (s_version && sscanf(s_version, \"%d.%d.%d\", &vers[0], &vers[1], &vers[2]) >= 2) {\n\t\t\tproduct_version = ((vers[0] & 0xFF) << 16) | ((vers[1] & 0xFF) << 8) | (vers[2] & 0xFF);\n\t\t}\n\t\tfree(s_version);\n\t}\n\tplist_free(p_version);\n\n\tif (op == OP_ACTIVATE && product_version >= 0x0A0200) {\n\t\t/* The activation server will not acknowledge the activation for iOS >= 10.2 anymore. Let's warn the user about this. */\n\t\tplist_t state = NULL;\n\t\tlockdownd_get_value(lockdown, NULL, \"ActivationState\", &state);\n\t\tif (state) {\n\t\t\tchar *state_str = NULL;\n\t\t\tplist_get_string_val(state, &state_str);\n\t\t\tif (state_str && strcmp(state_str, \"Unactivated\") != 0) {\n\t\t\t\tprintf(\"NOTE: This device appears to be already activated. The server might report an error 'Device Unknown' instead of acknowledging the activation.\\n\");\n\t\t\t}\n\t\t\tfree(state_str);\n\t\t\tplist_free(state);\n\t\t}\n\t}\n\n\t// check if we should use the new mobileactivation service\n\tlockdownd_service_descriptor_t svc = NULL;\n\tif (lockdownd_start_service(lockdown, MOBILEACTIVATION_SERVICE_NAME, &svc) == LOCKDOWN_E_SUCCESS) {\n\t\tmobileactivation_error_t maerr = mobileactivation_client_new(device, svc, &ma);\n\t\tlockdownd_service_descriptor_free(svc);\n\t\tsvc = NULL;\n\t\tif (maerr != MOBILEACTIVATION_E_SUCCESS) {\n\t\t\tfprintf(stderr, \"Failed to connect to %s\\n\", MOBILEACTIVATION_SERVICE_NAME);\n\t\t\tresult = EXIT_FAILURE;\n\t\t\tgoto cleanup;\n\t\t}\n\t\tuse_mobileactivation = 1;\n\t}\n\n\tswitch (op) {\n\t\tcase OP_DEACTIVATE:\n\t\t\tif (use_mobileactivation) {\n\t\t\t\t// deactivate device using mobileactivation\n\t\t\t\tif (MOBILEACTIVATION_E_SUCCESS != mobileactivation_deactivate(ma)) {\n\t\t\t\t\tfprintf(stderr, \"Failed to deactivate device.\\n\");\n\t\t\t\t\tresult = EXIT_FAILURE;\n\t\t\t\t\tgoto cleanup;\n\t\t\t\t}\n\t\t\t\tmobileactivation_client_free(ma);\n\t\t\t\tma = NULL;\n\t\t\t} else {\n\t\t\t\t// deactivate device using lockdown\n\t\t\t\tif (LOCKDOWN_E_SUCCESS != lockdownd_deactivate(lockdown)) {\n\t\t\t\t\tfprintf(stderr, \"Failed to deactivate device.\\n\");\n\t\t\t\t\tresult = EXIT_FAILURE;\n\t\t\t\t\tgoto cleanup;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tresult = EXIT_SUCCESS;\n\t\t\tprintf(\"Successfully deactivated device.\\n\");\n\t\t\tbreak;\n\t\tcase OP_ACTIVATE:\n\t\tdefault:\n\t\t\tif (use_mobileactivation) {\n\t\t\t\t// create activation request from mobileactivation\n\t\t\t\tplist_t ainfo = NULL;\n\t\t\t\tif ((product_version >= 0x0A0000) || (mobileactivation_create_activation_info(ma, &ainfo) != MOBILEACTIVATION_E_SUCCESS)) {\n\t\t\t\t\tsession_mode = 1;\n\t\t\t\t}\n\t\t\t\tmobileactivation_client_free(ma);\n\t\t\t\tma = NULL;\n\t\t\t\tif (session_mode) {\n\t\t\t\t\t/* first grab session blob from device required for drmHandshake */\n\t\t\t\t\tplist_t blob = NULL;\n\t\t\t\t\tif (mobileactivation_client_start_service(device, &ma, \"ideviceactivation\") != MOBILEACTIVATION_E_SUCCESS) {\n\t\t\t\t\t\tfprintf(stderr, \"Failed to connect to %s\\n\", MOBILEACTIVATION_SERVICE_NAME);\n\t\t\t\t\t\tresult = EXIT_FAILURE;\n\t\t\t\t\t\tgoto cleanup;\n\t\t\t\t\t}\n\t\t\t\t\tif (mobileactivation_create_activation_session_info(ma, &blob) != MOBILEACTIVATION_E_SUCCESS) {\n\t\t\t\t\t\tfprintf(stderr, \"Failed to get ActivationSessionInfo from mobileactivation\\n\");\n\t\t\t\t\t\tresult = EXIT_FAILURE;\n\t\t\t\t\t\tgoto cleanup;\n\t\t\t\t\t}\n\t\t\t\t\tmobileactivation_client_free(ma);\n\t\t\t\t\tma = NULL;\n\n\t\t\t\t\t/* create drmHandshake request with blob from device */\n\t\t\t\t\tif (idevice_activation_drm_handshake_request_new(IDEVICE_ACTIVATION_CLIENT_MOBILE_ACTIVATION, &request) != IDEVICE_ACTIVATION_E_SUCCESS) {\n\t\t\t\t\t\tfprintf(stderr, \"Failed to create drmHandshake request.\\n\");\n\t\t\t\t\t\tresult = EXIT_FAILURE;\n\t\t\t\t\t\tgoto cleanup;\n\t\t\t\t\t}\n\t\t\t\t\tidevice_activation_request_set_fields(request, blob);\n\t\t\t\t\tplist_free(blob);\n\n\t\t\t\t\tif (signing_service_url) {\n\t\t\t\t\t\tidevice_activation_request_set_url(request, signing_service_url);\n\t\t\t\t\t}\n\n\t\t\t\t\t/* send request to server and get response */\n\t\t\t\t\tif (idevice_activation_send_request(request, &response) != IDEVICE_ACTIVATION_E_SUCCESS) {\n\t\t\t\t\t\tfprintf(stderr, \"Failed to get drmHandshake result from activation server.\\n\");\n\t\t\t\t\t\tresult = EXIT_FAILURE;\n\t\t\t\t\t\tgoto cleanup;\n\t\t\t\t\t}\n\t\t\t\t\tplist_t handshake_response = NULL;\n\t\t\t\t\tidevice_activation_response_get_fields(response, &handshake_response);\n\t\t\t\t\tidevice_activation_response_free(response);\n\t\t\t\t\tresponse = NULL;\n\n\t\t\t\t\t/* use handshake response to get activation info from device */\n\t\t\t\t\tif (mobileactivation_client_start_service(device, &ma, \"ideviceactivation\") != MOBILEACTIVATION_E_SUCCESS) {\n\t\t\t\t\t\tfprintf(stderr, \"Failed to connect to %s\\n\", MOBILEACTIVATION_SERVICE_NAME);\n\t\t\t\t\t\tresult = EXIT_FAILURE;\n\t\t\t\t\t\tgoto cleanup;\n\t\t\t\t\t}\n\t\t\t\t\tif ((mobileactivation_create_activation_info_with_session(ma, handshake_response, &ainfo) != MOBILEACTIVATION_E_SUCCESS) || !ainfo || (plist_get_node_type(ainfo) != PLIST_DICT)) {\n\t\t\t\t\t\tfprintf(stderr, \"Failed to get ActivationInfo from mobileactivation\\n\");\n\t\t\t\t\t\tresult = EXIT_FAILURE;\n\t\t\t\t\t\tgoto cleanup;\n\t\t\t\t\t}\n\t\t\t\t\tmobileactivation_client_free(ma);\n\t\t\t\t\tma = NULL;\n\t\t\t\t} else if (!ainfo || plist_get_node_type(ainfo) != PLIST_DICT) {\n\t\t\t\t\tfprintf(stderr, \"Failed to get ActivationInfo from mobileactivation\\n\");\n\t\t\t\t\tresult = EXIT_FAILURE;\n\t\t\t\t\tgoto cleanup;\n\t\t\t\t}\n\n\t\t\t\t/* create activation request */\n\t\t\t\tif (idevice_activation_request_new(IDEVICE_ACTIVATION_CLIENT_MOBILE_ACTIVATION, &request) != IDEVICE_ACTIVATION_E_SUCCESS) {\n\t\t\t\t\tfprintf(stderr, \"Failed to create activation request.\\n\");\n\t\t\t\t\tresult = EXIT_FAILURE;\n\t\t\t\t\tgoto cleanup;\n\t\t\t\t}\n\n\t\t\t\t/* add activation info to request */\n\t\t\t\tplist_t request_fields = plist_new_dict();\n\t\t\t\tplist_dict_set_item(request_fields, \"activation-info\", ainfo);\n\t\t\t\tidevice_activation_request_set_fields(request, request_fields);\n\t\t\t} else {\n\t\t\t\t// create activation request from lockdown\n\t\t\t\tif (idevice_activation_request_new_from_lockdownd(\n\t\t\t\t\tIDEVICE_ACTIVATION_CLIENT_MOBILE_ACTIVATION, lockdown, &request) != IDEVICE_ACTIVATION_E_SUCCESS) {\n\t\t\t\t\tfprintf(stderr, \"Failed to create activation request.\\n\");\n\t\t\t\t\tresult = EXIT_FAILURE;\n\t\t\t\t\tgoto cleanup;\n\t\t\t\t}\n\t\t\t}\n\t\t\tlockdownd_client_free(lockdown);\n\t\t\tlockdown = NULL;\n\n\t\t\tif (request && signing_service_url) {\n\t\t\t\tidevice_activation_request_set_url(request, signing_service_url);\n\t\t\t}\n\n\t\t\twhile(1) {\n\t\t\t\tif (idevice_activation_send_request(request, &response) != IDEVICE_ACTIVATION_E_SUCCESS) {\n\t\t\t\t\tfprintf(stderr, \"Failed to send request or retrieve response.\\n\");\n\t\t\t\t\t// Here response might have some content that could't be correctly interpreted (parsed)\n\t\t\t\t\t// by the library. Printing out the content could help to identify the cause of the error.\n\t\t\t\t\tresult = EXIT_FAILURE;\n\t\t\t\t\tgoto cleanup;\n\t\t\t\t}\n\n\t\t\t\tif (idevice_activation_response_has_errors(response)) {\n\t\t\t\t\tfprintf(stderr, \"Activation server reports errors.\\n\");\n\n\t\t\t\t\tidevice_activation_response_get_title(response, &response_title);\n\t\t\t\t\tif (response_title) {\n\t\t\t\t\t\tfprintf(stderr, \"\\t%s\\n\", response_title);\n\t\t\t\t\t}\n\n\t\t\t\t\tidevice_activation_response_get_description(response, &response_description);\n\t\t\t\t\tif (response_description) {\n\t\t\t\t\t\tfprintf(stderr, \"\\t%s\\n\", response_description);\n\t\t\t\t\t}\n\t\t\t\t\tresult = EXIT_FAILURE;\n\t\t\t\t\tgoto cleanup;\n\t\t\t\t}\n\n\t\t\t\tidevice_activation_response_get_activation_record(response, &record);\n\n\t\t\t\tif (record) {\n\t\t\t\t\tif (LOCKDOWN_E_SUCCESS != lockdownd_client_new_with_handshake(device, &lockdown, \"ideviceactivation\")) {\n\t\t\t\t\t\tfprintf(stderr, \"Failed to connect to lockdownd\\n\");\n\t\t\t\t\t\tresult = EXIT_FAILURE;\n\t\t\t\t\t\tgoto cleanup;\n\t\t\t\t\t}\n\t\t\t\t\tif (use_mobileactivation) {\n\t\t\t\t\t\tsvc = NULL;\n\t\t\t\t\t\tif (lockdownd_start_service(lockdown, MOBILEACTIVATION_SERVICE_NAME, &svc) != LOCKDOWN_E_SUCCESS) {\n\t\t\t\t\t\t\tfprintf(stderr, \"Failed to start service %s\\n\", MOBILEACTIVATION_SERVICE_NAME);\n\t\t\t\t\t\t\tresult = EXIT_FAILURE;\n\t\t\t\t\t\t\tgoto cleanup;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tmobileactivation_error_t maerr = mobileactivation_client_new(device, svc, &ma);\n\t\t\t\t\t\tlockdownd_service_descriptor_free(svc);\n\t\t\t\t\t\tsvc = NULL;\n\t\t\t\t\t\tif (maerr != MOBILEACTIVATION_E_SUCCESS) {\n\t\t\t\t\t\t\tfprintf(stderr, \"Failed to connect to %s\\n\", MOBILEACTIVATION_SERVICE_NAME);\n\t\t\t\t\t\t\tresult = EXIT_FAILURE;\n\t\t\t\t\t\t\tgoto cleanup;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif (session_mode) {\n\t\t\t\t\t\t\tplist_t headers = NULL;\n\t\t\t\t\t\t\tidevice_activation_response_get_headers(response, &headers);\n\t\t\t\t\t\t\tif (MOBILEACTIVATION_E_SUCCESS != mobileactivation_activate_with_session(ma, record, headers)) {\n\t\t\t\t\t\t\t\tplist_free(headers);\n\t\t\t\t\t\t\t\tfprintf(stderr, \"Failed to activate device with record.\\n\");\n\t\t\t\t\t\t\t\tresult = EXIT_FAILURE;\n\t\t\t\t\t\t\t\tgoto cleanup;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tplist_free(headers);\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tif (MOBILEACTIVATION_E_SUCCESS != mobileactivation_activate(ma, record)) {\n\t\t\t\t\t\t\t\tfprintf(stderr, \"Failed to activate device with record.\\n\");\n\t\t\t\t\t\t\t\tresult = EXIT_FAILURE;\n\t\t\t\t\t\t\t\tgoto cleanup;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// activate device using lockdown\n\t\t\t\t\t\tif (LOCKDOWN_E_SUCCESS != lockdownd_activate(lockdown, record)) {\n\t\t\t\t\t\t\tplist_t state = NULL;\n\t\t\t\t\t\t\tlockdownd_get_value(lockdown, NULL, \"ActivationState\", &state);\n\t\t\t\t\t\t\tint success = 0;\n\t\t\t\t\t\t\tif (state && plist_get_node_type(state) == PLIST_STRING) {\n\t\t\t\t\t\t\t\tchar *strval = NULL;\n\t\t\t\t\t\t\t\tplist_get_string_val(state, &strval);\n\t\t\t\t\t\t\t\tif (strval && strcmp(strval, \"Unactivated\")) {\n\t\t\t\t\t\t\t\t\tsuccess = 1;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tfree(strval);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (!success) {\n\t\t\t\t\t\t\t\tfprintf(stderr, \"Failed to activate device with record.\\n\");\n\t\t\t\t\t\t\t\tresult = EXIT_FAILURE;\n\t\t\t\t\t\t\t\tgoto cleanup;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// set ActivationStateAcknowledged if we succeeded\n\t\t\t\t\tif (LOCKDOWN_E_SUCCESS != lockdownd_set_value(lockdown, NULL, \"ActivationStateAcknowledged\", plist_new_bool(1))) {\n\t\t\t\t\t\tfprintf(stderr, \"Failed to set ActivationStateAcknowledged on device.\\n\");\n\t\t\t\t\t\tresult = EXIT_FAILURE;\n\t\t\t\t\t\tgoto cleanup;\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t} else {\n\t\t\t\t\tif (idevice_activation_response_is_activation_acknowledged(response)) {\n\t\t\t\t\t\tprintf(\"Activation server reports that device is already activated.\\n\");\n\t\t\t\t\t\tresult = EXIT_SUCCESS;\n\t\t\t\t\t\tgoto cleanup;\n\t\t\t\t\t}\n\n\t\t\t\t\tidevice_activation_response_get_title(response, &response_title);\n\t\t\t\t\tif (response_title) {\n\t\t\t\t\t\tfprintf(stderr, \"Server reports:\\n%s\\n\", response_title);\n\t\t\t\t\t}\n\n\t\t\t\t\tidevice_activation_response_get_description(response, &response_description);\n\t\t\t\t\tif (response_description) {\n\t\t\t\t\t\tfprintf(stderr, \"Server reports:\\n%s\\n\", response_description);\n\t\t\t\t\t}\n\n\t\t\t\t\tidevice_activation_response_get_fields(response, &fields);\n\t\t\t\t\tif (!fields || plist_dict_get_size(fields) == 0) {\n\t\t\t\t\t\t// we have no activation record, no reported erros, no acknowledgment and no fields to send\n\t\t\t\t\t\tfprintf(stderr, \"Unknown error.\\n\");\n\t\t\t\t\t\tresult = EXIT_FAILURE;\n\t\t\t\t\t\tgoto cleanup;\n\t\t\t\t\t}\n\n\t\t\t\t\tplist_dict_new_iter(fields, &iter);\n\t\t\t\t\tif (!iter) {\n\t\t\t\t\t\tfprintf(stderr, \"Unknown error.\\n\");\n\t\t\t\t\t\tresult = EXIT_FAILURE;\n\t\t\t\t\t\tgoto cleanup;\n\t\t\t\t\t}\n\n\t\t\t\t\tidevice_activation_request_free(request);\n\t\t\t\t\trequest = NULL;\n\t\t\t\t\tif (idevice_activation_request_new(\n\t\t\t\t\t\tIDEVICE_ACTIVATION_CLIENT_MOBILE_ACTIVATION, &request) != IDEVICE_ACTIVATION_E_SUCCESS) {\n\t\t\t\t\t\tfprintf(stderr, \"Could not create new request.\\n\");\n\t\t\t\t\t\tresult = EXIT_FAILURE;\n\t\t\t\t\t\tgoto cleanup;\n\t\t\t\t\t}\n\n\t\t\t\t\tidevice_activation_request_set_fields_from_response(request, response);\n\n\t\t\t\t\tint interactive_count = 0;\n\t\t\t\t\tdo {\n\t\t\t\t\t\tfield_key = NULL;\n\t\t\t\t\t\tplist_dict_next_item(fields, iter, &field_key, NULL);\n\t\t\t\t\t\tif (field_key) {\n\t\t\t\t\t\t\tif (idevice_activation_response_field_requires_input(response, field_key)) {\n\t\t\t\t\t\t\t\tidevice_activation_response_get_label(response, field_key, &field_label);\n\t\t\t\t\t\t\t\tif (interactive) {\n\t\t\t\t\t\t\t\t\tchar *field_placeholder = NULL;\n\t\t\t\t\t\t\t\t\tint secure = idevice_activation_response_field_secure_input(response, field_key);\n\t\t\t\t\t\t\t\t\tidevice_activation_response_get_placeholder(response, field_key, &field_placeholder);\n\t\t\t\t\t\t\t\t\tprintf(\"input %s\", field_label ? field_label : field_key);\n\t\t\t\t\t\t\t\t\tif (field_placeholder) {\n\t\t\t\t\t\t\t\t\t\tprintf(\" (%s)\", field_placeholder);\n\t\t\t\t\t\t\t\t\t\tfree(field_placeholder);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tprintf(\": \");\n\t\t\t\t\t\t\t\t\tfflush(stdout);\n\t\t\t\t\t\t\t\t\tfflush(stdin);\n\t\t\t\t\t\t\t\t\tget_user_input(input, 1023, secure);\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tfprintf(stderr, \"Server requires input for '%s' but we're not running interactively.\\n\", field_label ? field_label : field_key);\n\t\t\t\t\t\t\t\t\tstrcpy(input, \"\");\n\t\t\t\t\t\t\t\t\tinteractive_count++;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tidevice_activation_request_set_field(request, field_key, input);\n\t\t\t\t\t\t\t\tif (field_label) {\n\t\t\t\t\t\t\t\t\tfree(field_label);\n\t\t\t\t\t\t\t\t\tfield_label = NULL;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t} while(field_key);\n\n\t\t\t\t\tfree(iter);\n\t\t\t\t\titer = NULL;\n\t\t\t\t\tidevice_activation_response_free(response);\n\t\t\t\t\tresponse = NULL;\n\n\t\t\t\t\tif (interactive_count > 0 && !interactive) {\n\t\t\t\t\t\tfprintf(stderr, \"Failed to activate device.\\n\");\n\t\t\t\t\t\tresult = EXIT_FAILURE;\n\t\t\t\t\t\tgoto cleanup;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t}\n\n\t\t\tresult = EXIT_SUCCESS;\n\t\t\tprintf(\"Successfully activated device.\\n\");\n\t\t\tbreak;\n\t\tcase OP_GETSTATE: {\n\t\t\tplist_t state = NULL;\n\t\t\tif (use_mobileactivation) {\n\t\t\t\tmobileactivation_get_activation_state(ma, &state);\n\t\t\t} else {\n\t\t\t\tlockdownd_get_value(lockdown, NULL, \"ActivationState\", &state);\n\t\t\t}\n\t\t\tif (plist_get_node_type(state) == PLIST_STRING) {\n\t\t\t\tchar *s_state = NULL;\n\t\t\t\tplist_get_string_val(state, &s_state);\n\t\t\t\tprintf(\"ActivationState: %s\\n\", s_state);\n\t\t\t\tfree(s_state);\n\t\t\t} else {\n\t\t\t\tprintf(\"Error getting activation state.\\n\");\n\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\n\t\tcase OP_ITUNES: {\n\t\t\t// set iTunesHasConnected if we succeeded\n\t\t\tif (LOCKDOWN_E_SUCCESS != lockdownd_set_value(lockdown, NULL, \"iTunesHasConnected\", plist_new_bool(1))) {\n\t\t\t\tfprintf(stderr, \"Failed to set iTunesHasConnected on device.\\n\");\n\t\t\t\tresult = EXIT_FAILURE;\n\t\t\t\tgoto cleanup;\n\t\t\t}\n\t\t\tresult = EXIT_SUCCESS;\n\t\t\tprintf(\"Successfully set 'iTunesHasConnected'.\\n\");\n\t\t\t}\n\t\t\tbreak;\n\t}\n\ncleanup:\n\tif (request)\n\t\tidevice_activation_request_free(request);\n\n\tif (response)\n\t\tidevice_activation_response_free(response);\n\n\tif (fields)\n\t\tplist_free(fields);\n\n\tif (field_label)\n\t\tfree(field_label);\n\n\tif (iter)\n\t\tfree(iter);\n\n\tif (record)\n\t\tplist_free(record);\n\n\tif (ma)\n\t\tmobileactivation_client_free(ma);\n\n\tif (lockdown)\n\t\tlockdownd_client_free(lockdown);\n\n\tif (device)\n\t\tidevice_free(device);\n\n\treturn result;\n}\n"
  }
]