wx消息防撤回插件成品+源码分享

wx消息防撤回插件成品+源码分享

 这个插件源码参考了别的git上的代码,自己测试实现并做成插件,仅供学习交流使用。

 功能概述:自己的消息正常撤回,别人发的消息不撤回。

适用微信版本:7.0.8

1.源码

- (void)onRevokeMsg:(id)arg1{
	/*
		<sysmsg type="revokemsg">
			<revokemsg>
				<session>can-mc</session>
				<msgid>1628803699</msgid>
				<newmsgid>1718130266044544059</newmsgid>
				<replacemsg><![CDATA["Echos Daddy" 撤回了一条消息]]></replacemsg>
				</revokemsg>
		</sysmsg>
	*/
	CMessageWrap * msg = arg1;
	if ([msg.m_nsContent rangeOfString:@"<session>"].location == NSNotFound) { return; }
	if ([msg.m_nsContent rangeOfString:@"<replacemsg>"].location == NSNotFound) { return; }
	NSString *(^parseSession)() = ^NSString *() {
		NSUInteger startIndex = [msg.m_nsContent rangeOfString:@"<session>"].location + @"<session>".length;
		NSUInteger endIndex = [msg.m_nsContent rangeOfString:@"</session>"].location;
		NSRange range = NSMakeRange(startIndex, endIndex - startIndex);
		return [msg.m_nsContent substringWithRange:range];
	};
	NSString *(^parseSenderName)() = ^NSString *() {
	    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"<!\\[CDATA\\[(.*?)撤回了一条消息\\]\\]>" options:NSRegularExpressionCaseInsensitive error:nil];

	    NSRange range = NSMakeRange(0, msg.m_nsContent.length);
	    NSTextCheckingResult *result = [regex matchesInString:msg.m_nsContent options:0 range:range].firstObject;
	    if (result.numberOfRanges < 2) { return nil; }

	    return [msg.m_nsContent substringWithRange:[result rangeAtIndex:1]];
	};
	CMessageWrap *msgWrap = [[%c(CMessageWrap) alloc] initWithMsgType:0x2710];	
	BOOL isSender = [%c(CMessageWrap) isSenderFromMsgWrap:msg];

	NSString *sendContent;
	if (isSender) {
		[msgWrap setM_nsFromUsr:msg.m_nsToUsr];
		[msgWrap setM_nsToUsr:msg.m_nsFromUsr];
		sendContent = @"你撤回一条消息";
		%orig(arg1);
	} else {
		[msgWrap setM_nsToUsr:msg.m_nsToUsr];
		[msgWrap setM_nsFromUsr:msg.m_nsFromUsr];

		NSString *name = parseSenderName();
		sendContent = [NSString stringWithFormat:@"拦截 %@ 的一条撤回消息", name ? name : msg.m_nsFromUsr];
	}
	[msgWrap setM_uiStatus:0x4];
	[msgWrap setM_nsContent:sendContent];
	[msgWrap setM_uiCreateTime:[arg1 m_uiCreateTime]];
	[self AddLocalMsg:parseSession() MsgWrap:msgWrap fixTime:0x1 NewMsgArriveNotify:0x0];
	%log;
}

%end

2.下载安装方式

  1. cydia设置添加源:http://lingo.bichonfrise.cn/cydia
  2. 找到WeChatForbiddenMsgRevoke下载安装即可。
  3. 测试体验,有问题反馈即可。

3.问题反馈

 有任何问题请联系vx:Nicholas_mc

1 Like

试了一下直接编译报错,
> Making all for tweak WeChatWin…

==> Preprocessing Tweak.xm…

Tweak.xm:34: error: %orig does not make sense outside a function

make[3]: *** [/Users/kewong/Desktop/WeChatWin/wechatwin/.theos/obj/debug/armv7/Tweak.xm.mm] Error 255

rm /Users/kewong/Desktop/WeChatWin/wechatwin/.theos/obj/debug/armv7/Tweak.xm.mm

make[2]: *** [/Users/kewong/Desktop/WeChatWin/wechatwin/.theos/obj/debug/armv7/WeChatWin.dylib] Error 2

make[1]: *** [internal-library-all_] Error 2

make: *** [WeChatWin.all.tweak.variables] Error 2

kewong@Ke-MBP-16 wechatwin %