diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d526c73 --- /dev/null +++ b/.gitignore @@ -0,0 +1,361 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# MIDL Generated files +src/WeChatSDKCore/sdkclk_c.c +src/WeChatSDKCore/sdkclk_h.h +src/WeChatSDKCore/sdkclk_s.c +src/WeChatSDKCore/sdkdef_c.c +src/WeChatSDKCore/sdkdef_h.h +src/WeChatSDKCore/sdkdef_s.c + +# Other files +*.sh diff --git a/hash.txt b/hash.txt index 2e729ac..17e527d 100644 --- a/hash.txt +++ b/hash.txt @@ -9,24 +9,24 @@ SHA1: B4150B13E4E6AE85ABE1F83F2B374B5D3E9E233B CRC32: 8E8D62D2 WeChatSDKCore.dll -MD5: 2AB0903104620622E9056EBCD22C9600 -SHA1: 8DD08DAA01329002A33900916C0F56A7E940CDD7 -CRC32: 59D2FA1A +MD5: 7CB7A580A227CD025C4222053BAFA195 +SHA1: 608B07AAB37912DBA39EE9C028A14FCC87813FC3 +CRC32: 016217D1 SuperWeChat.exe -MD5: AF365699BA3025C76F723D8B4B1791A9 -SHA1: 06F60F9158E12E641CB3485A9500D09BEB7F58CE -CRC32: 890C36B9 +MD5: 4666BB2DEC2B178421F981D1E508AE00 +SHA1: 6E2882C27562C94A3E1556D706C81BFBAFB4042E +CRC32: AAFE36CD SuperWeChat.zip -MD5: C28FEFE83C9EC1986B2491DAC220B846 -SHA1: 668853A7B3726C6D72E08596AC06B43B6830B5EF -CRC32: CBB90E7A +MD5: 5EC23C86BB7078A143BDD89402244F24 +SHA1: 7311FF554679DBDD3DBAD985C02732C8954B42D9 +CRC32: 1CA573FF WeChatSDK.dll -MD5: A4EBCB82557FFD521EAB40A71198819E -SHA1: 4A2467F7AACFD88D16666E8247B1CF23311F98C3 -CRC32: 7CABAA98 +MD5: DA4526ECACBDA4070E076B28596D12FD +SHA1: B602A3D00118FC43ECA2072C0058AE79EF67D8EA +CRC32: 4FA29F1A diff --git a/sdk/SuperWeChat.exe b/sdk/SuperWeChat.exe index 9f8e825..becb02c 100644 Binary files a/sdk/SuperWeChat.exe and b/sdk/SuperWeChat.exe differ diff --git a/sdk/SuperWeChat.zip b/sdk/SuperWeChat.zip index 70269d7..0b487a1 100644 Binary files a/sdk/SuperWeChat.zip and b/sdk/SuperWeChat.zip differ diff --git a/sdk/WeChatSDK.dll b/sdk/WeChatSDK.dll index 16f173f..bf59068 100644 Binary files a/sdk/WeChatSDK.dll and b/sdk/WeChatSDK.dll differ diff --git a/sdk/WeChatSDKCore.dll b/sdk/WeChatSDKCore.dll index bfb7303..ea5a3ca 100644 Binary files a/sdk/WeChatSDKCore.dll and b/sdk/WeChatSDKCore.dll differ diff --git a/src/WeChatSDK/openwechat.cpp b/src/WeChatSDK/openwechat.cpp index d9af33e..06a767d 100644 --- a/src/WeChatSDK/openwechat.cpp +++ b/src/WeChatSDK/openwechat.cpp @@ -92,7 +92,8 @@ BOOL IsTargetPid(DWORD Pid, DWORD* Pids, int num) int PatchWeChat() { - DWORD dwSize = 0; + DWORD dwSize = 0x1000; + DWORD dwRequiredSize = 0; POBJECT_NAME_INFORMATION pNameInfo; POBJECT_NAME_INFORMATION pNameType; PVOID pbuffer = NULL; @@ -101,7 +102,7 @@ int PatchWeChat() DWORD dwFlags = 0; char szType[128] = { 0 }; char szName[512] = { 0 }; - PSYSTEM_HANDLE_INFORMATION1 pHandleInfo = NULL; + PSYSTEM_HANDLE_INFORMATION_EX pHandleInfo = NULL; DWORD Pids[100] = { 0 }; int ret = -1; @@ -118,57 +119,42 @@ int PatchWeChat() goto Exit0; } - pbuffer = VirtualAlloc(NULL, 0x1000, MEM_COMMIT, PAGE_READWRITE); - - if (!pbuffer) + // 保证程序的正确性 + do { - goto Exit0; - } - - Status = ZwQuerySystemInformation(SystemHandleInformation, pbuffer, 0x1000, &dwSize); - - if (!NT_SUCCESS(Status)) - { - if (STATUS_INFO_LENGTH_MISMATCH != Status) + pbuffer = VirtualAlloc(NULL, dwSize, MEM_COMMIT, PAGE_READWRITE); + if (!pbuffer) { + printf ("Alloc Memory for System Handler Info failed!\n"); goto Exit0; } - else - { - // 这里大家可以保证程序的正确性使用循环分配稍好 - if (NULL != pbuffer) - { - VirtualFree(pbuffer, 0, MEM_RELEASE); - } - - if (dwSize * 2 > 0x4000000) // MAXSIZE - { - goto Exit0; - } - pbuffer = VirtualAlloc(NULL, dwSize * 2, MEM_COMMIT, PAGE_READWRITE); - - if (!pbuffer) + Status = ZwQuerySystemInformation(SystemHandleInformation, pbuffer, dwSize, &dwRequiredSize); + if (!NT_SUCCESS(Status)) + { + if (Status == STATUS_INFO_LENGTH_MISMATCH) { - goto Exit0; + if (pbuffer) + { + VirtualFree(pbuffer, 0, MEM_RELEASE); + pbuffer = NULL; + } + dwSize += dwRequiredSize; } - - Status = ZwQuerySystemInformation(SystemHandleInformation, pbuffer, dwSize * 2, NULL); - - if (!NT_SUCCESS(Status)) + else { + printf("Get System Hanlder Info failed : 0x%X\n", Status); goto Exit0; } } - } + } while (Status == STATUS_INFO_LENGTH_MISMATCH); - pHandleInfo = (PSYSTEM_HANDLE_INFORMATION1)pbuffer; + pHandleInfo = (PSYSTEM_HANDLE_INFORMATION_EX)pbuffer; for (nIndex = 0; nIndex < pHandleInfo->NumberOfHandles; nIndex++) { if (IsTargetPid(pHandleInfo->Handles[nIndex].UniqueProcessId, Pids, Num)) { - // HANDLE hHandle = DuplicateHandleEx(pHandleInfo->Handles[nIndex].UniqueProcessId, (HANDLE)pHandleInfo->Handles[nIndex].HandleValue, DUPLICATE_SAME_ACCESS @@ -194,14 +180,14 @@ int PatchWeChat() pNameInfo = (POBJECT_NAME_INFORMATION)szName; pNameType = (POBJECT_NAME_INFORMATION)szType; - WCHAR TypName[1024] = { 0 }; + WCHAR TypeName[1024] = { 0 }; WCHAR Name[1024] = { 0 }; - wcsncpy_s(TypName, (WCHAR*)pNameType->Name.Buffer, pNameType->Name.Length / 2); + wcsncpy_s(TypeName, (WCHAR*)pNameType->Name.Buffer, pNameType->Name.Length / 2); wcsncpy_s(Name, (WCHAR*)pNameInfo->Name.Buffer, pNameInfo->Name.Length / 2); // 匹配是否为需要关闭的句柄名称 - if (0 == wcscmp(TypName, L"Mutant")) + if (0 == wcscmp(TypeName, L"Mutant")) { //WeChat_aj5r8jpxt_Instance_Identity_Mutex_Name //if (wcsstr(Name, L"_WeChat_App_Instance_Identity_Mutex_Name")) @@ -228,8 +214,10 @@ int PatchWeChat() //goto Exit0; } } - - CloseHandle(hHandle); + else + { + CloseHandle(hHandle); + } } } diff --git a/src/WeChatSDK/openwechat.h b/src/WeChatSDK/openwechat.h index 94948fb..f66ab2d 100644 --- a/src/WeChatSDK/openwechat.h +++ b/src/WeChatSDK/openwechat.h @@ -175,10 +175,10 @@ typedef struct _SYSTEM_HANDLE_TABLE_ENTRY_INFO { ULONG GrantedAccess; } SYSTEM_HANDLE_TABLE_ENTRY_INFO, *PSYSTEM_HANDLE_TABLE_ENTRY_INFO; -typedef struct _SYSTEM_HANDLE_INFORMATION1 { +typedef struct _SYSTEM_HANDLE_INFORMATION_EX { ULONG NumberOfHandles; SYSTEM_HANDLE_TABLE_ENTRY_INFO Handles[1]; -} SYSTEM_HANDLE_INFORMATION1, *PSYSTEM_HANDLE_INFORMATION1; +} SYSTEM_HANDLE_INFORMATION_EX, * PSYSTEM_HANDLE_INFORMATION_EX; typedef enum _OBJECT_INFORMATION_CLASS { ObjectBasicInformation, diff --git a/src/WeChatSDKCore/WeChatSDKCore.sln b/src/WeChatSDKCore/WeChatSDKCore.sln index 1872720..b789e63 100644 --- a/src/WeChatSDKCore/WeChatSDKCore.sln +++ b/src/WeChatSDKCore/WeChatSDKCore.sln @@ -6,8 +6,15 @@ MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WeChatSDKCore", "WeChatResource.vcxproj", "{CC8544D5-1A6E-4515-B737-4DA205371032}" EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WeChatSDK", "..\WeChatSDK\WeChatSDK.vcxproj", "{3863B180-E079-4735-ABF7-13552EE0C3F1}" + ProjectSection(ProjectDependencies) = postProject + {CC8544D5-1A6E-4515-B737-4DA205371032} = {CC8544D5-1A6E-4515-B737-4DA205371032} + EndProjectSection EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WeChatSDKTest", "..\WeChatSDKTest\WeChatSDKTest.vcxproj", "{00EC6E77-8926-4860-A73F-3E5DBBE6221B}" + ProjectSection(ProjectDependencies) = postProject + {3863B180-E079-4735-ABF7-13552EE0C3F1} = {3863B180-E079-4735-ABF7-13552EE0C3F1} + {CC8544D5-1A6E-4515-B737-4DA205371032} = {CC8544D5-1A6E-4515-B737-4DA205371032} + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution