Skip to content

Commit

Permalink
show comment content
Browse files Browse the repository at this point in the history
  • Loading branch information
fkzhang committed Jan 28, 2016
1 parent 282529b commit b886a3e
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.fkzhang.wechatunrecalled"
minSdkVersion 16
targetSdkVersion 23
versionCode 4
versionName "1.2.1"
versionCode 5
versionName "1.3"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {

@Override
public void afterTextChanged(Editable s) {
String t = s.toString().trim();
if (TextUtils.isEmpty(t))
return;

settingsHelper.setString("recalled", s.toString());
}
});
Expand All @@ -104,6 +108,10 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {

@Override
public void afterTextChanged(Editable s) {
String t = s.toString().trim();
if (TextUtils.isEmpty(t))
return;

settingsHelper.setString("comment_recall_content", s.toString());
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public class WechatPackageNames {
public String avatarClass;
public String avatarMethod1;
public String avatarMethod2;
public String commentMethod;
public String commentField;
public String commentClass;

public WechatPackageNames(String packageName, String version) {
this.packageName = packageName;
Expand Down Expand Up @@ -67,6 +70,9 @@ private void set600() {
avatarClass += ".p.af";
avatarMethod1 = "uQ";
avatarMethod2 = "b";
commentClass += "aaq";
commentMethod = "m";
commentField = "fWd";
}

private void set635() {
Expand All @@ -88,6 +94,9 @@ private void set635() {
avatarClass += ".p.n";
avatarMethod1 = "vI";
avatarMethod2 = "b";
commentClass += "alx";
commentMethod = "ak";
commentField = "eNp";
}

private void set638() {
Expand All @@ -109,6 +118,9 @@ private void set638() {
avatarClass += ".p.n";
avatarMethod1 = "vF";
avatarMethod2 = "b";
commentClass += "aoq";
commentMethod = "ak";
commentField = "fdy";
}

private void set639() {
Expand All @@ -130,21 +142,34 @@ private void set639() {
avatarClass += ".q.n";
avatarMethod1 = "vi";
avatarMethod2 = "b";
commentClass += "api";
commentMethod = "al";
commentField = "fmw";
}


private void set6311() {
set639();
recallClass += "q";
recallMethod = "J";
snsClass += "h.l";
snsMethod += "h.d";
dbClass1 += "ah";
dbMethod1 = "tD";
dbMethod2 = "rs";
dbField = "bCw";// look for: ah.tD().rs() or in com.tencent.mm.storage.ah
updateMsgId = "aXP";
iconClass = this.packageName + ".aq.a";
contextGetter += "y";
iconClass += ".aq.a";
iconMethod = "aOQ";
imageClass = this.packageName + ".ab.n";
imageClass += ".ab.n";
imageMethod1 = "Ao";
imageMethod2 = "hM";
avatarClass += ".q.n";
avatarMethod1 = "vi";
avatarMethod1 = "vu";
commentClass += "apu";
commentMethod = "am";
commentField = "fsI";
}

private void initNames() {
Expand All @@ -166,5 +191,8 @@ private void initNames() {
avatarClass = this.packageName;
avatarMethod1 = "";
avatarMethod2 = "";
commentClass = this.packageName + ".protocal.b.";
commentMethod = "";
commentField = "";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class WechatUnrecalledHook {
protected Class<?> mAvatarLoader;
protected HashMap<String, Bitmap> mAvatarCache;
protected HashMap<String, String> mNicknameCache;
protected Class<?> mCommentClass;

public WechatUnrecalledHook(WechatPackageNames packageNames) {
this.mP = packageNames;
Expand Down Expand Up @@ -130,6 +131,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
super.afterHookedMethod(param);
mSettings.reload();
if (!mSettings.getBoolean("enable_new_comment_notification", false))
return;

Expand All @@ -140,9 +142,9 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable {
ContentValues v = (ContentValues) param.args[2];
String talker = (String) v.get("talker");
Bitmap icon = getAccountAvatar(talker);
String name = getNickname(talker);
String content = mSettings.getString("new_comment", "New comment");
showTextNotification(name, content, icon);
String name = getNickname(talker) + " " + mSettings.getString("new_comment", "(New comment)");
String content = getCommentContent(v.getAsByteArray("curActionBuf"));
showCommentNotification(name, content, icon);
}
});
}
Expand Down Expand Up @@ -180,7 +182,7 @@ protected void preventMsgRecall(XC_MethodHook.MethodHookParam param) {
return;

if (mSettings.getBoolean("enable_recall_notification", true)) {
String content = cursor.getString(cursor.getColumnIndex("content"));
String content = cursor.getString(cursor.getColumnIndex("content")).trim();
Bitmap icon = getAccountAvatar(talker);
int t = cursor.getInt(cursor.getColumnIndex("type"));
switch (t) {
Expand Down Expand Up @@ -215,8 +217,8 @@ protected void preventMsgRecall(XC_MethodHook.MethodHookParam param) {
}

long createTime = cursor.getLong(cursor.getColumnIndex("createTime"));
insertMessage(talker, replacemsg, createTime + 1);
cursor.close();
insertMessage(talker, replacemsg, createTime + 1);
}

protected void unRecallSnsComments(Object SQL) {
Expand All @@ -240,6 +242,7 @@ public void preventCommentRecall(XC_MethodHook.MethodHookParam param) {
String table = (String) param.args[0];
if (!table.equalsIgnoreCase("snscomment"))
return;
mSettings.reload();

ContentValues v = (ContentValues) param.args[1];
if (v.containsKey("commentflag") && v.getAsInteger("commentflag") == 1) {
Expand All @@ -249,12 +252,11 @@ public void preventCommentRecall(XC_MethodHook.MethodHookParam param) {

String talker = v.getAsString("talker");
Bitmap icon = getAccountAvatar(talker);
String name = getNickname(talker);
String name = getNickname(talker) + " " +
mSettings.getString("comment_recall_content", "comment_recall_content");
String content = getCommentContent(v.getAsByteArray("curActionBuf"));

mSettings.reload();
String content = mSettings.getString("comment_recall_content",
"tried to delete a comment");
showTextNotification(name, content, icon);
showCommentNotification(name, content, icon);
}
}

Expand Down Expand Up @@ -345,6 +347,24 @@ protected void showTextNotification(String title, String content, Bitmap icon) {
showNotification(builder, resultIntent);
}

protected void showCommentNotification(String title, String content, Bitmap icon) {
if (TextUtils.isEmpty(content))
return;

Notification.Builder builder = new Notification.Builder(mNotificationContext)
.setLargeIcon(icon)
.setSmallIcon(mNotificationIcon)
.setContentTitle(title)
.setAutoCancel(true)
.setContentText(content);

Intent resultIntent = new Intent();
resultIntent.setClassName(mNotificationContext.getPackageName(),
mP.packageName + ".plugin.sns.ui.SnsMsgUI");

showNotification(builder, resultIntent);
}

protected void showImageNotification(String title, Bitmap bitmap, Intent resultIntent,
String summary, Bitmap icon) {
Notification.Builder builder = new Notification.Builder(mNotificationContext)
Expand All @@ -356,6 +376,8 @@ protected void showImageNotification(String title, Bitmap bitmap, Intent resultI
if (bitmap != null) {
builder.setStyle(new Notification.BigPictureStyle()
.bigPicture(bitmap).setSummaryText(summary));
} else {
builder.setContentText(summary);
}

resultIntent.setClassName(mNotificationContext.getPackageName(),
Expand Down Expand Up @@ -401,6 +423,8 @@ public void initNotification(ClassLoader loader) {
findClass(mP.iconClass, loader), mP.iconMethod);
mNotificationLargeIcon = BitmapFactory.decodeResource(mNotificationContext
.getResources(), mNotificationContext.getApplicationInfo().icon);
// look for: curActionBuf
mCommentClass = findClass(mP.commentClass, loader);
}

protected Bitmap getImage(String path) {
Expand Down Expand Up @@ -434,7 +458,7 @@ protected Bitmap getAccountAvatar(String accountName) {
mAvatarCache.put(accountName, avatar);
}
} catch (Throwable t) {
// XposedBridge.log(t);
XposedBridge.log(t);
}
if (avatar == null) {
avatar = mNotificationLargeIcon;
Expand All @@ -458,15 +482,22 @@ protected String getNickname(String username) {
}

Cursor cursor = getContact(username);
if (cursor != null && cursor.moveToFirst()) {
String name = cursor.getString(cursor.getColumnIndex("conRemark"));
if (TextUtils.isEmpty(name)) {
name = cursor.getString(cursor.getColumnIndex("nickname"));
}
cursor.close();
mNicknameCache.put(username, name);
return name;
if (cursor == null || !cursor.moveToFirst())
return username;

String name = cursor.getString(cursor.getColumnIndex("conRemark"));
if (TextUtils.isEmpty(name)) {
name = cursor.getString(cursor.getColumnIndex("nickname"));
}
return username;
cursor.close();
mNicknameCache.put(username, name);
return name;
}


public String getCommentContent(byte[] blob) {
Object o = callMethod(XposedHelpers.newInstance(mCommentClass), mP.commentMethod,
new Class[]{byte[].class}, blob);
return (String) getObjectField(o, mP.commentField);
}
}
2 changes: 1 addition & 1 deletion app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
<string name="comment_recalled_message">评论删除消息</string>
<string name="enable_notification">开启消息撤回通知</string>
<string name="enable_comment_recall_notification">开启评论删除通知</string>
<string name="new_comment">新评论</string>
<string name="new_comment">(新评论)</string>
<string name="enable_new_comment_notification">开启新评论通知</string>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
<string name="comment_recalled_message">comment recalled message</string>
<string name="comment_recall_content">tried to delete a comment</string>
<string name="enable_comment_recall_notification">Enable comment recall notification</string>
<string name="new_comment">New comment</string>
<string name="new_comment">(New comment)</string>
<string name="enable_new_comment_notification">Enable new comment notification</string>
</resources>

0 comments on commit b886a3e

Please sign in to comment.