summaryrefslogtreecommitdiff
path: root/dwm/inter.h
diff options
context:
space:
mode:
authornavewindre <nw@moneybot.cc>2024-07-17 08:36:51 +0200
committernavewindre <nw@moneybot.cc>2024-07-17 08:36:51 +0200
commit819cf3e4e8abb5ad41d8830155fc20bd833b21e8 (patch)
tree463951e47fc2937979542c8c46d14b9e0da827ce /dwm/inter.h
parent4c8b52fc94c04c4b3d338c2501971ae348f5b3e5 (diff)
render wip
Diffstat (limited to 'dwm/inter.h')
-rw-r--r--dwm/inter.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/dwm/inter.h b/dwm/inter.h
new file mode 100644
index 0000000..d668eaa
--- /dev/null
+++ b/dwm/inter.h
@@ -0,0 +1,46 @@
+#pragma once
+#include "typedef.h"
+#include "util.h"
+
+class VMT {
+ U64 ptr;
+
+public:
+ VMT( U64 ptr ) : ptr( ptr ) {}
+
+ U64 get( U32 index ) {
+ return *(U64*)( ptr + index * sizeof( U64 ) );
+ }
+
+ U64 set( U32 index, U64 func ) {
+ U64 o = get( index );
+ *(U64*)( ptr + index * sizeof( U64 ) ) = func;
+
+ return o;
+ }
+};
+
+static U64 u_find_pattern( U64 module, const char* pattern, U64 start = 0 ) {
+ U32 len;
+ U8* sig_bytes = u_parse_signature( pattern, &len );
+
+ if( !sig_bytes || len <= 2 )
+ return 0;
+
+ IMAGE_DOS_HEADER dos_hdr;
+ IMAGE_NT_HEADERS64 nt_hdr;
+ U32 size;
+
+ dos_hdr = *(IMAGE_DOS_HEADER*)module;
+ nt_hdr = *(IMAGE_NT_HEADERS64*)( module + dos_hdr.e_lfanew );
+ size = nt_hdr.OptionalHeader.SizeOfImage;
+
+ for( U64 off = start - module; off < size; ++off ) {
+ if( u_binary_match( (U8*)( module + off ), sig_bytes, len ) ) {
+ free( sig_bytes );
+ return module + off;
+ }
+ }
+
+ return 0;
+} \ No newline at end of file