Skip to content

Commit

Permalink
Fix window render issue (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
blurfx authored Sep 10, 2021
1 parent 4506eb9 commit c093b13
Show file tree
Hide file tree
Showing 8 changed files with 204 additions and 61 deletions.
4 changes: 2 additions & 2 deletions KakaoTalkAdBlock.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
<MapFileExtensions>true</MapFileExtensions>
<InstallUrl>https://raw.githubusercontent.com/blurfx/KakaoTalkAdBlock/master/publish/</InstallUrl>
<UpdateUrl>https://raw.githubusercontent.com/blurfx/KakaoTalkAdBlock/master/publish/</UpdateUrl>
<ApplicationRevision>1</ApplicationRevision>
<ApplicationVersion>1.1.0.%2a</ApplicationVersion>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.2.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<CreateDesktopShortcut>true</CreateDesktopShortcut>
<PublishWizardCompleted>true</PublishWizardCompleted>
Expand Down
127 changes: 72 additions & 55 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ static bool EnumWindow(IntPtr Handle, IntPtr Parameter)
static string APP_NAME = "KakaoTalkAdBlock";

static volatile List<IntPtr> hwnd = new List<IntPtr>();
static IntPtr popUpHwnd = IntPtr.Zero;
static Container container = new Container();

static Thread watcherThread = new Thread(new ThreadStart(watchProcess));
Expand All @@ -84,6 +83,10 @@ static bool EnumWindow(IntPtr Handle, IntPtr Parameter)

const int UPDATE_RATE = 100;

const int LAYOUT_SHADOW_PADDING = 2;

const int MAINVIEW_PADDING = 31;

static uint WM_CLOSE = 0x10;
#endregion

Expand Down Expand Up @@ -140,10 +143,9 @@ static ContextMenuStrip buildContextMenu()
return contextMenu;
}

static void Main(string[] args)
static void Main()
{
bool isNotDuplicated = true;
var mutex = new Mutex(true, APP_NAME, out isNotDuplicated);
var mutex = new Mutex(true, APP_NAME, out bool isNotDuplicated);

if (!isNotDuplicated)
{
Expand All @@ -152,7 +154,7 @@ static void Main(string[] args)
}

// build trayicon
NotifyIcon tray = new NotifyIcon(container)
new NotifyIcon(container)
{
Visible = true,
Icon = Properties.Resources.icon,
Expand Down Expand Up @@ -229,66 +231,81 @@ static void removeAd()
GetClassName(childHwnd, windowClass, windowClass.Capacity);
GetWindowText(childHwnd, windowCaption, windowCaption.Capacity);

// hide adv
if (windowClass.ToString().Equals("BannerAdWnd") || windowClass.ToString().Equals("EVA_Window"))
{
GetWindowText(GetParent(childHwnd), windowParentCaption, windowParentCaption.Capacity);

if (GetParent(childHwnd) == wnd || windowParentCaption.ToString().StartsWith("LockModeView"))
{
ShowWindow(childHwnd, 0);
SetWindowPos(childHwnd, IntPtr.Zero, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE);
}
}

// remove white area
if (windowCaption.ToString().StartsWith("OnlineMainView") && GetParent(childHwnd) == wnd)
{
var width = rectKakaoTalk.Right - rectKakaoTalk.Left;
var height = (rectKakaoTalk.Bottom - rectKakaoTalk.Top) - 31; // 31; there might be dragon. don't touch it.
UpdateWindow(wnd);
SetWindowPos(childHwnd, IntPtr.Zero, 0, 0, width, height, SetWindowPosFlags.SWP_NOMOVE);
}

if (windowCaption.ToString().StartsWith("LockModeView") && GetParent(childHwnd) == wnd)
{
var width = rectKakaoTalk.Right - rectKakaoTalk.Left;
var height = (rectKakaoTalk.Bottom - rectKakaoTalk.Top); // 38; there might be dragon. don't touch it.
UpdateWindow(wnd);
SetWindowPos(childHwnd, IntPtr.Zero, 0, 0, width, height, SetWindowPosFlags.SWP_NOMOVE);
}
HideMainWindowAd(windowClass, windowParentCaption, wnd, childHwnd);
HideMainViewAdArea(windowCaption, wnd, rectKakaoTalk, childHwnd);
HideLockScreenAdArea(windowCaption, wnd, rectKakaoTalk, childHwnd);
}
}
HidePopupAd();
}
Thread.Sleep(UPDATE_RATE);
}
}

// close popup ad
popUpHwnd = IntPtr.Zero;
private static void HidePopupAd()
{
var popUpHwnd = IntPtr.Zero;
while ((popUpHwnd = FindWindowEx(IntPtr.Zero, popUpHwnd, null, "")) != IntPtr.Zero)
{
// popup ad does not have any parent
if (GetParent(popUpHwnd) != IntPtr.Zero) continue;

while ((popUpHwnd = FindWindowEx(IntPtr.Zero, popUpHwnd, null, "")) != IntPtr.Zero)
{
// popup ad does not have any parent
if (GetParent(popUpHwnd) != IntPtr.Zero) continue;
// get class name of blank title
var classNameSb = new StringBuilder(256);
GetClassName(popUpHwnd, classNameSb, classNameSb.Capacity);
string className = classNameSb.ToString();

// get class name of blank title
var classNameSb = new StringBuilder(256);
GetClassName(popUpHwnd, classNameSb, classNameSb.Capacity);
string className = classNameSb.ToString();
if (!className.Contains("RichPopWnd")) continue;

if (!className.Contains("RichPopWnd")) continue;
// get rect of popup ad
GetWindowRect(popUpHwnd, out RECT rectPopup);
var width = rectPopup.Right - rectPopup.Left;
var height = rectPopup.Bottom - rectPopup.Top;

// get rect of popup ad
RECT rectPopup = new RECT();
GetWindowRect(popUpHwnd, out rectPopup);
if (width.Equals(300) && height.Equals(150))
{
SendMessage(popUpHwnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
}
}
}

var width = rectPopup.Right - rectPopup.Left;
var height = rectPopup.Bottom - rectPopup.Top;
private static void HideMainWindowAd(StringBuilder windowClass, StringBuilder windowParentCaption, IntPtr wnd, IntPtr childHwnd)
{
if (windowClass.ToString().Equals("BannerAdWnd") || windowClass.ToString().Equals("EVA_Window"))
{
GetWindowText(GetParent(childHwnd), windowParentCaption, windowParentCaption.Capacity);

if (width.Equals(300) && height.Equals(150))
{
SendMessage(popUpHwnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
}
}
if (GetParent(childHwnd) == wnd || windowParentCaption.ToString().StartsWith("LockModeView"))
{
ShowWindow(childHwnd, 0);
SetWindowPos(childHwnd, IntPtr.Zero, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE);
}
Thread.Sleep(UPDATE_RATE);
}
}

private static void HideLockScreenAdArea(StringBuilder windowCaption, IntPtr wnd, RECT rectKakaoTalk, IntPtr childHwnd)
{
if (windowCaption.ToString().StartsWith("LockModeView") && GetParent(childHwnd) == wnd)
{
var width = rectKakaoTalk.Right - rectKakaoTalk.Left - LAYOUT_SHADOW_PADDING;
var height = rectKakaoTalk.Bottom - rectKakaoTalk.Top;
UpdateWindow(childHwnd);
SetWindowPos(childHwnd, IntPtr.Zero, 0, 0, width, height, SetWindowPosFlags.SWP_NOMOVE);
}
}

private static void HideMainViewAdArea(StringBuilder windowCaption, IntPtr wnd, RECT rectKakaoTalk, IntPtr childHwnd)
{
if (windowCaption.ToString().StartsWith("OnlineMainView") && GetParent(childHwnd) == wnd)
{
var width = rectKakaoTalk.Right - rectKakaoTalk.Left - LAYOUT_SHADOW_PADDING;
var height = rectKakaoTalk.Bottom - rectKakaoTalk.Top - MAINVIEW_PADDING;
if (height < 1)
{
return;
}
UpdateWindow(childHwnd);
SetWindowPos(childHwnd, IntPtr.Zero, 0, 0, width, height, SetWindowPosFlags.SWP_NOMOVE);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly xsi:schemaLocation="urn:schemas-microsoft-com:asm.v1 assembly.adaptive.xsd" manifestVersion="1.0" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns="urn:schemas-microsoft-com:asm.v2" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xrml="urn:mpeg:mpeg21:2003:01-REL-R-NS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:co.v1="urn:schemas-microsoft-com:clickonce.v1" xmlns:co.v2="urn:schemas-microsoft-com:clickonce.v2">
<assemblyIdentity name="KakaoTalkAdBlock.application" version="1.2.0.0" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="msil" xmlns="urn:schemas-microsoft-com:asm.v1" />
<description asmv2:publisher="KakaoTalkAdBlock" asmv2:product="KakaoTalkAdBlock" xmlns="urn:schemas-microsoft-com:asm.v1" />
<deployment install="true" mapFileExtensions="true" co.v1:createDesktopShortcut="true">
<subscription>
<update>
<beforeApplicationStartup />
</update>
</subscription>
<deploymentProvider codebase="https://raw.githubusercontent.com/blurfx/KakaoTalkAdBlock/master/publish/KakaoTalkAdBlock.application" />
</deployment>
<compatibleFrameworks xmlns="urn:schemas-microsoft-com:clickonce.v2">
<framework targetVersion="4.6.2" profile="Full" supportedRuntime="4.0.30319" />
</compatibleFrameworks>
<dependency>
<dependentAssembly dependencyType="install" codebase="Application Files\KakaoTalkAdBlock_1_2_0_0\KakaoTalkAdBlock.exe.manifest" size="5265">
<assemblyIdentity name="KakaoTalkAdBlock.exe" version="1.2.0.0" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="msil" type="win32" />
<hash>
<dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>SgbzH+SaS03k4ibokHwMsuHUFVuVeJDuZ1yq4TlHOQs=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
</asmv1:assembly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
</startup>
</configuration>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly xsi:schemaLocation="urn:schemas-microsoft-com:asm.v1 assembly.adaptive.xsd" manifestVersion="1.0" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns="urn:schemas-microsoft-com:asm.v2" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:co.v1="urn:schemas-microsoft-com:clickonce.v1" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:co.v2="urn:schemas-microsoft-com:clickonce.v2">
<asmv1:assemblyIdentity name="KakaoTalkAdBlock.exe" version="1.2.0.0" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="msil" type="win32" />
<description asmv2:iconFile="Resources\icon.ico" xmlns="urn:schemas-microsoft-com:asm.v1" />
<application />
<entryPoint>
<assemblyIdentity name="KakaoTalkAdBlock" version="1.0.0.0" publicKeyToken="4D9DCEC13DEC58CF" language="neutral" processorArchitecture="msil" />
<commandLine file="KakaoTalkAdBlock.exe" parameters="" />
</entryPoint>
<trustInfo>
<security>
<applicationRequestMinimum>
<PermissionSet version="1" class="System.Security.NamedPermissionSet" Name="LocalIntranet" Description="Default rights given to applications on the local intranet" Unrestricted="true" ID="Custom" SameSite="site" />
<defaultAssemblyRequest permissionSetReference="Custom" />
</applicationRequestMinimum>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<!-- UAC 매니페스트 옵션
Windows 사용자 계정 컨트롤 수준을 변경하려면
requestedExecutionLevel 노드를 다음 중 하나로 바꿉니다.
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
<requestedExecutionLevel level="highestAvailable" uiAccess="false" />
requestedExecutionLevel 요소를 지정하면 파일 및 레지스트리 가상화를 사용하지 않습니다.
이전 버전과의 호환성을 위해 응용 프로그램에 가상화가 필요한 경우
이 요소를 제거합니다.
-->
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<dependency>
<dependentOS>
<osVersionInfo>
<os majorVersion="5" minorVersion="1" buildNumber="2600" servicePackMajor="0" />
</osVersionInfo>
</dependentOS>
</dependency>
<dependency>
<dependentAssembly dependencyType="preRequisite" allowDelayedBinding="true">
<assemblyIdentity name="Microsoft.Windows.CommonLanguageRuntime" version="4.0.30319.0" />
</dependentAssembly>
</dependency>
<dependency>
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="KakaoTalkAdBlock.exe" size="352256">
<assemblyIdentity name="KakaoTalkAdBlock" version="1.0.0.0" publicKeyToken="4D9DCEC13DEC58CF" language="neutral" processorArchitecture="msil" />
<hash>
<dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>rrtgwoyu27QMVu37T4K9uulEJiZT78Hfl8OcAdYk+rU=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
<file name="KakaoTalkAdBlock.exe.config" size="184">
<hash>
<dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>m20YocjtLXRp5K9vfJFi4k8D121UK3HMX1QmW56Qm7E=</dsig:DigestValue>
</hash>
</file>
<file name="Resources\icon.ico" size="169662">
<hash>
<dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>Dylcd40wSfP+sCjnXQ1cTq72mmtJd5E6YvJAnuPX+N0=</dsig:DigestValue>
</hash>
</file>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- 이 응용 프로그램이 테스트되고 함께 작동하도록 설계된 Windows 버전
목록입니다. 적절한 요소의 주석 처리를 제거하면 Windows에서
호환 가능성이 가장 높은 환경을 자동으로 선택합니다. -->
<!-- Windows Vista -->
<!--<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />-->
<!-- Windows 7 -->
<!--<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />-->
<!-- Windows 8 -->
<!--<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />-->
<!-- Windows 8.1 -->
<!--<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />-->
<!-- Windows 10 -->
<!--<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />-->
</application>
</compatibility>
</asmv1:assembly>
Binary file not shown.
8 changes: 4 additions & 4 deletions publish/KakaoTalkAdBlock.application
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly xsi:schemaLocation="urn:schemas-microsoft-com:asm.v1 assembly.adaptive.xsd" manifestVersion="1.0" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns="urn:schemas-microsoft-com:asm.v2" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xrml="urn:mpeg:mpeg21:2003:01-REL-R-NS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" xmlns:co.v1="urn:schemas-microsoft-com:clickonce.v1" xmlns:co.v2="urn:schemas-microsoft-com:clickonce.v2">
<assemblyIdentity name="KakaoTalkAdBlock.application" version="1.1.0.1" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="msil" xmlns="urn:schemas-microsoft-com:asm.v1" />
<assemblyIdentity name="KakaoTalkAdBlock.application" version="1.2.0.0" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="msil" xmlns="urn:schemas-microsoft-com:asm.v1" />
<description asmv2:publisher="KakaoTalkAdBlock" asmv2:product="KakaoTalkAdBlock" xmlns="urn:schemas-microsoft-com:asm.v1" />
<deployment install="true" mapFileExtensions="true" co.v1:createDesktopShortcut="true">
<subscription>
Expand All @@ -14,14 +14,14 @@
<framework targetVersion="4.6.2" profile="Full" supportedRuntime="4.0.30319" />
</compatibleFrameworks>
<dependency>
<dependentAssembly dependencyType="install" codebase="Application Files\KakaoTalkAdBlock_1_1_0_1\KakaoTalkAdBlock.exe.manifest" size="5265">
<assemblyIdentity name="KakaoTalkAdBlock.exe" version="1.1.0.1" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="msil" type="win32" />
<dependentAssembly dependencyType="install" codebase="Application Files\KakaoTalkAdBlock_1_2_0_0\KakaoTalkAdBlock.exe.manifest" size="5265">
<assemblyIdentity name="KakaoTalkAdBlock.exe" version="1.2.0.0" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="msil" type="win32" />
<hash>
<dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>medK4BdfPUlLtQFFlW7kXrRw0K/BkvQNDxXBlnHLAiM=</dsig:DigestValue>
<dsig:DigestValue>SgbzH+SaS03k4ibokHwMsuHUFVuVeJDuZ1yq4TlHOQs=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
Expand Down

0 comments on commit c093b13

Please sign in to comment.