Navigation Menu

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!"); }
@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 / 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."
*/
/* Discretionary Round Robin
A DFQ tries to achieve the same criterias as in a Round Robin Queue
1. No starvation.
2. Traffic Shaping: throughput and burst guarantee
Instead of controlling _when_ to send as in normal traffic shaping queue,
DRR decides whether to send. When a sender wants to send a packet, it first
calls Flow.send(size). DRR either returns "Yes. You can send now" or "No.
Check with me again after t seconds."
*/
#include <stdio.h>
void unlockml (unsigned char *dst, const unsigned char *src,
int size, unsigned int key)
{
static const unsigned char shuf[] = {
0xb, 0xc, 0xa, 0x0,
0x8, 0xf, 0x2, 0x1,
0x6, 0x4, 0x9, 0x3,
0xd, 0x5, 0x7, 0xe};