Example #1
0
        public string checkIfFileExistsAndDownloadIfNot(string file , string urlToDownloadFile)
        {
        	if (File.Exists(file))
        		return file;
            if (file.valid().isFalse())
                file = urlToDownloadFile.fileName();
            var localTempFile = urlToDownloadFile.extension(".zip") 
                ? PublicDI.config.getTempFileInTempDirectory(".zip")
                : Path.Combine(PublicDI.config.O2TempDir, file);
        	if (File.Exists(localTempFile))
        		return localTempFile;
            downloadBinaryFile(urlToDownloadFile, localTempFile);
        	//var downloadedFile = downloadBinaryFile(urlToDownloadFile, false /*saveUsingTempFileName*/);
            if (File.Exists(localTempFile))
        	{
                if (Path.GetExtension(localTempFile) != ".zip" && urlToDownloadFile.fileName().extension(".zip").isFalse())
                    return localTempFile;

                List<string> extractedFiles = new zipUtils().unzipFileAndReturnListOfUnzipedFiles(localTempFile, PublicDI.config.O2TempDir);
        		if (extractedFiles != null)
        			foreach(var extractedFile in  extractedFiles)
        				if (Path.GetFileName(extractedFile) == file)
        					return extractedFile;        					        		        		        		
        	}
        	return "";
        }
Example #2
0
 public override bool execute()
 {
     if (sourceObject == null)
         return false;
     var fileToUnzip = (string) sourceObject;
     if (fileToUnzip.IndexOf("http://") > -1)
         fileToUnzip = new Web().downloadBinaryFile(fileToUnzip);
     if (!File.Exists(fileToUnzip))
         return false;
     folderToUnzipFiles = folderToUnzipFiles ?? DI.config.TempFolderInTempDirectory;
     List<string> unzipedFiles = new zipUtils().unzipFileAndReturnListOfUnzipedFiles(fileToUnzip, folderToUnzipFiles);
     if (unzipedFiles.Count == 0)
         return false;
     resultsObject = unzipedFiles;
     return true;
 }
        public IO2Assessment loadFile(string fileOrFolderToLoad)
        {
            var scanFile ="";
            var tempUnzipFolder = DI.config.getTempFolderInTempDirectory("_AppscanDE_Unzip");
            if (Path.GetExtension(fileOrFolderToLoad) == ".xml")
            {
                scanFile = fileOrFolderToLoad;
            }
            else
            {
                var filesToSearch = new List<string>();
                if (Directory.Exists(fileOrFolderToLoad))
                    filesToSearch = Files.getFilesFromDir_returnFullPath(fileOrFolderToLoad, "*.xml", true);
                else
                {
                    //fileToLoad = Files.MoveFile(fileToLoad, (fileToLoad + ".zip"));

                    // Path.GetFileNameWithoutExtension(fileToLoad));
                    filesToSearch = new zipUtils().unzipFileAndReturnListOfUnzipedFiles(fileOrFolderToLoad,
                                                                                        tempUnzipFolder);
                }

                if (filesToSearch.Count == 0)
                    DI.log.error("in O2AssesmentLoad_AppScanDE.loadFile, unzip operation failed for file: {0}", fileOrFolderToLoad);
                else
                    foreach (var file in filesToSearch)
                        if (
                            file.IndexOf(@"com.ibm.rational.appscan.ui.security.runnable.codeAnalysis.staticAnalysis\securityResultSet.xml") >-1)
                            scanFile = file;
                //scanFile = Path.Combine(tempFolder, @"com.ibm.rational.appscan.ui.security.runnable.codeAnalysis.staticAnalysis\securityResultSet.xml");
            }
            if (false == File.Exists(scanFile))
            {
                DI.log.error("Cound not find AppScanDE static analysis file: {0}", scanFile);
                return new O2Assessment();
            }

            IO2Assessment o2Assessment = null;
            var appScanDEResults = Serialize.getDeSerializedObjectFromXmlFile(scanFile, typeof(taintResultSet));
            if (appScanDEResults != null && appScanDEResults is taintResultSet)
                o2Assessment = createO2AssessmentFromCodeCrawlerObject((taintResultSet)appScanDEResults, Path.GetFileNameWithoutExtension(scanFile));

            Files.deleteFolder(tempUnzipFolder);
            return o2Assessment;
        }
Example #4
0
        public List<String> downloadZipFileAndExtractFiles(string urlOfFileToFetch)
        {
            var webClient = new WebClient();
            try
            {
                //setup headers
                foreach (var header in Headers_Request)
                    webClient.Headers.Add(header.Key, header.Value);

                string tempFileName = String.Format("{0}_{1}.zip", PublicDI.config.TempFileNameInTempDirectory,
                                                    Path.GetFileNameWithoutExtension(urlOfFileToFetch));
                byte[] pageData = webClient.DownloadData(urlOfFileToFetch);
                Files.WriteFileContent(tempFileName, pageData);
                List<string> extractedFiles = new zipUtils().unzipFileAndReturnListOfUnzipedFiles(tempFileName);
                File.Delete(tempFileName);
                return extractedFiles;
            }
            catch (Exception ex)
            {
                PublicDI.log.ex(ex);
            }
            return null;
        }
 //[Test]
 public void create_Libraries_Backup()
 {
     var libraryName = "temp_lib_createAndBackup";
     var newLibrary = tmWebServices.CreateLibrary(new Library() { caption = libraryName });
     Assert.That(newLibrary.notNull());
     var newGuidanceItem = new GuidanceItem_V3() { libraryId = newLibrary.libraryId };
     tmWebServices.CreateGuidanceItem(newGuidanceItem);
     var backupFile = tmXmlDatabase.xmlDB_Libraries_BackupLibrary(newLibrary.libraryId);
     Assert.IsTrue(backupFile.fileExists());
     var backedUpfiles = new zipUtils().getListOfFilesInZip(backupFile);
     Assert.AreEqual(backedUpfiles.size(), 2, "there should be two files backup-ed files");
     tmWebServices.DeleteLibrary(newLibrary.libraryId);
 }
Example #6
0
 public static void getPythonStringTargetFile(string fileToProcess, string targetFolder, bool processJarFiles)
 {
     //if (Directory.Exists(fileOrFolderToProcess))
     //    return fileOrFolderToProcess;
     if (File.Exists(fileToProcess))
     {
         var extension = Path.GetExtension(fileToProcess).ToLower();
         switch (extension)
         {
             case ".zip":
             case ".jar":
             case ".war":
                 if (extension == ".jar" && false == processJarFiles)     // handle the case where we don't want to process the Jar files
                     return;
                 targetFolder = Path.Combine(targetFolder, Path.GetFileName(fileToProcess).Replace(".", "_"));
                 var unzipedFiles = new zipUtils().unzipFileAndReturnListOfUnzipedFiles(fileToProcess, targetFolder);
                 foreach (var unzipedFile in unzipedFiles)
                     getPythonStringTargetFile(unzipedFile, targetFolder, processJarFiles);
                 break;
             case ".class":
                 var targetFile = fileToProcess.Replace(':','_').Replace('/','_').Replace('\\','_');
                 Files.Copy(fileToProcess, Path.Combine(targetFolder, targetFile));
                 break;
         }
     }
 }
Example #7
0
        public static Dictionary<string, List<string>> mapAvailableJars(List<string> jarPaths)
        {
            DI.log.info("Search recursively for all *.jar files");
            var availableJars = new List<string>();
            foreach (var jarSearchPath in jarPaths)
                availableJars.AddRange(Files.getFilesFromDir_returnFullPath(jarSearchPath, "*.jar", true));

            DI.log.info("Found {0} jar files", availableJars.Count);

            var mappedClasses = new Dictionary<string, List<string>>();
            foreach (var jarFile in availableJars)
            {
                var filesInJar = new zipUtils().getListOfFilesInZip(jarFile);
                foreach (var fileInJar in filesInJar)
                    if (Path.GetExtension(fileInJar) == ".class")
                    {
                        if (false == mappedClasses.ContainsKey(fileInJar))
                            mappedClasses.Add(fileInJar, new List<string>());
                        mappedClasses[fileInJar].Add(jarFile);
                    }
            }
            DI.log.info("There are {0} classes mapped", mappedClasses.Keys.Count);
            return mappedClasses;
        }