From: <Or...@us...> - 2008-09-20 15:23:46
|
Revision: 357 http://acmcontester.svn.sourceforge.net/acmcontester/?rev=357&view=rev Author: Oracle_ Date: 2008-09-20 15:23:38 +0000 (Sat, 20 Sep 2008) Log Message: ----------- Added SEH, applied some changes to Details, fixed small bug with SecureType::SysCall. Modified Paths: -------------- ACMServer/trunk/sharp tester/SourceTest 2.0/Load/LoaderClass.cs ACMServer/trunk/sharp tester/SourceTest 2.0/Main/TestEnvClass.cs ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/Program.cs ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/src/source1.txt ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/src/source10.txt ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/src/source17.txt ACMServer/trunk/sharp tester/SourceTest 2.0/Test/CompileClass.cpp ACMServer/trunk/sharp tester/SourceTest 2.0/Test/SecureClass.cpp ACMServer/trunk/sharp tester/SourceTest 2.0/Test/SecureClass.h ACMServer/trunk/sharp tester/SourceTest 2.0/Test/Test.cpp Added Paths: ----------- ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/src/source19.txt ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/src/source20.txt ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/src/source21.txt ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/src/source22.txt ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/src/source23.txt Modified: ACMServer/trunk/sharp tester/SourceTest 2.0/Load/LoaderClass.cs =================================================================== --- ACMServer/trunk/sharp tester/SourceTest 2.0/Load/LoaderClass.cs 2008-09-20 10:03:22 UTC (rev 356) +++ ACMServer/trunk/sharp tester/SourceTest 2.0/Load/LoaderClass.cs 2008-09-20 15:23:38 UTC (rev 357) @@ -37,23 +37,31 @@ while (!f.EndOfStream) { string[] param=f.ReadLine().Split(' '); - switch (param[0]) + if (param.Length < 2) continue; + try { - case "CodeLimit:": CodeLimit = Convert.ToInt32(param[1]); break; - case "CompilationTimeLimit:": CompilationTimeLimit = Convert.ToInt32(param[1]); break; - case "MemoryLimit:": MemoryLimit = Convert.ToInt32(param[1]); break; - case "OutputLimit:": OutputLimit = Convert.ToInt32(param[1]); break; - case "RealTimeLimit:": RealTimeLimit = Convert.ToInt32(param[1]); break; - case "TimeLimit:": TimeLimit = Convert.ToInt32(param[1]); break; - case "MaxThreads:": MaxThreads = Convert.ToInt32(param[1]); break; - case "PerTestCount:": PerTestCount = Convert.ToInt32(param[1]); break; - case "InputName:": InputName = param[1]; break; - case "OutputName:": OutputName = param[1]; break; - case "PointFileName:": PointFileName = param[1]; break; - case "TestFolderName:": TestFolderName = param[1]; break; - case "Checker:": Checker = param[1]; break; - case "CheckPlugin:": CheckPlugin = param[1]; break; + switch (param[0]) + { + case "CodeLimit:": CodeLimit = Convert.ToInt32(param[1]); break; + case "CompilationTimeLimit:": CompilationTimeLimit = Convert.ToInt32(param[1]); break; + case "MemoryLimit:": MemoryLimit = Convert.ToInt32(param[1]); break; + case "OutputLimit:": OutputLimit = Convert.ToInt32(param[1]); break; + case "RealTimeLimit:": RealTimeLimit = Convert.ToInt32(param[1]); break; + case "TimeLimit:": TimeLimit = Convert.ToInt32(param[1]); break; + case "MaxThreads:": MaxThreads = Convert.ToInt32(param[1]); break; + case "PerTestCount:": PerTestCount = Convert.ToInt32(param[1]); break; + case "InputName:": InputName = param[1]; break; + case "OutputName:": OutputName = param[1]; break; + case "PointFileName:": PointFileName = param[1]; break; + case "TestFolderName:": TestFolderName = param[1]; break; + case "Checker:": Checker = param[1]; break; + case "CheckPlugin:": CheckPlugin = param[1]; break; + } } + catch (Exception e) + { + return false; + } } return true; } @@ -90,7 +98,16 @@ output = ""; if (File.Exists(pointname)) - points = Convert.ToInt32(File.OpenText(pointname).ReadToEnd()); + { + try + { + points = Convert.ToInt32(File.OpenText(pointname).ReadToEnd()); + } + catch (Exception e) + { + points = 1; + } + } else points = 1; } Modified: ACMServer/trunk/sharp tester/SourceTest 2.0/Main/TestEnvClass.cs =================================================================== --- ACMServer/trunk/sharp tester/SourceTest 2.0/Main/TestEnvClass.cs 2008-09-20 10:03:22 UTC (rev 356) +++ ACMServer/trunk/sharp tester/SourceTest 2.0/Main/TestEnvClass.cs 2008-09-20 15:23:38 UTC (rev 357) @@ -5,6 +5,18 @@ namespace Main { + public class TesterException : ApplicationException + { + public TesterException(string message) : base(message) { } + public TesterException() : base() { } + } + + public class IncorrectFileException : ApplicationException + { + public IncorrectFileException(string message) : base(message) { } + public IncorrectFileException() : base() { } + } + public class TestEnv { public string ProblemPath; @@ -18,23 +30,78 @@ { this.Source = Source; this.TempPath = Path.GetFullPath(TempPath); + if (!Directory.Exists(this.TempPath)) + Directory.CreateDirectory(this.TempPath); this.CompPath = Path.GetFullPath(CompPath); + if (!File.Exists(this.CompPath)) + throw new FileNotFoundException("Compiler file do not exists!"); this.ProblemPath = Path.GetFullPath(ProblemPath); + if (!Directory.Exists(this.ProblemPath)) + throw new DirectoryNotFoundException("Problem path do not exists!"); } public void Compile() { - DataLoader dat = new DataLoader(ProblemPath + "ProblemData.txt"); - dat.Load(); - string[] InData=System.IO.File.ReadAllLines("TesterInData.txt"); - comp=new Compiler(CompPath,Source,TempPath,dat.CompilationTimeLimit,Convert.ToInt32(InData[0])); + if (comp == null) + { + if (!File.Exists(ProblemPath + "ProblemData.txt")) + throw new FileNotFoundException("ProblemData.txt do not exists"); + DataLoader dat = new DataLoader(ProblemPath + "ProblemData.txt"); + if (!dat.Load()) + throw new IncorrectFileException("Can not load data from ProblemData.txt"); + + if (!File.Exists("TesterInData.txt")) + throw new FileNotFoundException("TesterInData.txt do not exists"); + string[] InData = System.IO.File.ReadAllLines("TesterInData.txt"); + if (InData.Length < 1) + throw new IncorrectFileException("Can not load data from ProblemData.txt"); + int buf; + try + { + buf = Convert.ToInt32(InData[0]); + } + catch (Exception e) + { + throw new IncorrectFileException("Can not load sleep time from TesterInData.txt " + e.Message); + } + + comp = new Compiler(CompPath, Source, TempPath, dat.CompilationTimeLimit, buf); + } comp.Compile(); } - public void RunAllTests(SecureType SecType) + public void RunAllTests() { RunAllTests(SecureType.Double,true); } + public void RunAllTests(SecureType SecType) { RunAllTests(SecType,true); } + + public void RunAllTests(SecureType SecType, bool TestAll) { - run = new Runner(SecType,ProblemPath,comp.ExeFile,TempPath,comp.CONST_SLEEP); + if (run == null) + { + if (comp == null) + throw new TesterException("You should first compile source before running tests!"); + run = new Runner(SecType, ProblemPath, comp.ExeFile, TempPath, comp.CONST_SLEEP); + } + run.TestAll = TestAll; run.RunTests(); } + + public void RunOneTest(int index) { RunOneTest(SecureType.Double,index); } + + public void RunOneTest(SecureType SecType, int index) + { + if (run == null) + { + if (comp == null) + throw new TesterException("You should first compile source before running tests!"); + run = new Runner(SecType, ProblemPath, comp.ExeFile, TempPath, comp.CONST_SLEEP); + } + run.ExecuteTest(index); + } + + public void StopTesting() + { + if (run != null) + run.TerminateThreads(); + } } } Modified: ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/Program.cs =================================================================== --- ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/Program.cs 2008-09-20 10:03:22 UTC (rev 356) +++ ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/Program.cs 2008-09-20 15:23:38 UTC (rev 357) @@ -13,7 +13,7 @@ { Console.SetOut(File.CreateText("D:\\logout.txt")); string[] data=File.ReadAllLines("InData.txt"); - for (int ind = 1; ind <= 18; ind++) + for (int ind = 1; ind <= 1; ind++) { string src = File.ReadAllText("src\\source" + ind.ToString() + ".txt"); TestEnv test = new TestEnv(src, data[0], data[1], data[2]); Modified: ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/src/source1.txt =================================================================== --- ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/src/source1.txt 2008-09-20 10:03:22 UTC (rev 356) +++ ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/src/source1.txt 2008-09-20 15:23:38 UTC (rev 357) @@ -1,4 +1,4 @@ -uses windows; +uses windows,math; var s:string; begin readln(s); Modified: ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/src/source10.txt =================================================================== --- ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/src/source10.txt 2008-09-20 10:03:22 UTC (rev 356) +++ ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/src/source10.txt 2008-09-20 15:23:38 UTC (rev 357) @@ -1,4 +1,19 @@ -uses windows; +program Project2; + +{$APPTYPE CONSOLE} +uses Windows; + +type TMYPROC=procedure (x:Cardinal); stdcall; + +var h:HMODULE; +x:Pointer; begin -Sleep(100000); -end. \ No newline at end of file +h:=LoadLibraryExA('kernel32.dll',0,0); +x:=GetProcAddress(h,'Sleep'); +if (x<>nil) then +begin +TMyPROC(x)(10000000); +end else +writeln('ERROR!!!'); +FreeLibrary(h); +end. Modified: ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/src/source17.txt =================================================================== --- ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/src/source17.txt 2008-09-20 10:03:22 UTC (rev 356) +++ ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/src/source17.txt 2008-09-20 15:23:38 UTC (rev 357) @@ -2,5 +2,5 @@ {$APPTYPE CONSOLE} uses Windows; begin - MessageBox(GetDesktopWindow(),'Hello!','Hello',MB_OK); + MessageBox(0,'Hello!','Hello',MB_OK); end. \ No newline at end of file Added: ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/src/source19.txt =================================================================== --- ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/src/source19.txt (rev 0) +++ ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/src/source19.txt 2008-09-20 15:23:38 UTC (rev 357) @@ -0,0 +1,7 @@ +var a:array [1..10000000] of Integer; +x,y:integer; +begin +fillchar(a,0,sizeof(a)); +read(x,y); +write(x+y); +end. \ No newline at end of file Added: ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/src/source20.txt =================================================================== --- ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/src/source20.txt (rev 0) +++ ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/src/source20.txt 2008-09-20 15:23:38 UTC (rev 357) @@ -0,0 +1,8 @@ +program hello; +var a,b:integer; +ttt:text; +begin +assign(ttt,'ttt.txt'); +read(a,b); +write(a+b); +end. \ No newline at end of file Added: ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/src/source21.txt =================================================================== --- ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/src/source21.txt (rev 0) +++ ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/src/source21.txt 2008-09-20 15:23:38 UTC (rev 357) @@ -0,0 +1,9 @@ +program hello; +var a,b:integer; +ttt:text; +begin + assign(ttt,'ttt.txt'); + rewrite(ttt); + read(a,b); + write(a+b); +end. \ No newline at end of file Added: ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/src/source22.txt =================================================================== --- ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/src/source22.txt (rev 0) +++ ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/src/source22.txt 2008-09-20 15:23:38 UTC (rev 357) @@ -0,0 +1,9 @@ +program hello; +var a,b:integer; +ttt:text; +begin + assign(ttt,'C:\Documents and Settings\Pavlo\Desktop\ttt.txt'); + rewrite(ttt); + read(a,b); + write(a+b); +end. \ No newline at end of file Added: ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/src/source23.txt =================================================================== --- ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/src/source23.txt (rev 0) +++ ACMServer/trunk/sharp tester/SourceTest 2.0/SourceTest 2.0/bin/Debug/src/source23.txt 2008-09-20 15:23:38 UTC (rev 357) @@ -0,0 +1,12 @@ +program hello; +uses windows; +var t:SystemTime; +begin +t.wYear:=1700; +t.wMonth:=2; +t.wDay:=3; +t.wHour:=3; +t.wMinute:=3; +t.wSecond:=3; +SetSystemTime(t); +end. \ No newline at end of file Modified: ACMServer/trunk/sharp tester/SourceTest 2.0/Test/CompileClass.cpp =================================================================== --- ACMServer/trunk/sharp tester/SourceTest 2.0/Test/CompileClass.cpp 2008-09-20 10:03:22 UTC (rev 356) +++ ACMServer/trunk/sharp tester/SourceTest 2.0/Test/CompileClass.cpp 2008-09-20 15:23:38 UTC (rev 357) @@ -24,7 +24,12 @@ if (File::Exists(ExeFile)) //delete previsious source { File::Delete(ExeFile); - System::Threading::Thread::Sleep(CONST_SLEEP); //waiting for file to destroy + for (int i=0;i<CONST_SLEEP;i++) //waiting for file to destroy + { + if (!File::Exists(ExeFile)) + break; + System::Threading::Thread::Sleep(1); + } } si->RedirectStandardOutput=true; Modified: ACMServer/trunk/sharp tester/SourceTest 2.0/Test/SecureClass.cpp =================================================================== --- ACMServer/trunk/sharp tester/SourceTest 2.0/Test/SecureClass.cpp 2008-09-20 10:03:22 UTC (rev 356) +++ ACMServer/trunk/sharp tester/SourceTest 2.0/Test/SecureClass.cpp 2008-09-20 15:23:38 UTC (rev 357) @@ -50,8 +50,16 @@ fwscanf(f,L"%d %s %s",&buf,&USER_NAME,&USER_PASSW); fclose(f); - SetUserObjectFullAccess( GetThreadDesktop(GetCurrentThreadId())); //needed for accessing from CreateProcessAsUser - SetUserObjectFullAccess( GetProcessWindowStation()); //needed for accessing from CreateProcessAsUser + if (!SetUserObjectFullAccess(GetThreadDesktop(GetCurrentThreadId()))) + { + Details="Cannot SetUserObjectFullAccess(GetThreadDesktop(GetCurrentThreadId())). Error#"+ToStr(GetLastError()); + return false; //needed for accessing from CreateProcessAsUser + } + if (!SetUserObjectFullAccess( GetProcessWindowStation())) + { + Details="Cannot SetUserObjectFullAccess( GetProcessWindowStation()). Error#"+ToStr(GetLastError()); + return false; //needed for accessing from CreateProcessAsUser + } USER_INFO_1 ui; NET_API_STATUS st; @@ -69,16 +77,16 @@ if (st==NERR_UserExists) userex=true; else { - Details="Cannot create user."; + Details="Cannot create user. Error#"+ToStr(GetLastError()); return false; } } if (!userex) { array<DriveInfo^>^ drv=DriveInfo::GetDrives(); - for (int i=0;i<drv->Length;i++) //for all drives set limitation - if (drv[i]->DriveType==DriveType::Fixed) - DenyAccessFolder(drv[i]->Name); + for (int i=0;i<drv->Length;i++) //for all fixed drives set limitation + if (drv[i]->DriveType==DriveType::Fixed) + DenyAccessFolder(drv[i]->Name); wchar_t buf[MAX_PATH+1]; GetEnvironmentVariableW(L"ProgramFiles",buf,MAX_PATH); DenyAccessFolder(gcnew String(buf)); @@ -91,9 +99,9 @@ DWORD size=MAX_PATH; GetProfilesDirectory(buf,&size); DenyAccessFolder(gcnew String(buf)); - Details="User created."; + Details="User created. "; } else - Details="User exists."; + Details="User exists. "; return true; } @@ -208,12 +216,11 @@ } vector<TFunc> allowed; char mod_name[256],func_name[256]; -while (fscanf(f,"%s %s",mod_name,func_name)>0) +while (fscanf(f,"%s %s",mod_name,func_name)==2) { TFunc func; func.Name=func_name; func.Module=mod_name; - //func.handle=GetProcAddress(GetModuleHandleA(mod_name), func_name); allowed.push_back(func); } fclose(f); @@ -234,11 +241,12 @@ PIMAGE_THUNK_DATA pThunk = (PIMAGE_THUNK_DATA)((PBYTE) hmodCaller + pImportDesc->FirstThunk); for (; pThunk->u1.Function; pThunk++) { - //PROC* ppfn = (PROC*) &pThunk->u1.Function; + if ((pThunk->u1.Function&(1<<31))!=0) + continue; PSTR NAME=(PSTR)((PIMAGE_IMPORT_BY_NAME)((PBYTE)hmodCaller+pThunk->u1.AddressOfData))->Name; bool allow=false; - for (int i=0;i<allowed.size();i++) + for (unsigned i=0;i<allowed.size();i++) if ((allowed[i].Name==string(NAME))&&(allowed[i].Module==string(pszModName))) { allow=true; @@ -247,7 +255,7 @@ if (!allow) { HasDF=true; - Details="Destricted Function. "; + Details="Import DF. \""+string(NAME)+"\" from module \""+string(pszModName)+"\" "; FreeLibrary(hmodCaller); return true; } @@ -309,7 +317,7 @@ return true; } err=GetLastError(); -Details="Cannot create process. Error#"+ToStr(err=GetLastError()); +Details="Cannot create process. Error#"+ToStr(err); return false; } Modified: ACMServer/trunk/sharp tester/SourceTest 2.0/Test/SecureClass.h =================================================================== --- ACMServer/trunk/sharp tester/SourceTest 2.0/Test/SecureClass.h 2008-09-20 10:03:22 UTC (rev 356) +++ ACMServer/trunk/sharp tester/SourceTest 2.0/Test/SecureClass.h 2008-09-20 15:23:38 UTC (rev 357) @@ -45,7 +45,6 @@ { string Name; string Module; - //PROC handle; }; public class SysCallSecure:public BasicSecure Modified: ACMServer/trunk/sharp tester/SourceTest 2.0/Test/Test.cpp =================================================================== --- ACMServer/trunk/sharp tester/SourceTest 2.0/Test/Test.cpp 2008-09-20 10:03:22 UTC (rev 356) +++ ACMServer/trunk/sharp tester/SourceTest 2.0/Test/Test.cpp 2008-09-20 15:23:38 UTC (rev 357) @@ -14,6 +14,7 @@ data->Load(); testfield=gcnew TestLoader(data->InputName,data->OutputName,data->PointFileName,data->TestFolderName,ProblemPath); testfield->Load(); + results=gcnew array<TestRes^>(testfield->tests->Length); plug=gcnew PluginLoader(System::IO::Path::GetFullPath(data->CheckPlugin)); plug->Load(); exe=ExeFile; @@ -85,7 +86,7 @@ if (sec->CheckSecure()) { result->res=TestResult::DestrictedFunction; - result->Details=gcnew String(sec->Details.c_str())+" Destricted function."; + result->Details=gcnew String(sec->Details.c_str())+"Destricted function."; Marshal::FreeHGlobal(IntPtr(bufW)); return false; } @@ -327,8 +328,7 @@ { StopTest=false; CurrentTest=0; - threads=gcnew array<Threading::Thread^>(min(data->MaxThreads,test->tests->Length)); - results=gcnew array<TestRes^>(test->tests->Length); + threads=gcnew array<Threading::Thread^>(min(data->MaxThreads,testfield->tests->Length)); for (int i=0;i<threads->Length;i++) { Threading::Thread^ t=gcnew Threading::Thread(gcnew Threading::ThreadStart(this,&Runner::ThreadProc)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |