Skip to content

Instantly share code, notes, and snippets.

@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;
"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 / 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
# 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 / 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!"); }
#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;
public class BinarySearchAlgo
{
/** returns the largest index i such that array[i] &le; needle */
public static int largestMinor (int needle, int [] array)
{
int low = 0, high = array.length - 1;
while (low < high) {
int mid = (low + high + 1) / 2;
if (needle < array[mid])
high = mid - 1;
@wuyongzheng
wuyongzheng / bashhist.c.patch
Last active December 11, 2015 18:38
Log bash commands in another file. Used for my honeypot. Remember to pre-create the file and chown. Better yet, set append-only.
diff --git a/bashhist.c b/bashhist.c
index 7240a5b..63ec12a 100644
--- a/bashhist.c
+++ b/bashhist.c
@@ -792,6 +792,26 @@ static void
really_add_history (line)
char *line;
{
+ static int inited = 0;
+ static FILE *mylogfile = NULL;
@wuyongzheng
wuyongzheng / auth-passwd.c.patch
Created January 11, 2013 14:10
sshd password logging patch make sure sshd_config is set as following: PasswordAuthentication yes UsePAM no
--- auth-passwd.orig 2013-01-11 15:42:09.000000000 +0800
+++ auth-passwd.c 2013-01-11 15:43:47.000000000 +0800
@@ -77,8 +77,8 @@
* Tries to authenticate the user using password. Returns true if
* authentication succeeds.
*/
-int
-auth_password(Authctxt *authctxt, const char *password)
+static int
+auth_password_orig(Authctxt *authctxt, const char *password)
@wuyongzheng
wuyongzheng / gist:3937689
Created October 23, 2012 08:46
Generate 3 uniform random variables that sum to 0
See the question in http://stackoverflow.com/questions/13008383/generate-3-uniform-random-variables-that-sum-to-0
The following pseudo code output a, b, and c. Function rand() returns real number uniformly distributed in (0,1).
s = rand() * 3;
r = rand();
if (s < 1) {
a = r;
b = 1 - 2*r;
c = r - 1;