【发布时间】:2016-04-27 18:04:07
【问题描述】:
我遇到了一件很奇怪的事情。我用 C# 编写了一个非常简单的程序,并尝试构建它的 32 位和 64 位版本。 64 位版本运行良好,但每当我尝试构建 32 位版本时,我的防病毒软件都会将其删除。我已将这两个文件上传到 virustotal:
为什么?它的代码完全相同,唯一的区别是我在构建之前在 x64 和 x86 之间切换。
【问题讨论】:
标签: c# visual-studio x86 malware antivirus
我遇到了一件很奇怪的事情。我用 C# 编写了一个非常简单的程序,并尝试构建它的 32 位和 64 位版本。 64 位版本运行良好,但每当我尝试构建 32 位版本时,我的防病毒软件都会将其删除。我已将这两个文件上传到 virustotal:
为什么?它的代码完全相同,唯一的区别是我在构建之前在 x64 和 x86 之间切换。
【问题讨论】:
标签: c# visual-studio x86 malware antivirus
从代码中删除 P/Invokes 后,您可以将项目设置为 AnyCPU。这样您就不需要 x86 和 x64 构建。
我在您的项目中没有看到任何看起来不正常的东西,除了使用以下几行:
[DllImport("psapi.dll")]
static extern int EmptyWorkingSet(IntPtr hwProc);
static void MinimizeFootprint()
{
EmptyWorkingSet(System.Diagnostics.Process.GetCurrentProcess().Handle);
}
...
GC.Collect();
MinimizeFootprint();
考虑到您的小型应用程序,确实不需要手动调用垃圾收集器并调整工作集。 There are known issues with using it.
当你用完它们后,只需清理你的画笔:
private void DrawResistor(PaintEventArgs e)
{
Graphics g = e.Graphics;
SolidBrush brs;
//Første farve
g.DrawLine(Pens.Black, 130, 35, 130, 109);
g.DrawLine(Pens.Black, 140, 35, 140, 109);
using (brs = new SolidBrush(this.Controls.Find(Farver[0], false)[0].BackColor))
{
g.FillRectangle(brs, 131, 35, 9, 75);
}
//Anden farve
g.DrawLine(Pens.Black, 160, 44, 160, 100);
g.DrawLine(Pens.Black, 170, 44, 170, 100);
using (brs = new SolidBrush(this.Controls.Find(Farver[1], false)[0].BackColor))
{
g.FillRectangle(brs, 161, 44, 9, 56);
}
//Tredje farve
if (comboBox1.SelectedIndex != 0)
{
g.DrawLine(Pens.Black, 190, 44, 190, 100);
g.DrawLine(Pens.Black, 200, 44, 200, 100);
using (brs = new SolidBrush(this.Controls.Find(Farver[2], false)[0].BackColor))
{
g.FillRectangle(brs, 191, 44, 9, 56);
}
}
//Fjerde farve
g.DrawLine(Pens.Black, 220, 44, 220, 100);
g.DrawLine(Pens.Black, 230, 44, 230, 100);
using (brs = new SolidBrush(this.Controls.Find(Farver[3], false)[0].BackColor))
{
g.FillRectangle(brs, 221, 44, 9, 56);
}
//Femte farve
g.DrawLine(Pens.Black, 265, 35, 265, 109);
g.DrawLine(Pens.Black, 280, 35, 280, 109);
using (brs = new SolidBrush(this.Controls.Find(Farver[4], false)[0].BackColor))
{
g.FillRectangle(brs, 266, 35, 14, 75);
}
//Sjette farve
if (comboBox1.SelectedIndex == 2)
{
g.DrawLine(Pens.Black, 293, 35, 293, 109);
g.DrawLine(Pens.Black, 303, 35, 303, 109);
using (brs = new SolidBrush(this.Controls.Find(Farver[5], false)[0].BackColor))
{
g.FillRectangle(brs, 294, 35, 9, 75);
}
}
}
【讨论】: