Skip to content

Instantly share code, notes, and snippets.

@dr4k0nia
Created May 22, 2023 18:43
Show Gist options
  • Save dr4k0nia/813087cee2875f5f82e37c8a731b80b0 to your computer and use it in GitHub Desktop.
Save dr4k0nia/813087cee2875f5f82e37c8a731b80b0 to your computer and use it in GitHub Desktop.
Tool to generate Hashes for HInvoke
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
GetMethodHash("System.Reflection.Assembly", "Load");
private static void GetMethodHash(string typeName, string methodName)
{
Console.WriteLine($"{GetHash(typeName)} => {typeName}");
var typeDef = typeof(void).Assembly.GetTypes()
.First(type => type.FullName == typeName);
var methodInfo = typeDef.GetRuntimeMethods()
.Where(method => method.Name == methodName);
foreach (var method in methodInfo)
Console.WriteLine($"{GetHash(typeName)}, {GetHash(method.ToString())} => {method.ToString()}");
}
private static void GetPropHash(string typeName, string propName)
{
Console.WriteLine($"{GetHash(typeName)} => {typeName}");
var typeDef = typeof(void).Assembly.GetTypes()
.First(type => type.FullName == typeName);
var property = typeDef.GetRuntimeProperties()
.First(prop => prop.Name == propName);
Console.WriteLine($"{GetHash(typeName)}, {GetHash(property.ToString())} => {property.ToString()}");
}
private static uint GetHash(string name)
{
uint sum = 0;
foreach (char c in name)
{
sum = (sum >> 0xA | sum << 0x11) + c;
}
// zero terminator:
sum = (sum >> 0xA | sum << 0x11) + 0;
return sum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment