private static void testCausedFocusEventDeserialization() throws Exception { for (int i = 0; i < causesIn.length; i++) { final String causeIn = causesIn[i]; ObjectInputStream oi = new ObjectInputStream(new InputStream() { int cnt = 0; @Override public int read() throws IOException { if(cnt < data.length) { return data[cnt++]; } else if(cnt == data.length){ cnt++; return causeIn.length(); } else if(cnt - data.length - 1 < causeIn.length()) { return causeIn.getBytes()[cnt++ - data.length - 1]; } return -1; } }); FocusEvent ev = (FocusEvent) oi.readObject(); System.out.println(ev); if(ev.getCause() != causesOut[i]) { throw new RuntimeException("Wrong cause read :" +ev.getCause()); } } }
static void gcm_suppressUnreadCorrupt() throws Exception { Cipher c; byte[] read = new byte[200]; System.out.println("Running supressUnreadCorrupt test"); // Encrypt 100 bytes with AES/GCM/PKCS5Padding byte[] ct = encryptedText("GCM", 100); // Corrupt the encrypted message ct = corruptGCM(ct); // Create stream for decryption CipherInputStream in = getStream("GCM", ct); try { in.close(); System.out.println(" Pass."); } catch (IOException e) { System.out.println(" Fail: " + e.getMessage()); throw new RuntimeException(e.getCause()); } }
static void gcm_oneReadByte() throws Exception { System.out.println("Running gcm_oneReadByte test"); // Encrypt 100 bytes with AES/GCM/PKCS5Padding byte[] ct = encryptedText("GCM", 100); // Create stream for decryption CipherInputStream in = getStream("GCM", ct); try { in.read(); System.out.println(" Pass."); } catch (Exception e) { System.out.println(" Fail: " + e.getMessage()); throw new RuntimeException(e.getCause()); } }
static void gcm_oneReadByteCorrupt() throws Exception { System.out.println("Running gcm_oneReadByteCorrupt test"); // Encrypt 100 bytes with AES/GCM/PKCS5Padding byte[] ct = encryptedText("GCM", 100); // Corrupt the encrypted message ct = corruptGCM(ct); // Create stream for decryption CipherInputStream in = getStream("GCM", ct); try { in.read(); System.out.println(" Fail. No exception thrown."); } catch (IOException e) { Throwable ec = e.getCause(); if (ec instanceof AEADBadTagException) { System.out.println(" Pass."); } else { System.out.println(" Fail: " + ec.getMessage()); throw new RuntimeException(ec); } } }
static void cbc_shortStream() throws Exception { Cipher c; AlgorithmParameters params; byte[] read = new byte[200]; System.out.println("Running cbc_shortStream"); // Encrypt 97 byte with AES/CBC/PKCS5Padding byte[] ct = encryptedText("CBC", 97); // Create stream with only 96 bytes of encrypted data CipherInputStream in = getStream("CBC", ct, 96); try { int size = in.read(read); in.close(); if (size != 80) { throw new RuntimeException("Fail: CipherInputStream.read() " + "returned " + size + ". Should have been 80"); } System.out.println(" Pass."); } catch (IOException e) { System.out.println(" Fail: " + e.getMessage()); throw new RuntimeException(e.getCause()); } }
static void cbc_shortRead400() throws Exception { System.out.println("Running cbc_shortRead400"); // Encrypt 400 byte with AES/CBC/PKCS5Padding byte[] ct = encryptedText("CBC", 400); // Create stream with encrypted data CipherInputStream in = getStream("CBC", ct); try { in.read(); in.close(); System.out.println(" Pass."); } catch (IOException e) { System.out.println(" Fail: " + e.getMessage()); throw new RuntimeException(e.getCause()); } }
static void cbc_shortRead600() throws Exception { System.out.println("Running cbc_shortRead600"); // Encrypt 600 byte with AES/CBC/PKCS5Padding byte[] ct = encryptedText("CBC", 600); // Create stream with encrypted data CipherInputStream in = getStream("CBC", ct); try { in.read(); in.close(); System.out.println(" Pass."); } catch (IOException e) { System.out.println(" Fail: " + e.getMessage()); throw new RuntimeException(e.getCause()); } }
public static void main(String argv[]) throws InterruptedException, RuntimeException { if (argv.length == 1 && argv[0].equals("buildagent")) { buildAgent(); return; } if (inst == null) { throw new RuntimeException("Instrumentation object was null"); } new Thread() { public void run() { runTest(); } }.start(); // Test that NCDFE is not thrown for anonymous class: // ModifyAnonymous$InstanceMethodCallSiteApp$$Lambda$18 try { ModifyAnonymous test = new ModifyAnonymous(); InstanceMethodCallSiteApp.test(); } catch (NoClassDefFoundError e) { throw new RuntimeException("FAILED: NoClassDefFoundError thrown for " + e.getMessage()); } System.out.println("PASSED: NoClassDefFound error not thrown"); }
private static void testFocusEventDeserialization() throws Exception { ObjectInputStream oi = new ObjectInputStream( new ByteArrayInputStream(dataOld)); FocusEvent ev = (FocusEvent)oi.readObject(); if(ev.getCause() != FocusEvent.Cause.UNKNOWN) { throw new RuntimeException("Wrong cause in deserialized FocusEvent " + ev.getCause()); } }
public static byte[] enc(Object obj) { try { ByteArrayOutputStream bout; bout = new ByteArrayOutputStream(); new ObjectOutputStream(bout).writeObject(obj); byte[] data = bout.toByteArray(); for (int i = 0; i < data.length - 5; i++) { if (data[i] == 'j' && data[i + 1] == 'j' && data[i + 2] == 'j' && data[i + 3] == 'j' && data[i + 4] == 'j') { System.arraycopy("javax".getBytes(), 0, data, i, 5); } } return data; } catch (Exception e) { throw new RuntimeException(e); } }
public Capstone(int arch, int mode) { cs = (CS)Native.loadLibrary("capstone", CS.class); int version = cs.cs_version(null, null); if (version != (CS_API_MAJOR << 8) + CS_API_MINOR) { throw new RuntimeException("Different API version between core & binding (CS_ERR_VERSION)"); } this.arch = arch; this.mode = mode; ns = new NativeStruct(); ns.handleRef = new NativeLongByReference(); if (cs.cs_open(arch, mode, ns.handleRef) != CS_ERR_OK) { throw new RuntimeException("ERROR: Wrong arch or mode"); } ns.csh = ns.handleRef.getValue(); this.detail = CS_OPT_OFF; this.diet = cs.cs_support(CS_SUPPORT_DIET); }
public Object invoke(Object reader, Object firstChar, Object opts, Object pendingForms){ PushbackReader r = (PushbackReader) reader; pendingForms = ensurePending(pendingForms); Object name = read(r, true, null, false, opts, pendingForms); if (!(name instanceof Symbol)) throw new RuntimeException("Reader tag must be a symbol"); Symbol sym = (Symbol)name; Object form = read(r, true, null, true, opts, pendingForms); if(isPreserveReadCond(opts) || RT.suppressRead()) { return TaggedLiteral.create(sym, form); } else { return sym.getName().contains(".") ? readRecord(form, sym, opts, pendingForms) : readTagged(form, sym, opts, pendingForms); } }
private Object readTagged(Object o, Symbol tag, Object opts, Object pendingForms){ ILookup data_readers = (ILookup)RT.DATA_READERS.deref(); IFn data_reader = (IFn)RT.get(data_readers, tag); if(data_reader == null){ data_readers = (ILookup)RT.DEFAULT_DATA_READERS.deref(); data_reader = (IFn)RT.get(data_readers, tag); if(data_reader == null){ IFn default_reader = (IFn)RT.DEFAULT_DATA_READER_FN.deref(); if(default_reader != null) return default_reader.invoke(tag, o); else throw new RuntimeException("No reader function for tag " + tag.toString()); } } return data_reader.invoke(o); }