【发布时间】:2015-07-12 06:02:42
【问题描述】:
我是这里的新手。而且我没有任何编码经验。我被困在我项目的编码部分。我在 Visual Studio 的 C# 中完成了它
我想在作为源代码的另一个字符串打开的文件中搜索文本框中键入的字符串。我想在源代码中的“$_POST”这个词前面的 20 个字符之前检查输入的字符串是否存在。如果字符串存在,打印一些东西。我已经附上了代码,直到我完成为止。请帮助我。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace XSS_Prevention_Tool
{
public partial class Home : Form
{
int count = 0,lc=0;
string language;
public Home()
{
InitializeComponent();
}
private void Home_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
languageSelection();
folderBrowserDialog1.ShowDialog();
txtpath.Text= folderBrowserDialog1.SelectedPath.ToString();
ColumnHeader header1 = new ColumnHeader();
header1.Text = " Scanning: ";
header1.Width = listFiles.ClientSize.Width;
listFiles.Columns.Add(header1);
DirSearch(folderBrowserDialog1.SelectedPath.ToString());
}
private void languageSelection()
{
if (rdoASP.Checked == true)
{
language = "asp";
}
else if (rdoJSP.Checked == true)
language = "jsp";
else if (rdoPHP.Checked == true)
language = "php";
else
MessageBox.Show("Select a language");
lblLanguage.Text = language;
textBox2.Visible = true;
}
public void DirSearch(string dir)
{
try
{
foreach (string f in Directory.GetFiles(dir))
{
string e = Path.GetExtension(f);
if (e == "."+language)
{
listFiles.Items.Add(f);
lc++;
textBox2.Text = lc.ToString();
XSS(f);
}
count++;
textBox1.Text = count.ToString();
}
foreach (string d in Directory.GetDirectories(dir))
{
DirSearch(d);
}
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void XSS(string f)
{
String methode = "$_POST";
System.IO.StreamReader myFile = new System.IO.StreamReader(f);
string myString = myFile.ReadToEnd();
myFile.Close();
if (myString.Contains(methode))
{
int pos = myString.IndexOf(methode);
MessageBox.Show(pos.ToString());
}
}
private void label2_Click(object sender, EventArgs e)
{
}
private void listFiles_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void txtpath_TextChanged(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
}
}
}
【问题讨论】:
-
目前还不清楚您的问题到底是关于什么的。你看到了什么错误?
-
你的代码能编译吗?如果没有,报告什么错误?它运行吗?如果没有,会抛出什么异常,或者表现出什么其他意外行为?结果不正确吗?如果有,预期结果是什么,实际结果是什么?
-
Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers 和 Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking.)
-
对不起,我是新来的。我只是想知道那里有任何解决方案。此代码有效,但需要更多编码。那是我问的。从文本框中获取值并搜索它
标签: c# string visual-studio search substring