secure_shield 1.2.0
secure_shield: ^1.2.0 copied to clipboard
An intelligent, all-in-one security shield for Flutter apps, providing threat detection, analysis, and configurable automated responses.
example/lib/main.dart
// ignore_for_file: avoid_print
import 'package:flutter/material.dart';
import 'package:logging/logging.dart';
import 'package:secure_shield/secure_shield.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Geliştirici loglamasını aktif etme
Logger.root.level = Level.ALL;
Logger.root.onRecord.listen((record) {
// Bu satır, paketin loglarını konsolda görmenizi sağlar.
// 'print' uyarısı alırsanız, bunu 'debugPrint' ile değiştirebilirsiniz.
print(
'${record.level.name}: ${record.time}: [${record.loggerName}] ${record.message}',
);
});
// --- OTOMATİK KAPATMA POLİTİKASINI BURADA AYARLIYORUZ ---
// Hangi tehdidin uygulamayı kapatacağını seçmek için 'true' yapmanız yeterli.
SecureShield.initialize(
SecureShieldConfig(
terminateOnRoot: true,
terminateOnEmulator:
true, // Root/Jailbreak tespit edilirse kapat. // Emülatör/Simülatör tespit edilirse kapat.
terminateOnDebugger: true, // Debugger tespit edilirse kapat.
terminateOnHooking: true, // Hooking tespit edilirse kapat.
// Kurcalanmış uygulama tespit edilirse kapat.
),
);
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
Assessment? _assessment;
bool _isLoading = false;
Future<void> _runSecurityCheck() async {
setState(() {
_isLoading = true;
_assessment = null;
});
// Güvenlik kontrolünü çalıştırıyoruz.
// Eğer yukarıdaki kurallardan biri tetiklenirse, bu satırdan sonraki kodlar
// hiç çalışmaz çünkü uygulama zaten kapanmış olur.
final assessment = await SecureShield.getAssessment(
// Android Anti-Tamper için artık bu yöntemi kullanmıyoruz.
// trustedInstallers: ["com.android.vending"],
);
// Eğer uygulama kapanmadıysa (yani tehdit yoksa veya politika REPORT_ONLY ise),
// sonucu ekrana yazdırırız.
if (mounted) {
setState(() {
_assessment = assessment;
_isLoading = false;
});
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(title: const Text('SecureShield Test Uygulaması')),
body: Center(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
if (_isLoading)
const CircularProgressIndicator()
else if (_assessment != null)
Card(
color: _assessment!.threatLevel == ThreatLevel.NONE
? Colors.green.shade100
: Colors.red.shade100,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Text(
_assessment.toString(),
textAlign: TextAlign.center,
style: const TextStyle(fontSize: 16),
),
),
)
else
const Text('Güvenlik analizi için butona basın.'),
const SizedBox(height: 20),
ElevatedButton(
onPressed: _isLoading ? null : _runSecurityCheck,
child: const Text('Güvenlik Analizi Yap'),
),
],
),
),
),
),
);
}
}