Skip to content

Instantly share code, notes, and snippets.

@sunwayforever
sunwayforever / generator.rs
Created February 19, 2019 10:03
generator to iterator
#![feature(generators, generator_trait)]
use std::ops::GeneratorState;
use std::pin::Pin;
fn generator_to_iterator<G>(g: G) -> impl Iterator<Item = G::Yield>
where
G: std::marker::Unpin + std::ops::Generator,
{
struct GeneratorIter<G>(G);
@sunwayforever
sunwayforever / trie.rs
Created January 25, 2019 08:26
trie.rs
use std::collections::HashMap;
#[derive(Default)]
struct TrieNode {
is_leaf: bool,
children: HashMap<char, TrieNode>,
}
impl TrieNode {
fn add(&mut self, s: String) {
let mut root = self;
for c in s.chars() {
@sunwayforever
sunwayforever / expect.sh
Created October 25, 2018 06:04
expect example
#!/bin/bash
expect -c "
set timeout 10000
spawn sudo pacman -Su
expect {
\"Proceed with installation\" {send -- y\r}
}
expect eof
"
@sunwayforever
sunwayforever / test.c
Created October 13, 2017 07:07
hijack libc
#include <sys/auxv.h>
#include <elf.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <dlfcn.h>
void my_abort() {
printf("abort hijacked\n");
exit(-1);
@sunwayforever
sunwayforever / Android.mk
Created October 13, 2017 03:21
Android.mk for exectuable
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES:= test.c
LOCAL_CFLAGS := -Wno-error-unused-parameter
LOCAL_MODULE:= hello
LOCAL_MULTILIB := 32
# LOCAL_LDFLAGS := ...
@sunwayforever
sunwayforever / *scratch*.cpp
Created October 8, 2017 08:43
get address of c++ member function
std::vector<std::unique_ptr<const DexFile> > (OatFileManager::* ptrtofn)(const char *, const char *, jobject, jobjectArray, const art::OatFile **, std::vector<std::string> *) = &OatFileManager::OpenDexFilesFromOat;
VLOG(class_linker) << "sunway: " << (void * &)ptrtofn;
@sunwayforever
sunwayforever / linker.diff
Last active September 27, 2017 08:54
linker.diff
diff --git a/linker/linker.cpp b/linker/linker.cpp
index c661624..f426fe8 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -1029,6 +1029,16 @@ static int open_library_on_paths(ZipArchiveCache* zip_archive_cache,
}
if (fd != -1) {
+ ElfW(Ehdr) header;
+ ssize_t rc = TEMP_FAILURE_RETRY(pread64(fd, &header, sizeof(header), 0));
@sunwayforever
sunwayforever / sync_cache.c
Created July 24, 2017 02:38
sync_cache.c
/* Machine description for AArch64 architecture.
Copyright (C) 2012-2014 Free Software Foundation, Inc.
Contributed by ARM Ltd.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
@sunwayforever
sunwayforever / WbXmlConverter.cpp
Last active July 19, 2017 08:18
wbxml converter
#include <WbXmlConverter.hpp>
#include <utils/String8.h>
using namespace android;
const char* WbXmlConverter::DRM_ELEMENT_CODE_PAGE[] = {
RO_ELEMENT_RIGHTS, RO_ELEMENT_CONTEXT, RO_ELEMENT_VERSION, RO_ELEMENT_UID, RO_ELEMENT_AGREEMENT,
RO_ELEMENT_ASSET, RO_ELEMENT_KEYINFO, RO_ELEMENT_KEYVALUE, RO_ELEMENT_PERMISSION, RO_ELEMENT_PLAY,
RO_ELEMENT_DISPLAY, RO_ELEMENT_EXECUTE, RO_ELEMENT_PRINT, RO_ELEMENT_CONSTRAINT, RO_ELEMENT_COUNT,
RO_ELEMENT_DATE_TIME, RO_ELEMENT_START_TIME, RO_ELEMENT_EXPIRY_TIME, RO_ELEMENT_AVAILABLE_TIME
};
@sunwayforever
sunwayforever / salsa_pretranslator.c
Created July 19, 2017 08:12
android liblog and getopt example
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <libgen.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <getopt.h>