Skip to content

Instantly share code, notes, and snippets.

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
/* read 32bit little endian integer */
int read_leint (FILE *in, uint32_t *outint)
{
unsigned char bytes[4];
if (fread(bytes, 4, 1, in) != 1)
return 1;
@wuyongzheng
wuyongzheng / gist:9909031
Created April 1, 2014 06:49
compile error
out/target/common/obj/JAVA_LIBRARIES/android_stubs_current_intermediates/src/PKG/FOO.java:14: cannot find symbol
symbol : constructor BAR(int,android.os.Parcel)
location: class PKG.BAR
public FOO() { super(0,(android.os.Parcel)null); throw new RuntimeException("Stub!"); }
# begin build properties
# autogenerated by buildinfo.sh
ro.build.id=JSS15J
ro.build.display.id=JSS15J.I9505XXUEML1
ro.build.version.incremental=I9505XXUEML1
ro.build.version.sdk=18
ro.build.version.codename=REL
ro.build.version.release=4.3
ro.build.date=Tue Dec 10 14:28:08 KST 2013
ro.build.date.utc=1386653288
@wuyongzheng
wuyongzheng / soot-error
Created May 16, 2014 05:55
soot android framework error
$ git log -1
commit 6ec014ac4b72e309c561f01726c2c7c8e39284be
Author: Steven Arzt <Steven.Arzt@cased.de>
Date: Thu May 15 11:39:04 2014 +0200
Fixed some previously horribly hacky code for parsing annotations. Now it also works with malware samples that do not provide a full InnerClass annotation
$ git diff
diff --git a/src/soot/Scene.java b/src/soot/Scene.java
"Writing an LLVM Backend" http://llvm.org/docs/WritingAnLLVMBackend.html
"llvm commit: Remove the C backend" https://github.com/llvm-mirror/llvm/commit/a443e5b1f1013612950fc3c9ebfafca60a1c20df
"clang commit: Remove the vestiges of the C backend" https://github.com/llvm-mirror/clang/commit/f102c45ed9caf6f0002edb2adb19687e25ec20d3
@wuyongzheng
wuyongzheng / ECDH_BC.java
Last active October 29, 2022 14:44
Elliptic curve Diffie–Hellman using Bouncy Castle v1.50 example code
import java.math.BigInteger;
import java.security.PublicKey;
import java.security.PrivateKey;
import java.security.KeyFactory;
import java.security.Security;
import java.security.KeyPairGenerator;
import java.security.KeyPair;
import java.security.SecureRandom;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.ECGenParameterSpec;
@wuyongzheng
wuyongzheng / gist:b9a9bf4900841c1d4e6d
Last active August 29, 2015 14:03
Problem: re-order correction code
Problem: re-order correction code
You need to send a message through a datagram channel which may reorder
packets. It only reorder packets, but not drop or duplicate packets. You are
asked to design an efficient error correction code that can reliably deliver a
message. Minimal packets should be used. Specifically, you need to design two
functions (Java syntax for illustration purpose):
1. byte[][] encode (byte[] message, int packetSize)
2. byte[] decode (byte[][] packets)
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import javax.crypto.spec.IvParameterSpec;
public class CFBTest
{
final protected static char[] hexArray = "0123456789abcdef".toCharArray();
public static String bytesToHex(byte[] bytes, int offset, int size) {
char[] hexChars = new char[size * 2];
for ( int j = 0; j < size; j++ ) {
@wuyongzheng
wuyongzheng / TestSelect.java
Last active August 29, 2015 14:04
Java Selector behaviour
import java.net.InetSocketAddress;
import java.nio.channels.Selector;
import java.nio.channels.SelectionKey;
import java.nio.channels.SocketChannel;
import java.nio.ByteBuffer;
public class TestSelect
{
public static void main (String [] args) throws Exception
{
/* Discretionary Fair Queue
A DFQ tries to achieve the same criterias as in WFQ:
1. Fairness: equivelent to byte-level round-robin
2. Traffic Shaping: throughput and burst guarantee
Instead of controlling _when_ to send as in WFQ, DFQ decides whether to
send. When a sender wants to send a packet, it first calls
Flow.send(size). DFQ either returns "Yes. You can send now" or "No. Check
with me again after t seconds."
*/