R63b - Perfect packet char filter

Results 1 to 11 of 11
  1. #1
    Account Upgraded | Title Enabled! George2000 is offline
    MemberRank
    Jul 2011 Join Date
    The NetherlandsLocation
    1,150Posts

    R63b - Perfect packet char filter

    Hi, I've made a packet filter that filters ANY char other then A-Z a-z 0-9 and -

    For example, you will get:
    Received packet [0][0][0][36][15][160][0][32]RELEASE63-201205240929-144271078

    Code:

    PHP Code:
       public string FromCharToString(string Data)
            {
                
    string Filtered Data;
                
    Regex lettersOnly = new Regex("^[a-zA-Z]{1,25}$");
                
    Regex numbersOnly = new Regex("^[0-9]$");

                foreach (
    char C in Filtered)
                {
                    if (
    C.ToString() == "-" || lettersOnly.IsMatch(C.ToString()) || numbersOnly.IsMatch(C.ToString()))
                        continue;

                    
    Filtered Filtered.Replace(C.ToString(), "[" + (int)"]");
                }

                return 
    Filtered;
            } 
    Credits:

    Me - creating code
    Google - example regex.


  2. #2
    Account Upgraded | Title Enabled! AWA is offline
    MemberRank
    Feb 2008 Join Date
    1,320Posts

    Re: R63b - Perfect packet char filter

    you can't really credit google for this, can you?

  3. #3
    Valued Member Shebsonwai is offline
    MemberRank
    Mar 2012 Join Date
    wwwrootLocation
    108Posts

    Re: R63b - Perfect packet char filter

    Maybe you should tell us where to put this code.

  4. #4
    Ultra Light Beam Makarov is offline
    MemberRank
    Apr 2010 Join Date
    GothamLocation
    3,622Posts
    Suggestion: Show us some results!

    Sent from my DROID RAZR using Tapatalk 2

  5. #5
    Ask me about Daoism FullmetalPride is offline
    MemberRank
    Nov 2010 Join Date
    2,172Posts
    Still don't get what I put with packets to put them into an emulator..

  6. #6
    Alpha Member Zak© is offline
    MemberRank
    Oct 2007 Join Date
    2,693Posts

    Re: R63b - Perfect packet char filter

    @Above
    Tbh this is a key feature for a basic packet logger.

    It has nothing to really do with emulators.

    Thanks, i guess it's useful.

  7. #7
    Evil Italian Overlowrd Droppy is offline
    [Internal Coder]Rank
    Feb 2012 Join Date
    /home/droppyLocation
    2,080Posts

    Re: R63b - Perfect packet char filter

    Code complete, with modifications to save packets, packets writing, among others.
    Sorry For My Bad English, I'm Brazillian!
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Resources;
    using System.Text.RegularExpressions;
    using System.Text;
    
    /*
     * By Droppy and George2000
     * Do not remove this -> Compulsory license in the 'Creative Commons License' (Which we are using now) 
     */
    
    namespace ConsoleApplication20
    {
        class Program
        {
            public static void FromCharToString(string Data)
            {
                string Filtered = Data;
                Regex lettersOnly = new Regex("^[a-zA-Z]{1,25}$");
                Regex numbersOnly = new Regex("^[0-9]$");
    
                foreach (char C in Filtered)
                {
                    if (C.ToString() == "-" || lettersOnly.IsMatch(C.ToString()) || numbersOnly.IsMatch(C.ToString()))
                        continue;
    
                    Filtered = Filtered.Replace(C.ToString(), "[" + (int)C + "]");
                }
                TimeSpan span = (DateTime.Now - DateTime.Now);
    
    
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.Write("Result: ");
                Console.ResetColor();
                Console.WriteLine(Filtered);
                Console.WriteLine("Saved in lastPacket.txt");                                                        
                string[] Write = { "###################################", "### Credits: Droppy, George2000 ###", "###################################", "Packets (decoded): " + Filtered, "Packets (encoded): " + Data };
                System.IO.File.WriteAllLines(@"lastPacket.txt", Write);
                Console.WriteLine("     ");
    
            }  
    
            static void Main(string[] args)
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("############################################################");
                Console.WriteLine("### By: Droppy and George2000 - Creative Commons License ###");
                Console.WriteLine("############################################################");
                Console.WriteLine("### The last package will be saved in lastPacket.txt     ###");
                Console.WriteLine("############################################################");
                Console.WriteLine("     ");
                Console.ResetColor();
                Console.ForegroundColor = ConsoleColor.DarkRed;
                
                Console.WriteLine("Started!");
    
                Console.ResetColor();
                Console.WriteLine("     ");
                goto Programe;
            Programe:
                Console.ForegroundColor = ConsoleColor.Blue;
                Console.Write("Write Packets: ");
                Console.ResetColor();
                string phrase = Console.ReadLine();
                FromCharToString(phrase);
                
                goto Programe;
            }
        }
    }
    //Enjoy the code!
    Enjoy It :D

  8. #8
    Ask me about Daoism FullmetalPride is offline
    MemberRank
    Nov 2010 Join Date
    2,172Posts

    Re: R63b - Perfect packet char filter

    Quote Originally Posted by Zak© View Post
    @Above
    Tbh this is a key feature for a basic packet logger.

    It has nothing to really do with emulators.

    Thanks, i guess it's useful.
    I really have to start learning code..


    Couldn't even tell it was only a piece, ffs..

  9. #9
    Retired maritnmine is offline
    MemberRank
    May 2007 Join Date
    North KoreaLocation
    1,103Posts

    Re: R63b - Perfect packet char filter

    Quote Originally Posted by George2000 View Post
    PHP Code:
       public string FromCharToString(string Data)
            {
                
    string Filtered Data;
                
    Regex lettersOnly = new Regex("^[a-zA-Z]{1,25}$");
                
    Regex numbersOnly = new Regex("^[0-9]$");

                foreach (
    char C in Filtered)
                {
                    if (
    C.ToString() == "-" || lettersOnly.IsMatch(C.ToString()) || numbersOnly.IsMatch(C.ToString()))
                        continue;

                    
    Filtered Filtered.Replace(C.ToString(), "[" + (int)"]");
                }

                return 
    Filtered;
            } 
    Slow algorithm is slow :)
    #1: Each time you call the function, you have to create two new Regexes each time.
    #2: Running a for-statement on a string is faster than a foreach :) (Read on MSDN)
    #3: This thing could have been done way easier, like this :D

    http://pastebin.com/cMGVgDLB

    Code may be a bit longer, but it is way faster :)

    - Martin
    Last edited by maritnmine; 25-05-12 at 12:50 PM.

  10. #10
    Developer Quackster is offline
    DeveloperRank
    Dec 2010 Join Date
    AustraliaLocation
    3,483Posts

    Re: R63b - Perfect packet char filter

    Why isn't the method static?

  11. #11
    Account Upgraded | Title Enabled! George2000 is offline
    MemberRank
    Jul 2011 Join Date
    The NetherlandsLocation
    1,150Posts

    Re: R63b - Perfect packet char filter

    Quote Originally Posted by Quackster View Post
    Why isn't the method static?
    Not really needed in my emulator, since it's only used in the same class or methods with the class as parameter.



Advertisement