Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #310 from whitechi73/kritor
Browse files Browse the repository at this point in the history
kritorをmasterブランチに設定する
  • Loading branch information
whitechi73 authored Mar 21, 2024
2 parents 680317d + d66358a commit 0faada7
Show file tree
Hide file tree
Showing 119 changed files with 11,778 additions and 156 deletions.
1 change: 1 addition & 0 deletions kritor
Submodule kritor added at e4aac6
2 changes: 1 addition & 1 deletion processor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dependencies {
implementation("com.google.devtools.ksp:symbol-processing-api:1.9.21-1.0.15")
implementation("com.squareup:kotlinpoet:1.14.2")

implementation(DEPENDENCY_PROTOBUF)
//implementation(DEPENDENCY_PROTOBUF)
implementation(kotlinx("serialization-protobuf", "1.6.2"))

ksp("dev.zacsweers.autoservice:auto-service-ksp:1.1.0")
Expand Down
95 changes: 95 additions & 0 deletions processor/src/main/java/moe/fuqiuluo/ksp/impl/GrpcProcessor.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
@file:Suppress("UNCHECKED_CAST")
@file:OptIn(KspExperimental::class)

package moe.fuqiuluo.ksp.impl

import com.google.devtools.ksp.KspExperimental
import com.google.devtools.ksp.getAnnotationsByType
import com.google.devtools.ksp.getClassDeclarationByName
import com.google.devtools.ksp.getJavaClassByName
import com.google.devtools.ksp.getKotlinClassByName
import com.google.devtools.ksp.processing.CodeGenerator
import com.google.devtools.ksp.processing.Dependencies
import com.google.devtools.ksp.processing.KSPLogger
import com.google.devtools.ksp.processing.Resolver
import com.google.devtools.ksp.processing.SymbolProcessor
import com.google.devtools.ksp.symbol.KSAnnotated
import com.google.devtools.ksp.symbol.KSClassDeclaration
import com.google.devtools.ksp.symbol.KSDeclaration
import com.google.devtools.ksp.symbol.KSFunctionDeclaration
import com.google.devtools.ksp.symbol.KSType
import com.google.devtools.ksp.symbol.KSTypeParameter
import com.google.devtools.ksp.symbol.Modifier
import com.google.devtools.ksp.validate
import com.squareup.kotlinpoet.FileSpec
import com.squareup.kotlinpoet.FunSpec
import com.squareup.kotlinpoet.KModifier
import kritor.service.Grpc

class GrpcProcessor(
private val codeGenerator: CodeGenerator,
private val logger: KSPLogger
): SymbolProcessor {
override fun process(resolver: Resolver): List<KSAnnotated> {
val symbols = resolver.getSymbolsWithAnnotation(Grpc::class.qualifiedName!!)
val actions = (symbols as Sequence<KSFunctionDeclaration>).toList()

if (actions.isEmpty()) return emptyList()

// 怎么返回nullable的结果
val packageName = "kritor.handlers"
val funcBuilder = FunSpec.builder("handleGrpc")
.addModifiers(KModifier.SUSPEND)
.addParameter("cmd", String::class)
.addParameter("data", ByteArray::class)
.returns(ByteArray::class)
val fileSpec = FileSpec.scriptBuilder("AutoGrpcHandlers", packageName)

logger.warn("Found ${actions.size} grpc-actions")

//logger.error(resolver.getClassDeclarationByName("io.kritor.AuthReq").toString())
//logger.error(resolver.getJavaClassByName("io.kritor.AuthReq").toString())
//logger.error(resolver.getKotlinClassByName("io.kritor.AuthReq").toString())

actions.forEach { action ->
val methodName = action.qualifiedName?.asString()!!
val grpcMethod = action.getAnnotationsByType(Grpc::class).first()
val service = grpcMethod.serviceName
val funcName = grpcMethod.funcName
funcBuilder.addStatement("if (cmd == \"${service}.${funcName}\") {\t")

val reqType = action.parameters[0].type.toString()
val rspType = action.returnType.toString()
funcBuilder.addStatement("val resp: $rspType = $methodName($reqType.parseFrom(data))")
funcBuilder.addStatement("return resp.toByteArray()")

funcBuilder.addStatement("}")
}
funcBuilder.addStatement("return EMPTY_BYTE_ARRAY")
fileSpec
.addStatement("import io.kritor.*")
.addStatement("import io.kritor.core.*")
.addStatement("import io.kritor.contact.*")
.addStatement("import io.kritor.group.*")
.addStatement("import io.kritor.friend.*")
.addStatement("import io.kritor.file.*")
.addStatement("import io.kritor.message.*")
.addStatement("import io.kritor.web.*")
.addStatement("import io.kritor.developer.*")
.addFunction(funcBuilder.build())
.addImport("moe.fuqiuluo.symbols", "EMPTY_BYTE_ARRAY")
runCatching {
codeGenerator.createNewFile(
dependencies = Dependencies(aggregating = false),
packageName = packageName,
fileName = fileSpec.name
).use { outputStream ->
outputStream.writer().use {
fileSpec.build().writeTo(it)
}
}
}

return emptyList()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class ProtobufProcessor(
}.toList()

if (actions.isNotEmpty()) {
actions.forEachIndexed { index, clz ->
actions.forEachIndexed { _, clz ->
if (clz.isInternal()) return@forEachIndexed
if (clz.isPrivate()) return@forEachIndexed

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@file:Suppress("UNCHECKED_CAST", "LocalVariableName", "PrivatePropertyName")
@file:OptIn(KspExperimental::class)
@file:OptIn(KspExperimental::class, KspExperimental::class)

package moe.fuqiuluo.ksp.impl

Expand Down Expand Up @@ -27,10 +27,14 @@ class XposedHookProcessor(
private val logger: KSPLogger
): SymbolProcessor {
override fun process(resolver: Resolver): List<KSAnnotated> {
val symbols = resolver.getSymbolsWithAnnotation(XposedHook::class.qualifiedName!!)
val symbols = resolver.getSymbolsWithAnnotation(
annotationName = XposedHook::class.qualifiedName!!,
inDepth = true
)
logger.warn("Found ${symbols.count()} classes annotated with XposedHook")
val unableToProcess = symbols.filterNot { it.validate() }
val actions = (symbols.filter {
it is KSClassDeclaration && it.validate() && it.classKind == ClassKind.CLASS
it is KSClassDeclaration && it.classKind == ClassKind.CLASS
} as Sequence<KSClassDeclaration>).toList()

if (actions.isNotEmpty()) {
Expand All @@ -46,7 +50,7 @@ class XposedHookProcessor(
}

val context = ClassName("android.content", "Context")
val packageName = "moe.fuqiuluo.shamrock.xposed.hooks"
val packageName = "moe.fuqiuluo.shamrock.xposed.actions"
val fileSpec = FileSpec.builder(packageName, "AutoActionLoader").addFunction(FunSpec.builder("runFirstActions")
.addParameter("ctx", context)
.apply {
Expand Down Expand Up @@ -96,16 +100,6 @@ class XposedHookProcessor(
}
}
}

return unableToProcess.toList()
}

inner class ActionLoaderVisitor(
private val firstActions: List<KSClassDeclaration>,
private val serviceActions: List<KSClassDeclaration>,
): KSVisitorVoid() {
override fun visitClassDeclaration(classDeclaration: KSClassDeclaration, data: Unit) {

}
}
}
17 changes: 17 additions & 0 deletions processor/src/main/java/moe/fuqiuluo/ksp/providers/GrpcProvider.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package moe.fuqiuluo.ksp.providers

import com.google.auto.service.AutoService
import com.google.devtools.ksp.processing.SymbolProcessor
import com.google.devtools.ksp.processing.SymbolProcessorEnvironment
import com.google.devtools.ksp.processing.SymbolProcessorProvider
import moe.fuqiuluo.ksp.impl.GrpcProcessor

@AutoService(SymbolProcessorProvider::class)
class GrpcProvider: SymbolProcessorProvider {
override fun create(environment: SymbolProcessorEnvironment): SymbolProcessor {
return GrpcProcessor(
environment.codeGenerator,
environment.logger
)
}
}
4 changes: 2 additions & 2 deletions protobuf/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ android {
}

dependencies {
implementation(DEPENDENCY_PROTOBUF)
//implementation(DEPENDENCY_PROTOBUF)
implementation(kotlinx("serialization-protobuf", "1.6.2"))
implementation(kotlinx("serialization-json", "1.6.2"))

Expand All @@ -47,5 +47,5 @@ dependencies {
}

tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn"
kotlinOptions.freeCompilerArgs += "-opt-in=kotlin.RequiresOptIn"
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
@file:OptIn(ExperimentalSerializationApi::class)
package protobuf.oidb.cmd0x11c5

import com.google.protobuf.Internal.EMPTY_BYTE_ARRAY
import moe.fuqiuluo.symbols.EMPTY_BYTE_ARRAY
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.Serializable
import kotlinx.serialization.protobuf.ProtoNumber
import moe.fuqiuluo.symbols.Protobuf

@Serializable
data class NtV2RichMediaRsp(
@ProtoNumber(1) val head: RspHead,
@ProtoNumber(1) val head: RspHead?,
@ProtoNumber(2) val upload: UploadRsp?,
@ProtoNumber(3) val download: DownloadRsp?,
@ProtoNumber(4) val downloadRkeyRsp: DownloadRkeyRsp?,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package protobuf.oidb.cmd0x388

import com.google.protobuf.Internal.EMPTY_BYTE_ARRAY
import moe.fuqiuluo.symbols.EMPTY_BYTE_ARRAY
import kotlinx.serialization.Serializable
import kotlinx.serialization.protobuf.ProtoNumber
import moe.fuqiuluo.symbols.Protobuf
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

package protobuf.oidb.cmd0x388

import com.google.protobuf.Internal.EMPTY_BYTE_ARRAY
import moe.fuqiuluo.symbols.EMPTY_BYTE_ARRAY
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.Serializable
import kotlinx.serialization.protobuf.ProtoNumber
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@
import com.tencent.mobileqq.app.MessageHandler;
import com.tencent.qphone.base.remote.ToServiceMsg;

import java.util.concurrent.ConcurrentHashMap;

import mqq.app.AppRuntime;

public abstract class AppInterface extends AppRuntime {
private final ConcurrentHashMap<String, BusinessHandler> allHandler = new ConcurrentHashMap<>();

public String getCurrentNickname() {
return "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ public ToServiceMsg createToServiceMsg(String cmd) {
return null;
}

public void addBusinessObserver(ToServiceMsg toServiceMsg, BusinessObserver businessObserver, boolean z) {

}

public final <T> T decodePacket(byte[] data, String name, T obj) {
UniPacket uniPacket = new UniPacket(true);
try {
Expand All @@ -24,6 +28,10 @@ public final <T> T decodePacket(byte[] data, String name, T obj) {
}
}

public boolean msgCmdFilter(String str) {
return false;
}

protected abstract Set<String> getCommandList();

protected abstract Set<String> getPushCommandList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ public abstract class BusinessHandler extends BaseBusinessHandler {
public BusinessHandler(AppInterface appInterface) {
}

protected abstract Class<? extends BusinessObserver> observerClass();

@Override
public Set<String> getCommandList() {
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.tencent.mobileqq.msf.sdk;

import com.tencent.qphone.base.remote.FromServiceMsg;
import com.tencent.qphone.base.remote.ToServiceMsg;

public class MsfMessagePair {
public FromServiceMsg fromServiceMsg;
public String sendProcess;
public ToServiceMsg toServiceMsg;

public MsfMessagePair(String str, ToServiceMsg toServiceMsg, FromServiceMsg fromServiceMsg) {

}

public MsfMessagePair(ToServiceMsg toServiceMsg, FromServiceMsg fromServiceMsg) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ void getRichMediaElement(@NotNull RichMediaElementGetReq req) {
public void addMsgListener(IKernelMsgListener listener) {
}

public void removeMsgListener(@NotNull IKernelMsgListener iKernelMsgListener) {

}


public String getRichMediaFilePathForGuild(@NotNull RichMediaFilePathInfo richMediaFilePathInfo) {
return null;
}
Expand Down
7 changes: 7 additions & 0 deletions qqinterface/src/main/java/mqq/app/AppRuntime.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ public int getValue() {
}
}

public MobileQQ getApplication() {
return null;
}

public void startServlet(NewIntent newIntent) {
}

public <T extends IRuntimeService> T getRuntimeService(Class<T> cls, String namespace) {
throw new UnsupportedOperationException();
}
Expand Down
29 changes: 29 additions & 0 deletions qqinterface/src/main/java/mqq/app/NewIntent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package mqq.app;

import android.content.Context;
import android.content.Intent;

import com.tencent.mobileqq.app.BusinessObserver;

public class NewIntent extends Intent {
public boolean runNow;

public NewIntent(Context context, Class<? extends Servlet> cls) {
super(context, cls);
}

public BusinessObserver getObserver() {
return null;
}

public boolean isWithouLogin() {
return false;
}

public void setObserver(BusinessObserver businessObserver) {

}

public void setWithouLogin(boolean z) {
}
}
3 changes: 3 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ include(
include(":protobuf")
include(":processor")
include(":annotations")
include(":kritor")

project(":kritor").projectDir = file("kritor/protos")
Loading

0 comments on commit 0faada7

Please sign in to comment.