Skip to content

Instantly share code, notes, and snippets.

View nnnewb's full-sized avatar
😪
always sleepy

weak_ptr nnnewb

😪
always sleepy
View GitHub Profile
@nnnewb
nnnewb / example.c
Last active October 20, 2021 01:44
PE32 Packer NoRelocations
#include <Windows.h>
#include <memory.h>
#include <stdlib.h>
#include <winnt.h>
int main(void) {
MessageBoxA(NULL, "Hello world!", "MSGBOX", MB_OK);
return 0;
}
@nnnewb
nnnewb / tinype.asm
Last active October 12, 2021 08:03
PE from scratch with nasm
; author: weak_ptr <weak_ptr@outlook.com>
; date: 2021-10-11 17:01
; description: PE from scratch with nasm assembler
;
; reference: http://www.phreedom.org/research/tinype/
;
; compile command: nasm -f bin tinype.asm -o tinype.exe
;
BITS 32
@nnnewb
nnnewb / cli.py
Last active June 17, 2019 03:43
制作命令行工具的实用函数集
import sys
import subprocess
import logging
# ! 工具函数
# ----------------------------------------------------------------------------
def require(package, import_name=None, editable=False, quiet=True, index='https://pypi.org/simple'):
logger = logging.getLogger('require')
try:
from pip import main
@nnnewb
nnnewb / sqla.py
Created February 2, 2019 09:01
discover all sqlalchemy models from _decl_class_registry
from flask_sqlalchemy import SQLAlchemy
def list_models(db: SQLAlchemy):
classes, models, table_names = [], [], []
for clazz in db.Model._decl_class_registry.values():
if getattr(clazz, '__tablename__', None):
table_names.append(clazz.__tablename__)
classes.append(clazz)
for table in db.metadata.tables.items():
@nnnewb
nnnewb / imp.py
Created February 2, 2019 08:58
recursive import package, for sure all sub-modules had been executed, ready for other operation
# compatibility: python 3.6+
import types
import typing
from importlib import import_module
from pkgutil import walk_packages
def import_recursive(pkg: typing.Type[types.ModuleType]) -> typing.Sequence[typing.Type[types.ModuleType]]:
"""
递归导入指定包下所有模块
@nnnewb
nnnewb / Keycode.ts
Created January 5, 2019 05:08
enum Keycode by typescript
export enum Keycode {
None = -1,
// none = 0,1,2,3,4,5,6,7
BackSpace = 8,
Tab = 9,
// none = 10,11,12
Enter = 13,
// none = 14,15
Shift = 16,
Ctrl = 17,