Skip to content

Instantly share code, notes, and snippets.

@RikkaW
RikkaW / api.cpp
Created November 28, 2020 17:54
Socket send fd
void api::OpenFiles(RiruFile *files, size_t count) {
struct sockaddr_un addr{};
int fd;
socklen_t socklen;
uint8_t *data;
uint32_t data_size;
int32_t reply[count];
uint32_t reply_size;
std::vector<int> fds;
@RikkaW
RikkaW / gist:0ae7f51117768a03c6581c956d75958c
Last active June 18, 2024 05:31
insert general file with MediaStore
Context context = view.getContext();
ContentResolver cr = context.getContentResolver();
ContentValues values;
try {
// create a file for test
File file = new File(context.getFilesDir(), "1234568");
file.createNewFile();
try (OutputStream os = new FileOutputStream(file)) {
os.write("test".getBytes());
@RikkaW
RikkaW / gist:be3fe4178903702c54ec73b2fc1187fe
Last active October 2, 2024 14:10
show window in app_process (impossible to work from Android 14 QPR 3 or Android 15, as addView requires the calling process an Android app process)
token = new Binder();
try {
Context _context = android.app.ActivityThread.systemMain().getSystemContext();
final Context context = new ContextWrapper(_context) {
@Override
public Object getSystemService(String name) {
if (Context.WINDOW_SERVICE.equals(name)) {
WindowManager wm = (WindowManager) super.getSystemService(name);
if (wm != null) {
((android.view.WindowManagerImpl) wm).setDefaultToken(token);
private boolean insertImage(File image) throws IOException {
ContentValues values;
values = new ContentValues();
values.put(MediaStore.Images.ImageColumns.RELATIVE_PATH, Environment.DIRECTORY_PICTURES + "test");
values.put(MediaStore.Images.ImageColumns.DISPLAY_NAME, Long.toString(System.currentTimeMillis()));
values.put(MediaStore.Images.ImageColumns.IS_PENDING, true);
Uri uri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
if (uri == null) {
return false;
}
private boolean insertImage(File image) throws IOException {
ContentValues values;
values = new ContentValues();
values.put(MediaStore.Images.ImageColumns.RELATIVE_PATH, Environment.DIRECTORY_PICTURES + "test");
values.put(MediaStore.Images.ImageColumns.DISPLAY_NAME, Long.toString(System.currentTimeMillis()));
values.put(MediaStore.Images.ImageColumns.IS_PENDING, true);
Uri uri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
if (uri == null) {
return false;
}
@RikkaW
RikkaW / 喵2.cpp
Last active November 21, 2015 10:12
// 新的 windows 10 似乎已经修了问题 不需要这个了
// 而且下面这玩意在 windows 8.1 之前用会爆炸
typedef enum PROCESS_DPI_AWARENESS {
PROCESS_DPI_UNAWARE = 0,
PROCESS_SYSTEM_DPI_AWARE = 1,
PROCESS_PER_MONITOR_DPI_AWARE = 2
} PROCESS_DPI_AWARENESS;
STDAPI SetProcessDpiAwareness(
@RikkaW
RikkaW / 喵.cpp
Last active October 18, 2015 13:01
MSAA
/*
修改自 BTE Alpha 的 Renderer
正版默认有 MSAA 并自带一个 FBO
给正版用启动参数加 -nofbo -nomsaa
(很奇怪我的正版不会默认开 MSAA
*/
// 初始化 FBO