1 /* 2 * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 #ifndef WINDOWSPLATFORM_H 27 #define WINDOWSPLATFORM_H 28 29 #include <Windows.h> 30 #include "Platform.h" 31 32 class WindowsPlatform : virtual public Platform { 33 private: 34 DWORD FMainThread; 35 36 public: 37 WindowsPlatform(void); 38 virtual ~WindowsPlatform(void); 39 40 virtual TCHAR* ConvertStringToFileSystemString(TCHAR* Source, 41 bool &release); 42 virtual TCHAR* ConvertFileSystemStringToString(TCHAR* Source, 43 bool &release); 44 45 virtual void ShowMessage(TString title, TString description); 46 virtual void ShowMessage(TString description); 47 virtual MessageResponse ShowResponseMessage(TString title, 48 TString description); 49 50 virtual void SetCurrentDirectory(TString Value); 51 virtual TString GetPackageRootDirectory(); 52 virtual TString GetAppDataDirectory(); 53 virtual TString GetAppName(); 54 virtual TString GetBundledJVMLibraryFileName(TString RuntimePath); 55 TString GetPackageAppDirectory(); 56 TString GetPackageLauncherDirectory(); 57 TString GetPackageRuntimeBinDirectory(); 58 59 virtual ISectionalPropertyContainer* GetConfigFile(TString FileName); 60 61 virtual TString GetModuleFileName(); 62 virtual Module LoadLibrary(TString FileName); 63 virtual void FreeLibrary(Module AModule); 64 virtual Procedure GetProcAddress(Module AModule, std::string MethodName); 65 66 virtual Process* CreateProcess(); 67 68 virtual bool IsMainThread(); 69 virtual TPlatformNumber GetMemorySize(); 70 71 virtual TString GetTempDirectory(); 72 void InitStreamLocale(wios *stream); 73 void addPlatformDependencies(JavaLibrary *pJavaLibrary); 74 }; 75 76 class FileHandle { 77 private: 78 HANDLE FHandle; 79 80 public: 81 FileHandle(std::wstring FileName); 82 ~FileHandle(); 83 84 bool IsValid(); 85 HANDLE GetHandle(); 86 }; 87 88 89 class FileMappingHandle { 90 private: 91 HANDLE FHandle; 92 93 public: 94 FileMappingHandle(HANDLE FileHandle); 95 ~FileMappingHandle(); 96 97 bool IsValid(); 98 HANDLE GetHandle(); 99 }; 100 101 102 class FileData { 103 private: 104 LPVOID FBaseAddress; 105 106 public: 107 FileData(HANDLE Handle); 108 ~FileData(); 109 110 bool IsValid(); 111 LPVOID GetBaseAddress(); 112 }; 113 114 115 class WindowsLibrary { 116 private: 117 TString FFileName; 118 119 // Given an RVA, look up the section header that encloses it and return a 120 // pointer to its IMAGE_SECTION_HEADER 121 static PIMAGE_SECTION_HEADER GetEnclosingSectionHeader(DWORD rva, 122 PIMAGE_NT_HEADERS pNTHeader); 123 static LPVOID GetPtrFromRVA(DWORD rva, PIMAGE_NT_HEADERS pNTHeader, 124 DWORD imageBase); 125 static std::vector<TString> GetImportsSection(DWORD base, 126 PIMAGE_NT_HEADERS pNTHeader); 127 static std::vector<TString> DumpPEFile(PIMAGE_DOS_HEADER dosHeader); 128 129 public: 130 WindowsLibrary(const TString FileName); 131 132 std::vector<TString> GetImports(); 133 }; 134 135 136 class WindowsJob { 137 private: 138 HANDLE FHandle; 139 140 public: 141 WindowsJob(); 142 ~WindowsJob(); 143 144 HANDLE GetHandle(); 145 }; 146 147 148 class WindowsProcess : public Process { 149 private: 150 bool FRunning; 151 152 PROCESS_INFORMATION FProcessInfo; 153 static WindowsJob FJob; 154 155 void Cleanup(); 156 bool ReadOutput(); 157 158 public: 159 WindowsProcess(); 160 virtual ~WindowsProcess(); 161 162 virtual bool IsRunning(); 163 virtual bool Terminate(); 164 virtual bool Execute(const TString Application, 165 const std::vector<TString> Arguments, bool AWait = false); 166 virtual bool Wait(); 167 virtual TProcessID GetProcessID(); 168 virtual void SetInput(TString Value); 169 virtual std::list<TString> GetOutput(); 170 }; 171 172 #endif // WINDOWSPLATFORM_H