Dart wrapper via dart:ffi for https://github.com/libusb/libusb

Overview

libusb

Dart wrapper via dart:ffi for https://github.com/libusb/libusb

Environment

  • Windows(10)
  • macOS
  • Linux(Ubuntu 18.04 LTS)

Usage

Checkout example

Features and bugs

Please file feature requests and bugs at the issue tracker.

Build

Prepare llvm(9+)

  • Windows: winget install -e --id LLVM.LLVM
  • macOS: brew install llvm
  • Linux: sudo apt install libclang-10-dev

Build libusb_xxx.dart

  • Windows/Linux:
pub run ffigen
move lib/libusb.dart lib/libusb64.dart

Refactor timeval to timeval64

  • macOS:
pub run ffigen
mv lib/libusb.dart lib/libusb32.dart

Refactor timeval to timeval32

Contribute

Prepare libusb.h

Download xxx verion from https://github.com/libusb/libusb/releases and extract libusb.h

Prepare libusb-1.0 dynamic library

  • Windows:

Download xxx version from https://github.com/libusb/libusb/releases and extract

copy libusb-1.0.23\MS64\dll\libusb-1.0.dll libusb-1.0\
  • macOS:

Download xxx version from https://homebrew.bintray.com/bottles/libusb-1.0.23.catalina.bottle.tar.gz and extract

cp libusb/1.0.23/lib/libusb-1.0.dylib libusb-1.0/
  • Linux:

Download xxx version from http://old.kali.org/kali/pool/main/libu/libusb-1.0/ and install

cp /lib/x86_64-linux-gnu/libusb-1.0.so.0.xxx libusb-1.0/libusb-1.0.so
Comments
  • Example missing on how to use the library?

    Example missing on how to use the library?

    Thank you for the package.

    Sorry but I cannot see a straightforward way to using it.

    1. I cannot see an example section in the packages https://pub.dev/packages/libusb
    2. I can see an example folder in the github page but the use of it causes errors from listDeviceProducts.dart

    image

    I just want to import the library on windows platform and use its provided functions to access usb device and send data to it. Will there be a step by step guide in getting this done?

    Again thank you for your work and apologies if the solution was obvious but i could not pick up on it.

    opened by jyashi 9
  • Update ffi package dependency

    Update ffi package dependency

    Currently, using this package as dependency causes compile error

    Launching lib/main.dart on macOS in debug mode...
    lib/main.dart:1
    ../lib/src/quick_usb_desktop.dart:110:38: Error: Expected type 'Utf8' to be a valid and instantiated subtype of 'NativeType'.
     - 'Utf8' is from 'package:ffi/src/utf8.dart' ('../../../../.pub-cache/hosted/pub.dartlang.org/ffi-1.1.2/lib/src/utf8.dart').
    

    Offending line is

    Pointer<ffi.Utf8> string = ffi.malloc(256);

    Seems this is known issue https://github.com/flutter/flutter/issues/76705

    To resolve it, ffi package dependency needs to be updated to latest version (currently 1.1.2)

    opened by shaxxx 1
  • [generation] libusb_windows.dart syntax error

    [generation] libusb_windows.dart syntax error

    flutter pub run ffigen on Windows results with syntax error. Removing consts solves the error

    ffi.Pointer<ffi.Pointer<ffi.NativeFunction<const SERVER_ROUTINE>>> DispatchTable; // 101960
    ffi.Pointer<ffi.Pointer<ffi.NativeFunction<const STUB_THUNK>>> ThunkTable; // 101966 
    // ...
    typedef const SERVER_ROUTINE = ... // 241521
    typedef const STUB_THUNK = ... // 241524
    

    Related: https://github.com/dart-lang/ffigen/issues/145

    opened by Sunbreak 1
  • `pkg_ffi.Size` doesn't map to int

    `pkg_ffi.Size` doesn't map to int

    Since https://github.com/woodemi/libusb.dart/commit/0763bbd76b49600dc7cdf682c97790d715d7fe1b upgraded to ffigen 5.0.0-dev.0

    flutter pub run ffigen results in pkg_ffi.Size in Dart funtion decleration

      ffi.Pointer<pkg_ffi.UnsignedChar> libusb_dev_mem_alloc(
        ffi.Pointer<libusb_device_handle> dev_handle,
        pkg_ffi.Size length,
      ) {
        return _libusb_dev_mem_alloc(
          dev_handle,
          length,
        );
      }
    
      late final _libusb_dev_mem_allocPtr = _lookup<
          ffi.NativeFunction<
              ffi.Pointer<pkg_ffi.UnsignedChar> Function(
                  ffi.Pointer<libusb_device_handle>,
                  pkg_ffi.Size)>>('libusb_dev_mem_alloc');
      late final _libusb_dev_mem_alloc = _libusb_dev_mem_allocPtr.asFunction<
          ffi.Pointer<pkg_ffi.UnsignedChar> Function(
              ffi.Pointer<libusb_device_handle>, pkg_ffi.Size)>();
    
      int libusb_dev_mem_free(
        ffi.Pointer<libusb_device_handle> dev_handle,
        ffi.Pointer<pkg_ffi.UnsignedChar> buffer,
        pkg_ffi.Size length,
      ) {
        return _libusb_dev_mem_free(
          dev_handle,
          buffer,
          length,
        );
      }
    
      late final _libusb_dev_mem_freePtr = _lookup<
          ffi.NativeFunction<
              pkg_ffi.Int Function(
                  ffi.Pointer<libusb_device_handle>,
                  ffi.Pointer<pkg_ffi.UnsignedChar>,
                  pkg_ffi.Size)>>('libusb_dev_mem_free');
      late final _libusb_dev_mem_free = _libusb_dev_mem_freePtr.asFunction<
          int Function(ffi.Pointer<libusb_device_handle>,
              ffi.Pointer<pkg_ffi.UnsignedChar>, pkg_ffi.Size)>();
    
    opened by Sunbreak 0
  • Examples fail to run

    Examples fail to run

    Very excited to have found this library, unfortunately when I try to run the examples I receive the following FFI errors:

    $ dart --version
    Dart SDK version: 2.18.6 (stable) (Tue Dec 13 21:15:14 2022 +0000) on "macos_arm64
    
    $ dart run example/main.dart
    lib/src/libusb.ffigen.dart:112:15: Error: Type 'pkg_ffi.Char' not found.
      ffi.Pointer<pkg_ffi.Char> libusb_error_name(
                  ^^^^^^^^^^^^
    lib/src/libusb.ffigen.dart:127:17: Error: Type 'pkg_ffi.Char' not found.
        ffi.Pointer<pkg_ffi.Char> locale,
                    ^^^^^^^^^^^^
    lib/src/libusb.ffigen.dart:140:15: Error: Type 'pkg_ffi.Char' not found.
      ffi.Pointer<pkg_ffi.Char> libusb_strerror(
                  ^^^^^^^^^^^^
    lib/src/libusb.ffigen.dart:221:17: Error: Type 'pkg_ffi.Int' not found.
        ffi.Pointer<pkg_ffi.Int> config,
                    ^^^^^^^^^^^
    lib/src/libusb.ffigen.dart:901:17: Error: Type 'pkg_ffi.UnsignedChar' not found.
        ffi.Pointer<pkg_ffi.UnsignedChar> endpoints,
                    ^^^^^^^^^^^^^^^^^^^^
    lib/src/libusb.ffigen.dart:925:17: Error: Type 'pkg_ffi.UnsignedChar' not found.
        ffi.Pointer<pkg_ffi.UnsignedChar> endpoints,
                    ^^^^^^^^^^^^^^^^^^^^
    lib/src/libusb.ffigen.dart:945:15: Error: Type 'pkg_ffi.UnsignedChar' not found.
      ffi.Pointer<pkg_ffi.UnsignedChar> libusb_dev_mem_alloc(
                  ^^^^^^^^^^^^^^^^^^^^
    lib/src/libusb.ffigen.dart:966:17: Error: Type 'pkg_ffi.UnsignedChar' not found.
        ffi.Pointer<pkg_ffi.UnsignedChar> buffer,
                    ^^^^^^^^^^^^^^^^^^^^
    lib/src/libusb.ffigen.dart:1152:17: Error: Type 'pkg_ffi.UnsignedChar' not found.
        ffi.Pointer<pkg_ffi.UnsignedChar> data,
                    ^^^^^^^^^^^^^^^^^^^^
    lib/src/libusb.ffigen.dart:1186:17: Error: Type 'pkg_ffi.UnsignedChar' not found.
        ffi.Pointer<pkg_ffi.UnsignedChar> data,
    
    opened by jonahgeorge 0
  • open error: LIBUSB_ERROR_ACCESS

    open error: LIBUSB_ERROR_ACCESS

    hi: I tried to run listdeviceproducts Dart file, but always in libusb_ When you open, you get this error: open error: libusb_ ERROR_ ACCESS image Could you help me?

    opened by pauloved 1
  • [generation] unavailable inline C function

    [generation] unavailable inline C function

    For example:

    https://github.com/woodemi/libusb.dart/blob/7f7ed5fa9abd7c7804c861f6be060a11ce5f8bc8/libusb-1.0/libusb.h#L161-L178

    results

    https://github.com/woodemi/libusb.dart/blob/7f7ed5fa9abd7c7804c861f6be060a11ce5f8bc8/lib/libusb_macos.dart#L587-L602

    which doen't exist in dynamic library


    Calling it would throw ArgumentError

    https://github.com/woodemi/libusb.dart/blob/b67b2f77928cd7064bde208605e0472d01c1f66f/test/libusb_test.dart#L32-L34

    Marked those inline functions @Deprecated('inline') as a workaround

    opened by Sunbreak 1
Owner
Woodemi Co., Ltd
Woodemi Co., Ltd
Let's Encrypt support for the shelf package (free and automatic HTTPS certificate support).

shelf_letsencrypt shelf_letsencrypt brings support for Let's Encrypt to the shelf package. Usage To use the LetsEncrypt class import 'dart:io'; impor

Graciliano Monteiro Passos 8 Oct 31, 2022
Volt is a wrapper over the Revolt API for easily writing bots using the Dart language.

Volt is a wrapper over the Revolt API for easily writing bots using the Dart language. It is currently in active development so not all of the functionality has yet been implemented.

null 8 Dec 13, 2022
Minimal Dart wrapper to interact with Some Random Api. Easy to use, simplified and lightweight.

SRA - Some Random Api Minimal Dart wrapper to interact with Some Random Api. Easy to use, simplified and lightweight. Getting started Add the package

Yakiyo 3 Jan 4, 2023
A simple flexible API wrapper for coinbase commerce API. Totally unofficial.

coinbase_commerce A dart library that connects to interact with the Coinbase Commerce API. Enables projects to connect seamlessly to coinbase and rece

Onuoha Obinna 3 Oct 17, 2021
A script for automating the creation and uploading a flutter project to github

Flutter Automation Script A script for automating the tasks of creating and uploading a flutter project to github. Made with Batch Scripts, Shell Scri

Tushar Patil 18 Dec 15, 2022
Easy to use session wrapper that adds support to session storage and management in flutter.

flutter_session_manager Adds an easy to use wrapper to session management in flutter. Allows for easy session storage and management. The session pers

Eduardo Migueis 2 Feb 15, 2022
A Dart build script that downloads the Protobuf compiler and Dart plugin to streamline .proto to .dart compilation.

A Dart build script that downloads the Protobuf compiler and Dart plugin to streamline .proto to .dart compilation.

Julien Scholz 10 Oct 26, 2022
Extensible Dart interpreter for Dart with full interop

dart_eval is an extensible interpreter for the Dart language, written in Dart. It's powered under the hood by the Dart analyzer, so it achieves 100% c

Ethan 169 Dec 28, 2022
Quiver is a set of utility libraries for Dart that makes using many Dart libraries easier and more convenient, or adds additional functionality.

Quiver is a set of utility libraries for Dart that makes using many Dart libraries easier and more convenient, or adds additional functionality.

Google 905 Jan 2, 2023
AOP for Flutter(Dart)

AspectD Salute to AspectJ. AspectD is an AOP(aspect oriented programming) framework for dart. Like other traditional aop framework, AspectD provides c

null 1k Jan 7, 2023
Environment specific config generator for Dart and Flutter applications during CI/CD builds

Environment Config Generator Environment specific config generator. Allows to specify env configuration during CI/CD build. Primarily created to simpl

Denis Beketsky 86 Dec 2, 2022
A Very Good Command Line Interface for Dart created by Very Good Ventures 🦄

Very Good CLI Developed with ?? by Very Good Ventures ?? A Very Good Command Line Interface for Dart. Installing $ dart pub global activate very_good_

Very Good Open Source 1.8k Jan 8, 2023
🚀The Flutter dart code generator from zeplin. ex) Container, Text, Color, TextStyle, ... - Save your time.

Flutter Gen Zeplin Extension ?? The Flutter dart code generator from zeplin. ex) Container, Text, Color, TextStyle, ... - Save your time. ⬇ 1.1k Getti

NAVER 49 Oct 12, 2022
Dart language version of Persian-Tools

Persian tools Persian Tools dart package which you can use in all platforms Features Adding ordinal suffixes Converting Persian words to number Conver

Persian Tools 54 Dec 29, 2022
A Dart package to web scraping data from websites easily and faster using less code lines.

Chaleno A flutter package to webscraping data from websites This package contains a set of high-level functions that make it easy to webscrap websites

António Nicolau 30 Dec 29, 2022
A pure dart package to apply useful rate limiting strategies on regular functions.

Rate limiting is a strategy for limiting an action. It puts a cap on how often someone can repeat an action within a certain timeframe. Using rate_limiter we made it easier than ever to apply these strategies on regular dart functions.

Stream 24 Dec 14, 2022
Dart phone number parser, based on libphonenumber and PhoneNumberKit.

Dart library for parsing phone numbers. Inspired by Google's libphonenumber and PhoneNumberKit for ios.

cedvdb 39 Dec 31, 2022
Basic Dart reverse shell code

dart_rs Basic Dart reverse shell based on this one by Potato-Industries. Pretty self explanatory. You’ll need Windows. I used a Windows 7 64-bit VM. F

null 21 Oct 2, 2022
Dart phone number parser, based on libphonenumber and PhoneNumberKit.

Phone Numbers Parser Dart library for parsing phone numbers. Inspired by Google's libphonenumber and PhoneNumberKit for ios. The advantage of this lib

cedvdb 39 Dec 31, 2022