Skip to content

Commit

Permalink
v0.1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
ACK72 committed Dec 21, 2024
1 parent 2fdd85f commit 9e41cab
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 51 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pure_kakao"
version = "0.1.5"
version = "0.1.6"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Pure-Kakao ![Generic badge](https://img.shields.io/badge/version-0.1.5-green.svg)
# Pure-Kakao ![Generic badge](https://img.shields.io/badge/version-0.1.6-green.svg)

Simple & lightweight ad-remover for kakaotalk pc client, written in Rust

Expand Down
97 changes: 48 additions & 49 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,78 +1,77 @@
#![windows_subsystem = "windows"]

use std::{
thread, time::Duration
thread, time::Duration
};
use windows::{
core::*, Win32::Foundation::*, Win32::Graphics::Gdi::*, Win32::UI::WindowsAndMessaging::*
core::*, Win32::Foundation::*, Win32::Graphics::Gdi::*, Win32::UI::WindowsAndMessaging::*
};

fn main() {
let title = w!("카카오톡");
loop {
let pwnd = unsafe { FindWindowW(PCWSTR::null(), title) };
if pwnd == HWND(0) {
thread::sleep(Duration::from_secs(1));
continue;
}

_ = unsafe { EnumWindows(Some(check), LPARAM(pwnd.0)) };
thread::sleep(Duration::from_millis(15));
}
let title = w!("카카오톡");
loop {
let pwnd = unsafe { FindWindowW(PCWSTR::null(), title) };
if pwnd == HWND(0) {
thread::sleep(Duration::from_secs(1));
continue;
}

_ = unsafe { EnumWindows(Some(check), LPARAM(pwnd.0)) };
thread::sleep(Duration::from_millis(15));
}
}

unsafe extern "system" fn check(hwnd: HWND, param: LPARAM) -> BOOL {
let pwnd = HWND(param.0);
let pwnd = HWND(param.0);

if pwnd == GetParent(hwnd) {
let cwnd = GetWindow(hwnd, GW_CHILD);
if pwnd == GetParent(hwnd) {
let cwnd = GetWindow(hwnd, GW_CHILD);
let nwnd = GetWindow(hwnd, GW_HWNDNEXT);

if cwnd != HWND(0) {
hide(hwnd, pwnd);
return FALSE;
}
}
if cwnd != HWND(0) && nwnd == pwnd {
hide(hwnd, pwnd);
return FALSE;
}
}

TRUE
TRUE
}

fn hide(hwnd: HWND, pwnd: HWND) {
let mut cwnd = HWND(0);
let mut frame = RECT::default();
let mut cwnd = HWND(0);
let mut frame = RECT::default();

_ = unsafe { GetWindowRect(pwnd, &mut frame) };
let kt_size = frame.bottom - frame.top;
_ = unsafe { GetWindowRect(pwnd, &mut frame) };
let kt_size = frame.bottom - frame.top;

_ = unsafe { GetWindowRect(hwnd, &mut frame) };
let ad_size = frame.bottom - frame.top;
_ = unsafe { GetWindowRect(hwnd, &mut frame) };
let ad_size = frame.bottom - frame.top;

_ = unsafe { ShowWindow(hwnd, SW_HIDE) };
_ = unsafe { ShowWindow(hwnd, SW_HIDE) };

loop {
cwnd = unsafe { FindWindowExA(pwnd, cwnd, PCSTR::null(), PCSTR::null()) };
loop {
cwnd = unsafe { FindWindowExA(pwnd, cwnd, PCSTR::null(), PCSTR::null()) };

if cwnd == HWND(0) {
break;
}
if cwnd == HWND(0) {
break;
}

let size = unsafe { GetWindowTextLengthW(cwnd) } as usize;
let mut caption_vec = vec![0 as u16; size];
_ = unsafe { GetWindowTextW(cwnd, &mut caption_vec) };
let caption = String::from_utf16(&mut caption_vec).unwrap();
let size = unsafe { GetWindowTextLengthW(cwnd) } as usize;
let mut caption_vec = vec![0 as u16; size];
_ = unsafe { GetWindowTextW(cwnd, &mut caption_vec) };
let caption = String::from_utf16(&mut caption_vec).unwrap();

if caption.starts_with("OnlineMainView") || caption.starts_with("LockModeView") {
_ = unsafe { GetWindowRect(cwnd, &mut frame) };
let wn_size = frame.bottom - frame.top;
if caption.starts_with("OnlineMainView") || caption.starts_with("LockModeView") {
_ = unsafe { GetWindowRect(cwnd, &mut frame) };
let wn_size = frame.bottom - frame.top;

if wn_size != 0 && kt_size > wn_size + ad_size {
_ = unsafe { SetWindowPos(cwnd, HWND(0), 0, 0, frame.right - frame.left, wn_size + ad_size + 1, SWP_NOZORDER | SWP_NOMOVE) };
}
if wn_size != 0 && kt_size > wn_size + ad_size {
_ = unsafe { SetWindowPos(cwnd, HWND(0), 0, 0, frame.right - frame.left, wn_size + ad_size + 1, SWP_NOZORDER | SWP_NOMOVE) };
}

_ = unsafe { RedrawWindow(cwnd, None, HRGN(0), RDW_INVALIDATE | RDW_UPDATENOW | RDW_ALLCHILDREN) };
} else {
_ = unsafe { ShowWindow(cwnd, SW_HIDE) };
}
}
}
}

0 comments on commit 9e41cab

Please # to comment.