Beispiel #1
0
        /**
         * Return a File for the application plugin
         * from a Hit Packet
         * */
        public static G2File ParseHit(G2PacketH hit,FileLocationFound location)
        {
            // for now we dont take into accounts host of partial files
            if (isPartialFile(hit) && !Settings.ACCEPT_PARTIAL_FILE)
                return null;

            string FileName = "";
            long size = getNameAndSizeFromHit (hit, out FileName);
            if (size == 0)
                return null; // no size, no name or bug

            List<URN> Hashes = getHashesFromHit (hit);
            TypeHash type = TypeHash.Md4EDonkey;
            URN SingleHash = Hashes.Find (FindED2KHash);
            if (SingleHash == null) {
                SingleHash = Hashes.Find (FindSHA1Hash);
                type = TypeHash.Sha1;
            }
            // if there is not the hashes we want , we dont want this packet
            // for now. ActionInnoncence DLL needs to take care of more hashes
            if (SingleHash == null)
                return null;
            // gives a text representation of the hash
            string strHash = BitConverter.ToString(SingleHash.Digest).Replace("-", string.Empty).ToLower();

            string link = getDownloadLink (hit);
            Metadata meta = Metadata.ParseMetadata(hit.getStringFromChildType(G2PacketType.MD));

            G2File f = new G2File(FileName, strHash, SingleHash.Digest, type, size,
                FileType.Unknow, meta.Codec, location, meta.Length, Settings.PROTOCOL_NAME, link);

            f.Hashes = Hashes;
            f.CreationTime = getCreationTimeFromHit(hit);
            f.Metadata = meta;
            f.UserComment = hit.getStringFromChildType(G2PacketType.COM);
            f.PreviewUrl = hit.getStringFromChildType( G2PacketType.PVU);
            return f;
        }
Beispiel #2
0
        public static G2Packet getPacketByHeader(Header h)
        {
            G2Packet packet = null;
            switch(h.type) {
            case G2PacketType.PVU:
                packet = new G2PacketPVU (h);
                break;
            case G2PacketType.COM:
                packet = new G2PacketCOM (h);
                break;
            case G2PacketType.PART:
                packet = new G2PacketPART(h);
                break;
            case G2PacketType.SZ:
                packet = new G2PacketSZ (h);
                break;
            case G2PacketType.Q2:
                packet = new G2PacketQ2 (h);
                break;
            case G2PacketType.DN:
                packet = new G2PacketDN (h);
                break;
            case G2PacketType.KHL:
                packet = new G2PacketKHL (h);
                break;
            case G2PacketType.QA:
                packet = new G2PacketQA (h);
                break;
            case G2PacketType.SS:
                packet = new G2PacketSS (h);
                break;
            case G2PacketType.QH2:
                packet = new G2PacketQH2 (h);
                break;
            case G2PacketType.HG:
                packet = new G2PacketHG (h);
                break;
            case G2PacketType.PI:
                packet = new G2PacketPI (h);
                break;
            case G2PacketType.UDP:
                packet = new G2PacketUDP (h);
                break;
            case G2PacketType.PO:
                packet = new G2PacketPO (h);
                break;
            case G2PacketType.S:
                packet = new G2PacketS(h);
                break;
            case G2PacketType.D:
                packet = new G2PacketD(h);
                break;
            case G2PacketType.LNI:
                packet = new G2PacketLNI (h);
                break;
            case G2PacketType.GU:
                packet = new G2PacketGU (h);
                break;
            case G2PacketType.NA:
                packet = new G2PacketNA (h);
                break;
            case G2PacketType.QKR:
                packet = new G2PacketQKR (h);
                break;
            case G2PacketType.QKA:
                packet = new G2PacketQKA (h);
                break;
            case G2PacketType.SNA:
                packet = new G2PacketSNA (h);
                break;
            case G2PacketType.QNA:
                packet = new G2PacketQNA (h);
                break;
            case G2PacketType.V:
                packet = new G2PacketV (h);
                break;
            case G2PacketType.LS:
                packet = new G2PacketLS (h);
                break;
            case G2PacketType.HS:
                packet = new G2PacketHS (h);
                break;
            case G2PacketType.TLS:
                packet = new G2PacketTLS (h);
                break;
            case G2PacketType.TS:
                packet = new G2PacketTS (h);
                break;
            case G2PacketType.NH:
                packet = new G2PacketNH (h);
                break;
            case G2PacketType.RA:
                packet = new G2PacketRA (h);
                break;
            case G2PacketType.BUP:
                packet = new G2PacketBUP (h);
                break;
            case G2PacketType.H:
                packet = new G2PacketH (h);
                break;
            case G2PacketType.URL:
                packet = new G2PacketURL (h);
                break;
            case G2PacketType.URN:
                packet = new G2PacketURN (h);
                break;
            case G2PacketType.UPRO:
                packet = new G2PacketUPRO (h);
                break;
            case G2PacketType.NICK:
                packet = new G2PacketNICK (h);
                break;
            case G2PacketType.BH:
                packet = new G2PacketBH (h);
                break;
            case G2PacketType.FW:
                packet = new G2PacketFW (h);
                break;
            case G2PacketType.MD:
                packet = new G2PacketMD (h);
                break;
            case G2PacketType.UPROC:
               packet = new G2PacketUPROC(h);
               break;
            case G2PacketType.UPROD :
               packet = new G2PacketUPROD(h);
               break;
               case G2PacketType.XML:
               packet = new G2PacketXML(h);
               break;
            default :
                packet = new G2PacketDefault (h);
                break;

            }
            return packet;
        }
Beispiel #3
0
        public static G2Packet getPacketByHeader(Header h)
        {
            G2Packet packet = null;

            switch (h.type)
            {
            case G2PacketType.PVU:
                packet = new G2PacketPVU(h);
                break;

            case G2PacketType.COM:
                packet = new G2PacketCOM(h);
                break;

            case G2PacketType.PART:
                packet = new G2PacketPART(h);
                break;

            case G2PacketType.SZ:
                packet = new G2PacketSZ(h);
                break;

            case G2PacketType.Q2:
                packet = new G2PacketQ2(h);
                break;

            case G2PacketType.DN:
                packet = new G2PacketDN(h);
                break;

            case G2PacketType.KHL:
                packet = new G2PacketKHL(h);
                break;

            case G2PacketType.QA:
                packet = new G2PacketQA(h);
                break;

            case G2PacketType.SS:
                packet = new G2PacketSS(h);
                break;

            case G2PacketType.QH2:
                packet = new G2PacketQH2(h);
                break;

            case G2PacketType.HG:
                packet = new G2PacketHG(h);
                break;

            case G2PacketType.PI:
                packet = new G2PacketPI(h);
                break;

            case G2PacketType.UDP:
                packet = new G2PacketUDP(h);
                break;

            case G2PacketType.PO:
                packet = new G2PacketPO(h);
                break;

            case G2PacketType.S:
                packet = new G2PacketS(h);
                break;

            case G2PacketType.D:
                packet = new G2PacketD(h);
                break;

            case G2PacketType.LNI:
                packet = new G2PacketLNI(h);
                break;

            case G2PacketType.GU:
                packet = new G2PacketGU(h);
                break;

            case G2PacketType.NA:
                packet = new G2PacketNA(h);
                break;

            case G2PacketType.QKR:
                packet = new G2PacketQKR(h);
                break;

            case G2PacketType.QKA:
                packet = new G2PacketQKA(h);
                break;

            case G2PacketType.SNA:
                packet = new G2PacketSNA(h);
                break;

            case G2PacketType.QNA:
                packet = new G2PacketQNA(h);
                break;

            case G2PacketType.V:
                packet = new G2PacketV(h);
                break;

            case G2PacketType.LS:
                packet = new G2PacketLS(h);
                break;

            case G2PacketType.HS:
                packet = new G2PacketHS(h);
                break;

            case G2PacketType.TLS:
                packet = new G2PacketTLS(h);
                break;

            case G2PacketType.TS:
                packet = new G2PacketTS(h);
                break;

            case G2PacketType.NH:
                packet = new G2PacketNH(h);
                break;

            case G2PacketType.RA:
                packet = new G2PacketRA(h);
                break;

            case G2PacketType.BUP:
                packet = new G2PacketBUP(h);
                break;

            case G2PacketType.H:
                packet = new G2PacketH(h);
                break;

            case G2PacketType.URL:
                packet = new G2PacketURL(h);
                break;

            case G2PacketType.URN:
                packet = new G2PacketURN(h);
                break;

            case G2PacketType.UPRO:
                packet = new G2PacketUPRO(h);
                break;

            case G2PacketType.NICK:
                packet = new G2PacketNICK(h);
                break;

            case G2PacketType.BH:
                packet = new G2PacketBH(h);
                break;

            case G2PacketType.FW:
                packet = new G2PacketFW(h);
                break;

            case G2PacketType.MD:
                packet = new G2PacketMD(h);
                break;

            case G2PacketType.UPROC:
                packet = new G2PacketUPROC(h);
                break;

            case G2PacketType.UPROD:
                packet = new G2PacketUPROD(h);
                break;

            case G2PacketType.XML:
                packet = new G2PacketXML(h);
                break;

            default:
                packet = new G2PacketDefault(h);
                break;
            }
            return(packet);
        }
Beispiel #4
0
 private static bool isPartialFile(G2PacketH hit)
 {
     G2Packet part = hit.getFirstChildPacket(G2PacketType.PART);
     if (part != null)
         return true;
     return false;
 }
Beispiel #5
0
        /**
         * Return the size of the file and the name with the out parameters name
         * */
        private static long getNameAndSizeFromHit(G2PacketH hit, out string name)
        {
            G2Packet SZ,DN;
            DN = hit.getFirstChildPacket (G2PacketType.DN);
            SZ = hit.getFirstChildPacket (G2PacketType.SZ);
            name = "";
            if (DN == null) // no name
                return 0;
            // object size packet is not present
            // so we parse DN with a 32 bit integer before
            if ( SZ == null) {
                byte[] bytes = ((G2PacketDN)DN).bytes;
                byte[] bName = bytes.SubArray (4, bytes.Length - 4);
                long size = BinaryUtils.getVariableIntLE (bytes, 4);
                name = BinaryUtils.getStringFromBytes (bName, (int)(bytes.Length - 4));
                return size;

            } else {
                name = ((G2PacketDN)DN).Str;
                return ((G2PacketSZ)SZ).Size;

            }
        }
Beispiel #6
0
 /**
  * Parse all hashes contained for this file
  * */
 private static List<URN> getHashesFromHit(G2PacketH hit)
 {
     List<URN> hashes = new List<URN> ();
     foreach (G2Packet child in hit.children) {
         if (child.type != G2PacketType.URN)
             continue;
         G2PacketURN UrnPacket = child as G2PacketURN;
         if (UrnPacket == null)
             continue;
         hashes.Add (UrnPacket.urn);
     }
     return hashes;
 }
Beispiel #7
0
        /**
         * Get a URL link if present
         * IF not present , it has to beretrieved by HTTP request
         * */
        private static string getDownloadLink(G2PacketH hit)
        {
            G2Packet pack = hit.getFirstChildPacket (G2PacketType.URL);
            if (pack == null)
                return "";
            G2PacketURL url = pack as G2PacketURL;
            if (url == null)
                return "";

            return url.Str;
        }
Beispiel #8
0
 /**
  * Return creation time in DateTime format if present
  * otherwise return current time
  * */
 private static DateTime getCreationTimeFromHit(G2PacketH hit)
 {
     G2Packet pack = hit.getFirstChildPacket (G2PacketType.CT);
     if (pack == null)
         return DateTime.Now;
     G2PacketCT ct = pack as G2PacketCT;
     return BinaryUtils.UnixTimeStampToDateTime (ct.Timestamp);
 }