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

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

var gzipInputStream = Java.use('java.util.zip.GZIPInputStream');
var gzipOutputStream = Java.use('java.util.zip.GZIPOutputStream');

gzipOutputStream.write.implementation = function(buff, off, len_n){

    var buffer = Java.array('byte', buff);
    var result = "";
    for(var i = 0; i < buffer.length; ++i){
        if(buffer[i] >= 32 && buffer[i]<127)
            result+= (String.fromCharCode(buffer[i]));
    }

    agPacket({result: result}).send();

    return this.write(buff, off, len_n);
}

gzipInputStream.read.implementation = function(buff, off, len_n){
    var buffer = Java.array('byte', buff);
    var result = "";
    for(var i = 0; i < buffer.length; ++i){
        if(buffer[i] >= 32 && buffer[i]<127)
            result+= (String.fromCharCode(buffer[i]));
    }

    agPacket({result: result}).send();
    return this.write(buff,off,len_n);
}