private String createAMFRequest(String arg0, String arg1) { String data = "0A000000030200"; data += getHexLength(arg0) + JDHexUtils.getHexString(arg0) + "0200"; data += getHexLength(arg1) + JDHexUtils.getHexString(arg1) + "020004706C6179"; return JDHexUtils.toString( "000300000001000F66696C652E617564696F5F696E666F00022F31000000" + getHexLength(JDHexUtils.toString(data)) + data); }
private byte[] createAMFMessage(String... s) { String data = "0003000000010046636f6d2e627269676874636f76652e706c617965722e72756e74696d652e506c617965724d656469614661636164652e66696e644d6564696142795265666572656e6365496400022f3100000"; data += "06" + "50a00000004020028" + JDHexUtils.getHexString(s[0]); // 0x06(String marker) + length + String b data += "00428ad6ca5dbb8800020020"; data += JDHexUtils.getHexString(s[2]); data += "0040f9327000000000"; return JDHexUtils.getByteArray(data); }
@Override public void extract(ExtractionController ctrl) { final Archive archive = getExtractionController().getArchive(); final ArchiveFile firstArchiveFile = archive.getArchiveFiles().get(0); final String matches[] = splitType.getMatches(firstArchiveFile.getName()); if (matches != null) { try { final String fileName; final int skipBytes; final String signature = JDHexUtils.toString( FileSignatures.readFileSignature(new File(firstArchiveFile.getFilePath()))); if (new Regex(signature, "^[\\w]{3} \\d{3}").matches()) { final String extension = new Regex(signature, "^([\\w]{3})").getMatch(0); fileName = matches[0] + "." + extension; skipBytes = 8; } else { skipBytes = 0; fileName = matches[0]; } if (SplitUtil.merge(getExtractionController(), fileName, skipBytes, getConfig())) { archive.setExitCode(ExtractionControllerConstants.EXIT_CODE_SUCCESS); } else { if (archive.getExitCode() == -1) { archive.setExitCode(ExtractionControllerConstants.EXIT_CODE_FATAL_ERROR); } } return; } catch (ExtractionControllerException e) { archive.setExitCode(e.getExitCode()); } catch (IOException e) { archive.setExitCode(ExtractionControllerConstants.EXIT_CODE_FATAL_ERROR); } } else { archive.setExitCode(ExtractionControllerConstants.EXIT_CODE_FATAL_ERROR); } }
public void run() { try { InputStream requestInputStream = Current_Socket.getInputStream(); BufferedInputStream reader = new BufferedInputStream(requestInputStream); String line = null; HashMap<String, String> headers = new HashMap<String, String>(); while ((line = readline(reader)) != null && line.trim().length() > 0) { String key = null; String value = null; if (line.indexOf(": ") > 0) { key = line.substring(0, line.indexOf(": ")).toLowerCase(); value = line.substring(line.indexOf(": ") + 2); } else { key = null; value = line; } headers.put(key, value); } if (headers.containsKey(null)) { String Method = headers.get(null).split(" ")[0]; if (Method.compareToIgnoreCase("get") == 0 || Method.compareToIgnoreCase("post") == 0) { /* get oder post header gefunden */ if (headers.containsKey("content-type")) { if (headers .get("content-type") .compareToIgnoreCase("application/x-www-form-urlencoded") == 0) { if (headers.containsKey("content-length")) { /* * POST Form Daten in GET Format übersetzen, * damit der RequestParams Parser nicht * geändert werden muss */ int post_len = new Integer(headers.get("content-length")); int post_len_toread = post_len; int post_len_read = 0; byte[] cbuf = new byte[post_len]; int indexstart = 0; while (post_len_toread > 0) { if ((post_len_read = reader.read(cbuf, indexstart, post_len_toread)) == -1) { break; } indexstart = indexstart + post_len_read; post_len_toread = post_len_toread - post_len_read; } String RequestParams = new String(cbuf).trim(); if (indexstart == post_len) { /* * alten POST aus Header Liste holen, * neuen zusammenbauen */ String request = headers.get(null); String[] requ = request.split(" "); if (Method.compareToIgnoreCase("post") == 0) { headers.put( null, requ[0] + " " + requ[1] + "?" + RequestParams + " " + requ[2]); } else { logger.severe("POST Daten bei nem GET aufruf???"); } } else { logger.severe( "POST Fehler postlen soll = " + post_len + " postlen gelesen = " + post_len_read); } } } else if (headers.get("content-type").contains("multipart/form-data")) { /* * POST Form Daten in GET Format übersetzen, * damit der RequestParams Parser nicht geändert * werden muss * * Zusätzlich das File auslesen (die komplette * Verarbeiten findet auf Hex statt!!) */ if (headers.containsKey("content-length")) { int post_len = new Integer(headers.get("content-length")); int post_len_toread = post_len; int post_len_read = 0; byte[] cbuf = new byte[post_len]; int indexstart = 0; String limiter = new Regex( headers.get("content-type"), Pattern.compile("boundary=(.*)", Pattern.CASE_INSENSITIVE)) .getMatch(0); if (limiter != null) { /* * nur weitermachen falls ein limiter * vorhanden ist */ limiter = "--" + limiter; limiter = JDHexUtils.getHexString(limiter); while (post_len_toread > 0) { if ((post_len_read = reader.read(cbuf, indexstart, post_len_toread)) == -1) { break; } indexstart = indexstart + post_len_read; post_len_toread = post_len_toread - post_len_read; } if (indexstart == post_len) { String RequestParams = ""; /* * momentan wird multipart nur für * containerupload genutzt, daher * form-data parsing unnötig */ String MultiPartData[][] = new Regex( JDHexUtils.getHexString(cbuf), Pattern.compile( limiter + JDHexUtils.getHexString("\r") + "{0,1}" + JDHexUtils.getHexString("\n") + "{0,1}" + JDHexUtils.REGEX_MATCH_ALL_HEX + "(?=" + "" + JDHexUtils.getHexString("\r") + "{0,1}" + JDHexUtils.getHexString("\n") + "{0,1}" + limiter + ")", Pattern.CASE_INSENSITIVE | Pattern.DOTALL)) .getMatches(); for (String[] element : MultiPartData) { if (element[0].contains( JDHexUtils.getHexString( "Content-Disposition: form-data; name=\"container\""))) { String containertyp = new Regex( element[0], Pattern.compile( JDHexUtils.getHexString("filename=\"") + JDHexUtils.REGEX_FIND_ALL_HEX + JDHexUtils.getHexString(".") + JDHexUtils.REGEX_MATCH_ALL_HEX + JDHexUtils.getHexString("\""), Pattern.CASE_INSENSITIVE)) .getMatch(0); if (containertyp != null) { containertyp = new String(JDHexUtils.getByteArray(containertyp)); } if (containertyp != null && (containertyp.contains("dlc") || containertyp.contains("ccf") || containertyp.contains("rsdf") || containertyp.contains("jdc"))) { File containerfile = JDUtilities.getResourceFile( "container/" + System.currentTimeMillis() + "." + containertyp); if (JDIO.saveToFile( containerfile, JDHexUtils.getByteArray( element[0].substring( element[0].indexOf(JDHexUtils.getHexString("\r\n\r\n")) + 8)))) { /* * RequestParameter * zusammenbauen */ RequestParams = "do=Upload&file=" + Encoding.urlEncode(containerfile.getName()); break; } } else { if (containertyp != null) { logger.severe("unknown container typ: " + containertyp); } } } } /* * alten POST aus Header Liste * holen, neuen zusammenbauen */ String request = headers.get(null); String[] requ = request.split(" "); if (Method.compareToIgnoreCase("post") == 0) { headers.put( null, requ[0] + " " + requ[1] + "?" + RequestParams + " " + requ[2]); } else { logger.severe("POST Daten bei nem GET aufruf???"); } } else { logger.severe( "POST Fehler postlen soll = " + post_len + " postlen gelesen = " + post_len_read); } } } } } JDSimpleWebserverResponseCreator response = new JDSimpleWebserverResponseCreator(); JDSimpleWebserverRequestHandler request = new JDSimpleWebserverRequestHandler(headers, response); OutputStream outputStream = Current_Socket.getOutputStream(); if (NeedAuth == true) { /* need authorization */ if (headers.containsKey("authorization")) { if (JDSimpleWebserver.AuthUser.equals(headers.get("authorization"))) { /* * send authorization granted */ /* logger.info("pass stimmt"); */ request.handle(); } else { /* send authorization failed */ response.setAuth_failed(); } } else { /* send autorization needed */ response.setAuth_needed(); } } else { /* no autorization needed */ request.handle(); } response.writeToStream(outputStream); outputStream.close(); } } else { /* kein get oder post header */ logger.severe("kein post oder get header"); } Current_Socket.close(); } catch (SocketException e) { logger.severe("WebInterface: Socket error"); } catch (IOException e) { logger.severe("WebInterface: I/O Error"); } }
public DummyArchive checkComplete(Archive archive) throws CheckException { if (archive.getSplitType() == splitType) { try { final DummyArchive ret = new DummyArchive(archive, splitType.name()); boolean hasMissingArchiveFiles = false; for (ArchiveFile archiveFile : archive.getArchiveFiles()) { if (archiveFile instanceof MissingArchiveFile) { hasMissingArchiveFiles = true; } ret.add(new DummyArchiveFile(archiveFile)); } if (hasMissingArchiveFiles == false) { final ArchiveFile firstFile = archive.getArchiveFiles().get(0); final String firstArchiveFile = firstFile.getFilePath(); final String partNumberOfFirstArchiveFile = splitType.getPartNumberString(firstArchiveFile); if (splitType.getFirstPartIndex() != splitType.getPartNumber(partNumberOfFirstArchiveFile)) { throw new CheckException( "Wrong firstArchiveFile(" + firstArchiveFile + ") for Archive(" + archive.getName() + ")"); } if (firstFile.exists()) { final String signature = JDHexUtils.toString(FileSignatures.readFileSignature(new File(firstArchiveFile))); if (new Regex(signature, "^[\\w]{3} \\d{3}").matches()) { /** cutkiller header: extension and number of files */ final String numberOfPartsString = new Regex(signature, "^[\\w]{3} (\\d{3})").getMatch(0); final int numberOfParts = Integer.parseInt(numberOfPartsString); final List<ArchiveFile> missingArchiveFiles = SplitType.getMissingArchiveFiles(archive, splitType, numberOfParts); if (missingArchiveFiles != null) { for (ArchiveFile missingArchiveFile : missingArchiveFiles) { ret.add(new DummyArchiveFile(missingArchiveFile)); } } if (ret.getSize() < numberOfParts) { throw new CheckException( "Missing archiveParts(" + numberOfParts + "!=" + ret.getSize() + ") for Archive(" + archive.getName() + ")"); } else if (ret.getSize() > numberOfParts) { throw new CheckException( "Too many archiveParts(" + numberOfParts + "!=" + ret.getSize() + ") for Archive(" + archive.getName() + ")"); } } } } return ret; } catch (CheckException e) { throw e; } catch (Throwable e) { throw new CheckException("Cannot check Archive(" + archive.getName() + ")", e); } } return null; }