Esempio n. 1
0
        private void GenerateCPPCode()
        {
            if (_strCurrent == "" || txtExported.Text == "")
            {
                DialogResult dResult = MessageBox.Show(this, "You have not opened an executable file.  Would you like to now?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                if (dResult == DialogResult.Yes)
                    openToolStripMenuItem_Click(this, EventArgs.Empty);

                return;
            }

            /*
             * Prompt for a filename.
             */
            frmName frmPromptFile = new frmName();
            frmPromptFile.ShowDialog(this);

            if (frmPromptFile.FileName == "")
                return;
            else if (!txtExported.Text.Contains(STARTSTRNG))
            {
                MessageBox.Show(this, "The selected file does not export any functions.  Are you missing a definition file?", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            string strBuffer;
            string[] strSplit;
            int intStart = txtExported.Text.IndexOf(STARTSTRNG);
            int intFinish = txtExported.Text.LastIndexOf(STOPSTRING);

            //Clear existing content.
            txtCode.Text = "";

            //Get a substing.
            strBuffer = txtExported.Text.Substring(intStart + STARTSTRNG.Length, intFinish - (intStart + STARTSTRNG.Length)).Replace(Environment.NewLine, "\n");

            /*
             * Generate the file header.
             */
            txtCode.Text = "#include \"stdafx.h\"";
            txtCode.Text += Environment.NewLine;
            txtCode.Text += "#include <iostream>";
            txtCode.Text += Environment.NewLine;
            txtCode.Text += "#include <windows.h>";
            txtCode.Text += Environment.NewLine;
            txtCode.Text += Environment.NewLine;
            txtCode.Text += "using namespace std;";
            txtCode.Text += Environment.NewLine;

            //Split the text into an array seperated by lines.
            strSplit = strBuffer.Split('\n');

            /*
             * Generate each exports statement.
             */
            for (int i = 0; i < strSplit.Length; i++)
            {
                if (strSplit[i].Trim() != "")
                {
                    //Strip all multi-space spaces.
                    while (strSplit[i].Contains("  "))
                        strSplit[i] = strSplit[i].Replace("  ", " ");

                    string[] strPart = strSplit[i].Trim().Split(' ');

                    if (strPart.Length == 4)
                    {
                        txtCode.Text += Environment.NewLine;
                        txtCode.Text += "#pragma comment (linker, \"/export:" + strPart[3] + "=";
                        txtCode.Text += frmPromptFile.FileName.ToLower().Replace(".dll", "") + ".";
                        txtCode.Text += strPart[3] + ",@" + strPart[0] + "\")";
                    }
                    else
                    {
                        txtCode.Text += Environment.NewLine;
                        txtCode.Text += "#pragma comment (linker, \"/export:" + strPart[2] + "=";
                        txtCode.Text += frmPromptFile.FileName.ToLower().Replace(".dll", "") + ".";
                        txtCode.Text += strPart[2] + ",@" + strPart[0] + "\")";
                    }
                }
            }

            /*
             * Generate entry point function.
             */
            txtCode.Text += Environment.NewLine;
            txtCode.Text += Environment.NewLine + "BOOL WINAPI DllMain(HINSTANCE hInst,DWORD reason,LPVOID)";
            txtCode.Text += Environment.NewLine + "{";
            txtCode.Text += Environment.NewLine + "\treturn true;";
            txtCode.Text += Environment.NewLine + "}";
        }
Esempio n. 2
0
        private void GenerateCPPCode()
        {
            if (_strCurrent == "" || txtExported.Text == "")
            {
                DialogResult dResult = MessageBox.Show(this, "You have not opened an executable file.  Would you like to now?", this.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

                if (dResult == DialogResult.Yes)
                {
                    openToolStripMenuItem_Click(this, EventArgs.Empty);
                }

                return;
            }

            /*
             * Prompt for a filename.
             */
            frmName frmPromptFile = new frmName();

            frmPromptFile.ShowDialog(this);

            if (frmPromptFile.FileName == "")
            {
                return;
            }
            else if (!txtExported.Text.Contains(STARTSTRNG))
            {
                MessageBox.Show(this, "The selected file does not export any functions.  Are you missing a definition file?", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            string strBuffer;

            string[] strSplit;
            int      intStart  = txtExported.Text.IndexOf(STARTSTRNG);
            int      intFinish = txtExported.Text.LastIndexOf(STOPSTRING);

            //Clear existing content.
            txtCode.Text = "";

            //Get a substing.
            strBuffer = txtExported.Text.Substring(intStart + STARTSTRNG.Length, intFinish - (intStart + STARTSTRNG.Length)).Replace(Environment.NewLine, "\n");

            /*
             * Generate the file header.
             */
            txtCode.Text  = "#include \"stdafx.h\"";
            txtCode.Text += Environment.NewLine;
            txtCode.Text += "#include <iostream>";
            txtCode.Text += Environment.NewLine;
            txtCode.Text += "#include <windows.h>";
            txtCode.Text += Environment.NewLine;
            txtCode.Text += Environment.NewLine;
            txtCode.Text += "using namespace std;";
            txtCode.Text += Environment.NewLine;

            //Split the text into an array seperated by lines.
            strSplit = strBuffer.Split('\n');

            /*
             * Generate each exports statement.
             */
            for (int i = 0; i < strSplit.Length; i++)
            {
                if (strSplit[i].Trim() != "")
                {
                    //Strip all multi-space spaces.
                    while (strSplit[i].Contains("  "))
                    {
                        strSplit[i] = strSplit[i].Replace("  ", " ");
                    }

                    string[] strPart = strSplit[i].Trim().Split(' ');

                    if (strPart.Length == 4)
                    {
                        txtCode.Text += Environment.NewLine;
                        txtCode.Text += "#pragma comment (linker, \"/export:" + strPart[3] + "=";
                        txtCode.Text += frmPromptFile.FileName.ToLower().Replace(".dll", "") + ".";
                        txtCode.Text += strPart[3] + ",@" + strPart[0] + "\")";
                    }
                    else
                    {
                        txtCode.Text += Environment.NewLine;
                        txtCode.Text += "#pragma comment (linker, \"/export:" + strPart[2] + "=";
                        txtCode.Text += frmPromptFile.FileName.ToLower().Replace(".dll", "") + ".";
                        txtCode.Text += strPart[2] + ",@" + strPart[0] + "\")";
                    }
                }
            }

            /*
             * Generate entry point function.
             */
            txtCode.Text += Environment.NewLine;
            txtCode.Text += Environment.NewLine + "BOOL WINAPI DllMain(HINSTANCE hInst,DWORD reason,LPVOID)";
            txtCode.Text += Environment.NewLine + "{";
            txtCode.Text += Environment.NewLine + "\treturn true;";
            txtCode.Text += Environment.NewLine + "}";
        }