分类:
2008-10-13 16:10:52
using System;
using System.IO;
using NAnt.Core;
using NAnt.Core.Tasks;
using NAnt.Core.Attributes;
namespace Nant.Diviner
{
///
/// Bin2H 的摘要说明。
///
///
[TaskName("RubbishData")]
public class RubbishDataTask : Task
{
private FileInfo _dataFilename;
[TaskAttribute("datafile", Required=true)]
public FileInfo DataFilename
{
get { return _dataFilename; }
set { _dataFilename = value; }
}
//data区的填充大小
private int _datalenmin;
[TaskAttribute("datalenmin", Required=true)]
public int DataLenMin
{
get { return _datalenmin; }
set { _datalenmin = value; }
}
private int _datalenmax;
[TaskAttribute("datalenmax", Required=true)]
public int DataLenMax
{
get { return _datalenmax; }
set { _datalenmax = value; }
}
//rdata区的填充大小
private int _rdatalenmin;
[TaskAttribute("rdatalenmin", Required=true)]
public int RDataLenMin
{
get { return _rdatalenmin; }
set { _rdatalenmin = value; }
}
private int _rdatalenmax;
[TaskAttribute("rdatalenmax", Required=true)]
public int RDataLenMax
{
get { return _rdatalenmax; }
set { _rdatalenmax = value; }
}
//text段的填充大小
private int _textlenmin;
[TaskAttribute("textlenmin", Required=true)]
public int TextLenMin
{
get { return _textlenmin; }
set { _textlenmin = value; }
}
private int _textlenmax;
[TaskAttribute("textlenmax", Required=true)]
public int TextLenMax
{
get { return _textlenmax; }
set { _textlenmax = value; }
}
protected override void ExecuteTask()
{
StreamWriter sw = new StreamWriter(DataFilename.FullName,false);
int count=0;
//开始写data区段
int datalen=_datalenmin+Common.GetRandIntExt(_datalenmax-_datalenmin);
sw.WriteLine("#pragma data_seg(\".data\")");
sw.WriteLine("unsigned char rubbish_Data[]=");
sw.WriteLine("{");
for(int i=0;i
if(count==0)
sw.Write("\t");
byte bb=(byte)Common.GetRandIntExt(255);
sw.Write(string.Format("0x{0:x2},", bb));
count++;
if(count==16)
{
sw.WriteLine();
count=0;
}
}
if(count!=0)
sw.WriteLine();
sw.WriteLine("};");
sw.WriteLine();
//开始写rdata区段
count=0;
int rdatalen=_rdatalenmin+Common.GetRandIntExt(_rdatalenmax-_rdatalenmin);
sw.WriteLine("#pragma data_seg(\".rdata\")");
sw.WriteLine("unsigned char rubbish_RData[]=");
sw.WriteLine("{");
for(int i=0;i
if(count==0)
sw.Write("\t");
byte bb=(byte)Common.GetRandIntExt(255);
sw.Write(string.Format("0x{0:x2},", bb));
count++;
if(count==16)
{
sw.WriteLine();
count=0;
}
}
if(count!=0)
sw.WriteLine();
sw.WriteLine("};");
sw.WriteLine();
//开始写text区段
count=0;
int textlen=_textlenmin+Common.GetRandIntExt(_textlenmin-_textlenmin);
sw.WriteLine("#pragma data_seg(\".text\")");
sw.WriteLine("unsigned char rubbish_Text[]=");
sw.WriteLine("{");
for(int i=0;i
if(count==0)
sw.Write("\t");
byte bb=(byte)Common.GetRandIntExt(255);
sw.Write(string.Format("0x{0:x2},", bb));
count++;
if(count==16)
{
sw.WriteLine();
count=0;
}
}
if(count!=0)
sw.WriteLine();
sw.WriteLine("};");
sw.WriteLine();
sw.Flush();
sw.Close();
Log(Level.Info, "datafile is \"{0}\"",_dataFilename.FullName);
}
}
}