dumbfck's fault

06/28/2011 16:37 DitDat#1
Due to his signature I'm trying learn c# again

So I have ended up losing couple weeks reading various forums and such, but I have managed to rewrite the basic features of my launcher for pw.

Now I want to steal Noobs offset finder for the other functions like i done before

I have found the c# Regex command and the syntax seems simple enough, however all the guides for it want me to open text file

I have found lots of commands for opening files, but which one do i use to open a exe file for regex to use

I think I can convert the rest myself
06/28/2011 17:38 Interest07#2
I'd do something like this:

Code:
            byte[] ba;
            using (FileStream br = File.OpenRead(clientLocation))
            {
                ba = new byte[br.Length]; //br.Length
                br.Read(ba, 0, (int)br.Length); //br.Length
            }

            List<char> clist = new List<char>();
            foreach (byte b in ba)
                clist.Add((char)b);
            char[] ca = clist.ToArray();
            string client = new string(ca);
            
            Regex rx = new Regex(expression);
            foreach (Match mx in rx.Matches(client))
            {
                  //blah blah
            }
06/28/2011 18:05 DitDat#3
thx! i was so close yet so far lol
06/28/2011 19:10 DitDat#4
Well it kinda made sense to me but my computer didnt like it

It just seems to freeze at the rx.Matches command

I left it 10mins in case its being slow but the autoit version only takes few secs

I getting frustrated now so I gonna give up for today or rest of week lol :(

Code:
            if (File.Exists(file) == true)
            {
                byte[] ba;
                using (FileStream br = File.OpenRead(file))
                {
                    ba = new byte[br.Length]; //br.Length
                    br.Read(ba, 0, (int)br.Length); //br.Length
                }

                List<char> clist = new List<char>();
                foreach (byte b in ba)
                    clist.Add((char)b);
                char[] ca = clist.ToArray();
                Console.WriteLine(ca.Length); // output 6699664  so guess this bit is working, i dunno
                string client = new string(ca);

                Regex rx = new Regex(@".*?(8B0D(.{8})898D40F1FFFF6A01)"); //just test first one for now
                Console.WriteLine("hello, im working so far");//console did say this
                MatchCollection matches = rx.Matches(client);
                Console.WriteLine(matches.Count);             //just trying get helpful output but seems freeze at rx.matches(client)
                foreach (Match mx in rx.Matches(client))
                {
                    
                }
                Console.WriteLine("goodbye");    //apparently he wont talk to me anymore :(
            }
06/28/2011 21:21 Interest07#5
It shouldn't be slow, i can get about 15 done within a second (its faster than in autoit for me)

what happens if you remove "MatchCollection matches = rx.Matches(client);"?
06/28/2011 22:05 DitDat#6
it freezes at

foreach (Match mx in rx.Matches(client))

i added

MatchCollection matches = rx.Matches(client);
Console.WriteLine(matches.Count);

just see if it gave me a number, it just froze at that step instead
06/28/2011 22:55 Interest07#7
you have to escape hex characters with \x btw

like:
Code:
        private static string updateDescriptionExpression =
@"\x90\x90\x90\x90\x90\x90" +                            // align 10h
@"\x8B\x01" +                                        // mov     eax, [ecx]
@"\x6A\x00" +                                        // push    0
@"\xFF\x50\x34" +                                     // call    dword ptr [eax+34h]
@"\xC3";                                           // retn
06/28/2011 23:44 DitDat#8
i dont understand :(

do u mean noobs expressions are made for autoit and need changing for c#?

i havnt got a clue how to use your code, i cant pass the existing expression to it which was my only idea to what u meant
06/29/2011 08:33 Interest07#9
Quote:
Originally Posted by DitDat View Post
i dont understand :(

do u mean noobs expressions are made for autoit and need changing for c#?

i havnt got a clue how to use your code, i cant pass the existing expression to it which was my only idea to what u meant
yes, you need to change the expressions by adding \x in front of the bytes to show they're hex code. Otherwise it will look for a string with characters 8B0D (4 characters for example) instead of the 2 characters \x8B and \x0D

Regex rx = new Regex(@".*?(\x8B\x0D(.{8})\x89\x8D\x40\xF1\xFF\xFF \x6A\x01)");
06/29/2011 15:10 DitDat#10
well i spent all morning messing with it but cant get it too work.

It takes over a hour for rx.Matches(client) to complete with either expression and I get no results
06/29/2011 17:22 Interest07#11
that's odd...

I'll post a full example in a bit, see how that works for you
07/04/2011 14:26 DitDat#12
have you forgot about me or just been busy?

I spent this time get my memory functions working :)

I thought about actually playing pw for a bit but i got bored quick, this is my hobby now lol

It occurs to me that i could just use the autoit version and load the offsets from the text file but that kinda de-motivates me
07/04/2011 17:18 Interest07#13
I dug around my old code and this came up, hope you can use it :)

Code:
        static void findAddresses(string clientLocation, string iniLocation)
        {


            byte[] ba;
            using (FileStream br = File.OpenRead(clientLocation))
            {
                ba = new byte[br.Length]; //br.Length
                br.Read(ba, 0, (int)br.Length); //br.Length
            }

            List<char> clist = new List<char>();
            foreach (byte b in ba)
                clist.Add((char)b);
            char[] ca = clist.ToArray();
            string client = new string(ca);

            IniFile iniFile = new IniFile(iniLocation);
            findPacketFunctionAddress(client, iniFile);
    }


        private static void findPacketFunctionAddress(string client, IniFile iniFile)
        {

            int realBaseAddress = 0;
            int sendPacketAddress = 0;

            Regex rx = new Regex(findPacketFunctionExpression);
            foreach (Match mx in rx.Matches(client))
            {
                int call_pos = mx.Index + 0x40007B;

                //realBaseAddress
                Capture c1 = mx.Groups[1];

                byte[] bb = new byte[c1.Value.Length];

                int theOffset = 0;
                int multiplier = 0x100;
                for (int i = 0; i < c1.Value.Length; i++)
                {
                    theOffset += (byte)c1.Value[i] * (int)Math.Pow(multiplier, i);
                }
                realBaseAddress = theOffset;
                Debug.WriteLine("realBaseAddress: 0x{0:X}", theOffset);

                iniFile.IniWriteValue("Addresses", "GRaddr", "0x" + theOffset.ToString("X"));

                //sendPacketAddress
                c1 = mx.Groups[2];

                bb = new byte[c1.Value.Length];

                theOffset = 0;
                multiplier = 0x100;
                for (int i = 0; i < c1.Value.Length; i++)
                {
                    theOffset += (byte)c1.Value[i] * (int)Math.Pow(multiplier, i);
                }
                theOffset += call_pos + 7;
                sendPacketAddress = theOffset;
                
                Debug.WriteLine("sendPacketAddress: 0x{0:X}", theOffset);
                iniFile.IniWriteValue("Addresses", "aSendPacketCall", "0x" + theOffset.ToString("X"));

            }
            Console.WriteLine("realBaseAddress: 0x{0:X}", realBaseAddress);
            Console.WriteLine("sendPacketAddress: 0x{0:X}", sendPacketAddress);
        }

       private static string findPacketFunctionExpression =
            @"\x6A\x21" +                                    // push    21h
            @"\xE8.{4}" +                                   // call    sub740780      // Call Procedure
            @"\x8B\xF0" +                                    // mov     esi, eax
            @"\x83\xC4\x04" +                                 // add     esp, 4          // Add
            @"\x85\xF6" +                                    // test    esi, esi        // Logical Compare
            @"\x74.{1}" +                                    // jz      short loc5D9D9C // Jump if Zero (ZF=1)
            @"\x8A\x44\x24\x18" +                              // mov     al, [esp+4+moveType]
            @"\x66\x8B\x4C\x24\x10" +                           // mov     cx, [esp+4+ukShort]
            @"\x66\xC7\x06\x00\x00" +                           // mov     word ptr [esi], 0
            @"\x88\x46\x1E" +                                 // mov     [esi+1Eh], al
            @"\x8B\x44\x24\x08" +                              // mov     eax, [esp+4+XYZpointer1]
            @"\x66\x89\x4E\x1A" +                              // mov     [esi+1Ah], cx
            @"\xD9\x44\x24\x14" +                              // fld     [esp+4+moveSpeed] // Load Real
            @"\x8B\x10" +                                    // mov     edx, [eax]
            @"\x89\x56\x02" +                                 // mov     [esi+2], edx
            @"\x8B\x48\x04" +                                 // mov     ecx, [eax+4]
            @"\xD8\x0D.{4}" +                                   // fmul    ds:flt8BDB08   // Multiply Real
            @"\x89\x4E\x06" +                                 // mov     [esi+6], ecx
            @"\x8B\x50\x08" +                                 // mov     edx, [eax+8]
            @"\x8B\x44\x24\x0C" +                              // mov     eax, [esp+4+XYZpointer2]
            @"\x89\x56\x0A" +                                 // mov     [esi+0Ah], edx
            @"\xD8\x05.{4}" +                                   // fadd    ds:flt8AE894   // Add Real
            @"\x8B\x08" +                                    // mov     ecx, [eax]
            @"\x89\x4E\x0E" +                                 // mov     [esi+0Eh], ecx
            @"\x8B\x50\x04" +                                 // mov     edx, [eax+4]
            @"\x89\x56\x12" +                                 // mov     [esi+12h], edx
            @"\x8B\x40\x08" +                                 // mov     eax, [eax+8]
            @"\x89\x46\x16" +                                 // mov     [esi+16h], eax
            @"\xE8.{4}" +                                       // call    ftol           // Call Procedure
            @"\x66\x8B\x4C\x24\x1C" +                           // mov     cx, [esp+4+moveCounter]
            @"\x66\x89\x46\x1C" +                              // mov     [esi+1Ch], ax
            @"\x66\x89\x4E\x1F" +                              // mov     [esi+1Fh], cx
            @"\x8B\x15(.{4})" +                                 // mov     edx, dword98657C
            @"\x6A\x21" +                                    // push    21h             // Size
            @"\x56" +                                       // push    esi             // Src
            @"\x8B\x4A\x20" +                                 // mov     ecx, [edx+20h]
            @"\xE8(.{4})" +                                     // call    SendPacket    // Call Procedure
            @"\x56" +                                       // push    esi
            @"\xE8.{4}" +                                       // call    sub740790      // Call Procedure
            @"\x83\xC4\x04" +                                 // add     esp, 4          // Add
            @"\x5E" +                                       // pop     esi
            @"\xC3";                                        // retn                    // Return Near from Procedure
07/04/2011 23:23 DitDat#14
ok, your method for opening the exe works for your expression (obviously), i gave up trying to convert nooobs expressions to work with it as well,

Instead I figured out how open the exe the same way as autoit does in nooobs script

Code:
FileStream inputFile = new FileStream(file, FileMode.Open);
byte[] byteBuffer = new byte[inputFile.Length];
inputFile.Read(byteBuffer, 0, (int) inputFile.Length);
StringBuilder client = new StringBuilder();
for (int i = 0; i < byteBuffer.Length; i++)
{
      client.Append(byteBuffer[i].ToString("X2"));
}
Regex rx = new Regex(@"(8B0D(.{8})898D40F1FFFF6A01)");
foreach (Match mx in rx.Matches(client.ToString()))
{
      Console.WriteLine("yay got match");
}
which gave me 1 match so i guess its working so far :)

I just need convert the rest now. I think I read somewhere here that converting is bad coz it needs lots of testing, well im a noob so my code already needs lots testing :D

Anyway thx for giving me the right commands to research, it did help.
07/06/2011 10:39 Smurfin#15
have anyone ever tried writing an exact same bot/tool for pw in both autoit and c and compare the cpu and ram usage ? which one use less, and by less, does it matter much ?

I usually ran 6 clients if not more and each client has specific bot written for it, some of these bots sometimes use up to the same amount of cpu usage of the client itself and can go higher once in a while =.= (ranging from 1% - 12% cpu usage)

my cpu ends up using 95%-100% of its juice everyday, the heat is average at 80 degree celcius

here is an example of my cpu usage table from windows task manager, autoit is very cpu hungry :(
[Only registered and activated users can see links. Click Here To Register...]


* btw sorry for the interruption, just want to know if c can do the same thing with less cpu usage :handsdown: