Skip to content

Instantly share code, notes, and snippets.

@ek0
ek0 / get_object_name.cc
Created February 21, 2022 21:29
Get object name for handle
// Returns an OBJECT_NAME_INFORMATION object pointed by name
// Caller must free `name` after usage
UNICODE_STRING* GetObjectNameInformation(HANDLE object_handle)
{
ULONG length = 0;
UNICODE_STRING* obj = (UNICODE_STRING*)malloc(sizeof(UNICODE_STRING));
NTSTATUS(*myNtQueryObject)(HANDLE, ObjectInfoClass, UNICODE_STRING*, uint32_t, PULONG) = (NTSTATUS(*)(HANDLE, ObjectInfoClass, UNICODE_STRING*, uint32_t, PULONG))GetProcAddress(GetModuleHandle("ntdll"), "NtQueryObject");
NTSTATUS status = myNtQueryObject(object_handle, ObjectNameInformation, obj, sizeof(UNICODE_STRING), &length);
if (!NT_SUCCESS(status) && (status == 0xc0000004 || status == 0x80000005))
{
@ek0
ek0 / lua_repl.rs
Last active February 4, 2025 02:05
use mlua::Lua;
use rustyline::{
CompletionType, Config, EditMode, Editor,
completion::{Completer, Pair, extract_word},
error::ReadlineError,
history::FileHistory,
};
use rustyline_derive::{Helper, Highlighter, Hinter, Validator};
struct MyObject {
#include <clang/AST/ASTConsumer.h>
#include <clang/AST/RecursiveASTVisitor.h>
#include <clang/Frontend/FrontendAction.h>
#include <clang/Frontend/FrontendActions.h>
#include <clang/Tooling/CommonOptionsParser.h>
#include <clang/Tooling/Tooling.h>
#include <llvm/Support/CommandLine.h>
#include <llvm/Support/MemoryBuffer.h>
#include <filesystem>
use std::fs;
use tree_sitter::{InputEdit, Language, Node, Parser, Point};
use tree_sitter_cpp;
fn find_matching_parenthesis(node: &Node) -> Option<usize> {
for index in (0..node.child_count()).rev() {
println!("{}", node.child(index).unwrap());
let current = node.child(index).unwrap();
if current.kind() == ")" {