Ghidra is a software reverse engineering (SRE) framework
GP-7103: Port from JNA to java.lang.foreign.
Danf9cc9dc6dadb
diff --git a/Ghidra/Framework/Pty/Module.manifest b/Ghidra/Framework/Pty/Module.manifestindex d7934ca912..e69de29bb2 100644--- a/Ghidra/Framework/Pty/Module.manifest+++ b/Ghidra/Framework/Pty/Module.manifest@@ -1,2 +0,0 @@-MODULE FILE LICENSE: lib/jna-5.14.0.jar Apache License 2.0-MODULE FILE LICENSE: lib/jna-platform-5.14.0.jar Apache License 2.0\ No newline at end of filediff --git a/Ghidra/Framework/Pty/build.gradle b/Ghidra/Framework/Pty/build.gradleindex d751ad129b..013b371907 100644--- a/Ghidra/Framework/Pty/build.gradle+++ b/Ghidra/Framework/Pty/build.gradle@@ -25,8 +25,6 @@ apply plugin: 'eclipse'eclipse.project.name = 'Framework Pty'dependencies {- api "net.java.dev.jna:jna:5.14.0"- api "net.java.dev.jna:jna-platform:5.14.0"api project(":Docking")testImplementation project(":Generic")diff --git a/Ghidra/Framework/Pty/jextract/extract.bat b/Ghidra/Framework/Pty/jextract/extract.batnew file mode 100644index 0000000000..3cbd43d7ee--- /dev/null+++ b/Ghidra/Framework/Pty/jextract/extract.bat@@ -0,0 +1,69 @@+:: ###+:: IP: GHIDRA+::+:: Licensed under the Apache License, Version 2.0 (the "License");+:: you may not use this file except in compliance with the License.+:: You may obtain a copy of the License at+::+:: http://www.apache.org/licenses/LICENSE-2.0+::+:: Unless required by applicable law or agreed to in writing, software+:: distributed under the License is distributed on an "AS IS" BASIS,+:: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+:: See the License for the specific language governing permissions and+:: limitations under the License.+:: ##+::Run this from this same directory+@echo off+:: After extraction, manual edits are required to implement the captureState for LastError++C:\Software\jextract-25\bin\jextract ^+ --output ..\src\main\java ^+ --target-package com.microsoft.win32 ^+ win32.h ^+ --include-function AssignProcessToJobObject ^+ --include-function CloseHandle ^+ --include-function ClosePseudoConsole ^+ --include-function ConnectNamedPipe ^+ --include-function CreatePipe ^+ --include-function CreateJobObjectW ^+ --include-function CreateProcessW ^+ --include-function CreatePseudoConsole ^+ --include-function FlushFileBuffers ^+ --include-function FormatMessageW ^+ --include-function GetExitCodeProcess ^+ --include-function InitializeProcThreadAttributeList ^+ --include-function LocalFree ^+ --include-function ReadFile ^+ --include-function ResizePseudoConsole ^+ --include-function TerminateJobObject ^+ --include-function UpdateProcThreadAttribute ^+ --include-function WaitForSingleObject ^+ --include-function WriteFile ^+ --include-struct _COORD ^+ --include-struct _PROCESS_INFORMATION ^+ --include-struct _STARTUPINFOW ^+ --include-struct _STARTUPINFOEXW ^+ --include-typedef DWORD ^+ --include-typedef UINT ^+ --include-typedef HANDLE ^+ --include-typedef HRESULT ^+ --include-typedef LPWSTR ^+ --include-constant S_OK ^+ --include-constant CREATE_UNICODE_ENVIRONMENT ^+ --include-constant ERROR_BROKEN_PIPE ^+ --include-constant ERROR_PIPE_CONNECTED ^+ --include-constant ERROR_PIPE_LISTENING ^+ --include-constant EXTENDED_STARTUPINFO_PRESENT ^+ --include-constant FORMAT_MESSAGE_FROM_SYSTEM ^+ --include-constant FORMAT_MESSAGE_IGNORE_INSERTS ^+ --include-constant FORMAT_MESSAGE_ARGUMENT_ARRAY ^+ --include-constant FORMAT_MESSAGE_ALLOCATE_BUFFER ^+ --include-constant PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE ^+ --include-constant STARTF_USESTDHANDLES ^+ --include-constant STILL_ACTIVE ^+ --include-constant WAIT_ABANDONED ^+ --include-constant WAIT_FAILED ^+ --include-constant WAIT_OBJECT_0 ^+ --include-constant WAIT_TIMEOUT ^+ --library Kernel32diff --git a/Ghidra/Framework/Pty/jextract/extract.sh b/Ghidra/Framework/Pty/jextract/extract.shnew file mode 100755index 0000000000..b129a9787d--- /dev/null+++ b/Ghidra/Framework/Pty/jextract/extract.sh@@ -0,0 +1,67 @@+#!/usr/bin/bash+## ###+# IP: GHIDRA+#+# Licensed under the Apache License, Version 2.0 (the "License");+# you may not use this file except in compliance with the License.+# You may obtain a copy of the License at+#+# http://www.apache.org/licenses/LICENSE-2.0+#+# Unless required by applicable law or agreed to in writing, software+# distributed under the License is distributed on an "AS IS" BASIS,+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+# See the License for the specific language governing permissions and+# limitations under the License.+##+# Run this from this same directory+# After extract, manual edits are required to implement the captureState for errno++~/bin/jextract-25/bin/jextract \+ --output ../src/main/java \+ --target-package org.unix \+ "<fcntl.h>" \+ --include-function open \+ --include-typedef mode_t \+ --include-constant O_RDWR++~/bin/jextract-25/bin/jextract \+ --output ../src/main/java \+ --target-package org.unix.x \+ "<sys/ioctl.h>" \+ --include-function ioctl \+ --include-struct winsize++~/bin/jextract-25/bin/jextract \+ --output ../src/main/java \+ --target-package org.unix \+ "<pty.h>" \+ --include-function openpty++~/bin/jextract-25/bin/jextract \+ --output ../src/main/java \+ --target-package org.unix \+ "<string.h>" \+ --include-function strerror++~/bin/jextract-25/bin/jextract \+ --output ../src/main/java \+ --target-package org.unix \+ "<termios.h>" \+ --include-function tcgetattr \+ --include-function tcsetattr \+ --include-struct termios \+ --include-constant ECHO \+ --include-constant TCSANOW++~/bin/jextract-25/bin/jextract \+ --output ../src/main/java \+ --target-package org.unix \+ "<unistd.h>" \+ --include-function close \+ --include-function dup \+ --include-function dup2 \+ --include-function execv \+ --include-function read \+ --include-function setsid \+ --include-function writediff --git a/Ghidra/Framework/Pty/jextract/win32.h b/Ghidra/Framework/Pty/jextract/win32.hnew file mode 100644index 0000000000..bab76b8ad2--- /dev/null+++ b/Ghidra/Framework/Pty/jextract/win32.h@@ -0,0 +1,18 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+#include <Windows.h>+#include <WinCon.h>+#include <ConsoleApi.h>diff --git a/Ghidra/Framework/Pty/src/main/java/com/microsoft/win32/_COORD.java b/Ghidra/Framework/Pty/src/main/java/com/microsoft/win32/_COORD.javanew file mode 100644index 0000000000..0719e7bfc1--- /dev/null+++ b/Ghidra/Framework/Pty/src/main/java/com/microsoft/win32/_COORD.java@@ -0,0 +1,188 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+// Generated by jextract++package com.microsoft.win32;++import java.lang.invoke.*;+import java.lang.foreign.*;+import java.nio.ByteOrder;+import java.util.*;+import java.util.function.*;+import java.util.stream.*;++import static java.lang.foreign.ValueLayout.*;+import static java.lang.foreign.MemoryLayout.PathElement.*;++/**+ * {@snippet lang=c :+ * struct _COORD {+ * SHORT X;+ * SHORT Y;+ * }+ * }+ */+public class _COORD {++ _COORD() {+ // Should not be called directly+ }++ private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(+ win32_h.C_SHORT.withName("X"),+ win32_h.C_SHORT.withName("Y")+ ).withName("_COORD");++ /**+ * The layout of this struct+ */+ public static final GroupLayout layout() {+ return $LAYOUT;+ }++ private static final OfShort X$LAYOUT = (OfShort)$LAYOUT.select(groupElement("X"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * SHORT X+ * }+ */+ public static final OfShort X$layout() {+ return X$LAYOUT;+ }++ private static final long X$OFFSET = $LAYOUT.byteOffset(groupElement("X"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * SHORT X+ * }+ */+ public static final long X$offset() {+ return X$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * SHORT X+ * }+ */+ public static short X(MemorySegment struct) {+ return struct.get(X$LAYOUT, X$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * SHORT X+ * }+ */+ public static void X(MemorySegment struct, short fieldValue) {+ struct.set(X$LAYOUT, X$OFFSET, fieldValue);+ }++ private static final OfShort Y$LAYOUT = (OfShort)$LAYOUT.select(groupElement("Y"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * SHORT Y+ * }+ */+ public static final OfShort Y$layout() {+ return Y$LAYOUT;+ }++ private static final long Y$OFFSET = $LAYOUT.byteOffset(groupElement("Y"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * SHORT Y+ * }+ */+ public static final long Y$offset() {+ return Y$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * SHORT Y+ * }+ */+ public static short Y(MemorySegment struct) {+ return struct.get(Y$LAYOUT, Y$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * SHORT Y+ * }+ */+ public static void Y(MemorySegment struct, short fieldValue) {+ struct.set(Y$LAYOUT, Y$OFFSET, fieldValue);+ }++ /**+ * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}.+ * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()}+ */+ public static MemorySegment asSlice(MemorySegment array, long index) {+ return array.asSlice(layout().byteSize() * index);+ }++ /**+ * The size (in bytes) of this struct+ */+ public static long sizeof() { return layout().byteSize(); }++ /**+ * Allocate a segment of size {@code layout().byteSize()} using {@code allocator}+ */+ public static MemorySegment allocate(SegmentAllocator allocator) {+ return allocator.allocate(layout());+ }++ /**+ * Allocate an array of size {@code elementCount} using {@code allocator}.+ * The returned segment has size {@code elementCount * layout().byteSize()}.+ */+ public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) {+ return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout()));+ }++ /**+ * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).+ * The returned segment has size {@code layout().byteSize()}+ */+ public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer<MemorySegment> cleanup) {+ return reinterpret(addr, 1, arena, cleanup);+ }++ /**+ * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).+ * The returned segment has size {@code elementCount * layout().byteSize()}+ */+ public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer<MemorySegment> cleanup) {+ return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup);+ }+}+diff --git a/Ghidra/Framework/Pty/src/main/java/com/microsoft/win32/_PROCESS_INFORMATION.java b/Ghidra/Framework/Pty/src/main/java/com/microsoft/win32/_PROCESS_INFORMATION.javanew file mode 100644index 0000000000..6451e91896--- /dev/null+++ b/Ghidra/Framework/Pty/src/main/java/com/microsoft/win32/_PROCESS_INFORMATION.java@@ -0,0 +1,280 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+// Generated by jextract++package com.microsoft.win32;++import java.lang.invoke.*;+import java.lang.foreign.*;+import java.nio.ByteOrder;+import java.util.*;+import java.util.function.*;+import java.util.stream.*;++import static java.lang.foreign.ValueLayout.*;+import static java.lang.foreign.MemoryLayout.PathElement.*;++/**+ * {@snippet lang=c :+ * struct _PROCESS_INFORMATION {+ * HANDLE hProcess;+ * HANDLE hThread;+ * DWORD dwProcessId;+ * DWORD dwThreadId;+ * }+ * }+ */+public class _PROCESS_INFORMATION {++ _PROCESS_INFORMATION() {+ // Should not be called directly+ }++ private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(+ win32_h.C_POINTER.withName("hProcess"),+ win32_h.C_POINTER.withName("hThread"),+ win32_h.C_LONG.withName("dwProcessId"),+ win32_h.C_LONG.withName("dwThreadId")+ ).withName("_PROCESS_INFORMATION");++ /**+ * The layout of this struct+ */+ public static final GroupLayout layout() {+ return $LAYOUT;+ }++ private static final AddressLayout hProcess$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("hProcess"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * HANDLE hProcess+ * }+ */+ public static final AddressLayout hProcess$layout() {+ return hProcess$LAYOUT;+ }++ private static final long hProcess$OFFSET = $LAYOUT.byteOffset(groupElement("hProcess"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * HANDLE hProcess+ * }+ */+ public static final long hProcess$offset() {+ return hProcess$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * HANDLE hProcess+ * }+ */+ public static MemorySegment hProcess(MemorySegment struct) {+ return struct.get(hProcess$LAYOUT, hProcess$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * HANDLE hProcess+ * }+ */+ public static void hProcess(MemorySegment struct, MemorySegment fieldValue) {+ struct.set(hProcess$LAYOUT, hProcess$OFFSET, fieldValue);+ }++ private static final AddressLayout hThread$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("hThread"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * HANDLE hThread+ * }+ */+ public static final AddressLayout hThread$layout() {+ return hThread$LAYOUT;+ }++ private static final long hThread$OFFSET = $LAYOUT.byteOffset(groupElement("hThread"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * HANDLE hThread+ * }+ */+ public static final long hThread$offset() {+ return hThread$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * HANDLE hThread+ * }+ */+ public static MemorySegment hThread(MemorySegment struct) {+ return struct.get(hThread$LAYOUT, hThread$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * HANDLE hThread+ * }+ */+ public static void hThread(MemorySegment struct, MemorySegment fieldValue) {+ struct.set(hThread$LAYOUT, hThread$OFFSET, fieldValue);+ }++ private static final OfInt dwProcessId$LAYOUT = (OfInt)$LAYOUT.select(groupElement("dwProcessId"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * DWORD dwProcessId+ * }+ */+ public static final OfInt dwProcessId$layout() {+ return dwProcessId$LAYOUT;+ }++ private static final long dwProcessId$OFFSET = $LAYOUT.byteOffset(groupElement("dwProcessId"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * DWORD dwProcessId+ * }+ */+ public static final long dwProcessId$offset() {+ return dwProcessId$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * DWORD dwProcessId+ * }+ */+ public static int dwProcessId(MemorySegment struct) {+ return struct.get(dwProcessId$LAYOUT, dwProcessId$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * DWORD dwProcessId+ * }+ */+ public static void dwProcessId(MemorySegment struct, int fieldValue) {+ struct.set(dwProcessId$LAYOUT, dwProcessId$OFFSET, fieldValue);+ }++ private static final OfInt dwThreadId$LAYOUT = (OfInt)$LAYOUT.select(groupElement("dwThreadId"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * DWORD dwThreadId+ * }+ */+ public static final OfInt dwThreadId$layout() {+ return dwThreadId$LAYOUT;+ }++ private static final long dwThreadId$OFFSET = $LAYOUT.byteOffset(groupElement("dwThreadId"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * DWORD dwThreadId+ * }+ */+ public static final long dwThreadId$offset() {+ return dwThreadId$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * DWORD dwThreadId+ * }+ */+ public static int dwThreadId(MemorySegment struct) {+ return struct.get(dwThreadId$LAYOUT, dwThreadId$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * DWORD dwThreadId+ * }+ */+ public static void dwThreadId(MemorySegment struct, int fieldValue) {+ struct.set(dwThreadId$LAYOUT, dwThreadId$OFFSET, fieldValue);+ }++ /**+ * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}.+ * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()}+ */+ public static MemorySegment asSlice(MemorySegment array, long index) {+ return array.asSlice(layout().byteSize() * index);+ }++ /**+ * The size (in bytes) of this struct+ */+ public static long sizeof() { return layout().byteSize(); }++ /**+ * Allocate a segment of size {@code layout().byteSize()} using {@code allocator}+ */+ public static MemorySegment allocate(SegmentAllocator allocator) {+ return allocator.allocate(layout());+ }++ /**+ * Allocate an array of size {@code elementCount} using {@code allocator}.+ * The returned segment has size {@code elementCount * layout().byteSize()}.+ */+ public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) {+ return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout()));+ }++ /**+ * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).+ * The returned segment has size {@code layout().byteSize()}+ */+ public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer<MemorySegment> cleanup) {+ return reinterpret(addr, 1, arena, cleanup);+ }++ /**+ * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).+ * The returned segment has size {@code elementCount * layout().byteSize()}+ */+ public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer<MemorySegment> cleanup) {+ return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup);+ }+}+diff --git a/Ghidra/Framework/Pty/src/main/java/com/microsoft/win32/_STARTUPINFOEXW.java b/Ghidra/Framework/Pty/src/main/java/com/microsoft/win32/_STARTUPINFOEXW.javanew file mode 100644index 0000000000..dd758b9c97--- /dev/null+++ b/Ghidra/Framework/Pty/src/main/java/com/microsoft/win32/_STARTUPINFOEXW.java@@ -0,0 +1,188 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+// Generated by jextract++package com.microsoft.win32;++import java.lang.invoke.*;+import java.lang.foreign.*;+import java.nio.ByteOrder;+import java.util.*;+import java.util.function.*;+import java.util.stream.*;++import static java.lang.foreign.ValueLayout.*;+import static java.lang.foreign.MemoryLayout.PathElement.*;++/**+ * {@snippet lang=c :+ * struct _STARTUPINFOEXW {+ * STARTUPINFOW StartupInfo;+ * LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList;+ * }+ * }+ */+public class _STARTUPINFOEXW {++ _STARTUPINFOEXW() {+ // Should not be called directly+ }++ private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(+ _STARTUPINFOW.layout().withName("StartupInfo"),+ win32_h.C_POINTER.withName("lpAttributeList")+ ).withName("_STARTUPINFOEXW");++ /**+ * The layout of this struct+ */+ public static final GroupLayout layout() {+ return $LAYOUT;+ }++ private static final GroupLayout StartupInfo$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("StartupInfo"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * STARTUPINFOW StartupInfo+ * }+ */+ public static final GroupLayout StartupInfo$layout() {+ return StartupInfo$LAYOUT;+ }++ private static final long StartupInfo$OFFSET = $LAYOUT.byteOffset(groupElement("StartupInfo"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * STARTUPINFOW StartupInfo+ * }+ */+ public static final long StartupInfo$offset() {+ return StartupInfo$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * STARTUPINFOW StartupInfo+ * }+ */+ public static MemorySegment StartupInfo(MemorySegment struct) {+ return struct.asSlice(StartupInfo$OFFSET, StartupInfo$LAYOUT.byteSize());+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * STARTUPINFOW StartupInfo+ * }+ */+ public static void StartupInfo(MemorySegment struct, MemorySegment fieldValue) {+ MemorySegment.copy(fieldValue, 0L, struct, StartupInfo$OFFSET, StartupInfo$LAYOUT.byteSize());+ }++ private static final AddressLayout lpAttributeList$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("lpAttributeList"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList+ * }+ */+ public static final AddressLayout lpAttributeList$layout() {+ return lpAttributeList$LAYOUT;+ }++ private static final long lpAttributeList$OFFSET = $LAYOUT.byteOffset(groupElement("lpAttributeList"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList+ * }+ */+ public static final long lpAttributeList$offset() {+ return lpAttributeList$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList+ * }+ */+ public static MemorySegment lpAttributeList(MemorySegment struct) {+ return struct.get(lpAttributeList$LAYOUT, lpAttributeList$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList+ * }+ */+ public static void lpAttributeList(MemorySegment struct, MemorySegment fieldValue) {+ struct.set(lpAttributeList$LAYOUT, lpAttributeList$OFFSET, fieldValue);+ }++ /**+ * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}.+ * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()}+ */+ public static MemorySegment asSlice(MemorySegment array, long index) {+ return array.asSlice(layout().byteSize() * index);+ }++ /**+ * The size (in bytes) of this struct+ */+ public static long sizeof() { return layout().byteSize(); }++ /**+ * Allocate a segment of size {@code layout().byteSize()} using {@code allocator}+ */+ public static MemorySegment allocate(SegmentAllocator allocator) {+ return allocator.allocate(layout());+ }++ /**+ * Allocate an array of size {@code elementCount} using {@code allocator}.+ * The returned segment has size {@code elementCount * layout().byteSize()}.+ */+ public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) {+ return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout()));+ }++ /**+ * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).+ * The returned segment has size {@code layout().byteSize()}+ */+ public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer<MemorySegment> cleanup) {+ return reinterpret(addr, 1, arena, cleanup);+ }++ /**+ * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).+ * The returned segment has size {@code elementCount * layout().byteSize()}+ */+ public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer<MemorySegment> cleanup) {+ return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup);+ }+}+diff --git a/Ghidra/Framework/Pty/src/main/java/com/microsoft/win32/_STARTUPINFOW.java b/Ghidra/Framework/Pty/src/main/java/com/microsoft/win32/_STARTUPINFOW.javanew file mode 100644index 0000000000..8fa3f426e7--- /dev/null+++ b/Ghidra/Framework/Pty/src/main/java/com/microsoft/win32/_STARTUPINFOW.java@@ -0,0 +1,926 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+// Generated by jextract++package com.microsoft.win32;++import java.lang.invoke.*;+import java.lang.foreign.*;+import java.nio.ByteOrder;+import java.util.*;+import java.util.function.*;+import java.util.stream.*;++import static java.lang.foreign.ValueLayout.*;+import static java.lang.foreign.MemoryLayout.PathElement.*;++/**+ * {@snippet lang=c :+ * struct _STARTUPINFOW {+ * DWORD cb;+ * LPWSTR lpReserved;+ * LPWSTR lpDesktop;+ * LPWSTR lpTitle;+ * DWORD dwX;+ * DWORD dwY;+ * DWORD dwXSize;+ * DWORD dwYSize;+ * DWORD dwXCountChars;+ * DWORD dwYCountChars;+ * DWORD dwFillAttribute;+ * DWORD dwFlags;+ * WORD wShowWindow;+ * WORD cbReserved2;+ * LPBYTE lpReserved2;+ * HANDLE hStdInput;+ * HANDLE hStdOutput;+ * HANDLE hStdError;+ * }+ * }+ */+public class _STARTUPINFOW {++ _STARTUPINFOW() {+ // Should not be called directly+ }++ private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(+ win32_h.C_LONG.withName("cb"),+ MemoryLayout.paddingLayout(4),+ win32_h.C_POINTER.withName("lpReserved"),+ win32_h.C_POINTER.withName("lpDesktop"),+ win32_h.C_POINTER.withName("lpTitle"),+ win32_h.C_LONG.withName("dwX"),+ win32_h.C_LONG.withName("dwY"),+ win32_h.C_LONG.withName("dwXSize"),+ win32_h.C_LONG.withName("dwYSize"),+ win32_h.C_LONG.withName("dwXCountChars"),+ win32_h.C_LONG.withName("dwYCountChars"),+ win32_h.C_LONG.withName("dwFillAttribute"),+ win32_h.C_LONG.withName("dwFlags"),+ win32_h.C_SHORT.withName("wShowWindow"),+ win32_h.C_SHORT.withName("cbReserved2"),+ MemoryLayout.paddingLayout(4),+ win32_h.C_POINTER.withName("lpReserved2"),+ win32_h.C_POINTER.withName("hStdInput"),+ win32_h.C_POINTER.withName("hStdOutput"),+ win32_h.C_POINTER.withName("hStdError")+ ).withName("_STARTUPINFOW");++ /**+ * The layout of this struct+ */+ public static final GroupLayout layout() {+ return $LAYOUT;+ }++ private static final OfInt cb$LAYOUT = (OfInt)$LAYOUT.select(groupElement("cb"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * DWORD cb+ * }+ */+ public static final OfInt cb$layout() {+ return cb$LAYOUT;+ }++ private static final long cb$OFFSET = $LAYOUT.byteOffset(groupElement("cb"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * DWORD cb+ * }+ */+ public static final long cb$offset() {+ return cb$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * DWORD cb+ * }+ */+ public static int cb(MemorySegment struct) {+ return struct.get(cb$LAYOUT, cb$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * DWORD cb+ * }+ */+ public static void cb(MemorySegment struct, int fieldValue) {+ struct.set(cb$LAYOUT, cb$OFFSET, fieldValue);+ }++ private static final AddressLayout lpReserved$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("lpReserved"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * LPWSTR lpReserved+ * }+ */+ public static final AddressLayout lpReserved$layout() {+ return lpReserved$LAYOUT;+ }++ private static final long lpReserved$OFFSET = $LAYOUT.byteOffset(groupElement("lpReserved"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * LPWSTR lpReserved+ * }+ */+ public static final long lpReserved$offset() {+ return lpReserved$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * LPWSTR lpReserved+ * }+ */+ public static MemorySegment lpReserved(MemorySegment struct) {+ return struct.get(lpReserved$LAYOUT, lpReserved$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * LPWSTR lpReserved+ * }+ */+ public static void lpReserved(MemorySegment struct, MemorySegment fieldValue) {+ struct.set(lpReserved$LAYOUT, lpReserved$OFFSET, fieldValue);+ }++ private static final AddressLayout lpDesktop$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("lpDesktop"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * LPWSTR lpDesktop+ * }+ */+ public static final AddressLayout lpDesktop$layout() {+ return lpDesktop$LAYOUT;+ }++ private static final long lpDesktop$OFFSET = $LAYOUT.byteOffset(groupElement("lpDesktop"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * LPWSTR lpDesktop+ * }+ */+ public static final long lpDesktop$offset() {+ return lpDesktop$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * LPWSTR lpDesktop+ * }+ */+ public static MemorySegment lpDesktop(MemorySegment struct) {+ return struct.get(lpDesktop$LAYOUT, lpDesktop$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * LPWSTR lpDesktop+ * }+ */+ public static void lpDesktop(MemorySegment struct, MemorySegment fieldValue) {+ struct.set(lpDesktop$LAYOUT, lpDesktop$OFFSET, fieldValue);+ }++ private static final AddressLayout lpTitle$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("lpTitle"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * LPWSTR lpTitle+ * }+ */+ public static final AddressLayout lpTitle$layout() {+ return lpTitle$LAYOUT;+ }++ private static final long lpTitle$OFFSET = $LAYOUT.byteOffset(groupElement("lpTitle"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * LPWSTR lpTitle+ * }+ */+ public static final long lpTitle$offset() {+ return lpTitle$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * LPWSTR lpTitle+ * }+ */+ public static MemorySegment lpTitle(MemorySegment struct) {+ return struct.get(lpTitle$LAYOUT, lpTitle$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * LPWSTR lpTitle+ * }+ */+ public static void lpTitle(MemorySegment struct, MemorySegment fieldValue) {+ struct.set(lpTitle$LAYOUT, lpTitle$OFFSET, fieldValue);+ }++ private static final OfInt dwX$LAYOUT = (OfInt)$LAYOUT.select(groupElement("dwX"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * DWORD dwX+ * }+ */+ public static final OfInt dwX$layout() {+ return dwX$LAYOUT;+ }++ private static final long dwX$OFFSET = $LAYOUT.byteOffset(groupElement("dwX"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * DWORD dwX+ * }+ */+ public static final long dwX$offset() {+ return dwX$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * DWORD dwX+ * }+ */+ public static int dwX(MemorySegment struct) {+ return struct.get(dwX$LAYOUT, dwX$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * DWORD dwX+ * }+ */+ public static void dwX(MemorySegment struct, int fieldValue) {+ struct.set(dwX$LAYOUT, dwX$OFFSET, fieldValue);+ }++ private static final OfInt dwY$LAYOUT = (OfInt)$LAYOUT.select(groupElement("dwY"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * DWORD dwY+ * }+ */+ public static final OfInt dwY$layout() {+ return dwY$LAYOUT;+ }++ private static final long dwY$OFFSET = $LAYOUT.byteOffset(groupElement("dwY"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * DWORD dwY+ * }+ */+ public static final long dwY$offset() {+ return dwY$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * DWORD dwY+ * }+ */+ public static int dwY(MemorySegment struct) {+ return struct.get(dwY$LAYOUT, dwY$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * DWORD dwY+ * }+ */+ public static void dwY(MemorySegment struct, int fieldValue) {+ struct.set(dwY$LAYOUT, dwY$OFFSET, fieldValue);+ }++ private static final OfInt dwXSize$LAYOUT = (OfInt)$LAYOUT.select(groupElement("dwXSize"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * DWORD dwXSize+ * }+ */+ public static final OfInt dwXSize$layout() {+ return dwXSize$LAYOUT;+ }++ private static final long dwXSize$OFFSET = $LAYOUT.byteOffset(groupElement("dwXSize"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * DWORD dwXSize+ * }+ */+ public static final long dwXSize$offset() {+ return dwXSize$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * DWORD dwXSize+ * }+ */+ public static int dwXSize(MemorySegment struct) {+ return struct.get(dwXSize$LAYOUT, dwXSize$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * DWORD dwXSize+ * }+ */+ public static void dwXSize(MemorySegment struct, int fieldValue) {+ struct.set(dwXSize$LAYOUT, dwXSize$OFFSET, fieldValue);+ }++ private static final OfInt dwYSize$LAYOUT = (OfInt)$LAYOUT.select(groupElement("dwYSize"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * DWORD dwYSize+ * }+ */+ public static final OfInt dwYSize$layout() {+ return dwYSize$LAYOUT;+ }++ private static final long dwYSize$OFFSET = $LAYOUT.byteOffset(groupElement("dwYSize"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * DWORD dwYSize+ * }+ */+ public static final long dwYSize$offset() {+ return dwYSize$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * DWORD dwYSize+ * }+ */+ public static int dwYSize(MemorySegment struct) {+ return struct.get(dwYSize$LAYOUT, dwYSize$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * DWORD dwYSize+ * }+ */+ public static void dwYSize(MemorySegment struct, int fieldValue) {+ struct.set(dwYSize$LAYOUT, dwYSize$OFFSET, fieldValue);+ }++ private static final OfInt dwXCountChars$LAYOUT = (OfInt)$LAYOUT.select(groupElement("dwXCountChars"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * DWORD dwXCountChars+ * }+ */+ public static final OfInt dwXCountChars$layout() {+ return dwXCountChars$LAYOUT;+ }++ private static final long dwXCountChars$OFFSET = $LAYOUT.byteOffset(groupElement("dwXCountChars"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * DWORD dwXCountChars+ * }+ */+ public static final long dwXCountChars$offset() {+ return dwXCountChars$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * DWORD dwXCountChars+ * }+ */+ public static int dwXCountChars(MemorySegment struct) {+ return struct.get(dwXCountChars$LAYOUT, dwXCountChars$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * DWORD dwXCountChars+ * }+ */+ public static void dwXCountChars(MemorySegment struct, int fieldValue) {+ struct.set(dwXCountChars$LAYOUT, dwXCountChars$OFFSET, fieldValue);+ }++ private static final OfInt dwYCountChars$LAYOUT = (OfInt)$LAYOUT.select(groupElement("dwYCountChars"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * DWORD dwYCountChars+ * }+ */+ public static final OfInt dwYCountChars$layout() {+ return dwYCountChars$LAYOUT;+ }++ private static final long dwYCountChars$OFFSET = $LAYOUT.byteOffset(groupElement("dwYCountChars"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * DWORD dwYCountChars+ * }+ */+ public static final long dwYCountChars$offset() {+ return dwYCountChars$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * DWORD dwYCountChars+ * }+ */+ public static int dwYCountChars(MemorySegment struct) {+ return struct.get(dwYCountChars$LAYOUT, dwYCountChars$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * DWORD dwYCountChars+ * }+ */+ public static void dwYCountChars(MemorySegment struct, int fieldValue) {+ struct.set(dwYCountChars$LAYOUT, dwYCountChars$OFFSET, fieldValue);+ }++ private static final OfInt dwFillAttribute$LAYOUT = (OfInt)$LAYOUT.select(groupElement("dwFillAttribute"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * DWORD dwFillAttribute+ * }+ */+ public static final OfInt dwFillAttribute$layout() {+ return dwFillAttribute$LAYOUT;+ }++ private static final long dwFillAttribute$OFFSET = $LAYOUT.byteOffset(groupElement("dwFillAttribute"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * DWORD dwFillAttribute+ * }+ */+ public static final long dwFillAttribute$offset() {+ return dwFillAttribute$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * DWORD dwFillAttribute+ * }+ */+ public static int dwFillAttribute(MemorySegment struct) {+ return struct.get(dwFillAttribute$LAYOUT, dwFillAttribute$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * DWORD dwFillAttribute+ * }+ */+ public static void dwFillAttribute(MemorySegment struct, int fieldValue) {+ struct.set(dwFillAttribute$LAYOUT, dwFillAttribute$OFFSET, fieldValue);+ }++ private static final OfInt dwFlags$LAYOUT = (OfInt)$LAYOUT.select(groupElement("dwFlags"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * DWORD dwFlags+ * }+ */+ public static final OfInt dwFlags$layout() {+ return dwFlags$LAYOUT;+ }++ private static final long dwFlags$OFFSET = $LAYOUT.byteOffset(groupElement("dwFlags"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * DWORD dwFlags+ * }+ */+ public static final long dwFlags$offset() {+ return dwFlags$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * DWORD dwFlags+ * }+ */+ public static int dwFlags(MemorySegment struct) {+ return struct.get(dwFlags$LAYOUT, dwFlags$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * DWORD dwFlags+ * }+ */+ public static void dwFlags(MemorySegment struct, int fieldValue) {+ struct.set(dwFlags$LAYOUT, dwFlags$OFFSET, fieldValue);+ }++ private static final OfShort wShowWindow$LAYOUT = (OfShort)$LAYOUT.select(groupElement("wShowWindow"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * WORD wShowWindow+ * }+ */+ public static final OfShort wShowWindow$layout() {+ return wShowWindow$LAYOUT;+ }++ private static final long wShowWindow$OFFSET = $LAYOUT.byteOffset(groupElement("wShowWindow"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * WORD wShowWindow+ * }+ */+ public static final long wShowWindow$offset() {+ return wShowWindow$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * WORD wShowWindow+ * }+ */+ public static short wShowWindow(MemorySegment struct) {+ return struct.get(wShowWindow$LAYOUT, wShowWindow$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * WORD wShowWindow+ * }+ */+ public static void wShowWindow(MemorySegment struct, short fieldValue) {+ struct.set(wShowWindow$LAYOUT, wShowWindow$OFFSET, fieldValue);+ }++ private static final OfShort cbReserved2$LAYOUT = (OfShort)$LAYOUT.select(groupElement("cbReserved2"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * WORD cbReserved2+ * }+ */+ public static final OfShort cbReserved2$layout() {+ return cbReserved2$LAYOUT;+ }++ private static final long cbReserved2$OFFSET = $LAYOUT.byteOffset(groupElement("cbReserved2"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * WORD cbReserved2+ * }+ */+ public static final long cbReserved2$offset() {+ return cbReserved2$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * WORD cbReserved2+ * }+ */+ public static short cbReserved2(MemorySegment struct) {+ return struct.get(cbReserved2$LAYOUT, cbReserved2$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * WORD cbReserved2+ * }+ */+ public static void cbReserved2(MemorySegment struct, short fieldValue) {+ struct.set(cbReserved2$LAYOUT, cbReserved2$OFFSET, fieldValue);+ }++ private static final AddressLayout lpReserved2$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("lpReserved2"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * LPBYTE lpReserved2+ * }+ */+ public static final AddressLayout lpReserved2$layout() {+ return lpReserved2$LAYOUT;+ }++ private static final long lpReserved2$OFFSET = $LAYOUT.byteOffset(groupElement("lpReserved2"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * LPBYTE lpReserved2+ * }+ */+ public static final long lpReserved2$offset() {+ return lpReserved2$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * LPBYTE lpReserved2+ * }+ */+ public static MemorySegment lpReserved2(MemorySegment struct) {+ return struct.get(lpReserved2$LAYOUT, lpReserved2$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * LPBYTE lpReserved2+ * }+ */+ public static void lpReserved2(MemorySegment struct, MemorySegment fieldValue) {+ struct.set(lpReserved2$LAYOUT, lpReserved2$OFFSET, fieldValue);+ }++ private static final AddressLayout hStdInput$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("hStdInput"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * HANDLE hStdInput+ * }+ */+ public static final AddressLayout hStdInput$layout() {+ return hStdInput$LAYOUT;+ }++ private static final long hStdInput$OFFSET = $LAYOUT.byteOffset(groupElement("hStdInput"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * HANDLE hStdInput+ * }+ */+ public static final long hStdInput$offset() {+ return hStdInput$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * HANDLE hStdInput+ * }+ */+ public static MemorySegment hStdInput(MemorySegment struct) {+ return struct.get(hStdInput$LAYOUT, hStdInput$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * HANDLE hStdInput+ * }+ */+ public static void hStdInput(MemorySegment struct, MemorySegment fieldValue) {+ struct.set(hStdInput$LAYOUT, hStdInput$OFFSET, fieldValue);+ }++ private static final AddressLayout hStdOutput$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("hStdOutput"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * HANDLE hStdOutput+ * }+ */+ public static final AddressLayout hStdOutput$layout() {+ return hStdOutput$LAYOUT;+ }++ private static final long hStdOutput$OFFSET = $LAYOUT.byteOffset(groupElement("hStdOutput"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * HANDLE hStdOutput+ * }+ */+ public static final long hStdOutput$offset() {+ return hStdOutput$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * HANDLE hStdOutput+ * }+ */+ public static MemorySegment hStdOutput(MemorySegment struct) {+ return struct.get(hStdOutput$LAYOUT, hStdOutput$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * HANDLE hStdOutput+ * }+ */+ public static void hStdOutput(MemorySegment struct, MemorySegment fieldValue) {+ struct.set(hStdOutput$LAYOUT, hStdOutput$OFFSET, fieldValue);+ }++ private static final AddressLayout hStdError$LAYOUT = (AddressLayout)$LAYOUT.select(groupElement("hStdError"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * HANDLE hStdError+ * }+ */+ public static final AddressLayout hStdError$layout() {+ return hStdError$LAYOUT;+ }++ private static final long hStdError$OFFSET = $LAYOUT.byteOffset(groupElement("hStdError"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * HANDLE hStdError+ * }+ */+ public static final long hStdError$offset() {+ return hStdError$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * HANDLE hStdError+ * }+ */+ public static MemorySegment hStdError(MemorySegment struct) {+ return struct.get(hStdError$LAYOUT, hStdError$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * HANDLE hStdError+ * }+ */+ public static void hStdError(MemorySegment struct, MemorySegment fieldValue) {+ struct.set(hStdError$LAYOUT, hStdError$OFFSET, fieldValue);+ }++ /**+ * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}.+ * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()}+ */+ public static MemorySegment asSlice(MemorySegment array, long index) {+ return array.asSlice(layout().byteSize() * index);+ }++ /**+ * The size (in bytes) of this struct+ */+ public static long sizeof() { return layout().byteSize(); }++ /**+ * Allocate a segment of size {@code layout().byteSize()} using {@code allocator}+ */+ public static MemorySegment allocate(SegmentAllocator allocator) {+ return allocator.allocate(layout());+ }++ /**+ * Allocate an array of size {@code elementCount} using {@code allocator}.+ * The returned segment has size {@code elementCount * layout().byteSize()}.+ */+ public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) {+ return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout()));+ }++ /**+ * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).+ * The returned segment has size {@code layout().byteSize()}+ */+ public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer<MemorySegment> cleanup) {+ return reinterpret(addr, 1, arena, cleanup);+ }++ /**+ * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).+ * The returned segment has size {@code elementCount * layout().byteSize()}+ */+ public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer<MemorySegment> cleanup) {+ return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup);+ }+}+diff --git a/Ghidra/Framework/Pty/src/main/java/com/microsoft/win32/win32_h$shared.java b/Ghidra/Framework/Pty/src/main/java/com/microsoft/win32/win32_h$shared.javanew file mode 100644index 0000000000..a2456f9220--- /dev/null+++ b/Ghidra/Framework/Pty/src/main/java/com/microsoft/win32/win32_h$shared.java@@ -0,0 +1,79 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+// Generated by jextract++package com.microsoft.win32;++import java.lang.invoke.*;+import java.lang.foreign.*;+import java.nio.ByteOrder;+import java.util.*;+import java.util.function.*;+import java.util.stream.*;++import static java.lang.foreign.ValueLayout.*;+import static java.lang.foreign.MemoryLayout.PathElement.*;++public class win32_h$shared {++ win32_h$shared() {+ // Should not be called directly+ }++ public static final ValueLayout.OfBoolean C_BOOL = (ValueLayout.OfBoolean) Linker.nativeLinker().canonicalLayouts().get("bool");+ public static final ValueLayout.OfByte C_CHAR =(ValueLayout.OfByte)Linker.nativeLinker().canonicalLayouts().get("char");+ public static final ValueLayout.OfShort C_SHORT = (ValueLayout.OfShort) Linker.nativeLinker().canonicalLayouts().get("short");+ public static final ValueLayout.OfInt C_INT = (ValueLayout.OfInt) Linker.nativeLinker().canonicalLayouts().get("int");+ public static final ValueLayout.OfLong C_LONG_LONG = (ValueLayout.OfLong) Linker.nativeLinker().canonicalLayouts().get("long long");+ public static final ValueLayout.OfFloat C_FLOAT = (ValueLayout.OfFloat) Linker.nativeLinker().canonicalLayouts().get("float");+ public static final ValueLayout.OfDouble C_DOUBLE = (ValueLayout.OfDouble) Linker.nativeLinker().canonicalLayouts().get("double");+ public static final AddressLayout C_POINTER = ((AddressLayout) Linker.nativeLinker().canonicalLayouts().get("void*"))+ .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, C_CHAR));+ public static final ValueLayout.OfInt C_LONG = (ValueLayout.OfInt) Linker.nativeLinker().canonicalLayouts().get("long");+ public static final ValueLayout.OfDouble C_LONG_DOUBLE = (ValueLayout.OfDouble) Linker.nativeLinker().canonicalLayouts().get("double");++ static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls");++ static void traceDowncall(String name, Object... args) {+ String traceArgs = Arrays.stream(args)+ .map(Object::toString)+ .collect(Collectors.joining(", "));+ System.out.printf("%s(%s)\n", name, traceArgs);+ }++ static MethodHandle upcallHandle(Class<?> fi, String name, FunctionDescriptor fdesc) {+ try {+ return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType());+ } catch (ReflectiveOperationException ex) {+ throw new AssertionError(ex);+ }+ }++ static MemoryLayout align(MemoryLayout layout, long align) {+ return switch (layout) {+ case PaddingLayout p -> p;+ case ValueLayout v -> v.withByteAlignment(align);+ case GroupLayout g -> {+ MemoryLayout[] alignedMembers = g.memberLayouts().stream()+ .map(m -> align(m, align)).toArray(MemoryLayout[]::new);+ yield g instanceof StructLayout ?+ MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers);+ }+ case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align));+ };+ }+}+diff --git a/Ghidra/Framework/Pty/src/main/java/com/microsoft/win32/win32_h.java b/Ghidra/Framework/Pty/src/main/java/com/microsoft/win32/win32_h.javanew file mode 100644index 0000000000..4cfb87c9d1--- /dev/null+++ b/Ghidra/Framework/Pty/src/main/java/com/microsoft/win32/win32_h.java@@ -0,0 +1,1412 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+// Generated by jextract++package com.microsoft.win32;++import java.lang.invoke.*;+import java.lang.foreign.*;+import java.nio.ByteOrder;+import java.util.*;+import java.util.function.*;+import java.util.stream.*;++import ghidra.pty.windows.Win32Err;++import static java.lang.foreign.ValueLayout.*;+import static java.lang.foreign.MemoryLayout.PathElement.*;++public class win32_h extends win32_h$shared {++ win32_h() {+ // Should not be called directly+ }++ static final Arena LIBRARY_ARENA = Arena.ofAuto();+ static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.libraryLookup(System.mapLibraryName("Kernel32"), LIBRARY_ARENA)+ .or(SymbolLookup.loaderLookup())+ .or(Linker.nativeLinker().defaultLookup());++ private static final int CREATE_UNICODE_ENVIRONMENT = (int)1024L;+ /**+ * {@snippet lang=c :+ * #define CREATE_UNICODE_ENVIRONMENT 1024+ * }+ */+ public static int CREATE_UNICODE_ENVIRONMENT() {+ return CREATE_UNICODE_ENVIRONMENT;+ }+ private static final int EXTENDED_STARTUPINFO_PRESENT = (int)524288L;+ /**+ * {@snippet lang=c :+ * #define EXTENDED_STARTUPINFO_PRESENT 524288+ * }+ */+ public static int EXTENDED_STARTUPINFO_PRESENT() {+ return EXTENDED_STARTUPINFO_PRESENT;+ }+ private static final int FORMAT_MESSAGE_ALLOCATE_BUFFER = (int)256L;+ /**+ * {@snippet lang=c :+ * #define FORMAT_MESSAGE_ALLOCATE_BUFFER 256+ * }+ */+ public static int FORMAT_MESSAGE_ALLOCATE_BUFFER() {+ return FORMAT_MESSAGE_ALLOCATE_BUFFER;+ }+ private static final int FORMAT_MESSAGE_IGNORE_INSERTS = (int)512L;+ /**+ * {@snippet lang=c :+ * #define FORMAT_MESSAGE_IGNORE_INSERTS 512+ * }+ */+ public static int FORMAT_MESSAGE_IGNORE_INSERTS() {+ return FORMAT_MESSAGE_IGNORE_INSERTS;+ }+ private static final int FORMAT_MESSAGE_FROM_SYSTEM = (int)4096L;+ /**+ * {@snippet lang=c :+ * #define FORMAT_MESSAGE_FROM_SYSTEM 4096+ * }+ */+ public static int FORMAT_MESSAGE_FROM_SYSTEM() {+ return FORMAT_MESSAGE_FROM_SYSTEM;+ }+ private static final int FORMAT_MESSAGE_ARGUMENT_ARRAY = (int)8192L;+ /**+ * {@snippet lang=c :+ * #define FORMAT_MESSAGE_ARGUMENT_ARRAY 8192+ * }+ */+ public static int FORMAT_MESSAGE_ARGUMENT_ARRAY() {+ return FORMAT_MESSAGE_ARGUMENT_ARRAY;+ }+ private static final int STARTF_USESTDHANDLES = (int)256L;+ /**+ * {@snippet lang=c :+ * #define STARTF_USESTDHANDLES 256+ * }+ */+ public static int STARTF_USESTDHANDLES() {+ return STARTF_USESTDHANDLES;+ }+ /**+ * {@snippet lang=c :+ * typedef unsigned long DWORD+ * }+ */+ public static final OfInt DWORD = win32_h.C_LONG;+ /**+ * {@snippet lang=c :+ * typedef unsigned int UINT+ * }+ */+ public static final OfInt UINT = win32_h.C_INT;+ /**+ * {@snippet lang=c :+ * typedef WCHAR *LPWSTR+ * }+ */+ public static final AddressLayout LPWSTR = win32_h.C_POINTER;+ /**+ * {@snippet lang=c :+ * typedef void *HANDLE+ * }+ */+ public static final AddressLayout HANDLE = win32_h.C_POINTER;+ /**+ * {@snippet lang=c :+ * typedef long HRESULT+ * }+ */+ public static final OfInt HRESULT = win32_h.C_LONG;++ private static class FlushFileBuffers {+ public static final FunctionDescriptor DESC = FunctionDescriptor.of(+ win32_h.C_INT,+ win32_h.C_POINTER+ );++ public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("FlushFileBuffers");++ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC, Win32Err.OPT_CAPTURE_LASTERROR);+ }++ /**+ * Function descriptor for:+ * {@snippet lang=c :+ * BOOL FlushFileBuffers(HANDLE hFile)+ * }+ */+ public static FunctionDescriptor FlushFileBuffers$descriptor() {+ return FlushFileBuffers.DESC;+ }++ /**+ * Downcall method handle for:+ * {@snippet lang=c :+ * BOOL FlushFileBuffers(HANDLE hFile)+ * }+ */+ public static MethodHandle FlushFileBuffers$handle() {+ return FlushFileBuffers.HANDLE;+ }++ /**+ * Address for:+ * {@snippet lang=c :+ * BOOL FlushFileBuffers(HANDLE hFile)+ * }+ */+ public static MemorySegment FlushFileBuffers$address() {+ return FlushFileBuffers.ADDR;+ }++ /**+ * {@snippet lang=c :+ * BOOL FlushFileBuffers(HANDLE hFile)+ * }+ */+ public static int FlushFileBuffers(MemorySegment cs, MemorySegment hFile) {+ var mh$ = FlushFileBuffers.HANDLE;+ try {+ if (TRACE_DOWNCALLS) {+ traceDowncall("FlushFileBuffers", hFile);+ }+ return (int)mh$.invokeExact(cs, hFile);+ } catch (Error | RuntimeException ex) {+ throw ex;+ } catch (Throwable ex$) {+ throw new AssertionError("should not reach here", ex$);+ }+ }++ private static class ReadFile {+ public static final FunctionDescriptor DESC = FunctionDescriptor.of(+ win32_h.C_INT,+ win32_h.C_POINTER,+ win32_h.C_POINTER,+ win32_h.C_LONG,+ win32_h.C_POINTER,+ win32_h.C_POINTER+ );++ public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("ReadFile");++ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC, Win32Err.OPT_CAPTURE_LASTERROR);+ }++ /**+ * Function descriptor for:+ * {@snippet lang=c :+ * BOOL ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped)+ * }+ */+ public static FunctionDescriptor ReadFile$descriptor() {+ return ReadFile.DESC;+ }++ /**+ * Downcall method handle for:+ * {@snippet lang=c :+ * BOOL ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped)+ * }+ */+ public static MethodHandle ReadFile$handle() {+ return ReadFile.HANDLE;+ }++ /**+ * Address for:+ * {@snippet lang=c :+ * BOOL ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped)+ * }+ */+ public static MemorySegment ReadFile$address() {+ return ReadFile.ADDR;+ }++ /**+ * {@snippet lang=c :+ * BOOL ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped)+ * }+ */+ public static int ReadFile(MemorySegment cs, MemorySegment hFile, MemorySegment lpBuffer, int nNumberOfBytesToRead, MemorySegment lpNumberOfBytesRead, MemorySegment lpOverlapped) {+ var mh$ = ReadFile.HANDLE;+ try {+ if (TRACE_DOWNCALLS) {+ traceDowncall("ReadFile", hFile, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead, lpOverlapped);+ }+ return (int)mh$.invokeExact(cs, hFile, lpBuffer, nNumberOfBytesToRead, lpNumberOfBytesRead, lpOverlapped);+ } catch (Error | RuntimeException ex) {+ throw ex;+ } catch (Throwable ex$) {+ throw new AssertionError("should not reach here", ex$);+ }+ }++ private static class WriteFile {+ public static final FunctionDescriptor DESC = FunctionDescriptor.of(+ win32_h.C_INT,+ win32_h.C_POINTER,+ win32_h.C_POINTER,+ win32_h.C_LONG,+ win32_h.C_POINTER,+ win32_h.C_POINTER+ );++ public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("WriteFile");++ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC, Win32Err.OPT_CAPTURE_LASTERROR);+ }++ /**+ * Function descriptor for:+ * {@snippet lang=c :+ * BOOL WriteFile(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped)+ * }+ */+ public static FunctionDescriptor WriteFile$descriptor() {+ return WriteFile.DESC;+ }++ /**+ * Downcall method handle for:+ * {@snippet lang=c :+ * BOOL WriteFile(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped)+ * }+ */+ public static MethodHandle WriteFile$handle() {+ return WriteFile.HANDLE;+ }++ /**+ * Address for:+ * {@snippet lang=c :+ * BOOL WriteFile(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped)+ * }+ */+ public static MemorySegment WriteFile$address() {+ return WriteFile.ADDR;+ }++ /**+ * {@snippet lang=c :+ * BOOL WriteFile(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped)+ * }+ */+ public static int WriteFile(MemorySegment cs, MemorySegment hFile, MemorySegment lpBuffer, int nNumberOfBytesToWrite, MemorySegment lpNumberOfBytesWritten, MemorySegment lpOverlapped) {+ var mh$ = WriteFile.HANDLE;+ try {+ if (TRACE_DOWNCALLS) {+ traceDowncall("WriteFile", hFile, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten, lpOverlapped);+ }+ return (int)mh$.invokeExact(cs, hFile, lpBuffer, nNumberOfBytesToWrite, lpNumberOfBytesWritten, lpOverlapped);+ } catch (Error | RuntimeException ex) {+ throw ex;+ } catch (Throwable ex$) {+ throw new AssertionError("should not reach here", ex$);+ }+ }++ private static class CloseHandle {+ public static final FunctionDescriptor DESC = FunctionDescriptor.of(+ win32_h.C_INT,+ win32_h.C_POINTER+ );++ public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("CloseHandle");++ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC, Win32Err.OPT_CAPTURE_LASTERROR);+ }++ /**+ * Function descriptor for:+ * {@snippet lang=c :+ * BOOL CloseHandle(HANDLE hObject)+ * }+ */+ public static FunctionDescriptor CloseHandle$descriptor() {+ return CloseHandle.DESC;+ }++ /**+ * Downcall method handle for:+ * {@snippet lang=c :+ * BOOL CloseHandle(HANDLE hObject)+ * }+ */+ public static MethodHandle CloseHandle$handle() {+ return CloseHandle.HANDLE;+ }++ /**+ * Address for:+ * {@snippet lang=c :+ * BOOL CloseHandle(HANDLE hObject)+ * }+ */+ public static MemorySegment CloseHandle$address() {+ return CloseHandle.ADDR;+ }++ /**+ * {@snippet lang=c :+ * BOOL CloseHandle(HANDLE hObject)+ * }+ */+ public static int CloseHandle(MemorySegment cs, MemorySegment hObject) {+ var mh$ = CloseHandle.HANDLE;+ try {+ if (TRACE_DOWNCALLS) {+ traceDowncall("CloseHandle", hObject);+ }+ return (int)mh$.invokeExact(cs, hObject);+ } catch (Error | RuntimeException ex) {+ throw ex;+ } catch (Throwable ex$) {+ throw new AssertionError("should not reach here", ex$);+ }+ }++ private static class CreatePipe {+ public static final FunctionDescriptor DESC = FunctionDescriptor.of(+ win32_h.C_INT,+ win32_h.C_POINTER,+ win32_h.C_POINTER,+ win32_h.C_POINTER,+ win32_h.C_LONG+ );++ public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("CreatePipe");++ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC, Win32Err.OPT_CAPTURE_LASTERROR);+ }++ /**+ * Function descriptor for:+ * {@snippet lang=c :+ * BOOL CreatePipe(PHANDLE hReadPipe, PHANDLE hWritePipe, LPSECURITY_ATTRIBUTES lpPipeAttributes, DWORD nSize)+ * }+ */+ public static FunctionDescriptor CreatePipe$descriptor() {+ return CreatePipe.DESC;+ }++ /**+ * Downcall method handle for:+ * {@snippet lang=c :+ * BOOL CreatePipe(PHANDLE hReadPipe, PHANDLE hWritePipe, LPSECURITY_ATTRIBUTES lpPipeAttributes, DWORD nSize)+ * }+ */+ public static MethodHandle CreatePipe$handle() {+ return CreatePipe.HANDLE;+ }++ /**+ * Address for:+ * {@snippet lang=c :+ * BOOL CreatePipe(PHANDLE hReadPipe, PHANDLE hWritePipe, LPSECURITY_ATTRIBUTES lpPipeAttributes, DWORD nSize)+ * }+ */+ public static MemorySegment CreatePipe$address() {+ return CreatePipe.ADDR;+ }++ /**+ * {@snippet lang=c :+ * BOOL CreatePipe(PHANDLE hReadPipe, PHANDLE hWritePipe, LPSECURITY_ATTRIBUTES lpPipeAttributes, DWORD nSize)+ * }+ */+ public static int CreatePipe(MemorySegment cs, MemorySegment hReadPipe, MemorySegment hWritePipe, MemorySegment lpPipeAttributes, int nSize) {+ var mh$ = CreatePipe.HANDLE;+ try {+ if (TRACE_DOWNCALLS) {+ traceDowncall("CreatePipe", hReadPipe, hWritePipe, lpPipeAttributes, nSize);+ }+ return (int)mh$.invokeExact(cs, hReadPipe, hWritePipe, lpPipeAttributes, nSize);+ } catch (Error | RuntimeException ex) {+ throw ex;+ } catch (Throwable ex$) {+ throw new AssertionError("should not reach here", ex$);+ }+ }++ private static class ConnectNamedPipe {+ public static final FunctionDescriptor DESC = FunctionDescriptor.of(+ win32_h.C_INT,+ win32_h.C_POINTER,+ win32_h.C_POINTER+ );++ public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("ConnectNamedPipe");++ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC, Win32Err.OPT_CAPTURE_LASTERROR);+ }++ /**+ * Function descriptor for:+ * {@snippet lang=c :+ * BOOL ConnectNamedPipe(HANDLE hNamedPipe, LPOVERLAPPED lpOverlapped)+ * }+ */+ public static FunctionDescriptor ConnectNamedPipe$descriptor() {+ return ConnectNamedPipe.DESC;+ }++ /**+ * Downcall method handle for:+ * {@snippet lang=c :+ * BOOL ConnectNamedPipe(HANDLE hNamedPipe, LPOVERLAPPED lpOverlapped)+ * }+ */+ public static MethodHandle ConnectNamedPipe$handle() {+ return ConnectNamedPipe.HANDLE;+ }++ /**+ * Address for:+ * {@snippet lang=c :+ * BOOL ConnectNamedPipe(HANDLE hNamedPipe, LPOVERLAPPED lpOverlapped)+ * }+ */+ public static MemorySegment ConnectNamedPipe$address() {+ return ConnectNamedPipe.ADDR;+ }++ /**+ * {@snippet lang=c :+ * BOOL ConnectNamedPipe(HANDLE hNamedPipe, LPOVERLAPPED lpOverlapped)+ * }+ */+ public static int ConnectNamedPipe(MemorySegment cs, MemorySegment hNamedPipe, MemorySegment lpOverlapped) {+ var mh$ = ConnectNamedPipe.HANDLE;+ try {+ if (TRACE_DOWNCALLS) {+ traceDowncall("ConnectNamedPipe", hNamedPipe, lpOverlapped);+ }+ return (int)mh$.invokeExact(cs, hNamedPipe, lpOverlapped);+ } catch (Error | RuntimeException ex) {+ throw ex;+ } catch (Throwable ex$) {+ throw new AssertionError("should not reach here", ex$);+ }+ }++ private static class WaitForSingleObject {+ public static final FunctionDescriptor DESC = FunctionDescriptor.of(+ win32_h.C_LONG,+ win32_h.C_POINTER,+ win32_h.C_LONG+ );++ public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("WaitForSingleObject");++ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC, Win32Err.OPT_CAPTURE_LASTERROR);+ }++ /**+ * Function descriptor for:+ * {@snippet lang=c :+ * DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds)+ * }+ */+ public static FunctionDescriptor WaitForSingleObject$descriptor() {+ return WaitForSingleObject.DESC;+ }++ /**+ * Downcall method handle for:+ * {@snippet lang=c :+ * DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds)+ * }+ */+ public static MethodHandle WaitForSingleObject$handle() {+ return WaitForSingleObject.HANDLE;+ }++ /**+ * Address for:+ * {@snippet lang=c :+ * DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds)+ * }+ */+ public static MemorySegment WaitForSingleObject$address() {+ return WaitForSingleObject.ADDR;+ }++ /**+ * {@snippet lang=c :+ * DWORD WaitForSingleObject(HANDLE hHandle, DWORD dwMilliseconds)+ * }+ */+ public static int WaitForSingleObject(MemorySegment cs, MemorySegment hHandle, int dwMilliseconds) {+ var mh$ = WaitForSingleObject.HANDLE;+ try {+ if (TRACE_DOWNCALLS) {+ traceDowncall("WaitForSingleObject", hHandle, dwMilliseconds);+ }+ return (int)mh$.invokeExact(cs, hHandle, dwMilliseconds);+ } catch (Error | RuntimeException ex) {+ throw ex;+ } catch (Throwable ex$) {+ throw new AssertionError("should not reach here", ex$);+ }+ }++ private static class GetExitCodeProcess {+ public static final FunctionDescriptor DESC = FunctionDescriptor.of(+ win32_h.C_INT,+ win32_h.C_POINTER,+ win32_h.C_POINTER+ );++ public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("GetExitCodeProcess");++ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC, Win32Err.OPT_CAPTURE_LASTERROR);+ }++ /**+ * Function descriptor for:+ * {@snippet lang=c :+ * BOOL GetExitCodeProcess(HANDLE hProcess, LPDWORD lpExitCode)+ * }+ */+ public static FunctionDescriptor GetExitCodeProcess$descriptor() {+ return GetExitCodeProcess.DESC;+ }++ /**+ * Downcall method handle for:+ * {@snippet lang=c :+ * BOOL GetExitCodeProcess(HANDLE hProcess, LPDWORD lpExitCode)+ * }+ */+ public static MethodHandle GetExitCodeProcess$handle() {+ return GetExitCodeProcess.HANDLE;+ }++ /**+ * Address for:+ * {@snippet lang=c :+ * BOOL GetExitCodeProcess(HANDLE hProcess, LPDWORD lpExitCode)+ * }+ */+ public static MemorySegment GetExitCodeProcess$address() {+ return GetExitCodeProcess.ADDR;+ }++ /**+ * {@snippet lang=c :+ * BOOL GetExitCodeProcess(HANDLE hProcess, LPDWORD lpExitCode)+ * }+ */+ public static int GetExitCodeProcess(MemorySegment cs, MemorySegment hProcess, MemorySegment lpExitCode) {+ var mh$ = GetExitCodeProcess.HANDLE;+ try {+ if (TRACE_DOWNCALLS) {+ traceDowncall("GetExitCodeProcess", hProcess, lpExitCode);+ }+ return (int)mh$.invokeExact(cs, hProcess, lpExitCode);+ } catch (Error | RuntimeException ex) {+ throw ex;+ } catch (Throwable ex$) {+ throw new AssertionError("should not reach here", ex$);+ }+ }++ private static class CreateProcessW {+ public static final FunctionDescriptor DESC = FunctionDescriptor.of(+ win32_h.C_INT,+ win32_h.C_POINTER,+ win32_h.C_POINTER,+ win32_h.C_POINTER,+ win32_h.C_POINTER,+ win32_h.C_INT,+ win32_h.C_LONG,+ win32_h.C_POINTER,+ win32_h.C_POINTER,+ win32_h.C_POINTER,+ win32_h.C_POINTER+ );++ public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("CreateProcessW");++ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC, Win32Err.OPT_CAPTURE_LASTERROR);+ }++ /**+ * Function descriptor for:+ * {@snippet lang=c :+ * BOOL CreateProcessW(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)+ * }+ */+ public static FunctionDescriptor CreateProcessW$descriptor() {+ return CreateProcessW.DESC;+ }++ /**+ * Downcall method handle for:+ * {@snippet lang=c :+ * BOOL CreateProcessW(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)+ * }+ */+ public static MethodHandle CreateProcessW$handle() {+ return CreateProcessW.HANDLE;+ }++ /**+ * Address for:+ * {@snippet lang=c :+ * BOOL CreateProcessW(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)+ * }+ */+ public static MemorySegment CreateProcessW$address() {+ return CreateProcessW.ADDR;+ }++ /**+ * {@snippet lang=c :+ * BOOL CreateProcessW(LPCWSTR lpApplicationName, LPWSTR lpCommandLine, LPSECURITY_ATTRIBUTES lpProcessAttributes, LPSECURITY_ATTRIBUTES lpThreadAttributes, BOOL bInheritHandles, DWORD dwCreationFlags, LPVOID lpEnvironment, LPCWSTR lpCurrentDirectory, LPSTARTUPINFOW lpStartupInfo, LPPROCESS_INFORMATION lpProcessInformation)+ * }+ */+ public static int CreateProcessW(MemorySegment cs, MemorySegment lpApplicationName, MemorySegment lpCommandLine, MemorySegment lpProcessAttributes, MemorySegment lpThreadAttributes, int bInheritHandles, int dwCreationFlags, MemorySegment lpEnvironment, MemorySegment lpCurrentDirectory, MemorySegment lpStartupInfo, MemorySegment lpProcessInformation) {+ var mh$ = CreateProcessW.HANDLE;+ try {+ if (TRACE_DOWNCALLS) {+ traceDowncall("CreateProcessW", lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation);+ }+ return (int)mh$.invokeExact(cs, lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation);+ } catch (Error | RuntimeException ex) {+ throw ex;+ } catch (Throwable ex$) {+ throw new AssertionError("should not reach here", ex$);+ }+ }++ private static class InitializeProcThreadAttributeList {+ public static final FunctionDescriptor DESC = FunctionDescriptor.of(+ win32_h.C_INT,+ win32_h.C_POINTER,+ win32_h.C_LONG,+ win32_h.C_LONG,+ win32_h.C_POINTER+ );++ public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("InitializeProcThreadAttributeList");++ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC, Win32Err.OPT_CAPTURE_LASTERROR);+ }++ /**+ * Function descriptor for:+ * {@snippet lang=c :+ * BOOL InitializeProcThreadAttributeList(LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList, DWORD dwAttributeCount, DWORD dwFlags, PSIZE_T lpSize)+ * }+ */+ public static FunctionDescriptor InitializeProcThreadAttributeList$descriptor() {+ return InitializeProcThreadAttributeList.DESC;+ }++ /**+ * Downcall method handle for:+ * {@snippet lang=c :+ * BOOL InitializeProcThreadAttributeList(LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList, DWORD dwAttributeCount, DWORD dwFlags, PSIZE_T lpSize)+ * }+ */+ public static MethodHandle InitializeProcThreadAttributeList$handle() {+ return InitializeProcThreadAttributeList.HANDLE;+ }++ /**+ * Address for:+ * {@snippet lang=c :+ * BOOL InitializeProcThreadAttributeList(LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList, DWORD dwAttributeCount, DWORD dwFlags, PSIZE_T lpSize)+ * }+ */+ public static MemorySegment InitializeProcThreadAttributeList$address() {+ return InitializeProcThreadAttributeList.ADDR;+ }++ /**+ * {@snippet lang=c :+ * BOOL InitializeProcThreadAttributeList(LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList, DWORD dwAttributeCount, DWORD dwFlags, PSIZE_T lpSize)+ * }+ */+ public static int InitializeProcThreadAttributeList(MemorySegment cs, MemorySegment lpAttributeList, int dwAttributeCount, int dwFlags, MemorySegment lpSize) {+ var mh$ = InitializeProcThreadAttributeList.HANDLE;+ try {+ if (TRACE_DOWNCALLS) {+ traceDowncall("InitializeProcThreadAttributeList", lpAttributeList, dwAttributeCount, dwFlags, lpSize);+ }+ return (int)mh$.invokeExact(cs, lpAttributeList, dwAttributeCount, dwFlags, lpSize);+ } catch (Error | RuntimeException ex) {+ throw ex;+ } catch (Throwable ex$) {+ throw new AssertionError("should not reach here", ex$);+ }+ }++ private static class UpdateProcThreadAttribute {+ public static final FunctionDescriptor DESC = FunctionDescriptor.of(+ win32_h.C_INT,+ win32_h.C_POINTER,+ win32_h.C_LONG,+ win32_h.C_LONG_LONG,+ win32_h.C_POINTER,+ win32_h.C_LONG_LONG,+ win32_h.C_POINTER,+ win32_h.C_POINTER+ );++ public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("UpdateProcThreadAttribute");++ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC, Win32Err.OPT_CAPTURE_LASTERROR);+ }++ /**+ * Function descriptor for:+ * {@snippet lang=c :+ * BOOL UpdateProcThreadAttribute(LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList, DWORD dwFlags, DWORD_PTR Attribute, PVOID lpValue, SIZE_T cbSize, PVOID lpPreviousValue, PSIZE_T lpReturnSize)+ * }+ */+ public static FunctionDescriptor UpdateProcThreadAttribute$descriptor() {+ return UpdateProcThreadAttribute.DESC;+ }++ /**+ * Downcall method handle for:+ * {@snippet lang=c :+ * BOOL UpdateProcThreadAttribute(LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList, DWORD dwFlags, DWORD_PTR Attribute, PVOID lpValue, SIZE_T cbSize, PVOID lpPreviousValue, PSIZE_T lpReturnSize)+ * }+ */+ public static MethodHandle UpdateProcThreadAttribute$handle() {+ return UpdateProcThreadAttribute.HANDLE;+ }++ /**+ * Address for:+ * {@snippet lang=c :+ * BOOL UpdateProcThreadAttribute(LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList, DWORD dwFlags, DWORD_PTR Attribute, PVOID lpValue, SIZE_T cbSize, PVOID lpPreviousValue, PSIZE_T lpReturnSize)+ * }+ */+ public static MemorySegment UpdateProcThreadAttribute$address() {+ return UpdateProcThreadAttribute.ADDR;+ }++ /**+ * {@snippet lang=c :+ * BOOL UpdateProcThreadAttribute(LPPROC_THREAD_ATTRIBUTE_LIST lpAttributeList, DWORD dwFlags, DWORD_PTR Attribute, PVOID lpValue, SIZE_T cbSize, PVOID lpPreviousValue, PSIZE_T lpReturnSize)+ * }+ */+ public static int UpdateProcThreadAttribute(MemorySegment cs, MemorySegment lpAttributeList, int dwFlags, long Attribute, MemorySegment lpValue, long cbSize, MemorySegment lpPreviousValue, MemorySegment lpReturnSize) {+ var mh$ = UpdateProcThreadAttribute.HANDLE;+ try {+ if (TRACE_DOWNCALLS) {+ traceDowncall("UpdateProcThreadAttribute", lpAttributeList, dwFlags, Attribute, lpValue, cbSize, lpPreviousValue, lpReturnSize);+ }+ return (int)mh$.invokeExact(cs, lpAttributeList, dwFlags, Attribute, lpValue, cbSize, lpPreviousValue, lpReturnSize);+ } catch (Error | RuntimeException ex) {+ throw ex;+ } catch (Throwable ex$) {+ throw new AssertionError("should not reach here", ex$);+ }+ }++ private static class CreateJobObjectW {+ public static final FunctionDescriptor DESC = FunctionDescriptor.of(+ win32_h.C_POINTER,+ win32_h.C_POINTER,+ win32_h.C_POINTER+ );++ public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("CreateJobObjectW");++ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC, Win32Err.OPT_CAPTURE_LASTERROR);+ }++ /**+ * Function descriptor for:+ * {@snippet lang=c :+ * HANDLE CreateJobObjectW(LPSECURITY_ATTRIBUTES lpJobAttributes, LPCWSTR lpName)+ * }+ */+ public static FunctionDescriptor CreateJobObjectW$descriptor() {+ return CreateJobObjectW.DESC;+ }++ /**+ * Downcall method handle for:+ * {@snippet lang=c :+ * HANDLE CreateJobObjectW(LPSECURITY_ATTRIBUTES lpJobAttributes, LPCWSTR lpName)+ * }+ */+ public static MethodHandle CreateJobObjectW$handle() {+ return CreateJobObjectW.HANDLE;+ }++ /**+ * Address for:+ * {@snippet lang=c :+ * HANDLE CreateJobObjectW(LPSECURITY_ATTRIBUTES lpJobAttributes, LPCWSTR lpName)+ * }+ */+ public static MemorySegment CreateJobObjectW$address() {+ return CreateJobObjectW.ADDR;+ }++ /**+ * {@snippet lang=c :+ * HANDLE CreateJobObjectW(LPSECURITY_ATTRIBUTES lpJobAttributes, LPCWSTR lpName)+ * }+ */+ public static MemorySegment CreateJobObjectW(MemorySegment cs, MemorySegment lpJobAttributes, MemorySegment lpName) {+ var mh$ = CreateJobObjectW.HANDLE;+ try {+ if (TRACE_DOWNCALLS) {+ traceDowncall("CreateJobObjectW", lpJobAttributes, lpName);+ }+ return (MemorySegment)mh$.invokeExact(cs, lpJobAttributes, lpName);+ } catch (Error | RuntimeException ex) {+ throw ex;+ } catch (Throwable ex$) {+ throw new AssertionError("should not reach here", ex$);+ }+ }++ private static class AssignProcessToJobObject {+ public static final FunctionDescriptor DESC = FunctionDescriptor.of(+ win32_h.C_INT,+ win32_h.C_POINTER,+ win32_h.C_POINTER+ );++ public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("AssignProcessToJobObject");++ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC, Win32Err.OPT_CAPTURE_LASTERROR);+ }++ /**+ * Function descriptor for:+ * {@snippet lang=c :+ * BOOL AssignProcessToJobObject(HANDLE hJob, HANDLE hProcess)+ * }+ */+ public static FunctionDescriptor AssignProcessToJobObject$descriptor() {+ return AssignProcessToJobObject.DESC;+ }++ /**+ * Downcall method handle for:+ * {@snippet lang=c :+ * BOOL AssignProcessToJobObject(HANDLE hJob, HANDLE hProcess)+ * }+ */+ public static MethodHandle AssignProcessToJobObject$handle() {+ return AssignProcessToJobObject.HANDLE;+ }++ /**+ * Address for:+ * {@snippet lang=c :+ * BOOL AssignProcessToJobObject(HANDLE hJob, HANDLE hProcess)+ * }+ */+ public static MemorySegment AssignProcessToJobObject$address() {+ return AssignProcessToJobObject.ADDR;+ }++ /**+ * {@snippet lang=c :+ * BOOL AssignProcessToJobObject(HANDLE hJob, HANDLE hProcess)+ * }+ */+ public static int AssignProcessToJobObject(MemorySegment cs, MemorySegment hJob, MemorySegment hProcess) {+ var mh$ = AssignProcessToJobObject.HANDLE;+ try {+ if (TRACE_DOWNCALLS) {+ traceDowncall("AssignProcessToJobObject", hJob, hProcess);+ }+ return (int)mh$.invokeExact(cs, hJob, hProcess);+ } catch (Error | RuntimeException ex) {+ throw ex;+ } catch (Throwable ex$) {+ throw new AssertionError("should not reach here", ex$);+ }+ }++ private static class TerminateJobObject {+ public static final FunctionDescriptor DESC = FunctionDescriptor.of(+ win32_h.C_INT,+ win32_h.C_POINTER,+ win32_h.C_INT+ );++ public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("TerminateJobObject");++ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC, Win32Err.OPT_CAPTURE_LASTERROR);+ }++ /**+ * Function descriptor for:+ * {@snippet lang=c :+ * BOOL TerminateJobObject(HANDLE hJob, UINT uExitCode)+ * }+ */+ public static FunctionDescriptor TerminateJobObject$descriptor() {+ return TerminateJobObject.DESC;+ }++ /**+ * Downcall method handle for:+ * {@snippet lang=c :+ * BOOL TerminateJobObject(HANDLE hJob, UINT uExitCode)+ * }+ */+ public static MethodHandle TerminateJobObject$handle() {+ return TerminateJobObject.HANDLE;+ }++ /**+ * Address for:+ * {@snippet lang=c :+ * BOOL TerminateJobObject(HANDLE hJob, UINT uExitCode)+ * }+ */+ public static MemorySegment TerminateJobObject$address() {+ return TerminateJobObject.ADDR;+ }++ /**+ * {@snippet lang=c :+ * BOOL TerminateJobObject(HANDLE hJob, UINT uExitCode)+ * }+ */+ public static int TerminateJobObject(MemorySegment cs, MemorySegment hJob, int uExitCode) {+ var mh$ = TerminateJobObject.HANDLE;+ try {+ if (TRACE_DOWNCALLS) {+ traceDowncall("TerminateJobObject", hJob, uExitCode);+ }+ return (int)mh$.invokeExact(cs, hJob, uExitCode);+ } catch (Error | RuntimeException ex) {+ throw ex;+ } catch (Throwable ex$) {+ throw new AssertionError("should not reach here", ex$);+ }+ }++ private static class LocalFree {+ public static final FunctionDescriptor DESC = FunctionDescriptor.of(+ win32_h.C_POINTER,+ win32_h.C_POINTER+ );++ public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("LocalFree");++ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC);+ }++ /**+ * Function descriptor for:+ * {@snippet lang=c :+ * HLOCAL LocalFree(HLOCAL hMem)+ * }+ */+ public static FunctionDescriptor LocalFree$descriptor() {+ return LocalFree.DESC;+ }++ /**+ * Downcall method handle for:+ * {@snippet lang=c :+ * HLOCAL LocalFree(HLOCAL hMem)+ * }+ */+ public static MethodHandle LocalFree$handle() {+ return LocalFree.HANDLE;+ }++ /**+ * Address for:+ * {@snippet lang=c :+ * HLOCAL LocalFree(HLOCAL hMem)+ * }+ */+ public static MemorySegment LocalFree$address() {+ return LocalFree.ADDR;+ }++ /**+ * {@snippet lang=c :+ * HLOCAL LocalFree(HLOCAL hMem)+ * }+ */+ public static MemorySegment LocalFree(MemorySegment hMem) {+ var mh$ = LocalFree.HANDLE;+ try {+ if (TRACE_DOWNCALLS) {+ traceDowncall("LocalFree", hMem);+ }+ return (MemorySegment)mh$.invokeExact(hMem);+ } catch (Error | RuntimeException ex) {+ throw ex;+ } catch (Throwable ex$) {+ throw new AssertionError("should not reach here", ex$);+ }+ }++ private static class FormatMessageW {+ public static final FunctionDescriptor DESC = FunctionDescriptor.of(+ win32_h.C_LONG,+ win32_h.C_LONG,+ win32_h.C_POINTER,+ win32_h.C_LONG,+ win32_h.C_LONG,+ win32_h.C_POINTER,+ win32_h.C_LONG,+ win32_h.C_POINTER+ );++ public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("FormatMessageW");++ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC);+ }++ /**+ * Function descriptor for:+ * {@snippet lang=c :+ * DWORD FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, va_list *Arguments)+ * }+ */+ public static FunctionDescriptor FormatMessageW$descriptor() {+ return FormatMessageW.DESC;+ }++ /**+ * Downcall method handle for:+ * {@snippet lang=c :+ * DWORD FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, va_list *Arguments)+ * }+ */+ public static MethodHandle FormatMessageW$handle() {+ return FormatMessageW.HANDLE;+ }++ /**+ * Address for:+ * {@snippet lang=c :+ * DWORD FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, va_list *Arguments)+ * }+ */+ public static MemorySegment FormatMessageW$address() {+ return FormatMessageW.ADDR;+ }++ /**+ * {@snippet lang=c :+ * DWORD FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, va_list *Arguments)+ * }+ */+ public static int FormatMessageW(int dwFlags, MemorySegment lpSource, int dwMessageId, int dwLanguageId, MemorySegment lpBuffer, int nSize, MemorySegment Arguments) {+ var mh$ = FormatMessageW.HANDLE;+ try {+ if (TRACE_DOWNCALLS) {+ traceDowncall("FormatMessageW", dwFlags, lpSource, dwMessageId, dwLanguageId, lpBuffer, nSize, Arguments);+ }+ return (int)mh$.invokeExact(dwFlags, lpSource, dwMessageId, dwLanguageId, lpBuffer, nSize, Arguments);+ } catch (Error | RuntimeException ex) {+ throw ex;+ } catch (Throwable ex$) {+ throw new AssertionError("should not reach here", ex$);+ }+ }++ private static class CreatePseudoConsole {+ public static final FunctionDescriptor DESC = FunctionDescriptor.of(+ win32_h.C_LONG,+ _COORD.layout(),+ win32_h.C_POINTER,+ win32_h.C_POINTER,+ win32_h.C_LONG,+ win32_h.C_POINTER+ );++ public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("CreatePseudoConsole");++ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC, Win32Err.OPT_CAPTURE_LASTERROR);+ }++ /**+ * Function descriptor for:+ * {@snippet lang=c :+ * HRESULT CreatePseudoConsole(COORD size, HANDLE hInput, HANDLE hOutput, DWORD dwFlags, HPCON *phPC)+ * }+ */+ public static FunctionDescriptor CreatePseudoConsole$descriptor() {+ return CreatePseudoConsole.DESC;+ }++ /**+ * Downcall method handle for:+ * {@snippet lang=c :+ * HRESULT CreatePseudoConsole(COORD size, HANDLE hInput, HANDLE hOutput, DWORD dwFlags, HPCON *phPC)+ * }+ */+ public static MethodHandle CreatePseudoConsole$handle() {+ return CreatePseudoConsole.HANDLE;+ }++ /**+ * Address for:+ * {@snippet lang=c :+ * HRESULT CreatePseudoConsole(COORD size, HANDLE hInput, HANDLE hOutput, DWORD dwFlags, HPCON *phPC)+ * }+ */+ public static MemorySegment CreatePseudoConsole$address() {+ return CreatePseudoConsole.ADDR;+ }++ /**+ * {@snippet lang=c :+ * HRESULT CreatePseudoConsole(COORD size, HANDLE hInput, HANDLE hOutput, DWORD dwFlags, HPCON *phPC)+ * }+ */+ public static int CreatePseudoConsole(MemorySegment cs, MemorySegment size, MemorySegment hInput, MemorySegment hOutput, int dwFlags, MemorySegment phPC) {+ var mh$ = CreatePseudoConsole.HANDLE;+ try {+ if (TRACE_DOWNCALLS) {+ traceDowncall("CreatePseudoConsole", size, hInput, hOutput, dwFlags, phPC);+ }+ return (int)mh$.invokeExact(cs, size, hInput, hOutput, dwFlags, phPC);+ } catch (Error | RuntimeException ex) {+ throw ex;+ } catch (Throwable ex$) {+ throw new AssertionError("should not reach here", ex$);+ }+ }++ private static class ResizePseudoConsole {+ public static final FunctionDescriptor DESC = FunctionDescriptor.of(+ win32_h.C_LONG,+ win32_h.C_POINTER,+ _COORD.layout()+ );++ public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("ResizePseudoConsole");++ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC, Win32Err.OPT_CAPTURE_LASTERROR);+ }++ /**+ * Function descriptor for:+ * {@snippet lang=c :+ * HRESULT ResizePseudoConsole(HPCON hPC, COORD size)+ * }+ */+ public static FunctionDescriptor ResizePseudoConsole$descriptor() {+ return ResizePseudoConsole.DESC;+ }++ /**+ * Downcall method handle for:+ * {@snippet lang=c :+ * HRESULT ResizePseudoConsole(HPCON hPC, COORD size)+ * }+ */+ public static MethodHandle ResizePseudoConsole$handle() {+ return ResizePseudoConsole.HANDLE;+ }++ /**+ * Address for:+ * {@snippet lang=c :+ * HRESULT ResizePseudoConsole(HPCON hPC, COORD size)+ * }+ */+ public static MemorySegment ResizePseudoConsole$address() {+ return ResizePseudoConsole.ADDR;+ }++ /**+ * {@snippet lang=c :+ * HRESULT ResizePseudoConsole(HPCON hPC, COORD size)+ * }+ */+ public static int ResizePseudoConsole(MemorySegment cs, MemorySegment hPC, MemorySegment size) {+ var mh$ = ResizePseudoConsole.HANDLE;+ try {+ if (TRACE_DOWNCALLS) {+ traceDowncall("ResizePseudoConsole", hPC, size);+ }+ return (int)mh$.invokeExact(cs, hPC, size);+ } catch (Error | RuntimeException ex) {+ throw ex;+ } catch (Throwable ex$) {+ throw new AssertionError("should not reach here", ex$);+ }+ }++ private static class ClosePseudoConsole {+ public static final FunctionDescriptor DESC = FunctionDescriptor.ofVoid(+ win32_h.C_POINTER+ );++ public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("ClosePseudoConsole");++ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC);+ }++ /**+ * Function descriptor for:+ * {@snippet lang=c :+ * void ClosePseudoConsole(HPCON hPC)+ * }+ */+ public static FunctionDescriptor ClosePseudoConsole$descriptor() {+ return ClosePseudoConsole.DESC;+ }++ /**+ * Downcall method handle for:+ * {@snippet lang=c :+ * void ClosePseudoConsole(HPCON hPC)+ * }+ */+ public static MethodHandle ClosePseudoConsole$handle() {+ return ClosePseudoConsole.HANDLE;+ }++ /**+ * Address for:+ * {@snippet lang=c :+ * void ClosePseudoConsole(HPCON hPC)+ * }+ */+ public static MemorySegment ClosePseudoConsole$address() {+ return ClosePseudoConsole.ADDR;+ }++ /**+ * {@snippet lang=c :+ * void ClosePseudoConsole(HPCON hPC)+ * }+ */+ public static void ClosePseudoConsole(MemorySegment hPC) {+ var mh$ = ClosePseudoConsole.HANDLE;+ try {+ if (TRACE_DOWNCALLS) {+ traceDowncall("ClosePseudoConsole", hPC);+ }+ mh$.invokeExact(hPC);+ } catch (Error | RuntimeException ex) {+ throw ex;+ } catch (Throwable ex$) {+ throw new AssertionError("should not reach here", ex$);+ }+ }+ private static final int STILL_ACTIVE = (int)259L;+ /**+ * {@snippet lang=c :+ * #define STILL_ACTIVE 259+ * }+ */+ public static int STILL_ACTIVE() {+ return STILL_ACTIVE;+ }+ private static final int WAIT_FAILED = (int)4294967295L;+ /**+ * {@snippet lang=c :+ * #define WAIT_FAILED 4294967295+ * }+ */+ public static int WAIT_FAILED() {+ return WAIT_FAILED;+ }+ private static final int WAIT_OBJECT_0 = (int)0L;+ /**+ * {@snippet lang=c :+ * #define WAIT_OBJECT_0 0+ * }+ */+ public static int WAIT_OBJECT_0() {+ return WAIT_OBJECT_0;+ }+ private static final int WAIT_ABANDONED = (int)128L;+ /**+ * {@snippet lang=c :+ * #define WAIT_ABANDONED 128+ * }+ */+ public static int WAIT_ABANDONED() {+ return WAIT_ABANDONED;+ }+ private static final int PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE = (int)131094L;+ /**+ * {@snippet lang=c :+ * #define PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE 131094+ * }+ */+ public static int PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE() {+ return PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE;+ }+ private static final int ERROR_BROKEN_PIPE = (int)109L;+ /**+ * {@snippet lang=c :+ * #define ERROR_BROKEN_PIPE 109+ * }+ */+ public static int ERROR_BROKEN_PIPE() {+ return ERROR_BROKEN_PIPE;+ }+ private static final int WAIT_TIMEOUT = (int)258L;+ /**+ * {@snippet lang=c :+ * #define WAIT_TIMEOUT 258+ * }+ */+ public static int WAIT_TIMEOUT() {+ return WAIT_TIMEOUT;+ }+ private static final int ERROR_PIPE_CONNECTED = (int)535L;+ /**+ * {@snippet lang=c :+ * #define ERROR_PIPE_CONNECTED 535+ * }+ */+ public static int ERROR_PIPE_CONNECTED() {+ return ERROR_PIPE_CONNECTED;+ }+ private static final int ERROR_PIPE_LISTENING = (int)536L;+ /**+ * {@snippet lang=c :+ * #define ERROR_PIPE_LISTENING 536+ * }+ */+ public static int ERROR_PIPE_LISTENING() {+ return ERROR_PIPE_LISTENING;+ }+ private static final int S_OK = (int)0L;+ /**+ * {@snippet lang=c :+ * #define S_OK 0+ * }+ */+ public static int S_OK() {+ return S_OK;+ }+}+diff --git a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/linux/LinuxIoctls.java b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/linux/LinuxIoctls.javaindex 66aecc1180..115d083092 100644--- a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/linux/LinuxIoctls.java+++ b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/linux/LinuxIoctls.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -15,7 +15,7 @@*/package ghidra.pty.linux;-import ghidra.pty.unix.PosixC.Ioctls;+import ghidra.pty.unix.Ioctls;import ghidra.pty.unix.UnixPtySessionLeader;public enum LinuxIoctls implements Ioctls {diff --git a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/linux/LinuxPtySessionLeader.java b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/linux/LinuxPtySessionLeader.javaindex 1a4088e6c3..57f3cc2e0f 100644--- a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/linux/LinuxPtySessionLeader.java+++ b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/linux/LinuxPtySessionLeader.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -15,7 +15,7 @@*/package ghidra.pty.linux;-import ghidra.pty.unix.PosixC.Ioctls;+import ghidra.pty.unix.Ioctls;import ghidra.pty.unix.UnixPtySessionLeader;public class LinuxPtySessionLeader extends UnixPtySessionLeader {diff --git a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/local/LocalWindowsNativeProcessPtySession.java b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/local/LocalWindowsNativeProcessPtySession.javaindex a69178618d..daf5489169 100644--- a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/local/LocalWindowsNativeProcessPtySession.java+++ b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/local/LocalWindowsNativeProcessPtySession.java@@ -15,18 +15,17 @@*/package ghidra.pty.local;+import java.lang.foreign.Arena;+import java.lang.foreign.MemorySegment;import java.util.Optional;import java.util.concurrent.TimeUnit;import java.util.concurrent.TimeoutException;-import com.sun.jna.LastErrorException;-import com.sun.jna.platform.win32.Kernel32;-import com.sun.jna.platform.win32.WinBase;-import com.sun.jna.ptr.IntByReference;+import com.microsoft.win32.win32_h;import ghidra.pty.PtySession;import ghidra.pty.windows.Handle;-import ghidra.pty.windows.jna.JobApiNative;+import ghidra.pty.windows.Win32Err;import ghidra.util.Msg;public class LocalWindowsNativeProcessPtySession implements PtySession {@@ -50,19 +49,28 @@ public class LocalWindowsNativeProcessPtySession implements PtySession {}protected int doWaitExited(int millis) throws TimeoutException {- while (true) {- switch (Kernel32.INSTANCE.WaitForSingleObject(processHandle.getNative(), millis)) {- case Kernel32.WAIT_OBJECT_0:- case Kernel32.WAIT_ABANDONED:- IntByReference lpExitCode = new IntByReference();- Kernel32.INSTANCE.GetExitCodeProcess(processHandle.getNative(), lpExitCode);- if (lpExitCode.getValue() != WinBase.STILL_ACTIVE) {- return lpExitCode.getValue();+ try (Arena arena = Arena.ofConfined()) {+ MemorySegment cs = arena.allocate(Win32Err.LAYOUT);+ MemorySegment lpExitCode = arena.allocate(win32_h.DWORD);+ while (true) {+ int result = Win32Err.checkWaitFailed(+ win32_h.WaitForSingleObject(cs, processHandle.asSegment(), millis), cs);+ if (result == win32_h.WAIT_OBJECT_0() || result == win32_h.WAIT_ABANDONED()) {+ Win32Err.checkFalse(+ win32_h.GetExitCodeProcess(cs, processHandle.asSegment(), lpExitCode), cs);+ int exitCode = lpExitCode.get(win32_h.DWORD, 0);+ if (exitCode == win32_h.STILL_ACTIVE()) {+ continue;}- case Kernel32.WAIT_TIMEOUT:+ return exitCode;+ }+ if (result == win32_h.WAIT_TIMEOUT()) {throw new TimeoutException();- case Kernel32.WAIT_FAILED:- throw new LastErrorException(Kernel32.INSTANCE.GetLastError());+ }+ else {+ throw new AssertionError(+ "Unrecognized Wait result: %d (0x%x)".formatted(result, result));+ }}}}@@ -88,8 +96,9 @@ public class LocalWindowsNativeProcessPtySession implements PtySession {@Overridepublic void destroyForcibly() {- if (!JobApiNative.INSTANCE.TerminateJobObject(jobHandle.getNative(), 1).booleanValue()) {- throw new LastErrorException(Kernel32.INSTANCE.GetLastError());+ try (Arena arena = Arena.ofConfined()) {+ MemorySegment cs = arena.allocate(Win32Err.LAYOUT);+ Win32Err.checkFalse(win32_h.TerminateJobObject(cs, jobHandle.asSegment(), 1), cs);}}@@ -100,12 +109,17 @@ public class LocalWindowsNativeProcessPtySession implements PtySession {@Overridepublic ProcessHandle handle() {- IntByReference lpExitCode = new IntByReference();- Kernel32.INSTANCE.GetExitCodeProcess(processHandle.getNative(), lpExitCode);- Optional<ProcessHandle> result = ProcessHandle.of(pid);- if (lpExitCode.getValue() != WinBase.STILL_ACTIVE) {+ try (Arena arena = Arena.ofConfined()) {+ MemorySegment cs = arena.allocate(Win32Err.LAYOUT);+ MemorySegment lpExitCode = arena.allocate(win32_h.DWORD);+ Optional<ProcessHandle> result = ProcessHandle.of(pid);+ Win32Err.checkFalse(+ win32_h.GetExitCodeProcess(cs, processHandle.asSegment(), lpExitCode), cs);+ int exitCode = lpExitCode.get(win32_h.DWORD, 0);+ if (exitCode == win32_h.STILL_ACTIVE()) {+ return result.orElse(null);+ }return null;}- return result.orElseThrow(() -> new AssertionError());}}diff --git a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/macos/MacosIoctls.java b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/macos/MacosIoctls.javaindex 3a4a6fafcc..f96219bf25 100644--- a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/macos/MacosIoctls.java+++ b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/macos/MacosIoctls.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -15,7 +15,7 @@*/package ghidra.pty.macos;-import ghidra.pty.unix.PosixC.Ioctls;+import ghidra.pty.unix.Ioctls;import ghidra.pty.unix.UnixPtySessionLeader;public enum MacosIoctls implements Ioctls {diff --git a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/macos/MacosPtySessionLeader.java b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/macos/MacosPtySessionLeader.javaindex 87b0e84b66..d0de940335 100644--- a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/macos/MacosPtySessionLeader.java+++ b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/macos/MacosPtySessionLeader.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -15,7 +15,7 @@*/package ghidra.pty.macos;-import ghidra.pty.unix.PosixC.Ioctls;+import ghidra.pty.unix.Ioctls;import ghidra.pty.unix.UnixPtySessionLeader;public class MacosPtySessionLeader extends UnixPtySessionLeader {diff --git a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/openbsd/OpenBSDIoctls.java b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/openbsd/OpenBSDIoctls.javaindex 2f2cd7d67c..a9abd24fd7 100644--- a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/openbsd/OpenBSDIoctls.java+++ b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/openbsd/OpenBSDIoctls.java@@ -15,7 +15,7 @@*/package ghidra.pty.openbsd;-import ghidra.pty.unix.PosixC.Ioctls;+import ghidra.pty.unix.Ioctls;import ghidra.pty.unix.UnixPtySessionLeader;public enum OpenBSDIoctls implements Ioctls {diff --git a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/openbsd/OpenBSDPtySessionLeader.java b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/openbsd/OpenBSDPtySessionLeader.javaindex d3d915b92a..6f8828e5ec 100644--- a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/openbsd/OpenBSDPtySessionLeader.java+++ b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/openbsd/OpenBSDPtySessionLeader.java@@ -15,7 +15,7 @@*/package ghidra.pty.openbsd;-import ghidra.pty.unix.PosixC.Ioctls;+import ghidra.pty.unix.Ioctls;import ghidra.pty.unix.UnixPtySessionLeader;public class OpenBSDPtySessionLeader extends UnixPtySessionLeader {diff --git a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/FdInputStream.java b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/FdInputStream.javaindex 75ad7a813c..dbdbc26c7c 100644--- a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/FdInputStream.java+++ b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/FdInputStream.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -17,27 +17,26 @@ package ghidra.pty.unix;import java.io.IOException;import java.io.InputStream;+import java.lang.foreign.*;-import com.sun.jna.LastErrorException;-import com.sun.jna.Memory;+import org.unix.unistd_h;++import ghidra.pty.unix.UnixErr.ErrnoException;/*** An input stream that wraps a native POSIX file descriptor- ** <p>- * <b>WARNING:</b> This class makes use of jnr-ffi to invoke native functions. An invalid file+ * <b>WARNING:</b> This class uses java.lang.foreign to invoke native functions. An invalid file* descriptor is generally detected, but an incorrect, but valid file descriptor may cause undefined* behavior.*/public class FdInputStream extends InputStream {- private static final PosixC LIB_POSIX = PosixC.INSTANCE;-private final int fd;private volatile boolean closed = false;/*** Wrap the given file descriptor in an {@link InputStream}- *+ ** @param fd the file descriptor*/FdInputStream(int fd) {@@ -69,19 +68,17 @@ public class FdInputStream extends InputStream {if (len == 0) {return 0;}- Memory buf = new Memory(len);- int ret;- try {- ret = LIB_POSIX.read(fd, buf, len);+ try (Arena arena = Arena.ofConfined()) {+ MemorySegment cs = arena.allocate(UnixErr.LAYOUT);+ MemorySegment buf = arena.allocate(len);+ int ret = (int) UnixErr.checkLt0(unistd_h.read(cs, fd, buf, len), cs);+ MemorySegment.copy(buf, ValueLayout.JAVA_BYTE, 0, b, off, ret);+ return ret;}- catch (LastErrorException e) {- if (e.getErrorCode() == 5 || e.getErrorCode() == 9) {- throw new IOException(e);- }- throw e;+ catch (ErrnoException e) {+ // LATER: Should select specific err numbers?+ throw new IOException(e);}- buf.read(0, b, off, ret);- return ret;}@Overridediff --git a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/FdOutputStream.java b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/FdOutputStream.javaindex 0762c80eff..d1caedae53 100644--- a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/FdOutputStream.java+++ b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/FdOutputStream.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -17,21 +17,20 @@ package ghidra.pty.unix;import java.io.IOException;import java.io.OutputStream;+import java.lang.foreign.*;++import org.unix.unistd_h;-import com.sun.jna.LastErrorException;-import com.sun.jna.Memory;+import ghidra.pty.unix.UnixErr.ErrnoException;/*** An output stream that wraps a native POSIX file descriptor- ** <p>- * <b>WARNING:</b> This class makes use of jnr-ffi to invoke native functions. An invalid file+ * <b>WARNING:</b> This class uses java.lang.foreign to invoke native functions. An invalid file* descriptor is generally detected, but an incorrect, but valid file descriptor may cause undefined* behavior.*/public class FdOutputStream extends OutputStream {- private static final PosixC LIB_POSIX = PosixC.INSTANCE;-private final int fd;private boolean closed = false;@@ -59,21 +58,24 @@ public class FdOutputStream extends OutputStream {if (closed) {throw new IOException("Stream closed");}- Memory buf = new Memory(len);- buf.write(0, b, off, len);- try {+ if (len == 0) {+ return;+ }+ try (Arena arena = Arena.ofConfined()) {+ MemorySegment cs = arena.allocate(UnixErr.LAYOUT);+ MemorySegment buf = arena.allocate(len);+ MemorySegment.copy(b, off, buf, ValueLayout.JAVA_BYTE, 0, len);int total = 0;do {- int ret = LIB_POSIX.write(fd, buf, len - total);+ MemorySegment slice = buf.asSlice(total);+ int ret = (int) UnixErr.checkLt0(unistd_h.write(cs, fd, slice, len - total), cs);total += ret;}while (total < len);}- catch (LastErrorException e) {- if (e.getErrorCode() == 5 || e.getErrorCode() == 9) {- throw new IOException(e);- }- throw e;+ catch (ErrnoException e) {+ // LATER: Should select specific error numbers?+ throw new IOException(e);}}diff --git a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/Err.java b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/Ioctls.javasimilarity index 64%rename from Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/Err.javarename to Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/Ioctls.javaindex 918e7f0ad1..8803c8bbb3 100644--- a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/Err.java+++ b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/Ioctls.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -15,17 +15,10 @@*/package ghidra.pty.unix;-import com.sun.jna.LastErrorException;-import com.sun.jna.Native;+public interface Ioctls {+ Class<? extends UnixPtySessionLeader> leaderClass();-public interface Err {- PosixC BARE_POSIX = PosixC.BARE;+ long TIOCSCTTY();- static int checkLt0(int result) {- if (result < 0) {- int errno = Native.getLastError();- throw new LastErrorException("[" + errno + "] " + BARE_POSIX.strerror(errno));- }- return result;- }+ long TIOCSWINSZ();}diff --git a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/PosixC.java b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/PosixC.javadeleted file mode 100644index 03b6041f06..0000000000--- a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/PosixC.java+++ /dev/null@@ -1,165 +0,0 @@-/* ###- * IP: GHIDRA- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */-package ghidra.pty.unix;--import com.sun.jna.*;-import com.sun.jna.Structure.FieldOrder;--/**- * Interface for POSIX functions in libc- *- * <p>- * The functions are not documented here. Instead see the POSIX manual pages.- */-public interface PosixC extends Library {-- interface Ioctls {- Class<? extends UnixPtySessionLeader> leaderClass();-- long TIOCSCTTY();-- long TIOCSWINSZ();- }-- @FieldOrder({ "ws_row", "ws_col", "ws_xpixel", "ws_ypixel" })- class Winsize extends Structure {- public short ws_row;- public short ws_col;- public short ws_xpixel; // Unused- public short ws_ypixel; // Unused-- public static class ByReference extends Winsize implements Structure.ByReference {- }- }-- @FieldOrder({ "steal" })- class ControllingTty extends Structure {- public int steal;-- public static class ByReference extends ControllingTty implements Structure.ByReference {- }- }-- @FieldOrder(- { "c_iflag", "c_oflag", "c_cflag", "c_lflag", "c_line", "c_cc", "c_ispeed",- "c_ospeed" }- )- class Termios extends Structure {- // TCSANOW and ECHO are the same on Linux and macOS- public static final int TCSANOW = 0;- public static final int ECHO = 0000010; // Octal-- public int c_iflag;- public int c_oflag;- public int c_cflag;- public int c_lflag;-- public byte c_line;- public byte[] c_cc = new byte[32];-- public int c_ispeed;- public int c_ospeed;-- public static class ByReference extends Termios implements Structure.ByReference {- }- }-- /**- * The bare library without error handling- *- * @see Util#BARE- */- PosixC BARE = Native.load("c", PosixC.class);-- PosixC INSTANCE = new PosixC() {- @Override- public String strerror(int errnum) {- return BARE.strerror(errnum);- }-- @Override- public int close(int fd) {- return Err.checkLt0(BARE.close(fd));- }-- @Override- public int read(int fd, Pointer buf, int len) {- return Err.checkLt0(BARE.read(fd, buf, len));- }-- @Override- public int write(int fd, Pointer buf, int i) {- return Err.checkLt0(BARE.write(fd, buf, i));- }-- @Override- public int setsid() {- return Err.checkLt0(BARE.setsid());- }-- @Override- public int open(String path, int mode, int flags) {- return Err.checkLt0(BARE.open(path, mode, flags));- }-- @Override- public int dup2(int oldfd, int newfd) {- return Err.checkLt0(BARE.dup2(oldfd, newfd));- }-- @Override- public int execv(String path, String[] argv) {- return Err.checkLt0(BARE.execv(path, argv));- }-- @Override- public int ioctl(int fd, long cmd, Pointer... args) {- return Err.checkLt0(BARE.ioctl(fd, cmd, args));- }-- @Override- public int tcgetattr(int fd, Termios.ByReference termios_p) {- return Err.checkLt0(BARE.tcgetattr(fd, termios_p));- }-- @Override- public int tcsetattr(int fd, int optional_actions, Termios.ByReference termios_p) {- return Err.checkLt0(BARE.tcsetattr(fd, optional_actions, termios_p));- }- };-- String strerror(int errnum);-- int close(int fd);-- int read(int fd, Pointer buf, int len);-- int write(int fd, Pointer buf, int i);-- int setsid();-- int open(String path, int mode, int flags);-- int dup2(int oldfd, int newfd);-- int execv(String path, String[] argv);-- int ioctl(int fd, long cmd, Pointer... args);-- int tcgetattr(int fd, Termios.ByReference termios_p);-- int tcsetattr(int fd, int optional_actions, Termios.ByReference termios_p);-}diff --git a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/UnixErr.java b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/UnixErr.javanew file mode 100644index 0000000000..b46e6191c7--- /dev/null+++ b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/UnixErr.java@@ -0,0 +1,64 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.pty.unix;++import java.lang.foreign.*;+import java.lang.invoke.VarHandle;++import org.unix.string_h;++public interface UnixErr {+ Linker.Option OPT_CAPTURE_ERRNO = Linker.Option.captureCallState("errno");+ StructLayout LAYOUT = Linker.Option.captureStateLayout();+ VarHandle ERRNO = LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("errno"));++ class ErrnoException extends RuntimeException {+ private final int errno;++ public ErrnoException(int errno, String message) {+ super("[%d] %s".formatted(errno, message));+ this.errno = errno;+ }++ public int getErrno() {+ return errno;+ }+ }++ static String strerror(int errno) {+ MemorySegment errstr = string_h.strerror(errno);+ if (errstr.address() != 0) {+ return errstr.getString(0);+ }+ return "Unknown";+ }++ static int checkLt0(int result, MemorySegment cs) {+ if (result < 0) {+ int errno = (int) ERRNO.get(cs, 0);+ throw new ErrnoException(errno, strerror(errno));+ }+ return result;+ }++ static long checkLt0(long result, MemorySegment cs) {+ if (result < 0) {+ int errno = (int) ERRNO.get(cs, 0);+ throw new ErrnoException(errno, strerror(errno));+ }+ return result;+ }+}diff --git a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/UnixPty.java b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/UnixPty.javaindex 66cc987f71..db0425b9d4 100644--- a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/UnixPty.java+++ b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/UnixPty.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -16,18 +16,16 @@package ghidra.pty.unix;import java.io.IOException;+import java.lang.foreign.Arena;+import java.lang.foreign.MemorySegment;-import com.sun.jna.Memory;-import com.sun.jna.ptr.IntByReference;+import org.unix.*;import ghidra.pty.Pty;-import ghidra.pty.unix.PosixC.Ioctls;import ghidra.util.Msg;+import utility.function.ExceptionalSupplier;public class UnixPty implements Pty {-- static final PosixC LIB_POSIX = PosixC.INSTANCE;-private final int aparent;private final int achild;private boolean closed = false;@@ -36,12 +34,18 @@ public class UnixPty implements Pty {private final UnixPtyChild child;public static UnixPty openpty(Ioctls ioctls) throws IOException {- // TODO: Support termp and winp?- IntByReference p = new IntByReference();- IntByReference c = new IntByReference();- Memory n = new Memory(1024);- Util.INSTANCE.openpty(p, c, n, null, null);- return new UnixPty(ioctls, p.getValue(), c.getValue(), n.getString(0));+ // TODO: Support termp and winp?+ try (Arena arena = Arena.ofConfined()) {+ MemorySegment cs = arena.allocate(UnixErr.LAYOUT);+ MemorySegment p = arena.allocate(pty_h.C_INT);+ MemorySegment c = arena.allocate(pty_h.C_INT);+ MemorySegment n = arena.allocate(pty_h.C_CHAR, 1024);+ UnixErr.checkLt0(pty_h.openpty(cs, p, c, n, MemorySegment.NULL, MemorySegment.NULL), cs);+ return new UnixPty(ioctls,+ p.get(pty_h.C_INT, 0),+ c.get(pty_h.C_INT, 0),+ n.getString(0));+ }}UnixPty(Ioctls ioctls, int aparent, int achild, String name) {@@ -63,6 +67,33 @@ public class UnixPty implements Pty {return child;}+ static class OnError implements AutoCloseable {+ Throwable error = null;++ public <T> T step(ExceptionalSupplier<T, Throwable> step) {+ T ret = null;+ try {+ ret = step.get();+ }+ catch (Throwable e) {+ if (error == null) {+ error = e;+ }+ }+ return ret;+ }++ @Override+ public void close() throws Exception {+ switch (error) {+ case null -> {+ }+ case Exception e -> throw e;+ default -> throw new RuntimeException(error);+ }+ }+ }+@Overridepublic synchronized void close() throws IOException {if (closed) {@@ -70,8 +101,14 @@ public class UnixPty implements Pty {}child.closeStreams();parent.closeStreams();- LIB_POSIX.close(achild);- LIB_POSIX.close(aparent);- closed = true;+ try (Arena arena = Arena.ofConfined(); OnError err = new OnError()) {+ MemorySegment cs = arena.allocate(UnixErr.LAYOUT);+ err.step(() -> UnixErr.checkLt0(unistd_h.close(cs, achild), cs));+ err.step(() -> UnixErr.checkLt0(unistd_h.close(cs, aparent), cs));+ closed = true;+ }+ catch (Exception e) {+ throw new IOException("Error closing pty", e);+ }}}diff --git a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/UnixPtyChild.java b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/UnixPtyChild.javaindex cc91555897..5534e571e1 100644--- a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/UnixPtyChild.java+++ b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/UnixPtyChild.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -17,17 +17,18 @@ package ghidra.pty.unix;import java.io.File;import java.io.IOException;+import java.lang.foreign.Arena;+import java.lang.foreign.MemorySegment;import java.util.*;+import org.unix.*;+import ghidra.pty.PtyChild;import ghidra.pty.PtySession;import ghidra.pty.local.LocalProcessPtySession;-import ghidra.pty.unix.PosixC.*;import ghidra.util.Msg;public class UnixPtyChild extends UnixPtyEndpoint implements PtyChild {- static final PosixC LIB_POSIX = PosixC.INSTANCE;-private final String name;UnixPtyChild(Ioctls ioctls, int fd, String name) {@@ -101,23 +102,28 @@ public class UnixPtyChild extends UnixPtyEndpoint implements PtyChild {}private void disableEcho() {- Termios.ByReference tmios = new Termios.ByReference();- LIB_POSIX.tcgetattr(fd, tmios);- tmios.c_lflag &= ~Termios.ECHO;- LIB_POSIX.tcsetattr(fd, Termios.TCSANOW, tmios);+ try (Arena arena = Arena.ofConfined()) {+ MemorySegment cs = arena.allocate(UnixErr.LAYOUT);+ MemorySegment t = termios.allocate(arena);+ UnixErr.checkLt0(termios_h.tcgetattr(cs, fd, t), cs);+ termios.c_lflag(t, termios.c_lflag(t) & ~termios_h.ECHO());+ UnixErr.checkLt0(termios_h.tcsetattr(cs, fd, termios_h.TCSANOW(), t), cs);+ }}@Overridepublic void setWindowSize(short cols, short rows) {- Winsize.ByReference ws = new Winsize.ByReference();- ws.ws_col = cols;- ws.ws_row = rows;- ws.write();- try {- PosixC.INSTANCE.ioctl(fd, ioctls.TIOCSWINSZ(), ws.getPointer());+ try (Arena arena = Arena.ofConfined()) {+ MemorySegment cs = arena.allocate(UnixErr.LAYOUT);+ MemorySegment ws = winsize.allocate(arena);+ winsize.ws_col(ws, cols);+ winsize.ws_row(ws, rows);+ UnixErr.checkLt0(+ ioctl_h.ioctl.makeInvoker(winsize.layout()).apply(cs, fd, ioctls.TIOCSWINSZ(), ws),+ cs);}catch (Exception e) {- Msg.error(this, "Could not set terminal window size: " + e);+ Msg.error(this, "Could not set terminal windows size: " + e);}}}diff --git a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/UnixPtyEndpoint.java b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/UnixPtyEndpoint.javaindex 90ff133d70..8e3feca436 100644--- a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/UnixPtyEndpoint.java+++ b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/UnixPtyEndpoint.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -18,7 +18,6 @@ package ghidra.pty.unix;import java.io.*;import ghidra.pty.PtyEndpoint;-import ghidra.pty.unix.PosixC.Ioctls;public class UnixPtyEndpoint implements PtyEndpoint {protected final Ioctls ioctls;diff --git a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/UnixPtyParent.java b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/UnixPtyParent.javaindex c9184de7f1..0d90a4208b 100644--- a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/UnixPtyParent.java+++ b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/UnixPtyParent.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -16,7 +16,6 @@package ghidra.pty.unix;import ghidra.pty.PtyParent;-import ghidra.pty.unix.PosixC.Ioctls;public class UnixPtyParent extends UnixPtyEndpoint implements PtyParent {UnixPtyParent(Ioctls ioctls, int fd) {diff --git a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/UnixPtySessionLeader.java b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/UnixPtySessionLeader.javaindex 164fb4394a..5f030161f1 100644--- a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/UnixPtySessionLeader.java+++ b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/UnixPtySessionLeader.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -15,14 +15,12 @@*/package ghidra.pty.unix;+import java.lang.foreign.*;import java.util.List;-import ghidra.pty.unix.PosixC.ControllingTty;-import ghidra.pty.unix.PosixC.Ioctls;+import org.unix.*;public abstract class UnixPtySessionLeader {- private static final PosixC LIB_POSIX = PosixC.INSTANCE;- private static final int O_RDWR = 2; // TODO: Find this in libsprotected String ptyPath;protected List<String> subArgs;@@ -40,46 +38,58 @@ public abstract class UnixPtySessionLeader {* session's controlling TTY. Other platforms, e.g., BSD may require an explicit IOCTL.*/int bk = -1;- try {- int fd = LIB_POSIX.open(ptyPath, O_RDWR, 0);+ try (Arena arena = Arena.ofConfined()) {+ MemorySegment cs = arena.allocate(UnixErr.LAYOUT);++ int fd = UnixErr.checkLt0(fcntl_h.open.makeInvoker(fcntl_h.mode_t)+ .apply(cs, arena.allocateFrom(ptyPath), fcntl_h.O_RDWR(), 0),+ cs);/** Copy stderr to a backup descriptor, in case something goes wrong. */- int bkt = fd + 1;- LIB_POSIX.dup2(2, bkt);- bk = bkt;+ bk = UnixErr.checkLt0(unistd_h.dup(cs, 2), cs);/*** Copy the TTY fd over all standard streams. This effectively redirects the leader's* standard streams to the TTY.*/- LIB_POSIX.close(0);- LIB_POSIX.close(1);- LIB_POSIX.close(2);- LIB_POSIX.dup2(fd, 0);- LIB_POSIX.dup2(fd, 1);- LIB_POSIX.dup2(fd, 2);- LIB_POSIX.close(fd);+ UnixErr.checkLt0(unistd_h.close(cs, 0), cs);+ UnixErr.checkLt0(unistd_h.close(cs, 1), cs);+ UnixErr.checkLt0(unistd_h.close(cs, 2), cs);+ UnixErr.checkLt0(unistd_h.dup2(cs, fd, 0), cs);+ UnixErr.checkLt0(unistd_h.dup2(cs, fd, 1), cs);+ UnixErr.checkLt0(unistd_h.dup2(cs, fd, 2), cs);+ UnixErr.checkLt0(unistd_h.close(cs, fd), cs);/** This tells Linux to make this process the leader of a new session. */- LIB_POSIX.setsid();- ControllingTty.ByReference ctty = new ControllingTty.ByReference();- ctty.steal = 0;- LIB_POSIX.ioctl(0, ioctls().TIOCSCTTY(), ctty.getPointer());+ // returns sid/pid, but I don't care to keep it+ UnixErr.checkLt0(unistd_h.setsid(cs), cs);+ /** arg=0 declines to "steal" the terminal */+ UnixErr.checkLt0(ioctl_h.ioctl.makeInvoker(ioctl_h.C_INT)+ .apply(cs, 0, ioctls().TIOCSCTTY(), 0),+ cs);/*** At this point, we are the session leader and the named TTY is the controlling PTY.* Now, exec the specified image with arguments as the session leader. Recall, this* replaces the image of this process.*/- LIB_POSIX.execv(subArgs.get(0), subArgs.toArray(new String[0]));+ // One extra element to be the null arg terminator+ MemorySegment argsArr = arena.allocate(AddressLayout.ADDRESS, subArgs.size() + 1);+ for (int i = 0; i < subArgs.size(); i++) {+ argsArr.setAtIndex(AddressLayout.ADDRESS, i, arena.allocateFrom(subArgs.get(i)));+ }+ UnixErr.checkLt0(unistd_h.execv(cs,+ arena.allocateFrom(subArgs.get(0)),+ argsArr), cs);}catch (Throwable t) {// Print to both redirected and to inherited stderrSystem.err.println("Could not execute " + subArgs.get(0) + ": " + t.getMessage());+ t.printStackTrace();if (bk != -1) {- try {- int bkt = bk;- LIB_POSIX.dup2(bkt, 2);+ try (Arena arena = Arena.ofConfined()) {+ MemorySegment cs = arena.allocate(UnixErr.LAYOUT);+ UnixErr.checkLt0(unistd_h.dup2(cs, bk, 2), cs);}catch (Throwable t2) {// Catastrophic@@ -87,6 +97,7 @@ public abstract class UnixPtySessionLeader {}}System.err.println("Could not execute " + subArgs.get(0) + ": " + t.getMessage());+ t.printStackTrace();System.exit(127);}}diff --git a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/Util.java b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/Util.javadeleted file mode 100644index 7cfc113210..0000000000--- a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/unix/Util.java+++ /dev/null@@ -1,62 +0,0 @@-/* ###- * IP: GHIDRA- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */-package ghidra.pty.unix;--import com.sun.jna.*;-import com.sun.jna.ptr.IntByReference;--/**- * The interface for linking to {@code openpty} via jna- *- * <p>- * See the UNIX manual pages- */-public interface Util extends Library {-- /**- * The bare library without error handling- *- * <p>- * For error handling, use {@link #INSTANCE}, or check for errors manually, perhaps using- * {@link Err}.- *- * <p>- * We cannot just use {@code throws }{@link LastErrorException} to handle errors, because the- * idiom it applies is not correct for errno on UNIX. See- * https://man7.org/linux/man-pages/man3/errno.3.html, in particular:- *- * <blockquote>The value in errno is significant only when the return value of the call- * indicated an error (i.e., -1 from most system calls; -1 or NULL from most library functions);- * a function that succeeds is allowed to change errno.</blockquote>- *- * <p>- * This actually happens on our test setup when invoking the native {@code openpty} from a- * Docker container. It returns 0, but sets errno. JNA will incorrectly interpret this as- * failure.- */- Util BARE = Native.load("util", Util.class);-- Util INSTANCE = new Util() {- @Override- public int openpty(IntByReference amaster, IntByReference aslave, Pointer name,- Pointer termp, Pointer winp) {- return Err.checkLt0(BARE.openpty(amaster, aslave, name, termp, winp));- }- };-- int openpty(IntByReference amaster, IntByReference aslave, Pointer name, Pointer termp,- Pointer winp);-}diff --git a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/ConPty.java b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/ConPty.javaindex 823e03feda..9027fbe8db 100644--- a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/ConPty.java+++ b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/ConPty.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -16,23 +16,15 @@package ghidra.pty.windows;import java.io.IOException;+import java.lang.foreign.Arena;+import java.lang.foreign.MemorySegment;-import com.sun.jna.platform.win32.Kernel32;-import com.sun.jna.platform.win32.WinDef.DWORD;-import com.sun.jna.platform.win32.WinNT.HANDLEByReference;-import com.sun.jna.platform.win32.COM.COMUtils;+import com.microsoft.win32._COORD;+import com.microsoft.win32.win32_h;import ghidra.pty.*;-import ghidra.pty.windows.jna.ConsoleApiNative;-import ghidra.pty.windows.jna.ConsoleApiNative.COORD;public class ConPty implements Pty {- static final DWORD DW_ZERO = new DWORD(0);- static final DWORD DW_ONE = new DWORD(1);- static final DWORD PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE = new DWORD(0x20016);- static final DWORD EXTENDED_STARTUPINFO_PRESENT =- new DWORD(Kernel32.EXTENDED_STARTUPINFO_PRESENT);-private final Pipe pipeToChild;private final Pipe pipeFromChild;private final PseudoConsoleHandle pseudoConsoleHandle;@@ -50,19 +42,18 @@ public class ConPty implements Pty {// Close the child-connected ends after creating the pseudoconsole// Keep the parent-connected ends, because we're the parent- HANDLEByReference lphPC = new HANDLEByReference();-- COORD.ByValue size = new COORD.ByValue();- size.X = cols;- size.Y = rows;- COMUtils.checkRC(ConsoleApiNative.INSTANCE.CreatePseudoConsole(- size,- pipeToChild.getReadHandle().getNative(),- pipeFromChild.getWriteHandle().getNative(),- DW_ZERO,- lphPC));-- return new ConPty(pipeToChild, pipeFromChild, new PseudoConsoleHandle(lphPC.getValue()));+ try (Arena arena = Arena.ofConfined()) {+ MemorySegment cs = arena.allocate(Win32Err.LAYOUT);+ HandlePtr phPC = new HandlePtr(arena);+ MemorySegment size = _COORD.allocate(arena);+ _COORD.X(size, cols);+ _COORD.Y(size, rows);+ Win32Err.checkHResult(win32_h.CreatePseudoConsole(cs, size,+ pipeToChild.getReadHandle().asSegment(),+ pipeFromChild.getWriteHandle().asSegment(),+ 0, phPC.asSegment()), cs);+ return new ConPty(pipeToChild, pipeFromChild, new PseudoConsoleHandle(phPC.get()));+ }}public ConPty(Pipe pipeToChild, Pipe pipeFromChild, PseudoConsoleHandle pseudoConsoleHandle) {diff --git a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/ConPtyChild.java b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/ConPtyChild.javaindex 3ab7de73a3..eceff3b529 100644--- a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/ConPtyChild.java+++ b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/ConPtyChild.java@@ -17,22 +17,17 @@ package ghidra.pty.windows;import java.io.File;import java.io.IOException;+import java.lang.foreign.Arena;+import java.lang.foreign.MemorySegment;+import java.nio.charset.Charset;import java.util.*;-import com.sun.jna.*;-import com.sun.jna.platform.win32.Kernel32;-import com.sun.jna.platform.win32.WinBase;-import com.sun.jna.platform.win32.WinBase.PROCESS_INFORMATION;-import com.sun.jna.platform.win32.WinDef.*;-import com.sun.jna.platform.win32.WinNT.HANDLE;+import com.microsoft.win32.*;import ghidra.pty.PtyChild;import ghidra.pty.ShellUtils;import ghidra.pty.ShellUtils.Shell;import ghidra.pty.local.LocalWindowsNativeProcessPtySession;-import ghidra.pty.windows.jna.ConsoleApiNative;-import ghidra.pty.windows.jna.ConsoleApiNative.STARTUPINFOEX;-import ghidra.pty.windows.jna.JobApiNative;public class ConPtyChild extends ConPtyEndpoint implements PtyChild {@@ -41,39 +36,29 @@ public class ConPtyChild extends ConPtyEndpoint implements PtyChild {super(writeHandle, readHandle, pseudoConsoleHandle);}- protected STARTUPINFOEX prepareStartupInfo() {- STARTUPINFOEX si = new STARTUPINFOEX();- si.StartupInfo.cb = new DWORD(si.size());- si.StartupInfo.hStdOutput = new HANDLE();- si.StartupInfo.hStdError = new HANDLE();- si.StartupInfo.hStdInput = new HANDLE();- si.StartupInfo.dwFlags = WinBase.STARTF_USESTDHANDLES;+ protected MemorySegment prepareStartupInfo(Arena arena, MemorySegment cs) {+ MemorySegment sie = _STARTUPINFOEXW.allocate(arena);+ MemorySegment si = _STARTUPINFOEXW.StartupInfo(sie);+ _STARTUPINFOW.cb(si, (int) sie.byteSize());+ _STARTUPINFOW.hStdOutput(si, arena.allocate(win32_h.HANDLE));+ _STARTUPINFOW.hStdError(si, arena.allocate(win32_h.HANDLE));+ _STARTUPINFOW.hStdInput(si, arena.allocate(win32_h.HANDLE));+ _STARTUPINFOW.dwFlags(si, win32_h.STARTF_USESTDHANDLES());// Discover the size required for the thread attrs list and allocate- UINTByReference bytesRequired = new UINTByReference();+ MemorySegment bytesRequired = arena.allocate(win32_h.UINT);// NB. This will "fail." See Remarks on MSDN.- ConsoleApiNative.INSTANCE.InitializeProcThreadAttributeList(- null, ConPty.DW_ONE, ConPty.DW_ZERO, bytesRequired);- // NB. Memory frees itself in .finalize()- si.lpAttributeList = new Memory(bytesRequired.getValue().intValue());+ win32_h.InitializeProcThreadAttributeList(cs, MemorySegment.NULL, 1, 0, bytesRequired);+ MemorySegment attrs = arena.allocate(bytesRequired.get(win32_h.UINT, 0));+ _STARTUPINFOEXW.lpAttributeList(sie, attrs);// Initialize it- if (!ConsoleApiNative.INSTANCE.InitializeProcThreadAttributeList(- si.lpAttributeList, ConPty.DW_ONE, ConPty.DW_ZERO, bytesRequired)- .booleanValue()) {- throw new LastErrorException(Kernel32.INSTANCE.GetLastError());- }-+ Win32Err.checkFalse(+ win32_h.InitializeProcThreadAttributeList(cs, attrs, 1, 0, bytesRequired), cs);// Set the pseudoconsole information into the list- if (!ConsoleApiNative.INSTANCE.UpdateProcThreadAttribute(- si.lpAttributeList, ConPty.DW_ZERO,- ConPty.PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE,- new PVOID(pseudoConsoleHandle.getNative().getPointer()),- new DWORD(Native.POINTER_SIZE),- null, null).booleanValue()) {- throw new LastErrorException(Kernel32.INSTANCE.GetLastError());- }-- return si;+ Win32Err.checkFalse(win32_h.UpdateProcThreadAttribute(cs, attrs, 0,+ win32_h.PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE(), pseudoConsoleHandle.asSegment(),+ win32_h.HANDLE.byteSize(), MemorySegment.NULL, MemorySegment.NULL), cs);+ return sie;}private boolean isImplicitCmd(String[] args) {@@ -123,41 +108,45 @@ public class ConPtyChild extends ConPtyEndpoint implements PtyChild {/*** TODO: How to control local echo?*/-- HANDLE hJob = JobApiNative.INSTANCE.CreateJobObjectW(null, null);- if (hJob == null) {- throw new LastErrorException(Kernel32.INSTANCE.GetLastError());- }-- STARTUPINFOEX si = prepareStartupInfo();- PROCESS_INFORMATION pi = new PROCESS_INFORMATION();-- Shell shell = isImplicitCmd(args) ? Shell.WINDOWS_CMD : Shell.WINDOWS;- String commandLine = ShellUtils.generateLine(Arrays.asList(args), shell);-- if (!ConsoleApiNative.INSTANCE.CreateProcessW(- null /*lpApplicationName*/,- new WString(commandLine),- null /*lpProcessAttributes*/,- null /*lpThreadAttributes*/,- false /*bInheritHandles*/,- new DWORD(Kernel32.EXTENDED_STARTUPINFO_PRESENT |- Kernel32.CREATE_UNICODE_ENVIRONMENT) /*dwCreationFlags*/,- env == null ? null : new WString(ShellUtils.generateEnvBlock(env)),- workingDirectory == null ? null- : new WString(workingDirectory.getAbsolutePath()) /*lpCurrentDirectory*/,- si /*lpStartupInfo*/,- pi /*lpProcessInformation*/).booleanValue()) {- throw new LastErrorException(Kernel32.INSTANCE.GetLastError());+ try (Arena arena = Arena.ofConfined()) {+ MemorySegment cs = arena.allocate(Win32Err.LAYOUT);+ Handle hJob = new Handle(Win32Err.checkNull(+ win32_h.CreateJobObjectW(cs, MemorySegment.NULL, MemorySegment.NULL), cs));+ MemorySegment sie = prepareStartupInfo(arena, cs);+ MemorySegment pi = _PROCESS_INFORMATION.allocate(arena);++ Shell shell = isImplicitCmd(args) ? Shell.WINDOWS_CMD : Shell.WINDOWS;+ String commandLine = ShellUtils.generateLine(Arrays.asList(args), shell);++ Charset utf16le = Charset.forName("UTF-16LE");+ Win32Err.checkFalse(win32_h.CreateProcessW(cs,+ MemorySegment.NULL, // lpApplicationName+ arena.allocateFrom(commandLine, utf16le), // lpCommandLine+ MemorySegment.NULL, // lpProcessAttributes+ MemorySegment.NULL, // lpThreadAttributes+ 0, // bInheritHandles = false+ win32_h.EXTENDED_STARTUPINFO_PRESENT() |+ win32_h.CREATE_UNICODE_ENVIRONMENT(), // dwCreationFlags+ env == null ? MemorySegment.NULL+ : arena.allocateFrom(ShellUtils.generateEnvBlock(env),+ utf16le), // lpEnvironment+ workingDirectory == null ? MemorySegment.NULL+ : arena.allocateFrom(workingDirectory.getAbsolutePath(),+ utf16le), // lpCurrentDirectory+ sie, // lpStartupInfo+ pi), cs); // lpProcessInformation++ Win32Err.checkFalse(win32_h.AssignProcessToJobObject(cs, hJob.asSegment(),+ _PROCESS_INFORMATION.hProcess(pi)), cs);++ return new LocalWindowsNativeProcessPtySession(+ _PROCESS_INFORMATION.dwProcessId(pi),+ _PROCESS_INFORMATION.dwThreadId(pi),+ new Handle(_PROCESS_INFORMATION.hProcess(pi)),+ new Handle(_PROCESS_INFORMATION.hThread(pi)),+ "ConPTY",+ hJob);}-- if (!JobApiNative.INSTANCE.AssignProcessToJobObject(hJob, pi.hProcess).booleanValue()) {- throw new LastErrorException(Kernel32.INSTANCE.GetLastError());- }-- return new LocalWindowsNativeProcessPtySession(pi.dwProcessId.intValue(),- pi.dwThreadId.intValue(), new Handle(pi.hProcess), new Handle(pi.hThread), "ConPTY",- new Handle(hJob));}@Overridediff --git a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/Handle.java b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/Handle.javaindex eefdd112dc..a6b45610a8 100644--- a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/Handle.java+++ b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/Handle.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -15,26 +15,27 @@*/package ghidra.pty.windows;+import java.lang.foreign.Arena;+import java.lang.foreign.MemorySegment;import java.lang.ref.Cleaner;-import com.sun.jna.LastErrorException;-import com.sun.jna.platform.win32.Kernel32;-import com.sun.jna.platform.win32.WinNT.HANDLE;+import com.microsoft.win32.win32_h;public class Handle implements AutoCloseable {private static final Cleaner CLEANER = Cleaner.create();protected static class State implements Runnable {- protected final HANDLE handle;+ protected final long handle;- protected State(HANDLE handle) {+ protected State(long handle) {this.handle = handle;}@Overridepublic void run() {- if (!Kernel32.INSTANCE.CloseHandle(handle)) {- throw new LastErrorException(Kernel32.INSTANCE.GetLastError());+ try (Arena arena = Arena.ofConfined()) {+ MemorySegment cs = arena.allocate(Win32Err.LAYOUT);+ Win32Err.checkFalse(win32_h.CloseHandle(cs, MemorySegment.ofAddress(handle)), cs);}}}@@ -42,12 +43,12 @@ public class Handle implements AutoCloseable {private final State state;private final Cleaner.Cleanable cleanable;- public Handle(HANDLE handle) {- this.state = newState(handle);+ public Handle(MemorySegment handle) {+ this.state = newState(handle.address());this.cleanable = CLEANER.register(this, state);}- protected State newState(HANDLE handle) {+ protected State newState(long handle) {return new State(handle);}@@ -56,11 +57,7 @@ public class Handle implements AutoCloseable {cleanable.clean();}- public HANDLE getNative() {- HANDLE handle = state.handle;- if (handle == null) {- throw new IllegalStateException("This handle is no longer valid");- }- return handle;+ public MemorySegment asSegment() {+ return MemorySegment.ofAddress(state.handle);}}diff --git a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/HandleInputStream.java b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/HandleInputStream.javaindex 312e6b9ccf..ef6f240430 100644--- a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/HandleInputStream.java+++ b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/HandleInputStream.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -17,14 +17,15 @@ package ghidra.pty.windows;import java.io.IOException;import java.io.InputStream;+import java.lang.foreign.*;-import com.sun.jna.LastErrorException;-import com.sun.jna.platform.win32.Kernel32;-import com.sun.jna.ptr.IntByReference;+import com.microsoft.win32.win32_h;++import ghidra.pty.windows.Win32Err.LastErrorException;public class HandleInputStream extends InputStream {private final Handle handle;- private boolean closed = false;+ private volatile boolean closed = false;HandleInputStream(Handle handle) {this.handle = handle;@@ -42,51 +43,57 @@ public class HandleInputStream extends InputStream {return buf[0] & 0x0FF;}- protected void waitPipeConnected() {- if (Kernel32.INSTANCE.ConnectNamedPipe(handle.getNative(), null)) {+ protected void waitPipeConnected(MemorySegment cs) {+ try {+ Win32Err.checkFalse(+ win32_h.ConnectNamedPipe(cs, handle.asSegment(), MemorySegment.NULL), cs);return; // We waited, and now we're connected}- int error = Kernel32.INSTANCE.GetLastError();- if (error == Kernel32.ERROR_PIPE_CONNECTED) {- return; // We got the connection before we waited. OK+ catch (LastErrorException e) {+ if (e.getLastError() == win32_h.ERROR_PIPE_CONNECTED()) {+ return; // We got the connection before we waited. OK.+ }+ throw e;}- throw new LastErrorException(error);}@Overridepublic synchronized int read(byte[] b) throws IOException {- if (closed) {- throw new IOException("Stream closed");- }- IntByReference dwRead = new IntByReference();-- while (!Kernel32.INSTANCE.ReadFile(handle.getNative(), b, b.length, dwRead, null)) {- int error = Kernel32.INSTANCE.GetLastError();- switch (error) {- case Kernel32.ERROR_BROKEN_PIPE:- return -1;- case Kernel32.ERROR_PIPE_LISTENING:- /**- * Well, we know we're dealing with a listening pipe, now. Wait for a client,- * then try reading again.- */- waitPipeConnected();- continue;- }- throw new IOException("Could not read",- new LastErrorException(error));- }- return dwRead.getValue();+ return read(b, 0, b.length);}@Overridepublic synchronized int read(byte[] b, int off, int len) throws IOException {- byte[] temp = new byte[len];- int read = read(temp);- if (read > 0) {- System.arraycopy(temp, 0, b, off, read);+ if (closed) {+ throw new IOException("Stream closed");+ }+ if (len == 0) {+ return 0;+ }+ try (Arena arena = Arena.ofConfined()) {+ MemorySegment cs = arena.allocate(Win32Err.LAYOUT);+ MemorySegment buf = arena.allocate(len);+ MemorySegment dwRead = arena.allocate(win32_h.DWORD);+ while (true) {+ try {+ Win32Err.checkFalse(win32_h.ReadFile(cs, handle.asSegment(), buf, len, dwRead,+ MemorySegment.NULL), cs);+ int ret = dwRead.get(win32_h.DWORD, 0);+ MemorySegment.copy(buf, ValueLayout.JAVA_BYTE, 0, b, off, ret);+ return ret;+ }+ catch (LastErrorException e) {+ if (e.getLastError() == win32_h.ERROR_BROKEN_PIPE()) {+ return -1;+ }+ if (e.getLastError() == win32_h.ERROR_PIPE_LISTENING()) {+ waitPipeConnected(cs);+ continue;+ }+ throw new IOException("Could not read", e);+ }+ }}- return read;}@Overridediff --git a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/HandleOutputStream.java b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/HandleOutputStream.javaindex bfe073c72e..adf25d1578 100644--- a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/HandleOutputStream.java+++ b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/HandleOutputStream.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -17,11 +17,11 @@ package ghidra.pty.windows;import java.io.IOException;import java.io.OutputStream;-import java.util.Arrays;+import java.lang.foreign.*;-import com.sun.jna.LastErrorException;-import com.sun.jna.platform.win32.Kernel32;-import com.sun.jna.ptr.IntByReference;+import com.microsoft.win32.win32_h;++import ghidra.pty.windows.Win32Err.LastErrorException;public class HandleOutputStream extends OutputStream {private final Handle handle;@@ -38,27 +38,35 @@ public class HandleOutputStream extends OutputStream {@Overridepublic synchronized void write(byte[] b) throws IOException {+ write(b, 0, b.length);+ }++ @Override+ public synchronized void write(byte[] b, int off, int len) throws IOException {if (closed) {throw new IOException("Stream closed");}-- int total = 0;- do {- IntByReference dwWritten = new IntByReference();- if (!Kernel32.INSTANCE.WriteFile(handle.getNative(), b, b.length, dwWritten, null)) {- throw new IOException("Could not write",- new LastErrorException(Kernel32.INSTANCE.GetLastError()));+ if (len == 0) {+ return;+ }+ try (Arena arena = Arena.ofConfined()) {+ MemorySegment cs = arena.allocate(Win32Err.LAYOUT);+ MemorySegment buf = arena.allocate(len);+ MemorySegment.copy(b, off, buf, ValueLayout.JAVA_BYTE, 0, len);+ MemorySegment dwWritten = arena.allocate(win32_h.DWORD);+ int total = 0;+ do {+ MemorySegment slice = buf.asSlice(total);+ Win32Err.checkFalse(win32_h.WriteFile(cs, handle.asSegment(), slice, len - total,+ dwWritten, MemorySegment.NULL), cs);+ total += dwWritten.get(win32_h.DWORD, 0);}- total += dwWritten.getValue();+ while (total < len);+ }+ catch (LastErrorException e) {+ // LATER: Should select specific error numbers?+ throw new IOException(e);}- while (total < b.length);- }-- @Override- public synchronized void write(byte[] b, int off, int len) throws IOException {- // Abstraction of Windows API given by JNA doesn't have offset- // In C, could add offset to lpBuffer, but not here :(- write(Arrays.copyOfRange(b, off, off + len));}@Override@@ -67,8 +75,7 @@ public class HandleOutputStream extends OutputStream {}/**- * Check whether this handle has buffered output- *+ * {@return true if this handle has buffered output}* <p>* Windows can get touchy when trying to flush handles that are not actually buffered. If the* wrapped handle is not buffered, then this method must return false, otherwise, any attempt to@@ -85,8 +92,9 @@ public class HandleOutputStream extends OutputStream {if (!isBuffered()) {return;}- if (!(Kernel32.INSTANCE.FlushFileBuffers(handle.getNative()))) {- throw new LastErrorException(Kernel32.INSTANCE.GetLastError());+ try (Arena arena = Arena.ofConfined()) {+ MemorySegment cs = arena.allocate(Win32Err.LAYOUT);+ Win32Err.checkFalse(win32_h.FlushFileBuffers(cs, handle.asSegment()), cs);}}}diff --git a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/HandlePtr.java b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/HandlePtr.javanew file mode 100644index 0000000000..3155319108--- /dev/null+++ b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/HandlePtr.java@@ -0,0 +1,37 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.pty.windows;++import java.lang.foreign.Arena;+import java.lang.foreign.MemorySegment;++import com.microsoft.win32.win32_h;++public class HandlePtr {+ private final MemorySegment seg;++ public HandlePtr(Arena arena) {+ this.seg = arena.allocate(win32_h.HANDLE);+ }++ public MemorySegment asSegment() {+ return seg;+ }++ public MemorySegment get() {+ return seg.get(win32_h.HANDLE, 0);+ }+}diff --git a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/Pipe.java b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/Pipe.javaindex 50d7f48d9a..0c71386284 100644--- a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/Pipe.java+++ b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/Pipe.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -15,20 +15,21 @@*/package ghidra.pty.windows;-import com.sun.jna.LastErrorException;-import com.sun.jna.platform.win32.Kernel32;-import com.sun.jna.platform.win32.WinBase.SECURITY_ATTRIBUTES;-import com.sun.jna.platform.win32.WinNT.HANDLEByReference;+import java.lang.foreign.Arena;+import java.lang.foreign.MemorySegment;++import com.microsoft.win32.win32_h;public class Pipe {public static Pipe createPipe() {- HANDLEByReference pRead = new HANDLEByReference();- HANDLEByReference pWrite = new HANDLEByReference();-- if (!Kernel32.INSTANCE.CreatePipe(pRead, pWrite, new SECURITY_ATTRIBUTES(), 0)) {- throw new LastErrorException(Kernel32.INSTANCE.GetLastError());+ try (Arena arena = Arena.ofConfined()) {+ MemorySegment cs = arena.allocate(Win32Err.LAYOUT);+ HandlePtr pRead = new HandlePtr(arena);+ HandlePtr pWrite = new HandlePtr(arena);+ Win32Err.checkFalse(win32_h.CreatePipe(cs, pRead.asSegment(), pWrite.asSegment(),+ MemorySegment.NULL, 0), cs);+ return new Pipe(new Handle(pRead.get()), new Handle(pWrite.get()));}- return new Pipe(new Handle(pRead.getValue()), new Handle(pWrite.getValue()));}private final Handle readHandle;diff --git a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/PseudoConsoleHandle.java b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/PseudoConsoleHandle.javaindex d7598008b1..e23585f235 100644--- a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/PseudoConsoleHandle.java+++ b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/PseudoConsoleHandle.java@@ -4,9 +4,9 @@* Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at- *+ ** http://www.apache.org/licenses/LICENSE-2.0- *+ ** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.@@ -15,38 +15,41 @@*/package ghidra.pty.windows;-import com.sun.jna.platform.win32.WinNT.HANDLE;-import com.sun.jna.platform.win32.COM.COMUtils;+import java.lang.foreign.Arena;+import java.lang.foreign.MemorySegment;-import ghidra.pty.windows.jna.ConsoleApiNative;-import ghidra.pty.windows.jna.ConsoleApiNative.COORD;+import com.microsoft.win32._COORD;+import com.microsoft.win32.win32_h;public class PseudoConsoleHandle extends Handle {protected static class PseudoConsoleState extends State {- public PseudoConsoleState(HANDLE handle) {+ public PseudoConsoleState(long handle) {super(handle);}@Overridepublic void run() {- ConsoleApiNative.INSTANCE.ClosePseudoConsole(handle);+ win32_h.ClosePseudoConsole(MemorySegment.ofAddress(handle));}}- public PseudoConsoleHandle(HANDLE handle) {+ public PseudoConsoleHandle(MemorySegment handle) {super(handle);}@Override- protected State newState(HANDLE handle) {+ protected State newState(long handle) {return new PseudoConsoleState(handle);}public void resize(short rows, short cols) {- COORD.ByValue size = new COORD.ByValue();- size.X = cols;- size.Y = rows;- COMUtils.checkRC(ConsoleApiNative.INSTANCE.ResizePseudoConsole(getNative(), size));+ try (Arena arena = Arena.ofConfined()) {+ MemorySegment cs = arena.allocate(Win32Err.LAYOUT);+ MemorySegment size = _COORD.allocate(arena);+ _COORD.X(size, cols);+ _COORD.Y(size, rows);+ Win32Err.checkHResult(win32_h.ResizePseudoConsole(cs, asSegment(), size), cs);+ }}}diff --git a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/Win32Err.java b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/Win32Err.javanew file mode 100644index 0000000000..f984b7cb92--- /dev/null+++ b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/Win32Err.java@@ -0,0 +1,96 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+package ghidra.pty.windows;++import java.lang.foreign.*;+import java.lang.invoke.VarHandle;+import java.nio.charset.Charset;++import com.microsoft.win32.win32_h;++public interface Win32Err {+ Linker.Option OPT_CAPTURE_LASTERROR = Linker.Option.captureCallState("GetLastError");+ StructLayout LAYOUT = Linker.Option.captureStateLayout();+ VarHandle LASTERROR = LAYOUT.varHandle(MemoryLayout.PathElement.groupElement("GetLastError"));++ class LastErrorException extends RuntimeException {+ private final int lastError;++ public LastErrorException(int lastError, String message) {+ super("[%d] %s".formatted(lastError, message));+ this.lastError = lastError;+ }++ public int getLastError() {+ return lastError;+ }+ }++ static String formatMessage(int lastError) {+ try (Arena arena = Arena.ofConfined()) {+ MemorySegment pBuf = arena.allocate(win32_h.LPWSTR);+ int lenWchars = win32_h.FormatMessageW(+ win32_h.FORMAT_MESSAGE_ALLOCATE_BUFFER() | win32_h.FORMAT_MESSAGE_ARGUMENT_ARRAY() |+ win32_h.FORMAT_MESSAGE_FROM_SYSTEM() | win32_h.FORMAT_MESSAGE_IGNORE_INSERTS(),+ // dwFlags+ MemorySegment.NULL, // lpSource+ lastError, // dwMessageId+ 0, // dwLanguageId+ pBuf, // lpBuffer+ 0, // nSize+ MemorySegment.NULL); // Arguments+ if (lenWchars == 0) {+ return "[FormatMessage failed]";+ }+ int lenBytes = lenWchars * 2;+ MemorySegment unmanaged = pBuf.get(win32_h.LPWSTR, 0);+ byte[] managed = new byte[lenBytes];+ MemorySegment.copy(unmanaged, ValueLayout.JAVA_BYTE, 0, managed, 0, lenBytes);+ win32_h.LocalFree(unmanaged);+ return new String(managed, Charset.forName("UTF-16LE"));+ }+ }++ static void checkFalse(int result, MemorySegment cs) {+ if (result == 0) {+ int lastError = (int) LASTERROR.get(cs, 0);+ throw new LastErrorException(lastError, formatMessage(lastError));+ }+ }++ static void checkHResult(int result, MemorySegment cs) {+ if (result != win32_h.S_OK()) {+ int lastError = (int) LASTERROR.get(cs, 0);+ throw new LastErrorException(lastError, formatMessage(lastError));+ }+ }++ static MemorySegment checkNull(MemorySegment result, MemorySegment cs) {+ if (result.address() == 0) {+ int lastError = (int) LASTERROR.get(cs, 0);+ throw new LastErrorException(lastError, formatMessage(lastError));+ }+ return result;+ }++ static int checkWaitFailed(int result, MemorySegment cs) {+ if (result == win32_h.WAIT_FAILED()) {+ int lastError = (int) LASTERROR.get(cs, 0);+ throw new LastErrorException(lastError, formatMessage(lastError));+ }+ return result;+ }+}diff --git a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/jna/ConsoleApiNative.java b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/jna/ConsoleApiNative.javadeleted file mode 100644index 72efc340b4..0000000000--- a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/jna/ConsoleApiNative.java+++ /dev/null@@ -1,158 +0,0 @@-/* ###- * IP: GHIDRA- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */-package ghidra.pty.windows.jna;--import java.util.List;--import com.sun.jna.*;-import com.sun.jna.Structure.FieldOrder;-import com.sun.jna.platform.win32.WinBase;-import com.sun.jna.platform.win32.WinDef.*;-import com.sun.jna.platform.win32.WinNT.*;-import com.sun.jna.win32.StdCallLibrary;--public interface ConsoleApiNative extends StdCallLibrary {- ConsoleApiNative INSTANCE = Native.load("Kernel32.dll", ConsoleApiNative.class);- BOOL FAIL = new BOOL(false);-- BOOL CreatePipe(HANDLEByReference hReadPipe, HANDLEByReference hWritePipe,- SECURITY_ATTRIBUTES.ByReference lpPipeAttributes, DWORD nSize);-- HRESULT CreatePseudoConsole(COORD.ByValue size, HANDLE hInput, HANDLE hOutput,- DWORD dwFlags, HANDLEByReference phPC);-- HRESULT ResizePseudoConsole(HANDLE hPC, COORD.ByValue size);-- void ClosePseudoConsole(HANDLE hPC);-- BOOL InitializeProcThreadAttributeList(Pointer lpAttributeList,- DWORD dwAttributeCount, DWORD dwFlags, UINTByReference lpSize);-- BOOL UpdateProcThreadAttribute(- Pointer lpAttributeList,- DWORD dwFlags,- DWORD Attribute,- PVOID lpValue,- DWORD cbSize,- PVOID lpPreviousValue,- ULONGLONGByReference lpReturnSize);-- BOOL CreateProcessW(- WString lpApplicationName,- WString lpCommandLine,- WinBase.SECURITY_ATTRIBUTES lpProcessAttributes,- WinBase.SECURITY_ATTRIBUTES lpThreadAttributes,- boolean bInheritHandles,- DWORD dwCreationFlags,- WString lpEnvironment,- WString lpCurrentDirectory,- STARTUPINFOEX lpStartupInfo,- WinBase.PROCESS_INFORMATION lpProcessInformation);-- /*- BOOL GetConsoleMode(- HANDLE hConsoleMode,- DWORDByReference dwMode);-- BOOL CreateProcessWithTokenW(- HANDLE hToken,- DWORD dwLogonFlags,- WString lpApplicationName,- WString lpCommandLine,- DWORD dwCreationFlags,- Pointer lpEnvironment,- WString lpCurrentDirectory,- STARTUPINFOEX lpStartupInfo,- WinBase.PROCESS_INFORMATION lpProcessInformation);-- BOOL LogonUserW(- WString lpUsername,- WString lpDomain,- WString lpPassword,- DWORD dwLogonType,- DWORD dwLogonProvider,- HANDLEByReference phToken);- */-- @FieldOrder({ "X", "Y" })- public static class COORD extends Structure {- public static class ByValue extends COORD implements Structure.ByValue {- }-- public static class ByReference extends COORD implements Structure.ByReference {- }-- public short X;- public short Y;- }-- public static class SECURITY_ATTRIBUTES extends Structure {- public static class ByReference extends SECURITY_ATTRIBUTES- implements Structure.ByReference {- }-- public static final List<String> FIELDS = createFieldsOrder(- "nLength", "lpSecurityDescriptor", "bInheritedHandle");-- public DWORD nLength;- public ULONGLONG lpSecurityDescriptor;- public BOOL bInheritedHandle;-- @Override- protected List<String> getFieldOrder() {- return FIELDS;- }- }-- public static class PROC_THREAD_ATTRIBUTE_LIST extends Structure {- public static class ByReference extends PROC_THREAD_ATTRIBUTE_LIST- implements Structure.ByReference {- }-- public static final List<String> FIELDS = createFieldsOrder(- "dwFlags", "Size", "Count", "Reserved", "Unknown");-- public DWORD dwFlags;- public ULONG Size;- public ULONG Count;- public ULONG Reserved;- public ULONGLONG Unknown;- //public PROC_THREAD_ATTRIBUTE_ENTRY Entries[0];-- @Override- protected List<String> getFieldOrder() {- return FIELDS;- }- }-- public static class STARTUPINFOEX extends Structure {- public static class ByReference extends STARTUPINFOEX- implements Structure.ByReference {- }-- public static final List<String> FIELDS = createFieldsOrder(- "StartupInfo", "lpAttributeList");-- public WinBase.STARTUPINFO StartupInfo;- public Pointer lpAttributeList;-- @Override- protected List<String> getFieldOrder() {- return FIELDS;- }- }--}diff --git a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/jna/JobApiNative.java b/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/jna/JobApiNative.javadeleted file mode 100644index 38d7638c81..0000000000--- a/Ghidra/Framework/Pty/src/main/java/ghidra/pty/windows/jna/JobApiNative.java+++ /dev/null@@ -1,34 +0,0 @@-/* ###- * IP: GHIDRA- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */-package ghidra.pty.windows.jna;--import com.sun.jna.Native;-import com.sun.jna.WString;-import com.sun.jna.platform.win32.WinDef.BOOL;-import com.sun.jna.platform.win32.WinNT.HANDLE;-import com.sun.jna.win32.StdCallLibrary;--import ghidra.pty.windows.jna.ConsoleApiNative.SECURITY_ATTRIBUTES;--public interface JobApiNative extends StdCallLibrary {- JobApiNative INSTANCE = Native.load("kernel32.dll", JobApiNative.class);-- HANDLE CreateJobObjectW(SECURITY_ATTRIBUTES.ByReference lpJobAttributes, WString lpName);-- BOOL AssignProcessToJobObject(HANDLE hJob, HANDLE hProcess);-- BOOL TerminateJobObject(HANDLE hJob, int uExitCode);-}diff --git a/Ghidra/Framework/Pty/src/main/java/org/unix/fcntl_h$shared.java b/Ghidra/Framework/Pty/src/main/java/org/unix/fcntl_h$shared.javanew file mode 100644index 0000000000..71cfed0846--- /dev/null+++ b/Ghidra/Framework/Pty/src/main/java/org/unix/fcntl_h$shared.java@@ -0,0 +1,78 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+// Generated by jextract++package org.unix;++import java.lang.invoke.*;+import java.lang.foreign.*;+import java.nio.ByteOrder;+import java.util.*;+import java.util.function.*;+import java.util.stream.*;++import static java.lang.foreign.ValueLayout.*;+import static java.lang.foreign.MemoryLayout.PathElement.*;++public class fcntl_h$shared {++ fcntl_h$shared() {+ // Should not be called directly+ }++ public static final ValueLayout.OfBoolean C_BOOL = (ValueLayout.OfBoolean) Linker.nativeLinker().canonicalLayouts().get("bool");+ public static final ValueLayout.OfByte C_CHAR =(ValueLayout.OfByte)Linker.nativeLinker().canonicalLayouts().get("char");+ public static final ValueLayout.OfShort C_SHORT = (ValueLayout.OfShort) Linker.nativeLinker().canonicalLayouts().get("short");+ public static final ValueLayout.OfInt C_INT = (ValueLayout.OfInt) Linker.nativeLinker().canonicalLayouts().get("int");+ public static final ValueLayout.OfLong C_LONG_LONG = (ValueLayout.OfLong) Linker.nativeLinker().canonicalLayouts().get("long long");+ public static final ValueLayout.OfFloat C_FLOAT = (ValueLayout.OfFloat) Linker.nativeLinker().canonicalLayouts().get("float");+ public static final ValueLayout.OfDouble C_DOUBLE = (ValueLayout.OfDouble) Linker.nativeLinker().canonicalLayouts().get("double");+ public static final AddressLayout C_POINTER = ((AddressLayout) Linker.nativeLinker().canonicalLayouts().get("void*"))+ .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, C_CHAR));+ public static final ValueLayout.OfLong C_LONG = (ValueLayout.OfLong) Linker.nativeLinker().canonicalLayouts().get("long");++ static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls");++ static void traceDowncall(String name, Object... args) {+ String traceArgs = Arrays.stream(args)+ .map(Object::toString)+ .collect(Collectors.joining(", "));+ System.out.printf("%s(%s)\n", name, traceArgs);+ }++ static MethodHandle upcallHandle(Class<?> fi, String name, FunctionDescriptor fdesc) {+ try {+ return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType());+ } catch (ReflectiveOperationException ex) {+ throw new AssertionError(ex);+ }+ }++ static MemoryLayout align(MemoryLayout layout, long align) {+ return switch (layout) {+ case PaddingLayout p -> p;+ case ValueLayout v -> v.withByteAlignment(align);+ case GroupLayout g -> {+ MemoryLayout[] alignedMembers = g.memberLayouts().stream()+ .map(m -> align(m, align)).toArray(MemoryLayout[]::new);+ yield g instanceof StructLayout ?+ MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers);+ }+ case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align));+ };+ }+}+diff --git a/Ghidra/Framework/Pty/src/main/java/org/unix/fcntl_h.java b/Ghidra/Framework/Pty/src/main/java/org/unix/fcntl_h.javanew file mode 100644index 0000000000..a9b536fd0f--- /dev/null+++ b/Ghidra/Framework/Pty/src/main/java/org/unix/fcntl_h.java@@ -0,0 +1,132 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+// Generated by jextract++package org.unix;++import java.lang.invoke.*;+import java.lang.foreign.*;+import java.nio.ByteOrder;+import java.util.*;+import java.util.function.*;+import java.util.stream.*;++import ghidra.pty.unix.UnixErr;++import static java.lang.foreign.ValueLayout.*;+import static java.lang.foreign.MemoryLayout.PathElement.*;++public class fcntl_h extends fcntl_h$shared {++ fcntl_h() {+ // Should not be called directly+ }++ static final Arena LIBRARY_ARENA = Arena.ofAuto();++ static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.loaderLookup()+ .or(Linker.nativeLinker().defaultLookup());++ private static final int O_RDWR = (int)2L;+ /**+ * {@snippet lang=c :+ * #define O_RDWR 2+ * }+ */+ public static int O_RDWR() {+ return O_RDWR;+ }+ /**+ * {@snippet lang=c :+ * typedef __mode_t mode_t+ * }+ */+ public static final OfInt mode_t = fcntl_h.C_INT;++ /**+ * Variadic invoker class for:+ * {@snippet lang=c :+ * extern int open(const char *__file, int __oflag, ...)+ * }+ */+ public static class open {+ private static final FunctionDescriptor BASE_DESC = FunctionDescriptor.of(+ fcntl_h.C_INT,+ fcntl_h.C_POINTER,+ fcntl_h.C_INT+ );+ private static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("open");++ private final MethodHandle handle;+ private final FunctionDescriptor descriptor;+ private final MethodHandle spreader;++ private open(MethodHandle handle, FunctionDescriptor descriptor, MethodHandle spreader) {+ this.handle = handle;+ this.descriptor = descriptor;+ this.spreader = spreader;+ }++ /**+ * Variadic invoker factory for:+ * {@snippet lang=c :+ * extern int open(const char *__file, int __oflag, ...)+ * }+ */+ public static open makeInvoker(MemoryLayout... layouts) {+ FunctionDescriptor desc$ = BASE_DESC.appendArgumentLayouts(layouts);+ Linker.Option fva$ = Linker.Option.firstVariadicArg(BASE_DESC.argumentLayouts().size());+ var mh$ = Linker.nativeLinker().downcallHandle(ADDR, desc$, fva$, UnixErr.OPT_CAPTURE_ERRNO);+ var spreader$ = mh$.asSpreader(Object[].class, layouts.length);+ return new open(mh$, desc$, spreader$);+ }++ /**+ * {@return the address}+ */+ public static MemorySegment address() {+ return ADDR;+ }++ /**+ * {@return the specialized method handle}+ */+ public MethodHandle handle() {+ return handle;+ }++ /**+ * {@return the specialized descriptor}+ */+ public FunctionDescriptor descriptor() {+ return descriptor;+ }++ public int apply(MemorySegment cs, MemorySegment __file, int __oflag, Object... x2) {+ try {+ if (TRACE_DOWNCALLS) {+ traceDowncall("open", __file, __oflag, x2);+ }+ return (int) spreader.invokeExact(cs, __file, __oflag, x2);+ } catch(IllegalArgumentException | ClassCastException ex$) {+ throw ex$; // rethrow IAE from passing wrong number/type of args+ } catch (Throwable ex$) {+ throw new AssertionError("should not reach here", ex$);+ }+ }+ }+}+diff --git a/Ghidra/Framework/Pty/src/main/java/org/unix/ioctl_h$shared.java b/Ghidra/Framework/Pty/src/main/java/org/unix/ioctl_h$shared.javanew file mode 100644index 0000000000..9ed72fe235--- /dev/null+++ b/Ghidra/Framework/Pty/src/main/java/org/unix/ioctl_h$shared.java@@ -0,0 +1,78 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+// Generated by jextract++package org.unix;++import java.lang.invoke.*;+import java.lang.foreign.*;+import java.nio.ByteOrder;+import java.util.*;+import java.util.function.*;+import java.util.stream.*;++import static java.lang.foreign.ValueLayout.*;+import static java.lang.foreign.MemoryLayout.PathElement.*;++public class ioctl_h$shared {++ ioctl_h$shared() {+ // Should not be called directly+ }++ public static final ValueLayout.OfBoolean C_BOOL = (ValueLayout.OfBoolean) Linker.nativeLinker().canonicalLayouts().get("bool");+ public static final ValueLayout.OfByte C_CHAR =(ValueLayout.OfByte)Linker.nativeLinker().canonicalLayouts().get("char");+ public static final ValueLayout.OfShort C_SHORT = (ValueLayout.OfShort) Linker.nativeLinker().canonicalLayouts().get("short");+ public static final ValueLayout.OfInt C_INT = (ValueLayout.OfInt) Linker.nativeLinker().canonicalLayouts().get("int");+ public static final ValueLayout.OfLong C_LONG_LONG = (ValueLayout.OfLong) Linker.nativeLinker().canonicalLayouts().get("long long");+ public static final ValueLayout.OfFloat C_FLOAT = (ValueLayout.OfFloat) Linker.nativeLinker().canonicalLayouts().get("float");+ public static final ValueLayout.OfDouble C_DOUBLE = (ValueLayout.OfDouble) Linker.nativeLinker().canonicalLayouts().get("double");+ public static final AddressLayout C_POINTER = ((AddressLayout) Linker.nativeLinker().canonicalLayouts().get("void*"))+ .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, C_CHAR));+ public static final ValueLayout.OfLong C_LONG = (ValueLayout.OfLong) Linker.nativeLinker().canonicalLayouts().get("long");++ static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls");++ static void traceDowncall(String name, Object... args) {+ String traceArgs = Arrays.stream(args)+ .map(Object::toString)+ .collect(Collectors.joining(", "));+ System.out.printf("%s(%s)\n", name, traceArgs);+ }++ static MethodHandle upcallHandle(Class<?> fi, String name, FunctionDescriptor fdesc) {+ try {+ return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType());+ } catch (ReflectiveOperationException ex) {+ throw new AssertionError(ex);+ }+ }++ static MemoryLayout align(MemoryLayout layout, long align) {+ return switch (layout) {+ case PaddingLayout p -> p;+ case ValueLayout v -> v.withByteAlignment(align);+ case GroupLayout g -> {+ MemoryLayout[] alignedMembers = g.memberLayouts().stream()+ .map(m -> align(m, align)).toArray(MemoryLayout[]::new);+ yield g instanceof StructLayout ?+ MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers);+ }+ case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align));+ };+ }+}+diff --git a/Ghidra/Framework/Pty/src/main/java/org/unix/ioctl_h.java b/Ghidra/Framework/Pty/src/main/java/org/unix/ioctl_h.javanew file mode 100644index 0000000000..7073148da2--- /dev/null+++ b/Ghidra/Framework/Pty/src/main/java/org/unix/ioctl_h.java@@ -0,0 +1,117 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+// Generated by jextract++package org.unix;++import java.lang.invoke.*;+import java.lang.foreign.*;+import java.nio.ByteOrder;+import java.util.*;+import java.util.function.*;+import java.util.stream.*;++import ghidra.pty.unix.UnixErr;++import static java.lang.foreign.ValueLayout.*;+import static java.lang.foreign.MemoryLayout.PathElement.*;++public class ioctl_h extends ioctl_h$shared {++ ioctl_h() {+ // Should not be called directly+ }++ static final Arena LIBRARY_ARENA = Arena.ofAuto();++ static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.loaderLookup()+ .or(Linker.nativeLinker().defaultLookup());+++ /**+ * Variadic invoker class for:+ * {@snippet lang=c :+ * extern int ioctl(int __fd, unsigned long __request, ...)+ * }+ */+ public static class ioctl {+ private static final FunctionDescriptor BASE_DESC = FunctionDescriptor.of(+ ioctl_h.C_INT,+ ioctl_h.C_INT,+ ioctl_h.C_LONG+ );+ private static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("ioctl");++ private final MethodHandle handle;+ private final FunctionDescriptor descriptor;+ private final MethodHandle spreader;++ private ioctl(MethodHandle handle, FunctionDescriptor descriptor, MethodHandle spreader) {+ this.handle = handle;+ this.descriptor = descriptor;+ this.spreader = spreader;+ }++ /**+ * Variadic invoker factory for:+ * {@snippet lang=c :+ * extern int ioctl(int __fd, unsigned long __request, ...)+ * }+ */+ public static ioctl makeInvoker(MemoryLayout... layouts) {+ FunctionDescriptor desc$ = BASE_DESC.appendArgumentLayouts(layouts);+ Linker.Option fva$ = Linker.Option.firstVariadicArg(BASE_DESC.argumentLayouts().size());+ var mh$ = Linker.nativeLinker().downcallHandle(ADDR, desc$, fva$, UnixErr.OPT_CAPTURE_ERRNO);+ var spreader$ = mh$.asSpreader(Object[].class, layouts.length);+ return new ioctl(mh$, desc$, spreader$);+ }++ /**+ * {@return the address}+ */+ public static MemorySegment address() {+ return ADDR;+ }++ /**+ * {@return the specialized method handle}+ */+ public MethodHandle handle() {+ return handle;+ }++ /**+ * {@return the specialized descriptor}+ */+ public FunctionDescriptor descriptor() {+ return descriptor;+ }++ public int apply(MemorySegment cs, int __fd, long __request, Object... x2) {+ try {+ if (TRACE_DOWNCALLS) {+ traceDowncall("ioctl", __fd, __request, x2);+ }+ return (int) spreader.invokeExact(cs, __fd, __request, x2);+ } catch(IllegalArgumentException | ClassCastException ex$) {+ throw ex$; // rethrow IAE from passing wrong number/type of args+ } catch (Throwable ex$) {+ throw new AssertionError("should not reach here", ex$);+ }+ }+ }+}+diff --git a/Ghidra/Framework/Pty/src/main/java/org/unix/pty_h$shared.java b/Ghidra/Framework/Pty/src/main/java/org/unix/pty_h$shared.javanew file mode 100644index 0000000000..9774428e31--- /dev/null+++ b/Ghidra/Framework/Pty/src/main/java/org/unix/pty_h$shared.java@@ -0,0 +1,78 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+// Generated by jextract++package org.unix;++import java.lang.invoke.*;+import java.lang.foreign.*;+import java.nio.ByteOrder;+import java.util.*;+import java.util.function.*;+import java.util.stream.*;++import static java.lang.foreign.ValueLayout.*;+import static java.lang.foreign.MemoryLayout.PathElement.*;++public class pty_h$shared {++ pty_h$shared() {+ // Should not be called directly+ }++ public static final ValueLayout.OfBoolean C_BOOL = (ValueLayout.OfBoolean) Linker.nativeLinker().canonicalLayouts().get("bool");+ public static final ValueLayout.OfByte C_CHAR =(ValueLayout.OfByte)Linker.nativeLinker().canonicalLayouts().get("char");+ public static final ValueLayout.OfShort C_SHORT = (ValueLayout.OfShort) Linker.nativeLinker().canonicalLayouts().get("short");+ public static final ValueLayout.OfInt C_INT = (ValueLayout.OfInt) Linker.nativeLinker().canonicalLayouts().get("int");+ public static final ValueLayout.OfLong C_LONG_LONG = (ValueLayout.OfLong) Linker.nativeLinker().canonicalLayouts().get("long long");+ public static final ValueLayout.OfFloat C_FLOAT = (ValueLayout.OfFloat) Linker.nativeLinker().canonicalLayouts().get("float");+ public static final ValueLayout.OfDouble C_DOUBLE = (ValueLayout.OfDouble) Linker.nativeLinker().canonicalLayouts().get("double");+ public static final AddressLayout C_POINTER = ((AddressLayout) Linker.nativeLinker().canonicalLayouts().get("void*"))+ .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, C_CHAR));+ public static final ValueLayout.OfLong C_LONG = (ValueLayout.OfLong) Linker.nativeLinker().canonicalLayouts().get("long");++ static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls");++ static void traceDowncall(String name, Object... args) {+ String traceArgs = Arrays.stream(args)+ .map(Object::toString)+ .collect(Collectors.joining(", "));+ System.out.printf("%s(%s)\n", name, traceArgs);+ }++ static MethodHandle upcallHandle(Class<?> fi, String name, FunctionDescriptor fdesc) {+ try {+ return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType());+ } catch (ReflectiveOperationException ex) {+ throw new AssertionError(ex);+ }+ }++ static MemoryLayout align(MemoryLayout layout, long align) {+ return switch (layout) {+ case PaddingLayout p -> p;+ case ValueLayout v -> v.withByteAlignment(align);+ case GroupLayout g -> {+ MemoryLayout[] alignedMembers = g.memberLayouts().stream()+ .map(m -> align(m, align)).toArray(MemoryLayout[]::new);+ yield g instanceof StructLayout ?+ MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers);+ }+ case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align));+ };+ }+}+diff --git a/Ghidra/Framework/Pty/src/main/java/org/unix/pty_h.java b/Ghidra/Framework/Pty/src/main/java/org/unix/pty_h.javanew file mode 100644index 0000000000..62f82821a4--- /dev/null+++ b/Ghidra/Framework/Pty/src/main/java/org/unix/pty_h.java@@ -0,0 +1,108 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+// Generated by jextract++package org.unix;++import java.lang.invoke.*;+import java.lang.foreign.*;+import java.nio.ByteOrder;+import java.util.*;+import java.util.function.*;+import java.util.stream.*;++import ghidra.pty.unix.UnixErr;++import static java.lang.foreign.ValueLayout.*;+import static java.lang.foreign.MemoryLayout.PathElement.*;++public class pty_h extends pty_h$shared {++ pty_h() {+ // Should not be called directly+ }++ static final Arena LIBRARY_ARENA = Arena.ofAuto();++ static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.loaderLookup()+ .or(Linker.nativeLinker().defaultLookup());+++ private static class openpty {+ public static final FunctionDescriptor DESC = FunctionDescriptor.of(+ pty_h.C_INT,+ pty_h.C_POINTER,+ pty_h.C_POINTER,+ pty_h.C_POINTER,+ pty_h.C_POINTER,+ pty_h.C_POINTER+ );++ public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("openpty");++ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC, UnixErr.OPT_CAPTURE_ERRNO);+ }++ /**+ * Function descriptor for:+ * {@snippet lang=c :+ * extern int openpty(int *__amaster, int *__aslave, char *__name, const struct termios *__termp, const struct winsize *__winp)+ * }+ */+ public static FunctionDescriptor openpty$descriptor() {+ return openpty.DESC;+ }++ /**+ * Downcall method handle for:+ * {@snippet lang=c :+ * extern int openpty(int *__amaster, int *__aslave, char *__name, const struct termios *__termp, const struct winsize *__winp)+ * }+ */+ public static MethodHandle openpty$handle() {+ return openpty.HANDLE;+ }++ /**+ * Address for:+ * {@snippet lang=c :+ * extern int openpty(int *__amaster, int *__aslave, char *__name, const struct termios *__termp, const struct winsize *__winp)+ * }+ */+ public static MemorySegment openpty$address() {+ return openpty.ADDR;+ }++ /**+ * {@snippet lang=c :+ * extern int openpty(int *__amaster, int *__aslave, char *__name, const struct termios *__termp, const struct winsize *__winp)+ * }+ */+ public static int openpty(MemorySegment cs, MemorySegment __amaster, MemorySegment __aslave, MemorySegment __name, MemorySegment __termp, MemorySegment __winp) {+ var mh$ = openpty.HANDLE;+ try {+ if (TRACE_DOWNCALLS) {+ traceDowncall("openpty", __amaster, __aslave, __name, __termp, __winp);+ }+ return (int)mh$.invokeExact(cs, __amaster, __aslave, __name, __termp, __winp);+ } catch (Error | RuntimeException ex) {+ throw ex;+ } catch (Throwable ex$) {+ throw new AssertionError("should not reach here", ex$);+ }+ }+}+diff --git a/Ghidra/Framework/Pty/src/main/java/org/unix/string_h$shared.java b/Ghidra/Framework/Pty/src/main/java/org/unix/string_h$shared.javanew file mode 100644index 0000000000..429ca3774e--- /dev/null+++ b/Ghidra/Framework/Pty/src/main/java/org/unix/string_h$shared.java@@ -0,0 +1,78 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+// Generated by jextract++package org.unix;++import java.lang.invoke.*;+import java.lang.foreign.*;+import java.nio.ByteOrder;+import java.util.*;+import java.util.function.*;+import java.util.stream.*;++import static java.lang.foreign.ValueLayout.*;+import static java.lang.foreign.MemoryLayout.PathElement.*;++public class string_h$shared {++ string_h$shared() {+ // Should not be called directly+ }++ public static final ValueLayout.OfBoolean C_BOOL = (ValueLayout.OfBoolean) Linker.nativeLinker().canonicalLayouts().get("bool");+ public static final ValueLayout.OfByte C_CHAR =(ValueLayout.OfByte)Linker.nativeLinker().canonicalLayouts().get("char");+ public static final ValueLayout.OfShort C_SHORT = (ValueLayout.OfShort) Linker.nativeLinker().canonicalLayouts().get("short");+ public static final ValueLayout.OfInt C_INT = (ValueLayout.OfInt) Linker.nativeLinker().canonicalLayouts().get("int");+ public static final ValueLayout.OfLong C_LONG_LONG = (ValueLayout.OfLong) Linker.nativeLinker().canonicalLayouts().get("long long");+ public static final ValueLayout.OfFloat C_FLOAT = (ValueLayout.OfFloat) Linker.nativeLinker().canonicalLayouts().get("float");+ public static final ValueLayout.OfDouble C_DOUBLE = (ValueLayout.OfDouble) Linker.nativeLinker().canonicalLayouts().get("double");+ public static final AddressLayout C_POINTER = ((AddressLayout) Linker.nativeLinker().canonicalLayouts().get("void*"))+ .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, C_CHAR));+ public static final ValueLayout.OfLong C_LONG = (ValueLayout.OfLong) Linker.nativeLinker().canonicalLayouts().get("long");++ static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls");++ static void traceDowncall(String name, Object... args) {+ String traceArgs = Arrays.stream(args)+ .map(Object::toString)+ .collect(Collectors.joining(", "));+ System.out.printf("%s(%s)\n", name, traceArgs);+ }++ static MethodHandle upcallHandle(Class<?> fi, String name, FunctionDescriptor fdesc) {+ try {+ return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType());+ } catch (ReflectiveOperationException ex) {+ throw new AssertionError(ex);+ }+ }++ static MemoryLayout align(MemoryLayout layout, long align) {+ return switch (layout) {+ case PaddingLayout p -> p;+ case ValueLayout v -> v.withByteAlignment(align);+ case GroupLayout g -> {+ MemoryLayout[] alignedMembers = g.memberLayouts().stream()+ .map(m -> align(m, align)).toArray(MemoryLayout[]::new);+ yield g instanceof StructLayout ?+ MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers);+ }+ case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align));+ };+ }+}+diff --git a/Ghidra/Framework/Pty/src/main/java/org/unix/string_h.java b/Ghidra/Framework/Pty/src/main/java/org/unix/string_h.javanew file mode 100644index 0000000000..d2289d4734--- /dev/null+++ b/Ghidra/Framework/Pty/src/main/java/org/unix/string_h.java@@ -0,0 +1,102 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+// Generated by jextract++package org.unix;++import java.lang.invoke.*;+import java.lang.foreign.*;+import java.nio.ByteOrder;+import java.util.*;+import java.util.function.*;+import java.util.stream.*;++import static java.lang.foreign.ValueLayout.*;+import static java.lang.foreign.MemoryLayout.PathElement.*;++public class string_h extends string_h$shared {++ string_h() {+ // Should not be called directly+ }++ static final Arena LIBRARY_ARENA = Arena.ofAuto();++ static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.loaderLookup()+ .or(Linker.nativeLinker().defaultLookup());+++ private static class strerror {+ public static final FunctionDescriptor DESC = FunctionDescriptor.of(+ string_h.C_POINTER,+ string_h.C_INT+ );++ public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("strerror");++ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC);+ }++ /**+ * Function descriptor for:+ * {@snippet lang=c :+ * extern char *strerror(int __errnum)+ * }+ */+ public static FunctionDescriptor strerror$descriptor() {+ return strerror.DESC;+ }++ /**+ * Downcall method handle for:+ * {@snippet lang=c :+ * extern char *strerror(int __errnum)+ * }+ */+ public static MethodHandle strerror$handle() {+ return strerror.HANDLE;+ }++ /**+ * Address for:+ * {@snippet lang=c :+ * extern char *strerror(int __errnum)+ * }+ */+ public static MemorySegment strerror$address() {+ return strerror.ADDR;+ }++ /**+ * {@snippet lang=c :+ * extern char *strerror(int __errnum)+ * }+ */+ public static MemorySegment strerror(int __errnum) {+ var mh$ = strerror.HANDLE;+ try {+ if (TRACE_DOWNCALLS) {+ traceDowncall("strerror", __errnum);+ }+ return (MemorySegment)mh$.invokeExact(__errnum);+ } catch (Error | RuntimeException ex) {+ throw ex;+ } catch (Throwable ex$) {+ throw new AssertionError("should not reach here", ex$);+ }+ }+}+diff --git a/Ghidra/Framework/Pty/src/main/java/org/unix/termios.java b/Ghidra/Framework/Pty/src/main/java/org/unix/termios.javanew file mode 100644index 0000000000..d9ff4e2263--- /dev/null+++ b/Ghidra/Framework/Pty/src/main/java/org/unix/termios.java@@ -0,0 +1,498 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+// Generated by jextract++package org.unix;++import java.lang.invoke.*;+import java.lang.foreign.*;+import java.nio.ByteOrder;+import java.util.*;+import java.util.function.*;+import java.util.stream.*;++import static java.lang.foreign.ValueLayout.*;+import static java.lang.foreign.MemoryLayout.PathElement.*;++/**+ * {@snippet lang=c :+ * struct termios {+ * tcflag_t c_iflag;+ * tcflag_t c_oflag;+ * tcflag_t c_cflag;+ * tcflag_t c_lflag;+ * cc_t c_line;+ * cc_t c_cc[32];+ * speed_t c_ispeed;+ * speed_t c_ospeed;+ * }+ * }+ */+public class termios {++ termios() {+ // Should not be called directly+ }++ private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(+ termios_h.C_INT.withName("c_iflag"),+ termios_h.C_INT.withName("c_oflag"),+ termios_h.C_INT.withName("c_cflag"),+ termios_h.C_INT.withName("c_lflag"),+ termios_h.C_CHAR.withName("c_line"),+ MemoryLayout.sequenceLayout(32, termios_h.C_CHAR).withName("c_cc"),+ MemoryLayout.paddingLayout(3),+ termios_h.C_INT.withName("c_ispeed"),+ termios_h.C_INT.withName("c_ospeed")+ ).withName("termios");++ /**+ * The layout of this struct+ */+ public static final GroupLayout layout() {+ return $LAYOUT;+ }++ private static final OfInt c_iflag$LAYOUT = (OfInt)$LAYOUT.select(groupElement("c_iflag"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * tcflag_t c_iflag+ * }+ */+ public static final OfInt c_iflag$layout() {+ return c_iflag$LAYOUT;+ }++ private static final long c_iflag$OFFSET = $LAYOUT.byteOffset(groupElement("c_iflag"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * tcflag_t c_iflag+ * }+ */+ public static final long c_iflag$offset() {+ return c_iflag$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * tcflag_t c_iflag+ * }+ */+ public static int c_iflag(MemorySegment struct) {+ return struct.get(c_iflag$LAYOUT, c_iflag$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * tcflag_t c_iflag+ * }+ */+ public static void c_iflag(MemorySegment struct, int fieldValue) {+ struct.set(c_iflag$LAYOUT, c_iflag$OFFSET, fieldValue);+ }++ private static final OfInt c_oflag$LAYOUT = (OfInt)$LAYOUT.select(groupElement("c_oflag"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * tcflag_t c_oflag+ * }+ */+ public static final OfInt c_oflag$layout() {+ return c_oflag$LAYOUT;+ }++ private static final long c_oflag$OFFSET = $LAYOUT.byteOffset(groupElement("c_oflag"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * tcflag_t c_oflag+ * }+ */+ public static final long c_oflag$offset() {+ return c_oflag$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * tcflag_t c_oflag+ * }+ */+ public static int c_oflag(MemorySegment struct) {+ return struct.get(c_oflag$LAYOUT, c_oflag$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * tcflag_t c_oflag+ * }+ */+ public static void c_oflag(MemorySegment struct, int fieldValue) {+ struct.set(c_oflag$LAYOUT, c_oflag$OFFSET, fieldValue);+ }++ private static final OfInt c_cflag$LAYOUT = (OfInt)$LAYOUT.select(groupElement("c_cflag"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * tcflag_t c_cflag+ * }+ */+ public static final OfInt c_cflag$layout() {+ return c_cflag$LAYOUT;+ }++ private static final long c_cflag$OFFSET = $LAYOUT.byteOffset(groupElement("c_cflag"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * tcflag_t c_cflag+ * }+ */+ public static final long c_cflag$offset() {+ return c_cflag$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * tcflag_t c_cflag+ * }+ */+ public static int c_cflag(MemorySegment struct) {+ return struct.get(c_cflag$LAYOUT, c_cflag$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * tcflag_t c_cflag+ * }+ */+ public static void c_cflag(MemorySegment struct, int fieldValue) {+ struct.set(c_cflag$LAYOUT, c_cflag$OFFSET, fieldValue);+ }++ private static final OfInt c_lflag$LAYOUT = (OfInt)$LAYOUT.select(groupElement("c_lflag"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * tcflag_t c_lflag+ * }+ */+ public static final OfInt c_lflag$layout() {+ return c_lflag$LAYOUT;+ }++ private static final long c_lflag$OFFSET = $LAYOUT.byteOffset(groupElement("c_lflag"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * tcflag_t c_lflag+ * }+ */+ public static final long c_lflag$offset() {+ return c_lflag$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * tcflag_t c_lflag+ * }+ */+ public static int c_lflag(MemorySegment struct) {+ return struct.get(c_lflag$LAYOUT, c_lflag$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * tcflag_t c_lflag+ * }+ */+ public static void c_lflag(MemorySegment struct, int fieldValue) {+ struct.set(c_lflag$LAYOUT, c_lflag$OFFSET, fieldValue);+ }++ private static final OfByte c_line$LAYOUT = (OfByte)$LAYOUT.select(groupElement("c_line"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * cc_t c_line+ * }+ */+ public static final OfByte c_line$layout() {+ return c_line$LAYOUT;+ }++ private static final long c_line$OFFSET = $LAYOUT.byteOffset(groupElement("c_line"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * cc_t c_line+ * }+ */+ public static final long c_line$offset() {+ return c_line$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * cc_t c_line+ * }+ */+ public static byte c_line(MemorySegment struct) {+ return struct.get(c_line$LAYOUT, c_line$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * cc_t c_line+ * }+ */+ public static void c_line(MemorySegment struct, byte fieldValue) {+ struct.set(c_line$LAYOUT, c_line$OFFSET, fieldValue);+ }++ private static final SequenceLayout c_cc$LAYOUT = (SequenceLayout)$LAYOUT.select(groupElement("c_cc"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * cc_t c_cc[32]+ * }+ */+ public static final SequenceLayout c_cc$layout() {+ return c_cc$LAYOUT;+ }++ private static final long c_cc$OFFSET = $LAYOUT.byteOffset(groupElement("c_cc"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * cc_t c_cc[32]+ * }+ */+ public static final long c_cc$offset() {+ return c_cc$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * cc_t c_cc[32]+ * }+ */+ public static MemorySegment c_cc(MemorySegment struct) {+ return struct.asSlice(c_cc$OFFSET, c_cc$LAYOUT.byteSize());+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * cc_t c_cc[32]+ * }+ */+ public static void c_cc(MemorySegment struct, MemorySegment fieldValue) {+ MemorySegment.copy(fieldValue, 0L, struct, c_cc$OFFSET, c_cc$LAYOUT.byteSize());+ }++ private static long[] c_cc$DIMS = { 32 };++ /**+ * Dimensions for array field:+ * {@snippet lang=c :+ * cc_t c_cc[32]+ * }+ */+ public static long[] c_cc$dimensions() {+ return c_cc$DIMS;+ }+ private static final VarHandle c_cc$ELEM_HANDLE = c_cc$LAYOUT.varHandle(sequenceElement());++ /**+ * Indexed getter for field:+ * {@snippet lang=c :+ * cc_t c_cc[32]+ * }+ */+ public static byte c_cc(MemorySegment struct, long index0) {+ return (byte)c_cc$ELEM_HANDLE.get(struct, c_cc$OFFSET, index0);+ }++ /**+ * Indexed setter for field:+ * {@snippet lang=c :+ * cc_t c_cc[32]+ * }+ */+ public static void c_cc(MemorySegment struct, long index0, byte fieldValue) {+ c_cc$ELEM_HANDLE.set(struct, c_cc$OFFSET, index0, fieldValue);+ }++ private static final OfInt c_ispeed$LAYOUT = (OfInt)$LAYOUT.select(groupElement("c_ispeed"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * speed_t c_ispeed+ * }+ */+ public static final OfInt c_ispeed$layout() {+ return c_ispeed$LAYOUT;+ }++ private static final long c_ispeed$OFFSET = $LAYOUT.byteOffset(groupElement("c_ispeed"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * speed_t c_ispeed+ * }+ */+ public static final long c_ispeed$offset() {+ return c_ispeed$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * speed_t c_ispeed+ * }+ */+ public static int c_ispeed(MemorySegment struct) {+ return struct.get(c_ispeed$LAYOUT, c_ispeed$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * speed_t c_ispeed+ * }+ */+ public static void c_ispeed(MemorySegment struct, int fieldValue) {+ struct.set(c_ispeed$LAYOUT, c_ispeed$OFFSET, fieldValue);+ }++ private static final OfInt c_ospeed$LAYOUT = (OfInt)$LAYOUT.select(groupElement("c_ospeed"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * speed_t c_ospeed+ * }+ */+ public static final OfInt c_ospeed$layout() {+ return c_ospeed$LAYOUT;+ }++ private static final long c_ospeed$OFFSET = $LAYOUT.byteOffset(groupElement("c_ospeed"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * speed_t c_ospeed+ * }+ */+ public static final long c_ospeed$offset() {+ return c_ospeed$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * speed_t c_ospeed+ * }+ */+ public static int c_ospeed(MemorySegment struct) {+ return struct.get(c_ospeed$LAYOUT, c_ospeed$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * speed_t c_ospeed+ * }+ */+ public static void c_ospeed(MemorySegment struct, int fieldValue) {+ struct.set(c_ospeed$LAYOUT, c_ospeed$OFFSET, fieldValue);+ }++ /**+ * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}.+ * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()}+ */+ public static MemorySegment asSlice(MemorySegment array, long index) {+ return array.asSlice(layout().byteSize() * index);+ }++ /**+ * The size (in bytes) of this struct+ */+ public static long sizeof() { return layout().byteSize(); }++ /**+ * Allocate a segment of size {@code layout().byteSize()} using {@code allocator}+ */+ public static MemorySegment allocate(SegmentAllocator allocator) {+ return allocator.allocate(layout());+ }++ /**+ * Allocate an array of size {@code elementCount} using {@code allocator}.+ * The returned segment has size {@code elementCount * layout().byteSize()}.+ */+ public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) {+ return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout()));+ }++ /**+ * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).+ * The returned segment has size {@code layout().byteSize()}+ */+ public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer<MemorySegment> cleanup) {+ return reinterpret(addr, 1, arena, cleanup);+ }++ /**+ * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).+ * The returned segment has size {@code elementCount * layout().byteSize()}+ */+ public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer<MemorySegment> cleanup) {+ return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup);+ }+}+diff --git a/Ghidra/Framework/Pty/src/main/java/org/unix/termios_h$shared.java b/Ghidra/Framework/Pty/src/main/java/org/unix/termios_h$shared.javanew file mode 100644index 0000000000..daff92f822--- /dev/null+++ b/Ghidra/Framework/Pty/src/main/java/org/unix/termios_h$shared.java@@ -0,0 +1,78 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+// Generated by jextract++package org.unix;++import java.lang.invoke.*;+import java.lang.foreign.*;+import java.nio.ByteOrder;+import java.util.*;+import java.util.function.*;+import java.util.stream.*;++import static java.lang.foreign.ValueLayout.*;+import static java.lang.foreign.MemoryLayout.PathElement.*;++public class termios_h$shared {++ termios_h$shared() {+ // Should not be called directly+ }++ public static final ValueLayout.OfBoolean C_BOOL = (ValueLayout.OfBoolean) Linker.nativeLinker().canonicalLayouts().get("bool");+ public static final ValueLayout.OfByte C_CHAR =(ValueLayout.OfByte)Linker.nativeLinker().canonicalLayouts().get("char");+ public static final ValueLayout.OfShort C_SHORT = (ValueLayout.OfShort) Linker.nativeLinker().canonicalLayouts().get("short");+ public static final ValueLayout.OfInt C_INT = (ValueLayout.OfInt) Linker.nativeLinker().canonicalLayouts().get("int");+ public static final ValueLayout.OfLong C_LONG_LONG = (ValueLayout.OfLong) Linker.nativeLinker().canonicalLayouts().get("long long");+ public static final ValueLayout.OfFloat C_FLOAT = (ValueLayout.OfFloat) Linker.nativeLinker().canonicalLayouts().get("float");+ public static final ValueLayout.OfDouble C_DOUBLE = (ValueLayout.OfDouble) Linker.nativeLinker().canonicalLayouts().get("double");+ public static final AddressLayout C_POINTER = ((AddressLayout) Linker.nativeLinker().canonicalLayouts().get("void*"))+ .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, C_CHAR));+ public static final ValueLayout.OfLong C_LONG = (ValueLayout.OfLong) Linker.nativeLinker().canonicalLayouts().get("long");++ static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls");++ static void traceDowncall(String name, Object... args) {+ String traceArgs = Arrays.stream(args)+ .map(Object::toString)+ .collect(Collectors.joining(", "));+ System.out.printf("%s(%s)\n", name, traceArgs);+ }++ static MethodHandle upcallHandle(Class<?> fi, String name, FunctionDescriptor fdesc) {+ try {+ return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType());+ } catch (ReflectiveOperationException ex) {+ throw new AssertionError(ex);+ }+ }++ static MemoryLayout align(MemoryLayout layout, long align) {+ return switch (layout) {+ case PaddingLayout p -> p;+ case ValueLayout v -> v.withByteAlignment(align);+ case GroupLayout g -> {+ MemoryLayout[] alignedMembers = g.memberLayouts().stream()+ .map(m -> align(m, align)).toArray(MemoryLayout[]::new);+ yield g instanceof StructLayout ?+ MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers);+ }+ case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align));+ };+ }+}+diff --git a/Ghidra/Framework/Pty/src/main/java/org/unix/termios_h.java b/Ghidra/Framework/Pty/src/main/java/org/unix/termios_h.javanew file mode 100644index 0000000000..78c022dc19--- /dev/null+++ b/Ghidra/Framework/Pty/src/main/java/org/unix/termios_h.java@@ -0,0 +1,185 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+// Generated by jextract++package org.unix;++import java.lang.invoke.*;+import java.lang.foreign.*;+import java.nio.ByteOrder;+import java.util.*;+import java.util.function.*;+import java.util.stream.*;++import ghidra.pty.unix.UnixErr;++import static java.lang.foreign.ValueLayout.*;+import static java.lang.foreign.MemoryLayout.PathElement.*;++public class termios_h extends termios_h$shared {++ termios_h() {+ // Should not be called directly+ }++ static final Arena LIBRARY_ARENA = Arena.ofAuto();++ static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.loaderLookup()+ .or(Linker.nativeLinker().defaultLookup());++ private static final int ECHO = (int)8L;+ /**+ * {@snippet lang=c :+ * #define ECHO 8+ * }+ */+ public static int ECHO() {+ return ECHO;+ }+ private static final int TCSANOW = (int)0L;+ /**+ * {@snippet lang=c :+ * #define TCSANOW 0+ * }+ */+ public static int TCSANOW() {+ return TCSANOW;+ }++ private static class tcgetattr {+ public static final FunctionDescriptor DESC = FunctionDescriptor.of(+ termios_h.C_INT,+ termios_h.C_INT,+ termios_h.C_POINTER+ );++ public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("tcgetattr");++ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC, UnixErr.OPT_CAPTURE_ERRNO);+ }++ /**+ * Function descriptor for:+ * {@snippet lang=c :+ * extern int tcgetattr(int __fd, struct termios *__termios_p)+ * }+ */+ public static FunctionDescriptor tcgetattr$descriptor() {+ return tcgetattr.DESC;+ }++ /**+ * Downcall method handle for:+ * {@snippet lang=c :+ * extern int tcgetattr(int __fd, struct termios *__termios_p)+ * }+ */+ public static MethodHandle tcgetattr$handle() {+ return tcgetattr.HANDLE;+ }++ /**+ * Address for:+ * {@snippet lang=c :+ * extern int tcgetattr(int __fd, struct termios *__termios_p)+ * }+ */+ public static MemorySegment tcgetattr$address() {+ return tcgetattr.ADDR;+ }++ /**+ * {@snippet lang=c :+ * extern int tcgetattr(int __fd, struct termios *__termios_p)+ * }+ */+ public static int tcgetattr(MemorySegment cs, int __fd, MemorySegment __termios_p) {+ var mh$ = tcgetattr.HANDLE;+ try {+ if (TRACE_DOWNCALLS) {+ traceDowncall("tcgetattr", __fd, __termios_p);+ }+ return (int)mh$.invokeExact(cs, __fd, __termios_p);+ } catch (Error | RuntimeException ex) {+ throw ex;+ } catch (Throwable ex$) {+ throw new AssertionError("should not reach here", ex$);+ }+ }++ private static class tcsetattr {+ public static final FunctionDescriptor DESC = FunctionDescriptor.of(+ termios_h.C_INT,+ termios_h.C_INT,+ termios_h.C_INT,+ termios_h.C_POINTER+ );++ public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("tcsetattr");++ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC, UnixErr.OPT_CAPTURE_ERRNO);+ }++ /**+ * Function descriptor for:+ * {@snippet lang=c :+ * extern int tcsetattr(int __fd, int __optional_actions, const struct termios *__termios_p)+ * }+ */+ public static FunctionDescriptor tcsetattr$descriptor() {+ return tcsetattr.DESC;+ }++ /**+ * Downcall method handle for:+ * {@snippet lang=c :+ * extern int tcsetattr(int __fd, int __optional_actions, const struct termios *__termios_p)+ * }+ */+ public static MethodHandle tcsetattr$handle() {+ return tcsetattr.HANDLE;+ }++ /**+ * Address for:+ * {@snippet lang=c :+ * extern int tcsetattr(int __fd, int __optional_actions, const struct termios *__termios_p)+ * }+ */+ public static MemorySegment tcsetattr$address() {+ return tcsetattr.ADDR;+ }++ /**+ * {@snippet lang=c :+ * extern int tcsetattr(int __fd, int __optional_actions, const struct termios *__termios_p)+ * }+ */+ public static int tcsetattr(MemorySegment cs, int __fd, int __optional_actions, MemorySegment __termios_p) {+ var mh$ = tcsetattr.HANDLE;+ try {+ if (TRACE_DOWNCALLS) {+ traceDowncall("tcsetattr", __fd, __optional_actions, __termios_p);+ }+ return (int)mh$.invokeExact(cs, __fd, __optional_actions, __termios_p);+ } catch (Error | RuntimeException ex) {+ throw ex;+ } catch (Throwable ex$) {+ throw new AssertionError("should not reach here", ex$);+ }+ }+}+diff --git a/Ghidra/Framework/Pty/src/main/java/org/unix/unistd_h$shared.java b/Ghidra/Framework/Pty/src/main/java/org/unix/unistd_h$shared.javanew file mode 100644index 0000000000..8847a8a3aa--- /dev/null+++ b/Ghidra/Framework/Pty/src/main/java/org/unix/unistd_h$shared.java@@ -0,0 +1,78 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+// Generated by jextract++package org.unix;++import java.lang.invoke.*;+import java.lang.foreign.*;+import java.nio.ByteOrder;+import java.util.*;+import java.util.function.*;+import java.util.stream.*;++import static java.lang.foreign.ValueLayout.*;+import static java.lang.foreign.MemoryLayout.PathElement.*;++public class unistd_h$shared {++ unistd_h$shared() {+ // Should not be called directly+ }++ public static final ValueLayout.OfBoolean C_BOOL = (ValueLayout.OfBoolean) Linker.nativeLinker().canonicalLayouts().get("bool");+ public static final ValueLayout.OfByte C_CHAR =(ValueLayout.OfByte)Linker.nativeLinker().canonicalLayouts().get("char");+ public static final ValueLayout.OfShort C_SHORT = (ValueLayout.OfShort) Linker.nativeLinker().canonicalLayouts().get("short");+ public static final ValueLayout.OfInt C_INT = (ValueLayout.OfInt) Linker.nativeLinker().canonicalLayouts().get("int");+ public static final ValueLayout.OfLong C_LONG_LONG = (ValueLayout.OfLong) Linker.nativeLinker().canonicalLayouts().get("long long");+ public static final ValueLayout.OfFloat C_FLOAT = (ValueLayout.OfFloat) Linker.nativeLinker().canonicalLayouts().get("float");+ public static final ValueLayout.OfDouble C_DOUBLE = (ValueLayout.OfDouble) Linker.nativeLinker().canonicalLayouts().get("double");+ public static final AddressLayout C_POINTER = ((AddressLayout) Linker.nativeLinker().canonicalLayouts().get("void*"))+ .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, C_CHAR));+ public static final ValueLayout.OfLong C_LONG = (ValueLayout.OfLong) Linker.nativeLinker().canonicalLayouts().get("long");++ static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls");++ static void traceDowncall(String name, Object... args) {+ String traceArgs = Arrays.stream(args)+ .map(Object::toString)+ .collect(Collectors.joining(", "));+ System.out.printf("%s(%s)\n", name, traceArgs);+ }++ static MethodHandle upcallHandle(Class<?> fi, String name, FunctionDescriptor fdesc) {+ try {+ return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType());+ } catch (ReflectiveOperationException ex) {+ throw new AssertionError(ex);+ }+ }++ static MemoryLayout align(MemoryLayout layout, long align) {+ return switch (layout) {+ case PaddingLayout p -> p;+ case ValueLayout v -> v.withByteAlignment(align);+ case GroupLayout g -> {+ MemoryLayout[] alignedMembers = g.memberLayouts().stream()+ .map(m -> align(m, align)).toArray(MemoryLayout[]::new);+ yield g instanceof StructLayout ?+ MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers);+ }+ case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align));+ };+ }+}+diff --git a/Ghidra/Framework/Pty/src/main/java/org/unix/unistd_h.java b/Ghidra/Framework/Pty/src/main/java/org/unix/unistd_h.javanew file mode 100644index 0000000000..1c87507399--- /dev/null+++ b/Ghidra/Framework/Pty/src/main/java/org/unix/unistd_h.java@@ -0,0 +1,468 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+// Generated by jextract++package org.unix;++import java.lang.invoke.*;+import java.lang.foreign.*;+import java.nio.ByteOrder;+import java.util.*;+import java.util.function.*;+import java.util.stream.*;++import ghidra.pty.unix.UnixErr;++import static java.lang.foreign.ValueLayout.*;+import static java.lang.foreign.MemoryLayout.PathElement.*;++public class unistd_h extends unistd_h$shared {++ unistd_h() {+ // Should not be called directly+ }++ static final Arena LIBRARY_ARENA = Arena.ofAuto();++ static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.loaderLookup()+ .or(Linker.nativeLinker().defaultLookup());+++ private static class close {+ public static final FunctionDescriptor DESC = FunctionDescriptor.of(+ unistd_h.C_INT,+ unistd_h.C_INT+ );++ public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("close");++ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC, UnixErr.OPT_CAPTURE_ERRNO);+ }++ /**+ * Function descriptor for:+ * {@snippet lang=c :+ * extern int close(int __fd)+ * }+ */+ public static FunctionDescriptor close$descriptor() {+ return close.DESC;+ }++ /**+ * Downcall method handle for:+ * {@snippet lang=c :+ * extern int close(int __fd)+ * }+ */+ public static MethodHandle close$handle() {+ return close.HANDLE;+ }++ /**+ * Address for:+ * {@snippet lang=c :+ * extern int close(int __fd)+ * }+ */+ public static MemorySegment close$address() {+ return close.ADDR;+ }++ /**+ * {@snippet lang=c :+ * extern int close(int __fd)+ * }+ */+ public static int close(MemorySegment cs, int __fd) {+ var mh$ = close.HANDLE;+ try {+ if (TRACE_DOWNCALLS) {+ traceDowncall("close", __fd);+ }+ return (int)mh$.invokeExact(cs, __fd);+ } catch (Error | RuntimeException ex) {+ throw ex;+ } catch (Throwable ex$) {+ throw new AssertionError("should not reach here", ex$);+ }+ }++ private static class read {+ public static final FunctionDescriptor DESC = FunctionDescriptor.of(+ unistd_h.C_LONG,+ unistd_h.C_INT,+ unistd_h.C_POINTER,+ unistd_h.C_LONG+ );++ public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("read");++ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC, UnixErr.OPT_CAPTURE_ERRNO);+ }++ /**+ * Function descriptor for:+ * {@snippet lang=c :+ * extern ssize_t read(int __fd, void *__buf, size_t __nbytes)+ * }+ */+ public static FunctionDescriptor read$descriptor() {+ return read.DESC;+ }++ /**+ * Downcall method handle for:+ * {@snippet lang=c :+ * extern ssize_t read(int __fd, void *__buf, size_t __nbytes)+ * }+ */+ public static MethodHandle read$handle() {+ return read.HANDLE;+ }++ /**+ * Address for:+ * {@snippet lang=c :+ * extern ssize_t read(int __fd, void *__buf, size_t __nbytes)+ * }+ */+ public static MemorySegment read$address() {+ return read.ADDR;+ }++ /**+ * {@snippet lang=c :+ * extern ssize_t read(int __fd, void *__buf, size_t __nbytes)+ * }+ */+ public static long read(MemorySegment cs, int __fd, MemorySegment __buf, long __nbytes) {+ var mh$ = read.HANDLE;+ try {+ if (TRACE_DOWNCALLS) {+ traceDowncall("read", __fd, __buf, __nbytes);+ }+ return (long)mh$.invokeExact(cs, __fd, __buf, __nbytes);+ } catch (Error | RuntimeException ex) {+ throw ex;+ } catch (Throwable ex$) {+ throw new AssertionError("should not reach here", ex$);+ }+ }++ private static class write {+ public static final FunctionDescriptor DESC = FunctionDescriptor.of(+ unistd_h.C_LONG,+ unistd_h.C_INT,+ unistd_h.C_POINTER,+ unistd_h.C_LONG+ );++ public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("write");++ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC, UnixErr.OPT_CAPTURE_ERRNO);+ }++ /**+ * Function descriptor for:+ * {@snippet lang=c :+ * extern ssize_t write(int __fd, const void *__buf, size_t __n)+ * }+ */+ public static FunctionDescriptor write$descriptor() {+ return write.DESC;+ }++ /**+ * Downcall method handle for:+ * {@snippet lang=c :+ * extern ssize_t write(int __fd, const void *__buf, size_t __n)+ * }+ */+ public static MethodHandle write$handle() {+ return write.HANDLE;+ }++ /**+ * Address for:+ * {@snippet lang=c :+ * extern ssize_t write(int __fd, const void *__buf, size_t __n)+ * }+ */+ public static MemorySegment write$address() {+ return write.ADDR;+ }++ /**+ * {@snippet lang=c :+ * extern ssize_t write(int __fd, const void *__buf, size_t __n)+ * }+ */+ public static long write(MemorySegment cs, int __fd, MemorySegment __buf, long __n) {+ var mh$ = write.HANDLE;+ try {+ if (TRACE_DOWNCALLS) {+ traceDowncall("write", __fd, __buf, __n);+ }+ return (long)mh$.invokeExact(cs, __fd, __buf, __n);+ } catch (Error | RuntimeException ex) {+ throw ex;+ } catch (Throwable ex$) {+ throw new AssertionError("should not reach here", ex$);+ }+ }++ private static class dup {+ public static final FunctionDescriptor DESC = FunctionDescriptor.of(+ unistd_h.C_INT,+ unistd_h.C_INT+ );++ public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("dup");++ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC, UnixErr.OPT_CAPTURE_ERRNO);+ }++ /**+ * Function descriptor for:+ * {@snippet lang=c :+ * extern int dup(int __fd)+ * }+ */+ public static FunctionDescriptor dup$descriptor() {+ return dup.DESC;+ }++ /**+ * Downcall method handle for:+ * {@snippet lang=c :+ * extern int dup(int __fd)+ * }+ */+ public static MethodHandle dup$handle() {+ return dup.HANDLE;+ }++ /**+ * Address for:+ * {@snippet lang=c :+ * extern int dup(int __fd)+ * }+ */+ public static MemorySegment dup$address() {+ return dup.ADDR;+ }++ /**+ * {@snippet lang=c :+ * extern int dup(int __fd)+ * }+ */+ public static int dup(MemorySegment cs, int __fd) {+ var mh$ = dup.HANDLE;+ try {+ if (TRACE_DOWNCALLS) {+ traceDowncall("dup", __fd);+ }+ return (int)mh$.invokeExact(cs, __fd);+ } catch (Error | RuntimeException ex) {+ throw ex;+ } catch (Throwable ex$) {+ throw new AssertionError("should not reach here", ex$);+ }+ }++ private static class dup2 {+ public static final FunctionDescriptor DESC = FunctionDescriptor.of(+ unistd_h.C_INT,+ unistd_h.C_INT,+ unistd_h.C_INT+ );++ public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("dup2");++ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC, UnixErr.OPT_CAPTURE_ERRNO);+ }++ /**+ * Function descriptor for:+ * {@snippet lang=c :+ * extern int dup2(int __fd, int __fd2)+ * }+ */+ public static FunctionDescriptor dup2$descriptor() {+ return dup2.DESC;+ }++ /**+ * Downcall method handle for:+ * {@snippet lang=c :+ * extern int dup2(int __fd, int __fd2)+ * }+ */+ public static MethodHandle dup2$handle() {+ return dup2.HANDLE;+ }++ /**+ * Address for:+ * {@snippet lang=c :+ * extern int dup2(int __fd, int __fd2)+ * }+ */+ public static MemorySegment dup2$address() {+ return dup2.ADDR;+ }++ /**+ * {@snippet lang=c :+ * extern int dup2(int __fd, int __fd2)+ * }+ */+ public static int dup2(MemorySegment cs, int __fd, int __fd2) {+ var mh$ = dup2.HANDLE;+ try {+ if (TRACE_DOWNCALLS) {+ traceDowncall("dup2", __fd, __fd2);+ }+ return (int)mh$.invokeExact(cs, __fd, __fd2);+ } catch (Error | RuntimeException ex) {+ throw ex;+ } catch (Throwable ex$) {+ throw new AssertionError("should not reach here", ex$);+ }+ }++ private static class execv {+ public static final FunctionDescriptor DESC = FunctionDescriptor.of(+ unistd_h.C_INT,+ unistd_h.C_POINTER,+ unistd_h.C_POINTER+ );++ public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("execv");++ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC, UnixErr.OPT_CAPTURE_ERRNO);+ }++ /**+ * Function descriptor for:+ * {@snippet lang=c :+ * extern int execv(const char *__path, char *const __argv[])+ * }+ */+ public static FunctionDescriptor execv$descriptor() {+ return execv.DESC;+ }++ /**+ * Downcall method handle for:+ * {@snippet lang=c :+ * extern int execv(const char *__path, char *const __argv[])+ * }+ */+ public static MethodHandle execv$handle() {+ return execv.HANDLE;+ }++ /**+ * Address for:+ * {@snippet lang=c :+ * extern int execv(const char *__path, char *const __argv[])+ * }+ */+ public static MemorySegment execv$address() {+ return execv.ADDR;+ }++ /**+ * {@snippet lang=c :+ * extern int execv(const char *__path, char *const __argv[])+ * }+ */+ public static int execv(MemorySegment cs, MemorySegment __path, MemorySegment __argv) {+ var mh$ = execv.HANDLE;+ try {+ if (TRACE_DOWNCALLS) {+ traceDowncall("execv", __path, __argv);+ }+ return (int)mh$.invokeExact(cs, __path, __argv);+ } catch (Error | RuntimeException ex) {+ throw ex;+ } catch (Throwable ex$) {+ throw new AssertionError("should not reach here", ex$);+ }+ }++ private static class setsid {+ public static final FunctionDescriptor DESC = FunctionDescriptor.of(+ unistd_h.C_INT );++ public static final MemorySegment ADDR = SYMBOL_LOOKUP.findOrThrow("setsid");++ public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC, UnixErr.OPT_CAPTURE_ERRNO);+ }++ /**+ * Function descriptor for:+ * {@snippet lang=c :+ * extern __pid_t setsid()+ * }+ */+ public static FunctionDescriptor setsid$descriptor() {+ return setsid.DESC;+ }++ /**+ * Downcall method handle for:+ * {@snippet lang=c :+ * extern __pid_t setsid()+ * }+ */+ public static MethodHandle setsid$handle() {+ return setsid.HANDLE;+ }++ /**+ * Address for:+ * {@snippet lang=c :+ * extern __pid_t setsid()+ * }+ */+ public static MemorySegment setsid$address() {+ return setsid.ADDR;+ }++ /**+ * {@snippet lang=c :+ * extern __pid_t setsid()+ * }+ */+ public static int setsid(MemorySegment cs) {+ var mh$ = setsid.HANDLE;+ try {+ if (TRACE_DOWNCALLS) {+ traceDowncall("setsid");+ }+ return (int)mh$.invokeExact(cs);+ } catch (Error | RuntimeException ex) {+ throw ex;+ } catch (Throwable ex$) {+ throw new AssertionError("should not reach here", ex$);+ }+ }+}+diff --git a/Ghidra/Framework/Pty/src/main/java/org/unix/winsize.java b/Ghidra/Framework/Pty/src/main/java/org/unix/winsize.javanew file mode 100644index 0000000000..602492e808--- /dev/null+++ b/Ghidra/Framework/Pty/src/main/java/org/unix/winsize.java@@ -0,0 +1,282 @@+/* ###+ * IP: GHIDRA+ *+ * Licensed under the Apache License, Version 2.0 (the "License");+ * you may not use this file except in compliance with the License.+ * You may obtain a copy of the License at+ *+ * http://www.apache.org/licenses/LICENSE-2.0+ *+ * Unless required by applicable law or agreed to in writing, software+ * distributed under the License is distributed on an "AS IS" BASIS,+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+ * See the License for the specific language governing permissions and+ * limitations under the License.+ */+// Generated by jextract++package org.unix;++import java.lang.invoke.*;+import java.lang.foreign.*;+import java.nio.ByteOrder;+import java.util.*;+import java.util.function.*;+import java.util.stream.*;++import org.unix.ioctl_h;++import static java.lang.foreign.ValueLayout.*;+import static java.lang.foreign.MemoryLayout.PathElement.*;++/**+ * {@snippet lang=c :+ * struct winsize {+ * unsigned short ws_row;+ * unsigned short ws_col;+ * unsigned short ws_xpixel;+ * unsigned short ws_ypixel;+ * }+ * }+ */+public class winsize {++ winsize() {+ // Should not be called directly+ }++ private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(+ ioctl_h.C_SHORT.withName("ws_row"),+ ioctl_h.C_SHORT.withName("ws_col"),+ ioctl_h.C_SHORT.withName("ws_xpixel"),+ ioctl_h.C_SHORT.withName("ws_ypixel")+ ).withName("winsize");++ /**+ * The layout of this struct+ */+ public static final GroupLayout layout() {+ return $LAYOUT;+ }++ private static final OfShort ws_row$LAYOUT = (OfShort)$LAYOUT.select(groupElement("ws_row"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * unsigned short ws_row+ * }+ */+ public static final OfShort ws_row$layout() {+ return ws_row$LAYOUT;+ }++ private static final long ws_row$OFFSET = $LAYOUT.byteOffset(groupElement("ws_row"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * unsigned short ws_row+ * }+ */+ public static final long ws_row$offset() {+ return ws_row$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * unsigned short ws_row+ * }+ */+ public static short ws_row(MemorySegment struct) {+ return struct.get(ws_row$LAYOUT, ws_row$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * unsigned short ws_row+ * }+ */+ public static void ws_row(MemorySegment struct, short fieldValue) {+ struct.set(ws_row$LAYOUT, ws_row$OFFSET, fieldValue);+ }++ private static final OfShort ws_col$LAYOUT = (OfShort)$LAYOUT.select(groupElement("ws_col"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * unsigned short ws_col+ * }+ */+ public static final OfShort ws_col$layout() {+ return ws_col$LAYOUT;+ }++ private static final long ws_col$OFFSET = $LAYOUT.byteOffset(groupElement("ws_col"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * unsigned short ws_col+ * }+ */+ public static final long ws_col$offset() {+ return ws_col$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * unsigned short ws_col+ * }+ */+ public static short ws_col(MemorySegment struct) {+ return struct.get(ws_col$LAYOUT, ws_col$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * unsigned short ws_col+ * }+ */+ public static void ws_col(MemorySegment struct, short fieldValue) {+ struct.set(ws_col$LAYOUT, ws_col$OFFSET, fieldValue);+ }++ private static final OfShort ws_xpixel$LAYOUT = (OfShort)$LAYOUT.select(groupElement("ws_xpixel"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * unsigned short ws_xpixel+ * }+ */+ public static final OfShort ws_xpixel$layout() {+ return ws_xpixel$LAYOUT;+ }++ private static final long ws_xpixel$OFFSET = $LAYOUT.byteOffset(groupElement("ws_xpixel"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * unsigned short ws_xpixel+ * }+ */+ public static final long ws_xpixel$offset() {+ return ws_xpixel$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * unsigned short ws_xpixel+ * }+ */+ public static short ws_xpixel(MemorySegment struct) {+ return struct.get(ws_xpixel$LAYOUT, ws_xpixel$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * unsigned short ws_xpixel+ * }+ */+ public static void ws_xpixel(MemorySegment struct, short fieldValue) {+ struct.set(ws_xpixel$LAYOUT, ws_xpixel$OFFSET, fieldValue);+ }++ private static final OfShort ws_ypixel$LAYOUT = (OfShort)$LAYOUT.select(groupElement("ws_ypixel"));++ /**+ * Layout for field:+ * {@snippet lang=c :+ * unsigned short ws_ypixel+ * }+ */+ public static final OfShort ws_ypixel$layout() {+ return ws_ypixel$LAYOUT;+ }++ private static final long ws_ypixel$OFFSET = $LAYOUT.byteOffset(groupElement("ws_ypixel"));++ /**+ * Offset for field:+ * {@snippet lang=c :+ * unsigned short ws_ypixel+ * }+ */+ public static final long ws_ypixel$offset() {+ return ws_ypixel$OFFSET;+ }++ /**+ * Getter for field:+ * {@snippet lang=c :+ * unsigned short ws_ypixel+ * }+ */+ public static short ws_ypixel(MemorySegment struct) {+ return struct.get(ws_ypixel$LAYOUT, ws_ypixel$OFFSET);+ }++ /**+ * Setter for field:+ * {@snippet lang=c :+ * unsigned short ws_ypixel+ * }+ */+ public static void ws_ypixel(MemorySegment struct, short fieldValue) {+ struct.set(ws_ypixel$LAYOUT, ws_ypixel$OFFSET, fieldValue);+ }++ /**+ * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}.+ * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()}+ */+ public static MemorySegment asSlice(MemorySegment array, long index) {+ return array.asSlice(layout().byteSize() * index);+ }++ /**+ * The size (in bytes) of this struct+ */+ public static long sizeof() { return layout().byteSize(); }++ /**+ * Allocate a segment of size {@code layout().byteSize()} using {@code allocator}+ */+ public static MemorySegment allocate(SegmentAllocator allocator) {+ return allocator.allocate(layout());+ }++ /**+ * Allocate an array of size {@code elementCount} using {@code allocator}.+ * The returned segment has size {@code elementCount * layout().byteSize()}.+ */+ public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) {+ return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout()));+ }++ /**+ * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).+ * The returned segment has size {@code layout().byteSize()}+ */+ public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer<MemorySegment> cleanup) {+ return reinterpret(addr, 1, arena, cleanup);+ }++ /**+ * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).+ * The returned segment has size {@code elementCount * layout().byteSize()}+ */+ public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer<MemorySegment> cleanup) {+ return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup);+ }+}+diff --git a/Ghidra/Framework/Pty/src/test/java/ghidra/pty/unix/AbstractUnixPtyTest.java b/Ghidra/Framework/Pty/src/test/java/ghidra/pty/unix/AbstractUnixPtyTest.javaindex ca64500e35..b8e9446467 100644--- a/Ghidra/Framework/Pty/src/test/java/ghidra/pty/unix/AbstractUnixPtyTest.java+++ b/Ghidra/Framework/Pty/src/test/java/ghidra/pty/unix/AbstractUnixPtyTest.java@@ -15,14 +15,15 @@*/package ghidra.pty.unix;+import static org.hamcrest.MatcherAssert.assertThat;import static org.junit.Assert.assertEquals;import static org.junit.Assert.assertTrue;import java.io.*;import java.util.*;-import java.util.concurrent.TimeUnit;-import java.util.concurrent.TimeoutException;+import java.util.concurrent.*;+import org.hamcrest.Matchers;import org.junit.Test;import ghidra.pty.AbstractPtyTest;@@ -76,17 +77,39 @@ public abstract class AbstractUnixPtyTest extends AbstractPtyTest {}}+ static String readAllToErr(BufferedReader reader) {+ StringBuffer buf = new StringBuffer();+ while (true) {+ int c;+ try {+ c = reader.read();+ }+ catch (IOException e) {+ return buf.toString();+ }+ if (c == -1) {+ return buf.toString();+ }+ buf.append((char) c);+ }+ }+@Testpublic void testForkIntoNonExistent()- throws IOException, InterruptedException, TimeoutException {+ throws IOException, InterruptedException, TimeoutException, ExecutionException {+ CompletableFuture<String> future;try (UnixPty pty = openpty()) {PtySession dies =pty.getChild().session(new String[] { "thisHadBetterNotExist" }, null);/*** Choice of 127 is based on bash setting "exit code" to 127 for "command not found"*/+ BufferedReader reader = loggingReader(pty.getParent().getInputStream());+ future = CompletableFuture.supplyAsync(() -> readAllToErr(reader));assertEquals(127, dies.waitExited(2, TimeUnit.SECONDS));}+ String output = future.get(1, TimeUnit.SECONDS);+ assertThat(output, Matchers.containsString("No such file or directory"));}@Testdiff --git a/Ghidra/Framework/Pty/src/test/java/ghidra/pty/windows/ConPtyTest.java b/Ghidra/Framework/Pty/src/test/java/ghidra/pty/windows/ConPtyTest.javaindex 1e7a0f47a5..3ff4ac2ada 100644--- a/Ghidra/Framework/Pty/src/test/java/ghidra/pty/windows/ConPtyTest.java+++ b/Ghidra/Framework/Pty/src/test/java/ghidra/pty/windows/ConPtyTest.java@@ -22,15 +22,13 @@ import java.io.*;import java.lang.ProcessBuilder.Redirect;import java.util.concurrent.TimeUnit;-import org.junit.Before;import org.junit.BeforeClass;import org.junit.Test;-import com.sun.jna.LastErrorException;-import ghidra.framework.OperatingSystem;import ghidra.pty.*;import ghidra.pty.testutil.DummyProc;+import ghidra.pty.windows.Win32Err.LastErrorException;import ghidra.util.Msg;public class ConPtyTest extends AbstractPtyTest {@@ -61,7 +59,7 @@ public class ConPtyTest extends AbstractPtyTest {fail();}catch (LastErrorException e) {- assertEquals(2, e.getErrorCode());+ assertEquals(2, e.getLastError());}}@@ -148,8 +146,7 @@ public class ConPtyTest extends AbstractPtyTest {* we get to the {@link Process#waitFor(long, TimeUnit)} call. It will return false, thus* causing the expected {@link AssertionError}.*- * @throws Exception- * 'tis a test+ * @throws Exception 'tis a test*/@Test(expected = AssertionError.class)public void testGdbInterruptPlain() throws Exception {@@ -211,8 +208,7 @@ public class ConPtyTest extends AbstractPtyTest {* signal to actually get sent to gdb. I haven't the slightest idea where it goes instead, if* anywhere.*- * @throws Exception- * 'tis a test+ * @throws Exception 'tis a test*/@Testpublic void testGdbInterruptConPty() throws Exception {diff --git a/Ghidra/Framework/Pty/src/test/java/ghidra/pty/windows/NamedPipeTest.java b/Ghidra/Framework/Pty/src/test/java/ghidra/pty/windows/NamedPipeTest.javadeleted file mode 100644index 1557496cd4..0000000000--- a/Ghidra/Framework/Pty/src/test/java/ghidra/pty/windows/NamedPipeTest.java+++ /dev/null@@ -1,68 +0,0 @@-/* ###- * IP: GHIDRA- *- * Licensed under the Apache License, Version 2.0 (the "License");- * you may not use this file except in compliance with the License.- * You may obtain a copy of the License at- *- * http://www.apache.org/licenses/LICENSE-2.0- *- * Unless required by applicable law or agreed to in writing, software- * distributed under the License is distributed on an "AS IS" BASIS,- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.- * See the License for the specific language governing permissions and- * limitations under the License.- */-package ghidra.pty.windows;--import java.io.*;--import com.sun.jna.LastErrorException;-import com.sun.jna.platform.win32.Kernel32;-import com.sun.jna.platform.win32.WinNT.HANDLE;--public class NamedPipeTest {-- protected Handle checkHandle(HANDLE handle) {- if (Kernel32.INVALID_HANDLE_VALUE.equals(handle)) {- throw new LastErrorException(Kernel32.INSTANCE.GetLastError());- }- return new Handle(handle);- }-- // @Test- /**- * Experiment with MinGW GDB, named pipes, and {@code new-ui}.- *- * <p>- * Run this test, start GDB in a command shell, then issue- * "{@code new-ui mi2 \\\\.\\pipe\\GhidraGDB}". With GDB 11.1, GDB will print "New UI allocated"- * to the console, and I'll receive {@code =thread-group-added,id="i1"} on the pipe. However,- * GDB never seems to process my {@code -add-inferior} command. Furthermore, GDB freezes and no- * longer accepts input on the console, either.- */- public void testExpNamedPipes() throws Exception {- Handle hPipe = checkHandle(Kernel32.INSTANCE.CreateNamedPipe(- "\\\\.\\pipe\\GhidraGDB" /*lpName*/,- Kernel32.PIPE_ACCESS_DUPLEX /*dwOpenMode*/,- Kernel32.PIPE_TYPE_BYTE | Kernel32.PIPE_WAIT /*dwPipeMode*/,- Kernel32.PIPE_UNLIMITED_INSTANCES /*nMaxInstances*/,- 1024 /*nOutBufferSize*/,- 1024 /*nInBufferSize*/,- 0 /*nDefaultTimeOut*/,- null /*lpSecurityAttributes*/));-- try (PrintWriter writer = new PrintWriter(new HandleOutputStream(hPipe));- BufferedReader reader =- new BufferedReader(new InputStreamReader(new HandleInputStream(hPipe)))) {-- writer.println("-add-inferior");- writer.flush();-- String line;- while (null != (line = reader.readLine())) {- System.out.println(line);- }- }- }-}