{"id":12655,"date":"2024-03-26T18:07:14","date_gmt":"2024-03-26T10:07:14","guid":{"rendered":"http:\/\/xinyiworld.top\/wordpress_it\/?p=12655"},"modified":"2024-03-26T18:15:10","modified_gmt":"2024-03-26T10:15:10","slug":"%e5%88%a4%e6%96%adusb%e8%ae%be%e5%a4%87%e6%98%af%e5%90%a6%e4%b8%bafastboot%e8%ae%be%e5%a4%87","status":"publish","type":"post","link":"http:\/\/xinyiworld.top\/wordpress_it\/?p=12655","title":{"rendered":"\u5224\u65adusb\u8bbe\u5907\u662f\u5426\u4e3afastboot\u8bbe\u5907"},"content":{"rendered":"<pre><code class=\"language-cpp\">#include &lt;iostream&gt;\n#include &lt;libusb.h&gt;\n\nbool isFastbootDevice(libusb_device *device) {\n    libusb_device_handle *handle = nullptr;\n    int result = libusb_open(device, &amp;handle);\n    if (result != LIBUSB_SUCCESS) {\n        std::cerr &lt;&lt; &quot;Error opening device&quot; &lt;&lt; std::endl;\n        return false;\n    }\n\n    uint8_t buffer[256];\n    result = libusb_get_device_descriptor(device, reinterpret_cast&lt;libusb_device_descriptor *&gt;(buffer));\n    if (result != LIBUSB_SUCCESS) {\n        std::cerr &lt;&lt; &quot;Error getting device descriptor&quot; &lt;&lt; std::endl;\n        libusb_close(handle);\n        return false;\n    }\n\n    libusb_device_descriptor *desc = reinterpret_cast&lt;libusb_device_descriptor *&gt;(buffer);\n\n    \/\/ \u68c0\u67e5\u8bbe\u5907ID\u548c\u5382\u5546\u5b57\u7b26\u4e32\u662f\u5426\u4e3afastboot\u8bbe\u5907\u7684\u6807\u5fd7\n    bool isFastbootDevice = (desc-&gt;idVendor == 0x18d1 &amp;&amp; desc-&gt;idProduct == 0x4e26) ||\n                            (desc-&gt;idVendor == 0x0bb4 &amp;&amp; desc-&gt;idProduct == 0x0fff);\n\n    libusb_close(handle);\n    return isFastbootDevice;\n}\n\nint main() {\n    libusb_context *context = nullptr;\n    int result = libusb_init(&amp;context);\n    if (result != LIBUSB_SUCCESS) {\n        std::cerr &lt;&lt; &quot;Failed to initialize libusb&quot; &lt;&lt; std::endl;\n        return -1;\n    }\n\n    libusb_device **devs;\n    ssize_t cnt = libusb_get_device_list(context, &amp;devs);\n    if (cnt &lt; 0) {\n        std::cerr &lt;&lt; &quot;Error retrieving device list&quot; &lt;&lt; std::endl;\n        libusb_exit(nullptr);\n        return -1;\n    }\n\n    for (int i = 0; i &lt; cnt; i++) {\n        libusb_device *device = devs[i];\n        if (isFastbootDevice(device)) {\n            std::cout &lt;&lt; &quot;Fastboot device found&quot; &lt;&lt; std::endl;\n        } else {\n            std::cout &lt;&lt; &quot;Not a fastboot device&quot; &lt;&lt; std::endl;\n        }\n    }\n\n    libusb_free_device_list(devs, 1);\n    libusb_exit(context);\n    return 0;\n}<\/code><\/pre>\n<button class=\"simplefavorite-button\" data-postid=\"12655\" data-siteid=\"1\" data-groupid=\"1\" data-favoritecount=\"0\" style=\"\">\u6536\u85cf <i class=\"sf-icon-star-empty\"><\/i><\/button>","protected":false},"excerpt":{"rendered":"<p>#include &lt;iostream&gt; #include &lt;libusb.h&#038;gt [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[974],"tags":[],"_links":{"self":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/12655"}],"collection":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12655"}],"version-history":[{"count":1,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/12655\/revisions"}],"predecessor-version":[{"id":12656,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=\/wp\/v2\/posts\/12655\/revisions\/12656"}],"wp:attachment":[{"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12655"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12655"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/xinyiworld.top\/wordpress_it\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12655"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}