示例 3:不同的源和接收器文件

以下示例说明来自接收器的其他文件中的源。

TestCase_IOT_Xfile_Part1.java

public class TestCase_IOT_XFile_Part1 {
	public static void main(String[] args) {
		try {
			TestCase_IOT_XFile_Part1 testCase =
				new TestCase_IOT_XFile_Part1();
			TestCase_IOT_XFile_Part2 testCase2 =
				new TestCase_IOT_XFile_Part2();
			testCase2.writeToVulnerableSink(
				testCase.getVulnerableSource(args[0]));
		} catch (Exception e) {
		}
	}

	public String getVulnerableSource(String file)
		throws IOException, FileNotFoundException {
		FileInputStream fis = new FileInputStream(file);
		byte[] buf = new byte[100];
		fis.read(buf);
		String ret = new String(buf);
		fis.close();
		return ret;
	}
}

TestCase_IOT_Xfile_Part2.java

public class TestCase_IOT_XFile_Part2 {
	public void writeToVulnerableSink(String str)
		throws FileNotFoundException {
		FileOutputStream fos = new FileOutputStream(str);
		PrintWriter writer = new PrintWriter(fos);
		writer.write(str);
	}
}

TestCase_IOT_Xfile_Part1.javaTestCase_IOT_Xfile_Part2.java 跟踪数据允许在整个程序中跟踪数据流。将显示堆栈跟踪:


“跟踪”视图,显示从 TestCase_IOT_XFile_Part1 到 TestCase_IOT_XFile_Part2 的数据流

此示例显示数据通过 main 方法从TestCase_IOT_XFile_Part1 流到 TestCase_IOT_XFile_Part2