示例#1
0
 private void showError(id_log log)
 {
     if (log == id_log.Verbose || log == id_log.onError)
     {
         writeReport(InstructionSet.errorString);
     }
 }
示例#2
0
        private void wait(int millisecond, id_log log)

        {
            if (log == id_log.Verbose)
            {
                writeReport("Sleep " + ((float)millisecond / 1000).ToString() + " second(s)");
            }
            Thread.Sleep(millisecond);
        }
示例#3
0
        private bool VerifyAndPatch(Pointer p, string offset, string byteOrig, string bytePatch, id_log log)
        {
            // indirizzamento offset assoluto 0x834234
            if (log == id_log.Verbose)
            {
                writeReport("Patching Memory");
            }
            bool flag = false;
            int  size = (byteOrig.Length + 1) / 3;

            byte[]  first   = new byte[size];
            byte[]  second  = patch.string2Byte(byteOrig);
            byte[]  buffer1 = patch.string2Byte(bytePatch);
            Pointer pointer = p;

            byte[] buffer2 = first;
            int    length  = buffer2.Length;
            IntPtr iptr    = (IntPtr)Convert.ToInt32(offset, 16);

            pointer.ReadMemory(iptr, buffer2, length);
            if (patch.compareArray(first, second) && patch.compareArray(first, second))
            {
                p.WriteMemory(iptr, buffer1, size);
                flag = true;
                for (int i = 0; i < first.Length; i++)
                {
                    unsafe
                    {
                        if (log == id_log.Verbose)
                        {
                            writeReport(" " + toHex((int)iptr.ToPointer() + i) + " = " + toHex(first[i]) + " -> " + toHex(buffer1[i]));
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < first.Length; i++)
                {
                    unsafe
                    {
                        if (log == id_log.Verbose || log == id_log.onError)
                        {
                            writeReport(" " + toHex((int)iptr.ToPointer() + i) + " expected: " + toHex(second[i]) + " found: " + toHex(first[i]));
                        }
                    }
                    if (log == id_log.Verbose || log == id_log.onError)
                    {
                        writeReport("Alert - Byte mismatch - Ignore command");
                    }
                }
            }
            return(flag);
        }
示例#4
0
        //private bool VerifyAndPatch(Pointer p, string offset, string byteOrig, string bytePatch, id_log log)
        //{
        //    // indirizzamento offset CheatEngine style  "\"mz004\"+4BD2B"
        //    bool flag = false;
        //    IntPtr address1 = p.GetAddress(offset);
        //    int size = (byteOrig.Length + 1) / 3;
        //    byte[] first = new byte[size];
        //    byte[] second = patch.string2Byte(byteOrig);
        //    byte[] buffer1 = patch.string2Byte(bytePatch);
        //    Pointer pointer = p;
        //    IntPtr address2 = address1;
        //    byte[] buffer2 = first;
        //    int length = buffer2.Length;
        //    pointer.ReadMemory(address2, buffer2, length);
        //    if (patch.compareArray(first, second) && patch.compareArray(first, second))
        //    {
        //        p.WriteMemory(address1, buffer1, size);
        //        flag = true;
        //    }
        //    return flag;
        //}

        private bool VerifyAndWrite(FileStream fs, int offset, string byteOrig, string bytePatch, id_log log)
        {
            if (log == id_log.Verbose)
            {
                writeReport("Check match byte");
            }
            bool flag = false;
            int  size = (byteOrig.Length + 1) / 3;

            byte[] first   = new byte[size];
            byte[] second  = patch.string2Byte(byteOrig);
            byte[] buffer1 = patch.string2Byte(bytePatch);
            byte[] buffer2 = first;
            int    length  = buffer2.Length;

            fs.Position = offset;
            fs.Read(buffer2, 0, length);
            if (patch.compareArray(first, second) && patch.compareArray(first, second))
            {
                fs.Position = offset;
                fs.Write(buffer1, 0, size);
                flag = true;
                for (int i = 0; i < first.Length; i++)
                {
                    if (log == id_log.Verbose)
                    {
                        writeReport(" " + toHex((int)offset + i) + " = " + toHex(first[i]) + " -> " + toHex(buffer1[i]));
                    }
                }
            }
            else
            {
                for (int i = 0; i < first.Length; i++)
                {
                    if (log == id_log.Verbose || log == id_log.onError)
                    {
                        writeReport(" " + toHex(offset + i) + " expected: " + toHex(second[i]) + " found: " + toHex(first[i]));
                    }
                }
                if (log == id_log.Verbose || log == id_log.onError)
                {
                    writeReport("Alert - Byte mismatch - Ignore command");
                }
            }
            return(flag);
        }
示例#5
0
        private Process loadProcess(string applicationPath, string applicationArguments, id_log log)
        {
            if (log == id_log.Verbose)
            {
                writeReport("Load Process");
                writeReport(" Application Path: " + applicationPath);
                if (applicationArguments != "")
                {
                    writeReport(" Arguments: " + applicationArguments);
                }
            }
            Process p = null;
            // render

            ProcessStartInfo startInfo = new ProcessStartInfo();

            startInfo.FileName  = applicationPath;
            startInfo.Arguments = applicationArguments;
            p = Process.Start(startInfo);
            if (log == id_log.Verbose)
            {
                writeReport(" PID: " + p.Id.ToString() + " (" + toHex(p.Id) + ")");
                writeReport(" Process name: " + p.ProcessName);
                writeReport(" Main window title: " + p.MainWindowTitle);
            }
            return(p);
        }
示例#6
0
        private String Verify(string applicationPath, long applicationLen, string sha256, id_log log)
        {
            if (log == id_log.Verbose)
            {
                writeReport("Verify file");
                writeReport(" Application Path: " + applicationPath);
                writeReport(" Length: " + applicationLen);
                writeReport(" SHA265: " + sha256);
            }
            // render
            string[] sPath = applicationPath.Split('%');
            if (sPath.Length == 3)
            {
                string programFiles = Environment.ExpandEnvironmentVariables("%" + sPath[1] + "%");
                applicationPath = programFiles + sPath[2];
                if (log == id_log.Verbose)
                {
                    writeReport(" Resolve path: " + applicationPath);
                }
            }
            // verify path and Length
            if (File.Exists(applicationPath))
            {
                if (log == id_log.Verbose)
                {
                    writeReport(" FIle exist");
                }
                FileInfo f = new FileInfo(applicationPath);
                if (f.Length == applicationLen)
                {
                    if (log == id_log.Verbose)
                    {
                        writeReport(" Length correct");
                    }
                    string hash = GetChecksum(applicationPath);
                    if (hash == sha256)
                    {
                        if (log == id_log.Verbose)
                        {
                            writeReport(" SHA256 correct");
                            writeReport(" File is matched");
                        }
                    }
                    else
                    {
                        if (log == id_log.Verbose || log == id_log.onError)
                        {
                            writeReport("ERROR - Wrong SHA256 hash: expected " + sha256 + " found " + hash);
                            applicationPath = "";
                        }
                    }
                }
                else
                {
                    if (log == id_log.Verbose || log == id_log.onError)
                    {
                        writeReport("ERROR - Wrong executable lenght: expected " + applicationLen.ToString() + " found " + f.Length);
                        applicationPath = "";
                    }
                }
            }
            else
            {
                if (log == id_log.Verbose || log == id_log.onError)
                {
                    writeReport("ERROR - Path not exist");
                    applicationPath = "";
                }
            }

            return(applicationPath);
        }
示例#7
0
        private Boolean RegistryDeleteValue(string keyRoot, string keyName, string keyValue, id_log log)
        {
            Boolean isDone = true;

            if (log == id_log.Verbose)
            {
                writeReport("Delete Registry Value");
                writeReport(" Root Registry Key: " + keyRoot);
                writeReport(" Registry Key: " + keyName);
                writeReport(" Registry Value: " + keyValue);
            }
            RegistryKey r = null;

            if (keyRoot == "CU")
            {
                r = Registry.CurrentUser;
            }
            if (keyRoot == "LM")
            {
                r = Registry.LocalMachine;
            }
            try
            {
                using (RegistryKey key = r.OpenSubKey(keyName, true))
                    if (key != null)
                    {
                        key.DeleteValue(keyValue);
                        if (log == id_log.Verbose)
                        {
                            writeReport("Done");
                        }
                    }
                    else
                    {
                        if (log == id_log.Verbose || log == id_log.onError)
                        {
                            writeReport("ALERT - Value not exist. Ignore command");
                        }
                    }
            }
            catch (Exception ex)
            {
                if (log == id_log.Verbose || log == id_log.onError)
                {
                    writeReport("ERROR - " + ex.Message);
                }
                isDone = false;
            }
            return(isDone);
        }
示例#8
0
        private void parse(int idPatch)
        {
            // verify is the process run in admin mode
            if (mypatch[idPatch].admin)
            {
                if (!IsRunAsAdmin())
                {
                    goadmin ga = new goadmin();
                    ga.title = mypatch[idPatch].title;
                    ga.ShowDialog();
                    if (ga.isAccept)
                    {
                        ProcessStartInfo proc = new ProcessStartInfo();
                        proc.UseShellExecute  = true;
                        proc.WorkingDirectory = Environment.CurrentDirectory;
                        proc.FileName         = Assembly.GetEntryAssembly().CodeBase;

                        proc.Verb = "runas";
                        Process.Start(proc);
                        Application.Exit();
                    }
                    else
                    {
                        writeReport("HALT - This script run only in Admin mode");
                        return;
                    }
                }
            }
            id_log log = mypatch[idPatch].log;

            if (log == id_log.Verbose)
            {
                writeReport("Begin title:");
            }
            string banner = "*** " + mypatch[idPatch].title + " ***";

            if (mypatch[idPatch].author.Length > mypatch[idPatch].title.Length)
            {
                mypatch[idPatch].author = mypatch[idPatch].author.Substring(0, mypatch[idPatch].title.Length);
            }
            writeReport(string.Concat(Enumerable.Repeat("*", banner.Length)));
            writeReport(banner);
            writeReport("***" + string.Concat(Enumerable.Repeat(" ", banner.Length - 10 - mypatch[idPatch].author.Length)) + "by " + mypatch[idPatch].author + " ***");
            writeReport(string.Concat(Enumerable.Repeat("*", banner.Length)));
            //String applicationArguments = mypatch[idPatch].arguments;
            //string sha256 = mypatch[idPatch].sha256;
            //long applicationLen = mypatch[idPatch].length;
            Process    process = null;
            Pointer    p       = null;
            string     path    = "";
            FileStream fs      = null;

            for (int i = 0; i < mypatch[idPatch].istruction.Count; i++)
            {
                if (log == id_log.Verbose)
                {
                    writeReport("Step" + (i + 1).ToString());
                }
                string[] my_istr = mypatch[idPatch].istruction[i].Split('"');
                switch (mypatch[idPatch].idIstruction[i])
                {
                //                   pause = 1,
                //openfile,
                //closefile,
                //writefile,
                case id_instruction.openfile:
                    if (path != "")
                    {
                        if (log == id_log.Verbose)
                        {
                            writeReport("Opening file: " + path);
                        }
                        if (my_istr[1].ToLower() != "false")
                        {
                            string backfile = path + ".bak";
                            if (!File.Exists(backfile))
                            {
                                if (log == id_log.Verbose)
                                {
                                    writeReport("Make copy backup: " + backfile);
                                }
                                File.Copy(path, backfile);
                                //    if (log == id_log.Verbose)
                                //        writeReport("Delete old backup " + backfile);
                                //    File.Delete(backfile);
                            }
                        }
                        fs = new FileStream(path, FileMode.Open, FileAccess.ReadWrite);
                    }
                    else
                    {
                        if (log == id_log.Verbose || log == id_log.onError)
                        {
                            writeReport("HALT - File not exist");
                            fs = null;
                        }
                        return;
                    }
                    break;

                case id_instruction.writefile:
                    if (path != "" && fs != null)
                    {
                        VerifyAndWrite(fs, Convert.ToInt32(my_istr[1], 16), my_istr[3], my_istr[5], log);
                    }
                    else
                    {
                        if (log == id_log.Verbose || log == id_log.onError)
                        {
                            writeReport("HALT - File not exist or File not open");
                            path = "";
                            fs   = null;
                        }
                    }
                    break;

                case id_instruction.closefile:
                    if (log == id_log.Verbose)
                    {
                        writeReport("Close File");
                        fs = null;
                    }
                    break;

                case id_instruction.pause:
                    string caption = "Press any key to contunue";
                    if (my_istr[1] != "")
                    {
                        caption = my_istr[1];
                    }
                    writeReport(caption);
                    isKeyPressed = false;
                    button1.Show();
                    while (!isKeyPressed)
                    {
                        Application.DoEvents();
                    }

                    button1.Hide();
                    break;

                case id_instruction.explore:
                    InstructionSet.Explore("jj");

                    if (InstructionSet.error)
                    {
                        showError(log);
                    }
                    break;

                case id_instruction.messagebox:
                    if (log == id_log.Verbose)
                    {
                        writeReport("Show MessageBox");
                    }
                    message_box mb = new message_box();
                    mb.title         = mypatch[idPatch].title;
                    mb.textBox2.Text = my_istr[1].Replace("<NEWLINE>", Environment.NewLine);
                    mb.textBox1.Text = my_istr[3].Replace("<NEWLINE>", Environment.NewLine);
                    mb.ShowDialog();
                    break;

                case id_instruction.regdeletevalue:
                    string keyRoot  = my_istr[1];
                    string keyName  = my_istr[3];
                    string keyValue = my_istr[5];
                    RegistryDeleteValue(keyRoot, keyName, keyValue, log);
                    break;

                case id_instruction.verify:
                    path = Verify(my_istr[1], Convert.ToInt64(my_istr[3]), my_istr[5], log);
                    break;

                case id_instruction.exec:
                    if (path != "")
                    {
                        process = loadProcess(path, my_istr[1], log);
                        if (process == null)
                        {
                            if (log == id_log.Verbose || log == id_log.onError)
                            {
                                writeReport("HALT - handle process is invalid");
                            }
                            return;
                        }
                        p = new Pointer(process);
                    }
                    else
                    {
                        if (log == id_log.Verbose || log == id_log.onError)
                        {
                            writeReport("The file is not found or different");
                        }
                        return;
                    }

                    break;

                case id_instruction.wait:
                    wait(Convert.ToInt32(my_istr[1]), log);
                    break;

                case id_instruction.patch:
                    VerifyAndPatch(p, my_istr[1], my_istr[3], my_istr[5], log);
                    break;

                case id_instruction.print:
                    writeReport("*** " + my_istr[1] + " ***");
                    break;

                case id_instruction.exit:
                    if (log == id_log.Verbose)
                    {
                        writeReport("EXIT - Closing PatchManager");
                    }
                    Application.Exit();
                    break;
                }
            }
            if (log == id_log.Verbose)
            {
                writeReport("End patching");
            }
        }