import 'dart:ffi' as ffi; import 'dart:io'; import 'package:ffi/ffi.dart'; import 'deezcryptor_bindings_generated.dart'; const String _libName = 'deezcryptor'; /// The dynamic library in which the symbols for [DeezcryptorBindings] can be found. final ffi.DynamicLibrary _dylib = () { if (Platform.isMacOS || Platform.isIOS) { return ffi.DynamicLibrary.open('$_libName.framework/$_libName'); } if (Platform.isAndroid || Platform.isLinux) { return ffi.DynamicLibrary.open('lib$_libName.so'); } if (Platform.isWindows) { return ffi.DynamicLibrary.open('$_libName.dll'); } throw UnsupportedError('Unknown platform: ${Platform.operatingSystem}'); }(); /// The bindings to the native functions in [_dylib]. final DeezcryptorBindings _bindings = DeezcryptorBindings(_dylib); final decryptChunkRaw = _bindings.decryptChunk; List decryptChunk(List data, List key) { final ptr = malloc(data.length); final ptr1 = listIntToPointerChar(data); final ptr2 = listIntToPointerChar(key); final size = _bindings.decryptChunk(ptr, ptr1, ptr2); malloc.free(ptr1); malloc.free(ptr2); final dec = pointerCharToListInt(ptr, size); malloc.free(ptr); return dec; } ffi.Pointer listIntToPointerChar(List list) { final length = list.length; final ptr = malloc(length); for (int i = 0; i < length; i++) { ptr[i] = list[i]; } return ptr; } List pointerCharToListInt(ffi.Pointer ptr, int size) { return List.unmodifiable( Iterable.generate(size, (index) => ptr[index])); }