Skip to content

Instantly share code, notes, and snippets.

View happydpc's full-sized avatar

Michael Cheng happydpc

View GitHub Profile
@happydpc
happydpc / AutoFunc.py
Created August 24, 2022 12:34 — forked from 0xgalz/AutoFunc.py
IDAPython- Change Function Names in IDA According to their corresponding debug prints
import idc
import idautils
import idaapi
FUNCTIONS_REGISTERS = {"g_log": "rcx", "g_log_error": "rdx"}
def get_string_for_function(call_func_addr, register):
"""
:param start_addr: The function call address
@happydpc
happydpc / wgsl_3d_sdf.md
Created July 28, 2021 14:48 — forked from munrocket/wgsl_3d_sdf.md
3D SDF Primitives in WGSL

3D SDF Primitives in WGSL

How to use this gist:

  1. Build a sphere tracer with WebGPU (paper, paper2, youtube)
  2. Create model with sdf functions from here
  3. Add light and shadows
  4. ???
  5. PROFIT

This code tested in Chrome and Firefox, should work on PC too. Press star and subscribe.

@happydpc
happydpc / gist:7dc1854af4c25c46c9df5fefa78d222b
Created April 12, 2021 08:36 — forked from 5263/gist:3041500
FreeCAD interpolate surface
import FreeCAD
f1=open("surface.dat")
coords=[]
miny=1
for line in f1.readlines():
sline=line.strip()
if sline and not sline.startswith('#'):
ycoord=len(coords)
lcoords=[]
for xcoord, num in enumerate(sline.split()):

My current target uses a deterministic pattern when calling C++ constructors, so I can use the CFG to identify object instantiation. Here are my notes about how to use Ghidra's decompiler to get the sizes of objects to be created:

We can use the parameter of operator_new() to find the size of the objects. Instead of parsing the instructions of the relevant basic blocks (and hoping that we don't run into some unexpected instruction sequences generated by the compiler) we can use the decompiler to get the association between the call to operator_new() and its parameter.

Ghidra/Features/Decompiler/ghidra_scripts/ShowCCallsScript.java contains a nice example of how to use the Decompiler API. First, an instance of DecompInterface must be created, as shown in setUpDecompiler(). Note that this method doesn't call openProgram() on the returned DecomInterface object, that is necessary to run decompilation! The decompileFunction() method works as expected - the returned DecompileResults object con

@happydpc
happydpc / IMWidget.cpp
Created December 14, 2019 12:24 — forked from JSandusky/IMWidget.cpp
Nuklear in QT
#include "IMWidget.h"
#include <QAction>
#include <QApplication>
#include <QClipboard>
#include <QComboBox>
#include <QImage>
#include <QItemDelegate>
#include <QListWidget>
#include <QPainter>
@happydpc
happydpc / playground.rs
Created November 21, 2019 04:36 — forked from rust-play/playground.rs
Code shared from the Rust Playground
use tokio::prelude::*;
use tokio::runtime::TaskExecutor;
use tokio::runtime::Runtime;
use tokio::prelude::task::Task;
use std::sync::{Arc, Mutex};
use std::thread;
use std::time;
/// A future-creating function
fn custom_delay(seconds: f32) -> impl Future<Item=(), Error=()> {
@happydpc
happydpc / playground.rs
Created November 19, 2019 05:48 — forked from rust-play/playground.rs
Code shared from the Rust Playground
#![allow(unused)]
fn main() {
use std::collections::HashMap;
let mut a = HashMap::new();
a.insert(1, "a");
a.insert(2, "b");
println!("address a: {:p}", a[&1]);
@happydpc
happydpc / playground.rs
Created November 19, 2019 05:30 — forked from rust-play/playground.rs
Code shared from the Rust Playground
use std::collections::HashMap;
// Mutating one map
fn merge1(map1: &mut HashMap<(), ()>, map2: HashMap<(), ()>) {
map1.extend(map2);
}
// Without mutation
fn merge2(map1: HashMap<(), ()>, map2: HashMap<(), ()>) -> HashMap<(), ()> {
map1.into_iter().chain(map2).collect()
@happydpc
happydpc / playground.rs
Created November 16, 2019 16:21 — forked from rust-play/playground.rs
Code shared from the Rust Playground
use std::collections::HashMap;
use std::sync::mpsc;
use std::sync::Arc;
use std::sync::Mutex;
use std::thread;
fn main() {
let (tx, rx) = mpsc::channel();
thread::spawn(move || {
@happydpc
happydpc / playground.rs
Created November 16, 2019 07:58 — forked from rust-play/playground.rs
Code shared from the Rust Playground
use tokio::prelude::*;
use tokio::runtime::TaskExecutor;
use tokio::runtime::Runtime;
use tokio::prelude::task::Task;
use std::sync::{Arc, Mutex};
use std::thread;
use std::time;
/// A future-creating function
fn custom_delay(seconds: f32) -> impl Future<Item=(), Error=()> {