我想通过使用# $proc - process handle
if ($NtQueryInformationProcess(
$proc, 0, $PROCESS_BASIC_INFORMATION, [Runtime.InteropServices.Marshal]::SizeOf(
$PROCESS_BASIC_INFORMATION
), [IntPtr]::Zero
))) -eq 0) {
# pointer to RTL_USER_PROCESS_PARAMETERS
$ptr = [Runtime.InteropServices.Marshal]::ReadIntPtr($PROCESS_BASIC_INFORMATION.PebBaseAddress, 0x10)
# pointer to CommandLine field of structure above
$ptr = [Runtime.InteropServices.Marshal]::ReadIntPtr($ptr, 0x40)
# how to get CommandLine field (UNICODE_STRING structure)?
}
更改word / document.xml来修改 docx文档 - 获取为字节数组。
我有以下代码(基于SO讨论How to edit MS Word documents using Java?):
java nio ZipFileSystem
我想避免文件创建和写入磁盘,以获取public static void modifyDocxContent(byte[] docx, byte[] newContent) {
try {
// Create a Word File from byte[]
File docxFile = new File("C:\\test\\simple.docx");
Path docxPath = docxFile.toPath();
Files.write(docxPath, docx);
// Create jar URI for the same Word file
URI docxUri = URI.create("jar:file:/C:/test/simple.docx");
// Create a zip FileSystem for word file and modify content in it
Map<String, String> zipProperties = new HashMap<>();
zipProperties.put("encoding", "UTF-8");
zipProperties.put("create", "false");
try (FileSystem zipFS = FileSystems.newFileSystem(docxUri, zipProperties)) {
Path documentXmlPath = zipFS.getPath("word", "document.xml");
Files.delete(documentXmlPath);
Files.write(documentXmlPath, newContent, StandardOpenOption.CREATE, StandardOpenOption.APPEND, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.SYNC);
}
} catch (IOException e) {
e.printStackTrace();
}
}
调用中使用的URI。有没有更有效的方法来考虑获得这样的nio ZipFileSystem?