// Ripped from https://github.com/Ch0pin/medusa/ and modified to fit Androguard packets

colorLog('[+] LOADING FILE_SYSTEM/SHARED_PREFERENCES.JS',{c: Color.Red});

var SharedPreferencesImpl = Java.use("android.app.SharedPreferencesImpl");
var SharedPreferencesImpl_EditorImpl = Java.use("android.app.SharedPreferencesImpl$EditorImpl");
 
 SharedPreferencesImpl.contains.implementation = function(key) {
   var value = this.contains(key);
   agPacket({key: key, value: value}).send();
   return value;
 };

 SharedPreferencesImpl.getInt.implementation = function(key, defValue) {
   var value = this.getInt(key, defValue);
   agPacket({key: key, defValue: defValue, value: value}).send();
   return value;
 };

 SharedPreferencesImpl.getFloat.implementation = function(key, defValue) {  
   var value = this.getFloat(key, defValue);
   agPacket({key: key, defValue: defValue, value: value}).send();
   return value;
 };

 SharedPreferencesImpl.getLong.implementation = function(key, defValue) {
   var value = this.getLong(key, defValue);
   agPacket({key: key, defValue: defValue, value: value}).send();
   return value;
 };

 SharedPreferencesImpl.getBoolean.implementation = function(key, defValue) {
   var value = this.getBoolean(key, defValue);
   agPacket({key: key, defValue: defValue, value: value}).send();
   return value;
 };

 SharedPreferencesImpl.getString.implementation = function(key, defValue) {
   var value = this.getString(key, defValue);
   agPacket({key: key, defValue: defValue, value: value}).send();
   return value;
 };

 SharedPreferencesImpl.getStringSet.implementation = function(key, defValue) {
    var value = this.getStringSet(key, defValue);
    agPacket({key: key, defValue: defValue, value: value}).send();
    return value;
 };

 SharedPreferencesImpl_EditorImpl.putString.implementation = function(key, value) {
    agPacket({key: key, value: value}).send();
   return this.putString(key,value);
 };

 SharedPreferencesImpl_EditorImpl.putStringSet.implementation = function(key, values) {
    agPacket({key: key, values: values}).send();
   return this.putStringSet(key,values);
 };

 SharedPreferencesImpl_EditorImpl.putInt.implementation = function(key, value) {
   agPacket({key: key, value: value}).send();
   return this.putInt(key,value);
 };

 SharedPreferencesImpl_EditorImpl.putFloat.implementation = function(key, value) {
    agPacket({key: key, value: value}).send();
    return this.putFloat(key,value);
 };

 SharedPreferencesImpl_EditorImpl.putBoolean.implementation = function(key, value) {
    agPacket({key: key, value: value}).send();
    return this.putBoolean(key,value);
 };

 SharedPreferencesImpl_EditorImpl.putLong.implementation = function(key, value) {
    agPacket({key: key, value: value}).send();
    return this.putLong(key,value);
 };

 SharedPreferencesImpl_EditorImpl.remove.implementation = function(key) {
    agPacket({key: key}).send();
   return this.remove(key);
 };