Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*******************************************************************************
* Copyright (c) 2012 Secure Software Engineering Group at EC SPRIDE.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v2.1
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*
* Contributors: Christian Fritz, Steven Arzt, Siegfried Rasthofer, Eric
* Bodden, and others.
******************************************************************************/
package soot.jimple.infoflow.rifl;
import java.io.StringWriter;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import soot.jimple.infoflow.rifl.RIFLDocument.Assignable;
import soot.jimple.infoflow.rifl.RIFLDocument.Category;
import soot.jimple.infoflow.rifl.RIFLDocument.DomainAssignment;
import soot.jimple.infoflow.rifl.RIFLDocument.DomainSpec;
import soot.jimple.infoflow.rifl.RIFLDocument.FlowPair;
import soot.jimple.infoflow.rifl.RIFLDocument.JavaFieldSpec;
import soot.jimple.infoflow.rifl.RIFLDocument.JavaParameterSpec;
import soot.jimple.infoflow.rifl.RIFLDocument.JavaReturnValueSpec;
import soot.jimple.infoflow.rifl.RIFLDocument.SourceSinkSpec;
/**
* Class for writing out RIFL-compliant data flow policies
*
* @author Steven Arzt
*/
public class RIFLWriter {
private final RIFLDocument document;
/**
* Creates a new instance of the {@link RIFLWriter} class
*
* @param document
* The document to write out
*/
public RIFLWriter(RIFLDocument document) {
this.document = document;
}
public String write() {
try {
// Create a new document
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.newDocument();
Element rootElement = document.createElement(RIFLConstants.RIFL_SPEC_TAG);
document.appendChild(rootElement);
writeInterfaceSpec(document, rootElement);
writeDomains(document, rootElement);
writeDomainAssignment(document, rootElement);
writeFlowPolicy(document, rootElement);
// Write it out
StringWriter stringWriter = new StringWriter();
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(document);
StreamResult result = new StreamResult(stringWriter);
transformer.transform(source, result);
return stringWriter.toString();
} catch (ParserConfigurationException ex) {
throw new RuntimeException(ex);
} catch (TransformerConfigurationException ex) {
throw new RuntimeException(ex);
} catch (TransformerException ex) {
throw new RuntimeException(ex);
}
}
/**
* Writes out the interface specification component of the RIFL document
*
* @param document
* The XML document in which to write
* @param rootElement
* The root element of the document
*/
private void writeInterfaceSpec(Document document, Element rootElement) {
Element attackerIO = document.createElement(RIFLConstants.INTERFACE_SPEC_TAG);
rootElement.appendChild(attackerIO);
for (Assignable assign : this.document.getInterfaceSpec().getSourcesSinks()) {
writeAssignable(assign, document, attackerIO);
}
}
/**
* Writes out an assignable element the RIFL document
*
* @param document
* The XML document in which to write
* @param rootElement
* The root element of the document
*/
private void writeAssignable(Assignable assign, Document document, Element rootElement) {
Element attackerIO = document.createElement(RIFLConstants.ASSIGNABLE_TAG);
rootElement.appendChild(attackerIO);
attackerIO.setAttribute(RIFLConstants.HANDLE_ATTRIBUTE, assign.getHandle());
writeSourceSinkSpec(assign.getElement(), document, attackerIO);
}
/**
* Writes out a source/sink specification object
*
* @param spec
* The source/sink specification to write out
* @param document
* The document in which to write the source/sink specification
* @param parentElement
* The parent element in the DOM tree. This must be