Пример #1
0
  @RequestMapping("/source")
  public void source(
      Model model,
      @RequestParam("id") String jarid,
      @RequestParam("clz") String clazzName,
      @RequestParam(value = "type", required = false, defaultValue = "asmdump") String type) {
    model.addAttribute("clzName", clazzName);
    model.addAttribute("id", jarid);

    if (Database.get(jarid) == null) {
      return;
    }

    FileItem path = (FileItem) Database.get(jarid).getObj();
    model.addAttribute("jarFile", path);
    try {
      JarFile jarFile = new JarFile(path.getFullName());
      String code = "";

      JarEntry entry = jarFile.getJarEntry(clazzName);
      InputStream inputStream = jarFile.getInputStream(entry);

      if (type.equals("asmdump")) {
        code = asmDump(inputStream);
      } else if (type.equals("decomp")) {
        code = jclazzDecomp(clazzName, inputStream);
      }
      model.addAttribute("code", code);
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
Пример #2
0
  @RequestMapping("/view")
  public void view(
      Model model,
      @RequestParam("id") String jar,
      @RequestParam(value = "clz", required = false) String clazzName) {

    clazzName = clazzName != null ? clazzName.replace('.', '/') : null;

    model.addAttribute("clzName", clazzName);
    model.addAttribute("id", jar);

    if (Database.get(jar) == null) {
      return;
    }

    FileItem path = (FileItem) Database.get(jar).getObj();
    try {
      ClassMap classMap =
          ClassMap.build(new JarFile(new File(path.getFullName()).getCanonicalPath()));

      classMap.rebuildConfig(new RenameConfig(), null);

      model.addAttribute("classMap", classMap);
      model.addAttribute("origName", path.getOrigName());

      // to find which package should open
      if (clazzName != null) {
        model.addAttribute("openPkg", classMap.getShortPackage(clazzName));
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Пример #3
0
  @RequestMapping(value = "/script", method = RequestMethod.GET)
  public void script(Model model, @RequestParam("id") String jar) {
    model.addAttribute("id", jar);

    if (Database.get(jar) != null) {
      FileItem path = (FileItem) Database.get(jar).getObj();
      model.addAttribute("jarFile", path);
    }
  }
Пример #4
0
  @RequestMapping("/edit")
  public String editClass(
      Model model,
      @RequestParam("id") String jar,
      @RequestParam("className") String clazzName,
      @RequestParam("newClassName") String newClassName,
      @RequestParam("renameConfig") String renameConfig) {

    if (clazzName != null) {
      clazzName = clazzName.replace('.', '/');
    }
    if (newClassName != null) {
      newClassName = newClassName.replace('.', '/');
    }

    model.addAttribute("clzName", newClassName);
    model.addAttribute("clz", newClassName);
    model.addAttribute("id", jar);

    if (Database.get(jar) == null) {
      return "/jarviewer/view";
    }

    renameConfig = renameConfig.trim();
    renameConfig = "class: " + clazzName + " to " + newClassName + "\n" + renameConfig;

    executeRename(jar, renameConfig);
    return "redirect:/jarviewer/view.htm"; // ?id=" + jar + "&clz=" +
    // newClassName;
  }
  @Override
  public void onClick(View v) {
    if (v == go) {
      if (dest != null) {
        String requestUrl = "http://snarti.nu/?data=package&action=send";
        requestUrl += "&token=" + activeUser.getString("token");
        requestUrl += "&recipient=" + dest.getString("username");

        if (useTrustedCheck.isChecked()) {
          requestUrl += "&usetrust";
        }

        JSONObject result = Database.get(requestUrl);
        if (result != null && result.has("id")) {
          try {
            pkg = UserAuth.buildBundle(result.getJSONObject("package"));
          } catch (Exception e) {
            Log.e("TPDS", e.getMessage());
          }
        } else {
          Log.e("TPDS", "Unable to plan path.");
        }
      }
      if (pkg != null) {
        setResult(PKG_FOUND, new Intent().putExtras(pkg));
      } else {
        setResult(PKG_NOT_FOUND);
      }
      finish();
    }
  }
 @Override
 protected JSONObject queryDatabase(Editable s) {
   String requestUrl = "http://snarti.nu/?data=user&action=get";
   requestUrl += "&token=" + activeUser.getString("token");
   requestUrl += "&target=" + s;
   return Database.get(requestUrl);
 }
Пример #7
0
 @Test
 public void testDeleteBuffer() {
   db.put(new byte[] {1}, new byte[] {1});
   DirectBuffer key = new DirectBuffer(ByteBuffer.allocateDirect(1));
   key.putByte(0, (byte) 1);
   db.delete(key);
   assertNull(db.get(new byte[] {1}));
 }
Пример #8
0
  @RequestMapping(value = "/batch", method = RequestMethod.POST)
  public String batch(
      Model model,
      @RequestParam("id") String jar,
      @RequestParam("renameConfig") String renameConfig) {
    model.addAttribute("id", jar);

    if (Database.get(jar) != null) {
      FileItem path = (FileItem) Database.get(jar).getObj();
      model.addAttribute("jarFile", path);
    }
    if (renameConfig != null && renameConfig.length() > 0) {
      RenameConfig config = executeRename(jar, renameConfig);
      model.addAttribute("renameConfig", config);
    }
    return "/renamer/script";
  }
Пример #9
0
  @RequestMapping(value = "search")
  public String search(
      Model model, @RequestParam("id") String jarid, @RequestParam("q") final String query) {
    model.addAttribute("id", jarid);
    model.addAttribute("query", query);

    if (Database.get(jarid) == null) {
      return null;
    }

    FileItem path = (FileItem) Database.get(jarid).getObj();
    model.addAttribute("jarFile", path);
    try {
      ClassMap classMap =
          ClassMap.build(new JarFile(new File(path.getFullName()).getCanonicalPath()));

      classMap.rebuildConfig(new RenameConfig(), null);

      model.addAttribute("classMap", classMap);

      final Set<String> matches = new TreeSet<String>();
      ClassWalker walker =
          new ClassWalker() {

            @Override
            public void walk(ClassInfo classInfo) {
              if (classInfo.getClassShortName().equals(query)) {
                matches.add(classInfo.getClassName());
              }
            }
          };

      classMap.walk(walker);

      if (matches.size() == 1) {
        model.addAttribute("clz", matches.iterator().next());
        return "redirect:/jarviewer/view.htm";
      }
      model.addAttribute("matches", matches);

    } catch (IOException e) {
      e.printStackTrace();
    }
    return "/jarviewer/search";
  }
Пример #10
0
  @Test
  public void testDrop() {
    byte[] bytes = {1, 2, 3};
    db.put(bytes, bytes);
    byte[] value = db.get(bytes);
    assertArrayEquals(value, bytes);
    // empty
    db.drop(false);
    value = db.get(bytes);
    assertNull(value);
    db.put(bytes, bytes);
    db.drop(true);
    try {
      db.get(bytes);
      fail("db has been closed");
    } catch (LMDBException e) {

    }
  }
 @Override
 public CompletableFuture<Versioned<V>> get(K key) {
   checkNotNull(key, ERROR_NULL_KEY);
   return database
       .get(name, keyCache.getUnchecked(key))
       .thenApply(
           v ->
               v != null
                   ? new Versioned<>(serializer.decode(v.value()), v.version(), v.creationTime())
                   : null);
 }
Пример #12
0
  @Test
  public void testPutAndGetAndDelete() throws Exception {
    k1.putLong(0, 10);
    v1.putLong(0, 11);
    k2.putLong(0, 12);
    v2.putLong(0, 13);

    db.put(k1, v1);
    db.put(k2, v2);

    DirectBuffer k = new DirectBuffer();
    DirectBuffer v = new DirectBuffer();
    k.putLong(0, 10);
    db.get(k, v);
    assertThat(v.getLong(0), is(11L));

    db.delete(k);
    try {
      db.get(k, v);
    } catch (LMDBException e) {
      assertThat(e.errorCode, is(NOTFOUND));
    }
  }
  public static ArrayList<Bundle> getPath(String pathid, String token) {
    String requestUrl = "http://snarti.nu/?data=path&action=get";
    requestUrl += "&token=" + token;
    requestUrl += "&pathid=" + pathid;
    JSONObject result = Database.get(requestUrl);

    if (result != null && result.has("path")) {
      try {
        return makePath(result.getJSONArray("path"));
      } catch (Exception e) {
        Log.e("TPDS", e.getMessage());
      }
    }
    return null;
  }
Пример #14
0
 @RequestMapping(value = "download")
 public View download(@RequestParam("id") String jarid) {
   FileItem path = (FileItem) Database.get(jarid).getObj();
   StreamView view = null;
   try {
     File file = new File(path.getFullName());
     view = new StreamView("application/x-jar", new FileInputStream(file));
     view.setBufferSize(4 * 1024);
     view.setContentDisposition("attachment; filename=\"" + path.getOrigName() + "\"");
   } catch (FileNotFoundException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   return view;
 }
Пример #15
0
  @Test
  public void testReserveCursorRollback() {
    byte[] key = new byte[] {1, 1, 1};
    byte[] val = new byte[] {3, 3, 3};

    Transaction tx = env.createWriteTransaction();
    Cursor cursor = db.openCursor(tx);
    DirectBuffer keyBuf = new DirectBuffer(ByteBuffer.allocateDirect(key.length));
    keyBuf.putBytes(0, key);
    DirectBuffer valBuf = cursor.reserve(keyBuf, val.length);
    valBuf.putBytes(0, val);
    tx.abort();

    byte[] result = db.get(key);
    assertNull(result);
  }
Пример #16
0
  @Test
  public void testReserve() {
    byte[] key = new byte[] {1, 2, 3};
    byte[] val = new byte[] {3, 2, 1};

    try (Transaction tx = env.createWriteTransaction()) {
      DirectBuffer keyBuf = new DirectBuffer(ByteBuffer.allocateDirect(key.length));
      keyBuf.putBytes(0, key);
      DirectBuffer valBuf = db.reserve(tx, keyBuf, val.length);
      valBuf.putBytes(0, val);
      tx.commit();
    }

    try (Transaction tx = env.createReadTransaction()) {
      byte[] result = db.get(tx, key);
      assertArrayEquals(result, val);
    }
  }
Пример #17
0
  private RenameConfig executeRename(String jar, String renameConfig) {
    RenameConfig config = RenameConfig.loadFromString(renameConfig);

    FileItem path = (FileItem) Database.get(jar).getObj();

    String oldjar = path.getFullName();
    String newjar = jar + "_" + path.getVersion();

    File file = new File(Database.getConfig().getUploadPath(), newjar + ".upload");

    String filePath = null;
    try {
      filePath = file.getCanonicalPath();
    } catch (IOException e) {
      e.printStackTrace();
    }
    Renamer.rename(config, oldjar, filePath);
    path.setFulleName(filePath);
    Database.save("changelog-" + jar, Database.Util.nextId(), renameConfig);
    Database.save("file", jar, path);

    return config;
  }
Пример #18
0
  @RequestMapping("/graphdata")
  public View graphdata(
      @RequestParam("id") final String jar,
      @RequestParam(value = "clz", required = false) final String clz,
      @RequestParam(value = "type", required = false) final String type) {
    FileItem path = (FileItem) Database.get(jar).getObj();
    try {
      final ClassMap classMap =
          ClassMap.build(new JarFile(new File(path.getFullName()).getCanonicalPath()));
      classMap.rebuildConfig(new RenameConfig(), null);
      return new View() {

        @Override
        public String getContentType() {
          return "application/json";
          // return "text/plain";
        }

        @Override
        public void render(
            Map<String, ?> model, HttpServletRequest request, HttpServletResponse response)
            throws Exception {
          BufferedWriter writer = new BufferedWriter(response.getWriter());
          Map<String, List<ClassInfo>> tree = classMap.getTree();
          int count = 0;
          Set<String> allObj = new HashSet<String>();
          writer.write("{\"src\":\"");
          ClassInfo clzInfo = classMap.getClassInfo(clz);
          if (clzInfo != null) {
            // partial dep-graph
            if ("mydeps".equals(type)) {
              // deps of clz
              for (String dep : clzInfo.getDependencies()) {
                if (classMap.contains(dep)) {
                  writeDep(writer, clz, dep);
                }
              }
            } else if ("depsonme".equals(type)) {
              // who depends on me ?
              for (Map.Entry<String, List<ClassInfo>> e : tree.entrySet()) {
                for (ClassInfo info : e.getValue()) {
                  if (info.getDependencies().contains(clz)) {
                    writeDep(writer, info.getClassName(), clz);
                  }
                }
              }
            }
            writer.write(clz + " {color:red,link:'/'}");
          } else {
            // all data
            for (Map.Entry<String, List<ClassInfo>> e : tree.entrySet()) {
              writer.write(";" + e.getKey() + "\\n");
              for (ClassInfo clazz : e.getValue()) {
                for (String dep : clazz.getDependencies()) {
                  if (classMap.contains(dep)) {
                    allObj.add(clazz.getClassName());
                    allObj.add(dep);
                    writeDep(writer, clazz.getClassShortName(), Utils.getShortName(dep));
                    count++;
                  }
                }
              }
              writer.write(";// end of package " + e.getKey() + "\\n");
            }
          }
          writer.write("; totally " + count + " edges.\\n");
          // TODO link doesn't work,why?
          // for (String clz : allObj) {
          // writer.write(Utils.getShortName(clz) +
          // " {link:'view.htm?id=" + jar + "&clz=" + clz + "'}\\n");
          // }
          writer.write("\"}\n");
          writer.flush();
          Utils.close(writer);
        }

        private void writeDep(Writer writer, final String src, String dest) throws IOException {
          writer.write(src);
          writer.write(" -> ");
          writer.write(dest);
          writer.write("\\n");
        }
      };
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return null;
  }