diff --git a/.gitignore b/.gitignore index dc82ffb..18f9186 100644 --- a/.gitignore +++ b/.gitignore @@ -32,4 +32,5 @@ ipch/ *.opensdf *.ide packages/ -_* \ No newline at end of file +_* +.localhistory/ \ No newline at end of file diff --git a/GetMmdTransformationContainer/App.config b/GetMmdTransformationContainer/App.config new file mode 100644 index 0000000..2c307fa --- /dev/null +++ b/GetMmdTransformationContainer/App.config @@ -0,0 +1,6 @@ + + + + + + diff --git a/GetMmdTransformationContainer/GetMmdTransformationContainer.csproj b/GetMmdTransformationContainer/GetMmdTransformationContainer.csproj new file mode 100644 index 0000000..c8147b0 --- /dev/null +++ b/GetMmdTransformationContainer/GetMmdTransformationContainer.csproj @@ -0,0 +1,73 @@ + + + + + Debug + AnyCPU + {8DC503A7-C9C6-4CED-B0B5-8A15D72F73C3} + WinExe + Properties + GetMmdTransformationContainer + GetMmdTransformationContainer + v4.0 + 512 + true + + + + true + bin\Debug\ + DEBUG;TRACE + full + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + bin\Release\ + TRACE + true + pdbonly + x86 + prompt + MinimumRecommendedRules.ruleset + true + + + OnOutputUpdated + + + + + + + + + + + + + + + + + Program.cs + + + + + + + + + copy $(TargetPath) $(SolutionDir)GetMmdTransformationPlugin\Resources + + + \ No newline at end of file diff --git a/GetMmdTransformationContainer/Properties/AssemblyInfo.cs b/GetMmdTransformationContainer/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..41f2048 --- /dev/null +++ b/GetMmdTransformationContainer/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// アセンブリに関する一般情報は以下の属性セットをとおして制御されます。 +// アセンブリに関連付けられている情報を変更するには、 +// これらの属性値を変更してください。 +[assembly: AssemblyTitle("GetMmdTransformationContainer32")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("GetMmdTransformationContainer32")] +[assembly: AssemblyCopyright("Copyright © 2016")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible を false に設定すると、その型はこのアセンブリ内で COM コンポーネントから +// 参照不可能になります。COM からこのアセンブリ内の型にアクセスする場合は、 +// その型の ComVisible 属性を true に設定してください。 +[assembly: ComVisible(false)] + +// このプロジェクトが COM に公開される場合、次の GUID が typelib の ID になります +[assembly: Guid("8dc503a7-c9c6-4ced-b0b5-8a15d72f73c3")] + +// アセンブリのバージョン情報は次の 4 つの値で構成されています: +// +// メジャー バージョン +// マイナー バージョン +// ビルド番号 +// Revision +// +// すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を +// 既定値にすることができます: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/GetMmdTransformationContainer64/Program.cs b/GetMmdTransformationContainer64/Program.cs index 054fe4b..c2bf3eb 100644 --- a/GetMmdTransformationContainer64/Program.cs +++ b/GetMmdTransformationContainer64/Program.cs @@ -6,7 +6,7 @@ using System.Security; using System.Text; -namespace GetMmdTransformationContainer64 +namespace GetMmdTransformationContainer { class Program { @@ -77,7 +77,7 @@ static void Main(string[] args) WaitForSingleObject(hThread, unchecked((uint)-1)); CloseHandle(hThread); } - + // if finished, unload the library. FreeLibraryRemote(hProcess, kernelModule, hModule); FreeLibrary(localModule); diff --git a/GetMmdTransformationPlugin/GetMmdTransformationPlugin.csproj b/GetMmdTransformationPlugin/GetMmdTransformationPlugin.csproj index 731ac8e..c794c0c 100644 --- a/GetMmdTransformationPlugin/GetMmdTransformationPlugin.csproj +++ b/GetMmdTransformationPlugin/GetMmdTransformationPlugin.csproj @@ -22,7 +22,7 @@ prompt 4 false - x86 + AnyCPU pdbonly @@ -32,7 +32,7 @@ prompt 4 false - x86 + AnyCPU OnOutputUpdated @@ -90,6 +90,7 @@ + diff --git a/GetMmdTransformationPlugin/GetMmdTransformationPlugin.txt b/GetMmdTransformationPlugin/GetMmdTransformationPlugin.txt index 61b4fef..c490259 100644 --- a/GetMmdTransformationPlugin/GetMmdTransformationPlugin.txt +++ b/GetMmdTransformationPlugin/GetMmdTransformationPlugin.txt @@ -25,6 +25,10 @@ MikuMikuMoving.exe のあるフォルダの Plugins フォルダに本 dll を ◆更新履歴 +Version 0.6, Sun, 24 Jul 2016 + + x64 版 MMM に対応 + Version 0.5, Sat, 22 Sep 2012 x64 版 MMD に対応 diff --git a/GetMmdTransformationPlugin/Mmd/MmdImport.cs b/GetMmdTransformationPlugin/Mmd/MmdImport.cs index f4a9ae4..da07b83 100644 --- a/GetMmdTransformationPlugin/Mmd/MmdImport.cs +++ b/GetMmdTransformationPlugin/Mmd/MmdImport.cs @@ -6,7 +6,6 @@ using System.Linq; using System.Runtime.InteropServices; using System.Security; -using System.Text; using System.Threading; using Linearstar.MikuMikuMoving.GetMmdTransformationPlugin.Properties; @@ -49,13 +48,7 @@ public MmdImport(Process process) pipe = new NamedPipeServerStream(namedPipePrefix + this.Handle.ToString()); - ThreadPool.QueueUserWorkItem(_ => - { - if (this.IsPlatform64) - InvokeRemote64(process, this.Handle); - else - InvokeRemote(process, this.Handle); - }); + ThreadPool.QueueUserWorkItem(_ => InvokeRemote(process, this.Handle)); pipe.WaitForConnection(); protocol = new MmdPipeProtocol(pipe); @@ -83,12 +76,12 @@ static T GetDelegate(IntPtr hModule, string entryPoint) return (T)(object)Marshal.GetDelegateForFunctionPointer(proc, typeof(T)); } - bool IsWow64Process(IntPtr hProcess) + static bool IsWow64Process(IntPtr hProcess) { var proc = GetProcAddress(GetModuleHandle("kernel32"), "IsWow64Process"); if (proc == IntPtr.Zero) - return false; + return true; bool rt; @@ -102,36 +95,15 @@ bool IsWow64Process(IntPtr hProcess) static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName); [SuppressUnmanagedCodeSecurity, DllImport("kernel32")] static extern IntPtr GetModuleHandle(string lpModuleName); - [SuppressUnmanagedCodeSecurity, DllImport("kernel32")] - static extern IntPtr VirtualAllocEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect); - [SuppressUnmanagedCodeSecurity, DllImport("kernel32")] - static extern IntPtr VirtualFreeEx(IntPtr hProcess, IntPtr lpAddress, uint dwSize, uint dwFreeType); - [SuppressUnmanagedCodeSecurity, DllImport("kernel32")] - static extern bool WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, byte[] lpBuffer, uint nSize, out uint lpNumberOfBytesWritten); - [SuppressUnmanagedCodeSecurity, DllImport("kernel32")] - static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr lpThreadAttributes, uint dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, uint dwCreationFlags, out uint lpThreadId); - [SuppressUnmanagedCodeSecurity, DllImport("kernel32")] - static extern uint WaitForSingleObject(IntPtr hHandle, uint dwMilliseconds); - [SuppressUnmanagedCodeSecurity, DllImport("kernel32")] - static extern uint CloseHandle(IntPtr hHandle); - [SuppressUnmanagedCodeSecurity, DllImport("kernel32")] - static extern bool GetExitCodeThread(IntPtr hThread, out IntPtr lpExitCode); - [SuppressUnmanagedCodeSecurity, DllImport("kernel32")] - static extern IntPtr LoadLibrary(string lpFileName); - [SuppressUnmanagedCodeSecurity, DllImport("kernel32")] - static extern bool FreeLibrary(IntPtr hModule); - - const uint MEM_COMMIT = 0x1000; - const uint MEM_RELEASE = 0x8000; - const uint PAGE_READWRITE = 0x4; - static void InvokeRemote64(Process process, IntPtr parameter) + static void InvokeRemote(Process process, IntPtr parameter) { var remoteProxy = Path.GetTempFileName(); var remoteContainer = Path.GetTempFileName(); + var isPlatform64 = !IsWow64Process(process.Handle); - File.WriteAllBytes(remoteContainer, Resources.GetMmdTransformationContainer64); - File.WriteAllBytes(remoteProxy, Resources.GetMmdTransformationProxy64); + File.WriteAllBytes(remoteContainer, isPlatform64 ? Resources.GetMmdTransformationContainer64 : Resources.GetMmdTransformationContainer); + File.WriteAllBytes(remoteProxy, isPlatform64 ? Resources.GetMmdTransformationProxy64 : Resources.GetMmdTransformationProxy); using (var p = Process.Start(new ProcessStartInfo { @@ -165,102 +137,6 @@ static void InvokeRemote64(Process process, IntPtr parameter) } } - static void InvokeRemote(Process process, IntPtr parameter) - { - var remoteProxy = Path.GetTempFileName(); - - File.WriteAllBytes(remoteProxy, Resources.GetMmdTransformationProxy); - - var localModule = LoadLibrary(remoteProxy); - var hProcess = process.Handle; - var kernelModule = GetModuleHandle("kernel32"); - IntPtr hModule; - - // check if the assembly is already loaded. - { - var moduleName = Encoding.Unicode.GetBytes(Path.GetFileName(remoteProxy)).Concat(new[] { (byte)0 }).ToArray(); - var alloc = VirtualAllocEx(hProcess, IntPtr.Zero, (uint)moduleName.Length, MEM_COMMIT, PAGE_READWRITE); - uint writtenBytes; - - WriteProcessMemory(hProcess, alloc, moduleName, (uint)moduleName.Length, out writtenBytes); - - { - uint lpThreadId; - var getModuleHandle = GetProcAddress(kernelModule, "GetModuleHandleW"); - var hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, getModuleHandle, alloc, 0, out lpThreadId); - - WaitForSingleObject(hThread, unchecked((uint)-1)); - GetExitCodeThread(hThread, out hModule); - CloseHandle(hThread); - } - - VirtualFreeEx(hProcess, alloc, writtenBytes, MEM_RELEASE); - } - - // if not loaded, use LoadLibraryW. - if (hModule == IntPtr.Zero) - hModule = LoadLibraryRemote(remoteProxy, hProcess, kernelModule); - - // the main action. - { - uint lpThreadId; - var localEntryPointAddr = GetProcAddress(localModule, remoteEntryPoint); - - // while hModule is just an address of the module, you can get the remote proc address by doing this :) - var remoteEntryPointAddr = hModule + (localEntryPointAddr.ToInt32() - localModule.ToInt32()); - var hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, remoteEntryPointAddr, parameter, 0, out lpThreadId); - - WaitForSingleObject(hThread, unchecked((uint)-1)); - CloseHandle(hThread); - } - - // if finished, unload the library. - FreeLibraryRemote(hProcess, kernelModule, hModule); - FreeLibrary(localModule); - - try - { - File.Delete(remoteProxy); - } - catch - { - } - } - - static IntPtr LoadLibraryRemote(string location, IntPtr hProcess, IntPtr kernelModule) - { - IntPtr hModule; - var path = Encoding.Unicode.GetBytes(location).Concat(new[] { (byte)0 }).ToArray(); - var alloc = VirtualAllocEx(hProcess, IntPtr.Zero, (uint)path.Length, MEM_COMMIT, PAGE_READWRITE); - uint writtenBytes; - - WriteProcessMemory(hProcess, alloc, path, (uint)path.Length, out writtenBytes); - - { - uint lpThreadId; - var loadLibrary = GetProcAddress(kernelModule, "LoadLibraryW"); - var hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, loadLibrary, alloc, 0, out lpThreadId); - - WaitForSingleObject(hThread, unchecked((uint)-1)); - GetExitCodeThread(hThread, out hModule); - CloseHandle(hThread); - } - - VirtualFreeEx(hProcess, alloc, writtenBytes, MEM_RELEASE); - - return hModule; - } - - static void FreeLibraryRemote(IntPtr hProcess, IntPtr kernelModule, IntPtr hModule) - { - uint lpThreadId; - var freeLibrary = GetProcAddress(kernelModule, "FreeLibrary"); - var hThread = CreateRemoteThread(hProcess, IntPtr.Zero, 0, freeLibrary, hModule, 0, out lpThreadId); - - WaitForSingleObject(hThread, unchecked((uint)-1)); - CloseHandle(hThread); - } - T InvokeRemote(string entryPoint, int[] parameters) { return protocol.InvokeRemote(entryPoint, parameters); diff --git a/GetMmdTransformationPlugin/Properties/AssemblyInfo.cs b/GetMmdTransformationPlugin/Properties/AssemblyInfo.cs index ade6391..1e2313a 100644 --- a/GetMmdTransformationPlugin/Properties/AssemblyInfo.cs +++ b/GetMmdTransformationPlugin/Properties/AssemblyInfo.cs @@ -7,5 +7,5 @@ [assembly: AssemblyCopyright("Copyright © mfakane 2012")] [assembly: ComVisible(false)] [assembly: Guid("2c309851-7f3e-4b62-87f9-44e5c492a0f8")] -[assembly: AssemblyVersion("0.5.*")] +[assembly: AssemblyVersion("0.6.*")] diff --git a/GetMmdTransformationPlugin/Properties/Resources.Designer.cs b/GetMmdTransformationPlugin/Properties/Resources.Designer.cs index ef0f8e6..16ebdc2 100644 --- a/GetMmdTransformationPlugin/Properties/Resources.Designer.cs +++ b/GetMmdTransformationPlugin/Properties/Resources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // このコードはツールによって生成されました。 -// ランタイム バージョン:4.0.30319.17929 +// ランタイム バージョン:4.0.30319.42000 // // このファイルへの変更は、以下の状況下で不正な動作の原因になったり、 // コードが再生成されるときに損失したりします。 @@ -80,6 +80,16 @@ internal class Resources { } } + /// + /// 型 System.Byte[] のローカライズされたリソースを検索します。 + /// + internal static byte[] GetMmdTransformationContainer { + get { + object obj = ResourceManager.GetObject("GetMmdTransformationContainer", resourceCulture); + return ((byte[])(obj)); + } + } + /// /// 型 System.Byte[] のローカライズされたリソースを検索します。 /// diff --git a/GetMmdTransformationPlugin/Properties/Resources.resx b/GetMmdTransformationPlugin/Properties/Resources.resx index 77fffb4..d64119e 100644 --- a/GetMmdTransformationPlugin/Properties/Resources.resx +++ b/GetMmdTransformationPlugin/Properties/Resources.resx @@ -124,6 +124,9 @@ ..\resources\getmmdtransformation32.png;System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + ..\resources\getmmdtransformationcontainer.exe;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + ..\Resources\GetMmdTransformationContainer64.exe;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 diff --git a/GetMmdTransformationPlugin/Resources/GetMmdTransformationProxy.dll b/GetMmdTransformationPlugin/Resources/GetMmdTransformationProxy.dll index d5a70d4..c9a0293 100644 Binary files a/GetMmdTransformationPlugin/Resources/GetMmdTransformationProxy.dll and b/GetMmdTransformationPlugin/Resources/GetMmdTransformationProxy.dll differ diff --git a/MMMInstallPlugin.bat b/MMMInstallPlugin.bat index b8f2939..24f6454 100644 --- a/MMMInstallPlugin.bat +++ b/MMMInstallPlugin.bat @@ -1,6 +1,6 @@ @echo off :: MikuMikuMoving ̃vOCtH_ւ̃pXw肵܂ -set targetPath=X:\mmd\tools\MikuMikuMoving\Plugins +set targetPath=D:\Mmd\tools\MikuMikuMoving\Plugins copy %1 %targetPath% \ No newline at end of file diff --git a/MikuMikuMoving.sln b/MikuMikuMoving.sln index 3a59e6a..ef6dfd9 100644 --- a/MikuMikuMoving.sln +++ b/MikuMikuMoving.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.30723.0 +# Visual Studio 14 +VisualStudioVersion = 14.0.25123.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MotionUtil", "MotionUtil\MotionUtil.csproj", "{D7632895-7A65-4BDD-9788-AF42DB82CC07}" EndProject @@ -39,6 +39,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution readme.txt = readme.txt EndProjectSection EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GetMmdTransformationContainer", "GetMmdTransformationContainer\GetMmdTransformationContainer.csproj", "{8DC503A7-C9C6-4CED-B0B5-8A15D72F73C3}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -253,6 +255,18 @@ Global {3F81EBD7-D9B0-41D2-87EE-8E087B719258}.Release|Win32.ActiveCfg = Release|x64 {3F81EBD7-D9B0-41D2-87EE-8E087B719258}.Release|x64.ActiveCfg = Release|x64 {3F81EBD7-D9B0-41D2-87EE-8E087B719258}.Release|x64.Build.0 = Release|x64 + {8DC503A7-C9C6-4CED-B0B5-8A15D72F73C3}.Debug|Any CPU.ActiveCfg = Debug|x86 + {8DC503A7-C9C6-4CED-B0B5-8A15D72F73C3}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {8DC503A7-C9C6-4CED-B0B5-8A15D72F73C3}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {8DC503A7-C9C6-4CED-B0B5-8A15D72F73C3}.Debug|Win32.ActiveCfg = Debug|x86 + {8DC503A7-C9C6-4CED-B0B5-8A15D72F73C3}.Debug|Win32.Build.0 = Debug|x86 + {8DC503A7-C9C6-4CED-B0B5-8A15D72F73C3}.Debug|x64.ActiveCfg = Debug|x86 + {8DC503A7-C9C6-4CED-B0B5-8A15D72F73C3}.Release|Any CPU.ActiveCfg = Release|x86 + {8DC503A7-C9C6-4CED-B0B5-8A15D72F73C3}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {8DC503A7-C9C6-4CED-B0B5-8A15D72F73C3}.Release|Mixed Platforms.Build.0 = Release|x86 + {8DC503A7-C9C6-4CED-B0B5-8A15D72F73C3}.Release|Win32.ActiveCfg = Release|x86 + {8DC503A7-C9C6-4CED-B0B5-8A15D72F73C3}.Release|Win32.Build.0 = Release|x86 + {8DC503A7-C9C6-4CED-B0B5-8A15D72F73C3}.Release|x64.ActiveCfg = Release|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE