Skip to content

Instantly share code, notes, and snippets.

View xunge's full-sized avatar
🎯
Focusing

xunge xunge

🎯
Focusing
View GitHub Profile
@xunge
xunge / anaconda_sync.py
Created July 6, 2019 12:17
anaconda同步文件
#!/usr/bin/env python3
import os
import json
import hashlib
import tempfile
import shutil
import logging
import subprocess as sp
from pathlib import Path
from email.utils import parsedate_to_datetime
@xunge
xunge / pytorch_imagenet.py
Last active July 20, 2022 14:15
using pytorch to train and validate imagenet dataset
import time
import shutil
import os
import torch
import torch.nn as nn
import torchvision.datasets as datasets
import torchvision.transforms as transforms
import torchvision.models as models
import torch.backends.cudnn as cudnn
@xunge
xunge / multiprocessing_db.py
Created June 10, 2022 07:04
multiprocessing demo for select sqlite db.
import sqlite3
import multiprocessing as mp
from itertools import repeat
def build_db(db_name):
conn = sqlite3.connect(db_name)
cursor = conn.cursor()
cursor.execute('''CREATE TABLE IF NOT EXISTS EMPLOYEE (
ID INTEGER PRIMARY KEY,
@xunge
xunge / vuzzer64_angr_bb_weight.py
Last active April 6, 2022 02:01
vuzzer64 angr bb weight
# Copyright (C) 2017
#
# Written by Ashley Lesdalons <ashley.lesdalons@etu.univ-grenoble-alpes.fr>
#
# ========LICENCE========
# This script is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
@xunge
xunge / vuzzer64_ida_bb_weight.py
Created April 6, 2022 01:58
vuzzer64 ida bb weight
# -----------------------------------------------------------------------
# This script computes a weight value for each basis block of each functions. the algorithm is:
# 1. for each outgoing edge (i->j) of a BB i, assign a equal probability Eij, i.e. Eij= 1/n for a "n edges" BB.
# 2. assign root BB a weight of 1 (this is always reachable).
# 3. for each BB j, its weight is: W(j) = SUM (over i \in Pred(j)) W(i)*Eij
# after completion, it creates a pickle file that contains weights of BBs.
##Addintion: it also scans each function to find CMD instruction and check if it has some byte to compare with. All such bytes are saved in a pickle file that will be used to mutate inputs.
import idaapi
@xunge
xunge / vuzzer64_ghidra_bb_weight.py
Created April 6, 2022 01:57
vuzzer64 ghidra bb weight
#TODO This script performs the static analysis part of VUzzer. For a given binary, it computes a weight of each basic block of each function. It also extracts immediates from each CMP instruction.
#@author: Sanjay Rawat
#@category: VUzzer Static Analysis
#@keybinding
#@menupath tools.Static Analysis.VUzzer
#@toolbar
#TODO Add User Code Here
#from ghidra.program.model.block import *
@xunge
xunge / train_tokenizer_whitespace.py
Last active December 8, 2021 11:08
Whitespace tokenizer for training Roberta from scratch
from tokenizers import Tokenizer
from tokenizers.models import WordLevel
from tokenizers.trainers import WordLevelTrainer
from tokenizers.pre_tokenizers import WhitespaceSplit
from tokenizers.processors import RobertaProcessing
from model.roberta import RobertaTokenizerFast
SPECIAL_TOKENS = ["<s>", "<pad>", "</s>", "<unk>", "<mask>"]
UNK_TOKENS = "<unk>"
@xunge
xunge / deep_feedforward_networks_03.py
Last active July 3, 2019 01:45
定义单隐藏层前馈网络模型的训练样本X和Y、定义输入x,输出y,隐藏层参数分别定义为w1和b1,隐藏层的激活函数选取ReLU;输出层参数为w2,b2,输出层激活函数选取sigmoid。定义深度前馈网络模型输出out,定义损失函数为均方差损失函数loss,并且使用Adam算法的Optimizer
import tensorflow as tf
# 输入训练数据,这里是python的list, 也可以定义为numpy的ndarray
x_data = [[1., 0.], [0., 1.], [0., 0.], [1., 1.]]
x = tf.placeholder(tf.float32, shape=[None, 2]) # 定义占位符,占位符在运行图的时候必须feed数据
y_data = [[1], [1], [0], [0]] # 训练数据的标签,注意维度
y = tf.placeholder(tf.float32, shape=[None, 1])
# 定义variables,在运行图的过程中会被按照优化目标改变和保存
weights = {'w1': tf.Variable(tf.random_normal([2, 16])),
'w2': tf.Variable(tf.random_normal([16, 1]))}
@xunge
xunge / deep_feedforward_networks_02.py
Last active July 3, 2019 01:39
线性回归的训练过程
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
for i in range(1000):
for j in range(4):
sess.run(train, feed_dict={x: np.expand_dims(X[j], 0), y: np.expand_dims(Y[j], 0)})
loss_ = sess.run(loss, feed_dict={x: X, y: Y})
print("step: %d, loss: %.3f" % (i, loss_))
print("X: %r" % X)
print("pred: %r" % sess.run(out, feed_dict={x: X}))
@xunge
xunge / deep_feedforward_networks_01.py
Last active July 2, 2019 01:03
定义训练样本X和Y、定义输入x,输出y,定义权重w和偏置b,定义线性回归输出out,定义损失函数为均方差损失函数loss,并且使用Adam算法的Optimizer
import tensorflow as tf
import numpy as np
X = np.array([[0, 0], [0, 1], [1, 0], [1, 1]])
Y = np.array([[0], [1], [1], [0]])
x = tf.placeholder(tf.float32, [None, 2])
y = tf.placeholder(tf.float32, [None, 1])
w = tf.Variable(tf.random_normal([2, 1]))