Exemple #1
0
        private UInt32 FindPtr(IMAGE_SECTION_HEADER sec, byte[] data, UInt32 search)
        {
            UInt32 rv = FindNextPtr(sec, data, search, 0);

            if (rv != UInt32.MaxValue)
            {
                rv += 0x00400000 + sec.virtAddr;
            }
            return(rv);
        }
Exemple #2
0
        private bool PatchGServer(IMAGE_SECTION_HEADER sec, byte[] data, string serverName = "sylverant.net")
        {
            int          y, bytesWritten;
            const string origServ  = "pso20.sonic.isao.net";
            const string origServ2 = "sg207634.sonicteam.com";
            const string origServ3 = "pso-mp01.sonic.isao.net";
            const string origServ4 = "gsproduc.ath.cx";
            string       serv      = serverName;

            byte[] opBytes  = Encoding.ASCII.GetBytes(origServ);
            byte[] opBytes2 = Encoding.ASCII.GetBytes(origServ2);
            byte[] opBytes3 = Encoding.ASCII.GetBytes(origServ3);
            byte[] opBytes4 = Encoding.ASCII.GetBytes(origServ4);
            byte[] pBytes   = Encoding.ASCII.GetBytes(serv);
            bool   rv       = false;

            for (y = 0; y < sec.virtSz - serv.Length; ++y)
            {
                if (memEqual(data, opBytes, origServ.Length, y, 0))
                {
                    memset(data, 0, origServ.Length, y);
                    memcpy(data, pBytes, serv.Length, y, 0);
                    rv = true;
                }
                else if (memEqual(data, opBytes2, origServ2.Length, y, 0))
                {
                    memset(data, 0, origServ2.Length, y);
                    memcpy(data, pBytes, serv.Length, y, 0);
                    rv = true;
                }
                else if (memEqual(data, opBytes3, origServ3.Length, y, 0))
                {
                    memset(data, 0, origServ3.Length, y);
                    memcpy(data, pBytes, serv.Length, y, 0);
                    rv = true;
                }
                else if (memEqual(data, opBytes4, origServ4.Length, y, 0))
                {
                    memset(data, 0, origServ4.Length, y);
                    memcpy(data, pBytes, serv.Length, y, 0);
                    rv = true;
                }
            }

            if (rv && !WriteProcessMemory(0x00400000 + sec.virtAddr, sec.virtSz, data, out bytesWritten))
            {
                return(false);
            }

            return(rv);
        }
Exemple #3
0
        private bool DetectMapfix(IMAGE_SECTION_HEADER sec, byte[] data)
        {
            /* Assume that if one map has been fixed that all of them have. */
            UInt32 acaveptr = FindString(sec, data, Encoding.ASCII.GetBytes("map_acave01_05"));

            /* If we find that string, then the Cave 1 mapset is full, so the mapfix must have
             * already been applied. */
            if (acaveptr != UInt32.MaxValue)
            {
                return(true);
            }

            return(false);
        }
Exemple #4
0
        private UInt32 FindString(IMAGE_SECTION_HEADER sec, byte[] data, byte[] search)
        {
            UInt32 y;

            for (y = 0; y < sec.virtSz - search.Length; ++y)
            {
                if (memEqual(data, search, search.Length, (int)y, 0) && data[y + search.Length] == 0)
                {
                    return(y + 0x00400000 + sec.virtAddr);
                }
            }

            return(UInt32.MaxValue);
        }
Exemple #5
0
        private bool MusicPatch(IMAGE_SECTION_HEADER sec, byte[] data)
        {
            UInt32 mamboPtr = FindString(sec, data, Encoding.ASCII.GetBytes("mambo.adx"));

            if (mamboPtr == UInt32.MaxValue)
            {
                return(false);
            }

            UInt32 chuPtr = FindString(sec, data, Encoding.ASCII.GetBytes("chu_f.adx"));

            if (chuPtr == UInt32.MaxValue)
            {
                return(false);
            }

            UInt32 duel1Ptr = FindString(sec, data, Encoding.ASCII.GetBytes("duel1.adx"));

            if (duel1Ptr == UInt32.MaxValue)
            {
                return(false);
            }

            UInt32 duel2Ptr = FindString(sec, data, Encoding.ASCII.GetBytes("duel2.adx"));

            if (duel2Ptr == UInt32.MaxValue)
            {
                return(false);
            }

            UInt32 mambo2Ptr = FindPtr(sec, data, mamboPtr);

            if (mambo2Ptr == UInt32.MaxValue)
            {
                return(false);
            }

            UInt32 chu2byo = FindPtr(sec, data, chuPtr);

            if (chu2byo == UInt32.MaxValue)
            {
                return(false);
            }

            WriteUInt32(mambo2Ptr, duel1Ptr);
            WriteUInt32(chu2byo, duel2Ptr);

            return(true);
        }
Exemple #6
0
        private UInt32 FindNextPtr(IMAGE_SECTION_HEADER sec, byte[] data, UInt32 search, UInt32 y)
        {
            byte[] b = BitConverter.GetBytes(search);

            /* If we're resuming, then don't look at the same position. */
            if (y != 0)
            {
                ++y;
            }

            for (; y < sec.virtSz - 4; ++y)
            {
                if (memEqual(data, b, 4, (int)y, 0))
                {
                    return(y);
                }
            }

            return(UInt32.MaxValue);
        }
Exemple #7
0
        private UInt32 WriteSingleMap(IMAGE_SECTION_HEADER sec, byte[] data,
                                      string mapbase, string map, UInt32 start, UInt32 mapptr)
        {
            /* Now, find the map tables... */
            UInt32 acave01_00_loc = FindString(sec, data, Encoding.ASCII.GetBytes(map));
            UInt32 acave01_loc    = FindString(sec, data, Encoding.ASCII.GetBytes(mapbase));
            UInt32 acave01_00_ptr = FindPtr(sec, data, acave01_00_loc);

            /* The acave01_00_ptr should point at the middle of the first entry for ult maps
             * for the specified area. */
            UInt32 acave01_ptr_ptr = FindPtr(sec, data, acave01_00_ptr - 4);
            /* acave01_ptr_ptr should point at the first thing we'll have to change now. */
            int bytesWritten;

            byte[] tmp;

            if (!ReadProcessMemory(acave01_00_ptr - 4, 40, out tmp, out bytesWritten) ||
                bytesWritten != 40)
            {
                return(UInt32.MaxValue);
            }

            WriteUInt32(acave01_ptr_ptr, start);
            WriteUInt32(acave01_ptr_ptr + 4, 6);

            if (!WriteProcessMemory(start, 40, tmp, out bytesWritten) ||
                bytesWritten != 40)
            {
                return(UInt32.MaxValue);
            }

            start += 40;
            WriteUInt32(start, acave01_loc);
            WriteUInt32(start + 4, (uint)mapptr);
            start += 8;

            return(start);
        }
Exemple #8
0
        private bool PerformMapfix(IMAGE_SECTION_HEADER sec, byte[] data)
        {
            const string acave01_05    = "map_acave01_05";      // 15
            const string acave03_05    = "map_acave03_05";      // 15
            const string amachine01_05 = "map_amachine01_05";   // 18
            const string amachine02_05 = "map_amachine02_05";   // 18
            int          bytesWritten;
            uint         loc = 0, loc2;

            /* First, allocate enough space for the strings... */
            IntPtr mapptr = Kernel32.VirtualAllocEx(proc.Handle, IntPtr.Zero, 512, Kernel32.MEM_COMMIT, Kernel32.PAGE_READWRITE);

            if (mapptr == IntPtr.Zero)
            {
                return(false);
            }

            /* Write the map strings into the process' heap. */
            if (!WriteProcessMemory((uint)mapptr, 15, Encoding.ASCII.GetBytes(acave01_05), out bytesWritten) ||
                bytesWritten != 15)
            {
                return(false);
            }

            loc += (uint)bytesWritten;

            if (!WriteProcessMemory(((uint)mapptr) + loc, 15, Encoding.ASCII.GetBytes(acave03_05), out bytesWritten) ||
                bytesWritten != 15)
            {
                return(false);
            }

            loc += (uint)bytesWritten;

            if (!WriteProcessMemory(((uint)mapptr) + loc, 18, Encoding.ASCII.GetBytes(amachine01_05), out bytesWritten) ||
                bytesWritten != 18)
            {
                return(false);
            }

            loc += (uint)bytesWritten;

            if (!WriteProcessMemory(((uint)mapptr) + loc, 18, Encoding.ASCII.GetBytes(amachine02_05), out bytesWritten) ||
                bytesWritten != 18)
            {
                return(false);
            }

            loc += (uint)bytesWritten;

            loc2 = WriteSingleMap(sec, data, "map_acave01", "map_acave01_00", ((uint)mapptr) + loc, (uint)mapptr);
            if (loc2 == UInt32.MaxValue)
            {
                return(false);
            }

            loc2 = WriteSingleMap(sec, data, "map_acave03", "map_acave03_00", loc2, ((uint)mapptr) + 15);
            if (loc2 == UInt32.MaxValue)
            {
                return(false);
            }

            loc2 = WriteSingleMap(sec, data, "map_amachine01", "map_amachine01_00", loc2, ((uint)mapptr) + 30);
            if (loc2 == UInt32.MaxValue)
            {
                return(false);
            }

            loc2 = WriteSingleMap(sec, data, "map_amachine02", "map_amachine02_00", loc2, ((uint)mapptr) + 48);
            if (loc2 == UInt32.MaxValue)
            {
                return(false);
            }

            return(true);
        }