Mã nguồn đã công bố
Tải mã nguồn dạng ZIP
CH-J SM Mobile
Duyệt thư mục và tệp của một bản phát hành ứng dụng cụ thể.
CH-J / SM Mobile
175 tệp
sm-mobile-20261016T185235Z-8e93ecc1b59a
Ngày thêm: · Ngày dựng:
1
import 'dart:ffi';2
import 'dart:io';3
import 'dart:typed_data';5
/// Minimal POSIX socket bindings for unprivileged ICMP.6
///7
/// Darwin (iOS, macOS) and Linux (Android) both allow `SOCK_DGRAM` sockets8
/// with `IPPROTO_ICMP`/`IPPROTO_ICMPV6` without root. They differ in9
/// constants, in the `sockaddr` layout, in whether the IPv4 header is10
/// delivered, and in how ICMP errors arrive: Darwin delivers them as normal11
/// messages, Linux through the socket error queue (`IP_RECVERR`).12
final class PollFd extends Struct {13
@Int32()14
external int fd;15
@Int16()16
external int events;17
@Int16()18
external int revents;19
}21
final class IoVec extends Struct {22
external Pointer<Uint8> base;23
@IntPtr()24
external int length;25
}27
/// Linux `struct msghdr`; the FFI layout follows the 32/64-bit ABI.28
final class MsgHdr extends Struct {29
external Pointer<Uint8> name;30
@Uint32()31
external int nameLength;32
external Pointer<IoVec> iov;33
@IntPtr()34
external int iovLength;35
external Pointer<Uint8> control;36
@IntPtr()37
external int controlLength;38
@Int32()39
external int flags;40
}42
/// Linux `struct cmsghdr`.43
final class CmsgHdr extends Struct {44
@IntPtr()45
external int length;46
@Int32()47
external int level;48
@Int32()49
external int type;50
}52
class Posix {53
final bool darwin;54
final DynamicLibrary _lib;55
Posix._(this.darwin, this._lib);57
static Posix? _instance;59
/// Null where neither the Darwin nor the Linux implementation applies.60
static Posix? get current {61
if (_instance != null) return _instance;62
if (Platform.isIOS || Platform.isMacOS) {63
return _instance = Posix._(true, DynamicLibrary.process());64
}65
if (Platform.isAndroid) {66
return _instance = Posix._(false, DynamicLibrary.open('libc.so'));67
}68
if (Platform.isLinux) {69
return _instance = Posix._(false, DynamicLibrary.process());70
}71
return null;72
}74
// Constants (Darwin / Linux).75
int get afInet => 2;76
int get afInet6 => darwin ? 30 : 10;77
int get sockDgram => 2;78
int get sockStream => 1;79
int get ipprotoUdp => 17;80
int get ipprotoTcp => 6;81
int get solSocket => darwin ? 0xffff : 1;82
int get soError => darwin ? 0x1007 : 4;83
int get fGetFl => 3;84
int get fSetFl => 4;85
int get oNonBlock => darwin ? 0x4 : 0x800;86
// Don't Fragment: IP_DONTFRAG on Darwin; IP_MTU_DISCOVER = IP_PMTUDISC_DO87
// on Linux. IPv6: IPV6_DONTFRAG on Darwin; IPV6_MTU_DISCOVER on Linux.88
int get ipDontFrag => darwin ? 28 : 10;89
int get ipv6DontFrag => darwin ? 62 : 23;90
int get dontFragValue => darwin ? 1 : 2;91
int get ipprotoIp => 0;92
int get ipprotoIpv6 => 41;93
int get ipprotoIcmp => 1;94
int get ipprotoIcmpv6 => 58;95
int get ipTtl => darwin ? 4 : 2;96
int get ipv6UnicastHops => darwin ? 4 : 16;97
int get ipRecvErr => 11;98
int get ipv6RecvErr => 25;99
int get msgErrQueue => 0x2000;100
int get msgDontWait => darwin ? 0x80 : 0x40;101
static const pollIn = 0x1, pollOut = 0x4, pollErr = 0x8;102
// Linux sock_extended_err.ee_origin values.103
static const originIcmp = 2, originIcmp6 = 3;105
late final socket = _lib106
.lookupFunction<107
Int32 Function(Int32, Int32, Int32),108
int Function(int, int, int)109
>('socket');110
late final close = _lib111
.lookupFunction<Int32 Function(Int32), int Function(int)>('close');112
late final setsockopt = _lib113
.lookupFunction<114
Int32 Function(Int32, Int32, Int32, Pointer<Void>, Uint32),115
int Function(int, int, int, Pointer<Void>, int)116
>('setsockopt');117
late final sendto = _lib118
.lookupFunction<119
IntPtr Function(120
Int32,121
Pointer<Uint8>,122
IntPtr,123
Int32,124
Pointer<Uint8>,125
Uint32,126
),127
int Function(int, Pointer<Uint8>, int, int, Pointer<Uint8>, int)128
>('sendto');129
late final recvfrom = _lib130
.lookupFunction<131
IntPtr Function(132
Int32,133
Pointer<Uint8>,134
IntPtr,135
Int32,136
Pointer<Uint8>,137
Pointer<Uint32>,138
),139
int Function(140
int,141
Pointer<Uint8>,142
int,143
int,144
Pointer<Uint8>,145
Pointer<Uint32>,146
)147
>('recvfrom');148
late final connect = _lib149
.lookupFunction<150
Int32 Function(Int32, Pointer<Uint8>, Uint32),151
int Function(int, Pointer<Uint8>, int)152
>('connect');153
late final getsockname = _lib154
.lookupFunction<155
Int32 Function(Int32, Pointer<Uint8>, Pointer<Uint32>),156
int Function(int, Pointer<Uint8>, Pointer<Uint32>)157
>('getsockname');158
late final getsockopt = _lib159
.lookupFunction<160
Int32 Function(Int32, Int32, Int32, Pointer<Void>, Pointer<Uint32>),161
int Function(int, int, int, Pointer<Void>, Pointer<Uint32>)162
>('getsockopt');163
late final fcntl = _lib164
.lookupFunction<165
Int32 Function(Int32, Int32, VarArgs<(Int32,)>),166
int Function(int, int, int)167
>('fcntl');168
late final recvmsg = _lib169
.lookupFunction<170
IntPtr Function(Int32, Pointer<MsgHdr>, Int32),171
int Function(int, Pointer<MsgHdr>, int)172
>('recvmsg');173
// nfds_t is unsigned int on Darwin and unsigned long on Linux.174
late final int Function(Pointer<PollFd>, int, int) poll = darwin175
? _lib.lookupFunction<176
Int32 Function(Pointer<PollFd>, Uint32, Int32),177
int Function(Pointer<PollFd>, int, int)178
>('poll')179
: _lib.lookupFunction<180
Int32 Function(Pointer<PollFd>, UnsignedLong, Int32),181
int Function(Pointer<PollFd>, int, int)182
>('poll');183
late final Pointer<Int32> Function() _errnoLocation = _lib184
.lookupFunction<Pointer<Int32> Function(), Pointer<Int32> Function()>(185
darwin186
? '__error'187
: (Platform.isAndroid ? '__errno' : '__errno_location'),188
);190
/// The calling thread's errno, read right after a failed call.191
int get errno => _errnoLocation().value;193
// errno values that need a specific explanation.194
int get eAccess => 13;195
int get ePerm => 1;196
int get eNetUnreach => darwin ? 51 : 101;197
int get eHostUnreach => darwin ? 65 : 113;198
int get eInProgress => darwin ? 36 : 115;199
int get eConnRefused => darwin ? 61 : 111;200
int get eMsgSize => darwin ? 40 : 90;202
/// `struct sockaddr_in` / `sockaddr_in6` for [address] and [port].203
Uint8List sockaddr(InternetAddress address, [int port = 0]) {204
final v6 = address.type == InternetAddressType.IPv6;205
final raw = address.rawAddress;206
final out = Uint8List(v6 ? 28 : 16);207
if (darwin) {208
out[0] = out.length;209
out[1] = v6 ? afInet6 : afInet;210
} else {211
final family = v6 ? afInet6 : afInet;212
out[0] = family & 0xff;213
out[1] = family >> 8;214
}215
out[2] = (port >> 8) & 0xff;216
out[3] = port & 0xff;217
out.setRange(v6 ? 8 : 4, v6 ? 24 : 8, raw);218
return out;219
}221
/// The port of a `sockaddr_in` / `sockaddr_in6` (network byte order).222
int port(Uint8List sockaddr) =>223
sockaddr.length < 4 ? 0 : (sockaddr[2] << 8) | sockaddr[3];225
/// The address in a `sockaddr_in` / `sockaddr_in6` returned by the kernel.226
InternetAddress? address(Uint8List sockaddr, int length) {227
if (length >= 24 && sockaddr.length >= 24) {228
final family = darwin ? sockaddr[1] : sockaddr[0] | (sockaddr[1] << 8);229
if (family == afInet6) {230
return InternetAddress.fromRawAddress(sockaddr.sublist(8, 24));231
}232
}233
if (length >= 8 && sockaddr.length >= 8) {234
final family = darwin ? sockaddr[1] : sockaddr[0] | (sockaddr[1] << 8);235
if (family == afInet) {236
return InternetAddress.fromRawAddress(sockaddr.sublist(4, 8));237
}238
}239
return null;240
}241
}SHA-256
01152c0883838cc3329f3a326a972870af872ff60036de8e6c22f2de9d205df1CH-J Proprietary Software License 1.14 · Mã nguồn được cung cấp theo CH-J Proprietary Software License 1.14. Việc công khai mã nguồn không thay đổi các điều khoản giấy phép và không cấp thêm quyền nào.
SHA-256 của tệp nén
46e427a43e87af091004f36145590bda8fe90086dfb0f631afeb5029fb0b5655